mongoose 6.3.7 → 6.3.8
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/document.js
CHANGED
|
@@ -79,6 +79,7 @@ function Document(obj, fields, skipId, options) {
|
|
|
79
79
|
options = skipId;
|
|
80
80
|
skipId = options.skipId;
|
|
81
81
|
}
|
|
82
|
+
options = Object.assign({}, options);
|
|
82
83
|
|
|
83
84
|
// Support `browserDocument.js` syntax
|
|
84
85
|
if (this.$__schema == null) {
|
|
@@ -92,9 +93,9 @@ function Document(obj, fields, skipId, options) {
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
this.$__ = new InternalCache();
|
|
95
|
-
this.$isNew =
|
|
96
|
+
this.$isNew = 'isNew' in options ? options.isNew : true;
|
|
96
97
|
|
|
97
|
-
if (options
|
|
98
|
+
if (options.priorDoc != null) {
|
|
98
99
|
this.$__.priorDoc = options.priorDoc;
|
|
99
100
|
}
|
|
100
101
|
|
|
@@ -107,20 +108,18 @@ function Document(obj, fields, skipId, options) {
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
let defaults = true;
|
|
110
|
-
if (options
|
|
111
|
+
if (options.defaults !== undefined) {
|
|
111
112
|
this.$__.defaults = options.defaults;
|
|
112
113
|
defaults = options.defaults;
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
const schema = this.$__schema;
|
|
116
117
|
|
|
117
|
-
let strict;
|
|
118
118
|
if (typeof fields === 'boolean' || fields === 'throw') {
|
|
119
119
|
this.$__.strictMode = fields;
|
|
120
|
-
strict = fields;
|
|
121
120
|
fields = undefined;
|
|
122
121
|
} else {
|
|
123
|
-
|
|
122
|
+
this.$__.strictMode = schema.options.strict;
|
|
124
123
|
if (fields != null) {
|
|
125
124
|
this.$__.selected = fields;
|
|
126
125
|
}
|
|
@@ -170,15 +169,15 @@ function Document(obj, fields, skipId, options) {
|
|
|
170
169
|
// Function defaults get applied **after** setting initial values so they
|
|
171
170
|
// see the full doc rather than an empty one, unless they opt out.
|
|
172
171
|
// Re: gh-3781, gh-6155
|
|
173
|
-
if (options
|
|
172
|
+
if (options.willInit && defaults) {
|
|
174
173
|
if (options.skipDefaults) {
|
|
175
174
|
this.$__.skipDefaults = options.skipDefaults;
|
|
176
175
|
}
|
|
177
176
|
} else if (defaults) {
|
|
178
|
-
$__applyDefaults(this, fields, exclude, hasIncludedChildren, false, options
|
|
177
|
+
$__applyDefaults(this, fields, exclude, hasIncludedChildren, false, options.skipDefaults);
|
|
179
178
|
}
|
|
180
179
|
|
|
181
|
-
if (!
|
|
180
|
+
if (!this.$__.strictMode && obj) {
|
|
182
181
|
const _this = this;
|
|
183
182
|
const keys = Object.keys(this._doc);
|
|
184
183
|
|
|
@@ -40,8 +40,7 @@ function createImmutableSetter(path, immutable) {
|
|
|
40
40
|
const _value = this.$__.priorDoc != null ?
|
|
41
41
|
this.$__.priorDoc.$__getValue(path) :
|
|
42
42
|
this.$__getValue(path);
|
|
43
|
-
|
|
44
|
-
if (strict === 'throw' && v !== _value) {
|
|
43
|
+
if (this.$__.strictMode === 'throw' && v !== _value) {
|
|
45
44
|
throw new StrictModeError(path, 'Path `' + path + '` is immutable ' +
|
|
46
45
|
'and strict mode is set to throw.', true);
|
|
47
46
|
}
|
|
@@ -167,7 +167,7 @@ SubdocumentPath.prototype.cast = function(val, doc, init, priorVal, options) {
|
|
|
167
167
|
}
|
|
168
168
|
return obj;
|
|
169
169
|
}, null);
|
|
170
|
-
options =
|
|
170
|
+
options = Object.assign({}, options, { priorDoc: priorVal });
|
|
171
171
|
if (init) {
|
|
172
172
|
subdoc = new Constructor(void 0, selected, doc);
|
|
173
173
|
subdoc.$init(val);
|
|
@@ -391,6 +391,8 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
391
391
|
let selected;
|
|
392
392
|
let subdoc;
|
|
393
393
|
|
|
394
|
+
options = options || {};
|
|
395
|
+
|
|
394
396
|
if (!Array.isArray(value)) {
|
|
395
397
|
if (!init && !DocumentArrayPath.options.castNonArrays) {
|
|
396
398
|
throw new CastError('DocumentArray', value, this.path, null, this);
|
|
@@ -405,7 +407,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
405
407
|
|
|
406
408
|
// We need to create a new array, otherwise change tracking will
|
|
407
409
|
// update the old doc (gh-4449)
|
|
408
|
-
if (!options
|
|
410
|
+
if (!options.skipDocumentArrayCast || utils.isMongooseDocumentArray(value)) {
|
|
409
411
|
value = new MongooseDocumentArray(value, this.path, doc);
|
|
410
412
|
}
|
|
411
413
|
|
|
@@ -413,7 +415,7 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
|
|
|
413
415
|
value[arrayAtomicsSymbol] = prev[arrayAtomicsSymbol] || {};
|
|
414
416
|
}
|
|
415
417
|
|
|
416
|
-
if (options
|
|
418
|
+
if (options.arrayPathIndex != null) {
|
|
417
419
|
value[arrayPathSymbol] = this.path + '.' + options.arrayPathIndex;
|
|
418
420
|
}
|
|
419
421
|
|
package/lib/schematype.js
CHANGED
|
@@ -1181,7 +1181,6 @@ SchemaType.prototype._castNullish = function _castNullish(v) {
|
|
|
1181
1181
|
|
|
1182
1182
|
SchemaType.prototype.applySetters = function(value, scope, init, priorVal, options) {
|
|
1183
1183
|
let v = this._applySetters(value, scope, init, priorVal, options);
|
|
1184
|
-
|
|
1185
1184
|
if (v == null) {
|
|
1186
1185
|
return this._castNullish(v);
|
|
1187
1186
|
}
|