@datanimbus/mongoose 6.13.13 → 9.13.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/README.md +80 -70
- package/eslint.config.mjs +202 -0
- package/index.js +2 -1
- package/lib/aggregate.js +276 -174
- package/lib/cast/bigint.js +46 -0
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/decimal128.js +4 -1
- package/lib/cast/double.js +56 -0
- package/lib/cast/int32.js +42 -0
- package/lib/cast/number.js +6 -6
- package/lib/cast/objectid.js +3 -3
- package/lib/cast/string.js +3 -3
- package/lib/cast/uuid.js +35 -0
- package/lib/cast.js +100 -92
- package/lib/collection.js +31 -22
- package/lib/connection.js +792 -507
- package/lib/constants.js +73 -0
- package/lib/cursor/{AggregationCursor.js → aggregationCursor.js} +205 -52
- package/lib/cursor/changeStream.js +218 -0
- package/lib/cursor/queryCursor.js +676 -0
- package/lib/defaults/schemaDefaultsCache.js +62 -0
- package/lib/document.js +2419 -1306
- package/lib/drivers/node-mongodb-native/bulkWriteResult.js +5 -0
- package/lib/drivers/node-mongodb-native/collection.js +101 -135
- package/lib/drivers/node-mongodb-native/connection.js +386 -28
- package/lib/drivers/node-mongodb-native/index.js +3 -5
- package/lib/error/browserMissingSchema.js +5 -4
- package/lib/error/bulkSaveIncompleteError.js +44 -0
- package/lib/error/cast.js +30 -21
- package/lib/error/createCollectionsError.js +26 -0
- package/lib/error/divergentArray.js +11 -9
- package/lib/error/eachAsyncMultiError.js +2 -2
- package/lib/error/index.js +38 -29
- package/lib/error/invalidSchemaOption.js +32 -0
- package/lib/error/messages.js +4 -3
- package/lib/error/missingSchema.js +8 -6
- package/lib/error/notFound.js +7 -5
- package/lib/error/objectExpected.js +9 -8
- package/lib/error/objectParameter.js +12 -11
- package/lib/error/overwriteModel.js +7 -6
- package/lib/error/parallelSave.js +11 -8
- package/lib/error/parallelValidate.js +9 -7
- package/lib/error/serverSelection.js +1 -0
- package/lib/error/setOptionError.js +11 -9
- package/lib/error/strict.js +12 -10
- package/lib/error/strictPopulate.js +11 -9
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +11 -17
- package/lib/error/validator.js +9 -8
- package/lib/error/version.js +12 -10
- package/lib/filters/operators.js +8 -0
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
- package/lib/helpers/buildMiddlewareFilter.js +42 -0
- package/lib/helpers/clone.js +121 -35
- package/lib/helpers/common.js +7 -7
- package/lib/helpers/cursor/eachAsync.js +14 -11
- package/lib/helpers/cursor/waitForInitialization.js +17 -0
- package/lib/helpers/discriminator/applyEmbeddedDiscriminators.js +36 -0
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
- package/lib/helpers/discriminator/getConstructor.js +9 -6
- package/lib/helpers/discriminator/getDiscriminatorByKey.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorValueFromFilter.js +30 -0
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +41 -9
- package/lib/helpers/document/applyDefaults.js +82 -14
- package/lib/helpers/document/applyTimestamps.js +106 -0
- package/lib/helpers/document/applyVirtuals.js +147 -0
- package/lib/helpers/document/cleanModifiedSubpaths.js +14 -4
- package/lib/helpers/document/compile.js +20 -15
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +38 -0
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +6 -3
- package/lib/helpers/document/handleSpreadDoc.js +2 -1
- package/lib/helpers/document/isInPathsToSave.js +24 -0
- package/lib/helpers/document/toObjectRecursive.js +49 -0
- package/lib/helpers/get.js +1 -1
- package/lib/helpers/getDefaultBulkwriteResult.js +11 -20
- package/lib/helpers/getInheritedProperty.js +28 -0
- package/lib/helpers/getOwnProperty.js +19 -0
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/lib/helpers/indexes/getRelatedIndexes.js +8 -4
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/indexes/isIndexEqual.js +13 -12
- package/lib/helpers/indexes/isIndexSpecEqual.js +32 -0
- package/lib/helpers/indexes/isTimeseriesIndex.js +16 -0
- package/lib/helpers/isBsonType.js +3 -6
- package/lib/helpers/isMongooseDocument.js +24 -0
- package/lib/helpers/isMongooseObject.js +6 -4
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isPOJO.js +12 -0
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +41 -0
- package/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
- package/lib/helpers/model/applyHooks.js +72 -54
- package/lib/helpers/model/applyMethods.js +3 -3
- package/lib/helpers/model/applyStaticHooks.js +20 -50
- package/lib/helpers/model/castBulkWrite.js +278 -172
- package/lib/helpers/model/decorateBulkWriteResult.js +8 -0
- package/lib/helpers/model/discriminator.js +77 -21
- package/lib/helpers/omitUndefined.js +20 -0
- package/lib/helpers/parallelLimit.js +61 -34
- package/lib/helpers/path/setDottedPath.js +1 -1
- package/lib/helpers/pathTrie.js +167 -0
- package/lib/helpers/pluralize.js +5 -4
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +12 -7
- package/lib/helpers/populate/assignVals.js +46 -21
- package/lib/helpers/populate/createPopulateQueryFilter.js +13 -5
- package/lib/helpers/populate/getModelsMapForPopulate.js +250 -108
- package/lib/helpers/populate/getSchemaTypes.js +27 -30
- package/lib/helpers/populate/getVirtual.js +31 -0
- package/lib/helpers/populate/markArraySubdocsPopulated.js +6 -4
- package/lib/helpers/populate/modelNamesFromRefPath.js +11 -5
- package/lib/helpers/populate/removeDeselectedForeignField.js +3 -2
- package/lib/helpers/populate/setInheritedReadOptions.js +21 -0
- package/lib/helpers/populate/setPopulatedVirtualValue.js +33 -0
- package/lib/helpers/populate/splitPopulateQuery.js +81 -0
- package/lib/helpers/printJestWarning.js +1 -1
- package/lib/helpers/processConnectionOptions.js +7 -2
- package/lib/helpers/projection/applyProjection.js +8 -2
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isExclusive.js +8 -6
- package/lib/helpers/projection/isInclusive.js +2 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isPathSelectedInclusive.js +1 -11
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/projection/parseProjection.js +9 -4
- package/lib/helpers/query/applyGlobalOption.js +9 -9
- package/lib/helpers/query/cast$expr.js +52 -23
- package/lib/helpers/query/castFilterPath.js +22 -22
- package/lib/helpers/query/castUpdate.js +207 -79
- package/lib/helpers/query/cloneMongooseOptions.js +44 -0
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +27 -13
- package/lib/helpers/query/handleImmutable.js +18 -2
- package/lib/helpers/query/handleReadPreferenceAliases.js +23 -0
- package/lib/helpers/query/sanitizeFilter.js +3 -2
- package/lib/helpers/query/selectPopulatedFields.js +13 -0
- package/lib/helpers/query/validOps.js +1 -22
- package/lib/helpers/schema/applyPlugins.js +2 -2
- package/lib/helpers/schema/applyReadConcern.js +20 -0
- package/lib/helpers/schema/applyWriteConcern.js +12 -3
- package/lib/helpers/schema/cleanPositionalOperators.js +5 -3
- package/lib/helpers/schema/getIndexes.js +20 -13
- package/lib/helpers/schema/getKeysInSchemaOrder.js +13 -16
- package/lib/helpers/schema/getPath.js +11 -3
- package/lib/helpers/schema/getSubdocumentStrictValue.js +32 -0
- package/lib/helpers/schema/handleIdOption.js +1 -1
- package/lib/helpers/schema/idGetter.js +7 -2
- package/lib/helpers/schema/merge.js +9 -1
- package/lib/helpers/schematype/getConditionalHandler.js +23 -0
- package/lib/helpers/schematype/handleImmutable.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +85 -43
- package/lib/helpers/symbols.js +4 -4
- package/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
- package/lib/helpers/timestamps/setupTimestamps.js +69 -37
- package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
- package/lib/helpers/update/applyTimestampsToUpdate.js +53 -37
- package/lib/helpers/update/castArrayFilters.js +68 -29
- package/lib/helpers/update/decorateUpdateWithVersionKey.js +35 -0
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/update/removeUnusedArrayFilters.js +11 -2
- package/lib/helpers/updateValidators.js +87 -128
- package/lib/index.js +6 -1320
- package/lib/internal.js +7 -1
- package/lib/model.js +2587 -2618
- package/lib/modifiedPathsSnapshot.js +9 -0
- package/lib/mongoose.js +1456 -0
- package/lib/options/saveOptions.js +2 -0
- package/lib/options/{SchemaArrayOptions.js → schemaArrayOptions.js} +16 -5
- package/lib/options/{SchemaBufferOptions.js → schemaBufferOptions.js} +2 -2
- package/lib/options/{SchemaDateOptions.js → schemaDateOptions.js} +1 -1
- package/lib/options/{SchemaDocumentArrayOptions.js → schemaDocumentArrayOptions.js} +24 -1
- package/lib/options/{SchemaMapOptions.js → schemaMapOptions.js} +1 -1
- package/lib/options/{SchemaNumberOptions.js → schemaNumberOptions.js} +5 -5
- package/lib/options/{SchemaObjectIdOptions.js → schemaObjectIdOptions.js} +4 -4
- package/lib/options/{SchemaStringOptions.js → schemaStringOptions.js} +10 -10
- package/lib/options/schemaSubdocumentOptions.js +89 -0
- package/lib/options/{SchemaTypeOptions.js → schemaTypeOptions.js} +28 -14
- package/lib/options/schemaUnionOptions.js +32 -0
- package/lib/options/{VirtualOptions.js → virtualOptions.js} +13 -13
- package/lib/options.js +4 -1
- package/lib/plugins/index.js +0 -2
- package/lib/plugins/saveSubdocs.js +85 -50
- package/lib/plugins/sharding.js +43 -15
- package/lib/plugins/trackTransaction.js +46 -34
- package/lib/query.js +1844 -1909
- package/lib/{queryhelpers.js → queryHelpers.js} +184 -81
- package/lib/schema/array.js +229 -169
- package/lib/schema/bigint.js +281 -0
- package/lib/schema/boolean.js +90 -26
- package/lib/schema/buffer.js +119 -50
- package/lib/schema/date.js +102 -38
- package/lib/schema/decimal128.js +88 -37
- package/lib/schema/{documentarray.js → documentArray.js} +259 -151
- package/lib/schema/documentArrayElement.js +180 -0
- package/lib/schema/double.js +244 -0
- package/lib/schema/index.js +12 -19
- package/lib/schema/int32.js +288 -0
- package/lib/schema/map.js +129 -20
- package/lib/schema/mixed.js +40 -26
- package/lib/schema/number.js +128 -51
- package/lib/schema/{objectid.js → objectId.js} +89 -47
- package/lib/schema/operators/exists.js +1 -1
- package/lib/schema/operators/geospatial.js +2 -2
- package/lib/schema/operators/text.js +4 -4
- package/lib/schema/string.js +125 -66
- package/lib/schema/subdocument.js +443 -0
- package/lib/schema/symbols.js +2 -0
- package/lib/schema/union.js +167 -0
- package/lib/schema/uuid.js +90 -120
- package/lib/schema.js +1267 -388
- package/lib/{schematype.js → schemaType.js} +481 -246
- package/lib/standardSchema/convertErrorToIssues.js +20 -0
- package/lib/{statemachine.js → stateMachine.js} +66 -17
- package/lib/tracing.js +38 -0
- package/lib/types/array/index.js +13 -10
- package/lib/types/array/methods/index.js +243 -63
- package/lib/types/{ArraySubdocument.js → arraySubdocument.js} +35 -14
- package/lib/types/buffer.js +31 -14
- package/lib/types/decimal128.js +1 -1
- package/lib/types/{DocumentArray → documentArray}/index.js +13 -13
- package/lib/types/{DocumentArray → documentArray}/methods/index.js +197 -31
- package/lib/types/double.js +13 -0
- package/lib/types/index.js +5 -2
- package/lib/types/map.js +62 -25
- package/lib/types/objectid.js +2 -2
- package/lib/types/subdocument.js +79 -58
- package/lib/types/uuid.js +13 -0
- package/lib/utils.js +201 -155
- package/lib/{validoptions.js → validOptions.js} +10 -2
- package/lib/{virtualtype.js → virtualType.js} +47 -18
- package/package.json +75 -92
- package/types/aggregate.d.ts +31 -7
- package/types/augmentations.d.ts +2 -2
- package/types/collection.d.ts +21 -16
- package/types/connection.d.ts +82 -27
- package/types/cursor.d.ts +15 -10
- package/types/document.d.ts +137 -56
- package/types/error.d.ts +11 -6
- package/types/expressions.d.ts +33 -2
- package/types/index.d.ts +805 -190
- package/types/indexes.d.ts +85 -13
- package/types/inferhydrateddoctype.d.ts +151 -0
- package/types/inferrawdoctype.d.ts +201 -0
- package/types/inferschematype.d.ts +287 -128
- package/types/middlewares.d.ts +50 -7
- package/types/models.d.ts +1555 -268
- package/types/mongooseoptions.d.ts +56 -7
- package/types/pipelinestage.d.ts +42 -3
- package/types/populate.d.ts +63 -1
- package/types/query.d.ts +592 -255
- package/types/schemaoptions.d.ts +78 -12
- package/types/schematypes.d.ts +254 -65
- package/types/session.d.ts +0 -4
- package/types/tracing.d.ts +10 -0
- package/types/types.d.ts +25 -8
- package/types/utility.d.ts +329 -30
- package/types/validation.d.ts +19 -14
- package/types/virtuals.d.ts +10 -10
- package/.eslintrc.js +0 -232
- package/.mocharc.yml +0 -4
- package/browser.js +0 -8
- package/lgtm.yml +0 -12
- package/lib/browser.js +0 -158
- package/lib/browserDocument.js +0 -101
- package/lib/cursor/ChangeStream.js +0 -154
- package/lib/cursor/QueryCursor.js +0 -545
- package/lib/document_provider.js +0 -30
- package/lib/drivers/browser/ReadPreference.js +0 -7
- package/lib/drivers/browser/binary.js +0 -14
- package/lib/drivers/browser/decimal128.js +0 -7
- package/lib/drivers/browser/index.js +0 -16
- package/lib/drivers/browser/objectid.js +0 -29
- package/lib/drivers/node-mongodb-native/ReadPreference.js +0 -47
- package/lib/drivers/node-mongodb-native/binary.js +0 -10
- package/lib/drivers/node-mongodb-native/decimal128.js +0 -7
- package/lib/drivers/node-mongodb-native/objectid.js +0 -16
- package/lib/error/disconnected.js +0 -33
- package/lib/helpers/printStrictQueryWarning.js +0 -11
- package/lib/helpers/promiseOrCallback.js +0 -55
- package/lib/helpers/query/applyQueryMiddleware.js +0 -79
- package/lib/helpers/query/completeMany.js +0 -52
- package/lib/helpers/query/wrapThunk.js +0 -36
- package/lib/options/SchemaSubdocumentOptions.js +0 -42
- package/lib/options/removeOptions.js +0 -14
- package/lib/plugins/removeSubdocs.js +0 -31
- package/lib/plugins/validateBeforeSave.js +0 -45
- package/lib/promise_provider.js +0 -49
- package/lib/schema/DocumentArrayElement.js +0 -100
- package/lib/schema/SubdocumentPath.js +0 -369
- package/scripts/build-browser.js +0 -18
- package/scripts/create-tarball.js +0 -7
- package/scripts/generateSearch.js +0 -154
- package/scripts/tsc-diagnostics-check.js +0 -15
- package/tools/auth.js +0 -31
- package/tools/repl.js +0 -35
- package/tools/sharded.js +0 -46
- package/tsconfig.json +0 -9
- /package/lib/{connectionstate.js → connectionState.js} +0 -0
- /package/lib/helpers/populate/{SkipPopulateValue.js → skipPopulateValue.js} +0 -0
- /package/lib/options/{PopulateOptions.js → populateOptions.js} +0 -0
- /package/lib/types/{DocumentArray → documentArray}/isMongooseDocumentArray.js +0 -0
package/types/indexes.d.ts
CHANGED
|
@@ -8,15 +8,15 @@ declare module 'mongoose' {
|
|
|
8
8
|
* are in your schema but not in MongoDB.
|
|
9
9
|
*/
|
|
10
10
|
function syncIndexes(options?: SyncIndexesOptions): Promise<ConnectionSyncIndexesResult>;
|
|
11
|
-
function syncIndexes(options: SyncIndexesOptions | null, callback: Callback<ConnectionSyncIndexesResult>): void;
|
|
12
11
|
|
|
13
12
|
interface IndexManager {
|
|
13
|
+
/* Deletes all indexes that aren't defined in this model's schema. Used by `syncIndexes()`. Returns list of dropped index names. */
|
|
14
|
+
cleanIndexes(options?: { toDrop?: string[], hideIndexes?: boolean }): Promise<string[]>;
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
|
-
* Similar to `ensureIndexes()`, except for it uses the [`createIndex`](https://mongodb.github.io/node-mongodb-native/
|
|
17
|
+
* Similar to `ensureIndexes()`, except for it uses the [`createIndex`](https://mongodb.github.io/node-mongodb-native/7.0/classes/Collection.html#createIndex)
|
|
16
18
|
* function.
|
|
17
19
|
*/
|
|
18
|
-
createIndexes(options: mongodb.CreateIndexesOptions, callback: CallbackWithoutResult): void;
|
|
19
|
-
createIndexes(callback: CallbackWithoutResult): void;
|
|
20
20
|
createIndexes(options?: mongodb.CreateIndexesOptions): Promise<void>;
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -24,16 +24,12 @@ declare module 'mongoose' {
|
|
|
24
24
|
* the result of this function would be the result of
|
|
25
25
|
* Model.syncIndexes().
|
|
26
26
|
*/
|
|
27
|
-
diffIndexes(options: Record<string, unknown> | null, callback: Callback<IndexesDiff>): void
|
|
28
|
-
diffIndexes(callback: Callback<IndexesDiff>): void
|
|
29
27
|
diffIndexes(options?: Record<string, unknown>): Promise<IndexesDiff>
|
|
30
28
|
|
|
31
29
|
/**
|
|
32
30
|
* Sends `createIndex` commands to mongo for each index declared in the schema.
|
|
33
31
|
* The `createIndex` commands are sent in series.
|
|
34
32
|
*/
|
|
35
|
-
ensureIndexes(options: mongodb.CreateIndexesOptions, callback: CallbackWithoutResult): void;
|
|
36
|
-
ensureIndexes(callback: CallbackWithoutResult): void;
|
|
37
33
|
ensureIndexes(options?: mongodb.CreateIndexesOptions): Promise<void>;
|
|
38
34
|
|
|
39
35
|
/**
|
|
@@ -42,7 +38,6 @@ declare module 'mongoose' {
|
|
|
42
38
|
* use the [`autoIndex` option](/docs/guide.html#autoIndex) and if you
|
|
43
39
|
* build indexes manually.
|
|
44
40
|
*/
|
|
45
|
-
listIndexes(callback: Callback<Array<any>>): void;
|
|
46
41
|
listIndexes(): Promise<Array<any>>;
|
|
47
42
|
|
|
48
43
|
/**
|
|
@@ -51,7 +46,6 @@ declare module 'mongoose' {
|
|
|
51
46
|
* the model's schema except the `_id` index, and build any indexes that
|
|
52
47
|
* are in your schema but not in MongoDB.
|
|
53
48
|
*/
|
|
54
|
-
syncIndexes(options: SyncIndexesOptions | null, callback: Callback<Array<string>>): void;
|
|
55
49
|
syncIndexes(options?: SyncIndexesOptions): Promise<Array<string>>;
|
|
56
50
|
}
|
|
57
51
|
|
|
@@ -66,14 +60,15 @@ declare module 'mongoose' {
|
|
|
66
60
|
type IndexDefinition = Record<string, IndexDirection>;
|
|
67
61
|
|
|
68
62
|
interface SyncIndexesOptions extends mongodb.CreateIndexesOptions {
|
|
69
|
-
continueOnError?: boolean
|
|
63
|
+
continueOnError?: boolean;
|
|
64
|
+
hideIndexes?: boolean;
|
|
70
65
|
}
|
|
71
66
|
type ConnectionSyncIndexesResult = Record<string, OneCollectionSyncIndexesResult>;
|
|
72
67
|
type OneCollectionSyncIndexesResult = Array<string> & mongodb.MongoServerError;
|
|
73
68
|
|
|
74
|
-
|
|
69
|
+
type IndexOptions = Omit<mongodb.CreateIndexesOptions, 'expires' | 'weights' | 'unique'> & {
|
|
75
70
|
/**
|
|
76
|
-
* `expires` utilizes the `ms` module from [
|
|
71
|
+
* `expires` utilizes the `ms` module from [vercel](https://github.com/vercel/ms) allowing us to use a friendlier syntax:
|
|
77
72
|
*
|
|
78
73
|
* @example
|
|
79
74
|
* ```js
|
|
@@ -94,5 +89,82 @@ declare module 'mongoose' {
|
|
|
94
89
|
*/
|
|
95
90
|
expires?: number | string;
|
|
96
91
|
weights?: Record<string, number>;
|
|
92
|
+
|
|
93
|
+
unique?: boolean | [true, string]
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
type SearchIndexDescription = mongodb.SearchIndexDescription;
|
|
97
|
+
|
|
98
|
+
type SearchIndexStatus = 'BUILDING' | 'DELETING' | 'DOES_NOT_EXIST' | 'FAILED' | 'PENDING' | 'READY' | 'STALE';
|
|
99
|
+
|
|
100
|
+
type SearchIndexSynonymMappingStatus = 'BUILDING' | 'FAILED' | 'READY';
|
|
101
|
+
|
|
102
|
+
/** The status of one synonym mapping on one search node. */
|
|
103
|
+
interface SearchIndexSynonymMappingDetail {
|
|
104
|
+
/** The build state of the synonym mapping. */
|
|
105
|
+
status: SearchIndexSynonymMappingStatus;
|
|
106
|
+
/** Whether the synonym mapping can serve queries. */
|
|
107
|
+
queryable: boolean;
|
|
108
|
+
/** The error that made the synonym mapping fail, only returned when its status is `FAILED`. */
|
|
109
|
+
message?: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The status of one index generation, active or staged, on one search node. */
|
|
113
|
+
interface SearchIndexGenerationDetail {
|
|
114
|
+
/** The build state of this index generation. */
|
|
115
|
+
status: SearchIndexStatus;
|
|
116
|
+
/** Whether this index generation is ready to serve queries. */
|
|
117
|
+
queryable: boolean;
|
|
118
|
+
/** When the definition this generation builds with was created, and its version number. */
|
|
119
|
+
definitionVersion: { version: number, createdAt: NativeDate };
|
|
120
|
+
/** The definition this generation builds with. */
|
|
121
|
+
definition: AnyObject;
|
|
122
|
+
/** The status of this generation's synonym mappings, only returned when the index defines any. */
|
|
123
|
+
synonymMappingStatus?: SearchIndexSynonymMappingStatus;
|
|
124
|
+
/** The status of each of this generation's synonym mappings, keyed by mapping name. */
|
|
125
|
+
synonymMappingStatusDetail?: Array<Record<string, SearchIndexSynonymMappingDetail>>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The status of the index on one search node (`mongot`). */
|
|
129
|
+
interface SearchIndexStatusDetail {
|
|
130
|
+
/** The hostname of the search node, in the form `<replSetName>.<server.name>.<server.id>`. */
|
|
131
|
+
hostname: string;
|
|
132
|
+
/** The build state of the index on this search node. */
|
|
133
|
+
status: SearchIndexStatus;
|
|
134
|
+
/** Whether the index is ready to serve queries on this search node. */
|
|
135
|
+
queryable: boolean;
|
|
136
|
+
/** The active index on this search node. */
|
|
137
|
+
mainIndex: SearchIndexGenerationDetail;
|
|
138
|
+
/** The index being built in the background, only returned while an existing index is being updated. */
|
|
139
|
+
stagedIndex?: SearchIndexGenerationDetail;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* A single entry of the [`$listSearchIndexes`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/)
|
|
144
|
+
* output, as returned by `Model.listSearchIndexes()`.
|
|
145
|
+
*/
|
|
146
|
+
interface SearchIndexInfo {
|
|
147
|
+
/** The index's unique identifier, a hex string rather than an ObjectId. */
|
|
148
|
+
id: string;
|
|
149
|
+
/** The name of the index. */
|
|
150
|
+
name: string;
|
|
151
|
+
/** The type of the index. Only returned for Atlas deployments. */
|
|
152
|
+
type?: 'search' | 'vectorSearch';
|
|
153
|
+
/** The build state of the index. */
|
|
154
|
+
status: SearchIndexStatus;
|
|
155
|
+
/** Whether the index is ready to serve queries. */
|
|
156
|
+
queryable: boolean;
|
|
157
|
+
/** The version number of the most recent definition. */
|
|
158
|
+
latestVersion?: number;
|
|
159
|
+
/** When the most recent definition was created, and its version number. */
|
|
160
|
+
latestDefinitionVersion?: { version: number, createdAt: NativeDate };
|
|
161
|
+
/** The most recent definition of the index. */
|
|
162
|
+
latestDefinition: AnyObject;
|
|
163
|
+
/** The status of the index on each individual search node. */
|
|
164
|
+
statusDetail?: SearchIndexStatusDetail[];
|
|
165
|
+
/** The status of the index's synonym mappings, only returned when the index defines any. */
|
|
166
|
+
synonymMappingStatus?: SearchIndexSynonymMappingStatus;
|
|
167
|
+
/** The status of each synonym mapping on each search node, keyed by mapping name. */
|
|
168
|
+
synonymMappingStatusDetail?: Array<Record<string, SearchIndexSynonymMappingDetail>>;
|
|
97
169
|
}
|
|
98
170
|
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IsPathRequired,
|
|
3
|
+
IsSchemaTypeFromBuiltinClass,
|
|
4
|
+
RequiredPaths,
|
|
5
|
+
OptionalPaths,
|
|
6
|
+
PathEnumOrString
|
|
7
|
+
} from './inferschematype';
|
|
8
|
+
import { UUID } from 'mongodb';
|
|
9
|
+
|
|
10
|
+
declare module 'mongoose' {
|
|
11
|
+
export type InferHydratedDocTypeFromSchema<TSchema extends Schema<any>> = ObtainSchemaGeneric<TSchema, 'THydratedDocumentType'>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Given a schema definition, returns the hydrated document type from the schema definition.
|
|
15
|
+
*/
|
|
16
|
+
export type InferHydratedDocType<
|
|
17
|
+
DocDefinition,
|
|
18
|
+
TSchemaOptions extends Record<any, any> = DefaultSchemaOptions
|
|
19
|
+
> = Require_id<ApplySchemaOptions<{
|
|
20
|
+
[
|
|
21
|
+
K in keyof (RequiredPaths<DocDefinition, TSchemaOptions['typeKey']> &
|
|
22
|
+
OptionalPaths<DocDefinition, TSchemaOptions['typeKey']>)
|
|
23
|
+
]: IsPathRequired<DocDefinition[K], TSchemaOptions['typeKey']> extends true
|
|
24
|
+
? ObtainHydratedDocumentPathType<DocDefinition[K], TSchemaOptions['typeKey']>
|
|
25
|
+
: ObtainHydratedDocumentPathType<DocDefinition[K], TSchemaOptions['typeKey']> | null;
|
|
26
|
+
}, TSchemaOptions>>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @summary Obtains schema Path type.
|
|
30
|
+
* @description Obtains Path type by separating path type from other options and calling {@link ResolveHydratedPathType}
|
|
31
|
+
* @param {PathValueType} PathValueType Document definition path type.
|
|
32
|
+
* @param {TypeKey} TypeKey A generic refers to document definition.
|
|
33
|
+
*/
|
|
34
|
+
type ObtainHydratedDocumentPathType<
|
|
35
|
+
PathValueType,
|
|
36
|
+
TypeKey extends string = DefaultTypeKey
|
|
37
|
+
> = ResolveHydratedPathType<
|
|
38
|
+
TypeKey extends keyof PathValueType
|
|
39
|
+
? TypeKey extends keyof PathValueType[TypeKey]
|
|
40
|
+
? PathValueType
|
|
41
|
+
: PathValueType[TypeKey]
|
|
42
|
+
: PathValueType,
|
|
43
|
+
TypeKey extends keyof PathValueType
|
|
44
|
+
? TypeKey extends keyof PathValueType[TypeKey]
|
|
45
|
+
? {}
|
|
46
|
+
: Omit<PathValueType, TypeKey>
|
|
47
|
+
: {},
|
|
48
|
+
TypeKey,
|
|
49
|
+
HydratedDocTypeHint<PathValueType>,
|
|
50
|
+
HydratedDiscriminatorEnumType<PathValueType>
|
|
51
|
+
>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @summary Allows users to optionally choose their own type for a schema field for stronger typing.
|
|
55
|
+
*/
|
|
56
|
+
type HydratedDocTypeHint<T> = T extends { __hydratedDocTypeHint: infer U } ? U
|
|
57
|
+
: never;
|
|
58
|
+
|
|
59
|
+
type DiscriminatorHydratedKey<TBaseSchema extends Schema> =
|
|
60
|
+
ObtainSchemaGeneric<TBaseSchema, 'TSchemaOptions'> extends infer TSchemaOptions ?
|
|
61
|
+
'discriminatorKey' extends keyof TSchemaOptions ?
|
|
62
|
+
TSchemaOptions['discriminatorKey'] extends string ? TSchemaOptions['discriminatorKey'] : '__t'
|
|
63
|
+
: '__t'
|
|
64
|
+
: '__t';
|
|
65
|
+
|
|
66
|
+
type DiscriminatorHydratedBaseType<TBaseSchema extends Schema> =
|
|
67
|
+
InferHydratedDocTypeFromSchema<TBaseSchema> extends Record<DiscriminatorHydratedKey<TBaseSchema>, any> ?
|
|
68
|
+
InferHydratedDocTypeFromSchema<TBaseSchema>
|
|
69
|
+
: MergeType<InferHydratedDocTypeFromSchema<TBaseSchema>, { [K in DiscriminatorHydratedKey<TBaseSchema>]?: null }>;
|
|
70
|
+
|
|
71
|
+
type ResolveDiscriminatorHydratedPathType<TBaseSchema extends Schema, TDiscriminators> =
|
|
72
|
+
IsAny<TDiscriminators> extends true ? never
|
|
73
|
+
: TDiscriminators extends Record<string, any> ?
|
|
74
|
+
DiscriminatorHydratedBaseType<TBaseSchema> |
|
|
75
|
+
{
|
|
76
|
+
[K in keyof TDiscriminators]: TDiscriminators[K] extends Schema ?
|
|
77
|
+
MergeType<InferHydratedDocTypeFromSchema<TBaseSchema>, InferHydratedDocTypeFromSchema<TDiscriminators[K]>> &
|
|
78
|
+
{ [KDiscriminatorKey in DiscriminatorHydratedKey<TBaseSchema>]: K }
|
|
79
|
+
: never
|
|
80
|
+
}[keyof TDiscriminators]
|
|
81
|
+
: never;
|
|
82
|
+
|
|
83
|
+
type HydratedDiscriminatorEnumType<T> = string extends keyof T ? never
|
|
84
|
+
: number extends keyof T ? never
|
|
85
|
+
: T extends { type: infer BaseType; discriminators: infer TDiscriminators } ?
|
|
86
|
+
IsAny<BaseType> extends true ? never
|
|
87
|
+
: BaseType extends Schema ?
|
|
88
|
+
ResolveDiscriminatorHydratedPathType<BaseType, TDiscriminators>
|
|
89
|
+
: never
|
|
90
|
+
: never;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Same as inferSchemaType, except:
|
|
94
|
+
*
|
|
95
|
+
* 1. Replace `Types.DocumentArray` and `Types.Array` with vanilla `Array`
|
|
96
|
+
* 2. Replace `ObtainDocumentPathType` with `ObtainHydratedDocumentPathType`
|
|
97
|
+
* 3. Replace `ResolvePathType` with `ResolveHydratedPathType`
|
|
98
|
+
*
|
|
99
|
+
* @summary Resolve path type by returning the corresponding type.
|
|
100
|
+
* @param {PathValueType} PathValueType Document definition path type.
|
|
101
|
+
* @param {Options} Options Document definition path options except path type.
|
|
102
|
+
* @param {TypeKey} TypeKey A generic of literal string type. Refers to the property used for path type definition.
|
|
103
|
+
* @returns Type
|
|
104
|
+
*/
|
|
105
|
+
type ResolveHydratedPathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}, TypeKey extends string = DefaultSchemaOptions['typeKey'], TypeHint = never, TDiscriminatorEnumType = never> =
|
|
106
|
+
IsNotNever<TypeHint> extends true ? TypeHint
|
|
107
|
+
: IsNotNever<TDiscriminatorEnumType> extends true ? TDiscriminatorEnumType
|
|
108
|
+
: PathValueType extends Schema<any, any, any, any, any, any, any, any, infer THydratedDocumentType> ?
|
|
109
|
+
THydratedDocumentType :
|
|
110
|
+
PathValueType extends AnyArray<infer Item> ?
|
|
111
|
+
IfEquals<Item, never, any[], Item extends Schema<infer EmbeddedRawDocType, any, any, any, any, any, any, any, infer EmbeddedHydratedDocType extends AnyObject, infer TSchemaDefition> ?
|
|
112
|
+
IsItRecordAndNotAny<EmbeddedRawDocType> extends true ?
|
|
113
|
+
Types.DocumentArray<EmbeddedRawDocType, Types.Subdocument<EmbeddedHydratedDocType['_id'], unknown, EmbeddedHydratedDocType> & EmbeddedHydratedDocType> :
|
|
114
|
+
Types.DocumentArray<InferRawDocType<TSchemaDefition>, Types.Subdocument<InferHydratedDocType<TSchemaDefition>['_id'], unknown, InferHydratedDocType<TSchemaDefition>> & InferHydratedDocType<TSchemaDefition>> :
|
|
115
|
+
Item extends Record<TypeKey, any> ?
|
|
116
|
+
Item[TypeKey] extends Function | String ?
|
|
117
|
+
Types.Array<ObtainHydratedDocumentPathType<Item, TypeKey>> :
|
|
118
|
+
Types.DocumentArray<
|
|
119
|
+
InferRawDocType<Item>,
|
|
120
|
+
Types.Subdocument<InferHydratedDocType<Item>['_id'], unknown, InferHydratedDocType<Item>> & InferHydratedDocType<Item>
|
|
121
|
+
>:
|
|
122
|
+
IsSchemaTypeFromBuiltinClass<Item> extends true ?
|
|
123
|
+
Types.Array<ResolveHydratedPathType<Item, { enum: Exclude<Options['enum'], undefined> }, TypeKey>> :
|
|
124
|
+
IsItRecordAndNotAny<Item> extends true ?
|
|
125
|
+
Item extends Record<string, never> ?
|
|
126
|
+
Types.Array<ObtainHydratedDocumentPathType<Item, TypeKey>> :
|
|
127
|
+
Types.DocumentArray<
|
|
128
|
+
InferRawDocType<Item>,
|
|
129
|
+
Types.Subdocument<InferHydratedDocType<Item>['_id'], unknown, InferHydratedDocType<Item>> & InferHydratedDocType<Item>
|
|
130
|
+
> :
|
|
131
|
+
Types.Array<ObtainHydratedDocumentPathType<Item, TypeKey>>
|
|
132
|
+
>
|
|
133
|
+
: PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']>
|
|
134
|
+
: IfEquals<PathValueType, String> extends true ? PathEnumOrString<Options['enum']>
|
|
135
|
+
: PathValueType extends NumberSchemaDefinition ? Options['enum'] extends ReadonlyArray<any> ? Options['enum'][number] : number
|
|
136
|
+
: PathValueType extends DateSchemaDefinition ? NativeDate
|
|
137
|
+
: PathValueType extends BufferSchemaDefinition ? Buffer
|
|
138
|
+
: PathValueType extends BooleanSchemaDefinition ? boolean
|
|
139
|
+
: PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId
|
|
140
|
+
: PathValueType extends Decimal128SchemaDefinition ? Types.Decimal128
|
|
141
|
+
: PathValueType extends BigintSchemaDefinition ? bigint
|
|
142
|
+
: PathValueType extends UuidSchemaDefinition ? UUID
|
|
143
|
+
: PathValueType extends DoubleSchemaDefinition ? Types.Double
|
|
144
|
+
: PathValueType extends typeof Schema.Types.Mixed ? any
|
|
145
|
+
: PathValueType extends MapSchemaDefinition ? Map<string, ObtainHydratedDocumentPathType<Options['of']>>
|
|
146
|
+
: IfEquals<PathValueType, ObjectConstructor> extends true ? any
|
|
147
|
+
: PathValueType extends typeof SchemaType ? PathValueType['prototype']
|
|
148
|
+
: PathValueType extends ArrayConstructor ? Types.Array<any>
|
|
149
|
+
: PathValueType extends Record<string, any> ? InferHydratedDocType<PathValueType, { typeKey: TypeKey }>
|
|
150
|
+
: unknown;
|
|
151
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IsSchemaTypeFromBuiltinClass,
|
|
3
|
+
PathEnumOrString,
|
|
4
|
+
OptionalPaths,
|
|
5
|
+
RequiredPaths,
|
|
6
|
+
IsPathRequired,
|
|
7
|
+
PathAllowsNull
|
|
8
|
+
} from './inferschematype';
|
|
9
|
+
import { Binary, UUID } from 'mongodb';
|
|
10
|
+
|
|
11
|
+
declare module 'mongoose' {
|
|
12
|
+
export type InferRawDocTypeFromSchema<TSchema extends Schema<any>> = IsItRecordAndNotAny<ObtainSchemaGeneric<TSchema, 'EnforcedDocType'>> extends true
|
|
13
|
+
? ObtainSchemaGeneric<TSchema, 'EnforcedDocType'>
|
|
14
|
+
: unknown extends ObtainSchemaGeneric<TSchema, 'TSchemaDefinition'>
|
|
15
|
+
? Require_id<FlattenMaps<SubdocsToPOJOs<ObtainSchemaGeneric<TSchema, 'DocType'>>>>
|
|
16
|
+
: InferRawDocType<ObtainSchemaGeneric<TSchema, 'TSchemaDefinition'>>;
|
|
17
|
+
|
|
18
|
+
export type InferRawDocTypeWithout_id<
|
|
19
|
+
SchemaDefinition,
|
|
20
|
+
TSchemaOptions extends Record<any, any> = DefaultSchemaOptions,
|
|
21
|
+
TTransformOptions = { bufferToBinary: false }
|
|
22
|
+
> = ApplySchemaOptions<{
|
|
23
|
+
[
|
|
24
|
+
K in keyof (RequiredPaths<SchemaDefinition, TSchemaOptions['typeKey']> &
|
|
25
|
+
OptionalPaths<SchemaDefinition, TSchemaOptions['typeKey']>)
|
|
26
|
+
]: IsPathRequired<SchemaDefinition[K], TSchemaOptions['typeKey']> extends true
|
|
27
|
+
? ObtainRawDocumentPathType<SchemaDefinition[K], TSchemaOptions['typeKey'], TTransformOptions>
|
|
28
|
+
: PathAllowsNull<SchemaDefinition[K]> extends true
|
|
29
|
+
? ObtainRawDocumentPathType<SchemaDefinition[K], TSchemaOptions['typeKey'], TTransformOptions> | null
|
|
30
|
+
: ObtainRawDocumentPathType<SchemaDefinition[K], TSchemaOptions['typeKey'], TTransformOptions>;
|
|
31
|
+
}, TSchemaOptions>;
|
|
32
|
+
|
|
33
|
+
export type InferRawDocType<
|
|
34
|
+
SchemaDefinition,
|
|
35
|
+
TSchemaOptions extends Record<any, any> = DefaultSchemaOptions,
|
|
36
|
+
TTransformOptions = { bufferToBinary: false }
|
|
37
|
+
> = TSchemaOptions extends { _id: false }
|
|
38
|
+
? InferRawDocTypeWithout_id<SchemaDefinition, TSchemaOptions, TTransformOptions>
|
|
39
|
+
: Require_id<InferRawDocTypeWithout_id<SchemaDefinition, TSchemaOptions, TTransformOptions>>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @summary Allows users to optionally choose their own type for a schema field for stronger typing.
|
|
43
|
+
* Make sure to check for `any` because `T extends { __rawDocTypeHint: infer U }` will infer `unknown` if T is `any`.
|
|
44
|
+
*/
|
|
45
|
+
type RawDocTypeHint<T> = IsAny<T> extends true ? never
|
|
46
|
+
: T extends { __rawDocTypeHint: infer U } ? U: never;
|
|
47
|
+
|
|
48
|
+
type DiscriminatorRawKey<TBaseSchema extends Schema> =
|
|
49
|
+
ObtainSchemaGeneric<TBaseSchema, 'TSchemaOptions'> extends infer TSchemaOptions ?
|
|
50
|
+
'discriminatorKey' extends keyof TSchemaOptions ?
|
|
51
|
+
TSchemaOptions['discriminatorKey'] extends string ? TSchemaOptions['discriminatorKey'] : '__t'
|
|
52
|
+
: '__t'
|
|
53
|
+
: '__t';
|
|
54
|
+
|
|
55
|
+
type DiscriminatorRawBaseType<TBaseSchema extends Schema> =
|
|
56
|
+
InferRawDocTypeFromSchema<TBaseSchema> extends Record<DiscriminatorRawKey<TBaseSchema>, any> ?
|
|
57
|
+
InferRawDocTypeFromSchema<TBaseSchema>
|
|
58
|
+
: MergeType<InferRawDocTypeFromSchema<TBaseSchema>, { [K in DiscriminatorRawKey<TBaseSchema>]?: null }>;
|
|
59
|
+
|
|
60
|
+
type ResolveDiscriminatorRawPathType<TBaseSchema extends Schema, TDiscriminators> =
|
|
61
|
+
IsAny<TDiscriminators> extends true ? never
|
|
62
|
+
: TDiscriminators extends Record<string, any> ?
|
|
63
|
+
DiscriminatorRawBaseType<TBaseSchema> |
|
|
64
|
+
{
|
|
65
|
+
[K in keyof TDiscriminators]: TDiscriminators[K] extends Schema ?
|
|
66
|
+
MergeType<InferRawDocTypeFromSchema<TBaseSchema>, InferRawDocTypeFromSchema<TDiscriminators[K]>> &
|
|
67
|
+
{ [KDiscriminatorKey in DiscriminatorRawKey<TBaseSchema>]: K }
|
|
68
|
+
: never
|
|
69
|
+
}[keyof TDiscriminators]
|
|
70
|
+
: never;
|
|
71
|
+
|
|
72
|
+
type RawDiscriminatorEnumType<T> = string extends keyof T ? never
|
|
73
|
+
: number extends keyof T ? never
|
|
74
|
+
: T extends { type: infer BaseType; discriminators: infer TDiscriminators } ?
|
|
75
|
+
IsAny<BaseType> extends true ? never
|
|
76
|
+
: BaseType extends Schema ?
|
|
77
|
+
ResolveDiscriminatorRawPathType<BaseType, TDiscriminators>
|
|
78
|
+
: never
|
|
79
|
+
: never;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @summary Obtains schema Path type.
|
|
83
|
+
* @description Obtains Path type by separating path type from other options and calling {@link ResolveRawPathType}
|
|
84
|
+
* @param {PathValueType} PathValueType Document definition path type.
|
|
85
|
+
* @param {TypeKey} TypeKey A generic refers to document definition.
|
|
86
|
+
*/
|
|
87
|
+
type ObtainRawDocumentPathType<
|
|
88
|
+
PathValueType,
|
|
89
|
+
TypeKey extends string = DefaultTypeKey,
|
|
90
|
+
TTransformOptions = { bufferToBinary: false }
|
|
91
|
+
> = ResolveRawPathType<
|
|
92
|
+
TypeKey extends keyof PathValueType ?
|
|
93
|
+
TypeKey extends keyof PathValueType[TypeKey] ?
|
|
94
|
+
PathValueType
|
|
95
|
+
: PathValueType[TypeKey]
|
|
96
|
+
: PathValueType,
|
|
97
|
+
TypeKey extends keyof PathValueType ?
|
|
98
|
+
TypeKey extends keyof PathValueType[TypeKey] ?
|
|
99
|
+
{}
|
|
100
|
+
: Omit<PathValueType, TypeKey>
|
|
101
|
+
: {},
|
|
102
|
+
TypeKey,
|
|
103
|
+
TTransformOptions,
|
|
104
|
+
RawDocTypeHint<PathValueType>,
|
|
105
|
+
RawDiscriminatorEnumType<PathValueType>,
|
|
106
|
+
TypeKey extends keyof PathValueType ? false : true
|
|
107
|
+
>;
|
|
108
|
+
|
|
109
|
+
type neverOrAny = ' ~neverOrAny~';
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Same as inferSchemaType, except:
|
|
113
|
+
*
|
|
114
|
+
* 1. Replace `Types.DocumentArray` and `Types.Array` with vanilla `Array`
|
|
115
|
+
* 2. Replace `ObtainDocumentPathType` with `ObtainRawDocumentPathType`
|
|
116
|
+
* 3. Replace `ResolvePathType` with `ResolveRawPathType`
|
|
117
|
+
*
|
|
118
|
+
* @summary Resolve path type by returning the corresponding type.
|
|
119
|
+
* @param {PathValueType} PathValueType Document definition path type.
|
|
120
|
+
* @param {Options} Options Document definition path options except path type.
|
|
121
|
+
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
122
|
+
* @returns Number, "Number" or "number" will be resolved to number type.
|
|
123
|
+
*/
|
|
124
|
+
type ResolveRawPathType<
|
|
125
|
+
PathValueType,
|
|
126
|
+
Options extends SchemaTypeOptions<PathValueType> = {},
|
|
127
|
+
TypeKey extends string = DefaultSchemaOptions['typeKey'],
|
|
128
|
+
TTransformOptions = { bufferToBinary: false },
|
|
129
|
+
TypeHint = never,
|
|
130
|
+
TDiscriminatorEnumType = never,
|
|
131
|
+
IsNestedPath extends boolean = false
|
|
132
|
+
> =
|
|
133
|
+
IsNotNever<TypeHint> extends true ? TypeHint
|
|
134
|
+
: IsNotNever<TDiscriminatorEnumType> extends true ? TDiscriminatorEnumType
|
|
135
|
+
: [PathValueType] extends [neverOrAny] ? PathValueType
|
|
136
|
+
: PathValueType extends Schema<infer RawDocType, any, any, any, any, any, infer TSchemaOptions, infer DocType, any, infer TSchemaDefinition> ?
|
|
137
|
+
IsItRecordAndNotAny<RawDocType> extends true ?
|
|
138
|
+
RawDocType :
|
|
139
|
+
unknown extends TSchemaDefinition ?
|
|
140
|
+
TSchemaOptions extends { _id: false } ?
|
|
141
|
+
FlattenMaps<SubdocsToPOJOs<DocType>> :
|
|
142
|
+
Require_id<FlattenMaps<SubdocsToPOJOs<DocType>>> :
|
|
143
|
+
InferRawDocType<TSchemaDefinition, TSchemaOptions & Record<any, any>, TTransformOptions>
|
|
144
|
+
: PathValueType extends ReadonlyArray<infer Item> ?
|
|
145
|
+
IfEquals<Item, never> extends true ? any[]
|
|
146
|
+
: Item extends Schema<infer RawDocType, any, any, any, any, any, infer TSchemaOptions, infer DocType, any, infer TSchemaDefinition> ?
|
|
147
|
+
// If Item is a schema, infer its type.
|
|
148
|
+
Array<IsItRecordAndNotAny<RawDocType> extends true ?
|
|
149
|
+
RawDocType :
|
|
150
|
+
unknown extends TSchemaDefinition ?
|
|
151
|
+
TSchemaOptions extends { _id: false } ?
|
|
152
|
+
FlattenMaps<SubdocsToPOJOs<DocType>> :
|
|
153
|
+
Require_id<FlattenMaps<SubdocsToPOJOs<DocType>>> :
|
|
154
|
+
InferRawDocType<TSchemaDefinition, TSchemaOptions & Record<any, any>, TTransformOptions>>
|
|
155
|
+
: TypeKey extends keyof Item ?
|
|
156
|
+
Item[TypeKey] extends Function | String ?
|
|
157
|
+
// If Item has a type key that's a string or a callable, it must be a scalar,
|
|
158
|
+
// so we can directly obtain its path type.
|
|
159
|
+
ObtainRawDocumentPathType<Item, TypeKey, TTransformOptions>[]
|
|
160
|
+
: // If the type key isn't callable, then this is an array of objects, in which case
|
|
161
|
+
// we need to call InferRawDocType to correctly infer its type.
|
|
162
|
+
Array<InferRawDocType<Item, DefaultSchemaOptions, TTransformOptions>>
|
|
163
|
+
: IsSchemaTypeFromBuiltinClass<Item> extends true ? ResolveRawPathType<Item, { enum: Exclude<Options['enum'], undefined> }, TypeKey, TTransformOptions>[]
|
|
164
|
+
: IsItRecordAndNotAny<Item> extends true ?
|
|
165
|
+
Item extends Record<string, never> ?
|
|
166
|
+
ObtainRawDocumentPathType<Item, TypeKey, TTransformOptions>[]
|
|
167
|
+
: Array<InferRawDocType<Item, DefaultSchemaOptions, TTransformOptions>>
|
|
168
|
+
: ObtainRawDocumentPathType<Item, TypeKey, TTransformOptions>[]
|
|
169
|
+
: PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']>
|
|
170
|
+
: IfEquals<PathValueType, String> extends true ? PathEnumOrString<Options['enum']>
|
|
171
|
+
: PathValueType extends NumberSchemaDefinition ?
|
|
172
|
+
Options['enum'] extends ReadonlyArray<any> ?
|
|
173
|
+
Options['enum'][number]
|
|
174
|
+
: number
|
|
175
|
+
: PathValueType extends DateSchemaDefinition ? NativeDate
|
|
176
|
+
: PathValueType extends BufferSchemaDefinition ? (TTransformOptions extends { bufferToBinary: true } ? Binary : Buffer)
|
|
177
|
+
: PathValueType extends BooleanSchemaDefinition ? boolean
|
|
178
|
+
: PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId
|
|
179
|
+
: PathValueType extends Decimal128SchemaDefinition ? Types.Decimal128
|
|
180
|
+
: PathValueType extends BigintSchemaDefinition ? bigint
|
|
181
|
+
: PathValueType extends UuidSchemaDefinition ? Types.UUID
|
|
182
|
+
: PathValueType extends MapSchemaDefinition ? Record<string, ObtainRawDocumentPathType<Options['of'], TypeKey, TTransformOptions>>
|
|
183
|
+
: PathValueType extends DoubleSchemaDefinition ? Types.Double
|
|
184
|
+
: PathValueType extends UnionSchemaDefinition ?
|
|
185
|
+
ResolveRawPathType<Options['of'] extends ReadonlyArray<infer Item> ? Item : never>
|
|
186
|
+
: PathValueType extends ArrayConstructor ? any[]
|
|
187
|
+
: PathValueType extends typeof Schema.Types.Mixed ? any
|
|
188
|
+
: IfEquals<PathValueType, ObjectConstructor> extends true ? any
|
|
189
|
+
: IfEquals<PathValueType, {}> extends true ? any
|
|
190
|
+
: PathValueType extends typeof SchemaType ? PathValueType['prototype']
|
|
191
|
+
: PathValueType extends Record<string, any> ?
|
|
192
|
+
IsNestedPath extends true ?
|
|
193
|
+
// Nested path (no type key) - no _id
|
|
194
|
+
InferRawDocTypeWithout_id<PathValueType, { typeKey: TypeKey }, TTransformOptions>
|
|
195
|
+
: Options extends { _id: false } ?
|
|
196
|
+
// Subdocument with _id: false
|
|
197
|
+
InferRawDocTypeWithout_id<PathValueType, { typeKey: TypeKey }, TTransformOptions>
|
|
198
|
+
: // Subdocument with _id (default)
|
|
199
|
+
InferRawDocType<PathValueType, { typeKey: TypeKey }, TTransformOptions>
|
|
200
|
+
: unknown;
|
|
201
|
+
}
|