typia 5.4.14 → 5.5.0-dev.20240301
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.
- package/lib/factories/IdentifierFactory.d.ts +1 -1
- package/lib/functional/$guard.js +49 -28
- package/lib/functional/$guard.js.map +1 -1
- package/lib/functional/Namespace/index.d.ts +1 -1
- package/lib/http.d.ts +10 -493
- package/lib/http.js.map +1 -1
- package/lib/json.d.ts +9 -8
- package/lib/json.js.map +1 -1
- package/lib/misc.d.ts +9 -8
- package/lib/misc.js.map +1 -1
- package/lib/module.d.ts +17 -16
- package/lib/module.js.map +1 -1
- package/lib/notations.d.ts +13 -12
- package/lib/notations.js.map +1 -1
- package/lib/programmers/AssertProgrammer.d.ts +5 -1
- package/lib/programmers/AssertProgrammer.js +31 -22
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertFormDataProgrammer.d.ts +1 -1
- package/lib/programmers/http/HttpAssertFormDataProgrammer.js +6 -2
- package/lib/programmers/http/HttpAssertFormDataProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertHeadersProgrammer.d.ts +1 -1
- package/lib/programmers/http/HttpAssertHeadersProgrammer.js +6 -2
- package/lib/programmers/http/HttpAssertHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpAssertQueryProgrammer.d.ts +1 -1
- package/lib/programmers/http/HttpAssertQueryProgrammer.js +6 -2
- package/lib/programmers/http/HttpAssertQueryProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +9 -3
- package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonAssertStringifyProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonAssertStringifyProgrammer.js +9 -3
- package/lib/programmers/json/JsonAssertStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscAssertCloneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscAssertCloneProgrammer.js +9 -3
- package/lib/programmers/misc/MiscAssertCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscAssertPruneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscAssertPruneProgrammer.js +9 -3
- package/lib/programmers/misc/MiscAssertPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationAssertGeneralProgrammer.d.ts +1 -1
- package/lib/programmers/notations/NotationAssertGeneralProgrammer.js +9 -3
- package/lib/programmers/notations/NotationAssertGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.d.ts +1 -1
- package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js +6 -2
- package/lib/programmers/protobuf/ProtobufAssertDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufAssertEncodeProgrammer.d.ts +1 -1
- package/lib/programmers/protobuf/ProtobufAssertEncodeProgrammer.js +9 -3
- package/lib/programmers/protobuf/ProtobufAssertEncodeProgrammer.js.map +1 -1
- package/lib/protobuf.d.ts +9 -8
- package/lib/protobuf.js.map +1 -1
- package/lib/transformers/internal/GenericTransformer.d.ts +1 -1
- package/lib/transformers/internal/GenericTransformer.js +3 -3
- package/lib/transformers/internal/GenericTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/IdentifierFactory.ts +1 -1
- package/src/functional/$guard.ts +33 -19
- package/src/http.ts +25 -508
- package/src/json.ts +29 -8
- package/src/misc.ts +29 -8
- package/src/module.ts +57 -16
- package/src/notations.ts +43 -12
- package/src/programmers/AssertProgrammer.ts +69 -28
- package/src/programmers/http/HttpAssertFormDataProgrammer.ts +6 -2
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +6 -2
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +6 -2
- package/src/programmers/json/JsonAssertParseProgrammer.ts +9 -3
- package/src/programmers/json/JsonAssertStringifyProgrammer.ts +9 -3
- package/src/programmers/misc/MiscAssertCloneProgrammer.ts +9 -3
- package/src/programmers/misc/MiscAssertPruneProgrammer.ts +9 -3
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +9 -3
- package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +6 -2
- package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +9 -3
- package/src/protobuf.ts +29 -8
- package/src/transformers/internal/GenericTransformer.ts +12 -4
|
@@ -17,15 +17,14 @@ export namespace AssertProgrammer {
|
|
|
17
17
|
(project: IProject) =>
|
|
18
18
|
(modulo: ts.LeftHandSideExpression) =>
|
|
19
19
|
(props: boolean | { equals: boolean; guard: boolean }) =>
|
|
20
|
-
(type: ts.Type, name?: string) => {
|
|
20
|
+
(type: ts.Type, name?: string, init?: ts.Expression) => {
|
|
21
21
|
// TO SUPPORT LEGACY FEATURE
|
|
22
22
|
if (typeof props === "boolean") props = { equals: props, guard: false };
|
|
23
23
|
|
|
24
24
|
const importer: FunctionImporter = new FunctionImporter(modulo.getText());
|
|
25
|
-
const is = IsProgrammer.write(project)(modulo, true)(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
25
|
+
const is: ts.ArrowFunction = IsProgrammer.write(project)(modulo, true)(
|
|
26
|
+
props.equals,
|
|
27
|
+
)(type, name ?? TypeFactory.getFullName(project.checker)(type));
|
|
29
28
|
const assert: ts.ArrowFunction = CheckerProgrammer.write(project)({
|
|
30
29
|
prefix: "$a",
|
|
31
30
|
path: true,
|
|
@@ -41,7 +40,7 @@ export namespace AssertProgrammer {
|
|
|
41
40
|
? entry.conditions[0]!.map((cond) =>
|
|
42
41
|
ts.factory.createLogicalOr(
|
|
43
42
|
cond.expression,
|
|
44
|
-
create_guard_call(
|
|
43
|
+
create_guard_call(
|
|
45
44
|
explore.from === "top"
|
|
46
45
|
? ts.factory.createTrue()
|
|
47
46
|
: ts.factory.createIdentifier("_exceptionable"),
|
|
@@ -65,7 +64,7 @@ export namespace AssertProgrammer {
|
|
|
65
64
|
.reduce((a, b) => ts.factory.createLogicalAnd(a, b)),
|
|
66
65
|
)
|
|
67
66
|
.reduce((a, b) => ts.factory.createLogicalOr(a, b)),
|
|
68
|
-
create_guard_call(
|
|
67
|
+
create_guard_call(
|
|
69
68
|
explore.from === "top"
|
|
70
69
|
? ts.factory.createTrue()
|
|
71
70
|
: ts.factory.createIdentifier("_exceptionable"),
|
|
@@ -90,7 +89,10 @@ export namespace AssertProgrammer {
|
|
|
90
89
|
return ts.factory.createArrowFunction(
|
|
91
90
|
undefined,
|
|
92
91
|
undefined,
|
|
93
|
-
[
|
|
92
|
+
[
|
|
93
|
+
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
|
|
94
|
+
Guardian.parameter(init),
|
|
95
|
+
],
|
|
94
96
|
props.guard
|
|
95
97
|
? ts.factory.createTypePredicateNode(
|
|
96
98
|
ts.factory.createToken(ts.SyntaxKind.AssertsKeyword),
|
|
@@ -105,6 +107,21 @@ export namespace AssertProgrammer {
|
|
|
105
107
|
undefined,
|
|
106
108
|
ts.factory.createBlock(
|
|
107
109
|
[
|
|
110
|
+
StatementFactory.constant(
|
|
111
|
+
"$guard",
|
|
112
|
+
ts.factory.createCallExpression(
|
|
113
|
+
IdentifierFactory.access(
|
|
114
|
+
ts.factory.createParenthesizedExpression(
|
|
115
|
+
ts.factory.createAsExpression(
|
|
116
|
+
modulo,
|
|
117
|
+
TypeFactory.keyword("any"),
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
)("guard"),
|
|
121
|
+
undefined,
|
|
122
|
+
[Guardian.identifier()],
|
|
123
|
+
),
|
|
124
|
+
),
|
|
108
125
|
StatementFactory.constant("__is", is),
|
|
109
126
|
ts.factory.createIfStatement(
|
|
110
127
|
ts.factory.createStrictEquality(
|
|
@@ -159,7 +176,7 @@ export namespace AssertProgrammer {
|
|
|
159
176
|
? binary.expression
|
|
160
177
|
: ts.factory.createLogicalOr(
|
|
161
178
|
binary.expression,
|
|
162
|
-
create_guard_call(
|
|
179
|
+
create_guard_call(
|
|
163
180
|
explore.source === "top"
|
|
164
181
|
? ts.factory.createTrue()
|
|
165
182
|
: ts.factory.createIdentifier("_exceptionable"),
|
|
@@ -171,7 +188,7 @@ export namespace AssertProgrammer {
|
|
|
171
188
|
binaries
|
|
172
189
|
.map((binary) => binary.expression)
|
|
173
190
|
.reduce(ts.factory.createLogicalOr),
|
|
174
|
-
create_guard_call(
|
|
191
|
+
create_guard_call(
|
|
175
192
|
explore.source === "top"
|
|
176
193
|
? ts.factory.createTrue()
|
|
177
194
|
: ts.factory.createIdentifier("_exceptionable"),
|
|
@@ -184,7 +201,7 @@ export namespace AssertProgrammer {
|
|
|
184
201
|
// ) {
|
|
185
202
|
// addicted.push({
|
|
186
203
|
// combined: true,
|
|
187
|
-
// expression: create_guard_call(
|
|
204
|
+
// expression: create_guard_call(
|
|
188
205
|
// explore.source === "top"
|
|
189
206
|
// ? ts.factory.createTrue()
|
|
190
207
|
// : ts.factory.createIdentifier(
|
|
@@ -212,7 +229,7 @@ export namespace AssertProgrammer {
|
|
|
212
229
|
reduce: ts.factory.createLogicalAnd,
|
|
213
230
|
positive: ts.factory.createTrue(),
|
|
214
231
|
superfluous: (value) =>
|
|
215
|
-
create_guard_call(
|
|
232
|
+
create_guard_call()(
|
|
216
233
|
ts.factory.createAdd(
|
|
217
234
|
ts.factory.createIdentifier("_path"),
|
|
218
235
|
ts.factory.createCallExpression(importer.use("join"), undefined, [
|
|
@@ -244,7 +261,7 @@ export namespace AssertProgrammer {
|
|
|
244
261
|
[arrow],
|
|
245
262
|
),
|
|
246
263
|
failure: (value, expected, explore) =>
|
|
247
|
-
create_guard_call(
|
|
264
|
+
create_guard_call(
|
|
248
265
|
explore?.from === "top"
|
|
249
266
|
? ts.factory.createTrue()
|
|
250
267
|
: ts.factory.createIdentifier("_exceptionable"),
|
|
@@ -260,7 +277,7 @@ export namespace AssertProgrammer {
|
|
|
260
277
|
: (condition) => (input, expected, explore) =>
|
|
261
278
|
ts.factory.createLogicalOr(
|
|
262
279
|
condition,
|
|
263
|
-
create_guard_call(
|
|
280
|
+
create_guard_call(
|
|
264
281
|
explore.from === "top"
|
|
265
282
|
? ts.factory.createTrue()
|
|
266
283
|
: ts.factory.createIdentifier("_exceptionable"),
|
|
@@ -269,25 +286,49 @@ export namespace AssertProgrammer {
|
|
|
269
286
|
});
|
|
270
287
|
|
|
271
288
|
const create_guard_call =
|
|
272
|
-
(importer: FunctionImporter) =>
|
|
273
289
|
(exceptionable?: ts.Expression) =>
|
|
274
290
|
(
|
|
275
291
|
path: ts.Expression,
|
|
276
292
|
expected: string,
|
|
277
293
|
value: ts.Expression,
|
|
278
294
|
): ts.Expression =>
|
|
279
|
-
ts.factory.createCallExpression(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
ts.factory.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
295
|
+
ts.factory.createCallExpression(
|
|
296
|
+
ts.factory.createIdentifier("$guard"),
|
|
297
|
+
undefined,
|
|
298
|
+
[
|
|
299
|
+
exceptionable ?? ts.factory.createIdentifier("_exceptionable"),
|
|
300
|
+
ts.factory.createObjectLiteralExpression(
|
|
301
|
+
[
|
|
302
|
+
ts.factory.createPropertyAssignment("path", path),
|
|
303
|
+
ts.factory.createPropertyAssignment(
|
|
304
|
+
"expected",
|
|
305
|
+
ts.factory.createStringLiteral(expected),
|
|
306
|
+
),
|
|
307
|
+
ts.factory.createPropertyAssignment("value", value),
|
|
308
|
+
],
|
|
309
|
+
true,
|
|
310
|
+
),
|
|
311
|
+
],
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
export namespace Guardian {
|
|
315
|
+
export const identifier = () => ts.factory.createIdentifier("errorFactory");
|
|
316
|
+
export const parameter = (init: ts.Expression | undefined) =>
|
|
317
|
+
IdentifierFactory.parameter(
|
|
318
|
+
"errorFactory",
|
|
319
|
+
ts.factory.createImportTypeNode(
|
|
320
|
+
ts.factory.createLiteralTypeNode(
|
|
321
|
+
ts.factory.createStringLiteral("typia"),
|
|
322
|
+
),
|
|
323
|
+
undefined,
|
|
324
|
+
ts.factory.createQualifiedName(
|
|
325
|
+
ts.factory.createIdentifier("TypeGuardError"),
|
|
326
|
+
ts.factory.createIdentifier("IProps"),
|
|
327
|
+
),
|
|
328
|
+
undefined,
|
|
329
|
+
false,
|
|
291
330
|
),
|
|
292
|
-
|
|
331
|
+
init ?? ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
332
|
+
);
|
|
333
|
+
}
|
|
293
334
|
}
|
|
@@ -13,7 +13,7 @@ export namespace HttpAssertFormDataProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression): ts.ArrowFunction =>
|
|
17
17
|
ts.factory.createArrowFunction(
|
|
18
18
|
undefined,
|
|
19
19
|
undefined,
|
|
@@ -22,6 +22,7 @@ export namespace HttpAssertFormDataProgrammer {
|
|
|
22
22
|
"input",
|
|
23
23
|
ts.factory.createTypeReferenceNode("FormData"),
|
|
24
24
|
),
|
|
25
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
25
26
|
],
|
|
26
27
|
ts.factory.createTypeReferenceNode(
|
|
27
28
|
`typia.Resolved<${
|
|
@@ -65,7 +66,10 @@ export namespace HttpAssertFormDataProgrammer {
|
|
|
65
66
|
ts.factory.createCallExpression(
|
|
66
67
|
ts.factory.createIdentifier("assert"),
|
|
67
68
|
undefined,
|
|
68
|
-
[
|
|
69
|
+
[
|
|
70
|
+
ts.factory.createIdentifier("output"),
|
|
71
|
+
AssertProgrammer.Guardian.identifier(),
|
|
72
|
+
],
|
|
69
73
|
),
|
|
70
74
|
TypeFactory.keyword("any"),
|
|
71
75
|
),
|
|
@@ -13,7 +13,7 @@ export namespace HttpAssertHeadersProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression): ts.ArrowFunction =>
|
|
17
17
|
ts.factory.createArrowFunction(
|
|
18
18
|
undefined,
|
|
19
19
|
undefined,
|
|
@@ -24,6 +24,7 @@ export namespace HttpAssertHeadersProgrammer {
|
|
|
24
24
|
HttpHeadersProgrammer.INPUT_TYPE,
|
|
25
25
|
),
|
|
26
26
|
),
|
|
27
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
27
28
|
],
|
|
28
29
|
ts.factory.createTypeReferenceNode(
|
|
29
30
|
`typia.Resolved<${
|
|
@@ -67,7 +68,10 @@ export namespace HttpAssertHeadersProgrammer {
|
|
|
67
68
|
ts.factory.createCallExpression(
|
|
68
69
|
ts.factory.createIdentifier("assert"),
|
|
69
70
|
undefined,
|
|
70
|
-
[
|
|
71
|
+
[
|
|
72
|
+
ts.factory.createIdentifier("output"),
|
|
73
|
+
AssertProgrammer.Guardian.identifier(),
|
|
74
|
+
],
|
|
71
75
|
),
|
|
72
76
|
TypeFactory.keyword("any"),
|
|
73
77
|
),
|
|
@@ -13,7 +13,7 @@ export namespace HttpAssertQueryProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression): ts.ArrowFunction =>
|
|
17
17
|
ts.factory.createArrowFunction(
|
|
18
18
|
undefined,
|
|
19
19
|
undefined,
|
|
@@ -22,6 +22,7 @@ export namespace HttpAssertQueryProgrammer {
|
|
|
22
22
|
"input",
|
|
23
23
|
ts.factory.createTypeReferenceNode(HttpQueryProgrammer.INPUT_TYPE),
|
|
24
24
|
),
|
|
25
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
25
26
|
],
|
|
26
27
|
ts.factory.createTypeReferenceNode(
|
|
27
28
|
`typia.Resolved<${
|
|
@@ -65,7 +66,10 @@ export namespace HttpAssertQueryProgrammer {
|
|
|
65
66
|
ts.factory.createCallExpression(
|
|
66
67
|
ts.factory.createIdentifier("assert"),
|
|
67
68
|
undefined,
|
|
68
|
-
[
|
|
69
|
+
[
|
|
70
|
+
ts.factory.createIdentifier("output"),
|
|
71
|
+
AssertProgrammer.Guardian.identifier(),
|
|
72
|
+
],
|
|
69
73
|
),
|
|
70
74
|
TypeFactory.keyword("any"),
|
|
71
75
|
),
|
|
@@ -13,7 +13,7 @@ export namespace JsonAssertParseProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string): ts.ArrowFunction => {
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression): ts.ArrowFunction => {
|
|
17
17
|
JsonMetadataFactory.analyze(`typia.json.${modulo.getText()}`)(
|
|
18
18
|
project.checker,
|
|
19
19
|
project.context,
|
|
@@ -21,7 +21,10 @@ export namespace JsonAssertParseProgrammer {
|
|
|
21
21
|
return ts.factory.createArrowFunction(
|
|
22
22
|
undefined,
|
|
23
23
|
undefined,
|
|
24
|
-
[
|
|
24
|
+
[
|
|
25
|
+
IdentifierFactory.parameter("input", TypeFactory.keyword("string")),
|
|
26
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
27
|
+
],
|
|
25
28
|
ts.factory.createTypeReferenceNode(
|
|
26
29
|
`typia.Primitive<${
|
|
27
30
|
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
@@ -56,7 +59,10 @@ export namespace JsonAssertParseProgrammer {
|
|
|
56
59
|
ts.factory.createCallExpression(
|
|
57
60
|
ts.factory.createIdentifier("assert"),
|
|
58
61
|
undefined,
|
|
59
|
-
[
|
|
62
|
+
[
|
|
63
|
+
ts.factory.createIdentifier("input"),
|
|
64
|
+
AssertProgrammer.Guardian.identifier(),
|
|
65
|
+
],
|
|
60
66
|
),
|
|
61
67
|
ts.factory.createTypeReferenceNode("any"),
|
|
62
68
|
),
|
|
@@ -13,11 +13,14 @@ export namespace JsonAssertStringifyProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string) =>
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression) =>
|
|
17
17
|
ts.factory.createArrowFunction(
|
|
18
18
|
undefined,
|
|
19
19
|
undefined,
|
|
20
|
-
[
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
|
|
22
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
23
|
+
],
|
|
21
24
|
TypeFactory.keyword("string"),
|
|
22
25
|
undefined,
|
|
23
26
|
ts.factory.createBlock([
|
|
@@ -51,7 +54,10 @@ export namespace JsonAssertStringifyProgrammer {
|
|
|
51
54
|
ts.factory.createCallExpression(
|
|
52
55
|
ts.factory.createIdentifier("assert"),
|
|
53
56
|
undefined,
|
|
54
|
-
[
|
|
57
|
+
[
|
|
58
|
+
ts.factory.createIdentifier("input"),
|
|
59
|
+
AssertProgrammer.Guardian.identifier(),
|
|
60
|
+
],
|
|
55
61
|
),
|
|
56
62
|
],
|
|
57
63
|
),
|
|
@@ -13,11 +13,14 @@ export namespace MiscAssertCloneProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string) =>
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression) =>
|
|
17
17
|
ts.factory.createArrowFunction(
|
|
18
18
|
undefined,
|
|
19
19
|
undefined,
|
|
20
|
-
[
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
|
|
22
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
23
|
+
],
|
|
21
24
|
ts.factory.createTypeReferenceNode(
|
|
22
25
|
`typia.Resolved<${
|
|
23
26
|
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
@@ -44,7 +47,10 @@ export namespace MiscAssertCloneProgrammer {
|
|
|
44
47
|
ts.factory.createCallExpression(
|
|
45
48
|
ts.factory.createIdentifier("assert"),
|
|
46
49
|
undefined,
|
|
47
|
-
[
|
|
50
|
+
[
|
|
51
|
+
ts.factory.createIdentifier("input"),
|
|
52
|
+
AssertProgrammer.Guardian.identifier(),
|
|
53
|
+
],
|
|
48
54
|
),
|
|
49
55
|
),
|
|
50
56
|
StatementFactory.constant(
|
|
@@ -13,11 +13,14 @@ export namespace MiscAssertPruneProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string) =>
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression) =>
|
|
17
17
|
ts.factory.createArrowFunction(
|
|
18
18
|
undefined,
|
|
19
19
|
undefined,
|
|
20
|
-
[
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
|
|
22
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
23
|
+
],
|
|
21
24
|
ts.factory.createTypeReferenceNode(
|
|
22
25
|
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
23
26
|
),
|
|
@@ -42,7 +45,10 @@ export namespace MiscAssertPruneProgrammer {
|
|
|
42
45
|
ts.factory.createCallExpression(
|
|
43
46
|
ts.factory.createIdentifier("assert"),
|
|
44
47
|
undefined,
|
|
45
|
-
[
|
|
48
|
+
[
|
|
49
|
+
ts.factory.createIdentifier("input"),
|
|
50
|
+
AssertProgrammer.Guardian.identifier(),
|
|
51
|
+
],
|
|
46
52
|
),
|
|
47
53
|
),
|
|
48
54
|
ts.factory.createExpressionStatement(
|
|
@@ -14,11 +14,14 @@ export namespace NotationAssertGeneralProgrammer {
|
|
|
14
14
|
(rename: (str: string) => string) =>
|
|
15
15
|
(project: IProject) =>
|
|
16
16
|
(modulo: ts.LeftHandSideExpression) =>
|
|
17
|
-
(type: ts.Type, name?: string) =>
|
|
17
|
+
(type: ts.Type, name?: string, init?: ts.Expression) =>
|
|
18
18
|
ts.factory.createArrowFunction(
|
|
19
19
|
undefined,
|
|
20
20
|
undefined,
|
|
21
|
-
[
|
|
21
|
+
[
|
|
22
|
+
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
|
|
23
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
24
|
+
],
|
|
22
25
|
ts.factory.createTypeReferenceNode(
|
|
23
26
|
NotationGeneralProgrammer.returnType(rename)(
|
|
24
27
|
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
@@ -45,7 +48,10 @@ export namespace NotationAssertGeneralProgrammer {
|
|
|
45
48
|
ts.factory.createCallExpression(
|
|
46
49
|
ts.factory.createIdentifier("assert"),
|
|
47
50
|
undefined,
|
|
48
|
-
[
|
|
51
|
+
[
|
|
52
|
+
ts.factory.createIdentifier("input"),
|
|
53
|
+
AssertProgrammer.Guardian.identifier(),
|
|
54
|
+
],
|
|
49
55
|
),
|
|
50
56
|
),
|
|
51
57
|
StatementFactory.constant(
|
|
@@ -13,7 +13,7 @@ export namespace ProtobufAssertDecodeProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string) =>
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression) =>
|
|
17
17
|
ts.factory.createArrowFunction(
|
|
18
18
|
undefined,
|
|
19
19
|
undefined,
|
|
@@ -22,6 +22,7 @@ export namespace ProtobufAssertDecodeProgrammer {
|
|
|
22
22
|
"input",
|
|
23
23
|
ts.factory.createTypeReferenceNode("Uint8Array"),
|
|
24
24
|
),
|
|
25
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
25
26
|
],
|
|
26
27
|
ts.factory.createTypeReferenceNode(
|
|
27
28
|
`typia.Resolved<${
|
|
@@ -65,7 +66,10 @@ export namespace ProtobufAssertDecodeProgrammer {
|
|
|
65
66
|
ts.factory.createCallExpression(
|
|
66
67
|
ts.factory.createIdentifier("assert"),
|
|
67
68
|
undefined,
|
|
68
|
-
[
|
|
69
|
+
[
|
|
70
|
+
ts.factory.createIdentifier("output"),
|
|
71
|
+
AssertProgrammer.Guardian.identifier(),
|
|
72
|
+
],
|
|
69
73
|
),
|
|
70
74
|
TypeFactory.keyword("any"),
|
|
71
75
|
),
|
|
@@ -13,11 +13,14 @@ export namespace ProtobufAssertEncodeProgrammer {
|
|
|
13
13
|
export const write =
|
|
14
14
|
(project: IProject) =>
|
|
15
15
|
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
16
|
+
(type: ts.Type, name?: string, init?: ts.Expression): ts.ArrowFunction =>
|
|
17
17
|
ts.factory.createArrowFunction(
|
|
18
18
|
undefined,
|
|
19
19
|
undefined,
|
|
20
|
-
[
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
|
|
22
|
+
AssertProgrammer.Guardian.parameter(init),
|
|
23
|
+
],
|
|
21
24
|
ts.factory.createTypeReferenceNode("Uint8Array"),
|
|
22
25
|
undefined,
|
|
23
26
|
ts.factory.createBlock([
|
|
@@ -51,7 +54,10 @@ export namespace ProtobufAssertEncodeProgrammer {
|
|
|
51
54
|
ts.factory.createCallExpression(
|
|
52
55
|
ts.factory.createIdentifier("assert"),
|
|
53
56
|
undefined,
|
|
54
|
-
[
|
|
57
|
+
[
|
|
58
|
+
ts.factory.createIdentifier("input"),
|
|
59
|
+
AssertProgrammer.Guardian.identifier(),
|
|
60
|
+
],
|
|
55
61
|
),
|
|
56
62
|
],
|
|
57
63
|
),
|
package/src/protobuf.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as Namespace from "./functional/Namespace";
|
|
|
2
2
|
|
|
3
3
|
import { IValidation } from "./IValidation";
|
|
4
4
|
import { Resolved } from "./Resolved";
|
|
5
|
+
import { TypeGuardError } from "./TypeGuardError";
|
|
5
6
|
|
|
6
7
|
/* ===========================================================
|
|
7
8
|
PROTOCOL BUFFER
|
|
@@ -167,7 +168,10 @@ export { decodePure as decode };
|
|
|
167
168
|
*
|
|
168
169
|
* @author Jeongho Nam - https://github.com/samchon
|
|
169
170
|
*/
|
|
170
|
-
function assertDecode(
|
|
171
|
+
function assertDecode(
|
|
172
|
+
input: Uint8Array,
|
|
173
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
174
|
+
): never;
|
|
171
175
|
|
|
172
176
|
/**
|
|
173
177
|
* Protocol Buffer Decoder wity type assertion, but not safe.
|
|
@@ -196,7 +200,10 @@ function assertDecode(input: Uint8Array): never;
|
|
|
196
200
|
*
|
|
197
201
|
* @author Jeongho Nam - https://github.com/samchon
|
|
198
202
|
*/
|
|
199
|
-
function assertDecode<T>(
|
|
203
|
+
function assertDecode<T>(
|
|
204
|
+
input: Uint8Array,
|
|
205
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
206
|
+
): Resolved<T>;
|
|
200
207
|
|
|
201
208
|
/**
|
|
202
209
|
* @internal
|
|
@@ -443,7 +450,10 @@ export { encodePure as encode };
|
|
|
443
450
|
*
|
|
444
451
|
* @author Jeongho Nam - https://github.com/samchon
|
|
445
452
|
*/
|
|
446
|
-
function assertEncode<T>(
|
|
453
|
+
function assertEncode<T>(
|
|
454
|
+
input: T,
|
|
455
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
456
|
+
): Uint8Array;
|
|
447
457
|
|
|
448
458
|
/**
|
|
449
459
|
* Protocol Buffer Encoder with type assertion.
|
|
@@ -476,7 +486,10 @@ function assertEncode<T>(input: T): Uint8Array;
|
|
|
476
486
|
*
|
|
477
487
|
* @author Jeongho Nam - https://github.com/samchon
|
|
478
488
|
*/
|
|
479
|
-
function assertEncode<T>(
|
|
489
|
+
function assertEncode<T>(
|
|
490
|
+
input: unknown,
|
|
491
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
492
|
+
): Uint8Array;
|
|
480
493
|
|
|
481
494
|
/**
|
|
482
495
|
* @internal
|
|
@@ -742,7 +755,9 @@ export { createIsDecodePure as createIsDecode };
|
|
|
742
755
|
*
|
|
743
756
|
* @author Jeongho Nam - https://github.com/samchon
|
|
744
757
|
*/
|
|
745
|
-
function createAssertDecode(
|
|
758
|
+
function createAssertDecode(
|
|
759
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
760
|
+
): never;
|
|
746
761
|
|
|
747
762
|
/**
|
|
748
763
|
* Creates a reusable {@link assertDecode} function.
|
|
@@ -752,7 +767,9 @@ function createAssertDecode(): never;
|
|
|
752
767
|
*
|
|
753
768
|
* @author Jeongho Nam - https://github.com/samchon
|
|
754
769
|
*/
|
|
755
|
-
function createAssertDecode<T>(
|
|
770
|
+
function createAssertDecode<T>(
|
|
771
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
772
|
+
): (input: Uint8Array) => Resolved<T>;
|
|
756
773
|
|
|
757
774
|
/**
|
|
758
775
|
* @internal
|
|
@@ -893,7 +910,9 @@ export { createIsEncodePure as createIsEncode };
|
|
|
893
910
|
*
|
|
894
911
|
* @author Jeongho Nam - https://github.com/samchon
|
|
895
912
|
*/
|
|
896
|
-
function createAssertEncode(
|
|
913
|
+
function createAssertEncode(
|
|
914
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
915
|
+
): never;
|
|
897
916
|
|
|
898
917
|
/**
|
|
899
918
|
* Creates a reusable {@link assertEncode} function.
|
|
@@ -903,7 +922,9 @@ function createAssertEncode(): never;
|
|
|
903
922
|
*
|
|
904
923
|
* @author Jeongho Nam - https://github.com/samchon
|
|
905
924
|
*/
|
|
906
|
-
function createAssertEncode<T>(
|
|
925
|
+
function createAssertEncode<T>(
|
|
926
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
927
|
+
): (input: T) => Uint8Array;
|
|
907
928
|
|
|
908
929
|
/**
|
|
909
930
|
* @internal
|
|
@@ -17,7 +17,7 @@ export namespace GenericTransformer {
|
|
|
17
17
|
(modulo: ts.LeftHandSideExpression) =>
|
|
18
18
|
(expression: ts.CallExpression) => {
|
|
19
19
|
// CHECK PARAMETER
|
|
20
|
-
if (expression.arguments.length
|
|
20
|
+
if (expression.arguments.length === 0)
|
|
21
21
|
throw new TransformerError({
|
|
22
22
|
code: `typia.${method}`,
|
|
23
23
|
message: `no input value.`,
|
|
@@ -51,7 +51,7 @@ export namespace GenericTransformer {
|
|
|
51
51
|
: name(project.checker)(type)(node),
|
|
52
52
|
),
|
|
53
53
|
undefined,
|
|
54
|
-
|
|
54
|
+
expression.arguments,
|
|
55
55
|
);
|
|
56
56
|
};
|
|
57
57
|
|
|
@@ -62,7 +62,11 @@ export namespace GenericTransformer {
|
|
|
62
62
|
project: IProject,
|
|
63
63
|
) => (
|
|
64
64
|
modulo: ts.LeftHandSideExpression,
|
|
65
|
-
) => (
|
|
65
|
+
) => (
|
|
66
|
+
type: ts.Type,
|
|
67
|
+
name: string,
|
|
68
|
+
init?: ts.Expression,
|
|
69
|
+
) => ts.ArrowFunction,
|
|
66
70
|
) =>
|
|
67
71
|
(project: IProject) =>
|
|
68
72
|
(modulo: ts.LeftHandSideExpression) =>
|
|
@@ -85,7 +89,11 @@ export namespace GenericTransformer {
|
|
|
85
89
|
});
|
|
86
90
|
|
|
87
91
|
// DO TRANSFORM
|
|
88
|
-
return programmer(project)(modulo)(
|
|
92
|
+
return programmer(project)(modulo)(
|
|
93
|
+
type,
|
|
94
|
+
node.getFullText().trim(),
|
|
95
|
+
expression.arguments[0],
|
|
96
|
+
);
|
|
89
97
|
};
|
|
90
98
|
|
|
91
99
|
const name =
|