mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 07:17:04 +00:00
UpdateType(mongoose): add interfaces for promisified schema validators
Add `AsyncPromiseValidationFn`, `AsyncPromiseValidationOpts` as described in this document https://mongoosejs.com/docs/validation.html
This commit is contained in:
Vendored
+11
-1
@@ -977,7 +977,9 @@ declare module "mongoose" {
|
||||
validate?: RegExp | [RegExp, string] |
|
||||
SchemaTypeOpts.ValidateFn<T> | [SchemaTypeOpts.ValidateFn<T>, string] |
|
||||
SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.ValidateOpts[] |
|
||||
SchemaTypeOpts.AsyncValidateOpts | SchemaTypeOpts.AsyncValidateOpts[];
|
||||
SchemaTypeOpts.AsyncValidateOpts | SchemaTypeOpts.AsyncValidateOpts[] |
|
||||
SchemaTypeOpts.AsyncPromiseValidationFn<T> | SchemaTypeOpts.AsyncPromiseValidationFn<T>[] |
|
||||
SchemaTypeOpts.AsyncPromiseValidationOpts | SchemaTypeOpts.AsyncPromiseValidationOpts[];
|
||||
|
||||
/** Declares an unique index. */
|
||||
unique?: boolean | any;
|
||||
@@ -1060,6 +1062,14 @@ declare module "mongoose" {
|
||||
validator: AsyncValidateFn<any>;
|
||||
}
|
||||
|
||||
interface AsyncPromiseValidationFn<T> {
|
||||
(value: T): Promise<boolean>;
|
||||
}
|
||||
|
||||
interface AsyncPromiseValidationOpts extends ValidateOptsBase {
|
||||
validator: AsyncPromiseValidationFn<any>;
|
||||
}
|
||||
|
||||
interface EnumOpts<T> {
|
||||
values?: T[];
|
||||
message?: string;
|
||||
|
||||
@@ -524,7 +524,15 @@ new mongoose.Schema({
|
||||
setImmediate(done, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
promiseValidated: {
|
||||
type: Number,
|
||||
validate: {
|
||||
validator: async (val: number) => {
|
||||
return val === 2;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
new mongoose.Schema({ name: { type: String, validate: [
|
||||
{ validator: () => {return true}, msg: 'uh oh' },
|
||||
|
||||
Reference in New Issue
Block a user