Socket
Socket
Sign inDemoInstall

mongoose

Package Overview
Dependencies
Maintainers
4
Versions
884
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose - npm Package Compare versions

Comparing version 8.0.4 to 8.1.0

23

lib/connection.js

@@ -609,2 +609,22 @@ 'use strict';

/**
* Helper for MongoDB Node driver's `listCollections()`.
* Returns an array of collection objects.
*
* @method listCollections
* @return {Promise<Collection[]>}
* @api public
*/
Connection.prototype.listCollections = async function listCollections() {
if ((this.readyState === STATES.connecting || this.readyState === STATES.disconnected) && this._shouldBufferCommands()) {
await new Promise(resolve => {
this._queue.push({ fn: resolve });
});
}
const cursor = this.db.listCollections();
return await cursor.toArray();
};
/**
* Helper for `dropDatabase()`. Deletes the given database, including all

@@ -987,3 +1007,4 @@ * collections, documents, and indexes.

autoIndex: this.config.autoIndex != null ? this.config.autoIndex : this.base.options.autoIndex,
autoCreate: this.config.autoCreate != null ? this.config.autoCreate : this.base.options.autoCreate
autoCreate: this.config.autoCreate != null ? this.config.autoCreate : this.base.options.autoCreate,
autoSearchIndex: this.config.autoSearchIndex != null ? this.config.autoSearchIndex : this.base.options.autoSearchIndex
};

@@ -990,0 +1011,0 @@ options = Object.assign({}, defaultOptions, options ? clone(options) : {});

@@ -249,2 +249,7 @@ /*!

if ('autoSearchIndex' in options) {
this.config.autoSearchIndex = options.autoSearchIndex;
delete options.autoSearchIndex;
}
// Backwards compat

@@ -251,0 +256,0 @@ if (options.user || options.pass) {

3

lib/mongoose.js

@@ -68,3 +68,4 @@ 'use strict';

autoIndex: true,
autoCreate: true
autoCreate: true,
autoSearchIndex: false
}, options);

@@ -71,0 +72,0 @@ const createInitialConnection = utils.getOption('createInitialConnection', this.options);

@@ -62,3 +62,5 @@ 'use strict';

for (const option of defaultOptionsKeys) {
if (defaultOptions.hasOwnProperty(option) && !Object.prototype.hasOwnProperty.call(options, option)) {
if (option === 'validate') {
this.validate(defaultOptions.validate);
} else if (defaultOptions.hasOwnProperty(option) && !Object.prototype.hasOwnProperty.call(options, option)) {
options[option] = defaultOptions[option];

@@ -65,0 +67,0 @@ }

@@ -14,2 +14,3 @@

'autoIndex',
'autoSearchIndex',
'bufferCommands',

@@ -16,0 +17,0 @@ 'bufferTimeoutMS',

{
"name": "mongoose",
"description": "Mongoose MongoDB ODM",
"version": "8.0.4",
"version": "8.1.0",
"author": "Guillermo Rauch <guillermo@learnboost.com>",

@@ -24,3 +24,3 @@ "keywords": [

"kareem": "2.5.1",
"mongodb": "6.2.0",
"mongodb": "6.3.0",
"mpath": "0.9.0",

@@ -27,0 +27,0 @@ "mquery": "5.0.0",

@@ -51,3 +51,3 @@ declare module 'mongoose' {

autoIndex?: boolean;
/** Set to `true` to make Mongoose automatically call `createCollection()` on every model created on this connection. */
/** Set to `false` to disable Mongoose automatically calling `createCollection()` on every model created on this connection. */
autoCreate?: boolean;

@@ -126,2 +126,8 @@ }

/**
* Helper for MongoDB Node driver's `listCollections()`.
* Returns an array of collection names.
*/
listCollections(): Promise<Pick<mongodb.CollectionInfo, 'name' | 'type'>[]>;
/**
* A [POJO](https://masteringjs.io/tutorials/fundamentals/pojo) containing

@@ -128,0 +134,0 @@ * a map from model names to models. Contains all models that have been

@@ -163,2 +163,8 @@ import {

/**
* @summary Allows users to optionally choose their own type for a schema field for stronger typing.
*/
type TypeHint<T> = T extends { __typehint: infer U } ? U: never;
/**
* @summary Obtains schema Path type.

@@ -172,3 +178,4 @@ * @description Obtains Path type by separating path type from other options and calling {@link ResolvePathType}

PathValueType extends PathWithTypePropertyBaseType<TypeKey> ? Omit<PathValueType, TypeKey> : {},
TypeKey
TypeKey,
TypeHint<PathValueType>
>;

@@ -213,31 +220,17 @@

*/
type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}, TypeKey extends string = DefaultSchemaOptions['typeKey']> =
PathValueType extends Schema ? InferSchemaType<PathValueType> :
PathValueType extends (infer Item)[] ?
IfEquals<Item, never, any[], Item extends Schema ?
// If Item is a schema, infer its type.
Types.DocumentArray<InferSchemaType<Item>> :
Item extends Record<TypeKey, any> ?
Item[TypeKey] extends Function | String ?
// If Item has a type key that's a string or a callable, it must be a scalar,
// so we can directly obtain its path type.
ObtainDocumentPathType<Item, TypeKey>[] :
// If the type key isn't callable, then this is an array of objects, in which case
// we need to call ObtainDocumentType to correctly infer its type.
ObtainDocumentType<Item, any, { typeKey: TypeKey }>[] :
IsSchemaTypeFromBuiltinClass<Item> extends true ?
ObtainDocumentPathType<Item, TypeKey>[] :
IsItRecordAndNotAny<Item> extends true ?
Item extends Record<string, never> ?
ObtainDocumentPathType<Item, TypeKey>[] :
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
ObtainDocumentPathType<Item, TypeKey>[]
>:
PathValueType extends ReadonlyArray<infer Item> ?
type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}, TypeKey extends string = DefaultSchemaOptions['typeKey'], TypeHint = never> =
IfEquals<TypeHint, never,
PathValueType extends Schema ? InferSchemaType<PathValueType> :
PathValueType extends (infer Item)[] ?
IfEquals<Item, never, any[], Item extends Schema ?
// If Item is a schema, infer its type.
Types.DocumentArray<InferSchemaType<Item>> :
Item extends Record<TypeKey, any> ?
Item[TypeKey] extends Function | String ?
// If Item has a type key that's a string or a callable, it must be a scalar,
// so we can directly obtain its path type.
ObtainDocumentPathType<Item, TypeKey>[] :
ObtainDocumentType<Item, any, { typeKey: TypeKey }>[]:
// If the type key isn't callable, then this is an array of objects, in which case
// we need to call ObtainDocumentType to correctly infer its type.
ObtainDocumentType<Item, any, { typeKey: TypeKey }>[] :
IsSchemaTypeFromBuiltinClass<Item> extends true ?

@@ -251,31 +244,47 @@ ObtainDocumentPathType<Item, TypeKey>[] :

>:
PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']> :
IfEquals<PathValueType, Schema.Types.String> extends true ? PathEnumOrString<Options['enum']> :
IfEquals<PathValueType, String> extends true ? PathEnumOrString<Options['enum']> :
PathValueType extends NumberSchemaDefinition ? Options['enum'] extends ReadonlyArray<any> ? Options['enum'][number] : number :
IfEquals<PathValueType, Schema.Types.Number> extends true ? number :
PathValueType extends DateSchemaDefinition ? Date :
IfEquals<PathValueType, Schema.Types.Date> extends true ? Date :
PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer :
PathValueType extends BooleanSchemaDefinition ? boolean :
IfEquals<PathValueType, Schema.Types.Boolean> extends true ? boolean :
PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId :
IfEquals<PathValueType, Types.ObjectId> extends true ? Types.ObjectId :
IfEquals<PathValueType, Schema.Types.ObjectId> extends true ? Types.ObjectId :
PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
IfEquals<PathValueType, Schema.Types.Decimal128> extends true ? Types.Decimal128 :
IfEquals<PathValueType, Types.Decimal128> extends true ? Types.Decimal128 :
IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
IfEquals<PathValueType, BigInt> extends true ? bigint :
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
PathValueType extends ArrayConstructor ? any[] :
PathValueType extends typeof Schema.Types.Mixed ? any:
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
IfEquals<PathValueType, {}> extends true ? any:
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
unknown;
PathValueType extends ReadonlyArray<infer Item> ?
IfEquals<Item, never, any[], Item extends Schema ?
Types.DocumentArray<InferSchemaType<Item>> :
Item extends Record<TypeKey, any> ?
Item[TypeKey] extends Function | String ?
ObtainDocumentPathType<Item, TypeKey>[] :
ObtainDocumentType<Item, any, { typeKey: TypeKey }>[]:
IsSchemaTypeFromBuiltinClass<Item> extends true ?
ObtainDocumentPathType<Item, TypeKey>[] :
IsItRecordAndNotAny<Item> extends true ?
Item extends Record<string, never> ?
ObtainDocumentPathType<Item, TypeKey>[] :
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>> :
ObtainDocumentPathType<Item, TypeKey>[]
>:
PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']> :
IfEquals<PathValueType, Schema.Types.String> extends true ? PathEnumOrString<Options['enum']> :
IfEquals<PathValueType, String> extends true ? PathEnumOrString<Options['enum']> :
PathValueType extends NumberSchemaDefinition ? Options['enum'] extends ReadonlyArray<any> ? Options['enum'][number] : number :
IfEquals<PathValueType, Schema.Types.Number> extends true ? number :
PathValueType extends DateSchemaDefinition ? Date :
IfEquals<PathValueType, Schema.Types.Date> extends true ? Date :
PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer :
PathValueType extends BooleanSchemaDefinition ? boolean :
IfEquals<PathValueType, Schema.Types.Boolean> extends true ? boolean :
PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId :
IfEquals<PathValueType, Types.ObjectId> extends true ? Types.ObjectId :
IfEquals<PathValueType, Schema.Types.ObjectId> extends true ? Types.ObjectId :
PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
IfEquals<PathValueType, Schema.Types.Decimal128> extends true ? Types.Decimal128 :
IfEquals<PathValueType, Types.Decimal128> extends true ? Types.Decimal128 :
IfEquals<PathValueType, Schema.Types.BigInt> extends true ? bigint :
IfEquals<PathValueType, BigInt> extends true ? bigint :
PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint :
PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer :
IfEquals<PathValueType, Schema.Types.UUID> extends true ? Buffer :
PathValueType extends MapConstructor | 'Map' ? Map<string, ResolvePathType<Options['of']>> :
IfEquals<PathValueType, typeof Schema.Types.Map> extends true ? Map<string, ResolvePathType<Options['of']>> :
PathValueType extends ArrayConstructor ? any[] :
PathValueType extends typeof Schema.Types.Mixed ? any:
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
IfEquals<PathValueType, {}> extends true ? any:
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
PathValueType extends Record<string, any> ? ObtainDocumentType<PathValueType, any, { typeKey: TypeKey }> :
unknown,
TypeHint>;

@@ -226,3 +226,3 @@ declare module 'mongoose' {

filter?: FilterQuery<TRawDocType>,
options?: (mongodb.CountOptions & Omit<MongooseSpecificQueryOptions, 'lean' | 'timestamps'>) | null
options?: (mongodb.CountOptions & Omit<MongooseQueryOptions<TRawDocType>, 'lean' | 'timestamps'>) | null
): QueryWithHelpers<

@@ -249,2 +249,8 @@ number,

/**
* Create an [Atlas search index](https://www.mongodb.com/docs/atlas/atlas-search/create-index/).
* This function only works when connected to MongoDB Atlas.
*/
createSearchIndex(description: mongodb.SearchIndexDescription): Promise<string>;
/** Connection the model uses. */

@@ -260,3 +266,3 @@ db: Connection;

filter?: FilterQuery<TRawDocType>,
options?: (mongodb.DeleteOptions & Omit<MongooseSpecificQueryOptions, 'lean' | 'timestamps'>) | null
options?: (mongodb.DeleteOptions & Omit<MongooseQueryOptions<TRawDocType>, 'lean' | 'timestamps'>) | null
): QueryWithHelpers<

@@ -286,3 +292,3 @@ mongodb.DeleteResult,

filter?: FilterQuery<TRawDocType>,
options?: (mongodb.DeleteOptions & Omit<MongooseSpecificQueryOptions, 'lean' | 'timestamps'>) | null
options?: (mongodb.DeleteOptions & Omit<MongooseQueryOptions<TRawDocType>, 'lean' | 'timestamps'>) | null
): QueryWithHelpers<

@@ -306,2 +312,8 @@ mongodb.DeleteResult,

/**
* Delete an existing [Atlas search index](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) by name.
* This function only works when connected to MongoDB Atlas.
*/
dropSearchIndex(name: string): Promise<void>;
/**
* Event emitter that reports any errors that occurred. Useful for global error

@@ -481,2 +493,8 @@ * handling.

/**
* Update an existing [Atlas search index](https://www.mongodb.com/docs/atlas/atlas-search/create-index/).
* This function only works when connected to MongoDB Atlas.
*/
updateSearchIndex(name: string, definition: AnyObject): Promise<void>;
/** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */

@@ -699,3 +717,3 @@ validate(): Promise<void>;

replacement?: TRawDocType | AnyObject,
options?: (mongodb.ReplaceOptions & MongooseSpecificQueryOptions) | null
options?: (mongodb.ReplaceOptions & MongooseQueryOptions<TRawDocType>) | null
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'replaceOne'>;

@@ -710,3 +728,3 @@

update?: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
options?: (mongodb.UpdateOptions & Omit<MongooseSpecificQueryOptions, 'lean'>) | null
options?: (mongodb.UpdateOptions & Omit<MongooseQueryOptions<TRawDocType>, 'lean'>) | null
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'updateMany'>;

@@ -718,3 +736,3 @@

update?: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
options?: (mongodb.UpdateOptions & Omit<MongooseSpecificQueryOptions, 'lean'>) | null
options?: (mongodb.UpdateOptions & Omit<MongooseQueryOptions<TRawDocType>, 'lean'>) | null
): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'updateOne'>;

@@ -721,0 +739,0 @@

@@ -20,3 +20,10 @@ declare module 'mongoose' {

type MongooseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, 'populate' | 'lean' | 'strict' | 'sanitizeProjection' | 'sanitizeFilter'>;
type MongooseQueryOptions<DocType = unknown> = Pick<QueryOptions<DocType>, 'populate' |
'lean' |
'strict' |
'sanitizeProjection' |
'sanitizeFilter' |
'timestamps' |
'translateAliases'
>;

@@ -99,3 +106,13 @@ type ProjectionFields<DocType> = { [Key in keyof DocType]?: any } & Record<string, any>;

interface MongooseSpecificQueryOptions {
interface QueryOptions<DocType = unknown> extends
PopulateOption,
SessionOption {
arrayFilters?: { [key: string]: any }[];
batchSize?: number;
collation?: mongodb.CollationOptions;
comment?: any;
context?: string;
explain?: mongodb.ExplainVerbosityLike;
fields?: any | string;
hint?: mongodb.Hint;
/**

@@ -105,7 +122,29 @@ * If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.

lean?: boolean | Record<string, any>;
limit?: number;
maxTimeMS?: number;
multi?: boolean;
multipleCastError?: boolean;
/**
* By default, `findOneAndUpdate()` returns the document as it was **before**
* `update` was applied. If you set `new: true`, `findOneAndUpdate()` will
* instead give you the object after `update` was applied.
*/
new?: boolean;
overwriteDiscriminatorKey?: boolean;
projection?: ProjectionType<DocType>;
/**
* if true, returns the full ModifyResult rather than just the document
*/
includeResultMetadata?: boolean;
readPreference?: string | mongodb.ReadPreferenceMode;
/**
* An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
*/
returnOriginal?: boolean;
/**
* Another alias for the `new` option. `returnOriginal` is deprecated so this should be used.
*/
returnDocument?: 'before' | 'after';
/**
* Set to true to enable `update validators`

@@ -115,2 +154,4 @@ * (https://mongoosejs.com/docs/validation.html#update-validators). Defaults to false.

runValidators?: boolean;
/* Set to `true` to automatically sanitize potentially unsafe user-generated query projections */
sanitizeProjection?: boolean;
/**

@@ -121,8 +162,7 @@ * Set to `true` to automatically sanitize potentially unsafe query filters by stripping out query selectors that

sanitizeFilter?: boolean;
/* Set to `true` to automatically sanitize potentially unsafe user-generated query projections */
sanitizeProjection?: boolean;
setDefaultsOnInsert?: boolean;
skip?: number;
sort?: any;
/** overwrites the schema's strict mode option */
strict?: boolean | string;
/**

@@ -133,2 +173,3 @@ * equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default

strictQuery?: boolean | 'throw';
tailable?: number;
/**

@@ -140,3 +181,2 @@ * If set to `false` and schema-level timestamps are enabled,

timestamps?: boolean | QueryTimestampsConfig;
/**

@@ -147,49 +187,2 @@ * If `true`, convert any aliases in filter, projection, update, and distinct

translateAliases?: boolean;
[other: string]: any;
}
interface QueryOptions<DocType = unknown> extends
PopulateOption,
SessionOption,
MongooseSpecificQueryOptions {
arrayFilters?: { [key: string]: any }[];
batchSize?: number;
bypassDocumentValidation?: boolean;
collation?: mongodb.CollationOptions;
comment?: any;
context?: string;
explain?: mongodb.ExplainVerbosityLike;
fields?: any | string;
hint?: mongodb.Hint;
let?: Record<string, any>;
limit?: number;
maxTimeMS?: number;
multi?: boolean;
/**
* By default, `findOneAndUpdate()` returns the document as it was **before**
* `update` was applied. If you set `new: true`, `findOneAndUpdate()` will
* instead give you the object after `update` was applied.
*/
new?: boolean;
projection?: ProjectionType<DocType>;
/**
* if true, returns the full ModifyResult rather than just the document
*/
includeResultMetadata?: boolean;
readPreference?: string | mongodb.ReadPreferenceMode;
/**
* An alias for the `new` option. `returnOriginal: false` is equivalent to `new: true`.
*/
returnOriginal?: boolean;
/**
* Another alias for the `new` option. `returnOriginal` is deprecated so this should be used.
*/
returnDocument?: 'before' | 'after';
skip?: number;
sort?: any;
tailable?: number;
upsert?: boolean;

@@ -196,0 +189,0 @@ useBigInt64?: boolean;

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc