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/chain.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 链式调用 API 类型定义
|
|
3
|
-
* @module types/chain
|
|
4
|
-
* @since v2.0+
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { ExplainResult } from './stream';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Collation 选项(字符串排序规则)
|
|
11
|
-
*/
|
|
12
|
-
export interface CollationOptions {
|
|
13
|
-
locale: string; // 语言代码,如 'zh', 'en'
|
|
14
|
-
strength?: number; // 比较级别:1=基本, 2=重音, 3=大小写
|
|
15
|
-
caseLevel?: boolean; // 是否区分大小写
|
|
16
|
-
caseFirst?: 'upper' | 'lower'; // 大小写优先级
|
|
17
|
-
numericOrdering?: boolean; // 数字排序
|
|
18
|
-
alternate?: 'non-ignorable' | 'shifted'; // 空格和标点处理
|
|
19
|
-
maxVariable?: 'punct' | 'space'; // 最大可变字符
|
|
20
|
-
backwards?: boolean; // 反向比较
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* FindChain - find 查询的链式调用构建器
|
|
25
|
-
*
|
|
26
|
-
* @template T - 文档类型
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* // 基础链式调用
|
|
30
|
-
* const results = await collection<Product>('products')
|
|
31
|
-
* .find({ category: 'electronics' })
|
|
32
|
-
* .limit(10)
|
|
33
|
-
* .skip(5)
|
|
34
|
-
* .sort({ price: -1 });
|
|
35
|
-
*/
|
|
36
|
-
export interface FindChain<T = any> extends PromiseLike<T[]> {
|
|
37
|
-
/**
|
|
38
|
-
* 限制返回文档数量
|
|
39
|
-
* @param n - 限制数量,必须为非负数
|
|
40
|
-
* @returns 返回自身以支持链式调用
|
|
41
|
-
* @throws {Error} 如果 n 不是非负数
|
|
42
|
-
*/
|
|
43
|
-
limit(n: number): FindChain<T>;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 跳过指定数量的文档
|
|
47
|
-
* @param n - 跳过数量,必须为非负数
|
|
48
|
-
* @returns 返回自身以支持链式调用
|
|
49
|
-
* @throws {Error} 如果 n 不是非负数
|
|
50
|
-
*/
|
|
51
|
-
skip(n: number): FindChain<T>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 设置排序规则
|
|
55
|
-
* @param spec - 排序配置,如 { price: -1, name: 1 }
|
|
56
|
-
* @returns 返回自身以支持链式调用
|
|
57
|
-
* @throws {Error} 如果 spec 不是对象或数组
|
|
58
|
-
*/
|
|
59
|
-
sort(spec: Record<string, 1 | -1> | Array<[string, 1 | -1]>): FindChain<T>;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 设置字段投影
|
|
63
|
-
* @param spec - 投影配置,如 { name: 1, price: 1 }
|
|
64
|
-
* @returns 返回带有投影类型的新链
|
|
65
|
-
* @throws {Error} 如果 spec 不是对象或数组
|
|
66
|
-
*/
|
|
67
|
-
project<K extends keyof T>(spec: Record<K, 1 | 0> | Array<K>): FindChain<Pick<T, K>>;
|
|
68
|
-
project(spec: Record<string, 1 | 0> | string[]): FindChain<Partial<T>>;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 设置索引提示(强制使用指定索引)
|
|
72
|
-
* @param spec - 索引名称或索引规格
|
|
73
|
-
* @returns 返回自身以支持链式调用
|
|
74
|
-
* @throws {Error} 如果 spec 为空
|
|
75
|
-
*/
|
|
76
|
-
hint(spec: Record<string, 1 | -1> | string): FindChain<T>;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 设置排序规则(用于字符串排序)
|
|
80
|
-
* @param spec - 排序规则配置
|
|
81
|
-
* @returns 返回自身以支持链式调用
|
|
82
|
-
* @throws {Error} 如果 spec 不是对象
|
|
83
|
-
*/
|
|
84
|
-
collation(spec: CollationOptions): FindChain<T>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 设置查询注释(用于日志追踪)
|
|
88
|
-
* @param str - 注释内容
|
|
89
|
-
* @returns 返回自身以支持链式调用
|
|
90
|
-
* @throws {Error} 如果 str 不是字符串
|
|
91
|
-
*/
|
|
92
|
-
comment(str: string): FindChain<T>;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 设置查询超时时间
|
|
96
|
-
* @param ms - 超时时间(毫秒)
|
|
97
|
-
* @returns 返回自身以支持链式调用
|
|
98
|
-
* @throws {Error} 如果 ms 不是非负数
|
|
99
|
-
*/
|
|
100
|
-
maxTimeMS(ms: number): FindChain<T>;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* 设置批处理大小
|
|
104
|
-
* @param n - 批处理大小
|
|
105
|
-
* @returns 返回自身以支持链式调用
|
|
106
|
-
* @throws {Error} 如果 n 不是非负数
|
|
107
|
-
*/
|
|
108
|
-
batchSize(n: number): FindChain<T>;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 返回查询执行计划(不执行查询)
|
|
112
|
-
* @param verbosity - 详细级别
|
|
113
|
-
* @returns 执行计划
|
|
114
|
-
*/
|
|
115
|
-
explain(verbosity?: 'queryPlanner' | 'executionStats' | 'allPlansExecution'): Promise<ExplainResult>;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 返回流式结果
|
|
119
|
-
* @returns MongoDB 游标流
|
|
120
|
-
*/
|
|
121
|
-
stream(): NodeJS.ReadableStream;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 显式转换为数组(执行查询)
|
|
125
|
-
* @returns 查询结果数组
|
|
126
|
-
* @throws {Error} 如果查询已执行
|
|
127
|
-
*/
|
|
128
|
-
toArray(): Promise<T[]>;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Promise.then 接口
|
|
132
|
-
*/
|
|
133
|
-
then<TResult1 = T[], TResult2 = never>(
|
|
134
|
-
onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null,
|
|
135
|
-
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
136
|
-
): Promise<TResult1 | TResult2>;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Promise.catch 接口
|
|
140
|
-
*/
|
|
141
|
-
catch<TResult = never>(
|
|
142
|
-
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
|
|
143
|
-
): Promise<T[] | TResult>;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Promise.finally 接口
|
|
147
|
-
*/
|
|
148
|
-
finally(onfinally?: (() => void) | null): Promise<T[]>;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* AggregateChain - aggregate 查询的链式调用构建器
|
|
153
|
-
*
|
|
154
|
-
* @template T - 文档类型
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* // 基础聚合
|
|
158
|
-
* const results = await collection<Order>('orders')
|
|
159
|
-
* .aggregate([
|
|
160
|
-
* { $match: { status: 'paid' } },
|
|
161
|
-
* { $group: { _id: '$category', total: { $sum: '$amount' } } }
|
|
162
|
-
* ])
|
|
163
|
-
* .allowDiskUse(true);
|
|
164
|
-
*/
|
|
165
|
-
export interface AggregateChain<T = any> extends PromiseLike<T[]> {
|
|
166
|
-
/**
|
|
167
|
-
* 设置索引提示(强制使用指定索引)
|
|
168
|
-
* @param spec - 索引名称或索引规格
|
|
169
|
-
* @returns 返回自身以支持链式调用
|
|
170
|
-
* @throws {Error} 如果 spec 为空
|
|
171
|
-
*/
|
|
172
|
-
hint(spec: Record<string, 1 | -1> | string): AggregateChain<T>;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 设置排序规则(用于字符串排序)
|
|
176
|
-
* @param spec - 排序规则配置
|
|
177
|
-
* @returns 返回自身以支持链式调用
|
|
178
|
-
* @throws {Error} 如果 spec 不是对象
|
|
179
|
-
*/
|
|
180
|
-
collation(spec: CollationOptions): AggregateChain<T>;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 设置查询注释(用于日志追踪)
|
|
184
|
-
* @param str - 注释内容
|
|
185
|
-
* @returns 返回自身以支持链式调用
|
|
186
|
-
* @throws {Error} 如果 str 不是字符串
|
|
187
|
-
*/
|
|
188
|
-
comment(str: string): AggregateChain<T>;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* 设置查询超时时间
|
|
192
|
-
* @param ms - 超时时间(毫秒)
|
|
193
|
-
* @returns 返回自身以支持链式调用
|
|
194
|
-
* @throws {Error} 如果 ms 不是非负数
|
|
195
|
-
*/
|
|
196
|
-
maxTimeMS(ms: number): AggregateChain<T>;
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* 允许使用磁盘进行大数据量排序/分组
|
|
200
|
-
* @param bool - 是否允许
|
|
201
|
-
* @returns 返回自身以支持链式调用
|
|
202
|
-
* @throws {Error} 如果 bool 不是布尔值
|
|
203
|
-
*/
|
|
204
|
-
allowDiskUse(bool: boolean): AggregateChain<T>;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* 设置批处理大小
|
|
208
|
-
* @param n - 批处理大小
|
|
209
|
-
* @returns 返回自身以支持链式调用
|
|
210
|
-
* @throws {Error} 如果 n 不是非负数
|
|
211
|
-
*/
|
|
212
|
-
batchSize(n: number): AggregateChain<T>;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* 返回聚合执行计划(不执行聚合)
|
|
216
|
-
* @param verbosity - 详细级别
|
|
217
|
-
* @returns 执行计划
|
|
218
|
-
*/
|
|
219
|
-
explain(verbosity?: 'queryPlanner' | 'executionStats' | 'allPlansExecution'): Promise<ExplainResult>;
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* 返回流式结果
|
|
223
|
-
* @returns MongoDB 游标流
|
|
224
|
-
*/
|
|
225
|
-
stream(): NodeJS.ReadableStream;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* 显式转换为数组(执行聚合)
|
|
229
|
-
* @returns 聚合结果数组
|
|
230
|
-
* @throws {Error} 如果查询已执行
|
|
231
|
-
*/
|
|
232
|
-
toArray(): Promise<T[]>;
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Promise.then 接口
|
|
236
|
-
*/
|
|
237
|
-
then<TResult1 = T[], TResult2 = never>(
|
|
238
|
-
onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null,
|
|
239
|
-
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
|
|
240
|
-
): Promise<TResult1 | TResult2>;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Promise.catch 接口
|
|
244
|
-
*/
|
|
245
|
-
catch<TResult = never>(
|
|
246
|
-
onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
|
|
247
|
-
): Promise<T[] | TResult>;
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Promise.finally 接口
|
|
251
|
-
*/
|
|
252
|
-
finally(onfinally?: (() => void) | null): Promise<T[]>;
|
|
253
|
-
}
|
|
254
|
-
|
package/types/collection.ts
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Collection API 相关类型定义
|
|
3
|
-
* @module types/collection
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
FindOptions,
|
|
8
|
-
CountOptions,
|
|
9
|
-
AggregateOptions,
|
|
10
|
-
DistinctOptions,
|
|
11
|
-
} from "./query";
|
|
12
|
-
import type {
|
|
13
|
-
InsertOneSimplifiedOptions,
|
|
14
|
-
InsertOneOptions,
|
|
15
|
-
InsertOneResult,
|
|
16
|
-
InsertManySimplifiedOptions,
|
|
17
|
-
InsertManyOptions,
|
|
18
|
-
InsertManyResult,
|
|
19
|
-
} from "./write";
|
|
20
|
-
import type {
|
|
21
|
-
InsertBatchOptions,
|
|
22
|
-
InsertBatchResult,
|
|
23
|
-
UpdateBatchOptions,
|
|
24
|
-
UpdateBatchResult,
|
|
25
|
-
DeleteBatchOptions,
|
|
26
|
-
DeleteBatchResult,
|
|
27
|
-
} from "./batch";
|
|
28
|
-
import type {
|
|
29
|
-
FindPageOptions,
|
|
30
|
-
PageResult,
|
|
31
|
-
ResultWithMeta,
|
|
32
|
-
MetaOptions,
|
|
33
|
-
BookmarkKeyDims,
|
|
34
|
-
PrewarmBookmarksResult,
|
|
35
|
-
ListBookmarksResult,
|
|
36
|
-
ClearBookmarksResult,
|
|
37
|
-
} from "./pagination";
|
|
38
|
-
import type { StreamOptions, ExplainOptions } from "./stream";
|
|
39
|
-
import type { FindChain, AggregateChain } from "./chain";
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 健康视图
|
|
43
|
-
*/
|
|
44
|
-
export interface HealthView {
|
|
45
|
-
status: "up" | "down";
|
|
46
|
-
connected: boolean;
|
|
47
|
-
defaults?: any;
|
|
48
|
-
cache?: any;
|
|
49
|
-
driver?: { connected: boolean };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Collection 访问器接口
|
|
54
|
-
* 提供所有 Collection 操作方法
|
|
55
|
-
*/
|
|
56
|
-
export interface CollectionAccessor<TSchema = any> {
|
|
57
|
-
/**
|
|
58
|
-
* 获取命名空间信息
|
|
59
|
-
*/
|
|
60
|
-
getNamespace(): { iid: string; type: string; db: string; collection: string };
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 删除集合
|
|
64
|
-
*/
|
|
65
|
-
dropCollection(): Promise<boolean>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 创建集合
|
|
69
|
-
*/
|
|
70
|
-
createCollection(name?: string | null, options?: any): Promise<boolean>;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 创建视图
|
|
74
|
-
*/
|
|
75
|
-
createView(
|
|
76
|
-
viewName: string,
|
|
77
|
-
source: string,
|
|
78
|
-
pipeline?: any[],
|
|
79
|
-
): Promise<boolean>;
|
|
80
|
-
|
|
81
|
-
// ============================================================================
|
|
82
|
-
// 查询方法
|
|
83
|
-
// ============================================================================
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* 查询单个文档
|
|
87
|
-
* 支持 meta 参数和泛型
|
|
88
|
-
*/
|
|
89
|
-
findOne<T = TSchema>(
|
|
90
|
-
query?: any,
|
|
91
|
-
options?: Omit<FindOptions, "meta">,
|
|
92
|
-
): Promise<T | null>;
|
|
93
|
-
findOne<T = TSchema>(
|
|
94
|
-
query: any,
|
|
95
|
-
options: FindOptions & { meta: true | MetaOptions },
|
|
96
|
-
): Promise<ResultWithMeta<T | null>>;
|
|
97
|
-
findOne<T = TSchema>(
|
|
98
|
-
query?: any,
|
|
99
|
-
options?: FindOptions,
|
|
100
|
-
): Promise<T | null | ResultWithMeta<T | null>>;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* 通过 _id 查询单个文档(便利方法)
|
|
104
|
-
* @param id - 文档的 _id(字符串会自动转换为 ObjectId)
|
|
105
|
-
* @param options - 查询选项
|
|
106
|
-
*/
|
|
107
|
-
findOneById(
|
|
108
|
-
id: string | any,
|
|
109
|
-
options?: Omit<FindOptions, "meta">,
|
|
110
|
-
): Promise<any | null>;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 批量通过 _id 查询多个文档(便利方法)
|
|
114
|
-
* @param ids - _id 数组
|
|
115
|
-
* @param options - 查询选项
|
|
116
|
-
*/
|
|
117
|
-
findByIds(
|
|
118
|
-
ids: Array<string | any>,
|
|
119
|
-
options?: {
|
|
120
|
-
projection?: Record<string, any>;
|
|
121
|
-
sort?: Record<string, 1 | -1>;
|
|
122
|
-
cache?: number;
|
|
123
|
-
maxTimeMS?: number;
|
|
124
|
-
comment?: string;
|
|
125
|
-
preserveOrder?: boolean;
|
|
126
|
-
},
|
|
127
|
-
): Promise<any[]>;
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* 查询多个文档
|
|
131
|
-
* 支持 meta 参数和链式调用
|
|
132
|
-
*/
|
|
133
|
-
find<T = TSchema>(query?: any): FindChain<T>;
|
|
134
|
-
find<T = TSchema>(
|
|
135
|
-
query: any,
|
|
136
|
-
options: FindOptions & { meta: true | MetaOptions },
|
|
137
|
-
): Promise<ResultWithMeta<T[]>>;
|
|
138
|
-
find<T = TSchema>(
|
|
139
|
-
query?: any,
|
|
140
|
-
options?: FindOptions,
|
|
141
|
-
): Promise<T[]> | FindChain<T> | ResultWithMeta<T[]>;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 计数
|
|
145
|
-
* 支持 meta 参数
|
|
146
|
-
*/
|
|
147
|
-
count(query?: any, options?: Omit<CountOptions, "meta">): Promise<number>;
|
|
148
|
-
count(
|
|
149
|
-
query: any,
|
|
150
|
-
options: CountOptions & { meta: true | MetaOptions },
|
|
151
|
-
): Promise<ResultWithMeta<number>>;
|
|
152
|
-
count(
|
|
153
|
-
query?: any,
|
|
154
|
-
options?: CountOptions,
|
|
155
|
-
): Promise<number | ResultWithMeta<number>>;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 聚合查询
|
|
159
|
-
* 支持 meta 参数和链式调用
|
|
160
|
-
*/
|
|
161
|
-
aggregate<T = TSchema>(pipeline?: any[]): AggregateChain<T>;
|
|
162
|
-
aggregate<T = TSchema>(
|
|
163
|
-
pipeline: any[],
|
|
164
|
-
options: AggregateOptions & { meta: true | MetaOptions },
|
|
165
|
-
): Promise<ResultWithMeta<T[]>>;
|
|
166
|
-
aggregate<T = TSchema>(
|
|
167
|
-
pipeline?: any[],
|
|
168
|
-
options?: AggregateOptions,
|
|
169
|
-
): Promise<T[]> | AggregateChain<T> | ResultWithMeta<T[]>;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* 去重查询
|
|
173
|
-
* 支持 meta 参数
|
|
174
|
-
*/
|
|
175
|
-
distinct<T = any>(
|
|
176
|
-
field: string,
|
|
177
|
-
query?: any,
|
|
178
|
-
options?: Omit<DistinctOptions, "meta">,
|
|
179
|
-
): Promise<T[]>;
|
|
180
|
-
distinct<T = any>(
|
|
181
|
-
field: string,
|
|
182
|
-
query: any,
|
|
183
|
-
options: DistinctOptions & { meta: true | MetaOptions },
|
|
184
|
-
): Promise<ResultWithMeta<T[]>>;
|
|
185
|
-
distinct<T = any>(
|
|
186
|
-
field: string,
|
|
187
|
-
query?: any,
|
|
188
|
-
options?: DistinctOptions,
|
|
189
|
-
): Promise<T[] | ResultWithMeta<T[]>>;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 流式查询
|
|
193
|
-
* 返回 Node.js 可读流
|
|
194
|
-
*/
|
|
195
|
-
stream(query?: any, options?: StreamOptions): NodeJS.ReadableStream;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 查询执行计划诊断
|
|
199
|
-
*/
|
|
200
|
-
explain(query?: any, options?: ExplainOptions): Promise<any>;
|
|
201
|
-
|
|
202
|
-
// ============================================================================
|
|
203
|
-
// 分页相关
|
|
204
|
-
// ============================================================================
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* 深度分页
|
|
208
|
-
*/
|
|
209
|
-
findPage<T = TSchema>(options: FindPageOptions): Promise<PageResult<T>>;
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Bookmark 维护 APIs
|
|
213
|
-
*/
|
|
214
|
-
prewarmBookmarks(
|
|
215
|
-
keyDims: BookmarkKeyDims,
|
|
216
|
-
pages: number[],
|
|
217
|
-
): Promise<PrewarmBookmarksResult>;
|
|
218
|
-
listBookmarks(keyDims?: BookmarkKeyDims): Promise<ListBookmarksResult>;
|
|
219
|
-
clearBookmarks(keyDims?: BookmarkKeyDims): Promise<ClearBookmarksResult>;
|
|
220
|
-
|
|
221
|
-
// ============================================================================
|
|
222
|
-
// 写入操作
|
|
223
|
-
// ============================================================================
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* 插入单个文档
|
|
227
|
-
* 支持简化调用和完整配置
|
|
228
|
-
*/
|
|
229
|
-
insertOne<T = TSchema>(
|
|
230
|
-
document: T,
|
|
231
|
-
options?: InsertOneSimplifiedOptions,
|
|
232
|
-
): Promise<InsertOneResult>;
|
|
233
|
-
insertOne(options: InsertOneOptions): Promise<InsertOneResult>;
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* 插入多个文档
|
|
237
|
-
* 支持简化调用和完整配置
|
|
238
|
-
*/
|
|
239
|
-
insertMany<T = TSchema>(
|
|
240
|
-
documents: T[],
|
|
241
|
-
options?: InsertManySimplifiedOptions,
|
|
242
|
-
): Promise<InsertManyResult>;
|
|
243
|
-
insertMany(options: InsertManyOptions): Promise<InsertManyResult>;
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Upsert 单个文档(存在则更新,不存在则插入)
|
|
247
|
-
* @param filter - 查询条件
|
|
248
|
-
* @param update - 更新内容
|
|
249
|
-
* @param options - 操作选项
|
|
250
|
-
*/
|
|
251
|
-
upsertOne(
|
|
252
|
-
filter: Record<string, any>,
|
|
253
|
-
update: Record<string, any>,
|
|
254
|
-
options?: {
|
|
255
|
-
maxTimeMS?: number;
|
|
256
|
-
comment?: string;
|
|
257
|
-
},
|
|
258
|
-
): Promise<{
|
|
259
|
-
acknowledged: boolean;
|
|
260
|
-
matchedCount: number;
|
|
261
|
-
modifiedCount: number;
|
|
262
|
-
upsertedId?: any;
|
|
263
|
-
upsertedCount: number;
|
|
264
|
-
}>;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* 原子递增/递减字段值(便利方法)
|
|
268
|
-
* @param filter - 查询条件
|
|
269
|
-
* @param field - 字段名或字段-增量对象
|
|
270
|
-
* @param increment - 增量(默认 1,负数为递减)
|
|
271
|
-
* @param options - 操作选项
|
|
272
|
-
*/
|
|
273
|
-
incrementOne(
|
|
274
|
-
filter: Record<string, any>,
|
|
275
|
-
field: string | Record<string, number>,
|
|
276
|
-
increment?: number,
|
|
277
|
-
options?: {
|
|
278
|
-
returnDocument?: "before" | "after";
|
|
279
|
-
projection?: Record<string, any>;
|
|
280
|
-
maxTimeMS?: number;
|
|
281
|
-
comment?: string;
|
|
282
|
-
},
|
|
283
|
-
): Promise<{
|
|
284
|
-
acknowledged: boolean;
|
|
285
|
-
matchedCount: number;
|
|
286
|
-
modifiedCount: number;
|
|
287
|
-
value: any | null;
|
|
288
|
-
}>;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* 使缓存失效
|
|
292
|
-
*/
|
|
293
|
-
invalidate(
|
|
294
|
-
op?: "find" | "findOne" | "count" | "findPage" | "aggregate" | "distinct",
|
|
295
|
-
): Promise<number>;
|
|
296
|
-
|
|
297
|
-
// ============================================================================
|
|
298
|
-
// 批量操作
|
|
299
|
-
// ============================================================================
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* 大批量插入(自动分批+重试)
|
|
303
|
-
* @since v1.0.0
|
|
304
|
-
*/
|
|
305
|
-
insertBatch<T = TSchema>(
|
|
306
|
-
documents: T[],
|
|
307
|
-
options?: InsertBatchOptions,
|
|
308
|
-
): Promise<InsertBatchResult>;
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* 批量更新文档(流式查询+分批更新)
|
|
312
|
-
* @since v1.0.0
|
|
313
|
-
*/
|
|
314
|
-
updateBatch(
|
|
315
|
-
filter: Record<string, any>,
|
|
316
|
-
update: Record<string, any>,
|
|
317
|
-
options?: UpdateBatchOptions,
|
|
318
|
-
): Promise<UpdateBatchResult>;
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* 批量删除文档(流式查询+分批删除)
|
|
322
|
-
* @since v1.0.0
|
|
323
|
-
*/
|
|
324
|
-
deleteBatch(
|
|
325
|
-
filter: Record<string, any>,
|
|
326
|
-
options?: DeleteBatchOptions,
|
|
327
|
-
): Promise<DeleteBatchResult>;
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* 查询文档并返回总数(便利方法)
|
|
331
|
-
* @since v1.0.0
|
|
332
|
-
*/
|
|
333
|
-
findAndCount<T = TSchema>(
|
|
334
|
-
filter?: Record<string, any>,
|
|
335
|
-
options?: FindOptions,
|
|
336
|
-
): Promise<{ documents: T[]; total: number }>;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Collection 类型别名(与 CollectionAccessor 等价)
|
|
341
|
-
* @since v1.0.4
|
|
342
|
-
*/
|
|
343
|
-
export type Collection<TSchema = any> = CollectionAccessor<TSchema>;
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* 数据库访问器
|
|
347
|
-
*/
|
|
348
|
-
export type DbAccessor = {
|
|
349
|
-
collection<TSchema = any>(name: string): CollectionAccessor<TSchema>;
|
|
350
|
-
db(dbName: string): {
|
|
351
|
-
collection<TSchema = any>(name: string): CollectionAccessor<TSchema>;
|
|
352
|
-
};
|
|
353
|
-
/** `db()` 的别名,语义更清晰:`app.db.use('logs')` */
|
|
354
|
-
use(dbName: string): {
|
|
355
|
-
collection<TSchema = any>(name: string): CollectionAccessor<TSchema>;
|
|
356
|
-
};
|
|
357
|
-
};
|