typia 3.8.0-dev.20230420-2 → 3.8.0-dev.20230426

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