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