monsqlize 2.0.2 → 2.0.4
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/CHANGELOG.md +13 -5
- package/README.md +66 -20
- package/changelogs/README.md +8 -4
- package/changelogs/v2.0.0.md +1 -1
- package/changelogs/v2.0.3.md +58 -0
- package/changelogs/v2.0.4.md +61 -0
- package/dist/cjs/index.cjs +911 -213
- package/dist/cjs/transaction/Transaction.cjs +88 -3
- package/dist/cjs/transaction/TransactionManager.cjs +135 -11
- package/dist/esm/index.mjs +906 -208
- package/dist/types/collection.d.ts +5 -3
- package/dist/types/model.d.ts +279 -175
- package/dist/types/mongodb.d.ts +8 -1
- package/dist/types/monsqlize.d.ts +37 -4
- package/dist/types/pool.d.ts +1 -1
- package/dist/types/runtime.d.ts +33 -8
- package/dist/types/transaction.d.ts +12 -0
- package/package.json +23 -22
package/dist/types/model.d.ts
CHANGED
|
@@ -62,6 +62,104 @@ export interface VirtualConfig {
|
|
|
62
62
|
set?: (this: Record<string, unknown>, value: unknown) => void;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
export type ModelAutoIndexOptions = boolean | {
|
|
66
|
+
/** Enable automatic model index creation. Defaults to true for backward compatibility. */
|
|
67
|
+
enabled?: boolean;
|
|
68
|
+
/** Emit `model-index-error` when automatic index creation fails. Defaults to true. */
|
|
69
|
+
emitEvents?: boolean;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type ModelIndexSource = 'definition' | 'softDelete';
|
|
73
|
+
|
|
74
|
+
export interface ModelDeclaredIndex {
|
|
75
|
+
source: ModelIndexSource;
|
|
76
|
+
key: unknown;
|
|
77
|
+
options: Record<string, unknown>;
|
|
78
|
+
name?: string;
|
|
79
|
+
fingerprint: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface ModelIndexNamespace {
|
|
83
|
+
db: string;
|
|
84
|
+
collection: string;
|
|
85
|
+
poolName: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ModelIndexErrorSummary {
|
|
89
|
+
name?: string;
|
|
90
|
+
message: string;
|
|
91
|
+
code?: unknown;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface ModelIndexEnsureExisting {
|
|
95
|
+
declared: ModelDeclaredIndex;
|
|
96
|
+
existing: Record<string, unknown>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ModelIndexConflict {
|
|
100
|
+
declared: ModelDeclaredIndex;
|
|
101
|
+
existing?: Record<string, unknown>;
|
|
102
|
+
reason: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface ModelIndexCreated {
|
|
106
|
+
declared: ModelDeclaredIndex;
|
|
107
|
+
name?: string;
|
|
108
|
+
result?: unknown;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface ModelIndexFailure {
|
|
112
|
+
declared: ModelDeclaredIndex;
|
|
113
|
+
error: ModelIndexErrorSummary;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface ModelIndexSkipped {
|
|
117
|
+
declared: ModelDeclaredIndex;
|
|
118
|
+
reason: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface ModelEnsureIndexesOptions {
|
|
122
|
+
/** Return the index diff without creating missing indexes. */
|
|
123
|
+
dryRun?: boolean;
|
|
124
|
+
/** Throw a MonSQLize `MONGODB_ERROR` when conflicts or creation failures are found. */
|
|
125
|
+
throwOnError?: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface ModelEnsureAllIndexesOptions extends ModelEnsureIndexesOptions {
|
|
129
|
+
/** Limit the operation to specific registered model names. Defaults to all models. */
|
|
130
|
+
models?: string[];
|
|
131
|
+
/** Optional database scope for models without their own connection override. */
|
|
132
|
+
database?: string;
|
|
133
|
+
/** Optional pool scope for models without their own connection override. */
|
|
134
|
+
pool?: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface ModelIndexEnsureResult {
|
|
138
|
+
dryRun: boolean;
|
|
139
|
+
namespace: ModelIndexNamespace;
|
|
140
|
+
declared: ModelDeclaredIndex[];
|
|
141
|
+
existing: ModelIndexEnsureExisting[];
|
|
142
|
+
missing: ModelDeclaredIndex[];
|
|
143
|
+
created: ModelIndexCreated[];
|
|
144
|
+
conflicts: ModelIndexConflict[];
|
|
145
|
+
failed: ModelIndexFailure[];
|
|
146
|
+
skipped: ModelIndexSkipped[];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface ModelIndexEnsureSummary {
|
|
150
|
+
dryRun: boolean;
|
|
151
|
+
models: Array<{ name: string; result: ModelIndexEnsureResult }>;
|
|
152
|
+
totals: {
|
|
153
|
+
declared: number;
|
|
154
|
+
existing: number;
|
|
155
|
+
missing: number;
|
|
156
|
+
created: number;
|
|
157
|
+
conflicts: number;
|
|
158
|
+
failed: number;
|
|
159
|
+
skipped: number;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
65
163
|
/** v1 hooks factory format */
|
|
66
164
|
export type V1HooksFactory<TDocument = Record<string, unknown>> = (
|
|
67
165
|
model: ModelInstance<TDocument>,
|
|
@@ -95,6 +193,7 @@ export type V1MethodsFactory<TDocument = Record<string, unknown>> = (
|
|
|
95
193
|
export interface ModelDefinitionOptions {
|
|
96
194
|
timestamps?: boolean | { createdAt?: string | boolean; updatedAt?: string | boolean };
|
|
97
195
|
validate?: boolean;
|
|
196
|
+
autoIndex?: ModelAutoIndexOptions;
|
|
98
197
|
softDelete?: boolean | {
|
|
99
198
|
enabled?: boolean;
|
|
100
199
|
field?: string;
|
|
@@ -108,9 +207,9 @@ export interface ModelDefinitionOptions {
|
|
|
108
207
|
}
|
|
109
208
|
|
|
110
209
|
export interface ModelDefinition<TDocument = Record<string, unknown>> {
|
|
111
|
-
/**
|
|
210
|
+
/** Actual MongoDB collection name; falls back to `name` and then the `Model.define()` registration name. */
|
|
112
211
|
collection?: string;
|
|
113
|
-
/**
|
|
212
|
+
/** Compatibility collection name used by model auto-loading files; `collection` has higher priority. */
|
|
114
213
|
name?: string;
|
|
115
214
|
enums?: Record<string, string>;
|
|
116
215
|
schema?: ((dsl: unknown) => unknown) | Record<string, unknown>;
|
|
@@ -184,53 +283,53 @@ export interface ModelInstance<TDocument = any> {
|
|
|
184
283
|
readonly dbName: string;
|
|
185
284
|
readonly poolName?: string;
|
|
186
285
|
readonly definition: ModelDefinition<TDocument>;
|
|
187
|
-
/**
|
|
286
|
+
/** Returns namespace metadata for the current model, including instance ID, type, database, and collection. */
|
|
188
287
|
getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; };
|
|
189
|
-
/**
|
|
288
|
+
/** Returns the relation config map declared by the current model. */
|
|
190
289
|
getRelations(): Record<string, RelationConfig>;
|
|
191
|
-
/**
|
|
290
|
+
/** Returns the enum value map declared by the current model. */
|
|
192
291
|
getEnums(): Record<string, string>;
|
|
193
|
-
/**
|
|
292
|
+
/** Returns the underlying native MongoDB Collection for raw operations not wrapped by the framework. */
|
|
194
293
|
raw(): unknown;
|
|
195
294
|
/**
|
|
196
|
-
*
|
|
197
|
-
* @param query
|
|
198
|
-
* @param options
|
|
199
|
-
* @returns
|
|
295
|
+
* Finds documents matching the query.
|
|
296
|
+
* @param query Optional filter.
|
|
297
|
+
* @param options Optional query options such as projection, sort, and limit.
|
|
298
|
+
* @returns Document array with chainable `.populate()` support.
|
|
200
299
|
*/
|
|
201
300
|
find(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
202
301
|
/**
|
|
203
|
-
*
|
|
204
|
-
* @param query
|
|
205
|
-
* @param options
|
|
206
|
-
* @returns
|
|
302
|
+
* Finds the first document matching the query.
|
|
303
|
+
* @param query Optional filter.
|
|
304
|
+
* @param options Optional query options.
|
|
305
|
+
* @returns The matching document, or `null` when none is found.
|
|
207
306
|
*/
|
|
208
307
|
findOne(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
209
308
|
/**
|
|
210
|
-
*
|
|
211
|
-
* @param id
|
|
212
|
-
* @param options
|
|
213
|
-
* @returns
|
|
309
|
+
* Finds a single document by primary ID, as an ID shortcut for `findOne`.
|
|
310
|
+
* @param id Document primary key value.
|
|
311
|
+
* @param options Optional query options.
|
|
312
|
+
* @returns The matching document, or `null` when none is found.
|
|
214
313
|
*/
|
|
215
314
|
findOneById(id: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
216
315
|
/**
|
|
217
|
-
*
|
|
218
|
-
* @param id
|
|
219
|
-
* @param options
|
|
220
|
-
* @returns
|
|
316
|
+
* Finds a single document by primary ID; alias of `findOneById`.
|
|
317
|
+
* @param id Document primary key value.
|
|
318
|
+
* @param options Optional query options.
|
|
319
|
+
* @returns The matching document, or `null` when none is found.
|
|
221
320
|
*/
|
|
222
321
|
findById(id: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
223
322
|
/**
|
|
224
|
-
*
|
|
225
|
-
* @param ids
|
|
226
|
-
* @param options
|
|
227
|
-
* @returns
|
|
323
|
+
* Finds documents by multiple primary IDs.
|
|
324
|
+
* @param ids Primary key values.
|
|
325
|
+
* @param options Optional query options.
|
|
326
|
+
* @returns Matching documents.
|
|
228
327
|
*/
|
|
229
328
|
findByIds(ids: unknown[], options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
230
329
|
/**
|
|
231
|
-
*
|
|
232
|
-
* @param options
|
|
233
|
-
* @returns
|
|
330
|
+
* Finds documents with cursor-based or page-number pagination.
|
|
331
|
+
* @param options Pagination options including `limit`, `cursor`/`page`, `filter`, and `sort`.
|
|
332
|
+
* @returns Result object containing items, page information, and optional totals.
|
|
234
333
|
*/
|
|
235
334
|
findPage(options: { totals: { mode: 'sync'; } & Record<string, unknown>; } & Record<string, unknown>): PopulateProxy<{
|
|
236
335
|
items: Array<ModelDocument<TDocument>>;
|
|
@@ -245,273 +344,278 @@ export interface ModelInstance<TDocument = any> {
|
|
|
245
344
|
meta?: import('./collection').MetaInfo;
|
|
246
345
|
}>;
|
|
247
346
|
/**
|
|
248
|
-
*
|
|
249
|
-
* @param query
|
|
250
|
-
* @param options
|
|
251
|
-
* @returns
|
|
347
|
+
* Finds documents and returns the unpaginated total count.
|
|
348
|
+
* @param query Optional filter.
|
|
349
|
+
* @param options Optional query options.
|
|
350
|
+
* @returns Object containing documents and total count.
|
|
252
351
|
*/
|
|
253
352
|
findAndCount(query?: unknown, options?: unknown): PopulateProxy<{
|
|
254
353
|
data: Array<ModelDocument<TDocument>>;
|
|
255
354
|
total: number;
|
|
256
355
|
}>;
|
|
257
356
|
/**
|
|
258
|
-
*
|
|
259
|
-
* @param query
|
|
260
|
-
* @param options
|
|
261
|
-
* @returns
|
|
357
|
+
* Counts documents matching the query.
|
|
358
|
+
* @param query Optional filter.
|
|
359
|
+
* @param options Optional count options.
|
|
360
|
+
* @returns Number of matching documents.
|
|
262
361
|
*/
|
|
263
362
|
count(query?: unknown, options?: unknown): Promise<number>;
|
|
264
363
|
/**
|
|
265
|
-
*
|
|
266
|
-
* @param document
|
|
267
|
-
* @param options
|
|
268
|
-
* @returns
|
|
364
|
+
* Inserts a single document.
|
|
365
|
+
* @param document Document data to insert.
|
|
366
|
+
* @param options Optional write options.
|
|
367
|
+
* @returns Result object containing the inserted ID.
|
|
269
368
|
*/
|
|
270
369
|
insertOne(document?: unknown, options?: unknown): Promise<InsertOneResult>;
|
|
271
370
|
/**
|
|
272
|
-
*
|
|
273
|
-
* @param documents
|
|
274
|
-
* @param options
|
|
371
|
+
* Inserts multiple documents in order, stopping on the first error.
|
|
372
|
+
* @param documents Documents to insert.
|
|
373
|
+
* @param options Optional write options.
|
|
275
374
|
*/
|
|
276
375
|
insertMany(documents?: unknown[], options?: unknown): Promise<InsertManyResult>;
|
|
277
376
|
/**
|
|
278
|
-
*
|
|
279
|
-
* @param filter
|
|
280
|
-
* @param update
|
|
281
|
-
* @param options
|
|
377
|
+
* Updates the first document matching the filter.
|
|
378
|
+
* @param filter Filter.
|
|
379
|
+
* @param update Update operator document, such as `$set` or `$inc`.
|
|
380
|
+
* @param options Optional update options.
|
|
282
381
|
*/
|
|
283
382
|
updateOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
284
383
|
/**
|
|
285
|
-
*
|
|
286
|
-
* @param filter
|
|
287
|
-
* @param update
|
|
288
|
-
* @param options
|
|
384
|
+
* Updates all documents matching the filter.
|
|
385
|
+
* @param filter Filter.
|
|
386
|
+
* @param update Update operator document.
|
|
387
|
+
* @param options Optional update options.
|
|
289
388
|
*/
|
|
290
389
|
updateMany(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
291
390
|
/**
|
|
292
|
-
*
|
|
293
|
-
* @param filter
|
|
294
|
-
* @param replacement
|
|
295
|
-
* @param options
|
|
391
|
+
* Replaces the first document matching the filter with a full replacement document.
|
|
392
|
+
* @param filter Filter.
|
|
393
|
+
* @param replacement Full replacement document.
|
|
394
|
+
* @param options Optional replacement options.
|
|
296
395
|
*/
|
|
297
396
|
replaceOne(filter?: unknown, replacement?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
298
397
|
/**
|
|
299
|
-
*
|
|
300
|
-
* @param filter
|
|
301
|
-
* @param update
|
|
302
|
-
* @param options
|
|
303
|
-
* @returns
|
|
398
|
+
* Atomically finds and updates one document.
|
|
399
|
+
* @param filter Filter.
|
|
400
|
+
* @param update Update operator document.
|
|
401
|
+
* @param options Optional options such as `returnDocument: 'after'`.
|
|
402
|
+
* @returns Updated document, or `null` when none is found.
|
|
304
403
|
*/
|
|
305
404
|
findOneAndUpdate(filter?: unknown, update?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
306
405
|
/**
|
|
307
|
-
*
|
|
308
|
-
* @param filter
|
|
309
|
-
* @param replacement
|
|
310
|
-
* @param options
|
|
311
|
-
* @returns
|
|
406
|
+
* Atomically finds and replaces one document.
|
|
407
|
+
* @param filter Filter.
|
|
408
|
+
* @param replacement Full replacement document.
|
|
409
|
+
* @param options Optional options.
|
|
410
|
+
* @returns Replaced document, or `null` when none is found.
|
|
312
411
|
*/
|
|
313
412
|
findOneAndReplace(filter?: unknown, replacement?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
314
413
|
/**
|
|
315
|
-
*
|
|
316
|
-
* @param filter
|
|
317
|
-
* @param options
|
|
318
|
-
* @returns
|
|
414
|
+
* Atomically finds and deletes one document.
|
|
415
|
+
* @param filter Filter.
|
|
416
|
+
* @param options Optional options.
|
|
417
|
+
* @returns Deleted document, or `null` when none is found.
|
|
319
418
|
*/
|
|
320
419
|
findOneAndDelete(filter?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
321
420
|
/**
|
|
322
|
-
*
|
|
323
|
-
* @param filter
|
|
324
|
-
* @param update
|
|
325
|
-
* @param options
|
|
326
|
-
* @returns
|
|
421
|
+
* Updates an existing document or inserts one when none matches.
|
|
422
|
+
* @param filter Filter.
|
|
423
|
+
* @param update Update operator document.
|
|
424
|
+
* @param options Optional update options.
|
|
425
|
+
* @returns Standard `UpdateResult` object.
|
|
327
426
|
*/
|
|
328
427
|
upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
329
428
|
/**
|
|
330
|
-
*
|
|
331
|
-
* @param filter
|
|
332
|
-
* @param field
|
|
333
|
-
* @param increment
|
|
334
|
-
* @param options
|
|
429
|
+
* Atomically increments a field on one matching document.
|
|
430
|
+
* @param filter Filter.
|
|
431
|
+
* @param field Field name or field-increment map.
|
|
432
|
+
* @param increment Increment value used when `field` is a string.
|
|
433
|
+
* @param options Optional update options.
|
|
335
434
|
*/
|
|
336
435
|
incrementOne(filter?: unknown, field?: string | Record<string, number>, increment?: number, options?: unknown): Promise<IncrementOneResult<TDocument>>;
|
|
337
436
|
/**
|
|
338
|
-
*
|
|
339
|
-
* @param filter
|
|
340
|
-
* @param options
|
|
341
|
-
* @returns
|
|
437
|
+
* Deletes the first document matching the filter.
|
|
438
|
+
* @param filter Filter.
|
|
439
|
+
* @param options Optional delete options.
|
|
440
|
+
* @returns Standard `DeleteResult` object.
|
|
342
441
|
*/
|
|
343
442
|
deleteOne(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
344
443
|
/**
|
|
345
|
-
*
|
|
346
|
-
* @param filter
|
|
347
|
-
* @param options
|
|
348
|
-
* @returns
|
|
444
|
+
* Deletes all documents matching the filter.
|
|
445
|
+
* @param filter Filter.
|
|
446
|
+
* @param options Optional delete options.
|
|
447
|
+
* @returns Standard `DeleteResult` object.
|
|
349
448
|
*/
|
|
350
449
|
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
351
450
|
// soft-delete extended methods
|
|
352
451
|
/**
|
|
353
|
-
*
|
|
354
|
-
* @param query
|
|
355
|
-
* @param options
|
|
452
|
+
* Finds matching documents, including soft-deleted documents.
|
|
453
|
+
* @param query Optional filter.
|
|
454
|
+
* @param options Optional query options.
|
|
356
455
|
*/
|
|
357
456
|
findWithDeleted(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
358
457
|
/**
|
|
359
|
-
*
|
|
360
|
-
* @param query
|
|
361
|
-
* @param options
|
|
458
|
+
* Finds only soft-deleted documents.
|
|
459
|
+
* @param query Optional filter.
|
|
460
|
+
* @param options Optional query options.
|
|
362
461
|
*/
|
|
363
462
|
findOnlyDeleted(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
364
463
|
/**
|
|
365
|
-
*
|
|
366
|
-
* @param query
|
|
367
|
-
* @param options
|
|
368
|
-
* @returns
|
|
464
|
+
* Finds the first matching document, including soft-deleted documents.
|
|
465
|
+
* @param query Optional filter.
|
|
466
|
+
* @param options Optional query options.
|
|
467
|
+
* @returns Matching document, or `null` when none is found.
|
|
369
468
|
*/
|
|
370
469
|
findOneWithDeleted(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
371
470
|
/**
|
|
372
|
-
*
|
|
373
|
-
* @param filter
|
|
374
|
-
* @param options
|
|
471
|
+
* Restores the first soft-deleted document matching the filter.
|
|
472
|
+
* @param filter Filter.
|
|
473
|
+
* @param options Optional update options.
|
|
375
474
|
*/
|
|
376
475
|
restore(filter?: unknown, options?: unknown): Promise<RestoreResult>;
|
|
377
476
|
/**
|
|
378
|
-
*
|
|
379
|
-
* @param filter
|
|
380
|
-
* @param options
|
|
477
|
+
* Restores all soft-deleted documents matching the filter.
|
|
478
|
+
* @param filter Filter.
|
|
479
|
+
* @param options Optional update options.
|
|
381
480
|
*/
|
|
382
481
|
restoreMany(filter?: unknown, options?: unknown): Promise<RestoreResult>;
|
|
383
482
|
/**
|
|
384
|
-
*
|
|
385
|
-
* @param filter
|
|
386
|
-
* @param options
|
|
387
|
-
* @returns
|
|
483
|
+
* Physically deletes the first matching document, bypassing soft-delete.
|
|
484
|
+
* @param filter Filter.
|
|
485
|
+
* @param options Optional delete options.
|
|
486
|
+
* @returns Standard `DeleteResult` object.
|
|
388
487
|
*/
|
|
389
488
|
forceDelete(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
390
489
|
/**
|
|
391
|
-
*
|
|
392
|
-
* @param filter
|
|
393
|
-
* @param options
|
|
394
|
-
* @returns
|
|
490
|
+
* Physically deletes all matching documents, bypassing soft-delete.
|
|
491
|
+
* @param filter Filter.
|
|
492
|
+
* @param options Optional delete options.
|
|
493
|
+
* @returns Standard `DeleteResult` object.
|
|
395
494
|
*/
|
|
396
495
|
forceDeleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
397
496
|
/**
|
|
398
|
-
*
|
|
399
|
-
* @param query
|
|
400
|
-
* @param options
|
|
401
|
-
* @returns
|
|
497
|
+
* Finds the first matching document from only the soft-deleted set.
|
|
498
|
+
* @param query Optional filter.
|
|
499
|
+
* @param options Optional query options.
|
|
500
|
+
* @returns Matching deleted document, or `null` when none is found.
|
|
402
501
|
*/
|
|
403
502
|
findOneOnlyDeleted(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
404
503
|
/**
|
|
405
|
-
*
|
|
406
|
-
* @param query
|
|
407
|
-
* @param options
|
|
504
|
+
* Counts matching documents, including soft-deleted documents.
|
|
505
|
+
* @param query Optional filter.
|
|
506
|
+
* @param options Optional count options.
|
|
408
507
|
*/
|
|
409
508
|
countWithDeleted(query?: unknown, options?: unknown): Promise<number>;
|
|
410
509
|
/**
|
|
411
|
-
*
|
|
412
|
-
* @param query
|
|
413
|
-
* @param options
|
|
510
|
+
* Counts soft-deleted documents matching the query.
|
|
511
|
+
* @param query Optional filter.
|
|
512
|
+
* @param options Optional count options.
|
|
414
513
|
*/
|
|
415
514
|
countOnlyDeleted(query?: unknown, options?: unknown): Promise<number>;
|
|
416
515
|
/**
|
|
417
|
-
*
|
|
418
|
-
* @param docs
|
|
419
|
-
* @param options
|
|
516
|
+
* Inserts a large document batch through the write queue.
|
|
517
|
+
* @param docs Documents to insert.
|
|
518
|
+
* @param options Optional batch write options.
|
|
420
519
|
*/
|
|
421
520
|
insertBatch(docs: unknown[], options?: unknown): Promise<InsertBatchResult>;
|
|
422
521
|
/**
|
|
423
|
-
*
|
|
424
|
-
* @param filter
|
|
425
|
-
* @param update
|
|
426
|
-
* @param options
|
|
522
|
+
* Batch-updates matching documents using `bulkWrite`.
|
|
523
|
+
* @param filter Filter.
|
|
524
|
+
* @param update Update operator document.
|
|
525
|
+
* @param options Optional batch write options.
|
|
427
526
|
*/
|
|
428
527
|
updateBatch(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateBatchResult>;
|
|
429
|
-
/**
|
|
528
|
+
/** Batch-deletes matching documents. */
|
|
430
529
|
deleteBatch(filter?: unknown, options?: unknown): Promise<DeleteBatchResult>;
|
|
431
530
|
/**
|
|
432
|
-
*
|
|
433
|
-
* @param keys
|
|
434
|
-
* @param options
|
|
435
|
-
* @returns
|
|
531
|
+
* Creates a single index on the collection.
|
|
532
|
+
* @param keys Index key specification.
|
|
533
|
+
* @param options Optional index options such as `unique` or `sparse`.
|
|
534
|
+
* @returns Index creation result.
|
|
436
535
|
*/
|
|
437
536
|
createIndex(keys: unknown, options?: unknown): Promise<IndexCreateResult>;
|
|
438
537
|
/**
|
|
439
|
-
*
|
|
440
|
-
* @param specs
|
|
441
|
-
* @returns
|
|
538
|
+
* Creates multiple indexes.
|
|
539
|
+
* @param specs Index specifications, each containing `key` and optional index options.
|
|
540
|
+
* @returns Names of created indexes.
|
|
442
541
|
*/
|
|
443
542
|
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
444
|
-
/**
|
|
543
|
+
/** Lists all existing index definitions on the collection. */
|
|
445
544
|
listIndexes(): Promise<Record<string, unknown>[]>;
|
|
446
545
|
/**
|
|
447
|
-
*
|
|
448
|
-
*
|
|
546
|
+
* Compares declared model indexes with the database and optionally creates missing indexes.
|
|
547
|
+
* Does not drop, rename, or rebuild conflicting indexes.
|
|
548
|
+
*/
|
|
549
|
+
ensureIndexes(options?: ModelEnsureIndexesOptions): Promise<ModelIndexEnsureResult>;
|
|
550
|
+
/**
|
|
551
|
+
* Drops the specified index by name.
|
|
552
|
+
* @param name Index name.
|
|
449
553
|
*/
|
|
450
554
|
dropIndex(name: string): Promise<unknown>;
|
|
451
|
-
/**
|
|
555
|
+
/** Drops all non-`_id` indexes on the collection. */
|
|
452
556
|
dropIndexes(): Promise<unknown>;
|
|
453
|
-
/**
|
|
557
|
+
/** Prewarms cursor pagination bookmark cache. */
|
|
454
558
|
prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise<BookmarkPrewarmResult>;
|
|
455
|
-
/**
|
|
559
|
+
/** Lists cursor pagination bookmark cache entries. */
|
|
456
560
|
listBookmarks(keyDims?: unknown): Promise<BookmarkListResult>;
|
|
457
|
-
/**
|
|
561
|
+
/** Clears cursor pagination bookmark cache entries. */
|
|
458
562
|
clearBookmarks(keyDims?: unknown): Promise<BookmarkClearResult>;
|
|
459
563
|
/**
|
|
460
|
-
*
|
|
461
|
-
* @param key
|
|
462
|
-
* @param query
|
|
463
|
-
* @param options
|
|
464
|
-
* @returns
|
|
564
|
+
* Gets distinct values for a field from matching documents.
|
|
565
|
+
* @param key Target field name.
|
|
566
|
+
* @param query Optional filter.
|
|
567
|
+
* @param options Optional driver-level options.
|
|
568
|
+
* @returns Distinct values.
|
|
465
569
|
*/
|
|
466
570
|
distinct(key: string, query?: unknown, options?: unknown): Promise<unknown[]>;
|
|
467
571
|
/**
|
|
468
|
-
*
|
|
469
|
-
* @param pipeline
|
|
470
|
-
* @param options
|
|
471
|
-
* @returns
|
|
572
|
+
* Executes an aggregation pipeline and returns result documents.
|
|
573
|
+
* @param pipeline Aggregation stages.
|
|
574
|
+
* @param options Optional aggregation options such as `allowDiskUse`.
|
|
575
|
+
* @returns Aggregation result documents.
|
|
472
576
|
*/
|
|
473
577
|
aggregate(pipeline?: unknown[], options?: unknown): Promise<unknown[]>;
|
|
474
|
-
/**
|
|
578
|
+
/** Returns a readable stream for matching query results. */
|
|
475
579
|
stream(query?: unknown, options?: unknown): NodeJS.ReadableStream;
|
|
476
|
-
/**
|
|
580
|
+
/** Returns the MongoDB query execution plan. */
|
|
477
581
|
explain(query?: unknown, options?: unknown): Promise<unknown>;
|
|
478
|
-
/**
|
|
582
|
+
/** Manually invalidates read cache for the current model collection. */
|
|
479
583
|
invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise<number>;
|
|
480
|
-
/**
|
|
584
|
+
/** Drops the collection for the current model. */
|
|
481
585
|
dropCollection(): Promise<boolean>;
|
|
482
|
-
/**
|
|
586
|
+
/** Creates the current collection or a collection with the specified name. */
|
|
483
587
|
createCollection(name?: string, options?: Record<string, unknown>): Promise<boolean>;
|
|
484
|
-
/**
|
|
588
|
+
/** Creates a MongoDB view. */
|
|
485
589
|
createView(name: string, source: string, pipeline?: unknown[]): Promise<boolean>;
|
|
486
|
-
/**
|
|
590
|
+
/** Returns index usage statistics. */
|
|
487
591
|
indexStats(): Promise<unknown[]>;
|
|
488
|
-
/**
|
|
592
|
+
/** Sets the collection JSON Schema validator. */
|
|
489
593
|
setValidator(validator: unknown, options?: { validationLevel?: string; validationAction?: string }): Promise<{ ok: number; collection: string }>;
|
|
490
|
-
/**
|
|
594
|
+
/** Sets the collection validation level. */
|
|
491
595
|
setValidationLevel(level: 'off' | 'moderate' | 'strict' | string): Promise<{ ok: number; validationLevel: string }>;
|
|
492
|
-
/**
|
|
596
|
+
/** Sets the collection validation action. */
|
|
493
597
|
setValidationAction(action: 'error' | 'warn' | string): Promise<{ ok: number; validationAction: string }>;
|
|
494
|
-
/**
|
|
598
|
+
/** Reads the collection validator and validation settings. */
|
|
495
599
|
getValidator(): Promise<{ validator: Record<string, unknown> | null; validationLevel: string; validationAction: string }>;
|
|
496
|
-
/**
|
|
600
|
+
/** Returns collection storage and index statistics. */
|
|
497
601
|
stats(options?: { scale?: number }): Promise<{ ns: string; count: number; size: number; storageSize: number; totalIndexSize: number; nindexes: number; avgObjSize?: number; scaleFactor?: number }>;
|
|
498
|
-
/**
|
|
602
|
+
/** Renames the collection for the current model. */
|
|
499
603
|
renameCollection(newName: string, options?: { dropTarget?: boolean }): Promise<{ renamed: boolean; from: string; to: string }>;
|
|
500
|
-
/**
|
|
604
|
+
/** Executes a collMod management command. */
|
|
501
605
|
collMod(modifications: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
502
|
-
/**
|
|
606
|
+
/** Converts the collection to a capped collection. */
|
|
503
607
|
convertToCapped(size: number, options?: { max?: number }): Promise<{ ok: number; collection: string; capped: boolean; size: number }>;
|
|
504
608
|
/**
|
|
505
|
-
*
|
|
506
|
-
* @param pipeline
|
|
507
|
-
* @param options
|
|
508
|
-
* @returns MongoDB
|
|
609
|
+
* Opens a ChangeStream on the collection.
|
|
610
|
+
* @param pipeline Optional aggregation filter pipeline.
|
|
611
|
+
* @param options Optional ChangeStream options.
|
|
612
|
+
* @returns Native MongoDB ChangeStream object.
|
|
509
613
|
*/
|
|
510
614
|
watch(pipeline?: unknown[], options?: unknown): import('mongodb').ChangeStream;
|
|
511
615
|
/**
|
|
512
|
-
*
|
|
513
|
-
* @param document
|
|
514
|
-
* @returns
|
|
616
|
+
* Validates document data against the model schema definition.
|
|
617
|
+
* @param document Document to validate.
|
|
618
|
+
* @returns Validation result containing the `valid` flag and error details.
|
|
515
619
|
*/
|
|
516
620
|
validate(document?: unknown): ValidationResult;
|
|
517
621
|
}
|
package/dist/types/mongodb.d.ts
CHANGED
|
@@ -13,7 +13,14 @@ export interface MongoConnectConfig {
|
|
|
13
13
|
useMemoryServer?: boolean;
|
|
14
14
|
/** Instance/binary configuration options for mongodb-memory-server. */
|
|
15
15
|
memoryServerOptions?: {
|
|
16
|
-
instance?: {
|
|
16
|
+
instance?: {
|
|
17
|
+
port?: number;
|
|
18
|
+
dbName?: string;
|
|
19
|
+
storageEngine?: string;
|
|
20
|
+
replSet?: string;
|
|
21
|
+
dbPath?: string;
|
|
22
|
+
launchTimeout?: number;
|
|
23
|
+
};
|
|
17
24
|
binary?: { version?: string };
|
|
18
25
|
[key: string]: unknown;
|
|
19
26
|
};
|