typia 3.5.0-dev.20221219 → 3.5.0-dev.20230107

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 (136) hide show
  1. package/README.md +62 -17
  2. package/lib/executable/internal/TypiaSetupWizard.d.ts +6 -2
  3. package/lib/executable/internal/TypiaSetupWizard.js +25 -23
  4. package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
  5. package/lib/executable/typia.js +11 -10
  6. package/lib/executable/typia.js.map +1 -1
  7. package/lib/factories/MetadataCollection.d.ts +1 -9
  8. package/lib/factories/MetadataCollection.js +2 -77
  9. package/lib/factories/MetadataCollection.js.map +1 -1
  10. package/lib/factories/MetadataTagFactory.js +4 -1
  11. package/lib/factories/MetadataTagFactory.js.map +1 -1
  12. package/lib/factories/ProtocolFactory.d.ts +0 -1
  13. package/lib/factories/ProtocolFactory.js +0 -6
  14. package/lib/factories/ProtocolFactory.js.map +1 -1
  15. package/lib/factories/internal/metadata/iterate_metadata_object.js +4 -2
  16. package/lib/factories/internal/metadata/iterate_metadata_object.js.map +1 -1
  17. package/lib/factories/internal/protocols/iterate_protocol_main.js +2 -3
  18. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -1
  19. package/lib/factories/internal/protocols/iterate_protocol_map.js +3 -4
  20. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
  21. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +2 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
  23. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +3 -4
  24. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
  25. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +3 -4
  26. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -1
  27. package/lib/functional/$number.js +2 -9
  28. package/lib/functional/$number.js.map +1 -1
  29. package/lib/metadata/Metadata.js +32 -29
  30. package/lib/metadata/Metadata.js.map +1 -1
  31. package/lib/programmers/AssertParseProgrammer.js +12 -1
  32. package/lib/programmers/AssertParseProgrammer.js.map +1 -1
  33. package/lib/programmers/AssertProgrammer.js +3 -2
  34. package/lib/programmers/AssertProgrammer.js.map +1 -1
  35. package/lib/programmers/AssertStringifyProgrammer.js +13 -2
  36. package/lib/programmers/AssertStringifyProgrammer.js.map +1 -1
  37. package/lib/programmers/CheckerProgrammer.d.ts +1 -0
  38. package/lib/programmers/CheckerProgrammer.js +153 -138
  39. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  40. package/lib/programmers/IsParseProgrammer.js +12 -1
  41. package/lib/programmers/IsParseProgrammer.js.map +1 -1
  42. package/lib/programmers/IsProgrammer.js +5 -2
  43. package/lib/programmers/IsProgrammer.js.map +1 -1
  44. package/lib/programmers/IsStringifyProgrammer.js +13 -2
  45. package/lib/programmers/IsStringifyProgrammer.js.map +1 -1
  46. package/lib/programmers/MessageProgrammer.js +11 -6
  47. package/lib/programmers/MessageProgrammer.js.map +1 -1
  48. package/lib/programmers/StringifyProgrammer.js +6 -1
  49. package/lib/programmers/StringifyProgrammer.js.map +1 -1
  50. package/lib/programmers/ValidateParseProgrammer.js +12 -1
  51. package/lib/programmers/ValidateParseProgrammer.js.map +1 -1
  52. package/lib/programmers/ValidateProgrammer.js +3 -2
  53. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  54. package/lib/programmers/ValidateStringifyProgrammer.js +13 -2
  55. package/lib/programmers/ValidateStringifyProgrammer.js.map +1 -1
  56. package/lib/programmers/helpers/OptionPredicator.d.ts +2 -1
  57. package/lib/programmers/helpers/OptionPredicator.js +8 -6
  58. package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
  59. package/lib/programmers/helpers/UnionExplorer.d.ts +23 -29
  60. package/lib/programmers/helpers/UnionExplorer.js +29 -41
  61. package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
  62. package/lib/programmers/internal/application_object.js +9 -9
  63. package/lib/programmers/internal/application_object.js.map +1 -1
  64. package/lib/programmers/internal/application_schema.js +14 -6
  65. package/lib/programmers/internal/application_schema.js.map +1 -1
  66. package/lib/programmers/internal/check_array.js +4 -32
  67. package/lib/programmers/internal/check_array.js.map +1 -1
  68. package/lib/programmers/internal/check_array_length.d.ts +1 -0
  69. package/lib/programmers/internal/check_array_length.js +47 -0
  70. package/lib/programmers/internal/check_array_length.js.map +1 -0
  71. package/lib/programmers/internal/check_bigint.d.ts +3 -0
  72. package/lib/programmers/internal/check_bigint.js +97 -0
  73. package/lib/programmers/internal/check_bigint.js.map +1 -0
  74. package/lib/programmers/internal/check_number.js +21 -23
  75. package/lib/programmers/internal/check_number.js.map +1 -1
  76. package/lib/programmers/internal/check_union_array_like.d.ts +21 -0
  77. package/lib/programmers/internal/check_union_array_like.js +83 -0
  78. package/lib/programmers/internal/check_union_array_like.js.map +1 -0
  79. package/lib/programmers/internal/check_union_tuple.d.ts +1 -0
  80. package/lib/programmers/internal/check_union_tuple.js +11 -0
  81. package/lib/programmers/internal/check_union_tuple.js.map +1 -0
  82. package/lib/schemas/IJsonSchema.d.ts +3 -5
  83. package/lib/transformers/ITransformOptions.d.ts +43 -2
  84. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +5 -3
  85. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  86. package/lib/transformers/features/stringifiers/StringifyTransformer.js +12 -1
  87. package/lib/transformers/features/stringifiers/StringifyTransformer.js.map +1 -1
  88. package/lib/utils/NameEncoder.d.ts +4 -0
  89. package/lib/utils/NameEncoder.js +89 -0
  90. package/lib/utils/NameEncoder.js.map +1 -0
  91. package/package.json +6 -5
  92. package/src/executable/internal/TypiaSetupWizard.ts +37 -24
  93. package/src/executable/typia.ts +7 -5
  94. package/src/factories/MetadataCollection.ts +2 -43
  95. package/src/factories/MetadataTagFactory.ts +5 -1
  96. package/src/factories/ProtocolFactory.ts +0 -5
  97. package/src/factories/internal/metadata/iterate_metadata_object.ts +6 -3
  98. package/src/factories/internal/protocols/iterate_protocol_main.ts +2 -3
  99. package/src/factories/internal/protocols/iterate_protocol_map.ts +3 -5
  100. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +1 -0
  101. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +3 -6
  102. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +3 -6
  103. package/src/functional/$number.ts +2 -9
  104. package/src/metadata/Metadata.ts +10 -7
  105. package/src/programmers/AssertParseProgrammer.ts +11 -1
  106. package/src/programmers/AssertProgrammer.ts +4 -3
  107. package/src/programmers/AssertStringifyProgrammer.ts +22 -2
  108. package/src/programmers/CheckerProgrammer.ts +258 -200
  109. package/src/programmers/IsParseProgrammer.ts +11 -1
  110. package/src/programmers/IsProgrammer.ts +5 -2
  111. package/src/programmers/IsStringifyProgrammer.ts +22 -2
  112. package/src/programmers/MessageProgrammer.ts +12 -6
  113. package/src/programmers/StringifyProgrammer.ts +7 -1
  114. package/src/programmers/ValidateParseProgrammer.ts +11 -1
  115. package/src/programmers/ValidateProgrammer.ts +3 -2
  116. package/src/programmers/ValidateStringifyProgrammer.ts +22 -2
  117. package/src/programmers/helpers/OptionPredicator.ts +7 -10
  118. package/src/programmers/helpers/UnionExplorer.ts +75 -238
  119. package/src/programmers/internal/application_default.ts +1 -1
  120. package/src/programmers/internal/application_object.ts +5 -5
  121. package/src/programmers/internal/application_schema.ts +20 -5
  122. package/src/programmers/internal/check_array.ts +3 -25
  123. package/src/programmers/internal/check_array_length.ts +45 -0
  124. package/src/programmers/internal/check_bigint.ts +85 -0
  125. package/src/programmers/internal/check_number.ts +45 -51
  126. package/src/programmers/internal/check_union_array_like.ts +242 -0
  127. package/src/programmers/internal/check_union_tuple.ts +33 -0
  128. package/src/schemas/IJsonSchema.ts +4 -6
  129. package/src/transformers/ITransformOptions.ts +45 -2
  130. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +7 -3
  131. package/src/transformers/features/stringifiers/StringifyTransformer.ts +11 -1
  132. package/src/utils/NameEncoder.ts +32 -0
  133. package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.d.ts +0 -5
  134. package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.js +0 -29
  135. package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.js.map +0 -1
  136. package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +0 -41
@@ -0,0 +1,45 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+
5
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
6
+
7
+ import { check_length } from "./check_length";
8
+
9
+ /**
10
+ * @internal
11
+ */
12
+ export function check_array_length(
13
+ input: ts.Expression,
14
+ tagList: IMetadataTag[],
15
+ ): ts.Expression | null {
16
+ const conditions: ts.Expression[] = [];
17
+
18
+ // CHECK TAGS
19
+ for (const tag of tagList)
20
+ if (tag.kind === "minItems")
21
+ conditions.push(
22
+ ts.factory.createLessThanEquals(
23
+ ts.factory.createNumericLiteral(tag.value),
24
+ IdentifierFactory.join(input, "length"),
25
+ ),
26
+ );
27
+ else if (tag.kind === "maxItems")
28
+ conditions.push(
29
+ ts.factory.createGreaterThanEquals(
30
+ ts.factory.createNumericLiteral(tag.value),
31
+ IdentifierFactory.join(input, "length"),
32
+ ),
33
+ );
34
+ else if (tag.kind === "items")
35
+ check_length(
36
+ conditions,
37
+ IdentifierFactory.join(input, "length"),
38
+ tag,
39
+ );
40
+
41
+ // COMBINATION
42
+ return conditions.length
43
+ ? conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y))
44
+ : null;
45
+ }
@@ -0,0 +1,85 @@
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+
5
+ export function check_bigint(input: ts.Expression, tagList: IMetadataTag[]) {
6
+ const caster = (value: number) =>
7
+ ts.factory.createIdentifier(`${Math.floor(value)}n`);
8
+
9
+ // TYPEOF STATEMENT
10
+ const conditions: ts.Expression[] = [
11
+ ts.factory.createStrictEquality(
12
+ ts.factory.createStringLiteral("bigint"),
13
+ ts.factory.createTypeOfExpression(input),
14
+ ),
15
+ ];
16
+
17
+ // TAG (RANGE)
18
+ for (const tag of tagList)
19
+ if (tag.kind === "multipleOf")
20
+ conditions.push(
21
+ ts.factory.createStrictEquality(
22
+ caster(0),
23
+ ts.factory.createModulo(input, caster(tag.value)),
24
+ ),
25
+ );
26
+ else if (tag.kind === "step") {
27
+ const modulo = () =>
28
+ ts.factory.createModulo(input, caster(tag.value));
29
+ const minimum = (() => {
30
+ for (const tag of tagList)
31
+ if (tag.kind === "minimum") return tag.value;
32
+ else if (tag.kind === "exclusiveMinimum") return tag.value;
33
+ else if (tag.kind === "range" && tag.minimum !== undefined)
34
+ return tag.minimum.value;
35
+ return undefined;
36
+ })();
37
+ conditions.push(
38
+ ts.factory.createStrictEquality(
39
+ caster(0),
40
+ minimum !== undefined
41
+ ? ts.factory.createSubtract(modulo(), caster(minimum))
42
+ : modulo(),
43
+ ),
44
+ );
45
+ } else if (tag.kind === "range") {
46
+ if (tag.minimum !== undefined)
47
+ conditions.push(
48
+ (tag.minimum.include
49
+ ? ts.factory.createLessThanEquals
50
+ : ts.factory.createLessThan)(
51
+ caster(tag.minimum.value),
52
+ input,
53
+ ),
54
+ );
55
+ if (tag.maximum !== undefined)
56
+ conditions.push(
57
+ (tag.maximum.include
58
+ ? ts.factory.createLessThanEquals
59
+ : ts.factory.createLessThan)(
60
+ input,
61
+ caster(tag.maximum.value),
62
+ ),
63
+ );
64
+ } else if (tag.kind === "minimum")
65
+ conditions.push(
66
+ ts.factory.createLessThanEquals(caster(tag.value), input),
67
+ );
68
+ else if (tag.kind === "maximum")
69
+ conditions.push(
70
+ ts.factory.createGreaterThanEquals(caster(tag.value), input),
71
+ );
72
+ else if (tag.kind === "exclusiveMinimum")
73
+ conditions.push(
74
+ ts.factory.createLessThan(caster(tag.value), input),
75
+ );
76
+ else if (tag.kind === "exclusiveMaximum")
77
+ conditions.push(
78
+ ts.factory.createGreaterThan(caster(tag.value), input),
79
+ );
80
+
81
+ // COMBINATION
82
+ return conditions.length === 1
83
+ ? conditions[0]!
84
+ : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
85
+ }
@@ -9,9 +9,10 @@ import { OptionPredicator } from "../helpers/OptionPredicator";
9
9
  /**
10
10
  * @internal
11
11
  */
12
- export function check_number(project: IProject, numeric: boolean) {
13
- return function (input: ts.Expression, tagList: IMetadataTag[]) {
14
- // TYPEOF
12
+ export const check_number =
13
+ ({ options }: IProject, numeric: boolean) =>
14
+ (input: ts.Expression, tagList: IMetadataTag[]) => {
15
+ // TYPEOF STATEMENT
15
16
  const conditions: ts.Expression[] = [
16
17
  ts.factory.createStrictEquality(
17
18
  ts.factory.createStringLiteral("number"),
@@ -19,6 +20,47 @@ export function check_number(project: IProject, numeric: boolean) {
19
20
  ),
20
21
  ];
21
22
 
23
+ // CHECK FINITE AND NAN
24
+ const finite: boolean =
25
+ !!tagList.find(
26
+ (tag) =>
27
+ tag.kind === "range" &&
28
+ tag.minimum !== undefined &&
29
+ tag.maximum !== undefined,
30
+ ) ||
31
+ (!!tagList.find(
32
+ (tag) =>
33
+ tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
34
+ ) &&
35
+ !!tagList.find(
36
+ (tag) =>
37
+ tag.kind === "maximum" ||
38
+ tag.kind === "exclusiveMaximum",
39
+ )) ||
40
+ !!tagList.find(
41
+ (tag) => tag.kind === "step" || tag.kind === "multipleOf",
42
+ );
43
+
44
+ if (numeric === true && finite === false)
45
+ if (OptionPredicator.finite(options))
46
+ conditions.push(
47
+ ts.factory.createCallExpression(
48
+ ts.factory.createIdentifier("Number.isFinite"),
49
+ undefined,
50
+ [input],
51
+ ),
52
+ );
53
+ else if (OptionPredicator.numeric(options))
54
+ conditions.push(
55
+ ts.factory.createLogicalNot(
56
+ ts.factory.createCallExpression(
57
+ ts.factory.createIdentifier("Number.isNaN"),
58
+ undefined,
59
+ [input],
60
+ ),
61
+ ),
62
+ );
63
+
22
64
  // TAG (RANGE)
23
65
  for (const tag of tagList)
24
66
  if (tag.kind === "type") {
@@ -126,56 +168,8 @@ export function check_number(project: IProject, numeric: boolean) {
126
168
  ),
127
169
  );
128
170
 
129
- // NUMERIC VALIDATION
130
- const finite: boolean =
131
- !!tagList.find(
132
- (tag) =>
133
- tag.kind === "range" &&
134
- tag.minimum !== undefined &&
135
- tag.maximum !== undefined,
136
- ) ||
137
- (!!tagList.find(
138
- (tag) =>
139
- tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
140
- ) &&
141
- !!tagList.find(
142
- (tag) =>
143
- tag.kind === "maximum" ||
144
- tag.kind === "exclusiveMaximum",
145
- )) ||
146
- !!tagList.find(
147
- (tag) => tag.kind === "step" || tag.kind === "multipleOf",
148
- );
149
- const valid: boolean =
150
- finite || tagList.find((tag) => tag.kind === "type") !== undefined;
151
-
152
- if (
153
- numeric &&
154
- OptionPredicator.numeric(project.options, "checker") === false
155
- ) {
156
- if (finite === false)
157
- conditions.push(
158
- ts.factory.createCallExpression(
159
- ts.factory.createIdentifier("Number.isFinite"),
160
- undefined,
161
- [input],
162
- ),
163
- );
164
- if (valid === false)
165
- conditions.push(
166
- ts.factory.createLogicalNot(
167
- ts.factory.createCallExpression(
168
- ts.factory.createIdentifier("Number.isNaN"),
169
- undefined,
170
- [input],
171
- ),
172
- ),
173
- );
174
- }
175
-
176
171
  // COMBINATION
177
172
  return conditions.length === 1
178
173
  ? conditions[0]!
179
174
  : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
180
175
  };
181
- }
@@ -0,0 +1,242 @@
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+ import { StatementFactory } from "../../factories/StatementFactory";
5
+
6
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
7
+
8
+ import { CheckerProgrammer } from "../CheckerProgrammer";
9
+ import { FeatureProgrammer } from "../FeatureProgrammer";
10
+ import { UnionExplorer } from "../helpers/UnionExplorer";
11
+
12
+ export const check_union_array_like =
13
+ <T>(accessor: check_union_array_like.IAccessor<T>) =>
14
+ (props: check_union_array_like.IProps<T>) =>
15
+ (
16
+ input: ts.Expression,
17
+ targets: T[],
18
+ explore: FeatureProgrammer.IExplore,
19
+ tags: IMetadataTag[],
20
+ ) => {
21
+ // ONLY ONE TYPE
22
+ if (targets.length === 1)
23
+ return props.decoder(
24
+ accessor.array(input),
25
+ targets[0]!,
26
+ explore,
27
+ tags,
28
+ );
29
+
30
+ //----
31
+ // LIST UP VARIABLES
32
+ //----
33
+ // TUPLES
34
+ const tupleListVariable: ts.VariableStatement =
35
+ StatementFactory.constant(
36
+ "tupleList",
37
+ ts.factory.createArrayLiteralExpression(
38
+ targets.map((meta) =>
39
+ ts.factory.createArrayLiteralExpression([
40
+ ts.factory.createArrowFunction(
41
+ undefined,
42
+ undefined,
43
+ [IdentifierFactory.parameter("top")],
44
+ undefined,
45
+ undefined,
46
+ props.checker(
47
+ ts.factory.createIdentifier("top"),
48
+ meta,
49
+ {
50
+ ...explore,
51
+ tracable: false,
52
+ postfix: `"[0]"`,
53
+ },
54
+ tags,
55
+ input,
56
+ ),
57
+ ),
58
+ ts.factory.createArrowFunction(
59
+ undefined,
60
+ undefined,
61
+ [IdentifierFactory.parameter("top")],
62
+ undefined,
63
+ undefined,
64
+ props.decoder(
65
+ ts.factory.createIdentifier("top"),
66
+ meta,
67
+ {
68
+ ...explore,
69
+ tracable: true,
70
+ },
71
+ tags,
72
+ ),
73
+ ),
74
+ ]),
75
+ ),
76
+ ),
77
+ );
78
+
79
+ // FILTERED TUPLES
80
+ const filteredVariable = StatementFactory.constant(
81
+ "filtered",
82
+ ts.factory.createCallExpression(
83
+ ts.factory.createIdentifier("tupleList.filter"),
84
+ undefined,
85
+ [
86
+ ts.factory.createArrowFunction(
87
+ undefined,
88
+ undefined,
89
+ [IdentifierFactory.parameter("tuple")],
90
+ undefined,
91
+ undefined,
92
+ ts.factory.createStrictEquality(
93
+ props.success,
94
+ ts.factory.createCallExpression(
95
+ ts.factory.createIdentifier("tuple[0]"),
96
+ undefined,
97
+ [ts.factory.createIdentifier("front")],
98
+ ),
99
+ ),
100
+ ),
101
+ ],
102
+ ),
103
+ );
104
+
105
+ //----
106
+ // STATEMENTS
107
+ //----
108
+ // ONLY ONE TYPE
109
+ const uniqueStatement = ts.factory.createIfStatement(
110
+ ts.factory.createStrictEquality(
111
+ ts.factory.createNumericLiteral(1),
112
+ ts.factory.createIdentifier("filtered.length"),
113
+ ),
114
+ ts.factory.createReturnStatement(
115
+ ts.factory.createCallExpression(
116
+ ts.factory.createIdentifier(`filtered[0][1]`),
117
+ undefined,
118
+ [accessor.array(input)],
119
+ ),
120
+ ),
121
+ );
122
+
123
+ // UNION TYPE
124
+ const forOfStatement = ts.factory.createForOfStatement(
125
+ undefined,
126
+ ts.factory.createVariableDeclarationList(
127
+ [ts.factory.createVariableDeclaration("tuple")],
128
+ ts.NodeFlags.Const,
129
+ ),
130
+ // StatementFactory.variable(ts.NodeFlags.Const, "tuple"),
131
+ ts.factory.createIdentifier("filtered"),
132
+ ts.factory.createIfStatement(
133
+ ts.factory.createCallExpression(
134
+ IdentifierFactory.join(
135
+ ts.factory.createIdentifier("array"),
136
+ "every",
137
+ ),
138
+ undefined,
139
+ [
140
+ ts.factory.createArrowFunction(
141
+ undefined,
142
+ undefined,
143
+ [IdentifierFactory.parameter("value")],
144
+ undefined,
145
+ undefined,
146
+ ts.factory.createStrictEquality(
147
+ props.success,
148
+ ts.factory.createCallExpression(
149
+ ts.factory.createIdentifier("tuple[0]"),
150
+ undefined,
151
+ [ts.factory.createIdentifier("value")],
152
+ ),
153
+ ),
154
+ ),
155
+ ],
156
+ ),
157
+ ts.factory.createReturnStatement(
158
+ ts.factory.createCallExpression(
159
+ ts.factory.createIdentifier(`tuple[1]`),
160
+ undefined,
161
+ [ts.factory.createIdentifier("array")],
162
+ ),
163
+ ),
164
+ ),
165
+ );
166
+ const unionStatement = ts.factory.createIfStatement(
167
+ ts.factory.createLessThan(
168
+ ts.factory.createNumericLiteral(1),
169
+ ts.factory.createIdentifier("filtered.length"),
170
+ ),
171
+ forOfStatement,
172
+ );
173
+
174
+ const block = [
175
+ // ARRAY.LENGTH := 0
176
+ ...(accessor.size !== null
177
+ ? [
178
+ ts.factory.createIfStatement(
179
+ ts.factory.createStrictEquality(
180
+ ts.factory.createNumericLiteral(0),
181
+ accessor.size(input),
182
+ ),
183
+ ts.factory.createReturnStatement(props.empty),
184
+ ),
185
+ ]
186
+ : []),
187
+
188
+ // UNION PREDICATORS
189
+ tupleListVariable,
190
+ StatementFactory.constant("front", accessor.front(input)),
191
+ filteredVariable,
192
+ uniqueStatement,
193
+
194
+ // CONDITIONAL STATEMENTS
195
+ StatementFactory.constant("array", accessor.array(input)),
196
+ unionStatement,
197
+ props.failure(
198
+ input,
199
+ `(${targets.map((t) => accessor.name(t)).join(" | ")})`,
200
+ explore,
201
+ ),
202
+ ];
203
+
204
+ return ts.factory.createCallExpression(
205
+ ts.factory.createArrowFunction(
206
+ undefined,
207
+ undefined,
208
+ [],
209
+ undefined,
210
+ undefined,
211
+ ts.factory.createBlock(block, true),
212
+ ),
213
+ undefined,
214
+ undefined,
215
+ );
216
+ };
217
+ export namespace check_union_array_like {
218
+ export interface IProps<T> {
219
+ checker(
220
+ front: ts.Expression,
221
+ target: T,
222
+ explore: FeatureProgrammer.IExplore,
223
+ tags: IMetadataTag[],
224
+ array: ts.Expression,
225
+ ): ts.Expression;
226
+ decoder: UnionExplorer.Decoder<T>;
227
+ empty: ts.Expression;
228
+ success: ts.Expression;
229
+ failure(
230
+ input: ts.Expression,
231
+ expected: string,
232
+ explore: CheckerProgrammer.IExplore,
233
+ ): ts.Statement;
234
+ }
235
+
236
+ export interface IAccessor<T> {
237
+ name(target: T): string;
238
+ front(input: ts.Expression): ts.Expression;
239
+ array(input: ts.Expression): ts.Expression;
240
+ size: null | ((input: ts.Expression) => ts.Expression);
241
+ }
242
+ }
@@ -0,0 +1,33 @@
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+ import { Metadata } from "../../metadata/Metadata";
5
+
6
+ import { IProject } from "../../transformers/IProject";
7
+
8
+ import { CheckerProgrammer } from "../CheckerProgrammer";
9
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
10
+
11
+ /**
12
+ * @internal
13
+ * @todo Faster union checking logic is required
14
+ */
15
+ export const check_union_tuple =
16
+ (
17
+ project: IProject,
18
+ config: CheckerProgrammer.IConfig,
19
+ importer: FunctionImporter,
20
+ ) =>
21
+ (
22
+ _front: ts.Expression,
23
+ elements: Metadata[],
24
+ explore: CheckerProgrammer.IExplore,
25
+ tags: IMetadataTag[],
26
+ array: ts.Expression,
27
+ ) =>
28
+ CheckerProgrammer.decode_tuple(project, config, importer, true)(
29
+ array,
30
+ elements,
31
+ explore,
32
+ tags,
33
+ );
@@ -8,11 +8,9 @@ export namespace IJsonSchema {
8
8
  export type NotUnknown =
9
9
  | IEnumeration<"boolean">
10
10
  | IEnumeration<"number">
11
- | IEnumeration<"bigint">
12
11
  | IEnumeration<"string">
13
12
  | IBoolean
14
13
  | INumber
15
- | IBigInt
16
14
  | IString
17
15
  | IArray
18
16
  | ITuple
@@ -24,11 +22,12 @@ export namespace IJsonSchema {
24
22
  /* -----------------------------------------------------------
25
23
  ATOMICS
26
24
  ----------------------------------------------------------- */
27
- export interface IEnumeration<Literal extends Atomic.Literal>
28
- extends IAtomic<Literal> {
25
+ export interface IEnumeration<
26
+ Literal extends Exclude<Atomic.Literal, "bigint">,
27
+ > extends IAtomic<Literal> {
29
28
  enum: Array<Atomic.Mapper[Literal]>;
30
29
  }
31
- export interface IAtomic<Literal extends Atomic.Literal>
30
+ export interface IAtomic<Literal extends Exclude<Atomic.Literal, "bigint">>
32
31
  extends ISignificant<Literal> {
33
32
  default?: Atomic.Mapper[Literal];
34
33
  }
@@ -46,7 +45,6 @@ export namespace IJsonSchema {
46
45
  multipleOf?: number;
47
46
  }
48
47
  export interface IBoolean extends IAtomic<"boolean"> {}
49
- export interface IBigInt extends IAtomic<"bigint"> {}
50
48
 
51
49
  /* -----------------------------------------------------------
52
50
  OBJECTS
@@ -1,4 +1,47 @@
1
1
  export interface ITransformOptions {
2
- functional?: boolean | "checker" | "stringify";
3
- numeric?: boolean | "checker" | "stringify";
2
+ /**
3
+ * Whether to validate finite number or not.
4
+ *
5
+ * If configured true, number typed values would be validated by Number.isNaN().
6
+ *
7
+ * However, whatever you configure, it would be ignored when marshaling or parsing.
8
+ *
9
+ * - when marshaling, always be true
10
+ * - assertStringify()
11
+ * - validateEncode()
12
+ * - when parsing, always be false
13
+ * - assertParse()
14
+ * - isDecode()
15
+ *
16
+ * @default false
17
+ */
18
+ finite?: boolean;
19
+
20
+ /**
21
+ * Whether to validate finite number or not.
22
+ *
23
+ * If configured true, number typed values would be validated by Number.isFinite().
24
+ *
25
+ * However, whatever you configure, it can be ignored in below case.
26
+ *
27
+ * - when `finite` option is true, this option would be ignored
28
+ * - when marshaling, always be true
29
+ * - assertStringify()
30
+ * - validateEncode()
31
+ * - when parsing, always be false
32
+ * - assertParse()
33
+ * - isDecode()
34
+ *
35
+ * @default false
36
+ */
37
+ numeric?: boolean;
38
+
39
+ /**
40
+ * Whether to validate functional type or not.
41
+ *
42
+ * However, whatever you configure, it becomes false when marshaling or parsing.
43
+ *
44
+ * @default false
45
+ */
46
+ functional?: boolean;
4
47
  }
@@ -59,13 +59,15 @@ export namespace ApplicationTransformer {
59
59
  // GENERATORS
60
60
  //----
61
61
  // METADATA
62
- const collection: MetadataCollection = new MetadataCollection({
63
- replace: MetadataCollection.replace,
64
- });
62
+ const collection: MetadataCollection = new MetadataCollection();
65
63
  const metadatas: Array<Metadata> = types.map((type) =>
66
64
  MetadataFactory.generate(checker, collection, type, {
67
65
  resolve: true,
68
66
  constant: true,
67
+ validate: (meta) => {
68
+ if (meta.atomics.find((str) => str === "bigint"))
69
+ throw new Error(ErrorMessages.NO_BIGIT);
70
+ },
69
71
  }),
70
72
  );
71
73
 
@@ -111,4 +113,6 @@ export namespace ApplicationTransformer {
111
113
  const enum ErrorMessages {
112
114
  NO_GENERIC_ARGUMENT = "Error on typia.application(): no generic argument.",
113
115
  GENERIC_ARGUMENT = "Error on typia.application(): non-specified generic argument(s).",
116
+ NO_BIGIT = "Error on typia.application(): does not allow bigint type.",
117
+ NO_ZERO_LENGTH_TUPLE = "Error on typia.application(): swagger does not support zero length tuple type.",
114
118
  }
@@ -23,7 +23,17 @@ export namespace StringifyTransformer {
23
23
  throw new Error(ErrorMessages.GENERIC_ARGUMENT);
24
24
 
25
25
  return ts.factory.createCallExpression(
26
- StringifyProgrammer.generate(project, modulo)(type),
26
+ StringifyProgrammer.generate(
27
+ {
28
+ ...project,
29
+ options: {
30
+ ...project.options,
31
+ functional: false,
32
+ numeric: true,
33
+ },
34
+ },
35
+ modulo,
36
+ )(type),
27
37
  undefined,
28
38
  [expression.arguments[0]!],
29
39
  );
@@ -0,0 +1,32 @@
1
+ export namespace NameEncoder {
2
+ export function encode(str: string): string {
3
+ for (const [before, after] of REPLACERS)
4
+ str = str.split(before).join(after);
5
+ return str;
6
+ }
7
+
8
+ export function decode(str: string): string {
9
+ for (const [before, after] of REPLACERS)
10
+ if (after !== "") str = str.split(after).join(before);
11
+ return str;
12
+ }
13
+ }
14
+
15
+ const REPLACERS: [string, string][] = [
16
+ ["$", "_dollar_"],
17
+ ["&", "_and_"],
18
+ ["|", "_or_"],
19
+ ["{", "_blt_"],
20
+ ["}", "_bgt_"],
21
+ ["<", "_lt_"],
22
+ [">", "_gt_"],
23
+ ["(", "_lp_"],
24
+ [")", "_rp_"],
25
+ ["[", "_alt_"],
26
+ ["]", "_agt_"],
27
+ [",", "_comma_"],
28
+ ["`", "_backquote_"],
29
+ ["'", "_singlequote_"],
30
+ ['"', "_doublequote_"],
31
+ [" ", "_space_"],
32
+ ];