mongoose 6.4.1 → 6.4.2
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 +3 -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/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/schema/symbols.js +1 -1
- package/lib/schema.js +3 -3
- package/lib/types/DocumentArray/methods/index.js +1 -1
- package/package.json +1 -1
- package/types/collection.d.ts +1 -1
- package/types/document.d.ts +4 -4
- package/types/expressions.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/types/indexes.d.ts +2 -2
- package/types/inferschematype.d.ts +51 -33
- package/types/middlewares.d.ts +1 -1
- package/types/models.d.ts +6 -6
- package/types/mongooseoptions.d.ts +1 -1
- package/types/schemaoptions.d.ts +1 -1
- package/types/utility.d.ts +7 -0
package/.eslintrc.json
CHANGED
package/lib/cast/date.js
CHANGED
package/lib/cast/decimal128.js
CHANGED
package/lib/cast/objectid.js
CHANGED
package/lib/cast.js
CHANGED
|
@@ -9,4 +9,4 @@ exports.Collection = require('./collection');
|
|
|
9
9
|
exports.Decimal128 = require('./decimal128');
|
|
10
10
|
exports.ObjectId = require('./objectid');
|
|
11
11
|
exports.ReadPreference = require('./ReadPreference');
|
|
12
|
-
exports.getConnection = () => require('./connection');
|
|
12
|
+
exports.getConnection = () => require('./connection');
|
package/lib/helpers/each.js
CHANGED
package/lib/helpers/get.js
CHANGED
package/lib/helpers/isObject.js
CHANGED
package/lib/helpers/isPromise.js
CHANGED
package/lib/helpers/once.js
CHANGED
package/lib/helpers/pluralize.js
CHANGED
|
@@ -14,4 +14,4 @@ if (typeof jest !== 'undefined' && process.nextTick.toString().indexOf('nextTick
|
|
|
14
14
|
'with Jest\'s mock timers enabled. Please make sure you read ' +
|
|
15
15
|
'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
|
|
16
16
|
'https://mongoosejs.com/docs/jest.html');
|
|
17
|
-
}
|
|
17
|
+
}
|
|
@@ -9,7 +9,7 @@ function processConnectionOptions(uri, options) {
|
|
|
9
9
|
? opts.readPreference
|
|
10
10
|
: getUriReadPreference(uri);
|
|
11
11
|
|
|
12
|
-
const resolvedOpts = (readPreference && readPreference !== 'primary')
|
|
12
|
+
const resolvedOpts = (readPreference && readPreference !== 'primary' && readPreference !== 'primaryPreferred')
|
|
13
13
|
? resolveOptsConflicts(readPreference, opts)
|
|
14
14
|
: opts;
|
|
15
15
|
|
package/lib/helpers/symbols.js
CHANGED
|
@@ -17,4 +17,4 @@ exports.populateModelSymbol = Symbol('mongoose.PopulateOptions#Model');
|
|
|
17
17
|
exports.schemaTypeSymbol = Symbol('mongoose#schemaType');
|
|
18
18
|
exports.sessionNewDocuments = Symbol('mongoose:ClientSession#newDocuments');
|
|
19
19
|
exports.scopeSymbol = Symbol('mongoose#Document#scope');
|
|
20
|
-
exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
|
|
20
|
+
exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
|
package/lib/helpers/timers.js
CHANGED
|
@@ -13,4 +13,4 @@ module.exports = function isSSLError(topologyDescription) {
|
|
|
13
13
|
const descriptions = Array.from(topologyDescription.servers.values());
|
|
14
14
|
return descriptions.length > 0 &&
|
|
15
15
|
descriptions.every(descr => descr.error && descr.error.message.indexOf(nonSSLMessage) !== -1);
|
|
16
|
-
};
|
|
16
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1223,7 +1223,7 @@ Mongoose.prototype._promiseOrCallback = function(callback, fn, ee) {
|
|
|
1223
1223
|
/**
|
|
1224
1224
|
* Use this function in `pre()` middleware to skip calling the wrapped function.
|
|
1225
1225
|
*
|
|
1226
|
-
* ####Example:
|
|
1226
|
+
* #### Example:
|
|
1227
1227
|
*
|
|
1228
1228
|
* schema.pre('save', function() {
|
|
1229
1229
|
* // Will skip executing `save()`, but will execute post hooks as if
|
|
@@ -1241,7 +1241,7 @@ Mongoose.prototype.skipMiddlewareFunction = Kareem.skipWrappedFunction;
|
|
|
1241
1241
|
/**
|
|
1242
1242
|
* Use this function in `post()` middleware to replace the result
|
|
1243
1243
|
*
|
|
1244
|
-
* ####Example:
|
|
1244
|
+
* #### Example:
|
|
1245
1245
|
*
|
|
1246
1246
|
* schema.post('find', function(res) {
|
|
1247
1247
|
* // Normally you have to modify `res` in place. But with
|
package/lib/schema/symbols.js
CHANGED
package/lib/schema.js
CHANGED
|
@@ -477,7 +477,7 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
477
477
|
* Inherit a Schema by applying a discriminator on an existing Schema.
|
|
478
478
|
*
|
|
479
479
|
*
|
|
480
|
-
* ####Example:
|
|
480
|
+
* #### Example:
|
|
481
481
|
*
|
|
482
482
|
* const options = { discriminatorKey: 'kind' };
|
|
483
483
|
*
|
|
@@ -648,7 +648,7 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
648
648
|
* removeIndex only removes indexes from your schema object. Does **not** affect the indexes
|
|
649
649
|
* in MongoDB.
|
|
650
650
|
*
|
|
651
|
-
* ####Example:
|
|
651
|
+
* #### Example:
|
|
652
652
|
*
|
|
653
653
|
* const ToySchema = new Schema({ name: String, color: String, price: Number });
|
|
654
654
|
*
|
|
@@ -701,7 +701,7 @@ Schema.prototype.removeIndex = function removeIndex(index) {
|
|
|
701
701
|
* clearIndexes only removes indexes from your schema object. Does **not** affect the indexes
|
|
702
702
|
* in MongoDB.
|
|
703
703
|
*
|
|
704
|
-
* ####Example:
|
|
704
|
+
* #### Example:
|
|
705
705
|
*
|
|
706
706
|
* const ToySchema = new Schema({ name: String, color: String, price: Number });
|
|
707
707
|
* ToySchema.index({ name: 1 });
|
package/package.json
CHANGED
package/types/collection.d.ts
CHANGED
package/types/document.d.ts
CHANGED
|
@@ -200,10 +200,10 @@ declare module 'mongoose' {
|
|
|
200
200
|
$parent(): Document | undefined;
|
|
201
201
|
|
|
202
202
|
/** Populates document references. */
|
|
203
|
-
populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<this
|
|
204
|
-
populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this
|
|
205
|
-
populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions): Promise<this
|
|
206
|
-
populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<this
|
|
203
|
+
populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<MergeType<this, Paths>>;
|
|
204
|
+
populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<MergeType<this, Paths>>): void;
|
|
205
|
+
populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions): Promise<MergeType<this, Paths>>;
|
|
206
|
+
populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<MergeType<this, Paths>>): void;
|
|
207
207
|
|
|
208
208
|
/** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */
|
|
209
209
|
populated(path: string): any;
|
package/types/expressions.d.ts
CHANGED
|
@@ -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] | null;
|
|
1037
|
+
$ne: Expression | [Expression, Expression | NullExpression] | null;
|
|
1038
1038
|
}
|
|
1039
1039
|
|
|
1040
1040
|
export interface Cond {
|
|
@@ -2879,4 +2879,4 @@ declare module 'mongoose' {
|
|
|
2879
2879
|
export type DateExpressionOperatorReturningString =
|
|
2880
2880
|
Expression.DateToString;
|
|
2881
2881
|
|
|
2882
|
-
}
|
|
2882
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -166,7 +166,7 @@ declare module 'mongoose' {
|
|
|
166
166
|
/**
|
|
167
167
|
* Create a new schema
|
|
168
168
|
*/
|
|
169
|
-
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>);
|
|
170
170
|
|
|
171
171
|
/** Adds key path / schema type pairs to this schema. */
|
|
172
172
|
add(obj: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>> | Schema, prefix?: string): this;
|
package/types/indexes.d.ts
CHANGED
|
@@ -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
|
@@ -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,
|
|
@@ -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/schemaoptions.d.ts
CHANGED
package/types/utility.d.ts
CHANGED
|
@@ -12,4 +12,11 @@ declare module 'mongoose' {
|
|
|
12
12
|
|
|
13
13
|
type MergeType<A, B> = Omit<A, keyof B> & B;
|
|
14
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] };
|
|
21
|
+
|
|
15
22
|
}
|