mongoose 6.2.9 → 6.3.0

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/browser.umd.js +2 -1693
  3. package/lib/aggregate.js +59 -67
  4. package/lib/browser.js +4 -4
  5. package/lib/connection.js +21 -21
  6. package/lib/cursor/AggregationCursor.js +2 -2
  7. package/lib/cursor/ChangeStream.js +42 -2
  8. package/lib/cursor/QueryCursor.js +5 -3
  9. package/lib/document.js +39 -46
  10. package/lib/error/eachAsyncMultiError.js +41 -0
  11. package/lib/error/index.js +2 -2
  12. package/lib/helpers/cursor/eachAsync.js +44 -12
  13. package/lib/helpers/indexes/applySchemaCollation.js +13 -0
  14. package/lib/helpers/indexes/isTextIndex.js +16 -0
  15. package/lib/helpers/model/discriminator.js +1 -3
  16. package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  17. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  18. package/lib/helpers/query/applyGlobalOption.js +29 -0
  19. package/lib/helpers/query/castUpdate.js +3 -1
  20. package/lib/helpers/update/applyTimestampsToChildren.js +2 -2
  21. package/lib/helpers/update/applyTimestampsToUpdate.js +0 -1
  22. package/lib/index.js +33 -26
  23. package/lib/model.js +88 -90
  24. package/lib/options/SchemaArrayOptions.js +2 -2
  25. package/lib/options/SchemaBufferOptions.js +1 -1
  26. package/lib/options/SchemaDateOptions.js +2 -2
  27. package/lib/options/SchemaDocumentArrayOptions.js +3 -3
  28. package/lib/options/SchemaMapOptions.js +2 -2
  29. package/lib/options/SchemaNumberOptions.js +3 -3
  30. package/lib/options/SchemaObjectIdOptions.js +2 -2
  31. package/lib/options/SchemaStringOptions.js +1 -1
  32. package/lib/options/SchemaSubdocumentOptions.js +2 -2
  33. package/lib/options/SchemaTypeOptions.js +3 -3
  34. package/lib/query.js +273 -249
  35. package/lib/schema/SubdocumentPath.js +4 -3
  36. package/lib/schema/array.js +2 -2
  37. package/lib/schema/boolean.js +4 -4
  38. package/lib/schema/buffer.js +3 -3
  39. package/lib/schema/date.js +7 -7
  40. package/lib/schema/decimal128.js +2 -2
  41. package/lib/schema/documentarray.js +3 -3
  42. package/lib/schema/mixed.js +2 -2
  43. package/lib/schema/number.js +6 -6
  44. package/lib/schema/objectid.js +4 -7
  45. package/lib/schema/string.js +38 -16
  46. package/lib/schema.js +144 -30
  47. package/lib/schematype.js +75 -68
  48. package/lib/types/ArraySubdocument.js +1 -1
  49. package/lib/types/DocumentArray/methods/index.js +2 -2
  50. package/lib/types/array/index.js +1 -1
  51. package/lib/types/array/methods/index.js +13 -13
  52. package/lib/types/buffer.js +1 -1
  53. package/lib/types/decimal128.js +1 -1
  54. package/lib/types/objectid.js +1 -1
  55. package/lib/types/subdocument.js +31 -2
  56. package/lib/validoptions.js +1 -0
  57. package/lib/virtualtype.js +3 -3
  58. package/package.json +19 -13
  59. package/tools/repl.js +2 -1
  60. package/types/aggregate.d.ts +223 -0
  61. package/types/cursor.d.ts +10 -4
  62. package/types/index.d.ts +194 -209
  63. package/types/mongooseoptions.d.ts +10 -4
  64. package/lib/helpers/query/applyGlobalMaxTimeMS.js +0 -15
@@ -167,10 +167,11 @@ SubdocumentPath.prototype.cast = function(val, doc, init, priorVal, options) {
167
167
  const path = this.path;
168
168
  const selected = Object.keys(parentSelected).reduce((obj, key) => {
169
169
  if (key.startsWith(path + '.')) {
170
+ obj = obj || {};
170
171
  obj[key.substring(path.length + 1)] = parentSelected[key];
171
172
  }
172
173
  return obj;
173
- }, {});
174
+ }, null);
174
175
  options = Object.assign({}, options, { priorDoc: priorVal });
175
176
  if (init) {
176
177
  subdoc = new Constructor(void 0, selected, doc);
@@ -283,7 +284,7 @@ SubdocumentPath.prototype.doValidateSync = function(value, scope, options) {
283
284
  /**
284
285
  * Adds a discriminator to this single nested subdocument.
285
286
  *
286
- * ####Example:
287
+ * #### Example:
287
288
  * const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
288
289
  * const schema = Schema({ shape: shapeSchema });
289
290
  *
@@ -321,7 +322,7 @@ SubdocumentPath.prototype.discriminator = function(name, schema, options) {
321
322
  /**
322
323
  * Sets a default option for all SubdocumentPath instances.
323
324
  *
324
- * ####Example:
325
+ * #### Example:
325
326
  *
326
327
  * // Make all numbers have option `min` equal to 0.
327
328
  * mongoose.Schema.Embedded.set('required', true);
@@ -153,7 +153,7 @@ SchemaArray.defaultOptions = {};
153
153
  /**
154
154
  * Sets a default option for all Array instances.
155
155
  *
156
- * ####Example:
156
+ * #### Example:
157
157
  *
158
158
  * // Make all Array instances have `required` of true by default.
159
159
  * mongoose.Schema.Array.set('required', true);
@@ -186,7 +186,7 @@ SchemaArray._checkRequired = SchemaType.prototype.checkRequired;
186
186
  * Override the function the required validator uses to check whether an array
187
187
  * passes the `required` check.
188
188
  *
189
- * ####Example:
189
+ * #### Example:
190
190
  *
191
191
  * // Require non-empty array to pass `required` check
192
192
  * mongoose.Schema.Types.Array.checkRequired(v => Array.isArray(v) && v.length);
@@ -47,7 +47,7 @@ SchemaBoolean._cast = castBoolean;
47
47
  /**
48
48
  * Sets a default option for all Boolean instances.
49
49
  *
50
- * ####Example:
50
+ * #### Example:
51
51
  *
52
52
  * // Make all booleans have `default` of false.
53
53
  * mongoose.Schema.Boolean.set('default', false);
@@ -68,7 +68,7 @@ SchemaBoolean.set = SchemaType.set;
68
68
  /**
69
69
  * Get/set the function used to cast arbitrary values to booleans.
70
70
  *
71
- * ####Example:
71
+ * #### Example:
72
72
  *
73
73
  * // Make Mongoose cast empty string '' to false.
74
74
  * const original = mongoose.Schema.Boolean.cast();
@@ -148,7 +148,7 @@ SchemaBoolean.prototype.checkRequired = function(value) {
148
148
  /**
149
149
  * Configure which values get casted to `true`.
150
150
  *
151
- * ####Example:
151
+ * #### Example:
152
152
  *
153
153
  * const M = mongoose.model('Test', new Schema({ b: Boolean }));
154
154
  * new M({ b: 'affirmative' }).b; // undefined
@@ -168,7 +168,7 @@ Object.defineProperty(SchemaBoolean, 'convertToTrue', {
168
168
  /**
169
169
  * Configure which values get casted to `false`.
170
170
  *
171
- * ####Example:
171
+ * #### Example:
172
172
  *
173
173
  * const M = mongoose.model('Test', new Schema({ b: Boolean }));
174
174
  * new M({ b: 'nay' }).b; // undefined
@@ -52,7 +52,7 @@ SchemaBuffer._checkRequired = v => !!(v && v.length);
52
52
  /**
53
53
  * Sets a default option for all Buffer instances.
54
54
  *
55
- * ####Example:
55
+ * #### Example:
56
56
  *
57
57
  * // Make all buffers have `required` of true by default.
58
58
  * mongoose.Schema.Buffer.set('required', true);
@@ -74,7 +74,7 @@ SchemaBuffer.set = SchemaType.set;
74
74
  * Override the function the required validator uses to check whether a string
75
75
  * passes the `required` check.
76
76
  *
77
- * ####Example:
77
+ * #### Example:
78
78
  *
79
79
  * // Allow empty strings to pass `required` check
80
80
  * mongoose.Schema.Types.String.checkRequired(v => v != null);
@@ -204,7 +204,7 @@ SchemaBuffer.prototype.cast = function(value, doc, init) {
204
204
  * Sets the default [subtype](https://studio3t.com/whats-new/best-practices-uuid-mongodb/)
205
205
  * for this buffer. You can find a [list of allowed subtypes here](https://api.mongodb.com/python/current/api/bson/binary.html).
206
206
  *
207
- * ####Example:
207
+ * #### Example:
208
208
  *
209
209
  * const s = new Schema({ uuid: { type: Buffer, subtype: 4 });
210
210
  * const M = db.model('M', s);
@@ -52,7 +52,7 @@ SchemaDate._cast = castDate;
52
52
  /**
53
53
  * Sets a default option for all Date instances.
54
54
  *
55
- * ####Example:
55
+ * #### Example:
56
56
  *
57
57
  * // Make all dates have `required` of true by default.
58
58
  * mongoose.Schema.Date.set('required', true);
@@ -73,7 +73,7 @@ SchemaDate.set = SchemaType.set;
73
73
  /**
74
74
  * Get/set the function used to cast arbitrary values to dates.
75
75
  *
76
- * ####Example:
76
+ * #### Example:
77
77
  *
78
78
  * // Mongoose converts empty string '' into `null` for date types. You
79
79
  * // can create a custom caster to disable it.
@@ -122,14 +122,14 @@ SchemaDate._defaultCaster = v => {
122
122
  * This sets the `expireAfterSeconds` index option available in MongoDB >= 2.1.2.
123
123
  * This index type is only compatible with Date types.
124
124
  *
125
- * ####Example:
125
+ * #### Example:
126
126
  *
127
127
  * // expire in 24 hours
128
128
  * new Schema({ createdAt: { type: Date, expires: 60*60*24 }});
129
129
  *
130
130
  * `expires` utilizes the `ms` module from [guille](https://github.com/guille/) allowing us to use a friendlier syntax:
131
131
  *
132
- * ####Example:
132
+ * #### Example:
133
133
  *
134
134
  * // expire in 24 hours
135
135
  * new Schema({ createdAt: { type: Date, expires: '24h' }});
@@ -167,7 +167,7 @@ SchemaDate._checkRequired = v => v instanceof Date;
167
167
  * Override the function the required validator uses to check whether a string
168
168
  * passes the `required` check.
169
169
  *
170
- * ####Example:
170
+ * #### Example:
171
171
  *
172
172
  * // Allow empty strings to pass `required` check
173
173
  * mongoose.Schema.Types.String.checkRequired(v => v != null);
@@ -210,7 +210,7 @@ SchemaDate.prototype.checkRequired = function(value, doc) {
210
210
  /**
211
211
  * Sets a minimum date validator.
212
212
  *
213
- * ####Example:
213
+ * #### Example:
214
214
  *
215
215
  * const s = new Schema({ d: { type: Date, min: Date('1970-01-01') })
216
216
  * const M = db.model('M', s)
@@ -272,7 +272,7 @@ SchemaDate.prototype.min = function(value, message) {
272
272
  /**
273
273
  * Sets a maximum date validator.
274
274
  *
275
- * ####Example:
275
+ * #### Example:
276
276
  *
277
277
  * const s = new Schema({ d: { type: Date, max: Date('2014-01-01') })
278
278
  * const M = db.model('M', s)
@@ -48,7 +48,7 @@ Decimal128._cast = castDecimal128;
48
48
  /**
49
49
  * Sets a default option for all Decimal128 instances.
50
50
  *
51
- * ####Example:
51
+ * #### Example:
52
52
  *
53
53
  * // Make all decimal 128s have `required` of true by default.
54
54
  * mongoose.Schema.Decimal128.set('required', true);
@@ -69,7 +69,7 @@ Decimal128.set = SchemaType.set;
69
69
  /**
70
70
  * Get/set the function used to cast arbitrary values to decimals.
71
71
  *
72
- * ####Example:
72
+ * #### Example:
73
73
  *
74
74
  * // Make Mongoose only refuse to cast numbers as decimal128
75
75
  * const original = mongoose.Schema.Types.Decimal128.cast();
@@ -152,7 +152,7 @@ function _createConstructor(schema, options, baseClass) {
152
152
  /**
153
153
  * Adds a discriminator to this document array.
154
154
  *
155
- * ####Example:
155
+ * #### Example:
156
156
  * const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
157
157
  * const schema = Schema({ shapes: [shapeSchema] });
158
158
  *
@@ -274,7 +274,7 @@ DocumentArrayPath.prototype.doValidate = function(array, fn, scope, options) {
274
274
  /**
275
275
  * Performs local validations first, then validations on each embedded doc.
276
276
  *
277
- * ####Note:
277
+ * #### Note:
278
278
  *
279
279
  * This method ignores the asynchronous validators.
280
280
  *
@@ -565,7 +565,7 @@ function scopePaths(array, fields, init) {
565
565
  /**
566
566
  * Sets a default option for all DocumentArray instances.
567
567
  *
568
- * ####Example:
568
+ * #### Example:
569
569
  *
570
570
  * // Make all numbers have option `min` equal to 0.
571
571
  * mongoose.Schema.DocumentArray.set('_id', false);
@@ -56,7 +56,7 @@ Mixed.prototype.constructor = Mixed;
56
56
  /**
57
57
  * Attaches a getter for all Mixed paths.
58
58
  *
59
- * ####Example:
59
+ * #### Example:
60
60
  *
61
61
  * // Hide the 'hidden' path
62
62
  * mongoose.Schema.Mixed.get(v => Object.assign({}, v, { hidden: null }));
@@ -76,7 +76,7 @@ Mixed.get = SchemaType.get;
76
76
  /**
77
77
  * Sets a default option for all Mixed instances.
78
78
  *
79
- * ####Example:
79
+ * #### Example:
80
80
  *
81
81
  * // Make all mixed instances have `required` of true by default.
82
82
  * mongoose.Schema.Mixed.set('required', true);
@@ -29,7 +29,7 @@ function SchemaNumber(key, options) {
29
29
  /**
30
30
  * Attaches a getter for all Number instances.
31
31
  *
32
- * ####Example:
32
+ * #### Example:
33
33
  *
34
34
  * // Make all numbers round down
35
35
  * mongoose.Number.get(function(v) { return Math.floor(v); });
@@ -49,7 +49,7 @@ SchemaNumber.get = SchemaType.get;
49
49
  /**
50
50
  * Sets a default option for all Number instances.
51
51
  *
52
- * ####Example:
52
+ * #### Example:
53
53
  *
54
54
  * // Make all numbers have option `min` equal to 0.
55
55
  * mongoose.Schema.Number.set('min', 0);
@@ -76,7 +76,7 @@ SchemaNumber._cast = castNumber;
76
76
  /**
77
77
  * Get/set the function used to cast arbitrary values to numbers.
78
78
  *
79
- * ####Example:
79
+ * #### Example:
80
80
  *
81
81
  * // Make Mongoose cast empty strings '' to 0 for paths declared as numbers
82
82
  * const original = mongoose.Number.cast();
@@ -180,7 +180,7 @@ SchemaNumber.prototype.checkRequired = function checkRequired(value, doc) {
180
180
  /**
181
181
  * Sets a minimum number validator.
182
182
  *
183
- * ####Example:
183
+ * #### Example:
184
184
  *
185
185
  * const s = new Schema({ n: { type: Number, min: 10 })
186
186
  * const M = db.model('M', s)
@@ -234,7 +234,7 @@ SchemaNumber.prototype.min = function(value, message) {
234
234
  /**
235
235
  * Sets a maximum number validator.
236
236
  *
237
- * ####Example:
237
+ * #### Example:
238
238
  *
239
239
  * const s = new Schema({ n: { type: Number, max: 10 })
240
240
  * const M = db.model('M', s)
@@ -288,7 +288,7 @@ SchemaNumber.prototype.max = function(value, message) {
288
288
  /**
289
289
  * Sets a enum validator
290
290
  *
291
- * ####Example:
291
+ * #### Example:
292
292
  *
293
293
  * const s = new Schema({ n: { type: Number, enum: [1, 2, 3] });
294
294
  * const M = db.model('M', s);
@@ -55,7 +55,7 @@ ObjectId.prototype.OptionsConstructor = SchemaObjectIdOptions;
55
55
  /**
56
56
  * Attaches a getter for all ObjectId instances
57
57
  *
58
- * ####Example:
58
+ * #### Example:
59
59
  *
60
60
  * // Always convert to string when getting an ObjectId
61
61
  * mongoose.ObjectId.get(v => v.toString());
@@ -75,7 +75,7 @@ ObjectId.get = SchemaType.get;
75
75
  /**
76
76
  * Sets a default option for all ObjectId instances.
77
77
  *
78
- * ####Example:
78
+ * #### Example:
79
79
  *
80
80
  * // Make all object ids have option `required` equal to true.
81
81
  * mongoose.Schema.ObjectId.set('required', true);
@@ -124,7 +124,7 @@ ObjectId._cast = castObjectId;
124
124
  /**
125
125
  * Get/set the function used to cast arbitrary values to objectids.
126
126
  *
127
- * ####Example:
127
+ * #### Example:
128
128
  *
129
129
  * // Make Mongoose only try to cast length 24 strings. By default, any 12
130
130
  * // char string is a valid ObjectId.
@@ -171,7 +171,7 @@ ObjectId._defaultCaster = v => {
171
171
  * Override the function the required validator uses to check whether a string
172
172
  * passes the `required` check.
173
173
  *
174
- * ####Example:
174
+ * #### Example:
175
175
  *
176
176
  * // Allow empty strings to pass `required` check
177
177
  * mongoose.Schema.Types.String.checkRequired(v => v != null);
@@ -282,11 +282,8 @@ function resetId(v) {
282
282
  if (this instanceof Document) {
283
283
  if (v === void 0) {
284
284
  const _v = new oid();
285
- this.$__._id = _v;
286
285
  return _v;
287
286
  }
288
-
289
- this.$__._id = v;
290
287
  }
291
288
 
292
289
  return v;
@@ -58,7 +58,7 @@ SchemaString._cast = castString;
58
58
  /**
59
59
  * Get/set the function used to cast arbitrary values to strings.
60
60
  *
61
- * ####Example:
61
+ * #### Example:
62
62
  *
63
63
  * // Throw an error if you pass in an object. Normally, Mongoose allows
64
64
  * // objects with custom `toString()` functions.
@@ -104,7 +104,7 @@ SchemaString._defaultCaster = v => {
104
104
  /**
105
105
  * Attaches a getter for all String instances.
106
106
  *
107
- * ####Example:
107
+ * #### Example:
108
108
  *
109
109
  * // Make all numbers round down
110
110
  * mongoose.Schema.String.get(v => v.toLowerCase());
@@ -124,7 +124,7 @@ SchemaString.get = SchemaType.get;
124
124
  /**
125
125
  * Sets a default option for all String instances.
126
126
  *
127
- * ####Example:
127
+ * #### Example:
128
128
  *
129
129
  * // Make all strings have option `trim` equal to true.
130
130
  * mongoose.Schema.String.set('trim', true);
@@ -152,7 +152,7 @@ SchemaString._checkRequired = v => (v instanceof String || typeof v === 'string'
152
152
  * Override the function the required validator uses to check whether a string
153
153
  * passes the `required` check.
154
154
  *
155
- * ####Example:
155
+ * #### Example:
156
156
  *
157
157
  * // Allow empty strings to pass `required` check
158
158
  * mongoose.Schema.Types.String.checkRequired(v => v != null);
@@ -172,7 +172,7 @@ SchemaString.checkRequired = SchemaType.checkRequired;
172
172
  /**
173
173
  * Adds an enum validator
174
174
  *
175
- * ####Example:
175
+ * #### Example:
176
176
  *
177
177
  * const states = ['opening', 'open', 'closing', 'closed']
178
178
  * const s = new Schema({ state: { type: String, enum: states }})
@@ -255,7 +255,7 @@ SchemaString.prototype.enum = function() {
255
255
  /**
256
256
  * Adds a lowercase [setter](https://mongoosejs.com/docs/api.html#schematype_SchemaType-set).
257
257
  *
258
- * ####Example:
258
+ * #### Example:
259
259
  *
260
260
  * const s = new Schema({ email: { type: String, lowercase: true }})
261
261
  * const M = db.model('M', s);
@@ -265,7 +265,7 @@ SchemaString.prototype.enum = function() {
265
265
  *
266
266
  * Note that `lowercase` does **not** affect regular expression queries:
267
267
  *
268
- * ####Example:
268
+ * #### Example:
269
269
  * // Still queries for documents whose `email` matches the regular
270
270
  * // expression /SomeEmail/. Mongoose does **not** convert the RegExp
271
271
  * // to lowercase.
@@ -293,7 +293,7 @@ SchemaString.prototype.lowercase = function(shouldApply) {
293
293
  /**
294
294
  * Adds an uppercase [setter](https://mongoosejs.com/docs/api.html#schematype_SchemaType-set).
295
295
  *
296
- * ####Example:
296
+ * #### Example:
297
297
  *
298
298
  * const s = new Schema({ caps: { type: String, uppercase: true }})
299
299
  * const M = db.model('M', s);
@@ -303,7 +303,7 @@ SchemaString.prototype.lowercase = function(shouldApply) {
303
303
  *
304
304
  * Note that `uppercase` does **not** affect regular expression queries:
305
305
  *
306
- * ####Example:
306
+ * #### Example:
307
307
  * // Mongoose does **not** convert the RegExp to uppercase.
308
308
  * M.find({ email: /an example/ });
309
309
  *
@@ -331,7 +331,7 @@ SchemaString.prototype.uppercase = function(shouldApply) {
331
331
  *
332
332
  * The string value will be [trimmed](https://masteringjs.io/tutorials/fundamentals/trim-string) when set.
333
333
  *
334
- * ####Example:
334
+ * #### Example:
335
335
  *
336
336
  * const s = new Schema({ name: { type: String, trim: true }});
337
337
  * const M = db.model('M', s);
@@ -345,7 +345,7 @@ SchemaString.prototype.uppercase = function(shouldApply) {
345
345
  *
346
346
  * Note that `trim` does **not** affect regular expression queries:
347
347
  *
348
- * ####Example:
348
+ * #### Example:
349
349
  * // Mongoose does **not** trim whitespace from the RegExp.
350
350
  * M.find({ name: / some name / });
351
351
  *
@@ -371,7 +371,7 @@ SchemaString.prototype.trim = function(shouldTrim) {
371
371
  /**
372
372
  * Sets a minimum length validator.
373
373
  *
374
- * ####Example:
374
+ * #### Example:
375
375
  *
376
376
  * const schema = new Schema({ postalCode: { type: String, minlength: 5 })
377
377
  * const Address = db.model('Address', schema)
@@ -427,7 +427,7 @@ SchemaString.prototype.minLength = SchemaString.prototype.minlength;
427
427
  /**
428
428
  * Sets a maximum length validator.
429
429
  *
430
- * ####Example:
430
+ * #### Example:
431
431
  *
432
432
  * const schema = new Schema({ postalCode: { type: String, maxlength: 9 })
433
433
  * const Address = db.model('Address', schema)
@@ -485,7 +485,7 @@ SchemaString.prototype.maxLength = SchemaString.prototype.maxlength;
485
485
  *
486
486
  * Any value that does not pass `regExp`.test(val) will fail validation.
487
487
  *
488
- * ####Example:
488
+ * #### Example:
489
489
  *
490
490
  * const s = new Schema({ name: { type: String, match: /^a/ }})
491
491
  * const M = db.model('M', s)
@@ -612,6 +612,10 @@ function handleSingle(val) {
612
612
  return this.castForQuery(val);
613
613
  }
614
614
 
615
+ /*!
616
+ * ignore
617
+ */
618
+
615
619
  function handleArray(val) {
616
620
  const _this = this;
617
621
  if (!Array.isArray(val)) {
@@ -622,14 +626,32 @@ function handleArray(val) {
622
626
  });
623
627
  }
624
628
 
629
+ /*!
630
+ * ignore
631
+ */
632
+
633
+ function handleSingleNoSetters(val) {
634
+ if (val == null) {
635
+ return this._castNullish(val);
636
+ }
637
+
638
+ return this.cast(val, this);
639
+ }
640
+
625
641
  const $conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {
626
642
  $all: handleArray,
627
643
  $gt: handleSingle,
628
644
  $gte: handleSingle,
629
645
  $lt: handleSingle,
630
646
  $lte: handleSingle,
631
- $options: String,
632
- $regex: handleSingle,
647
+ $options: handleSingleNoSetters,
648
+ $regex: function handle$regex(val) {
649
+ if (Object.prototype.toString.call(val) === '[object RegExp]') {
650
+ return val;
651
+ }
652
+
653
+ return handleSingleNoSetters.call(this, val);
654
+ },
633
655
  $not: handleSingle
634
656
  });
635
657