typia 5.2.5 → 5.2.6-dev.20231108

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 (64) hide show
  1. package/lib/factories/ExpressionFactory.d.ts +1 -0
  2. package/lib/factories/ExpressionFactory.js +5 -0
  3. package/lib/factories/ExpressionFactory.js.map +1 -1
  4. package/lib/programmers/CheckerProgrammer.js +4 -4
  5. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  6. package/lib/programmers/RandomProgrammer.js +16 -18
  7. package/lib/programmers/RandomProgrammer.js.map +1 -1
  8. package/lib/programmers/ValidateProgrammer.js +2 -1
  9. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  10. package/lib/programmers/helpers/RandomJoiner.js +4 -6
  11. package/lib/programmers/helpers/RandomJoiner.js.map +1 -1
  12. package/lib/programmers/helpers/RandomRanger.js +3 -2
  13. package/lib/programmers/helpers/RandomRanger.js.map +1 -1
  14. package/lib/programmers/http/HttpHeadersProgrammer.js +1 -1
  15. package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
  16. package/lib/programmers/internal/check_dynamic_properties.js +4 -3
  17. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  18. package/lib/programmers/internal/check_union_array_like.js +3 -2
  19. package/lib/programmers/internal/check_union_array_like.js.map +1 -1
  20. package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
  21. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  22. package/lib/programmers/misc/MiscCloneProgrammer.js +1 -3
  23. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  24. package/lib/programmers/misc/MiscLiteralsProgrammer.js +1 -1
  25. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  26. package/lib/programmers/misc/MiscPruneProgrammer.js +1 -3
  27. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  28. package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -3
  29. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  30. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +6 -6
  31. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  32. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +2 -2
  33. package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/Primitive.ts +135 -135
  36. package/src/executable/TypiaSetupWizard.ts +142 -142
  37. package/src/executable/setup/CommandExecutor.ts +8 -8
  38. package/src/factories/ExpressionFactory.ts +8 -0
  39. package/src/factories/JsonMetadataFactory.ts +50 -50
  40. package/src/factories/MetadataCollection.ts +282 -282
  41. package/src/factories/internal/metadata/emplace_metadata_object.ts +178 -178
  42. package/src/functional/$stoll.ts +8 -8
  43. package/src/functional/Namespace.ts +168 -168
  44. package/src/programmers/AssertProgrammer.ts +322 -322
  45. package/src/programmers/CheckerProgrammer.ts +4 -4
  46. package/src/programmers/IsProgrammer.ts +258 -258
  47. package/src/programmers/RandomProgrammer.ts +16 -17
  48. package/src/programmers/ValidateProgrammer.ts +350 -349
  49. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  50. package/src/programmers/helpers/RandomJoiner.ts +4 -6
  51. package/src/programmers/helpers/RandomRanger.ts +4 -2
  52. package/src/programmers/http/HttpHeadersProgrammer.ts +1 -1
  53. package/src/programmers/internal/check_dynamic_key.ts +178 -178
  54. package/src/programmers/internal/check_dynamic_properties.ts +202 -201
  55. package/src/programmers/internal/check_object.ts +62 -62
  56. package/src/programmers/internal/check_union_array_like.ts +4 -3
  57. package/src/programmers/json/JsonStringifyProgrammer.ts +960 -964
  58. package/src/programmers/misc/MiscCloneProgrammer.ts +786 -790
  59. package/src/programmers/misc/MiscLiteralsProgrammer.ts +1 -1
  60. package/src/programmers/misc/MiscPruneProgrammer.ts +548 -552
  61. package/src/programmers/notations/NotationGeneralProgrammer.ts +716 -720
  62. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +7 -9
  63. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +882 -882
  64. package/src/transform.ts +35 -35
@@ -1,31 +1,31 @@
1
- import { Metadata } from "../../schemas/metadata/Metadata";
2
-
3
- import { Atomic } from "../../typings/Atomic";
4
-
5
- import { ArrayUtil } from "../../utils/ArrayUtil";
6
-
7
- export namespace AtomicPredicator {
8
- export const constant =
9
- (meta: Metadata) =>
10
- (name: Atomic.Literal): boolean =>
11
- !ArrayUtil.has(meta.atomics, (a) => a.type === name) &&
12
- !ArrayUtil.has(
13
- meta.natives,
14
- (native) => native.toLowerCase() === name,
15
- );
16
-
17
- export const atomic =
18
- (meta: Metadata) =>
19
- (name: Atomic.Literal): boolean =>
20
- !ArrayUtil.has(
21
- meta.natives,
22
- (native) => native.toLowerCase() === name,
23
- );
24
-
25
- export const native = (name: string) => LIKE.has(name.toLowerCase());
26
-
27
- export const template = (meta: Metadata): boolean =>
28
- !ArrayUtil.has(meta.atomics, (a) => a.type === "string");
29
- }
30
-
31
- const LIKE = new Set(["boolean", "bigint", "number", "string"]);
1
+ import { Metadata } from "../../schemas/metadata/Metadata";
2
+
3
+ import { Atomic } from "../../typings/Atomic";
4
+
5
+ import { ArrayUtil } from "../../utils/ArrayUtil";
6
+
7
+ export namespace AtomicPredicator {
8
+ export const constant =
9
+ (meta: Metadata) =>
10
+ (name: Atomic.Literal): boolean =>
11
+ !ArrayUtil.has(meta.atomics, (a) => a.type === name) &&
12
+ !ArrayUtil.has(
13
+ meta.natives,
14
+ (native) => native.toLowerCase() === name,
15
+ );
16
+
17
+ export const atomic =
18
+ (meta: Metadata) =>
19
+ (name: Atomic.Literal): boolean =>
20
+ !ArrayUtil.has(
21
+ meta.natives,
22
+ (native) => native.toLowerCase() === name,
23
+ );
24
+
25
+ export const native = (name: string) => LIKE.has(name.toLowerCase());
26
+
27
+ export const template = (meta: Metadata): boolean =>
28
+ !ArrayUtil.has(meta.atomics, (a) => a.type === "string");
29
+ }
30
+
31
+ const LIKE = new Set(["boolean", "bigint", "number", "string"]);
@@ -1,5 +1,6 @@
1
1
  import ts from "typescript";
2
2
 
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
3
4
  import { StatementFactory } from "../../factories/StatementFactory";
4
5
  import { TypeFactory } from "../../factories/TypeFactory";
5
6
 
@@ -36,7 +37,7 @@ export namespace RandomJoiner {
36
37
  if (explore.recursive === false) return generator;
37
38
  return ts.factory.createConditionalExpression(
38
39
  ts.factory.createGreaterThanEquals(
39
- ts.factory.createNumericLiteral(5),
40
+ ExpressionFactory.number(5),
40
41
  ts.factory.createIdentifier("_depth"),
41
42
  ),
42
43
  undefined,
@@ -99,7 +100,7 @@ export namespace RandomJoiner {
99
100
  ? [
100
101
  ts.factory.createIfStatement(
101
102
  ts.factory.createGreaterThanEquals(
102
- ts.factory.createNumericLiteral(5),
103
+ ExpressionFactory.number(5),
103
104
  ts.factory.createIdentifier("_depth"),
104
105
  ),
105
106
  ts.factory.createBlock(properties, true),
@@ -137,10 +138,7 @@ export namespace RandomJoiner {
137
138
  ts.factory.createCallExpression(
138
139
  coalesce("integer"),
139
140
  undefined,
140
- [
141
- ts.factory.createNumericLiteral(0),
142
- ts.factory.createNumericLiteral(3),
143
- ],
141
+ [ExpressionFactory.number(0), ExpressionFactory.number(3)],
144
142
  ),
145
143
  ]);
146
144
  }
@@ -1,5 +1,7 @@
1
1
  import ts from "typescript";
2
2
 
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+
3
5
  import { IMetadataTypeTag } from "../../schemas/metadata/IMetadataTypeTag";
4
6
 
5
7
  export namespace RandomRanger {
@@ -30,8 +32,8 @@ export namespace RandomRanger {
30
32
  coalesce("integer"),
31
33
  undefined,
32
34
  [
33
- ts.factory.createNumericLiteral(props.minimum),
34
- ts.factory.createNumericLiteral(props.maximum),
35
+ ExpressionFactory.number(props.minimum),
36
+ ExpressionFactory.number(props.maximum),
35
37
  ],
36
38
  );
37
39
  };
@@ -196,7 +196,7 @@ export namespace HttpHeadersProgrammer {
196
196
  const access = IdentifierFactory.access(output)(key);
197
197
  return ts.factory.createIfStatement(
198
198
  ts.factory.createStrictEquality(
199
- ts.factory.createNumericLiteral(0),
199
+ ExpressionFactory.number(0),
200
200
  IdentifierFactory.access(access)("length"),
201
201
  ),
202
202
  ts.factory.createExpressionStatement(
@@ -1,178 +1,178 @@
1
- import ts from "typescript";
2
-
3
- import { Metadata } from "../../schemas/metadata/Metadata";
4
-
5
- import { IProject } from "../../transformers/IProject";
6
-
7
- import { FunctionImporter } from "../helpers/FunctionImporeter";
8
- import { ICheckEntry } from "../helpers/ICheckEntry";
9
- import { check_bigint } from "./check_bigint";
10
- import { check_number } from "./check_number";
11
- import { check_string } from "./check_string";
12
- import { check_template } from "./check_template";
13
-
14
- export const check_dynamic_key =
15
- (project: IProject) =>
16
- (importer: FunctionImporter) =>
17
- (input: ts.Expression, metadata: Metadata): ts.Expression => {
18
- // IF PURE STRING EXISTS, THEN SKIP VALIDATION
19
- if (
20
- (metadata.atomics.length !== 0 &&
21
- metadata.atomics.some(
22
- (a) =>
23
- a.type === "string" &&
24
- a.tags.filter((row) =>
25
- row.every((t) => t.validate !== undefined),
26
- ).length === 0,
27
- )) ||
28
- (metadata.natives.length !== 0 &&
29
- metadata.natives.some((type) => type === "String"))
30
- )
31
- return ts.factory.createTrue();
32
-
33
- const conditions: ts.Expression[] = [];
34
-
35
- // NULLISH COALESCING
36
- if (metadata.nullable === true)
37
- conditions.push(
38
- ts.factory.createStrictEquality(
39
- ts.factory.createStringLiteral("null"),
40
- input,
41
- ),
42
- );
43
- if (metadata.isRequired() === false)
44
- conditions.push(
45
- ts.factory.createStrictEquality(
46
- ts.factory.createStringLiteral("undefined"),
47
- input,
48
- ),
49
- );
50
-
51
- // ATOMICS
52
- for (const atom of metadata.atomics)
53
- if (atom.type === "boolean")
54
- conditions.push(
55
- ts.factory.createLogicalOr(
56
- ts.factory.createStrictEquality(
57
- ts.factory.createStringLiteral("false"),
58
- input,
59
- ),
60
- ts.factory.createStrictEquality(
61
- ts.factory.createStringLiteral("true"),
62
- input,
63
- ),
64
- ),
65
- );
66
- else if (atom.type === "bigint")
67
- conditions.push(
68
- ts.factory.createLogicalAnd(
69
- ts.factory.createCallExpression(
70
- importer.use("is_bigint_string"),
71
- undefined,
72
- [input],
73
- ),
74
- atomist(
75
- check_bigint(project)(atom)(
76
- ts.factory.createCallExpression(
77
- ts.factory.createIdentifier("BigInt"),
78
- undefined,
79
- [input],
80
- ),
81
- ),
82
- ),
83
- ),
84
- );
85
- else if (atom.type === "number")
86
- conditions.push(
87
- atomist(
88
- check_number(project, true)(atom)(
89
- ts.factory.createCallExpression(
90
- ts.factory.createIdentifier("Number"),
91
- undefined,
92
- [input],
93
- ),
94
- ),
95
- ),
96
- );
97
- else conditions.push(atomist(check_string(project)(atom)(input)));
98
-
99
- // CONSTANTS
100
- for (const constant of metadata.constants)
101
- for (const value of constant.values)
102
- conditions.push(
103
- ts.factory.createStrictEquality(
104
- ts.factory.createStringLiteral(String(value)),
105
- input,
106
- ),
107
- );
108
-
109
- // TEMPLATES
110
- if (!!metadata.templates.length)
111
- conditions.push(atomist(check_template(metadata.templates)(input)));
112
-
113
- // NATIVES
114
- for (const native of metadata.natives)
115
- if (native === "Boolean")
116
- conditions.push(
117
- ts.factory.createLogicalOr(
118
- ts.factory.createStrictEquality(
119
- ts.factory.createStringLiteral("false"),
120
- input,
121
- ),
122
- ts.factory.createStrictEquality(
123
- ts.factory.createStringLiteral("true"),
124
- input,
125
- ),
126
- ),
127
- );
128
- else if (native === "BigInt")
129
- conditions.push(
130
- ts.factory.createCallExpression(
131
- importer.use("is_bigint_string"),
132
- undefined,
133
- [input],
134
- ),
135
- );
136
- else if (native === "Number")
137
- conditions.push(
138
- ts.factory.createStrictEquality(
139
- ts.factory.createFalse(),
140
- ts.factory.createCallExpression(
141
- ts.factory.createIdentifier("Number.isNaN"),
142
- undefined,
143
- [
144
- ts.factory.createCallExpression(
145
- ts.factory.createIdentifier("Number"),
146
- undefined,
147
- [input],
148
- ),
149
- ],
150
- ),
151
- ),
152
- );
153
-
154
- return conditions.length === 0
155
- ? ts.factory.createTrue()
156
- : conditions.length === 1
157
- ? conditions[0]!
158
- : conditions.reduce(ts.factory.createLogicalOr);
159
- };
160
-
161
- const atomist = (entry: ICheckEntry) => {
162
- return [
163
- ...(entry.expression ? [entry.expression] : []),
164
- ...(entry.conditions.length === 0
165
- ? []
166
- : [
167
- entry.conditions
168
- .map((set) =>
169
- set
170
- .map((s) => s.expression)
171
- .reduce((a, b) =>
172
- ts.factory.createLogicalAnd(a, b),
173
- ),
174
- )
175
- .reduce((a, b) => ts.factory.createLogicalOr(a, b)),
176
- ]),
177
- ].reduce((x, y) => ts.factory.createLogicalAnd(x, y));
178
- };
1
+ import ts from "typescript";
2
+
3
+ import { Metadata } from "../../schemas/metadata/Metadata";
4
+
5
+ import { IProject } from "../../transformers/IProject";
6
+
7
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
8
+ import { ICheckEntry } from "../helpers/ICheckEntry";
9
+ import { check_bigint } from "./check_bigint";
10
+ import { check_number } from "./check_number";
11
+ import { check_string } from "./check_string";
12
+ import { check_template } from "./check_template";
13
+
14
+ export const check_dynamic_key =
15
+ (project: IProject) =>
16
+ (importer: FunctionImporter) =>
17
+ (input: ts.Expression, metadata: Metadata): ts.Expression => {
18
+ // IF PURE STRING EXISTS, THEN SKIP VALIDATION
19
+ if (
20
+ (metadata.atomics.length !== 0 &&
21
+ metadata.atomics.some(
22
+ (a) =>
23
+ a.type === "string" &&
24
+ a.tags.filter((row) =>
25
+ row.every((t) => t.validate !== undefined),
26
+ ).length === 0,
27
+ )) ||
28
+ (metadata.natives.length !== 0 &&
29
+ metadata.natives.some((type) => type === "String"))
30
+ )
31
+ return ts.factory.createTrue();
32
+
33
+ const conditions: ts.Expression[] = [];
34
+
35
+ // NULLISH COALESCING
36
+ if (metadata.nullable === true)
37
+ conditions.push(
38
+ ts.factory.createStrictEquality(
39
+ ts.factory.createStringLiteral("null"),
40
+ input,
41
+ ),
42
+ );
43
+ if (metadata.isRequired() === false)
44
+ conditions.push(
45
+ ts.factory.createStrictEquality(
46
+ ts.factory.createStringLiteral("undefined"),
47
+ input,
48
+ ),
49
+ );
50
+
51
+ // ATOMICS
52
+ for (const atom of metadata.atomics)
53
+ if (atom.type === "boolean")
54
+ conditions.push(
55
+ ts.factory.createLogicalOr(
56
+ ts.factory.createStrictEquality(
57
+ ts.factory.createStringLiteral("false"),
58
+ input,
59
+ ),
60
+ ts.factory.createStrictEquality(
61
+ ts.factory.createStringLiteral("true"),
62
+ input,
63
+ ),
64
+ ),
65
+ );
66
+ else if (atom.type === "bigint")
67
+ conditions.push(
68
+ ts.factory.createLogicalAnd(
69
+ ts.factory.createCallExpression(
70
+ importer.use("is_bigint_string"),
71
+ undefined,
72
+ [input],
73
+ ),
74
+ atomist(
75
+ check_bigint(project)(atom)(
76
+ ts.factory.createCallExpression(
77
+ ts.factory.createIdentifier("BigInt"),
78
+ undefined,
79
+ [input],
80
+ ),
81
+ ),
82
+ ),
83
+ ),
84
+ );
85
+ else if (atom.type === "number")
86
+ conditions.push(
87
+ atomist(
88
+ check_number(project, true)(atom)(
89
+ ts.factory.createCallExpression(
90
+ ts.factory.createIdentifier("Number"),
91
+ undefined,
92
+ [input],
93
+ ),
94
+ ),
95
+ ),
96
+ );
97
+ else conditions.push(atomist(check_string(project)(atom)(input)));
98
+
99
+ // CONSTANTS
100
+ for (const constant of metadata.constants)
101
+ for (const value of constant.values)
102
+ conditions.push(
103
+ ts.factory.createStrictEquality(
104
+ ts.factory.createStringLiteral(String(value)),
105
+ input,
106
+ ),
107
+ );
108
+
109
+ // TEMPLATES
110
+ if (!!metadata.templates.length)
111
+ conditions.push(atomist(check_template(metadata.templates)(input)));
112
+
113
+ // NATIVES
114
+ for (const native of metadata.natives)
115
+ if (native === "Boolean")
116
+ conditions.push(
117
+ ts.factory.createLogicalOr(
118
+ ts.factory.createStrictEquality(
119
+ ts.factory.createStringLiteral("false"),
120
+ input,
121
+ ),
122
+ ts.factory.createStrictEquality(
123
+ ts.factory.createStringLiteral("true"),
124
+ input,
125
+ ),
126
+ ),
127
+ );
128
+ else if (native === "BigInt")
129
+ conditions.push(
130
+ ts.factory.createCallExpression(
131
+ importer.use("is_bigint_string"),
132
+ undefined,
133
+ [input],
134
+ ),
135
+ );
136
+ else if (native === "Number")
137
+ conditions.push(
138
+ ts.factory.createStrictEquality(
139
+ ts.factory.createFalse(),
140
+ ts.factory.createCallExpression(
141
+ ts.factory.createIdentifier("Number.isNaN"),
142
+ undefined,
143
+ [
144
+ ts.factory.createCallExpression(
145
+ ts.factory.createIdentifier("Number"),
146
+ undefined,
147
+ [input],
148
+ ),
149
+ ],
150
+ ),
151
+ ),
152
+ );
153
+
154
+ return conditions.length === 0
155
+ ? ts.factory.createTrue()
156
+ : conditions.length === 1
157
+ ? conditions[0]!
158
+ : conditions.reduce(ts.factory.createLogicalOr);
159
+ };
160
+
161
+ const atomist = (entry: ICheckEntry) => {
162
+ return [
163
+ ...(entry.expression ? [entry.expression] : []),
164
+ ...(entry.conditions.length === 0
165
+ ? []
166
+ : [
167
+ entry.conditions
168
+ .map((set) =>
169
+ set
170
+ .map((s) => s.expression)
171
+ .reduce((a, b) =>
172
+ ts.factory.createLogicalAnd(a, b),
173
+ ),
174
+ )
175
+ .reduce((a, b) => ts.factory.createLogicalOr(a, b)),
176
+ ]),
177
+ ].reduce((x, y) => ts.factory.createLogicalAnd(x, y));
178
+ };