monsqlize 1.3.0 → 2.0.0
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 +56 -60
- package/LICENSE +201 -21
- package/README.md +537 -1828
- package/changelogs/README.md +160 -0
- package/changelogs/v2.0.0.md +222 -0
- package/dist/cjs/index.cjs +10600 -0
- package/dist/cjs/mongodb/common/transaction-aware.cjs +10 -0
- package/dist/cjs/transaction/CacheLockManager.cjs +100 -0
- package/dist/cjs/transaction/Transaction.cjs +158 -0
- package/dist/cjs/transaction/TransactionManager.cjs +298 -0
- package/dist/esm/index.mjs +10650 -0
- package/dist/types/base.d.ts +81 -0
- package/dist/types/collection.d.ts +1031 -0
- package/dist/types/expression.d.ts +115 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/lock.d.ts +74 -0
- package/dist/types/model.d.ts +526 -0
- package/dist/types/mongodb.d.ts +49 -0
- package/dist/types/monsqlize.d.ts +491 -0
- package/dist/types/pool.d.ts +84 -0
- package/dist/types/runtime.d.ts +362 -0
- package/dist/types/saga.d.ts +143 -0
- package/dist/types/slow-query-log.d.ts +126 -0
- package/dist/types/sync.d.ts +103 -0
- package/dist/types/transaction.d.ts +132 -0
- package/package.json +67 -69
- package/index.d.ts +0 -206
- package/index.mjs +0 -52
- package/lib/cache-invalidation.js +0 -279
- package/lib/cache.js +0 -530
- package/lib/common/cursor.js +0 -59
- package/lib/common/docs-urls.js +0 -73
- package/lib/common/index-options.js +0 -223
- package/lib/common/log.js +0 -61
- package/lib/common/namespace.js +0 -22
- package/lib/common/normalize.js +0 -34
- package/lib/common/page-result.js +0 -43
- package/lib/common/runner.js +0 -57
- package/lib/common/server-features.js +0 -232
- package/lib/common/shape-builders.js +0 -27
- package/lib/common/validation.js +0 -113
- package/lib/connect.js +0 -99
- package/lib/constants.js +0 -55
- package/lib/count-queue.js +0 -188
- package/lib/distributed-cache-invalidator.js +0 -260
- package/lib/errors.js +0 -168
- package/lib/expression/cache/ExpressionCache.js +0 -114
- package/lib/expression/compiler/ExpressionCompiler.js +0 -1090
- package/lib/expression/compiler/ExpressionCompilerExtensions.js +0 -531
- package/lib/expression/detector.js +0 -84
- package/lib/expression/factory.js +0 -29
- package/lib/expression/index.js +0 -19
- package/lib/function-cache.js +0 -533
- package/lib/index.js +0 -1251
- package/lib/infrastructure/ConnectionPoolManager.js +0 -464
- package/lib/infrastructure/HealthChecker.js +0 -281
- package/lib/infrastructure/PoolConfig.js +0 -199
- package/lib/infrastructure/PoolSelector.js +0 -225
- package/lib/infrastructure/PoolStats.js +0 -244
- package/lib/infrastructure/ssh-tunnel-ssh2.js +0 -212
- package/lib/infrastructure/ssh-tunnel.js +0 -41
- package/lib/infrastructure/uri-parser.js +0 -36
- package/lib/lock/Lock.js +0 -67
- package/lib/lock/errors.js +0 -28
- package/lib/lock/index.js +0 -13
- package/lib/logger.js +0 -225
- package/lib/model/examples/test.js +0 -311
- package/lib/model/features/defaults.js +0 -161
- package/lib/model/features/populate.js +0 -568
- package/lib/model/features/relations.js +0 -120
- package/lib/model/features/soft-delete.js +0 -349
- package/lib/model/features/version.js +0 -157
- package/lib/model/features/virtuals.js +0 -219
- package/lib/model/index.js +0 -1265
- package/lib/mongodb/common/accessor-helpers.js +0 -59
- package/lib/mongodb/common/agg-pipeline.js +0 -36
- package/lib/mongodb/common/aggregation-validator.js +0 -127
- package/lib/mongodb/common/iid.js +0 -28
- package/lib/mongodb/common/lexicographic-expr.js +0 -53
- package/lib/mongodb/common/shape.js +0 -32
- package/lib/mongodb/common/sort.js +0 -39
- package/lib/mongodb/common/transaction-aware.js +0 -25
- package/lib/mongodb/connect.js +0 -234
- package/lib/mongodb/index.js +0 -639
- package/lib/mongodb/management/admin-ops.js +0 -200
- package/lib/mongodb/management/bookmark-ops.js +0 -167
- package/lib/mongodb/management/cache-ops.js +0 -50
- package/lib/mongodb/management/collection-ops.js +0 -387
- package/lib/mongodb/management/database-ops.js +0 -202
- package/lib/mongodb/management/index-ops.js +0 -475
- package/lib/mongodb/management/index.js +0 -17
- package/lib/mongodb/management/namespace.js +0 -31
- package/lib/mongodb/management/validation-ops.js +0 -268
- package/lib/mongodb/queries/aggregate.js +0 -172
- package/lib/mongodb/queries/chain.js +0 -631
- package/lib/mongodb/queries/count.js +0 -99
- package/lib/mongodb/queries/distinct.js +0 -78
- package/lib/mongodb/queries/find-and-count.js +0 -193
- package/lib/mongodb/queries/find-by-ids.js +0 -236
- package/lib/mongodb/queries/find-one-by-id.js +0 -171
- package/lib/mongodb/queries/find-one.js +0 -71
- package/lib/mongodb/queries/find-page.js +0 -618
- package/lib/mongodb/queries/find.js +0 -171
- package/lib/mongodb/queries/index.js +0 -51
- package/lib/mongodb/queries/watch.js +0 -538
- package/lib/mongodb/writes/common/batch-retry.js +0 -65
- package/lib/mongodb/writes/delete-batch.js +0 -323
- package/lib/mongodb/writes/delete-many.js +0 -181
- package/lib/mongodb/writes/delete-one.js +0 -173
- package/lib/mongodb/writes/find-one-and-delete.js +0 -203
- package/lib/mongodb/writes/find-one-and-replace.js +0 -239
- package/lib/mongodb/writes/find-one-and-update.js +0 -240
- package/lib/mongodb/writes/increment-one.js +0 -259
- package/lib/mongodb/writes/index.js +0 -46
- package/lib/mongodb/writes/insert-batch.js +0 -508
- package/lib/mongodb/writes/insert-many.js +0 -223
- package/lib/mongodb/writes/insert-one.js +0 -169
- package/lib/mongodb/writes/replace-one.js +0 -226
- package/lib/mongodb/writes/result-handler.js +0 -237
- package/lib/mongodb/writes/update-batch.js +0 -416
- package/lib/mongodb/writes/update-many.js +0 -275
- package/lib/mongodb/writes/update-one.js +0 -273
- package/lib/mongodb/writes/upsert-one.js +0 -203
- package/lib/multi-level-cache.js +0 -244
- package/lib/operators.js +0 -330
- package/lib/redis-cache-adapter.js +0 -267
- package/lib/saga/SagaContext.js +0 -67
- package/lib/saga/SagaDefinition.js +0 -32
- package/lib/saga/SagaExecutor.js +0 -201
- package/lib/saga/SagaOrchestrator.js +0 -186
- package/lib/saga/index.js +0 -11
- package/lib/slow-query-log/base-storage.js +0 -70
- package/lib/slow-query-log/batch-queue.js +0 -97
- package/lib/slow-query-log/config-manager.js +0 -196
- package/lib/slow-query-log/index.js +0 -238
- package/lib/slow-query-log/mongodb-storage.js +0 -324
- package/lib/slow-query-log/query-hash.js +0 -39
- package/lib/sync/ChangeStreamSyncManager.js +0 -405
- package/lib/sync/ResumeTokenStore.js +0 -192
- package/lib/sync/SyncConfig.js +0 -127
- package/lib/sync/SyncTarget.js +0 -240
- package/lib/sync/index.js +0 -20
- package/lib/transaction/CacheLockManager.js +0 -162
- package/lib/transaction/DistributedCacheLockManager.js +0 -475
- package/lib/transaction/Transaction.js +0 -315
- package/lib/transaction/TransactionManager.js +0 -267
- package/lib/transaction/index.js +0 -11
- package/lib/utils/objectid-converter.js +0 -632
- package/types/README.md +0 -122
- package/types/base.ts +0 -94
- package/types/batch.ts +0 -187
- package/types/cache.ts +0 -71
- package/types/chain.ts +0 -254
- package/types/collection.ts +0 -357
- package/types/expression.ts +0 -109
- package/types/function-cache.d.ts +0 -135
- package/types/lock.ts +0 -95
- package/types/model/definition.ts +0 -152
- package/types/model/index.ts +0 -10
- package/types/model/instance.ts +0 -121
- package/types/model/relations.ts +0 -121
- package/types/model/virtuals.ts +0 -32
- package/types/monsqlize.ts +0 -245
- package/types/options.ts +0 -192
- package/types/pagination.ts +0 -154
- package/types/pool.ts +0 -125
- package/types/query.ts +0 -71
- package/types/saga.ts +0 -125
- package/types/stream.ts +0 -64
- package/types/sync.ts +0 -79
- package/types/transaction.ts +0 -79
- package/types/write.ts +0 -77
package/types/pagination.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 分页系统相关类型定义
|
|
3
|
-
* @module types/pagination
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { FindOptions, MetaOptions } from './query';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Bookmark 维护 APIs 相关接口
|
|
10
|
-
*/
|
|
11
|
-
export interface BookmarkKeyDims {
|
|
12
|
-
sort?: Record<string, 1 | -1>; // 排序配置(与 findPage 一致)
|
|
13
|
-
limit?: number; // 每页数量
|
|
14
|
-
query?: object; // 查询条件(用于计算 queryShape)
|
|
15
|
-
pipeline?: object[]; // 聚合管道(用于计算 pipelineShape)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface PrewarmBookmarksResult {
|
|
19
|
-
warmed: number; // 成功预热的 bookmark 数量
|
|
20
|
-
failed: number; // 预热失败的 bookmark 数量
|
|
21
|
-
keys: string[]; // 已缓存的 bookmark 键列表
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ListBookmarksResult {
|
|
25
|
-
count: number; // bookmark 总数
|
|
26
|
-
pages: number[]; // 已缓存的页码列表(排序后)
|
|
27
|
-
keys: string[]; // 缓存键列表
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface ClearBookmarksResult {
|
|
31
|
-
cleared: number; // 清除的 bookmark 数量
|
|
32
|
-
pattern: string; // 使用的匹配模式
|
|
33
|
-
keysBefore: number; // 清除前的 bookmark 数量
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 跳页相关类型
|
|
38
|
-
*/
|
|
39
|
-
export interface JumpOptions {
|
|
40
|
-
step?: number; // 书签密度:每隔 step 页存一个书签;默认 10
|
|
41
|
-
maxHops?: number; // 单次跳页允许的"连续 after 次数(累计)"上限;默认 20
|
|
42
|
-
keyDims?: object; // 可选;未传则自动生成去敏形状
|
|
43
|
-
getBookmark?: (params: { keyDims: any; page: number }) => Promise<string | null>;
|
|
44
|
-
saveBookmark?: (params: { keyDims: any; page: number; cursor: string; ttlMs?: number }) => Promise<void>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface OffsetJumpOptions {
|
|
48
|
-
enable?: boolean; // 开启后,当 skip=(page-1)*limit ≤ maxSkip 时走 `$skip+$limit`
|
|
49
|
-
maxSkip?: number; // 默认 50_000;超过则回退到"书签跳转"逻辑
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface TotalsOptions {
|
|
53
|
-
mode?: 'none' | 'async' | 'approx' | 'sync'; // 默认 'none'
|
|
54
|
-
maxTimeMS?: number; // 用于 `countDocuments` 的超时(sync/async)
|
|
55
|
-
ttlMs?: number; // 总数缓存 TTL(async/approx),默认 10 分钟
|
|
56
|
-
hint?: any; // 计数 hint(可选)
|
|
57
|
-
collation?: any; // 计数 collation(可选,与列表一致更安全)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* 深度分页(统一版)选项
|
|
62
|
-
*/
|
|
63
|
-
export interface FindPageOptions extends FindOptions {
|
|
64
|
-
/**
|
|
65
|
-
* 附加聚合管道(在 projection 之前执行,仅对当页数据生效)
|
|
66
|
-
*/
|
|
67
|
-
pipeline?: object[];
|
|
68
|
-
after?: string;
|
|
69
|
-
before?: string;
|
|
70
|
-
limit: number;
|
|
71
|
-
allowDiskUse?: boolean;
|
|
72
|
-
/** Mongo-only: 透传 hint 到 aggregate */
|
|
73
|
-
hint?: any;
|
|
74
|
-
/** Mongo-only: 透传 collation 到 aggregate */
|
|
75
|
-
collation?: any;
|
|
76
|
-
|
|
77
|
-
// 新增:跳页相关参数
|
|
78
|
-
page?: number; // 目标页(≥1);与 after/before 互斥
|
|
79
|
-
jump?: JumpOptions; // 跳页(书签)配置
|
|
80
|
-
offsetJump?: OffsetJumpOptions; // 小范围 offset 兜底
|
|
81
|
-
totals?: TotalsOptions; // 总数/总页数配置
|
|
82
|
-
meta?: boolean | MetaOptions; // 返回耗时元信息
|
|
83
|
-
// 注:projection 继承自 FindOptions,findPage 自 v1.2.0 起正式支持。
|
|
84
|
-
// 排序字段会被自动保留以确保游标正确生成。
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 元信息
|
|
89
|
-
*/
|
|
90
|
-
export interface MetaInfo {
|
|
91
|
-
op: string;
|
|
92
|
-
ns: { iid: string; type: string; db: string; coll: string };
|
|
93
|
-
startTs: number;
|
|
94
|
-
endTs: number;
|
|
95
|
-
durationMs: number;
|
|
96
|
-
maxTimeMS?: number;
|
|
97
|
-
fromCache?: boolean;
|
|
98
|
-
cacheHit?: boolean;
|
|
99
|
-
cacheTtl?: number;
|
|
100
|
-
keyHash?: string;
|
|
101
|
-
// findPage 专用字段
|
|
102
|
-
page?: number;
|
|
103
|
-
after?: boolean;
|
|
104
|
-
before?: boolean;
|
|
105
|
-
hops?: number;
|
|
106
|
-
step?: number;
|
|
107
|
-
steps?: Array<{ phase: 'hop' | 'offset'; index?: number; durationMs: number }>; // level='sub' 时提供
|
|
108
|
-
error?: { code?: string; message: string };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 总数信息
|
|
113
|
-
*/
|
|
114
|
-
export interface TotalsInfo {
|
|
115
|
-
mode: 'async' | 'sync' | 'approx';
|
|
116
|
-
total?: number | null | undefined; // async: null(未就绪);approx: undefined(未知或近似)
|
|
117
|
-
totalPages?: number | null | undefined;
|
|
118
|
-
token?: string; // async 时返回的短标识(<keyHash>)
|
|
119
|
-
ts?: number; // 写入时间戳(毫秒),如果来自缓存
|
|
120
|
-
error?: string; // 仅 async:统计失败时可能附带的错误标识
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 页面信息
|
|
125
|
-
*/
|
|
126
|
-
export interface PageInfo {
|
|
127
|
-
hasNext: boolean;
|
|
128
|
-
hasPrev: boolean;
|
|
129
|
-
startCursor: string | null;
|
|
130
|
-
endCursor: string | null;
|
|
131
|
-
currentPage?: number; // 仅跳页/offset 模式回显目标页号(逻辑页号)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 分页结果
|
|
136
|
-
*/
|
|
137
|
-
export interface PageResult<T = any> {
|
|
138
|
-
items: T[];
|
|
139
|
-
pageInfo: PageInfo;
|
|
140
|
-
totals?: TotalsInfo; // 当启用 totals 时返回
|
|
141
|
-
meta?: MetaInfo; // 当启用 meta 时返回
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* 带 meta 的返回类型(用于 findOne/find/count)
|
|
146
|
-
*/
|
|
147
|
-
export interface ResultWithMeta<T = any> {
|
|
148
|
-
data: T;
|
|
149
|
-
meta: MetaInfo;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// 重新导出 MetaOptions,方便其他模块使用
|
|
153
|
-
export { MetaOptions };
|
|
154
|
-
|
package/types/pool.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 连接池管理相关类型定义
|
|
3
|
-
* @module types/pool
|
|
4
|
-
* @since v1.0.8
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { LoggerLike } from './base';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 连接池角色
|
|
11
|
-
* @since v1.0.8
|
|
12
|
-
*/
|
|
13
|
-
export type PoolRole = 'primary' | 'secondary' | 'analytics' | 'custom';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 连接池选择策略
|
|
17
|
-
* @since v1.0.8
|
|
18
|
-
*/
|
|
19
|
-
export type PoolStrategy = 'auto' | 'roundRobin' | 'weighted' | 'leastConnections' | 'manual';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 故障转移策略
|
|
23
|
-
* @since v1.0.8
|
|
24
|
-
*/
|
|
25
|
-
export type FallbackStrategy = 'error' | 'readonly' | 'primary';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 连接池配置
|
|
29
|
-
* @since v1.0.8
|
|
30
|
-
*/
|
|
31
|
-
export interface PoolConfig {
|
|
32
|
-
/** 连接池名称(唯一标识) */
|
|
33
|
-
name: string;
|
|
34
|
-
/** MongoDB URI */
|
|
35
|
-
uri: string;
|
|
36
|
-
/** 连接池角色 */
|
|
37
|
-
role?: PoolRole;
|
|
38
|
-
/** 权重(用于加权选择策略,默认 1) */
|
|
39
|
-
weight?: number;
|
|
40
|
-
/** 标签(用于筛选) */
|
|
41
|
-
tags?: string[];
|
|
42
|
-
/** MongoDB 连接选项 */
|
|
43
|
-
options?: {
|
|
44
|
-
maxPoolSize?: number;
|
|
45
|
-
minPoolSize?: number;
|
|
46
|
-
maxIdleTimeMS?: number;
|
|
47
|
-
waitQueueTimeoutMS?: number;
|
|
48
|
-
connectTimeoutMS?: number;
|
|
49
|
-
serverSelectionTimeoutMS?: number;
|
|
50
|
-
};
|
|
51
|
-
/** 健康检查配置 */
|
|
52
|
-
healthCheck?: {
|
|
53
|
-
enabled?: boolean;
|
|
54
|
-
interval?: number;
|
|
55
|
-
timeout?: number;
|
|
56
|
-
retries?: number;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* 连接池管理器选项
|
|
62
|
-
* @since v1.0.8
|
|
63
|
-
*/
|
|
64
|
-
export interface ConnectionPoolManagerOptions {
|
|
65
|
-
/** 连接池配置数组 */
|
|
66
|
-
pools?: PoolConfig[];
|
|
67
|
-
/** 最大连接池数量(默认 10) */
|
|
68
|
-
maxPoolsCount?: number;
|
|
69
|
-
/** 选择策略(默认 'auto') */
|
|
70
|
-
poolStrategy?: PoolStrategy;
|
|
71
|
-
/** 故障转移配置 */
|
|
72
|
-
poolFallback?: {
|
|
73
|
-
enabled?: boolean;
|
|
74
|
-
fallbackStrategy?: FallbackStrategy;
|
|
75
|
-
retryDelay?: number;
|
|
76
|
-
maxRetries?: number;
|
|
77
|
-
};
|
|
78
|
-
/** 日志记录器 */
|
|
79
|
-
logger?: LoggerLike;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 连接池健康状态
|
|
84
|
-
* @since v1.0.8
|
|
85
|
-
*/
|
|
86
|
-
export interface PoolHealthStatus {
|
|
87
|
-
status: 'up' | 'down' | 'degraded';
|
|
88
|
-
consecutiveFailures: number;
|
|
89
|
-
lastCheckTime: Date | null;
|
|
90
|
-
lastError: Error | null;
|
|
91
|
-
uptime: number;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 连接池统计信息
|
|
96
|
-
* @since v1.0.8
|
|
97
|
-
*/
|
|
98
|
-
export interface PoolStats {
|
|
99
|
-
name: string;
|
|
100
|
-
totalRequests: number;
|
|
101
|
-
successCount: number;
|
|
102
|
-
errorCount: number;
|
|
103
|
-
avgResponseTime: number;
|
|
104
|
-
minResponseTime: number;
|
|
105
|
-
maxResponseTime: number;
|
|
106
|
-
errorRate: number;
|
|
107
|
-
lastRequestTime: Date | null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 连接池管理器类
|
|
112
|
-
* @since v1.0.8
|
|
113
|
-
*/
|
|
114
|
-
export interface ConnectionPoolManager {
|
|
115
|
-
addPool(config: PoolConfig): Promise<void>;
|
|
116
|
-
removePool(name: string): Promise<void>;
|
|
117
|
-
getPool(name: string): any;
|
|
118
|
-
selectPool(operation: string, options?: { tags?: string[] }): any;
|
|
119
|
-
startHealthCheck(): void;
|
|
120
|
-
stopHealthCheck(): void;
|
|
121
|
-
getHealthStatus(): Record<string, PoolHealthStatus>;
|
|
122
|
-
getPoolStats(): Record<string, PoolStats>;
|
|
123
|
-
close(): Promise<void>;
|
|
124
|
-
}
|
|
125
|
-
|
package/types/query.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 查询选项类型定义
|
|
3
|
-
* @module types/query
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 元信息选项
|
|
8
|
-
*/
|
|
9
|
-
export interface MetaOptions {
|
|
10
|
-
level?: 'op' | 'sub'; // sub: 返回子步骤耗时(仅 findPage)
|
|
11
|
-
includeCache?: boolean; // 包含缓存相关信息
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* find 查询选项
|
|
16
|
-
*/
|
|
17
|
-
export interface FindOptions {
|
|
18
|
-
projection?: Record<string, any> | string[];
|
|
19
|
-
sort?: Record<string, 1 | -1>;
|
|
20
|
-
limit?: number;
|
|
21
|
-
skip?: number;
|
|
22
|
-
cache?: number;
|
|
23
|
-
maxTimeMS?: number;
|
|
24
|
-
/** Mongo-only: 透传 hint 到驱动 */
|
|
25
|
-
hint?: any;
|
|
26
|
-
/** Mongo-only: 透传 collation 到驱动 */
|
|
27
|
-
collation?: any;
|
|
28
|
-
/** 查询注释(用于生产环境日志跟踪)*/
|
|
29
|
-
comment?: string;
|
|
30
|
-
meta?: boolean | MetaOptions; // 返回耗时元信息
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* count 查询选项
|
|
35
|
-
*/
|
|
36
|
-
export interface CountOptions {
|
|
37
|
-
cache?: number;
|
|
38
|
-
maxTimeMS?: number;
|
|
39
|
-
/** Mongo-only: 透传 hint 到 countDocuments */
|
|
40
|
-
hint?: any;
|
|
41
|
-
/** Mongo-only: 透传 collation 到 countDocuments */
|
|
42
|
-
collation?: any;
|
|
43
|
-
/** 查询注释(用于生产环境日志跟踪)*/
|
|
44
|
-
comment?: string;
|
|
45
|
-
meta?: boolean | MetaOptions;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* aggregate 聚合查询选项
|
|
50
|
-
*/
|
|
51
|
-
export interface AggregateOptions {
|
|
52
|
-
cache?: number; // 缓存时间(毫秒),默认 0(不缓存)
|
|
53
|
-
maxTimeMS?: number; // 查询超时时间(毫秒)
|
|
54
|
-
allowDiskUse?: boolean; // 是否允许使用磁盘(默认 false)
|
|
55
|
-
collation?: any; // 排序规则(可选)
|
|
56
|
-
hint?: string | object; // 索引提示(可选)
|
|
57
|
-
comment?: string; // 查询注释(可选)
|
|
58
|
-
meta?: boolean | MetaOptions; // 返回耗时元信息
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* distinct 查询选项
|
|
63
|
-
*/
|
|
64
|
-
export interface DistinctOptions {
|
|
65
|
-
cache?: number; // 缓存时间(毫秒),默认继承实例缓存配置
|
|
66
|
-
maxTimeMS?: number; // 查询超时时间(毫秒)
|
|
67
|
-
collation?: any; // 排序规则(可选)
|
|
68
|
-
hint?: string | object; // 索引提示(可选)
|
|
69
|
-
meta?: boolean | MetaOptions; // 返回耗时元信息
|
|
70
|
-
}
|
|
71
|
-
|
package/types/saga.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Saga分布式事务相关类型定义
|
|
3
|
-
* @module types/saga
|
|
4
|
-
* @since v1.0.8
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { CacheLike } from './cache';
|
|
8
|
-
import type { LoggerLike } from './base';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Saga 步骤定义
|
|
12
|
-
* @since v1.0.8
|
|
13
|
-
*/
|
|
14
|
-
export interface SagaStep {
|
|
15
|
-
/** 步骤名称 */
|
|
16
|
-
name: string;
|
|
17
|
-
/** 执行函数 */
|
|
18
|
-
execute: (context: SagaContext) => Promise<any>;
|
|
19
|
-
/** 补偿函数(失败时执行) */
|
|
20
|
-
compensate: (context: SagaContext) => Promise<void>;
|
|
21
|
-
/** 步骤超时时间(毫秒) */
|
|
22
|
-
timeout?: number;
|
|
23
|
-
/** 重试次数(默认 0) */
|
|
24
|
-
retries?: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Saga 定义
|
|
29
|
-
* @since v1.0.8
|
|
30
|
-
*/
|
|
31
|
-
export interface SagaDefinition {
|
|
32
|
-
/** Saga 名称 */
|
|
33
|
-
name: string;
|
|
34
|
-
/** 步骤数组 */
|
|
35
|
-
steps: SagaStep[];
|
|
36
|
-
/** 超时时间(毫秒,默认 60000) */
|
|
37
|
-
timeout?: number;
|
|
38
|
-
/** 是否启用日志(默认 true) */
|
|
39
|
-
logging?: boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Saga 上下文
|
|
44
|
-
* @since v1.0.8
|
|
45
|
-
*/
|
|
46
|
-
export interface SagaContext {
|
|
47
|
-
/** Saga 执行 ID */
|
|
48
|
-
readonly executionId: string;
|
|
49
|
-
/** 输入数据 */
|
|
50
|
-
readonly data: any;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 设置上下文变量
|
|
54
|
-
* @param key 键
|
|
55
|
-
* @param value 值
|
|
56
|
-
*/
|
|
57
|
-
set(key: string, value: any): void;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 获取上下文变量
|
|
61
|
-
* @param key 键
|
|
62
|
-
*/
|
|
63
|
-
get(key: string): any;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 检查变量是否存在
|
|
67
|
-
* @param key 键
|
|
68
|
-
*/
|
|
69
|
-
has(key: string): boolean;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 获取所有上下文变量
|
|
73
|
-
*/
|
|
74
|
-
getAll(): Record<string, any>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Saga 执行结果
|
|
79
|
-
* @since v1.0.8
|
|
80
|
-
*/
|
|
81
|
-
export interface SagaResult {
|
|
82
|
-
/** 执行 ID */
|
|
83
|
-
executionId: string;
|
|
84
|
-
/** 是否成功 */
|
|
85
|
-
success: boolean;
|
|
86
|
-
/** 执行结果 */
|
|
87
|
-
result?: any;
|
|
88
|
-
/** 错误信息 */
|
|
89
|
-
error?: Error;
|
|
90
|
-
/** 已完成的步骤 */
|
|
91
|
-
completedSteps: string[];
|
|
92
|
-
/** 已补偿的步骤 */
|
|
93
|
-
compensatedSteps: string[];
|
|
94
|
-
/** 执行时长(毫秒) */
|
|
95
|
-
duration: number;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Saga 协调器选项
|
|
100
|
-
* @since v1.0.8
|
|
101
|
-
*/
|
|
102
|
-
export interface SagaOrchestratorOptions {
|
|
103
|
-
/** 缓存实例(用于分布式状态存储) */
|
|
104
|
-
cache?: CacheLike;
|
|
105
|
-
/** 日志记录器 */
|
|
106
|
-
logger?: LoggerLike;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Saga 协调器类
|
|
111
|
-
* @since v1.0.8
|
|
112
|
-
*/
|
|
113
|
-
export interface SagaOrchestrator {
|
|
114
|
-
define(definition: SagaDefinition): void;
|
|
115
|
-
execute(name: string, data: any): Promise<SagaResult>;
|
|
116
|
-
getSaga(name: string): SagaDefinition | undefined;
|
|
117
|
-
listSagas(): string[];
|
|
118
|
-
getStats(): {
|
|
119
|
-
totalExecutions: number;
|
|
120
|
-
successCount: number;
|
|
121
|
-
failureCount: number;
|
|
122
|
-
compensationCount: number;
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
package/types/stream.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 流式查询和诊断相关类型定义
|
|
3
|
-
* @module types/stream
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 流式查询选项
|
|
8
|
-
*/
|
|
9
|
-
export interface StreamOptions {
|
|
10
|
-
projection?: Record<string, any> | string[]; // 字段投影
|
|
11
|
-
sort?: Record<string, 1 | -1>; // 排序配置
|
|
12
|
-
limit?: number; // 限制返回数量
|
|
13
|
-
skip?: number; // 跳过数量
|
|
14
|
-
batchSize?: number; // 每批次大小(默认 1000)
|
|
15
|
-
maxTimeMS?: number; // 查询超时时间(毫秒)
|
|
16
|
-
hint?: any; // 索引提示
|
|
17
|
-
collation?: any; // 排序规则
|
|
18
|
-
noCursorTimeout?: boolean; // 禁用游标超时(默认 false)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Explain 选项(查询执行计划诊断)
|
|
23
|
-
*/
|
|
24
|
-
export interface ExplainOptions {
|
|
25
|
-
projection?: object; // 字段投影
|
|
26
|
-
sort?: Record<string, 1 | -1>; // 排序配置
|
|
27
|
-
limit?: number; // 限制返回数量
|
|
28
|
-
skip?: number; // 跳过数量
|
|
29
|
-
maxTimeMS?: number; // 查询超时时间(毫秒)
|
|
30
|
-
hint?: any; // 索引提示
|
|
31
|
-
collation?: any; // 排序规则
|
|
32
|
-
verbosity?: 'queryPlanner' | 'executionStats' | 'allPlansExecution'; // 详细程度(默认 'queryPlanner')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Explain 执行计划结果
|
|
37
|
-
*/
|
|
38
|
-
export interface ExplainResult {
|
|
39
|
-
queryPlanner: {
|
|
40
|
-
plannerVersion: number;
|
|
41
|
-
namespace: string;
|
|
42
|
-
indexFilterSet: boolean;
|
|
43
|
-
parsedQuery?: any;
|
|
44
|
-
winningPlan: any;
|
|
45
|
-
rejectedPlans: any[];
|
|
46
|
-
};
|
|
47
|
-
executionStats?: {
|
|
48
|
-
executionSuccess: boolean;
|
|
49
|
-
nReturned: number;
|
|
50
|
-
executionTimeMillis: number;
|
|
51
|
-
totalKeysExamined: number;
|
|
52
|
-
totalDocsExamined: number;
|
|
53
|
-
executionStages: any;
|
|
54
|
-
allPlansExecution?: any[];
|
|
55
|
-
};
|
|
56
|
-
serverInfo?: {
|
|
57
|
-
host: string;
|
|
58
|
-
port: number;
|
|
59
|
-
version: string;
|
|
60
|
-
gitVersion: string;
|
|
61
|
-
};
|
|
62
|
-
ok: number;
|
|
63
|
-
}
|
|
64
|
-
|
package/types/sync.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Change Stream数据同步相关类型定义
|
|
3
|
-
* @module types/sync
|
|
4
|
-
* @since v1.0.8
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 同步目标配置
|
|
9
|
-
* @since v1.0.8
|
|
10
|
-
*/
|
|
11
|
-
export interface SyncTarget {
|
|
12
|
-
/** 目标名称 */
|
|
13
|
-
name: string;
|
|
14
|
-
/** MongoDB URI */
|
|
15
|
-
uri: string;
|
|
16
|
-
/** 要同步的集合(['*'] 表示全部) */
|
|
17
|
-
collections?: string[];
|
|
18
|
-
/** 健康检查配置 */
|
|
19
|
-
healthCheck?: {
|
|
20
|
-
enabled?: boolean;
|
|
21
|
-
interval?: number;
|
|
22
|
-
timeout?: number;
|
|
23
|
-
retries?: number;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Resume Token 配置
|
|
29
|
-
* @since v1.0.8
|
|
30
|
-
*/
|
|
31
|
-
export interface ResumeTokenConfig {
|
|
32
|
-
/** 存储类型('file' | 'redis') */
|
|
33
|
-
storage?: 'file' | 'redis';
|
|
34
|
-
/** 文件路径(storage='file' 时使用) */
|
|
35
|
-
path?: string;
|
|
36
|
-
/** Redis 实例(storage='redis' 时使用) */
|
|
37
|
-
redis?: any;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Change Stream 同步配置
|
|
42
|
-
* @since v1.0.8
|
|
43
|
-
*/
|
|
44
|
-
export interface SyncConfig {
|
|
45
|
-
/** 是否启用同步 */
|
|
46
|
-
enabled: boolean;
|
|
47
|
-
/** 备份目标数组 */
|
|
48
|
-
targets: SyncTarget[];
|
|
49
|
-
/** 要监听的集合(可选,默认全部) */
|
|
50
|
-
collections?: string[];
|
|
51
|
-
/** Resume Token 配置 */
|
|
52
|
-
resumeToken?: ResumeTokenConfig;
|
|
53
|
-
/** 事件过滤函数 */
|
|
54
|
-
filter?: (event: any) => boolean;
|
|
55
|
-
/** 数据转换函数 */
|
|
56
|
-
transform?: (document: any) => any;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Change Stream 同步统计
|
|
61
|
-
* @since v1.0.8
|
|
62
|
-
*/
|
|
63
|
-
export interface SyncStats {
|
|
64
|
-
isRunning: boolean;
|
|
65
|
-
eventCount: number;
|
|
66
|
-
syncedCount: number;
|
|
67
|
-
errorCount: number;
|
|
68
|
-
startTime: Date | null;
|
|
69
|
-
lastEventTime: Date | null;
|
|
70
|
-
targets: Array<{
|
|
71
|
-
name: string;
|
|
72
|
-
syncCount: number;
|
|
73
|
-
errorCount: number;
|
|
74
|
-
lastSyncTime: Date | null;
|
|
75
|
-
lastError: Error | null;
|
|
76
|
-
successRate: string;
|
|
77
|
-
}>;
|
|
78
|
-
}
|
|
79
|
-
|
package/types/transaction.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 事务相关类型定义
|
|
3
|
-
* @module types/transaction
|
|
4
|
-
* @since v0.2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* MongoDB 事务会话(原生 ClientSession)
|
|
9
|
-
* @since v0.2.0
|
|
10
|
-
*/
|
|
11
|
-
export interface MongoSession {
|
|
12
|
-
/** 会话 ID */
|
|
13
|
-
id: any;
|
|
14
|
-
/** 是否在事务中 */
|
|
15
|
-
inTransaction(): boolean;
|
|
16
|
-
/** 事务状态 */
|
|
17
|
-
transaction?: {
|
|
18
|
-
state: string;
|
|
19
|
-
};
|
|
20
|
-
/** 结束会话 */
|
|
21
|
-
endSession(): void;
|
|
22
|
-
/** 其他 MongoDB 原生方法 */
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Transaction 事务类
|
|
28
|
-
* 封装 MongoDB 原生会话,提供事务生命周期管理
|
|
29
|
-
* @since v0.2.0
|
|
30
|
-
*/
|
|
31
|
-
export interface Transaction {
|
|
32
|
-
/** 事务唯一 ID */
|
|
33
|
-
readonly id: string;
|
|
34
|
-
|
|
35
|
-
/** MongoDB 原生会话对象(传递给查询方法) */
|
|
36
|
-
readonly session: MongoSession;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 启动事务
|
|
40
|
-
* @returns Promise<void>
|
|
41
|
-
*/
|
|
42
|
-
start(): Promise<void>;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 提交事务
|
|
46
|
-
* @returns Promise<void>
|
|
47
|
-
*/
|
|
48
|
-
commit(): Promise<void>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 中止(回滚)事务
|
|
52
|
-
* @returns Promise<void>
|
|
53
|
-
*/
|
|
54
|
-
abort(): Promise<void>;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 结束会话(清理资源)
|
|
58
|
-
* @returns Promise<void>
|
|
59
|
-
*/
|
|
60
|
-
end(): Promise<void>;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 获取事务执行时长(毫秒)
|
|
64
|
-
* @returns number
|
|
65
|
-
*/
|
|
66
|
-
getDuration(): number;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 获取事务信息
|
|
70
|
-
* @returns 事务状态信息
|
|
71
|
-
*/
|
|
72
|
-
getInfo(): {
|
|
73
|
-
id: string;
|
|
74
|
-
status: 'pending' | 'started' | 'committed' | 'aborted';
|
|
75
|
-
duration: number;
|
|
76
|
-
sessionId: string;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|