proto.io 0.0.172 → 0.0.174

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