mongoose 8.2.3 → 8.3.0

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.
@@ -192,10 +192,14 @@ declare module 'mongoose' {
192
192
  [other: string]: any;
193
193
  }
194
194
 
195
- interface Validator {
196
- message?: string; type?: string; validator?: Function
195
+ interface Validator<DocType = any> {
196
+ message?: string;
197
+ type?: string;
198
+ validator?: ValidatorFunction<DocType>;
197
199
  }
198
200
 
201
+ type ValidatorFunction<DocType = any> = (this: DocType, value: any, validatorProperties?: Validator) => any;
202
+
199
203
  class SchemaType<T = any, DocType = any> {
200
204
  /** SchemaType constructor */
201
205
  constructor(path: string, options?: AnyObject, instance?: string);
@@ -281,7 +285,10 @@ declare module 'mongoose' {
281
285
  validators: Validator[];
282
286
 
283
287
  /** Adds validator(s) for this document path. */
284
- validate(obj: RegExp | ((this: DocType, value: any, validatorProperties?: Validator) => any), errorMsg?: string, type?: string): this;
288
+ validate(obj: RegExp | ValidatorFunction<DocType> | Validator<DocType>, errorMsg?: string, type?: string): this;
289
+
290
+ /** Adds multiple validators for this document path. */
291
+ validateAll(validators: Array<RegExp | ValidatorFunction<DocType> | Validator<DocType>>): this;
285
292
 
286
293
  /** Default options for this SchemaType */
287
294
  defaultOptions?: Record<string, any>;