mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 01:47:21 +08:00
Merge pull request #13529 from simonxca/patch-mongoose
Mongoose add Object fallback for Schema defs fixes #13356
This commit is contained in:
54
mongoose/index.d.ts
vendored
54
mongoose/index.d.ts
vendored
@@ -748,6 +748,18 @@ declare module "mongoose" {
|
||||
* ...
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* Note: the properties have Object as a fallback type: | Object
|
||||
* because this interface does not apply to a schematype that
|
||||
* does not have a type property. Ex:
|
||||
* new Schema({
|
||||
* name: {
|
||||
* first: String, // since name does not have a "type" property
|
||||
* last: String // first and last can have any valid type
|
||||
* ...
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* References:
|
||||
* - http://mongoosejs.com/docs/schematypes.html
|
||||
* - http://mongoosejs.com/docs/api.html#schema_Schema.Types
|
||||
@@ -763,7 +775,7 @@ declare module "mongoose" {
|
||||
* Getters allow you to transform the representation of the data as it travels
|
||||
* from the raw mongodb document to the value that you see.
|
||||
*/
|
||||
get?: (value: T, schematype?: this) => T;
|
||||
get?: (value: T, schematype?: this) => T | Object;
|
||||
|
||||
/** Declares the index options for this schematype. */
|
||||
index?: SchemaTypeOpts.IndexOpts | boolean | string;
|
||||
@@ -774,7 +786,8 @@ declare module "mongoose" {
|
||||
*/
|
||||
required?: SchemaTypeOpts.RequiredFn<T> |
|
||||
boolean | [boolean, string] |
|
||||
string | [string, string];
|
||||
string | [string, string] |
|
||||
Object;
|
||||
|
||||
/**
|
||||
* Sets default select() behavior for this path.
|
||||
@@ -782,19 +795,19 @@ declare module "mongoose" {
|
||||
* if it should be excluded by default. This setting can be overridden at
|
||||
* the query level.
|
||||
*/
|
||||
select?: boolean;
|
||||
select?: boolean | Object;
|
||||
|
||||
/**
|
||||
* Setters allow you to transform the data before it gets to the raw mongodb
|
||||
* document and is set as a value on an actual key.
|
||||
*/
|
||||
set?: (value: T, schematype?: this) => T;
|
||||
set?: (value: T, schematype?: this) => T | Object;
|
||||
|
||||
/** Declares a sparse index. */
|
||||
sparse?: boolean;
|
||||
sparse?: boolean | Object;
|
||||
|
||||
/** Declares a full text index. */
|
||||
text?: boolean;
|
||||
text?: boolean | Object;
|
||||
|
||||
/**
|
||||
* Adds validator(s) for this document path.
|
||||
@@ -803,50 +816,53 @@ declare module "mongoose" {
|
||||
*/
|
||||
validate?: RegExp | [RegExp, string] |
|
||||
SchemaTypeOpts.ValidateFn<T> | [SchemaTypeOpts.ValidateFn<T>, string] |
|
||||
SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.ValidateOpts[];
|
||||
SchemaTypeOpts.ValidateOpts | SchemaTypeOpts.ValidateOpts[] |
|
||||
Object;
|
||||
|
||||
/** Declares an unique index. */
|
||||
unique?: boolean;
|
||||
unique?: boolean | Object;
|
||||
|
||||
|
||||
/* Options for specific schema types (String, Number, Date, etc.) */
|
||||
/** String only - Adds an enum validator */
|
||||
enum?: T[] | SchemaTypeOpts.EnumOpts<T>;
|
||||
enum?: T[] | SchemaTypeOpts.EnumOpts<T> | Object;
|
||||
/** String only - Adds a lowercase setter. */
|
||||
lowercase?: boolean;
|
||||
lowercase?: boolean | Object;
|
||||
/** String only - Sets a regexp validator. */
|
||||
match?: RegExp | [RegExp, string];
|
||||
match?: RegExp | [RegExp, string] | Object;
|
||||
/** String only - Sets a maximum length validator. */
|
||||
maxlength?: number | [number, string];
|
||||
maxlength?: number | [number, string] | Object;
|
||||
/** String only - Sets a minimum length validator. */
|
||||
minlength?: number | [number, string];
|
||||
minlength?: number | [number, string] | Object;
|
||||
/** String only - Adds a trim setter. */
|
||||
trim?: boolean;
|
||||
trim?: boolean | Object;
|
||||
/** String only - Adds an uppercase setter. */
|
||||
uppercase?: boolean;
|
||||
uppercase?: boolean | Object;
|
||||
|
||||
/**
|
||||
* Date, Number only - Sets a minimum number validator.
|
||||
* Sets a minimum date validator.
|
||||
*/
|
||||
min?: number | [number, string] |
|
||||
Date | [Date, string];
|
||||
Date | [Date, string] |
|
||||
Object;
|
||||
|
||||
/**
|
||||
* Date, Number only - Sets a maximum number validator.
|
||||
* Sets a maximum date validator.
|
||||
*/
|
||||
max?: number | [number, string] |
|
||||
Date | [Date, string];
|
||||
Date | [Date, string] |
|
||||
Object;
|
||||
|
||||
/**
|
||||
* Date only - Declares a TTL index (rounded to the nearest second)
|
||||
* for Date types only.
|
||||
*/
|
||||
expires?: number | string;
|
||||
expires?: number | string | Object;
|
||||
|
||||
/** ObjectId only - Adds an auto-generated ObjectId default if turnOn is true. */
|
||||
auto?: boolean;
|
||||
auto?: boolean | Object;
|
||||
|
||||
[other: string]: any;
|
||||
}
|
||||
|
||||
@@ -318,7 +318,14 @@ new mongoose.Schema({
|
||||
hidden: Boolean,
|
||||
meta: {
|
||||
votes: Number,
|
||||
favs: Number
|
||||
favs: Number,
|
||||
text: String
|
||||
},
|
||||
meta2: {
|
||||
text: mongoose.Schema.Types.Number,
|
||||
select: {
|
||||
type: String
|
||||
}
|
||||
}
|
||||
});
|
||||
new mongoose.Schema({ name: { type: String, index: true }});
|
||||
|
||||
Reference in New Issue
Block a user