Comparing version 8.7.3 to 8.8.0
@@ -31,2 +31,3 @@ 'use strict'; | ||
* @param {Boolean|"throw"} [options.strictQuery] Enable strict Queries | ||
* @param {Boolean} [options.sanitizeFilter] avoid adding implict query selectors ($in) | ||
* @param {Boolean} [options.upsert] | ||
@@ -376,3 +377,3 @@ * @param {Query} [context] passed to setters | ||
} | ||
} else if (Array.isArray(val) && ['Buffer', 'Array'].indexOf(schematype.instance) === -1) { | ||
} else if (Array.isArray(val) && ['Buffer', 'Array'].indexOf(schematype.instance) === -1 && !options.sanitizeFilter) { | ||
const casted = []; | ||
@@ -379,0 +380,0 @@ const valuesArray = val; |
@@ -14,5 +14,8 @@ 'use strict'; | ||
const Mixed = require('./mixed'); | ||
const VirtualOptions = require('../options/virtualOptions'); | ||
const VirtualType = require('../virtualType'); | ||
const arrayDepth = require('../helpers/arrayDepth'); | ||
const cast = require('../cast'); | ||
const clone = require('../helpers/clone'); | ||
const getConstructorName = require('../helpers/getConstructorName'); | ||
const isOperator = require('../helpers/query/isOperator'); | ||
@@ -221,2 +224,8 @@ const util = require('util'); | ||
/*! | ||
* Virtuals defined on this array itself. | ||
*/ | ||
SchemaArray.prototype.virtuals = null; | ||
/** | ||
@@ -580,2 +589,28 @@ * Check if the given value satisfies the `required` validator. | ||
/** | ||
* Add a virtual to this array. Specifically to this array, not the individual elements. | ||
* | ||
* @param {String} name | ||
* @param {Object} [options] | ||
* @api private | ||
*/ | ||
SchemaArray.prototype.virtual = function virtual(name, options) { | ||
if (name instanceof VirtualType || getConstructorName(name) === 'VirtualType') { | ||
return this.virtual(name.path, name.options); | ||
} | ||
options = new VirtualOptions(options); | ||
if (utils.hasUserDefinedProperty(options, ['ref', 'refPath'])) { | ||
throw new MongooseError('Cannot set populate virtual as a property of an array'); | ||
} | ||
const virtual = new VirtualType(options, name); | ||
if (this.virtuals === null) { | ||
this.virtuals = {}; | ||
} | ||
this.virtuals[name] = virtual; | ||
return virtual; | ||
}; | ||
function cast$all(val, context) { | ||
@@ -582,0 +617,0 @@ if (!Array.isArray(val)) { |
@@ -432,3 +432,3 @@ 'use strict'; | ||
if (!options.skipDocumentArrayCast || utils.isMongooseDocumentArray(value)) { | ||
value = new MongooseDocumentArray(value, path, doc); | ||
value = new MongooseDocumentArray(value, path, doc, this); | ||
} | ||
@@ -435,0 +435,0 @@ |
@@ -93,2 +93,5 @@ /*! | ||
} | ||
if (schematype && schematype.virtuals && schematype.virtuals.hasOwnProperty(prop)) { | ||
return schematype.virtuals[prop].applyGetters(undefined, target); | ||
} | ||
if (typeof prop === 'string' && numberRE.test(prop) && schematype?.$embeddedSchemaType != null) { | ||
@@ -105,2 +108,4 @@ return schematype.$embeddedSchemaType.applyGetters(__array[prop], doc); | ||
internals[prop] = value; | ||
} else if (schematype && schematype.virtuals && schematype.virtuals.hasOwnProperty(prop)) { | ||
schematype.virtuals[prop].applySetters(value, target); | ||
} else { | ||
@@ -107,0 +112,0 @@ __array[prop] = value; |
@@ -31,3 +31,3 @@ 'use strict'; | ||
function MongooseDocumentArray(values, path, doc) { | ||
function MongooseDocumentArray(values, path, doc, schematype) { | ||
const __array = []; | ||
@@ -88,2 +88,5 @@ | ||
} | ||
if (schematype && schematype.virtuals && schematype.virtuals.hasOwnProperty(prop)) { | ||
return schematype.virtuals[prop].applyGetters(undefined, target); | ||
} | ||
if (ArrayMethods.hasOwnProperty(prop)) { | ||
@@ -100,2 +103,4 @@ return ArrayMethods[prop]; | ||
internals[prop] = value; | ||
} else if (schematype && schematype.virtuals && schematype.virtuals.hasOwnProperty(prop)) { | ||
schematype.virtuals[prop].applySetters(value, target); | ||
} else { | ||
@@ -102,0 +107,0 @@ __array[prop] = value; |
{ | ||
"name": "mongoose", | ||
"description": "Mongoose MongoDB ODM", | ||
"version": "8.7.3", | ||
"version": "8.8.0", | ||
"author": "Guillermo Rauch <guillermo@learnboost.com>", | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"kareem": "2.6.3", | ||
"mongodb": "6.9.0", | ||
"mongodb": "~6.10.0", | ||
"mpath": "0.9.0", | ||
@@ -27,0 +27,0 @@ "mquery": "5.0.0", |
@@ -259,6 +259,13 @@ declare module 'mongoose' { | ||
/** The return value of this method is used in calls to JSON.stringify(doc). */ | ||
toJSON(options?: ToObjectOptions & { flattenMaps?: true }): FlattenMaps<Require_id<DocType>>; | ||
toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Require_id<DocType>>; | ||
toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Require_id<DocType>>; | ||
toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Require_id<DocType>>>; | ||
toJSON(options: ToObjectOptions & { flattenMaps: false }): Require_id<DocType>; | ||
toJSON<T = Require_id<DocType>>(options?: ToObjectOptions & { flattenMaps?: true }): FlattenMaps<T>; | ||
toJSON(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<Require_id<DocType>>; | ||
toJSON<T = Require_id<DocType>>(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<T>; | ||
toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<T>; | ||
toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<T>>; | ||
toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenMaps: false }): T; | ||
toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<T>; | ||
@@ -265,0 +272,0 @@ /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */ |
@@ -28,3 +28,3 @@ /// <reference path="./aggregate.d.ts" /> | ||
declare class NativeDate extends global.Date { } | ||
declare class NativeDate extends globalThis.Date { } | ||
@@ -144,3 +144,3 @@ declare module 'mongoose' { | ||
? T | ||
: T & { __v?: number }; | ||
: T & { __v: number }; | ||
@@ -628,2 +628,5 @@ /** Helper type for getting the hydrated document type from the raw document type. The hydrated document type is what `new MyModel()` returns. */ | ||
/** If true and the given `name` is a direct child of an array, apply the virtual to the array rather than the elements. */ | ||
applyToArray?: boolean; | ||
/** Additional options for plugins */ | ||
@@ -630,0 +633,0 @@ [extra: string]: any; |
@@ -60,3 +60,4 @@ declare module 'mongoose' { | ||
interface SyncIndexesOptions extends mongodb.CreateIndexesOptions { | ||
continueOnError?: boolean | ||
continueOnError?: boolean; | ||
hideIndexes?: boolean; | ||
} | ||
@@ -63,0 +64,0 @@ type ConnectionSyncIndexesResult = Record<string, OneCollectionSyncIndexesResult>; |
@@ -129,3 +129,3 @@ declare module 'mongoose' { | ||
interface ModifyResult<T> { | ||
value: Require_id<T> | null; | ||
value: Default__v<Require_id<T>> | null; | ||
/** see https://www.mongodb.com/docs/manual/reference/command/findAndModify/#lasterrorobject */ | ||
@@ -297,2 +297,7 @@ lastErrorObject?: { | ||
/** | ||
* Apply this model's timestamps to a given POJO, including subdocument timestamps | ||
*/ | ||
applyTimestamps(obj: AnyObject, options?: { isUpdate?: boolean, currentTime?: () => Date }): AnyObject; | ||
/** | ||
* Sends multiple `insertOne`, `updateOne`, `updateMany`, `replaceOne`, | ||
@@ -299,0 +304,0 @@ * `deleteOne`, and/or `deleteMany` operations to the MongoDB server in one |
@@ -27,2 +27,3 @@ declare module 'mongoose' { | ||
| 'sanitizeFilter' | ||
| 'schemaLevelProjections' | ||
| 'setDefaultsOnInsert' | ||
@@ -183,2 +184,7 @@ | 'strict' | ||
sanitizeFilter?: boolean; | ||
/** | ||
* Enable or disable schema level projections for this query. Enabled by default. | ||
* Set to `false` to include fields with `select: false` in the query result by default. | ||
*/ | ||
schemaLevelProjections?: boolean; | ||
setDefaultsOnInsert?: boolean; | ||
@@ -216,3 +222,3 @@ skip?: number; | ||
type GetLeanResultType<RawDocType, ResultType, QueryOp> = QueryOp extends QueryOpThatReturnsDocument | ||
? (ResultType extends any[] ? Require_id<BufferToBinary<FlattenMaps<RawDocType>>>[] : Require_id<BufferToBinary<FlattenMaps<RawDocType>>>) | ||
? (ResultType extends any[] ? Default__v<Require_id<BufferToBinary<FlattenMaps<RawDocType>>>>[] : Default__v<Require_id<BufferToBinary<FlattenMaps<RawDocType>>>>) | ||
: ResultType; | ||
@@ -740,2 +746,8 @@ | ||
/** | ||
* Enable or disable schema level projections for this query. Enabled by default. | ||
* Set to `false` to include fields with `select: false` in the query result by default. | ||
*/ | ||
schemaLevelProjections(value: boolean): this; | ||
/** Specifies which document fields to include or exclude (also known as the query "projection") */ | ||
@@ -742,0 +754,0 @@ select<RawDocTypeOverride extends { [P in keyof RawDocType]?: any } = {}>( |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2748416
290
52033
4
+ Addedmongodb@6.10.0(transitive)
- Removedmongodb@6.9.0(transitive)
Updatedmongodb@~6.10.0