mongoose 9.2.3 → 9.2.4
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/lib/aggregate.js +41 -41
- package/lib/cast/bigint.js +2 -2
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/double.js +2 -2
- package/lib/cast/int32.js +2 -2
- package/lib/cast/number.js +2 -2
- package/lib/cast/string.js +2 -2
- package/lib/cast.js +6 -6
- package/lib/collection.js +4 -4
- package/lib/connection.js +58 -58
- package/lib/cursor/aggregationCursor.js +6 -6
- package/lib/cursor/queryCursor.js +7 -7
- package/lib/document.js +176 -176
- package/lib/drivers/node-mongodb-native/collection.js +2 -2
- package/lib/drivers/node-mongodb-native/connection.js +8 -8
- package/lib/error/cast.js +2 -2
- package/lib/error/createCollectionsError.js +2 -2
- package/lib/error/divergentArray.js +1 -1
- package/lib/error/eachAsyncMultiError.js +1 -1
- package/lib/error/index.js +2 -2
- package/lib/error/invalidSchemaOption.js +1 -1
- package/lib/error/missingSchema.js +1 -1
- package/lib/error/objectParameter.js +3 -3
- package/lib/error/overwriteModel.js +1 -1
- package/lib/error/setOptionError.js +3 -3
- package/lib/error/strict.js +3 -3
- package/lib/error/strictPopulate.js +2 -2
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +2 -2
- package/lib/error/validator.js +1 -1
- package/lib/error/version.js +2 -2
- package/lib/helpers/buildMiddlewareFilter.js +2 -2
- package/lib/helpers/clone.js +4 -4
- package/lib/helpers/createJSONSchemaTypeDefinition.js +4 -4
- package/lib/helpers/cursor/eachAsync.js +3 -3
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +3 -3
- package/lib/helpers/document/applyTimestamps.js +9 -9
- package/lib/helpers/document/applyVirtuals.js +6 -6
- package/lib/helpers/document/compile.js +10 -10
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +2 -2
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +2 -2
- package/lib/helpers/indexes/isIndexEqual.js +3 -3
- package/lib/helpers/indexes/isIndexSpecEqual.js +3 -3
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +2 -2
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/castBulkWrite.js +2 -2
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +2 -2
- package/lib/helpers/populate/assignVals.js +6 -6
- package/lib/helpers/populate/createPopulateQueryFilter.js +2 -2
- package/lib/helpers/populate/getModelsMapForPopulate.js +12 -12
- package/lib/helpers/populate/getSchemaTypes.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/setPopulatedVirtualValue.js +5 -5
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/query/castUpdate.js +14 -14
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +4 -4
- package/lib/helpers/query/handleImmutable.js +6 -6
- package/lib/helpers/schema/getIndexes.js +1 -1
- package/lib/helpers/schema/getSubdocumentStrictValue.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +3 -3
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/updateValidators.js +2 -2
- package/lib/model.js +263 -263
- package/lib/mongoose.js +54 -54
- package/lib/options/schemaArrayOptions.js +2 -2
- package/lib/options/schemaBufferOptions.js +1 -1
- package/lib/options/schemaNumberOptions.js +3 -3
- package/lib/options/schemaObjectIdOptions.js +2 -2
- package/lib/options/schemaStringOptions.js +6 -6
- package/lib/options/schemaTypeOptions.js +13 -13
- package/lib/options/virtualOptions.js +11 -11
- package/lib/query.js +222 -222
- package/lib/queryHelpers.js +4 -4
- package/lib/schema/array.js +18 -18
- package/lib/schema/bigint.js +13 -13
- package/lib/schema/boolean.js +13 -13
- package/lib/schema/buffer.js +14 -14
- package/lib/schema/date.js +16 -16
- package/lib/schema/decimal128.js +13 -13
- package/lib/schema/documentArray.js +15 -15
- package/lib/schema/documentArrayElement.js +5 -6
- package/lib/schema/double.js +12 -12
- package/lib/schema/int32.js +13 -13
- package/lib/schema/map.js +10 -10
- package/lib/schema/mixed.js +10 -10
- package/lib/schema/number.js +18 -18
- package/lib/schema/objectId.js +14 -14
- package/lib/schema/operators/text.js +3 -3
- package/lib/schema/string.js +17 -17
- package/lib/schema/subdocument.js +13 -13
- package/lib/schema/union.js +3 -3
- package/lib/schema/uuid.js +16 -16
- package/lib/schema.js +76 -76
- package/lib/schemaType.js +62 -62
- package/lib/stateMachine.js +5 -8
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +12 -12
- package/lib/types/arraySubdocument.js +8 -8
- package/lib/types/buffer.js +4 -4
- package/lib/types/documentArray/index.js +1 -1
- package/lib/types/documentArray/methods/index.js +5 -5
- package/lib/types/map.js +3 -3
- package/lib/types/subdocument.js +11 -11
- package/lib/utils.js +45 -45
- package/lib/virtualType.js +18 -18
- package/package.json +8 -5
- package/types/index.d.ts +16 -15
- package/types/inferschematype.d.ts +10 -0
- package/types/models.d.ts +7 -4
- package/types/schemaoptions.d.ts +1 -1
- package/types/virtuals.d.ts +10 -10
package/lib/schema/int32.js
CHANGED
|
@@ -13,9 +13,9 @@ const handleBitwiseOperator = require('./operators/bitwise');
|
|
|
13
13
|
/**
|
|
14
14
|
* Int32 SchemaType constructor.
|
|
15
15
|
*
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
16
|
+
* @param {string} path
|
|
17
|
+
* @param {object} options
|
|
18
|
+
* @param {object} schemaOptions
|
|
19
19
|
* @param {Schema} parentSchema
|
|
20
20
|
* @inherits SchemaType
|
|
21
21
|
* @api public
|
|
@@ -55,8 +55,8 @@ SchemaInt32._cast = castInt32;
|
|
|
55
55
|
* // Make all Int32 fields required by default
|
|
56
56
|
* mongoose.Schema.Types.Int32.set('required', true);
|
|
57
57
|
*
|
|
58
|
-
* @param {
|
|
59
|
-
* @param {
|
|
58
|
+
* @param {string} option The option you'd like to set the value for
|
|
59
|
+
* @param {any} value value for option
|
|
60
60
|
* @return {undefined}
|
|
61
61
|
* @function set
|
|
62
62
|
* @static
|
|
@@ -161,8 +161,8 @@ SchemaInt32.checkRequired = SchemaType.checkRequired;
|
|
|
161
161
|
/**
|
|
162
162
|
* Check if the given value satisfies a required validator.
|
|
163
163
|
*
|
|
164
|
-
* @param {
|
|
165
|
-
* @return {
|
|
164
|
+
* @param {any} value
|
|
165
|
+
* @return {boolean}
|
|
166
166
|
* @api public
|
|
167
167
|
*/
|
|
168
168
|
|
|
@@ -173,8 +173,8 @@ SchemaInt32.prototype.checkRequired = function(value) {
|
|
|
173
173
|
/**
|
|
174
174
|
* Casts to Int32
|
|
175
175
|
*
|
|
176
|
-
* @param {
|
|
177
|
-
* @param {
|
|
176
|
+
* @param {object} value
|
|
177
|
+
* @param {object} model this value is optional
|
|
178
178
|
* @api private
|
|
179
179
|
*/
|
|
180
180
|
|
|
@@ -237,7 +237,7 @@ function handleSingle(val, context) {
|
|
|
237
237
|
/**
|
|
238
238
|
* Casts contents for queries.
|
|
239
239
|
*
|
|
240
|
-
* @param {
|
|
240
|
+
* @param {string} $conditional
|
|
241
241
|
* @param {any} val
|
|
242
242
|
* @api private
|
|
243
243
|
*/
|
|
@@ -267,9 +267,9 @@ SchemaInt32.prototype.castForQuery = function($conditional, val, context) {
|
|
|
267
267
|
/**
|
|
268
268
|
* Returns this schema type's representation in a JSON schema.
|
|
269
269
|
*
|
|
270
|
-
* @param [options]
|
|
271
|
-
* @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
272
|
-
* @returns {
|
|
270
|
+
* @param {object} [options]
|
|
271
|
+
* @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
272
|
+
* @returns {object} JSON schema properties
|
|
273
273
|
*/
|
|
274
274
|
|
|
275
275
|
SchemaInt32.prototype.toJSONSchema = function toJSONSchema(options) {
|
package/lib/schema/map.js
CHANGED
|
@@ -16,9 +16,9 @@ class SchemaMap extends SchemaType {
|
|
|
16
16
|
/**
|
|
17
17
|
* Map SchemaType constructor.
|
|
18
18
|
*
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
19
|
+
* @param {string} path
|
|
20
|
+
* @param {object} options
|
|
21
|
+
* @param {object} schemaOptions
|
|
22
22
|
* @param {Schema} parentSchema
|
|
23
23
|
* @inherits SchemaType
|
|
24
24
|
* @api public
|
|
@@ -34,8 +34,8 @@ class SchemaMap extends SchemaType {
|
|
|
34
34
|
/**
|
|
35
35
|
* Sets a default option for all Map instances.
|
|
36
36
|
*
|
|
37
|
-
* @param {
|
|
38
|
-
* @param {
|
|
37
|
+
* @param {string} option The option you'd like to set the value for
|
|
38
|
+
* @param {any} value value for option
|
|
39
39
|
* @return {undefined}
|
|
40
40
|
* @function set
|
|
41
41
|
* @api public
|
|
@@ -48,8 +48,8 @@ class SchemaMap extends SchemaType {
|
|
|
48
48
|
/**
|
|
49
49
|
* Casts to Map
|
|
50
50
|
*
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {
|
|
51
|
+
* @param {object} value
|
|
52
|
+
* @param {object} model this value is optional
|
|
53
53
|
* @api private
|
|
54
54
|
*/
|
|
55
55
|
|
|
@@ -119,9 +119,9 @@ class SchemaMap extends SchemaType {
|
|
|
119
119
|
/**
|
|
120
120
|
* Returns this schema type's representation in a JSON schema.
|
|
121
121
|
*
|
|
122
|
-
* @param [options]
|
|
123
|
-
* @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
124
|
-
* @returns {
|
|
122
|
+
* @param {object} [options]
|
|
123
|
+
* @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
124
|
+
* @returns {object} JSON schema properties
|
|
125
125
|
*/
|
|
126
126
|
|
|
127
127
|
toJSONSchema(options) {
|
package/lib/schema/mixed.js
CHANGED
|
@@ -12,9 +12,9 @@ const utils = require('../utils');
|
|
|
12
12
|
/**
|
|
13
13
|
* Mixed SchemaType constructor.
|
|
14
14
|
*
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
15
|
+
* @param {string} path
|
|
16
|
+
* @param {object} options
|
|
17
|
+
* @param {object} _schemaOptions
|
|
18
18
|
* @param {Schema} parentSchema
|
|
19
19
|
* @inherits SchemaType
|
|
20
20
|
* @api public
|
|
@@ -86,8 +86,8 @@ SchemaMixed.get = SchemaType.get;
|
|
|
86
86
|
* const User = mongoose.model('User', new Schema({ test: mongoose.Mixed }));
|
|
87
87
|
* new User({ }).validateSync().errors.test.message; // Path `test` is required.
|
|
88
88
|
*
|
|
89
|
-
* @param {
|
|
90
|
-
* @param {
|
|
89
|
+
* @param {string} option The option you'd like to set the value for
|
|
90
|
+
* @param {any} value value for option
|
|
91
91
|
* @return {undefined}
|
|
92
92
|
* @function set
|
|
93
93
|
* @static
|
|
@@ -103,7 +103,7 @@ SchemaMixed.setters = [];
|
|
|
103
103
|
*
|
|
104
104
|
* _this is a no-op_
|
|
105
105
|
*
|
|
106
|
-
* @param {
|
|
106
|
+
* @param {object} value to cast
|
|
107
107
|
* @api private
|
|
108
108
|
*/
|
|
109
109
|
|
|
@@ -117,7 +117,7 @@ SchemaMixed.prototype.cast = function(val) {
|
|
|
117
117
|
/**
|
|
118
118
|
* Casts contents for queries.
|
|
119
119
|
*
|
|
120
|
-
* @param {
|
|
120
|
+
* @param {string} $cond
|
|
121
121
|
* @param {any} [val]
|
|
122
122
|
* @api private
|
|
123
123
|
*/
|
|
@@ -129,9 +129,9 @@ SchemaMixed.prototype.castForQuery = function($cond, val) {
|
|
|
129
129
|
/**
|
|
130
130
|
* Returns this schema type's representation in a JSON schema.
|
|
131
131
|
*
|
|
132
|
-
* @param [options]
|
|
133
|
-
* @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
134
|
-
* @returns {
|
|
132
|
+
* @param {object} [options]
|
|
133
|
+
* @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
134
|
+
* @returns {object} JSON schema properties
|
|
135
135
|
*/
|
|
136
136
|
|
|
137
137
|
// eslint-disable-next-line no-unused-vars
|
package/lib/schema/number.js
CHANGED
|
@@ -17,9 +17,9 @@ const CastError = SchemaType.CastError;
|
|
|
17
17
|
/**
|
|
18
18
|
* Number SchemaType constructor.
|
|
19
19
|
*
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {
|
|
20
|
+
* @param {string} key
|
|
21
|
+
* @param {object} options
|
|
22
|
+
* @param {object} schemaOptions
|
|
23
23
|
* @param {Schema} parentSchema
|
|
24
24
|
* @inherits SchemaType
|
|
25
25
|
* @api public
|
|
@@ -61,8 +61,8 @@ SchemaNumber.get = SchemaType.get;
|
|
|
61
61
|
* const Order = mongoose.model('Order', new Schema({ amount: Number }));
|
|
62
62
|
* new Order({ amount: -10 }).validateSync().errors.amount.message; // Path `amount` must be larger than 0.
|
|
63
63
|
*
|
|
64
|
-
* @param {
|
|
65
|
-
* @param {
|
|
64
|
+
* @param {string} option The option you'd like to set the value for
|
|
65
|
+
* @param {any} value value for option
|
|
66
66
|
* @return {undefined}
|
|
67
67
|
* @function set
|
|
68
68
|
* @static
|
|
@@ -163,9 +163,9 @@ SchemaNumber.checkRequired = SchemaType.checkRequired;
|
|
|
163
163
|
/**
|
|
164
164
|
* Check if the given value satisfies a required validator.
|
|
165
165
|
*
|
|
166
|
-
* @param {
|
|
166
|
+
* @param {any} value
|
|
167
167
|
* @param {Document} doc
|
|
168
|
-
* @return {
|
|
168
|
+
* @return {boolean}
|
|
169
169
|
* @api public
|
|
170
170
|
*/
|
|
171
171
|
|
|
@@ -207,8 +207,8 @@ SchemaNumber.prototype.checkRequired = function checkRequired(value, doc) {
|
|
|
207
207
|
* console.log(String(err)) // ValidationError: The value of path `n` (4) is beneath the limit (10).
|
|
208
208
|
* })
|
|
209
209
|
*
|
|
210
|
-
* @param {
|
|
211
|
-
* @param {
|
|
210
|
+
* @param {number} value minimum number
|
|
211
|
+
* @param {string} [message] optional custom error message
|
|
212
212
|
* @return {SchemaType} this
|
|
213
213
|
* @see Customized Error Messages https://mongoosejs.com/docs/api/error.html#Error.messages
|
|
214
214
|
* @api public
|
|
@@ -261,8 +261,8 @@ SchemaNumber.prototype.min = function(value, message) {
|
|
|
261
261
|
* console.log(String(err)) // ValidationError: The value of path `n` (4) exceeds the limit (10).
|
|
262
262
|
* })
|
|
263
263
|
*
|
|
264
|
-
* @param {
|
|
265
|
-
* @param {
|
|
264
|
+
* @param {number} maximum number
|
|
265
|
+
* @param {string} [message] optional custom error message
|
|
266
266
|
* @return {SchemaType} this
|
|
267
267
|
* @see Customized Error Messages https://mongoosejs.com/docs/api/error.html#Error.messages
|
|
268
268
|
* @api public
|
|
@@ -306,7 +306,7 @@ SchemaNumber.prototype.max = function(value, message) {
|
|
|
306
306
|
* await m.save(); // succeeds
|
|
307
307
|
*
|
|
308
308
|
* @param {Array} values allowed values
|
|
309
|
-
* @param {
|
|
309
|
+
* @param {string} [message] optional custom error message
|
|
310
310
|
* @return {SchemaType} this
|
|
311
311
|
* @see Customized Error Messages https://mongoosejs.com/docs/api/error.html#Error.messages
|
|
312
312
|
* @api public
|
|
@@ -381,9 +381,9 @@ SchemaNumber.prototype.enum = function(values, message) {
|
|
|
381
381
|
/**
|
|
382
382
|
* Casts to number
|
|
383
383
|
*
|
|
384
|
-
* @param {
|
|
384
|
+
* @param {object} value value to cast
|
|
385
385
|
* @param {Document} doc document that triggers the casting
|
|
386
|
-
* @param {
|
|
386
|
+
* @param {boolean} init
|
|
387
387
|
* @api private
|
|
388
388
|
*/
|
|
389
389
|
|
|
@@ -463,7 +463,7 @@ Object.defineProperty(SchemaNumber.prototype, '$conditionalHandlers', {
|
|
|
463
463
|
/**
|
|
464
464
|
* Casts contents for queries.
|
|
465
465
|
*
|
|
466
|
-
* @param {
|
|
466
|
+
* @param {string} $conditional
|
|
467
467
|
* @param {any} [value]
|
|
468
468
|
* @api private
|
|
469
469
|
*/
|
|
@@ -493,9 +493,9 @@ SchemaNumber.prototype.castForQuery = function($conditional, val, context) {
|
|
|
493
493
|
/**
|
|
494
494
|
* Returns this schema type's representation in a JSON schema.
|
|
495
495
|
*
|
|
496
|
-
* @param [options]
|
|
497
|
-
* @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
498
|
-
* @returns {
|
|
496
|
+
* @param {object} [options]
|
|
497
|
+
* @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
498
|
+
* @returns {object} JSON schema properties
|
|
499
499
|
*/
|
|
500
500
|
|
|
501
501
|
SchemaNumber.prototype.toJSONSchema = function toJSONSchema(options) {
|
package/lib/schema/objectId.js
CHANGED
|
@@ -19,9 +19,9 @@ let Document;
|
|
|
19
19
|
/**
|
|
20
20
|
* ObjectId SchemaType constructor.
|
|
21
21
|
*
|
|
22
|
-
* @param {
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {
|
|
22
|
+
* @param {string} key
|
|
23
|
+
* @param {object} options
|
|
24
|
+
* @param {object} schemaOptions
|
|
25
25
|
* @param {Schema} parentSchema
|
|
26
26
|
* @inherits SchemaType
|
|
27
27
|
* @api public
|
|
@@ -87,8 +87,8 @@ SchemaObjectId.get = SchemaType.get;
|
|
|
87
87
|
* const Order = mongoose.model('Order', new Schema({ userId: ObjectId }));
|
|
88
88
|
* new Order({ }).validateSync().errors.userId.message; // Path `userId` is required.
|
|
89
89
|
*
|
|
90
|
-
* @param {
|
|
91
|
-
* @param {
|
|
90
|
+
* @param {string} option The option you'd like to set the value for
|
|
91
|
+
* @param {any} value value for option
|
|
92
92
|
* @return {undefined}
|
|
93
93
|
* @function set
|
|
94
94
|
* @static
|
|
@@ -101,7 +101,7 @@ SchemaObjectId.setters = [];
|
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* Adds an auto-generated ObjectId default if turnOn is true.
|
|
104
|
-
* @param {
|
|
104
|
+
* @param {boolean} turnOn auto generated ObjectId defaults
|
|
105
105
|
* @api public
|
|
106
106
|
* @return {SchemaType} this
|
|
107
107
|
*/
|
|
@@ -197,9 +197,9 @@ SchemaObjectId.checkRequired = SchemaType.checkRequired;
|
|
|
197
197
|
/**
|
|
198
198
|
* Check if the given value satisfies a required validator.
|
|
199
199
|
*
|
|
200
|
-
* @param {
|
|
200
|
+
* @param {any} value
|
|
201
201
|
* @param {Document} doc
|
|
202
|
-
* @return {
|
|
202
|
+
* @return {boolean}
|
|
203
203
|
* @api public
|
|
204
204
|
*/
|
|
205
205
|
|
|
@@ -220,9 +220,9 @@ SchemaObjectId.prototype.checkRequired = function checkRequired(value, doc) {
|
|
|
220
220
|
/**
|
|
221
221
|
* Casts to ObjectId
|
|
222
222
|
*
|
|
223
|
-
* @param {
|
|
224
|
-
* @param {
|
|
225
|
-
* @param {
|
|
223
|
+
* @param {object} value
|
|
224
|
+
* @param {object} doc
|
|
225
|
+
* @param {boolean} init whether this is an initialization cast
|
|
226
226
|
* @api private
|
|
227
227
|
*/
|
|
228
228
|
|
|
@@ -311,9 +311,9 @@ function resetId(v) {
|
|
|
311
311
|
/**
|
|
312
312
|
* Returns this schema type's representation in a JSON schema.
|
|
313
313
|
*
|
|
314
|
-
* @param [options]
|
|
315
|
-
* @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
316
|
-
* @returns {
|
|
314
|
+
* @param {object} [options]
|
|
315
|
+
* @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
316
|
+
* @returns {object} JSON schema properties
|
|
317
317
|
* @api public
|
|
318
318
|
*/
|
|
319
319
|
|
|
@@ -8,9 +8,9 @@ const castString = require('../../cast/string');
|
|
|
8
8
|
* Casts val to an object suitable for `$text`. Throws an error if the object
|
|
9
9
|
* can't be casted.
|
|
10
10
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {
|
|
13
|
-
* @return {
|
|
11
|
+
* @param {any} val value to cast
|
|
12
|
+
* @param {string} [path] path to associate with any errors that occurred
|
|
13
|
+
* @return {object} casted object
|
|
14
14
|
* @see https://www.mongodb.com/docs/manual/reference/operator/query/text/
|
|
15
15
|
* @api private
|
|
16
16
|
*/
|
package/lib/schema/string.js
CHANGED
|
@@ -17,9 +17,9 @@ const CastError = SchemaType.CastError;
|
|
|
17
17
|
/**
|
|
18
18
|
* String SchemaType constructor.
|
|
19
19
|
*
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {
|
|
20
|
+
* @param {string} key
|
|
21
|
+
* @param {object} options
|
|
22
|
+
* @param {object} schemaOptions
|
|
23
23
|
* @param {Schema} parentSchema
|
|
24
24
|
* @inherits SchemaType
|
|
25
25
|
* @api public
|
|
@@ -136,8 +136,8 @@ SchemaString.get = SchemaType.get;
|
|
|
136
136
|
* const User = mongoose.model('User', new Schema({ name: String }));
|
|
137
137
|
* new User({ name: ' John Doe ' }).name; // 'John Doe'
|
|
138
138
|
*
|
|
139
|
-
* @param {
|
|
140
|
-
* @param {
|
|
139
|
+
* @param {string} option The option you'd like to set the value for
|
|
140
|
+
* @param {any} value value for option
|
|
141
141
|
* @return {undefined}
|
|
142
142
|
* @function set
|
|
143
143
|
* @static
|
|
@@ -204,7 +204,7 @@ SchemaString.checkRequired = SchemaType.checkRequired;
|
|
|
204
204
|
* await m.save();
|
|
205
205
|
* // success
|
|
206
206
|
*
|
|
207
|
-
* @param {...
|
|
207
|
+
* @param {...string|object} [args] enumeration values
|
|
208
208
|
* @return {SchemaType} this
|
|
209
209
|
* @see Customized Error Messages https://mongoosejs.com/docs/api/error.html#Error.messages
|
|
210
210
|
* @see Enums in JavaScript https://masteringjs.io/tutorials/fundamentals/enum
|
|
@@ -402,8 +402,8 @@ SchemaString.prototype.trim = function(shouldTrim) {
|
|
|
402
402
|
* console.log(String(err)) // ValidationError: The value of path `postalCode` (`9512`) is shorter than the minimum length (5).
|
|
403
403
|
* })
|
|
404
404
|
*
|
|
405
|
-
* @param {
|
|
406
|
-
* @param {
|
|
405
|
+
* @param {number} value minimum string length
|
|
406
|
+
* @param {string} [message] optional custom error message
|
|
407
407
|
* @return {SchemaType} this
|
|
408
408
|
* @see Customized Error Messages https://mongoosejs.com/docs/api/error.html#Error.messages
|
|
409
409
|
* @api public
|
|
@@ -458,8 +458,8 @@ SchemaString.prototype.minLength = SchemaString.prototype.minlength;
|
|
|
458
458
|
* console.log(String(err)) // ValidationError: The value of path `postalCode` (`9512512345`) exceeds the maximum allowed length (9).
|
|
459
459
|
* })
|
|
460
460
|
*
|
|
461
|
-
* @param {
|
|
462
|
-
* @param {
|
|
461
|
+
* @param {number} value maximum string length
|
|
462
|
+
* @param {string} [message] optional custom error message
|
|
463
463
|
* @return {SchemaType} this
|
|
464
464
|
* @see Customized Error Messages https://mongoosejs.com/docs/api/error.html#Error.messages
|
|
465
465
|
* @api public
|
|
@@ -522,7 +522,7 @@ SchemaString.prototype.maxLength = SchemaString.prototype.maxlength;
|
|
|
522
522
|
* const s = new Schema({ name: { type: String, match: /^a/, required: true }})
|
|
523
523
|
*
|
|
524
524
|
* @param {RegExp} regExp regular expression to test against
|
|
525
|
-
* @param {
|
|
525
|
+
* @param {string} [message] optional custom error message
|
|
526
526
|
* @return {SchemaType} this
|
|
527
527
|
* @see Customized Error Messages https://mongoosejs.com/docs/api/error.html#Error.messages
|
|
528
528
|
* @api public
|
|
@@ -563,9 +563,9 @@ SchemaString.prototype.match = function match(regExp, message) {
|
|
|
563
563
|
* has positive length. The `required` validator **will** fail for empty
|
|
564
564
|
* strings.
|
|
565
565
|
*
|
|
566
|
-
* @param {
|
|
566
|
+
* @param {any} value
|
|
567
567
|
* @param {Document} doc
|
|
568
|
-
* @return {
|
|
568
|
+
* @return {boolean}
|
|
569
569
|
* @api public
|
|
570
570
|
*/
|
|
571
571
|
|
|
@@ -680,7 +680,7 @@ Object.defineProperty(SchemaString.prototype, '$conditionalHandlers', {
|
|
|
680
680
|
/**
|
|
681
681
|
* Casts contents for queries.
|
|
682
682
|
*
|
|
683
|
-
* @param {
|
|
683
|
+
* @param {string} $conditional
|
|
684
684
|
* @param {any} [val]
|
|
685
685
|
* @api private
|
|
686
686
|
*/
|
|
@@ -712,9 +712,9 @@ SchemaString.prototype.castForQuery = function($conditional, val, context) {
|
|
|
712
712
|
/**
|
|
713
713
|
* Returns this schema type's representation in a JSON schema.
|
|
714
714
|
*
|
|
715
|
-
* @param [options]
|
|
716
|
-
* @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
717
|
-
* @returns {
|
|
715
|
+
* @param {object} [options]
|
|
716
|
+
* @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
717
|
+
* @returns {object} JSON schema properties
|
|
718
718
|
*/
|
|
719
719
|
|
|
720
720
|
SchemaString.prototype.toJSONSchema = function toJSONSchema(options) {
|
|
@@ -30,8 +30,8 @@ module.exports = SchemaSubdocument;
|
|
|
30
30
|
* Single nested subdocument SchemaType constructor.
|
|
31
31
|
*
|
|
32
32
|
* @param {Schema} schema
|
|
33
|
-
* @param {
|
|
34
|
-
* @param {
|
|
33
|
+
* @param {string} path
|
|
34
|
+
* @param {object} options
|
|
35
35
|
* @param {Schema} parentSchema
|
|
36
36
|
* @inherits SchemaType
|
|
37
37
|
* @api public
|
|
@@ -127,7 +127,7 @@ const $conditionalHandlers = { ...SchemaType.prototype.$conditionalHandlers };
|
|
|
127
127
|
* locations for use with $geoWithin.
|
|
128
128
|
* https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
|
|
129
129
|
*
|
|
130
|
-
* @param {
|
|
130
|
+
* @param {object} val
|
|
131
131
|
* @api private
|
|
132
132
|
*/
|
|
133
133
|
|
|
@@ -171,7 +171,7 @@ Object.defineProperty(SchemaSubdocument.prototype, '$conditionalHandlers', {
|
|
|
171
171
|
/**
|
|
172
172
|
* Casts contents
|
|
173
173
|
*
|
|
174
|
-
* @param {
|
|
174
|
+
* @param {object} value
|
|
175
175
|
* @api private
|
|
176
176
|
*/
|
|
177
177
|
|
|
@@ -325,11 +325,11 @@ SchemaSubdocument.prototype.doValidateSync = function(value, scope, options) {
|
|
|
325
325
|
* const singleNestedPath = parentSchema.path('shape');
|
|
326
326
|
* singleNestedPath.discriminator('Circle', Schema({ radius: Number }));
|
|
327
327
|
*
|
|
328
|
-
* @param {
|
|
328
|
+
* @param {string} name
|
|
329
329
|
* @param {Schema} schema fields to add to the schema for instances of this sub-class
|
|
330
|
-
* @param {
|
|
331
|
-
* @param {
|
|
332
|
-
* @param {
|
|
330
|
+
* @param {object|string} [options] If string, same as `options.value`.
|
|
331
|
+
* @param {string} [options.value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
|
|
332
|
+
* @param {boolean} [options.clone=true] By default, `discriminator()` clones the given `schema`. Set to `false` to skip cloning.
|
|
333
333
|
* @return {Function} the constructor Mongoose will use for creating instances of this discriminator model
|
|
334
334
|
* @see discriminators https://mongoosejs.com/docs/discriminators.html
|
|
335
335
|
* @api public
|
|
@@ -367,8 +367,8 @@ SchemaSubdocument.defaultOptions = {};
|
|
|
367
367
|
* // Make all subdocuments required by default.
|
|
368
368
|
* mongoose.Schema.Types.Subdocument.set('required', true);
|
|
369
369
|
*
|
|
370
|
-
* @param {
|
|
371
|
-
* @param {
|
|
370
|
+
* @param {string} option The option you'd like to set the value for
|
|
371
|
+
* @param {any} value value for option
|
|
372
372
|
* @return {void}
|
|
373
373
|
* @function set
|
|
374
374
|
* @static
|
|
@@ -422,9 +422,9 @@ SchemaSubdocument.prototype.clone = function() {
|
|
|
422
422
|
/**
|
|
423
423
|
* Returns this schema type's representation in a JSON schema.
|
|
424
424
|
*
|
|
425
|
-
* @param [options]
|
|
426
|
-
* @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
427
|
-
* @returns {
|
|
425
|
+
* @param {object} [options]
|
|
426
|
+
* @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
427
|
+
* @returns {object} JSON schema properties
|
|
428
428
|
*/
|
|
429
429
|
|
|
430
430
|
SchemaSubdocument.prototype.toJSONSchema = function toJSONSchema(options) {
|
package/lib/schema/union.js
CHANGED
|
@@ -17,9 +17,9 @@ class Union extends SchemaType {
|
|
|
17
17
|
/**
|
|
18
18
|
* Create a Union schema type.
|
|
19
19
|
*
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {
|
|
20
|
+
* @param {string} key the path in the schema for this schema type
|
|
21
|
+
* @param {object} options SchemaType-specific options (must have 'of' as array)
|
|
22
|
+
* @param {object} schemaOptions additional options from the schema this schematype belongs to
|
|
23
23
|
* @param {Schema} parentSchema the schema this schematype belongs to
|
|
24
24
|
*/
|
|
25
25
|
constructor(key, options, schemaOptions, parentSchema) {
|
package/lib/schema/uuid.js
CHANGED
|
@@ -15,8 +15,8 @@ const UUID_FORMAT = castUUID.UUID_FORMAT;
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Convert binary to a uuid string
|
|
18
|
-
* @param {Buffer|Binary|
|
|
19
|
-
* @returns {
|
|
18
|
+
* @param {Buffer|Binary|string} uuidBin The value to process
|
|
19
|
+
* @returns {string} The completed uuid-string
|
|
20
20
|
* @api private
|
|
21
21
|
*/
|
|
22
22
|
function binaryToString(uuidBin) {
|
|
@@ -33,9 +33,9 @@ function binaryToString(uuidBin) {
|
|
|
33
33
|
/**
|
|
34
34
|
* UUIDv1 SchemaType constructor.
|
|
35
35
|
*
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {
|
|
38
|
-
* @param {
|
|
36
|
+
* @param {string} key
|
|
37
|
+
* @param {object} options
|
|
38
|
+
* @param {object} _schemaOptions
|
|
39
39
|
* @param {Schema} parentSchema
|
|
40
40
|
* @inherits SchemaType
|
|
41
41
|
* @api public
|
|
@@ -98,8 +98,8 @@ SchemaUUID.get = SchemaType.get;
|
|
|
98
98
|
* const User = mongoose.model('User', new Schema({ test: mongoose.UUID }));
|
|
99
99
|
* new User({ }).validateSync().errors.test.message; // Path `test` is required.
|
|
100
100
|
*
|
|
101
|
-
* @param {
|
|
102
|
-
* @param {
|
|
101
|
+
* @param {string} option The option you'd like to set the value for
|
|
102
|
+
* @param {any} value value for option
|
|
103
103
|
* @return {undefined}
|
|
104
104
|
* @function set
|
|
105
105
|
* @static
|
|
@@ -166,8 +166,8 @@ SchemaUUID.checkRequired = SchemaType.checkRequired;
|
|
|
166
166
|
/**
|
|
167
167
|
* Check if the given value satisfies a required validator.
|
|
168
168
|
*
|
|
169
|
-
* @param {
|
|
170
|
-
* @return {
|
|
169
|
+
* @param {any} value
|
|
170
|
+
* @return {boolean}
|
|
171
171
|
* @api public
|
|
172
172
|
*/
|
|
173
173
|
|
|
@@ -181,9 +181,9 @@ SchemaUUID.prototype.checkRequired = function checkRequired(value) {
|
|
|
181
181
|
/**
|
|
182
182
|
* Casts to UUID
|
|
183
183
|
*
|
|
184
|
-
* @param {
|
|
185
|
-
* @param {
|
|
186
|
-
* @param {
|
|
184
|
+
* @param {object} value
|
|
185
|
+
* @param {object} doc
|
|
186
|
+
* @param {boolean} init whether this is an initialization cast
|
|
187
187
|
* @api private
|
|
188
188
|
*/
|
|
189
189
|
|
|
@@ -257,7 +257,7 @@ Object.defineProperty(SchemaUUID.prototype, '$conditionalHandlers', {
|
|
|
257
257
|
/**
|
|
258
258
|
* Casts contents for queries.
|
|
259
259
|
*
|
|
260
|
-
* @param {
|
|
260
|
+
* @param {string} $conditional
|
|
261
261
|
* @param {any} val
|
|
262
262
|
* @api private
|
|
263
263
|
*/
|
|
@@ -284,9 +284,9 @@ SchemaUUID.prototype.castForQuery = function($conditional, val, context) {
|
|
|
284
284
|
/**
|
|
285
285
|
* Returns this schema type's representation in a JSON schema.
|
|
286
286
|
*
|
|
287
|
-
* @param [options]
|
|
288
|
-
* @param [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
289
|
-
* @returns {
|
|
287
|
+
* @param {object} [options]
|
|
288
|
+
* @param {boolean} [options.useBsonType=false] If true, return a representation with `bsonType` for use with MongoDB's `$jsonSchema`.
|
|
289
|
+
* @returns {object} JSON schema properties
|
|
290
290
|
*/
|
|
291
291
|
|
|
292
292
|
SchemaUUID.prototype.toJSONSchema = function toJSONSchema(options) {
|