monsqlize 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -5
- package/README.md +35 -19
- package/changelogs/README.md +8 -4
- package/changelogs/v2.0.0.md +1 -1
- package/changelogs/v2.0.2.md +22 -0
- package/changelogs/v2.0.3.md +58 -0
- package/dist/cjs/index.cjs +648 -192
- package/dist/cjs/transaction/Transaction.cjs +88 -3
- package/dist/cjs/transaction/TransactionManager.cjs +135 -11
- package/dist/esm/index.mjs +643 -187
- package/dist/types/collection.d.ts +5 -3
- package/dist/types/model.d.ts +175 -175
- package/dist/types/mongodb.d.ts +8 -1
- package/dist/types/monsqlize.d.ts +28 -3
- package/dist/types/pool.d.ts +1 -1
- package/dist/types/runtime.d.ts +31 -7
- package/dist/types/transaction.d.ts +12 -0
- package/package.json +36 -35
|
@@ -34,6 +34,8 @@ export interface TotalsInfo {
|
|
|
34
34
|
token?: string;
|
|
35
35
|
/** Write timestamp (ms) if from cache */
|
|
36
36
|
ts?: number;
|
|
37
|
+
/** True when an approximate totals strategy was used */
|
|
38
|
+
approx?: boolean;
|
|
37
39
|
/** Error identifier for async mode failures */
|
|
38
40
|
error?: string;
|
|
39
41
|
}
|
|
@@ -98,9 +100,9 @@ export interface OffsetJumpOptions {
|
|
|
98
100
|
export interface TotalsOptions {
|
|
99
101
|
/** Counting strategy (default 'none') */
|
|
100
102
|
mode?: 'none' | 'async' | 'approx' | 'sync';
|
|
101
|
-
/** Timeout for countDocuments
|
|
103
|
+
/** Timeout for countDocuments / estimatedDocumentCount (ms) */
|
|
102
104
|
maxTimeMS?: number;
|
|
103
|
-
/** Cache TTL for totals (
|
|
105
|
+
/** Cache TTL for totals (ms; default 10 min) */
|
|
104
106
|
ttlMs?: number;
|
|
105
107
|
/** Index hint for count query */
|
|
106
108
|
hint?: unknown;
|
|
@@ -220,7 +222,7 @@ export interface FindPageOptions<TSchema = any> {
|
|
|
220
222
|
hint?: Document | string;
|
|
221
223
|
collation?: Document;
|
|
222
224
|
batchSize?: number;
|
|
223
|
-
/** Cache TTL in milliseconds */
|
|
225
|
+
/** Cache TTL in milliseconds for the non-stream/non-explain page result */
|
|
224
226
|
cache?: number;
|
|
225
227
|
/** Include timing/meta info in result — pass true or MetaOptions for sub-step detail */
|
|
226
228
|
meta?: boolean | MetaOptions;
|
package/dist/types/model.d.ts
CHANGED
|
@@ -108,9 +108,9 @@ export interface ModelDefinitionOptions {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
export interface ModelDefinition<TDocument = Record<string, unknown>> {
|
|
111
|
-
/**
|
|
111
|
+
/** Actual MongoDB collection name; falls back to `name` and then the `Model.define()` registration name. */
|
|
112
112
|
collection?: string;
|
|
113
|
-
/**
|
|
113
|
+
/** Compatibility collection name used by model auto-loading files; `collection` has higher priority. */
|
|
114
114
|
name?: string;
|
|
115
115
|
enums?: Record<string, string>;
|
|
116
116
|
schema?: ((dsl: unknown) => unknown) | Record<string, unknown>;
|
|
@@ -184,53 +184,53 @@ export interface ModelInstance<TDocument = any> {
|
|
|
184
184
|
readonly dbName: string;
|
|
185
185
|
readonly poolName?: string;
|
|
186
186
|
readonly definition: ModelDefinition<TDocument>;
|
|
187
|
-
/**
|
|
187
|
+
/** Returns namespace metadata for the current model, including instance ID, type, database, and collection. */
|
|
188
188
|
getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; };
|
|
189
|
-
/**
|
|
189
|
+
/** Returns the relation config map declared by the current model. */
|
|
190
190
|
getRelations(): Record<string, RelationConfig>;
|
|
191
|
-
/**
|
|
191
|
+
/** Returns the enum value map declared by the current model. */
|
|
192
192
|
getEnums(): Record<string, string>;
|
|
193
|
-
/**
|
|
193
|
+
/** Returns the underlying native MongoDB Collection for raw operations not wrapped by the framework. */
|
|
194
194
|
raw(): unknown;
|
|
195
195
|
/**
|
|
196
|
-
*
|
|
197
|
-
* @param query
|
|
198
|
-
* @param options
|
|
199
|
-
* @returns
|
|
196
|
+
* Finds documents matching the query.
|
|
197
|
+
* @param query Optional filter.
|
|
198
|
+
* @param options Optional query options such as projection, sort, and limit.
|
|
199
|
+
* @returns Document array with chainable `.populate()` support.
|
|
200
200
|
*/
|
|
201
201
|
find(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
202
202
|
/**
|
|
203
|
-
*
|
|
204
|
-
* @param query
|
|
205
|
-
* @param options
|
|
206
|
-
* @returns
|
|
203
|
+
* Finds the first document matching the query.
|
|
204
|
+
* @param query Optional filter.
|
|
205
|
+
* @param options Optional query options.
|
|
206
|
+
* @returns The matching document, or `null` when none is found.
|
|
207
207
|
*/
|
|
208
208
|
findOne(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
209
209
|
/**
|
|
210
|
-
*
|
|
211
|
-
* @param id
|
|
212
|
-
* @param options
|
|
213
|
-
* @returns
|
|
210
|
+
* Finds a single document by primary ID, as an ID shortcut for `findOne`.
|
|
211
|
+
* @param id Document primary key value.
|
|
212
|
+
* @param options Optional query options.
|
|
213
|
+
* @returns The matching document, or `null` when none is found.
|
|
214
214
|
*/
|
|
215
215
|
findOneById(id: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
216
216
|
/**
|
|
217
|
-
*
|
|
218
|
-
* @param id
|
|
219
|
-
* @param options
|
|
220
|
-
* @returns
|
|
217
|
+
* Finds a single document by primary ID; alias of `findOneById`.
|
|
218
|
+
* @param id Document primary key value.
|
|
219
|
+
* @param options Optional query options.
|
|
220
|
+
* @returns The matching document, or `null` when none is found.
|
|
221
221
|
*/
|
|
222
222
|
findById(id: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
223
223
|
/**
|
|
224
|
-
*
|
|
225
|
-
* @param ids
|
|
226
|
-
* @param options
|
|
227
|
-
* @returns
|
|
224
|
+
* Finds documents by multiple primary IDs.
|
|
225
|
+
* @param ids Primary key values.
|
|
226
|
+
* @param options Optional query options.
|
|
227
|
+
* @returns Matching documents.
|
|
228
228
|
*/
|
|
229
229
|
findByIds(ids: unknown[], options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
230
230
|
/**
|
|
231
|
-
*
|
|
232
|
-
* @param options
|
|
233
|
-
* @returns
|
|
231
|
+
* Finds documents with cursor-based or page-number pagination.
|
|
232
|
+
* @param options Pagination options including `limit`, `cursor`/`page`, `filter`, and `sort`.
|
|
233
|
+
* @returns Result object containing items, page information, and optional totals.
|
|
234
234
|
*/
|
|
235
235
|
findPage(options: { totals: { mode: 'sync'; } & Record<string, unknown>; } & Record<string, unknown>): PopulateProxy<{
|
|
236
236
|
items: Array<ModelDocument<TDocument>>;
|
|
@@ -245,273 +245,273 @@ export interface ModelInstance<TDocument = any> {
|
|
|
245
245
|
meta?: import('./collection').MetaInfo;
|
|
246
246
|
}>;
|
|
247
247
|
/**
|
|
248
|
-
*
|
|
249
|
-
* @param query
|
|
250
|
-
* @param options
|
|
251
|
-
* @returns
|
|
248
|
+
* Finds documents and returns the unpaginated total count.
|
|
249
|
+
* @param query Optional filter.
|
|
250
|
+
* @param options Optional query options.
|
|
251
|
+
* @returns Object containing documents and total count.
|
|
252
252
|
*/
|
|
253
253
|
findAndCount(query?: unknown, options?: unknown): PopulateProxy<{
|
|
254
254
|
data: Array<ModelDocument<TDocument>>;
|
|
255
255
|
total: number;
|
|
256
256
|
}>;
|
|
257
257
|
/**
|
|
258
|
-
*
|
|
259
|
-
* @param query
|
|
260
|
-
* @param options
|
|
261
|
-
* @returns
|
|
258
|
+
* Counts documents matching the query.
|
|
259
|
+
* @param query Optional filter.
|
|
260
|
+
* @param options Optional count options.
|
|
261
|
+
* @returns Number of matching documents.
|
|
262
262
|
*/
|
|
263
263
|
count(query?: unknown, options?: unknown): Promise<number>;
|
|
264
264
|
/**
|
|
265
|
-
*
|
|
266
|
-
* @param document
|
|
267
|
-
* @param options
|
|
268
|
-
* @returns
|
|
265
|
+
* Inserts a single document.
|
|
266
|
+
* @param document Document data to insert.
|
|
267
|
+
* @param options Optional write options.
|
|
268
|
+
* @returns Result object containing the inserted ID.
|
|
269
269
|
*/
|
|
270
270
|
insertOne(document?: unknown, options?: unknown): Promise<InsertOneResult>;
|
|
271
271
|
/**
|
|
272
|
-
*
|
|
273
|
-
* @param documents
|
|
274
|
-
* @param options
|
|
272
|
+
* Inserts multiple documents in order, stopping on the first error.
|
|
273
|
+
* @param documents Documents to insert.
|
|
274
|
+
* @param options Optional write options.
|
|
275
275
|
*/
|
|
276
276
|
insertMany(documents?: unknown[], options?: unknown): Promise<InsertManyResult>;
|
|
277
277
|
/**
|
|
278
|
-
*
|
|
279
|
-
* @param filter
|
|
280
|
-
* @param update
|
|
281
|
-
* @param options
|
|
278
|
+
* Updates the first document matching the filter.
|
|
279
|
+
* @param filter Filter.
|
|
280
|
+
* @param update Update operator document, such as `$set` or `$inc`.
|
|
281
|
+
* @param options Optional update options.
|
|
282
282
|
*/
|
|
283
283
|
updateOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
284
284
|
/**
|
|
285
|
-
*
|
|
286
|
-
* @param filter
|
|
287
|
-
* @param update
|
|
288
|
-
* @param options
|
|
285
|
+
* Updates all documents matching the filter.
|
|
286
|
+
* @param filter Filter.
|
|
287
|
+
* @param update Update operator document.
|
|
288
|
+
* @param options Optional update options.
|
|
289
289
|
*/
|
|
290
290
|
updateMany(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
291
291
|
/**
|
|
292
|
-
*
|
|
293
|
-
* @param filter
|
|
294
|
-
* @param replacement
|
|
295
|
-
* @param options
|
|
292
|
+
* Replaces the first document matching the filter with a full replacement document.
|
|
293
|
+
* @param filter Filter.
|
|
294
|
+
* @param replacement Full replacement document.
|
|
295
|
+
* @param options Optional replacement options.
|
|
296
296
|
*/
|
|
297
297
|
replaceOne(filter?: unknown, replacement?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
298
298
|
/**
|
|
299
|
-
*
|
|
300
|
-
* @param filter
|
|
301
|
-
* @param update
|
|
302
|
-
* @param options
|
|
303
|
-
* @returns
|
|
299
|
+
* Atomically finds and updates one document.
|
|
300
|
+
* @param filter Filter.
|
|
301
|
+
* @param update Update operator document.
|
|
302
|
+
* @param options Optional options such as `returnDocument: 'after'`.
|
|
303
|
+
* @returns Updated document, or `null` when none is found.
|
|
304
304
|
*/
|
|
305
305
|
findOneAndUpdate(filter?: unknown, update?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
306
306
|
/**
|
|
307
|
-
*
|
|
308
|
-
* @param filter
|
|
309
|
-
* @param replacement
|
|
310
|
-
* @param options
|
|
311
|
-
* @returns
|
|
307
|
+
* Atomically finds and replaces one document.
|
|
308
|
+
* @param filter Filter.
|
|
309
|
+
* @param replacement Full replacement document.
|
|
310
|
+
* @param options Optional options.
|
|
311
|
+
* @returns Replaced document, or `null` when none is found.
|
|
312
312
|
*/
|
|
313
313
|
findOneAndReplace(filter?: unknown, replacement?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
314
314
|
/**
|
|
315
|
-
*
|
|
316
|
-
* @param filter
|
|
317
|
-
* @param options
|
|
318
|
-
* @returns
|
|
315
|
+
* Atomically finds and deletes one document.
|
|
316
|
+
* @param filter Filter.
|
|
317
|
+
* @param options Optional options.
|
|
318
|
+
* @returns Deleted document, or `null` when none is found.
|
|
319
319
|
*/
|
|
320
320
|
findOneAndDelete(filter?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
321
321
|
/**
|
|
322
|
-
*
|
|
323
|
-
* @param filter
|
|
324
|
-
* @param update
|
|
325
|
-
* @param options
|
|
326
|
-
* @returns
|
|
322
|
+
* Updates an existing document or inserts one when none matches.
|
|
323
|
+
* @param filter Filter.
|
|
324
|
+
* @param update Update operator document.
|
|
325
|
+
* @param options Optional update options.
|
|
326
|
+
* @returns Standard `UpdateResult` object.
|
|
327
327
|
*/
|
|
328
328
|
upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
329
329
|
/**
|
|
330
|
-
*
|
|
331
|
-
* @param filter
|
|
332
|
-
* @param field
|
|
333
|
-
* @param increment
|
|
334
|
-
* @param options
|
|
330
|
+
* Atomically increments a field on one matching document.
|
|
331
|
+
* @param filter Filter.
|
|
332
|
+
* @param field Field name or field-increment map.
|
|
333
|
+
* @param increment Increment value used when `field` is a string.
|
|
334
|
+
* @param options Optional update options.
|
|
335
335
|
*/
|
|
336
336
|
incrementOne(filter?: unknown, field?: string | Record<string, number>, increment?: number, options?: unknown): Promise<IncrementOneResult<TDocument>>;
|
|
337
337
|
/**
|
|
338
|
-
*
|
|
339
|
-
* @param filter
|
|
340
|
-
* @param options
|
|
341
|
-
* @returns
|
|
338
|
+
* Deletes the first document matching the filter.
|
|
339
|
+
* @param filter Filter.
|
|
340
|
+
* @param options Optional delete options.
|
|
341
|
+
* @returns Standard `DeleteResult` object.
|
|
342
342
|
*/
|
|
343
343
|
deleteOne(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
344
344
|
/**
|
|
345
|
-
*
|
|
346
|
-
* @param filter
|
|
347
|
-
* @param options
|
|
348
|
-
* @returns
|
|
345
|
+
* Deletes all documents matching the filter.
|
|
346
|
+
* @param filter Filter.
|
|
347
|
+
* @param options Optional delete options.
|
|
348
|
+
* @returns Standard `DeleteResult` object.
|
|
349
349
|
*/
|
|
350
350
|
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
351
351
|
// soft-delete extended methods
|
|
352
352
|
/**
|
|
353
|
-
*
|
|
354
|
-
* @param query
|
|
355
|
-
* @param options
|
|
353
|
+
* Finds matching documents, including soft-deleted documents.
|
|
354
|
+
* @param query Optional filter.
|
|
355
|
+
* @param options Optional query options.
|
|
356
356
|
*/
|
|
357
357
|
findWithDeleted(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
358
358
|
/**
|
|
359
|
-
*
|
|
360
|
-
* @param query
|
|
361
|
-
* @param options
|
|
359
|
+
* Finds only soft-deleted documents.
|
|
360
|
+
* @param query Optional filter.
|
|
361
|
+
* @param options Optional query options.
|
|
362
362
|
*/
|
|
363
363
|
findOnlyDeleted(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
364
364
|
/**
|
|
365
|
-
*
|
|
366
|
-
* @param query
|
|
367
|
-
* @param options
|
|
368
|
-
* @returns
|
|
365
|
+
* Finds the first matching document, including soft-deleted documents.
|
|
366
|
+
* @param query Optional filter.
|
|
367
|
+
* @param options Optional query options.
|
|
368
|
+
* @returns Matching document, or `null` when none is found.
|
|
369
369
|
*/
|
|
370
370
|
findOneWithDeleted(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
371
371
|
/**
|
|
372
|
-
*
|
|
373
|
-
* @param filter
|
|
374
|
-
* @param options
|
|
372
|
+
* Restores the first soft-deleted document matching the filter.
|
|
373
|
+
* @param filter Filter.
|
|
374
|
+
* @param options Optional update options.
|
|
375
375
|
*/
|
|
376
376
|
restore(filter?: unknown, options?: unknown): Promise<RestoreResult>;
|
|
377
377
|
/**
|
|
378
|
-
*
|
|
379
|
-
* @param filter
|
|
380
|
-
* @param options
|
|
378
|
+
* Restores all soft-deleted documents matching the filter.
|
|
379
|
+
* @param filter Filter.
|
|
380
|
+
* @param options Optional update options.
|
|
381
381
|
*/
|
|
382
382
|
restoreMany(filter?: unknown, options?: unknown): Promise<RestoreResult>;
|
|
383
383
|
/**
|
|
384
|
-
*
|
|
385
|
-
* @param filter
|
|
386
|
-
* @param options
|
|
387
|
-
* @returns
|
|
384
|
+
* Physically deletes the first matching document, bypassing soft-delete.
|
|
385
|
+
* @param filter Filter.
|
|
386
|
+
* @param options Optional delete options.
|
|
387
|
+
* @returns Standard `DeleteResult` object.
|
|
388
388
|
*/
|
|
389
389
|
forceDelete(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
390
390
|
/**
|
|
391
|
-
*
|
|
392
|
-
* @param filter
|
|
393
|
-
* @param options
|
|
394
|
-
* @returns
|
|
391
|
+
* Physically deletes all matching documents, bypassing soft-delete.
|
|
392
|
+
* @param filter Filter.
|
|
393
|
+
* @param options Optional delete options.
|
|
394
|
+
* @returns Standard `DeleteResult` object.
|
|
395
395
|
*/
|
|
396
396
|
forceDeleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
397
397
|
/**
|
|
398
|
-
*
|
|
399
|
-
* @param query
|
|
400
|
-
* @param options
|
|
401
|
-
* @returns
|
|
398
|
+
* Finds the first matching document from only the soft-deleted set.
|
|
399
|
+
* @param query Optional filter.
|
|
400
|
+
* @param options Optional query options.
|
|
401
|
+
* @returns Matching deleted document, or `null` when none is found.
|
|
402
402
|
*/
|
|
403
403
|
findOneOnlyDeleted(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
404
404
|
/**
|
|
405
|
-
*
|
|
406
|
-
* @param query
|
|
407
|
-
* @param options
|
|
405
|
+
* Counts matching documents, including soft-deleted documents.
|
|
406
|
+
* @param query Optional filter.
|
|
407
|
+
* @param options Optional count options.
|
|
408
408
|
*/
|
|
409
409
|
countWithDeleted(query?: unknown, options?: unknown): Promise<number>;
|
|
410
410
|
/**
|
|
411
|
-
*
|
|
412
|
-
* @param query
|
|
413
|
-
* @param options
|
|
411
|
+
* Counts soft-deleted documents matching the query.
|
|
412
|
+
* @param query Optional filter.
|
|
413
|
+
* @param options Optional count options.
|
|
414
414
|
*/
|
|
415
415
|
countOnlyDeleted(query?: unknown, options?: unknown): Promise<number>;
|
|
416
416
|
/**
|
|
417
|
-
*
|
|
418
|
-
* @param docs
|
|
419
|
-
* @param options
|
|
417
|
+
* Inserts a large document batch through the write queue.
|
|
418
|
+
* @param docs Documents to insert.
|
|
419
|
+
* @param options Optional batch write options.
|
|
420
420
|
*/
|
|
421
421
|
insertBatch(docs: unknown[], options?: unknown): Promise<InsertBatchResult>;
|
|
422
422
|
/**
|
|
423
|
-
*
|
|
424
|
-
* @param filter
|
|
425
|
-
* @param update
|
|
426
|
-
* @param options
|
|
423
|
+
* Batch-updates matching documents using `bulkWrite`.
|
|
424
|
+
* @param filter Filter.
|
|
425
|
+
* @param update Update operator document.
|
|
426
|
+
* @param options Optional batch write options.
|
|
427
427
|
*/
|
|
428
428
|
updateBatch(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateBatchResult>;
|
|
429
|
-
/**
|
|
429
|
+
/** Batch-deletes matching documents. */
|
|
430
430
|
deleteBatch(filter?: unknown, options?: unknown): Promise<DeleteBatchResult>;
|
|
431
431
|
/**
|
|
432
|
-
*
|
|
433
|
-
* @param keys
|
|
434
|
-
* @param options
|
|
435
|
-
* @returns
|
|
432
|
+
* Creates a single index on the collection.
|
|
433
|
+
* @param keys Index key specification.
|
|
434
|
+
* @param options Optional index options such as `unique` or `sparse`.
|
|
435
|
+
* @returns Index creation result.
|
|
436
436
|
*/
|
|
437
437
|
createIndex(keys: unknown, options?: unknown): Promise<IndexCreateResult>;
|
|
438
438
|
/**
|
|
439
|
-
*
|
|
440
|
-
* @param specs
|
|
441
|
-
* @returns
|
|
439
|
+
* Creates multiple indexes.
|
|
440
|
+
* @param specs Index specifications, each containing `key` and optional index options.
|
|
441
|
+
* @returns Names of created indexes.
|
|
442
442
|
*/
|
|
443
443
|
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
444
|
-
/**
|
|
444
|
+
/** Lists all existing index definitions on the collection. */
|
|
445
445
|
listIndexes(): Promise<Record<string, unknown>[]>;
|
|
446
446
|
/**
|
|
447
|
-
*
|
|
448
|
-
* @param name
|
|
447
|
+
* Drops the specified index by name.
|
|
448
|
+
* @param name Index name.
|
|
449
449
|
*/
|
|
450
450
|
dropIndex(name: string): Promise<unknown>;
|
|
451
|
-
/**
|
|
451
|
+
/** Drops all non-`_id` indexes on the collection. */
|
|
452
452
|
dropIndexes(): Promise<unknown>;
|
|
453
|
-
/**
|
|
453
|
+
/** Prewarms cursor pagination bookmark cache. */
|
|
454
454
|
prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise<BookmarkPrewarmResult>;
|
|
455
|
-
/**
|
|
455
|
+
/** Lists cursor pagination bookmark cache entries. */
|
|
456
456
|
listBookmarks(keyDims?: unknown): Promise<BookmarkListResult>;
|
|
457
|
-
/**
|
|
457
|
+
/** Clears cursor pagination bookmark cache entries. */
|
|
458
458
|
clearBookmarks(keyDims?: unknown): Promise<BookmarkClearResult>;
|
|
459
459
|
/**
|
|
460
|
-
*
|
|
461
|
-
* @param key
|
|
462
|
-
* @param query
|
|
463
|
-
* @param options
|
|
464
|
-
* @returns
|
|
460
|
+
* Gets distinct values for a field from matching documents.
|
|
461
|
+
* @param key Target field name.
|
|
462
|
+
* @param query Optional filter.
|
|
463
|
+
* @param options Optional driver-level options.
|
|
464
|
+
* @returns Distinct values.
|
|
465
465
|
*/
|
|
466
466
|
distinct(key: string, query?: unknown, options?: unknown): Promise<unknown[]>;
|
|
467
467
|
/**
|
|
468
|
-
*
|
|
469
|
-
* @param pipeline
|
|
470
|
-
* @param options
|
|
471
|
-
* @returns
|
|
468
|
+
* Executes an aggregation pipeline and returns result documents.
|
|
469
|
+
* @param pipeline Aggregation stages.
|
|
470
|
+
* @param options Optional aggregation options such as `allowDiskUse`.
|
|
471
|
+
* @returns Aggregation result documents.
|
|
472
472
|
*/
|
|
473
473
|
aggregate(pipeline?: unknown[], options?: unknown): Promise<unknown[]>;
|
|
474
|
-
/**
|
|
474
|
+
/** Returns a readable stream for matching query results. */
|
|
475
475
|
stream(query?: unknown, options?: unknown): NodeJS.ReadableStream;
|
|
476
|
-
/**
|
|
476
|
+
/** Returns the MongoDB query execution plan. */
|
|
477
477
|
explain(query?: unknown, options?: unknown): Promise<unknown>;
|
|
478
|
-
/**
|
|
478
|
+
/** Manually invalidates read cache for the current model collection. */
|
|
479
479
|
invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise<number>;
|
|
480
|
-
/**
|
|
480
|
+
/** Drops the collection for the current model. */
|
|
481
481
|
dropCollection(): Promise<boolean>;
|
|
482
|
-
/**
|
|
482
|
+
/** Creates the current collection or a collection with the specified name. */
|
|
483
483
|
createCollection(name?: string, options?: Record<string, unknown>): Promise<boolean>;
|
|
484
|
-
/**
|
|
484
|
+
/** Creates a MongoDB view. */
|
|
485
485
|
createView(name: string, source: string, pipeline?: unknown[]): Promise<boolean>;
|
|
486
|
-
/**
|
|
486
|
+
/** Returns index usage statistics. */
|
|
487
487
|
indexStats(): Promise<unknown[]>;
|
|
488
|
-
/**
|
|
488
|
+
/** Sets the collection JSON Schema validator. */
|
|
489
489
|
setValidator(validator: unknown, options?: { validationLevel?: string; validationAction?: string }): Promise<{ ok: number; collection: string }>;
|
|
490
|
-
/**
|
|
490
|
+
/** Sets the collection validation level. */
|
|
491
491
|
setValidationLevel(level: 'off' | 'moderate' | 'strict' | string): Promise<{ ok: number; validationLevel: string }>;
|
|
492
|
-
/**
|
|
492
|
+
/** Sets the collection validation action. */
|
|
493
493
|
setValidationAction(action: 'error' | 'warn' | string): Promise<{ ok: number; validationAction: string }>;
|
|
494
|
-
/**
|
|
494
|
+
/** Reads the collection validator and validation settings. */
|
|
495
495
|
getValidator(): Promise<{ validator: Record<string, unknown> | null; validationLevel: string; validationAction: string }>;
|
|
496
|
-
/**
|
|
496
|
+
/** Returns collection storage and index statistics. */
|
|
497
497
|
stats(options?: { scale?: number }): Promise<{ ns: string; count: number; size: number; storageSize: number; totalIndexSize: number; nindexes: number; avgObjSize?: number; scaleFactor?: number }>;
|
|
498
|
-
/**
|
|
498
|
+
/** Renames the collection for the current model. */
|
|
499
499
|
renameCollection(newName: string, options?: { dropTarget?: boolean }): Promise<{ renamed: boolean; from: string; to: string }>;
|
|
500
|
-
/**
|
|
500
|
+
/** Executes a collMod management command. */
|
|
501
501
|
collMod(modifications: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
502
|
-
/**
|
|
502
|
+
/** Converts the collection to a capped collection. */
|
|
503
503
|
convertToCapped(size: number, options?: { max?: number }): Promise<{ ok: number; collection: string; capped: boolean; size: number }>;
|
|
504
504
|
/**
|
|
505
|
-
*
|
|
506
|
-
* @param pipeline
|
|
507
|
-
* @param options
|
|
508
|
-
* @returns MongoDB
|
|
505
|
+
* Opens a ChangeStream on the collection.
|
|
506
|
+
* @param pipeline Optional aggregation filter pipeline.
|
|
507
|
+
* @param options Optional ChangeStream options.
|
|
508
|
+
* @returns Native MongoDB ChangeStream object.
|
|
509
509
|
*/
|
|
510
510
|
watch(pipeline?: unknown[], options?: unknown): import('mongodb').ChangeStream;
|
|
511
511
|
/**
|
|
512
|
-
*
|
|
513
|
-
* @param document
|
|
514
|
-
* @returns
|
|
512
|
+
* Validates document data against the model schema definition.
|
|
513
|
+
* @param document Document to validate.
|
|
514
|
+
* @returns Validation result containing the `valid` flag and error details.
|
|
515
515
|
*/
|
|
516
516
|
validate(document?: unknown): ValidationResult;
|
|
517
517
|
}
|
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
|
};
|
|
@@ -8,7 +8,7 @@ export interface SSHConfig {
|
|
|
8
8
|
/** SSH server hostname or IP. */
|
|
9
9
|
host: string;
|
|
10
10
|
/** SSH server port (default: 22). */
|
|
11
|
-
|
|
11
|
+
port?: number;
|
|
12
12
|
/** SSH login username. */
|
|
13
13
|
username: string;
|
|
14
14
|
/** SSH password (mutually exclusive with privateKey). */
|
|
@@ -41,6 +41,7 @@ import type {
|
|
|
41
41
|
CacheLike,
|
|
42
42
|
CacheLockManager,
|
|
43
43
|
DistributedCacheInvalidator,
|
|
44
|
+
DistributedCacheInvalidatorStats,
|
|
44
45
|
FunctionCache,
|
|
45
46
|
Logger,
|
|
46
47
|
MemoryCache,
|
|
@@ -65,7 +66,7 @@ import type {
|
|
|
65
66
|
import type { SagaDefinition, SagaOrchestrator, SagaResult, SagaStats } from './saga';
|
|
66
67
|
import type { SlowQueryLogConfigInput, SlowQueryLogEntry, SlowQueryLogFilter, SlowQueryLogManager, SlowQueryLogQueryOptions, SlowQueryLogRecord } from './slow-query-log';
|
|
67
68
|
import type { ChangeStreamSyncManager, SyncConfig, SyncStats } from './sync';
|
|
68
|
-
import type { Transaction, TransactionOptions } from './transaction';
|
|
69
|
+
import type { Transaction, TransactionOptions, TransactionStats } from './transaction';
|
|
69
70
|
|
|
70
71
|
export interface MonSQLizeOptions {
|
|
71
72
|
type?: 'mongodb';
|
|
@@ -107,7 +108,7 @@ export interface MonSQLizeOptions {
|
|
|
107
108
|
/**
|
|
108
109
|
* Distributed cache invalidation via Redis Pub/Sub.
|
|
109
110
|
* When configured, broadcasts `delPattern` events to all other connected instances.
|
|
110
|
-
*
|
|
111
|
+
* `ioredis` is installed with monSQLize; this block only enables and configures Redis usage.
|
|
111
112
|
* @since v2.0.0
|
|
112
113
|
*/
|
|
113
114
|
distributed?: {
|
|
@@ -131,6 +132,24 @@ export interface MonSQLizeOptions {
|
|
|
131
132
|
maxPoolsCount?: number;
|
|
132
133
|
sync?: SyncConfig;
|
|
133
134
|
slowQueryLog?: SlowQueryLogConfigInput;
|
|
135
|
+
/** Global transaction defaults and transaction statistics settings. @since v1.4.0 */
|
|
136
|
+
transaction?: {
|
|
137
|
+
enableRetry?: boolean;
|
|
138
|
+
maxRetries?: number;
|
|
139
|
+
retryDelay?: number;
|
|
140
|
+
retryBackoff?: number;
|
|
141
|
+
/** Default transaction timeout in milliseconds. Alias: `maxDuration`. */
|
|
142
|
+
defaultTimeout?: number;
|
|
143
|
+
/** Default transaction timeout in milliseconds. Alias: `defaultTimeout`. */
|
|
144
|
+
maxDuration?: number;
|
|
145
|
+
defaultReadConcern?: TransactionOptions['readConcern'];
|
|
146
|
+
defaultWriteConcern?: TransactionOptions['writeConcern'];
|
|
147
|
+
defaultReadPreference?: TransactionOptions['readPreference'];
|
|
148
|
+
lockMaxDuration?: number;
|
|
149
|
+
lockCleanupInterval?: number;
|
|
150
|
+
maxStatsSamples?: number;
|
|
151
|
+
distributedLock?: Record<string, unknown>;
|
|
152
|
+
};
|
|
134
153
|
/** Global query timeout in milliseconds applied to all find/aggregate operations. Default: 2000. @since v1.3.0 */
|
|
135
154
|
maxTimeMS?: number;
|
|
136
155
|
/** Default limit for find() when caller does not specify one. Default: 10. @since v1.3.0 */
|
|
@@ -292,8 +311,12 @@ export interface MonSQLizeInstance {
|
|
|
292
311
|
executeSaga(name: string, data: unknown): Promise<SagaResult>;
|
|
293
312
|
/** List all registered Saga names. */
|
|
294
313
|
listSagas(): string[];
|
|
314
|
+
/** Return aggregate transaction statistics; `null` before transaction capability initialization. */
|
|
315
|
+
getTransactionStats(): TransactionStats | null;
|
|
295
316
|
/** Return Saga execution statistics (success / failure / compensation counts, etc.). */
|
|
296
317
|
getSagaStats(): SagaStats;
|
|
318
|
+
/** Return distributed cache invalidator statistics; `null` when distributed invalidation is not enabled. */
|
|
319
|
+
getDistributedCacheInvalidatorStats(): DistributedCacheInvalidatorStats | null;
|
|
297
320
|
/** Start ChangeStream data synchronisation. */
|
|
298
321
|
startSync(): Promise<void>;
|
|
299
322
|
/** Stop ChangeStream data synchronisation. */
|
|
@@ -431,7 +454,9 @@ export default class MonSQLize implements MonSQLizeInstance {
|
|
|
431
454
|
defineSaga(definition: SagaDefinition): Promise<SagaDefinition>;
|
|
432
455
|
executeSaga(name: string, data: unknown): Promise<SagaResult>;
|
|
433
456
|
listSagas(): string[];
|
|
457
|
+
getTransactionStats(): TransactionStats | null;
|
|
434
458
|
getSagaStats(): SagaStats;
|
|
459
|
+
getDistributedCacheInvalidatorStats(): DistributedCacheInvalidatorStats | null;
|
|
435
460
|
startSync(): Promise<void>;
|
|
436
461
|
stopSync(): Promise<void>;
|
|
437
462
|
getSyncStats(): SyncStats | null;
|