mongoose 6.4.0 → 6.4.3
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.
- package/.eslintrc.json +5 -2
- package/dist/browser.umd.js +68579 -2
- package/lib/cast/date.js +1 -1
- package/lib/cast/decimal128.js +1 -1
- package/lib/cast/objectid.js +1 -1
- package/lib/cast.js +1 -1
- package/lib/document.js +8 -2
- package/lib/drivers/node-mongodb-native/index.js +1 -1
- package/lib/error/parallelValidate.js +1 -1
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +1 -1
- package/lib/helpers/aggregate/stringifyFunctionOperators.js +1 -1
- package/lib/helpers/arrayDepth.js +1 -1
- package/lib/helpers/cursor/eachAsync.js +1 -1
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
- package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +1 -1
- package/lib/helpers/discriminator/getConstructor.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/lib/helpers/document/handleSpreadDoc.js +1 -1
- package/lib/helpers/each.js +1 -1
- package/lib/helpers/get.js +1 -1
- package/lib/helpers/getConstructorName.js +1 -1
- package/lib/helpers/getDefaultBulkwriteResult.js +1 -1
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/indexes/isTextIndex.js +1 -1
- package/lib/helpers/isMongooseObject.js +1 -1
- package/lib/helpers/isObject.js +1 -1
- package/lib/helpers/isPromise.js +1 -1
- package/lib/helpers/model/applyHooks.js +1 -1
- package/lib/helpers/model/applyStaticHooks.js +1 -1
- package/lib/helpers/once.js +1 -1
- package/lib/helpers/path/flattenObjectWithDottedPaths.js +1 -1
- package/lib/helpers/path/parentPaths.js +1 -1
- package/lib/helpers/path/setDottedPath.js +1 -1
- package/lib/helpers/pluralize.js +1 -1
- package/lib/helpers/populate/SkipPopulateValue.js +1 -1
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +1 -1
- package/lib/helpers/populate/assignVals.js +1 -1
- package/lib/helpers/populate/createPopulateQueryFilter.js +1 -1
- package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
- package/lib/helpers/populate/leanPopulateMap.js +1 -1
- package/lib/helpers/populate/lookupLocalFields.js +1 -1
- package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
- package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
- package/lib/helpers/populate/validateRef.js +1 -1
- package/lib/helpers/printJestWarning.js +1 -1
- package/lib/helpers/processConnectionOptions.js +1 -1
- package/lib/helpers/projection/applyProjection.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/parseProjection.js +1 -1
- package/lib/helpers/query/applyGlobalOption.js +1 -1
- package/lib/helpers/query/applyQueryMiddleware.js +1 -1
- package/lib/helpers/query/cast$expr.js +1 -1
- package/lib/helpers/query/castFilterPath.js +1 -1
- package/lib/helpers/query/sanitizeFilter.js +1 -1
- package/lib/helpers/query/sanitizeProjection.js +1 -1
- package/lib/helpers/query/trusted.js +1 -1
- package/lib/helpers/query/validOps.js +1 -1
- package/lib/helpers/query/wrapThunk.js +1 -1
- package/lib/helpers/schema/addAutoId.js +1 -1
- package/lib/helpers/schema/applyPlugins.js +1 -1
- package/lib/helpers/schema/cleanPositionalOperators.js +1 -1
- package/lib/helpers/schema/getKeysInSchemaOrder.js +1 -1
- package/lib/helpers/schema/getPath.js +1 -1
- package/lib/helpers/schema/handleIdOption.js +1 -1
- package/lib/helpers/schema/handleTimestampOption.js +1 -1
- package/lib/helpers/specialProperties.js +1 -1
- package/lib/helpers/symbols.js +1 -1
- package/lib/helpers/timers.js +1 -1
- package/lib/helpers/timestamps/setupTimestamps.js +1 -1
- package/lib/helpers/topology/allServersUnknown.js +1 -1
- package/lib/helpers/topology/isAtlas.js +1 -1
- package/lib/helpers/topology/isSSLError.js +1 -1
- package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
- package/lib/helpers/update/castArrayFilters.js +1 -1
- package/lib/helpers/update/moveImmutableProperties.js +1 -1
- package/lib/helpers/update/removeUnusedArrayFilters.js +1 -1
- package/lib/helpers/update/updatedPathsByArrayFilter.js +1 -1
- package/lib/index.js +2 -2
- package/lib/options/PopulateOptions.js +1 -1
- package/lib/options/SchemaArrayOptions.js +1 -1
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDocumentArrayOptions.js +1 -1
- package/lib/options/SchemaMapOptions.js +1 -1
- package/lib/options/SchemaNumberOptions.js +1 -1
- package/lib/options/SchemaObjectIdOptions.js +1 -1
- package/lib/options/SchemaSubdocumentOptions.js +1 -1
- package/lib/options/SchemaTypeOptions.js +1 -1
- package/lib/options/VirtualOptions.js +1 -1
- package/lib/options/propertyOptions.js +1 -1
- package/lib/options/removeOptions.js +1 -1
- package/lib/options/saveOptions.js +1 -1
- package/lib/plugins/trackTransaction.js +1 -1
- package/lib/queryhelpers.js +5 -0
- package/lib/schema/array.js +1 -1
- package/lib/schema/date.js +2 -2
- package/lib/schema/number.js +2 -2
- package/lib/schema/string.js +2 -2
- package/lib/schema/symbols.js +1 -1
- package/lib/schema.js +3 -3
- package/lib/schematype.js +2 -1
- package/lib/types/DocumentArray/methods/index.js +1 -1
- package/lib/types/buffer.js +26 -28
- package/lib/types/decimal128.js +3 -3
- package/lib/types/map.js +70 -0
- package/package.json +11 -11
- package/types/collection.d.ts +1 -1
- package/types/document.d.ts +12 -6
- package/types/expressions.d.ts +30 -9
- package/types/index.d.ts +13 -12
- package/types/{indizes.d.ts → indexes.d.ts} +2 -2
- package/types/inferschematype.d.ts +51 -33
- package/types/middlewares.d.ts +1 -1
- package/types/models.d.ts +14 -14
- package/types/mongooseoptions.d.ts +1 -1
- package/types/pipelinestage.d.ts +2 -2
- package/types/query.d.ts +1 -1
- package/types/schemaoptions.d.ts +1 -1
- package/types/types.d.ts +3 -1
- package/types/utility.d.ts +8 -1
package/types/expressions.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ declare module 'mongoose' {
|
|
|
32
32
|
*
|
|
33
33
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add
|
|
34
34
|
*/
|
|
35
|
-
$add:
|
|
35
|
+
$add: Expression[];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface Ceil {
|
|
@@ -1034,7 +1034,7 @@ declare module 'mongoose' {
|
|
|
1034
1034
|
*
|
|
1035
1035
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/ne/#mongodb-expression-exp.-ne
|
|
1036
1036
|
*/
|
|
1037
|
-
$ne: Expression | [Expression, Expression];
|
|
1037
|
+
$ne: Expression | [Expression, Expression | NullExpression] | null;
|
|
1038
1038
|
}
|
|
1039
1039
|
|
|
1040
1040
|
export interface Cond {
|
|
@@ -1043,7 +1043,7 @@ declare module 'mongoose' {
|
|
|
1043
1043
|
*
|
|
1044
1044
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/cond/#mongodb-expression-exp.-cond
|
|
1045
1045
|
*/
|
|
1046
|
-
$cond: { if:
|
|
1046
|
+
$cond: { if: Expression, then: AnyExpression, else: AnyExpression } | [BooleanExpression, AnyExpression, AnyExpression];
|
|
1047
1047
|
}
|
|
1048
1048
|
|
|
1049
1049
|
export interface IfNull {
|
|
@@ -1957,7 +1957,7 @@ declare module 'mongoose' {
|
|
|
1957
1957
|
* @version 5.0
|
|
1958
1958
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/addToSet/#mongodb-expression-exp.-addToSet
|
|
1959
1959
|
*/
|
|
1960
|
-
$addToSet:
|
|
1960
|
+
$addToSet: Expression | Record<string, Expression>;
|
|
1961
1961
|
}
|
|
1962
1962
|
|
|
1963
1963
|
export interface Avg {
|
|
@@ -1967,7 +1967,7 @@ declare module 'mongoose' {
|
|
|
1967
1967
|
* @version 5.0
|
|
1968
1968
|
* @see https://docs.mongodb.com/manual/reference/operator/aggregation/avg/#mongodb-expression-exp.-avg
|
|
1969
1969
|
*/
|
|
1970
|
-
$avg:
|
|
1970
|
+
$avg: Expression;
|
|
1971
1971
|
}
|
|
1972
1972
|
|
|
1973
1973
|
export interface Count {
|
|
@@ -2316,6 +2316,21 @@ declare module 'mongoose' {
|
|
|
2316
2316
|
$toObjectId: Expression;
|
|
2317
2317
|
}
|
|
2318
2318
|
|
|
2319
|
+
export interface Top {
|
|
2320
|
+
$top: {
|
|
2321
|
+
sortBy: AnyObject,
|
|
2322
|
+
output: Expression
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
export interface TopN {
|
|
2327
|
+
$topN: {
|
|
2328
|
+
n: Expression,
|
|
2329
|
+
sortBy: AnyObject,
|
|
2330
|
+
output: Expression
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2319
2334
|
export interface ToString {
|
|
2320
2335
|
/**
|
|
2321
2336
|
* Converts a value to a string. If the value cannot be converted to a string, $toString errors. If the value is
|
|
@@ -2385,6 +2400,7 @@ declare module 'mongoose' {
|
|
|
2385
2400
|
|
|
2386
2401
|
type Path = string;
|
|
2387
2402
|
|
|
2403
|
+
|
|
2388
2404
|
export type Expression =
|
|
2389
2405
|
Path |
|
|
2390
2406
|
ArithmeticExpressionOperator |
|
|
@@ -2405,7 +2421,10 @@ declare module 'mongoose' {
|
|
|
2405
2421
|
TypeExpressionOperator |
|
|
2406
2422
|
AccumulatorOperator |
|
|
2407
2423
|
VariableExpressionOperator |
|
|
2408
|
-
WindowOperator
|
|
2424
|
+
WindowOperator |
|
|
2425
|
+
Expression.Top |
|
|
2426
|
+
Expression.TopN |
|
|
2427
|
+
any;
|
|
2409
2428
|
|
|
2410
2429
|
export type NullExpression = null;
|
|
2411
2430
|
|
|
@@ -2428,7 +2447,8 @@ declare module 'mongoose' {
|
|
|
2428
2447
|
DateExpression |
|
|
2429
2448
|
BinaryExpression |
|
|
2430
2449
|
FunctionExpression |
|
|
2431
|
-
ObjectIdExpression
|
|
2450
|
+
ObjectIdExpression |
|
|
2451
|
+
ConditionalExpressionOperator;
|
|
2432
2452
|
|
|
2433
2453
|
export type ObjectIdExpression =
|
|
2434
2454
|
TypeExpressionOperatorReturningObjectId;
|
|
@@ -2476,7 +2496,8 @@ declare module 'mongoose' {
|
|
|
2476
2496
|
DataSizeOperatorReturningNumber |
|
|
2477
2497
|
CustomAggregationExpressionOperatorReturningAny |
|
|
2478
2498
|
TypeExpressionOperatorReturningNumber |
|
|
2479
|
-
DateExpression
|
|
2499
|
+
DateExpression |
|
|
2500
|
+
DateExpressionOperatorReturningNumber;
|
|
2480
2501
|
|
|
2481
2502
|
export type ObjectExpression =
|
|
2482
2503
|
Path |
|
|
@@ -2877,4 +2898,4 @@ declare module 'mongoose' {
|
|
|
2877
2898
|
export type DateExpressionOperatorReturningString =
|
|
2878
2899
|
Expression.DateToString;
|
|
2879
2900
|
|
|
2880
|
-
}
|
|
2901
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
/// <reference path="./expressions.d.ts" />
|
|
9
9
|
/// <reference path="./helpers.d.ts" />
|
|
10
10
|
/// <reference path="./middlewares.d.ts" />
|
|
11
|
-
/// <reference path="./
|
|
11
|
+
/// <reference path="./indexes.d.ts" />
|
|
12
12
|
/// <reference path="./models.d.ts" />
|
|
13
13
|
/// <reference path="./mongooseoptions.d.ts" />
|
|
14
14
|
/// <reference path="./pipelinestage.d.ts" />
|
|
@@ -156,6 +156,8 @@ declare module 'mongoose' {
|
|
|
156
156
|
? Schema<Omit<DocType, keyof T1> & T1, DiscriminatorModel<T2, M>, T3 | TInstanceMethods, T4 | TQueryHelpers, T5 | TVirtuals>
|
|
157
157
|
: Schema<DocType, M, TInstanceMethods, TQueryHelpers, TVirtuals>;
|
|
158
158
|
|
|
159
|
+
type QueryResultType<T> = T extends Query<infer ResultType, any> ? ResultType : never;
|
|
160
|
+
|
|
159
161
|
export class Schema<EnforcedDocType = any, M = Model<EnforcedDocType, any, any, any>, TInstanceMethods = {}, TQueryHelpers = {}, TVirtuals = any,
|
|
160
162
|
TStaticMethods = {},
|
|
161
163
|
TPathTypeKey extends TypeKeyBaseType = DefaultTypeKey,
|
|
@@ -164,7 +166,7 @@ declare module 'mongoose' {
|
|
|
164
166
|
/**
|
|
165
167
|
* Create a new schema
|
|
166
168
|
*/
|
|
167
|
-
constructor(definition?: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>> | DocType, options?: SchemaOptions<TPathTypeKey, DocType
|
|
169
|
+
constructor(definition?: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>> | DocType, options?: SchemaOptions<TPathTypeKey, FlatRecord<DocType>, TInstanceMethods, TQueryHelpers, TStaticMethods>);
|
|
168
170
|
|
|
169
171
|
/** Adds key path / schema type pairs to this schema. */
|
|
170
172
|
add(obj: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>> | Schema, prefix?: string): this;
|
|
@@ -225,6 +227,7 @@ declare module 'mongoose' {
|
|
|
225
227
|
obj: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>>;
|
|
226
228
|
|
|
227
229
|
/** Gets/sets schema paths. */
|
|
230
|
+
path<pathGeneric extends keyof EnforcedDocType>(path: pathGeneric): SchemaType<EnforcedDocType[pathGeneric]>;
|
|
228
231
|
path<ResultType extends SchemaType = SchemaType>(path: string): ResultType;
|
|
229
232
|
path(path: string, constructor: any): this;
|
|
230
233
|
|
|
@@ -242,8 +245,8 @@ declare module 'mongoose' {
|
|
|
242
245
|
/** Defines a post hook for the model. */
|
|
243
246
|
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, T>): this;
|
|
244
247
|
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
|
|
245
|
-
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PostMiddlewareFunction<T, T
|
|
246
|
-
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, T
|
|
248
|
+
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
|
|
249
|
+
post<T extends Query<any, any>>(method: MongooseQueryMiddleware | MongooseQueryMiddleware[] | string | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;
|
|
247
250
|
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
|
|
248
251
|
post<T extends Aggregate<any>>(method: 'aggregate' | RegExp, options: SchemaPostOptions, fn: PostMiddlewareFunction<T, Array<AggregateExtract<T>>>): this;
|
|
249
252
|
post<T = M>(method: 'insertMany' | RegExp, fn: PostMiddlewareFunction<T, T>): this;
|
|
@@ -443,22 +446,20 @@ declare module 'mongoose' {
|
|
|
443
446
|
$min?: AnyKeys<TSchema> & AnyObject;
|
|
444
447
|
$max?: AnyKeys<TSchema> & AnyObject;
|
|
445
448
|
$mul?: AnyKeys<TSchema> & AnyObject;
|
|
446
|
-
$rename?:
|
|
449
|
+
$rename?: Record<string, string>;
|
|
447
450
|
$set?: AnyKeys<TSchema> & AnyObject;
|
|
448
451
|
$setOnInsert?: AnyKeys<TSchema> & AnyObject;
|
|
449
452
|
$unset?: AnyKeys<TSchema> & AnyObject;
|
|
450
453
|
|
|
451
454
|
/** @see https://docs.mongodb.com/manual/reference/operator/update-array/ */
|
|
452
|
-
$addToSet?:
|
|
455
|
+
$addToSet?: mongodb.SetFields<TSchema>;
|
|
453
456
|
$pop?: AnyKeys<TSchema> & AnyObject;
|
|
454
|
-
$pull?:
|
|
455
|
-
$push?:
|
|
456
|
-
$pullAll?:
|
|
457
|
+
$pull?: mongodb.PullOperator<TSchema>;
|
|
458
|
+
$push?: mongodb.PushOperator<TSchema>;
|
|
459
|
+
$pullAll?: mongodb.PullAllOperator<TSchema>;
|
|
457
460
|
|
|
458
461
|
/** @see https://docs.mongodb.com/manual/reference/operator/update-bitwise/ */
|
|
459
|
-
$bit?:
|
|
460
|
-
[key: string]: { [key in 'and' | 'or' | 'xor']?: number };
|
|
461
|
-
};
|
|
462
|
+
$bit?: Record<string, mongodb.NumericType>;
|
|
462
463
|
};
|
|
463
464
|
|
|
464
465
|
export type UpdateWithAggregationPipeline = UpdateAggregationStage[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema, InferSchemaType, SchemaType, SchemaTypeOptions, TypeKeyBaseType } from 'mongoose';
|
|
1
|
+
import { Schema, InferSchemaType, SchemaType, SchemaTypeOptions, TypeKeyBaseType, Types, NumberSchemaDefinition, StringSchemaDefinition, BooleanSchemaDefinition, DateSchemaDefinition } from 'mongoose';
|
|
2
2
|
|
|
3
3
|
declare module 'mongoose' {
|
|
4
4
|
/**
|
|
@@ -6,13 +6,13 @@ declare module 'mongoose' {
|
|
|
6
6
|
* @description Obtains document schema type from document Definition OR returns enforced schema type if it's provided.
|
|
7
7
|
* @param {DocDefinition} DocDefinition A generic equals to the type of document definition "provided in as first parameter in Schema constructor".
|
|
8
8
|
* @param {EnforcedDocType} EnforcedDocType A generic type enforced by user "provided before schema constructor".
|
|
9
|
-
* @param {TypeKey} TypeKey A generic of literal string type.
|
|
9
|
+
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
type ObtainDocumentType<DocDefinition, EnforcedDocType = any, TypeKey extends TypeKeyBaseType = DefaultTypeKey> =
|
|
12
|
+
IsItRecordAndNotAny<EnforcedDocType> extends true ? EnforcedDocType : {
|
|
13
|
+
[K in keyof (RequiredPaths<DocDefinition, TypeKey> &
|
|
14
|
+
OptionalPaths<DocDefinition, TypeKey>)]: ObtainDocumentPathType<DocDefinition[K], TypeKey>;
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @summary Obtains document schema type from Schema instance.
|
|
@@ -64,10 +64,22 @@ type IfEquals<T, U, Y = true, N = false> =
|
|
|
64
64
|
(<G>() => G extends U ? 1 : 0) ? Y : N;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* @summary
|
|
68
|
-
* @
|
|
67
|
+
* @summary Checks if a document path is required or optional.
|
|
68
|
+
* @param {P} P Document path.
|
|
69
|
+
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
69
70
|
*/
|
|
70
|
-
type
|
|
71
|
+
type IsPathRequired<P, TypeKey extends TypeKeyBaseType> =
|
|
72
|
+
P extends { required: true | [true, string | undefined] } | ArrayConstructor | any[]
|
|
73
|
+
? true
|
|
74
|
+
: P extends (Record<TypeKey, ArrayConstructor | any[]>)
|
|
75
|
+
? P extends { default: undefined }
|
|
76
|
+
? false
|
|
77
|
+
: true
|
|
78
|
+
: P extends (Record<TypeKey, NumberSchemaDefinition | StringSchemaDefinition | BooleanSchemaDefinition | DateSchemaDefinition>)
|
|
79
|
+
? P extends { default: ResolvePathType<P[TypeKey]> }
|
|
80
|
+
? true
|
|
81
|
+
: false
|
|
82
|
+
: false;
|
|
71
83
|
|
|
72
84
|
/**
|
|
73
85
|
* @summary Path base type defined by using TypeKey
|
|
@@ -79,37 +91,41 @@ type PathWithTypePropertyBaseType<TypeKey extends TypeKeyBaseType> = { [k in Typ
|
|
|
79
91
|
/**
|
|
80
92
|
* @summary A Utility to obtain schema's required path keys.
|
|
81
93
|
* @param {T} T A generic refers to document definition.
|
|
94
|
+
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
82
95
|
* @returns required paths keys of document definition.
|
|
83
96
|
*/
|
|
84
|
-
type RequiredPathKeys<T> = {
|
|
85
|
-
[K in keyof T]: T[K] extends
|
|
97
|
+
type RequiredPathKeys<T, TypeKey extends TypeKeyBaseType> = {
|
|
98
|
+
[K in keyof T]: IsPathRequired<T[K], TypeKey> extends true ? IfEquals<T[K], any, never, K> : never;
|
|
86
99
|
}[keyof T];
|
|
87
100
|
|
|
88
101
|
/**
|
|
89
102
|
* @summary A Utility to obtain schema's required paths.
|
|
90
103
|
* @param {T} T A generic refers to document definition.
|
|
104
|
+
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
91
105
|
* @returns a record contains required paths with the corresponding type.
|
|
92
106
|
*/
|
|
93
|
-
type RequiredPaths<T> = {
|
|
94
|
-
[K in RequiredPathKeys<T>]: T[K];
|
|
107
|
+
type RequiredPaths<T, TypeKey extends TypeKeyBaseType> = {
|
|
108
|
+
[K in RequiredPathKeys<T, TypeKey>]: T[K];
|
|
95
109
|
};
|
|
96
110
|
|
|
97
111
|
/**
|
|
98
112
|
* @summary A Utility to obtain schema's optional path keys.
|
|
99
113
|
* @param {T} T A generic refers to document definition.
|
|
114
|
+
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
100
115
|
* @returns optional paths keys of document definition.
|
|
101
116
|
*/
|
|
102
|
-
type OptionalPathKeys<T> = {
|
|
103
|
-
[K in keyof T]: T[K] extends
|
|
117
|
+
type OptionalPathKeys<T, TypeKey extends TypeKeyBaseType> = {
|
|
118
|
+
[K in keyof T]: IsPathRequired<T[K], TypeKey> extends true ? never : K;
|
|
104
119
|
}[keyof T];
|
|
105
120
|
|
|
106
121
|
/**
|
|
107
122
|
* @summary A Utility to obtain schema's optional paths.
|
|
108
123
|
* @param {T} T A generic refers to document definition.
|
|
124
|
+
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
109
125
|
* @returns a record contains optional paths with the corresponding type.
|
|
110
126
|
*/
|
|
111
|
-
type OptionalPaths<T> = {
|
|
112
|
-
[K in OptionalPathKeys<T>]?: T[K];
|
|
127
|
+
type OptionalPaths<T, TypeKey extends TypeKeyBaseType> = {
|
|
128
|
+
[K in OptionalPathKeys<T, TypeKey>]?: T[K];
|
|
113
129
|
};
|
|
114
130
|
|
|
115
131
|
/**
|
|
@@ -138,18 +154,20 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends (
|
|
|
138
154
|
* @returns Number, "Number" or "number" will be resolved to string type.
|
|
139
155
|
*/
|
|
140
156
|
type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}> =
|
|
141
|
-
PathValueType extends
|
|
142
|
-
PathValueType extends
|
|
143
|
-
PathValueType extends
|
|
144
|
-
PathValueType extends
|
|
145
|
-
PathValueType extends
|
|
146
|
-
PathValueType extends
|
|
147
|
-
PathValueType extends
|
|
148
|
-
PathValueType extends '
|
|
149
|
-
PathValueType extends
|
|
150
|
-
PathValueType extends
|
|
151
|
-
PathValueType extends
|
|
152
|
-
|
|
153
|
-
IfEquals<PathValueType,
|
|
154
|
-
PathValueType extends
|
|
155
|
-
|
|
157
|
+
PathValueType extends Schema ? InferSchemaType<PathValueType> :
|
|
158
|
+
PathValueType extends (infer Item)[] ? IfEquals<Item, never, any, ResolvePathType<Item>>[] :
|
|
159
|
+
PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']> :
|
|
160
|
+
PathValueType extends NumberSchemaDefinition ? number :
|
|
161
|
+
PathValueType extends DateSchemaDefinition ? Date :
|
|
162
|
+
PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer :
|
|
163
|
+
PathValueType extends BooleanSchemaDefinition ? boolean :
|
|
164
|
+
PathValueType extends 'objectId' | 'ObjectId' | typeof Schema.Types.ObjectId ? Types.ObjectId :
|
|
165
|
+
PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
|
|
166
|
+
PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
|
|
167
|
+
PathValueType extends ArrayConstructor ? any[] :
|
|
168
|
+
PathValueType extends typeof Schema.Types.Mixed ? any:
|
|
169
|
+
IfEquals<PathValueType, ObjectConstructor> extends true ? any:
|
|
170
|
+
IfEquals<PathValueType, {}> extends true ? any:
|
|
171
|
+
PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
|
|
172
|
+
PathValueType extends {} ? PathValueType :
|
|
173
|
+
unknown;
|
package/types/middlewares.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ declare module 'mongoose' {
|
|
|
11
11
|
type PreSaveMiddlewareFunction<ThisType = any> = (this: ThisType, next: CallbackWithoutResultAndOptionalError, opts: SaveOptions) => void | Promise<void>;
|
|
12
12
|
type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
|
|
13
13
|
type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void;
|
|
14
|
-
}
|
|
14
|
+
}
|
package/types/models.d.ts
CHANGED
|
@@ -119,7 +119,7 @@ declare module 'mongoose' {
|
|
|
119
119
|
AcceptsDiscriminator,
|
|
120
120
|
IndexManager,
|
|
121
121
|
SessionStarter {
|
|
122
|
-
new <DocType = T>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<
|
|
122
|
+
new <DocType = T>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): HydratedDocument<T, TMethodsAndOverrides, TVirtuals> & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
|
|
123
123
|
|
|
124
124
|
aggregate<R = any>(pipeline?: PipelineStage[], options?: mongodb.AggregateOptions, callback?: Callback<R[]>): Aggregate<Array<R>>;
|
|
125
125
|
aggregate<R = any>(pipeline: PipelineStage[], callback?: Callback<R[]>): Aggregate<Array<R>>;
|
|
@@ -163,11 +163,11 @@ declare module 'mongoose' {
|
|
|
163
163
|
countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
|
|
164
164
|
|
|
165
165
|
/** Creates a new document or documents */
|
|
166
|
-
create<DocContents = T
|
|
167
|
-
create<DocContents = T
|
|
168
|
-
create<DocContents = T
|
|
169
|
-
create<DocContents = T
|
|
170
|
-
create<DocContents = T
|
|
166
|
+
create<DocContents = AnyKeys<T>>(docs: Array<T | DocContents>, options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
167
|
+
create<DocContents = AnyKeys<T>>(docs: Array<T | DocContents>, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
|
|
168
|
+
create<DocContents = AnyKeys<T>>(doc: DocContents | T): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
|
|
169
|
+
create<DocContents = AnyKeys<T>>(...docs: Array<T | DocContents>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
|
|
170
|
+
create<DocContents = AnyKeys<T>>(doc: T | DocContents, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
|
|
171
171
|
|
|
172
172
|
/**
|
|
173
173
|
* Create the collection for this model. By default, if no indexes are specified,
|
|
@@ -315,21 +315,21 @@ declare module 'mongoose' {
|
|
|
315
315
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
316
316
|
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
317
317
|
filter: FilterQuery<T>,
|
|
318
|
-
projection
|
|
319
|
-
options
|
|
320
|
-
callback?: Callback<ResultDoc[]>
|
|
318
|
+
projection?: ProjectionType<T> | null | undefined,
|
|
319
|
+
options?: QueryOptions<T> | null | undefined,
|
|
320
|
+
callback?: Callback<ResultDoc[]> | undefined
|
|
321
321
|
): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
322
322
|
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
323
323
|
filter: FilterQuery<T>,
|
|
324
|
-
projection
|
|
325
|
-
callback?: Callback<ResultDoc[]>
|
|
324
|
+
projection?: ProjectionType<T> | null | undefined,
|
|
325
|
+
callback?: Callback<ResultDoc[]> | undefined
|
|
326
326
|
): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
327
327
|
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
328
328
|
filter: FilterQuery<T>,
|
|
329
|
-
callback?: Callback<ResultDoc[]>
|
|
329
|
+
callback?: Callback<ResultDoc[]> | undefined
|
|
330
330
|
): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
331
331
|
find<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(
|
|
332
|
-
callback?: Callback<ResultDoc[]>
|
|
332
|
+
callback?: Callback<ResultDoc[]> | undefined
|
|
333
333
|
): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
334
334
|
|
|
335
335
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
@@ -431,4 +431,4 @@ declare module 'mongoose' {
|
|
|
431
431
|
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(obj: object): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
432
432
|
where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
|
|
433
433
|
}
|
|
434
|
-
}
|
|
434
|
+
}
|
package/types/pipelinestage.d.ts
CHANGED
|
@@ -147,7 +147,7 @@ declare module 'mongoose' {
|
|
|
147
147
|
|
|
148
148
|
export interface Match {
|
|
149
149
|
/** [`$match` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/match/) */
|
|
150
|
-
$match:
|
|
150
|
+
$match: FilterQuery<any>;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
export interface Merge {
|
|
@@ -212,7 +212,7 @@ declare module 'mongoose' {
|
|
|
212
212
|
|
|
213
213
|
export interface Set {
|
|
214
214
|
/** [`$set` reference](https://docs.mongodb.com/manual/reference/operator/aggregation/set/) */
|
|
215
|
-
$set: Record<string, AnyExpression>
|
|
215
|
+
$set: Record<string, AnyExpression | any>
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
export interface SetWindowFields {
|
package/types/query.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare module 'mongoose' {
|
|
2
2
|
import mongodb = require('mongodb');
|
|
3
3
|
|
|
4
|
-
export type ApplyBasicQueryCasting<T
|
|
4
|
+
export type ApplyBasicQueryCasting<T> = T | T[] | (T extends (infer U)[] ? U : any) | any;
|
|
5
5
|
type Condition<T> = ApplyBasicQueryCasting<T> | QuerySelector<ApplyBasicQueryCasting<T>>;
|
|
6
6
|
|
|
7
7
|
type _FilterQuery<T> = {
|
package/types/schemaoptions.d.ts
CHANGED
package/types/types.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
declare module 'mongoose' {
|
|
3
3
|
import mongodb = require('mongodb');
|
|
4
4
|
|
|
5
|
+
class NativeBuffer extends Buffer {}
|
|
6
|
+
|
|
5
7
|
namespace Types {
|
|
6
8
|
class Array<T> extends global.Array<T> {
|
|
7
9
|
/** Pops the array atomically at most one time per document `save()`. */
|
|
@@ -47,7 +49,7 @@ declare module 'mongoose' {
|
|
|
47
49
|
unshift(...args: any[]): number;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
class Buffer extends
|
|
52
|
+
class Buffer extends NativeBuffer {
|
|
51
53
|
/** Sets the subtype option and marks the buffer modified. */
|
|
52
54
|
subtype(subtype: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128 | ToObjectOptions): void;
|
|
53
55
|
|
package/types/utility.d.ts
CHANGED
|
@@ -10,6 +10,13 @@ declare module 'mongoose' {
|
|
|
10
10
|
? T
|
|
11
11
|
: Omit<T, keyof U> & U;
|
|
12
12
|
|
|
13
|
-
type MergeType<A
|
|
13
|
+
type MergeType<A, B> = Omit<A, keyof B> & B;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @summary Converts Unions to one record "object".
|
|
17
|
+
* @description It makes intellisense dialog box easier to read as a single object instead of showing that in multiple object unions.
|
|
18
|
+
* @param {T} T The type to be converted.
|
|
19
|
+
*/
|
|
20
|
+
type FlatRecord<T> = { [K in keyof T]: T[K] };
|
|
14
21
|
|
|
15
22
|
}
|