proto.io 0.0.227 → 0.0.229

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.
Files changed (65) hide show
  1. package/README.md +1017 -0
  2. package/dist/adapters/file/aliyun-oss.d.mts +26 -0
  3. package/dist/adapters/file/aliyun-oss.d.mts.map +1 -0
  4. package/dist/adapters/file/aliyun-oss.d.ts +3 -3
  5. package/dist/adapters/file/database.d.mts +23 -0
  6. package/dist/adapters/file/database.d.mts.map +1 -0
  7. package/dist/adapters/file/database.d.ts +2 -2
  8. package/dist/adapters/file/database.js +1 -1
  9. package/dist/adapters/file/database.mjs +1 -1
  10. package/dist/adapters/file/filesystem.d.mts +25 -0
  11. package/dist/adapters/file/filesystem.d.mts.map +1 -0
  12. package/dist/adapters/file/filesystem.d.ts +3 -3
  13. package/dist/adapters/file/google-cloud-storage.d.mts +29 -0
  14. package/dist/adapters/file/google-cloud-storage.d.mts.map +1 -0
  15. package/dist/adapters/file/google-cloud-storage.d.ts +3 -3
  16. package/dist/adapters/storage/postgres.d.mts +299 -0
  17. package/dist/adapters/storage/postgres.d.mts.map +1 -0
  18. package/dist/adapters/storage/postgres.d.ts +5 -1
  19. package/dist/adapters/storage/postgres.d.ts.map +1 -1
  20. package/dist/adapters/storage/postgres.js +182 -74
  21. package/dist/adapters/storage/postgres.js.map +1 -1
  22. package/dist/adapters/storage/postgres.mjs +182 -74
  23. package/dist/adapters/storage/postgres.mjs.map +1 -1
  24. package/dist/client.d.mts +16 -0
  25. package/dist/client.d.mts.map +1 -0
  26. package/dist/client.d.ts +3 -3
  27. package/dist/client.js +1 -1
  28. package/dist/client.mjs +2 -2
  29. package/dist/index.d.mts +151 -0
  30. package/dist/index.d.mts.map +1 -0
  31. package/dist/index.d.ts +3 -3
  32. package/dist/index.js +68 -25
  33. package/dist/index.js.map +1 -1
  34. package/dist/index.mjs +69 -26
  35. package/dist/index.mjs.map +1 -1
  36. package/dist/internals/{base-DSo02iAX.d.ts → base-Bhrj5Pq1.d.ts} +2 -2
  37. package/dist/internals/{base-DSo02iAX.d.ts.map → base-Bhrj5Pq1.d.ts.map} +1 -1
  38. package/dist/internals/base-CiZHXD0o.d.mts +27 -0
  39. package/dist/internals/base-CiZHXD0o.d.mts.map +1 -0
  40. package/dist/internals/chunk-Cp2QN7ug.d.mts +17 -0
  41. package/dist/internals/chunk-Cp2QN7ug.d.mts.map +1 -0
  42. package/dist/internals/{chunk-BhwfdCdq.d.ts → chunk-o7lWIP-f.d.ts} +3 -3
  43. package/dist/internals/{chunk-BhwfdCdq.d.ts.map → chunk-o7lWIP-f.d.ts.map} +1 -1
  44. package/dist/internals/{index-vOFh8pVc.js → index-B0TO6h9r.js} +8 -1
  45. package/dist/internals/index-B0TO6h9r.js.map +1 -0
  46. package/dist/internals/{index-Cj45GkKv.d.ts → index-B710pfTH.d.ts} +2 -2
  47. package/dist/internals/{index-Cj45GkKv.d.ts.map → index-B710pfTH.d.ts.map} +1 -1
  48. package/dist/internals/{index-BWZIV3_T.mjs → index-DG2-4tQ1.mjs} +8 -1
  49. package/dist/internals/index-DG2-4tQ1.mjs.map +1 -0
  50. package/dist/internals/index-DwjvuRyl.d.mts +92 -0
  51. package/dist/internals/index-DwjvuRyl.d.mts.map +1 -0
  52. package/dist/internals/index-OwgXw07h.d.mts +2107 -0
  53. package/dist/internals/index-OwgXw07h.d.mts.map +1 -0
  54. package/dist/internals/{index-1ZK5N4yb.d.ts → index-OwgXw07h.d.ts} +49 -7
  55. package/dist/internals/index-OwgXw07h.d.ts.map +1 -0
  56. package/dist/internals/{validator-Bc1jRJfA.js → validator-CFlx3oyq.js} +33 -1
  57. package/dist/internals/validator-CFlx3oyq.js.map +1 -0
  58. package/dist/internals/{validator-Boj1PUjM.mjs → validator-DubDY921.mjs} +32 -2
  59. package/dist/internals/validator-DubDY921.mjs.map +1 -0
  60. package/package.json +7 -19
  61. package/dist/internals/index-1ZK5N4yb.d.ts.map +0 -1
  62. package/dist/internals/index-BWZIV3_T.mjs.map +0 -1
  63. package/dist/internals/index-vOFh8pVc.js.map +0 -1
  64. package/dist/internals/validator-Bc1jRJfA.js.map +0 -1
  65. package/dist/internals/validator-Boj1PUjM.mjs.map +0 -1
@@ -0,0 +1,2107 @@
1
+ import * as _o2ter_utils_js from '@o2ter/utils-js';
2
+ import { BinaryData, asyncStream, Awaitable } from '@o2ter/utils-js';
3
+ import jwt, { SignOptions, VerifyOptions } from 'jsonwebtoken';
4
+ import { Request, CookieOptions } from '@o2ter/server-js';
5
+ import Decimal$1, { Decimal } from 'decimal.js';
6
+ import _$1 from 'lodash';
7
+ import { Readable } from 'node:stream';
8
+ import * as socket_io_client from 'socket.io-client';
9
+ import { Socket } from 'socket.io-client';
10
+
11
+ type _Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
12
+ type _Lower = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
13
+ type _Upper = Uppercase<_Lower>;
14
+ type _Alphabet = _Lower | _Upper;
15
+ type _String<T extends string, C extends string | number> = T extends `${infer H}${C}` ? H extends '' | _String<H, C> ? T : never : never;
16
+ type Digits<T extends string> = T extends `${number}` ? T : never;
17
+ type FieldName<T extends string> = string extends T ? string : T extends `${'_' | _Alphabet}${'' | _String<infer _U, '_' | '-' | _Alphabet | _Digit>}` ? T : never;
18
+ type PathArrayGetter<T extends string> = T extends `[${Digits<infer _T>}]` ? T : T extends `[${Digits<infer L>}]${infer R}` ? `[${L}]${PathArrayGetter<R>}` : never;
19
+ type PathComponent<T extends string> = T extends Digits<T> | FieldName<T> ? T : T extends `${Digits<infer L> | FieldName<infer L>}[${infer _R}` ? `${L}${PathArrayGetter<`[${_R}`>}` : never;
20
+ type PathComponents<T extends string> = T extends PathComponent<T> ? T : T extends `${PathComponent<infer L>}.${infer R}` ? `${L}.${PathComponents<R>}` : never;
21
+ type PathName<T extends string> = string extends T ? string : T extends '$' | PathComponent<T> ? T : T extends `${infer L}.${infer R}` ? `${PathComponent<L>}.${PathComponents<R>}` : never;
22
+ type IncludePath<T extends string> = T extends '*' | FieldName<T> ? T : T extends `${infer L}.${infer R}` ? `${FieldName<L>}.${IncludePath<R>}` : never;
23
+ type IncludePaths<T extends _$1.RecursiveArray<string>> = T extends [] ? [] : T extends [infer H extends string, ...infer R extends _$1.RecursiveArray<string>] ? H extends undefined ? IncludePaths<R> : [IncludePath<H>, ...IncludePaths<R>] : T;
24
+ type PathNameMap<T extends object> = Exact<T, {
25
+ [K in keyof T as K extends string ? PathName<K> : never]: T[K];
26
+ }>;
27
+
28
+ declare class TUser extends TObject {
29
+ constructor(attributes?: Record<string, TValue> | ((self: TObject) => Record<string, TValue>));
30
+ }
31
+
32
+ /**
33
+ * Class representing a Role.
34
+ * @extends TObject
35
+ */
36
+ declare class TRole extends TObject {
37
+ constructor(attributes?: Record<string, TValue> | ((self: TObject) => Record<string, TValue>));
38
+ /**
39
+ * Get the name of the role.
40
+ * @return {string | undefined} The name of the role.
41
+ */
42
+ get name(): string | undefined;
43
+ /**
44
+ * Get the users associated with the role.
45
+ * @return {TUser[]} The users associated with the role.
46
+ */
47
+ get users(): TUser[];
48
+ /**
49
+ * Set the users associated with the role.
50
+ * @param {TUser[]} value - The users to associate with the role.
51
+ */
52
+ set users(value: TUser[]);
53
+ /**
54
+ * Get the roles associated with the role.
55
+ * @return {TRole[]} The roles associated with the role.
56
+ */
57
+ get roles(): TRole[];
58
+ /**
59
+ * Set the roles associated with the role.
60
+ * @param {TRole[]} value - The roles to associate with the role.
61
+ */
62
+ set roles(value: TRole[]);
63
+ }
64
+
65
+ /**
66
+ * Represents a stream of data that can be read.
67
+ * It can be either a ReadableStream or a Readable.
68
+ */
69
+ type FileStream = ReadableStream | Readable;
70
+ /**
71
+ * Represents the data of a file.
72
+ * It can be a string, Blob, BinaryData, FileStream, or an object containing a base64 string.
73
+ */
74
+ type FileData = string | Blob | BinaryData | FileStream | {
75
+ base64: string;
76
+ };
77
+
78
+ /**
79
+ * Interface representing a file.
80
+ */
81
+ interface TFile {
82
+ /**
83
+ * URL of the file.
84
+ */
85
+ url: string | undefined;
86
+ /**
87
+ * Retrieves the file data.
88
+ * @param options - Optional extra options.
89
+ * @returns A FileStream containing the file data.
90
+ */
91
+ fileData(options?: ExtraOptions<boolean>): FileStream;
92
+ /**
93
+ * Saves the file.
94
+ * @param options - Optional extra options including cascadeSave and uploadToken.
95
+ * @returns A promise that resolves to the current instance.
96
+ */
97
+ save(options?: ExtraOptions<boolean> & {
98
+ cascadeSave?: boolean;
99
+ uploadToken?: string;
100
+ }): PromiseLike<this>;
101
+ }
102
+ /**
103
+ * Class representing a file.
104
+ */
105
+ declare class TFile extends TObject {
106
+ constructor(attributes?: Record<string, TValue> | ((self: TObject) => Record<string, TValue>));
107
+ /**
108
+ * Gets the filename of the file.
109
+ * @returns The filename.
110
+ */
111
+ get filename(): string | undefined;
112
+ /**
113
+ * Gets the size of the file.
114
+ * @returns The size of the file.
115
+ */
116
+ get size(): number | undefined;
117
+ /**
118
+ * Gets the type of the file.
119
+ * @returns The type of the file.
120
+ */
121
+ get type(): string | undefined;
122
+ /**
123
+ * Gets the token of the file.
124
+ * @returns The token of the file.
125
+ */
126
+ get token(): string | undefined;
127
+ }
128
+
129
+ /**
130
+ * Class representing a Job.
131
+ * @extends TObject
132
+ */
133
+ declare class TJob extends TObject {
134
+ constructor(attributes?: Record<string, TValue> | ((self: TObject) => Record<string, TValue>));
135
+ /**
136
+ * Get the name of the job.
137
+ * @return {string} The name of the job.
138
+ */
139
+ get name(): string;
140
+ /**
141
+ * Get the data of the job.
142
+ * @return {TValue | undefined} The data of the job.
143
+ */
144
+ get data(): TValue | undefined;
145
+ /**
146
+ * Get the user associated with the job.
147
+ * @return {TUser | undefined} The user associated with the job.
148
+ */
149
+ get user(): TUser | undefined;
150
+ /**
151
+ * Get the error of the job.
152
+ * @return {TValue | undefined} The error of the job.
153
+ */
154
+ get error(): TValue | undefined;
155
+ /**
156
+ * Get the start time of the job.
157
+ * @return {Date | undefined} The start time of the job.
158
+ */
159
+ get startedAt(): Date | undefined;
160
+ /**
161
+ * Get the completion time of the job.
162
+ * @return {Date | undefined} The completion time of the job.
163
+ */
164
+ get completedAt(): Date | undefined;
165
+ }
166
+
167
+ declare class TSession extends TObject {
168
+ constructor(attributes?: Record<string, TValue> | ((self: TObject) => Record<string, TValue>));
169
+ /**
170
+ * Get the session ID.
171
+ * @return {string} The session ID.
172
+ */
173
+ get sessionId(): string;
174
+ /**
175
+ * Get the user associated with the session.
176
+ * @return {TObject | undefined} The user associated with the session.
177
+ */
178
+ get user(): TObject | undefined;
179
+ get loginedAt(): Date | undefined;
180
+ }
181
+
182
+ declare const TObjectTypes: {
183
+ User: typeof TUser;
184
+ Role: typeof TRole;
185
+ File: typeof TFile;
186
+ _Job: typeof TJob;
187
+ _Session: typeof TSession;
188
+ };
189
+ type _TObjectType<K> = K extends keyof typeof TObjectTypes ? InstanceType<(typeof TObjectTypes)[K]> : TObject;
190
+ type PickBy<T, C> = {
191
+ [P in keyof T as T[P] extends C ? P : never]: T[P];
192
+ };
193
+ type PropertyDescriptor<T> = {
194
+ enumerable?: boolean;
195
+ get: () => T;
196
+ set?: (value: T) => void;
197
+ };
198
+ type ReadOnlyProperty<T> = Pick<PropertyDescriptor<T>, 'get'>;
199
+ type ReadWriteProperty<T> = Required<Pick<PropertyDescriptor<T>, 'get' | 'set'>>;
200
+ type PropertyMapToMethods<T> = PickBy<T, Function> & {
201
+ [P in keyof PickBy<T, ReadWriteProperty<any>>]: T[P] extends PropertyDescriptor<infer V> ? V : never;
202
+ } & {
203
+ readonly [P in keyof PickBy<T, ReadOnlyProperty<any>>]: T[P] extends PropertyDescriptor<infer V> ? V : never;
204
+ };
205
+ type Property<T> = T extends Function ? T | PropertyDescriptor<T> : PropertyDescriptor<T>;
206
+ type PropertyMap<T, O, A> = {
207
+ [K in keyof T]: T[K] extends Property<any> ? T[K] : never;
208
+ } & ThisType<O & PropertyMapToMethods<T> & PropertyMapToMethods<A>>;
209
+ type TExtensions<E> = {
210
+ [K in keyof E]: PropertyMap<E[K], _TObjectType<K>, '*' extends keyof E ? Omit<E['*'], keyof E[K]> : {}>;
211
+ };
212
+ type _TMethods<K, E> = K extends keyof E ? '*' extends keyof E ? PropertyMapToMethods<Omit<E['*'], keyof E[K]> & E[K]> : PropertyMapToMethods<E[K]> : {};
213
+ type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
214
+ type TMethods<K, E> = IfAny<E, {}, _TMethods<K, E>>;
215
+ type TObjectType<K, E> = _TObjectType<K> & TMethods<K, E>;
216
+ declare const TUpdateOpKeys: readonly ["$set", "$inc", "$dec", "$mul", "$div", "$max", "$min", "$addToSet", "$push", "$removeAll", "$popFirst", "$popLast"];
217
+ type TUpdateOp = ExactOneProp<Record<(typeof TUpdateOpKeys)[number], TValueWithUndefined>>;
218
+
219
+ declare const TComparisonKeys: readonly ["$eq", "$gt", "$gte", "$lt", "$lte", "$ne"];
220
+ declare const TValueListKeys: readonly ["$in", "$nin"];
221
+ declare const TValueSetKeys: readonly ["$subset", "$superset", "$intersect"];
222
+ declare const TConditionalKeys: readonly ["$and", "$nor", "$or"];
223
+
224
+ declare const TZeroParamExprKeys: readonly ["$now", "$rand"];
225
+ declare const TUnaryExprKeys: readonly ["$abs", "$neg", "$sqrt", "$cbrt", "$ceil", "$floor", "$round", "$exp", "$ln", "$log2", "$log10", "$sin", "$cos", "$tan", "$asin", "$acos", "$atan", "$asinh", "$acosh", "$atanh", "$sinh", "$cosh", "$tanh", "$degrees", "$radians", "$sign", "$size", "$lower", "$upper"];
226
+ declare const TBinaryExprKeys: readonly ["$divide", "$subtract", "$log", "$pow", "$atan2", "$trim", "$ltrim", "$rtrim", "$first", "$last", "$ldrop", "$rdrop"];
227
+ declare const TTernaryExprKeys: readonly ["$lpad", "$rpad"];
228
+ declare const TListExprKeys: readonly ["$add", "$multiply", "$ifNull", "$concat"];
229
+ declare const TDistanceExprKeys: readonly ["$distance", "$innerProduct", "$negInnerProduct", "$cosineDistance", "$rectilinearDistance"];
230
+ type TBooleanExpression = {
231
+ $not?: TBooleanExpression;
232
+ } & {
233
+ [x in (typeof TComparisonKeys)[number]]?: [TExpression, TExpression];
234
+ } & {
235
+ [x in (typeof TConditionalKeys)[number]]?: TBooleanExpression[];
236
+ };
237
+ type TDistanceExpression = {
238
+ [x in (typeof TDistanceExprKeys)[number]]?: [
239
+ TExpression[] | {
240
+ $key: string;
241
+ } | {
242
+ $value: number[];
243
+ },
244
+ TExpression[] | {
245
+ $key: string;
246
+ } | {
247
+ $value: number[];
248
+ }
249
+ ];
250
+ };
251
+ type TExpression = {
252
+ $array?: TExpression[];
253
+ $key?: string;
254
+ $value?: TValue;
255
+ } & {
256
+ $cond?: {
257
+ branch: _.Many<{
258
+ case: TExpression;
259
+ then: TExpression;
260
+ }[]>;
261
+ default: TExpression;
262
+ };
263
+ } & {
264
+ [x in (typeof TZeroParamExprKeys)[number]]?: true | {};
265
+ } & {
266
+ [x in (typeof TUnaryExprKeys)[number]]?: TExpression;
267
+ } & {
268
+ [x in (typeof TBinaryExprKeys)[number]]?: [TExpression, TExpression];
269
+ } & {
270
+ [x in (typeof TTernaryExprKeys)[number]]?: [TExpression, TExpression, TExpression];
271
+ } & {
272
+ [x in (typeof TListExprKeys)[number]]?: TExpression[];
273
+ } & TBooleanExpression & TDistanceExpression;
274
+
275
+ type TThisQuerySelector = {
276
+ $?: TFieldQuerySelector;
277
+ };
278
+ type TFieldQuerySelector = {
279
+ $not?: TFieldQuerySelector;
280
+ $starts?: string;
281
+ $ends?: string;
282
+ $pattern?: RegExp | string;
283
+ $size?: number;
284
+ $empty?: boolean;
285
+ $every?: TQuerySelector | TThisQuerySelector;
286
+ $some?: TQuerySelector | TThisQuerySelector;
287
+ } & {
288
+ [x in (typeof TComparisonKeys)[number]]?: TValue;
289
+ } & {
290
+ [x in (typeof TValueListKeys)[number]]?: TValue[];
291
+ } & {
292
+ [x in (typeof TValueSetKeys)[number]]?: TValue[];
293
+ };
294
+ type TCoditionalQuerySelector = {
295
+ [x in (typeof TConditionalKeys)[number]]?: TQuerySelector[];
296
+ };
297
+ type TQuerySelector = (TCoditionalQuerySelector & {
298
+ $expr?: TBooleanExpression;
299
+ }) | {
300
+ [x: string]: TFieldQuerySelector;
301
+ };
302
+
303
+ declare const TUnaryAccumulatorKeys: readonly ["$max", "$min", "$most", "$sum", "$avg", "$stdDevPop", "$stdDevSamp", "$varPop", "$varSamp"];
304
+ declare const TZeroParamAccumulatorKeys: readonly ["$count"];
305
+ type TQueryAccumulator = {
306
+ $percentile?: {
307
+ input: TExpression;
308
+ p: number;
309
+ mode?: 'discrete' | 'continuous';
310
+ };
311
+ $group?: {
312
+ key: TExpression;
313
+ value: Omit<TQueryAccumulator, '$group'>;
314
+ };
315
+ } & {
316
+ [x in (typeof TZeroParamAccumulatorKeys)[number]]?: true | {};
317
+ } & {
318
+ [x in (typeof TUnaryAccumulatorKeys)[number]]?: TExpression;
319
+ };
320
+ type TAccumulatorResult<A extends TQueryAccumulator> = A extends {
321
+ $group: any;
322
+ } ? {
323
+ key: any;
324
+ value: any;
325
+ }[] : A extends {
326
+ $count: any;
327
+ } ? number : any;
328
+
329
+ /**
330
+ * Options for a query filter.
331
+ */
332
+ interface TQueryFilterBaseOptions {
333
+ /**
334
+ * The filter(s) to apply to the query.
335
+ */
336
+ filter?: TQuerySelector | TQuerySelector[];
337
+ }
338
+ /**
339
+ * Sort option for a query.
340
+ */
341
+ type TSortOption = {
342
+ /**
343
+ * The expression to sort by.
344
+ */
345
+ expr: TExpression;
346
+ /**
347
+ * The order of sorting, 1 for ascending and -1 for descending.
348
+ */
349
+ order: 1 | -1;
350
+ };
351
+ /**
352
+ * Base options for a query.
353
+ */
354
+ interface TQueryBaseOptions extends TQueryFilterBaseOptions {
355
+ /**
356
+ * The sorting options for the query.
357
+ */
358
+ sort?: Record<string, 1 | -1> | TSortOption[];
359
+ /**
360
+ * The number of results to skip.
361
+ */
362
+ skip?: number;
363
+ /**
364
+ * The limit on the number of results.
365
+ */
366
+ limit?: number;
367
+ /**
368
+ * Nested query options for matching specific fields.
369
+ */
370
+ matches?: Record<string, TQueryBaseOptions>;
371
+ /**
372
+ * Groups the query results by the specified key and applies the provided accumulators.
373
+ */
374
+ groupMatches?: Record<string, Record<string, TQueryAccumulator>>;
375
+ }
376
+ /**
377
+ * Base class for query filters.
378
+ */
379
+ declare class TQueryFilterBase {
380
+ /**
381
+ * Applies a filter to the query.
382
+ * @param filter - The filter to apply.
383
+ * @returns The current instance for chaining.
384
+ */
385
+ filter(filter: TQuerySelector): this;
386
+ /**
387
+ * Applies an equality filter to the query.
388
+ * @param key - The key to filter.
389
+ * @param value - The value to filter.
390
+ * @returns The current instance for chaining.
391
+ */
392
+ equalTo<T extends string>(key: PathName<T>, value: TValueWithUndefined): this;
393
+ /**
394
+ * Applies a not equal filter to the query.
395
+ * @param key - The key to filter.
396
+ * @param value - The value to filter.
397
+ * @returns The current instance for chaining.
398
+ */
399
+ notEqualTo<T extends string>(key: PathName<T>, value: TValueWithUndefined): this;
400
+ /**
401
+ * Applies a less than filter to the query.
402
+ * @param key - The key to filter.
403
+ * @param value - The value to filter.
404
+ * @returns The current instance for chaining.
405
+ */
406
+ lessThan<T extends string>(key: PathName<T>, value: TValueWithUndefined): this;
407
+ /**
408
+ * Applies a greater than filter to the query.
409
+ * @param key - The key to filter.
410
+ * @param value - The value to filter.
411
+ * @returns The current instance for chaining.
412
+ */
413
+ greaterThan<T extends string>(key: PathName<T>, value: TValueWithUndefined): this;
414
+ /**
415
+ * Applies a less than or equal to filter to the query.
416
+ * @param key - The key to filter.
417
+ * @param value - The value to filter.
418
+ * @returns The current instance for chaining.
419
+ */
420
+ lessThanOrEqualTo<T extends string>(key: PathName<T>, value: TValueWithUndefined): this;
421
+ /**
422
+ * Applies a greater than or equal to filter to the query.
423
+ * @param key - The key to filter.
424
+ * @param value - The value to filter.
425
+ * @returns The current instance for chaining.
426
+ */
427
+ greaterThanOrEqualTo<T extends string>(key: PathName<T>, value: TValueWithUndefined): this;
428
+ /**
429
+ * Applies a pattern filter to the query.
430
+ * @param key - The key to filter.
431
+ * @param value - The pattern to filter.
432
+ * @returns The current instance for chaining.
433
+ */
434
+ pattern<T extends string>(key: PathName<T>, value: RegExp | string): this;
435
+ /**
436
+ * Applies a starts with filter to the query.
437
+ * @param key - The key to filter.
438
+ * @param value - The value to filter.
439
+ * @returns The current instance for chaining.
440
+ */
441
+ startsWith<T extends string>(key: PathName<T>, value: string): this;
442
+ /**
443
+ * Applies an ends with filter to the query.
444
+ * @param key - The key to filter.
445
+ * @param value - The value to filter.
446
+ * @returns The current instance for chaining.
447
+ */
448
+ endsWith<T extends string>(key: PathName<T>, value: string): this;
449
+ /**
450
+ * Applies a size filter to the query.
451
+ * @param key - The key to filter.
452
+ * @param value - The value to filter.
453
+ * @returns The current instance for chaining.
454
+ */
455
+ size<T extends string>(key: PathName<T>, value: number): this;
456
+ /**
457
+ * Applies an empty filter to the query.
458
+ * @param key - The key to filter.
459
+ * @returns The current instance for chaining.
460
+ */
461
+ empty<T extends string>(key: PathName<T>): this;
462
+ /**
463
+ * Applies a not empty filter to the query.
464
+ * @param key - The key to filter.
465
+ * @returns The current instance for chaining.
466
+ */
467
+ notEmpty<T extends string>(key: PathName<T>): this;
468
+ /**
469
+ * Filters the query to include only documents where the specified key contains any of the specified values.
470
+ * @param key - The key to check for values.
471
+ * @param value - The array of values to check for.
472
+ * @returns The current instance for chaining.
473
+ */
474
+ containedIn<T extends string>(key: PathName<T>, value: TValueWithUndefined[]): this;
475
+ /**
476
+ * Filters the query to exclude documents where the specified key contains any of the specified values.
477
+ * @param key - The key to check for values.
478
+ * @param value - The array of values to exclude.
479
+ * @returns The current instance for chaining.
480
+ */
481
+ notContainedIn<T extends string>(key: PathName<T>, value: TValueWithUndefined[]): this;
482
+ /**
483
+ * Filters the query to include only documents where the specified key contains all of the specified values.
484
+ * @param key - The key to check for containing values.
485
+ * @param value - The array of values to check against.
486
+ * @returns The current instance for chaining.
487
+ */
488
+ containedBy<T extends string>(key: PathName<T>, value: TValueWithUndefined[]): this;
489
+ /**
490
+ * Filters the query to exclude documents where the specified key contains all of the specified values.
491
+ * @param key - The key to check for superset.
492
+ * @param value - The array of values to check against.
493
+ * @returns The current instance for chaining.
494
+ */
495
+ notContainedBy<T extends string>(key: PathName<T>, value: TValueWithUndefined[]): this;
496
+ /**
497
+ * Filters the query to include only documents where the specified key is a subset of the specified values.
498
+ * @param key - The key to check for subset.
499
+ * @param value - The array of values to check against.
500
+ * @returns The current instance for chaining.
501
+ */
502
+ isSubset<T extends string>(key: PathName<T>, value: TValueWithUndefined[]): this;
503
+ /**
504
+ * Filters the query to include only documents where the specified key is a superset of the specified values.
505
+ * @param key - The key to check for superset.
506
+ * @param value - The array of values to check against.
507
+ * @returns The current instance for chaining.
508
+ */
509
+ isSuperset<T extends string>(key: PathName<T>, value: TValueWithUndefined[]): this;
510
+ /**
511
+ * Filters the query to include only documents where the specified key is disjoint from the specified values.
512
+ * @param key - The key to check for disjoint.
513
+ * @param value - The array of values to check against.
514
+ * @returns The current instance for chaining.
515
+ */
516
+ isDisjoint<T extends string>(key: PathName<T>, value: TValueWithUndefined[]): this;
517
+ /**
518
+ * Filters the query to include only documents where the specified key intersects with the specified values.
519
+ * @param key - The key to check for intersection.
520
+ * @param value - The array of values to check against.
521
+ * @returns The current instance for chaining.
522
+ */
523
+ isIntersect<T extends string>(key: PathName<T>, value: TValueWithUndefined[]): this;
524
+ /**
525
+ * Filters the query to include only documents where every element of the specified key matches the provided callback query.
526
+ * @param key - The key to check for every element.
527
+ * @param callback - The callback query to apply to each element.
528
+ * @returns The current instance for chaining.
529
+ */
530
+ every<T extends string>(key: PathName<T>, callback: (query: TQueryFilterBase) => void): this;
531
+ /**
532
+ * Filters the query to include only documents where some elements of the specified key match the provided callback query.
533
+ * @param key - The key to check for some elements.
534
+ * @param callback - The callback query to apply to each element.
535
+ * @returns The current instance for chaining.
536
+ */
537
+ some<T extends string>(key: PathName<T>, callback: (query: TQueryFilterBase) => void): this;
538
+ /**
539
+ * Filters the query to include only documents that match all of the provided callback queries.
540
+ * @param callbacks - The callback queries to apply.
541
+ * @returns The current instance for chaining.
542
+ */
543
+ and(...callbacks: _$1.Many<(query: TQueryFilterBase) => void>[]): this;
544
+ /**
545
+ * Filters the query to include only documents that match any of the provided callback queries.
546
+ * @param callbacks - The callback queries to apply.
547
+ * @returns The current instance for chaining.
548
+ */
549
+ or(...callbacks: _$1.Many<(query: TQueryFilterBase) => void>[]): this;
550
+ /**
551
+ * Filters the query to include only documents that do not match any of the provided callback queries.
552
+ * @param callbacks - The callback queries to apply.
553
+ * @returns The current instance for chaining.
554
+ */
555
+ nor(...callbacks: _$1.Many<(query: TQueryFilterBase) => void>[]): this;
556
+ }
557
+ declare class TQueryBase extends TQueryFilterBase {
558
+ /**
559
+ * Sorts the query results.
560
+ * @param sort - The sorting criteria.
561
+ * @returns The current instance for chaining.
562
+ */
563
+ sort<T extends Record<string, 1 | -1>>(sort: PathNameMap<T> | TSortOption[]): this;
564
+ /**
565
+ * Skips the specified number of results.
566
+ * @param skip - The number of results to skip.
567
+ * @returns The current instance for chaining.
568
+ */
569
+ skip(skip: number): this;
570
+ /**
571
+ * Limits the number of results.
572
+ * @param limit - The maximum number of results to return.
573
+ * @returns The current instance for chaining.
574
+ */
575
+ limit(limit: number): this;
576
+ /**
577
+ * Performs a nested query on a specific key.
578
+ * @param key - The key to match.
579
+ * @param callback - The callback function to execute.
580
+ * @returns The current instance for chaining.
581
+ */
582
+ match<T extends string>(key: PathName<T>, callback: (query: TQueryBase) => void): this;
583
+ /**
584
+ * Groups the query results by the specified key and applies the provided accumulators.
585
+ * @param key - The key to group by.
586
+ * @param accumulators - The accumulators to apply.
587
+ * @returns The current instance for chaining.
588
+ */
589
+ groupMatches<T extends string>(key: PathName<T>, accumulators: Record<string, TQueryAccumulator>): this;
590
+ }
591
+
592
+ declare class LiveQuerySubscription<T extends string, E> {
593
+ private _className;
594
+ private _proto;
595
+ private _filter;
596
+ constructor(className: T, proto: ProtoType<E>, filter: TQuerySelector | TQuerySelector[]);
597
+ get className(): T;
598
+ on(event: 'create' | 'update' | 'delete', callback: (object: TObjectType<T, E>) => void): {
599
+ remove: VoidFunction;
600
+ socket?: socket_io_client.Socket;
601
+ };
602
+ }
603
+
604
+ /**
605
+ * Options for a query.
606
+ */
607
+ interface TQueryOptions extends TQueryBaseOptions {
608
+ /**
609
+ * Fields to include in the query.
610
+ */
611
+ includes?: string[];
612
+ }
613
+ /**
614
+ * Options for a random query.
615
+ */
616
+ interface TQueryRandomOptions {
617
+ /**
618
+ * Field to use for weighting the random selection.
619
+ */
620
+ weight?: TExpression;
621
+ }
622
+ /**
623
+ * Abstract base class for queries.
624
+ */
625
+ declare abstract class TQuery<T extends string, Ext, M extends boolean> extends TQueryBase {
626
+ /**
627
+ * Clones the query with optional new options.
628
+ * @param options - The new options for the query.
629
+ * @returns A new query instance.
630
+ */
631
+ abstract clone(options?: TQueryOptions): TQuery<T, Ext, M>;
632
+ /**
633
+ * Explains the query execution plan.
634
+ * @param options - Extra options for the query.
635
+ * @returns A promise that resolves to the explanation.
636
+ */
637
+ abstract explain(options?: ExtraOptions<M>): PromiseLike<any>;
638
+ /**
639
+ * Counts the number of results for the query.
640
+ * @param options - Extra options for the query.
641
+ * @returns A promise that resolves to the count.
642
+ */
643
+ abstract count(options?: ExtraOptions<M>): PromiseLike<number>;
644
+ /**
645
+ * Finds the results for the query.
646
+ * @param options - Extra options for the query.
647
+ * @returns A stream of the results.
648
+ */
649
+ abstract find(options?: ExtraOptions<M>): ReturnType<typeof asyncStream<TObjectType<T, Ext>>>;
650
+ /**
651
+ * Selects a random result for the query.
652
+ * @param opts - Options for the random selection.
653
+ * @param options - Extra options for the query.
654
+ * @returns A stream of the random result.
655
+ */
656
+ abstract random(opts?: TQueryRandomOptions, options?: ExtraOptions<M>): ReturnType<typeof asyncStream<TObjectType<T, Ext>>>;
657
+ /**
658
+ * Finds grouped results for the query.
659
+ * @param accumulators - The accumulators to use for grouping.
660
+ * @param options - Extra options for the query.
661
+ * @returns A stream of the grouped results.
662
+ */
663
+ abstract groupFind<T extends Record<string, TQueryAccumulator>>(accumulators: T, options?: ExtraOptions<M>): Promise<{
664
+ [K in keyof T]: TAccumulatorResult<T[K]>;
665
+ }>;
666
+ /**
667
+ * Finds non-reference results for the query.
668
+ * @param options - Extra options for the query.
669
+ * @returns A stream of the non-reference results.
670
+ */
671
+ abstract nonrefs(options?: ExtraOptions<M>): ReturnType<typeof asyncStream<TObjectType<T, Ext>>>;
672
+ /**
673
+ * Inserts a new record.
674
+ * @param attrs - The attributes of the new record.
675
+ * @param options - Extra options for the query.
676
+ * @returns A promise that resolves to the inserted record.
677
+ */
678
+ insert(attrs: Record<string, TValueWithUndefined>, options?: ExtraOptions<M>): Promise<TObjectType<T, Ext>>;
679
+ /**
680
+ * Inserts multiple new records.
681
+ * @param values - The attributes of the new records.
682
+ * @param options - Extra options for the query.
683
+ * @returns A promise that resolves to the inserted records.
684
+ */
685
+ abstract insertMany(values: Record<string, TValueWithUndefined>[], options?: ExtraOptions<M>): PromiseLike<TObjectType<T, Ext>[]>;
686
+ /**
687
+ * Updates a single record.
688
+ * @param update - The update operations.
689
+ * @param options - Extra options for the query.
690
+ * @returns A promise that resolves to the updated record or undefined.
691
+ */
692
+ updateOne(update: Record<string, TUpdateOp>, options?: ExtraOptions<M>): Promise<TObjectType<T, Ext> | undefined>;
693
+ /**
694
+ * Updates multiple records.
695
+ * @param update - The update operations.
696
+ * @param options - Extra options for the query.
697
+ * @returns A promise that resolves to the updated records.
698
+ */
699
+ abstract updateMany(update: Record<string, TUpdateOp>, options?: ExtraOptions<M>): PromiseLike<TObjectType<T, Ext>[]>;
700
+ /**
701
+ * Upserts a single record.
702
+ * @param update - The update operations.
703
+ * @param setOnInsert - The attributes to set on insert.
704
+ * @param options - Extra options for the query.
705
+ * @returns A promise that resolves to the upserted record.
706
+ */
707
+ upsertOne(update: Record<string, TUpdateOp>, setOnInsert: Record<string, TValueWithUndefined>, options?: ExtraOptions<M>): Promise<TObjectType<T, Ext>>;
708
+ /**
709
+ * Upserts multiple records.
710
+ * @param update - The update operations.
711
+ * @param setOnInsert - The attributes to set on insert.
712
+ * @param options - Extra options for the query.
713
+ * @returns A promise that resolves to the upserted records.
714
+ */
715
+ abstract upsertMany(update: Record<string, TUpdateOp>, setOnInsert: Record<string, TValueWithUndefined>, options?: ExtraOptions<M>): PromiseLike<TObjectType<T, Ext>[]>;
716
+ /**
717
+ * Deletes a single record.
718
+ * @param options - Extra options for the query.
719
+ * @returns A promise that resolves to the deleted record or undefined.
720
+ */
721
+ deleteOne(options?: ExtraOptions<M>): Promise<TObjectType<T, Ext> | undefined>;
722
+ /**
723
+ * Deletes multiple records.
724
+ * @param options - Extra options for the query.
725
+ * @returns A promise that resolves to the deleted records.
726
+ */
727
+ abstract deleteMany(options?: ExtraOptions<M>): PromiseLike<TObjectType<T, Ext>[]>;
728
+ /**
729
+ * Subscribes to live query updates.
730
+ * @returns A live query subscription.
731
+ */
732
+ abstract subscribe(): LiveQuerySubscription<T, Ext>;
733
+ /**
734
+ * Adds fields to include in the query.
735
+ * @param includes - The fields to include.
736
+ * @returns The query instance.
737
+ */
738
+ includes<T extends _$1.RecursiveArray<string>>(...includes: IncludePaths<T>): this;
739
+ /**
740
+ * Gets a record by its ID.
741
+ * @param id - The ID of the record.
742
+ * @param options - Extra options for the query.
743
+ * @returns A promise that resolves to the record or undefined.
744
+ */
745
+ get(id: string, options?: ExtraOptions<M>): Promise<TObjectType<T, Ext> | undefined>;
746
+ /**
747
+ * Gets the first record.
748
+ * @param options - Extra options for the query.
749
+ * @returns A promise that resolves to the first record or undefined.
750
+ */
751
+ first(options?: ExtraOptions<M>): Promise<TObjectType<T, Ext> | undefined>;
752
+ /**
753
+ * Gets a random record.
754
+ * @param opts - Options for the random selection.
755
+ * @param options - Extra options for the query.
756
+ * @returns A promise that resolves to the random record or undefined.
757
+ */
758
+ randomOne(opts?: TQueryRandomOptions, options?: ExtraOptions<M>): Promise<TObjectType<T, Ext> | undefined>;
759
+ /**
760
+ * Checks if any records exist.
761
+ * @param options - Extra options for the query.
762
+ * @returns A promise that resolves to a boolean indicating if any records exist.
763
+ */
764
+ exists(options?: ExtraOptions<M>): Promise<boolean>;
765
+ /**
766
+ * Iterates over each batch of records.
767
+ * @param callback - The callback to execute for each batch.
768
+ * @param options - Extra options for the query.
769
+ */
770
+ eachBatch(callback: (batch: TObjectType<T, Ext>[]) => Awaitable<void>, options?: ExtraOptions<M> & {
771
+ batchSize?: number;
772
+ }): Promise<void>;
773
+ /**
774
+ * Iterates over each record.
775
+ * @param callback - The callback to execute for each record.
776
+ * @param options - Extra options for the query.
777
+ */
778
+ each(callback: (object: TObjectType<T, Ext>) => Awaitable<void>, options?: ExtraOptions<M> & {
779
+ batchSize?: number;
780
+ }): Promise<void>;
781
+ /**
782
+ * Finds all records matching the query.
783
+ * @param options - Extra options for the query.
784
+ * @returns An iterator for the records.
785
+ */
786
+ findAll(options?: ExtraOptions<M> & {
787
+ batchSize?: number;
788
+ }): _o2ter_utils_js.AsyncStream<Awaited<TObjectType<T, Ext>>>;
789
+ }
790
+
791
+ type TNumber = number | Decimal | BigInt;
792
+ type TPrimitive = RegExp | Date | string | TNumber | boolean | null | undefined;
793
+ type TSerializable = _TContainer<TPrimitive | TObject>;
794
+ type SerializeOptions = {
795
+ space?: string | number;
796
+ objAttrs?: string[];
797
+ };
798
+ type DeserializeOptions = {
799
+ objAttrs?: string[];
800
+ };
801
+ declare const serialize: (x: TSerializable, options?: SerializeOptions) => string;
802
+ declare const deserialize: (buffer: string, options?: DeserializeOptions) => TSerializable;
803
+
804
+ /**
805
+ * A callback function type.
806
+ * @param request - The request object.
807
+ * @returns An awaitable response.
808
+ */
809
+ type Callback<T, R, E> = (request: ProtoService<E> & T) => Awaitable<R>;
810
+ /**
811
+ * A callback function type.
812
+ * @param request - The request object.
813
+ * @returns An awaitable response.
814
+ */
815
+ type ProtoFunction<E, P extends TSerializable, R extends TSerializable | void> = Callback<{
816
+ params: P;
817
+ }, R, E>;
818
+ /**
819
+ * A trigger callback function type.
820
+ * @param request - The request object.
821
+ * @returns An awaitable response.
822
+ */
823
+ type ProtoTriggerFunction<T, E> = Callback<{
824
+ object: TObjectType<T, E>;
825
+ }, void, E>;
826
+ /**
827
+ * A job callback function type.
828
+ * @param request - The request object.
829
+ * @returns An awaitable response.
830
+ */
831
+ type ProtoJobFunction<E, P extends TValueWithoutObject> = Callback<{
832
+ params: P;
833
+ user?: TUser;
834
+ job: TObjectType<'_Job', E>;
835
+ }, void, E>;
836
+ /**
837
+ * Validator options for proto functions.
838
+ */
839
+ type Validator = {
840
+ /**
841
+ * Indicates if a user is required.
842
+ */
843
+ requireUser?: boolean;
844
+ /**
845
+ * Indicates if a master user is required.
846
+ */
847
+ requireMaster?: boolean;
848
+ /**
849
+ * Indicates if any user roles are required.
850
+ */
851
+ requireAnyUserRoles?: string[];
852
+ /**
853
+ * Indicates if all user roles are required.
854
+ */
855
+ requireAllUserRoles?: string[];
856
+ };
857
+ /**
858
+ * Options for configuring a proto function.
859
+ */
860
+ type ProtoFunctionOptions<E> = {
861
+ /**
862
+ * The callback function for the proto function.
863
+ */
864
+ callback: ProtoFunction<E, any, any>;
865
+ /**
866
+ * Optional validator for the proto function.
867
+ */
868
+ validator?: Validator;
869
+ };
870
+ /**
871
+ * Options for configuring a proto job function.
872
+ */
873
+ type ProtoJobFunctionOptions<E> = {
874
+ /**
875
+ * The callback function for the proto job function.
876
+ */
877
+ callback: ProtoJobFunction<E, any>;
878
+ /**
879
+ * Optional scopes for the proto job function.
880
+ */
881
+ scopes?: string[];
882
+ /**
883
+ * Optional validator for the proto function.
884
+ */
885
+ validator?: Validator;
886
+ };
887
+
888
+ type _Session = Awaited<ReturnType<typeof session>>;
889
+ declare const session: <E>(proto: ProtoService<E>, request: Request) => Promise<{
890
+ user?: TObject | undefined;
891
+ _roles?: TRole[] | undefined;
892
+ sessionId?: string | undefined;
893
+ createdAt?: Date | undefined;
894
+ updatedAt?: Date | undefined;
895
+ loginedAt?: Date | undefined;
896
+ cookieOptions?: any;
897
+ }>;
898
+
899
+ declare const _logLevels: readonly ["error", "warn", "info", "debug", "trace"];
900
+ type _Logger = {
901
+ [x in typeof _logLevels[number]]: (...args: any[]) => void;
902
+ };
903
+ type Logger = _Logger & {
904
+ loggerLevel: keyof _Logger | 'all' | 'none';
905
+ };
906
+ /**
907
+ * The mode of the transaction.
908
+ */
909
+ type TransactionMode = 'default' | 'committed' | 'repeatable' | 'serializable';
910
+ /**
911
+ * Options for configuring a transaction.
912
+ */
913
+ type TransactionOptions = {
914
+ /**
915
+ * The mode of the transaction.
916
+ */
917
+ mode?: TransactionMode;
918
+ /**
919
+ * The number of retries or a boolean indicating whether to retry.
920
+ */
921
+ retry?: number | boolean;
922
+ };
923
+ /**
924
+ * Represents event data with additional metadata.
925
+ */
926
+ type EventData = Record<string, TValueWithoutObject> & {
927
+ /**
928
+ * The unique identifier for the event.
929
+ */
930
+ _id: string;
931
+ /**
932
+ * The creation date of the event.
933
+ */
934
+ _created_at: Date;
935
+ /**
936
+ * The read permissions for the event.
937
+ */
938
+ _rperm: string[];
939
+ };
940
+ declare abstract class ProtoType<Ext> {
941
+ isQuery: (x: any) => x is TQuery<any, any, any>;
942
+ isObject: (x: any) => x is TObject;
943
+ isUser: (x: any) => x is TUser;
944
+ isRole: (x: any) => x is TRole;
945
+ isFile: (x: any) => x is TFile;
946
+ isJob: (x: any) => x is TJob;
947
+ /**
948
+ * Gets the endpoint URL.
949
+ * @returns The endpoint URL as a string.
950
+ */
951
+ get endpoint(): string;
952
+ /**
953
+ * Retrieves the configuration.
954
+ * @param options - Optional settings for retrieving the configuration.
955
+ * @returns A promise that resolves to the configuration.
956
+ */
957
+ abstract config(options?: {
958
+ master?: boolean;
959
+ }): Promise<Record<string, TValueWithoutObject>>;
960
+ /**
961
+ * Retrieves the ACL of configuration.
962
+ * @param options - Settings for retrieving the ACL of configuration.
963
+ * @returns A promise that resolves to the ACL of configuration.
964
+ */
965
+ abstract configAcl(options: {
966
+ master: true;
967
+ }): PromiseLike<Record<string, string[]>>;
968
+ /**
969
+ * Sets the configuration.
970
+ * @param values - The configuration values to set.
971
+ * @param options - Settings for setting the configuration.
972
+ * @returns A promise that resolves when the configuration is set.
973
+ */
974
+ abstract setConfig(values: Record<string, TValueWithoutObject>, options: {
975
+ master: true;
976
+ acl?: string[];
977
+ }): Promise<void>;
978
+ /**
979
+ * Runs a function.
980
+ * @param name - The name of the function to run.
981
+ * @param data - The data to pass to the function.
982
+ * @param options - Additional options for running the function.
983
+ * @returns A promise that resolves to the result of the function.
984
+ */
985
+ abstract run<R extends TSerializable | void = any>(name: string, data?: TSerializable, options?: ExtraOptions<boolean>): Promise<R>;
986
+ /**
987
+ * Schedules a job.
988
+ * @param name - The name of the job to schedule.
989
+ * @param params - The parameters to pass to the job.
990
+ * @param options - Additional options for scheduling the job.
991
+ * @returns A promise that resolves when the job is scheduled.
992
+ */
993
+ abstract scheduleJob(name: string, params?: TValueWithoutObject, options?: ExtraOptions<boolean>): Promise<TJob>;
994
+ /**
995
+ * Creates a query.
996
+ * @param className - The name of the class to query.
997
+ * @returns A query instance.
998
+ */
999
+ abstract Query<T extends string>(className: T): TQuery<T, Ext, boolean>;
1000
+ /**
1001
+ * Creates a relation query.
1002
+ * @param object - The object to create the relation for.
1003
+ * @param key - The key of the relation.
1004
+ * @returns A relation query instance.
1005
+ */
1006
+ abstract Relation<T extends string>(object: TObject, key: PathName<T>): TQuery<string, Ext, boolean>;
1007
+ /**
1008
+ * Get all references to an object.
1009
+ * @param object - The object to get references for.
1010
+ * @param options - Additional options for getting references.
1011
+ * @returns A stream of references.
1012
+ */
1013
+ abstract refs(object: TObject, options?: ExtraOptions<boolean>): ReturnType<typeof asyncStream<TObjectType<string, Ext>>>;
1014
+ /**
1015
+ * Checks if the server is online.
1016
+ * @returns A promise that resolves to a boolean indicating if the server is online.
1017
+ */
1018
+ online(): Promise<boolean>;
1019
+ /**
1020
+ * Rebinds an object to the proto instance.
1021
+ * @param object - The object to rebind.
1022
+ * @returns The rebinded object.
1023
+ */
1024
+ rebind<T extends TSerializable | undefined>(object: T): T;
1025
+ /**
1026
+ * Creates a new object.
1027
+ * @param className - The name of the class to create.
1028
+ * @param id - The ID of the object to create.
1029
+ * @returns The created object.
1030
+ */
1031
+ Object<T extends string>(className: T, id?: string): TObjectType<T, Ext>;
1032
+ /**
1033
+ * Creates a new file object.
1034
+ * @param filename - The name of the file.
1035
+ * @param data - The file data.
1036
+ * @param type - The type of the file.
1037
+ * @returns The created file object.
1038
+ */
1039
+ File(filename: string, data: FileData, type?: string): TObjectType<"File", Ext>;
1040
+ /**
1041
+ * Notifies an event.
1042
+ * @param data - The data to notify.
1043
+ * @param options - Additional options for notifying the event.
1044
+ */
1045
+ abstract notify(data: Record<string, TValueWithoutObject> & {
1046
+ _rperm?: string[];
1047
+ }, options?: ExtraOptions<boolean>): Promise<void>;
1048
+ /**
1049
+ * Listens for events.
1050
+ * @param callback - The callback to call when an event occurs.
1051
+ * @returns An object with a remove function to stop listening.
1052
+ */
1053
+ abstract listen(callback: (data: EventData) => void, selector?: TQuerySelector): {
1054
+ remove: VoidFunction;
1055
+ socket?: Socket;
1056
+ };
1057
+ }
1058
+ interface ProtoType<Ext> {
1059
+ get logger(): Logger;
1060
+ /**
1061
+ * Connects a request with optional attributes.
1062
+ * @param req - The request to connect.
1063
+ * @param attrs - Optional attributes or a function returning attributes.
1064
+ * @returns The instance with the request and attributes.
1065
+ */
1066
+ connect<R extends Request, T extends object>(req: R, attrs?: T | ((x: this & {
1067
+ req: R;
1068
+ }) => T)): this & {
1069
+ req: R;
1070
+ } & T;
1071
+ /**
1072
+ * Connects using a session token with optional attributes.
1073
+ * @param token - The session token.
1074
+ * @param attrs - Optional attributes or a function returning attributes.
1075
+ * @returns A promise resolving to the instance with the session and attributes.
1076
+ */
1077
+ connectWithSessionToken<T extends object>(token: string, attrs?: T | ((x: this & {
1078
+ session?: _Session;
1079
+ }) => T)): Promise<this & {
1080
+ session?: _Session;
1081
+ } & T>;
1082
+ /**
1083
+ * Refreshes the authentication/session status for the socket connection.
1084
+ *
1085
+ * This method should be called when the session token or authentication state changes,
1086
+ * ensuring that any active socket connections are updated to reflect the new session.
1087
+ * Useful for maintaining real-time features (such as LiveQuery) after login, logout,
1088
+ * or session renewal.
1089
+ */
1090
+ refreshSocketSession(): void;
1091
+ /**
1092
+ * Sets the session token.
1093
+ * @param token - The session token.
1094
+ */
1095
+ setSessionToken(token?: string): void;
1096
+ /**
1097
+ * Retrieves the roles of a user.
1098
+ * @param user - The user whose roles are to be retrieved.
1099
+ * @returns A promise resolving to an array of roles.
1100
+ */
1101
+ userRoles(user: TUser): Promise<TRole[]>;
1102
+ /**
1103
+ * Becomes a specified user.
1104
+ * @param req - The request.
1105
+ * @param user - The user to become.
1106
+ * @param options - Optional cookie and JWT sign options.
1107
+ * @returns A promise resolving to void.
1108
+ */
1109
+ becomeUser(req: Request, user: TUser, options?: {
1110
+ cookieOptions?: CookieOptions | undefined;
1111
+ jwtSignOptions?: SignOptions | undefined;
1112
+ }): Promise<void>;
1113
+ /**
1114
+ * Logs out a user.
1115
+ * @param req - The request.
1116
+ * @param options - Optional cookie and JWT sign options.
1117
+ * @returns A promise resolving to void.
1118
+ */
1119
+ logoutUser(req: Request, options?: {
1120
+ cookieOptions?: CookieOptions | undefined;
1121
+ jwtSignOptions?: SignOptions | undefined;
1122
+ }): Promise<void>;
1123
+ /**
1124
+ * Verifies a user's password.
1125
+ * @param user - The user whose password is to be verified.
1126
+ * @param password - The password to verify.
1127
+ * @param options - Extra options.
1128
+ * @returns A promise resolving to a boolean indicating if the password is correct.
1129
+ */
1130
+ verifyPassword(user: TUser, password: string, options: ExtraOptions<true>): Promise<boolean>;
1131
+ /**
1132
+ * Sets a user's password.
1133
+ * @param user - The user whose password is to be set.
1134
+ * @param password - The new password.
1135
+ * @param options - Extra options.
1136
+ * @returns A promise resolving to void.
1137
+ */
1138
+ setPassword(user: TUser, password: string, options: ExtraOptions<true>): Promise<void>;
1139
+ /**
1140
+ * Unsets a user's password.
1141
+ * @param user - The user whose password is to be unset.
1142
+ * @param options - Extra options.
1143
+ * @returns A promise resolving to void.
1144
+ */
1145
+ unsetPassword(user: TUser, options: ExtraOptions<true>): Promise<void>;
1146
+ /**
1147
+ * Defines a new function.
1148
+ * @param name - The name of the function.
1149
+ * @param callback - The function callback.
1150
+ * @param options - Optional function options excluding the callback.
1151
+ */
1152
+ define<P extends TSerializable = any, R extends TSerializable | void = any>(name: string, callback: ProtoFunction<Ext, P, R>, options?: Omit<ProtoFunctionOptions<Ext>, 'callback'>): void;
1153
+ /**
1154
+ * Registers a callback to be executed after an object is created.
1155
+ * @param className - The name of the class.
1156
+ * @param callback - The callback function.
1157
+ */
1158
+ afterCreate<T extends string>(className: string, callback: ProtoTriggerFunction<T, Ext>): void;
1159
+ /**
1160
+ * Registers a callback to be executed after an object is updated.
1161
+ * @param className - The name of the class.
1162
+ * @param callback - The callback function.
1163
+ */
1164
+ afterUpdate<T extends string>(className: string, callback: ProtoTriggerFunction<T, Ext>): void;
1165
+ /**
1166
+ * Registers a callback to be executed after an object is deleted.
1167
+ * @param className - The name of the class.
1168
+ * @param callback - The callback function.
1169
+ */
1170
+ afterDelete<T extends string>(className: string, callback: ProtoTriggerFunction<T, Ext>): void;
1171
+ /**
1172
+ * Defines a new job function.
1173
+ * @param name - The name of the job function.
1174
+ * @param callback - The job function callback.
1175
+ * @param options - Optional job function options excluding the callback.
1176
+ */
1177
+ defineJob<P extends TValueWithoutObject = any>(name: string, callback: ProtoJobFunction<Ext, P>, options?: Omit<ProtoJobFunctionOptions<Ext>, 'callback'>): void;
1178
+ /**
1179
+ * Locks a table for updates.
1180
+ * @param className - The name of the class or an array of class names.
1181
+ * @param update - Whether to lock for update.
1182
+ */
1183
+ lockTable(className: string | string[], update: boolean): void;
1184
+ /**
1185
+ * Executes a callback within a transaction.
1186
+ * @param callback - The callback to execute.
1187
+ * @param options - Optional transaction options.
1188
+ */
1189
+ withTransaction<T>(callback: (connection: ProtoType<Ext>) => PromiseLike<T>, options?: TransactionOptions): void;
1190
+ /**
1191
+ * Generates an upload token.
1192
+ * @param options - Optional settings for the upload token.
1193
+ * @returns The generated upload token.
1194
+ */
1195
+ generateUploadToken(options?: {
1196
+ maxUploadSize?: number;
1197
+ }): string;
1198
+ /**
1199
+ * Signs a JWT.
1200
+ * @param payload - The payload to sign.
1201
+ * @param options - Options for signing the JWT.
1202
+ * @returns The signed JWT.
1203
+ */
1204
+ jwtSign(payload: any, options: jwt.SignOptions): string;
1205
+ /**
1206
+ * Verifies a JWT.
1207
+ * @param token - The token to verify.
1208
+ * @param options - Options for verifying the JWT.
1209
+ * @returns The decoded JWT payload or undefined if verification fails.
1210
+ */
1211
+ jwtVerify(token: string, options?: jwt.VerifyOptions): jwt.JwtPayload | undefined;
1212
+ }
1213
+
1214
+ /**
1215
+ * Represents additional options that can be passed to certain methods.
1216
+ */
1217
+ type ExtraOptions<M extends boolean> = {
1218
+ /**
1219
+ * Indicates whether the master option is enabled.
1220
+ */
1221
+ master?: M;
1222
+ /**
1223
+ * The session associated with the operation.
1224
+ */
1225
+ session?: ProtoType<any>;
1226
+ /**
1227
+ * An AbortSignal object that can be used to abort the operation.
1228
+ */
1229
+ abortSignal?: AbortSignal;
1230
+ /**
1231
+ * Disable the triggers.
1232
+ *
1233
+ * Only effective when `master` is `true`.
1234
+ */
1235
+ silent?: boolean;
1236
+ };
1237
+
1238
+ /**
1239
+ * Interface representing a object.
1240
+ */
1241
+ interface TObject {
1242
+ /**
1243
+ * Clones the object.
1244
+ * @returns A clone of the object.
1245
+ */
1246
+ clone(): this;
1247
+ /**
1248
+ * Gets a relation query for the specified key.
1249
+ * @param key - The key of the relation.
1250
+ * @returns A query object for the relation.
1251
+ */
1252
+ relation<T extends string>(key: PathName<T>): TQuery<string, any, boolean>;
1253
+ /**
1254
+ * Fetches the object with the specified keys included.
1255
+ * @param keys - The keys to include.
1256
+ * @param options - Additional options for the fetch operation.
1257
+ * @returns A promise that resolves to the fetched object.
1258
+ */
1259
+ fetchWithInclude<T extends _$1.RecursiveArray<string>>(keys: IncludePaths<T>, options?: ExtraOptions<boolean>): PromiseLike<this>;
1260
+ /**
1261
+ * Saves the object.
1262
+ * @param options - Additional options for the save operation.
1263
+ * @returns A promise that resolves to the saved object.
1264
+ */
1265
+ save(options?: ExtraOptions<boolean> & {
1266
+ cascadeSave?: boolean;
1267
+ }): PromiseLike<this>;
1268
+ /**
1269
+ * Destroys the object.
1270
+ * @param options - Additional options for the destroy operation.
1271
+ * @returns A promise that resolves to the destroyed object.
1272
+ */
1273
+ destroy(options?: ExtraOptions<boolean>): PromiseLike<this>;
1274
+ }
1275
+ /**
1276
+ * Class representing a object.
1277
+ */
1278
+ declare class TObject {
1279
+ static defaultReadonlyKeys: string[];
1280
+ static defaultKeys: string[];
1281
+ constructor(className: string, attributes?: Record<string, TValue> | ((self: TObject) => Record<string, TValue>));
1282
+ /**
1283
+ * Gets the class name of the object.
1284
+ */
1285
+ get className(): string;
1286
+ /**
1287
+ * Gets the attributes of the object.
1288
+ */
1289
+ get attributes(): Record<string, TValue>;
1290
+ /**
1291
+ * Gets the object ID.
1292
+ */
1293
+ get id(): string | undefined;
1294
+ /**
1295
+ * Gets the creation date of the object.
1296
+ */
1297
+ get createdAt(): Date | undefined;
1298
+ /**
1299
+ * Gets the last updated date of the object.
1300
+ */
1301
+ get updatedAt(): Date | undefined;
1302
+ /**
1303
+ * Gets the version number of the object.
1304
+ */
1305
+ get __v(): number;
1306
+ /**
1307
+ * Gets the sequence number of the object.
1308
+ */
1309
+ get __i(): number;
1310
+ /**
1311
+ * Gets the expiration date of the object.
1312
+ */
1313
+ get expiredAt(): Date | undefined;
1314
+ /**
1315
+ * Sets the expiration date of the object.
1316
+ * @param value - The expiration date.
1317
+ */
1318
+ set expiredAt(value: Date | undefined);
1319
+ /**
1320
+ * Gets the access control list (ACL) of the object.
1321
+ * @returns The ACL of the object.
1322
+ */
1323
+ acl(): TSchema.ACLs;
1324
+ /**
1325
+ * Sets the access control list (ACL) of the object.
1326
+ * @param value - The ACL to set.
1327
+ */
1328
+ setAcl(value: Partial<TSchema.ACLs>): void;
1329
+ /**
1330
+ * Sets the read access control list (ACL) of the object.
1331
+ * @param value - The read ACL to set.
1332
+ */
1333
+ setReadAcl(value: TSchema.ACL): void;
1334
+ /**
1335
+ * Sets the write access control list (ACL) of the object.
1336
+ * @param value - The write ACL to set.
1337
+ */
1338
+ setWriteAcl(value: TSchema.ACL): void;
1339
+ /**
1340
+ * Gets the keys of the object's attributes and mutated attributes.
1341
+ * @returns An array of keys.
1342
+ */
1343
+ keys(): string[];
1344
+ /**
1345
+ * Gets an iterator for the entries of the object's attributes.
1346
+ * @returns An iterator for the entries.
1347
+ */
1348
+ entries(): Generator<[string, any], void, unknown>;
1349
+ /**
1350
+ * Converts the object to a plain object.
1351
+ * @param replacer - An optional function to replace values during the conversion.
1352
+ * @returns The plain object representation of the object.
1353
+ */
1354
+ toObject(replacer?: (value: TObject) => any): any;
1355
+ private _value;
1356
+ /**
1357
+ * Get the value of the attribute.
1358
+ * @param key - The key of the attribute.
1359
+ * @returns The value of the attribute.
1360
+ */
1361
+ get<T extends string>(key: PathName<T>): any;
1362
+ /**
1363
+ * Set the value of the attribute.
1364
+ * @param key - The key of the attribute.
1365
+ * @param value - The value to set.
1366
+ */
1367
+ set<T extends string>(key: PathName<T>, value: TValueWithUndefined): void;
1368
+ /**
1369
+ * Is the object dirty.
1370
+ */
1371
+ get isDirty(): boolean;
1372
+ /**
1373
+ * Increment the value of the attribute.
1374
+ * @param key - The key to increment.
1375
+ * @param value - The value to increment by.
1376
+ */
1377
+ increment<T extends string>(key: PathName<T>, value: number | Decimal): void;
1378
+ /**
1379
+ * Decrement the value of the attribute.
1380
+ * @param key - The key to decrement.
1381
+ * @param value - The value to decrement by.
1382
+ */
1383
+ decrement<T extends string>(key: PathName<T>, value: number | Decimal): void;
1384
+ /**
1385
+ * Multiplies the value of the specified attribute.
1386
+ * @param key - The key of the attribute to multiply.
1387
+ * @param value - The multiplier value.
1388
+ */
1389
+ multiply<T extends string>(key: PathName<T>, value: number | Decimal): void;
1390
+ /**
1391
+ * Divides the value of the specified attribute.
1392
+ * @param key - The key of the attribute to divide.
1393
+ * @param value - The divisor value.
1394
+ */
1395
+ divide<T extends string>(key: PathName<T>, value: number | Decimal): void;
1396
+ /**
1397
+ * Sets the value of the specified attribute to the maximum of the current value and the provided value.
1398
+ * @param key - The key of the attribute to compare.
1399
+ * @param value - The value to compare against.
1400
+ */
1401
+ max<T extends string>(key: PathName<T>, value: TValue): void;
1402
+ /**
1403
+ * Sets the value of the specified attribute to the minimum of the current value and the provided value.
1404
+ * @param key - The key of the attribute to compare.
1405
+ * @param value - The value to compare against.
1406
+ */
1407
+ min<T extends string>(key: PathName<T>, value: TValue): void;
1408
+ /**
1409
+ * Adds the specified values to the set of the specified attribute.
1410
+ * @param key - The key of the attribute.
1411
+ * @param values - The values to add to the set.
1412
+ */
1413
+ addToSet<T extends string>(key: PathName<T>, values: TValue[]): void;
1414
+ /**
1415
+ * Adds the values to the array of the attribute.
1416
+ * @param key - The key of the attribute.
1417
+ * @param values - The values to add.
1418
+ */
1419
+ push<T extends string>(key: PathName<T>, values: TValue[]): void;
1420
+ /**
1421
+ * Removes the values from the array of the attribute.
1422
+ * @param key - The key of the attribute.
1423
+ * @param values - The values to remove.
1424
+ */
1425
+ removeAll<T extends string>(key: PathName<T>, values: TValue[]): void;
1426
+ /**
1427
+ * Removes the first elements from the array of the attribute.
1428
+ * @param key - The key of the attribute.
1429
+ * @param count - The number of elements to remove. Defaults to 1.
1430
+ */
1431
+ popFirst<T extends string>(key: PathName<T>, count?: number): void;
1432
+ /**
1433
+ * Removes the last elements from the array of the attribute.
1434
+ * @param key - The key of the attribute.
1435
+ * @param count - The number of elements to remove. Defaults to 1.
1436
+ */
1437
+ popLast<T extends string>(key: PathName<T>, count?: number): void;
1438
+ /**
1439
+ * Fetches the object data.
1440
+ * @param options - Additional options for the fetch operation.
1441
+ * @returns A promise that resolves to the fetched object.
1442
+ */
1443
+ fetch(options?: ExtraOptions<boolean>): Promise<this>;
1444
+ /**
1445
+ * Fetches the object data if needed.
1446
+ * @param keys - The keys of the attributes to fetch.
1447
+ * @param options - Additional options for the fetch operation.
1448
+ * @returns A promise that resolves to the fetched object.
1449
+ */
1450
+ fetchIfNeeded<T extends _$1.RecursiveArray<string>>(keys: IncludePaths<T>, options?: ExtraOptions<boolean>): Promise<this>;
1451
+ }
1452
+
1453
+ type _TContainer<Primitive> = {
1454
+ [x: string]: _TContainer<Primitive>;
1455
+ } | _TContainer<Primitive>[] | Primitive;
1456
+ type TPrimitiveValue = boolean | number | Decimal$1 | string | Date | null;
1457
+ type TValueWithUndefined = _TContainer<TPrimitiveValue | TObject | undefined>;
1458
+ type TValueWithoutObject = _TContainer<TPrimitiveValue>;
1459
+ type TValue = _TContainer<TPrimitiveValue | TObject>;
1460
+ type Exact<T, Shape> = T extends Shape ? Exclude<keyof T, keyof Shape> extends never ? T : never : never;
1461
+ type ExactOneProp<T> = {
1462
+ [K in keyof T]-?: Pick<T, K> & {
1463
+ [P in Exclude<keyof T, K>]?: never;
1464
+ };
1465
+ }[keyof T];
1466
+
1467
+ declare namespace TSchema {
1468
+ /**
1469
+ * Access Control List (ACL).
1470
+ *
1471
+ * An array of strings representing users or roles that have access to a resource.
1472
+ */
1473
+ type ACL = string[];
1474
+ /**
1475
+ * Access Control Lists for read and update operations.
1476
+ *
1477
+ * Defines separate ACLs for reading and updating an object.
1478
+ */
1479
+ type ACLs = {
1480
+ /**
1481
+ * ACL for read operation.
1482
+ * Users or roles allowed to read the object.
1483
+ */
1484
+ read: TSchema.ACL;
1485
+ /**
1486
+ * ACL for update operation.
1487
+ * Users or roles allowed to update the object.
1488
+ */
1489
+ update: TSchema.ACL;
1490
+ };
1491
+ /**
1492
+ * Supported primitive data types.
1493
+ */
1494
+ type Primitive = 'boolean' | 'number' | 'decimal' | 'string' | 'string[]' | 'date' | 'object' | 'array';
1495
+ /**
1496
+ * Primitive type with optional default value.
1497
+ *
1498
+ * Can be a string literal (e.g., 'string') or an object specifying the type and a default value.
1499
+ */
1500
+ type PrimitiveType = Primitive | {
1501
+ /**
1502
+ * The primitive type.
1503
+ */
1504
+ type: Primitive;
1505
+ /**
1506
+ * Optional default value for the field.
1507
+ */
1508
+ default?: TValueWithoutObject;
1509
+ };
1510
+ /**
1511
+ * Vector type with a specified dimension and optional default value.
1512
+ *
1513
+ * Used for fields storing fixed-length numeric arrays (vectors).
1514
+ */
1515
+ type VectorType = {
1516
+ /**
1517
+ * The type of the field. Always 'vector'.
1518
+ */
1519
+ type: 'vector';
1520
+ /**
1521
+ * The dimension (length) of the vector.
1522
+ */
1523
+ dimension: number;
1524
+ /**
1525
+ * Optional default value for the vector.
1526
+ */
1527
+ default?: number[];
1528
+ };
1529
+ /**
1530
+ * Shape type for nested objects.
1531
+ *
1532
+ * Allows defining complex, nested object structures with their own field types.
1533
+ */
1534
+ type ShapeType = {
1535
+ /**
1536
+ * The type of the field. Always 'shape'.
1537
+ */
1538
+ type: 'shape';
1539
+ /**
1540
+ * The shape definition, mapping field names to their data types.
1541
+ */
1542
+ shape: Record<string, DataType>;
1543
+ };
1544
+ /**
1545
+ * Pointer type for referencing another class.
1546
+ *
1547
+ * Represents a one-to-one relationship to another object.
1548
+ */
1549
+ type PointerType = {
1550
+ /**
1551
+ * The type of the field. Always 'pointer'.
1552
+ */
1553
+ type: 'pointer';
1554
+ /**
1555
+ * The name of the target class being referenced.
1556
+ */
1557
+ target: string;
1558
+ };
1559
+ /**
1560
+ * Relation type for referencing multiple objects in another class.
1561
+ *
1562
+ * Represents a one-to-many or many-to-many relationship.
1563
+ * - `target`: The related class name.
1564
+ * - `foreignField`: (Optional) The field in the target class that refers back to this class.
1565
+ * - `match`: (Optional) Default match query options (filter, sort, etc.) applied when querying this relation.
1566
+ * Only used if `foreignField` is set.
1567
+ */
1568
+ type RelationType = {
1569
+ /**
1570
+ * The type of the field. Always 'relation'.
1571
+ */
1572
+ type: 'relation';
1573
+ /**
1574
+ * The name of the target class for this relation.
1575
+ */
1576
+ target: string;
1577
+ /**
1578
+ * (Optional) The field in the target class that refers back to this class.
1579
+ * If provided, the relation is managed via this foreign key.
1580
+ */
1581
+ foreignField?: string;
1582
+ /**
1583
+ * (Optional) Default match query options for this relation.
1584
+ *
1585
+ * These options define default query behaviors—such as filtering, sorting, limiting results, and other query parameters—
1586
+ * that will be automatically applied when querying this relation via the specified `foreignField`.
1587
+ *
1588
+ * Note: `match` is only applicable if `foreignField` is set. If `foreignField` is not provided, `match` will be ignored.
1589
+ */
1590
+ match?: TQueryBaseOptions;
1591
+ };
1592
+ /**
1593
+ * Data type for schema fields.
1594
+ *
1595
+ * Can be a primitive, vector, shape, pointer, or relation type.
1596
+ */
1597
+ type DataType = PrimitiveType | VectorType | ShapeType | PointerType | RelationType;
1598
+ /**
1599
+ * Class Level Permissions (CLPs).
1600
+ *
1601
+ * Defines access control for various operations at the class level.
1602
+ */
1603
+ type CLPs = {
1604
+ /**
1605
+ * ACL for get (read single object) operation.
1606
+ */
1607
+ get?: TSchema.ACL;
1608
+ /**
1609
+ * ACL for find (query multiple objects) operation.
1610
+ */
1611
+ find?: TSchema.ACL;
1612
+ /**
1613
+ * ACL for count operation.
1614
+ */
1615
+ count?: TSchema.ACL;
1616
+ /**
1617
+ * ACL for create operation.
1618
+ */
1619
+ create?: TSchema.ACL;
1620
+ /**
1621
+ * ACL for update operation.
1622
+ */
1623
+ update?: TSchema.ACL;
1624
+ /**
1625
+ * ACL for delete operation.
1626
+ */
1627
+ delete?: TSchema.ACL;
1628
+ };
1629
+ /**
1630
+ * Field Level Permissions (FLPs).
1631
+ *
1632
+ * Defines access control for individual fields.
1633
+ */
1634
+ type FLPs = {
1635
+ /**
1636
+ * ACL for reading the field.
1637
+ */
1638
+ read?: TSchema.ACL;
1639
+ /**
1640
+ * ACL for creating the field.
1641
+ */
1642
+ create?: TSchema.ACL;
1643
+ /**
1644
+ * ACL for updating the field.
1645
+ */
1646
+ update?: TSchema.ACL;
1647
+ };
1648
+ /**
1649
+ * Index definitions for the schema.
1650
+ *
1651
+ * Supports both basic and vector indexes.
1652
+ */
1653
+ type Indexes = {
1654
+ /**
1655
+ * Type of the index. Default is 'basic'.
1656
+ */
1657
+ type?: 'basic';
1658
+ /**
1659
+ * Keys for the index, mapping field names to sort order (1 for ascending, -1 for descending).
1660
+ */
1661
+ keys: Record<string, 1 | -1>;
1662
+ /**
1663
+ * Whether the index is unique.
1664
+ */
1665
+ unique?: boolean;
1666
+ } | {
1667
+ /**
1668
+ * Type of the index. Must be 'vector' for vector indexes.
1669
+ */
1670
+ type: 'vector';
1671
+ /**
1672
+ * Keys for the vector index. Can be a single field or an array of fields.
1673
+ */
1674
+ keys: string | string[];
1675
+ /**
1676
+ * Method for the vector index. Supported: 'hnsw', 'ivfflat'.
1677
+ */
1678
+ method?: 'hnsw' | 'ivfflat';
1679
+ };
1680
+ }
1681
+ interface TSchema {
1682
+ /**
1683
+ * Fields of the schema, where each field is a data type.
1684
+ */
1685
+ fields: Record<string, TSchema.DataType>;
1686
+ /**
1687
+ * Class level permissions for the schema.
1688
+ */
1689
+ classLevelPermissions?: TSchema.CLPs;
1690
+ /**
1691
+ * Additional object permissions for the schema.
1692
+ */
1693
+ additionalObjectPermissions?: TSchema.ACLs;
1694
+ /**
1695
+ * Field level permissions for the schema, where each field can have its own permissions.
1696
+ */
1697
+ fieldLevelPermissions?: Record<string, TSchema.FLPs>;
1698
+ /**
1699
+ * Secure fields in the schema.
1700
+ */
1701
+ secureFields?: string[];
1702
+ /**
1703
+ * Indexes for the schema.
1704
+ */
1705
+ indexes?: TSchema.Indexes[];
1706
+ /**
1707
+ * Indicates if live query is enabled for the schema.
1708
+ */
1709
+ liveQuery?: boolean;
1710
+ }
1711
+
1712
+ /**
1713
+ * Represents file information.
1714
+ */
1715
+ type TFileInfo = {
1716
+ /**
1717
+ * The MIME type of the file.
1718
+ */
1719
+ mimeType?: string;
1720
+ /**
1721
+ * The filename.
1722
+ */
1723
+ filename?: string;
1724
+ };
1725
+ /**
1726
+ * Interface for file storage operations.
1727
+ */
1728
+ interface TFileStorage {
1729
+ /**
1730
+ * The schema definition for the file storage.
1731
+ */
1732
+ schema: Record<string, TSchema>;
1733
+ /**
1734
+ * Creates a new file in the storage.
1735
+ * @param proto - The ProtoService instance.
1736
+ * @param stream - The binary data stream or async iterable of binary data.
1737
+ * @param info - The file information.
1738
+ * @param maxUploadSize - The maximum upload size.
1739
+ * @returns A promise that resolves to an object containing the file ID and size.
1740
+ */
1741
+ create<E>(proto: ProtoService<E>, stream: BinaryData | AsyncIterable<BinaryData>, info: TFileInfo, maxUploadSize: number): PromiseLike<{
1742
+ _id: string;
1743
+ size: number;
1744
+ }>;
1745
+ /**
1746
+ * Destroys a file in the storage.
1747
+ * @param proto - The ProtoService instance.
1748
+ * @param id - The ID of the file to destroy.
1749
+ * @returns A promise that resolves when the file is destroyed.
1750
+ */
1751
+ destroy<E>(proto: ProtoService<E>, id: string): PromiseLike<void>;
1752
+ /**
1753
+ * Retrieves file data from the storage.
1754
+ * @param proto - The ProtoService instance.
1755
+ * @param id - The ID of the file.
1756
+ * @param start - The optional start byte position.
1757
+ * @param end - The optional end byte position.
1758
+ * @returns An async iterable of binary data.
1759
+ */
1760
+ fileData<E>(proto: ProtoService<E>, id: string, start?: number, end?: number): AsyncIterable<BinaryData>;
1761
+ }
1762
+
1763
+ declare class QueryExpression {
1764
+ static decode(expr: _$1.Many<TExpression>, dollerSign: boolean): QueryExpression;
1765
+ simplify(): QueryExpression;
1766
+ keyPaths(): string[];
1767
+ mapKey(callback: (key: string) => string): QueryExpression;
1768
+ eval(value: any): any;
1769
+ evalType(schema: Record<string, TSchema>, className: string): TSchema.DataType[];
1770
+ }
1771
+
1772
+ declare class QuerySelector {
1773
+ static decode(selectors: _$1.Many<TQuerySelector>, dollerSign?: boolean): QuerySelector;
1774
+ simplify(): QuerySelector;
1775
+ keyPaths(): string[];
1776
+ eval(value: any): boolean;
1777
+ }
1778
+ declare class FieldSelectorExpression {
1779
+ type: keyof TFieldQuerySelector;
1780
+ value: QuerySelector | FieldSelectorExpression | RegExp | TValue;
1781
+ constructor(type: keyof TFieldQuerySelector, value: QuerySelector | FieldSelectorExpression | RegExp | TValue);
1782
+ static decode(selector: TFieldQuerySelector): FieldSelectorExpression;
1783
+ simplify(): FieldSelectorExpression;
1784
+ keyPaths(field?: string): string[];
1785
+ eval(value: any): any;
1786
+ }
1787
+
1788
+ declare class QueryAccumulator {
1789
+ static decode(query: TQueryAccumulator): QueryAccumulator;
1790
+ simplify(): QueryAccumulator;
1791
+ keyPaths(): string[];
1792
+ mapKey(callback: (key: string) => string): QueryAccumulator;
1793
+ evalType(schema: Record<string, TSchema>, className: string): TSchema.DataType | undefined;
1794
+ }
1795
+
1796
+ type FindOptions = {
1797
+ className: string;
1798
+ } & TQueryOptions;
1799
+ type RelationOptions = {
1800
+ relatedBy?: {
1801
+ className: string;
1802
+ id: string;
1803
+ key: string;
1804
+ };
1805
+ };
1806
+ type Decoded<T, R> = Omit<T, keyof R> & R;
1807
+ type DecodedSortOption = {
1808
+ expr: QueryExpression;
1809
+ order: 1 | -1;
1810
+ };
1811
+ type DecodedBaseQuery = Decoded<TQueryBaseOptions, {
1812
+ filter?: QuerySelector;
1813
+ matches: Record<string, DecodedBaseQuery>;
1814
+ groupMatches?: Record<string, Record<string, QueryAccumulator>>;
1815
+ sort?: Record<string, 1 | -1> | DecodedSortOption[];
1816
+ }>;
1817
+ type DecodedQuery<T> = Decoded<T, {
1818
+ filter: QuerySelector;
1819
+ matches: Record<string, DecodedBaseQuery>;
1820
+ groupMatches: Record<string, Record<string, QueryAccumulator>>;
1821
+ includes: string[];
1822
+ objectIdSize: number;
1823
+ sort?: Record<string, 1 | -1> | DecodedSortOption[];
1824
+ extraFilter?: (className: string) => QuerySelector;
1825
+ }>;
1826
+ type InsertOptions = {
1827
+ className: string;
1828
+ includes: string[];
1829
+ matches: Record<string, DecodedBaseQuery>;
1830
+ groupMatches: Record<string, Record<string, QueryAccumulator>>;
1831
+ objectIdSize: number;
1832
+ };
1833
+ type QueryRandomOptions = {
1834
+ weight?: QueryExpression;
1835
+ };
1836
+ interface TStorage {
1837
+ selectLock(): boolean;
1838
+ prepare(schema: Record<string, TSchema>): PromiseLike<void>;
1839
+ shutdown(): PromiseLike<void>;
1840
+ classes(): string[];
1841
+ config(acl?: string[]): PromiseLike<Record<string, TValueWithoutObject>>;
1842
+ configAcl(): PromiseLike<Record<string, string[]>>;
1843
+ setConfig(values: Record<string, TValueWithoutObject>, acl?: string[]): PromiseLike<void>;
1844
+ explain(query: DecodedQuery<FindOptions & RelationOptions>): PromiseLike<any>;
1845
+ count(query: DecodedQuery<FindOptions & RelationOptions>): PromiseLike<number>;
1846
+ find(query: DecodedQuery<FindOptions & RelationOptions>): AsyncIterable<TObject>;
1847
+ random(query: DecodedQuery<FindOptions & RelationOptions>, opts?: QueryRandomOptions): AsyncIterable<TObject>;
1848
+ groupFind(query: DecodedQuery<FindOptions & RelationOptions>, accumulators: Record<string, QueryAccumulator>): PromiseLike<Record<string, any>>;
1849
+ refs(object: TObject, classNames: string[], roles?: string[]): AsyncIterable<TObject>;
1850
+ nonrefs(query: DecodedQuery<FindOptions>): AsyncIterable<TObject>;
1851
+ insert(options: InsertOptions, values: Record<string, TValueWithUndefined>[]): PromiseLike<TObject[]>;
1852
+ update(query: DecodedQuery<FindOptions>, update: Record<string, TUpdateOp>): PromiseLike<TObject[]>;
1853
+ upsert(query: DecodedQuery<FindOptions>, update: Record<string, TUpdateOp>, setOnInsert: Record<string, TValueWithUndefined>): PromiseLike<TObject[]>;
1854
+ delete(query: DecodedQuery<FindOptions>): PromiseLike<TObject[]>;
1855
+ lockTable(className: string | string[], update: boolean): Promise<void>;
1856
+ withConnection<T>(callback: (connection: TStorage) => PromiseLike<T>): PromiseLike<T>;
1857
+ isDuplicateIdError(error: any): boolean;
1858
+ atomic<T>(callback: (connection: TStorage) => PromiseLike<T>, options?: {
1859
+ lockTable?: string;
1860
+ retry?: boolean;
1861
+ }): PromiseLike<T>;
1862
+ withTransaction<T>(callback: (connection: TStorage) => PromiseLike<T>, options?: TransactionOptions): PromiseLike<T>;
1863
+ }
1864
+
1865
+ type _PasswordHashOptions = {
1866
+ 'scrypt': {
1867
+ log2n: number;
1868
+ blockSize: number;
1869
+ parallel: number;
1870
+ keySize: number;
1871
+ saltSize: number;
1872
+ };
1873
+ };
1874
+ type PasswordHashOptions = {
1875
+ [K in keyof _PasswordHashOptions]: {
1876
+ alg: K;
1877
+ } & _PasswordHashOptions[K];
1878
+ }[keyof _PasswordHashOptions];
1879
+
1880
+ /**
1881
+ * Interface for publish-subscribe operations.
1882
+ */
1883
+ interface TPubSub {
1884
+ /**
1885
+ * Subscribes to a channel.
1886
+ * @param channel - The name of the channel to subscribe to.
1887
+ * @param callback - The callback function to handle the event data.
1888
+ * @returns A function to unsubscribe from the channel.
1889
+ */
1890
+ subscribe(channel: string, callback: (payload: TValueWithoutObject) => void): VoidFunction;
1891
+ /**
1892
+ * Publishes an event to a channel.
1893
+ * @param channel - The name of the channel to publish to.
1894
+ * @param payload - The event data to publish.
1895
+ * @returns A promise that resolves when the event is published.
1896
+ */
1897
+ publish(channel: string, payload: TValueWithoutObject): Awaitable<void>;
1898
+ }
1899
+
1900
+ type ProtoServiceOptions<Ext> = {
1901
+ /**
1902
+ * The endpoint for the service.
1903
+ */
1904
+ endpoint: string;
1905
+ /**
1906
+ * The schema definitions for the service.
1907
+ */
1908
+ schema: Record<string, TSchema>;
1909
+ /**
1910
+ * Role resolver configuration.
1911
+ */
1912
+ roleResolver?: {
1913
+ /**
1914
+ * Keys to inherit roles.
1915
+ */
1916
+ inheritKeys?: string[];
1917
+ /**
1918
+ * Custom resolver function for roles.
1919
+ * @param user The user object.
1920
+ * @param defaultResolver The default resolver function.
1921
+ * @returns A promise that resolves to an array of roles.
1922
+ */
1923
+ resolver?: (user: TUser, defaultResolver: () => Promise<TRole[]>) => Awaitable<TRole[]>;
1924
+ };
1925
+ /**
1926
+ * Logger configuration.
1927
+ */
1928
+ logger?: Partial<Logger>;
1929
+ /**
1930
+ * Storage configuration.
1931
+ */
1932
+ storage: TStorage;
1933
+ /**
1934
+ * File storage configuration.
1935
+ */
1936
+ fileStorage: TFileStorage;
1937
+ /**
1938
+ * Pub/Sub configuration.
1939
+ */
1940
+ pubsub?: TPubSub;
1941
+ /**
1942
+ * Class extensions configuration.
1943
+ */
1944
+ classExtends?: TExtensions<Ext>;
1945
+ /**
1946
+ * Size of the object ID.
1947
+ */
1948
+ objectIdSize?: number;
1949
+ /**
1950
+ * Maximum fetch limit.
1951
+ */
1952
+ maxFetchLimit?: number;
1953
+ /**
1954
+ * Maximum upload size.
1955
+ */
1956
+ maxUploadSize?: number;
1957
+ /**
1958
+ * Cookie options.
1959
+ */
1960
+ cookieOptions?: CookieOptions;
1961
+ /**
1962
+ * JWT sign options.
1963
+ */
1964
+ jwtSignOptions?: SignOptions;
1965
+ /**
1966
+ * JWT verify options.
1967
+ */
1968
+ jwtVerifyOptions?: VerifyOptions;
1969
+ /**
1970
+ * JWT upload sign options.
1971
+ */
1972
+ jwtUploadSignOptions?: SignOptions;
1973
+ /**
1974
+ * JWT upload verify options.
1975
+ */
1976
+ jwtUploadVerifyOptions?: VerifyOptions;
1977
+ /**
1978
+ * Password hash options.
1979
+ */
1980
+ passwordHashOptions?: PasswordHashOptions;
1981
+ /**
1982
+ * Password policy options.
1983
+ */
1984
+ passwordPolicy?: {
1985
+ /**
1986
+ * Do not allow reusing previous passwords.
1987
+ */
1988
+ maxPasswordHistory?: number;
1989
+ /**
1990
+ * Custom validator callback for password strength.
1991
+ * @param password The password to validate.
1992
+ * @param user The user object (optional).
1993
+ * @returns A boolean or a promise that resolves to a boolean indicating whether the password is valid.
1994
+ */
1995
+ validatorCallback?: (password: string, user?: TUser) => Awaitable<boolean>;
1996
+ };
1997
+ };
1998
+ type ProtoServiceKeyOptions = {
1999
+ /**
2000
+ * JWT token for the service.
2001
+ */
2002
+ jwtToken: string;
2003
+ /**
2004
+ * Master users configuration.
2005
+ */
2006
+ masterUsers?: {
2007
+ /**
2008
+ * Username of the master user.
2009
+ */
2010
+ user: string;
2011
+ /**
2012
+ * Password of the master user.
2013
+ */
2014
+ pass: string;
2015
+ }[];
2016
+ };
2017
+
2018
+ declare class ProtoService<Ext = any> extends ProtoType<Ext> {
2019
+ private _storage?;
2020
+ private _schedule;
2021
+ req?: Request;
2022
+ session?: _Session;
2023
+ constructor(options: ProtoServiceOptions<Ext> & ProtoServiceKeyOptions);
2024
+ shutdown(): Promise<void>;
2025
+ get logger(): Logger;
2026
+ classes(): string[];
2027
+ Query<T extends string>(className: T): TQuery<T, Ext, boolean>;
2028
+ Relation<T extends string>(object: TObject, key: PathName<T>): TQuery<string, Ext, boolean>;
2029
+ InsecureQuery<T extends string>(className: T): TQuery<T, Ext, true>;
2030
+ sessionInfo(): Promise<{
2031
+ user?: TObject | undefined;
2032
+ _roles?: TRole[] | undefined;
2033
+ sessionId?: string | undefined;
2034
+ createdAt?: Date | undefined;
2035
+ updatedAt?: Date | undefined;
2036
+ loginedAt?: Date | undefined;
2037
+ cookieOptions?: any;
2038
+ } | undefined>;
2039
+ currentUser(): Promise<TUser | undefined>;
2040
+ _currentRoles(): Promise<TRole[]>;
2041
+ currentRoles(): Promise<string[]>;
2042
+ get isMaster(): boolean;
2043
+ get isInvalidMasterToken(): boolean;
2044
+ connect<R extends Request, T extends object>(req: R, attrs?: T | ((x: this & {
2045
+ req: R;
2046
+ }) => T)): this & {
2047
+ req: R;
2048
+ } & T;
2049
+ connectWithSessionToken<T extends object>(token: string, attrs?: T | ((x: this & {
2050
+ session?: _Session;
2051
+ }) => T)): Promise<this & {
2052
+ session?: _Session;
2053
+ } & T>;
2054
+ userRoles(user: TUser): Promise<TRole[]>;
2055
+ becomeUser(req: Request, user: TUser, options?: {
2056
+ cookieOptions?: CookieOptions | undefined;
2057
+ jwtSignOptions?: jwt.SignOptions | undefined;
2058
+ }): Promise<void>;
2059
+ logoutUser(req: Request, options?: {
2060
+ cookieOptions?: CookieOptions | undefined;
2061
+ jwtSignOptions?: jwt.SignOptions | undefined;
2062
+ }): Promise<void>;
2063
+ verifyPassword(user: TUser, password: string, options: ExtraOptions<true>): Promise<boolean>;
2064
+ setPassword(user: TUser, password: string, options: ExtraOptions<true>): Promise<void>;
2065
+ unsetPassword(user: TUser, options: ExtraOptions<true>): Promise<void>;
2066
+ get schema(): ProtoServiceOptions<Ext>['schema'];
2067
+ get storage(): ProtoServiceOptions<Ext>['storage'];
2068
+ get fileStorage(): ProtoServiceOptions<Ext>['fileStorage'];
2069
+ config(options?: {
2070
+ master?: boolean;
2071
+ }): Promise<Record<string, TValueWithoutObject>>;
2072
+ configAcl(options: {
2073
+ master: true;
2074
+ }): PromiseLike<Record<string, string[]>>;
2075
+ setConfig(values: Record<string, TValueWithoutObject>, options: {
2076
+ master: true;
2077
+ acl?: string[];
2078
+ }): Promise<void>;
2079
+ run<R extends TSerializable | void = any>(name: string, params?: TSerializable, options?: ExtraOptions<boolean>): Promise<R>;
2080
+ define<P extends TSerializable = any, R extends TSerializable | void = any>(name: string, callback: ProtoFunction<Ext, P, R>, options?: Omit<ProtoFunctionOptions<Ext>, 'callback'>): void;
2081
+ afterCreate<T extends string>(className: string, callback: ProtoTriggerFunction<T, Ext>): void;
2082
+ afterUpdate<T extends string>(className: string, callback: ProtoTriggerFunction<T, Ext>): void;
2083
+ afterDelete<T extends string>(className: string, callback: ProtoTriggerFunction<T, Ext>): void;
2084
+ scheduleJob(name: string, params?: TValueWithoutObject, options?: ExtraOptions<boolean>): Promise<TObjectType<"_Job", Ext>>;
2085
+ defineJob<P extends TValueWithoutObject = any>(name: string, callback: ProtoJobFunction<Ext, P>, options?: Omit<ProtoJobFunctionOptions<Ext>, 'callback'>): void;
2086
+ lockTable(className: string | string[], update: boolean): Promise<void>;
2087
+ withTransaction<T>(callback: (connection: ProtoService<Ext>) => PromiseLike<T>, options?: TransactionOptions): Promise<T>;
2088
+ generateUploadToken(options?: {
2089
+ maxUploadSize?: number;
2090
+ attributes?: Record<string, TValue>;
2091
+ jwtSignOptions?: jwt.SignOptions;
2092
+ }): string;
2093
+ jwtSign(payload: any, options: jwt.SignOptions): string;
2094
+ jwtVerify(token: string, options?: jwt.VerifyOptions): jwt.JwtPayload | undefined;
2095
+ notify(data: Record<string, TValueWithoutObject> & {
2096
+ _rperm?: string[];
2097
+ }): Promise<void>;
2098
+ listen(callback: (data: EventData) => void, selector?: TQuerySelector): {
2099
+ remove: VoidFunction;
2100
+ };
2101
+ refs(object: TObject, options?: ExtraOptions<boolean>): _o2ter_utils_js.AsyncStream<TObjectType<string, Ext>>;
2102
+ gc(classNames?: string | string[]): Promise<void>;
2103
+ }
2104
+
2105
+ export { FieldSelectorExpression as F, ProtoService as P, QueryExpression as Q, TSchema as T, deserialize as g, ProtoType as i, TQuery as j, TObject as k, TUser as n, serialize as s, QueryAccumulator as u, QuerySelector as v };
2106
+ export type { TransactionOptions as A, QueryRandomOptions as B, TPubSub as C, DeserializeOptions as D, ExtraOptions as E, TFileInfo as G, InsertOptions as I, RelationOptions as R, SerializeOptions as S, ProtoServiceOptions as a, ProtoServiceKeyOptions as b, TValueWithoutObject as c, TFileStorage as d, TNumber as e, TSerializable as f, TExtensions as h, PathName as l, TObjectType as m, EventData as o, TQuerySelector as p, TValueWithUndefined as q, TValue as r, TUpdateOp as t, DecodedQuery as w, FindOptions as x, DecodedSortOption as y, TStorage as z };
2107
+ //# sourceMappingURL=index-OwgXw07h.d.mts.map