typia 5.0.0-dev.20230823-2 → 5.0.0-dev.2023084

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/lib/factories/MetadataTagFactory.js +4 -2
  2. package/lib/factories/MetadataTagFactory.js.map +1 -1
  3. package/lib/factories/ProtobufFactory.js +2 -1
  4. package/lib/factories/ProtobufFactory.js.map +1 -1
  5. package/lib/factories/internal/metadata/emend_metadata_atomics.js +6 -6
  6. package/lib/factories/internal/metadata/emend_metadata_atomics.js.map +1 -1
  7. package/lib/factories/internal/metadata/iterate_metadata_atomic.js +1 -1
  8. package/lib/factories/internal/metadata/iterate_metadata_atomic.js.map +1 -1
  9. package/lib/programmers/CheckerProgrammer.js +6 -6
  10. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  11. package/lib/programmers/RandomProgrammer.js +5 -5
  12. package/lib/programmers/RandomProgrammer.js.map +1 -1
  13. package/lib/programmers/helpers/AtomicPredicator.js +2 -2
  14. package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
  15. package/lib/programmers/helpers/ProtobufUtil.js +2 -2
  16. package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
  17. package/lib/programmers/internal/application_default_string.js +2 -2
  18. package/lib/programmers/internal/application_default_string.js.map +1 -1
  19. package/lib/programmers/internal/application_schema.js +5 -5
  20. package/lib/programmers/internal/application_schema.js.map +1 -1
  21. package/lib/programmers/internal/metadata_to_pattern.js +4 -4
  22. package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
  23. package/lib/programmers/internal/stringify_dynamic_properties.js +2 -1
  24. package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
  25. package/lib/programmers/json/JsonStringifyProgrammer.js +16 -10
  26. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  27. package/lib/programmers/misc/MiscLiteralsProgrammer.js +2 -2
  28. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  29. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
  30. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  31. package/lib/schemas/metadata/IMetadata.d.ts +2 -2
  32. package/lib/schemas/metadata/IMetadataAtomic.d.ts +12 -0
  33. package/lib/schemas/metadata/IMetadataAtomic.js +3 -0
  34. package/lib/schemas/metadata/IMetadataAtomic.js.map +1 -0
  35. package/lib/schemas/metadata/Metadata.d.ts +2 -2
  36. package/lib/schemas/metadata/Metadata.js +49 -44
  37. package/lib/schemas/metadata/Metadata.js.map +1 -1
  38. package/lib/tags/ExclusiveMaximum.d.ts +8 -0
  39. package/lib/tags/ExclusiveMaximum.js +3 -0
  40. package/lib/tags/ExclusiveMaximum.js.map +1 -0
  41. package/lib/tags/ExclusiveMinimum.d.ts +8 -0
  42. package/lib/tags/ExclusiveMinimum.js +3 -0
  43. package/lib/tags/ExclusiveMinimum.js.map +1 -0
  44. package/lib/tags/Format.d.ts +8 -0
  45. package/lib/tags/Format.js +3 -0
  46. package/lib/tags/Format.js.map +1 -0
  47. package/lib/tags/MaxItems.d.ts +8 -0
  48. package/lib/tags/MaxItems.js +3 -0
  49. package/lib/tags/MaxItems.js.map +1 -0
  50. package/lib/tags/MaxLength.d.ts +8 -0
  51. package/lib/tags/MaxLength.js +3 -0
  52. package/lib/tags/MaxLength.js.map +1 -0
  53. package/lib/tags/Maximum.d.ts +8 -0
  54. package/lib/tags/Maximum.js +3 -0
  55. package/lib/tags/Maximum.js.map +1 -0
  56. package/lib/tags/MinItems.d.ts +8 -0
  57. package/lib/tags/MinItems.js +3 -0
  58. package/lib/tags/MinItems.js.map +1 -0
  59. package/lib/tags/MinLength.d.ts +8 -0
  60. package/lib/tags/MinLength.js +3 -0
  61. package/lib/tags/MinLength.js.map +1 -0
  62. package/lib/tags/Minimum.d.ts +8 -0
  63. package/lib/tags/Minimum.js +3 -0
  64. package/lib/tags/Minimum.js.map +1 -0
  65. package/lib/tags/MultipleOf.d.ts +8 -0
  66. package/lib/tags/MultipleOf.js +3 -0
  67. package/lib/tags/MultipleOf.js.map +1 -0
  68. package/lib/tags/Pattern.d.ts +8 -0
  69. package/lib/tags/Pattern.js +3 -0
  70. package/lib/tags/Pattern.js.map +1 -0
  71. package/lib/tags/TagBase.d.ts +10 -0
  72. package/lib/tags/TagBase.js +3 -0
  73. package/lib/tags/TagBase.js.map +1 -0
  74. package/lib/tags/Type.d.ts +13 -0
  75. package/lib/tags/Type.js +3 -0
  76. package/lib/tags/Type.js.map +1 -0
  77. package/lib/tags/index.d.ts +12 -0
  78. package/lib/tags/index.js +29 -0
  79. package/lib/tags/index.js.map +1 -0
  80. package/lib/transformers/features/json/JsonApplicationTransformer.js +1 -1
  81. package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
  82. package/package.json +1 -1
  83. package/src/Primitive.ts +135 -135
  84. package/src/Resolved.ts +116 -116
  85. package/src/factories/MetadataFactory.ts +46 -46
  86. package/src/factories/MetadataTagFactory.ts +366 -364
  87. package/src/factories/ProtobufFactory.ts +268 -266
  88. package/src/factories/internal/metadata/emend_metadata_atomics.ts +35 -33
  89. package/src/factories/internal/metadata/explore_metadata.ts +38 -38
  90. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +63 -59
  91. package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
  92. package/src/factories/internal/metadata/iterate_metadata_native.ts +210 -210
  93. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
  94. package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
  95. package/src/functional/$ProtobufWriter.ts +151 -151
  96. package/src/json.ts +648 -648
  97. package/src/misc.ts +651 -651
  98. package/src/module.ts +709 -709
  99. package/src/programmers/AssertProgrammer.ts +281 -281
  100. package/src/programmers/CheckerProgrammer.ts +1174 -1173
  101. package/src/programmers/IsProgrammer.ts +241 -241
  102. package/src/programmers/RandomProgrammer.ts +874 -874
  103. package/src/programmers/ValidateProgrammer.ts +307 -307
  104. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  105. package/src/programmers/helpers/FunctionImporeter.ts +91 -91
  106. package/src/programmers/helpers/ProtobufUtil.ts +29 -29
  107. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  108. package/src/programmers/helpers/disable_function_importer_declare.ts +32 -32
  109. package/src/programmers/internal/application_default_string.ts +37 -33
  110. package/src/programmers/internal/application_resolved.ts +55 -55
  111. package/src/programmers/internal/application_schema.ts +157 -157
  112. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  113. package/src/programmers/internal/stringify_dynamic_properties.ts +171 -171
  114. package/src/programmers/json/JsonStringifyProgrammer.ts +995 -989
  115. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +71 -71
  116. package/src/programmers/misc/MiscCloneProgrammer.ts +775 -775
  117. package/src/programmers/misc/MiscIsCloneProgrammer.ts +78 -78
  118. package/src/programmers/misc/MiscLiteralsProgrammer.ts +64 -64
  119. package/src/programmers/misc/MiscPruneProgrammer.ts +544 -544
  120. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +85 -85
  121. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +75 -75
  122. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +673 -673
  123. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +814 -814
  124. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +85 -85
  125. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -75
  126. package/src/protobuf.ts +881 -881
  127. package/src/schemas/metadata/IMetadata.ts +27 -28
  128. package/src/schemas/metadata/IMetadataAtomic.ts +13 -0
  129. package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
  130. package/src/schemas/metadata/Metadata.ts +643 -634
  131. package/src/schemas/metadata/MetadataEscaped.ts +51 -51
  132. package/src/tags/ExclusiveMaximum.ts +8 -0
  133. package/src/tags/ExclusiveMinimum.ts +8 -0
  134. package/src/tags/Format.ts +29 -0
  135. package/src/tags/MaxItems.ts +8 -0
  136. package/src/tags/MaxLength.ts +8 -0
  137. package/src/tags/Maximum.ts +8 -0
  138. package/src/tags/MinItems.ts +8 -0
  139. package/src/tags/MinLength.ts +8 -0
  140. package/src/tags/Minimum.ts +8 -0
  141. package/src/tags/MultipleOf.ts +10 -0
  142. package/src/tags/Pattern.ts +8 -0
  143. package/src/tags/TagBase.ts +17 -0
  144. package/src/tags/Type.ts +30 -0
  145. package/src/tags/index.ts +12 -0
  146. package/src/transformers/features/json/JsonApplicationTransformer.ts +111 -111
  147. package/src/transformers/features/misc/MetadataTransformer.ts +53 -53
  148. package/src/utils/RandomGenerator.ts +83 -83
@@ -1,241 +1,241 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../factories/ExpressionFactory";
4
- import { IdentifierFactory } from "../factories/IdentifierFactory";
5
- import { MetadataCollection } from "../factories/MetadataCollection";
6
- import { TypeFactory } from "../factories/TypeFactory";
7
- import { ValueFactory } from "../factories/ValueFactory";
8
-
9
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
10
-
11
- import { IProject } from "../transformers/IProject";
12
-
13
- import { CheckerProgrammer } from "./CheckerProgrammer";
14
- import { FunctionImporter } from "./helpers/FunctionImporeter";
15
- import { IExpressionEntry } from "./helpers/IExpressionEntry";
16
- import { OptionPredicator } from "./helpers/OptionPredicator";
17
- import { disable_function_importer_declare } from "./helpers/disable_function_importer_declare";
18
- import { check_object } from "./internal/check_object";
19
- import { feature_object_entries } from "./internal/feature_object_entries";
20
-
21
- export namespace IsProgrammer {
22
- export const configure =
23
- (options?: Partial<CONFIG.IOptions>) =>
24
- (importer: FunctionImporter): CheckerProgrammer.IConfig => ({
25
- prefix: "$i",
26
- trace: false,
27
- path: false,
28
- equals: !!options?.object,
29
- numeric: OptionPredicator.numeric({
30
- numeric: options?.numeric,
31
- }),
32
- atomist: () => (entry) => () =>
33
- [
34
- entry.expression,
35
- ...entry.tags.map((tag) => tag.expression),
36
- ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
37
- combiner: () => (type: "and" | "or") => {
38
- const initial: ts.TrueLiteral | ts.FalseLiteral =
39
- type === "and"
40
- ? ts.factory.createTrue()
41
- : ts.factory.createFalse();
42
- const binder =
43
- type === "and"
44
- ? ts.factory.createLogicalAnd
45
- : ts.factory.createLogicalOr;
46
- return (
47
- _input: ts.Expression,
48
- binaries: CheckerProgrammer.IBinary[],
49
- ) =>
50
- binaries.length
51
- ? binaries
52
- .map((binary) => binary.expression)
53
- .reduce((x, y) => binder(x, y))
54
- : initial;
55
- },
56
- joiner: {
57
- object:
58
- options?.object ||
59
- check_object({
60
- equals: !!options?.object,
61
- undefined: OptionPredicator.undefined({
62
- undefined: options?.undefined,
63
- }),
64
- assert: true,
65
- reduce: ts.factory.createLogicalAnd,
66
- positive: ts.factory.createTrue(),
67
- superfluous: () => ts.factory.createFalse(),
68
- })(importer),
69
- array: (input, arrow) =>
70
- ts.factory.createCallExpression(
71
- IdentifierFactory.access(input)("every"),
72
- undefined,
73
- [arrow],
74
- ),
75
- failure: () => ts.factory.createFalse(),
76
- },
77
- success: ts.factory.createTrue(),
78
- });
79
-
80
- export namespace CONFIG {
81
- export interface IOptions {
82
- numeric: boolean;
83
- undefined: boolean;
84
- object: (
85
- input: ts.Expression,
86
- entries: IExpressionEntry<ts.Expression>[],
87
- ) => ts.Expression;
88
- }
89
- }
90
-
91
- /* -----------------------------------------------------------
92
- WRITERS
93
- ----------------------------------------------------------- */
94
- export const write =
95
- (project: IProject) =>
96
- (modulo: ts.LeftHandSideExpression, disable?: boolean) =>
97
- (equals: boolean) => {
98
- const importer: FunctionImporter =
99
- disable === <any>{}
100
- ? disable_function_importer_declare(
101
- new FunctionImporter(modulo.getText()),
102
- )
103
- : new FunctionImporter(modulo.getText());
104
-
105
- // CONFIGURATION
106
- const config: CheckerProgrammer.IConfig = {
107
- ...configure({
108
- object: check_object({
109
- equals,
110
- undefined: OptionPredicator.undefined(project.options),
111
- assert: true,
112
- reduce: ts.factory.createLogicalAnd,
113
- positive: ts.factory.createTrue(),
114
- superfluous: () => ts.factory.createFalse(),
115
- })(importer),
116
- numeric: OptionPredicator.numeric(project.options),
117
- })(importer),
118
- trace: equals,
119
- addition: () => importer.declare(modulo),
120
- };
121
-
122
- config.decoder =
123
- () => (input, target, explore, tags, jsDocTags) => {
124
- if (
125
- target.size() === 1 &&
126
- target.objects.length === 1 &&
127
- target.isRequired() === true &&
128
- target.nullable === false
129
- ) {
130
- // ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
131
- const obj: MetadataObject = target.objects[0]!;
132
- if (
133
- obj._Is_simple(explore.from === "top" ? 0 : 1) &&
134
- (equals === false ||
135
- OptionPredicator.undefined(project.options) ===
136
- false)
137
- )
138
- return ts.factory.createLogicalAnd(
139
- ExpressionFactory.isObject({
140
- checkNull: true,
141
- checkArray: false,
142
- })(input),
143
- config.joiner.object(
144
- ts.factory.createAsExpression(
145
- input,
146
- TypeFactory.keyword("any"),
147
- ),
148
- feature_object_entries(config as any)(
149
- importer,
150
- )(obj)(
151
- ts.factory.createAsExpression(
152
- input,
153
- TypeFactory.keyword("any"),
154
- ),
155
- "top",
156
- ),
157
- ),
158
- );
159
- }
160
- return CheckerProgrammer.decode(project)(config)(importer)(
161
- input,
162
- target,
163
- explore,
164
- tags,
165
- jsDocTags,
166
- );
167
- };
168
-
169
- // GENERATE CHECKER
170
- return CheckerProgrammer.write(project)(config)(importer);
171
- };
172
-
173
- export const write_function_statements =
174
- (project: IProject) =>
175
- (importer: FunctionImporter) =>
176
- (collection: MetadataCollection) => {
177
- const config = configure()(importer);
178
- const objects =
179
- CheckerProgrammer.write_object_functions(project)(config)(
180
- importer,
181
- )(collection);
182
- const unions =
183
- CheckerProgrammer.write_union_functions(project)(config)(
184
- importer,
185
- )(collection);
186
- const arrays =
187
- CheckerProgrammer.write_array_functions(project)(config)(
188
- importer,
189
- )(collection);
190
- const tuples =
191
- CheckerProgrammer.write_tuple_functions(project)(config)(
192
- importer,
193
- )(collection);
194
-
195
- return [
196
- ...objects.filter((_, i) =>
197
- importer.hasLocal(`${config.prefix}o${i}`),
198
- ),
199
- ...unions.filter((_, i) =>
200
- importer.hasLocal(`${config.prefix}u${i}`),
201
- ),
202
- ...arrays.filter((_, i) =>
203
- importer.hasLocal(`${config.prefix}a${i}`),
204
- ),
205
- ...tuples.filter((_, i) =>
206
- importer.hasLocal(`${config.prefix}t${i}`),
207
- ),
208
- ];
209
- };
210
-
211
- /* -----------------------------------------------------------
212
- DECODERS
213
- ----------------------------------------------------------- */
214
- export const decode = (project: IProject) => (importer: FunctionImporter) =>
215
- CheckerProgrammer.decode(project)(configure()(importer))(importer);
216
-
217
- export const decode_object = (importer: FunctionImporter) =>
218
- CheckerProgrammer.decode_object(configure()(importer))(importer);
219
-
220
- export const decode_to_json =
221
- (checkNull: boolean) =>
222
- (input: ts.Expression): ts.Expression =>
223
- ts.factory.createLogicalAnd(
224
- ExpressionFactory.isObject({
225
- checkArray: false,
226
- checkNull,
227
- })(input),
228
- ts.factory.createStrictEquality(
229
- ts.factory.createStringLiteral("function"),
230
- ValueFactory.TYPEOF(
231
- IdentifierFactory.access(input)("toJSON"),
232
- ),
233
- ),
234
- );
235
-
236
- export const decode_functional = (input: ts.Expression) =>
237
- ts.factory.createStrictEquality(
238
- ts.factory.createStringLiteral("function"),
239
- ValueFactory.TYPEOF(input),
240
- );
241
- }
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
5
+ import { MetadataCollection } from "../factories/MetadataCollection";
6
+ import { TypeFactory } from "../factories/TypeFactory";
7
+ import { ValueFactory } from "../factories/ValueFactory";
8
+
9
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
10
+
11
+ import { IProject } from "../transformers/IProject";
12
+
13
+ import { CheckerProgrammer } from "./CheckerProgrammer";
14
+ import { FunctionImporter } from "./helpers/FunctionImporeter";
15
+ import { IExpressionEntry } from "./helpers/IExpressionEntry";
16
+ import { OptionPredicator } from "./helpers/OptionPredicator";
17
+ import { disable_function_importer_declare } from "./helpers/disable_function_importer_declare";
18
+ import { check_object } from "./internal/check_object";
19
+ import { feature_object_entries } from "./internal/feature_object_entries";
20
+
21
+ export namespace IsProgrammer {
22
+ export const configure =
23
+ (options?: Partial<CONFIG.IOptions>) =>
24
+ (importer: FunctionImporter): CheckerProgrammer.IConfig => ({
25
+ prefix: "$i",
26
+ trace: false,
27
+ path: false,
28
+ equals: !!options?.object,
29
+ numeric: OptionPredicator.numeric({
30
+ numeric: options?.numeric,
31
+ }),
32
+ atomist: () => (entry) => () =>
33
+ [
34
+ entry.expression,
35
+ ...entry.tags.map((tag) => tag.expression),
36
+ ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
37
+ combiner: () => (type: "and" | "or") => {
38
+ const initial: ts.TrueLiteral | ts.FalseLiteral =
39
+ type === "and"
40
+ ? ts.factory.createTrue()
41
+ : ts.factory.createFalse();
42
+ const binder =
43
+ type === "and"
44
+ ? ts.factory.createLogicalAnd
45
+ : ts.factory.createLogicalOr;
46
+ return (
47
+ _input: ts.Expression,
48
+ binaries: CheckerProgrammer.IBinary[],
49
+ ) =>
50
+ binaries.length
51
+ ? binaries
52
+ .map((binary) => binary.expression)
53
+ .reduce((x, y) => binder(x, y))
54
+ : initial;
55
+ },
56
+ joiner: {
57
+ object:
58
+ options?.object ||
59
+ check_object({
60
+ equals: !!options?.object,
61
+ undefined: OptionPredicator.undefined({
62
+ undefined: options?.undefined,
63
+ }),
64
+ assert: true,
65
+ reduce: ts.factory.createLogicalAnd,
66
+ positive: ts.factory.createTrue(),
67
+ superfluous: () => ts.factory.createFalse(),
68
+ })(importer),
69
+ array: (input, arrow) =>
70
+ ts.factory.createCallExpression(
71
+ IdentifierFactory.access(input)("every"),
72
+ undefined,
73
+ [arrow],
74
+ ),
75
+ failure: () => ts.factory.createFalse(),
76
+ },
77
+ success: ts.factory.createTrue(),
78
+ });
79
+
80
+ export namespace CONFIG {
81
+ export interface IOptions {
82
+ numeric: boolean;
83
+ undefined: boolean;
84
+ object: (
85
+ input: ts.Expression,
86
+ entries: IExpressionEntry<ts.Expression>[],
87
+ ) => ts.Expression;
88
+ }
89
+ }
90
+
91
+ /* -----------------------------------------------------------
92
+ WRITERS
93
+ ----------------------------------------------------------- */
94
+ export const write =
95
+ (project: IProject) =>
96
+ (modulo: ts.LeftHandSideExpression, disable?: boolean) =>
97
+ (equals: boolean) => {
98
+ const importer: FunctionImporter =
99
+ disable === <any>{}
100
+ ? disable_function_importer_declare(
101
+ new FunctionImporter(modulo.getText()),
102
+ )
103
+ : new FunctionImporter(modulo.getText());
104
+
105
+ // CONFIGURATION
106
+ const config: CheckerProgrammer.IConfig = {
107
+ ...configure({
108
+ object: check_object({
109
+ equals,
110
+ undefined: OptionPredicator.undefined(project.options),
111
+ assert: true,
112
+ reduce: ts.factory.createLogicalAnd,
113
+ positive: ts.factory.createTrue(),
114
+ superfluous: () => ts.factory.createFalse(),
115
+ })(importer),
116
+ numeric: OptionPredicator.numeric(project.options),
117
+ })(importer),
118
+ trace: equals,
119
+ addition: () => importer.declare(modulo),
120
+ };
121
+
122
+ config.decoder =
123
+ () => (input, target, explore, tags, jsDocTags) => {
124
+ if (
125
+ target.size() === 1 &&
126
+ target.objects.length === 1 &&
127
+ target.isRequired() === true &&
128
+ target.nullable === false
129
+ ) {
130
+ // ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
131
+ const obj: MetadataObject = target.objects[0]!;
132
+ if (
133
+ obj._Is_simple(explore.from === "top" ? 0 : 1) &&
134
+ (equals === false ||
135
+ OptionPredicator.undefined(project.options) ===
136
+ false)
137
+ )
138
+ return ts.factory.createLogicalAnd(
139
+ ExpressionFactory.isObject({
140
+ checkNull: true,
141
+ checkArray: false,
142
+ })(input),
143
+ config.joiner.object(
144
+ ts.factory.createAsExpression(
145
+ input,
146
+ TypeFactory.keyword("any"),
147
+ ),
148
+ feature_object_entries(config as any)(
149
+ importer,
150
+ )(obj)(
151
+ ts.factory.createAsExpression(
152
+ input,
153
+ TypeFactory.keyword("any"),
154
+ ),
155
+ "top",
156
+ ),
157
+ ),
158
+ );
159
+ }
160
+ return CheckerProgrammer.decode(project)(config)(importer)(
161
+ input,
162
+ target,
163
+ explore,
164
+ tags,
165
+ jsDocTags,
166
+ );
167
+ };
168
+
169
+ // GENERATE CHECKER
170
+ return CheckerProgrammer.write(project)(config)(importer);
171
+ };
172
+
173
+ export const write_function_statements =
174
+ (project: IProject) =>
175
+ (importer: FunctionImporter) =>
176
+ (collection: MetadataCollection) => {
177
+ const config = configure()(importer);
178
+ const objects =
179
+ CheckerProgrammer.write_object_functions(project)(config)(
180
+ importer,
181
+ )(collection);
182
+ const unions =
183
+ CheckerProgrammer.write_union_functions(project)(config)(
184
+ importer,
185
+ )(collection);
186
+ const arrays =
187
+ CheckerProgrammer.write_array_functions(project)(config)(
188
+ importer,
189
+ )(collection);
190
+ const tuples =
191
+ CheckerProgrammer.write_tuple_functions(project)(config)(
192
+ importer,
193
+ )(collection);
194
+
195
+ return [
196
+ ...objects.filter((_, i) =>
197
+ importer.hasLocal(`${config.prefix}o${i}`),
198
+ ),
199
+ ...unions.filter((_, i) =>
200
+ importer.hasLocal(`${config.prefix}u${i}`),
201
+ ),
202
+ ...arrays.filter((_, i) =>
203
+ importer.hasLocal(`${config.prefix}a${i}`),
204
+ ),
205
+ ...tuples.filter((_, i) =>
206
+ importer.hasLocal(`${config.prefix}t${i}`),
207
+ ),
208
+ ];
209
+ };
210
+
211
+ /* -----------------------------------------------------------
212
+ DECODERS
213
+ ----------------------------------------------------------- */
214
+ export const decode = (project: IProject) => (importer: FunctionImporter) =>
215
+ CheckerProgrammer.decode(project)(configure()(importer))(importer);
216
+
217
+ export const decode_object = (importer: FunctionImporter) =>
218
+ CheckerProgrammer.decode_object(configure()(importer))(importer);
219
+
220
+ export const decode_to_json =
221
+ (checkNull: boolean) =>
222
+ (input: ts.Expression): ts.Expression =>
223
+ ts.factory.createLogicalAnd(
224
+ ExpressionFactory.isObject({
225
+ checkArray: false,
226
+ checkNull,
227
+ })(input),
228
+ ts.factory.createStrictEquality(
229
+ ts.factory.createStringLiteral("function"),
230
+ ValueFactory.TYPEOF(
231
+ IdentifierFactory.access(input)("toJSON"),
232
+ ),
233
+ ),
234
+ );
235
+
236
+ export const decode_functional = (input: ts.Expression) =>
237
+ ts.factory.createStrictEquality(
238
+ ts.factory.createStringLiteral("function"),
239
+ ValueFactory.TYPEOF(input),
240
+ );
241
+ }