monsqlize 2.0.0 → 2.0.2
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 +461 -458
- package/README.md +7 -2
- package/changelogs/README.md +141 -138
- package/changelogs/v2.0.0.md +164 -164
- package/changelogs/v2.0.1.md +39 -0
- package/changelogs/v2.0.2.md +22 -0
- package/dist/cjs/index.cjs +329 -141
- package/dist/esm/index.mjs +329 -141
- package/dist/types/base.d.ts +81 -81
- package/dist/types/collection.d.ts +973 -973
- package/dist/types/expression.d.ts +115 -115
- package/dist/types/index.d.ts +23 -23
- package/dist/types/model.d.ts +489 -485
- package/dist/types/mongodb.d.ts +49 -49
- package/dist/types/monsqlize.d.ts +429 -429
- package/dist/types/pool.d.ts +84 -84
- package/dist/types/runtime.d.ts +315 -315
- package/dist/types/saga.d.ts +121 -121
- package/dist/types/slow-query-log.d.ts +126 -126
- package/dist/types/sync.d.ts +103 -103
- package/package.json +101 -99
package/dist/types/model.d.ts
CHANGED
|
@@ -1,156 +1,160 @@
|
|
|
1
1
|
import type { BookmarkClearResult, BookmarkListResult, BookmarkPrewarmResult, DeleteBatchResult, DeleteResult, IncrementOneResult, IndexCreateResult, InsertBatchResult, InsertManyResult, InsertOneResult, UpdateBatchResult, UpdateResult } from './collection';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Schema DSL transformer function.
|
|
5
|
-
* Receives a raw DSL descriptor and returns a transformed schema object.
|
|
6
|
-
* @since v1.0.0
|
|
7
|
-
*/
|
|
8
|
-
export type SchemaDSL = (dsl: unknown) => unknown;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Default value for a model field — either a static value or a factory function.
|
|
12
|
-
* @template T Field value type
|
|
13
|
-
* @since v1.0.0
|
|
14
|
-
*/
|
|
15
|
-
export type DefaultValue<T = unknown> = T | ((context?: unknown, doc?: unknown) => T);
|
|
16
|
-
|
|
17
|
-
export interface ValidationResult {
|
|
18
|
-
valid: boolean;
|
|
19
|
-
errors?: Array<{
|
|
20
|
-
field: string;
|
|
21
|
-
message: string;
|
|
22
|
-
value?: unknown;
|
|
23
|
-
}>;
|
|
24
|
-
data?: unknown;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface HookContext {
|
|
28
|
-
operation: string;
|
|
29
|
-
collection: string;
|
|
30
|
-
data?: unknown;
|
|
31
|
-
filter?: unknown;
|
|
32
|
-
update?: unknown;
|
|
33
|
-
result?: unknown;
|
|
34
|
-
error?: Error;
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ModelConnection {
|
|
39
|
-
pool?: string;
|
|
40
|
-
database?: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface RelationConfig {
|
|
44
|
-
from: string;
|
|
45
|
-
localField: string;
|
|
46
|
-
foreignField: string;
|
|
47
|
-
single?: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface PopulateConfig {
|
|
51
|
-
path: string;
|
|
52
|
-
select?: string | string[];
|
|
53
|
-
match?: Record<string, unknown>;
|
|
54
|
-
sort?: Record<string, 1 | -1>;
|
|
55
|
-
limit?: number;
|
|
56
|
-
skip?: number;
|
|
57
|
-
populate?: string | PopulateConfig | Array<string | PopulateConfig>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface VirtualConfig {
|
|
61
|
-
get: (this: Record<string, unknown>) => unknown;
|
|
62
|
-
set?: (this: Record<string, unknown>, value: unknown) => void;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** v1 hooks factory format */
|
|
66
|
-
export type V1HooksFactory<TDocument = Record<string, unknown>> = (
|
|
67
|
-
model: ModelInstance<TDocument>,
|
|
68
|
-
) => {
|
|
69
|
-
find?: {
|
|
70
|
-
before?: (ctx: Record<string, unknown>, ...args: unknown[]) => unknown;
|
|
71
|
-
after?: (ctx: Record<string, unknown>, result: unknown) => unknown;
|
|
72
|
-
};
|
|
73
|
-
insert?: {
|
|
74
|
-
before?: (ctx: Record<string, unknown>, ...args: unknown[]) => unknown;
|
|
75
|
-
after?: (ctx: Record<string, unknown>, result: unknown) => unknown;
|
|
76
|
-
};
|
|
77
|
-
update?: {
|
|
78
|
-
before?: (ctx: Record<string, unknown>, ...args: unknown[]) => unknown;
|
|
79
|
-
after?: (ctx: Record<string, unknown>, result: unknown) => unknown;
|
|
80
|
-
};
|
|
81
|
-
delete?: {
|
|
82
|
-
before?: (ctx: Record<string, unknown>, ...args: unknown[]) => unknown;
|
|
83
|
-
after?: (ctx: Record<string, unknown>, result: unknown) => unknown;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/** v1 methods factory format */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Schema DSL transformer function.
|
|
5
|
+
* Receives a raw DSL descriptor and returns a transformed schema object.
|
|
6
|
+
* @since v1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export type SchemaDSL = (dsl: unknown) => unknown;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Default value for a model field — either a static value or a factory function.
|
|
12
|
+
* @template T Field value type
|
|
13
|
+
* @since v1.0.0
|
|
14
|
+
*/
|
|
15
|
+
export type DefaultValue<T = unknown> = T | ((context?: unknown, doc?: unknown) => T);
|
|
16
|
+
|
|
17
|
+
export interface ValidationResult {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
errors?: Array<{
|
|
20
|
+
field: string;
|
|
21
|
+
message: string;
|
|
22
|
+
value?: unknown;
|
|
23
|
+
}>;
|
|
24
|
+
data?: unknown;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface HookContext {
|
|
28
|
+
operation: string;
|
|
29
|
+
collection: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
filter?: unknown;
|
|
32
|
+
update?: unknown;
|
|
33
|
+
result?: unknown;
|
|
34
|
+
error?: Error;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ModelConnection {
|
|
39
|
+
pool?: string;
|
|
40
|
+
database?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface RelationConfig {
|
|
44
|
+
from: string;
|
|
45
|
+
localField: string;
|
|
46
|
+
foreignField: string;
|
|
47
|
+
single?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface PopulateConfig {
|
|
51
|
+
path: string;
|
|
52
|
+
select?: string | string[];
|
|
53
|
+
match?: Record<string, unknown>;
|
|
54
|
+
sort?: Record<string, 1 | -1>;
|
|
55
|
+
limit?: number;
|
|
56
|
+
skip?: number;
|
|
57
|
+
populate?: string | PopulateConfig | Array<string | PopulateConfig>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface VirtualConfig {
|
|
61
|
+
get: (this: Record<string, unknown>) => unknown;
|
|
62
|
+
set?: (this: Record<string, unknown>, value: unknown) => void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** v1 hooks factory format */
|
|
66
|
+
export type V1HooksFactory<TDocument = Record<string, unknown>> = (
|
|
67
|
+
model: ModelInstance<TDocument>,
|
|
68
|
+
) => {
|
|
69
|
+
find?: {
|
|
70
|
+
before?: (ctx: Record<string, unknown>, ...args: unknown[]) => unknown;
|
|
71
|
+
after?: (ctx: Record<string, unknown>, result: unknown) => unknown;
|
|
72
|
+
};
|
|
73
|
+
insert?: {
|
|
74
|
+
before?: (ctx: Record<string, unknown>, ...args: unknown[]) => unknown;
|
|
75
|
+
after?: (ctx: Record<string, unknown>, result: unknown) => unknown;
|
|
76
|
+
};
|
|
77
|
+
update?: {
|
|
78
|
+
before?: (ctx: Record<string, unknown>, ...args: unknown[]) => unknown;
|
|
79
|
+
after?: (ctx: Record<string, unknown>, result: unknown) => unknown;
|
|
80
|
+
};
|
|
81
|
+
delete?: {
|
|
82
|
+
before?: (ctx: Record<string, unknown>, ...args: unknown[]) => unknown;
|
|
83
|
+
after?: (ctx: Record<string, unknown>, result: unknown) => unknown;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** v1 methods factory format */
|
|
88
88
|
export type V1MethodsFactory<TDocument = Record<string, unknown>> = (
|
|
89
|
-
model: ModelInstance<TDocument>,
|
|
90
|
-
) => {
|
|
91
|
-
instance?: Record<string, (this: TDocument & Record<string, unknown>, ...args: unknown[]) => unknown>;
|
|
92
|
-
static?: Record<string, (...args: unknown[]) => unknown>;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export interface ModelDefinitionOptions {
|
|
96
|
-
timestamps?: boolean | { createdAt?: string | boolean; updatedAt?: string | boolean };
|
|
97
|
-
validate?: boolean;
|
|
98
|
-
softDelete?: boolean | {
|
|
99
|
-
enabled?: boolean;
|
|
100
|
-
field?: string;
|
|
101
|
-
type?: string;
|
|
102
|
-
ttl?: number | null;
|
|
103
|
-
};
|
|
104
|
-
version?: boolean | {
|
|
105
|
-
enabled?: boolean;
|
|
106
|
-
field?: string;
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface ModelDefinition<TDocument = Record<string, unknown>> {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
89
|
+
model: ModelInstance<TDocument>,
|
|
90
|
+
) => {
|
|
91
|
+
instance?: Record<string, (this: TDocument & Record<string, unknown>, ...args: unknown[]) => unknown>;
|
|
92
|
+
static?: Record<string, (...args: unknown[]) => unknown>;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export interface ModelDefinitionOptions {
|
|
96
|
+
timestamps?: boolean | { createdAt?: string | boolean; updatedAt?: string | boolean };
|
|
97
|
+
validate?: boolean;
|
|
98
|
+
softDelete?: boolean | {
|
|
99
|
+
enabled?: boolean;
|
|
100
|
+
field?: string;
|
|
101
|
+
type?: string;
|
|
102
|
+
ttl?: number | null;
|
|
103
|
+
};
|
|
104
|
+
version?: boolean | {
|
|
105
|
+
enabled?: boolean;
|
|
106
|
+
field?: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ModelDefinition<TDocument = Record<string, unknown>> {
|
|
111
|
+
/** 实际 MongoDB 集合名;不填时依次回退到 `name` 与 `Model.define()` 的注册名。 */
|
|
112
|
+
collection?: string;
|
|
113
|
+
/** Model 自动加载文件中的兼容集合名;`collection` 优先级更高。 */
|
|
114
|
+
name?: string;
|
|
115
|
+
enums?: Record<string, string>;
|
|
116
|
+
schema?: ((dsl: unknown) => unknown) | Record<string, unknown>;
|
|
117
|
+
defaults?: Record<string, unknown | ((context?: unknown, doc?: TDocument) => unknown)>;
|
|
118
|
+
hooks?:
|
|
119
|
+
| {
|
|
120
|
+
beforeCreate?: (context: HookContext) => Promise<void> | void;
|
|
121
|
+
afterCreate?: (context: HookContext) => Promise<void> | void;
|
|
122
|
+
beforeInsert?: (context: HookContext) => Promise<void> | void;
|
|
123
|
+
afterInsert?: (context: HookContext) => Promise<void> | void;
|
|
124
|
+
beforeUpdate?: (context: HookContext) => Promise<void> | void;
|
|
125
|
+
afterUpdate?: (context: HookContext) => Promise<void> | void;
|
|
126
|
+
beforeDelete?: (context: HookContext) => Promise<void> | void;
|
|
127
|
+
afterDelete?: (context: HookContext) => Promise<void> | void;
|
|
128
|
+
beforeFind?: (context: HookContext) => Promise<void> | void;
|
|
129
|
+
afterFind?: (context: HookContext) => Promise<void> | void;
|
|
130
|
+
}
|
|
131
|
+
| V1HooksFactory<TDocument>;
|
|
132
|
+
methods?:
|
|
133
|
+
| Record<string, (this: TDocument & Record<string, unknown>, ...args: unknown[]) => unknown>
|
|
134
|
+
| V1MethodsFactory<TDocument>;
|
|
135
|
+
statics?: Record<string, (...args: unknown[]) => unknown>;
|
|
136
|
+
relations?: Record<string, RelationConfig>;
|
|
137
|
+
virtuals?: Record<string, VirtualConfig>;
|
|
138
|
+
connection?: ModelConnection;
|
|
139
|
+
indexes?: Array<{ key: unknown } & Record<string, unknown>>;
|
|
140
|
+
options?: ModelDefinitionOptions;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface RegisteredModel<TDocument = Record<string, unknown>> {
|
|
144
|
+
collectionName: string;
|
|
145
|
+
definition: ModelDefinition<TDocument>;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface ModelScopeOptions {
|
|
149
|
+
database?: string;
|
|
150
|
+
pool?: string;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface PopulateProxy<T = unknown> extends Promise<T> {
|
|
154
|
+
populate(path: string | PopulateConfig | Array<string | PopulateConfig>, options?: Partial<Omit<PopulateConfig, 'path'>>): PopulateProxy<T>;
|
|
155
|
+
exec(): Promise<T>;
|
|
156
|
+
}
|
|
157
|
+
|
|
154
158
|
type LegacyModelPageInfo<TDocument = any> = unknown extends TDocument ? any : {
|
|
155
159
|
hasNext: boolean;
|
|
156
160
|
hasPrev: boolean;
|
|
@@ -168,66 +172,66 @@ export type RestoreResult = Pick<UpdateResult, 'modifiedCount'> & Partial<Update
|
|
|
168
172
|
|
|
169
173
|
export type ModelDocument<TDocument = any> = TDocument & Record<string, unknown> & {
|
|
170
174
|
save(): Promise<ModelDocument<TDocument>>;
|
|
171
|
-
remove(): Promise<boolean>;
|
|
172
|
-
validate(): Promise<ValidationResult>;
|
|
173
|
-
populate(path: string | PopulateConfig | Array<string | PopulateConfig>): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
174
|
-
toObject(): TDocument & Record<string, unknown>;
|
|
175
|
-
toJSON(): TDocument & Record<string, unknown>;
|
|
176
|
-
};
|
|
177
|
-
|
|
175
|
+
remove(): Promise<boolean>;
|
|
176
|
+
validate(): Promise<ValidationResult>;
|
|
177
|
+
populate(path: string | PopulateConfig | Array<string | PopulateConfig>): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
178
|
+
toObject(): TDocument & Record<string, unknown>;
|
|
179
|
+
toJSON(): TDocument & Record<string, unknown>;
|
|
180
|
+
};
|
|
181
|
+
|
|
178
182
|
export interface ModelInstance<TDocument = any> {
|
|
179
|
-
readonly collectionName: string;
|
|
180
|
-
readonly dbName: string;
|
|
181
|
-
readonly poolName?: string;
|
|
182
|
-
readonly definition: ModelDefinition<TDocument>;
|
|
183
|
-
/** 返回当前模型的命名空间元数据,包含实例 ID、类型、数据库和集合名称。 */
|
|
184
|
-
getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; };
|
|
185
|
-
/** 返回当前模型声明的关系配置映射。 */
|
|
186
|
-
getRelations(): Record<string, RelationConfig>;
|
|
187
|
-
/** 返回当前模型声明的枚举字段值映射。 */
|
|
188
|
-
getEnums(): Record<string, string>;
|
|
189
|
-
/** 返回底层原生 MongoDB Collection 对象,用于执行框架未封装的原始操作。 */
|
|
190
|
-
raw(): unknown;
|
|
191
|
-
/**
|
|
192
|
-
* 查询符合条件的文档列表。
|
|
193
|
-
* @param query 可选的过滤条件。
|
|
194
|
-
* @param options 可选的查询选项(projection、sort、limit 等)。
|
|
195
|
-
* @returns 文档数组,支持链式 `.populate()` 调用。
|
|
196
|
-
*/
|
|
197
|
-
find(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
198
|
-
/**
|
|
199
|
-
* 查询第一条符合条件的文档。
|
|
200
|
-
* @param query 可选的过滤条件。
|
|
201
|
-
* @param options 可选的查询选项。
|
|
202
|
-
* @returns 匹配的文档,未找到时返回 `null`。
|
|
203
|
-
*/
|
|
204
|
-
findOne(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
205
|
-
/**
|
|
206
|
-
* 按主键 ID 查询单条文档(`findOne` 的 ID 快捷方式)。
|
|
207
|
-
* @param id 文档主键值。
|
|
208
|
-
* @param options 可选的查询选项。
|
|
209
|
-
* @returns 匹配的文档,未找到时返回 `null`。
|
|
210
|
-
*/
|
|
211
|
-
findOneById(id: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
212
|
-
/**
|
|
213
|
-
* 按主键 ID 查询单条文档(`findOneById` 的别名)。
|
|
214
|
-
* @param id 文档主键值。
|
|
215
|
-
* @param options 可选的查询选项。
|
|
216
|
-
* @returns 匹配的文档,未找到时返回 `null`。
|
|
217
|
-
*/
|
|
218
|
-
findById(id: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
219
|
-
/**
|
|
220
|
-
* 按多个主键 ID 批量查询文档。
|
|
221
|
-
* @param ids 主键值数组。
|
|
222
|
-
* @param options 可选的查询选项。
|
|
223
|
-
* @returns 匹配的文档数组。
|
|
224
|
-
*/
|
|
225
|
-
findByIds(ids: unknown[], options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
226
|
-
/**
|
|
227
|
-
* 分页查询文档,支持基于游标或页码两种分页模式。
|
|
228
|
-
* @param options 分页选项,包含 `limit`、`cursor`/`page`、`filter`、`sort` 等字段。
|
|
229
|
-
* @returns 包含文档列表、分页信息及可选汇总数据的结果对象。
|
|
230
|
-
*/
|
|
183
|
+
readonly collectionName: string;
|
|
184
|
+
readonly dbName: string;
|
|
185
|
+
readonly poolName?: string;
|
|
186
|
+
readonly definition: ModelDefinition<TDocument>;
|
|
187
|
+
/** 返回当前模型的命名空间元数据,包含实例 ID、类型、数据库和集合名称。 */
|
|
188
|
+
getNamespace(): { iid: string; type: 'mongodb'; db: string; collection: string; };
|
|
189
|
+
/** 返回当前模型声明的关系配置映射。 */
|
|
190
|
+
getRelations(): Record<string, RelationConfig>;
|
|
191
|
+
/** 返回当前模型声明的枚举字段值映射。 */
|
|
192
|
+
getEnums(): Record<string, string>;
|
|
193
|
+
/** 返回底层原生 MongoDB Collection 对象,用于执行框架未封装的原始操作。 */
|
|
194
|
+
raw(): unknown;
|
|
195
|
+
/**
|
|
196
|
+
* 查询符合条件的文档列表。
|
|
197
|
+
* @param query 可选的过滤条件。
|
|
198
|
+
* @param options 可选的查询选项(projection、sort、limit 等)。
|
|
199
|
+
* @returns 文档数组,支持链式 `.populate()` 调用。
|
|
200
|
+
*/
|
|
201
|
+
find(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
202
|
+
/**
|
|
203
|
+
* 查询第一条符合条件的文档。
|
|
204
|
+
* @param query 可选的过滤条件。
|
|
205
|
+
* @param options 可选的查询选项。
|
|
206
|
+
* @returns 匹配的文档,未找到时返回 `null`。
|
|
207
|
+
*/
|
|
208
|
+
findOne(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
209
|
+
/**
|
|
210
|
+
* 按主键 ID 查询单条文档(`findOne` 的 ID 快捷方式)。
|
|
211
|
+
* @param id 文档主键值。
|
|
212
|
+
* @param options 可选的查询选项。
|
|
213
|
+
* @returns 匹配的文档,未找到时返回 `null`。
|
|
214
|
+
*/
|
|
215
|
+
findOneById(id: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
216
|
+
/**
|
|
217
|
+
* 按主键 ID 查询单条文档(`findOneById` 的别名)。
|
|
218
|
+
* @param id 文档主键值。
|
|
219
|
+
* @param options 可选的查询选项。
|
|
220
|
+
* @returns 匹配的文档,未找到时返回 `null`。
|
|
221
|
+
*/
|
|
222
|
+
findById(id: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
223
|
+
/**
|
|
224
|
+
* 按多个主键 ID 批量查询文档。
|
|
225
|
+
* @param ids 主键值数组。
|
|
226
|
+
* @param options 可选的查询选项。
|
|
227
|
+
* @returns 匹配的文档数组。
|
|
228
|
+
*/
|
|
229
|
+
findByIds(ids: unknown[], options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
230
|
+
/**
|
|
231
|
+
* 分页查询文档,支持基于游标或页码两种分页模式。
|
|
232
|
+
* @param options 分页选项,包含 `limit`、`cursor`/`page`、`filter`、`sort` 等字段。
|
|
233
|
+
* @returns 包含文档列表、分页信息及可选汇总数据的结果对象。
|
|
234
|
+
*/
|
|
231
235
|
findPage(options: { totals: { mode: 'sync'; } & Record<string, unknown>; } & Record<string, unknown>): PopulateProxy<{
|
|
232
236
|
items: Array<ModelDocument<TDocument>>;
|
|
233
237
|
pageInfo: LegacyModelPageInfo<TDocument>;
|
|
@@ -240,287 +244,287 @@ export interface ModelInstance<TDocument = any> {
|
|
|
240
244
|
totals?: LegacyModelTotalsInfo<TDocument>;
|
|
241
245
|
meta?: import('./collection').MetaInfo;
|
|
242
246
|
}>;
|
|
243
|
-
/**
|
|
244
|
-
* 查询符合条件的文档列表,同时返回未分页的总数。
|
|
245
|
-
* @param query 可选的过滤条件。
|
|
246
|
-
* @param options 可选的查询选项。
|
|
247
|
-
* @returns 包含文档数组和总数的对象。
|
|
248
|
-
*/
|
|
249
|
-
findAndCount(query?: unknown, options?: unknown): PopulateProxy<{
|
|
250
|
-
data: Array<ModelDocument<TDocument>>;
|
|
251
|
-
total: number;
|
|
252
|
-
}>;
|
|
253
|
-
/**
|
|
254
|
-
* 统计符合条件的文档数量。
|
|
255
|
-
* @param query 可选的过滤条件。
|
|
256
|
-
* @param options 可选的统计选项。
|
|
257
|
-
* @returns 匹配的文档数量。
|
|
258
|
-
*/
|
|
259
|
-
count(query?: unknown, options?: unknown): Promise<number>;
|
|
260
|
-
/**
|
|
261
|
-
* 插入单条文档。
|
|
262
|
-
* @param document 要插入的文档数据。
|
|
263
|
-
* @param options 可选的写入选项。
|
|
264
|
-
* @returns 包含插入 ID 的结果对象。
|
|
265
|
-
*/
|
|
266
|
-
insertOne(document?: unknown, options?: unknown): Promise<InsertOneResult>;
|
|
267
|
-
/**
|
|
268
|
-
* 批量插入多条文档(有序插入,遇错即停)。
|
|
269
|
-
* @param documents 要插入的文档数组。
|
|
270
|
-
* @param options 可选的写入选项。
|
|
271
|
-
*/
|
|
247
|
+
/**
|
|
248
|
+
* 查询符合条件的文档列表,同时返回未分页的总数。
|
|
249
|
+
* @param query 可选的过滤条件。
|
|
250
|
+
* @param options 可选的查询选项。
|
|
251
|
+
* @returns 包含文档数组和总数的对象。
|
|
252
|
+
*/
|
|
253
|
+
findAndCount(query?: unknown, options?: unknown): PopulateProxy<{
|
|
254
|
+
data: Array<ModelDocument<TDocument>>;
|
|
255
|
+
total: number;
|
|
256
|
+
}>;
|
|
257
|
+
/**
|
|
258
|
+
* 统计符合条件的文档数量。
|
|
259
|
+
* @param query 可选的过滤条件。
|
|
260
|
+
* @param options 可选的统计选项。
|
|
261
|
+
* @returns 匹配的文档数量。
|
|
262
|
+
*/
|
|
263
|
+
count(query?: unknown, options?: unknown): Promise<number>;
|
|
264
|
+
/**
|
|
265
|
+
* 插入单条文档。
|
|
266
|
+
* @param document 要插入的文档数据。
|
|
267
|
+
* @param options 可选的写入选项。
|
|
268
|
+
* @returns 包含插入 ID 的结果对象。
|
|
269
|
+
*/
|
|
270
|
+
insertOne(document?: unknown, options?: unknown): Promise<InsertOneResult>;
|
|
271
|
+
/**
|
|
272
|
+
* 批量插入多条文档(有序插入,遇错即停)。
|
|
273
|
+
* @param documents 要插入的文档数组。
|
|
274
|
+
* @param options 可选的写入选项。
|
|
275
|
+
*/
|
|
272
276
|
insertMany(documents?: unknown[], options?: unknown): Promise<InsertManyResult>;
|
|
273
|
-
/**
|
|
274
|
-
* 更新第一条符合条件的文档。
|
|
275
|
-
* @param filter 过滤条件。
|
|
276
|
-
* @param update 更新操作符文档(如 `$set`、`$inc`)。
|
|
277
|
-
* @param options 可选的更新选项。
|
|
278
|
-
*/
|
|
277
|
+
/**
|
|
278
|
+
* 更新第一条符合条件的文档。
|
|
279
|
+
* @param filter 过滤条件。
|
|
280
|
+
* @param update 更新操作符文档(如 `$set`、`$inc`)。
|
|
281
|
+
* @param options 可选的更新选项。
|
|
282
|
+
*/
|
|
279
283
|
updateOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
280
|
-
/**
|
|
281
|
-
* 更新所有符合条件的文档。
|
|
282
|
-
* @param filter 过滤条件。
|
|
283
|
-
* @param update 更新操作符文档。
|
|
284
|
-
* @param options 可选的更新选项。
|
|
285
|
-
*/
|
|
284
|
+
/**
|
|
285
|
+
* 更新所有符合条件的文档。
|
|
286
|
+
* @param filter 过滤条件。
|
|
287
|
+
* @param update 更新操作符文档。
|
|
288
|
+
* @param options 可选的更新选项。
|
|
289
|
+
*/
|
|
286
290
|
updateMany(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
287
|
-
/**
|
|
288
|
-
* 替换第一条符合条件的文档(整体替换,不使用更新操作符)。
|
|
289
|
-
* @param filter 过滤条件。
|
|
290
|
-
* @param replacement 替换后的完整文档。
|
|
291
|
-
* @param options 可选的替换选项。
|
|
292
|
-
*/
|
|
291
|
+
/**
|
|
292
|
+
* 替换第一条符合条件的文档(整体替换,不使用更新操作符)。
|
|
293
|
+
* @param filter 过滤条件。
|
|
294
|
+
* @param replacement 替换后的完整文档。
|
|
295
|
+
* @param options 可选的替换选项。
|
|
296
|
+
*/
|
|
293
297
|
replaceOne(filter?: unknown, replacement?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
294
|
-
/**
|
|
295
|
-
* 原子地查找并更新单条文档,返回更新后的文档。
|
|
296
|
-
* @param filter 过滤条件。
|
|
297
|
-
* @param update 更新操作符文档。
|
|
298
|
-
* @param options 可选的选项(如 `returnDocument: 'after'`)。
|
|
299
|
-
* @returns 更新后的文档,未找到时返回 `null`。
|
|
300
|
-
*/
|
|
301
|
-
findOneAndUpdate(filter?: unknown, update?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
302
|
-
/**
|
|
303
|
-
* 原子地查找并替换单条文档,返回替换后的文档。
|
|
304
|
-
* @param filter 过滤条件。
|
|
305
|
-
* @param replacement 替换后的完整文档。
|
|
306
|
-
* @param options 可选的选项。
|
|
307
|
-
* @returns 替换后的文档,未找到时返回 `null`。
|
|
308
|
-
*/
|
|
309
|
-
findOneAndReplace(filter?: unknown, replacement?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
310
|
-
/**
|
|
311
|
-
* 原子地查找并删除单条文档,返回被删除的文档。
|
|
312
|
-
* @param filter 过滤条件。
|
|
313
|
-
* @param options 可选的选项。
|
|
314
|
-
* @returns 被删除的文档,未找到时返回 `null`。
|
|
315
|
-
*/
|
|
316
|
-
findOneAndDelete(filter?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
317
|
-
/**
|
|
318
|
-
* 若文档存在则更新,否则插入(upsert 语义)。
|
|
319
|
-
* @param filter 过滤条件。
|
|
320
|
-
* @param update 更新操作符文档。
|
|
321
|
-
* @param options 可选的更新选项。
|
|
322
|
-
* @returns 标准 `UpdateResult` 对象。
|
|
323
|
-
*/
|
|
324
|
-
upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
325
|
-
/**
|
|
326
|
-
* 对符合条件的单条文档的指定字段执行原子自增操作。
|
|
327
|
-
* @param filter 过滤条件。
|
|
328
|
-
* @param field 字段名或字段-增量映射对象。
|
|
329
|
-
* @param increment 增量值(`field` 为字符串时使用)。
|
|
330
|
-
* @param options 可选的更新选项。
|
|
331
|
-
*/
|
|
298
|
+
/**
|
|
299
|
+
* 原子地查找并更新单条文档,返回更新后的文档。
|
|
300
|
+
* @param filter 过滤条件。
|
|
301
|
+
* @param update 更新操作符文档。
|
|
302
|
+
* @param options 可选的选项(如 `returnDocument: 'after'`)。
|
|
303
|
+
* @returns 更新后的文档,未找到时返回 `null`。
|
|
304
|
+
*/
|
|
305
|
+
findOneAndUpdate(filter?: unknown, update?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
306
|
+
/**
|
|
307
|
+
* 原子地查找并替换单条文档,返回替换后的文档。
|
|
308
|
+
* @param filter 过滤条件。
|
|
309
|
+
* @param replacement 替换后的完整文档。
|
|
310
|
+
* @param options 可选的选项。
|
|
311
|
+
* @returns 替换后的文档,未找到时返回 `null`。
|
|
312
|
+
*/
|
|
313
|
+
findOneAndReplace(filter?: unknown, replacement?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
314
|
+
/**
|
|
315
|
+
* 原子地查找并删除单条文档,返回被删除的文档。
|
|
316
|
+
* @param filter 过滤条件。
|
|
317
|
+
* @param options 可选的选项。
|
|
318
|
+
* @returns 被删除的文档,未找到时返回 `null`。
|
|
319
|
+
*/
|
|
320
|
+
findOneAndDelete(filter?: unknown, options?: unknown): Promise<TDocument | null>;
|
|
321
|
+
/**
|
|
322
|
+
* 若文档存在则更新,否则插入(upsert 语义)。
|
|
323
|
+
* @param filter 过滤条件。
|
|
324
|
+
* @param update 更新操作符文档。
|
|
325
|
+
* @param options 可选的更新选项。
|
|
326
|
+
* @returns 标准 `UpdateResult` 对象。
|
|
327
|
+
*/
|
|
328
|
+
upsertOne(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateResult>;
|
|
329
|
+
/**
|
|
330
|
+
* 对符合条件的单条文档的指定字段执行原子自增操作。
|
|
331
|
+
* @param filter 过滤条件。
|
|
332
|
+
* @param field 字段名或字段-增量映射对象。
|
|
333
|
+
* @param increment 增量值(`field` 为字符串时使用)。
|
|
334
|
+
* @param options 可选的更新选项。
|
|
335
|
+
*/
|
|
332
336
|
incrementOne(filter?: unknown, field?: string | Record<string, number>, increment?: number, options?: unknown): Promise<IncrementOneResult<TDocument>>;
|
|
333
|
-
/**
|
|
334
|
-
* 删除第一条符合条件的文档。
|
|
335
|
-
* @param filter 过滤条件。
|
|
336
|
-
* @param options 可选的删除选项。
|
|
337
|
-
* @returns 标准 `DeleteResult` 对象。
|
|
338
|
-
*/
|
|
339
|
-
deleteOne(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
340
|
-
/**
|
|
341
|
-
* 删除所有符合条件的文档。
|
|
342
|
-
* @param filter 过滤条件。
|
|
343
|
-
* @param options 可选的删除选项。
|
|
344
|
-
* @returns 标准 `DeleteResult` 对象。
|
|
345
|
-
*/
|
|
346
|
-
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
347
|
-
// soft-delete extended methods
|
|
348
|
-
/**
|
|
349
|
-
* 查询包含软删除文档在内的所有匹配文档。
|
|
350
|
-
* @param query 可选的过滤条件。
|
|
351
|
-
* @param options 可选的查询选项。
|
|
352
|
-
*/
|
|
353
|
-
findWithDeleted(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
354
|
-
/**
|
|
355
|
-
* 仅查询已被软删除的文档。
|
|
356
|
-
* @param query 可选的过滤条件。
|
|
357
|
-
* @param options 可选的查询选项。
|
|
358
|
-
*/
|
|
359
|
-
findOnlyDeleted(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
360
|
-
/**
|
|
361
|
-
* 查询第一条符合条件的文档(包含软删除文档)。
|
|
362
|
-
* @param query 可选的过滤条件。
|
|
363
|
-
* @param options 可选的查询选项。
|
|
364
|
-
* @returns 匹配的文档,未找到时返回 `null`。
|
|
365
|
-
*/
|
|
366
|
-
findOneWithDeleted(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
367
|
-
/**
|
|
368
|
-
* 恢复第一条符合条件的软删除文档。
|
|
369
|
-
* @param filter 过滤条件。
|
|
370
|
-
* @param options 可选的更新选项。
|
|
371
|
-
*/
|
|
337
|
+
/**
|
|
338
|
+
* 删除第一条符合条件的文档。
|
|
339
|
+
* @param filter 过滤条件。
|
|
340
|
+
* @param options 可选的删除选项。
|
|
341
|
+
* @returns 标准 `DeleteResult` 对象。
|
|
342
|
+
*/
|
|
343
|
+
deleteOne(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
344
|
+
/**
|
|
345
|
+
* 删除所有符合条件的文档。
|
|
346
|
+
* @param filter 过滤条件。
|
|
347
|
+
* @param options 可选的删除选项。
|
|
348
|
+
* @returns 标准 `DeleteResult` 对象。
|
|
349
|
+
*/
|
|
350
|
+
deleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
351
|
+
// soft-delete extended methods
|
|
352
|
+
/**
|
|
353
|
+
* 查询包含软删除文档在内的所有匹配文档。
|
|
354
|
+
* @param query 可选的过滤条件。
|
|
355
|
+
* @param options 可选的查询选项。
|
|
356
|
+
*/
|
|
357
|
+
findWithDeleted(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
358
|
+
/**
|
|
359
|
+
* 仅查询已被软删除的文档。
|
|
360
|
+
* @param query 可选的过滤条件。
|
|
361
|
+
* @param options 可选的查询选项。
|
|
362
|
+
*/
|
|
363
|
+
findOnlyDeleted(query?: unknown, options?: unknown): PopulateProxy<Array<ModelDocument<TDocument>>>;
|
|
364
|
+
/**
|
|
365
|
+
* 查询第一条符合条件的文档(包含软删除文档)。
|
|
366
|
+
* @param query 可选的过滤条件。
|
|
367
|
+
* @param options 可选的查询选项。
|
|
368
|
+
* @returns 匹配的文档,未找到时返回 `null`。
|
|
369
|
+
*/
|
|
370
|
+
findOneWithDeleted(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
371
|
+
/**
|
|
372
|
+
* 恢复第一条符合条件的软删除文档。
|
|
373
|
+
* @param filter 过滤条件。
|
|
374
|
+
* @param options 可选的更新选项。
|
|
375
|
+
*/
|
|
372
376
|
restore(filter?: unknown, options?: unknown): Promise<RestoreResult>;
|
|
373
|
-
/**
|
|
374
|
-
* 批量恢复所有符合条件的软删除文档。
|
|
375
|
-
* @param filter 过滤条件。
|
|
376
|
-
* @param options 可选的更新选项。
|
|
377
|
-
*/
|
|
377
|
+
/**
|
|
378
|
+
* 批量恢复所有符合条件的软删除文档。
|
|
379
|
+
* @param filter 过滤条件。
|
|
380
|
+
* @param options 可选的更新选项。
|
|
381
|
+
*/
|
|
378
382
|
restoreMany(filter?: unknown, options?: unknown): Promise<RestoreResult>;
|
|
379
|
-
/**
|
|
380
|
-
* 物理删除第一条符合条件的文档(绕过软删除机制)。
|
|
381
|
-
* @param filter 过滤条件。
|
|
382
|
-
* @param options 可选的删除选项。
|
|
383
|
-
* @returns 标准 `DeleteResult` 对象。
|
|
384
|
-
*/
|
|
385
|
-
forceDelete(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
386
|
-
/**
|
|
387
|
-
* 物理删除所有符合条件的文档(绕过软删除机制)。
|
|
388
|
-
* @param filter 过滤条件。
|
|
389
|
-
* @param options 可选的删除选项。
|
|
390
|
-
* @returns 标准 `DeleteResult` 对象。
|
|
391
|
-
*/
|
|
392
|
-
forceDeleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
393
|
-
/**
|
|
394
|
-
* 查询第一条仅在软删除范围内匹配的文档。
|
|
395
|
-
* @param query 可选的过滤条件。
|
|
396
|
-
* @param options 可选的查询选项。
|
|
397
|
-
* @returns 匹配的已删除文档,未找到时返回 `null`。
|
|
398
|
-
*/
|
|
399
|
-
findOneOnlyDeleted(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
400
|
-
/**
|
|
401
|
-
* 统计包含软删除文档在内的匹配数量。
|
|
402
|
-
* @param query 可选的过滤条件。
|
|
403
|
-
* @param options 可选的统计选项。
|
|
404
|
-
*/
|
|
405
|
-
countWithDeleted(query?: unknown, options?: unknown): Promise<number>;
|
|
406
|
-
/**
|
|
407
|
-
* 统计已被软删除的文档数量。
|
|
408
|
-
* @param query 可选的过滤条件。
|
|
409
|
-
* @param options 可选的统计选项。
|
|
410
|
-
*/
|
|
411
|
-
countOnlyDeleted(query?: unknown, options?: unknown): Promise<number>;
|
|
412
|
-
/**
|
|
413
|
-
* 使用写队列批量插入大量文档,适合高吞吐写入场景。
|
|
414
|
-
* @param docs 要插入的文档数组。
|
|
415
|
-
* @param options 可选的批量写入选项。
|
|
416
|
-
*/
|
|
383
|
+
/**
|
|
384
|
+
* 物理删除第一条符合条件的文档(绕过软删除机制)。
|
|
385
|
+
* @param filter 过滤条件。
|
|
386
|
+
* @param options 可选的删除选项。
|
|
387
|
+
* @returns 标准 `DeleteResult` 对象。
|
|
388
|
+
*/
|
|
389
|
+
forceDelete(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
390
|
+
/**
|
|
391
|
+
* 物理删除所有符合条件的文档(绕过软删除机制)。
|
|
392
|
+
* @param filter 过滤条件。
|
|
393
|
+
* @param options 可选的删除选项。
|
|
394
|
+
* @returns 标准 `DeleteResult` 对象。
|
|
395
|
+
*/
|
|
396
|
+
forceDeleteMany(filter?: unknown, options?: unknown): Promise<DeleteResult>;
|
|
397
|
+
/**
|
|
398
|
+
* 查询第一条仅在软删除范围内匹配的文档。
|
|
399
|
+
* @param query 可选的过滤条件。
|
|
400
|
+
* @param options 可选的查询选项。
|
|
401
|
+
* @returns 匹配的已删除文档,未找到时返回 `null`。
|
|
402
|
+
*/
|
|
403
|
+
findOneOnlyDeleted(query?: unknown, options?: unknown): PopulateProxy<ModelDocument<TDocument> | null>;
|
|
404
|
+
/**
|
|
405
|
+
* 统计包含软删除文档在内的匹配数量。
|
|
406
|
+
* @param query 可选的过滤条件。
|
|
407
|
+
* @param options 可选的统计选项。
|
|
408
|
+
*/
|
|
409
|
+
countWithDeleted(query?: unknown, options?: unknown): Promise<number>;
|
|
410
|
+
/**
|
|
411
|
+
* 统计已被软删除的文档数量。
|
|
412
|
+
* @param query 可选的过滤条件。
|
|
413
|
+
* @param options 可选的统计选项。
|
|
414
|
+
*/
|
|
415
|
+
countOnlyDeleted(query?: unknown, options?: unknown): Promise<number>;
|
|
416
|
+
/**
|
|
417
|
+
* 使用写队列批量插入大量文档,适合高吞吐写入场景。
|
|
418
|
+
* @param docs 要插入的文档数组。
|
|
419
|
+
* @param options 可选的批量写入选项。
|
|
420
|
+
*/
|
|
417
421
|
insertBatch(docs: unknown[], options?: unknown): Promise<InsertBatchResult>;
|
|
418
|
-
/**
|
|
419
|
-
* 批量更新符合条件的文档(底层使用 `bulkWrite`)。
|
|
420
|
-
* @param filter 过滤条件。
|
|
421
|
-
* @param update 更新操作符文档。
|
|
422
|
-
* @param options 可选的批量写入选项。
|
|
423
|
-
*/
|
|
422
|
+
/**
|
|
423
|
+
* 批量更新符合条件的文档(底层使用 `bulkWrite`)。
|
|
424
|
+
* @param filter 过滤条件。
|
|
425
|
+
* @param update 更新操作符文档。
|
|
426
|
+
* @param options 可选的批量写入选项。
|
|
427
|
+
*/
|
|
424
428
|
updateBatch(filter?: unknown, update?: unknown, options?: unknown): Promise<UpdateBatchResult>;
|
|
425
|
-
/** 批量删除符合条件的文档。 */
|
|
426
|
-
deleteBatch(filter?: unknown, options?: unknown): Promise<DeleteBatchResult>;
|
|
427
|
-
/**
|
|
428
|
-
* 在集合上创建单个索引。
|
|
429
|
-
* @param keys 索引键规范对象。
|
|
430
|
-
* @param options 可选的索引选项(如 `unique`、`sparse`)。
|
|
431
|
-
* @returns 索引创建结果。
|
|
432
|
-
*/
|
|
433
|
-
createIndex(keys: unknown, options?: unknown): Promise<IndexCreateResult>;
|
|
434
|
-
/**
|
|
435
|
-
* 批量创建多个索引。
|
|
436
|
-
* @param specs 索引规范数组,每项包含 `key` 及可选的索引选项。
|
|
437
|
-
* @returns 已创建索引的名称数组。
|
|
438
|
-
*/
|
|
439
|
-
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
440
|
-
/** 列出集合上所有现有索引的定义信息。 */
|
|
441
|
-
listIndexes(): Promise<Record<string, unknown>[]>;
|
|
442
|
-
/**
|
|
443
|
-
* 按名称删除指定索引。
|
|
444
|
-
* @param name 索引名称。
|
|
445
|
-
*/
|
|
446
|
-
dropIndex(name: string): Promise<unknown>;
|
|
447
|
-
/** 删除集合上的所有非 `_id` 索引。 */
|
|
448
|
-
dropIndexes(): Promise<unknown>;
|
|
449
|
-
/** 预热游标分页书签缓存。 */
|
|
450
|
-
prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise<BookmarkPrewarmResult>;
|
|
451
|
-
/** 列出游标分页书签缓存。 */
|
|
452
|
-
listBookmarks(keyDims?: unknown): Promise<BookmarkListResult>;
|
|
453
|
-
/** 清理游标分页书签缓存。 */
|
|
454
|
-
clearBookmarks(keyDims?: unknown): Promise<BookmarkClearResult>;
|
|
455
|
-
/**
|
|
456
|
-
* 获取指定字段在符合条件的文档中的所有唯一值。
|
|
457
|
-
* @param key 目标字段名。
|
|
458
|
-
* @param query 可选的过滤条件。
|
|
459
|
-
* @param options 可选的驱动级选项。
|
|
460
|
-
* @returns 唯一值数组。
|
|
461
|
-
*/
|
|
462
|
-
distinct(key: string, query?: unknown, options?: unknown): Promise<unknown[]>;
|
|
463
|
-
/**
|
|
464
|
-
* 执行聚合管道并返回结果数组。
|
|
465
|
-
* @param pipeline 聚合阶段数组。
|
|
466
|
-
* @param options 可选的聚合选项(如 `allowDiskUse`)。
|
|
467
|
-
* @returns 聚合结果文档数组。
|
|
468
|
-
*/
|
|
469
|
-
aggregate(pipeline?: unknown[], options?: unknown): Promise<unknown[]>;
|
|
470
|
-
/** 返回匹配查询的可读流。 */
|
|
471
|
-
stream(query?: unknown, options?: unknown): NodeJS.ReadableStream;
|
|
472
|
-
/** 返回 MongoDB 查询执行计划。 */
|
|
473
|
-
explain(query?: unknown, options?: unknown): Promise<unknown>;
|
|
474
|
-
/** 手动失效当前 Model 对应集合的读缓存。 */
|
|
475
|
-
invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise<number>;
|
|
476
|
-
/** 删除当前 Model 对应集合。 */
|
|
477
|
-
dropCollection(): Promise<boolean>;
|
|
478
|
-
/** 创建当前或指定名称的集合。 */
|
|
479
|
-
createCollection(name?: string, options?: Record<string, unknown>): Promise<boolean>;
|
|
480
|
-
/** 创建 MongoDB view。 */
|
|
481
|
-
createView(name: string, source: string, pipeline?: unknown[]): Promise<boolean>;
|
|
482
|
-
/** 返回索引使用统计。 */
|
|
483
|
-
indexStats(): Promise<unknown[]>;
|
|
484
|
-
/** 设置集合 JSON Schema validator。 */
|
|
485
|
-
setValidator(validator: unknown, options?: { validationLevel?: string; validationAction?: string }): Promise<{ ok: number; collection: string }>;
|
|
486
|
-
/** 设置集合 validation level。 */
|
|
487
|
-
setValidationLevel(level: 'off' | 'moderate' | 'strict' | string): Promise<{ ok: number; validationLevel: string }>;
|
|
488
|
-
/** 设置集合 validation action。 */
|
|
489
|
-
setValidationAction(action: 'error' | 'warn' | string): Promise<{ ok: number; validationAction: string }>;
|
|
490
|
-
/** 读取集合 validator 与校验设置。 */
|
|
491
|
-
getValidator(): Promise<{ validator: Record<string, unknown> | null; validationLevel: string; validationAction: string }>;
|
|
492
|
-
/** 返回集合存储与索引统计。 */
|
|
493
|
-
stats(options?: { scale?: number }): Promise<{ ns: string; count: number; size: number; storageSize: number; totalIndexSize: number; nindexes: number; avgObjSize?: number; scaleFactor?: number }>;
|
|
494
|
-
/** 重命名当前 Model 对应集合。 */
|
|
495
|
-
renameCollection(newName: string, options?: { dropTarget?: boolean }): Promise<{ renamed: boolean; from: string; to: string }>;
|
|
496
|
-
/** 执行 collMod 管理命令。 */
|
|
497
|
-
collMod(modifications: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
498
|
-
/** 将集合转换为 capped collection。 */
|
|
499
|
-
convertToCapped(size: number, options?: { max?: number }): Promise<{ ok: number; collection: string; capped: boolean; size: number }>;
|
|
500
|
-
/**
|
|
501
|
-
* 打开集合的 ChangeStream 以监听实时变更事件。
|
|
502
|
-
* @param pipeline 可选的聚合过滤管道。
|
|
503
|
-
* @param options 可选的 ChangeStream 选项。
|
|
504
|
-
* @returns MongoDB 原生 ChangeStream 对象。
|
|
505
|
-
*/
|
|
506
|
-
watch(pipeline?: unknown[], options?: unknown): import('mongodb').ChangeStream;
|
|
507
|
-
/**
|
|
508
|
-
* 根据模型 schema 定义验证文档数据的合法性。
|
|
509
|
-
* @param document 要验证的文档对象。
|
|
510
|
-
* @returns 包含 `valid` 标志和错误详情的验证结果对象。
|
|
511
|
-
*/
|
|
512
|
-
validate(document?: unknown): ValidationResult;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
export declare class Model {
|
|
516
|
-
static define<TDocument = Record<string, unknown>>(collectionName: string, definition: ModelDefinition<TDocument>): void;
|
|
517
|
-
static get<TDocument = Record<string, unknown>>(collectionName: string): RegisteredModel<TDocument> | undefined;
|
|
518
|
-
static has(collectionName: string): boolean;
|
|
519
|
-
static list(): string[];
|
|
520
|
-
static undefine(collectionName: string): boolean;
|
|
521
|
-
static redefine<TDocument = Record<string, unknown>>(collectionName: string, definition: ModelDefinition<TDocument>): void;
|
|
522
|
-
static _clear(): void;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
429
|
+
/** 批量删除符合条件的文档。 */
|
|
430
|
+
deleteBatch(filter?: unknown, options?: unknown): Promise<DeleteBatchResult>;
|
|
431
|
+
/**
|
|
432
|
+
* 在集合上创建单个索引。
|
|
433
|
+
* @param keys 索引键规范对象。
|
|
434
|
+
* @param options 可选的索引选项(如 `unique`、`sparse`)。
|
|
435
|
+
* @returns 索引创建结果。
|
|
436
|
+
*/
|
|
437
|
+
createIndex(keys: unknown, options?: unknown): Promise<IndexCreateResult>;
|
|
438
|
+
/**
|
|
439
|
+
* 批量创建多个索引。
|
|
440
|
+
* @param specs 索引规范数组,每项包含 `key` 及可选的索引选项。
|
|
441
|
+
* @returns 已创建索引的名称数组。
|
|
442
|
+
*/
|
|
443
|
+
createIndexes(specs: Array<{ key: unknown; } & Record<string, unknown>>): Promise<string[]>;
|
|
444
|
+
/** 列出集合上所有现有索引的定义信息。 */
|
|
445
|
+
listIndexes(): Promise<Record<string, unknown>[]>;
|
|
446
|
+
/**
|
|
447
|
+
* 按名称删除指定索引。
|
|
448
|
+
* @param name 索引名称。
|
|
449
|
+
*/
|
|
450
|
+
dropIndex(name: string): Promise<unknown>;
|
|
451
|
+
/** 删除集合上的所有非 `_id` 索引。 */
|
|
452
|
+
dropIndexes(): Promise<unknown>;
|
|
453
|
+
/** 预热游标分页书签缓存。 */
|
|
454
|
+
prewarmBookmarks(keyDims?: unknown, pages?: number[]): Promise<BookmarkPrewarmResult>;
|
|
455
|
+
/** 列出游标分页书签缓存。 */
|
|
456
|
+
listBookmarks(keyDims?: unknown): Promise<BookmarkListResult>;
|
|
457
|
+
/** 清理游标分页书签缓存。 */
|
|
458
|
+
clearBookmarks(keyDims?: unknown): Promise<BookmarkClearResult>;
|
|
459
|
+
/**
|
|
460
|
+
* 获取指定字段在符合条件的文档中的所有唯一值。
|
|
461
|
+
* @param key 目标字段名。
|
|
462
|
+
* @param query 可选的过滤条件。
|
|
463
|
+
* @param options 可选的驱动级选项。
|
|
464
|
+
* @returns 唯一值数组。
|
|
465
|
+
*/
|
|
466
|
+
distinct(key: string, query?: unknown, options?: unknown): Promise<unknown[]>;
|
|
467
|
+
/**
|
|
468
|
+
* 执行聚合管道并返回结果数组。
|
|
469
|
+
* @param pipeline 聚合阶段数组。
|
|
470
|
+
* @param options 可选的聚合选项(如 `allowDiskUse`)。
|
|
471
|
+
* @returns 聚合结果文档数组。
|
|
472
|
+
*/
|
|
473
|
+
aggregate(pipeline?: unknown[], options?: unknown): Promise<unknown[]>;
|
|
474
|
+
/** 返回匹配查询的可读流。 */
|
|
475
|
+
stream(query?: unknown, options?: unknown): NodeJS.ReadableStream;
|
|
476
|
+
/** 返回 MongoDB 查询执行计划。 */
|
|
477
|
+
explain(query?: unknown, options?: unknown): Promise<unknown>;
|
|
478
|
+
/** 手动失效当前 Model 对应集合的读缓存。 */
|
|
479
|
+
invalidate(op?: 'find' | 'findOne' | 'count' | 'findPage' | 'aggregate' | 'distinct'): Promise<number>;
|
|
480
|
+
/** 删除当前 Model 对应集合。 */
|
|
481
|
+
dropCollection(): Promise<boolean>;
|
|
482
|
+
/** 创建当前或指定名称的集合。 */
|
|
483
|
+
createCollection(name?: string, options?: Record<string, unknown>): Promise<boolean>;
|
|
484
|
+
/** 创建 MongoDB view。 */
|
|
485
|
+
createView(name: string, source: string, pipeline?: unknown[]): Promise<boolean>;
|
|
486
|
+
/** 返回索引使用统计。 */
|
|
487
|
+
indexStats(): Promise<unknown[]>;
|
|
488
|
+
/** 设置集合 JSON Schema validator。 */
|
|
489
|
+
setValidator(validator: unknown, options?: { validationLevel?: string; validationAction?: string }): Promise<{ ok: number; collection: string }>;
|
|
490
|
+
/** 设置集合 validation level。 */
|
|
491
|
+
setValidationLevel(level: 'off' | 'moderate' | 'strict' | string): Promise<{ ok: number; validationLevel: string }>;
|
|
492
|
+
/** 设置集合 validation action。 */
|
|
493
|
+
setValidationAction(action: 'error' | 'warn' | string): Promise<{ ok: number; validationAction: string }>;
|
|
494
|
+
/** 读取集合 validator 与校验设置。 */
|
|
495
|
+
getValidator(): Promise<{ validator: Record<string, unknown> | null; validationLevel: string; validationAction: string }>;
|
|
496
|
+
/** 返回集合存储与索引统计。 */
|
|
497
|
+
stats(options?: { scale?: number }): Promise<{ ns: string; count: number; size: number; storageSize: number; totalIndexSize: number; nindexes: number; avgObjSize?: number; scaleFactor?: number }>;
|
|
498
|
+
/** 重命名当前 Model 对应集合。 */
|
|
499
|
+
renameCollection(newName: string, options?: { dropTarget?: boolean }): Promise<{ renamed: boolean; from: string; to: string }>;
|
|
500
|
+
/** 执行 collMod 管理命令。 */
|
|
501
|
+
collMod(modifications: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
502
|
+
/** 将集合转换为 capped collection。 */
|
|
503
|
+
convertToCapped(size: number, options?: { max?: number }): Promise<{ ok: number; collection: string; capped: boolean; size: number }>;
|
|
504
|
+
/**
|
|
505
|
+
* 打开集合的 ChangeStream 以监听实时变更事件。
|
|
506
|
+
* @param pipeline 可选的聚合过滤管道。
|
|
507
|
+
* @param options 可选的 ChangeStream 选项。
|
|
508
|
+
* @returns MongoDB 原生 ChangeStream 对象。
|
|
509
|
+
*/
|
|
510
|
+
watch(pipeline?: unknown[], options?: unknown): import('mongodb').ChangeStream;
|
|
511
|
+
/**
|
|
512
|
+
* 根据模型 schema 定义验证文档数据的合法性。
|
|
513
|
+
* @param document 要验证的文档对象。
|
|
514
|
+
* @returns 包含 `valid` 标志和错误详情的验证结果对象。
|
|
515
|
+
*/
|
|
516
|
+
validate(document?: unknown): ValidationResult;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export declare class Model {
|
|
520
|
+
static define<TDocument = Record<string, unknown>>(collectionName: string, definition: ModelDefinition<TDocument>): void;
|
|
521
|
+
static get<TDocument = Record<string, unknown>>(collectionName: string): RegisteredModel<TDocument> | undefined;
|
|
522
|
+
static has(collectionName: string): boolean;
|
|
523
|
+
static list(): string[];
|
|
524
|
+
static undefine(collectionName: string): boolean;
|
|
525
|
+
static redefine<TDocument = Record<string, unknown>>(collectionName: string, definition: ModelDefinition<TDocument>): void;
|
|
526
|
+
static _clear(): void;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|