mongoose 9.13.0 → 9.13.1
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/helpers/updateValidators.js +3 -3
- package/lib/model.js +4 -4
- package/lib/options/schemaArrayOptions.js +13 -2
- package/lib/schema/array.js +15 -13
- package/lib/schema.js +30 -1
- package/package.json +1 -1
- package/types/pipelinestage.d.ts +4 -2
- package/tstyche.json +0 -7
- package/tstyche.matrix.json +0 -9
|
@@ -98,10 +98,10 @@ module.exports = async function updateValidators(query, schema, castedDoc, optio
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
if (v && Array.isArray(v.$in)) {
|
|
101
|
-
v.$in.forEach((
|
|
101
|
+
v.$in.forEach((value, index) => {
|
|
102
102
|
validatorsToExecute.push(
|
|
103
|
-
schemaPath.doValidate(
|
|
104
|
-
err.path = updates[i] + '.$in.' +
|
|
103
|
+
schemaPath.doValidate(value, context, { updateValidator: true }).catch(err => {
|
|
104
|
+
err.path = updates[i] + '.$in.' + index;
|
|
105
105
|
validationErrors.push(err);
|
|
106
106
|
})
|
|
107
107
|
);
|
package/lib/model.js
CHANGED
|
@@ -3464,9 +3464,9 @@ function _setIsNew(doc, val, hasOnlyPrimitiveValues) {
|
|
|
3464
3464
|
* @param {boolean} [options.ordered=true] If true, execute writes in order and stop at the first error. If false, execute writes in parallel and continue until all writes have either succeeded or errored.
|
|
3465
3465
|
* @param {boolean} [options.timestamps=true] If false, do not apply [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) to any operations. Can be overridden at the operation-level.
|
|
3466
3466
|
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
3467
|
-
* @param {string|number} [options.w
|
|
3467
|
+
* @param {string|number} [options.w] The [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/). If not set, the MongoDB server's default write concern applies. See [`Query#w()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.w()) for more information.
|
|
3468
3468
|
* @param {number} [options.wtimeout=null] The [write concern timeout](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout).
|
|
3469
|
-
* @param {boolean} [options.j
|
|
3469
|
+
* @param {boolean} [options.j] Set to true to request [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option). If not set, the MongoDB server's default write concern applies.
|
|
3470
3470
|
* @param {boolean} [options.skipValidation=false] Set to true to skip Mongoose schema validation on bulk write operations. Mongoose currently runs validation on `insertOne` and `replaceOne` operations by default.
|
|
3471
3471
|
* @param {boolean} [options.bypassDocumentValidation=false] If true, disable [MongoDB server-side schema validation](https://www.mongodb.com/docs/manual/core/schema-validation/) for all writes in this bulk.
|
|
3472
3472
|
* @param {boolean} [options.throwOnValidationError=false] If true and `ordered: false`, throw an error if one of the operations failed validation, but all valid operations completed successfully. Note that Mongoose will still send all valid operations to the MongoDB server.
|
|
@@ -3656,9 +3656,9 @@ async function _bulkWrite(ops, options) {
|
|
|
3656
3656
|
* @param {object} [options] options passed to the underlying `bulkWrite()`
|
|
3657
3657
|
* @param {boolean} [options.timestamps] defaults to `null`, when set to false, mongoose will not add/update timestamps to the documents.
|
|
3658
3658
|
* @param {ClientSession} [options.session=null] The session associated with this bulk write. See [transactions docs](https://mongoosejs.com/docs/transactions.html).
|
|
3659
|
-
* @param {string|number} [options.w
|
|
3659
|
+
* @param {string|number} [options.w] The [write concern](https://www.mongodb.com/docs/manual/reference/write-concern/). If not set, the MongoDB server's default write concern applies. See [`Query#w()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.w()) for more information.
|
|
3660
3660
|
* @param {number} [options.wtimeout=null] The [write concern timeout](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout).
|
|
3661
|
-
* @param {boolean} [options.j
|
|
3661
|
+
* @param {boolean} [options.j] Set to true to request [journal acknowledgement](https://www.mongodb.com/docs/manual/reference/write-concern/#j-option). If not set, the MongoDB server's default write concern applies.
|
|
3662
3662
|
* @param {boolean} [options.validateBeforeSave=true] set to `false` to skip Mongoose validation on all documents
|
|
3663
3663
|
* @param {boolean|object} [options.middleware=true] set to `false` to skip all user-defined middleware
|
|
3664
3664
|
* @param {boolean} [options.middleware.pre=true] set to `false` to skip only pre hooks
|
|
@@ -53,8 +53,13 @@ Object.defineProperty(SchemaArrayOptions.prototype, 'enum', opts);
|
|
|
53
53
|
Object.defineProperty(SchemaArrayOptions.prototype, 'of', opts);
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* If set to `false`,
|
|
57
|
-
* If set to `true`,
|
|
56
|
+
* If set to `false`, Mongoose throws a `CastError` when you set a non-array value
|
|
57
|
+
* on this path. If set to `true`, Mongoose wraps the value in an array. Overrides
|
|
58
|
+
* the global `mongoose.Schema.Types.Array.options.castNonArrays` for this path.
|
|
59
|
+
* Values loaded from MongoDB are always wrapped, regardless of this option.
|
|
60
|
+
*
|
|
61
|
+
* This option only applies to the array it's set on, not to arrays nested
|
|
62
|
+
* inside it. For nested arrays, set `castNonArrays` on each level.
|
|
58
63
|
*
|
|
59
64
|
* #### Example:
|
|
60
65
|
*
|
|
@@ -62,6 +67,12 @@ Object.defineProperty(SchemaArrayOptions.prototype, 'of', opts);
|
|
|
62
67
|
* const doc = new Model({ x1: "some non-array value" });
|
|
63
68
|
* await doc.validate(); // Errors with "CastError"
|
|
64
69
|
*
|
|
70
|
+
* // Only the outer array: `1` is a CastError, but `[1, 2]` becomes `[[1, 2]]`
|
|
71
|
+
* new Schema({ matrix: { castNonArrays: false, type: [[Number]] } });
|
|
72
|
+
*
|
|
73
|
+
* // Both levels: `1` and `[1, 2]` are both CastErrors
|
|
74
|
+
* new Schema({ matrix: { castNonArrays: false, type: [{ type: [Number], castNonArrays: false }] } });
|
|
75
|
+
*
|
|
65
76
|
* @api public
|
|
66
77
|
* @property castNonArrays
|
|
67
78
|
* @memberOf SchemaArrayOptions
|
package/lib/schema/array.js
CHANGED
|
@@ -296,26 +296,28 @@ SchemaArray.prototype.applyGetters = function(value, scope) {
|
|
|
296
296
|
};
|
|
297
297
|
|
|
298
298
|
SchemaArray.prototype._applySetters = function(value, scope, init, priorVal) {
|
|
299
|
-
|
|
300
|
-
if (this.embeddedSchemaType.$isMongooseArray &&
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
let depth = 0;
|
|
299
|
+
// No need to wrap empty arrays
|
|
300
|
+
if (this.embeddedSchemaType.$isMongooseArray && value != null && value.length !== 0) {
|
|
301
|
+
// This array and its nested arrays, outermost first
|
|
302
|
+
const levels = [];
|
|
304
303
|
let arr = this;
|
|
305
304
|
while (arr != null &&
|
|
306
305
|
arr.$isMongooseArray &&
|
|
307
306
|
!arr.$isMongooseDocumentArray) {
|
|
308
|
-
|
|
307
|
+
levels.push(arr);
|
|
309
308
|
arr = arr.embeddedSchemaType;
|
|
310
309
|
}
|
|
311
310
|
|
|
312
|
-
//
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
311
|
+
// Check nesting levels and wrap in array if necessary. A value nested
|
|
312
|
+
// `valueDepth.max` levels deep puts non-array values in every level from
|
|
313
|
+
// `valueDepth.max` inward, so each of those levels must allow wrapping.
|
|
314
|
+
const valueDepth = arrayDepth(value);
|
|
315
|
+
if (valueDepth.min === valueDepth.max &&
|
|
316
|
+
valueDepth.max < levels.length &&
|
|
317
|
+
valueDepth.containsNonArrayItem &&
|
|
318
|
+
levels.slice(valueDepth.max).every(level => level.options.castNonArrays ?? SchemaArray.options.castNonArrays)) {
|
|
319
|
+
for (let i = valueDepth.max; i < levels.length; ++i) {
|
|
320
|
+
value = [value];
|
|
319
321
|
}
|
|
320
322
|
}
|
|
321
323
|
}
|
package/lib/schema.js
CHANGED
|
@@ -1750,7 +1750,9 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1750
1750
|
? cast[options.typeKey]
|
|
1751
1751
|
: cast;
|
|
1752
1752
|
if (Array.isArray(type)) {
|
|
1753
|
-
|
|
1753
|
+
// Pass `cast` rather than `type` so options on a nested array, like
|
|
1754
|
+
// `[{ type: [Number], castNonArrays: false }]`, aren't dropped.
|
|
1755
|
+
return new MongooseTypes.Array(path, this.interpretAsType(path, cast, options), obj, null, this);
|
|
1754
1756
|
}
|
|
1755
1757
|
|
|
1756
1758
|
name = typeof type === 'string'
|
|
@@ -2855,6 +2857,17 @@ Schema.prototype.remove = function(path) {
|
|
|
2855
2857
|
}
|
|
2856
2858
|
this._defaultsCache = null;
|
|
2857
2859
|
this._hasSelectedPaths = undefined;
|
|
2860
|
+
// Drop aliases that point to the removed path, or to a path under it, along
|
|
2861
|
+
// with their virtuals, so they don't keep translating keys to a missing path.
|
|
2862
|
+
for (const [alias, target] of Object.entries(this.aliases)) {
|
|
2863
|
+
if (target === name || target.startsWith(name + '.')) {
|
|
2864
|
+
delete this.aliases[alias];
|
|
2865
|
+
delete this.virtuals[alias];
|
|
2866
|
+
if (get(this.tree, alias) instanceof VirtualType) {
|
|
2867
|
+
_deletePath(this, alias);
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2858
2871
|
if (this.nested[name]) {
|
|
2859
2872
|
const allKeys = Object.keys(this.paths).
|
|
2860
2873
|
concat(Object.keys(this.nested));
|
|
@@ -2955,6 +2968,22 @@ Schema.prototype.removeVirtual = function(path) {
|
|
|
2955
2968
|
}
|
|
2956
2969
|
|
|
2957
2970
|
for (const virtual of path) {
|
|
2971
|
+
if (Object.hasOwn(this.aliases, virtual)) {
|
|
2972
|
+
// `pick()` rebuilds aliases from the SchemaType's options, and `omit()` and
|
|
2973
|
+
// `add(schema)` rebuild them from the tree, so drop the alias from both or it
|
|
2974
|
+
// comes back on every schema derived from this one.
|
|
2975
|
+
const aliasedPath = this.aliases[virtual];
|
|
2976
|
+
delete this.aliases[virtual];
|
|
2977
|
+
const treeEntry = get(this.tree, aliasedPath);
|
|
2978
|
+
const treeOptions = treeEntry instanceof SchemaType ? treeEntry.options : treeEntry;
|
|
2979
|
+
for (const options of [this.paths[aliasedPath]?.options, treeOptions]) {
|
|
2980
|
+
if (options?.alias === virtual) {
|
|
2981
|
+
delete options.alias;
|
|
2982
|
+
} else if (Array.isArray(options?.alias)) {
|
|
2983
|
+
options.alias = options.alias.filter(a => a !== virtual);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2958
2987
|
delete this.paths[virtual];
|
|
2959
2988
|
delete this.virtuals[virtual];
|
|
2960
2989
|
if (virtual.indexOf('.') !== -1) {
|
package/package.json
CHANGED
package/types/pipelinestage.d.ts
CHANGED
|
@@ -323,11 +323,13 @@ declare module 'mongoose' {
|
|
|
323
323
|
exact?: boolean;
|
|
324
324
|
index: string,
|
|
325
325
|
path: string,
|
|
326
|
-
queryVector: number[],
|
|
327
326
|
numCandidates?: number,
|
|
328
327
|
limit: number,
|
|
329
328
|
filter?: Expression,
|
|
330
|
-
}
|
|
329
|
+
} & (
|
|
330
|
+
{ queryVector: number[], query?: never, model?: never } |
|
|
331
|
+
{ query: { text: string }, queryVector?: never, model?: string }
|
|
332
|
+
)
|
|
331
333
|
}
|
|
332
334
|
|
|
333
335
|
}
|
package/tstyche.json
DELETED