mongoose 6.8.0 → 6.8.2
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/README.md +3 -3
- package/dist/browser.umd.js +1 -1
- package/lib/connection.js +12 -12
- package/lib/document.js +1 -1
- package/lib/helpers/common.js +1 -0
- package/lib/helpers/model/discriminator.js +3 -0
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +4 -1
- package/lib/helpers/populate/assignVals.js +2 -0
- package/lib/helpers/query/castUpdate.js +12 -0
- package/lib/helpers/schema/applyBuiltinPlugins.js +12 -0
- package/lib/helpers/update/castArrayFilters.js +41 -15
- package/lib/index.js +32 -40
- package/lib/model.js +18 -4
- package/lib/plugins/index.js +7 -0
- package/lib/query.js +22 -6
- package/lib/schema.js +3 -0
- package/lib/types/map.js +1 -1
- package/package.json +4 -6
- package/scripts/tsc-diagnostics-check.js +15 -0
- package/tools/auth.js +2 -2
- package/tools/sharded.js +4 -4
- package/types/aggregate.d.ts +6 -6
- package/types/document.d.ts +3 -0
- package/types/index.d.ts +10 -0
- package/types/inferschematype.d.ts +11 -7
- package/types/middlewares.d.ts +1 -0
- package/types/schemaoptions.d.ts +6 -0
- package/types/schematypes.d.ts +42 -0
- package/lib/plugins/clearValidating.js +0 -28
package/tools/auth.js
CHANGED
|
@@ -21,11 +21,11 @@ async function run() {
|
|
|
21
21
|
// Start process
|
|
22
22
|
await server.start();
|
|
23
23
|
|
|
24
|
-
const db = await mongodb.MongoClient.connect('mongodb://
|
|
24
|
+
const db = await mongodb.MongoClient.connect('mongodb://127.0.0.1:27017/admin');
|
|
25
25
|
|
|
26
26
|
await db.addUser('passwordIsTaco', 'taco', {
|
|
27
27
|
roles: ['dbOwner']
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
console.log('done');
|
|
31
|
-
}
|
|
31
|
+
}
|
package/tools/sharded.js
CHANGED
|
@@ -17,18 +17,18 @@ async function run() {
|
|
|
17
17
|
|
|
18
18
|
await topology.addShard([{
|
|
19
19
|
options: {
|
|
20
|
-
bind_ip: '
|
|
20
|
+
bind_ip: '127.0.0.1', port: 31000, dbpath: '/data/db/31000', shardsvr: null
|
|
21
21
|
}
|
|
22
22
|
}], { replSet: 'rs1' });
|
|
23
23
|
|
|
24
24
|
await topology.addConfigurationServers([{
|
|
25
25
|
options: {
|
|
26
|
-
bind_ip: '
|
|
26
|
+
bind_ip: '127.0.0.1', port: 35000, dbpath: '/data/db/35000'
|
|
27
27
|
}
|
|
28
28
|
}], { replSet: 'rs0' });
|
|
29
29
|
|
|
30
30
|
await topology.addProxies([{
|
|
31
|
-
bind_ip: '
|
|
31
|
+
bind_ip: '127.0.0.1', port: 51000, configdb: '127.0.0.1:35000'
|
|
32
32
|
}], {
|
|
33
33
|
binary: 'mongos'
|
|
34
34
|
});
|
|
@@ -43,4 +43,4 @@ async function run() {
|
|
|
43
43
|
await topology.enableSharding('test');
|
|
44
44
|
|
|
45
45
|
console.log('done');
|
|
46
|
-
}
|
|
46
|
+
}
|
package/types/aggregate.d.ts
CHANGED
|
@@ -68,13 +68,13 @@ declare module 'mongoose' {
|
|
|
68
68
|
[key: string]: any;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
class Aggregate<
|
|
71
|
+
class Aggregate<ResultType> implements SessionOperation {
|
|
72
72
|
/**
|
|
73
73
|
* Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js)
|
|
74
74
|
* You do not need to call this function explicitly, the JavaScript runtime
|
|
75
75
|
* will call it for you.
|
|
76
76
|
*/
|
|
77
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<Unpacked<
|
|
77
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Unpacked<ResultType>>;
|
|
78
78
|
|
|
79
79
|
options: AggregateOptions;
|
|
80
80
|
|
|
@@ -103,7 +103,7 @@ declare module 'mongoose' {
|
|
|
103
103
|
* resolved with either the doc(s) or rejected with the error.
|
|
104
104
|
* Like [`.then()`](#query_Query-then), but only takes a rejection handler.
|
|
105
105
|
*/
|
|
106
|
-
catch: Promise<
|
|
106
|
+
catch: Promise<ResultType>['catch'];
|
|
107
107
|
|
|
108
108
|
/** Set the collation. */
|
|
109
109
|
collation(options: mongodb.CollationOptions): this;
|
|
@@ -121,8 +121,8 @@ declare module 'mongoose' {
|
|
|
121
121
|
|
|
122
122
|
|
|
123
123
|
/** Executes the aggregate pipeline on the currently bound Model. */
|
|
124
|
-
exec(callback: Callback<
|
|
125
|
-
exec(): Promise<
|
|
124
|
+
exec(callback: Callback<ResultType>): void;
|
|
125
|
+
exec(): Promise<ResultType>;
|
|
126
126
|
|
|
127
127
|
/** Execute the aggregation with explain */
|
|
128
128
|
explain(verbosity: mongodb.ExplainVerbosityLike, callback: Callback<AnyObject>): void;
|
|
@@ -215,7 +215,7 @@ declare module 'mongoose' {
|
|
|
215
215
|
sort(arg: string | Record<string, SortValues> | PipelineStage.Sort['$sort']): this;
|
|
216
216
|
|
|
217
217
|
/** Provides promise for aggregate. */
|
|
218
|
-
then: Promise<
|
|
218
|
+
then: Promise<ResultType>['then'];
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
221
|
* Appends a new $sortByCount operator to this aggregate pipeline. Accepts either a string field name
|
package/types/document.d.ts
CHANGED
|
@@ -28,6 +28,9 @@ declare module 'mongoose' {
|
|
|
28
28
|
/** Assert that a given path or paths is populated. Throws an error if not populated. */
|
|
29
29
|
$assertPopulated<Paths = {}>(path: string | string[], values?: Partial<Paths>): Omit<this, keyof Paths> & Paths;
|
|
30
30
|
|
|
31
|
+
/** Returns a deep clone of this document */
|
|
32
|
+
$clone(): this;
|
|
33
|
+
|
|
31
34
|
/* Get all subdocs (by bfs) */
|
|
32
35
|
$getAllSubdocs(): Document[];
|
|
33
36
|
|
package/types/index.d.ts
CHANGED
|
@@ -305,6 +305,16 @@ declare module 'mongoose' {
|
|
|
305
305
|
post<T = M>(method: 'insertMany' | RegExp, options: SchemaPostOptions, fn: ErrorHandlingMiddlewareFunction<T>): this;
|
|
306
306
|
|
|
307
307
|
/** Defines a pre hook for the model. */
|
|
308
|
+
pre<T = HydratedDocument<DocType, TInstanceMethods>>(
|
|
309
|
+
method: DocumentOrQueryMiddleware | DocumentOrQueryMiddleware[],
|
|
310
|
+
options: SchemaPreOptions & { document: true; query: false; },
|
|
311
|
+
fn: PreMiddlewareFunction<T>
|
|
312
|
+
): this;
|
|
313
|
+
pre<T = Query<any, any>>(
|
|
314
|
+
method: DocumentOrQueryMiddleware | DocumentOrQueryMiddleware[],
|
|
315
|
+
options: SchemaPreOptions & { document: false; query: true; },
|
|
316
|
+
fn: PreMiddlewareFunction<T>
|
|
317
|
+
): this;
|
|
308
318
|
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', fn: PreSaveMiddlewareFunction<T>): this;
|
|
309
319
|
pre<T = HydratedDocument<DocType, TInstanceMethods>>(method: 'save', options: SchemaPreOptions, fn: PreSaveMiddlewareFunction<T>): this;
|
|
310
320
|
pre<T = Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | RegExp, fn: PreMiddlewareFunction<T>): this;
|
|
@@ -83,15 +83,19 @@ type IsPathDefaultUndefined<PathType> = PathType extends { default: undefined }
|
|
|
83
83
|
type IsPathRequired<P, TypeKey extends string = DefaultTypeKey> =
|
|
84
84
|
P extends { required: true | [true, string | undefined] } | ArrayConstructor | any[]
|
|
85
85
|
? true
|
|
86
|
-
: P extends
|
|
87
|
-
?
|
|
86
|
+
: P extends { required: boolean }
|
|
87
|
+
? P extends { required: false }
|
|
88
88
|
? false
|
|
89
89
|
: true
|
|
90
|
-
: P extends (Record<TypeKey, any>)
|
|
91
|
-
? P extends
|
|
92
|
-
?
|
|
93
|
-
:
|
|
94
|
-
:
|
|
90
|
+
: P extends (Record<TypeKey, ArrayConstructor | any[]>)
|
|
91
|
+
? IsPathDefaultUndefined<P> extends true
|
|
92
|
+
? false
|
|
93
|
+
: true
|
|
94
|
+
: P extends (Record<TypeKey, any>)
|
|
95
|
+
? P extends { default: any }
|
|
96
|
+
? IfEquals<P['default'], undefined, false, true>
|
|
97
|
+
: false
|
|
98
|
+
: false;
|
|
95
99
|
|
|
96
100
|
/**
|
|
97
101
|
* @summary Path base type defined by using TypeKey
|
package/types/middlewares.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ declare module 'mongoose' {
|
|
|
2
2
|
|
|
3
3
|
type MongooseDocumentMiddleware = 'validate' | 'save' | 'remove' | 'updateOne' | 'deleteOne' | 'init';
|
|
4
4
|
type MongooseQueryMiddleware = 'count' | 'estimatedDocumentCount' | 'countDocuments' | 'deleteMany' | 'deleteOne' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndRemove' | 'findOneAndReplace' | 'findOneAndUpdate' | 'remove' | 'replaceOne' | 'update' | 'updateOne' | 'updateMany';
|
|
5
|
+
type DocumentOrQueryMiddleware = 'updateOne' | 'deleteOne' | 'remove';
|
|
5
6
|
|
|
6
7
|
type MiddlewareOptions = {
|
|
7
8
|
/**
|
package/types/schemaoptions.d.ts
CHANGED
|
@@ -213,6 +213,12 @@ declare module 'mongoose' {
|
|
|
213
213
|
* Virtual paths.
|
|
214
214
|
*/
|
|
215
215
|
virtuals?: SchemaOptionsVirtualsPropertyType<DocType, TVirtuals, TInstanceMethods>,
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Set to `true` to default to overwriting models with the same name when calling `mongoose.model()`, as opposed to throwing an `OverwriteModelError`.
|
|
219
|
+
* @default false
|
|
220
|
+
*/
|
|
221
|
+
overwriteModels?: boolean;
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
interface DefaultSchemaOptions {
|
package/types/schematypes.d.ts
CHANGED
|
@@ -278,6 +278,9 @@ declare module 'mongoose' {
|
|
|
278
278
|
|
|
279
279
|
/** Adds validator(s) for this document path. */
|
|
280
280
|
validate(obj: RegExp | ((this: DocType, value: any, validatorProperties?: Validator) => any), errorMsg?: string, type?: string): this;
|
|
281
|
+
|
|
282
|
+
/** Default options for this SchemaType */
|
|
283
|
+
defaultOptions?: Record<string, any>;
|
|
281
284
|
}
|
|
282
285
|
|
|
283
286
|
namespace Schema {
|
|
@@ -294,6 +297,9 @@ declare module 'mongoose' {
|
|
|
294
297
|
/** The schematype embedded in this array */
|
|
295
298
|
caster?: SchemaType;
|
|
296
299
|
|
|
300
|
+
/** Default options for this SchemaType */
|
|
301
|
+
defaultOptions: Record<string, any>;
|
|
302
|
+
|
|
297
303
|
/**
|
|
298
304
|
* Adds an enum validator if this is an array of strings or numbers. Equivalent to
|
|
299
305
|
* `SchemaString.prototype.enum()` or `SchemaNumber.prototype.enum()`
|
|
@@ -310,6 +316,9 @@ declare module 'mongoose' {
|
|
|
310
316
|
|
|
311
317
|
/** Configure which values get casted to `false`. */
|
|
312
318
|
static convertToFalse: Set<any>;
|
|
319
|
+
|
|
320
|
+
/** Default options for this SchemaType */
|
|
321
|
+
defaultOptions: Record<string, any>;
|
|
313
322
|
}
|
|
314
323
|
|
|
315
324
|
class Buffer extends SchemaType {
|
|
@@ -321,6 +330,9 @@ declare module 'mongoose' {
|
|
|
321
330
|
* for this buffer. You can find a [list of allowed subtypes here](http://api.mongodb.com/python/current/api/bson/binary.html).
|
|
322
331
|
*/
|
|
323
332
|
subtype(subtype: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128): this;
|
|
333
|
+
|
|
334
|
+
/** Default options for this SchemaType */
|
|
335
|
+
defaultOptions: Record<string, any>;
|
|
324
336
|
}
|
|
325
337
|
|
|
326
338
|
class Date extends SchemaType {
|
|
@@ -335,11 +347,17 @@ declare module 'mongoose' {
|
|
|
335
347
|
|
|
336
348
|
/** Sets a minimum date validator. */
|
|
337
349
|
min(value: NativeDate, message: string): this;
|
|
350
|
+
|
|
351
|
+
/** Default options for this SchemaType */
|
|
352
|
+
defaultOptions: Record<string, any>;
|
|
338
353
|
}
|
|
339
354
|
|
|
340
355
|
class Decimal128 extends SchemaType {
|
|
341
356
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
342
357
|
static schemaName: 'Decimal128';
|
|
358
|
+
|
|
359
|
+
/** Default options for this SchemaType */
|
|
360
|
+
defaultOptions: Record<string, any>;
|
|
343
361
|
}
|
|
344
362
|
|
|
345
363
|
class DocumentArray extends SchemaType implements AcceptsDiscriminator {
|
|
@@ -356,16 +374,25 @@ declare module 'mongoose' {
|
|
|
356
374
|
|
|
357
375
|
/** The constructor used for subdocuments in this array */
|
|
358
376
|
caster?: typeof Types.Subdocument;
|
|
377
|
+
|
|
378
|
+
/** Default options for this SchemaType */
|
|
379
|
+
defaultOptions: Record<string, any>;
|
|
359
380
|
}
|
|
360
381
|
|
|
361
382
|
class Map extends SchemaType {
|
|
362
383
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
363
384
|
static schemaName: 'Map';
|
|
385
|
+
|
|
386
|
+
/** Default options for this SchemaType */
|
|
387
|
+
defaultOptions: Record<string, any>;
|
|
364
388
|
}
|
|
365
389
|
|
|
366
390
|
class Mixed extends SchemaType {
|
|
367
391
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
368
392
|
static schemaName: 'Mixed';
|
|
393
|
+
|
|
394
|
+
/** Default options for this SchemaType */
|
|
395
|
+
defaultOptions: Record<string, any>;
|
|
369
396
|
}
|
|
370
397
|
|
|
371
398
|
class Number extends SchemaType {
|
|
@@ -380,6 +407,9 @@ declare module 'mongoose' {
|
|
|
380
407
|
|
|
381
408
|
/** Sets a minimum number validator. */
|
|
382
409
|
min(value: number, message: string): this;
|
|
410
|
+
|
|
411
|
+
/** Default options for this SchemaType */
|
|
412
|
+
defaultOptions: Record<string, any>;
|
|
383
413
|
}
|
|
384
414
|
|
|
385
415
|
class ObjectId extends SchemaType {
|
|
@@ -388,6 +418,9 @@ declare module 'mongoose' {
|
|
|
388
418
|
|
|
389
419
|
/** Adds an auto-generated ObjectId default if turnOn is true. */
|
|
390
420
|
auto(turnOn: boolean): this;
|
|
421
|
+
|
|
422
|
+
/** Default options for this SchemaType */
|
|
423
|
+
defaultOptions: Record<string, any>;
|
|
391
424
|
}
|
|
392
425
|
|
|
393
426
|
class Subdocument extends SchemaType implements AcceptsDiscriminator {
|
|
@@ -397,6 +430,9 @@ declare module 'mongoose' {
|
|
|
397
430
|
/** The document's schema */
|
|
398
431
|
schema: Schema;
|
|
399
432
|
|
|
433
|
+
/** Default options for this SchemaType */
|
|
434
|
+
defaultOptions: Record<string, any>;
|
|
435
|
+
|
|
400
436
|
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
401
437
|
discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
|
|
402
438
|
}
|
|
@@ -425,11 +461,17 @@ declare module 'mongoose' {
|
|
|
425
461
|
|
|
426
462
|
/** Adds an uppercase [setter](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-set). */
|
|
427
463
|
uppercase(shouldApply?: boolean): this;
|
|
464
|
+
|
|
465
|
+
/** Default options for this SchemaType */
|
|
466
|
+
defaultOptions: Record<string, any>;
|
|
428
467
|
}
|
|
429
468
|
|
|
430
469
|
class UUID extends SchemaType {
|
|
431
470
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
432
471
|
static schemaName: 'UUID';
|
|
472
|
+
|
|
473
|
+
/** Default options for this SchemaType */
|
|
474
|
+
defaultOptions: Record<string, any>;
|
|
433
475
|
}
|
|
434
476
|
}
|
|
435
477
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/*!
|
|
4
|
-
* ignore
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
module.exports = function clearValidating(schema) {
|
|
8
|
-
// `this.$__.validating` tracks whether there are multiple validations running
|
|
9
|
-
// in parallel. We need to clear `this.$__.validating` before post hooks for gh-8597
|
|
10
|
-
const unshift = true;
|
|
11
|
-
schema.s.hooks.post('validate', false, function clearValidatingPostValidate() {
|
|
12
|
-
if (this.$isSubdocument) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
this.$__.validating = null;
|
|
17
|
-
}, unshift);
|
|
18
|
-
|
|
19
|
-
schema.s.hooks.post('validate', false, function clearValidatingPostValidateError(error, res, next) {
|
|
20
|
-
if (this.$isSubdocument) {
|
|
21
|
-
next();
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.$__.validating = null;
|
|
26
|
-
next();
|
|
27
|
-
}, unshift);
|
|
28
|
-
};
|