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,201 +1,202 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
- import { StatementFactory } from "../../factories/StatementFactory";
5
-
6
- import { IProject } from "../../transformers/IProject";
7
-
8
- import { FunctionImporter } from "../helpers/FunctionImporeter";
9
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
10
- import { check_dynamic_key } from "./check_dynamic_key";
11
- import { check_everything } from "./check_everything";
12
- import { check_object } from "./check_object";
13
-
14
- /**
15
- * @internal
16
- */
17
- export const check_dynamic_properties =
18
- (props: check_object.IProps) =>
19
- (project: IProject) =>
20
- (importer: FunctionImporter) =>
21
- (
22
- input: ts.Expression,
23
- regular: IExpressionEntry<ts.Expression>[],
24
- dynamic: IExpressionEntry<ts.Expression>[],
25
- ): ts.Expression => {
26
- const length = IdentifierFactory.access(
27
- ts.factory.createCallExpression(
28
- ts.factory.createIdentifier("Object.keys"),
29
- undefined,
30
- [input],
31
- ),
32
- )("length");
33
- const left: ts.Expression | null =
34
- props.equals === true && dynamic.length === 0
35
- ? props.undefined === true ||
36
- regular.every((r) => r.meta.isRequired())
37
- ? ts.factory.createStrictEquality(
38
- ts.factory.createNumericLiteral(
39
- regular.filter((r) => r.meta.isRequired()).length,
40
- ),
41
- length,
42
- )
43
- : ts.factory.createCallExpression(
44
- importer.use("is_between"),
45
- [],
46
- [
47
- length,
48
- ts.factory.createNumericLiteral(
49
- regular.filter((r) => r.meta.isRequired())
50
- .length,
51
- ),
52
- ts.factory.createNumericLiteral(regular.length),
53
- ],
54
- )
55
- : null;
56
- if (
57
- props.undefined === false &&
58
- left !== null &&
59
- regular.every((r) => r.meta.isRequired())
60
- )
61
- return left;
62
-
63
- const criteria = props.entries
64
- ? ts.factory.createCallExpression(props.entries, undefined, [
65
- ts.factory.createCallExpression(
66
- ts.factory.createIdentifier("Object.keys"),
67
- undefined,
68
- [input],
69
- ),
70
- check_dynamic_property(props)(project)(importer)(
71
- input,
72
- regular,
73
- dynamic,
74
- ),
75
- ])
76
- : ts.factory.createCallExpression(
77
- IdentifierFactory.access(
78
- ts.factory.createCallExpression(
79
- ts.factory.createIdentifier("Object.keys"),
80
- undefined,
81
- [input],
82
- ),
83
- )(props.assert ? "every" : "map"),
84
- undefined,
85
- [
86
- check_dynamic_property(props)(project)(importer)(
87
- input,
88
- regular,
89
- dynamic,
90
- ),
91
- ],
92
- );
93
- const right: ts.Expression = (props.halt || ((elem) => elem))(
94
- props.assert ? criteria : check_everything(criteria),
95
- );
96
- return left
97
- ? (props.undefined
98
- ? ts.factory.createLogicalOr
99
- : ts.factory.createLogicalAnd)(left, right)
100
- : right;
101
- };
102
-
103
- const check_dynamic_property =
104
- (props: check_object.IProps) =>
105
- (project: IProject) =>
106
- (importer: FunctionImporter) =>
107
- (
108
- input: ts.Expression,
109
- regular: IExpressionEntry<ts.Expression>[],
110
- dynamic: IExpressionEntry<ts.Expression>[],
111
- ) => {
112
- //----
113
- // IF CONDITIONS
114
- //----
115
- // PREPARE ASSETS
116
- const key = ts.factory.createIdentifier("key");
117
- const value = ts.factory.createIdentifier("value");
118
-
119
- const statements: ts.Statement[] = [];
120
- const add = (exp: ts.Expression, output: ts.Expression) =>
121
- statements.push(
122
- ts.factory.createIfStatement(
123
- exp,
124
- ts.factory.createReturnStatement(output),
125
- ),
126
- );
127
-
128
- // GATHER CONDITIONS
129
- if (regular.length) add(is_regular_property(regular), props.positive);
130
- statements.push(
131
- StatementFactory.constant(
132
- "value",
133
- ts.factory.createElementAccessExpression(input, key),
134
- ),
135
- );
136
- if (props.undefined === true)
137
- add(
138
- ts.factory.createStrictEquality(
139
- ts.factory.createIdentifier("undefined"),
140
- value,
141
- ),
142
- props.positive,
143
- );
144
-
145
- for (const entry of dynamic)
146
- add(
147
- check_dynamic_key(project)(importer)(key, entry.key),
148
- entry.expression,
149
- );
150
-
151
- //----
152
- // FUNCTION BODY
153
- //----
154
- // CLOSURE BLOCK
155
- const block: ts.Block = ts.factory.createBlock(
156
- [
157
- ...statements,
158
- ts.factory.createReturnStatement(
159
- props.equals === true
160
- ? props.superfluous(value)
161
- : props.positive,
162
- ),
163
- ],
164
- true,
165
- );
166
-
167
- // RETURNS
168
- return ts.factory.createArrowFunction(
169
- undefined,
170
- undefined,
171
- [IdentifierFactory.parameter("key")],
172
- undefined,
173
- undefined,
174
- block,
175
- );
176
- };
177
-
178
- const is_regular_property = (regular: IExpressionEntry[]) =>
179
- ts.factory.createCallExpression(
180
- IdentifierFactory.access(
181
- ts.factory.createArrayLiteralExpression(
182
- regular.map((entry) =>
183
- ts.factory.createStringLiteral(entry.key.getSoleLiteral()!),
184
- ),
185
- ),
186
- )("some"),
187
- undefined,
188
- [
189
- ts.factory.createArrowFunction(
190
- undefined,
191
- undefined,
192
- [IdentifierFactory.parameter("prop")],
193
- undefined,
194
- undefined,
195
- ts.factory.createStrictEquality(
196
- ts.factory.createIdentifier("key"),
197
- ts.factory.createIdentifier("prop"),
198
- ),
199
- ),
200
- ],
201
- );
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
+ import { StatementFactory } from "../../factories/StatementFactory";
6
+
7
+ import { IProject } from "../../transformers/IProject";
8
+
9
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
10
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
11
+ import { check_dynamic_key } from "./check_dynamic_key";
12
+ import { check_everything } from "./check_everything";
13
+ import { check_object } from "./check_object";
14
+
15
+ /**
16
+ * @internal
17
+ */
18
+ export const check_dynamic_properties =
19
+ (props: check_object.IProps) =>
20
+ (project: IProject) =>
21
+ (importer: FunctionImporter) =>
22
+ (
23
+ input: ts.Expression,
24
+ regular: IExpressionEntry<ts.Expression>[],
25
+ dynamic: IExpressionEntry<ts.Expression>[],
26
+ ): ts.Expression => {
27
+ const length = IdentifierFactory.access(
28
+ ts.factory.createCallExpression(
29
+ ts.factory.createIdentifier("Object.keys"),
30
+ undefined,
31
+ [input],
32
+ ),
33
+ )("length");
34
+ const left: ts.Expression | null =
35
+ props.equals === true && dynamic.length === 0
36
+ ? props.undefined === true ||
37
+ regular.every((r) => r.meta.isRequired())
38
+ ? ts.factory.createStrictEquality(
39
+ ExpressionFactory.number(
40
+ regular.filter((r) => r.meta.isRequired()).length,
41
+ ),
42
+ length,
43
+ )
44
+ : ts.factory.createCallExpression(
45
+ importer.use("is_between"),
46
+ [],
47
+ [
48
+ length,
49
+ ExpressionFactory.number(
50
+ regular.filter((r) => r.meta.isRequired())
51
+ .length,
52
+ ),
53
+ ExpressionFactory.number(regular.length),
54
+ ],
55
+ )
56
+ : null;
57
+ if (
58
+ props.undefined === false &&
59
+ left !== null &&
60
+ regular.every((r) => r.meta.isRequired())
61
+ )
62
+ return left;
63
+
64
+ const criteria = props.entries
65
+ ? ts.factory.createCallExpression(props.entries, undefined, [
66
+ ts.factory.createCallExpression(
67
+ ts.factory.createIdentifier("Object.keys"),
68
+ undefined,
69
+ [input],
70
+ ),
71
+ check_dynamic_property(props)(project)(importer)(
72
+ input,
73
+ regular,
74
+ dynamic,
75
+ ),
76
+ ])
77
+ : ts.factory.createCallExpression(
78
+ IdentifierFactory.access(
79
+ ts.factory.createCallExpression(
80
+ ts.factory.createIdentifier("Object.keys"),
81
+ undefined,
82
+ [input],
83
+ ),
84
+ )(props.assert ? "every" : "map"),
85
+ undefined,
86
+ [
87
+ check_dynamic_property(props)(project)(importer)(
88
+ input,
89
+ regular,
90
+ dynamic,
91
+ ),
92
+ ],
93
+ );
94
+ const right: ts.Expression = (props.halt || ((elem) => elem))(
95
+ props.assert ? criteria : check_everything(criteria),
96
+ );
97
+ return left
98
+ ? (props.undefined
99
+ ? ts.factory.createLogicalOr
100
+ : ts.factory.createLogicalAnd)(left, right)
101
+ : right;
102
+ };
103
+
104
+ const check_dynamic_property =
105
+ (props: check_object.IProps) =>
106
+ (project: IProject) =>
107
+ (importer: FunctionImporter) =>
108
+ (
109
+ input: ts.Expression,
110
+ regular: IExpressionEntry<ts.Expression>[],
111
+ dynamic: IExpressionEntry<ts.Expression>[],
112
+ ) => {
113
+ //----
114
+ // IF CONDITIONS
115
+ //----
116
+ // PREPARE ASSETS
117
+ const key = ts.factory.createIdentifier("key");
118
+ const value = ts.factory.createIdentifier("value");
119
+
120
+ const statements: ts.Statement[] = [];
121
+ const add = (exp: ts.Expression, output: ts.Expression) =>
122
+ statements.push(
123
+ ts.factory.createIfStatement(
124
+ exp,
125
+ ts.factory.createReturnStatement(output),
126
+ ),
127
+ );
128
+
129
+ // GATHER CONDITIONS
130
+ if (regular.length) add(is_regular_property(regular), props.positive);
131
+ statements.push(
132
+ StatementFactory.constant(
133
+ "value",
134
+ ts.factory.createElementAccessExpression(input, key),
135
+ ),
136
+ );
137
+ if (props.undefined === true)
138
+ add(
139
+ ts.factory.createStrictEquality(
140
+ ts.factory.createIdentifier("undefined"),
141
+ value,
142
+ ),
143
+ props.positive,
144
+ );
145
+
146
+ for (const entry of dynamic)
147
+ add(
148
+ check_dynamic_key(project)(importer)(key, entry.key),
149
+ entry.expression,
150
+ );
151
+
152
+ //----
153
+ // FUNCTION BODY
154
+ //----
155
+ // CLOSURE BLOCK
156
+ const block: ts.Block = ts.factory.createBlock(
157
+ [
158
+ ...statements,
159
+ ts.factory.createReturnStatement(
160
+ props.equals === true
161
+ ? props.superfluous(value)
162
+ : props.positive,
163
+ ),
164
+ ],
165
+ true,
166
+ );
167
+
168
+ // RETURNS
169
+ return ts.factory.createArrowFunction(
170
+ undefined,
171
+ undefined,
172
+ [IdentifierFactory.parameter("key")],
173
+ undefined,
174
+ undefined,
175
+ block,
176
+ );
177
+ };
178
+
179
+ const is_regular_property = (regular: IExpressionEntry[]) =>
180
+ ts.factory.createCallExpression(
181
+ IdentifierFactory.access(
182
+ ts.factory.createArrayLiteralExpression(
183
+ regular.map((entry) =>
184
+ ts.factory.createStringLiteral(entry.key.getSoleLiteral()!),
185
+ ),
186
+ ),
187
+ )("some"),
188
+ undefined,
189
+ [
190
+ ts.factory.createArrowFunction(
191
+ undefined,
192
+ undefined,
193
+ [IdentifierFactory.parameter("prop")],
194
+ undefined,
195
+ undefined,
196
+ ts.factory.createStrictEquality(
197
+ ts.factory.createIdentifier("key"),
198
+ ts.factory.createIdentifier("prop"),
199
+ ),
200
+ ),
201
+ ],
202
+ );
@@ -1,62 +1,62 @@
1
- import ts from "typescript";
2
-
3
- import { IProject } from "../../transformers/IProject";
4
-
5
- import { FunctionImporter } from "../helpers/FunctionImporeter";
6
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
7
- import { check_dynamic_properties } from "./check_dynamic_properties";
8
- import { check_everything } from "./check_everything";
9
-
10
- /**
11
- * @internal
12
- */
13
- export const check_object =
14
- (props: check_object.IProps) =>
15
- (project: IProject) =>
16
- (importer: FunctionImporter) =>
17
- (input: ts.Expression, entries: IExpressionEntry<ts.Expression>[]) => {
18
- // PREPARE ASSETS
19
- const regular = entries.filter((entry) => entry.key.isSoleLiteral());
20
- const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
21
- const flags: ts.Expression[] = regular.map((entry) => entry.expression);
22
-
23
- // REGULAR WITHOUT DYNAMIC PROPERTIES
24
- if (props.equals === false && dynamic.length === 0)
25
- return regular.length === 0 ? props.positive : reduce(props)(flags);
26
-
27
- // CHECK DYNAMIC PROPERTIES
28
- flags.push(
29
- check_dynamic_properties(props)(project)(importer)(
30
- input,
31
- regular,
32
- dynamic,
33
- ),
34
- );
35
- return reduce(props)(flags);
36
- };
37
-
38
- /**
39
- * @internal
40
- */
41
- export namespace check_object {
42
- export interface IProps {
43
- equals: boolean;
44
- assert: boolean;
45
- undefined: boolean;
46
- halt?: undefined | ((exp: ts.Expression) => ts.Expression);
47
- reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
48
- positive: ts.Expression;
49
- superfluous: (value: ts.Expression) => ts.Expression;
50
- entries?: undefined | ts.Identifier;
51
- }
52
- }
53
-
54
- /**
55
- * @internal
56
- */
57
- const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
58
- props.assert
59
- ? expressions.reduce(props.reduce)
60
- : check_everything(
61
- ts.factory.createArrayLiteralExpression(expressions),
62
- );
1
+ import ts from "typescript";
2
+
3
+ import { IProject } from "../../transformers/IProject";
4
+
5
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
6
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
7
+ import { check_dynamic_properties } from "./check_dynamic_properties";
8
+ import { check_everything } from "./check_everything";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export const check_object =
14
+ (props: check_object.IProps) =>
15
+ (project: IProject) =>
16
+ (importer: FunctionImporter) =>
17
+ (input: ts.Expression, entries: IExpressionEntry<ts.Expression>[]) => {
18
+ // PREPARE ASSETS
19
+ const regular = entries.filter((entry) => entry.key.isSoleLiteral());
20
+ const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
21
+ const flags: ts.Expression[] = regular.map((entry) => entry.expression);
22
+
23
+ // REGULAR WITHOUT DYNAMIC PROPERTIES
24
+ if (props.equals === false && dynamic.length === 0)
25
+ return regular.length === 0 ? props.positive : reduce(props)(flags);
26
+
27
+ // CHECK DYNAMIC PROPERTIES
28
+ flags.push(
29
+ check_dynamic_properties(props)(project)(importer)(
30
+ input,
31
+ regular,
32
+ dynamic,
33
+ ),
34
+ );
35
+ return reduce(props)(flags);
36
+ };
37
+
38
+ /**
39
+ * @internal
40
+ */
41
+ export namespace check_object {
42
+ export interface IProps {
43
+ equals: boolean;
44
+ assert: boolean;
45
+ undefined: boolean;
46
+ halt?: undefined | ((exp: ts.Expression) => ts.Expression);
47
+ reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
48
+ positive: ts.Expression;
49
+ superfluous: (value: ts.Expression) => ts.Expression;
50
+ entries?: undefined | ts.Identifier;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * @internal
56
+ */
57
+ const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
58
+ props.assert
59
+ ? expressions.reduce(props.reduce)
60
+ : check_everything(
61
+ ts.factory.createArrayLiteralExpression(expressions),
62
+ );
@@ -1,5 +1,6 @@
1
1
  import ts from "typescript";
2
2
 
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
3
4
  import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
5
  import { StatementFactory } from "../../factories/StatementFactory";
5
6
  import { TypeFactory } from "../../factories/TypeFactory";
@@ -159,7 +160,7 @@ export const check_union_array_like =
159
160
  StatementFactory.constant("top", accessor.front(input)),
160
161
  ts.factory.createIfStatement(
161
162
  ts.factory.createStrictEquality(
162
- ts.factory.createNumericLiteral(0),
163
+ ExpressionFactory.number(0),
163
164
  accessor.size(input),
164
165
  ),
165
166
  ts.isReturnStatement(props.empty)
@@ -198,7 +199,7 @@ export const check_union_array_like =
198
199
  ),
199
200
  ts.factory.createIfStatement(
200
201
  ts.factory.createStrictEquality(
201
- ts.factory.createNumericLiteral(1),
202
+ ExpressionFactory.number(1),
202
203
  ts.factory.createIdentifier("passed.length"),
203
204
  ),
204
205
  ts.factory.createReturnStatement(
@@ -215,7 +216,7 @@ export const check_union_array_like =
215
216
  ),
216
217
  ts.factory.createIfStatement(
217
218
  ts.factory.createLessThan(
218
- ts.factory.createNumericLiteral(1),
219
+ ExpressionFactory.number(1),
219
220
  ts.factory.createIdentifier("passed.length"),
220
221
  ),
221
222
  iterate("pred")(ts.factory.createIdentifier("passed"))(