mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #28390 from mernxl/mongoose
UpdateType(mongoose): add interfaces for promisified schema validators
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.AsyncValidateOpts |
|
||||
(SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.AsyncValidateOpts)[];
|
||||
SchemaTypeOpts.AsyncPromiseValidationFn<T> | SchemaTypeOpts.AsyncPromiseValidationOpts |
|
||||
(SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.AsyncValidateOpts |
|
||||
SchemaTypeOpts.AsyncPromiseValidationFn<T> | 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