/
index.ts
1254 lines (1178 loc) · 37.6 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @packageDocumentation
* @module Types
*/
import {
JsonTypeInfoAs,
JsonTypeInfoId,
JsonIncludeType,
JsonFormatShape,
JsonPropertyAccess,
ObjectIdGenerator,
JsonFilterType,
PropertyNamingStrategy,
JsonCreatorMode,
JsonSetterNulls
} from '../decorators';
import {
DeserializationFeature,
SerializationFeature
} from '../databind';
/**
* https://stackoverflow.com/a/55032655/4637638
*/
export type Modify<T, R> = Omit<T, keyof R> & R;
// before typescript@3.5
// type Modify<T, R> = Pick<T, Exclude<keyof T, keyof R>> & R;
/**
* Helper type that represents a general JavaScript type.
*/
export type ClassType<T> = (new () => T) | (new (...args: any[]) => T) |
((...args: any[]) => T) | ((...args: any[]) => ((cls: any) => T));
export type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift';
export type FixedLengthArray<T, L extends number, TObj = [T, ...Array<T>]> =
Pick<TObj, Exclude<keyof TObj, ArrayLengthMutationKeys>>
& {
[ I: number ]: T;
readonly length: L;
[Symbol.iterator]: () => IterableIterator<T>;
};
/**
* Helper interface used to declare a List of ClassType recursively.
*/
export interface ClassList<T> extends Array<any> {
[index: number]: T | ClassList<T>;
0: T;
}
/**
* Decorator type with at least one required option.
*/
export type JacksonDecoratorWithOptions<T extends JsonDecoratorOptions, TDecorator> = (options: T) => TDecorator;
/**
* Decorator type with optional options.
*/
export type JacksonDecoratorWithOptionalOptions<T extends JsonDecoratorOptions, TDecorator> = (options?: T) => TDecorator;
/**
* Decorator type.
*/
export type JacksonDecorator<T extends JsonDecoratorOptions, TDecorator> =
JacksonDecoratorWithOptions<T, TDecorator> | JacksonDecoratorWithOptionalOptions<T, TDecorator>;
/**
* Decorator type for {@link JsonAlias}.
*/
export type JsonAliasDecorator = JacksonDecoratorWithOptions<JsonAliasOptions, PropertyDecorator & ParameterDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonAppend}.
*/
export type JsonAppendDecorator = JacksonDecoratorWithOptions<JsonAppendOptions, ClassDecorator>;
/**
* Decorator type for {@link JsonClassType}.
*/
export type JsonClassTypeDecorator = JacksonDecoratorWithOptions<JsonClassTypeOptions,
PropertyDecorator & ParameterDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonDeserialize}.
*/
export type JsonDeserializeDecorator = JacksonDecoratorWithOptions<JsonDeserializeOptions,
ClassDecorator & PropertyDecorator & ParameterDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonFilter}.
*/
export type JsonFilterDecorator = JacksonDecoratorWithOptions<JsonFilterOptions,
ClassDecorator & PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonIdentityInfo}.
*/
export type JsonIdentityInfoDecorator = JacksonDecoratorWithOptions<JsonIdentityInfoOptions,
ClassDecorator & PropertyDecorator & ParameterDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonIdentityReference}.
*/
export type JsonIdentityReferenceDecorator = JacksonDecoratorWithOptions<JsonIdentityReferenceOptions,
ClassDecorator & PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonNaming}.
*/
export type JsonNamingDecorator = JacksonDecoratorWithOptions<JsonNamingOptions, ClassDecorator>;
/**
* Decorator type for {@link JsonSerialize}.
*/
export type JsonSerializeDecorator = JacksonDecoratorWithOptions<JsonSerializeOptions,
ClassDecorator & PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonSubTypes}.
*/
export type JsonSubTypesDecorator = JacksonDecoratorWithOptions<JsonSubTypesOptions,
ClassDecorator & MethodDecorator & PropertyDecorator & ParameterDecorator>;
/**
* Decorator type for {@link JsonTypeInfo}.
*/
export type JsonTypeInfoDecorator = JacksonDecoratorWithOptions<JsonTypeInfoOptions,
ClassDecorator & MethodDecorator & PropertyDecorator & ParameterDecorator>;
/**
* Decorator type for {@link JsonIgnoreProperties}.
*/
export type JsonIgnorePropertiesDecorator = JacksonDecoratorWithOptions<JsonIgnorePropertiesOptions,
ClassDecorator & PropertyDecorator & ParameterDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonPropertyOrder}.
*/
export type JsonPropertyOrderDecorator = JacksonDecoratorWithOptions<JsonPropertyOrderOptions,
ClassDecorator & PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonTypeIdResolver}.
*/
export type JsonTypeIdResolverDecorator = JacksonDecoratorWithOptions<JsonTypeIdResolverOptions,
ClassDecorator & MethodDecorator & PropertyDecorator & ParameterDecorator>;
/**
* Decorator type for {@link JsonView}.
*/
export type JsonViewDecorator = JacksonDecoratorWithOptions<JsonViewOptions,
ClassDecorator & MethodDecorator & PropertyDecorator & ParameterDecorator>;
/**
* Decorator type for {@link JsonAnyGetter}.
*/
export type JsonAnyGetterDecorator = JacksonDecoratorWithOptionalOptions<JsonAnyGetterOptions, MethodDecorator>;
/**
* Decorator type for {@link JsonAnySetter}.
*/
export type JsonAnySetterDecorator = JacksonDecoratorWithOptionalOptions<JsonAnySetterOptions, MethodDecorator>;
/**
* Decorator type for {@link JsonBackReference}.
*/
export type JsonBackReferenceDecorator = JacksonDecoratorWithOptionalOptions<JsonBackReferenceOptions, PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonCreator}.
*/
export type JsonCreatorDecorator = JacksonDecoratorWithOptionalOptions<JsonCreatorOptions, ClassDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonFormat}.
*/
export type JsonFormatDecorator = JacksonDecoratorWithOptionalOptions<JsonFormatOptions,
ClassDecorator & PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonGetter}.
*/
export type JsonGetterDecorator = JacksonDecoratorWithOptionalOptions<JsonGetterOptions, MethodDecorator & PropertyDecorator>;
/**
* Decorator type for {@link JsonSetter}.
*/
export type JsonSetterDecorator = JacksonDecoratorWithOptionalOptions<JsonSetterOptions, MethodDecorator & PropertyDecorator>;
/**
* Decorator type for {@link JsonIgnore}.
*/
export type JsonIgnoreDecorator = JacksonDecoratorWithOptionalOptions<JsonIgnoreOptions,
PropertyDecorator & ParameterDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonIgnoreType}.
*/
export type JsonIgnoreTypeDecorator = JacksonDecoratorWithOptionalOptions<JsonIgnoreTypeOptions, ClassDecorator>;
/**
* Decorator type for {@link JsonInclude}.
*/
export type JsonIncludeDecorator = JacksonDecoratorWithOptionalOptions<JsonIncludeOptions,
ClassDecorator & PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonInject}.
*/
export type JsonInjectDecorator = JacksonDecoratorWithOptionalOptions<JsonInjectOptions,
PropertyDecorator & ParameterDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonManagedReference}.
*/
export type JsonManagedReferenceDecorator = JacksonDecoratorWithOptionalOptions<JsonManagedReferenceOptions,
PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonProperty}.
*/
export type JsonPropertyDecorator = JacksonDecoratorWithOptionalOptions<JsonPropertyOptions,
PropertyDecorator & MethodDecorator & ParameterDecorator>;
/**
* Decorator type for {@link JsonRawValue}.
*/
export type JsonRawValueDecorator = JacksonDecoratorWithOptionalOptions<JsonRawValueOptions, PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonRootName}.
*/
export type JsonRootNameDecorator = JacksonDecoratorWithOptionalOptions<JsonRootNameOptions, ClassDecorator>;
/**
* Decorator type for {@link JsonTypeName}.
*/
export type JsonTypeNameDecorator = JacksonDecoratorWithOptionalOptions<JsonTypeNameOptions, ClassDecorator>;
/**
* Decorator type for {@link JsonUnwrapped}.
*/
export type JsonUnwrappedDecorator = JacksonDecoratorWithOptionalOptions<JsonUnwrappedOptions,
PropertyDecorator & MethodDecorator>;
/**
* Decorator type for {@link JsonValue}.
*/
export type JsonValueDecorator = JacksonDecoratorWithOptionalOptions<JsonValueOptions, MethodDecorator & PropertyDecorator>;
/**
* Decorator type for {@link JsonTypeId}.
*/
export type JsonTypeIdDecorator = JacksonDecoratorWithOptionalOptions<JsonTypeIdOptions, PropertyDecorator & MethodDecorator>;
/**
* Common context properties used during serialization and deserialization.
*/
export interface JsonStringifierParserCommonContext<T> {
/**
* List of views (see {@link JsonView}) used to serialize/deserialize JSON objects.
*/
withViews?: () => ClassType<any>[];
/**
* List of context groups used to serialize/deserialize JSON objects.
*/
withContextGroups?: string[];
/**
* Property that defines features to set for {@link ObjectMapper}, {@link JsonStringifier} and {@link JsonParser}.
*/
features?: {};
/**
* Property whose keys are the decorators name that will be enabled/disabled during serialization/deserialization.
*/
decoratorsEnabled?: {
[key: string]: boolean;
};
/**
* Property whose keys are JavaScript Classes and its values are contexts to be used only for that JavaScript Classes.
*
* More specific contexts can be nested one inside the other. In this way, specific contexts can be applied to a
* JavaScript Class only if the nested JavaScript Class is found as one of the values of the parent JavaScript Class properties.
*/
forType?: Map<ClassType<any>, T>;
/**
* Map containing decorators to be applied to Iterable values or Class properties
* only at the first depth of the next pre/post transform process step.
* @internal
*/
_internalDecorators?: Map<ClassType<any>, InternalDecorators>;
/**
* JavaScript Class of the upper level of depth of the current pre/post transform process step.
* @internal
*/
_propertyParentCreator?: ClassType<any>;
}
/**
* Filter options used during serialization.
*/
export interface JsonStringifierFilterOptions {
/**
* Type used to determine whether to serialize property as is, or to filter it out.
*/
type: JsonFilterType;
/**
* The list of the properties that are affected by the filter type.
*/
values?: string[];
}
/**
* Context properties used during serialization without {@link JsonStringifierContext.mainCreator}.
*/
export interface JsonStringifierForTypeContext
extends JsonStringifierParserCommonContext<JsonStringifierForTypeContext> {
/**
* An Object Literal containing attributes values to be assigned during serialization for {@link JsonAppend} attributes.
*/
attributes?: {
[key: string]: any;
};
/**
* Property that defines features to set for {@link ObjectMapper} and {@link JsonStringifier}.
*/
features?: {
/**
* Property that defines features to set for {@link ObjectMapper} and {@link JsonStringifier}.
*/
serialization: SerializationFeature;
};
/**
* An Object Literal containing filter options used by {@link JsonFilter} during serialization.
* Object keys are simple string that refers to the name of the corresponding {@link JsonFilterOptions.value}.
*/
filters?: {
[key: string]: JsonStringifierFilterOptions;
};
/**
* A `String` or `Number` object that's used to insert white space into the output JSON string for readability purposes.
*
* If this is a Number, it indicates the number of space characters to use as white space;
* this number is capped at 10 (if it is greater, the value is just 10).
* Values less than 1 indicate that no space should be used.
*
* If this is a String, the string (or the first 10 characters of the string, if it's longer than that)
* is used as white space. If this parameter is not provided (or is null), no white space is used.
*/
format?: string | number;
/**
* Array of custom user-defined serializers.
*/
serializers?: CustomMapper<Serializer>[];
}
/**
* Context properties used by {@link JsonStringifier.stringify} during serialization.
*/
export interface JsonStringifierContext extends JsonStringifierForTypeContext {
/**
* Function that returns a list of JavaScript Classes.
*
* @returns ClassList<ClassType<any>>
*/
mainCreator?: () => ClassList<ClassType<any>>;
}
/**
* Context properties used by {@link JsonStringifier.transform} during serialization.
*/
export type JsonStringifierTransformerContext = Modify<JsonStringifierContext, {
/**
* List of the current JavaScript Class that is being serialized.
* So, `mainCreator[0]` will return the current JavaScript Class.
*/
mainCreator?: ClassList<ClassType<any>>;
}>;
/**
* Context properties used during deserialization without {@link JsonParserContext.mainCreator}.
*/
export interface JsonParserForTypeContext
extends JsonStringifierParserCommonContext<JsonParserForTypeContext> {
/**
* Property that defines features to set for {@link ObjectMapper} and {@link JsonParser}.
*/
features?: {
/**
* Property that defines features to set for {@link ObjectMapper} and {@link JsonParser}.
*/
deserialization: DeserializationFeature;
};
/**
* Define which {@link JsonCreator} should be used during deserialization through its name.
*/
withCreatorName?: string;
/**
* Array of custom user-defined deserializers.
*/
deserializers?: CustomMapper<Deserializer>[];
/**
* An Object Literal that stores the values to inject during deserialization, identified by simple String keys.
*/
injectableValues?: {
[key: string]: any;
};
}
/**
* Context properties used by {@link JsonParser.parse} during deserialization.
*/
export interface JsonParserContext extends JsonParserForTypeContext {
/**
* Function that returns a list of JavaScript Classes.
*
* @returns ClassList<ClassType<any>>
*/
mainCreator?: () => ClassList<ClassType<any>>;
}
/**
* Context properties used by {@link JsonParser.transform} during deserialization.
*/
export type JsonParserTransformerContext = Modify<JsonParserContext, {
/**
* List of the current JavaScript Class that is being deserialized.
* So, `mainCreator[0]` will return the current JavaScript Class.
*/
mainCreator?: ClassList<ClassType<any>>;
}>;
/**
* Serializer type.
*/
export type Serializer = (key: string, value: any, context?: JsonStringifierTransformerContext) => any;
/**
* Deserializer type.
*/
export type Deserializer = (key: string, value: any, context?: JsonParserTransformerContext) => any;
/**
* Interface that represents a serializer/deserializer used by {@link ObjectMapper}.
*/
export interface CustomMapper<T> {
/**
* The serializer/deserializer.
*/
mapper: T;
/**
* A JavaScript type, that could be:
* - a class;
* - a string such as "string" or "number" as if you were using the "typeof" operator.
*/
type?: () => any;
/**
* The order in which the serializer/deserializer should be executed.
* `0` has the highest precedence.
*/
order?: number;
}
/**
* Basic decorator options.
*/
export interface JsonDecoratorOptions {
/**
* Property that defines whether this decorator is active or not.
*
* @default `true`
*/
enabled?: boolean;
/**
* Property that defines whether this decorator is part of a context group
* or multiple groups.
*/
contextGroups?: string[];
/**
* @internal
*/
_descriptor?: TypedPropertyDescriptor<any>;
/**
* @internal
*/
_propertyKey?: string;
}
/**
* General decorator type.
*/
export type JsonDecorator = <T>(
/**
* Decorator options.
*/
options: JsonDecoratorOptions,
target: Record<string, any>,
propertyKey: string | symbol,
descriptorOrParamIndex: number | TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
/**
* Decorator options for {@link JsonAnyGetter}.
*/
export interface JsonAnyGetterOptions extends JsonDecoratorOptions {
/**
* Specify the name of the class property that contains the set of key/value pairs
* that should be added along with regular property values tha class has.
*/
value?: string;
}
/**
* Decorator options for {@link JsonAnySetter}.
*/
export type JsonAnySetterOptions = JsonDecoratorOptions;
/**
* Decorator options for {@link JsonBackReference}.
*/
export interface JsonBackReferenceOptions extends JsonDecoratorOptions {
/**
* Logical name for the reference property pair; used to link managed and back references.
* Default name can be used if there is just single reference pair
* (for example, node class that just has parent/child linkage, consisting of one managed reference and matching back reference).
*
* @default `'defaultReference'`
*/
value?: string;
}
/**
* Decorator options for {@link JsonCreator}.
*/
export interface JsonCreatorOptions extends JsonDecoratorOptions {
/**
* Creator name.
*/
name?: string;
/**
* Property that is used to indicate how argument(s) is/are bound for creator.
*
* @default {@link JsonCreatorMode.PROPERTIES}
*/
mode?: JsonCreatorMode;
/**
* @internal
*/
_ctor?: Record<string, any> | ObjectConstructor;
/**
* @internal
*/
_method?: Function;
}
/**
* Decorator options for {@link JsonDeserialize}.
*/
export interface JsonDeserializeOptions extends JsonDecoratorOptions {
/**
* Deserializer function to use for deserializing associated value.
*
* @param obj
* @param context
*/
using?: (obj: any, context?: JsonParserTransformerContext) => any;
/**
* Deserializer function to use for deserializing contents
* (elements of a Iterables and values of Maps) of decorated property.
*
* @param obj
* @param context
*/
contentUsing?: (obj: any, context?: JsonParserTransformerContext) => any;
/**
* Deserializer function to use for deserializing `Map` of `Object Literal`
* keys of decorated property.
*
* @param key
* @param context
*/
keyUsing?: (key: any, context?: JsonParserTransformerContext) => any;
}
/**
* Decorator base options for {@link JsonFormat}.
*/
export interface JsonFormatBaseOptions extends JsonDecoratorOptions {
/**
* Shape to be used by {@link JsonFormat}.
*/
shape?: JsonFormatShape;
}
/**
* Decorator specific options for {@link JsonFormat} with {@link JsonFormatBaseOptions.shape} value {@link JsonFormatShape.ANY}.
*/
export interface JsonFormatAny extends JsonFormatBaseOptions {
shape: JsonFormatShape.ANY;
}
/**
* Decorator specific options for {@link JsonFormat} with {@link JsonFormatBaseOptions.shape} value {@link JsonFormatShape.ARRAY}.
*/
export interface JsonFormatArray extends JsonFormatBaseOptions {
/**
* Value that indicates that (JSON) Array type should be used.
*/
shape: JsonFormatShape.ARRAY;
}
/**
* Decorator specific options for {@link JsonFormat} with {@link JsonFormatBaseOptions.shape} value {@link JsonFormatShape.BOOLEAN}.
*/
export interface JsonFormatBoolean extends JsonFormatBaseOptions {
/**
* Value that indicates that (JSON) boolean type (true, false) should be used.
*/
shape: JsonFormatShape.BOOLEAN;
}
/**
* Decorator specific options for {@link JsonFormat} with {@link JsonFormatBaseOptions.shape} value {@link JsonFormatShape.NUMBER_FLOAT}.
*/
export interface JsonFormatNumberFloat extends JsonFormatBaseOptions {
/**
* Value that indicates that floating-point numeric type should be used.
*/
shape: JsonFormatShape.NUMBER_FLOAT;
}
/**
* Decorator specific options for {@link JsonFormat} with {@link JsonFormatBaseOptions.shape} value {@link JsonFormatShape.NUMBER_INT}.
*/
export interface JsonFormatNumberInt extends JsonFormatBaseOptions {
/**
* Value that indicates that integer number type should be used.
*/
shape: JsonFormatShape.NUMBER_INT;
}
/**
* Decorator specific options for {@link JsonFormat} with {@link JsonFormatBaseOptions.shape} value {@link JsonFormatShape.OBJECT}.
*/
export interface JsonFormatObject extends JsonFormatBaseOptions {
/**
* Value that indicates that (JSON) Object type should be used.
*/
shape: JsonFormatShape.OBJECT;
}
/**
* Decorator specific options for {@link JsonFormat} with {@link JsonFormatBaseOptions.shape} value {@link JsonFormatShape.SCALAR}.
*/
export interface JsonFormatScalar extends JsonFormatBaseOptions {
/**
* Value that indicates shape should not be structural.
*/
shape: JsonFormatShape.SCALAR;
}
/**
* Decorator specific options for {@link JsonFormat} with {@link JsonFormatBaseOptions.shape} value {@link JsonFormatShape.STRING}.
*
* When formatting a `Date`, the {@link https://github.com/iamkun/dayjs} date library is used.
*/
export interface JsonFormatString extends JsonFormatBaseOptions {
/**
* Value that indicates that (JSON) String type should be used.
*/
shape: JsonFormatShape.STRING;
/**
* Pattern to be used to format a `Date` during serialization.
*/
pattern?: string;
/**
* Locale to be used to format a `Date` during serialization.
*
* @default `'en'`
*/
locale?: string;
/**
* Timezone to be used to format a `Date` during serialization.
*/
timezone?: string;
/**
* Radix to be used to format an integer `Number` during serialization and using `parseInt()`.
*/
radix?: number;
/**
* An integer specifying the number of digits after the decimal point
* to be used to format an integer `Number` during serialization and using `toExponential()`.
*/
toExponential?: number;
/**
* The number of digits to appear after the decimal point to be used to format a `Number`
* during serialization and using `toFixed()`.
*/
toFixed?: number;
/**
* An integer specifying the number of significant digits to be used to format a `Number`
* during serialization and using `toPrecision()`.
*/
toPrecision?: number;
}
/**
* Decorator options for {@link JsonFormat}.
*
* @default {@link JsonFormatAny}
*/
export type JsonFormatOptions = JsonFormatAny | JsonFormatArray | JsonFormatBoolean | JsonFormatNumberFloat |
JsonFormatNumberInt | JsonFormatObject | JsonFormatScalar | JsonFormatString;
/**
* Decorator options for {@link JsonIgnore}.
*/
export type JsonIgnoreOptions = JsonDecoratorOptions;
/**
* Decorator options for {@link JsonIgnoreProperties}.
*/
export interface JsonIgnorePropertiesOptions extends JsonDecoratorOptions {
/**
* Names of properties to ignore.
*/
value?: string[];
/**
* Property that can be enabled to allow "getters" to be used
* (that is, prevent ignoral of getters for properties listed in {@link value}).
*
* @default `false`
*/
allowGetters?: boolean;
/**
* Property that can be enabled to allow "setters" to be used
* (that is, prevent ignoral of setters for properties listed in {@link value}).
*
* @default `false`
*/
allowSetters?: boolean;
/**
* Property that defines whether it is ok to just ignore
* any unrecognized properties during deserialization.
*
* @default `false`
*/
ignoreUnknown?: boolean;
}
/**
* Decorator options for {@link JsonIgnoreType}.
*/
export type JsonIgnoreTypeOptions = JsonDecoratorOptions;
/**
* Decorator base options for {@link JsonInclude}.
*/
export interface JsonIncludeBaseOptions {
/**
* Inclusion rule to use for instances (values) of types (Classes) or properties decorated.
*
* @default {@link JsonIncludeType.ALWAYS}
*/
value?: JsonIncludeType;
/**
* Specifies a function to use in case {@link value} is {@link JsonIncludeType.CUSTOM} for filtering the value.
* If it returns `true`, then the value is not serialized.
*
* @param value - value to be filtered.
* @returns boolean
*/
valueFilter?: (value: any) => boolean;
/**
* Inclusion rule to use for entries ("content") of decorated `Map` or "Object Literal" properties.
*
* @default {@link JsonIncludeType.ALWAYS}
*/
content?: JsonIncludeType;
/**
* Specifies a function to use in case {@link content} is {@link JsonIncludeType.CUSTOM} for filtering the content value.
* If it returns `true`, then the content value is not serialized.
*
* @param value - content value to be filtered.
* @returns boolean
*/
contentFilter?: (value: any) => boolean;
}
/**
* Decorator options for {@link JsonInclude}.
*/
export type JsonIncludeOptions = JsonIncludeBaseOptions & JsonDecoratorOptions;
/**
* Decorator options for {@link JsonManagedReference}.
*/
export interface JsonManagedReferenceOptions extends JsonDecoratorOptions {
/**
* Logical name for the reference property pair; used to link managed and back references.
* Default name can be used if there is just single reference pair
* (for example, node class that just has parent/child linkage, consisting of one managed reference and matching back reference).
*
* @default `'defaultReference'`
*/
value?: string;
}
/**
* Decorator options for {@link JsonProperty}.
*/
export interface JsonPropertyOptions extends JsonDecoratorOptions {
/**
* Defines name of the logical property.
*/
value?: any;
/**
* Property that may be used to change the way visibility of accessors (getter, field-as-getter)
* and mutators (constructor parameter, setter, field-as-setter) is determined.
*
* @default {@link JsonPropertyAccess.READ_WRITE}
*/
access?: JsonPropertyAccess;
/**
* Property that indicates whether a value (which may be explicit null)
* is expected for property during deserialization or not.
*
* @default `false`
*/
required?: boolean;
}
/**
* Decorator options for {@link JsonPropertyOrder}.
*/
export interface JsonPropertyOrderOptions extends JsonDecoratorOptions {
/**
* Property that defines what to do regarding ordering of properties not explicitly included in decorator instance.
* If set to true, they will be alphabetically ordered; if false, order is undefined (default setting).
*/
alphabetic?: boolean;
/**
* Order in which properties of decorated object are to be serialized in.
*/
value?: string[];
}
/**
* Decorator options for {@link JsonRawValue}.
*/
export type JsonRawValueOptions = JsonDecoratorOptions;
/**
* Decorator options for {@link JsonRootName}.
*/
export interface JsonRootNameOptions extends JsonDecoratorOptions {
/**
* Root name to use.
*/
value?: string;
}
/**
* Decorator options for {@link JsonSerialize}.
*/
export interface JsonSerializeOptions extends JsonDecoratorOptions {
/**
* Serializer function to use for serializing associated value.
*
* @param obj
* @param context
*/
using?: (obj: any, context?: JsonStringifierTransformerContext) => any;
/**
* Serializer function to use for serializing contents
* (elements of a Iterables and values of Maps) of decorated property.
*
* @param obj
* @param context
*/
contentUsing?: (obj: any, context?: JsonStringifierTransformerContext) => any;
/**
* Serializer function to use for serializing `Map` of `Object Literal`
* keys of decorated property.
*
* @param key
* @param context
*/
keyUsing?: (key: any, context?: JsonStringifierTransformerContext) => any;
/**
* Serializer function to use for serializing nulls for properties that are decorated.
*
* @param context
*/
nullsUsing?: (context?: JsonStringifierTransformerContext) => any;
}
/**
* Subtypes of the decorated type with {@link JsonSubTypes}.
*/
export interface JsonSubTypeOptions extends JsonDecoratorOptions {
/**
* A function that returns the JavaScript Class of the subtype.
*/
class: () => ClassType<any>;
/**
* Logical type name used as the type identifier for the class.
*/
name?: string;
}
/**
* Decorator options for {@link JsonSubTypes}.
*/
export interface JsonSubTypesOptions extends JsonDecoratorOptions {
/**
* Subtypes of the decorated type.
*/
types: JsonSubTypeOptions[];
}
/**
* Decorator options for {@link JsonTypeInfo}.
*/
export interface JsonTypeInfoOptions extends JsonDecoratorOptions {
/**
* Specifies kind of type metadata to use when serializing type information
* for instances of decorated type and its subtypes;
* as well as what is expected during deserialization.
*/
use: JsonTypeInfoId;
/**
* Specifies mechanism to use for including type metadata.
* Used when serializing, and expected when deserializing.
*/
include: JsonTypeInfoAs;
/**
* Property names used when type inclusion method {@link JsonTypeInfoAs.PROPERTY} is used.
*/
property?: string;
}
/**
* Decorator options for {@link JsonTypeName}.
*/
export interface JsonTypeNameOptions extends JsonDecoratorOptions {
/**
* Logical type name for decorated type.
* If missing (or defined as Empty String), defaults to using class name as the type.
*/
value?: string;
/**
* @internal
*/
_ctor?: Record<string, any> | ObjectConstructor;
}
/**
* Decorator options for {@link JsonValue}.
*/
export type JsonValueOptions = JsonDecoratorOptions;
/**
* Decorator options for {@link JsonView}.
*/
export interface JsonViewOptions extends JsonDecoratorOptions {
/**
* A function that returns the view or a list of views that decorated element is part of.
*/
value: () => ClassType<any>[];
}
/**
* Decorator options for {@link JsonAlias}.
*/
export interface JsonAliasOptions extends JsonDecoratorOptions {
/**
* One or more secondary names to accept as aliases to the official name.
*/
values: string[];
}
/**
* Helper type used in {@link JsonClassType} to declare a ClassType and apply decorators to it.
*/
export type ClassTypeWithDecoratorDefinitions = () => ({
/**
* JavaScript type.
*/
target: ClassType<any>;
/**
* Property that contains the list of decorators to be applied.
*/
decorators: {
/**
* Name of the decorator.
*/
name: string;
/**
* Decorator options.
*/
options: JsonDecoratorOptions;
}[];
});
/**
* Decorator options for {@link JsonClassType}.
*/
export interface JsonClassTypeOptions extends JsonDecoratorOptions {
/**
* Function used to get the type of a class property or method parameter.
*/
type: () => ClassList<ClassType<any> | ClassTypeWithDecoratorDefinitions>;
}
/**
* Decorator options for {@link JsonUnwrapped}.
*/
export interface JsonUnwrappedOptions extends JsonDecoratorOptions {
/**
* Property that can be used to add prefix String to use in front of names of properties that are unwrapped:
* this can be done for example to prevent name collisions.
*/
prefix?: string;
/**
* Property that can be used to add suffix String to append at the end of names of properties that are unwrapped:
* this can be done for example to prevent name collisions.
*/
suffix?: string;
}
/**