Skip to content

Commit

Permalink
Merge branch '6.3' into 7971-followUp
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Apr 14, 2022
2 parents be1061d + cbcec5c commit 63fbbb2
Show file tree
Hide file tree
Showing 28 changed files with 472 additions and 123 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
name: Benchmark
on:
pull_request:
paths:
- 'package.json'
- 'types/**'
- 'benchmarks/typescript/**'
push:
branches:
- master
paths:
- 'package.json'
- 'types/**'
- 'benchmarks/typescript/**'
permissions:
contents: read

jobs:
typescript:
runs-on: ubuntu-20.04
name: TypeScript
name: Benchmark TypeScript Types
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3

Expand Down
93 changes: 46 additions & 47 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
name: Test
on:
pull_request:
push:
pull_request:
paths:
- 'package.json'
- 'index.js'
- 'lib/**'
- 'test/**.js'
push:
branches:
- master
paths:
- 'package.json'
- 'index.js'
- 'lib/**'
- 'test/**.js'
permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
name: Lint JS-Files
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3

- name: Setup node
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version: 14

- run: npm install

- name: Lint JS-Files
run: npm run lint-js

test:
needs:
- lint
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -43,52 +73,9 @@ jobs:
echo `pwd`/mongodb-linux-x86_64-${{ matrix.mongo-os }}-${{ matrix.mongo }}/bin >> $GITHUB_PATH
- run: npm test

lint:
runs-on: ubuntu-latest
name: Linter
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3

- name: Setup node
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version: 14

- run: npm install

- name: Linter
run: npm run lint

test-ts-types:
runs-on: ubuntu-latest
name: Typescript Types
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3

- name: Setup node
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version: 12

- run: npm install

- name: Typings
run: npm run test-tsd

test-replica-sets:
runs-on: ubuntu-latest
name: Replica Set tests
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3
- name: Setup node
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version: 16
- run: npm install
- name: Test
run: env START_REPLICA_SET=1 npm test

coverage:
needs:
- test
runs-on: ubuntu-20.04
name: Coverage
steps:
Expand All @@ -115,3 +102,15 @@ jobs:
with:
name: coverage
path: coverage
test-replica-sets:
runs-on: ubuntu-latest
name: Replica Set tests
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3
- name: Setup node
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version: 16
- run: npm install
- name: Test
run: env START_REPLICA_SET=1 npm test
5 changes: 5 additions & 0 deletions .github/workflows/tidelift-alignment.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Tidelift Alignment
on:
pull_request:
paths:
- 'package.json'
push:
paths:
- 'package.json'
schedule:
- cron: '0 0 * * *' # every day at midnight

Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/tsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Typescript Types
on:
pull_request:
paths:
- 'package.json'
- 'types/**'
- 'test/types/**'
push:
branches:
- master
paths:
- 'package.json'
- 'types/**'
- 'test/types/**'
permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
name: Lint TS-Files
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3

- name: Setup node
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version: 14

- run: npm install

- name: Lint TS-Files
run: npm run lint-ts

test-ts-types:
needs:
- lint
runs-on: ubuntu-latest
name: Test Typescript Types
steps:
- uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3

- name: Setup node
uses: actions/setup-node@5b52f097d36d4b0b2f94ed6de710023fbb8b2236 # v3.1.0
with:
node-version: 12

- run: npm install

- name: Typings
run: npm run test-tsd
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
6.2.11 / 2022-04-13
===================
* fix(document): handle validation with triply nested document arrays #11564
* fix(query): skip applying string schema setters on $regex #11426
* fix: skip findOneAndReplace() validation if runValidators = false #11559
* fix(model): correctly handle schema-level collations in syncIndexes() #7621
* fix(types): correct populate query return type with lean #11560 [mohammad0-0ahmad](https://github.com/mohammad0-0ahmad)
* fix(types): allow using { type: Mixed } as schema type definition for any path #10900
* docs: fix example on Schema.prototype.post() #11648 [EmilienLeroy](https://github.com/EmilienLeroy)
* docs: fix typo in methods/index.js #11651 [eltociear](https://github.com/eltociear)

6.2.10 / 2022-04-04
===================
* fix(types): improve lastErrorObject typing for rawResults #11602 [simllll](https://github.com/simllll)
Expand Down
6 changes: 3 additions & 3 deletions docs/typescript/populate.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Parent {
name?: string
}
const ParentModel = model<Parent>('Parent', new Schema({
child: { type: 'ObjectId', ref: 'Child' },
child: { type: Schema.Types.ObjectId, ref: 'Child' },
name: String
}));

Expand Down Expand Up @@ -45,7 +45,7 @@ interface PopulatedParent {
child: Child | null;
}
const ParentModel = model<Parent>('Parent', new Schema({
child: { type: 'ObjectId', ref: 'Child' },
child: { type: Schema.Types.ObjectId, ref: 'Child' },
name: String
}));
const childSchema: Schema = new Schema({ name: String });
Expand All @@ -56,4 +56,4 @@ ParentModel.findOne({}).populate<Pick<PopulatedParent, 'child'>>('child').orFail
// Works
const t: string = doc.child.name;
});
```
```
4 changes: 2 additions & 2 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const utils = require('./utils');
const read = Query.prototype.read;
const readConcern = Query.prototype.readConcern;

const validRedactStringValues = new Set(['$$DESCEND', '$$PRUNE', '$$KEEP']);

/**
* Aggregate constructor used for building aggregation pipelines. Do not
* instantiate this class directly, use [Model.aggregate()](/docs/api.html#model_Model.aggregate) instead.
Expand Down Expand Up @@ -672,8 +674,6 @@ Aggregate.prototype.readConcern = function(level) {
* @api public
*/

const validRedactStringValues = new Set(['$$DESCEND', '$$PRUNE', '$$KEEP']);

Aggregate.prototype.redact = function(expression, thenExpr, elseExpr) {
if (arguments.length === 3) {
if ((typeof thenExpr === 'string' && !validRedactStringValues.has(thenExpr)) ||
Expand Down
13 changes: 3 additions & 10 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function Document(obj, fields, skipId, options) {
this.$__ = new InternalCache();
this.$isNew = 'isNew' in options ? options.isNew : true;

if ('priorDoc' in options) {
if (options.priorDoc != null) {
this.$__.priorDoc = options.priorDoc;
}

Expand All @@ -119,7 +119,7 @@ function Document(obj, fields, skipId, options) {
fields = undefined;
} else {
this.$__.strictMode = schema.options.strict;
if (fields !== undefined) {
if (fields != null) {
this.$__.selected = fields;
}
}
Expand Down Expand Up @@ -177,8 +177,6 @@ function Document(obj, fields, skipId, options) {
$__applyDefaults(this, fields, exclude, hasIncludedChildren, false, options.skipDefaults);
}

this.$__._id = this._id;

if (!this.$__.strictMode && obj) {
const _this = this;
const keys = Object.keys(this._doc);
Expand Down Expand Up @@ -743,8 +741,6 @@ Document.prototype.$__init = function(doc, opts) {
this.$emit('init', this);
this.constructor.emit('init', this);

this.$__._id = this._id;

const hasIncludedChildren = this.$__.exclude === false && this.$__.fields ?
$__hasIncludedChildren(this.$__.fields) :
null;
Expand Down Expand Up @@ -2485,10 +2481,7 @@ function _getPathsToValidate(doc) {
if (subdoc.$basePath) {
// Remove child paths for now, because we'll be validating the whole
// subdoc
if (!subdoc.$__.fullPath) {
subdoc.ownerDocument();
}
const fullPathToSubdoc = subdoc.$__.fullPath;
const fullPathToSubdoc = subdoc.$__fullPathWithIndexes();

for (const p of paths) {
if (p === null || p.startsWith(fullPathToSubdoc + '.')) {
Expand Down
4 changes: 3 additions & 1 deletion lib/helpers/query/castUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = function castUpdate(schema, obj, options, context, filter) {
} else if (!options.overwriteDiscriminatorKey) {
delete obj[schema.options.discriminatorKey];
}
if (options.upsert) {
if (options.upsert && !options.overwrite) {
moveImmutableProperties(schema, obj, context);
}

Expand Down Expand Up @@ -217,6 +217,7 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {
}

if (op !== '$setOnInsert' &&
!options.overwrite &&
handleImmutable(schematype, strict, obj, key, prefix + key, context)) {
continue;
}
Expand Down Expand Up @@ -311,6 +312,7 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) {

// You can use `$setOnInsert` with immutable keys
if (op !== '$setOnInsert' &&
!options.overwrite &&
handleImmutable(schematype, strict, obj, key, prefix + key, context)) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/update/applyTimestampsToChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function applyTimestampsToChildren(now, update, schema) {
}

const keys = Object.keys(update);
const hasDollarKey = keys.some(key => key.startsWith('$'));
const hasDollarKey = keys.some(key => key[0] === '$');

if (hasDollarKey) {
if (update.$push) {
Expand All @@ -38,7 +38,7 @@ function applyTimestampsToChildren(now, update, schema) {
}
}

const updateKeys = Object.keys(update).filter(key => !key.startsWith('$'));
const updateKeys = Object.keys(update).filter(key => key[0] !== '$');
for (const key of updateKeys) {
applyTimestampsToUpdateKey(schema, key, update, now);
}
Expand Down
1 change: 0 additions & 1 deletion lib/helpers/update/applyTimestampsToUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function applyTimestampsToUpdate(now, createdAt, updatedAt, currentUpdate, optio
}

if (!skipCreatedAt && createdAt) {

if (currentUpdate[createdAt]) {
delete currentUpdate[createdAt];
}
Expand Down

0 comments on commit 63fbbb2

Please sign in to comment.