Skip to content

Commit 7e4cc9a

Browse files
committed
feat:补全类型
1 parent 033c08b commit 7e4cc9a

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

‎index.d.ts‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,40 @@ declare module 'monsqlize' {
338338
slowQueryTag?: { event?: string; code?: string };
339339
formatSlowQuery?: (meta: any) => any;
340340
};
341+
/**
342+
* ObjectId 自动转换配置(v1.3.0+)
343+
* 自动将字符串 _id 转换为 ObjectId
344+
* @default true(MongoDB)
345+
* @since v1.3.0
346+
*/
347+
autoConvertObjectId?: boolean | {
348+
/** 是否启用(默认 true) */
349+
enabled?: boolean;
350+
/** 排除字段列表 */
351+
excludeFields?: string[];
352+
/** 自定义字段模式 */
353+
customFieldPatterns?: string[];
354+
/** 最大转换深度(默认 10) */
355+
maxDepth?: number;
356+
/** 日志级别(默认 'warn') */
357+
logLevel?: 'info' | 'warn' | 'error';
358+
};
359+
/**
360+
* Count 队列配置(高并发控制)
361+
* 避免大量并发 count 查询压垮数据库
362+
* @default { enabled: true, concurrency: CPU核心数 }
363+
* @since v1.0.0
364+
*/
365+
countQueue?: boolean | {
366+
/** 是否启用队列(默认 true) */
367+
enabled?: boolean;
368+
/** 并发数(默认 CPU 核心数,最少 4,最多 16) */
369+
concurrency?: number;
370+
/** 最大队列长度(默认 10000) */
371+
maxQueueSize?: number;
372+
/** 超时时间(毫秒,默认 60000) */
373+
timeout?: number;
374+
};
341375
}
342376
interface FindOptions {
343377
projection?: Record<string, any> | string[];
@@ -784,6 +818,12 @@ u /**
784818
invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise<number>;
785819
}
786820

821+
/**
822+
* Collection 类型别名(与 CollectionAccessor 等价)
823+
* @since v1.0.4
824+
*/
825+
type Collection<TSchema = any> = CollectionAccessor<TSchema>;
826+
787827
type DbAccessor = {
788828
collection<TSchema = any>(name: string): CollectionAccessor<TSchema>;
789829
db(dbName: string): { collection<TSchema = any>(name: string): CollectionAccessor<TSchema> };
@@ -872,15 +912,15 @@ u /**
872912
* @returns Transaction 实例
873913
* @since v0.2.0
874914
* @example
875-
* const tx = await msq.startTransaction();
915+
* const tx = await msq.startSession();
876916
* try {
877917
* await collection('users').updateOne({...}, {...}, { session: tx.session });
878918
* await tx.commit();
879919
* } catch (error) {
880920
* await tx.abort();
881921
* }
882922
*/
883-
startTransaction(options?: TransactionOptions): Promise<Transaction>;
923+
startSession(options?: TransactionOptions): Promise<Transaction>;
884924

885925
/**
886926
* 自动管理事务生命周期(推荐)
@@ -1617,6 +1657,18 @@ u /**
16171657
* 导出 Model 类
16181658
*/
16191659
export { Model };
1660+
1661+
/**
1662+
* 导出锁错误类型
1663+
* @since v1.4.0
1664+
*/
1665+
export { LockAcquireError, LockTimeoutError };
1666+
1667+
/**
1668+
* 导出类型别名
1669+
* @since v1.0.4
1670+
*/
1671+
export type { Collection, CollectionAccessor };
16201672
}
16211673

16221674

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "monsqlize",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "A lightweight MongoDB ORM with multi-level caching, transaction support, and distributed features",
55
"main": "lib/index.js",
66
"module": "index.mjs",

0 commit comments

Comments
 (0)