mondoo 0.1.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/dist/index.cjs +5236 -0
- package/dist/index.d.cts +3249 -0
- package/dist/index.d.ts +3249 -0
- package/dist/index.js +5153 -0
- package/package.json +55 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3249 @@
|
|
|
1
|
+
import { ObjectId } from 'mondodb';
|
|
2
|
+
export { ObjectId } from 'mondodb';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Core types for Mondoo
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Schema type markers for type inference
|
|
10
|
+
*/
|
|
11
|
+
interface SchemaTypeOptions<T = unknown> {
|
|
12
|
+
type?: T;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
default?: T | (() => T);
|
|
15
|
+
validate?: ((value: T) => boolean | Promise<boolean>) | RegExp;
|
|
16
|
+
enum?: readonly T[];
|
|
17
|
+
min?: number;
|
|
18
|
+
max?: number;
|
|
19
|
+
minLength?: number;
|
|
20
|
+
maxLength?: number;
|
|
21
|
+
match?: RegExp;
|
|
22
|
+
ref?: string;
|
|
23
|
+
index?: boolean;
|
|
24
|
+
unique?: boolean;
|
|
25
|
+
sparse?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Base schema type - all schema types extend this
|
|
29
|
+
*/
|
|
30
|
+
declare abstract class SchemaType<T, Required extends boolean = false> {
|
|
31
|
+
abstract readonly _type: T;
|
|
32
|
+
abstract readonly _required: Required;
|
|
33
|
+
protected _options: SchemaTypeOptions<T>;
|
|
34
|
+
protected _validators: Array<(value: T) => boolean | Promise<boolean>>;
|
|
35
|
+
required(): SchemaType<T, true>;
|
|
36
|
+
default(value: T | (() => T)): this;
|
|
37
|
+
validate(fn: (value: T) => boolean | Promise<boolean>): this;
|
|
38
|
+
index(value?: boolean): this;
|
|
39
|
+
unique(value?: boolean): this;
|
|
40
|
+
protected abstract _clone(): this;
|
|
41
|
+
/** @internal */
|
|
42
|
+
_getOptions(): SchemaTypeOptions<T>;
|
|
43
|
+
/** @internal */
|
|
44
|
+
_getValidators(): Array<(value: T) => boolean | Promise<boolean>>;
|
|
45
|
+
/** @internal */
|
|
46
|
+
abstract _cast(value: unknown): T;
|
|
47
|
+
/** @internal */
|
|
48
|
+
_validate(value: T): Promise<boolean>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* String schema type
|
|
52
|
+
*/
|
|
53
|
+
declare class StringType<R extends boolean = false> extends SchemaType<string, R> {
|
|
54
|
+
readonly _type: string;
|
|
55
|
+
readonly _required: R;
|
|
56
|
+
protected _clone(): this;
|
|
57
|
+
_cast(value: unknown): string;
|
|
58
|
+
email(): this;
|
|
59
|
+
url(): this;
|
|
60
|
+
uuid(): this;
|
|
61
|
+
regex(pattern: RegExp): this;
|
|
62
|
+
min(length: number): this;
|
|
63
|
+
max(length: number): this;
|
|
64
|
+
length(len: number): this;
|
|
65
|
+
trim(): this;
|
|
66
|
+
lowercase(): this;
|
|
67
|
+
uppercase(): this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Number schema type
|
|
71
|
+
*/
|
|
72
|
+
declare class NumberType<R extends boolean = false> extends SchemaType<number, R> {
|
|
73
|
+
readonly _type: number;
|
|
74
|
+
readonly _required: R;
|
|
75
|
+
protected _clone(): this;
|
|
76
|
+
_cast(value: unknown): number;
|
|
77
|
+
min(value: number): this;
|
|
78
|
+
max(value: number): this;
|
|
79
|
+
int(): this;
|
|
80
|
+
positive(): this;
|
|
81
|
+
negative(): this;
|
|
82
|
+
finite(): this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Boolean schema type
|
|
86
|
+
*/
|
|
87
|
+
declare class BooleanType<R extends boolean = false> extends SchemaType<boolean, R> {
|
|
88
|
+
readonly _type: boolean;
|
|
89
|
+
readonly _required: R;
|
|
90
|
+
protected _clone(): this;
|
|
91
|
+
_cast(value: unknown): boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Date schema type
|
|
95
|
+
*/
|
|
96
|
+
declare class DateType<R extends boolean = false> extends SchemaType<Date, R> {
|
|
97
|
+
readonly _type: Date;
|
|
98
|
+
readonly _required: R;
|
|
99
|
+
protected _clone(): this;
|
|
100
|
+
_cast(value: unknown): Date;
|
|
101
|
+
min(date: Date | string | number): this;
|
|
102
|
+
max(date: Date | string | number): this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* ObjectId schema type with ref support
|
|
106
|
+
*/
|
|
107
|
+
declare class ObjectIdType<R extends boolean = false, RefModel extends string = never> extends SchemaType<ObjectId, R> {
|
|
108
|
+
readonly _type: ObjectId;
|
|
109
|
+
readonly _required: R;
|
|
110
|
+
readonly _ref: RefModel;
|
|
111
|
+
protected _clone(): this;
|
|
112
|
+
_cast(value: unknown): ObjectId;
|
|
113
|
+
_validate(value: ObjectId): Promise<boolean>;
|
|
114
|
+
ref<M extends string>(model: M): ObjectIdType<R, M>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Array schema type
|
|
118
|
+
*/
|
|
119
|
+
declare class ArrayType<T, R extends boolean = false> extends SchemaType<T[], R> {
|
|
120
|
+
readonly _type: T[];
|
|
121
|
+
readonly _required: R;
|
|
122
|
+
readonly _itemType: SchemaType<T, any>;
|
|
123
|
+
constructor(itemType: SchemaType<T, any>);
|
|
124
|
+
protected _clone(): this;
|
|
125
|
+
_cast(value: unknown): T[];
|
|
126
|
+
_validate(value: T[]): Promise<boolean>;
|
|
127
|
+
min(length: number): this;
|
|
128
|
+
max(length: number): this;
|
|
129
|
+
length(len: number): this;
|
|
130
|
+
nonempty(): this;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Object schema type for nested schemas
|
|
134
|
+
*/
|
|
135
|
+
declare class ObjectType<T extends Record<string, SchemaType<any, any>>, R extends boolean = false> extends SchemaType<InferObject<T>, R> {
|
|
136
|
+
readonly _type: InferObject<T>;
|
|
137
|
+
readonly _required: R;
|
|
138
|
+
readonly _shape: T;
|
|
139
|
+
constructor(shape: T);
|
|
140
|
+
protected _clone(): this;
|
|
141
|
+
_cast(value: unknown): InferObject<T>;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Enum schema type
|
|
145
|
+
*/
|
|
146
|
+
declare class EnumType<T extends readonly string[], R extends boolean = false> extends SchemaType<T[number], R> {
|
|
147
|
+
readonly _type: T[number];
|
|
148
|
+
readonly _required: R;
|
|
149
|
+
readonly _values: T;
|
|
150
|
+
constructor(values: T);
|
|
151
|
+
protected _clone(): this;
|
|
152
|
+
_cast(value: unknown): T[number];
|
|
153
|
+
_validate(value: T[number]): Promise<boolean>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Literal schema type
|
|
157
|
+
*/
|
|
158
|
+
declare class LiteralType<T extends string | number | boolean, R extends boolean = false> extends SchemaType<T, R> {
|
|
159
|
+
readonly _type: T;
|
|
160
|
+
readonly _required: R;
|
|
161
|
+
readonly _value: T;
|
|
162
|
+
constructor(value: T);
|
|
163
|
+
protected _clone(): this;
|
|
164
|
+
_cast(value: unknown): T;
|
|
165
|
+
_validate(value: T): Promise<boolean>;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Map schema type
|
|
169
|
+
*/
|
|
170
|
+
declare class MapType<T, R extends boolean = false> extends SchemaType<Map<string, T>, R> {
|
|
171
|
+
readonly _type: Map<string, T>;
|
|
172
|
+
readonly _required: R;
|
|
173
|
+
readonly _valueType: SchemaType<T, any>;
|
|
174
|
+
constructor(valueType: SchemaType<T, any>);
|
|
175
|
+
protected _clone(): this;
|
|
176
|
+
_cast(value: unknown): Map<string, T>;
|
|
177
|
+
_validate(value: Map<string, T> | Record<string, T>): Promise<boolean>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Mixed/Any schema type
|
|
181
|
+
*/
|
|
182
|
+
declare class MixedType<R extends boolean = false> extends SchemaType<unknown, R> {
|
|
183
|
+
readonly _type: unknown;
|
|
184
|
+
readonly _required: R;
|
|
185
|
+
protected _clone(): this;
|
|
186
|
+
_cast(value: unknown): unknown;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Buffer schema type
|
|
190
|
+
*/
|
|
191
|
+
declare class BufferType<R extends boolean = false> extends SchemaType<ArrayBuffer, R> {
|
|
192
|
+
readonly _type: ArrayBuffer;
|
|
193
|
+
readonly _required: R;
|
|
194
|
+
protected _clone(): this;
|
|
195
|
+
_cast(value: unknown): ArrayBuffer;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* BigInt schema type
|
|
199
|
+
*/
|
|
200
|
+
declare class BigIntType<R extends boolean = false> extends SchemaType<bigint, R> {
|
|
201
|
+
readonly _type: bigint;
|
|
202
|
+
readonly _required: R;
|
|
203
|
+
protected _clone(): this;
|
|
204
|
+
_cast(value: unknown): bigint;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Infer the TypeScript type from a SchemaType
|
|
208
|
+
*/
|
|
209
|
+
type InferSchemaType<T> = T extends SchemaType<infer V, infer R> ? R extends true ? V : V | undefined : never;
|
|
210
|
+
/**
|
|
211
|
+
* Infer object type from object shape
|
|
212
|
+
*/
|
|
213
|
+
type InferObject<T extends Record<string, SchemaType<any, any>>> = {
|
|
214
|
+
[K in keyof T as T[K] extends SchemaType<any, true> ? K : never]: InferSchemaType<T[K]>;
|
|
215
|
+
} & {
|
|
216
|
+
[K in keyof T as T[K] extends SchemaType<any, true> ? never : K]?: InferSchemaType<T[K]>;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Infer the full document type from a schema shape
|
|
220
|
+
*/
|
|
221
|
+
type InferSchema<T extends Record<string, SchemaType<any, any>>> = InferObject<T> & {
|
|
222
|
+
_id: ObjectId;
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Transform populated paths - replace ObjectId refs with actual documents
|
|
226
|
+
*/
|
|
227
|
+
type PopulatedDoc<T, Paths extends keyof T = never> = {
|
|
228
|
+
[K in keyof T]: K extends Paths ? T[K] extends ObjectId | undefined ? unknown : T[K] extends (ObjectId | undefined)[] ? unknown[] : T[K] : T[K];
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Schema class - supports both Mongoose-style and $-style definitions
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
declare const Types: {
|
|
236
|
+
String: StringConstructor;
|
|
237
|
+
Number: NumberConstructor;
|
|
238
|
+
Boolean: BooleanConstructor;
|
|
239
|
+
Date: DateConstructor;
|
|
240
|
+
ObjectId: "ObjectId";
|
|
241
|
+
Buffer: "Buffer";
|
|
242
|
+
Mixed: "Mixed";
|
|
243
|
+
Array: ArrayConstructor;
|
|
244
|
+
Map: MapConstructor;
|
|
245
|
+
BigInt: BigIntConstructor;
|
|
246
|
+
};
|
|
247
|
+
type MongooseFieldDef = typeof String | typeof Number | typeof Boolean | typeof Date | 'ObjectId' | 'Buffer' | 'Mixed' | typeof BigInt | MongooseFieldDefObject | [MongooseFieldDef] | SchemaType<any, any>;
|
|
248
|
+
interface MongooseFieldDefObject {
|
|
249
|
+
type?: MongooseFieldDef;
|
|
250
|
+
required?: boolean;
|
|
251
|
+
default?: unknown;
|
|
252
|
+
validate?: ((value: any) => boolean | Promise<boolean>) | RegExp;
|
|
253
|
+
enum?: readonly string[];
|
|
254
|
+
min?: number;
|
|
255
|
+
max?: number;
|
|
256
|
+
minLength?: number;
|
|
257
|
+
maxLength?: number;
|
|
258
|
+
match?: RegExp;
|
|
259
|
+
ref?: string;
|
|
260
|
+
index?: boolean;
|
|
261
|
+
unique?: boolean;
|
|
262
|
+
sparse?: boolean;
|
|
263
|
+
select?: boolean;
|
|
264
|
+
immutable?: boolean;
|
|
265
|
+
transform?: (value: any) => any;
|
|
266
|
+
}
|
|
267
|
+
type SchemaDefinition = Record<string, MongooseFieldDef>;
|
|
268
|
+
interface SchemaOptions$1 {
|
|
269
|
+
timestamps?: boolean | {
|
|
270
|
+
createdAt?: string | boolean;
|
|
271
|
+
updatedAt?: string | boolean;
|
|
272
|
+
};
|
|
273
|
+
versionKey?: boolean | string;
|
|
274
|
+
strict?: boolean | 'throw';
|
|
275
|
+
collection?: string;
|
|
276
|
+
discriminatorKey?: string;
|
|
277
|
+
autoIndex?: boolean;
|
|
278
|
+
minimize?: boolean;
|
|
279
|
+
toJSON?: {
|
|
280
|
+
virtuals?: boolean;
|
|
281
|
+
getters?: boolean;
|
|
282
|
+
transform?: Function;
|
|
283
|
+
};
|
|
284
|
+
toObject?: {
|
|
285
|
+
virtuals?: boolean;
|
|
286
|
+
getters?: boolean;
|
|
287
|
+
transform?: Function;
|
|
288
|
+
};
|
|
289
|
+
id?: boolean;
|
|
290
|
+
_id?: boolean;
|
|
291
|
+
}
|
|
292
|
+
type HookType = 'validate' | 'save' | 'remove' | 'deleteOne' | 'updateOne' | 'init' | 'find' | 'findOne' | 'findOneAndUpdate' | 'findOneAndDelete' | 'findOneAndReplace' | 'updateMany' | 'deleteMany' | 'aggregate' | 'insertMany';
|
|
293
|
+
type PreHookFn<T = any> = (this: T, next: (err?: Error) => void) => void | Promise<void>;
|
|
294
|
+
type PostHookFn<T = any, R = any> = (this: T, doc: R, next: (err?: Error) => void) => void | Promise<void>;
|
|
295
|
+
interface MiddlewareEntry$1 {
|
|
296
|
+
fn: Function;
|
|
297
|
+
options?: {
|
|
298
|
+
document?: boolean;
|
|
299
|
+
query?: boolean;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
interface VirtualType<T = any> {
|
|
303
|
+
get?: (this: T) => any;
|
|
304
|
+
set?: (this: T, value: any) => void;
|
|
305
|
+
options?: {
|
|
306
|
+
ref?: string;
|
|
307
|
+
localField?: string;
|
|
308
|
+
foreignField?: string;
|
|
309
|
+
justOne?: boolean;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
declare class Schema<T = any> {
|
|
313
|
+
private _definition;
|
|
314
|
+
private _options;
|
|
315
|
+
private _paths;
|
|
316
|
+
private _methods;
|
|
317
|
+
private _statics;
|
|
318
|
+
private _virtuals;
|
|
319
|
+
private _preHooks;
|
|
320
|
+
private _postHooks;
|
|
321
|
+
private _indexes;
|
|
322
|
+
private _plugins;
|
|
323
|
+
/**
|
|
324
|
+
* Mongoose-style constructor
|
|
325
|
+
*/
|
|
326
|
+
constructor(definition?: SchemaDefinition, options?: SchemaOptions$1);
|
|
327
|
+
/**
|
|
328
|
+
* Create schema from $-style definition
|
|
329
|
+
*/
|
|
330
|
+
static fromZodStyle<T extends Record<string, SchemaType<any, any>>>(shape: T, options?: SchemaOptions$1): Schema<InferObject<T>>;
|
|
331
|
+
/**
|
|
332
|
+
* Parse Mongoose-style definition into SchemaTypes
|
|
333
|
+
*/
|
|
334
|
+
private _parseDefinition;
|
|
335
|
+
/**
|
|
336
|
+
* Parse a single field definition
|
|
337
|
+
*/
|
|
338
|
+
private _parseField;
|
|
339
|
+
/**
|
|
340
|
+
* Add a path to the schema
|
|
341
|
+
*/
|
|
342
|
+
add(definition: SchemaDefinition | Record<string, SchemaType<any, any>>, prefix?: string): this;
|
|
343
|
+
/**
|
|
344
|
+
* Get a path's SchemaType
|
|
345
|
+
*/
|
|
346
|
+
path(path: string): SchemaType<any, any> | undefined;
|
|
347
|
+
/**
|
|
348
|
+
* Get all paths
|
|
349
|
+
*/
|
|
350
|
+
paths(): Map<string, SchemaType<any, any>>;
|
|
351
|
+
/**
|
|
352
|
+
* Iterate over all paths (Mongoose-compatible)
|
|
353
|
+
*/
|
|
354
|
+
eachPath(fn: (path: string, type: SchemaType<any, any>) => void): void;
|
|
355
|
+
/**
|
|
356
|
+
* Check if path exists
|
|
357
|
+
*/
|
|
358
|
+
pathType(path: string): 'real' | 'virtual' | 'nested' | 'adhocOrUndefined';
|
|
359
|
+
/**
|
|
360
|
+
* Get required paths
|
|
361
|
+
*/
|
|
362
|
+
requiredPaths(): string[];
|
|
363
|
+
/**
|
|
364
|
+
* Clone the schema
|
|
365
|
+
*/
|
|
366
|
+
clone(): Schema<T>;
|
|
367
|
+
/**
|
|
368
|
+
* Add an instance method
|
|
369
|
+
*/
|
|
370
|
+
method(name: string, fn: Function): this;
|
|
371
|
+
method(methods: Record<string, Function>): this;
|
|
372
|
+
/**
|
|
373
|
+
* Get instance methods (Mongoose-compatible property)
|
|
374
|
+
*/
|
|
375
|
+
get methods(): Record<string, Function>;
|
|
376
|
+
/**
|
|
377
|
+
* Add a static method
|
|
378
|
+
*/
|
|
379
|
+
static(name: string, fn: Function): this;
|
|
380
|
+
static(statics: Record<string, Function>): this;
|
|
381
|
+
/**
|
|
382
|
+
* Get static methods (Mongoose-compatible property)
|
|
383
|
+
*/
|
|
384
|
+
get statics(): Record<string, Function>;
|
|
385
|
+
/**
|
|
386
|
+
* Add a virtual property
|
|
387
|
+
*/
|
|
388
|
+
virtual(name: string, options?: VirtualType['options']): VirtualBuilder;
|
|
389
|
+
/**
|
|
390
|
+
* Get virtuals
|
|
391
|
+
*/
|
|
392
|
+
virtuals(): Map<string, VirtualType>;
|
|
393
|
+
/**
|
|
394
|
+
* Add pre middleware
|
|
395
|
+
*/
|
|
396
|
+
pre<K extends HookType>(hook: K | K[], options: {
|
|
397
|
+
document?: boolean;
|
|
398
|
+
query?: boolean;
|
|
399
|
+
} | PreHookFn, fn?: PreHookFn): this;
|
|
400
|
+
/**
|
|
401
|
+
* Add post middleware
|
|
402
|
+
*/
|
|
403
|
+
post<K extends HookType>(hook: K | K[], options: {
|
|
404
|
+
document?: boolean;
|
|
405
|
+
query?: boolean;
|
|
406
|
+
} | PostHookFn, fn?: PostHookFn): this;
|
|
407
|
+
/**
|
|
408
|
+
* Get pre hooks for a specific operation
|
|
409
|
+
*/
|
|
410
|
+
getPreHooks(hook: HookType): MiddlewareEntry$1[];
|
|
411
|
+
/**
|
|
412
|
+
* Get post hooks for a specific operation
|
|
413
|
+
*/
|
|
414
|
+
getPostHooks(hook: HookType): MiddlewareEntry$1[];
|
|
415
|
+
/**
|
|
416
|
+
* Add an index
|
|
417
|
+
*/
|
|
418
|
+
index(fields: Record<string, 1 | -1 | 'text' | '2dsphere'>, options?: Record<string, any>): this;
|
|
419
|
+
/**
|
|
420
|
+
* Get all indexes (Mongoose-compatible format: [fields, options][])
|
|
421
|
+
*/
|
|
422
|
+
indexes(): Array<[Record<string, 1 | -1>, Record<string, any> | undefined]>;
|
|
423
|
+
/**
|
|
424
|
+
* Apply a plugin
|
|
425
|
+
*/
|
|
426
|
+
plugin(fn: (schema: Schema<T>, options?: any) => void, options?: any): this;
|
|
427
|
+
/**
|
|
428
|
+
* Schema options (Mongoose-compatible property)
|
|
429
|
+
*/
|
|
430
|
+
get options(): SchemaOptions$1;
|
|
431
|
+
/**
|
|
432
|
+
* Original schema definition (Mongoose-compatible property)
|
|
433
|
+
*/
|
|
434
|
+
get obj(): SchemaDefinition;
|
|
435
|
+
/**
|
|
436
|
+
* Get/set schema options
|
|
437
|
+
*/
|
|
438
|
+
set<K extends keyof SchemaOptions$1>(key: K, value: SchemaOptions$1[K]): this;
|
|
439
|
+
set(options: SchemaOptions$1): this;
|
|
440
|
+
get<K extends keyof SchemaOptions$1>(key: K): SchemaOptions$1[K];
|
|
441
|
+
/**
|
|
442
|
+
* Validate a document against this schema
|
|
443
|
+
*/
|
|
444
|
+
validate(doc: Record<string, unknown>): Promise<{
|
|
445
|
+
valid: boolean;
|
|
446
|
+
errors: ValidationError[];
|
|
447
|
+
}>;
|
|
448
|
+
/**
|
|
449
|
+
* Cast a document to schema types
|
|
450
|
+
*/
|
|
451
|
+
cast(doc: Record<string, unknown>): T;
|
|
452
|
+
}
|
|
453
|
+
declare class VirtualBuilder {
|
|
454
|
+
private virtual;
|
|
455
|
+
constructor(virtual: VirtualType);
|
|
456
|
+
get(fn: () => any): this;
|
|
457
|
+
set(fn: (value: any) => void): this;
|
|
458
|
+
}
|
|
459
|
+
interface ValidationError {
|
|
460
|
+
path: string;
|
|
461
|
+
message: string;
|
|
462
|
+
kind: string;
|
|
463
|
+
value: unknown;
|
|
464
|
+
}
|
|
465
|
+
declare class MongooseValidationError extends Error {
|
|
466
|
+
errors: Map<string, ValidationError>;
|
|
467
|
+
constructor(message?: string);
|
|
468
|
+
addError(path: string, error: ValidationError): void;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* The $ namespace - Zod-style API for Mondoo
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```typescript
|
|
476
|
+
* import { $ } from 'mondoo'
|
|
477
|
+
*
|
|
478
|
+
* const userSchema = $.schema({
|
|
479
|
+
* name: $.string().required(),
|
|
480
|
+
* email: $.string().email(),
|
|
481
|
+
* age: $.number().min(0).max(150),
|
|
482
|
+
* role: $.enum(['admin', 'user', 'guest']),
|
|
483
|
+
* posts: $.array($.objectId().ref('Post'))
|
|
484
|
+
* })
|
|
485
|
+
*
|
|
486
|
+
* type User = $.infer<typeof userSchema>
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
type InferHelper = <T extends Schema<any>>() => T extends Schema<infer U> ? U : never;
|
|
491
|
+
interface SchemaOptions {
|
|
492
|
+
timestamps?: boolean;
|
|
493
|
+
versionKey?: boolean | string;
|
|
494
|
+
strict?: boolean | 'throw';
|
|
495
|
+
collection?: string;
|
|
496
|
+
discriminatorKey?: string;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* The $ namespace - TypeScript-first schema builder
|
|
500
|
+
*/
|
|
501
|
+
declare const $: {
|
|
502
|
+
/**
|
|
503
|
+
* Create a string schema type
|
|
504
|
+
* @example $.string().email().required()
|
|
505
|
+
*/
|
|
506
|
+
string: () => StringType<false>;
|
|
507
|
+
/**
|
|
508
|
+
* Create a number schema type
|
|
509
|
+
* @example $.number().min(0).max(100)
|
|
510
|
+
*/
|
|
511
|
+
number: () => NumberType<false>;
|
|
512
|
+
/**
|
|
513
|
+
* Create a boolean schema type
|
|
514
|
+
*/
|
|
515
|
+
boolean: () => BooleanType<false>;
|
|
516
|
+
/**
|
|
517
|
+
* Create a date schema type
|
|
518
|
+
* @example $.date().min(new Date('2020-01-01'))
|
|
519
|
+
*/
|
|
520
|
+
date: () => DateType<false>;
|
|
521
|
+
/**
|
|
522
|
+
* Create an ObjectId schema type
|
|
523
|
+
* @example $.objectId().ref('User')
|
|
524
|
+
*/
|
|
525
|
+
objectId: () => ObjectIdType<false, never>;
|
|
526
|
+
/**
|
|
527
|
+
* Create a buffer/binary schema type
|
|
528
|
+
*/
|
|
529
|
+
buffer: () => BufferType<false>;
|
|
530
|
+
/**
|
|
531
|
+
* Create a bigint schema type
|
|
532
|
+
*/
|
|
533
|
+
bigint: () => BigIntType<false>;
|
|
534
|
+
/**
|
|
535
|
+
* Create an array schema type
|
|
536
|
+
* @example $.array($.string())
|
|
537
|
+
*/
|
|
538
|
+
array: <T>(itemType: SchemaType<T, any>) => ArrayType<T, false>;
|
|
539
|
+
/**
|
|
540
|
+
* Create a nested object schema type
|
|
541
|
+
* @example $.object({ name: $.string(), age: $.number() })
|
|
542
|
+
*/
|
|
543
|
+
object: <T extends Record<string, SchemaType<any, any>>>(shape: T) => ObjectType<T, false>;
|
|
544
|
+
/**
|
|
545
|
+
* Create a map schema type (string keys, typed values)
|
|
546
|
+
* @example $.map($.number())
|
|
547
|
+
*/
|
|
548
|
+
map: <T>(valueType: SchemaType<T, any>) => MapType<T, false>;
|
|
549
|
+
/**
|
|
550
|
+
* Create an enum schema type
|
|
551
|
+
* @example $.enum(['admin', 'user', 'guest'])
|
|
552
|
+
*/
|
|
553
|
+
enum: <T extends readonly string[]>(values: T) => EnumType<T, false>;
|
|
554
|
+
/**
|
|
555
|
+
* Create a literal schema type
|
|
556
|
+
* @example $.literal('active')
|
|
557
|
+
*/
|
|
558
|
+
literal: <T extends string | number | boolean>(value: T) => LiteralType<T, false>;
|
|
559
|
+
/**
|
|
560
|
+
* Create a mixed/any schema type (no type checking)
|
|
561
|
+
*/
|
|
562
|
+
mixed: () => MixedType<false>;
|
|
563
|
+
/**
|
|
564
|
+
* Alias for mixed()
|
|
565
|
+
*/
|
|
566
|
+
any: () => MixedType<false>;
|
|
567
|
+
/**
|
|
568
|
+
* Create a new schema from a shape definition
|
|
569
|
+
* @example
|
|
570
|
+
* ```typescript
|
|
571
|
+
* const userSchema = $.schema({
|
|
572
|
+
* name: $.string().required(),
|
|
573
|
+
* email: $.string().email()
|
|
574
|
+
* })
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
schema: <T extends Record<string, SchemaType<any, any>>>(shape: T, options?: SchemaOptions) => Schema<InferObject<T>>;
|
|
578
|
+
/**
|
|
579
|
+
* Infer TypeScript type from schema (compile-time only)
|
|
580
|
+
* @example type User = $.infer<typeof userSchema>
|
|
581
|
+
*/
|
|
582
|
+
infer: InferHelper;
|
|
583
|
+
/**
|
|
584
|
+
* Infer input type (before transforms)
|
|
585
|
+
*/
|
|
586
|
+
input: InferHelper;
|
|
587
|
+
/**
|
|
588
|
+
* Infer output type (after transforms)
|
|
589
|
+
*/
|
|
590
|
+
output: InferHelper;
|
|
591
|
+
};
|
|
592
|
+
type $ = typeof $;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Document class - represents a single MongoDB document with change tracking
|
|
596
|
+
*/
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Internal document state for tracking changes and metadata
|
|
600
|
+
*/
|
|
601
|
+
interface DocumentInternal {
|
|
602
|
+
/** Set of paths that have been modified */
|
|
603
|
+
modifiedPaths: Set<string>;
|
|
604
|
+
/** Whether this is a new document (not yet saved) */
|
|
605
|
+
isNew: boolean;
|
|
606
|
+
/** Original values before modification (for dirty checking) */
|
|
607
|
+
originalValues: Map<string, unknown>;
|
|
608
|
+
/** Paths that have been populated with referenced documents */
|
|
609
|
+
populated: Map<string, ObjectId | ObjectId[]>;
|
|
610
|
+
/** Transaction session */
|
|
611
|
+
session: unknown | null;
|
|
612
|
+
/** Whether the document has been deleted */
|
|
613
|
+
wasDeleted: boolean;
|
|
614
|
+
/** Validation errors */
|
|
615
|
+
validationError: MongooseValidationError | null;
|
|
616
|
+
/** Paths that were explicitly marked as modified */
|
|
617
|
+
directModifiedPaths: Set<string>;
|
|
618
|
+
/** The schema for this document */
|
|
619
|
+
schema: Schema<any> | null;
|
|
620
|
+
/** Reference to the Model (will be set by Model class) */
|
|
621
|
+
model: any | null;
|
|
622
|
+
/** Version key value */
|
|
623
|
+
version: number;
|
|
624
|
+
/** Paths to select (projection) */
|
|
625
|
+
selected?: Record<string, 0 | 1>;
|
|
626
|
+
/** Whether strict mode is enabled */
|
|
627
|
+
strictMode: boolean | 'throw';
|
|
628
|
+
}
|
|
629
|
+
interface ToObjectOptions {
|
|
630
|
+
/** Include getters in output */
|
|
631
|
+
getters?: boolean;
|
|
632
|
+
/** Include virtuals in output */
|
|
633
|
+
virtuals?: boolean;
|
|
634
|
+
/** Include version key */
|
|
635
|
+
versionKey?: boolean;
|
|
636
|
+
/** Transform function */
|
|
637
|
+
transform?: (doc: Document<any>, ret: Record<string, unknown>, options: ToObjectOptions) => Record<string, unknown>;
|
|
638
|
+
/** Depopulate refs */
|
|
639
|
+
depopulate?: boolean;
|
|
640
|
+
/** Minimize output (remove empty objects) */
|
|
641
|
+
minimize?: boolean;
|
|
642
|
+
/** Flatten maps to plain objects */
|
|
643
|
+
flattenMaps?: boolean;
|
|
644
|
+
/** Use aliases */
|
|
645
|
+
aliases?: boolean;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Document class with Proxy-based change tracking
|
|
649
|
+
*/
|
|
650
|
+
declare class Document<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
651
|
+
/** Internal document data storage */
|
|
652
|
+
_doc: T;
|
|
653
|
+
/** Internal state object */
|
|
654
|
+
$__: DocumentInternal;
|
|
655
|
+
/** Whether this document is new (not yet saved to database) */
|
|
656
|
+
get isNew(): boolean;
|
|
657
|
+
set isNew(value: boolean);
|
|
658
|
+
/** Whether this document has been deleted */
|
|
659
|
+
$isDeleted: boolean;
|
|
660
|
+
/** The document's _id */
|
|
661
|
+
get _id(): ObjectId | undefined;
|
|
662
|
+
set _id(value: ObjectId | undefined);
|
|
663
|
+
/** The document's id as a string */
|
|
664
|
+
get id(): string | undefined;
|
|
665
|
+
/**
|
|
666
|
+
* Create a new Document instance
|
|
667
|
+
*/
|
|
668
|
+
constructor(doc?: Partial<T>, schema?: Schema<T>, isNew?: boolean);
|
|
669
|
+
/**
|
|
670
|
+
* Create a Proxy wrapper for change tracking
|
|
671
|
+
*/
|
|
672
|
+
private _createProxy;
|
|
673
|
+
/**
|
|
674
|
+
* Mark a path as modified
|
|
675
|
+
*/
|
|
676
|
+
markModified(path: string): this;
|
|
677
|
+
/**
|
|
678
|
+
* Check if a path (or any path if not specified) has been modified
|
|
679
|
+
*/
|
|
680
|
+
isModified(path?: string | string[]): boolean;
|
|
681
|
+
/**
|
|
682
|
+
* Get all modified paths
|
|
683
|
+
*/
|
|
684
|
+
modifiedPaths(options?: {
|
|
685
|
+
includeChildren?: boolean;
|
|
686
|
+
}): string[];
|
|
687
|
+
/**
|
|
688
|
+
* Get paths that were directly modified (not parent paths)
|
|
689
|
+
*/
|
|
690
|
+
directModifiedPaths(): string[];
|
|
691
|
+
/**
|
|
692
|
+
* Helper to get nested paths from an object
|
|
693
|
+
*/
|
|
694
|
+
private _getNestedPaths;
|
|
695
|
+
/**
|
|
696
|
+
* Unmark a path as modified
|
|
697
|
+
*/
|
|
698
|
+
unmarkModified(path: string): this;
|
|
699
|
+
/**
|
|
700
|
+
* Check if document is selected for a path
|
|
701
|
+
*/
|
|
702
|
+
isSelected(path: string): boolean;
|
|
703
|
+
/**
|
|
704
|
+
* Check if document is initialized
|
|
705
|
+
*/
|
|
706
|
+
isInit(path: string): boolean;
|
|
707
|
+
/**
|
|
708
|
+
* Save the document to the database
|
|
709
|
+
* Note: This is a placeholder - actual implementation will be in Model
|
|
710
|
+
*/
|
|
711
|
+
save(options?: {
|
|
712
|
+
validateBeforeSave?: boolean;
|
|
713
|
+
session?: unknown;
|
|
714
|
+
}): Promise<this>;
|
|
715
|
+
/**
|
|
716
|
+
* Run schema validators on this document
|
|
717
|
+
*/
|
|
718
|
+
validate(pathsToValidate?: string[]): Promise<void>;
|
|
719
|
+
/**
|
|
720
|
+
* Validate a specific path synchronously
|
|
721
|
+
* Note: This is named for Mongoose compatibility but may not support async validators
|
|
722
|
+
*/
|
|
723
|
+
validateSync(paths?: string[]): ValidationError[] | null;
|
|
724
|
+
/**
|
|
725
|
+
* Get the validation error for this document
|
|
726
|
+
*/
|
|
727
|
+
get errors(): Map<string, ValidationError> | undefined;
|
|
728
|
+
/**
|
|
729
|
+
* Convert document to a plain JavaScript object
|
|
730
|
+
*/
|
|
731
|
+
toObject(options?: ToObjectOptions): Record<string, unknown>;
|
|
732
|
+
/**
|
|
733
|
+
* Convert document to JSON
|
|
734
|
+
*/
|
|
735
|
+
toJSON(options?: ToObjectOptions): Record<string, unknown>;
|
|
736
|
+
/**
|
|
737
|
+
* Helper to minimize an object (remove empty nested objects)
|
|
738
|
+
*/
|
|
739
|
+
private _minimize;
|
|
740
|
+
/**
|
|
741
|
+
* Helper to flatten Maps to plain objects
|
|
742
|
+
*/
|
|
743
|
+
private _flattenMaps;
|
|
744
|
+
/**
|
|
745
|
+
* Get a value by path (supports dot notation)
|
|
746
|
+
*/
|
|
747
|
+
get(path: string, type?: any): unknown;
|
|
748
|
+
/**
|
|
749
|
+
* Set a value by path (supports dot notation) with change tracking
|
|
750
|
+
*/
|
|
751
|
+
set(path: string | Record<string, unknown>, val?: unknown): this;
|
|
752
|
+
/**
|
|
753
|
+
* Helper to set a nested value by path
|
|
754
|
+
*/
|
|
755
|
+
private _setNestedValue;
|
|
756
|
+
/**
|
|
757
|
+
* Populate referenced documents
|
|
758
|
+
* Note: This is a placeholder - actual implementation requires Model
|
|
759
|
+
*/
|
|
760
|
+
populate(path: string | string[] | Record<string, any>): Promise<this>;
|
|
761
|
+
/**
|
|
762
|
+
* Get the original ObjectId for a populated path
|
|
763
|
+
*/
|
|
764
|
+
populated(path: string): ObjectId | ObjectId[] | undefined;
|
|
765
|
+
/**
|
|
766
|
+
* Restore the original ObjectId for a populated path
|
|
767
|
+
*/
|
|
768
|
+
depopulate(path?: string): this;
|
|
769
|
+
/**
|
|
770
|
+
* Mark a path as populated with the original ObjectId
|
|
771
|
+
* @internal
|
|
772
|
+
*/
|
|
773
|
+
_markPopulated(path: string, originalId: ObjectId | ObjectId[]): void;
|
|
774
|
+
/**
|
|
775
|
+
* Get or set the transaction session
|
|
776
|
+
*/
|
|
777
|
+
$session(): unknown | null;
|
|
778
|
+
$session(session: unknown | null): this;
|
|
779
|
+
/**
|
|
780
|
+
* Get a specific field's value (alias for get)
|
|
781
|
+
*/
|
|
782
|
+
$get(path: string): unknown;
|
|
783
|
+
/**
|
|
784
|
+
* Set a specific field's value (alias for set)
|
|
785
|
+
*/
|
|
786
|
+
$set(path: string | Record<string, unknown>, val?: unknown): this;
|
|
787
|
+
/**
|
|
788
|
+
* Check if a path exists in the document
|
|
789
|
+
*/
|
|
790
|
+
$has(path: string): boolean;
|
|
791
|
+
/**
|
|
792
|
+
* Delete a path from the document
|
|
793
|
+
*/
|
|
794
|
+
$unset(path: string | string[]): this;
|
|
795
|
+
/**
|
|
796
|
+
* Increment a numeric field
|
|
797
|
+
*/
|
|
798
|
+
$inc(path: string, val?: number): this;
|
|
799
|
+
/**
|
|
800
|
+
* Check equality with another document or object
|
|
801
|
+
*/
|
|
802
|
+
equals(doc: Document<T> | Record<string, unknown>): boolean;
|
|
803
|
+
/**
|
|
804
|
+
* Get the document's schema
|
|
805
|
+
*/
|
|
806
|
+
get schema(): Schema<T> | null;
|
|
807
|
+
/**
|
|
808
|
+
* Get the document's model name
|
|
809
|
+
*/
|
|
810
|
+
get modelName(): string | undefined;
|
|
811
|
+
/**
|
|
812
|
+
* Get the collection for this document
|
|
813
|
+
*/
|
|
814
|
+
get collection(): unknown | undefined;
|
|
815
|
+
/**
|
|
816
|
+
* Get the database for this document
|
|
817
|
+
*/
|
|
818
|
+
get db(): unknown | undefined;
|
|
819
|
+
/**
|
|
820
|
+
* Override for Array.isArray checks
|
|
821
|
+
*/
|
|
822
|
+
get [Symbol.toStringTag](): string;
|
|
823
|
+
/**
|
|
824
|
+
* Create a copy of this document
|
|
825
|
+
*/
|
|
826
|
+
$clone(): Document<T>;
|
|
827
|
+
/**
|
|
828
|
+
* Reset all modifications
|
|
829
|
+
*/
|
|
830
|
+
$reset(): this;
|
|
831
|
+
/**
|
|
832
|
+
* Mark document as deleted
|
|
833
|
+
*/
|
|
834
|
+
$markDeleted(val?: boolean): void;
|
|
835
|
+
/**
|
|
836
|
+
* Check if document was deleted
|
|
837
|
+
*/
|
|
838
|
+
$wasDeleted(): boolean;
|
|
839
|
+
/**
|
|
840
|
+
* Get parent document (for subdocuments)
|
|
841
|
+
*/
|
|
842
|
+
parent(): Document<any> | undefined;
|
|
843
|
+
/**
|
|
844
|
+
* Get root document (for nested subdocuments)
|
|
845
|
+
*/
|
|
846
|
+
$root(): Document<any>;
|
|
847
|
+
/**
|
|
848
|
+
* Remove this document from the database
|
|
849
|
+
* Note: Placeholder - actual implementation in Model
|
|
850
|
+
*/
|
|
851
|
+
deleteOne(options?: {
|
|
852
|
+
session?: unknown;
|
|
853
|
+
}): Promise<this>;
|
|
854
|
+
/**
|
|
855
|
+
* Alias for deleteOne
|
|
856
|
+
*/
|
|
857
|
+
remove(options?: {
|
|
858
|
+
session?: unknown;
|
|
859
|
+
}): Promise<this>;
|
|
860
|
+
/**
|
|
861
|
+
* Update this document
|
|
862
|
+
* Note: Placeholder - actual implementation in Model
|
|
863
|
+
*/
|
|
864
|
+
updateOne(update: Record<string, unknown>, options?: {
|
|
865
|
+
session?: unknown;
|
|
866
|
+
}): Promise<unknown>;
|
|
867
|
+
/**
|
|
868
|
+
* Overwrite this document's data
|
|
869
|
+
*/
|
|
870
|
+
overwrite(obj: Partial<T>): this;
|
|
871
|
+
/**
|
|
872
|
+
* Replaces current document with another
|
|
873
|
+
*/
|
|
874
|
+
$replaceWith(replacement: Partial<T>): this;
|
|
875
|
+
/**
|
|
876
|
+
* Inspect for console logging
|
|
877
|
+
*/
|
|
878
|
+
inspect(): Record<string, unknown>;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Query Builder - Chainable query construction for Mondoo
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* ```typescript
|
|
886
|
+
* // Basic query
|
|
887
|
+
* const users = await User.find({ age: { $gte: 18 } })
|
|
888
|
+
*
|
|
889
|
+
* // Chained query
|
|
890
|
+
* const users = await User
|
|
891
|
+
* .find()
|
|
892
|
+
* .where('age').gte(18)
|
|
893
|
+
* .where('role').in(['admin', 'user'])
|
|
894
|
+
* .select('name email')
|
|
895
|
+
* .sort({ createdAt: -1 })
|
|
896
|
+
* .limit(10)
|
|
897
|
+
* .lean()
|
|
898
|
+
* ```
|
|
899
|
+
*/
|
|
900
|
+
/**
|
|
901
|
+
* Query operation types
|
|
902
|
+
*/
|
|
903
|
+
type QueryOperation = 'find' | 'findOne' | 'findOneAndUpdate' | 'findOneAndDelete' | 'findOneAndReplace' | 'updateOne' | 'updateMany' | 'deleteOne' | 'deleteMany' | 'count' | 'countDocuments' | 'estimatedDocumentCount' | 'distinct';
|
|
904
|
+
/**
|
|
905
|
+
* Filter operators for queries
|
|
906
|
+
*/
|
|
907
|
+
interface FilterOperators<T = unknown> {
|
|
908
|
+
$eq?: T;
|
|
909
|
+
$ne?: T;
|
|
910
|
+
$gt?: T;
|
|
911
|
+
$gte?: T;
|
|
912
|
+
$lt?: T;
|
|
913
|
+
$lte?: T;
|
|
914
|
+
$in?: T[];
|
|
915
|
+
$nin?: T[];
|
|
916
|
+
$exists?: boolean;
|
|
917
|
+
$regex?: RegExp | string;
|
|
918
|
+
$not?: FilterOperators<T>;
|
|
919
|
+
$elemMatch?: Record<string, unknown>;
|
|
920
|
+
$size?: number;
|
|
921
|
+
$all?: T[];
|
|
922
|
+
$type?: string | number;
|
|
923
|
+
$mod?: [number, number];
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Root query filter type
|
|
927
|
+
*/
|
|
928
|
+
type FilterQuery<T> = {
|
|
929
|
+
[P in keyof T]?: T[P] | FilterOperators<T[P]>;
|
|
930
|
+
} & {
|
|
931
|
+
$and?: FilterQuery<T>[];
|
|
932
|
+
$or?: FilterQuery<T>[];
|
|
933
|
+
$nor?: FilterQuery<T>[];
|
|
934
|
+
$not?: FilterQuery<T>;
|
|
935
|
+
$text?: {
|
|
936
|
+
$search: string;
|
|
937
|
+
$language?: string;
|
|
938
|
+
$caseSensitive?: boolean;
|
|
939
|
+
};
|
|
940
|
+
$where?: string | Function;
|
|
941
|
+
$comment?: string;
|
|
942
|
+
};
|
|
943
|
+
/**
|
|
944
|
+
* Population options
|
|
945
|
+
*/
|
|
946
|
+
interface PopulateOptions$1 {
|
|
947
|
+
path: string;
|
|
948
|
+
select?: string | string[] | Record<string, 0 | 1>;
|
|
949
|
+
match?: Record<string, unknown>;
|
|
950
|
+
model?: string;
|
|
951
|
+
options?: QueryOptions;
|
|
952
|
+
populate?: PopulateOptions$1 | PopulateOptions$1[] | string;
|
|
953
|
+
justOne?: boolean;
|
|
954
|
+
localField?: string;
|
|
955
|
+
foreignField?: string;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Query options (sort, skip, limit, etc.)
|
|
959
|
+
*/
|
|
960
|
+
interface QueryOptions {
|
|
961
|
+
lean?: boolean;
|
|
962
|
+
populate?: string | string[] | PopulateOptions$1 | PopulateOptions$1[];
|
|
963
|
+
select?: string | Record<string, 0 | 1>;
|
|
964
|
+
sort?: string | Record<string, 1 | -1 | 'asc' | 'desc'>;
|
|
965
|
+
limit?: number;
|
|
966
|
+
skip?: number;
|
|
967
|
+
projection?: Record<string, 0 | 1>;
|
|
968
|
+
new?: boolean;
|
|
969
|
+
upsert?: boolean;
|
|
970
|
+
session?: unknown;
|
|
971
|
+
timestamps?: boolean;
|
|
972
|
+
strict?: boolean;
|
|
973
|
+
batchSize?: number;
|
|
974
|
+
collation?: {
|
|
975
|
+
locale: string;
|
|
976
|
+
caseLevel?: boolean;
|
|
977
|
+
caseFirst?: 'upper' | 'lower' | 'off';
|
|
978
|
+
strength?: 1 | 2 | 3 | 4 | 5;
|
|
979
|
+
numericOrdering?: boolean;
|
|
980
|
+
alternate?: 'non-ignorable' | 'shifted';
|
|
981
|
+
maxVariable?: 'punct' | 'space';
|
|
982
|
+
backwards?: boolean;
|
|
983
|
+
};
|
|
984
|
+
hint?: Record<string, 1 | -1> | string;
|
|
985
|
+
maxTimeMS?: number;
|
|
986
|
+
readPreference?: string;
|
|
987
|
+
comment?: string;
|
|
988
|
+
tailable?: boolean;
|
|
989
|
+
awaitData?: boolean;
|
|
990
|
+
allowDiskUse?: boolean;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Model interface (placeholder - will be replaced by actual Model type)
|
|
994
|
+
*/
|
|
995
|
+
interface ModelLike$1<T = unknown> {
|
|
996
|
+
collection?: {
|
|
997
|
+
find(filter: FilterQuery<T>, options?: QueryOptions): Promise<T[]>;
|
|
998
|
+
findOne(filter: FilterQuery<T>, options?: QueryOptions): Promise<T | null>;
|
|
999
|
+
countDocuments(filter: FilterQuery<T>): Promise<number>;
|
|
1000
|
+
estimatedDocumentCount(): Promise<number>;
|
|
1001
|
+
distinct(field: string, filter?: FilterQuery<T>): Promise<unknown[]>;
|
|
1002
|
+
};
|
|
1003
|
+
modelName?: string;
|
|
1004
|
+
schema?: {
|
|
1005
|
+
getPreHooks(hook: string): Array<{
|
|
1006
|
+
fn: Function;
|
|
1007
|
+
options?: {
|
|
1008
|
+
query?: boolean;
|
|
1009
|
+
};
|
|
1010
|
+
}>;
|
|
1011
|
+
getPostHooks(hook: string): Array<{
|
|
1012
|
+
fn: Function;
|
|
1013
|
+
options?: {
|
|
1014
|
+
query?: boolean;
|
|
1015
|
+
};
|
|
1016
|
+
}>;
|
|
1017
|
+
};
|
|
1018
|
+
hydrate?(doc: unknown): T;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Chainable query builder for Mondoo
|
|
1022
|
+
*
|
|
1023
|
+
* The Query class is LAZY - it doesn't execute until:
|
|
1024
|
+
* - exec() is called
|
|
1025
|
+
* - then() is called (await/Promise chain)
|
|
1026
|
+
* - A terminal method is called
|
|
1027
|
+
*
|
|
1028
|
+
* @template TDoc - The document type
|
|
1029
|
+
* @template TResult - The expected result type
|
|
1030
|
+
*/
|
|
1031
|
+
declare class Query<TDoc = unknown, TResult = TDoc> implements PromiseLike<TResult> {
|
|
1032
|
+
/** The query filter object */
|
|
1033
|
+
private _filter;
|
|
1034
|
+
/** Fields to select/exclude (projection) */
|
|
1035
|
+
private _projection;
|
|
1036
|
+
/** Query options (sort, skip, limit, etc.) */
|
|
1037
|
+
private _options;
|
|
1038
|
+
/** Population options */
|
|
1039
|
+
private _populate;
|
|
1040
|
+
/** Whether to return plain objects */
|
|
1041
|
+
private _lean;
|
|
1042
|
+
/** Reference to the Model */
|
|
1043
|
+
private _model;
|
|
1044
|
+
/** The query operation type */
|
|
1045
|
+
private _operation;
|
|
1046
|
+
/** Current path for chained conditions (where().equals()) */
|
|
1047
|
+
private _currentPath;
|
|
1048
|
+
/** Update document for update operations */
|
|
1049
|
+
private _update;
|
|
1050
|
+
/** Distinct field for distinct queries */
|
|
1051
|
+
private _distinctField;
|
|
1052
|
+
/**
|
|
1053
|
+
* Create a new Query instance
|
|
1054
|
+
* @param model - The model to query against
|
|
1055
|
+
* @param operation - The query operation type
|
|
1056
|
+
* @param filter - Initial filter conditions
|
|
1057
|
+
* @param update - Update document for update operations
|
|
1058
|
+
*/
|
|
1059
|
+
constructor(model: ModelLike$1<TDoc>, operation?: QueryOperation, filter?: FilterQuery<TDoc>, update?: Record<string, unknown>);
|
|
1060
|
+
/**
|
|
1061
|
+
* Create a find query
|
|
1062
|
+
*/
|
|
1063
|
+
static find<T>(model: ModelLike$1<T>, filter?: FilterQuery<T>): Query<T, T[]>;
|
|
1064
|
+
/**
|
|
1065
|
+
* Create a findOne query
|
|
1066
|
+
*/
|
|
1067
|
+
static findOne<T>(model: ModelLike$1<T>, filter?: FilterQuery<T>): Query<T, T | null>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Create a countDocuments query
|
|
1070
|
+
*/
|
|
1071
|
+
static countDocuments<T>(model: ModelLike$1<T>, filter?: FilterQuery<T>): Query<T, number>;
|
|
1072
|
+
/**
|
|
1073
|
+
* Create an estimatedDocumentCount query
|
|
1074
|
+
*/
|
|
1075
|
+
static estimatedDocumentCount<T>(model: ModelLike$1<T>): Query<T, number>;
|
|
1076
|
+
/**
|
|
1077
|
+
* Create a distinct query
|
|
1078
|
+
*/
|
|
1079
|
+
static distinct<T>(model: ModelLike$1<T>, field: string, filter?: FilterQuery<T>): Query<T, unknown[]>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Start building a condition on a path or add filter conditions
|
|
1082
|
+
* @param path - The document path to query, or an object of conditions
|
|
1083
|
+
* @param val - Optional direct value (Mongoose-style shorthand)
|
|
1084
|
+
* @example query.where('age').gte(18)
|
|
1085
|
+
* @example query.where({ name: 'John', age: 30 })
|
|
1086
|
+
* @example query.where('name', 'John')
|
|
1087
|
+
*/
|
|
1088
|
+
where(path: string, val?: unknown): this;
|
|
1089
|
+
where(obj: Record<string, unknown>): this;
|
|
1090
|
+
/**
|
|
1091
|
+
* Add an equals condition
|
|
1092
|
+
* @param val - The value to match
|
|
1093
|
+
*/
|
|
1094
|
+
equals<V>(val: V): this;
|
|
1095
|
+
/**
|
|
1096
|
+
* Alias for equals
|
|
1097
|
+
*/
|
|
1098
|
+
eq<V>(val: V): this;
|
|
1099
|
+
/**
|
|
1100
|
+
* Add a greater-than condition
|
|
1101
|
+
* @param val - The minimum value (exclusive)
|
|
1102
|
+
*/
|
|
1103
|
+
gt(val: number): this;
|
|
1104
|
+
gt(path: string, val: number): this;
|
|
1105
|
+
/**
|
|
1106
|
+
* Add a greater-than-or-equal condition
|
|
1107
|
+
* @param val - The minimum value (inclusive)
|
|
1108
|
+
*/
|
|
1109
|
+
gte(val: number): this;
|
|
1110
|
+
gte(path: string, val: number): this;
|
|
1111
|
+
/**
|
|
1112
|
+
* Add a less-than condition
|
|
1113
|
+
* @param val - The maximum value (exclusive)
|
|
1114
|
+
*/
|
|
1115
|
+
lt(val: number): this;
|
|
1116
|
+
lt(path: string, val: number): this;
|
|
1117
|
+
/**
|
|
1118
|
+
* Add a less-than-or-equal condition
|
|
1119
|
+
* @param val - The maximum value (inclusive)
|
|
1120
|
+
*/
|
|
1121
|
+
lte(val: number): this;
|
|
1122
|
+
lte(path: string, val: number): this;
|
|
1123
|
+
/**
|
|
1124
|
+
* Add a not-equal condition
|
|
1125
|
+
* @param val - The value to not match
|
|
1126
|
+
*/
|
|
1127
|
+
ne<V>(val: V): this;
|
|
1128
|
+
ne<V>(path: string, val: V): this;
|
|
1129
|
+
/**
|
|
1130
|
+
* Add an $in condition (value must be in array)
|
|
1131
|
+
* @param vals - Array of acceptable values
|
|
1132
|
+
*/
|
|
1133
|
+
in<V>(vals: V[]): this;
|
|
1134
|
+
in<V>(path: string, vals: V[]): this;
|
|
1135
|
+
/**
|
|
1136
|
+
* Add a $nin condition (value must not be in array)
|
|
1137
|
+
* @param vals - Array of unacceptable values
|
|
1138
|
+
*/
|
|
1139
|
+
nin<V>(vals: V[]): this;
|
|
1140
|
+
nin<V>(path: string, vals: V[]): this;
|
|
1141
|
+
/**
|
|
1142
|
+
* Add an $exists condition
|
|
1143
|
+
* @param exists - Whether the field must exist
|
|
1144
|
+
*/
|
|
1145
|
+
exists(exists?: boolean): this;
|
|
1146
|
+
exists(path: string, exists?: boolean): this;
|
|
1147
|
+
/**
|
|
1148
|
+
* Add a $regex condition
|
|
1149
|
+
* @param pattern - The regex pattern to match
|
|
1150
|
+
* @param flags - Optional regex flags
|
|
1151
|
+
*/
|
|
1152
|
+
regex(pattern: RegExp | string, flags?: string): this;
|
|
1153
|
+
regex(path: string, pattern: RegExp | string, flags?: string): this;
|
|
1154
|
+
/**
|
|
1155
|
+
* Add an $elemMatch condition for arrays
|
|
1156
|
+
* @param criteria - The criteria for matching array elements
|
|
1157
|
+
*/
|
|
1158
|
+
elemMatch(criteria: Record<string, unknown>): this;
|
|
1159
|
+
elemMatch(path: string, criteria: Record<string, unknown>): this;
|
|
1160
|
+
/**
|
|
1161
|
+
* Add a $size condition for arrays
|
|
1162
|
+
* @param n - The exact array size to match
|
|
1163
|
+
*/
|
|
1164
|
+
size(n: number): this;
|
|
1165
|
+
size(path: string, n: number): this;
|
|
1166
|
+
/**
|
|
1167
|
+
* Add an $all condition for arrays (must contain all values)
|
|
1168
|
+
* @param arr - Array of values that must all be present
|
|
1169
|
+
*/
|
|
1170
|
+
all<V>(arr: V[]): this;
|
|
1171
|
+
all<V>(path: string, arr: V[]): this;
|
|
1172
|
+
/**
|
|
1173
|
+
* Add a $mod condition
|
|
1174
|
+
* @param divisor - The divisor
|
|
1175
|
+
* @param remainder - The expected remainder
|
|
1176
|
+
*/
|
|
1177
|
+
mod(divisor: number, remainder: number): this;
|
|
1178
|
+
mod(path: string, divisor: number, remainder: number): this;
|
|
1179
|
+
/**
|
|
1180
|
+
* Add conditions using $and
|
|
1181
|
+
* @param conditions - Array of conditions to AND together
|
|
1182
|
+
*/
|
|
1183
|
+
and(conditions: FilterQuery<TDoc>[]): this;
|
|
1184
|
+
/**
|
|
1185
|
+
* Add conditions using $or
|
|
1186
|
+
* @param conditions - Array of conditions to OR together
|
|
1187
|
+
*/
|
|
1188
|
+
or(conditions: FilterQuery<TDoc>[]): this;
|
|
1189
|
+
/**
|
|
1190
|
+
* Add conditions using $nor
|
|
1191
|
+
* @param conditions - Array of conditions to NOR together
|
|
1192
|
+
*/
|
|
1193
|
+
nor(conditions: FilterQuery<TDoc>[]): this;
|
|
1194
|
+
/**
|
|
1195
|
+
* Set fields to select (projection)
|
|
1196
|
+
* @param fields - Fields to include/exclude
|
|
1197
|
+
* @example query.select('name email') // include name and email
|
|
1198
|
+
* @example query.select('-password') // exclude password
|
|
1199
|
+
* @example query.select({ name: 1, email: 1 }) // include name and email
|
|
1200
|
+
* @example query.select(['name', 'email']) // include name and email
|
|
1201
|
+
*/
|
|
1202
|
+
select(fields: string | string[] | Record<string, 0 | 1>): this;
|
|
1203
|
+
/**
|
|
1204
|
+
* Alias for select
|
|
1205
|
+
*/
|
|
1206
|
+
projection(fields: string | string[] | Record<string, 0 | 1>): this;
|
|
1207
|
+
/**
|
|
1208
|
+
* Set sort order
|
|
1209
|
+
* @param order - Sort specification
|
|
1210
|
+
* @example query.sort({ createdAt: -1 }) // descending
|
|
1211
|
+
* @example query.sort('name -createdAt') // name asc, createdAt desc
|
|
1212
|
+
* @example query.sort([['name', 1], ['createdAt', -1]])
|
|
1213
|
+
*/
|
|
1214
|
+
sort(order: string | Record<string, 1 | -1 | 'asc' | 'desc'> | [string, 1 | -1 | 'asc' | 'desc'][]): this;
|
|
1215
|
+
/**
|
|
1216
|
+
* Set the maximum number of documents to return
|
|
1217
|
+
* @param n - The maximum number of documents
|
|
1218
|
+
*/
|
|
1219
|
+
limit(n: number): this;
|
|
1220
|
+
/**
|
|
1221
|
+
* Set the number of documents to skip
|
|
1222
|
+
* @param n - The number of documents to skip
|
|
1223
|
+
*/
|
|
1224
|
+
skip(n: number): this;
|
|
1225
|
+
/**
|
|
1226
|
+
* Enable lean mode - return plain JavaScript objects instead of Mondoo documents
|
|
1227
|
+
* @param lean - Whether to enable lean mode (default: true)
|
|
1228
|
+
*/
|
|
1229
|
+
lean<LeanResult = TResult>(lean?: boolean): Query<TDoc, LeanResult>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Add population for referenced documents
|
|
1232
|
+
* @param path - The path to populate, or population options
|
|
1233
|
+
* @param select - Optional fields to select in populated documents
|
|
1234
|
+
* @param options - Additional population options
|
|
1235
|
+
*/
|
|
1236
|
+
populate(path: string | PopulateOptions$1 | PopulateOptions$1[], select?: string | string[] | Record<string, 0 | 1>, options?: Partial<PopulateOptions$1>): this;
|
|
1237
|
+
/**
|
|
1238
|
+
* Set the MongoDB session for transactions
|
|
1239
|
+
* @param clientSession - The client session
|
|
1240
|
+
*/
|
|
1241
|
+
session(clientSession: unknown): this;
|
|
1242
|
+
/**
|
|
1243
|
+
* Set batch size for cursor iteration
|
|
1244
|
+
* @param size - The batch size
|
|
1245
|
+
*/
|
|
1246
|
+
batchSize(size: number): this;
|
|
1247
|
+
/**
|
|
1248
|
+
* Set collation options
|
|
1249
|
+
* @param collation - The collation options
|
|
1250
|
+
*/
|
|
1251
|
+
collation(collation: QueryOptions['collation']): this;
|
|
1252
|
+
/**
|
|
1253
|
+
* Set index hint
|
|
1254
|
+
* @param hint - The index hint
|
|
1255
|
+
*/
|
|
1256
|
+
hint(hint: Record<string, 1 | -1> | string): this;
|
|
1257
|
+
/**
|
|
1258
|
+
* Set maximum execution time
|
|
1259
|
+
* @param ms - Maximum time in milliseconds
|
|
1260
|
+
*/
|
|
1261
|
+
maxTimeMS(ms: number): this;
|
|
1262
|
+
/**
|
|
1263
|
+
* Set read preference
|
|
1264
|
+
* @param pref - The read preference
|
|
1265
|
+
* @param tags - Optional read preference tags
|
|
1266
|
+
*/
|
|
1267
|
+
read(pref: string, tags?: unknown[]): this;
|
|
1268
|
+
/**
|
|
1269
|
+
* Add a comment to the query
|
|
1270
|
+
* @param comment - The comment string
|
|
1271
|
+
*/
|
|
1272
|
+
comment(val: string): this;
|
|
1273
|
+
/**
|
|
1274
|
+
* Create a tailable cursor
|
|
1275
|
+
* @param tailable - Whether the cursor is tailable
|
|
1276
|
+
* @param awaitData - Whether to await data
|
|
1277
|
+
*/
|
|
1278
|
+
tailable(tailable?: boolean, awaitData?: boolean): this;
|
|
1279
|
+
/**
|
|
1280
|
+
* Allow disk use for large sorts
|
|
1281
|
+
* @param val - Whether to allow disk use
|
|
1282
|
+
*/
|
|
1283
|
+
allowDiskUse(val?: boolean): this;
|
|
1284
|
+
/**
|
|
1285
|
+
* Set all query options at once
|
|
1286
|
+
* @param options - The options object
|
|
1287
|
+
*/
|
|
1288
|
+
setOptions(options: QueryOptions): this;
|
|
1289
|
+
/**
|
|
1290
|
+
* Set the update document
|
|
1291
|
+
* @param update - The update document
|
|
1292
|
+
*/
|
|
1293
|
+
setUpdate(update: Record<string, unknown>): this;
|
|
1294
|
+
/**
|
|
1295
|
+
* Merge another filter or query into this query
|
|
1296
|
+
* @param source - The filter or query to merge
|
|
1297
|
+
*/
|
|
1298
|
+
merge(source: Query<TDoc, unknown> | FilterQuery<TDoc>): this;
|
|
1299
|
+
/**
|
|
1300
|
+
* Set the entire filter
|
|
1301
|
+
* @param filter - The new filter
|
|
1302
|
+
*/
|
|
1303
|
+
setQuery(filter: FilterQuery<TDoc>): this;
|
|
1304
|
+
/**
|
|
1305
|
+
* Get the current filter
|
|
1306
|
+
*/
|
|
1307
|
+
getFilter(): FilterQuery<TDoc>;
|
|
1308
|
+
/**
|
|
1309
|
+
* Alias for getFilter
|
|
1310
|
+
*/
|
|
1311
|
+
getQuery(): FilterQuery<TDoc>;
|
|
1312
|
+
/**
|
|
1313
|
+
* Get the current options
|
|
1314
|
+
*/
|
|
1315
|
+
getOptions(): QueryOptions;
|
|
1316
|
+
/**
|
|
1317
|
+
* Get the current projection
|
|
1318
|
+
*/
|
|
1319
|
+
getProjection(): Record<string, 0 | 1> | null;
|
|
1320
|
+
/**
|
|
1321
|
+
* Get the population options
|
|
1322
|
+
*/
|
|
1323
|
+
getPopulate(): PopulateOptions$1[];
|
|
1324
|
+
/**
|
|
1325
|
+
* Get the update document
|
|
1326
|
+
*/
|
|
1327
|
+
getUpdate(): Record<string, unknown> | null;
|
|
1328
|
+
/**
|
|
1329
|
+
* Get the query operation type
|
|
1330
|
+
*/
|
|
1331
|
+
op(): QueryOperation;
|
|
1332
|
+
/**
|
|
1333
|
+
* Get the model
|
|
1334
|
+
*/
|
|
1335
|
+
model(): ModelLike$1<TDoc>;
|
|
1336
|
+
/**
|
|
1337
|
+
* Clone this query
|
|
1338
|
+
*/
|
|
1339
|
+
clone(): Query<TDoc, TResult>;
|
|
1340
|
+
/**
|
|
1341
|
+
* Execute the query and return a Promise
|
|
1342
|
+
*/
|
|
1343
|
+
exec(): Promise<TResult>;
|
|
1344
|
+
/**
|
|
1345
|
+
* Make the query thenable (allows await/Promise chain)
|
|
1346
|
+
*/
|
|
1347
|
+
then<TFulfilled = TResult, TRejected = never>(onfulfilled?: ((value: TResult) => TFulfilled | PromiseLike<TFulfilled>) | null, onrejected?: ((reason: unknown) => TRejected | PromiseLike<TRejected>) | null): Promise<TFulfilled | TRejected>;
|
|
1348
|
+
/**
|
|
1349
|
+
* Handle rejection
|
|
1350
|
+
*/
|
|
1351
|
+
catch<TRejected = never>(onrejected?: ((reason: unknown) => TRejected | PromiseLike<TRejected>) | null): Promise<TResult | TRejected>;
|
|
1352
|
+
/**
|
|
1353
|
+
* Finally handler
|
|
1354
|
+
*/
|
|
1355
|
+
finally(onfinally?: (() => void) | null): Promise<TResult>;
|
|
1356
|
+
/**
|
|
1357
|
+
* Return a cursor for iteration (placeholder)
|
|
1358
|
+
* This returns an async iterable that can be used with for-await-of
|
|
1359
|
+
*/
|
|
1360
|
+
cursor(): QueryCursor<TDoc>;
|
|
1361
|
+
/**
|
|
1362
|
+
* Count documents matching the query
|
|
1363
|
+
*/
|
|
1364
|
+
countDocuments(): Query<TDoc, number>;
|
|
1365
|
+
/**
|
|
1366
|
+
* Explain the query execution plan
|
|
1367
|
+
*/
|
|
1368
|
+
explain(verbosity?: 'queryPlanner' | 'executionStats' | 'allPlansExecution'): Promise<unknown>;
|
|
1369
|
+
/**
|
|
1370
|
+
* Convert query to string representation
|
|
1371
|
+
*/
|
|
1372
|
+
toString(): string;
|
|
1373
|
+
/**
|
|
1374
|
+
* Set a condition on the current path
|
|
1375
|
+
*/
|
|
1376
|
+
private _setPathCondition;
|
|
1377
|
+
/**
|
|
1378
|
+
* Parse a projection string into an object
|
|
1379
|
+
*/
|
|
1380
|
+
private _parseProjectionString;
|
|
1381
|
+
/**
|
|
1382
|
+
* Parse a sort string into an object
|
|
1383
|
+
*/
|
|
1384
|
+
private _parseSortString;
|
|
1385
|
+
/**
|
|
1386
|
+
* Normalize sort order to 1 or -1
|
|
1387
|
+
*/
|
|
1388
|
+
private _normalizeSortOrder;
|
|
1389
|
+
/**
|
|
1390
|
+
* Build final options object for the driver
|
|
1391
|
+
*/
|
|
1392
|
+
private _buildOptions;
|
|
1393
|
+
/**
|
|
1394
|
+
* Get the hook name for the current operation
|
|
1395
|
+
*/
|
|
1396
|
+
private _getHookName;
|
|
1397
|
+
/**
|
|
1398
|
+
* Get placeholder result for when no collection is available
|
|
1399
|
+
*/
|
|
1400
|
+
private _getPlaceholderResult;
|
|
1401
|
+
/**
|
|
1402
|
+
* Apply population to results (placeholder)
|
|
1403
|
+
*/
|
|
1404
|
+
private _applyPopulate;
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Cursor for iterating over query results
|
|
1408
|
+
* Provides async iteration support for streaming large result sets
|
|
1409
|
+
*/
|
|
1410
|
+
declare class QueryCursor<TDoc> implements AsyncIterable<TDoc> {
|
|
1411
|
+
private _query;
|
|
1412
|
+
private _results;
|
|
1413
|
+
private _index;
|
|
1414
|
+
private _closed;
|
|
1415
|
+
constructor(query: Query<TDoc, TDoc[]>);
|
|
1416
|
+
/**
|
|
1417
|
+
* Close the cursor
|
|
1418
|
+
*/
|
|
1419
|
+
close(): Promise<void>;
|
|
1420
|
+
/**
|
|
1421
|
+
* Check if the cursor is closed
|
|
1422
|
+
*/
|
|
1423
|
+
get closed(): boolean;
|
|
1424
|
+
/**
|
|
1425
|
+
* Check if there are more documents
|
|
1426
|
+
*/
|
|
1427
|
+
hasNext(): Promise<boolean>;
|
|
1428
|
+
/**
|
|
1429
|
+
* Get the next document
|
|
1430
|
+
*/
|
|
1431
|
+
next(): Promise<TDoc | null>;
|
|
1432
|
+
/**
|
|
1433
|
+
* Execute a function for each document
|
|
1434
|
+
* @param fn - The function to execute for each document
|
|
1435
|
+
* @param options - Options for parallel processing
|
|
1436
|
+
*/
|
|
1437
|
+
eachAsync(fn: (doc: TDoc, index: number) => void | Promise<void>, options?: {
|
|
1438
|
+
parallel?: number;
|
|
1439
|
+
}): Promise<void>;
|
|
1440
|
+
/**
|
|
1441
|
+
* Map documents to a new array
|
|
1442
|
+
* @param fn - The mapping function
|
|
1443
|
+
*/
|
|
1444
|
+
map<T>(fn: (doc: TDoc) => T | Promise<T>): Promise<T[]>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Convert cursor to array
|
|
1447
|
+
*/
|
|
1448
|
+
toArray(): Promise<TDoc[]>;
|
|
1449
|
+
/**
|
|
1450
|
+
* Rewind the cursor to the beginning
|
|
1451
|
+
*/
|
|
1452
|
+
rewind(): this;
|
|
1453
|
+
/**
|
|
1454
|
+
* Add a cursor flag (placeholder for MongoDB cursor flags)
|
|
1455
|
+
* @param flag - The flag name
|
|
1456
|
+
* @param value - The flag value
|
|
1457
|
+
*/
|
|
1458
|
+
addCursorFlag(flag: string, value: boolean): this;
|
|
1459
|
+
/**
|
|
1460
|
+
* Make the cursor async iterable
|
|
1461
|
+
*/
|
|
1462
|
+
[Symbol.asyncIterator](): AsyncIterator<TDoc>;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
/**
|
|
1466
|
+
* Aggregate Builder - MongoDB Aggregation Pipeline for Mondoo
|
|
1467
|
+
*
|
|
1468
|
+
* @example
|
|
1469
|
+
* ```typescript
|
|
1470
|
+
* // Basic aggregation
|
|
1471
|
+
* const results = await User.aggregate()
|
|
1472
|
+
* .match({ active: true })
|
|
1473
|
+
* .group({ _id: '$department', count: { $sum: 1 } })
|
|
1474
|
+
* .sort({ count: -1 })
|
|
1475
|
+
* .limit(10)
|
|
1476
|
+
* .exec()
|
|
1477
|
+
*
|
|
1478
|
+
* // With initial pipeline
|
|
1479
|
+
* const stats = await Order.aggregate([
|
|
1480
|
+
* { $match: { status: 'completed' } }
|
|
1481
|
+
* ])
|
|
1482
|
+
* .group({ _id: '$customerId', total: { $sum: '$amount' } })
|
|
1483
|
+
* .sort({ total: -1 })
|
|
1484
|
+
*
|
|
1485
|
+
* // Faceted search
|
|
1486
|
+
* const results = await Product.aggregate()
|
|
1487
|
+
* .facet({
|
|
1488
|
+
* categories: [{ $group: { _id: '$category', count: { $sum: 1 } } }],
|
|
1489
|
+
* priceRanges: [{ $bucket: { groupBy: '$price', boundaries: [0, 100, 500, 1000] } }]
|
|
1490
|
+
* })
|
|
1491
|
+
* ```
|
|
1492
|
+
*/
|
|
1493
|
+
|
|
1494
|
+
/**
|
|
1495
|
+
* Options for aggregate execution
|
|
1496
|
+
*/
|
|
1497
|
+
interface AggregateOptions {
|
|
1498
|
+
/** Allow disk use for large result sets */
|
|
1499
|
+
allowDiskUse?: boolean;
|
|
1500
|
+
/** Set batch size for cursor */
|
|
1501
|
+
batchSize?: number;
|
|
1502
|
+
/** Maximum time for operation (ms) */
|
|
1503
|
+
maxTimeMS?: number;
|
|
1504
|
+
/** Read preference */
|
|
1505
|
+
readPreference?: string;
|
|
1506
|
+
/** Read concern level */
|
|
1507
|
+
readConcern?: {
|
|
1508
|
+
level: string;
|
|
1509
|
+
};
|
|
1510
|
+
/** Collation options */
|
|
1511
|
+
collation?: {
|
|
1512
|
+
locale: string;
|
|
1513
|
+
caseLevel?: boolean;
|
|
1514
|
+
caseFirst?: 'upper' | 'lower' | 'off';
|
|
1515
|
+
strength?: 1 | 2 | 3 | 4 | 5;
|
|
1516
|
+
numericOrdering?: boolean;
|
|
1517
|
+
alternate?: 'non-ignorable' | 'shifted';
|
|
1518
|
+
maxVariable?: 'punct' | 'space';
|
|
1519
|
+
backwards?: boolean;
|
|
1520
|
+
};
|
|
1521
|
+
/** Comment for logging */
|
|
1522
|
+
comment?: string;
|
|
1523
|
+
/** Hint for index usage */
|
|
1524
|
+
hint?: Record<string, 1 | -1> | string;
|
|
1525
|
+
/** Let variables for the pipeline */
|
|
1526
|
+
let?: Record<string, unknown>;
|
|
1527
|
+
/** Client session for transactions */
|
|
1528
|
+
session?: unknown;
|
|
1529
|
+
/** Write concern (for $out and $merge stages) */
|
|
1530
|
+
writeConcern?: {
|
|
1531
|
+
w?: number | 'majority';
|
|
1532
|
+
j?: boolean;
|
|
1533
|
+
wtimeout?: number;
|
|
1534
|
+
};
|
|
1535
|
+
/** Bypass document validation (for $out and $merge) */
|
|
1536
|
+
bypassDocumentValidation?: boolean;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* $lookup stage options
|
|
1540
|
+
*/
|
|
1541
|
+
interface LookupOptions {
|
|
1542
|
+
from: string;
|
|
1543
|
+
localField?: string;
|
|
1544
|
+
foreignField?: string;
|
|
1545
|
+
as: string;
|
|
1546
|
+
let?: Record<string, unknown>;
|
|
1547
|
+
pipeline?: Record<string, unknown>[];
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* $unwind stage options
|
|
1551
|
+
*/
|
|
1552
|
+
interface UnwindOptions {
|
|
1553
|
+
path: string;
|
|
1554
|
+
includeArrayIndex?: string;
|
|
1555
|
+
preserveNullAndEmptyArrays?: boolean;
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* $bucket stage options
|
|
1559
|
+
*/
|
|
1560
|
+
interface BucketOptions {
|
|
1561
|
+
groupBy: string | Record<string, unknown>;
|
|
1562
|
+
boundaries: (number | Date)[];
|
|
1563
|
+
default?: unknown;
|
|
1564
|
+
output?: Record<string, unknown>;
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* $bucketAuto stage options
|
|
1568
|
+
*/
|
|
1569
|
+
interface BucketAutoOptions {
|
|
1570
|
+
groupBy: string | Record<string, unknown>;
|
|
1571
|
+
buckets: number;
|
|
1572
|
+
output?: Record<string, unknown>;
|
|
1573
|
+
granularity?: 'R5' | 'R10' | 'R20' | 'R40' | 'R80' | '1-2-5' | 'E6' | 'E12' | 'E24' | 'E48' | 'E96' | 'E192' | 'POWERSOF2';
|
|
1574
|
+
}
|
|
1575
|
+
/**
|
|
1576
|
+
* $merge stage options
|
|
1577
|
+
*/
|
|
1578
|
+
interface MergeOptions {
|
|
1579
|
+
into: string | {
|
|
1580
|
+
db: string;
|
|
1581
|
+
coll: string;
|
|
1582
|
+
};
|
|
1583
|
+
on?: string | string[];
|
|
1584
|
+
whenMatched?: 'replace' | 'keepExisting' | 'merge' | 'fail' | Record<string, unknown>[];
|
|
1585
|
+
whenNotMatched?: 'insert' | 'discard' | 'fail';
|
|
1586
|
+
let?: Record<string, unknown>;
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* $graphLookup stage options
|
|
1590
|
+
*/
|
|
1591
|
+
interface GraphLookupOptions {
|
|
1592
|
+
from: string;
|
|
1593
|
+
startWith: string | Record<string, unknown>;
|
|
1594
|
+
connectFromField: string;
|
|
1595
|
+
connectToField: string;
|
|
1596
|
+
as: string;
|
|
1597
|
+
maxDepth?: number;
|
|
1598
|
+
depthField?: string;
|
|
1599
|
+
restrictSearchWithMatch?: Record<string, unknown>;
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* $geoNear stage options
|
|
1603
|
+
*/
|
|
1604
|
+
interface GeoNearOptions {
|
|
1605
|
+
near: {
|
|
1606
|
+
type: 'Point';
|
|
1607
|
+
coordinates: [number, number];
|
|
1608
|
+
} | [number, number];
|
|
1609
|
+
distanceField: string;
|
|
1610
|
+
spherical?: boolean;
|
|
1611
|
+
maxDistance?: number;
|
|
1612
|
+
minDistance?: number;
|
|
1613
|
+
query?: Record<string, unknown>;
|
|
1614
|
+
distanceMultiplier?: number;
|
|
1615
|
+
includeLocs?: string;
|
|
1616
|
+
key?: string;
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* $sample stage options
|
|
1620
|
+
*/
|
|
1621
|
+
interface SampleOptions {
|
|
1622
|
+
size: number;
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* $unionWith stage options
|
|
1626
|
+
*/
|
|
1627
|
+
interface UnionWithOptions {
|
|
1628
|
+
coll: string;
|
|
1629
|
+
pipeline?: Record<string, unknown>[];
|
|
1630
|
+
}
|
|
1631
|
+
/**
|
|
1632
|
+
* Model interface for aggregate operations
|
|
1633
|
+
*/
|
|
1634
|
+
interface AggregateModelLike<T = unknown> {
|
|
1635
|
+
collection?: {
|
|
1636
|
+
aggregate(pipeline: Record<string, unknown>[], options?: AggregateOptions): Promise<T[]>;
|
|
1637
|
+
};
|
|
1638
|
+
modelName?: string;
|
|
1639
|
+
schema?: Schema<any>;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Chainable aggregation pipeline builder for Mondoo
|
|
1643
|
+
*
|
|
1644
|
+
* The Aggregate class is LAZY - it doesn't execute until:
|
|
1645
|
+
* - exec() is called
|
|
1646
|
+
* - then() is called (await/Promise chain)
|
|
1647
|
+
*
|
|
1648
|
+
* @template TResult - The expected result type
|
|
1649
|
+
*/
|
|
1650
|
+
declare class Aggregate<TResult = unknown> implements PromiseLike<TResult[]> {
|
|
1651
|
+
/** The aggregation pipeline stages */
|
|
1652
|
+
private _pipeline;
|
|
1653
|
+
/** Aggregation options */
|
|
1654
|
+
private _options;
|
|
1655
|
+
/** Reference to the Model */
|
|
1656
|
+
private _model;
|
|
1657
|
+
/**
|
|
1658
|
+
* Create a new Aggregate instance
|
|
1659
|
+
* @param model - The model to aggregate against
|
|
1660
|
+
* @param pipeline - Initial pipeline stages
|
|
1661
|
+
*/
|
|
1662
|
+
constructor(model: AggregateModelLike, pipeline?: Record<string, unknown>[]);
|
|
1663
|
+
/**
|
|
1664
|
+
* Add a $match stage to filter documents
|
|
1665
|
+
* @param filter - The filter conditions
|
|
1666
|
+
* @example aggregate.match({ status: 'active', age: { $gte: 18 } })
|
|
1667
|
+
*/
|
|
1668
|
+
match(filter: Record<string, unknown>): this;
|
|
1669
|
+
/**
|
|
1670
|
+
* Add a $project stage to reshape documents
|
|
1671
|
+
* @param spec - The projection specification
|
|
1672
|
+
* @example aggregate.project({ name: 1, fullName: { $concat: ['$firstName', ' ', '$lastName'] } })
|
|
1673
|
+
*/
|
|
1674
|
+
project(spec: Record<string, unknown>): this;
|
|
1675
|
+
/**
|
|
1676
|
+
* Add a $group stage to group documents
|
|
1677
|
+
* @param spec - The grouping specification (must include _id)
|
|
1678
|
+
* @example aggregate.group({ _id: '$department', count: { $sum: 1 }, avgSalary: { $avg: '$salary' } })
|
|
1679
|
+
*/
|
|
1680
|
+
group(spec: Record<string, unknown>): this;
|
|
1681
|
+
/**
|
|
1682
|
+
* Add a $sort stage to order documents
|
|
1683
|
+
* @param spec - The sort specification
|
|
1684
|
+
* @example aggregate.sort({ count: -1, name: 1 })
|
|
1685
|
+
*/
|
|
1686
|
+
sort(spec: Record<string, 1 | -1 | {
|
|
1687
|
+
$meta: string;
|
|
1688
|
+
}>): this;
|
|
1689
|
+
/**
|
|
1690
|
+
* Add a $limit stage to limit number of documents
|
|
1691
|
+
* @param n - Maximum number of documents
|
|
1692
|
+
* @example aggregate.limit(10)
|
|
1693
|
+
*/
|
|
1694
|
+
limit(n: number): this;
|
|
1695
|
+
/**
|
|
1696
|
+
* Add a $skip stage to skip documents
|
|
1697
|
+
* @param n - Number of documents to skip
|
|
1698
|
+
* @example aggregate.skip(20)
|
|
1699
|
+
*/
|
|
1700
|
+
skip(n: number): this;
|
|
1701
|
+
/**
|
|
1702
|
+
* Add a $unwind stage to deconstruct arrays
|
|
1703
|
+
* @param path - The array field path or unwind options
|
|
1704
|
+
* @example aggregate.unwind('$tags')
|
|
1705
|
+
* @example aggregate.unwind({ path: '$tags', preserveNullAndEmptyArrays: true })
|
|
1706
|
+
*/
|
|
1707
|
+
unwind(path: string | UnwindOptions): this;
|
|
1708
|
+
/**
|
|
1709
|
+
* Add a $lookup stage to join with another collection
|
|
1710
|
+
* @param spec - The lookup specification
|
|
1711
|
+
* @example aggregate.lookup({ from: 'orders', localField: '_id', foreignField: 'customerId', as: 'orders' })
|
|
1712
|
+
*/
|
|
1713
|
+
lookup(spec: LookupOptions): this;
|
|
1714
|
+
/**
|
|
1715
|
+
* Add a $facet stage for multi-faceted aggregations
|
|
1716
|
+
* @param spec - The facet specifications
|
|
1717
|
+
* @example aggregate.facet({ byCategory: [{ $group: { _id: '$category' } }], byPrice: [{ $bucket: {...} }] })
|
|
1718
|
+
*/
|
|
1719
|
+
facet(spec: Record<string, Record<string, unknown>[]>): this;
|
|
1720
|
+
/**
|
|
1721
|
+
* Add a $bucket stage to categorize documents into groups
|
|
1722
|
+
* @param spec - The bucket specification
|
|
1723
|
+
* @example aggregate.bucket({ groupBy: '$price', boundaries: [0, 100, 500, 1000], default: 'Other' })
|
|
1724
|
+
*/
|
|
1725
|
+
bucket(spec: BucketOptions): this;
|
|
1726
|
+
/**
|
|
1727
|
+
* Add a $bucketAuto stage for automatic bucket boundaries
|
|
1728
|
+
* @param spec - The bucket auto specification
|
|
1729
|
+
* @example aggregate.bucketAuto({ groupBy: '$price', buckets: 4 })
|
|
1730
|
+
*/
|
|
1731
|
+
bucketAuto(spec: BucketAutoOptions): this;
|
|
1732
|
+
/**
|
|
1733
|
+
* Add a $addFields stage to add new fields
|
|
1734
|
+
* @param fields - The fields to add
|
|
1735
|
+
* @example aggregate.addFields({ fullName: { $concat: ['$firstName', ' ', '$lastName'] } })
|
|
1736
|
+
*/
|
|
1737
|
+
addFields(fields: Record<string, unknown>): this;
|
|
1738
|
+
/**
|
|
1739
|
+
* Add a $set stage (alias for $addFields)
|
|
1740
|
+
* @param fields - The fields to set
|
|
1741
|
+
*/
|
|
1742
|
+
set(fields: Record<string, unknown>): this;
|
|
1743
|
+
/**
|
|
1744
|
+
* Add a $replaceRoot stage to replace the document root
|
|
1745
|
+
* @param spec - The replacement specification
|
|
1746
|
+
* @example aggregate.replaceRoot({ newRoot: '$embeddedDoc' })
|
|
1747
|
+
*/
|
|
1748
|
+
replaceRoot(spec: {
|
|
1749
|
+
newRoot: string | Record<string, unknown>;
|
|
1750
|
+
}): this;
|
|
1751
|
+
/**
|
|
1752
|
+
* Add a $replaceWith stage (alias for $replaceRoot)
|
|
1753
|
+
* @param replacement - The replacement expression
|
|
1754
|
+
*/
|
|
1755
|
+
replaceWith(replacement: string | Record<string, unknown>): this;
|
|
1756
|
+
/**
|
|
1757
|
+
* Add a $count stage to count documents
|
|
1758
|
+
* @param field - The name of the count field
|
|
1759
|
+
* @example aggregate.count('total')
|
|
1760
|
+
*/
|
|
1761
|
+
count(field: string): this;
|
|
1762
|
+
/**
|
|
1763
|
+
* Add a $merge stage to write results to a collection
|
|
1764
|
+
* @param spec - The merge specification (string for collection name or options object)
|
|
1765
|
+
* @example aggregate.merge('output_collection')
|
|
1766
|
+
* @example aggregate.merge({ into: 'output', whenMatched: 'replace' })
|
|
1767
|
+
*/
|
|
1768
|
+
merge(spec: string | MergeOptions): this;
|
|
1769
|
+
/**
|
|
1770
|
+
* Add a $out stage to write results to a collection
|
|
1771
|
+
* @param collection - The output collection name
|
|
1772
|
+
* @example aggregate.out('archived_orders')
|
|
1773
|
+
*/
|
|
1774
|
+
out(collection: string): this;
|
|
1775
|
+
/**
|
|
1776
|
+
* Add a $redact stage for field-level access control
|
|
1777
|
+
* @param expression - The redact expression
|
|
1778
|
+
* @example aggregate.redact({ $cond: { if: { $eq: ['$level', 'public'] }, then: '$$DESCEND', else: '$$PRUNE' } })
|
|
1779
|
+
*/
|
|
1780
|
+
redact(expression: Record<string, unknown>): this;
|
|
1781
|
+
/**
|
|
1782
|
+
* Add a $sample stage to randomly select documents
|
|
1783
|
+
* @param spec - The sample specification or size number
|
|
1784
|
+
* @example aggregate.sample(100)
|
|
1785
|
+
* @example aggregate.sample({ size: 100 })
|
|
1786
|
+
*/
|
|
1787
|
+
sample(spec: number | SampleOptions): this;
|
|
1788
|
+
/**
|
|
1789
|
+
* Add a $sortByCount stage (groups and counts, then sorts)
|
|
1790
|
+
* @param expression - The field or expression to sort by count
|
|
1791
|
+
* @example aggregate.sortByCount('$category')
|
|
1792
|
+
*/
|
|
1793
|
+
sortByCount(expression: string | Record<string, unknown>): this;
|
|
1794
|
+
/**
|
|
1795
|
+
* Add a $graphLookup stage for recursive lookups
|
|
1796
|
+
* @param spec - The graph lookup specification
|
|
1797
|
+
*/
|
|
1798
|
+
graphLookup(spec: GraphLookupOptions): this;
|
|
1799
|
+
/**
|
|
1800
|
+
* Add a $geoNear stage for geospatial queries (must be first stage)
|
|
1801
|
+
* @param spec - The geo near specification
|
|
1802
|
+
*/
|
|
1803
|
+
near(spec: GeoNearOptions): this;
|
|
1804
|
+
/**
|
|
1805
|
+
* Add a $unset stage to remove fields
|
|
1806
|
+
* @param fields - Field(s) to remove
|
|
1807
|
+
* @example aggregate.unset('password')
|
|
1808
|
+
* @example aggregate.unset(['password', 'internalNotes'])
|
|
1809
|
+
*/
|
|
1810
|
+
unset(fields: string | string[]): this;
|
|
1811
|
+
/**
|
|
1812
|
+
* Add a $densify stage to fill in gaps
|
|
1813
|
+
* @param spec - The densify specification
|
|
1814
|
+
*/
|
|
1815
|
+
densify(spec: {
|
|
1816
|
+
field: string;
|
|
1817
|
+
partitionByFields?: string[];
|
|
1818
|
+
range: {
|
|
1819
|
+
step: number;
|
|
1820
|
+
unit?: string;
|
|
1821
|
+
bounds: [unknown, unknown] | 'full' | 'partition';
|
|
1822
|
+
};
|
|
1823
|
+
}): this;
|
|
1824
|
+
/**
|
|
1825
|
+
* Add a $fill stage to fill null/missing values
|
|
1826
|
+
* @param spec - The fill specification
|
|
1827
|
+
*/
|
|
1828
|
+
fill(spec: {
|
|
1829
|
+
partitionBy?: Record<string, unknown>;
|
|
1830
|
+
partitionByFields?: string[];
|
|
1831
|
+
sortBy?: Record<string, 1 | -1>;
|
|
1832
|
+
output: Record<string, {
|
|
1833
|
+
value: unknown;
|
|
1834
|
+
} | {
|
|
1835
|
+
method: 'linear' | 'locf';
|
|
1836
|
+
}>;
|
|
1837
|
+
}): this;
|
|
1838
|
+
/**
|
|
1839
|
+
* Add a $unionWith stage to combine pipelines
|
|
1840
|
+
* @param spec - The union specification
|
|
1841
|
+
* @example aggregate.unionWith({ coll: 'archive', pipeline: [{ $match: { archived: true } }] })
|
|
1842
|
+
*/
|
|
1843
|
+
unionWith(spec: string | UnionWithOptions): this;
|
|
1844
|
+
/**
|
|
1845
|
+
* Add a $setWindowFields stage for window functions
|
|
1846
|
+
* @param spec - The window fields specification
|
|
1847
|
+
*/
|
|
1848
|
+
setWindowFields(spec: {
|
|
1849
|
+
partitionBy?: string | Record<string, unknown>;
|
|
1850
|
+
sortBy?: Record<string, 1 | -1>;
|
|
1851
|
+
output: Record<string, unknown>;
|
|
1852
|
+
}): this;
|
|
1853
|
+
/**
|
|
1854
|
+
* Add a $search stage (MongoDB Atlas Search)
|
|
1855
|
+
* @param spec - The search specification
|
|
1856
|
+
*/
|
|
1857
|
+
search(spec: Record<string, unknown>): this;
|
|
1858
|
+
/**
|
|
1859
|
+
* Add a $searchMeta stage (MongoDB Atlas Search metadata)
|
|
1860
|
+
* @param spec - The search meta specification
|
|
1861
|
+
*/
|
|
1862
|
+
searchMeta(spec: Record<string, unknown>): this;
|
|
1863
|
+
/**
|
|
1864
|
+
* Append one or more stages to the pipeline
|
|
1865
|
+
* @param stages - The stages to append
|
|
1866
|
+
* @example aggregate.append({ $match: { active: true } }, { $sort: { name: 1 } })
|
|
1867
|
+
*/
|
|
1868
|
+
append(...stages: Record<string, unknown>[]): this;
|
|
1869
|
+
/**
|
|
1870
|
+
* Add a raw stage to the pipeline
|
|
1871
|
+
* @param stage - The raw stage object
|
|
1872
|
+
*/
|
|
1873
|
+
addStage(stage: Record<string, unknown>): this;
|
|
1874
|
+
/**
|
|
1875
|
+
* Set an option for the aggregation
|
|
1876
|
+
* @param key - The option name
|
|
1877
|
+
* @param value - The option value
|
|
1878
|
+
*/
|
|
1879
|
+
option<K extends keyof AggregateOptions>(key: K, value: AggregateOptions[K]): this;
|
|
1880
|
+
/**
|
|
1881
|
+
* Set multiple options at once
|
|
1882
|
+
* @param options - The options object
|
|
1883
|
+
*/
|
|
1884
|
+
setOptions(options: AggregateOptions): this;
|
|
1885
|
+
/**
|
|
1886
|
+
* Enable disk use for large result sets
|
|
1887
|
+
* @param val - Whether to allow disk use
|
|
1888
|
+
*/
|
|
1889
|
+
allowDiskUse(val?: boolean): this;
|
|
1890
|
+
/**
|
|
1891
|
+
* Set batch size for cursor
|
|
1892
|
+
* @param size - The batch size
|
|
1893
|
+
*/
|
|
1894
|
+
batchSize(size: number): this;
|
|
1895
|
+
/**
|
|
1896
|
+
* Set read preference
|
|
1897
|
+
* @param pref - The read preference
|
|
1898
|
+
*/
|
|
1899
|
+
read(pref: string): this;
|
|
1900
|
+
/**
|
|
1901
|
+
* Set read concern
|
|
1902
|
+
* @param level - The read concern level
|
|
1903
|
+
*/
|
|
1904
|
+
readConcern(level: string): this;
|
|
1905
|
+
/**
|
|
1906
|
+
* Set maximum time for operation
|
|
1907
|
+
* @param ms - Maximum time in milliseconds
|
|
1908
|
+
*/
|
|
1909
|
+
maxTimeMS(ms: number): this;
|
|
1910
|
+
/**
|
|
1911
|
+
* Set collation options
|
|
1912
|
+
* @param collation - The collation options
|
|
1913
|
+
*/
|
|
1914
|
+
collation(collation: AggregateOptions['collation']): this;
|
|
1915
|
+
/**
|
|
1916
|
+
* Add a comment to the aggregation
|
|
1917
|
+
* @param val - The comment string
|
|
1918
|
+
*/
|
|
1919
|
+
comment(val: string): this;
|
|
1920
|
+
/**
|
|
1921
|
+
* Set index hint
|
|
1922
|
+
* @param hint - The index hint
|
|
1923
|
+
*/
|
|
1924
|
+
hint(hint: Record<string, 1 | -1> | string): this;
|
|
1925
|
+
/**
|
|
1926
|
+
* Set let variables for the pipeline
|
|
1927
|
+
* @param variables - The variable definitions
|
|
1928
|
+
*/
|
|
1929
|
+
let(variables: Record<string, unknown>): this;
|
|
1930
|
+
/**
|
|
1931
|
+
* Set session for transactions
|
|
1932
|
+
* @param clientSession - The client session
|
|
1933
|
+
*/
|
|
1934
|
+
session(clientSession: unknown): this;
|
|
1935
|
+
/**
|
|
1936
|
+
* Get the current pipeline
|
|
1937
|
+
*/
|
|
1938
|
+
pipeline(): Record<string, unknown>[];
|
|
1939
|
+
/**
|
|
1940
|
+
* Get the current options
|
|
1941
|
+
*/
|
|
1942
|
+
getOptions(): AggregateOptions;
|
|
1943
|
+
/**
|
|
1944
|
+
* Get the model reference
|
|
1945
|
+
*/
|
|
1946
|
+
model(): AggregateModelLike;
|
|
1947
|
+
/**
|
|
1948
|
+
* Clone this aggregate
|
|
1949
|
+
*/
|
|
1950
|
+
clone(): Aggregate<TResult>;
|
|
1951
|
+
/**
|
|
1952
|
+
* Execute the aggregation and return a Promise
|
|
1953
|
+
*/
|
|
1954
|
+
exec(): Promise<TResult[]>;
|
|
1955
|
+
/**
|
|
1956
|
+
* Make the aggregate thenable (allows await/Promise chain)
|
|
1957
|
+
*/
|
|
1958
|
+
then<TFulfilled = TResult[], TRejected = never>(onfulfilled?: ((value: TResult[]) => TFulfilled | PromiseLike<TFulfilled>) | null, onrejected?: ((reason: unknown) => TRejected | PromiseLike<TRejected>) | null): Promise<TFulfilled | TRejected>;
|
|
1959
|
+
/**
|
|
1960
|
+
* Handle rejection
|
|
1961
|
+
*/
|
|
1962
|
+
catch<TRejected = never>(onrejected?: ((reason: unknown) => TRejected | PromiseLike<TRejected>) | null): Promise<TResult[] | TRejected>;
|
|
1963
|
+
/**
|
|
1964
|
+
* Finally handler
|
|
1965
|
+
*/
|
|
1966
|
+
finally(onfinally?: (() => void) | null): Promise<TResult[]>;
|
|
1967
|
+
/**
|
|
1968
|
+
* Return a cursor for iteration
|
|
1969
|
+
* This returns an async iterable that can be used with for-await-of
|
|
1970
|
+
*/
|
|
1971
|
+
cursor(): AggregateCursor<TResult>;
|
|
1972
|
+
/**
|
|
1973
|
+
* Explain the aggregation execution plan
|
|
1974
|
+
*/
|
|
1975
|
+
explain(verbosity?: 'queryPlanner' | 'executionStats' | 'allPlansExecution'): Promise<unknown>;
|
|
1976
|
+
/**
|
|
1977
|
+
* Convert aggregation to string representation
|
|
1978
|
+
*/
|
|
1979
|
+
toString(): string;
|
|
1980
|
+
/**
|
|
1981
|
+
* Symbol.toStringTag for better debugging
|
|
1982
|
+
*/
|
|
1983
|
+
get [Symbol.toStringTag](): string;
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* Cursor for iterating over aggregation results
|
|
1987
|
+
* Provides async iteration support for streaming large result sets
|
|
1988
|
+
*/
|
|
1989
|
+
declare class AggregateCursor<TResult> implements AsyncIterable<TResult> {
|
|
1990
|
+
private _aggregate;
|
|
1991
|
+
private _results;
|
|
1992
|
+
private _index;
|
|
1993
|
+
private _closed;
|
|
1994
|
+
constructor(aggregate: Aggregate<TResult>);
|
|
1995
|
+
/**
|
|
1996
|
+
* Close the cursor
|
|
1997
|
+
*/
|
|
1998
|
+
close(): Promise<void>;
|
|
1999
|
+
/**
|
|
2000
|
+
* Check if the cursor is closed
|
|
2001
|
+
*/
|
|
2002
|
+
get closed(): boolean;
|
|
2003
|
+
/**
|
|
2004
|
+
* Check if there are more documents
|
|
2005
|
+
*/
|
|
2006
|
+
hasNext(): Promise<boolean>;
|
|
2007
|
+
/**
|
|
2008
|
+
* Get the next document
|
|
2009
|
+
*/
|
|
2010
|
+
next(): Promise<TResult | null>;
|
|
2011
|
+
/**
|
|
2012
|
+
* Execute a function for each document
|
|
2013
|
+
* @param fn - The function to execute for each document
|
|
2014
|
+
* @param options - Options for parallel processing
|
|
2015
|
+
*/
|
|
2016
|
+
eachAsync(fn: (doc: TResult, index: number) => void | Promise<void>, options?: {
|
|
2017
|
+
parallel?: number;
|
|
2018
|
+
}): Promise<void>;
|
|
2019
|
+
/**
|
|
2020
|
+
* Map documents to a new array
|
|
2021
|
+
* @param fn - The mapping function
|
|
2022
|
+
*/
|
|
2023
|
+
map<T>(fn: (doc: TResult) => T | Promise<T>): Promise<T[]>;
|
|
2024
|
+
/**
|
|
2025
|
+
* Convert cursor to array
|
|
2026
|
+
*/
|
|
2027
|
+
toArray(): Promise<TResult[]>;
|
|
2028
|
+
/**
|
|
2029
|
+
* Rewind the cursor to the beginning
|
|
2030
|
+
*/
|
|
2031
|
+
rewind(): this;
|
|
2032
|
+
/**
|
|
2033
|
+
* Add a cursor flag (placeholder for MongoDB cursor flags)
|
|
2034
|
+
* @param flag - The flag name
|
|
2035
|
+
* @param value - The flag value
|
|
2036
|
+
*/
|
|
2037
|
+
addCursorFlag(flag: string, value: boolean): this;
|
|
2038
|
+
/**
|
|
2039
|
+
* Make the cursor async iterable
|
|
2040
|
+
*/
|
|
2041
|
+
[Symbol.asyncIterator](): AsyncIterator<TResult>;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
/**
|
|
2045
|
+
* Model class - wraps MongoDB collection operations and provides Mongoose-compatible API
|
|
2046
|
+
*/
|
|
2047
|
+
|
|
2048
|
+
interface ModelOptions {
|
|
2049
|
+
collection?: string;
|
|
2050
|
+
connection?: any;
|
|
2051
|
+
skipInit?: boolean;
|
|
2052
|
+
}
|
|
2053
|
+
interface InsertManyOptions {
|
|
2054
|
+
ordered?: boolean;
|
|
2055
|
+
rawResult?: boolean;
|
|
2056
|
+
session?: any;
|
|
2057
|
+
lean?: boolean;
|
|
2058
|
+
}
|
|
2059
|
+
interface UpdateResult {
|
|
2060
|
+
acknowledged: boolean;
|
|
2061
|
+
modifiedCount: number;
|
|
2062
|
+
upsertedId?: ObjectId;
|
|
2063
|
+
upsertedCount: number;
|
|
2064
|
+
matchedCount: number;
|
|
2065
|
+
}
|
|
2066
|
+
interface DeleteResult {
|
|
2067
|
+
acknowledged: boolean;
|
|
2068
|
+
deletedCount: number;
|
|
2069
|
+
}
|
|
2070
|
+
interface IndexDefinition {
|
|
2071
|
+
fields: Record<string, 1 | -1 | 'text' | '2dsphere'>;
|
|
2072
|
+
options?: {
|
|
2073
|
+
unique?: boolean;
|
|
2074
|
+
sparse?: boolean;
|
|
2075
|
+
background?: boolean;
|
|
2076
|
+
expireAfterSeconds?: number;
|
|
2077
|
+
name?: string;
|
|
2078
|
+
partialFilterExpression?: Record<string, any>;
|
|
2079
|
+
};
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* Interface for Model constructor (callable as new Model())
|
|
2083
|
+
*/
|
|
2084
|
+
interface ModelConstructor<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
2085
|
+
new (doc?: Partial<T>): Document<T> & T;
|
|
2086
|
+
schema: Schema<T>;
|
|
2087
|
+
collection: any;
|
|
2088
|
+
modelName: string;
|
|
2089
|
+
db: any;
|
|
2090
|
+
baseModelName?: string;
|
|
2091
|
+
discriminators?: Map<string, ModelConstructor<any>>;
|
|
2092
|
+
create(doc: Partial<T>): Promise<Document<T> & T>;
|
|
2093
|
+
create(docs: Partial<T>[]): Promise<(Document<T> & T)[]>;
|
|
2094
|
+
insertMany(docs: Partial<T>[], options?: InsertManyOptions): Promise<(Document<T> & T)[]>;
|
|
2095
|
+
find(filter?: Record<string, any>, projection?: Record<string, 0 | 1> | string, options?: QueryOptions): Query<T, (Document<T> & T)[]>;
|
|
2096
|
+
findOne(filter?: Record<string, any>, projection?: Record<string, 0 | 1> | string, options?: QueryOptions): Query<T, (Document<T> & T) | null>;
|
|
2097
|
+
findById(id: ObjectId | string, projection?: Record<string, 0 | 1> | string, options?: QueryOptions): Query<T, (Document<T> & T) | null>;
|
|
2098
|
+
findByIdAndUpdate(id: ObjectId | string, update: Record<string, any>, options?: QueryOptions & {
|
|
2099
|
+
new?: boolean;
|
|
2100
|
+
}): Query<T, (Document<T> & T) | null>;
|
|
2101
|
+
findByIdAndDelete(id: ObjectId | string, options?: QueryOptions): Query<T, (Document<T> & T) | null>;
|
|
2102
|
+
findOneAndUpdate(filter: Record<string, any>, update: Record<string, any>, options?: QueryOptions & {
|
|
2103
|
+
new?: boolean;
|
|
2104
|
+
upsert?: boolean;
|
|
2105
|
+
}): Query<T, (Document<T> & T) | null>;
|
|
2106
|
+
findOneAndDelete(filter: Record<string, any>, options?: QueryOptions): Query<T, (Document<T> & T) | null>;
|
|
2107
|
+
findOneAndReplace(filter: Record<string, any>, replacement: Partial<T>, options?: QueryOptions & {
|
|
2108
|
+
new?: boolean;
|
|
2109
|
+
upsert?: boolean;
|
|
2110
|
+
}): Query<T, (Document<T> & T) | null>;
|
|
2111
|
+
updateOne(filter: Record<string, any>, update: Record<string, any>, options?: QueryOptions & {
|
|
2112
|
+
upsert?: boolean;
|
|
2113
|
+
}): Query<T, UpdateResult>;
|
|
2114
|
+
updateMany(filter: Record<string, any>, update: Record<string, any>, options?: QueryOptions & {
|
|
2115
|
+
upsert?: boolean;
|
|
2116
|
+
}): Query<T, UpdateResult>;
|
|
2117
|
+
replaceOne(filter: Record<string, any>, replacement: Partial<T>, options?: QueryOptions & {
|
|
2118
|
+
upsert?: boolean;
|
|
2119
|
+
}): Query<T, UpdateResult>;
|
|
2120
|
+
deleteOne(filter: Record<string, any>, options?: QueryOptions): Query<T, DeleteResult>;
|
|
2121
|
+
deleteMany(filter: Record<string, any>, options?: QueryOptions): Query<T, DeleteResult>;
|
|
2122
|
+
countDocuments(filter?: Record<string, any>): Query<T, number>;
|
|
2123
|
+
estimatedDocumentCount(): Promise<number>;
|
|
2124
|
+
distinct(field: string, filter?: Record<string, any>): Query<T, any[]>;
|
|
2125
|
+
hydrate(doc: Record<string, any>): Document<T> & T;
|
|
2126
|
+
createIndexes(): Promise<void>;
|
|
2127
|
+
ensureIndexes(): Promise<void>;
|
|
2128
|
+
syncIndexes(): Promise<string[]>;
|
|
2129
|
+
listIndexes(): Promise<IndexDefinition[]>;
|
|
2130
|
+
exists(filter: Record<string, any>): Promise<{
|
|
2131
|
+
_id: ObjectId;
|
|
2132
|
+
} | null>;
|
|
2133
|
+
where(path: string, val?: any): Query<T, (Document<T> & T)[]>;
|
|
2134
|
+
aggregate<R = any>(pipeline?: Record<string, any>[]): Aggregate<R>;
|
|
2135
|
+
bulkWrite(ops: BulkWriteOperation<T>[], options?: {
|
|
2136
|
+
ordered?: boolean;
|
|
2137
|
+
session?: any;
|
|
2138
|
+
}): Promise<BulkWriteResult>;
|
|
2139
|
+
watch(pipeline?: Record<string, any>[], options?: Record<string, any>): ChangeStream<T>;
|
|
2140
|
+
_saveDocument(doc: Document<T>, options?: any): Promise<Document<T>>;
|
|
2141
|
+
_deleteDocument(doc: Document<T>, options?: any): Promise<Document<T>>;
|
|
2142
|
+
_populateDocument(doc: Document<T>, path: string | string[] | Record<string, any>): Promise<Document<T>>;
|
|
2143
|
+
}
|
|
2144
|
+
interface BulkWriteOperation<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
2145
|
+
insertOne?: {
|
|
2146
|
+
document: Partial<T>;
|
|
2147
|
+
};
|
|
2148
|
+
updateOne?: {
|
|
2149
|
+
filter: Record<string, any>;
|
|
2150
|
+
update: Record<string, any>;
|
|
2151
|
+
upsert?: boolean;
|
|
2152
|
+
};
|
|
2153
|
+
updateMany?: {
|
|
2154
|
+
filter: Record<string, any>;
|
|
2155
|
+
update: Record<string, any>;
|
|
2156
|
+
upsert?: boolean;
|
|
2157
|
+
};
|
|
2158
|
+
deleteOne?: {
|
|
2159
|
+
filter: Record<string, any>;
|
|
2160
|
+
};
|
|
2161
|
+
deleteMany?: {
|
|
2162
|
+
filter: Record<string, any>;
|
|
2163
|
+
};
|
|
2164
|
+
replaceOne?: {
|
|
2165
|
+
filter: Record<string, any>;
|
|
2166
|
+
replacement: Partial<T>;
|
|
2167
|
+
upsert?: boolean;
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
interface BulkWriteResult {
|
|
2171
|
+
insertedCount: number;
|
|
2172
|
+
matchedCount: number;
|
|
2173
|
+
modifiedCount: number;
|
|
2174
|
+
deletedCount: number;
|
|
2175
|
+
upsertedCount: number;
|
|
2176
|
+
upsertedIds: Record<number, ObjectId>;
|
|
2177
|
+
}
|
|
2178
|
+
interface ChangeStream<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
2179
|
+
on(event: 'change', listener: (change: ChangeEvent<T>) => void): this;
|
|
2180
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
2181
|
+
on(event: 'close', listener: () => void): this;
|
|
2182
|
+
close(): Promise<void>;
|
|
2183
|
+
[Symbol.asyncIterator](): AsyncIterator<ChangeEvent<T>>;
|
|
2184
|
+
}
|
|
2185
|
+
interface ChangeEvent<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
2186
|
+
operationType: 'insert' | 'update' | 'replace' | 'delete' | 'invalidate' | 'drop' | 'dropDatabase' | 'rename';
|
|
2187
|
+
fullDocument?: T;
|
|
2188
|
+
documentKey?: {
|
|
2189
|
+
_id: ObjectId;
|
|
2190
|
+
};
|
|
2191
|
+
updateDescription?: {
|
|
2192
|
+
updatedFields: Record<string, any>;
|
|
2193
|
+
removedFields: string[];
|
|
2194
|
+
};
|
|
2195
|
+
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Base Model class with static methods
|
|
2198
|
+
*/
|
|
2199
|
+
declare class Model<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
2200
|
+
/** The schema for this model */
|
|
2201
|
+
static schema: Schema<any>;
|
|
2202
|
+
/** MongoDB collection reference (placeholder) */
|
|
2203
|
+
static collection: any;
|
|
2204
|
+
/** The model name */
|
|
2205
|
+
static modelName: string;
|
|
2206
|
+
/** Database connection reference (placeholder) */
|
|
2207
|
+
static db: any;
|
|
2208
|
+
/** Base path for discriminators */
|
|
2209
|
+
static baseModelName?: string;
|
|
2210
|
+
/** Discriminator mapping */
|
|
2211
|
+
static discriminators?: Map<string, ModelConstructor<any>>;
|
|
2212
|
+
/**
|
|
2213
|
+
* Create one or more documents
|
|
2214
|
+
*/
|
|
2215
|
+
static create<T extends Record<string, unknown>>(this: ModelConstructor<T>, doc: Partial<T>): Promise<Document<T> & T>;
|
|
2216
|
+
static create<T extends Record<string, unknown>>(this: ModelConstructor<T>, docs: Partial<T>[]): Promise<(Document<T> & T)[]>;
|
|
2217
|
+
/**
|
|
2218
|
+
* Insert multiple documents
|
|
2219
|
+
*/
|
|
2220
|
+
static insertMany<T extends Record<string, unknown>>(this: ModelConstructor<T>, docs: Partial<T>[], options?: InsertManyOptions): Promise<(Document<T> & T)[]>;
|
|
2221
|
+
/**
|
|
2222
|
+
* Find documents matching filter
|
|
2223
|
+
*/
|
|
2224
|
+
static find<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter?: Record<string, any>, projection?: Record<string, 0 | 1> | string, options?: QueryOptions): Query<T, (Document<T> & T)[]>;
|
|
2225
|
+
/**
|
|
2226
|
+
* Find a single document
|
|
2227
|
+
*/
|
|
2228
|
+
static findOne<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter?: Record<string, any>, projection?: Record<string, 0 | 1> | string, options?: QueryOptions): Query<T, (Document<T> & T) | null>;
|
|
2229
|
+
/**
|
|
2230
|
+
* Find a document by its _id
|
|
2231
|
+
*/
|
|
2232
|
+
static findById<T extends Record<string, unknown>>(this: ModelConstructor<T>, id: ObjectId | string, projection?: Record<string, 0 | 1> | string, options?: QueryOptions): Query<T, (Document<T> & T) | null>;
|
|
2233
|
+
/**
|
|
2234
|
+
* Find a document by _id and update it
|
|
2235
|
+
*/
|
|
2236
|
+
static findByIdAndUpdate<T extends Record<string, unknown>>(this: ModelConstructor<T>, id: ObjectId | string, update: Record<string, any>, options?: QueryOptions & {
|
|
2237
|
+
new?: boolean;
|
|
2238
|
+
}): Query<T, (Document<T> & T) | null>;
|
|
2239
|
+
/**
|
|
2240
|
+
* Find a document by _id and delete it
|
|
2241
|
+
*/
|
|
2242
|
+
static findByIdAndDelete<T extends Record<string, unknown>>(this: ModelConstructor<T>, id: ObjectId | string, options?: QueryOptions): Query<T, (Document<T> & T) | null>;
|
|
2243
|
+
/**
|
|
2244
|
+
* Find a document and update it
|
|
2245
|
+
*/
|
|
2246
|
+
static findOneAndUpdate<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>, update: Record<string, any>, options?: QueryOptions & {
|
|
2247
|
+
new?: boolean;
|
|
2248
|
+
upsert?: boolean;
|
|
2249
|
+
}): Query<T, (Document<T> & T) | null>;
|
|
2250
|
+
/**
|
|
2251
|
+
* Find a document and delete it
|
|
2252
|
+
*/
|
|
2253
|
+
static findOneAndDelete<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>, options?: QueryOptions): Query<T, (Document<T> & T) | null>;
|
|
2254
|
+
/**
|
|
2255
|
+
* Find a document and replace it
|
|
2256
|
+
*/
|
|
2257
|
+
static findOneAndReplace<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>, replacement: Partial<T>, options?: QueryOptions & {
|
|
2258
|
+
new?: boolean;
|
|
2259
|
+
upsert?: boolean;
|
|
2260
|
+
}): Query<T, (Document<T> & T) | null>;
|
|
2261
|
+
/**
|
|
2262
|
+
* Update a single document
|
|
2263
|
+
*/
|
|
2264
|
+
static updateOne<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>, update: Record<string, any>, options?: QueryOptions & {
|
|
2265
|
+
upsert?: boolean;
|
|
2266
|
+
}): Query<T, UpdateResult>;
|
|
2267
|
+
/**
|
|
2268
|
+
* Update multiple documents
|
|
2269
|
+
*/
|
|
2270
|
+
static updateMany<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>, update: Record<string, any>, options?: QueryOptions & {
|
|
2271
|
+
upsert?: boolean;
|
|
2272
|
+
}): Query<T, UpdateResult>;
|
|
2273
|
+
/**
|
|
2274
|
+
* Replace a single document
|
|
2275
|
+
*/
|
|
2276
|
+
static replaceOne<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>, replacement: Partial<T>, options?: QueryOptions & {
|
|
2277
|
+
upsert?: boolean;
|
|
2278
|
+
}): Query<T, UpdateResult>;
|
|
2279
|
+
/**
|
|
2280
|
+
* Delete a single document
|
|
2281
|
+
*/
|
|
2282
|
+
static deleteOne<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>, options?: QueryOptions): Query<T, DeleteResult>;
|
|
2283
|
+
/**
|
|
2284
|
+
* Delete multiple documents
|
|
2285
|
+
*/
|
|
2286
|
+
static deleteMany<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>, options?: QueryOptions): Query<T, DeleteResult>;
|
|
2287
|
+
/**
|
|
2288
|
+
* Count documents matching filter
|
|
2289
|
+
*/
|
|
2290
|
+
static countDocuments<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter?: Record<string, any>): Query<T, number>;
|
|
2291
|
+
/**
|
|
2292
|
+
* Estimated document count (faster, uses collection metadata)
|
|
2293
|
+
*/
|
|
2294
|
+
static estimatedDocumentCount<T extends Record<string, unknown>>(this: ModelConstructor<T>): Promise<number>;
|
|
2295
|
+
/**
|
|
2296
|
+
* Get distinct values for a field
|
|
2297
|
+
*/
|
|
2298
|
+
static distinct<T extends Record<string, unknown>>(this: ModelConstructor<T>, field: string, filter?: Record<string, any>): Query<T, any[]>;
|
|
2299
|
+
/**
|
|
2300
|
+
* Check if any document exists matching filter
|
|
2301
|
+
*/
|
|
2302
|
+
static exists<T extends Record<string, unknown>>(this: ModelConstructor<T>, filter: Record<string, any>): Promise<{
|
|
2303
|
+
_id: ObjectId;
|
|
2304
|
+
} | null>;
|
|
2305
|
+
/**
|
|
2306
|
+
* Create a Document instance from a plain object (without saving)
|
|
2307
|
+
*/
|
|
2308
|
+
static hydrate<T extends Record<string, unknown>>(this: ModelConstructor<T>, doc: Partial<T>): Document<T> & T;
|
|
2309
|
+
/**
|
|
2310
|
+
* Start a query with where clause
|
|
2311
|
+
*/
|
|
2312
|
+
static where<T extends Record<string, unknown>>(this: ModelConstructor<T>, path: string, val?: any): Query<T, (Document<T> & T)[]>;
|
|
2313
|
+
/**
|
|
2314
|
+
* Start an aggregation pipeline
|
|
2315
|
+
*/
|
|
2316
|
+
static aggregate<T extends Record<string, unknown>, R = any>(this: ModelConstructor<T>, pipeline?: Record<string, any>[]): Aggregate<R>;
|
|
2317
|
+
/**
|
|
2318
|
+
* Create indexes defined in the schema
|
|
2319
|
+
*/
|
|
2320
|
+
static createIndexes<T extends Record<string, unknown>>(this: ModelConstructor<T>): Promise<void>;
|
|
2321
|
+
/**
|
|
2322
|
+
* Ensure indexes exist (alias for createIndexes)
|
|
2323
|
+
*/
|
|
2324
|
+
static ensureIndexes<T extends Record<string, unknown>>(this: ModelConstructor<T>): Promise<void>;
|
|
2325
|
+
/**
|
|
2326
|
+
* Sync indexes - create missing and drop extra indexes
|
|
2327
|
+
*/
|
|
2328
|
+
static syncIndexes<T extends Record<string, unknown>>(this: ModelConstructor<T>): Promise<string[]>;
|
|
2329
|
+
/**
|
|
2330
|
+
* List all indexes
|
|
2331
|
+
*/
|
|
2332
|
+
static listIndexes<T extends Record<string, unknown>>(this: ModelConstructor<T>): Promise<IndexDefinition[]>;
|
|
2333
|
+
/**
|
|
2334
|
+
* Execute bulk write operations
|
|
2335
|
+
*/
|
|
2336
|
+
static bulkWrite<T extends Record<string, unknown>>(this: ModelConstructor<T>, ops: BulkWriteOperation<T>[], options?: {
|
|
2337
|
+
ordered?: boolean;
|
|
2338
|
+
session?: any;
|
|
2339
|
+
}): Promise<BulkWriteResult>;
|
|
2340
|
+
/**
|
|
2341
|
+
* Watch for changes on the collection
|
|
2342
|
+
*/
|
|
2343
|
+
static watch<T extends Record<string, unknown>>(this: ModelConstructor<T>, pipeline?: Record<string, any>[], options?: Record<string, any>): ChangeStream<T>;
|
|
2344
|
+
/**
|
|
2345
|
+
* Create a discriminator model
|
|
2346
|
+
*/
|
|
2347
|
+
static discriminator<T extends Record<string, unknown>, D extends T>(this: ModelConstructor<T>, name: string, schema: Schema<D>, value?: string): ModelConstructor<D>;
|
|
2348
|
+
/**
|
|
2349
|
+
* Save a document to the database
|
|
2350
|
+
* @internal
|
|
2351
|
+
*/
|
|
2352
|
+
static _saveDocument<T extends Record<string, unknown>>(this: ModelConstructor<T>, doc: Document<T>, options?: any): Promise<Document<T>>;
|
|
2353
|
+
/**
|
|
2354
|
+
* Delete a document from the database
|
|
2355
|
+
* @internal
|
|
2356
|
+
*/
|
|
2357
|
+
static _deleteDocument<T extends Record<string, unknown>>(this: ModelConstructor<T>, doc: Document<T>, options?: any): Promise<Document<T>>;
|
|
2358
|
+
/**
|
|
2359
|
+
* Populate a document
|
|
2360
|
+
* @internal
|
|
2361
|
+
*/
|
|
2362
|
+
static _populateDocument<T extends Record<string, unknown>>(this: ModelConstructor<T>, doc: Document<T>, path: string | string[] | Record<string, any>): Promise<Document<T>>;
|
|
2363
|
+
/**
|
|
2364
|
+
* Translate aliases in an update document
|
|
2365
|
+
*/
|
|
2366
|
+
static translateAliases<T extends Record<string, unknown>>(this: ModelConstructor<T>, raw: Record<string, any>): Record<string, any>;
|
|
2367
|
+
/**
|
|
2368
|
+
* Validate paths
|
|
2369
|
+
*/
|
|
2370
|
+
static validate<T extends Record<string, unknown>>(this: ModelConstructor<T>, obj: Partial<T>, paths?: string[]): Promise<void>;
|
|
2371
|
+
/**
|
|
2372
|
+
* Cast a filter to proper types
|
|
2373
|
+
*/
|
|
2374
|
+
static castObject<T extends Record<string, unknown>>(this: ModelConstructor<T>, obj: Record<string, any>): Record<string, any>;
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Create a new model from a schema
|
|
2378
|
+
*/
|
|
2379
|
+
declare function model<T extends Record<string, unknown> = Record<string, unknown>>(name: string, schema: Schema<T>, options?: ModelOptions): ModelConstructor<T>;
|
|
2380
|
+
/**
|
|
2381
|
+
* Get a registered model by name
|
|
2382
|
+
*/
|
|
2383
|
+
declare function getModel<T extends Record<string, unknown> = Record<string, unknown>>(name: string): ModelConstructor<T> | undefined;
|
|
2384
|
+
/**
|
|
2385
|
+
* Check if a model is registered
|
|
2386
|
+
*/
|
|
2387
|
+
declare function hasModel(name: string): boolean;
|
|
2388
|
+
/**
|
|
2389
|
+
* Delete a registered model
|
|
2390
|
+
*/
|
|
2391
|
+
declare function deleteModel(name: string): boolean;
|
|
2392
|
+
/**
|
|
2393
|
+
* Get all registered model names
|
|
2394
|
+
*/
|
|
2395
|
+
declare function modelNames(): string[];
|
|
2396
|
+
|
|
2397
|
+
/**
|
|
2398
|
+
* Middleware/Hooks System for Mondoo
|
|
2399
|
+
*
|
|
2400
|
+
* Implements Mongoose-compatible pre/post hooks for documents, queries, models, and aggregations.
|
|
2401
|
+
*/
|
|
2402
|
+
|
|
2403
|
+
/**
|
|
2404
|
+
* Document middleware hooks - operate on document instances
|
|
2405
|
+
*/
|
|
2406
|
+
type DocumentHookType = 'validate' | 'save' | 'remove' | 'updateOne' | 'deleteOne' | 'init';
|
|
2407
|
+
/**
|
|
2408
|
+
* Query middleware hooks - operate on Query objects
|
|
2409
|
+
*/
|
|
2410
|
+
type QueryHookType = 'find' | 'findOne' | 'findOneAndUpdate' | 'findOneAndDelete' | 'findOneAndReplace' | 'updateOne' | 'updateMany' | 'deleteOne' | 'deleteMany';
|
|
2411
|
+
/**
|
|
2412
|
+
* Model middleware hooks - operate on Model class methods
|
|
2413
|
+
*/
|
|
2414
|
+
type ModelHookType = 'insertMany';
|
|
2415
|
+
/**
|
|
2416
|
+
* Aggregate middleware hooks - operate on Aggregation pipeline
|
|
2417
|
+
*/
|
|
2418
|
+
type AggregateHookType = 'aggregate';
|
|
2419
|
+
interface MiddlewareOptions {
|
|
2420
|
+
/** Run this hook on document operations (default: true for document hooks) */
|
|
2421
|
+
document?: boolean;
|
|
2422
|
+
/** Run this hook on query operations (default: true for query hooks) */
|
|
2423
|
+
query?: boolean;
|
|
2424
|
+
}
|
|
2425
|
+
interface MiddlewareEntry {
|
|
2426
|
+
fn: Function;
|
|
2427
|
+
options?: MiddlewareOptions;
|
|
2428
|
+
}
|
|
2429
|
+
/**
|
|
2430
|
+
* Context passed to hooks during execution
|
|
2431
|
+
*/
|
|
2432
|
+
interface HookContext {
|
|
2433
|
+
/** The document being operated on (for document hooks) */
|
|
2434
|
+
document?: any;
|
|
2435
|
+
/** The query being executed (for query hooks) */
|
|
2436
|
+
query?: any;
|
|
2437
|
+
/** The model class */
|
|
2438
|
+
model?: any;
|
|
2439
|
+
/** The aggregation pipeline (for aggregate hooks) */
|
|
2440
|
+
pipeline?: any[];
|
|
2441
|
+
/** Operation-specific options */
|
|
2442
|
+
options?: Record<string, any>;
|
|
2443
|
+
/** Whether this is a new document (for save hooks) */
|
|
2444
|
+
isNew?: boolean;
|
|
2445
|
+
/** Modified paths (for save/update hooks) */
|
|
2446
|
+
modifiedPaths?: string[];
|
|
2447
|
+
}
|
|
2448
|
+
declare class MiddlewareError extends Error {
|
|
2449
|
+
readonly hookType: HookType;
|
|
2450
|
+
readonly phase: 'pre' | 'post';
|
|
2451
|
+
readonly originalError?: Error | undefined;
|
|
2452
|
+
constructor(message: string, hookType: HookType, phase: 'pre' | 'post', originalError?: Error | undefined);
|
|
2453
|
+
}
|
|
2454
|
+
/**
|
|
2455
|
+
* Manages and executes pre and post hooks for a specific hook type
|
|
2456
|
+
*/
|
|
2457
|
+
declare class MiddlewareChain {
|
|
2458
|
+
readonly hookType: HookType;
|
|
2459
|
+
private _preHooks;
|
|
2460
|
+
private _postHooks;
|
|
2461
|
+
private _errorPostHooks;
|
|
2462
|
+
constructor(hookType: HookType);
|
|
2463
|
+
/**
|
|
2464
|
+
* Add a pre hook to the chain
|
|
2465
|
+
*/
|
|
2466
|
+
addPre(fn: Function, options?: MiddlewareOptions): this;
|
|
2467
|
+
/**
|
|
2468
|
+
* Add a post hook to the chain
|
|
2469
|
+
*/
|
|
2470
|
+
addPost(fn: Function, options?: MiddlewareOptions): this;
|
|
2471
|
+
/**
|
|
2472
|
+
* Add an error-handling post hook
|
|
2473
|
+
* Error post hooks receive (error, doc, next) and can handle or re-throw errors
|
|
2474
|
+
*/
|
|
2475
|
+
addPostError(fn: Function, options?: MiddlewareOptions): this;
|
|
2476
|
+
/**
|
|
2477
|
+
* Get all pre hooks
|
|
2478
|
+
*/
|
|
2479
|
+
getPreHooks(): MiddlewareEntry[];
|
|
2480
|
+
/**
|
|
2481
|
+
* Get all post hooks
|
|
2482
|
+
*/
|
|
2483
|
+
getPostHooks(): MiddlewareEntry[];
|
|
2484
|
+
/**
|
|
2485
|
+
* Run all pre hooks in sequence
|
|
2486
|
+
*
|
|
2487
|
+
* Hooks are executed in order. Each hook receives a next() callback.
|
|
2488
|
+
* Execution stops if:
|
|
2489
|
+
* - An error is thrown
|
|
2490
|
+
* - An error is passed to next(err)
|
|
2491
|
+
* - A hook returns a rejected Promise
|
|
2492
|
+
*/
|
|
2493
|
+
runPre(context: HookContext): Promise<void>;
|
|
2494
|
+
/**
|
|
2495
|
+
* Run all post hooks in sequence
|
|
2496
|
+
*
|
|
2497
|
+
* Post hooks receive the result of the operation.
|
|
2498
|
+
* Errors in post hooks are passed to error post hooks if available.
|
|
2499
|
+
*/
|
|
2500
|
+
runPost(context: HookContext, result: any): Promise<any>;
|
|
2501
|
+
/**
|
|
2502
|
+
* Check if a hook should run based on its options and context
|
|
2503
|
+
*/
|
|
2504
|
+
private _shouldRunHook;
|
|
2505
|
+
/**
|
|
2506
|
+
* Execute a single pre hook
|
|
2507
|
+
*/
|
|
2508
|
+
private _executeHook;
|
|
2509
|
+
/**
|
|
2510
|
+
* Execute a single post hook
|
|
2511
|
+
*/
|
|
2512
|
+
private _executePostHook;
|
|
2513
|
+
/**
|
|
2514
|
+
* Run error post hooks to handle errors from post hooks
|
|
2515
|
+
*/
|
|
2516
|
+
private _runErrorPostHooks;
|
|
2517
|
+
/**
|
|
2518
|
+
* Clear all hooks
|
|
2519
|
+
*/
|
|
2520
|
+
clear(): void;
|
|
2521
|
+
}
|
|
2522
|
+
/**
|
|
2523
|
+
* Manages all middleware chains for a schema
|
|
2524
|
+
*/
|
|
2525
|
+
declare class MiddlewareManager {
|
|
2526
|
+
private _chains;
|
|
2527
|
+
/**
|
|
2528
|
+
* Get or create a middleware chain for a hook type
|
|
2529
|
+
*/
|
|
2530
|
+
getChain(hookType: HookType): MiddlewareChain;
|
|
2531
|
+
/**
|
|
2532
|
+
* Check if there are any hooks for a given type
|
|
2533
|
+
*/
|
|
2534
|
+
hasHooks(hookType: HookType): boolean;
|
|
2535
|
+
/**
|
|
2536
|
+
* Create from a Schema's hook storage
|
|
2537
|
+
*/
|
|
2538
|
+
static fromSchema(schema: Schema<any>): MiddlewareManager;
|
|
2539
|
+
}
|
|
2540
|
+
/**
|
|
2541
|
+
* Execute pre hooks from a schema for a given hook type
|
|
2542
|
+
*
|
|
2543
|
+
* @param schema - The schema containing the hooks
|
|
2544
|
+
* @param hookType - The type of hook to execute
|
|
2545
|
+
* @param context - The execution context
|
|
2546
|
+
*/
|
|
2547
|
+
declare function executePreHooks(schema: Schema<any>, hookType: HookType, context: HookContext): Promise<void>;
|
|
2548
|
+
/**
|
|
2549
|
+
* Execute post hooks from a schema for a given hook type
|
|
2550
|
+
*
|
|
2551
|
+
* @param schema - The schema containing the hooks
|
|
2552
|
+
* @param hookType - The type of hook to execute
|
|
2553
|
+
* @param context - The execution context
|
|
2554
|
+
* @param result - The result of the operation
|
|
2555
|
+
* @returns The potentially modified result
|
|
2556
|
+
*/
|
|
2557
|
+
declare function executePostHooks<R>(schema: Schema<any>, hookType: HookType, context: HookContext, result: R): Promise<R>;
|
|
2558
|
+
/**
|
|
2559
|
+
* Execute both pre and post hooks around an operation
|
|
2560
|
+
*
|
|
2561
|
+
* @param schema - The schema containing the hooks
|
|
2562
|
+
* @param hookType - The type of hook to execute
|
|
2563
|
+
* @param context - The execution context
|
|
2564
|
+
* @param operation - The operation to execute between pre and post hooks
|
|
2565
|
+
* @returns The result of the operation
|
|
2566
|
+
*/
|
|
2567
|
+
declare function executeWithHooks<R>(schema: Schema<any>, hookType: HookType, context: HookContext, operation: () => R | Promise<R>): Promise<R>;
|
|
2568
|
+
/**
|
|
2569
|
+
* Create a hook context for document operations
|
|
2570
|
+
*/
|
|
2571
|
+
declare function createDocumentContext(document: any, options?: {
|
|
2572
|
+
isNew?: boolean;
|
|
2573
|
+
modifiedPaths?: string[];
|
|
2574
|
+
model?: any;
|
|
2575
|
+
}): HookContext;
|
|
2576
|
+
/**
|
|
2577
|
+
* Create a hook context for query operations
|
|
2578
|
+
*/
|
|
2579
|
+
declare function createQueryContext(query: any, options?: {
|
|
2580
|
+
model?: any;
|
|
2581
|
+
options?: Record<string, any>;
|
|
2582
|
+
}): HookContext;
|
|
2583
|
+
/**
|
|
2584
|
+
* Create a hook context for aggregate operations
|
|
2585
|
+
*/
|
|
2586
|
+
declare function createAggregateContext(pipeline: any[], options?: {
|
|
2587
|
+
model?: any;
|
|
2588
|
+
options?: Record<string, any>;
|
|
2589
|
+
}): HookContext;
|
|
2590
|
+
/**
|
|
2591
|
+
* Create a hook context for model operations (like insertMany)
|
|
2592
|
+
*/
|
|
2593
|
+
declare function createModelContext(model: any, options?: {
|
|
2594
|
+
documents?: any[];
|
|
2595
|
+
options?: Record<string, any>;
|
|
2596
|
+
}): HookContext;
|
|
2597
|
+
/**
|
|
2598
|
+
* Type guard to check if a hook type is a document hook
|
|
2599
|
+
*/
|
|
2600
|
+
declare function isDocumentHook(hookType: HookType): hookType is DocumentHookType;
|
|
2601
|
+
/**
|
|
2602
|
+
* Type guard to check if a hook type is a query hook
|
|
2603
|
+
*/
|
|
2604
|
+
declare function isQueryHook(hookType: HookType): hookType is QueryHookType;
|
|
2605
|
+
/**
|
|
2606
|
+
* Type guard to check if a hook type is a model hook
|
|
2607
|
+
*/
|
|
2608
|
+
declare function isModelHook(hookType: HookType): hookType is ModelHookType;
|
|
2609
|
+
/**
|
|
2610
|
+
* Type guard to check if a hook type is an aggregate hook
|
|
2611
|
+
*/
|
|
2612
|
+
declare function isAggregateHook(hookType: HookType): hookType is AggregateHookType;
|
|
2613
|
+
|
|
2614
|
+
/**
|
|
2615
|
+
* Population System for Mondoo
|
|
2616
|
+
*
|
|
2617
|
+
* Handles resolving ObjectId references to full documents with support for:
|
|
2618
|
+
* - Single and array ref population
|
|
2619
|
+
* - Nested population (populate within populated docs)
|
|
2620
|
+
* - Virtual population (reverse lookups via localField/foreignField)
|
|
2621
|
+
* - Query deduplication and batch optimization
|
|
2622
|
+
* - Circular reference handling
|
|
2623
|
+
*
|
|
2624
|
+
* @example
|
|
2625
|
+
* ```typescript
|
|
2626
|
+
* // Basic population
|
|
2627
|
+
* const user = await User.findById(id).populate('posts')
|
|
2628
|
+
*
|
|
2629
|
+
* // Nested population
|
|
2630
|
+
* const user = await User.findById(id).populate({
|
|
2631
|
+
* path: 'posts',
|
|
2632
|
+
* populate: { path: 'comments' }
|
|
2633
|
+
* })
|
|
2634
|
+
*
|
|
2635
|
+
* // Virtual population (reverse lookup)
|
|
2636
|
+
* const author = await Author.findById(id).populate({
|
|
2637
|
+
* path: 'books',
|
|
2638
|
+
* localField: '_id',
|
|
2639
|
+
* foreignField: 'author'
|
|
2640
|
+
* })
|
|
2641
|
+
* ```
|
|
2642
|
+
*/
|
|
2643
|
+
/**
|
|
2644
|
+
* Options for populating a path
|
|
2645
|
+
*/
|
|
2646
|
+
interface PopulateOptions {
|
|
2647
|
+
/** The path to populate */
|
|
2648
|
+
path: string;
|
|
2649
|
+
/** Fields to select in populated documents (projection) */
|
|
2650
|
+
select?: string | string[] | Record<string, 0 | 1>;
|
|
2651
|
+
/** Filter criteria for populated documents */
|
|
2652
|
+
match?: Record<string, unknown>;
|
|
2653
|
+
/** Override the model name from schema ref */
|
|
2654
|
+
model?: string;
|
|
2655
|
+
/** Additional query options (sort, limit, skip) */
|
|
2656
|
+
options?: PopulateQueryOptions;
|
|
2657
|
+
/** Nested population options */
|
|
2658
|
+
populate?: PopulateOptions | PopulateOptions[] | string;
|
|
2659
|
+
/** Force returning single doc (true) or array (false), overrides schema */
|
|
2660
|
+
justOne?: boolean;
|
|
2661
|
+
/** Local field for virtual population (default: path) */
|
|
2662
|
+
localField?: string;
|
|
2663
|
+
/** Foreign field for virtual population */
|
|
2664
|
+
foreignField?: string;
|
|
2665
|
+
/** Transform function applied to each populated doc */
|
|
2666
|
+
transform?: (doc: unknown) => unknown;
|
|
2667
|
+
/** Skip population if condition is false */
|
|
2668
|
+
skip?: boolean;
|
|
2669
|
+
/** Strict mode - throw if ref model not found */
|
|
2670
|
+
strictPopulate?: boolean;
|
|
2671
|
+
/** Limit number of populated docs per parent */
|
|
2672
|
+
perDocumentLimit?: number;
|
|
2673
|
+
}
|
|
2674
|
+
/**
|
|
2675
|
+
* Query options for population queries
|
|
2676
|
+
*/
|
|
2677
|
+
interface PopulateQueryOptions {
|
|
2678
|
+
sort?: string | Record<string, 1 | -1>;
|
|
2679
|
+
limit?: number;
|
|
2680
|
+
skip?: number;
|
|
2681
|
+
lean?: boolean;
|
|
2682
|
+
session?: unknown;
|
|
2683
|
+
}
|
|
2684
|
+
/**
|
|
2685
|
+
* Parsed population path info
|
|
2686
|
+
*/
|
|
2687
|
+
interface ParsedPopulatePath {
|
|
2688
|
+
/** The path to populate */
|
|
2689
|
+
path: string;
|
|
2690
|
+
/** The model name for this ref */
|
|
2691
|
+
modelName: string | null;
|
|
2692
|
+
/** Whether this is an array of refs */
|
|
2693
|
+
isArray: boolean;
|
|
2694
|
+
/** Whether this is a virtual population */
|
|
2695
|
+
isVirtual: boolean;
|
|
2696
|
+
/** Local field for virtual population */
|
|
2697
|
+
localField: string;
|
|
2698
|
+
/** Foreign field for virtual population */
|
|
2699
|
+
foreignField: string | null;
|
|
2700
|
+
/** The full populate options */
|
|
2701
|
+
options: PopulateOptions;
|
|
2702
|
+
}
|
|
2703
|
+
/**
|
|
2704
|
+
* Schema-like interface for extracting ref info
|
|
2705
|
+
*/
|
|
2706
|
+
interface SchemaLike {
|
|
2707
|
+
path(path: string): SchemaTypeLike | undefined;
|
|
2708
|
+
virtuals(): Map<string, VirtualLike>;
|
|
2709
|
+
}
|
|
2710
|
+
/**
|
|
2711
|
+
* Schema type interface for ref info
|
|
2712
|
+
*/
|
|
2713
|
+
interface SchemaTypeLike {
|
|
2714
|
+
_options?: {
|
|
2715
|
+
ref?: string;
|
|
2716
|
+
};
|
|
2717
|
+
_ref?: string;
|
|
2718
|
+
_itemType?: SchemaTypeLike;
|
|
2719
|
+
}
|
|
2720
|
+
/**
|
|
2721
|
+
* Virtual type interface
|
|
2722
|
+
*/
|
|
2723
|
+
interface VirtualLike {
|
|
2724
|
+
options?: {
|
|
2725
|
+
ref?: string;
|
|
2726
|
+
localField?: string;
|
|
2727
|
+
foreignField?: string;
|
|
2728
|
+
justOne?: boolean;
|
|
2729
|
+
};
|
|
2730
|
+
}
|
|
2731
|
+
/**
|
|
2732
|
+
* Model registry interface for looking up models by name
|
|
2733
|
+
*/
|
|
2734
|
+
interface ModelRegistry {
|
|
2735
|
+
get(name: string): ModelLike | undefined;
|
|
2736
|
+
}
|
|
2737
|
+
/**
|
|
2738
|
+
* Model-like interface for population queries
|
|
2739
|
+
*/
|
|
2740
|
+
interface ModelLike {
|
|
2741
|
+
find(filter: Record<string, unknown>, projection?: Record<string, 0 | 1>): PromiseLike<unknown[]>;
|
|
2742
|
+
findOne?(filter: Record<string, unknown>, projection?: Record<string, 0 | 1>): PromiseLike<unknown | null>;
|
|
2743
|
+
modelName: string;
|
|
2744
|
+
schema?: SchemaLike;
|
|
2745
|
+
}
|
|
2746
|
+
/**
|
|
2747
|
+
* Set the model registry for population lookups
|
|
2748
|
+
* @internal
|
|
2749
|
+
*/
|
|
2750
|
+
declare function setModelRegistry(registry: ModelRegistry): void;
|
|
2751
|
+
/**
|
|
2752
|
+
* Populate documents with referenced documents
|
|
2753
|
+
*
|
|
2754
|
+
* This is the main entry point for population. It handles:
|
|
2755
|
+
* - Single documents or arrays of documents
|
|
2756
|
+
* - Multiple populate paths
|
|
2757
|
+
* - Batch optimization (one query per ref model)
|
|
2758
|
+
* - Query deduplication
|
|
2759
|
+
*
|
|
2760
|
+
* @param docs - Document(s) to populate
|
|
2761
|
+
* @param paths - Population options (string, object, or array)
|
|
2762
|
+
* @param schema - Schema for resolving refs
|
|
2763
|
+
* @param options - Additional options
|
|
2764
|
+
* @returns The populated document(s)
|
|
2765
|
+
*
|
|
2766
|
+
* @example
|
|
2767
|
+
* ```typescript
|
|
2768
|
+
* // Populate a single path
|
|
2769
|
+
* const populated = await populate(user, 'posts', schema)
|
|
2770
|
+
*
|
|
2771
|
+
* // Populate multiple paths
|
|
2772
|
+
* const populated = await populate(user, ['posts', 'friends'], schema)
|
|
2773
|
+
*
|
|
2774
|
+
* // Populate with options
|
|
2775
|
+
* const populated = await populate(user, {
|
|
2776
|
+
* path: 'posts',
|
|
2777
|
+
* select: 'title content',
|
|
2778
|
+
* match: { published: true },
|
|
2779
|
+
* options: { sort: { createdAt: -1 }, limit: 10 }
|
|
2780
|
+
* }, schema)
|
|
2781
|
+
* ```
|
|
2782
|
+
*/
|
|
2783
|
+
declare function populate<T>(docs: T | T[], paths: string | string[] | PopulateOptions | PopulateOptions[], schema?: SchemaLike, options?: {
|
|
2784
|
+
session?: unknown;
|
|
2785
|
+
}): Promise<T | T[]>;
|
|
2786
|
+
/**
|
|
2787
|
+
* Collect all paths that need to be populated from a schema and options
|
|
2788
|
+
*
|
|
2789
|
+
* This helper parses populate options and resolves them against a schema
|
|
2790
|
+
* to get the full list of paths and their configurations.
|
|
2791
|
+
*
|
|
2792
|
+
* @param schema - The schema to check for refs
|
|
2793
|
+
* @param options - The populate options
|
|
2794
|
+
* @returns Array of parsed populate paths
|
|
2795
|
+
*/
|
|
2796
|
+
declare function collectPopulatePaths(schema: SchemaLike | undefined, options: string | string[] | PopulateOptions | PopulateOptions[]): ParsedPopulatePath[];
|
|
2797
|
+
/**
|
|
2798
|
+
* Resolve the referenced model name for a schema path
|
|
2799
|
+
*
|
|
2800
|
+
* @param schema - The schema to check
|
|
2801
|
+
* @param path - The path to check for ref
|
|
2802
|
+
* @returns The model name or null if not found
|
|
2803
|
+
*/
|
|
2804
|
+
declare function resolveRefModel(schema: SchemaLike | undefined, path: string): string | null;
|
|
2805
|
+
/**
|
|
2806
|
+
* Assign populated documents back to the parent documents
|
|
2807
|
+
*
|
|
2808
|
+
* This is a helper for manual population assignment when you have
|
|
2809
|
+
* already fetched the documents separately.
|
|
2810
|
+
*
|
|
2811
|
+
* @param docs - The parent documents to assign to
|
|
2812
|
+
* @param path - The path to assign at
|
|
2813
|
+
* @param fetchedDocs - Map of ID -> fetched document
|
|
2814
|
+
* @param options - Population options
|
|
2815
|
+
*/
|
|
2816
|
+
declare function assignPopulated(docs: unknown[], path: string, fetchedDocs: Map<string, unknown>, options?: {
|
|
2817
|
+
isArray?: boolean;
|
|
2818
|
+
justOne?: boolean;
|
|
2819
|
+
}): void;
|
|
2820
|
+
/**
|
|
2821
|
+
* Depopulate a path on documents - restore original ObjectId values
|
|
2822
|
+
*
|
|
2823
|
+
* @param docs - Documents to depopulate
|
|
2824
|
+
* @param path - Path to depopulate (or all if not specified)
|
|
2825
|
+
*/
|
|
2826
|
+
declare function depopulate(docs: unknown | unknown[], path?: string): void;
|
|
2827
|
+
/**
|
|
2828
|
+
* Check if a path on a document is currently populated
|
|
2829
|
+
*
|
|
2830
|
+
* @param doc - Document to check
|
|
2831
|
+
* @param path - Path to check
|
|
2832
|
+
* @returns true if the path is populated with a document/documents
|
|
2833
|
+
*/
|
|
2834
|
+
declare function isPopulated(doc: unknown, path: string): boolean;
|
|
2835
|
+
|
|
2836
|
+
/**
|
|
2837
|
+
* Connection adapter for Mondoo - adapts mondoo for Cloudflare Workers with capnweb
|
|
2838
|
+
*/
|
|
2839
|
+
|
|
2840
|
+
/**
|
|
2841
|
+
* Durable Object Namespace binding type
|
|
2842
|
+
* This is a simplified type - the actual type comes from @cloudflare/workers-types
|
|
2843
|
+
*/
|
|
2844
|
+
interface DurableObjectNamespace {
|
|
2845
|
+
newUniqueId(options?: {
|
|
2846
|
+
jurisdiction?: string;
|
|
2847
|
+
}): DurableObjectId;
|
|
2848
|
+
idFromName(name: string): DurableObjectId;
|
|
2849
|
+
idFromString(id: string): DurableObjectId;
|
|
2850
|
+
get(id: DurableObjectId): DurableObjectStub;
|
|
2851
|
+
}
|
|
2852
|
+
interface DurableObjectId {
|
|
2853
|
+
toString(): string;
|
|
2854
|
+
equals(other: DurableObjectId): boolean;
|
|
2855
|
+
}
|
|
2856
|
+
interface DurableObjectStub {
|
|
2857
|
+
id: DurableObjectId;
|
|
2858
|
+
name?: string;
|
|
2859
|
+
fetch(request: Request | string, init?: RequestInit): Promise<Response>;
|
|
2860
|
+
}
|
|
2861
|
+
/**
|
|
2862
|
+
* Connection ready states (compatible with Mongoose)
|
|
2863
|
+
*/
|
|
2864
|
+
declare const STATES: {
|
|
2865
|
+
readonly disconnected: 0;
|
|
2866
|
+
readonly connected: 1;
|
|
2867
|
+
readonly connecting: 2;
|
|
2868
|
+
readonly disconnecting: 3;
|
|
2869
|
+
};
|
|
2870
|
+
type ConnectionState = typeof STATES[keyof typeof STATES];
|
|
2871
|
+
/**
|
|
2872
|
+
* Event types for connection events
|
|
2873
|
+
*/
|
|
2874
|
+
type ConnectionEventType = 'connected' | 'disconnected' | 'error' | 'connecting' | 'disconnecting' | 'open' | 'close' | 'reconnected';
|
|
2875
|
+
/**
|
|
2876
|
+
* Connection options
|
|
2877
|
+
*/
|
|
2878
|
+
interface ConnectionOptions {
|
|
2879
|
+
/** Database name */
|
|
2880
|
+
dbName?: string;
|
|
2881
|
+
/** Auto create indexes on model creation */
|
|
2882
|
+
autoIndex?: boolean;
|
|
2883
|
+
/** Auto create collections */
|
|
2884
|
+
autoCreate?: boolean;
|
|
2885
|
+
/** Maximum pool size (not applicable for DO but kept for compatibility) */
|
|
2886
|
+
maxPoolSize?: number;
|
|
2887
|
+
/** Minimum pool size */
|
|
2888
|
+
minPoolSize?: number;
|
|
2889
|
+
/** Buffer commands when disconnected */
|
|
2890
|
+
bufferCommands?: boolean;
|
|
2891
|
+
}
|
|
2892
|
+
/**
|
|
2893
|
+
* Cloudflare Worker environment interface
|
|
2894
|
+
* This defines the expected shape of the Worker env object
|
|
2895
|
+
*/
|
|
2896
|
+
interface WorkerEnv {
|
|
2897
|
+
/** The Durable Object binding for mondodb */
|
|
2898
|
+
MONDODB?: DurableObjectNamespace;
|
|
2899
|
+
/** Alternative binding names */
|
|
2900
|
+
DB?: DurableObjectNamespace;
|
|
2901
|
+
DATABASE?: DurableObjectNamespace;
|
|
2902
|
+
/** Any other DO bindings */
|
|
2903
|
+
[key: string]: unknown;
|
|
2904
|
+
}
|
|
2905
|
+
/**
|
|
2906
|
+
* Session options for transactions
|
|
2907
|
+
*/
|
|
2908
|
+
interface SessionOptions {
|
|
2909
|
+
/** Default transaction options */
|
|
2910
|
+
defaultTransactionOptions?: {
|
|
2911
|
+
readConcern?: {
|
|
2912
|
+
level: string;
|
|
2913
|
+
};
|
|
2914
|
+
writeConcern?: {
|
|
2915
|
+
w: number | string;
|
|
2916
|
+
};
|
|
2917
|
+
};
|
|
2918
|
+
}
|
|
2919
|
+
/**
|
|
2920
|
+
* Client session for transactions (placeholder)
|
|
2921
|
+
*/
|
|
2922
|
+
interface ClientSession {
|
|
2923
|
+
/** Session ID */
|
|
2924
|
+
id: string;
|
|
2925
|
+
/** Whether the session is in a transaction */
|
|
2926
|
+
inTransaction(): boolean;
|
|
2927
|
+
/** Start a transaction */
|
|
2928
|
+
startTransaction(options?: Record<string, unknown>): void;
|
|
2929
|
+
/** Commit the transaction */
|
|
2930
|
+
commitTransaction(): Promise<void>;
|
|
2931
|
+
/** Abort the transaction */
|
|
2932
|
+
abortTransaction(): Promise<void>;
|
|
2933
|
+
/** End the session */
|
|
2934
|
+
endSession(): Promise<void>;
|
|
2935
|
+
/** Run a callback in a transaction */
|
|
2936
|
+
withTransaction<T>(fn: () => Promise<T>, options?: Record<string, unknown>): Promise<T>;
|
|
2937
|
+
}
|
|
2938
|
+
type EventListener = (...args: unknown[]) => void;
|
|
2939
|
+
/**
|
|
2940
|
+
* Simple EventEmitter implementation for connection events
|
|
2941
|
+
* Uses native EventTarget internally but provides Node.js-style API
|
|
2942
|
+
*/
|
|
2943
|
+
declare class SimpleEventEmitter {
|
|
2944
|
+
private _listeners;
|
|
2945
|
+
/**
|
|
2946
|
+
* Add an event listener
|
|
2947
|
+
*/
|
|
2948
|
+
on(event: string, listener: EventListener): this;
|
|
2949
|
+
/**
|
|
2950
|
+
* Add a one-time event listener
|
|
2951
|
+
*/
|
|
2952
|
+
once(event: string, listener: EventListener): this;
|
|
2953
|
+
/**
|
|
2954
|
+
* Remove an event listener
|
|
2955
|
+
*/
|
|
2956
|
+
off(event: string, listener: EventListener): this;
|
|
2957
|
+
/**
|
|
2958
|
+
* Remove all listeners for an event (or all events if no event specified)
|
|
2959
|
+
*/
|
|
2960
|
+
removeAllListeners(event?: string): this;
|
|
2961
|
+
/**
|
|
2962
|
+
* Emit an event
|
|
2963
|
+
*/
|
|
2964
|
+
emit(event: string, ...args: unknown[]): boolean;
|
|
2965
|
+
/**
|
|
2966
|
+
* Get the number of listeners for an event
|
|
2967
|
+
*/
|
|
2968
|
+
listenerCount(event: string): number;
|
|
2969
|
+
/**
|
|
2970
|
+
* Get all listeners for an event
|
|
2971
|
+
*/
|
|
2972
|
+
listeners(event: string): EventListener[];
|
|
2973
|
+
/**
|
|
2974
|
+
* Alias for on()
|
|
2975
|
+
*/
|
|
2976
|
+
addListener(event: string, listener: EventListener): this;
|
|
2977
|
+
/**
|
|
2978
|
+
* Alias for off()
|
|
2979
|
+
*/
|
|
2980
|
+
removeListener(event: string, listener: EventListener): this;
|
|
2981
|
+
}
|
|
2982
|
+
/**
|
|
2983
|
+
* Connection class for managing database connections
|
|
2984
|
+
* Adapts mondoo for Cloudflare Workers with Durable Objects
|
|
2985
|
+
*/
|
|
2986
|
+
declare class Connection extends SimpleEventEmitter {
|
|
2987
|
+
/** Current ready state */
|
|
2988
|
+
private _readyState;
|
|
2989
|
+
/** Registered models for this connection */
|
|
2990
|
+
private _models;
|
|
2991
|
+
/** Database reference (placeholder for mondodb DO) */
|
|
2992
|
+
private _db;
|
|
2993
|
+
/** Database name */
|
|
2994
|
+
private _name;
|
|
2995
|
+
/** Connection options */
|
|
2996
|
+
private _options;
|
|
2997
|
+
/** Worker environment reference */
|
|
2998
|
+
private _env;
|
|
2999
|
+
/** The host (for Mongoose compatibility) */
|
|
3000
|
+
private _host;
|
|
3001
|
+
/** The port (for Mongoose compatibility) */
|
|
3002
|
+
private _port;
|
|
3003
|
+
/** Connection URI (for Mongoose compatibility) */
|
|
3004
|
+
private _uri;
|
|
3005
|
+
/** Buffer for commands issued before connection is ready */
|
|
3006
|
+
private _commandBuffer;
|
|
3007
|
+
/**
|
|
3008
|
+
* Get the current ready state
|
|
3009
|
+
*/
|
|
3010
|
+
get readyState(): ConnectionState;
|
|
3011
|
+
/**
|
|
3012
|
+
* Get registered models
|
|
3013
|
+
*/
|
|
3014
|
+
get models(): Map<string, ModelConstructor<any>>;
|
|
3015
|
+
/**
|
|
3016
|
+
* Get database reference
|
|
3017
|
+
*/
|
|
3018
|
+
get db(): unknown;
|
|
3019
|
+
/**
|
|
3020
|
+
* Get database name
|
|
3021
|
+
*/
|
|
3022
|
+
get name(): string;
|
|
3023
|
+
/**
|
|
3024
|
+
* Get the host
|
|
3025
|
+
*/
|
|
3026
|
+
get host(): string;
|
|
3027
|
+
/**
|
|
3028
|
+
* Get the port
|
|
3029
|
+
*/
|
|
3030
|
+
get port(): number;
|
|
3031
|
+
/**
|
|
3032
|
+
* Get connection options
|
|
3033
|
+
*/
|
|
3034
|
+
get options(): ConnectionOptions;
|
|
3035
|
+
/**
|
|
3036
|
+
* Alias for models property (Mongoose compatibility)
|
|
3037
|
+
*/
|
|
3038
|
+
get collections(): Map<string, ModelConstructor<any>>;
|
|
3039
|
+
/**
|
|
3040
|
+
* Open a connection
|
|
3041
|
+
* In Workers context, this validates the environment is set up
|
|
3042
|
+
*/
|
|
3043
|
+
openUri(uri?: string, options?: ConnectionOptions): Promise<this>;
|
|
3044
|
+
/**
|
|
3045
|
+
* Set the Worker environment - this is the primary way to connect in Workers
|
|
3046
|
+
*/
|
|
3047
|
+
useEnv(env: WorkerEnv): this;
|
|
3048
|
+
/**
|
|
3049
|
+
* Get the Worker environment
|
|
3050
|
+
*/
|
|
3051
|
+
getEnv(): WorkerEnv | null;
|
|
3052
|
+
/**
|
|
3053
|
+
* Close the connection
|
|
3054
|
+
*/
|
|
3055
|
+
close(force?: boolean): Promise<void>;
|
|
3056
|
+
/**
|
|
3057
|
+
* Alias for close
|
|
3058
|
+
*/
|
|
3059
|
+
disconnect(): Promise<void>;
|
|
3060
|
+
/**
|
|
3061
|
+
* Extract database name from URI
|
|
3062
|
+
*/
|
|
3063
|
+
private _extractDbName;
|
|
3064
|
+
/**
|
|
3065
|
+
* Buffer a command if not connected
|
|
3066
|
+
*/
|
|
3067
|
+
private _bufferCommand;
|
|
3068
|
+
/**
|
|
3069
|
+
* Flush buffered commands
|
|
3070
|
+
*/
|
|
3071
|
+
private _flushCommandBuffer;
|
|
3072
|
+
/**
|
|
3073
|
+
* Register or retrieve a model
|
|
3074
|
+
*/
|
|
3075
|
+
model<T extends Record<string, unknown> = Record<string, unknown>>(name: string, schema?: Schema<T>, collection?: string): ModelConstructor<T>;
|
|
3076
|
+
/**
|
|
3077
|
+
* Get all registered model names
|
|
3078
|
+
*/
|
|
3079
|
+
modelNames(): string[];
|
|
3080
|
+
/**
|
|
3081
|
+
* Delete a model from the connection
|
|
3082
|
+
*/
|
|
3083
|
+
deleteModel(name: string): this;
|
|
3084
|
+
/**
|
|
3085
|
+
* Check if a model exists
|
|
3086
|
+
*/
|
|
3087
|
+
hasModel(name: string): boolean;
|
|
3088
|
+
/**
|
|
3089
|
+
* Start a session for transactions
|
|
3090
|
+
* Note: This is a placeholder - actual implementation depends on mondodb
|
|
3091
|
+
*/
|
|
3092
|
+
startSession(options?: SessionOptions): Promise<ClientSession>;
|
|
3093
|
+
/**
|
|
3094
|
+
* Run a function within a transaction
|
|
3095
|
+
*/
|
|
3096
|
+
transaction<T>(fn: (session: ClientSession) => Promise<T>, options?: SessionOptions): Promise<T>;
|
|
3097
|
+
/**
|
|
3098
|
+
* Set a connection option
|
|
3099
|
+
*/
|
|
3100
|
+
set(key: keyof ConnectionOptions, value: unknown): this;
|
|
3101
|
+
/**
|
|
3102
|
+
* Get a connection option
|
|
3103
|
+
*/
|
|
3104
|
+
get(key: keyof ConnectionOptions): unknown;
|
|
3105
|
+
/**
|
|
3106
|
+
* Create a new connection (for multiple database support)
|
|
3107
|
+
*/
|
|
3108
|
+
createConnection(): Connection;
|
|
3109
|
+
/**
|
|
3110
|
+
* Get the client (Mongoose compatibility)
|
|
3111
|
+
*/
|
|
3112
|
+
getClient(): unknown;
|
|
3113
|
+
/**
|
|
3114
|
+
* Set the client
|
|
3115
|
+
*/
|
|
3116
|
+
setClient(client: unknown): this;
|
|
3117
|
+
/**
|
|
3118
|
+
* Sync all indexes for registered models
|
|
3119
|
+
*/
|
|
3120
|
+
syncIndexes(options?: {
|
|
3121
|
+
background?: boolean;
|
|
3122
|
+
}): Promise<Record<string, string[]>>;
|
|
3123
|
+
/**
|
|
3124
|
+
* Drop the database
|
|
3125
|
+
* Note: Placeholder - actual implementation depends on mondodb
|
|
3126
|
+
*/
|
|
3127
|
+
dropDatabase(): Promise<void>;
|
|
3128
|
+
/**
|
|
3129
|
+
* List all collections
|
|
3130
|
+
*/
|
|
3131
|
+
listCollections(): Promise<string[]>;
|
|
3132
|
+
/**
|
|
3133
|
+
* Get a collection by name (Mongoose compatibility)
|
|
3134
|
+
*/
|
|
3135
|
+
collection(name: string): unknown;
|
|
3136
|
+
/**
|
|
3137
|
+
* Watch for changes (Mongoose compatibility)
|
|
3138
|
+
*/
|
|
3139
|
+
watch(pipeline?: Record<string, unknown>[], options?: Record<string, unknown>): unknown;
|
|
3140
|
+
/**
|
|
3141
|
+
* Check if connected
|
|
3142
|
+
*/
|
|
3143
|
+
isConnected(): boolean;
|
|
3144
|
+
/**
|
|
3145
|
+
* Asynchronously iterate over models
|
|
3146
|
+
*/
|
|
3147
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<[string, ModelConstructor<any>]>;
|
|
3148
|
+
}
|
|
3149
|
+
/**
|
|
3150
|
+
* Create a mondoo instance configured for a Cloudflare Worker
|
|
3151
|
+
* This is the recommended way to use mondoo in Workers
|
|
3152
|
+
*
|
|
3153
|
+
* @example
|
|
3154
|
+
* ```typescript
|
|
3155
|
+
* // In your Worker
|
|
3156
|
+
* export default {
|
|
3157
|
+
* async fetch(request: Request, env: Env) {
|
|
3158
|
+
* const mondoo = createMondoo(env)
|
|
3159
|
+
*
|
|
3160
|
+
* const User = mondoo.model('User', userSchema)
|
|
3161
|
+
* const users = await User.find()
|
|
3162
|
+
*
|
|
3163
|
+
* return Response.json(users)
|
|
3164
|
+
* }
|
|
3165
|
+
* }
|
|
3166
|
+
* ```
|
|
3167
|
+
*/
|
|
3168
|
+
declare function createMondoo(env: WorkerEnv, options?: ConnectionOptions): Connection;
|
|
3169
|
+
/**
|
|
3170
|
+
* Connect to database (Mongoose-compatible API)
|
|
3171
|
+
* In Workers, this is mainly for API compatibility - use createMondoo() instead
|
|
3172
|
+
*/
|
|
3173
|
+
declare function connect(uri?: string, options?: ConnectionOptions): Promise<Connection>;
|
|
3174
|
+
/**
|
|
3175
|
+
* Disconnect from database
|
|
3176
|
+
*/
|
|
3177
|
+
declare function disconnect(): Promise<void>;
|
|
3178
|
+
/**
|
|
3179
|
+
* The default connection instance
|
|
3180
|
+
* This mimics mongoose.connection
|
|
3181
|
+
*/
|
|
3182
|
+
declare const defaultConnection: Connection;
|
|
3183
|
+
/**
|
|
3184
|
+
* Alias for defaultConnection (mongoose.connection pattern)
|
|
3185
|
+
*/
|
|
3186
|
+
declare const connection: Connection;
|
|
3187
|
+
|
|
3188
|
+
/**
|
|
3189
|
+
* The main mondoo export - mimics mongoose's default export
|
|
3190
|
+
*/
|
|
3191
|
+
declare const mondoo: {
|
|
3192
|
+
$: {
|
|
3193
|
+
string: () => StringType<false>;
|
|
3194
|
+
number: () => NumberType<false>;
|
|
3195
|
+
boolean: () => BooleanType<false>;
|
|
3196
|
+
date: () => DateType<false>;
|
|
3197
|
+
objectId: () => ObjectIdType<false, never>;
|
|
3198
|
+
buffer: () => BufferType<false>;
|
|
3199
|
+
bigint: () => BigIntType<false>;
|
|
3200
|
+
array: <T>(itemType: SchemaType<T, any>) => ArrayType<T, false>;
|
|
3201
|
+
object: <T extends Record<string, SchemaType<any, any>>>(shape: T) => ObjectType<T, false>;
|
|
3202
|
+
map: <T>(valueType: SchemaType<T, any>) => MapType<T, false>;
|
|
3203
|
+
enum: <T extends readonly string[]>(values: T) => EnumType<T, false>;
|
|
3204
|
+
literal: <T extends string | number | boolean>(value: T) => LiteralType<T, false>;
|
|
3205
|
+
mixed: () => MixedType<false>;
|
|
3206
|
+
any: () => MixedType<false>;
|
|
3207
|
+
schema: <T extends Record<string, SchemaType<any, any>>>(shape: T, options?: SchemaOptions) => Schema<InferObject<T>>;
|
|
3208
|
+
infer: <T extends Schema<any>>() => T extends Schema<infer U> ? U : never;
|
|
3209
|
+
input: <T extends Schema<any>>() => T extends Schema<infer U> ? U : never;
|
|
3210
|
+
output: <T extends Schema<any>>() => T extends Schema<infer U> ? U : never;
|
|
3211
|
+
};
|
|
3212
|
+
Schema: typeof Schema;
|
|
3213
|
+
Document: typeof Document;
|
|
3214
|
+
Model: typeof Model;
|
|
3215
|
+
Query: typeof Query;
|
|
3216
|
+
Aggregate: typeof Aggregate;
|
|
3217
|
+
Connection: typeof Connection;
|
|
3218
|
+
Types: {
|
|
3219
|
+
String: StringConstructor;
|
|
3220
|
+
Number: NumberConstructor;
|
|
3221
|
+
Boolean: BooleanConstructor;
|
|
3222
|
+
Date: DateConstructor;
|
|
3223
|
+
ObjectId: "ObjectId";
|
|
3224
|
+
Buffer: "Buffer";
|
|
3225
|
+
Mixed: "Mixed";
|
|
3226
|
+
Array: ArrayConstructor;
|
|
3227
|
+
Map: MapConstructor;
|
|
3228
|
+
BigInt: BigIntConstructor;
|
|
3229
|
+
};
|
|
3230
|
+
model: typeof model;
|
|
3231
|
+
getModel: typeof getModel;
|
|
3232
|
+
hasModel: typeof hasModel;
|
|
3233
|
+
deleteModel: typeof deleteModel;
|
|
3234
|
+
modelNames: typeof modelNames;
|
|
3235
|
+
createMondoo: typeof createMondoo;
|
|
3236
|
+
connect: typeof connect;
|
|
3237
|
+
disconnect: typeof disconnect;
|
|
3238
|
+
connection: Connection;
|
|
3239
|
+
STATES: {
|
|
3240
|
+
readonly disconnected: 0;
|
|
3241
|
+
readonly connected: 1;
|
|
3242
|
+
readonly connecting: 2;
|
|
3243
|
+
readonly disconnecting: 3;
|
|
3244
|
+
};
|
|
3245
|
+
populate: typeof populate;
|
|
3246
|
+
version: string;
|
|
3247
|
+
};
|
|
3248
|
+
|
|
3249
|
+
export { $, Aggregate, AggregateCursor, type AggregateHookType, type AggregateOptions, ArrayType, BigIntType, BooleanType, type BucketAutoOptions, type BucketOptions, BufferType, type BulkWriteOperation, type BulkWriteResult, type ClientSession, Connection, type ConnectionEventType, type ConnectionOptions, type ConnectionState, DateType, type DeleteResult, Document, type DocumentHookType, type DocumentInternal, EnumType, type GeoNearOptions, type GraphLookupOptions, type HookType, type InferObject, type InferSchema, type InferSchemaType, LiteralType, type LookupOptions, MapType, type MergeOptions, MiddlewareChain, MiddlewareError, MiddlewareManager, MixedType, Model, type ModelConstructor, type ModelHookType, MongooseValidationError, NumberType, ObjectIdType, ObjectType, type PopulateOptions$1 as PopulateOptions, type PopulatedDoc, type PopulateOptions as PopulationOptions, type PostHookFn, type PreHookFn, Query, QueryCursor, type QueryHookType, type QueryOptions, STATES, type SampleOptions, Schema, type SchemaDefinition, type SchemaOptions$1 as SchemaOptions, SchemaType, type SchemaTypeOptions, type SessionOptions, StringType, type ToObjectOptions, Types, type UnionWithOptions, type UnwindOptions, type UpdateResult, type ValidationError, type WorkerEnv, assignPopulated, collectPopulatePaths, connect, connection, createAggregateContext, createDocumentContext, createModelContext, createMondoo, createQueryContext, mondoo as default, defaultConnection, deleteModel, depopulate, disconnect, executePostHooks, executePreHooks, executeWithHooks, getModel, hasModel, isAggregateHook, isDocumentHook, isModelHook, isPopulated, isQueryHook, model, modelNames, populate, resolveRefModel, setModelRegistry };
|