typia 4.1.0 → 4.1.1-dev.20230621

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 (34) hide show
  1. package/lib/factories/internal/metadata/iterate_metadata_array.js +1 -1
  2. package/lib/factories/internal/metadata/iterate_metadata_array.js.map +1 -1
  3. package/lib/module.d.ts +2 -2
  4. package/package.json +3 -2
  5. package/src/factories/CommentFactory.ts +64 -64
  6. package/src/factories/IdentifierFactory.ts +59 -59
  7. package/src/factories/MetadataFactory.ts +30 -30
  8. package/src/factories/internal/metadata/iterate_metadata_array.ts +1 -2
  9. package/src/metadata/MetadataObject.ts +118 -118
  10. package/src/module.ts +2038 -2038
  11. package/src/programmers/ApplicationProgrammer.ts +47 -47
  12. package/src/programmers/AssertCloneProgrammer.ts +71 -71
  13. package/src/programmers/AssertParseProgrammer.ts +66 -66
  14. package/src/programmers/AssertProgrammer.ts +279 -279
  15. package/src/programmers/AssertPruneProgrammer.ts +68 -68
  16. package/src/programmers/AssertStringifyProgrammer.ts +66 -66
  17. package/src/programmers/CloneProgrammer.ts +587 -587
  18. package/src/programmers/IsCloneProgrammer.ts +78 -78
  19. package/src/programmers/IsParseProgrammer.ts +72 -72
  20. package/src/programmers/IsProgrammer.ts +239 -239
  21. package/src/programmers/IsPruneProgrammer.ts +73 -73
  22. package/src/programmers/IsStringifyProgrammer.ts +76 -76
  23. package/src/programmers/LiteralsProgrammer.ts +60 -60
  24. package/src/programmers/PruneProgrammer.ts +542 -542
  25. package/src/programmers/RandomProgrammer.ts +581 -581
  26. package/src/programmers/StringifyProgrammer.ts +978 -978
  27. package/src/programmers/ValidateCloneProgrammer.ts +85 -85
  28. package/src/programmers/ValidateParseProgrammer.ts +70 -70
  29. package/src/programmers/ValidateProgrammer.ts +305 -305
  30. package/src/programmers/ValidatePruneProgrammer.ts +78 -78
  31. package/src/programmers/ValidateStringifyProgrammer.ts +84 -84
  32. package/src/programmers/internal/application_tuple.ts +57 -57
  33. package/src/programmers/internal/feature_object_entries.ts +63 -63
  34. package/src/schemas/IJsonSchema.ts +133 -133
@@ -1,305 +1,305 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../factories/IdentifierFactory";
4
- import { StatementFactory } from "../factories/StatementFactory";
5
- import { TypeFactory } from "../factories/TypeFactory";
6
-
7
- import { IProject } from "../transformers/IProject";
8
-
9
- import { CheckerProgrammer } from "./CheckerProgrammer";
10
- import { IsProgrammer } from "./IsProgrammer";
11
- import { FunctionImporter } from "./helpers/FunctionImporeter";
12
- import { OptionPredicator } from "./helpers/OptionPredicator";
13
- import { check_everything } from "./internal/check_everything";
14
- import { check_object } from "./internal/check_object";
15
-
16
- export namespace ValidateProgrammer {
17
- export const write =
18
- (project: IProject) =>
19
- (modulo: ts.LeftHandSideExpression) =>
20
- (equals: boolean) =>
21
- (type: ts.Type, name?: string) => {
22
- const importer: FunctionImporter = new FunctionImporter();
23
-
24
- const is = IsProgrammer.write(project)(modulo, true)(equals)(
25
- type,
26
- name ?? TypeFactory.getFullName(project.checker)(type),
27
- );
28
- const validate: ts.ArrowFunction = CheckerProgrammer.write(project)(
29
- {
30
- prefix: "$v",
31
- path: true,
32
- trace: true,
33
- numeric: OptionPredicator.numeric(project.options),
34
- equals,
35
- atomist: (explore) => (tuple) => (input) =>
36
- [
37
- tuple.expression,
38
- ...tuple.tags.map((tag) =>
39
- ts.factory.createLogicalOr(
40
- tag.expression,
41
- create_report_call(
42
- explore.from === "top"
43
- ? ts.factory.createTrue()
44
- : ts.factory.createIdentifier(
45
- "_exceptionable",
46
- ),
47
- )(
48
- ts.factory.createIdentifier(
49
- explore.postfix
50
- ? `_path + ${explore.postfix}`
51
- : "_path",
52
- ),
53
- tag.expected,
54
- input,
55
- ),
56
- ),
57
- ),
58
- ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
59
- combiner: combine(equals)(importer),
60
- joiner: joiner(equals)(importer),
61
- success: ts.factory.createTrue(),
62
- addition: () => importer.declare(modulo),
63
- },
64
- )(importer)(type, name);
65
-
66
- return ts.factory.createArrowFunction(
67
- undefined,
68
- undefined,
69
- [
70
- IdentifierFactory.parameter(
71
- "input",
72
- TypeFactory.keyword("any"),
73
- ),
74
- ],
75
- ts.factory.createTypeReferenceNode(
76
- `typia.IValidation<${
77
- name ?? TypeFactory.getFullName(project.checker)(type)
78
- }>`,
79
- ),
80
- undefined,
81
- ts.factory.createBlock(
82
- [
83
- StatementFactory.constant(
84
- "errors",
85
- ts.factory.createAsExpression(
86
- ts.factory.createArrayLiteralExpression([]),
87
- ts.factory.createArrayTypeNode(
88
- TypeFactory.keyword("any"),
89
- ),
90
- ),
91
- ),
92
- StatementFactory.constant("__is", is),
93
- ts.factory.createIfStatement(
94
- ts.factory.createStrictEquality(
95
- ts.factory.createFalse(),
96
- ts.factory.createCallExpression(
97
- ts.factory.createIdentifier("__is"),
98
- undefined,
99
- [ts.factory.createIdentifier("input")],
100
- ),
101
- ),
102
- ts.factory.createBlock([
103
- StatementFactory.constant(
104
- "$report",
105
- ts.factory.createCallExpression(
106
- IdentifierFactory.access(
107
- ts.factory.createParenthesizedExpression(
108
- ts.factory.createAsExpression(
109
- modulo,
110
- TypeFactory.keyword("any"),
111
- ),
112
- ),
113
- )("report"),
114
- [],
115
- [ts.factory.createIdentifier("errors")],
116
- ),
117
- ),
118
- ts.factory.createExpressionStatement(
119
- ts.factory.createCallExpression(
120
- validate,
121
- undefined,
122
- [
123
- ts.factory.createIdentifier(
124
- "input",
125
- ),
126
- ts.factory.createStringLiteral(
127
- "$input",
128
- ),
129
- ts.factory.createTrue(),
130
- ],
131
- ),
132
- ),
133
- ]),
134
- ),
135
- StatementFactory.constant(
136
- "success",
137
- ts.factory.createStrictEquality(
138
- ts.factory.createNumericLiteral(0),
139
- ts.factory.createIdentifier("errors.length"),
140
- ),
141
- ),
142
- ts.factory.createReturnStatement(
143
- ts.factory.createAsExpression(
144
- create_output(),
145
- TypeFactory.keyword("any"),
146
- ),
147
- ),
148
- ],
149
- true,
150
- ),
151
- );
152
- };
153
- }
154
-
155
- const combine =
156
- (equals: boolean) =>
157
- (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
158
- (explore: CheckerProgrammer.IExplore) => {
159
- if (explore.tracable === false)
160
- return IsProgrammer.configure({
161
- object: validate_object(equals)(importer),
162
- numeric: true,
163
- })(importer).combiner(explore);
164
-
165
- const path: string = explore.postfix
166
- ? `_path + ${explore.postfix}`
167
- : "_path";
168
- return (logic) => (input, binaries, expected) =>
169
- logic === "and"
170
- ? binaries
171
- .map((binary) =>
172
- binary.combined
173
- ? binary.expression
174
- : ts.factory.createLogicalOr(
175
- binary.expression,
176
- create_report_call(
177
- explore.source === "top"
178
- ? ts.factory.createTrue()
179
- : ts.factory.createIdentifier(
180
- "_exceptionable",
181
- ),
182
- )(
183
- ts.factory.createIdentifier(path),
184
- expected,
185
- input,
186
- ),
187
- ),
188
- )
189
- .reduce(ts.factory.createLogicalAnd)
190
- : ts.factory.createLogicalOr(
191
- binaries
192
- .map((binary) => binary.expression)
193
- .reduce(ts.factory.createLogicalOr),
194
- create_report_call(
195
- explore.source === "top"
196
- ? ts.factory.createTrue()
197
- : ts.factory.createIdentifier("_exceptionable"),
198
- )(ts.factory.createIdentifier(path), expected, input),
199
- );
200
- };
201
-
202
- const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
203
- check_object({
204
- equals,
205
- undefined: true,
206
- assert: false,
207
- reduce: ts.factory.createLogicalAnd,
208
- positive: ts.factory.createTrue(),
209
- superfluous: (value) =>
210
- create_report_call()(
211
- ts.factory.createAdd(
212
- ts.factory.createIdentifier("_path"),
213
- ts.factory.createCallExpression(
214
- importer.use("join"),
215
- undefined,
216
- [ts.factory.createIdentifier("key")],
217
- ),
218
- ),
219
- "undefined",
220
- value,
221
- ),
222
- halt: (expr) =>
223
- ts.factory.createLogicalOr(
224
- ts.factory.createStrictEquality(
225
- ts.factory.createFalse(),
226
- ts.factory.createIdentifier("_exceptionable"),
227
- ),
228
- expr,
229
- ),
230
- })(importer);
231
-
232
- const joiner =
233
- (equals: boolean) =>
234
- (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
235
- object: validate_object(equals)(importer),
236
- array: (input, arrow) =>
237
- check_everything(
238
- ts.factory.createCallExpression(
239
- IdentifierFactory.access(input)("map"),
240
- undefined,
241
- [arrow],
242
- ),
243
- ),
244
- failure: (value, expected, explore) =>
245
- create_report_call(
246
- explore?.from === "top"
247
- ? ts.factory.createTrue()
248
- : ts.factory.createIdentifier("_exceptionable"),
249
- )(
250
- ts.factory.createIdentifier(
251
- explore?.postfix ? `_path + ${explore.postfix}` : "_path",
252
- ),
253
- expected,
254
- value,
255
- ),
256
- tuple: (binaries) =>
257
- check_everything(
258
- ts.factory.createArrayLiteralExpression(binaries, true),
259
- ),
260
- });
261
-
262
- const create_output = () =>
263
- ts.factory.createObjectLiteralExpression(
264
- [
265
- ts.factory.createShorthandPropertyAssignment("success"),
266
- ts.factory.createShorthandPropertyAssignment("errors"),
267
- ts.factory.createPropertyAssignment(
268
- "data",
269
- ts.factory.createConditionalExpression(
270
- ts.factory.createIdentifier("success"),
271
- undefined,
272
- ts.factory.createIdentifier("input"),
273
- undefined,
274
- ts.factory.createIdentifier("undefined"),
275
- ),
276
- ),
277
- ],
278
- true,
279
- );
280
-
281
- const create_report_call =
282
- (exceptionable?: ts.Expression) =>
283
- (
284
- path: ts.Expression,
285
- expected: string,
286
- value: ts.Expression,
287
- ): ts.Expression =>
288
- ts.factory.createCallExpression(
289
- ts.factory.createIdentifier("$report"),
290
- undefined,
291
- [
292
- exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
293
- ts.factory.createObjectLiteralExpression(
294
- [
295
- ts.factory.createPropertyAssignment("path", path),
296
- ts.factory.createPropertyAssignment(
297
- "expected",
298
- ts.factory.createStringLiteral(expected),
299
- ),
300
- ts.factory.createPropertyAssignment("value", value),
301
- ],
302
- true,
303
- ),
304
- ],
305
- );
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../factories/StatementFactory";
5
+ import { TypeFactory } from "../factories/TypeFactory";
6
+
7
+ import { IProject } from "../transformers/IProject";
8
+
9
+ import { CheckerProgrammer } from "./CheckerProgrammer";
10
+ import { IsProgrammer } from "./IsProgrammer";
11
+ import { FunctionImporter } from "./helpers/FunctionImporeter";
12
+ import { OptionPredicator } from "./helpers/OptionPredicator";
13
+ import { check_everything } from "./internal/check_everything";
14
+ import { check_object } from "./internal/check_object";
15
+
16
+ export namespace ValidateProgrammer {
17
+ export const write =
18
+ (project: IProject) =>
19
+ (modulo: ts.LeftHandSideExpression) =>
20
+ (equals: boolean) =>
21
+ (type: ts.Type, name?: string) => {
22
+ const importer: FunctionImporter = new FunctionImporter();
23
+
24
+ const is = IsProgrammer.write(project)(modulo, true)(equals)(
25
+ type,
26
+ name ?? TypeFactory.getFullName(project.checker)(type),
27
+ );
28
+ const validate: ts.ArrowFunction = CheckerProgrammer.write(project)(
29
+ {
30
+ prefix: "$v",
31
+ path: true,
32
+ trace: true,
33
+ numeric: OptionPredicator.numeric(project.options),
34
+ equals,
35
+ atomist: (explore) => (tuple) => (input) =>
36
+ [
37
+ tuple.expression,
38
+ ...tuple.tags.map((tag) =>
39
+ ts.factory.createLogicalOr(
40
+ tag.expression,
41
+ create_report_call(
42
+ explore.from === "top"
43
+ ? ts.factory.createTrue()
44
+ : ts.factory.createIdentifier(
45
+ "_exceptionable",
46
+ ),
47
+ )(
48
+ ts.factory.createIdentifier(
49
+ explore.postfix
50
+ ? `_path + ${explore.postfix}`
51
+ : "_path",
52
+ ),
53
+ tag.expected,
54
+ input,
55
+ ),
56
+ ),
57
+ ),
58
+ ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
59
+ combiner: combine(equals)(importer),
60
+ joiner: joiner(equals)(importer),
61
+ success: ts.factory.createTrue(),
62
+ addition: () => importer.declare(modulo),
63
+ },
64
+ )(importer)(type, name);
65
+
66
+ return ts.factory.createArrowFunction(
67
+ undefined,
68
+ undefined,
69
+ [
70
+ IdentifierFactory.parameter(
71
+ "input",
72
+ TypeFactory.keyword("any"),
73
+ ),
74
+ ],
75
+ ts.factory.createTypeReferenceNode(
76
+ `typia.IValidation<${
77
+ name ?? TypeFactory.getFullName(project.checker)(type)
78
+ }>`,
79
+ ),
80
+ undefined,
81
+ ts.factory.createBlock(
82
+ [
83
+ StatementFactory.constant(
84
+ "errors",
85
+ ts.factory.createAsExpression(
86
+ ts.factory.createArrayLiteralExpression([]),
87
+ ts.factory.createArrayTypeNode(
88
+ TypeFactory.keyword("any"),
89
+ ),
90
+ ),
91
+ ),
92
+ StatementFactory.constant("__is", is),
93
+ ts.factory.createIfStatement(
94
+ ts.factory.createStrictEquality(
95
+ ts.factory.createFalse(),
96
+ ts.factory.createCallExpression(
97
+ ts.factory.createIdentifier("__is"),
98
+ undefined,
99
+ [ts.factory.createIdentifier("input")],
100
+ ),
101
+ ),
102
+ ts.factory.createBlock([
103
+ StatementFactory.constant(
104
+ "$report",
105
+ ts.factory.createCallExpression(
106
+ IdentifierFactory.access(
107
+ ts.factory.createParenthesizedExpression(
108
+ ts.factory.createAsExpression(
109
+ modulo,
110
+ TypeFactory.keyword("any"),
111
+ ),
112
+ ),
113
+ )("report"),
114
+ [],
115
+ [ts.factory.createIdentifier("errors")],
116
+ ),
117
+ ),
118
+ ts.factory.createExpressionStatement(
119
+ ts.factory.createCallExpression(
120
+ validate,
121
+ undefined,
122
+ [
123
+ ts.factory.createIdentifier(
124
+ "input",
125
+ ),
126
+ ts.factory.createStringLiteral(
127
+ "$input",
128
+ ),
129
+ ts.factory.createTrue(),
130
+ ],
131
+ ),
132
+ ),
133
+ ]),
134
+ ),
135
+ StatementFactory.constant(
136
+ "success",
137
+ ts.factory.createStrictEquality(
138
+ ts.factory.createNumericLiteral(0),
139
+ ts.factory.createIdentifier("errors.length"),
140
+ ),
141
+ ),
142
+ ts.factory.createReturnStatement(
143
+ ts.factory.createAsExpression(
144
+ create_output(),
145
+ TypeFactory.keyword("any"),
146
+ ),
147
+ ),
148
+ ],
149
+ true,
150
+ ),
151
+ );
152
+ };
153
+ }
154
+
155
+ const combine =
156
+ (equals: boolean) =>
157
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
158
+ (explore: CheckerProgrammer.IExplore) => {
159
+ if (explore.tracable === false)
160
+ return IsProgrammer.configure({
161
+ object: validate_object(equals)(importer),
162
+ numeric: true,
163
+ })(importer).combiner(explore);
164
+
165
+ const path: string = explore.postfix
166
+ ? `_path + ${explore.postfix}`
167
+ : "_path";
168
+ return (logic) => (input, binaries, expected) =>
169
+ logic === "and"
170
+ ? binaries
171
+ .map((binary) =>
172
+ binary.combined
173
+ ? binary.expression
174
+ : ts.factory.createLogicalOr(
175
+ binary.expression,
176
+ create_report_call(
177
+ explore.source === "top"
178
+ ? ts.factory.createTrue()
179
+ : ts.factory.createIdentifier(
180
+ "_exceptionable",
181
+ ),
182
+ )(
183
+ ts.factory.createIdentifier(path),
184
+ expected,
185
+ input,
186
+ ),
187
+ ),
188
+ )
189
+ .reduce(ts.factory.createLogicalAnd)
190
+ : ts.factory.createLogicalOr(
191
+ binaries
192
+ .map((binary) => binary.expression)
193
+ .reduce(ts.factory.createLogicalOr),
194
+ create_report_call(
195
+ explore.source === "top"
196
+ ? ts.factory.createTrue()
197
+ : ts.factory.createIdentifier("_exceptionable"),
198
+ )(ts.factory.createIdentifier(path), expected, input),
199
+ );
200
+ };
201
+
202
+ const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
203
+ check_object({
204
+ equals,
205
+ undefined: true,
206
+ assert: false,
207
+ reduce: ts.factory.createLogicalAnd,
208
+ positive: ts.factory.createTrue(),
209
+ superfluous: (value) =>
210
+ create_report_call()(
211
+ ts.factory.createAdd(
212
+ ts.factory.createIdentifier("_path"),
213
+ ts.factory.createCallExpression(
214
+ importer.use("join"),
215
+ undefined,
216
+ [ts.factory.createIdentifier("key")],
217
+ ),
218
+ ),
219
+ "undefined",
220
+ value,
221
+ ),
222
+ halt: (expr) =>
223
+ ts.factory.createLogicalOr(
224
+ ts.factory.createStrictEquality(
225
+ ts.factory.createFalse(),
226
+ ts.factory.createIdentifier("_exceptionable"),
227
+ ),
228
+ expr,
229
+ ),
230
+ })(importer);
231
+
232
+ const joiner =
233
+ (equals: boolean) =>
234
+ (importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
235
+ object: validate_object(equals)(importer),
236
+ array: (input, arrow) =>
237
+ check_everything(
238
+ ts.factory.createCallExpression(
239
+ IdentifierFactory.access(input)("map"),
240
+ undefined,
241
+ [arrow],
242
+ ),
243
+ ),
244
+ failure: (value, expected, explore) =>
245
+ create_report_call(
246
+ explore?.from === "top"
247
+ ? ts.factory.createTrue()
248
+ : ts.factory.createIdentifier("_exceptionable"),
249
+ )(
250
+ ts.factory.createIdentifier(
251
+ explore?.postfix ? `_path + ${explore.postfix}` : "_path",
252
+ ),
253
+ expected,
254
+ value,
255
+ ),
256
+ tuple: (binaries) =>
257
+ check_everything(
258
+ ts.factory.createArrayLiteralExpression(binaries, true),
259
+ ),
260
+ });
261
+
262
+ const create_output = () =>
263
+ ts.factory.createObjectLiteralExpression(
264
+ [
265
+ ts.factory.createShorthandPropertyAssignment("success"),
266
+ ts.factory.createShorthandPropertyAssignment("errors"),
267
+ ts.factory.createPropertyAssignment(
268
+ "data",
269
+ ts.factory.createConditionalExpression(
270
+ ts.factory.createIdentifier("success"),
271
+ undefined,
272
+ ts.factory.createIdentifier("input"),
273
+ undefined,
274
+ ts.factory.createIdentifier("undefined"),
275
+ ),
276
+ ),
277
+ ],
278
+ true,
279
+ );
280
+
281
+ const create_report_call =
282
+ (exceptionable?: ts.Expression) =>
283
+ (
284
+ path: ts.Expression,
285
+ expected: string,
286
+ value: ts.Expression,
287
+ ): ts.Expression =>
288
+ ts.factory.createCallExpression(
289
+ ts.factory.createIdentifier("$report"),
290
+ undefined,
291
+ [
292
+ exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
293
+ ts.factory.createObjectLiteralExpression(
294
+ [
295
+ ts.factory.createPropertyAssignment("path", path),
296
+ ts.factory.createPropertyAssignment(
297
+ "expected",
298
+ ts.factory.createStringLiteral(expected),
299
+ ),
300
+ ts.factory.createPropertyAssignment("value", value),
301
+ ],
302
+ true,
303
+ ),
304
+ ],
305
+ );