@powerlines/deepkit 0.4.90 → 0.4.92

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.
@@ -1 +1,3425 @@
1
- export * from '@deepkit/type';
1
+ export type NumberFields<T> = {
2
+ [K in keyof T]: T[K] extends number | bigint ? K : never;
3
+ }[keyof T];
4
+ export type Expression<T> = {
5
+ [P in keyof T & string]?: string;
6
+ };
7
+ type Partial$1<T> = {
8
+ [P in keyof T & string]?: T[P];
9
+ };
10
+ export type DeepPartial<T> = {
11
+ [P in keyof T]?: T[P];
12
+ } & {
13
+ [deepPath: string]: any;
14
+ };
15
+ export interface ChangesInterface<T> {
16
+ $set?: DeepPartial<T> | T;
17
+ $unset?: {
18
+ [path: string]: number;
19
+ };
20
+ $inc?: Partial$1<Pick<T, NumberFields<T>>>;
21
+ }
22
+ export declare class Changes<T extends object> {
23
+ $set?: DeepPartial<T> | T;
24
+ $unset?: {
25
+ [path: string]: number;
26
+ };
27
+ $inc?: Partial$1<Pick<T, NumberFields<T>>>;
28
+ empty: boolean;
29
+ fieldNames: string[];
30
+ constructor(changes?: ChangesInterface<T>);
31
+ clear(): void;
32
+ getReturning(): string[];
33
+ protected detectEmpty(): void;
34
+ replaceSet($set: DeepPartial<T> | T): void;
35
+ mergeSet($set: Partial$1<T> | T): void;
36
+ increase(property: NumberFields<T>, increase?: number): void;
37
+ set(property: keyof T & string, value: any): void;
38
+ unset(property: keyof T & string, unset?: boolean): void;
39
+ has(name: keyof T & string): boolean;
40
+ }
41
+ export declare class ItemChanges<T extends object> extends Changes<T> {
42
+ protected item: T;
43
+ constructor(changes: ChangesInterface<T> | undefined, item: T);
44
+ increase(property: NumberFields<T>, increase?: number): void;
45
+ set(property: keyof T & string, value: any): void;
46
+ unset(property: keyof T & string, unset?: boolean): void;
47
+ }
48
+ export declare const changeSetSymbol: unique symbol;
49
+ export declare class AtomicChangeInstance<T extends object> {
50
+ protected object: any;
51
+ readonly changeSet: Changes<T>;
52
+ constructor(object: any);
53
+ increase(property: NumberFields<T>, increase?: number): void;
54
+ }
55
+ export declare function atomicChange<T extends object>(object: T): AtomicChangeInstance<T>;
56
+ export declare type __ΩNumberFields = any[];
57
+ export declare type __ΩExpression = any[];
58
+ export declare type __ΩPartial = any[];
59
+ export declare type __ΩDeepPartial = any[];
60
+ export declare type __ΩChangesInterface = any[];
61
+ declare class CustomError extends Error {
62
+ name: string;
63
+ constructor(...args: any[]);
64
+ }
65
+ interface CustomError {
66
+ cause?: unknown;
67
+ }
68
+ interface ClassType<T = any> {
69
+ new (...args: any[]): T;
70
+ }
71
+ type AbstractClassType<T = any> = abstract new (...args: any[]) => T;
72
+ type ExtractClassType<T> = T extends AbstractClassType<infer K> ? K : never;
73
+ declare class CompilerContext {
74
+ readonly context: Map<string, any>;
75
+ protected constVariables: Map<any, string>;
76
+ maxReservedVariable: number;
77
+ protected reservedNames: Set<string>;
78
+ protected variableContext: {
79
+ [name: string]: any;
80
+ };
81
+ /**
82
+ * Code that is executed in the context, but before the actual function is generated.
83
+ * This helps for example to initialize dynamically some context variables.
84
+ */
85
+ preCode: string;
86
+ initialiseVariables: string[];
87
+ config: {
88
+ indent: boolean;
89
+ };
90
+ constructor(config?: Partial<CompilerContext["config"]>);
91
+ reserveName(name: string): string;
92
+ set(values: {
93
+ [name: string]: any;
94
+ }): void;
95
+ /**
96
+ * Returns always the same variable name for the same value.
97
+ * The variable name should not be set afterwards.
98
+ */
99
+ reserveConst(value: any, name?: string): string;
100
+ reserveVariable(name?: string, value?: any): string;
101
+ raw(functionCode: string): Function;
102
+ protected format(code: string): string;
103
+ build(functionCode: string, ...args: string[]): any;
104
+ buildAsync(functionCode: string, ...args: string[]): Function;
105
+ }
106
+ type TypeAnnotation<T extends string, Options = never> = unknown;
107
+ /**
108
+ * note: Checks are based on range checks (>, <, etc), so when adding
109
+ * new types a check is required for all code using `TypeNumberBrand`.
110
+ */
111
+ export declare enum TypeNumberBrand {
112
+ integer = 0,
113
+ int8 = 1,
114
+ int16 = 2,
115
+ int32 = 3,
116
+ uint8 = 4,
117
+ uint16 = 5,
118
+ uint32 = 6,
119
+ float = 7,
120
+ float32 = 8,
121
+ float64 = 9
122
+ }
123
+ declare enum ReflectionOp {
124
+ never = 0,
125
+ any = 1,
126
+ unknown = 2,
127
+ void = 3,
128
+ object = 4,
129
+ string = 5,
130
+ number = 6,
131
+ numberBrand = 7,
132
+ boolean = 8,
133
+ bigint = 9,
134
+ symbol = 10,
135
+ null = 11,
136
+ undefined = 12,
137
+ /**
138
+ * The literal type of string, number, or boolean.
139
+ *
140
+ * This OP has 1 parameter. The next byte is the absolute address of the literal on the stack, which is the actual literal value.
141
+ *
142
+ * Pushes a function type.
143
+ */
144
+ literal = 13,
145
+ /**
146
+ * This OP pops all types on the current stack frame.
147
+ *
148
+ * This OP has 1 parameter. The next byte is the absolute address of a string|number|symbol entry on the stack.
149
+ *
150
+ * Pushes a function type.
151
+ */
152
+ function = 14,
153
+ /**
154
+ * This OP pops all types on the current stack frame.
155
+ *
156
+ * Pushes a method type.
157
+ */
158
+ method = 15,
159
+ methodSignature = 16,//has 1 parameter, reference to stack for its property name
160
+ parameter = 17,
161
+ /**
162
+ * This OP pops the latest type entry on the stack.
163
+ *
164
+ * Pushes a property type.
165
+ */
166
+ property = 18,
167
+ propertySignature = 19,//has 1 parameter, reference to stack for its property name
168
+ /**
169
+ * This OP pops all types on the current stack frame. Those types should be method|property.
170
+ *
171
+ * Pushes a TypeClass onto the stack.
172
+ */
173
+ class = 20,
174
+ /**
175
+ * If a class extends another class with generics, this OP represents the generic type arguments of the super class.
176
+ *
177
+ * e.g. `class A extends B<string, boolean>`, string and boolean are on the stack and classExtends pops() them, and then assigns to A.extendsTypeArguments = [string, boolean].
178
+ *
179
+ * This is only emitted when the class that is currently being described actually extends another class and uses generics.
180
+ *
181
+ * This OP has 1 argument and pops x types from the stack. X is the first argument.
182
+ * Expects a TypeClass on the stack.
183
+ */
184
+ classExtends = 21,
185
+ /**
186
+ * This OP has 1 parameter, the stack entry to the actual class symbol.
187
+ */
188
+ classReference = 22,
189
+ /**
190
+ * Marks the last entry in the stack as optional. Used for method|property. Equal to the QuestionMark operator in a property assignment.
191
+ */
192
+ optional = 23,
193
+ readonly = 24,
194
+ public = 25,
195
+ private = 26,
196
+ protected = 27,
197
+ abstract = 28,
198
+ defaultValue = 29,
199
+ description = 30,
200
+ rest = 31,
201
+ regexp = 32,
202
+ enum = 33,
203
+ enumMember = 34,//has one argument, the name.
204
+ set = 35,
205
+ map = 36,
206
+ /**
207
+ * Pops the latest stack entry and uses it as T for an array type.
208
+ *
209
+ * Pushes an array type.
210
+ */
211
+ array = 37,
212
+ tuple = 38,
213
+ tupleMember = 39,
214
+ namedTupleMember = 40,//has one argument, the name.
215
+ union = 41,//pops frame. requires frame start when stack can be dirty.
216
+ intersection = 42,
217
+ indexSignature = 43,
218
+ objectLiteral = 44,
219
+ mappedType = 45,//2 parameters: functionPointer and modifier.
220
+ in = 46,
221
+ frame = 47,//creates a new stack frame
222
+ moveFrame = 48,//pop() as T, pops the current stack frame, push(T)
223
+ return = 49,
224
+ templateLiteral = 50,
225
+ date = 51,
226
+ int8Array = 52,
227
+ uint8ClampedArray = 53,
228
+ uint8Array = 54,
229
+ int16Array = 55,
230
+ uint16Array = 56,
231
+ int32Array = 57,
232
+ uint32Array = 58,
233
+ float32Array = 59,
234
+ float64Array = 60,
235
+ bigInt64Array = 61,
236
+ arrayBuffer = 62,
237
+ promise = 63,
238
+ arg = 64,//@deprecated. parameter is a number referencing an entry in the stack, relative to the beginning of the current frame, *-1. pushes that entry onto the stack. this is related to the calling convention.
239
+ typeParameter = 65,//generic type parameter, e.g. T in a generic. has 1 parameter: reference to the name.
240
+ typeParameterDefault = 66,//generic type parameter with a default value, e.g. T in a generic. has 1 parameter: reference to the name. pop() for the default value
241
+ var = 67,//reserve a new variable in the stack
242
+ loads = 68,//pushes to the stack a referenced value in the stack. has 2 parameters: <frame> <index>, frame is a negative offset to the frame, and index the index of the stack entry withing the referenced frame
243
+ indexAccess = 69,//T['string'], 2 items on the stack
244
+ keyof = 70,//keyof operator
245
+ infer = 71,//2 params, like `loads`
246
+ typeof = 72,//1 parameter that points to a function returning the runtime value from which we need to extract the type
247
+ condition = 73,
248
+ jumpCondition = 74,//@deprecated. used when INFER is used in `extends` conditional branch. 2 args: left program, right program
249
+ jump = 75,//jump to an address
250
+ call = 76,//has one parameter, the next program address. creates a new stack frame with current program address as first stack entry, and jumps back to that + 1.
251
+ inline = 77,
252
+ inlineCall = 78,
253
+ distribute = 79,//has one parameter, the co-routine program index.
254
+ extends = 80,//X extends Y in a conditional type, XY popped from the stack, pushes boolean on the stack
255
+ widen = 81,//widens the type on the stack, .e.g 'asd' => string, 34 => number, etc. this is necessary for infer runtime data, and widen if necessary (object member or non-contained literal)
256
+ static = 82,
257
+ mappedType2 = 83,//same as mappedType2 but the given functionPointer returns a tuple [type, name]
258
+ functionReference = 84,//Same as classReference but for functions
259
+ callSignature = 85,//Same as function but for call signatures (in object literals)
260
+ /**
261
+ * Assign for Enum, Interface, Class, and TypeAlias declaration at the very end
262
+ * of the program the typeName. This is so that we have type names available even
263
+ * if the JS code is minified.
264
+ *
265
+ * his operator also assigns originTypes to the type, as it acts as the finalization
266
+ * step of a type.
267
+ */
268
+ typeName = 86,//has one parameter, the index of the stack entry that contains the type name. Uses current head of the stack as type and assigns typeName to it.
269
+ /**
270
+ * If a class implement an interface or type,
271
+ *
272
+ * e.g. `class A implements B`, then B is on the stack and implements pops() it, and then assigns to A.implements = [B].
273
+ *
274
+ * This is only emitted when the class that is currently being described actually implements something.
275
+ *
276
+ * This OP has 1 argument and pops x types from the stack. X is the first argument.
277
+ * Expects a TypeClass on the stack.
278
+ */
279
+ implements = 87,//pops one type from the stack and assigns it to the latest class on the stack as `implements` type.
280
+ nominal = 88,//marks the last type on the stack as nominal. (used at the end of class/interface/type alias programs).
281
+ /**
282
+ * Custom Storm Software operators
283
+ */
284
+ tags = 89
285
+ }
286
+ export declare enum ReflectionVisibility {
287
+ public = 0,
288
+ protected = 1,
289
+ private = 2
290
+ }
291
+ export declare enum ReflectionKind {
292
+ never = 0,
293
+ any = 1,
294
+ unknown = 2,
295
+ void = 3,
296
+ object = 4,
297
+ string = 5,
298
+ number = 6,
299
+ boolean = 7,
300
+ symbol = 8,
301
+ bigint = 9,
302
+ null = 10,
303
+ undefined = 11,
304
+ regexp = 12,
305
+ literal = 13,
306
+ templateLiteral = 14,
307
+ property = 15,
308
+ method = 16,
309
+ function = 17,
310
+ parameter = 18,
311
+ promise = 19,
312
+ /**
313
+ * Uint8Array, Date, custom classes, Set, Map, etc
314
+ */
315
+ class = 20,
316
+ typeParameter = 21,
317
+ enum = 22,
318
+ union = 23,
319
+ intersection = 24,
320
+ array = 25,
321
+ tuple = 26,
322
+ tupleMember = 27,
323
+ enumMember = 28,
324
+ rest = 29,
325
+ objectLiteral = 30,
326
+ indexSignature = 31,
327
+ propertySignature = 32,
328
+ methodSignature = 33,
329
+ infer = 34,
330
+ callSignature = 35
331
+ }
332
+ export type TypeDecorator = (annotations: Annotations, decorator: TypeObjectLiteral) => boolean;
333
+ export type Annotations = any;
334
+ /**
335
+ * @reflection never
336
+ */
337
+ export interface TypeAnnotations {
338
+ id?: number;
339
+ origin?: Type;
340
+ /**
341
+ * True when this type comes from an inline type, e.g.
342
+ *
343
+ * `type A = T;`. Type of `T` is inlined.
344
+ * `type A = {}`. Type of `{}` is not inlined.
345
+ *
346
+ * If the type is not inlined and the result of a type function, then we assign parents of members accordingly. This is not the caee when a type was inlined.
347
+ */
348
+ inlined?: true;
349
+ /**
350
+ * If the type was created by a type function, this contains the alias name.
351
+ */
352
+ typeName?: string;
353
+ /**
354
+ * If the type was created by a type function, this contains the arguments passed the function.
355
+ */
356
+ typeArguments?: Type[];
357
+ /**
358
+ * Set for index access expressions, e.g. Config['property'].
359
+ */
360
+ indexAccessOrigin?: {
361
+ container: TypeClass | TypeObjectLiteral;
362
+ index: Type;
363
+ };
364
+ /**
365
+ * type User = {id: number, user: string};
366
+ * type UserCreate = Pick<User, 'user'>;
367
+ * typeOf<UserCreate>().originTypes[0].typeName = 'Pick'
368
+ * typeOf<UserCreate>().originTypes[0].typeArguments = [User, 'user']
369
+ */
370
+ originTypes?: {
371
+ typeName: string;
372
+ typeArguments?: Type[];
373
+ }[];
374
+ annotations?: Annotations;
375
+ decorators?: Type[];
376
+ scheduleDecorators?: TypeObjectLiteral[];
377
+ /**
378
+ * A place where arbitrary jit functions and its cache data is stored.
379
+ */
380
+ jit?: JitContainer;
381
+ }
382
+ export declare function applyScheduledAnnotations(type: Type): void;
383
+ export declare function hasTypeInformation(object: ClassType | Function): boolean;
384
+ /**
385
+ * Object to hold runtime jit data.
386
+ */
387
+ export type JitContainer = any;
388
+ export declare function getTypeJitContainer(type: Type): JitContainer;
389
+ export declare function clearTypeJitContainer(type: Type): void;
390
+ export interface TagsReflection {
391
+ hidden?: boolean;
392
+ ignore?: boolean;
393
+ internal?: boolean;
394
+ alias?: string[];
395
+ title?: string;
396
+ readonly?: boolean;
397
+ permission?: string[];
398
+ domain?: string;
399
+ }
400
+ export interface TypeNever extends TypeAnnotations {
401
+ kind: ReflectionKind.never;
402
+ parent?: Type;
403
+ }
404
+ export interface TypeAny extends TypeAnnotations {
405
+ kind: ReflectionKind.any;
406
+ parent?: Type;
407
+ }
408
+ export interface TypeUnknown extends TypeAnnotations {
409
+ kind: ReflectionKind.unknown;
410
+ parent?: Type;
411
+ }
412
+ export interface TypeVoid extends TypeAnnotations {
413
+ kind: ReflectionKind.void;
414
+ parent?: Type;
415
+ }
416
+ export interface TypeObject extends TypeAnnotations {
417
+ kind: ReflectionKind.object;
418
+ parent?: Type;
419
+ }
420
+ export interface TypeString extends TypeAnnotations {
421
+ kind: ReflectionKind.string;
422
+ parent?: Type;
423
+ }
424
+ export declare function isIntegerType(type: Type): type is TypeNumber;
425
+ export interface TypeNumber extends TypeAnnotations {
426
+ kind: ReflectionKind.number;
427
+ brand?: TypeNumberBrand;
428
+ parent?: Type;
429
+ }
430
+ export interface TypeBoolean extends TypeAnnotations {
431
+ kind: ReflectionKind.boolean;
432
+ parent?: Type;
433
+ }
434
+ export interface TypeBigInt extends TypeAnnotations {
435
+ kind: ReflectionKind.bigint;
436
+ parent?: Type;
437
+ }
438
+ export interface TypeSymbol extends TypeAnnotations {
439
+ kind: ReflectionKind.symbol;
440
+ parent?: Type;
441
+ }
442
+ export interface TypeNull extends TypeAnnotations {
443
+ kind: ReflectionKind.null;
444
+ parent?: Type;
445
+ }
446
+ export interface TypeUndefined extends TypeAnnotations {
447
+ kind: ReflectionKind.undefined;
448
+ parent?: Type;
449
+ }
450
+ export interface TypeLiteral extends TypeAnnotations {
451
+ kind: ReflectionKind.literal;
452
+ literal: symbol | string | number | boolean | bigint | RegExp;
453
+ parent?: Type;
454
+ }
455
+ export interface TypeTemplateLiteral extends TypeAnnotations {
456
+ kind: ReflectionKind.templateLiteral;
457
+ types: (TypeString | TypeAny | TypeNumber | TypeLiteral | TypeInfer)[];
458
+ parent?: Type;
459
+ }
460
+ export interface TypeRegexp extends TypeAnnotations {
461
+ kind: ReflectionKind.regexp;
462
+ parent?: Type;
463
+ }
464
+ export interface TypeBaseMember extends TypeAnnotations {
465
+ visibility: ReflectionVisibility;
466
+ abstract?: true;
467
+ static?: true;
468
+ optional?: true;
469
+ readonly?: true;
470
+ tags?: TagsReflection;
471
+ }
472
+ export interface TypeParameter extends TypeAnnotations {
473
+ kind: ReflectionKind.parameter;
474
+ name: string;
475
+ type: Type;
476
+ parent: TypeFunction | TypeMethod | TypeMethodSignature | TypeCallSignature;
477
+ visibility?: ReflectionVisibility;
478
+ readonly?: true;
479
+ optional?: true;
480
+ description?: string;
481
+ /**
482
+ * Set when the parameter has a default value aka initializer.
483
+ */
484
+ default?: (() => any) | any;
485
+ tags?: TagsReflection;
486
+ }
487
+ export interface TypeMethod extends TypeBaseMember {
488
+ kind: ReflectionKind.method;
489
+ parent: TypeClass;
490
+ name: number | string | symbol;
491
+ description?: string;
492
+ parameters: TypeParameter[];
493
+ return: Type;
494
+ }
495
+ export interface TypeProperty extends TypeBaseMember {
496
+ kind: ReflectionKind.property;
497
+ parent: TypeClass;
498
+ visibility: ReflectionVisibility;
499
+ name: number | string | symbol;
500
+ description?: string;
501
+ type: Type;
502
+ /**
503
+ * Set when the property has a default value aka initializer.
504
+ */
505
+ default?: (() => any) | any;
506
+ }
507
+ export interface TypeFunction extends TypeAnnotations {
508
+ kind: ReflectionKind.function;
509
+ parent?: Type;
510
+ name?: number | string | symbol;
511
+ description?: string;
512
+ function?: Function;
513
+ parameters: TypeParameter[];
514
+ return: Type;
515
+ tags?: TagsReflection;
516
+ }
517
+ export interface TypeCallSignature extends TypeAnnotations {
518
+ kind: ReflectionKind.callSignature;
519
+ parent?: Type;
520
+ parameters: TypeParameter[];
521
+ return: Type;
522
+ tags?: TagsReflection;
523
+ }
524
+ export interface TypePromise extends TypeAnnotations {
525
+ kind: ReflectionKind.promise;
526
+ parent?: Type;
527
+ type: Type;
528
+ }
529
+ export interface TypeClass extends TypeAnnotations {
530
+ kind: ReflectionKind.class;
531
+ parent?: Type;
532
+ classType: ClassType;
533
+ description?: string;
534
+ /**
535
+ * When the class extends another class and uses on it generic type arguments, then those arguments
536
+ * are in this array.
537
+ * For example `class A extends B<string, boolean> {}` then extendsArguments = [string, boolean].
538
+ * The reference to `B` is not part of TypeClass since this information is available in JavaScript runtime
539
+ * by using `Object.getPrototypeOf(type.classType)`.
540
+ */
541
+ extendsArguments?: Type[];
542
+ /**
543
+ * When the class implements another interface/type, then those types are in this array.
544
+ *
545
+ * For example `class A implements B<string, boolean> {}` then implements = [B<string, boolean>].
546
+ */
547
+ implements?: Type[];
548
+ /**
549
+ * When class has generic type arguments, e.g. MyClass<string>, it contains
550
+ * all type arguments. If no type arguments are given, it's undefined.
551
+ */
552
+ arguments?: Type[];
553
+ /**
554
+ * properties/methods.
555
+ */
556
+ types: (TypeIndexSignature | TypeProperty | TypeMethod)[];
557
+ tags?: TagsReflection;
558
+ }
559
+ export interface TypeEnum extends TypeAnnotations {
560
+ kind: ReflectionKind.enum;
561
+ parent?: Type;
562
+ enum: {
563
+ [name: string]: string | number | undefined | null;
564
+ };
565
+ values: (string | number | undefined | null)[];
566
+ indexType: Type;
567
+ description?: string;
568
+ tags?: TagsReflection;
569
+ }
570
+ export interface TypeEnumMember extends TypeAnnotations {
571
+ kind: ReflectionKind.enumMember;
572
+ parent: TypeEnum;
573
+ name: string;
574
+ description?: string;
575
+ default?: (() => string | number) | string | number;
576
+ tags?: TagsReflection;
577
+ }
578
+ export interface TypeTypeParameter extends TypeAnnotations {
579
+ kind: ReflectionKind.typeParameter;
580
+ parent?: Type;
581
+ name: string;
582
+ tags?: TagsReflection;
583
+ }
584
+ export interface TypeUnion extends TypeAnnotations {
585
+ kind: ReflectionKind.union;
586
+ parent?: Type;
587
+ types: Type[];
588
+ }
589
+ export interface TypeIntersection extends TypeAnnotations {
590
+ kind: ReflectionKind.intersection;
591
+ parent?: Type;
592
+ types: Type[];
593
+ }
594
+ export interface TypeArray extends TypeAnnotations {
595
+ kind: ReflectionKind.array;
596
+ parent?: Type;
597
+ type: Type;
598
+ tags?: TagsReflection;
599
+ }
600
+ export interface TypePropertySignature extends TypeAnnotations {
601
+ kind: ReflectionKind.propertySignature;
602
+ parent: TypeObjectLiteral;
603
+ name: number | string | symbol;
604
+ optional?: true;
605
+ readonly?: true;
606
+ description?: string;
607
+ type: Type;
608
+ /**
609
+ * Set when the property has a default value aka initializer.
610
+ */
611
+ default?: (() => any) | any;
612
+ tags?: TagsReflection;
613
+ }
614
+ export interface TypeMethodSignature extends TypeAnnotations {
615
+ kind: ReflectionKind.methodSignature;
616
+ parent: TypeObjectLiteral;
617
+ name: number | string | symbol;
618
+ optional?: true;
619
+ description?: string;
620
+ parameters: TypeParameter[];
621
+ return: Type;
622
+ tags?: TagsReflection;
623
+ }
624
+ /**
625
+ * Object literals or interfaces.
626
+ */
627
+ export interface TypeObjectLiteral extends TypeAnnotations {
628
+ kind: ReflectionKind.objectLiteral;
629
+ parent?: Type;
630
+ description?: string;
631
+ types: (TypeIndexSignature | TypePropertySignature | TypeMethodSignature | TypeCallSignature)[];
632
+ /**
633
+ * When the interface extends another interface/type, then those types are in this array.
634
+ *
635
+ * For example `interface A extends B<string, boolean> {}` then implements = [B<string, boolean>].
636
+ */
637
+ implements?: Type[];
638
+ tags?: TagsReflection;
639
+ }
640
+ export interface TypeIndexSignature extends TypeAnnotations {
641
+ kind: ReflectionKind.indexSignature;
642
+ parent: TypeClass | TypeObjectLiteral;
643
+ index: Type;
644
+ type: Type;
645
+ /**
646
+ * Set when the property has a default value aka initializer.
647
+ */
648
+ default?: (() => any) | any;
649
+ tags?: TagsReflection;
650
+ }
651
+ export interface TypeInfer extends TypeAnnotations {
652
+ kind: ReflectionKind.infer;
653
+ parent?: Type;
654
+ set(type: Type): void;
655
+ }
656
+ export interface TypeTupleMember extends TypeAnnotations {
657
+ kind: ReflectionKind.tupleMember;
658
+ parent: TypeTuple;
659
+ type: Type;
660
+ optional?: true;
661
+ name?: string;
662
+ }
663
+ export interface TypeTuple extends TypeAnnotations {
664
+ kind: ReflectionKind.tuple;
665
+ parent?: Type;
666
+ types: TypeTupleMember[];
667
+ }
668
+ export interface TypeRest extends TypeAnnotations {
669
+ kind: ReflectionKind.rest;
670
+ parent: TypeTypeParameter | TypeTupleMember;
671
+ type: Type;
672
+ }
673
+ /**
674
+ * @reflection never
675
+ */
676
+ export type Type = TypeNever | TypeAny | TypeUnknown | TypeVoid | TypeObject | TypeString | TypeNumber | TypeBoolean | TypeBigInt | TypeSymbol | TypeNull | TypeUndefined | TypeLiteral | TypeTemplateLiteral | TypeParameter | TypeFunction | TypeMethod | TypeProperty | TypePromise | TypeClass | TypeEnum | TypeEnumMember | TypeUnion | TypeIntersection | TypeArray | TypeObjectLiteral | TypeIndexSignature | TypePropertySignature | TypeMethodSignature | TypeTypeParameter | TypeInfer | TypeTuple | TypeTupleMember | TypeRest | TypeRegexp | TypeCallSignature;
677
+ export type Widen<T> = T extends string ? string : T extends number ? number : T extends bigint ? bigint : T extends boolean ? boolean : T extends symbol ? symbol : T;
678
+ export type FindType<T extends Type, LOOKUP extends ReflectionKind> = T extends {
679
+ kind: infer K;
680
+ } ? K extends LOOKUP ? T : never : never;
681
+ /**
682
+ * Merge dynamic runtime types with static types. In the type-system resolves as any, in runtime as the correct type.
683
+ *
684
+ * ```typescript
685
+ * const stringType = {kind: ReflectionKind.string};
686
+ * type t = {a: InlineRuntimeType<typeof stringType>}
687
+ *
688
+ * const value = 34;
689
+ * type t = {a: InlineRuntimeType<typeof value>}
690
+ * ```
691
+ */
692
+ export type InlineRuntimeType<T extends ReflectionClass<any> | Type | number | string | boolean | bigint> = T extends ReflectionClass<infer K> ? K : any;
693
+ export declare function isType(entry: any): entry is Type;
694
+ export declare function isBinary(type: Type): boolean;
695
+ export declare function isPrimitive<T extends Type>(type: T): boolean;
696
+ export declare function isPropertyType(type: Type): type is TypePropertySignature | TypeProperty;
697
+ /**
698
+ * Returns true if the type is TypePropertySignature | TypeProperty and not a static member.
699
+ */
700
+ export declare function isPropertyMemberType(type: Type): type is TypePropertySignature | TypeProperty;
701
+ /**
702
+ * Return all properties created in the constructor (via `constructor(public title: string)`)
703
+ *
704
+ * If a non-property parameter is in the constructor, the type is given instead, e.g. `constructor(public title: string, anotherOne:number)` => [TypeProperty, TypeNumber]
705
+ */
706
+ export declare function getConstructorProperties(type: TypeClass | TypeObjectLiteral): {
707
+ parameters: (TypeProperty | Type)[];
708
+ properties: TypeProperty[];
709
+ };
710
+ export type WithAnnotations = TypeAny | TypeUnknown | TypeString | TypeNumber | TypeBigInt | TypeBoolean | TypeArray | TypeTuple | TypeLiteral | TypeNull | TypeUndefined | TypeClass | TypeObjectLiteral | TypeObject | TypeTemplateLiteral | TypeRegexp | TypeSymbol;
711
+ export declare function isWithAnnotations(type: ParentLessType): type is WithAnnotations;
712
+ export declare function getAnnotations(type: WithAnnotations): Annotations;
713
+ type StackEntry = {
714
+ left: Type;
715
+ right: Type;
716
+ };
717
+ /**
718
+ * Checks if the structure of a and b are identical.
719
+ */
720
+ export declare function isSameType(a: Type, b: Type, stack?: StackEntry[]): boolean;
721
+ export declare function addType<T extends Type>(container: T, type: Type): T;
722
+ export declare function isTypeIncluded(types: Type[], type: Type, stack?: StackEntry[]): boolean;
723
+ /**
724
+ * `true | (string | number)` => `true | string | number`
725
+ */
726
+ export declare function flatten<T extends Type>(type: T): T;
727
+ /**
728
+ * Flatten nested union types.
729
+ */
730
+ export declare function flattenUnionTypes(types: Type[]): Type[];
731
+ /**
732
+ * empty union => never
733
+ * union with one member => member
734
+ * otherwise the union is returned
735
+ */
736
+ export declare function unboxUnion(union: TypeUnion): Type;
737
+ export declare function findMember(index: string | number | symbol | TypeTemplateLiteral, types: Type[]): TypePropertySignature | TypeMethodSignature | TypeMethod | TypeProperty | TypeIndexSignature | undefined;
738
+ interface CStack {
739
+ iterator: Type[];
740
+ i: number;
741
+ round: number;
742
+ }
743
+ export declare function emptyObject(type: Type): boolean;
744
+ export declare class CartesianProduct {
745
+ protected stack: CStack[];
746
+ private current;
747
+ private next;
748
+ toGroup(type: Type): Type[];
749
+ add(item: Type): void;
750
+ calculate(): Type[][];
751
+ }
752
+ /**
753
+ * Query a container type and return the result.
754
+ *
755
+ * container[index]
756
+ *
757
+ * e.g. {a: string}['a'] => string
758
+ * e.g. {a: string, b: number}[keyof T] => string | number
759
+ * e.g. [string, number][0] => string
760
+ * e.g. [string, number][number] => string | number
761
+ */
762
+ export declare function indexAccess(container: Type, index: Type): Type;
763
+ export declare function merge(types: (TypeObjectLiteral | TypeClass)[]): TypeObjectLiteral;
764
+ export declare function narrowOriginalLiteral(type: Type): Type;
765
+ type GetArrayElement<T extends any[]> = [
766
+ T
767
+ ] extends [
768
+ Array<infer K>
769
+ ] ? K : never;
770
+ type RemoveParent<T, K extends keyof T> = {
771
+ [P in K]: T[P] extends Type[] ? RemoveParentHomomorphic<GetArrayElement<T[P]>>[] : T[P] extends Type ? RemoveParentHomomorphic<T[P]> : T[P];
772
+ };
773
+ type RemoveParentHomomorphic<T> = RemoveParent<T, Exclude<keyof T, "parent">>;
774
+ type RemoveDeepParent<T extends Type> = T extends infer K ? RemoveParentHomomorphic<K> : never;
775
+ export type ParentLessType = RemoveDeepParent<Type>;
776
+ /**
777
+ * This function does not do a deep copy, only shallow. A deep copy makes it way to inefficient, so much that router.spec.ts takes up to 20-30seconds
778
+ * to complete instead of barely 30ms.
779
+ */
780
+ export declare function copyAndSetParent<T extends ParentLessType>(inc: T, parent?: Type): FindType<Type, T["kind"]>;
781
+ export declare function widenLiteral(type: Type): Type;
782
+ export declare function assertType<K extends ReflectionKind, T>(t: Type | undefined, kind: K): asserts t is FindType<Type, K>;
783
+ export declare function getClassType(type: Type): ClassType;
784
+ export declare function isMember(type: Type): type is TypePropertySignature | TypeProperty | TypeMethodSignature | TypeMethod;
785
+ export declare function hasMember(type: TypeObjectLiteral | TypeClass, memberName: number | string | symbol, memberType?: Type): boolean;
786
+ export declare function getMember(type: TypeObjectLiteral | TypeClass, memberName: number | string | symbol): TypeMethodSignature | TypeMethod | TypePropertySignature | TypeProperty | void;
787
+ export declare function getTypeObjectLiteralFromTypeClass<T extends Type>(type: T): T extends TypeClass ? TypeObjectLiteral : T;
788
+ /**
789
+ * Checks whether `undefined` is allowed as type.
790
+ */
791
+ export declare function isOptional(type: Type): boolean;
792
+ /**
793
+ * Whether a property has an initializer/default value.
794
+ */
795
+ export declare function hasDefaultValue(type: Type): boolean;
796
+ /**
797
+ * Checks whether `null` is allowed as type.
798
+ */
799
+ export declare function isNullable(type: Type): boolean;
800
+ /**
801
+ * Get tags from type.
802
+ */
803
+ export declare function getTags(type: Type): TagsReflection;
804
+ /**
805
+ * Checks whether the \`hidden\` tag was specified for the type.
806
+ */
807
+ export declare function isHidden(type: Type): boolean;
808
+ /**
809
+ * Checks whether the \`ignore\` tag was specified for the type.
810
+ */
811
+ export declare function isIgnore(type: Type): boolean;
812
+ /**
813
+ * Checks whether the \`internal\` tag was specified for the type.
814
+ */
815
+ export declare function isInternal(type: Type): boolean;
816
+ /**
817
+ * Returns the values specified by the type's \`alias\` tag(s).
818
+ */
819
+ export declare function getAlias(type: Type): string[];
820
+ /**
821
+ * Checks whether the \`readonly\` tag was specified for the type.
822
+ */
823
+ export declare function isReadonly(type: Type): boolean;
824
+ /**
825
+ * Returns the values specified by the type's \`title\` tag.
826
+ */
827
+ export declare function getTitle(type: Type): string | undefined;
828
+ /**
829
+ * Returns the values specified by the type's \`permission\` tag(s).
830
+ */
831
+ export declare function getPermission(type: Type): string[];
832
+ /**
833
+ * Returns the values specified by the type's \`domain\` tag.
834
+ */
835
+ export declare function getDomain(type: Type): string | undefined;
836
+ /**
837
+ * Integer
838
+ */
839
+ export type integer = number;
840
+ /**
841
+ * Integer 8 bit.
842
+ * Min value -127, max value 128
843
+ */
844
+ export type int8 = number;
845
+ /**
846
+ * Unsigned integer 8 bit.
847
+ * Min value 0, max value 255
848
+ */
849
+ export type uint8 = number;
850
+ /**
851
+ * Integer 16 bit.
852
+ * Min value -32768, max value 32767
853
+ */
854
+ export type int16 = number;
855
+ /**
856
+ * Unsigned integer 16 bit.
857
+ * Min value 0, max value 65535
858
+ */
859
+ export type uint16 = number;
860
+ /**
861
+ * Integer 8 bit.
862
+ * Min value -2147483648, max value 2147483647
863
+ */
864
+ export type int32 = number;
865
+ /**
866
+ * Unsigned integer 32 bit.
867
+ * Min value 0, max value 4294967295
868
+ */
869
+ export type uint32 = number;
870
+ /**
871
+ * Float (same as number, but different semantic for databases).
872
+ */
873
+ export type float = number;
874
+ /**
875
+ * Float 32 bit.
876
+ */
877
+ export type float32 = number;
878
+ /**
879
+ * Float 64 bit.
880
+ */
881
+ export type float64 = number;
882
+ export declare class AnnotationDefinition<T = true> {
883
+ readonly id: string;
884
+ symbol: symbol;
885
+ constructor(id: string);
886
+ register(annotations: Annotations, data: T): void;
887
+ reset(annotations: Annotations): void;
888
+ registerType<TType extends Type>(type: TType, data: T): TType;
889
+ replace(annotations: Annotations, annotation: T[]): void;
890
+ replaceType(type: Type, annotation: T[]): void;
891
+ getAnnotations(type: Type): T[];
892
+ getFirst(type: Type): T | undefined;
893
+ hasAnnotations(type: Type): boolean;
894
+ }
895
+ export type AnnotationType<T extends AnnotationDefinition<any>> = T extends AnnotationDefinition<infer K> ? K : never;
896
+ export type ReferenceActions = "RESTRICT" | "NO ACTION" | "CASCADE" | "SET NULL" | "SET DEFAULT";
897
+ export interface ReferenceOptions {
898
+ /**
899
+ * Default is CASCADE.
900
+ */
901
+ onDelete?: ReferenceActions;
902
+ /**
903
+ * Default is CASCADE.
904
+ */
905
+ onUpdate?: ReferenceActions;
906
+ }
907
+ /**
908
+ * note: if this is adjusted, make sure to adjust ReflectionClass, entityAnnotation, and type serializer accordingly.
909
+ */
910
+ export interface EntityOptions {
911
+ name?: string;
912
+ description?: string;
913
+ collection?: string;
914
+ database?: string;
915
+ singleTableInheritance?: boolean;
916
+ indexes?: {
917
+ names: string[];
918
+ options: IndexOptions;
919
+ }[];
920
+ }
921
+ /**
922
+ * Type to decorate an interface/object literal with entity information.
923
+ *
924
+ * ```typescript
925
+ * interface User extends Entity<{name: 'user'}> {
926
+ * id: number & PrimaryKey & AutoIncrement;
927
+ * username: string & Unique;
928
+ * }
929
+ * ```
930
+ */
931
+ export type Entity<T extends EntityOptions> = {} & TypeAnnotation<"entity", T>;
932
+ /**
933
+ * Marks a property as primary key.
934
+ * ```typescript
935
+ * class Entity {
936
+ * id: number & Primary = 0;
937
+ * }
938
+ * ```
939
+ */
940
+ export type PrimaryKey = TypeAnnotation<"primaryKey">;
941
+ type TypeKeyOf<T> = T[keyof T];
942
+ export type PrimaryKeyFields<T> = any extends T ? any : {
943
+ [P in keyof T]: Required<T[P]> extends Required<PrimaryKey> ? T[P] : never;
944
+ };
945
+ export type PrimaryKeyType<T> = any extends T ? any : TypeKeyOf<PrimaryKeyFields<T>>;
946
+ export type ReferenceFields<T> = {
947
+ [P in keyof T]: Required<T[P]> extends Required<Reference> | Required<BackReference> ? T[P] : never;
948
+ };
949
+ /**
950
+ * Marks a primary property key as auto-increment.
951
+ *
952
+ * ```typescript
953
+ * class Entity {
954
+ * id: number & Primary & AutoIncrement = 0;
955
+ * }
956
+ * ```
957
+ */
958
+ export type AutoIncrement = TypeAnnotation<"autoIncrement">;
959
+ /**
960
+ * UUID v4, as string, serialized as string in JSON, and binary in database.
961
+ * Use `uuid()` as handy initializer.
962
+ *
963
+ * ```typescript
964
+ * class Entity {
965
+ * id: UUID = uuid();
966
+ * }
967
+ * ```
968
+ */
969
+ export type UUID = string & TypeAnnotation<"UUIDv4">;
970
+ /**
971
+ * MongoDB's ObjectID type. serialized as string in JSON, ObjectID in database.
972
+ */
973
+ export type MongoId = string & TypeAnnotation<"mongoId">;
974
+ /**
975
+ * Same as `bigint` but serializes to unsigned binary with unlimited size (instead of 8 bytes in most databases).
976
+ * Negative values will be converted to positive (abs(x)).
977
+ *
978
+ * ```typescript
979
+ * class Entity {
980
+ * id: BinaryBigInt = 0n;
981
+ * }
982
+ * ```
983
+ */
984
+ export type BinaryBigInt = bigint & TypeAnnotation<"binaryBigInt">;
985
+ /**
986
+ * Same as `bigint` but serializes to signed binary with unlimited size (instead of 8 bytes in most databases).
987
+ * The binary has an additional leading sign byte and is represented as an uint: 255 for negative, 0 for zero, or 1 for positive.
988
+ *
989
+ * ```typescript
990
+ * class Entity {
991
+ * id: SignedBinaryBigInt = 0n;
992
+ * }
993
+ * ```
994
+ */
995
+ export type SignedBinaryBigInt = bigint & TypeAnnotation<"signedBinaryBigInt">;
996
+ export interface BackReferenceOptions {
997
+ /**
998
+ * Necessary for normalised many-to-many relations. This defines the class of the pivot table/collection.
999
+ */
1000
+ via?: ClassType | {};
1001
+ /**
1002
+ * A reference/backReference can define which reference on the other side
1003
+ * reference back. This is necessary when there are multiple outgoing references
1004
+ * to the same entity.
1005
+ */
1006
+ mappedBy?: string;
1007
+ }
1008
+ export type Reference<Options extends ReferenceOptions = {}> = TypeAnnotation<"reference", Options>;
1009
+ export type BackReference<Options extends BackReferenceOptions = {}> = TypeAnnotation<"backReference", Options>;
1010
+ export type EmbeddedMeta<Options> = TypeAnnotation<"embedded", Options>;
1011
+ export type Embedded<T, Options extends {
1012
+ prefix?: string;
1013
+ } = {}> = T & EmbeddedMeta<Options>;
1014
+ export type MapName<Alias extends string, ForSerializer extends string = ""> = TypeAnnotation<"mapName", [
1015
+ Alias,
1016
+ ForSerializer
1017
+ ]>;
1018
+ export declare const referenceAnnotation: AnnotationDefinition<ReferenceOptions>;
1019
+ export declare const entityAnnotation: {
1020
+ set<K extends keyof EntityOptions>(type: Type, name: K, value: EntityOptions[K]): void;
1021
+ get(type: Type): EntityOptions;
1022
+ symbol: symbol;
1023
+ readonly id: string;
1024
+ register(annotations: Annotations, data: EntityOptions): void;
1025
+ reset(annotations: Annotations): void;
1026
+ registerType<TType extends Type>(type: TType, data: EntityOptions): TType;
1027
+ replace(annotations: Annotations, annotation: EntityOptions[]): void;
1028
+ replaceType(type: Type, annotation: EntityOptions[]): void;
1029
+ getAnnotations(type: Type): EntityOptions[];
1030
+ getFirst(type: Type): EntityOptions | undefined;
1031
+ hasAnnotations(type: Type): boolean;
1032
+ };
1033
+ export declare const mapNameAnnotation: AnnotationDefinition<{
1034
+ name: string;
1035
+ serializer?: string;
1036
+ }>;
1037
+ export declare const autoIncrementAnnotation: AnnotationDefinition<true>;
1038
+ export declare const primaryKeyAnnotation: {
1039
+ isPrimaryKey(type: Type): boolean;
1040
+ symbol: symbol;
1041
+ readonly id: string;
1042
+ register(annotations: Annotations, data: true): void;
1043
+ reset(annotations: Annotations): void;
1044
+ registerType<TType extends Type>(type: TType, data: true): TType;
1045
+ replace(annotations: Annotations, annotation: true[]): void;
1046
+ replaceType(type: Type, annotation: true[]): void;
1047
+ getAnnotations(type: Type): true[];
1048
+ getFirst(type: Type): true | undefined;
1049
+ hasAnnotations(type: Type): boolean;
1050
+ };
1051
+ export interface BackReferenceOptionsResolved {
1052
+ /**
1053
+ * Necessary for normalised many-to-many relations. This defines the class of the pivot table/collection.
1054
+ */
1055
+ via?: TypeClass | TypeObjectLiteral;
1056
+ /**
1057
+ * A reference/backReference can define which reference on the other side
1058
+ * reference back. This is necessary when there are multiple outgoing references
1059
+ * to the same entity.
1060
+ */
1061
+ mappedBy?: string;
1062
+ }
1063
+ export declare const backReferenceAnnotation: AnnotationDefinition<BackReferenceOptionsResolved>;
1064
+ export declare const validationAnnotation: AnnotationDefinition<{
1065
+ name: string;
1066
+ args: Type[];
1067
+ }>;
1068
+ export declare const UUIDAnnotation: AnnotationDefinition<true>;
1069
+ export declare const mongoIdAnnotation: AnnotationDefinition<true>;
1070
+ export declare const uuidAnnotation: AnnotationDefinition<true>;
1071
+ export declare const defaultAnnotation: AnnotationDefinition<Type>;
1072
+ export declare function isUUIDType(type: Type): boolean;
1073
+ export declare function isPrimaryKeyType(type: Type): boolean;
1074
+ export declare function isAutoIncrementType(type: Type): boolean;
1075
+ export declare function isMongoIdType(type: Type): boolean;
1076
+ export declare function isBinaryBigIntType(type: Type): boolean;
1077
+ export declare function isReferenceType(type: Type): boolean;
1078
+ export declare function getReferenceType(type: Type): ReferenceOptions | undefined;
1079
+ export declare function isBackReferenceType(type: Type): boolean;
1080
+ export declare function resolveProperty(type: Type): Type;
1081
+ export declare function getBackReferenceType(type: Type): BackReferenceOptionsResolved;
1082
+ export declare function isDateType(type: Type): boolean;
1083
+ export declare function isSetType(type: Type): boolean;
1084
+ export declare function isMapType(type: Type): boolean;
1085
+ /**
1086
+ * Get the key type of a Map or object literal with index signatures.
1087
+ */
1088
+ export declare function getKeyType(type: Type): Type;
1089
+ /**
1090
+ * Get the value type of a Map or object literal with index signatures.
1091
+ */
1092
+ export declare function getValueType(type: Type): Type;
1093
+ export interface EmbeddedOptions {
1094
+ prefix?: string;
1095
+ }
1096
+ export declare const embeddedAnnotation: AnnotationDefinition<EmbeddedOptions>;
1097
+ export declare function hasEmbedded(type: Type): boolean;
1098
+ /**
1099
+ * Assigns one or multiple groups to a type.
1100
+ *
1101
+ * @example
1102
+ * ```typescript
1103
+ * interface User {
1104
+ * username: string;
1105
+ * password: string & Group<'credentials'>;
1106
+ * }
1107
+ * ```
1108
+ */
1109
+ export type Group<Name extends string> = TypeAnnotation<"group", Name>;
1110
+ /**
1111
+ * Excludes the type from serialization of all kind.
1112
+ *
1113
+ * @example
1114
+ * ```typescript
1115
+ * interface User {
1116
+ * username: string;
1117
+ * password: string & Excluded;
1118
+ * }
1119
+ * ```
1120
+ */
1121
+ export type Excluded<Name extends string = "*"> = TypeAnnotation<"excluded", Name>;
1122
+ /**
1123
+ * Assigns arbitrary data to a type that can be read in runtime.
1124
+ *
1125
+ * @example
1126
+ * ```typescript
1127
+ * interface User {
1128
+ * username: string;
1129
+ * password: string & Data<'role', 'admin'>;
1130
+ * }
1131
+ * ```
1132
+ */
1133
+ export type Data<Name extends string, Value> = TypeAnnotation<"data", [
1134
+ Name,
1135
+ Value
1136
+ ]>;
1137
+ /**
1138
+ * Resets an already set decorator to undefined.
1139
+ *
1140
+ * The required Name is the name of the type decorator (its first tuple entry).
1141
+ *
1142
+ * ```typescript
1143
+ * type Password = string & MinLength<6> & Excluded;
1144
+ *
1145
+ * interface UserCreationPayload {
1146
+ * password: Password & ResetAnnotation<'excluded'>
1147
+ * }
1148
+ * ```
1149
+ */
1150
+ export type ResetAnnotation<Name extends string> = TypeAnnotation<"reset", Name>;
1151
+ export type IndexOptions = {
1152
+ name?: string;
1153
+ size?: number;
1154
+ unique?: boolean;
1155
+ spatial?: boolean;
1156
+ sparse?: boolean;
1157
+ fulltext?: boolean;
1158
+ where?: string;
1159
+ expireAfterSeconds?: number;
1160
+ };
1161
+ export type Unique<Options extends IndexOptions = {}> = TypeAnnotation<"index", Options & {
1162
+ unique: true;
1163
+ }>;
1164
+ export type Index<Options extends IndexOptions = {}> = TypeAnnotation<"index", Options>;
1165
+ export interface DatabaseFieldOptions {
1166
+ /**
1167
+ * The name of the column in the database.
1168
+ * e.g. `userName: string & DatabaseField<{name: 'user_name'}>`
1169
+ *
1170
+ * Can alternatively also be configured by using a different NamingStrategy.
1171
+ */
1172
+ name?: string;
1173
+ /**
1174
+ *
1175
+ * e.g. `field: string & MySQL<{type: 'VARCHAR(255)'}>`
1176
+ */
1177
+ type?: string;
1178
+ /**
1179
+ * If the property is on a class, its initializer/default value is per default used.
1180
+ * This can be overridden using this option.
1181
+ * e.g. `field: string & MySQL<{default: 'abc'}>`
1182
+ */
1183
+ default?: any;
1184
+ /**
1185
+ * e.g. `field: string & MySQL<{defaultExpr: 'NOW()'}>`
1186
+ */
1187
+ defaultExpr?: any;
1188
+ /**
1189
+ * If true no default column value is inferred from the property initializer/default value.
1190
+ * e.g. `field: string & MySQL<{noDefault: true}> = ''`
1191
+ */
1192
+ noDefault?: true;
1193
+ /**
1194
+ * Skip this property in all queries and database migration files.
1195
+ */
1196
+ skip?: true;
1197
+ /**
1198
+ * Skip this property in database migration files. This excludes the property from the database, but
1199
+ * keeps it in the queries.
1200
+ */
1201
+ skipMigration?: true;
1202
+ }
1203
+ export interface MySQLOptions extends DatabaseFieldOptions {
1204
+ }
1205
+ export interface PostgresOptions extends DatabaseFieldOptions {
1206
+ }
1207
+ export interface SqliteOptions extends DatabaseFieldOptions {
1208
+ }
1209
+ type Database<Name extends string, Options extends {
1210
+ [name: string]: any;
1211
+ }> = TypeAnnotation<"database", [
1212
+ Name,
1213
+ Options
1214
+ ]>;
1215
+ export type MySQL<Options extends MySQLOptions> = Database<"mysql", Options>;
1216
+ export type Postgres<Options extends PostgresOptions> = Database<"postgres", Options>;
1217
+ export type SQLite<Options extends SqliteOptions> = Database<"sqlite", Options>;
1218
+ export type DatabaseField<Options extends DatabaseFieldOptions, Name extends string = "*"> = Database<Name, Options>;
1219
+ export declare const enum BinaryBigIntType {
1220
+ unsigned = 0,
1221
+ signed = 1
1222
+ }
1223
+ export declare const binaryBigIntAnnotation: AnnotationDefinition<BinaryBigIntType>;
1224
+ export declare const groupAnnotation: AnnotationDefinition<string>;
1225
+ export declare const excludedAnnotation: {
1226
+ isExcluded(type: Type, name: string): boolean;
1227
+ symbol: symbol;
1228
+ readonly id: string;
1229
+ register(annotations: Annotations, data: string): void;
1230
+ reset(annotations: Annotations): void;
1231
+ registerType<TType extends Type>(type: TType, data: string): TType;
1232
+ replace(annotations: Annotations, annotation: string[]): void;
1233
+ replaceType(type: Type, annotation: string[]): void;
1234
+ getAnnotations(type: Type): string[];
1235
+ getFirst(type: Type): string | undefined;
1236
+ hasAnnotations(type: Type): boolean;
1237
+ };
1238
+ export declare const dataAnnotation: {
1239
+ set<T extends Type>(type: T, key: string, value: any): T;
1240
+ get(type: Type, key: string): any;
1241
+ symbol: symbol;
1242
+ readonly id: string;
1243
+ register(annotations: Annotations, data: {
1244
+ [name: string]: any;
1245
+ }): void;
1246
+ reset(annotations: Annotations): void;
1247
+ registerType<TType extends Type>(type: TType, data: {
1248
+ [name: string]: any;
1249
+ }): TType;
1250
+ replace(annotations: Annotations, annotation: {
1251
+ [name: string]: any;
1252
+ }[]): void;
1253
+ replaceType(type: Type, annotation: {
1254
+ [name: string]: any;
1255
+ }[]): void;
1256
+ getAnnotations(type: Type): {
1257
+ [name: string]: any;
1258
+ }[];
1259
+ getFirst(type: Type): {
1260
+ [name: string]: any;
1261
+ } | undefined;
1262
+ hasAnnotations(type: Type): boolean;
1263
+ };
1264
+ /**
1265
+ * All raw data from `TypeAnnotation<Name, Options>` types.
1266
+ */
1267
+ export declare const typeAnnotation: {
1268
+ /**
1269
+ * Returns the parsed Type to JS objects, e.g. `{name: string}` => `{name: 'xy'}`
1270
+ */
1271
+ getOption(type: Type, name: string): any;
1272
+ /**
1273
+ * Returns the Type object of the annotation which can be parsed with `typeToObject`.
1274
+ */
1275
+ getType(type: Type, name: string): Type | undefined;
1276
+ symbol: symbol;
1277
+ readonly id: string;
1278
+ register(annotations: Annotations, data: {
1279
+ name: string;
1280
+ options: Type;
1281
+ }): void;
1282
+ reset(annotations: Annotations): void;
1283
+ registerType<TType extends Type>(type: TType, data: {
1284
+ name: string;
1285
+ options: Type;
1286
+ }): TType;
1287
+ replace(annotations: Annotations, annotation: {
1288
+ name: string;
1289
+ options: Type;
1290
+ }[]): void;
1291
+ replaceType(type: Type, annotation: {
1292
+ name: string;
1293
+ options: Type;
1294
+ }[]): void;
1295
+ getAnnotations(type: Type): {
1296
+ name: string;
1297
+ options: Type;
1298
+ }[];
1299
+ getFirst(type: Type): {
1300
+ name: string;
1301
+ options: Type;
1302
+ } | undefined;
1303
+ hasAnnotations(type: Type): boolean;
1304
+ };
1305
+ export declare const indexAnnotation: AnnotationDefinition<IndexOptions>;
1306
+ export declare const databaseAnnotation: {
1307
+ getDatabase<T extends DatabaseFieldOptions>(type: Type, name: string): T | undefined;
1308
+ symbol: symbol;
1309
+ readonly id: string;
1310
+ register(annotations: Annotations, data: {
1311
+ name: string;
1312
+ options: {
1313
+ [name: string]: any;
1314
+ };
1315
+ }): void;
1316
+ reset(annotations: Annotations): void;
1317
+ registerType<TType extends Type>(type: TType, data: {
1318
+ name: string;
1319
+ options: {
1320
+ [name: string]: any;
1321
+ };
1322
+ }): TType;
1323
+ replace(annotations: Annotations, annotation: {
1324
+ name: string;
1325
+ options: {
1326
+ [name: string]: any;
1327
+ };
1328
+ }[]): void;
1329
+ replaceType(type: Type, annotation: {
1330
+ name: string;
1331
+ options: {
1332
+ [name: string]: any;
1333
+ };
1334
+ }[]): void;
1335
+ getAnnotations(type: Type): {
1336
+ name: string;
1337
+ options: {
1338
+ [name: string]: any;
1339
+ };
1340
+ }[];
1341
+ getFirst(type: Type): {
1342
+ name: string;
1343
+ options: {
1344
+ [name: string]: any;
1345
+ };
1346
+ } | undefined;
1347
+ hasAnnotations(type: Type): boolean;
1348
+ };
1349
+ export declare function registerTypeDecorator(decorator: TypeDecorator): void;
1350
+ /**
1351
+ * Type annotations are object literals with a single optional __meta in it
1352
+ * that has as type a tuple with the name of the annotation as first entry.
1353
+ * The tuple is intersected with the `never` type to make sure it does not
1354
+ * interfere with type checking.
1355
+ *
1356
+ * The processor has currently implemented to not resolve `never & x` to `never`,
1357
+ * so we still have the intersection type in runtime to resolve __meta correctly.
1358
+ *
1359
+ * ```typescript
1360
+ * type MyAnnotation1 = TypeAnnotation<'myAnnotation'>
1361
+ * type MyAnnotation1<T> = TypeAnnotation<'myAnnotation', T>
1362
+ *
1363
+ * //under the hood it is:
1364
+ * type lowLevel1 = { __meta?: never & ['myAnnotation'] }
1365
+ * type lowLevel2<T> = { __meta?: never & ['myAnnotation', T] }
1366
+ * ```
1367
+ */
1368
+ export declare function getAnnotationMeta(type: TypeObjectLiteral): {
1369
+ id: string;
1370
+ options: Type;
1371
+ } | undefined;
1372
+ export declare const typeDecorators: TypeDecorator[];
1373
+ export declare function typeToObject(type?: Type, state?: {
1374
+ stack: Type[];
1375
+ }): any;
1376
+ export declare function memberNameToString(name: number | string | symbol): string;
1377
+ export declare const binaryTypes: ClassType[];
1378
+ /**
1379
+ * Returns true if the given type is Date, ArrayBuffer, Uint8Array, etc.
1380
+ */
1381
+ export declare function isGlobalTypeClass(type: Type): type is TypeClass;
1382
+ /**
1383
+ * Returns true if the given type is TypeClass and references a custom (non-global) class.
1384
+ */
1385
+ export declare function isCustomTypeClass(type: Type): type is TypeClass;
1386
+ /**
1387
+ * Returns a type predicate that checks if the given type is a class and is of the given classType.
1388
+ * If withInheritance is true, it also checks if the type is a subclass of the given classType.
1389
+ */
1390
+ export declare function isTypeClassOf(classType: ClassType, withInheritance?: boolean): (type: Type) => boolean;
1391
+ /**
1392
+ * Returns the members of a class or object literal.
1393
+ */
1394
+ export declare function resolveTypeMembers(type: TypeClass | TypeObjectLiteral): (TypeProperty | TypePropertySignature | TypeMethodSignature | TypeMethod | TypeIndexSignature | TypeCallSignature)[];
1395
+ export declare function stringifyResolvedType(type: Type): string;
1396
+ export declare function stringifyShortResolvedType(type: Type, stateIn?: Partial<StringifyTypeOptions>): string;
1397
+ /**
1398
+ * Returns all (including inherited) constructor properties of a class.
1399
+ */
1400
+ export declare function getDeepConstructorProperties(type: TypeClass): TypeParameter[];
1401
+ /**
1402
+ * Returns the index to `type.values` if the given value is part of the enum, exactly or case-insensitive.
1403
+ * Returns -1 if not found.
1404
+ */
1405
+ export declare function getEnumValueIndexMatcher(type: TypeEnum): (value: string | number | undefined | null) => number;
1406
+ interface StringifyTypeOptions {
1407
+ showNames: boolean;
1408
+ showFullDefinition: boolean;
1409
+ showDescription: boolean;
1410
+ defaultIsOptional: boolean;
1411
+ showHeritage: boolean;
1412
+ showDefaults: boolean;
1413
+ showTags: boolean;
1414
+ defaultValues: any;
1415
+ stringify?: (type: Type) => string | undefined;
1416
+ }
1417
+ export declare function stringifyType(type: Type, stateIn?: Partial<StringifyTypeOptions>): string;
1418
+ export declare function annotateClass<T>(clazz: ClassType | AbstractClassType, type?: ReceiveType<T>): void;
1419
+ export declare type __ΩReflectionVisibility = any[];
1420
+ export declare type __ΩReflectionKind = any[];
1421
+ export declare type __ΩTypeDecorator = any[];
1422
+ export declare type __ΩAnnotations = any[];
1423
+ export declare type __ΩJitContainer = any[];
1424
+ export declare type __ΩTagsReflection = any[];
1425
+ export declare type __ΩTypeNever = any[];
1426
+ export declare type __ΩTypeAny = any[];
1427
+ export declare type __ΩTypeUnknown = any[];
1428
+ export declare type __ΩTypeVoid = any[];
1429
+ export declare type __ΩTypeObject = any[];
1430
+ export declare type __ΩTypeString = any[];
1431
+ export declare type __ΩTypeNumber = any[];
1432
+ export declare type __ΩTypeBoolean = any[];
1433
+ export declare type __ΩTypeBigInt = any[];
1434
+ export declare type __ΩTypeSymbol = any[];
1435
+ export declare type __ΩTypeNull = any[];
1436
+ export declare type __ΩTypeUndefined = any[];
1437
+ export declare type __ΩTypeLiteral = any[];
1438
+ export declare type __ΩTypeTemplateLiteral = any[];
1439
+ export declare type __ΩTypeRegexp = any[];
1440
+ export declare type __ΩTypeBaseMember = any[];
1441
+ export declare type __ΩTypeParameter = any[];
1442
+ export declare type __ΩTypeMethod = any[];
1443
+ export declare type __ΩTypeProperty = any[];
1444
+ export declare type __ΩTypeFunction = any[];
1445
+ export declare type __ΩTypeCallSignature = any[];
1446
+ export declare type __ΩTypePromise = any[];
1447
+ export declare type __ΩTypeClass = any[];
1448
+ export declare type __ΩTypeEnum = any[];
1449
+ export declare type __ΩTypeEnumMember = any[];
1450
+ export declare type __ΩTypeTypeParameter = any[];
1451
+ export declare type __ΩTypeUnion = any[];
1452
+ export declare type __ΩTypeIntersection = any[];
1453
+ export declare type __ΩTypeArray = any[];
1454
+ export declare type __ΩTypePropertySignature = any[];
1455
+ export declare type __ΩTypeMethodSignature = any[];
1456
+ export declare type __ΩTypeObjectLiteral = any[];
1457
+ export declare type __ΩTypeIndexSignature = any[];
1458
+ export declare type __ΩTypeInfer = any[];
1459
+ export declare type __ΩTypeTupleMember = any[];
1460
+ export declare type __ΩTypeTuple = any[];
1461
+ export declare type __ΩTypeRest = any[];
1462
+ export declare type __ΩWiden = any[];
1463
+ export declare type __ΩFindType = any[];
1464
+ export declare type __ΩInlineRuntimeType = any[];
1465
+ export declare type __ΩWithAnnotations = any[];
1466
+ export declare type __ΩParentLessType = any[];
1467
+ export declare type __Ωinteger = any[];
1468
+ export declare type __Ωint8 = any[];
1469
+ export declare type __Ωuint8 = any[];
1470
+ export declare type __Ωint16 = any[];
1471
+ export declare type __Ωuint16 = any[];
1472
+ export declare type __Ωint32 = any[];
1473
+ export declare type __Ωuint32 = any[];
1474
+ export declare type __Ωfloat = any[];
1475
+ export declare type __Ωfloat32 = any[];
1476
+ export declare type __Ωfloat64 = any[];
1477
+ export declare type __ΩAnnotationType = any[];
1478
+ export declare type __ΩReferenceActions = any[];
1479
+ export declare type __ΩReferenceOptions = any[];
1480
+ export declare type __ΩEntityOptions = any[];
1481
+ export declare type __ΩEntity = any[];
1482
+ export declare type __ΩPrimaryKey = any[];
1483
+ export declare type __ΩPrimaryKeyFields = any[];
1484
+ export declare type __ΩPrimaryKeyType = any[];
1485
+ export declare type __ΩReferenceFields = any[];
1486
+ export declare type __ΩAutoIncrement = any[];
1487
+ export declare type __ΩUUID = any[];
1488
+ export declare type __ΩMongoId = any[];
1489
+ export declare type __ΩBinaryBigInt = any[];
1490
+ export declare type __ΩSignedBinaryBigInt = any[];
1491
+ export declare type __ΩBackReferenceOptions = any[];
1492
+ export declare type __ΩReference = any[];
1493
+ export declare type __ΩBackReference = any[];
1494
+ export declare type __ΩEmbeddedMeta = any[];
1495
+ export declare type __ΩEmbedded = any[];
1496
+ export declare type __ΩMapName = any[];
1497
+ export declare type __ΩBackReferenceOptionsResolved = any[];
1498
+ export declare type __ΩEmbeddedOptions = any[];
1499
+ export declare type __ΩGroup = any[];
1500
+ export declare type __ΩExcluded = any[];
1501
+ export declare type __ΩData = any[];
1502
+ export declare type __ΩResetAnnotation = any[];
1503
+ export declare type __ΩIndexOptions = any[];
1504
+ export declare type __ΩUnique = any[];
1505
+ export declare type __ΩIndex = any[];
1506
+ export declare type __ΩDatabaseFieldOptions = any[];
1507
+ export declare type __ΩMySQLOptions = any[];
1508
+ export declare type __ΩPostgresOptions = any[];
1509
+ export declare type __ΩSqliteOptions = any[];
1510
+ export declare type __ΩMySQL = any[];
1511
+ export declare type __ΩPostgres = any[];
1512
+ export declare type __ΩSQLite = any[];
1513
+ export declare type __ΩDatabaseField = any[];
1514
+ export declare type __ΩBinaryBigIntType = any[];
1515
+ export interface SerializedTypeAnnotations {
1516
+ entityOptions?: EntityOptions;
1517
+ typeName?: string;
1518
+ typeArguments?: SerializedTypeReference[];
1519
+ indexAccessOrigin?: {
1520
+ container: SerializedTypeReference;
1521
+ index: SerializedTypeReference;
1522
+ };
1523
+ decorators?: SerializedTypeReference[];
1524
+ }
1525
+ export interface SerializedTypeObjectLiteral extends SerializedTypeAnnotations {
1526
+ kind: ReflectionKind.objectLiteral;
1527
+ types: SerializedTypeReference[];
1528
+ tags?: TagsReflection;
1529
+ }
1530
+ export interface SerializedTypeClassType extends SerializedTypeAnnotations {
1531
+ kind: ReflectionKind.class;
1532
+ name?: string;
1533
+ globalObject?: true;
1534
+ classType: string;
1535
+ extendsArguments?: SerializedTypeReference[];
1536
+ arguments?: SerializedTypeReference[];
1537
+ superClass?: SerializedTypeReference;
1538
+ types: SerializedTypeReference[];
1539
+ tags?: TagsReflection;
1540
+ }
1541
+ export interface SerializedTypeFunction extends SerializedTypeAnnotations {
1542
+ kind: ReflectionKind.function;
1543
+ name?: number | string | symbol;
1544
+ parameters: SerializedTypeParameter[];
1545
+ return: SerializedTypeReference;
1546
+ tags?: TagsReflection;
1547
+ }
1548
+ export type SerializedTypeReference = number;
1549
+ export interface SimpleSerializedType extends SerializedTypeAnnotations {
1550
+ kind: ReflectionKind.never | ReflectionKind.any | ReflectionKind.unknown | ReflectionKind.void | ReflectionKind.object | ReflectionKind.string | ReflectionKind.number | ReflectionKind.boolean | ReflectionKind.symbol | ReflectionKind.bigint | ReflectionKind.null | ReflectionKind.undefined | ReflectionKind.regexp;
1551
+ origin?: SerializedTypeReference;
1552
+ }
1553
+ export interface SerializedTypeLiteral extends SerializedTypeAnnotations {
1554
+ kind: ReflectionKind.literal;
1555
+ literal: {
1556
+ type: "symbol";
1557
+ name: string;
1558
+ } | string | number | boolean | {
1559
+ type: "bigint";
1560
+ value: string;
1561
+ } | {
1562
+ type: "regex";
1563
+ regex: string;
1564
+ };
1565
+ }
1566
+ export interface SerializedTypeTemplateLiteral extends SerializedTypeAnnotations {
1567
+ kind: ReflectionKind.templateLiteral;
1568
+ types: SerializedTypeReference[];
1569
+ }
1570
+ export interface SerializedTypeParameter extends SerializedTypeAnnotations {
1571
+ kind: ReflectionKind.parameter;
1572
+ name: string;
1573
+ type: SerializedTypeReference;
1574
+ visibility?: ReflectionVisibility;
1575
+ readonly?: true;
1576
+ optional?: true;
1577
+ /**
1578
+ * Set when the parameter has a default value aka initializer.
1579
+ */
1580
+ default?: any;
1581
+ tags?: TagsReflection;
1582
+ }
1583
+ export interface SerializedTypeBaseMember extends SerializedTypeAnnotations {
1584
+ visibility: ReflectionVisibility;
1585
+ abstract?: true;
1586
+ optional?: true;
1587
+ readonly?: true;
1588
+ tags?: TagsReflection;
1589
+ }
1590
+ export interface SerializedTypeMethod extends SerializedTypeBaseMember {
1591
+ kind: ReflectionKind.method;
1592
+ visibility: ReflectionVisibility;
1593
+ name: number | string | symbol;
1594
+ parameters: SerializedTypeParameter[];
1595
+ optional?: true;
1596
+ abstract?: true;
1597
+ return: SerializedTypeReference;
1598
+ }
1599
+ export interface SerializedTypeProperty extends SerializedTypeBaseMember {
1600
+ kind: ReflectionKind.property;
1601
+ visibility: ReflectionVisibility;
1602
+ name: number | string | symbol;
1603
+ optional?: true;
1604
+ readonly?: true;
1605
+ abstract?: true;
1606
+ description?: string;
1607
+ type: SerializedTypeReference;
1608
+ /**
1609
+ * Set when the property has a default value aka initializer.
1610
+ */
1611
+ default?: any;
1612
+ }
1613
+ export interface SerializedTypePromise extends SerializedTypeAnnotations {
1614
+ kind: ReflectionKind.promise;
1615
+ type: SerializedTypeReference;
1616
+ }
1617
+ export interface SerializedTypeEnum extends SerializedTypeAnnotations {
1618
+ kind: ReflectionKind.enum;
1619
+ enum: {
1620
+ [name: string]: string | number | undefined | null;
1621
+ };
1622
+ values: (string | number | undefined | null)[];
1623
+ indexType: SerializedTypeReference;
1624
+ tags?: TagsReflection;
1625
+ }
1626
+ export interface SerializedTypeUnion extends SerializedTypeAnnotations {
1627
+ kind: ReflectionKind.union;
1628
+ types: SerializedTypeReference[];
1629
+ }
1630
+ export interface SerializedTypeIntersection extends SerializedTypeAnnotations {
1631
+ kind: ReflectionKind.intersection;
1632
+ types: SerializedTypeReference[];
1633
+ }
1634
+ export interface SerializedTypeArray extends SerializedTypeAnnotations {
1635
+ kind: ReflectionKind.array;
1636
+ type: SerializedTypeReference;
1637
+ tags?: TagsReflection;
1638
+ }
1639
+ export interface SerializedTypeIndexSignature extends SerializedTypeAnnotations {
1640
+ kind: ReflectionKind.indexSignature;
1641
+ index: SerializedTypeReference;
1642
+ type: SerializedTypeReference;
1643
+ /**
1644
+ * Set when the parameter has a default value aka initializer.
1645
+ */
1646
+ default?: any;
1647
+ }
1648
+ export interface SerializedTypePropertySignature extends SerializedTypeAnnotations {
1649
+ kind: ReflectionKind.propertySignature;
1650
+ name: number | string | symbol;
1651
+ optional?: true;
1652
+ readonly?: true;
1653
+ description?: string;
1654
+ type: SerializedTypeReference;
1655
+ /**
1656
+ * Set when the parameter has a default value aka initializer.
1657
+ */
1658
+ default?: any;
1659
+ tags?: TagsReflection;
1660
+ }
1661
+ export interface SerializedTypeMethodSignature extends SerializedTypeAnnotations {
1662
+ kind: ReflectionKind.methodSignature;
1663
+ name: number | string | symbol;
1664
+ optional?: true;
1665
+ parameters: SerializedTypeParameter[];
1666
+ return: SerializedTypeReference;
1667
+ tags?: TagsReflection;
1668
+ }
1669
+ export interface SerializedTypeTypeParameter extends SerializedTypeAnnotations {
1670
+ kind: ReflectionKind.typeParameter;
1671
+ name: string;
1672
+ }
1673
+ export interface SerializedTypeInfer extends SerializedTypeAnnotations {
1674
+ kind: ReflectionKind.infer;
1675
+ }
1676
+ export interface SerializedTypeTupleMember extends SerializedTypeAnnotations {
1677
+ kind: ReflectionKind.tupleMember;
1678
+ type: SerializedTypeReference;
1679
+ optional?: true;
1680
+ name?: string;
1681
+ }
1682
+ export interface SerializedTypeTuple extends SerializedTypeAnnotations {
1683
+ kind: ReflectionKind.tuple;
1684
+ types: SerializedTypeTupleMember[];
1685
+ }
1686
+ export interface SerializedTypeRest extends SerializedTypeAnnotations {
1687
+ kind: ReflectionKind.rest;
1688
+ type: SerializedTypeReference;
1689
+ }
1690
+ export type SerializedType = SimpleSerializedType | SerializedTypeLiteral | SerializedTypeTemplateLiteral | SerializedTypeParameter | SerializedTypeFunction | SerializedTypeMethod | SerializedTypeProperty | SerializedTypePromise | SerializedTypeClassType | SerializedTypeEnum | SerializedTypeUnion | SerializedTypeIntersection | SerializedTypeArray | SerializedTypeObjectLiteral | SerializedTypeIndexSignature | SerializedTypePropertySignature | SerializedTypeMethodSignature | SerializedTypeTypeParameter | SerializedTypeInfer | SerializedTypeTuple | SerializedTypeTupleMember | SerializedTypeRest;
1691
+ export type SerializedTypes = SerializedType[];
1692
+ export interface SerializerState {
1693
+ types: SerializedTypes;
1694
+ disableMethods?: true;
1695
+ refs: Map<Type, number>;
1696
+ }
1697
+ /**
1698
+ * Converts a (possibly circular/nested) type into a JSON.stringify'able structure suited to be transmitted over the wire and deserialized back to the correct Type object.
1699
+ */
1700
+ export declare function serializeType(type: Type, state?: Partial<SerializerState>): SerializedTypes;
1701
+ interface DeserializeState {
1702
+ types: SerializedTypes;
1703
+ disableReuse?: boolean;
1704
+ deserialized: {
1705
+ [index: number]: {
1706
+ type: Type;
1707
+ refs: Type[];
1708
+ active: boolean;
1709
+ };
1710
+ };
1711
+ }
1712
+ export declare function deserializeType(types?: SerializedTypes, state?: Partial<DeserializeState>): Type;
1713
+ export declare type __ΩSerializedTypeAnnotations = any[];
1714
+ export declare type __ΩSerializedTypeObjectLiteral = any[];
1715
+ export declare type __ΩSerializedTypeClassType = any[];
1716
+ export declare type __ΩSerializedTypeFunction = any[];
1717
+ export declare type __ΩSerializedTypeReference = any[];
1718
+ export declare type __ΩSimpleSerializedType = any[];
1719
+ export declare type __ΩSerializedTypeLiteral = any[];
1720
+ export declare type __ΩSerializedTypeTemplateLiteral = any[];
1721
+ export declare type __ΩSerializedTypeParameter = any[];
1722
+ export declare type __ΩSerializedTypeBaseMember = any[];
1723
+ export declare type __ΩSerializedTypeMethod = any[];
1724
+ export declare type __ΩSerializedTypeProperty = any[];
1725
+ export declare type __ΩSerializedTypePromise = any[];
1726
+ export declare type __ΩSerializedTypeEnum = any[];
1727
+ export declare type __ΩSerializedTypeUnion = any[];
1728
+ export declare type __ΩSerializedTypeIntersection = any[];
1729
+ export declare type __ΩSerializedTypeArray = any[];
1730
+ export declare type __ΩSerializedTypeIndexSignature = any[];
1731
+ export declare type __ΩSerializedTypePropertySignature = any[];
1732
+ export declare type __ΩSerializedTypeMethodSignature = any[];
1733
+ export declare type __ΩSerializedTypeTypeParameter = any[];
1734
+ export declare type __ΩSerializedTypeInfer = any[];
1735
+ export declare type __ΩSerializedTypeTupleMember = any[];
1736
+ export declare type __ΩSerializedTypeTuple = any[];
1737
+ export declare type __ΩSerializedTypeRest = any[];
1738
+ export declare type __ΩSerializedType = any[];
1739
+ export declare type __ΩSerializedTypes = any[];
1740
+ export declare type __ΩSerializerState = any[];
1741
+ /**
1742
+ * Make sure to change the id when a custom naming strategy is implemented, since caches are based on it.
1743
+ */
1744
+ export declare class NamingStrategy {
1745
+ id: string;
1746
+ constructor(id?: string);
1747
+ getPropertyName(type: TypeProperty | TypePropertySignature, forSerializer: string): string | undefined;
1748
+ }
1749
+ export declare const underscoreNamingStrategy: {
1750
+ getPropertyName(type: TypeProperty | TypePropertySignature, forSerializer: string): string | undefined;
1751
+ id: string;
1752
+ };
1753
+ /**
1754
+ * Options that can be passed to the serialization/deserialization functions
1755
+ * and change the behavior in runtime (not embedded in JIT).
1756
+ */
1757
+ export interface SerializationOptions {
1758
+ /**
1759
+ * Which groups to include. If a property is not assigned to
1760
+ * a given group, it will be excluded.
1761
+ * Use an empty array to include only non-grouped properties.
1762
+ */
1763
+ groups?: string[];
1764
+ /**
1765
+ * Which groups to exclude. If a property is assigned to at least
1766
+ * one given group, it will be excluded. Basically the opposite of
1767
+ * `groups`, but you can combine both.
1768
+ * Use an empty array to exclude only non-grouped properties.
1769
+ */
1770
+ groupsExclude?: string[];
1771
+ /**
1772
+ * Allows more loosely data for certain types. e.g.
1773
+ *
1774
+ * - '1', '0', 'true', 'false' will be converted to true|false for boolean type.
1775
+ * - '1' will be converted to number for number type.
1776
+ * - 1 will be converted to string for string type.
1777
+ *
1778
+ * This will activate all registered type guards with negative specifically.
1779
+ *
1780
+ * This is enabled by default.
1781
+ */
1782
+ loosely?: boolean;
1783
+ }
1784
+ export type SerializeFunction<T = any, R = any> = (data: T, state?: SerializationOptions) => R;
1785
+ export declare function getPartialType(type: TypeClass | TypeObjectLiteral): any;
1786
+ /**
1787
+ * Creates a (cached) Partial<T> of the given type and returns a (cached) serializer function for the given registry (serialize or deserialize).
1788
+ */
1789
+ export declare function getPartialSerializeFunction(type: TypeClass | TypeObjectLiteral, registry: TemplateRegistry, namingStrategy?: NamingStrategy): SerializeFunction<any, any>;
1790
+ /**
1791
+ * Returns a (cached) serializer function for the given registry (serialize or deserialize).
1792
+ */
1793
+ export declare function getSerializeFunction(type: Type, registry: TemplateRegistry, namingStrategy?: NamingStrategy, path?: string, jitStack?: JitStack): SerializeFunction;
1794
+ export declare function createSerializeFunction(type: Type, registry: TemplateRegistry, namingStrategy?: NamingStrategy, path?: string | RuntimeCode | (string | RuntimeCode)[], jitStack?: JitStack): SerializeFunction;
1795
+ export type Guard<T> = (data: any, state?: {
1796
+ errors?: ValidationErrorItem[];
1797
+ }) => data is T;
1798
+ export declare function createTypeGuardFunction(type: Type, stateIn?: Partial<TemplateState>, serializerToUse?: Serializer, withLoose?: boolean): undefined | Guard<any>;
1799
+ export declare class SerializationError extends CustomError {
1800
+ originalMessage: string;
1801
+ code: string;
1802
+ path: string;
1803
+ constructor(originalMessage: string, code?: string, path?: string);
1804
+ }
1805
+ export declare class RuntimeCode {
1806
+ code: string;
1807
+ constructor(code: string);
1808
+ }
1809
+ export declare function collapsePath(path: (string | RuntimeCode)[], prefix?: string): string;
1810
+ export declare function getPropertyNameString(propertyName?: string | RuntimeCode): string;
1811
+ /**
1812
+ * internal: The jit stack cache is used in both serializer and guards, so its cache key needs to be aware of it
1813
+ */
1814
+ export declare class JitStack {
1815
+ protected stacks: {
1816
+ registry?: TemplateRegistry;
1817
+ map: Map<Type, {
1818
+ fn: Function | undefined;
1819
+ id: number;
1820
+ }>;
1821
+ }[];
1822
+ protected id: number;
1823
+ getStack(registry?: TemplateRegistry): Map<Type, {
1824
+ fn: Function | undefined;
1825
+ id: number;
1826
+ }>;
1827
+ has(registry: TemplateRegistry, type: Type): boolean;
1828
+ get(registry: TemplateRegistry, type: Type): {
1829
+ fn: Function | undefined;
1830
+ id: number;
1831
+ } | undefined;
1832
+ prepare(registry: TemplateRegistry, type: Type): {
1833
+ id: number;
1834
+ prepare: (fn: Function) => {
1835
+ fn: Function | undefined;
1836
+ };
1837
+ };
1838
+ getOrCreate(registry: TemplateRegistry | undefined, type: Type, create: () => Function): {
1839
+ fn: Function | undefined;
1840
+ id: number;
1841
+ };
1842
+ }
1843
+ export declare class ContainerAccessor {
1844
+ container: string | ContainerAccessor;
1845
+ property: string;
1846
+ constructor(container: string | ContainerAccessor, property: string);
1847
+ toString(): string;
1848
+ }
1849
+ export declare class TemplateState {
1850
+ originalSetter: string | ContainerAccessor;
1851
+ originalAccessor: string | ContainerAccessor;
1852
+ compilerContext: CompilerContext;
1853
+ registry: TemplateRegistry;
1854
+ namingStrategy: NamingStrategy;
1855
+ jitStack: JitStack;
1856
+ path: (string | RuntimeCode)[];
1857
+ /**
1858
+ * Before and after template content is rendered before/after all other templates.
1859
+ * When a template is put into its own function, before/after templates are run outside of this function.
1860
+ */
1861
+ template: string;
1862
+ ended: boolean;
1863
+ setter: string | ContainerAccessor;
1864
+ accessor: string | ContainerAccessor;
1865
+ /**
1866
+ * Strict means only use type guards of specificality of 1 (used for is()/validation()).
1867
+ * For deserialization loose is used.
1868
+ */
1869
+ validation?: "strict" | "loose";
1870
+ /**
1871
+ * When this is set all specificalities are used (used in union type guards to detect which member to pick).
1872
+ */
1873
+ allSpecificalities?: TypeGuardRegistry;
1874
+ propertyName?: string | RuntimeCode;
1875
+ setterDisabled: boolean;
1876
+ parentTypes: Type[];
1877
+ target: "serialize" | "deserialize";
1878
+ protected handledAnnotations: AnnotationDefinition[];
1879
+ constructor(originalSetter: string | ContainerAccessor, originalAccessor: string | ContainerAccessor, compilerContext: CompilerContext, registry: TemplateRegistry, namingStrategy?: NamingStrategy, jitStack?: JitStack, path?: (string | RuntimeCode)[]);
1880
+ isValidation(): boolean;
1881
+ withValidation(validation: this["validation"]): this;
1882
+ includeAllSpecificalities(guardRegistry: TypeGuardRegistry): this;
1883
+ replaceTemplate(template: string): void;
1884
+ /**
1885
+ * Forks as state, with an empty propertyName.
1886
+ */
1887
+ fork(setter?: string | ContainerAccessor, accessor?: string | ContainerAccessor, path?: (string | RuntimeCode)[]): TemplateState;
1888
+ fullFork(): TemplateState;
1889
+ forRegistry(registry: TemplateRegistry): this;
1890
+ forPropertyName(name?: string | number | symbol | RuntimeCode): this;
1891
+ disableSetter(): this;
1892
+ enableSetter(): this;
1893
+ /**
1894
+ * Can be used to track which annotation was already handled. Necessary to use with `isAnnotationHandled` to avoid infinite recursive loops
1895
+ * when a serializer template issues sub calls depending on annotation data.
1896
+ */
1897
+ annotationHandled(annotation: AnnotationDefinition<any>): void;
1898
+ isAnnotationHandled(annotation: AnnotationDefinition<any>): boolean;
1899
+ get isSerialization(): boolean;
1900
+ get isDeserialization(): boolean;
1901
+ extendPath(path: string | RuntimeCode | number | symbol): this;
1902
+ assignValidationError(code: string, message: string): string;
1903
+ throwCode(type: Type | string, error?: string, accessor?: string | ContainerAccessor): string;
1904
+ /**
1905
+ * Adds template code for setting the `this.setter` variable. The expression evaluated in `code` is assigned to `this.setter`.
1906
+ * `this.accessor` will point now to `this.setter`.
1907
+ */
1908
+ addSetter(code: string | {
1909
+ toString(): string;
1910
+ }): void;
1911
+ addSetterAndReportErrorIfInvalid(errorCode: string, message: string, code: string): void;
1912
+ /**
1913
+ * Adds a converter function that is executed on the current `this.accessor` value.
1914
+ *
1915
+ * @example
1916
+ * ```typescript
1917
+ * serializer.deserializeRegistry.registerClass(Date, (type, state) => {
1918
+ * // make sure to check `v` as it is any!
1919
+ * state.convert((v: any) => {
1920
+ * if ('number' !== typeof v) throw new SerializationError('Expected number');
1921
+ * return new Date(v);
1922
+ * });
1923
+ * });
1924
+ *
1925
+ * serializer.serializeRegistry.registerClass(Date, (type, state) => {
1926
+ * // in serialization `v` is always the specific type
1927
+ * state.convert((v: Date) => v.getTime());
1928
+ * });
1929
+ * ```
1930
+ */
1931
+ convert(callback: (value: any) => any): void;
1932
+ /**
1933
+ * Allows to add a custom code that is executed on the current `this.accessor` value.
1934
+ *
1935
+ * @example
1936
+ * ```typescript
1937
+ * serializer.deserializeRegistry.addDecorator(
1938
+ * isCustomTypeClass,
1939
+ * (type, state) => {
1940
+ * state.touch((value) => {
1941
+ * if ('onLoad' in value) value.onLoad();
1942
+ * });
1943
+ * }
1944
+ * );
1945
+ * ```
1946
+ */
1947
+ touch(callback: (value: any) => void): void;
1948
+ /**
1949
+ * Stop executing next templates.
1950
+ */
1951
+ stop(): void;
1952
+ setVariable(name: string, value?: any): string;
1953
+ setContext(values: {
1954
+ [name: string]: any;
1955
+ }): void;
1956
+ addCode(code: string): void;
1957
+ /**
1958
+ * Adds template code for setting the `this.setter` variable manually, so use `${state.setter} = value`.
1959
+ * `this.accessor` will point now to `this.setter`.
1960
+ */
1961
+ addCodeForSetter(code: string): void;
1962
+ hasSetterCode(): boolean;
1963
+ }
1964
+ export type Template<T extends Type> = (type: T, state: TemplateState) => void;
1965
+ export type TemplateHook = (type: Type, state: TemplateState) => void;
1966
+ /**
1967
+ * Just sets the state.setter to state.accessor without any modification.
1968
+ */
1969
+ export declare function noopTemplate(type: Type, state: TemplateState): void;
1970
+ interface TemplateDecorator {
1971
+ predicate: (type: Type) => boolean;
1972
+ template: Template<any>;
1973
+ }
1974
+ export declare class TemplateRegistry {
1975
+ serializer: Serializer;
1976
+ protected static ids: number;
1977
+ id: number;
1978
+ protected templates: {
1979
+ [kind in ReflectionKind]?: Template<any>[];
1980
+ };
1981
+ protected decorator: TemplateDecorator[];
1982
+ preHooks: TemplateHook[];
1983
+ postHooks: TemplateHook[];
1984
+ classTemplates: Map<ClassType<any>, Template<any>[]>;
1985
+ constructor(serializer?: Serializer);
1986
+ clear(): void;
1987
+ get(type: Type): Template<Type>[];
1988
+ getDecorator(type: Type): Template<Type>[];
1989
+ /**
1990
+ * Registers a template for all binary classes: ArrayBuffer, Uint8Array, Int8Array, etc.
1991
+ */
1992
+ registerBinary(template: Template<TypeClass>): void;
1993
+ /**
1994
+ * Registers a template for a given class type.
1995
+ *
1996
+ * As soon as a single template has registered for the given classType the template registry
1997
+ * only returns templates for this particular classType and omits all general purpose ReflectionKind.class templates for this particular classType.
1998
+ */
1999
+ registerClass(classType: ClassType, template: Template<TypeClass>): void;
2000
+ prependClass(classType: ClassType, template: Template<TypeClass>): void;
2001
+ appendClass(classType: ClassType, template: Template<TypeClass>): void;
2002
+ protected getClassTemplates(classType: ClassType): Template<TypeClass>[];
2003
+ addPreHook(callback: TemplateHook): void;
2004
+ addPostHook(callback: TemplateHook): void;
2005
+ /**
2006
+ * Removes all registered templates.
2007
+ */
2008
+ unregister(kind: ReflectionKind): void;
2009
+ /**
2010
+ * Registers a new template and replaces all existing (added via register,prepend,append).
2011
+ */
2012
+ register<T extends ReflectionKind>(kind: T, template: Template<FindType<Type, T>>): void;
2013
+ /**
2014
+ * Registers additional templates that handle type decorators/annotations. The templates can safely assume that the given type in `state.accessor`
2015
+ * is already type-checked to be `T`.
2016
+ *
2017
+ * Decorator templates run last (after normal templates and postHook).
2018
+ *
2019
+ * This split between register and registerForDecorator is made to have a distinction between native type templates and additional user-made templates.
2020
+ * This allows to fetch only decorator templates and decide upon the result whether additional code is necessary or not. (this would not be possible
2021
+ * if everything is added to the `register` call that does always the basic checks).
2022
+ */
2023
+ addDecorator(predicate: (type: Type) => boolean, template: Template<Type>): void;
2024
+ /**
2025
+ * Removes all registered decorators for a certain type.
2026
+ */
2027
+ removeDecorator(type: Type): void;
2028
+ prepend<T extends ReflectionKind>(kind: T, template: Template<FindType<Type, T>>): void;
2029
+ append<T extends ReflectionKind>(kind: T, template: Template<FindType<Type, T>>): void;
2030
+ }
2031
+ /**
2032
+ * To avoid circular builds, class/object literal code is extract to its own function.
2033
+ * if this returns true, code is put into state to call an already existing function.
2034
+ */
2035
+ export declare function callExtractedFunctionIfAvailable(state: TemplateState, type: Type): boolean;
2036
+ export declare function extractStateToFunctionAndCallIt(state: TemplateState, type: Type): {
2037
+ setFunction: (fn: Function) => {
2038
+ fn: Function | undefined;
2039
+ };
2040
+ id: number;
2041
+ state: TemplateState;
2042
+ };
2043
+ export declare function buildFunction(state: TemplateState, type: Type): Function;
2044
+ export declare function executeTemplates(state: TemplateState, type: Type, withLoose?: boolean, withCache?: boolean): string;
2045
+ export declare function createConverterJSForMember(property: ReflectionProperty | TypeProperty | TypePropertySignature | TypeIndexSignature, state: TemplateState, undefinedSetterCode?: string, nullSetterCode?: string): string;
2046
+ export declare function inAccessor(accessor: ContainerAccessor | string): string;
2047
+ export declare function deserializeEmbedded(type: TypeClass | TypeObjectLiteral, state: TemplateState, container?: string): string;
2048
+ export declare function getIndexCheck(context: CompilerContext, i: string, type: Type): string;
2049
+ /**
2050
+ * Sort, so the order is literal, number, string, symbol. literal comes first as its the most specific type.
2051
+ * We need to do that for numbers since all keys are string|symbol in runtime, and we need to check if a string is numeric first before falling back to string.
2052
+ */
2053
+ export declare function sortSignatures(signatures: TypeIndexSignature[]): void;
2054
+ export declare function getStaticDefaultCodeForProperty(member: TypeProperty | TypePropertySignature, setter: string | ContainerAccessor, state: TemplateState): string;
2055
+ export declare function getEmbeddedProperty(type: TypeClass | TypeObjectLiteral): TypeProperty | TypePropertySignature | undefined;
2056
+ export declare function serializeObjectLiteral(type: TypeObjectLiteral | TypeClass, state: TemplateState): void;
2057
+ export declare function typeGuardEmbedded(type: TypeClass | TypeObjectLiteral, state: TemplateState, embedded: EmbeddedOptions): void;
2058
+ export declare function typeGuardObjectLiteral(type: TypeObjectLiteral | TypeClass, state: TemplateState): void;
2059
+ export declare function serializeArray(type: TypeArray, state: TemplateState): void;
2060
+ export declare function typeGuardArray(elementType: Type, state: TemplateState): void;
2061
+ export declare function getSetTypeToArray(type: TypeClass): TypeArray;
2062
+ export declare function getMapTypeToArray(type: TypeClass): TypeArray;
2063
+ export declare function getNTypeToArray(type: TypeClass, n: number): TypeArray;
2064
+ export declare function executeTypeArgumentAsArray(type: TypeClass, typeIndex: number, state: TemplateState): void;
2065
+ export declare function forwardSetToArray(type: TypeClass, state: TemplateState): void;
2066
+ export declare function forwardMapToArray(type: TypeClass, state: TemplateState): void;
2067
+ export declare function serializePropertyOrParameter(type: TypePropertySignature | TypeProperty | TypeParameter, state: TemplateState): void;
2068
+ export declare function validatePropertyOrParameter(type: TypePropertySignature | TypeProperty | TypeParameter, state: TemplateState): void;
2069
+ export declare function handleUnion(type: TypeUnion, state: TemplateState): void;
2070
+ export declare function getNameExpression(name: string | number | symbol | undefined, state: TemplateState): string;
2071
+ export declare class TypeGuardRegistry {
2072
+ serializer: Serializer;
2073
+ registry: {
2074
+ [specificality: number]: TemplateRegistry;
2075
+ };
2076
+ protected sorted?: [
2077
+ specificality: number,
2078
+ registry: TemplateRegistry
2079
+ ][];
2080
+ /**
2081
+ * Lowest specificality first
2082
+ */
2083
+ getSortedTemplateRegistries(): [
2084
+ specificality: number,
2085
+ registry: TemplateRegistry
2086
+ ][];
2087
+ constructor(serializer: Serializer);
2088
+ clear(): void;
2089
+ /**
2090
+ *
2091
+ * @see register() for specificality explanation.
2092
+ */
2093
+ getRegistry(specificality: number): TemplateRegistry;
2094
+ /**
2095
+ * Registers a new template and replaces all existing (added via register,prepend,append).
2096
+ *
2097
+ * Specificality defines when the given template guard is executed.
2098
+ *
2099
+ * - 1 means its used for JS types - exact types. For example for type string `'string' ==== typeof v` is used. Same for number, bigint, and boolean.
2100
+ * Guards of this specificality are used for the `is()` function.
2101
+ *
2102
+ * - >1 means it acts as a fallback. For example in a union `number | Date`, when a string is given, the Date can allow `string` type as well, so it gets converted to a Date.
2103
+ *
2104
+ * - >0 && <1 means its acts as a priority guard. For example in a `string | Date`, a string of date-format is converted to a Date instead of a string. This is necessary
2105
+ * to support regular JSON.
2106
+ *
2107
+ * - <0, anything below 0 means it can optionally be used for loosely types. This is handy when data comes from a string-only encoding like URL query strings.
2108
+ * In this specificality a numeric string is converted to a number or bigint, a 1|0|true|false string converted to boolean .
2109
+ */
2110
+ register<T extends ReflectionKind>(specificality: number, kind: T, template: Template<FindType<Type, T>>): void;
2111
+ /**
2112
+ * @see register
2113
+ */
2114
+ registerClass(specificality: number, classType: ClassType, template: Template<TypeClass>): void;
2115
+ /**
2116
+ * @see register
2117
+ */
2118
+ registerBinary(specificality: number, template: Template<TypeClass>): void;
2119
+ }
2120
+ /**
2121
+ * Default serializer that can convert JS data structures to the target type.
2122
+ * It coerces types, converts object literals to class instances, and has type guards for JS types.
2123
+ *
2124
+ * JSONSerializer has the same but for JSON data structures.
2125
+ */
2126
+ export declare class Serializer {
2127
+ name: string;
2128
+ serializeRegistry: TemplateRegistry;
2129
+ deserializeRegistry: TemplateRegistry;
2130
+ typeGuards: TypeGuardRegistry;
2131
+ validators: TemplateRegistry;
2132
+ constructor(name?: string);
2133
+ setExplicitUndefined(type: Type, state: TemplateState): boolean;
2134
+ protected registerValidators(): void;
2135
+ clear(): void;
2136
+ protected registerSerializers(): void;
2137
+ protected registerTypeGuards(): void;
2138
+ }
2139
+ export declare const serializableKinds: ReflectionKind[];
2140
+ export declare class EmptySerializer extends Serializer {
2141
+ constructor(name?: string);
2142
+ protected registerValidators(): void;
2143
+ protected registerSerializers(): void;
2144
+ }
2145
+ export declare const serializer: Serializer;
2146
+ export declare type __ΩSerializationOptions = any[];
2147
+ export declare type __ΩSerializeFunction = any[];
2148
+ export declare type __ΩGuard = any[];
2149
+ export declare type __ΩTemplate = any[];
2150
+ export declare type __ΩTemplateHook = any[];
2151
+ export type ValidatorMeta<Name extends string, Args extends [
2152
+ ...args: any[]
2153
+ ] = [
2154
+ ]> = TypeAnnotation<"validator", [
2155
+ Name,
2156
+ Args
2157
+ ]>;
2158
+ export type ValidateFunction = (value: any, type: Type, options: any) => ValidatorError | void;
2159
+ export type Validate<T extends ValidateFunction, Options extends Parameters<T>[2] = unknown> = ValidatorMeta<"function", [
2160
+ T,
2161
+ Options
2162
+ ]>;
2163
+ export type Pattern<T extends RegExp> = ValidatorMeta<"pattern", [
2164
+ T
2165
+ ]>;
2166
+ export type Alpha = ValidatorMeta<"alpha">;
2167
+ export type Alphanumeric = ValidatorMeta<"alphanumeric">;
2168
+ export type Ascii = ValidatorMeta<"ascii">;
2169
+ export type Decimal<MinDigits extends number = 1, MaxDigits extends number = 100> = ValidatorMeta<"decimal", [
2170
+ MinDigits,
2171
+ MaxDigits
2172
+ ]>;
2173
+ export type MultipleOf<Num extends number> = ValidatorMeta<"multipleOf", [
2174
+ Num
2175
+ ]>;
2176
+ export type MinLength<Length extends number> = ValidatorMeta<"minLength", [
2177
+ Length
2178
+ ]>;
2179
+ export type MaxLength<Length extends number> = ValidatorMeta<"maxLength", [
2180
+ Length
2181
+ ]>;
2182
+ export type Includes<T extends string | number | boolean> = ValidatorMeta<"includes", [
2183
+ T
2184
+ ]>;
2185
+ export type Excludes<T extends string | number | boolean> = ValidatorMeta<"excludes", [
2186
+ T
2187
+ ]>;
2188
+ export type Minimum<T extends number | bigint> = ValidatorMeta<"minimum", [
2189
+ T
2190
+ ]>;
2191
+ export type Maximum<T extends number | bigint> = ValidatorMeta<"maximum", [
2192
+ T
2193
+ ]>;
2194
+ /**
2195
+ Includes 0. Use PositiveNoZero to exclude 0.
2196
+ */
2197
+ export type Positive = ValidatorMeta<"positive", unknown & [
2198
+ true
2199
+ ]>;
2200
+ /**
2201
+ * Includes 0. Use NegativeNoZero to exclude 0.
2202
+ */
2203
+ export type Negative = ValidatorMeta<"negative", [
2204
+ true
2205
+ ]>;
2206
+ export type PositiveNoZero = ValidatorMeta<"positive", [
2207
+ false
2208
+ ]>;
2209
+ export type NegativeNoZero = ValidatorMeta<"negative", [
2210
+ false
2211
+ ]>;
2212
+ export type ExclusiveMinimum<T extends number | bigint> = ValidatorMeta<"exclusiveMinimum", [
2213
+ T
2214
+ ]>;
2215
+ export type ExclusiveMaximum<T extends number | bigint> = ValidatorMeta<"exclusiveMaximum", [
2216
+ T
2217
+ ]>;
2218
+ export type BeforeDate<T extends number> = ValidatorMeta<"beforeDate", [
2219
+ T
2220
+ ]>;
2221
+ export type AfterDate<T extends number> = ValidatorMeta<"afterDate", [
2222
+ T
2223
+ ]>;
2224
+ export type BeforeNow = ValidatorMeta<"beforeNow">;
2225
+ export type AfterNow = ValidatorMeta<"afterNow">;
2226
+ export declare const EMAIL_REGEX: RegExp;
2227
+ export type Email = string & Pattern<typeof EMAIL_REGEX>;
2228
+ /**
2229
+ * Used in validator functions.
2230
+ */
2231
+ export declare class ValidatorError {
2232
+ readonly code: string;
2233
+ readonly message: string;
2234
+ readonly path?: string | undefined;
2235
+ constructor(code: string, message: string, path?: string | undefined);
2236
+ }
2237
+ /**
2238
+ * The structure of a validation error.
2239
+ *
2240
+ * Path defines the shallow or deep path (using dots).
2241
+ * Message is an arbitrary message in english.
2242
+ *
2243
+ * In validators please use and return `new ValidatorError('code', 'message')` instead.
2244
+ */
2245
+ export declare class ValidationErrorItem {
2246
+ /**
2247
+ * The path to the property. Might be a deep path separated by dot.
2248
+ */
2249
+ readonly path: string;
2250
+ /**
2251
+ * A lower cased error code that can be used to identify this error and translate.
2252
+ */
2253
+ readonly code: string;
2254
+ /**
2255
+ * Free text of the error.
2256
+ */
2257
+ readonly message: string;
2258
+ /**
2259
+ * Optional value that caused the error.
2260
+ */
2261
+ readonly value?: any | undefined;
2262
+ constructor(
2263
+ /**
2264
+ * The path to the property. Might be a deep path separated by dot.
2265
+ */
2266
+ path: string,
2267
+ /**
2268
+ * A lower cased error code that can be used to identify this error and translate.
2269
+ */
2270
+ code: string,
2271
+ /**
2272
+ * Free text of the error.
2273
+ */
2274
+ message: string,
2275
+ /**
2276
+ * Optional value that caused the error.
2277
+ */
2278
+ value?: any | undefined);
2279
+ toString(prefix?: string): string;
2280
+ }
2281
+ export declare class ValidationError extends CustomError {
2282
+ readonly errors: ValidationErrorItem[];
2283
+ constructor(errors: ValidationErrorItem[], type?: Type);
2284
+ static from(errors: {
2285
+ path: string;
2286
+ message: string;
2287
+ code?: string;
2288
+ value?: any;
2289
+ }[]): ValidationError;
2290
+ }
2291
+ /**
2292
+ * Returns empty array when valid, or ValidationErrorItem[] with detailed error messages if not valid.
2293
+ *
2294
+ * Returns validation error items when failed. If successful returns an empty array.
2295
+ */
2296
+ export declare function validate<T>(data: any, type?: ReceiveType<T>): ValidationErrorItem[];
2297
+ export declare function validateFunction<T>(serializerToUse?: Serializer, type?: ReceiveType<T>): (data: T) => ValidationErrorItem[];
2298
+ /**
2299
+ * Returns true when valid, and false if not.
2300
+ */
2301
+ export declare function validates<T>(data: any, type?: ReceiveType<T>): boolean;
2302
+ export declare type __ΩValidatorMeta = any[];
2303
+ export declare type __ΩValidateFunction = any[];
2304
+ export declare type __ΩValidate = any[];
2305
+ export declare type __ΩPattern = any[];
2306
+ export declare type __ΩAlpha = any[];
2307
+ export declare type __ΩAlphanumeric = any[];
2308
+ export declare type __ΩAscii = any[];
2309
+ export declare type __ΩDecimal = any[];
2310
+ export declare type __ΩMultipleOf = any[];
2311
+ export declare type __ΩMinLength = any[];
2312
+ export declare type __ΩMaxLength = any[];
2313
+ export declare type __ΩIncludes = any[];
2314
+ export declare type __ΩExcludes = any[];
2315
+ export declare type __ΩMinimum = any[];
2316
+ export declare type __ΩMaximum = any[];
2317
+ export declare type __ΩPositive = any[];
2318
+ export declare type __ΩNegative = any[];
2319
+ export declare type __ΩPositiveNoZero = any[];
2320
+ export declare type __ΩNegativeNoZero = any[];
2321
+ export declare type __ΩExclusiveMinimum = any[];
2322
+ export declare type __ΩExclusiveMaximum = any[];
2323
+ export declare type __ΩBeforeDate = any[];
2324
+ export declare type __ΩAfterDate = any[];
2325
+ export declare type __ΩBeforeNow = any[];
2326
+ export declare type __ΩAfterNow = any[];
2327
+ export declare type __ΩEmail = any[];
2328
+ export type RuntimeStackEntry = Type | Object | (() => ClassType | Object) | string | number | boolean | bigint;
2329
+ export type Packed = (RuntimeStackEntry | string)[] & {
2330
+ __is?: (data: any) => boolean;
2331
+ } & {
2332
+ __type?: Type;
2333
+ } & {
2334
+ __unpack?: PackStruct;
2335
+ };
2336
+ export declare class PackStruct {
2337
+ ops: ReflectionOp[];
2338
+ stack: RuntimeStackEntry[];
2339
+ constructor(ops?: ReflectionOp[], stack?: RuntimeStackEntry[]);
2340
+ }
2341
+ export declare function encodeOps(ops: ReflectionOp[]): string;
2342
+ /**
2343
+ * Pack a pack structure (op instructions + pre-defined stack) and create a encoded version of it.
2344
+ */
2345
+ export declare function pack(packOrOps: PackStruct | ReflectionOp[]): Packed;
2346
+ export declare function unpack(pack: Packed): PackStruct;
2347
+ export declare function resolvePacked(type: Packed, args?: any[], options?: ReflectOptions): Type;
2348
+ /**
2349
+ * Computes a type of given object. This function caches the result on the object itself.
2350
+ * This is the slow path, using the full type virtual machine to resolve the type.
2351
+ * If you want to handle some fast paths (including cache), try using resolveReceiveType() instead.
2352
+ */
2353
+ export declare function resolveRuntimeType(o: ClassType | Function | Packed | any, args?: any[], options?: ReflectOptions): Type;
2354
+ interface Frame {
2355
+ index: number;
2356
+ startIndex: number;
2357
+ variables: number;
2358
+ inputs: RuntimeStackEntry[];
2359
+ previous?: Frame;
2360
+ mappedType?: Loop;
2361
+ distributiveLoop?: Loop;
2362
+ }
2363
+ declare class Loop {
2364
+ fromType: Type;
2365
+ private types;
2366
+ private i;
2367
+ constructor(fromType: Type);
2368
+ next(): Type | undefined;
2369
+ }
2370
+ interface Program {
2371
+ frame: Frame;
2372
+ active: boolean;
2373
+ stack: (RuntimeStackEntry | Type)[];
2374
+ stackPointer: number;
2375
+ program: number;
2376
+ depth: number;
2377
+ initialStack: (RuntimeStackEntry | Type)[];
2378
+ resultType: Type;
2379
+ ops: ReflectionOp[];
2380
+ end: number;
2381
+ inputs: RuntimeStackEntry[];
2382
+ resultTypes?: Type[];
2383
+ started: number;
2384
+ typeParameters?: Type[];
2385
+ previous?: Program;
2386
+ directReturn?: boolean;
2387
+ object?: ClassType | Function | Packed | any;
2388
+ }
2389
+ export interface ReflectOptions {
2390
+ /**
2391
+ *
2392
+ */
2393
+ reuseCached?: boolean;
2394
+ inline?: boolean;
2395
+ typeName?: string;
2396
+ }
2397
+ /**
2398
+ * @reflection never
2399
+ */
2400
+ export declare class Processor {
2401
+ static typeProcessor?: Processor;
2402
+ static get(): Processor;
2403
+ private cache;
2404
+ /**
2405
+ * Linked list of programs to execute. For each external call to external program will this be changed.
2406
+ */
2407
+ protected program: Program;
2408
+ reflect(object: ClassType | Function | Packed | any, inputs?: RuntimeStackEntry[], options?: ReflectOptions): Type;
2409
+ _reflect(object: ClassType | Function | Packed | any, inputs?: RuntimeStackEntry[], options?: ReflectOptions): Type;
2410
+ run(ops: ReflectionOp[], initialStack: RuntimeStackEntry[], inputs?: RuntimeStackEntry[], object?: ClassType | Function | Packed | any): Type;
2411
+ runProgram(program: Program): Type;
2412
+ /**
2413
+ * Semantic is important here: This triggers true only for the very last op of a program.
2414
+ * If it is checked in OP inline then it could be true or false:
2415
+ *
2416
+ * type t<T> = T; => false since we have nominal past the inline op
2417
+ * typeOf<T>() => true since we have no nominal past the inline op
2418
+ */
2419
+ protected isEnded(): boolean;
2420
+ /**
2421
+ * Runs all scheduled programs until termination.
2422
+ */
2423
+ protected loop(until?: Program): Type | RuntimeStackEntry;
2424
+ private handleTuple;
2425
+ private handleIntersection;
2426
+ private handleDistribute;
2427
+ private handleIndexAccess;
2428
+ private handleKeyOf;
2429
+ private handleMappedType;
2430
+ private handleTemplateLiteral;
2431
+ protected push(entry: RuntimeStackEntry, program?: Program): void;
2432
+ protected pop(): RuntimeStackEntry;
2433
+ protected pushFrame(): void;
2434
+ protected popFrame(): RuntimeStackEntry[];
2435
+ /**
2436
+ * Create a new stack frame with the calling convention.
2437
+ */
2438
+ protected call(program: number, jumpBackTo?: number): void;
2439
+ /**
2440
+ * Removes the stack frame, and puts the latest entry on the stack.
2441
+ */
2442
+ protected returnFrame(): void;
2443
+ protected pushType(type: Type): void;
2444
+ protected eatParameter(): RuntimeStackEntry;
2445
+ }
2446
+ export declare function typeInfer(value: any): Type;
2447
+ export declare function getEnumType(values: any[]): Type;
2448
+ export declare type __ΩRuntimeStackEntry = any[];
2449
+ export declare type __ΩPacked = any[];
2450
+ export declare type __ΩReflectOptions = any[];
2451
+ /**
2452
+ * Receives the runtime type of template argument.
2453
+ *
2454
+ * Use
2455
+ *
2456
+ * ```typescript
2457
+ *
2458
+ * function f<T>(type?: ReceiveType<T>): Type {
2459
+ * return resolveReceiveType(type);
2460
+ * }
2461
+ *
2462
+ * ```
2463
+ */
2464
+ export type ReceiveType<T> = Packed | Type | ClassType<T>;
2465
+ export declare function resolveReceiveType(type?: Packed | Type | ClassType | AbstractClassType | ReflectionClass<any>): Type;
2466
+ export declare function reflect(o: any, ...args: any[]): Type;
2467
+ export declare function reflectOrUndefined(o: any, ...args: any[]): Type | undefined;
2468
+ export declare function valuesOf<T>(args?: any[], p?: ReceiveType<T>): (string | number | symbol | Type)[];
2469
+ export declare function propertiesOf<T>(args?: any[], p?: ReceiveType<T>): (string | number | symbol | Type)[];
2470
+ export declare function getNominalId<T>(args?: any[], p?: ReceiveType<T>): number | undefined;
2471
+ export declare function typeOf<T>(args?: any[], p?: ReceiveType<T>): Type;
2472
+ export declare function removeTypeName<T extends Type>(type: T): T;
2473
+ export declare function removeNominal<T extends Type | undefined | Type[]>(type: T): T;
2474
+ export declare function getProperty(type: TypeObjectLiteral | TypeClass, memberName: number | string | symbol): TypeProperty | TypePropertySignature | undefined;
2475
+ export declare function toSignature(type: TypeProperty | TypeMethod | TypePropertySignature | TypeMethodSignature): TypePropertySignature | TypeMethodSignature;
2476
+ export declare function hasCircularReference(type: Type): any;
2477
+ export declare function visit(type: Type, visitor: (type: Type, path: string) => false | void, onCircular?: () => void): void;
2478
+ /**
2479
+ * @reflection never
2480
+ */
2481
+ export declare class ReflectionParameter {
2482
+ readonly parameter: TypeParameter;
2483
+ readonly reflectionFunction: ReflectionMethod | ReflectionFunction;
2484
+ type: Type;
2485
+ constructor(parameter: TypeParameter, reflectionFunction: ReflectionMethod | ReflectionFunction);
2486
+ getType(): Type;
2487
+ getName(): string;
2488
+ get name(): string;
2489
+ isOptional(): boolean;
2490
+ hasDefault(): boolean;
2491
+ isValueRequired(): boolean;
2492
+ getDefaultValue(): any;
2493
+ setDefaultValue(value: any): void;
2494
+ hasDefaultFunctionExpression(): boolean;
2495
+ applyDecorator(t: TData): void;
2496
+ getVisibility(): ReflectionVisibility | undefined;
2497
+ isPublic(): boolean;
2498
+ isProtected(): boolean;
2499
+ isPrivate(): boolean;
2500
+ isReadonly(): boolean;
2501
+ setTags(tags: TagsReflection): void;
2502
+ getTags(): TagsReflection;
2503
+ isHidden(): boolean;
2504
+ isIgnored(): boolean;
2505
+ isInternal(): boolean;
2506
+ getAlias(): string[];
2507
+ getTitle(): string | undefined;
2508
+ getPermission(): string[];
2509
+ getDomain(): string | undefined;
2510
+ /**
2511
+ * True if the parameter becomes a property in the class.
2512
+ * This is the case for parameters in constructors with visibility or readonly.
2513
+ *
2514
+ * ```typescript
2515
+ * class User {
2516
+ * constructor(public name: string) {}
2517
+ * }
2518
+ */
2519
+ isProperty(): boolean;
2520
+ }
2521
+ /**
2522
+ * @reflection never
2523
+ */
2524
+ export declare class ReflectionFunction {
2525
+ readonly type: TypeMethod | TypeMethodSignature | TypeFunction;
2526
+ parameters: ReflectionParameter[];
2527
+ parameterAliases: Map<string, string>;
2528
+ description: string;
2529
+ constructor(type: TypeMethod | TypeMethodSignature | TypeFunction);
2530
+ static from(fn: Function): ReflectionFunction;
2531
+ getParameterNames(): string[];
2532
+ hasParameter(name: string | number | symbol): boolean;
2533
+ getParameterOrUndefined(name: string | number | symbol): ReflectionParameter | undefined;
2534
+ getParameter(name: string | number | symbol): ReflectionParameter;
2535
+ getParameterType(name: string | number | symbol): Type | undefined;
2536
+ getParameters(): ReflectionParameter[];
2537
+ getReturnType(): Type;
2538
+ getName(): number | string | symbol;
2539
+ getDescription(): string;
2540
+ get name(): string;
2541
+ setTags(tags: TagsReflection): void;
2542
+ getTags(): TagsReflection;
2543
+ isHidden(): boolean;
2544
+ isReadonly(): boolean;
2545
+ isIgnored(): boolean;
2546
+ isInternal(): boolean;
2547
+ getAlias(): string[];
2548
+ getTitle(): string | undefined;
2549
+ getPermission(): string[];
2550
+ getDomain(): string | undefined;
2551
+ }
2552
+ /**
2553
+ * @reflection never
2554
+ */
2555
+ export declare class ReflectionMethod extends ReflectionFunction {
2556
+ type: TypeMethod | TypeMethodSignature;
2557
+ reflectionClass: ReflectionClass<any>;
2558
+ /**
2559
+ * Whether this method acts as validator.
2560
+ */
2561
+ validator: boolean;
2562
+ constructor(type: TypeMethod | TypeMethodSignature, reflectionClass: ReflectionClass<any>);
2563
+ setType(method: TypeMethod | TypeMethodSignature): void;
2564
+ applyDecorator(data: TData): void;
2565
+ clone(reflectionClass?: ReflectionClass<any>, method?: TypeMethod | TypeMethodSignature): ReflectionMethod;
2566
+ isOptional(): boolean;
2567
+ setTags(tags: TagsReflection): void;
2568
+ getTags(): TagsReflection;
2569
+ isHidden(): boolean;
2570
+ isIgnored(): boolean;
2571
+ isReadonly(): boolean;
2572
+ isInternal(): boolean;
2573
+ getAlias(): string[];
2574
+ getTitle(): string | undefined;
2575
+ getPermission(): string[];
2576
+ getDomain(): string | undefined;
2577
+ }
2578
+ export declare function resolveForeignReflectionClass(property: ReflectionProperty): ReflectionClass<any>;
2579
+ /**
2580
+ * Resolved the class/object ReflectionClass of the given TypeClass|TypeObjectLiteral
2581
+ */
2582
+ export declare function resolveClassType(type: Type): ReflectionClass<any>;
2583
+ /**
2584
+ * @reflection never
2585
+ */
2586
+ export declare class ReflectionProperty {
2587
+ property: TypeProperty | TypePropertySignature;
2588
+ reflectionClass: ReflectionClass<any>;
2589
+ jsonType?: Type;
2590
+ serializer?: SerializerFn;
2591
+ deserializer?: SerializerFn;
2592
+ data: {
2593
+ [name: string]: any;
2594
+ };
2595
+ /**
2596
+ * The type of the property, not the property itself.
2597
+ *
2598
+ * Note: If the property is optional via `property?: T`, this information
2599
+ * is not available here. It's on `property`.
2600
+ * Use `isOptional()` instead, which handles this case plus the case
2601
+ * where optionality is given via union of T and undefined.
2602
+ */
2603
+ type: Type;
2604
+ symbol: symbol;
2605
+ protected cachedResolvedReflectionClass?: ReflectionClass<any>;
2606
+ constructor(property: TypeProperty | TypePropertySignature, reflectionClass: ReflectionClass<any>);
2607
+ setType(type: Type): void;
2608
+ isPrimaryKey(): boolean;
2609
+ isEmbedded(): boolean;
2610
+ /**
2611
+ * Returns the sub type if available (for arrays for example).
2612
+ *
2613
+ * @throws Error if the property type does not support sub types.
2614
+ */
2615
+ getSubType(): Type;
2616
+ /**
2617
+ * If undefined, it's not an embedded class.
2618
+ */
2619
+ getEmbedded(): {
2620
+ prefix?: string;
2621
+ } | undefined;
2622
+ isBackReference(): boolean;
2623
+ isDatabaseSkipped(database: string): boolean;
2624
+ isDatabaseMigrationSkipped(database: string): boolean;
2625
+ getBackReference(): BackReferenceOptionsResolved;
2626
+ isAutoIncrement(): boolean;
2627
+ isReference(): boolean;
2628
+ isArray(): boolean;
2629
+ isDate(): boolean;
2630
+ isNumber(): boolean;
2631
+ getForeignKeyName(): string;
2632
+ getReference(): ReferenceOptions | undefined;
2633
+ getGroups(): string[];
2634
+ isInGroup(...group: string[]): boolean;
2635
+ getExcluded(): string[];
2636
+ isSerializerExcluded(name: string): boolean;
2637
+ getData(): {
2638
+ [name: string]: any;
2639
+ };
2640
+ /**
2641
+ * Returns the ReflectionClass of the reference class/object literal.
2642
+ *
2643
+ * @throws Error if the property is not from type TypeClass or TypeObjectLiteral
2644
+ */
2645
+ getResolvedReflectionClass(): ReflectionClass<any>;
2646
+ /**
2647
+ * If undefined the property is not an index.
2648
+ * A unique property is defined as index with IndexOptions.unique=true.
2649
+ */
2650
+ getIndex(): IndexOptions | undefined;
2651
+ /**
2652
+ * Returns database specific options, if defined
2653
+ *
2654
+ * ```typescript
2655
+ * interface User {
2656
+ * logins: number & DatabaseField<{type: 'integer(8)'}>;
2657
+ *
2658
+ * //of for a specific db engine
2659
+ * logins: number & Sqlite<{type: 'integer(8)'}>;
2660
+ * }
2661
+ *
2662
+ * ```
2663
+ */
2664
+ getDatabase<T extends DatabaseFieldOptions>(name: string): T | undefined;
2665
+ clone(reflectionClass?: ReflectionClass<any>, property?: TypeProperty | TypePropertySignature): ReflectionProperty;
2666
+ applyDecorator(data: TData): void;
2667
+ getName(): number | string | symbol;
2668
+ getNameAsString(): string;
2669
+ get name(): string;
2670
+ getKind(): ReflectionKind;
2671
+ getType(): Type;
2672
+ getDescription(): string;
2673
+ /**
2674
+ * Whether a value is required from serialization point of view.
2675
+ * If this property has for example a default value (set via constructor or manually via t.default),
2676
+ * then the value is not required to instantiate the property value.
2677
+ */
2678
+ isValueRequired(): boolean;
2679
+ /**
2680
+ * Returns true when `undefined` or a missing value is allowed at the class itself.
2681
+ * This is now only true when `optional` is set, but also when type is `any`.
2682
+ */
2683
+ isActualOptional(): boolean;
2684
+ /**
2685
+ * If the property is actual optional or is an union with undefined in it.
2686
+ */
2687
+ isOptional(): boolean;
2688
+ setOptional(v: boolean): void;
2689
+ isNullable(): boolean;
2690
+ isReadonly(): boolean;
2691
+ isAbstract(): boolean;
2692
+ hasDefault(): boolean;
2693
+ getDefaultValue(): any;
2694
+ setDefaultValue(value: any): void;
2695
+ hasDefaultFunctionExpression(): boolean;
2696
+ getDefaultValueFunction(): (() => any) | undefined;
2697
+ getVisibility(): ReflectionVisibility | undefined;
2698
+ isPublic(): boolean;
2699
+ isProtected(): boolean;
2700
+ isPrivate(): boolean;
2701
+ setTags(tags: TagsReflection): void;
2702
+ getTags(): TagsReflection;
2703
+ isHidden(): boolean;
2704
+ isIgnored(): boolean;
2705
+ isInternal(): boolean;
2706
+ getAlias(): string[];
2707
+ getTitle(): string | undefined;
2708
+ getPermission(): string[];
2709
+ getDomain(): string | undefined;
2710
+ }
2711
+ export declare const reflectionClassSymbol: unique symbol;
2712
+ export interface SerializerFn {
2713
+ (value: any, property: ReflectionProperty): any;
2714
+ }
2715
+ export declare class TData {
2716
+ validator: boolean;
2717
+ validators: ValidateFunction[];
2718
+ type?: Packed | Type | ClassType;
2719
+ data: {
2720
+ [name: string]: any;
2721
+ };
2722
+ serializer?: SerializerFn;
2723
+ deserializer?: SerializerFn;
2724
+ }
2725
+ export declare class EntityData {
2726
+ name?: string;
2727
+ collectionName?: string;
2728
+ databaseSchemaName?: string;
2729
+ disableConstructor: boolean;
2730
+ data: {
2731
+ [name: string]: any;
2732
+ };
2733
+ indexes: {
2734
+ names: string[];
2735
+ options: IndexOptions;
2736
+ }[];
2737
+ singleTableInheritance?: true;
2738
+ }
2739
+ /**
2740
+ * @reflection never
2741
+ */
2742
+ export declare class ReflectionClass<T> {
2743
+ readonly type: TypeClass | TypeObjectLiteral;
2744
+ readonly parent?: ReflectionClass<any> | undefined;
2745
+ /**
2746
+ * The description, extracted from the class JSDoc @description.
2747
+ */
2748
+ description: string;
2749
+ /**
2750
+ * The tags, extracted from the class JSDoc @tag.
2751
+ */
2752
+ tags?: TagsReflection;
2753
+ /**
2754
+ * A place where arbitrary data is stored, usually set via decorator t.data.
2755
+ */
2756
+ data: {
2757
+ [name: string]: any;
2758
+ };
2759
+ /**
2760
+ * The unique entity name.
2761
+ *
2762
+ * ```typescript
2763
+ * @entity.name('user')
2764
+ * class User {
2765
+ *
2766
+ * }
2767
+ * ```
2768
+ */
2769
+ name?: string;
2770
+ databaseSchemaName?: string;
2771
+ disableConstructor: boolean;
2772
+ /**
2773
+ * The collection name, used in database context (also known as table name).
2774
+ *
2775
+ * Usually, if this is not set, `name` will be used.
2776
+ *
2777
+ * ```typescript
2778
+ * @entity.collection('users').name('user')
2779
+ * class User {
2780
+ *
2781
+ * }
2782
+ * ```
2783
+ */
2784
+ collectionName?: string;
2785
+ /**
2786
+ * True when @entity.singleTableInheritance was set.
2787
+ */
2788
+ singleTableInheritance: boolean;
2789
+ /**
2790
+ * Contains all indexed, multi-field using entity.index and all indexes from properties.
2791
+ *
2792
+ * ```typescript
2793
+ * @entity
2794
+ * .collection('users')
2795
+ * .name('user')
2796
+ * .index(['username', 'email'])
2797
+ * .index(['email', 'region'], {unique: true})
2798
+ * class User {
2799
+ * username: string;
2800
+ * email: string;
2801
+ * }
2802
+ * ```
2803
+ */
2804
+ indexes: {
2805
+ names: string[];
2806
+ options: IndexOptions;
2807
+ }[];
2808
+ protected propertyNames: string[];
2809
+ protected methodNames: string[];
2810
+ protected properties: ReflectionProperty[];
2811
+ protected propertyAliases: Map<string, string>;
2812
+ protected methods: ReflectionMethod[];
2813
+ protected methodAliases: Map<string, string>;
2814
+ /**
2815
+ * References and back references.
2816
+ */
2817
+ protected references: ReflectionProperty[];
2818
+ protected primaries: ReflectionProperty[];
2819
+ protected autoIncrements: ReflectionProperty[];
2820
+ /**
2821
+ * If a custom validator method was set via @t.validator, then this is the method name.
2822
+ */
2823
+ validationMethod?: string | symbol | number | TypeTemplateLiteral;
2824
+ /**
2825
+ * A class using @t.singleTableInheritance registers itself in this array in its super class.
2826
+ */
2827
+ subClasses: ReflectionClass<any>[];
2828
+ constructor(type: TypeClass | TypeObjectLiteral, parent?: ReflectionClass<any> | undefined);
2829
+ clone(): ReflectionClass<any>;
2830
+ toString(): string;
2831
+ getPropertiesDeclaredInConstructor(): ReflectionProperty[];
2832
+ clearJitContainer(): void;
2833
+ getJitContainer(): any;
2834
+ getClassType(): ClassType;
2835
+ getClassName(): string;
2836
+ createDefaultObject(): object;
2837
+ getName(): string;
2838
+ getDescription(): string;
2839
+ getCollectionName(): string;
2840
+ hasProperty(name: string | symbol | number): boolean;
2841
+ hasMethod(name: string | symbol | number): boolean;
2842
+ getPrimary(): ReflectionProperty;
2843
+ getAutoIncrement(): ReflectionProperty | undefined;
2844
+ isSchemaOf(classType: ClassType): boolean;
2845
+ hasPrimary(): boolean;
2846
+ getPrimaries(): ReflectionProperty[];
2847
+ /**
2848
+ * Returns the ReflectionClass object from parent/super class, if available.
2849
+ */
2850
+ getSuperReflectionClass(): ReflectionClass<any> | undefined;
2851
+ removeProperty(name: string | number | symbol): void;
2852
+ registerProperty(property: ReflectionProperty): void;
2853
+ addProperty(prop: {
2854
+ name: number | string | symbol;
2855
+ optional?: true;
2856
+ readonly?: true;
2857
+ description?: string;
2858
+ visibility?: ReflectionVisibility;
2859
+ type: Type;
2860
+ default?: any;
2861
+ tags?: TagsReflection;
2862
+ }): ReflectionProperty;
2863
+ registerMethod(method: ReflectionMethod): void;
2864
+ add(member: Type): void;
2865
+ assignedSingleTableInheritanceSubClassesByIdentifier?: {
2866
+ [id: string]: ReflectionClass<any>;
2867
+ };
2868
+ getAssignedSingleTableInheritanceSubClassesByIdentifier(): {
2869
+ [id: string]: ReflectionClass<any>;
2870
+ } | undefined;
2871
+ hasSingleTableInheritanceSubClasses(): boolean;
2872
+ getSingleTableInheritanceDiscriminantName(): string;
2873
+ applyDecorator(data: EntityData): void;
2874
+ static from<T>(classTypeIn?: ReceiveType<T> | AbstractClassType<T> | TypeClass | TypeObjectLiteral | ReflectionClass<any>, args?: any[]): ReflectionClass<T>;
2875
+ getIndexSignatures(): void;
2876
+ getPropertyNames(): (string | number | symbol)[];
2877
+ getProperties(): ReflectionProperty[];
2878
+ getPropertiesInGroup(...group: string[]): ReflectionProperty[];
2879
+ getMethodNames(): (string | number | symbol)[];
2880
+ getMethods(): ReflectionMethod[];
2881
+ /**
2882
+ * Returns references and back references.
2883
+ */
2884
+ getReferences(): ReflectionProperty[];
2885
+ getConstructorOrUndefined(): ReflectionMethod | undefined;
2886
+ getPropertyOrUndefined(name: string | number | symbol | TypeTemplateLiteral): ReflectionProperty | undefined;
2887
+ getProperty(name: string | number | symbol): ReflectionProperty;
2888
+ getMethodParameters(name: string | number | symbol): ReflectionParameter[];
2889
+ getMethodOrUndefined(name: string | number | symbol | TypeTemplateLiteral): ReflectionMethod | undefined;
2890
+ getMethod(name: string | number | symbol): ReflectionMethod;
2891
+ hasCircularReference(): boolean;
2892
+ serializeType(): SerializedTypes;
2893
+ setTags(tags: TagsReflection): void;
2894
+ getTags(): TagsReflection;
2895
+ isHidden(): boolean;
2896
+ isIgnored(): boolean;
2897
+ isInternal(): boolean;
2898
+ isReadonly(): boolean;
2899
+ getAlias(): string[];
2900
+ getTitle(): string | undefined;
2901
+ getPermission(): string[];
2902
+ getDomain(): string | undefined;
2903
+ /**
2904
+ * All references have a counter-part. This methods finds it and errors if not possible.
2905
+ *
2906
+ * If the given reference is a owning reference it finds the correct backReference,
2907
+ * which can be found by checking all reference options.mappedBy.
2908
+ *
2909
+ * If the given reference is a back reference it finds the owning reference,
2910
+ * which can be found by using its options.mappedBy.
2911
+ *
2912
+ * Alternatively we simply check for resolvedClassType to be given `classType`, and if only one
2913
+ * found, we return it. When more than one found, we throw an error saying the user he
2914
+ * should make its relation mapping not ambiguous.
2915
+ */
2916
+ findReverseReference(toClassType: ClassType, fromReference: ReflectionProperty): ReflectionProperty;
2917
+ extractPrimaryKey(item: object): Partial<T>;
2918
+ }
2919
+ export declare type __ΩReceiveType = any[];
2920
+ export declare type __ΩSerializerFn = any[];
2921
+ /**
2922
+ * This is a comparator function for the snapshots. They are either string, number, boolean, array, or objects.
2923
+ * No date, moment, or custom classes involved here.
2924
+ */
2925
+ export declare function genericEqual(a: any, b: any): boolean;
2926
+ export declare function getChangeDetector<T extends object>(classSchema: ReflectionClass<T>): (last: any, current: any, item: T) => ItemChanges<T> | undefined;
2927
+ export declare function buildChanges<T extends object>(classSchema: ReflectionClass<T>, lastSnapshot: any, item: T): Changes<T>;
2928
+ export declare enum UnpopulatedCheck {
2929
+ None = 0,//returns undefined
2930
+ Throw = 1,//throws regular error
2931
+ ReturnSymbol = 2
2932
+ }
2933
+ export declare const unpopulatedSymbol: unique symbol;
2934
+ export interface TypeSettings {
2935
+ registeredEntities: {
2936
+ [name: string]: ClassType;
2937
+ };
2938
+ unpopulatedCheck: UnpopulatedCheck;
2939
+ }
2940
+ export declare const typeSettings: TypeSettings;
2941
+ export interface TypedArrayClassType<T> {
2942
+ new (...args: any[]): T;
2943
+ readonly BYTES_PER_ELEMENT: number;
2944
+ }
2945
+ export interface TypedArray {
2946
+ /**
2947
+ * The size in bytes of each element in the array.
2948
+ */
2949
+ readonly BYTES_PER_ELEMENT: number;
2950
+ /**
2951
+ * The ArrayBuffer instance referenced by the array.
2952
+ */
2953
+ readonly buffer: ArrayBufferLike;
2954
+ /**
2955
+ * The length of the array.
2956
+ */
2957
+ readonly length: number;
2958
+ /**
2959
+ * The length in bytes of the array.
2960
+ */
2961
+ readonly byteLength: number;
2962
+ /**
2963
+ * The offset in bytes of the array.
2964
+ */
2965
+ readonly byteOffset: number;
2966
+ }
2967
+ export declare function nodeBufferToTypedArray<K>(buf: Buffer, type: TypedArrayClassType<K>): K;
2968
+ /**
2969
+ * When using Buffer.from() node is using a buffer from the buffer pool.
2970
+ * This makes it necessary to create the given TypedArray using byteOffset and byteLength accordingly.
2971
+ *
2972
+ * Note: The created TypedArray.buffer is pointing probably to a larger Buffer. Make sure
2973
+ * to use byteLength/byeOffset correctly or use typedArrayToArrayBuffer() if you want to use
2974
+ * a raw ArrayBuffer that represents the actual data correctly.
2975
+ */
2976
+ export declare function base64ToTypedArray<K>(base64: string, type: TypedArrayClassType<K>): K;
2977
+ /**
2978
+ * Creates a new fresh ArrayBuffer with given data.
2979
+ * Note: Regular Buffer.from(base64, 'base64) creates in Node a shared buffer, this function makes
2980
+ * sure a copy happens and the ArrayBuffer is not shared.
2981
+ */
2982
+ export declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
2983
+ /**
2984
+ * When using Buffer.from() node is using a buffer from the buffer pool.
2985
+ * This makes it necessary to create the a new ArrayType using slice to make a copy.
2986
+ *
2987
+ * This makes a copy.
2988
+ */
2989
+ export declare function nodeBufferToArrayBuffer<K>(buf: Uint8Array | ArrayBuffer): ArrayBuffer;
2990
+ /**
2991
+ * In node environment the TypedArray.buffer is probably a larger buffer from the buffer pool.
2992
+ * This makes it necessary to create a Buffer with offset & length so that it accurately represents
2993
+ * the given TypedArray.
2994
+ */
2995
+ export declare function typedArrayToBuffer<K>(typedArray: TypedArray): Buffer;
2996
+ export declare function arrayBufferToBase64(arrayBuffer: ArrayBuffer): string;
2997
+ export declare function typedArrayToBase64(typedArray: TypedArray): string;
2998
+ /**
2999
+ * Same as Buffer.from() but creates a ArrayBuffer that is not shared.
3000
+ */
3001
+ export declare function arrayBufferFrom(data: string, encoding?: string): ArrayBuffer;
3002
+ /**
3003
+ * Same as Buffer.from(arrayBuffer).toString(encoding), but more in line with the current API.
3004
+ */
3005
+ export declare function arrayBufferTo(arrayBuffer: ArrayBuffer, encoding?: string | "utf8" | "base64" | "ascii"): string;
3006
+ export declare type __ΩUnpopulatedCheck = any[];
3007
+ export declare type __ΩTypeSettings = any[];
3008
+ export declare type __ΩTypedArrayClassType = any[];
3009
+ export declare type __ΩTypedArray = any[];
3010
+ export type ClassDecoratorFn = (classType: AbstractClassType, property?: string, parameterIndexOrDescriptor?: any) => void;
3011
+ export type PropertyDecoratorFn = (prototype: object, property?: number | string | symbol, parameterIndexOrDescriptor?: any) => void;
3012
+ export type FluidDecorator<T, D extends Function> = {
3013
+ [name in keyof T]: T[name] extends (...args: infer K) => any ? (...args: K) => D & FluidDecorator<T, D> : D & FluidDecorator<T, D> & {
3014
+ _data: ExtractApiDataType<T>;
3015
+ };
3016
+ };
3017
+ export declare function createFluidDecorator<API extends APIClass<any> | APIProperty<any>, D extends Function>(api: API, modifier: {
3018
+ name: string;
3019
+ args?: any;
3020
+ Ω?: any;
3021
+ }[], collapse: (modifier: {
3022
+ name: string;
3023
+ args?: any;
3024
+ }[], target: any, property?: string, parameterIndexOrDescriptor?: any) => void, returnCollapse?: boolean, fluidFunctionSymbol?: symbol): FluidDecorator<ExtractClass<API>, D>;
3025
+ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
3026
+ export type Merge<U> = {
3027
+ [K in keyof U]: U[K] extends ((...a: infer A) => infer R) ? R extends DualDecorator ? (...a: A) => PropertyDecoratorFn & R & U : (...a: A) => R : never;
3028
+ };
3029
+ /**
3030
+ * A dual decorator is a decorator that can be used on a class and class property.
3031
+ */
3032
+ export type DualDecorator = void & {
3033
+ __DualDecorator?: true;
3034
+ };
3035
+ export declare function mergeDecorator<T extends any[]>(...args: T): Merge<Omit<UnionToIntersection<T[number]>, "_fetch" | "t">>;
3036
+ export interface ClassApiTypeInterface<T> {
3037
+ t: T;
3038
+ onDecorator?: (classType: ClassType, property?: string, parameterIndexOrDescriptor?: any) => void;
3039
+ }
3040
+ export type APIClass<T> = ClassType<ClassApiTypeInterface<T>>;
3041
+ export type ExtractClass<T> = T extends ClassType<infer K> ? K : never;
3042
+ export type ExtractApiDataType<T> = T extends AbstractClassType<infer K> ? K extends {
3043
+ t: infer P;
3044
+ } ? P : never : (T extends {
3045
+ t: infer P;
3046
+ } ? P : never);
3047
+ export type ClassDecoratorResult<API extends APIClass<any>> = FluidDecorator<ExtractClass<API>, ClassDecoratorFn> & DecoratorAndFetchSignature<API, ClassDecoratorFn>;
3048
+ export declare function createClassDecoratorContext<API extends APIClass<any>, T = ExtractApiDataType<API>>(apiType: API): ClassDecoratorResult<API>;
3049
+ export interface PropertyApiTypeInterface<T> {
3050
+ t: T;
3051
+ onDecorator?: (target: ClassType, property: string | undefined, parameterIndexOrDescriptor?: any) => void;
3052
+ }
3053
+ export type APIProperty<T> = ClassType<PropertyApiTypeInterface<T>>;
3054
+ export type DecoratorAndFetchSignature<API extends APIProperty<any>, FN extends (...args: any[]) => any> = FN & {
3055
+ _fetch: (...args: Parameters<FN>) => ExtractApiDataType<API> | undefined;
3056
+ };
3057
+ export type PropertyDecoratorResult<API extends APIProperty<any>> = FluidDecorator<ExtractClass<API>, PropertyDecoratorFn> & DecoratorAndFetchSignature<API, PropertyDecoratorFn>;
3058
+ export declare function createPropertyDecoratorContext<API extends APIProperty<any>>(apiType: API): PropertyDecoratorResult<API>;
3059
+ export type FreeDecoratorFn<API> = {
3060
+ (target?: any, property?: number | string | symbol, parameterIndexOrDescriptor?: any): ExtractApiDataType<API>;
3061
+ } & {
3062
+ _data: ExtractApiDataType<API>;
3063
+ };
3064
+ export type FreeFluidDecorator<API> = {
3065
+ [name in keyof ExtractClass<API>]: ExtractClass<API>[name] extends (...args: infer K) => any ? (...args: K) => FreeFluidDecorator<API> : FreeFluidDecorator<API>;
3066
+ } & FreeDecoratorFn<API>;
3067
+ export type FreeDecoratorResult<API extends APIClass<any>> = FreeFluidDecorator<API> & {
3068
+ _fluidFunctionSymbol: symbol;
3069
+ };
3070
+ export declare function createFreeDecoratorContext<API extends APIClass<any>, T = ExtractApiDataType<API>>(apiType: API): FreeDecoratorResult<API>;
3071
+ export declare function isDecoratorContext<API extends APIClass<any>>(context: FreeDecoratorResult<API>, fn: Function): fn is FreeFluidDecorator<API>;
3072
+ export declare type __ΩClassDecoratorFn = any[];
3073
+ export declare type __ΩPropertyDecoratorFn = any[];
3074
+ export declare type __ΩFluidDecorator = any[];
3075
+ export declare type __ΩUnionToIntersection = any[];
3076
+ export declare type __ΩMerge = any[];
3077
+ export declare type __ΩDualDecorator = any[];
3078
+ export declare type __ΩClassApiTypeInterface = any[];
3079
+ export declare type __ΩAPIClass = any[];
3080
+ export declare type __ΩExtractClass = any[];
3081
+ export declare type __ΩExtractApiDataType = any[];
3082
+ export declare type __ΩClassDecoratorResult = any[];
3083
+ export declare type __ΩPropertyApiTypeInterface = any[];
3084
+ export declare type __ΩAPIProperty = any[];
3085
+ export declare type __ΩDecoratorAndFetchSignature = any[];
3086
+ export declare type __ΩPropertyDecoratorResult = any[];
3087
+ export declare type __ΩFreeDecoratorFn = any[];
3088
+ export declare type __ΩFreeFluidDecorator = any[];
3089
+ export declare type __ΩFreeDecoratorResult = any[];
3090
+ declare class TDecorator {
3091
+ t: TData;
3092
+ onDecorator(target: any, property?: string, parameterIndexOrDescriptor?: any): void;
3093
+ type<T>(type: ReceiveType<T> | ClassType): void;
3094
+ /**
3095
+ * Marks the method as validator. Is executed for each is/validate call.
3096
+ *
3097
+ * ```typescript
3098
+ *
3099
+ * class MyClass {
3100
+ * field1: string;
3101
+ * field2: string;
3102
+ *
3103
+ * @t.validator
3104
+ * validate(): ValidatorError | undefined {
3105
+ * return new ValidatorError('invalid', 'MyClass is invalid');
3106
+ * }
3107
+ * }
3108
+ *
3109
+ * ```
3110
+ */
3111
+ get validator(): void;
3112
+ validate(...validators: ValidateFunction[]): void;
3113
+ serialize(serializer: SerializerFn): void;
3114
+ deserialize(deserializer: SerializerFn): void;
3115
+ data(name: string, value: any): void;
3116
+ }
3117
+ export declare const t: PropertyDecoratorResult<typeof TDecorator>;
3118
+ declare class EntityDecorator {
3119
+ t: EntityData;
3120
+ onDecorator(target: any): void;
3121
+ name(name: string): void;
3122
+ collection(name: string): void;
3123
+ /**
3124
+ * Disables calling the constructor when deserializing.
3125
+ */
3126
+ disableConstructor(): void;
3127
+ databaseSchema(name: string): void;
3128
+ index(names: string[], options?: IndexOptions): void;
3129
+ singleTableInheritance(): void;
3130
+ data(name: string, value: any): void;
3131
+ /**
3132
+ * Exclude this entity from database migrations.
3133
+ */
3134
+ excludeMigration(): void;
3135
+ }
3136
+ export declare const entity: ClassDecoratorResult<typeof EntityDecorator>;
3137
+ interface DeferredDecorator {
3138
+ data: any;
3139
+ target: any;
3140
+ property?: string;
3141
+ parameterIndexOrDescriptor?: any;
3142
+ }
3143
+ export declare function isWithDeferredDecorators(obj: any): obj is {
3144
+ __decorators: DeferredDecorator[];
3145
+ };
3146
+ /**
3147
+ * Returns a sensible default value for a given type.
3148
+ * Sensible means it satisfies the type checker, but not necessarily attached validators.
3149
+ */
3150
+ export declare function defaultValue(type: Type): any;
3151
+ type UnionToIntersection$1<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
3152
+ /**
3153
+ * Function to mixin multiple classes together and create a new class, which can be extended from.
3154
+ *
3155
+ * The first entry of the mixin() call will be used as base class.
3156
+ *
3157
+ * @example
3158
+ * ```typescript
3159
+ *
3160
+ * class Timestampable {
3161
+ * createdAt: Date = new Date;
3162
+ * updatedAt: Date = new Date;
3163
+ * }
3164
+ *
3165
+ * class SoftDeleted {
3166
+ * deletedAt?: Date;
3167
+ * deletedBy?: string;
3168
+ * }
3169
+ *
3170
+ * class User extends mixin(Timestampable, SoftDeleted) {
3171
+ * id: number = 0;
3172
+ * constructor(public username: string) {}
3173
+ * }
3174
+ * ```
3175
+ */
3176
+ export declare function mixin<T extends AbstractClassType[]>(...classTypes: T): ClassType<UnionToIntersection$1<ExtractClassType<T[number]>>>;
3177
+ export type Resolver = (path: string) => Type | undefined;
3178
+ export declare function resolvePath<T>(path: string, type?: ReceiveType<T>): Type;
3179
+ export declare function pathResolver<T>(type?: ReceiveType<T>, jitStack?: JitStack): Resolver;
3180
+ export declare type __ΩResolver = any[];
3181
+ export declare function isReferenceInstance(obj: any): boolean;
3182
+ export declare function getReferenceInfo<T>(obj: T): ReferenceInfo<T> | undefined;
3183
+ export declare function getReferenceItemInfo<T>(obj: T): ReferenceItemInfo<T> | undefined;
3184
+ export declare function getOrCreateReferenceItemInfo<T>(obj: T): ReferenceItemInfo<T>;
3185
+ export declare function isReferenceHydrated(obj: any): boolean;
3186
+ export declare function markAsHydrated(item: any): void;
3187
+ export interface ReferenceInfo<T> {
3188
+ hydrator?: (item: T) => Promise<void>;
3189
+ }
3190
+ export interface ReferenceItemInfo<T> {
3191
+ hydrated: boolean;
3192
+ }
3193
+ export declare const referenceSymbol: unique symbol;
3194
+ export declare const referenceItemSymbol: unique symbol;
3195
+ export declare function createReference<T>(type: ClassType<T> | Type | ReflectionClass<any>, pk: {
3196
+ [name: string]: any;
3197
+ }): T;
3198
+ export declare function createReferenceClass<T>(reflection: ReflectionClass<any>): ClassType<T>;
3199
+ export declare type __ΩReferenceInfo = any[];
3200
+ export declare type __ΩReferenceItemInfo = any[];
3201
+ interface RegistryDecorator<T> {
3202
+ predicate: (type: Type) => boolean;
3203
+ v: T;
3204
+ }
3205
+ export declare class TypeRegistry<T> {
3206
+ protected results: {
3207
+ [kind in ReflectionKind]?: T;
3208
+ };
3209
+ classes: Map<ClassType<any>, T>;
3210
+ protected decorators: RegistryDecorator<T>[];
3211
+ clear(): void;
3212
+ get(type: Type): T | undefined;
3213
+ decorator(predicate: (type: Type) => boolean, v: T): void;
3214
+ /**
3215
+ * Registers a template for all binary classes: ArrayBuffer, Uint8Array, Int8Array, etc.
3216
+ */
3217
+ setBinary(v: T): void;
3218
+ setNumeric(v: T): void;
3219
+ /**
3220
+ * Registers a template for a given class type.
3221
+ *
3222
+ * As soon as a single template has registered for the given classType the template registry
3223
+ * only returns templates for this particular classType and omits all general purpose ReflectionKind.class templates for this particular classType.
3224
+ */
3225
+ setClass(classType: ClassType, v: T): void;
3226
+ /**
3227
+ * Removes all registered templates.
3228
+ */
3229
+ remove(kind: ReflectionKind): void;
3230
+ /**
3231
+ * Registers a new template and replaces all existing (added via register,prepend,append).
3232
+ */
3233
+ set(kind: ReflectionKind | ReflectionKind[] | ((type: Type) => boolean), v: T): void;
3234
+ }
3235
+ export declare class NoTypeReceived extends Error {
3236
+ constructor(message?: string);
3237
+ }
3238
+ /**
3239
+ * Returns a new UUID v4 as string.
3240
+ */
3241
+ export declare function uuid(): string;
3242
+ /**
3243
+ * Writes a new uuid v4 into an existing buffer, and returns the same buffer.
3244
+ */
3245
+ export declare function writeUuid(buffer: Uint8Array, offset?: number): Uint8Array;
3246
+ /**
3247
+ * Stringify an exising Uint8Array buffer.
3248
+ */
3249
+ export declare function stringifyUuid(buffer: Uint8Array, offset?: number): string;
3250
+ export type Binary = ArrayBuffer | Uint8Array | Int8Array | Uint8ClampedArray | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array;
3251
+ export type JSONPartial<T> = T extends Date ? string : T extends Array<infer K> ? Array<JSONPartial<K>> : T extends Binary ? string : T extends object ? JSONPartialObject<T> : T extends string ? number | T : T extends boolean ? number | string | T : T extends bigint ? number | string | T : T extends number ? bigint | string | T : T;
3252
+ export type JSONPartialObject<T> = {
3253
+ [name in keyof T]?: T[name] | null;
3254
+ };
3255
+ export type JSONSingle<T> = T extends Date ? string | Date : T extends Array<infer K> ? Array<JSONSingle<K>> : T extends Binary ? string : T extends object ? JSONEntity<T> : T extends string ? string | number | boolean | undefined : T extends boolean ? T | number | string : T extends number ? T | string : T;
3256
+ export type JSONEntity<T> = {
3257
+ [name in keyof T]: JSONSingle<T[name]>;
3258
+ };
3259
+ export declare function regExpFromString(v: string): RegExp;
3260
+ export declare type __ΩBinary = any[];
3261
+ export declare type __ΩJSONPartial = any[];
3262
+ export declare type __ΩJSONPartialObject = any[];
3263
+ export declare type __ΩJSONSingle = any[];
3264
+ export declare type __ΩJSONEntity = any[];
3265
+ /**
3266
+ * Casts/coerces a given data structure to the target data type and validates all attached validators.
3267
+ *
3268
+ * Same as validatedDeserialize().
3269
+ *
3270
+ * @throws ValidationError if casting or validation fails
3271
+ */
3272
+ export declare function cast<T>(data: JSONPartial<T> | unknown, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType<T>): T;
3273
+ /**
3274
+ * Same as cast but returns a ready to use function. Used to improve performance.
3275
+ */
3276
+ export declare function castFunction<T>(serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType<T>): (data: JSONPartial<T> | unknown, options?: SerializationOptions) => T;
3277
+ /**
3278
+ * Deserialize given data structure from JSON data objects to JavaScript objects, without running any validators.
3279
+ *
3280
+ * Types that are already correct will be used as-is.
3281
+ *
3282
+ * ```typescript
3283
+ * interface Data {
3284
+ * created: Date;
3285
+ * }
3286
+ *
3287
+ * const data = deserialize<Data>({created: '2009-02-13T23:31:30.123Z'});
3288
+ * //data is {created: Date(2009-02-13T23:31:30.123Z)}
3289
+ *
3290
+ * @throws ValidationError when deserialization fails.
3291
+ * ```
3292
+ */
3293
+ export declare function deserialize<T>(data: JSONPartial<T> | unknown, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType<T>): T;
3294
+ /**
3295
+ * Same as deserialize but returns a ready to use function. Used to improve performance.
3296
+ */
3297
+ export declare function deserializeFunction<T>(serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType<T>): SerializeFunction<any, T>;
3298
+ /**
3299
+ * Patch serialization for deep dot paths, e.g. `{'user.shippingAddress.street': 'abc'}`
3300
+ * If a naming strategy is used, it could be converted to `{'user.shipping_address.street': 'abc'}`.
3301
+ */
3302
+ export declare function patch<T>(data: DeepPartial<T>, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType<T>): (data: JSONPartial<T> | unknown) => T;
3303
+ /**
3304
+ * Create a serializer/deserializer function including validator for the given type for a patch structure.
3305
+ * This is handy for deep patch structures like e.g '{user.address.street: "new street"}'.
3306
+ */
3307
+ export declare function getPatchSerializeFunction(type: TypeClass | TypeObjectLiteral, registry: TemplateRegistry, namingStrategy?: NamingStrategy): (data: any, state?: SerializationOptions, patch?: {
3308
+ normalizeArrayIndex: boolean;
3309
+ }) => any;
3310
+ /**
3311
+ * Serialize given data structure to JSON data objects (not a JSON string).
3312
+ *
3313
+ * The resulting JSON object can be stringified using JSON.stringify().
3314
+ *
3315
+ * ```typescript
3316
+ * interface Data {
3317
+ * created: Date;
3318
+ * }
3319
+ *
3320
+ * const json = serialize<Data>({created: new Date(1234567890123)});
3321
+ * //json is {created: '2009-02-13T23:31:30.123Z'}
3322
+ *
3323
+ * const jsonString = JSON.stringify(json);
3324
+ * //jsonString is '{"created":"2009-02-13T23:31:30.123Z"}'
3325
+ * ```
3326
+ *
3327
+ * @throws ValidationError when serialization or validation fails.
3328
+ */
3329
+ export declare function serialize<T>(data: T, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType<T>): JSONSingle<T>;
3330
+ /**
3331
+ * Same as serialize but returns a ready to use function. Used to improve performance.
3332
+ */
3333
+ export declare function serializeFunction<T>(serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType<T>): SerializeFunction<T>;
3334
+ /**
3335
+ * Clones a class instance deeply.
3336
+ */
3337
+ export declare function cloneClass<T>(target: T, options?: SerializationOptions): T;
3338
+ /**
3339
+ * Tries to deserialize given data as T, and throws an error if it's not possible or validation after conversion fails.
3340
+ *
3341
+ * @deprecated use cast() instead
3342
+ *
3343
+ * @throws ValidationError when serialization or validation fails.
3344
+ */
3345
+ export declare function validatedDeserialize<T>(data: any, options?: SerializationOptions, serializerToUse?: Serializer, namingStrategy?: NamingStrategy, type?: ReceiveType<T>): T;
3346
+ declare class SnapshotSerializer extends Serializer {
3347
+ name: string;
3348
+ protected registerSerializers(): void;
3349
+ }
3350
+ export declare const snapshotSerializer: SnapshotSerializer;
3351
+ /**
3352
+ * Creates a new JIT compiled function to convert the class instance to a snapshot.
3353
+ * A snapshot is essentially the class instance as `plain` serialization while references are
3354
+ * stored only as their primary keys.
3355
+ *
3356
+ * Generated function is cached.
3357
+ */
3358
+ export declare function getConverterForSnapshot(reflectionClass: ReflectionClass<any>): (value: any) => any;
3359
+ /**
3360
+ * Creates a snapshot using getConverterForSnapshot().
3361
+ */
3362
+ export declare function createSnapshot<T>(reflectionClass: ReflectionClass<T>, item: T): any;
3363
+ /**
3364
+ * Extracts the primary key of a snapshot and converts to class type.
3365
+ */
3366
+ export declare function getPrimaryKeyExtractor<T>(reflectionClass: ReflectionClass<T>): (value: any) => Partial<T>;
3367
+ /**
3368
+ * Creates a primary key hash generator that takes an item from any format
3369
+ * converts it to class format, then to plain, then uses the primitive values to create a string hash.
3370
+ *
3371
+ * This function is designed to work on the plain values (db records or json values)
3372
+ */
3373
+ export declare function getPrimaryKeyHashGenerator(reflectionClass: ReflectionClass<any>, serializerToUse?: Serializer): (value: any) => string;
3374
+ export declare function getSimplePrimaryKeyHashGenerator(reflectionClass: ReflectionClass<any>): (data: PrimaryKeyFields<any>) => string;
3375
+ /**
3376
+ * ```typescript
3377
+ * const validator = getValidatorFunction<MyType>();
3378
+ *
3379
+ * const errors: ValidationErrorItem[] = [];
3380
+ * const valid = validator(data, {errors})
3381
+ *
3382
+ * if (errors.length) console.log(errors); //validation failed if not empty
3383
+ * ```
3384
+ */
3385
+ export declare function getValidatorFunction<T>(serializerToUse?: Serializer, receiveType?: ReceiveType<T>): Guard<T>;
3386
+ export declare function is<T>(data: any, serializerToUse?: Serializer, errors?: ValidationErrorItem[], receiveType?: ReceiveType<T>): data is T;
3387
+ export declare function guard<T>(serializerToUse?: Serializer, receiveType?: ReceiveType<T>): Guard<T>;
3388
+ /**
3389
+ * @throws ValidationError when type is invalid.
3390
+ */
3391
+ export declare function assert<T>(data: any, serializerToUse?: Serializer, receiveType?: ReceiveType<T>): asserts data is T;
3392
+ export type AutoId = number & PrimaryKey & AutoIncrement & Positive;
3393
+ export declare type __ΩAutoId = any[];
3394
+ export declare const validators: {
3395
+ [name in string]?: (...args: any[]) => (value: any) => ValidatorError | undefined;
3396
+ };
3397
+ type AssignableType = Type | string | boolean | number | symbol | bigint | undefined | null;
3398
+ type StackEntry$1 = {
3399
+ left: Type;
3400
+ right: Type;
3401
+ };
3402
+ /**
3403
+ * The check of `extends` in Typescript. This function can be read as `left extends right`.
3404
+ *
3405
+ * See https://www.typescriptlang.org/docs/handbook/type-compatibility.html#any-unknown-object-void-undefined-null-and-never-assignability
3406
+ * This algo follows strict mode.
3407
+ *
3408
+ * Warning: If you do not pass Type objects, typeInfer() is used which does not use cache (it is designed to be called withing type processor)
3409
+ */
3410
+ export declare function isExtendable(leftValue: AssignableType, rightValue: AssignableType, extendStack?: StackEntry$1[]): boolean;
3411
+ export declare function _isExtendable(left: Type, right: Type, extendStack?: StackEntry$1[]): boolean;
3412
+ /**
3413
+ * We don't want to embed in each and every file the type definition of Promise<t>,
3414
+ * so we do it ondemand at runtime instead. This saves bundle size.
3415
+ */
3416
+ export declare function createPromiseObjectLiteral(type: TypePromise): TypeObjectLiteral;
3417
+ export declare function parametersToTuple(parameters: TypeParameter[]): TypeTuple;
3418
+ export declare function extendTemplateLiteral(left: TypeLiteral | TypeTemplateLiteral, right: TypeTemplateLiteral): boolean;
3419
+
3420
+ export {
3421
+ Partial$1 as Partial,
3422
+ typeAnnotation as metaAnnotation,
3423
+ };
3424
+
3425
+ export {};