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.
@@ -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 (sync/async modes, ms) */
103
+ /** Timeout for countDocuments / estimatedDocumentCount (ms) */
102
104
  maxTimeMS?: number;
103
- /** Cache TTL for totals (async/approx modes, ms; default 10 min) */
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;
@@ -108,9 +108,9 @@ export interface ModelDefinitionOptions {
108
108
  }
109
109
 
110
110
  export interface ModelDefinition<TDocument = Record<string, unknown>> {
111
- /** 实际 MongoDB 集合名;不填时依次回退到 `name` `Model.define()` 的注册名。 */
111
+ /** Actual MongoDB collection name; falls back to `name` and then the `Model.define()` registration name. */
112
112
  collection?: string;
113
- /** Model 自动加载文件中的兼容集合名;`collection` 优先级更高。 */
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
- /** 返回当前模型的命名空间元数据,包含实例 ID、类型、数据库和集合名称。 */
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
- /** 返回底层原生 MongoDB Collection 对象,用于执行框架未封装的原始操作。 */
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 可选的查询选项(projectionsortlimit 等)。
199
- * @returns 文档数组,支持链式 `.populate()` 调用。
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 匹配的文档,未找到时返回 `null`。
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
- * 按主键 ID 查询单条文档(`findOne` ID 快捷方式)。
211
- * @param id 文档主键值。
212
- * @param options 可选的查询选项。
213
- * @returns 匹配的文档,未找到时返回 `null`。
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
- * 按主键 ID 查询单条文档(`findOneById` 的别名)。
218
- * @param id 文档主键值。
219
- * @param options 可选的查询选项。
220
- * @returns 匹配的文档,未找到时返回 `null`。
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
- * 按多个主键 ID 批量查询文档。
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 分页选项,包含 `limit`、`cursor`/`page`、`filter`、`sort` 等字段。
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 包含插入 ID 的结果对象。
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 更新操作符文档(如 `$set`、`$inc`)。
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 可选的选项(如 `returnDocument: 'after'`)。
303
- * @returns 更新后的文档,未找到时返回 `null`。
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 替换后的文档,未找到时返回 `null`。
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 被删除的文档,未找到时返回 `null`。
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
- * 若文档存在则更新,否则插入(upsert 语义)。
323
- * @param filter 过滤条件。
324
- * @param update 更新操作符文档。
325
- * @param options 可选的更新选项。
326
- * @returns 标准 `UpdateResult` 对象。
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 增量值(`field` 为字符串时使用)。
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 标准 `DeleteResult` 对象。
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 标准 `DeleteResult` 对象。
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 匹配的文档,未找到时返回 `null`。
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 标准 `DeleteResult` 对象。
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 标准 `DeleteResult` 对象。
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 匹配的已删除文档,未找到时返回 `null`。
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
- * 批量更新符合条件的文档(底层使用 `bulkWrite`)。
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 可选的索引选项(如 `unique`、`sparse`)。
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 索引规范数组,每项包含 `key` 及可选的索引选项。
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
- /** 删除集合上的所有非 `_id` 索引。 */
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 可选的聚合选项(如 `allowDiskUse`)。
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
- /** 返回 MongoDB 查询执行计划。 */
476
+ /** Returns the MongoDB query execution plan. */
477
477
  explain(query?: unknown, options?: unknown): Promise<unknown>;
478
- /** 手动失效当前 Model 对应集合的读缓存。 */
478
+ /** Manually invalidates read cache for the current model collection. */
479
479
  invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise<number>;
480
- /** 删除当前 Model 对应集合。 */
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
- /** 创建 MongoDB view */
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
- /** 设置集合 JSON Schema validator */
488
+ /** Sets the collection JSON Schema validator. */
489
489
  setValidator(validator: unknown, options?: { validationLevel?: string; validationAction?: string }): Promise<{ ok: number; collection: string }>;
490
- /** 设置集合 validation level */
490
+ /** Sets the collection validation level. */
491
491
  setValidationLevel(level: 'off' | 'moderate' | 'strict' | string): Promise<{ ok: number; validationLevel: string }>;
492
- /** 设置集合 validation action */
492
+ /** Sets the collection validation action. */
493
493
  setValidationAction(action: 'error' | 'warn' | string): Promise<{ ok: number; validationAction: string }>;
494
- /** 读取集合 validator 与校验设置。 */
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
- /** 重命名当前 Model 对应集合。 */
498
+ /** Renames the collection for the current model. */
499
499
  renameCollection(newName: string, options?: { dropTarget?: boolean }): Promise<{ renamed: boolean; from: string; to: string }>;
500
- /** 执行 collMod 管理命令。 */
500
+ /** Executes a collMod management command. */
501
501
  collMod(modifications: Record<string, unknown>): Promise<Record<string, unknown>>;
502
- /** 将集合转换为 capped collection */
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
- * 打开集合的 ChangeStream 以监听实时变更事件。
506
- * @param pipeline 可选的聚合过滤管道。
507
- * @param options 可选的 ChangeStream 选项。
508
- * @returns MongoDB 原生 ChangeStream 对象。
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
- * 根据模型 schema 定义验证文档数据的合法性。
513
- * @param document 要验证的文档对象。
514
- * @returns 包含 `valid` 标志和错误详情的验证结果对象。
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
  }
@@ -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?: { port?: number; dbName?: string; storageEngine?: string; replSet?: string };
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
- scopedCollection<TSchema = unknown>(name: string, options?: { database?: string; pool?: string; }): Collection<TSchema>;
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
- * Requires `ioredis` to be installed separately.
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;