Socket
Socket
Sign inDemoInstall

mongoose

Package Overview
Dependencies
Maintainers
4
Versions
887
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.3 to 8.0.4

lib/helpers/projection/isNestedProjection.js

12

lib/cursor/changeStream.js

@@ -63,8 +63,2 @@ 'use strict';

this.driverChangeStream.on(ev, data => {
// Sometimes Node driver still polls after close, so
// avoid any uncaught exceptions due to closed change streams
// See tests for gh-7022
if (ev === 'error' && this.closed) {
return;
}
if (data != null && data.fullDocument != null && this.options && this.options.hydrate) {

@@ -87,8 +81,2 @@ data.fullDocument = this.options.model.hydrate(data.fullDocument);

this.driverChangeStream.on(ev, data => {
// Sometimes Node driver still polls after close, so
// avoid any uncaught exceptions due to closed change streams
// See tests for gh-7022
if (ev === 'error' && this.closed) {
return;
}
if (data != null && data.fullDocument != null && this.options && this.options.hydrate) {

@@ -95,0 +83,0 @@ data.fullDocument = this.options.model.hydrate(data.fullDocument);

9

lib/helpers/discriminator/applyEmbeddedDiscriminators.js

@@ -19,6 +19,13 @@ 'use strict';

}
if (schemaType._appliedDiscriminators) {
continue;
}
for (const disc of schemaType.schema._applyDiscriminators.keys()) {
schemaType.discriminator(disc, schemaType.schema._applyDiscriminators.get(disc));
schemaType.discriminator(
disc,
schemaType.schema._applyDiscriminators.get(disc)
);
}
schemaType._appliedDiscriminators = true;
}
}
'use strict';
const isNestedProjection = require('../projection/isNestedProjection');
module.exports = function applyDefaults(doc, fields, exclude, hasIncludedChildren, isBeforeSetters, pathsToSkip) {

@@ -35,3 +37,3 @@ const paths = Object.keys(doc.$__schema.paths);

const hasSubpaths = type.$isSingleNested || type.$isMongooseDocumentArray;
if (curPath in fields || (j === len - 1 && hasSubpaths && hasIncludedChildren != null && hasIncludedChildren[curPath])) {
if ((curPath in fields && !isNestedProjection(fields[curPath])) || (j === len - 1 && hasSubpaths && hasIncludedChildren != null && hasIncludedChildren[curPath])) {
included = true;

@@ -38,0 +40,0 @@ } else if (hasIncludedChildren != null && !hasIncludedChildren[curPath]) {

'use strict';
const hasDollarKeys = require('../query/hasDollarKeys');
function getRelatedSchemaIndexes(model, schemaIndexes) {

@@ -49,3 +51,5 @@ return getRelatedIndexes({

const partialFilterExpression = getPartialFilterExpression(index, indexesType);
return !partialFilterExpression || !partialFilterExpression[discriminatorKey];
return !partialFilterExpression
|| !partialFilterExpression[discriminatorKey]
|| (hasDollarKeys(partialFilterExpression[discriminatorKey]) && !('$eq' in partialFilterExpression[discriminatorKey]));
});

@@ -52,0 +56,0 @@ }

@@ -9,2 +9,3 @@ 'use strict';

const castUpdate = require('../query/castUpdate');
const clone = require('../clone');
const decorateUpdateWithVersionKey = require('../update/decorateUpdateWithVersionKey');

@@ -68,2 +69,4 @@ const { inspect } = require('util');

const update = clone(op['updateOne']['update']);
_addDiscriminatorToObject(schema, op['updateOne']['filter']);

@@ -74,7 +77,7 @@

const updatedAt = model.schema.$timestamps.updatedAt;
applyTimestampsToUpdate(now, createdAt, updatedAt, op['updateOne']['update'], {});
applyTimestampsToUpdate(now, createdAt, updatedAt, update, {});
}
if (op['updateOne'].timestamps !== false) {
applyTimestampsToChildren(now, op['updateOne']['update'], model.schema);
applyTimestampsToChildren(now, update, model.schema);
}

@@ -86,3 +89,3 @@

if (shouldSetDefaultsOnInsert !== false) {
setDefaultsOnInsert(op['updateOne']['filter'], model.schema, op['updateOne']['update'], {
setDefaultsOnInsert(op['updateOne']['filter'], model.schema, update, {
setDefaultsOnInsert: true,

@@ -94,3 +97,3 @@ upsert: op['updateOne'].upsert

decorateUpdateWithVersionKey(
op['updateOne']['update'],
update,
op['updateOne'],

@@ -104,4 +107,3 @@ model.schema.options.versionKey

});
op['updateOne']['update'] = castUpdate(model.schema, op['updateOne']['update'], {
op['updateOne']['update'] = castUpdate(model.schema, update, {
strict: strict,

@@ -108,0 +110,0 @@ upsert: op['updateOne'].upsert

@@ -24,2 +24,3 @@ 'use strict';

for (const key of keys) {
if (key.indexOf('.') === -1) {

@@ -26,0 +27,0 @@ hasIncludedChildren[key] = 1;

@@ -16,2 +16,3 @@ 'use strict';

const utils = require('../../utils');
const { internalToObjectOptions } = require('../../options');

@@ -103,3 +104,6 @@ const mongodbUpdateOperators = new Set([

hasDollarKey = hasDollarKey || op.startsWith('$');
if (val != null && val.$__) {
val = val.toObject(internalToObjectOptions);
ret[op] = val;
}
if (val &&

@@ -106,0 +110,0 @@ typeof val === 'object' &&

@@ -641,3 +641,3 @@ 'use strict';

function createLogicalQueryOperatorHandler(op) {
return function logicalQueryOperatorHandler(val) {
return function logicalQueryOperatorHandler(val, context) {
if (!Array.isArray(val)) {

@@ -649,3 +649,3 @@ throw new TypeError('conditional ' + op + ' requires an array');

for (const obj of val) {
ret.push(cast(this.casterConstructor.schema, obj, null, this && this.$$context));
ret.push(cast(this.casterConstructor.schema ?? context.schema, obj, null, this && this.$$context));
}

@@ -652,0 +652,0 @@

@@ -215,3 +215,10 @@ 'use strict';

return this.applySetters(val, context);
try {
return this.applySetters(val, context);
} catch (err) {
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
err.path = this.$fullPath;
}
throw err;
}
};

@@ -218,0 +225,0 @@

@@ -259,3 +259,10 @@ 'use strict';

return this.applySetters(val, context);
try {
return this.applySetters(val, context);
} catch (err) {
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
err.path = this.$fullPath;
}
throw err;
}
};

@@ -262,0 +269,0 @@

@@ -282,3 +282,12 @@ /*!

}
const casted = this.applySetters(val, context);
let casted;
try {
casted = this.applySetters(val, context);
} catch (err) {
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
err.path = this.$fullPath;
}
throw err;
}
return casted ? casted.toObject({ transform: false, virtuals: false }) : casted;

@@ -285,0 +294,0 @@ };

@@ -410,3 +410,10 @@ /*!

if ($conditional == null) {
return this.applySetters(val, context);
try {
return this.applySetters(val, context);
} catch (err) {
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
err.path = this.$fullPath;
}
throw err;
}
}

@@ -413,0 +420,0 @@

@@ -432,3 +432,12 @@ 'use strict';

}
val = this.applySetters(val, context);
try {
val = this.applySetters(val, context);
} catch (err) {
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
err.path = this.$fullPath;
}
throw err;
}
return val;

@@ -435,0 +444,0 @@ };

@@ -691,3 +691,10 @@ 'use strict';

return this.applySetters(val, context);
try {
return this.applySetters(val, context);
} catch (err) {
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
err.path = this.$fullPath;
}
throw err;
}
};

@@ -694,0 +701,0 @@

@@ -347,5 +347,12 @@ /*!

return handler.call(this, val, context);
} else {
return this.cast(val);
}
try {
return this.applySetters(val, context);
} catch (err) {
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
err.path = this.$fullPath;
}
throw err;
}
};

@@ -352,0 +359,0 @@

@@ -1633,3 +1633,10 @@ 'use strict';

return this.applySetters(val, context);
try {
return this.applySetters(val, context);
} catch (err) {
if (err instanceof CastError && err.path === this.path && this.$fullPath != null) {
err.path = this.$fullPath;
}
throw err;
}
};

@@ -1636,0 +1643,0 @@

@@ -185,3 +185,3 @@ 'use strict';

Subdocument.prototype.isModified = function(paths, modifiedPaths) {
Subdocument.prototype.isModified = function(paths, options, modifiedPaths) {
const parent = this.$parent();

@@ -196,6 +196,6 @@ if (parent != null) {

return parent.$isModified(paths, modifiedPaths);
return parent.$isModified(paths, options, modifiedPaths);
}
return Document.prototype.isModified.call(this, paths, modifiedPaths);
return Document.prototype.isModified.call(this, paths, options, modifiedPaths);
};

@@ -202,0 +202,0 @@

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

@@ -31,4 +31,4 @@ "keywords": [

"devDependencies": {
"@babel/core": "7.23.5",
"@babel/preset-env": "7.23.5",
"@babel/core": "7.23.7",
"@babel/preset-env": "7.23.7",
"@typescript-eslint/eslint-plugin": "^6.2.1",

@@ -49,3 +49,3 @@ "@typescript-eslint/parser": "^6.2.1",

"dox": "1.0.0",
"eslint": "8.55.0",
"eslint": "8.56.0",
"eslint-plugin-markdown": "^3.0.1",

@@ -70,4 +70,4 @@ "eslint-plugin-mocha-no-only": "1.1.1",

"stream-browserify": "3.0.0",
"tsd": "0.29.0",
"typescript": "5.3.2",
"tsd": "0.30.3",
"typescript": "5.3.3",
"uuid": "9.0.1",

@@ -74,0 +74,0 @@ "webpack": "5.89.0"

@@ -187,4 +187,4 @@ declare module 'mongoose' {

*/
isModified<T extends keyof DocType>(path?: T | Array<T>): boolean;
isModified(path?: string | Array<string>): boolean;
isModified<T extends keyof DocType>(path?: T | Array<T>, options?: { ignoreAtomics?: boolean } | null): boolean;
isModified(path?: string | Array<string>, options?: { ignoreAtomics?: boolean } | null): boolean;

@@ -191,0 +191,0 @@ /** Boolean flag specifying if the document is new. */

@@ -305,2 +305,5 @@ /// <reference path="./aggregate.d.ts" />

/** Returns a new schema that has the `paths` from the original schema, minus the omitted ones. */
omit<T = this>(paths: string[], options?: SchemaOptions): T;
/** Gets/sets schema paths. */

@@ -307,0 +310,0 @@ path<ResultType extends SchemaType = SchemaType<any, THydratedDocumentType>>(path: string): ResultType;

@@ -30,2 +30,3 @@ declare module 'mongoose' {

timestamps?: boolean;
strict?: boolean | 'throw';
}

@@ -35,3 +36,3 @@

timestamps?: boolean;
strict?: boolean;
strict?: boolean | 'throw';
session?: ClientSession;

@@ -227,3 +228,3 @@ skipValidation?: boolean;

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

@@ -260,3 +261,3 @@ number,

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

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

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

@@ -572,4 +573,4 @@ mongodb.DeleteResult,

findByIdAndDelete<ResultDoc = THydratedDocumentType>(
id?: mongodb.ObjectId | any,
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
id: mongodb.ObjectId | any,
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;

@@ -698,3 +699,3 @@ findByIdAndDelete<ResultDoc = THydratedDocumentType>(

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

@@ -709,3 +710,3 @@

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

@@ -717,3 +718,3 @@

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

@@ -720,0 +721,0 @@

@@ -98,7 +98,55 @@ declare module 'mongoose' {

interface MongooseSpecificQueryOptions {
/**
* If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
*/
lean?: boolean | Record<string, any>;
multipleCastError?: boolean;
overwriteDiscriminatorKey?: boolean;
/**
* Set to true to enable `update validators`
* (https://mongoosejs.com/docs/validation.html#update-validators). Defaults to false.
*/
runValidators?: boolean;
/**
* Set to `true` to automatically sanitize potentially unsafe query filters by stripping out query selectors that
* aren't explicitly allowed using `mongoose.trusted()`.
*/
sanitizeFilter?: boolean;
/* Set to `true` to automatically sanitize potentially unsafe user-generated query projections */
sanitizeProjection?: boolean;
setDefaultsOnInsert?: boolean;
/** overwrites the schema's strict mode option */
strict?: boolean | string;
/**
* equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
* [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
*/
strictQuery?: boolean | 'throw';
/**
* If set to `false` and schema-level timestamps are enabled,
* skip timestamps for this update. Note that this allows you to overwrite
* timestamps. Does nothing if schema-level timestamps are not set.
*/
timestamps?: boolean | QueryTimestampsConfig;
/**
* If `true`, convert any aliases in filter, projection, update, and distinct
* to their database property names. Defaults to false.
*/
translateAliases?: boolean;
[other: string]: any;
}
interface QueryOptions<DocType = unknown> extends
PopulateOption,
SessionOption {
SessionOption,
MongooseSpecificQueryOptions {
arrayFilters?: { [key: string]: any }[];
batchSize?: number;
bypassDocumentValidation?: boolean;
collation?: mongodb.CollationOptions;

@@ -110,10 +158,7 @@ comment?: any;

hint?: mongodb.Hint;
/**
* If truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document.
*/
lean?: boolean | Record<string, any>;
let?: Record<string, any>;
limit?: number;
maxTimeMS?: number;
multi?: boolean;
multipleCastError?: boolean;
/**

@@ -125,4 +170,2 @@ * By default, `findOneAndUpdate()` returns the document as it was **before**

new?: boolean;
overwriteDiscriminatorKey?: boolean;
projection?: ProjectionType<DocType>;

@@ -142,36 +185,7 @@ /**

returnDocument?: 'before' | 'after';
/**
* Set to true to enable `update validators`
* (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;
/**
* Set to `true` to automatically sanitize potentially unsafe query filters by stripping out query selectors that
* aren't explicitly allowed using `mongoose.trusted()`.
*/
sanitizeFilter?: boolean;
setDefaultsOnInsert?: boolean;
skip?: number;
sort?: any;
/** overwrites the schema's strict mode option */
strict?: boolean | string;
/**
* equal to `strict` by default, may be `false`, `true`, or `'throw'`. Sets the default
* [strictQuery](https://mongoosejs.com/docs/guide.html#strictQuery) mode for schemas.
*/
strictQuery?: boolean | 'throw';
tailable?: number;
/**
* If set to `false` and schema-level timestamps are enabled,
* skip timestamps for this update. Note that this allows you to overwrite
* timestamps. Does nothing if schema-level timestamps are not set.
*/
timestamps?: boolean | QueryTimestampsConfig;
/**
* If `true`, convert any aliases in filter, projection, update, and distinct
* to their database property names. Defaults to false.
*/
translateAliases?: boolean;
upsert?: boolean;

@@ -423,2 +437,6 @@ useBigInt64?: boolean;

findByIdAndDelete(
id: mongodb.ObjectId | any,
options: QueryOptions<DocType> & { includeResultMetadata: true }
): QueryWithHelpers<ModifyResult<DocType>, DocType, THelpers, RawDocType, 'findOneAndDelete'>;
findByIdAndDelete(
id?: mongodb.ObjectId | any,

@@ -425,0 +443,0 @@ options?: QueryOptions<DocType> | null

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

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