mongoose 5.13.2 → 5.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +11 -0
- package/dist/browser.umd.js +14 -14
- package/index.d.ts +19 -16
- package/lib/document.js +3 -0
- package/lib/helpers/update/applyTimestampsToChildren.js +35 -28
- package/lib/model.js +10 -7
- package/lib/schema.js +3 -1
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ declare module 'mongoose' {
|
|
|
120
120
|
* [timestamps](/docs/guide.html#timestamps). You may stub out this function
|
|
121
121
|
* using a tool like [Sinon](https://www.npmjs.com/package/sinon) for testing.
|
|
122
122
|
*/
|
|
123
|
-
export function now():
|
|
123
|
+
export function now(): NativeDate;
|
|
124
124
|
|
|
125
125
|
/** Declares a global plugin executed on all Schemas. */
|
|
126
126
|
export function plugin(fn: (schema: Schema, opts?: any) => void, opts?: any): typeof mongoose;
|
|
@@ -618,8 +618,8 @@ declare module 'mongoose' {
|
|
|
618
618
|
|
|
619
619
|
interface AcceptsDiscriminator {
|
|
620
620
|
/** Adds a discriminator type. */
|
|
621
|
-
discriminator<D
|
|
622
|
-
discriminator<T
|
|
621
|
+
discriminator<D>(name: string | number, schema: Schema<D>, value?: string | number | ObjectId): Model<D>;
|
|
622
|
+
discriminator<T, U extends Model<T>>(name: string | number, schema: Schema<T, U>, value?: string | number | ObjectId): U;
|
|
623
623
|
}
|
|
624
624
|
|
|
625
625
|
interface AnyObject { [k: string]: any }
|
|
@@ -1167,7 +1167,7 @@ declare module 'mongoose' {
|
|
|
1167
1167
|
obj: any;
|
|
1168
1168
|
|
|
1169
1169
|
/** Gets/sets schema paths. */
|
|
1170
|
-
path(path: string):
|
|
1170
|
+
path<ResultType extends SchemaType = SchemaType>(path: string): ResultType;
|
|
1171
1171
|
path(path: string, constructor: any): this;
|
|
1172
1172
|
|
|
1173
1173
|
/** Lists all paths and their type in the schema. */
|
|
@@ -1432,7 +1432,7 @@ declare module 'mongoose' {
|
|
|
1432
1432
|
interface SchemaTimestampsConfig {
|
|
1433
1433
|
createdAt?: boolean | string;
|
|
1434
1434
|
updatedAt?: boolean | string;
|
|
1435
|
-
currentTime?: () => (
|
|
1435
|
+
currentTime?: () => (NativeDate | number);
|
|
1436
1436
|
}
|
|
1437
1437
|
|
|
1438
1438
|
type Unpacked<T> = T extends (infer U)[] ? U : T;
|
|
@@ -1533,13 +1533,13 @@ declare module 'mongoose' {
|
|
|
1533
1533
|
subtype?: number
|
|
1534
1534
|
|
|
1535
1535
|
/** The minimum value allowed for this path. Only allowed for numbers and dates. */
|
|
1536
|
-
min?: number |
|
|
1536
|
+
min?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string];
|
|
1537
1537
|
|
|
1538
1538
|
/** The maximum value allowed for this path. Only allowed for numbers and dates. */
|
|
1539
|
-
max?: number |
|
|
1539
|
+
max?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string];
|
|
1540
1540
|
|
|
1541
1541
|
/** Defines a TTL index on this path. Only allowed for dates. */
|
|
1542
|
-
expires?: number |
|
|
1542
|
+
expires?: number | NativeDate;
|
|
1543
1543
|
|
|
1544
1544
|
/** If `true`, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays. */
|
|
1545
1545
|
excludeIndexes?: boolean;
|
|
@@ -1703,8 +1703,8 @@ declare module 'mongoose' {
|
|
|
1703
1703
|
|
|
1704
1704
|
static options: { castNonArrays: boolean; };
|
|
1705
1705
|
|
|
1706
|
-
discriminator<D
|
|
1707
|
-
discriminator<T
|
|
1706
|
+
discriminator<D>(name: string | number, schema: Schema<D>, value?: string): Model<D>;
|
|
1707
|
+
discriminator<T, U extends Model<T>>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
1708
1708
|
|
|
1709
1709
|
/**
|
|
1710
1710
|
* Adds an enum validator if this is an array of strings or numbers. Equivalent to
|
|
@@ -1743,10 +1743,10 @@ declare module 'mongoose' {
|
|
|
1743
1743
|
expires(when: number | string): this;
|
|
1744
1744
|
|
|
1745
1745
|
/** Sets a maximum date validator. */
|
|
1746
|
-
max(value:
|
|
1746
|
+
max(value: NativeDate, message: string): this;
|
|
1747
1747
|
|
|
1748
1748
|
/** Sets a minimum date validator. */
|
|
1749
|
-
min(value:
|
|
1749
|
+
min(value: NativeDate, message: string): this;
|
|
1750
1750
|
}
|
|
1751
1751
|
|
|
1752
1752
|
class Decimal128 extends SchemaType {
|
|
@@ -1760,8 +1760,8 @@ declare module 'mongoose' {
|
|
|
1760
1760
|
|
|
1761
1761
|
static options: { castNonArrays: boolean; };
|
|
1762
1762
|
|
|
1763
|
-
discriminator<D
|
|
1764
|
-
discriminator<T
|
|
1763
|
+
discriminator<D>(name: string | number, schema: Schema<D>, value?: string): Model<D>;
|
|
1764
|
+
discriminator<T, U extends Model<T>>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
1765
1765
|
|
|
1766
1766
|
/** The schema used for documents in this array */
|
|
1767
1767
|
schema: Schema;
|
|
@@ -1799,12 +1799,15 @@ declare module 'mongoose' {
|
|
|
1799
1799
|
auto(turnOn: boolean): this;
|
|
1800
1800
|
}
|
|
1801
1801
|
|
|
1802
|
-
class Embedded extends SchemaType {
|
|
1802
|
+
class Embedded extends SchemaType implements AcceptsDiscriminator {
|
|
1803
1803
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
1804
1804
|
static schemaName: string;
|
|
1805
1805
|
|
|
1806
1806
|
/** The document's schema */
|
|
1807
1807
|
schema: Schema;
|
|
1808
|
+
|
|
1809
|
+
discriminator<D>(name: string | number, schema: Schema<D>, value?: string): Model<D>;
|
|
1810
|
+
discriminator<T, U extends Model<T>>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
1808
1811
|
}
|
|
1809
1812
|
|
|
1810
1813
|
class String extends SchemaType {
|
|
@@ -2441,7 +2444,7 @@ declare module 'mongoose' {
|
|
|
2441
2444
|
type actualPrimitives = string | boolean | number | bigint | symbol | null | undefined;
|
|
2442
2445
|
type TreatAsPrimitives = actualPrimitives |
|
|
2443
2446
|
// eslint-disable-next-line no-undef
|
|
2444
|
-
|
|
2447
|
+
NativeDate | RegExp | symbol | Error | BigInt | Types.ObjectId;
|
|
2445
2448
|
|
|
2446
2449
|
type LeanType<T> =
|
|
2447
2450
|
0 extends (1 & T) ? T : // any
|
package/lib/document.js
CHANGED
|
@@ -994,6 +994,9 @@ Document.prototype.$set = function $set(path, val, type, options) {
|
|
|
994
994
|
delete this._doc[key];
|
|
995
995
|
// Make sure we set `{}` back even if we minimize re: gh-8565
|
|
996
996
|
options = Object.assign({}, options, { _skipMinimizeTopLevel: true });
|
|
997
|
+
} else {
|
|
998
|
+
// Make sure we set `{_skipMinimizeTopLevel: false}` if don't have overwrite: gh-10441
|
|
999
|
+
options = Object.assign({}, options, { _skipMinimizeTopLevel: false });
|
|
997
1000
|
}
|
|
998
1001
|
|
|
999
1002
|
const someCondition = typeof path[key] === 'object' &&
|
|
@@ -19,34 +19,10 @@ function applyTimestampsToChildren(now, update, schema) {
|
|
|
19
19
|
|
|
20
20
|
if (hasDollarKey) {
|
|
21
21
|
if (update.$push) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
$path.$isMongooseDocumentArray &&
|
|
27
|
-
$path.schema.options.timestamps) {
|
|
28
|
-
const timestamps = $path.schema.options.timestamps;
|
|
29
|
-
const createdAt = handleTimestampOption(timestamps, 'createdAt');
|
|
30
|
-
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
|
|
31
|
-
if (update.$push[key].$each) {
|
|
32
|
-
update.$push[key].$each.forEach(function(subdoc) {
|
|
33
|
-
if (updatedAt != null) {
|
|
34
|
-
subdoc[updatedAt] = now;
|
|
35
|
-
}
|
|
36
|
-
if (createdAt != null) {
|
|
37
|
-
subdoc[createdAt] = now;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
if (updatedAt != null) {
|
|
42
|
-
update.$push[key][updatedAt] = now;
|
|
43
|
-
}
|
|
44
|
-
if (createdAt != null) {
|
|
45
|
-
update.$push[key][createdAt] = now;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
22
|
+
_applyTimestampToUpdateOperator(update.$push);
|
|
23
|
+
}
|
|
24
|
+
if (update.$addToSet) {
|
|
25
|
+
_applyTimestampToUpdateOperator(update.$addToSet);
|
|
50
26
|
}
|
|
51
27
|
if (update.$set != null) {
|
|
52
28
|
const keys = Object.keys(update.$set);
|
|
@@ -60,6 +36,37 @@ function applyTimestampsToChildren(now, update, schema) {
|
|
|
60
36
|
for (const key of updateKeys) {
|
|
61
37
|
applyTimestampsToUpdateKey(schema, key, update, now);
|
|
62
38
|
}
|
|
39
|
+
|
|
40
|
+
function _applyTimestampToUpdateOperator(op) {
|
|
41
|
+
for (const key of Object.keys(op)) {
|
|
42
|
+
const $path = schema.path(key.replace(/\.\$\./i, '.').replace(/.\$$/, ''));
|
|
43
|
+
if (op[key] &&
|
|
44
|
+
$path &&
|
|
45
|
+
$path.$isMongooseDocumentArray &&
|
|
46
|
+
$path.schema.options.timestamps) {
|
|
47
|
+
const timestamps = $path.schema.options.timestamps;
|
|
48
|
+
const createdAt = handleTimestampOption(timestamps, 'createdAt');
|
|
49
|
+
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
|
|
50
|
+
if (op[key].$each) {
|
|
51
|
+
op[key].$each.forEach(function(subdoc) {
|
|
52
|
+
if (updatedAt != null) {
|
|
53
|
+
subdoc[updatedAt] = now;
|
|
54
|
+
}
|
|
55
|
+
if (createdAt != null) {
|
|
56
|
+
subdoc[createdAt] = now;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
if (updatedAt != null) {
|
|
61
|
+
op[key][updatedAt] = now;
|
|
62
|
+
}
|
|
63
|
+
if (createdAt != null) {
|
|
64
|
+
op[key][createdAt] = now;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
function applyTimestampsToDocumentArray(arr, schematype, now) {
|
package/lib/model.js
CHANGED
|
@@ -3729,18 +3729,21 @@ Model.buildBulkWriteOperations = function buildBulkWriteOperations(documents, op
|
|
|
3729
3729
|
}
|
|
3730
3730
|
|
|
3731
3731
|
const delta = document.$__delta();
|
|
3732
|
-
const where = document.$__where(delta[0]);
|
|
3733
|
-
const changes = delta[1];
|
|
3734
|
-
|
|
3735
|
-
_applyCustomWhere(document, where);
|
|
3736
|
-
|
|
3737
|
-
document.$__version(where, delta);
|
|
3738
3732
|
|
|
3739
3733
|
if (document.isNew) {
|
|
3734
|
+
// new document
|
|
3740
3735
|
accumulator.push({
|
|
3741
3736
|
insertOne: { document }
|
|
3742
3737
|
});
|
|
3743
|
-
} else if (!utils.isEmptyObject(
|
|
3738
|
+
} else if (delta != null && !utils.isEmptyObject(delta[0])) {
|
|
3739
|
+
// document with changes
|
|
3740
|
+
const where = document.$__where(delta[0]);
|
|
3741
|
+
const changes = delta[1];
|
|
3742
|
+
|
|
3743
|
+
_applyCustomWhere(document, where);
|
|
3744
|
+
|
|
3745
|
+
document.$__version(where, delta);
|
|
3746
|
+
|
|
3744
3747
|
accumulator.push({
|
|
3745
3748
|
updateOne: {
|
|
3746
3749
|
filter: where,
|
package/lib/schema.js
CHANGED
|
@@ -1937,7 +1937,9 @@ Schema.prototype.loadClass = function(model, virtualsOnly) {
|
|
|
1937
1937
|
return;
|
|
1938
1938
|
}
|
|
1939
1939
|
const prop = Object.getOwnPropertyDescriptor(model, name);
|
|
1940
|
-
|
|
1940
|
+
if (prop.hasOwnProperty('value')) {
|
|
1941
|
+
this.static(name, prop.value);
|
|
1942
|
+
}
|
|
1941
1943
|
}, this);
|
|
1942
1944
|
}
|
|
1943
1945
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "5.13.
|
|
4
|
+
"version": "5.13.3",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@types/node": "14.x || 15.x",
|
|
24
24
|
"bson": "^1.1.4",
|
|
25
25
|
"kareem": "2.3.2",
|
|
26
|
-
"mongodb": "3.6.
|
|
26
|
+
"mongodb": "3.6.10",
|
|
27
27
|
"mongoose-legacy-pluralize": "1.0.2",
|
|
28
28
|
"mpath": "0.8.3",
|
|
29
29
|
"mquery": "3.2.5",
|