Comparing version 8.2.4 to 8.3.0
@@ -282,3 +282,3 @@ 'use strict'; | ||
doc.$__validate(callback); | ||
doc.$__validate(null, options, callback); | ||
} | ||
@@ -334,3 +334,3 @@ } | ||
const subdocValidateError = doc.validateSync(); | ||
const subdocValidateError = doc.validateSync(options); | ||
@@ -337,0 +337,0 @@ if (subdocValidateError && resultError == null) { |
@@ -807,2 +807,17 @@ 'use strict'; | ||
/** | ||
* Adds multiple validators for this document path. | ||
* Calls `validate()` for every element in validators. | ||
* | ||
* @param {Array<RegExp|Function|Object>} validators | ||
* @returns this | ||
*/ | ||
SchemaType.prototype.validateAll = function(validators) { | ||
for (let i = 0; i < validators.length; i++) { | ||
this.validate(validators[i]); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Adds validator(s) for this document path. | ||
@@ -1289,2 +1304,5 @@ * | ||
const path = this.path; | ||
if (typeof fn !== 'function') { | ||
throw new TypeError(`Must pass callback function to doValidate(), got ${typeof fn}`); | ||
} | ||
@@ -1424,3 +1442,2 @@ // Avoid non-object `validators` | ||
for (i = 0; i < len; ++i) { | ||
const v = validators[i]; | ||
@@ -1427,0 +1444,0 @@ |
{ | ||
"name": "mongoose", | ||
"description": "Mongoose MongoDB ODM", | ||
"version": "8.2.4", | ||
"version": "8.3.0", | ||
"author": "Guillermo Rauch <guillermo@learnboost.com>", | ||
@@ -22,5 +22,5 @@ "keywords": [ | ||
"dependencies": { | ||
"bson": "^6.2.0", | ||
"kareem": "2.5.1", | ||
"mongodb": "6.3.0", | ||
"bson": "^6.5.0", | ||
"kareem": "2.6.0", | ||
"mongodb": "6.5.0", | ||
"mpath": "0.9.0", | ||
@@ -32,4 +32,4 @@ "mquery": "5.0.0", | ||
"devDependencies": { | ||
"@babel/core": "7.24.0", | ||
"@babel/preset-env": "7.24.0", | ||
"@babel/core": "7.24.3", | ||
"@babel/preset-env": "7.24.3", | ||
"@typescript-eslint/eslint-plugin": "^6.2.1", | ||
@@ -51,3 +51,3 @@ "@typescript-eslint/parser": "^6.2.1", | ||
"eslint": "8.57.0", | ||
"eslint-plugin-markdown": "^3.0.1", | ||
"eslint-plugin-markdown": "^4.0.1", | ||
"eslint-plugin-mocha-no-only": "1.1.1", | ||
@@ -62,3 +62,3 @@ "express": "^4.18.1", | ||
"mkdirp": "^3.0.1", | ||
"mocha": "10.3.0", | ||
"mocha": "10.4.0", | ||
"moment": "2.x", | ||
@@ -72,6 +72,6 @@ "mongodb-memory-server": "8.15.1", | ||
"stream-browserify": "3.0.0", | ||
"tsd": "0.30.7", | ||
"typescript": "5.3.3", | ||
"tsd": "0.31.0", | ||
"typescript": "5.4.3", | ||
"uuid": "9.0.1", | ||
"webpack": "5.90.3" | ||
"webpack": "5.91.0" | ||
}, | ||
@@ -78,0 +78,0 @@ "directories": { |
@@ -30,2 +30,3 @@ /// <reference path="./aggregate.d.ts" /> | ||
declare module 'mongoose' { | ||
import Kareem = require('kareem'); | ||
import events = require('events'); | ||
@@ -401,3 +402,2 @@ import mongodb = require('mongodb'); | ||
pre<T = THydratedDocumentType>(method: 'save', fn: PreSaveMiddlewareFunction<T>): this; | ||
pre<T = THydratedDocumentType>(method: 'save', options: SchemaPreOptions, fn: PreSaveMiddlewareFunction<T>): this; | ||
pre<T = THydratedDocumentType>(method: MongooseDistinctDocumentMiddleware|MongooseDistinctDocumentMiddleware[], fn: PreMiddlewareFunction<T>): this; | ||
@@ -420,3 +420,2 @@ pre<T = THydratedDocumentType>(method: MongooseDistinctDocumentMiddleware|MongooseDistinctDocumentMiddleware[], options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this; | ||
pre<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PreMiddlewareFunction<T>): this; | ||
pre<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPreOptions, fn: PreMiddlewareFunction<T>): this; | ||
/* method insertMany */ | ||
@@ -432,12 +431,2 @@ pre<T = TModelType>( | ||
): this; | ||
pre<T = TModelType>( | ||
method: 'insertMany' | RegExp, | ||
options: SchemaPreOptions, | ||
fn: ( | ||
this: T, | ||
next: (err?: CallbackError) => void, | ||
docs: any | Array<any>, | ||
options?: InsertManyOptions & { lean?: boolean } | ||
) => void | Promise<void> | ||
): this; | ||
/* method bulkWrite */ | ||
@@ -453,12 +442,2 @@ pre<T = TModelType>( | ||
): this; | ||
pre<T = TModelType>( | ||
method: 'bulkWrite' | RegExp, | ||
options: SchemaPreOptions, | ||
fn: ( | ||
this: T, | ||
next: (err?: CallbackError) => void, | ||
ops: Array<mongodb.AnyBulkWriteOperation<any> & MongooseBulkWritePerWriteOptions>, | ||
options?: mongodb.BulkWriteOptions & MongooseBulkWriteOptions | ||
) => void | Promise<void> | ||
): this; | ||
/* method createCollection */ | ||
@@ -473,11 +452,2 @@ pre<T = TModelType>( | ||
): this; | ||
pre<T = TModelType>( | ||
method: 'createCollection' | RegExp, | ||
options: SchemaPreOptions, | ||
fn: ( | ||
this: T, | ||
next: (err?: CallbackError) => void, | ||
options?: mongodb.CreateCollectionOptions & Pick<SchemaOptions, 'expires'> | ||
) => void | Promise<void> | ||
): this; | ||
@@ -731,3 +701,7 @@ /** Object of currently defined query helpers on this schema. */ | ||
export function overwriteMiddlewareResult(val: any): Kareem.OverwriteMiddlewareResult; | ||
export function skipMiddlewareFunction(val: any): Kareem.SkipWrappedFunction; | ||
export default mongoose; | ||
} |
declare module 'mongoose' { | ||
import Kareem = require('kareem'); | ||
@@ -40,3 +41,3 @@ type MongooseQueryAndDocumentMiddleware = 'updateOne' | 'deleteOne'; | ||
opts?: Record<string, any> | ||
) => void | Promise<void>; | ||
) => void | Promise<void> | Kareem.SkipWrappedFunction; | ||
type PreSaveMiddlewareFunction<ThisType = any> = ( | ||
@@ -46,6 +47,6 @@ this: ThisType, | ||
opts: SaveOptions | ||
) => void | Promise<void>; | ||
type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>; | ||
) => void | Promise<void> | Kareem.SkipWrappedFunction; | ||
type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void> | Kareem.OverwriteMiddlewareResult; | ||
type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void; | ||
type ErrorHandlingMiddlewareWithOption<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType | null, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>; | ||
type ErrorHandlingMiddlewareWithOption<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType | null, next: CallbackWithoutResultAndOptionalError) => void | Promise<void> | Kareem.OverwriteMiddlewareResult; | ||
} |
@@ -744,3 +744,6 @@ declare module 'mongoose' { | ||
/** Sets the sort order. If an object is passed, values allowed are `asc`, `desc`, `ascending`, `descending`, `1`, and `-1`. */ | ||
sort(arg?: string | { [key: string]: SortOrder | { $meta: any } } | [string, SortOrder][] | undefined | null): this; | ||
sort( | ||
arg?: string | { [key: string]: SortOrder | { $meta: any } } | [string, SortOrder][] | undefined | null, | ||
options?: { override?: boolean } | ||
): this; | ||
@@ -747,0 +750,0 @@ /** Sets the tailable option (for use with capped collections). */ |
@@ -195,6 +195,10 @@ declare module 'mongoose' { | ||
interface Validator { | ||
message?: string; type?: string; validator?: Function | ||
interface Validator<DocType = any> { | ||
message?: string; | ||
type?: string; | ||
validator?: ValidatorFunction<DocType>; | ||
} | ||
type ValidatorFunction<DocType = any> = (this: DocType, value: any, validatorProperties?: Validator) => any; | ||
class SchemaType<T = any, DocType = any> { | ||
@@ -285,4 +289,7 @@ /** SchemaType constructor */ | ||
/** Adds validator(s) for this document path. */ | ||
validate(obj: RegExp | ((this: DocType, value: any, validatorProperties?: Validator) => any), errorMsg?: string, type?: string): this; | ||
validate(obj: RegExp | ValidatorFunction<DocType> | Validator<DocType>, errorMsg?: string, type?: string): this; | ||
/** Adds multiple validators for this document path. */ | ||
validateAll(validators: Array<RegExp | ValidatorFunction<DocType> | Validator<DocType>>): this; | ||
/** Default options for this SchemaType */ | ||
@@ -289,0 +296,0 @@ defaultOptions?: Record<string, 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
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
2640522
50146
+ Addedkareem@2.6.0(transitive)
+ Addedmongodb@6.5.0(transitive)
- Removedkareem@2.5.1(transitive)
- Removedmongodb@6.3.0(transitive)
Updatedbson@^6.5.0
Updatedkareem@2.6.0
Updatedmongodb@6.5.0