typia 5.2.5 → 5.2.6

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
@@ -779,7 +779,7 @@ export namespace CheckerProgrammer {
779
779
  IdentifierFactory.access(input)("slice"),
780
780
  undefined,
781
781
  [
782
- ts.factory.createNumericLiteral(
782
+ ExpressionFactory.number(
783
783
  tuple.elements.length - 1,
784
784
  ),
785
785
  ],
@@ -809,7 +809,7 @@ export namespace CheckerProgrammer {
809
809
  expression:
810
810
  ts.factory.createStrictEquality(
811
811
  arrayLength,
812
- ts.factory.createNumericLiteral(
812
+ ExpressionFactory.number(
813
813
  tuple.elements.length,
814
814
  ),
815
815
  ),
@@ -820,7 +820,7 @@ export namespace CheckerProgrammer {
820
820
  combined: false,
821
821
  expression: ts.factory.createLogicalAnd(
822
822
  ts.factory.createLessThanEquals(
823
- ts.factory.createNumericLiteral(
823
+ ExpressionFactory.number(
824
824
  tuple.elements.filter(
825
825
  (t) =>
826
826
  t.optional === false,
@@ -829,7 +829,7 @@ export namespace CheckerProgrammer {
829
829
  arrayLength,
830
830
  ),
831
831
  ts.factory.createGreaterThanEquals(
832
- ts.factory.createNumericLiteral(
832
+ ExpressionFactory.number(
833
833
  tuple.elements.length,
834
834
  ),
835
835
  arrayLength,
@@ -1,258 +1,258 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../factories/ExpressionFactory";
4
- import { IdentifierFactory } from "../factories/IdentifierFactory";
5
- import { MetadataCollection } from "../factories/MetadataCollection";
6
- import { TypeFactory } from "../factories/TypeFactory";
7
- import { ValueFactory } from "../factories/ValueFactory";
8
-
9
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
10
-
11
- import { IProject } from "../transformers/IProject";
12
-
13
- import { CheckerProgrammer } from "./CheckerProgrammer";
14
- import { FunctionImporter } from "./helpers/FunctionImporeter";
15
- import { IExpressionEntry } from "./helpers/IExpressionEntry";
16
- import { OptionPredicator } from "./helpers/OptionPredicator";
17
- import { disable_function_importer_declare } from "./helpers/disable_function_importer_declare";
18
- import { check_object } from "./internal/check_object";
19
- import { feature_object_entries } from "./internal/feature_object_entries";
20
-
21
- export namespace IsProgrammer {
22
- export const configure =
23
- (options?: Partial<CONFIG.IOptions>) =>
24
- (project: IProject) =>
25
- (importer: FunctionImporter): CheckerProgrammer.IConfig => ({
26
- prefix: "$i",
27
- equals: !!options?.object,
28
- trace: false,
29
- path: false,
30
- numeric: OptionPredicator.numeric({
31
- numeric: options?.numeric,
32
- }),
33
- atomist: () => (entry) => () =>
34
- [
35
- ...(entry.expression ? [entry.expression] : []),
36
- ...(entry.conditions.length === 0
37
- ? []
38
- : [
39
- entry.conditions
40
- .map((set) =>
41
- set
42
- .map((s) => s.expression)
43
- .reduce((a, b) =>
44
- ts.factory.createLogicalAnd(a, b),
45
- ),
46
- )
47
- .reduce((a, b) =>
48
- ts.factory.createLogicalOr(a, b),
49
- ),
50
- ]),
51
- ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
52
- combiner: () => (type: "and" | "or") => {
53
- const initial: ts.TrueLiteral | ts.FalseLiteral =
54
- type === "and"
55
- ? ts.factory.createTrue()
56
- : ts.factory.createFalse();
57
- const binder =
58
- type === "and"
59
- ? ts.factory.createLogicalAnd
60
- : ts.factory.createLogicalOr;
61
- return (
62
- _input: ts.Expression,
63
- binaries: CheckerProgrammer.IBinary[],
64
- ) =>
65
- binaries.length
66
- ? binaries
67
- .map((binary) => binary.expression)
68
- .reduce((x, y) => binder(x, y))
69
- : initial;
70
- },
71
- joiner: {
72
- object:
73
- options?.object ||
74
- check_object({
75
- equals: !!options?.object,
76
- undefined: OptionPredicator.undefined({
77
- undefined: options?.undefined,
78
- }),
79
- assert: true,
80
- reduce: ts.factory.createLogicalAnd,
81
- positive: ts.factory.createTrue(),
82
- superfluous: () => ts.factory.createFalse(),
83
- })(project)(importer),
84
- array: (input, arrow) =>
85
- ts.factory.createCallExpression(
86
- IdentifierFactory.access(input)("every"),
87
- undefined,
88
- [arrow],
89
- ),
90
- failure: () => ts.factory.createFalse(),
91
- },
92
- success: ts.factory.createTrue(),
93
- });
94
-
95
- export namespace CONFIG {
96
- export interface IOptions {
97
- numeric: boolean;
98
- undefined: boolean;
99
- object: (
100
- input: ts.Expression,
101
- entries: IExpressionEntry<ts.Expression>[],
102
- ) => ts.Expression;
103
- }
104
- }
105
-
106
- /* -----------------------------------------------------------
107
- WRITERS
108
- ----------------------------------------------------------- */
109
- export const write =
110
- (project: IProject) =>
111
- (modulo: ts.LeftHandSideExpression, disable?: boolean) =>
112
- (equals: boolean) => {
113
- const importer: FunctionImporter =
114
- disable === <any>{}
115
- ? disable_function_importer_declare(
116
- new FunctionImporter(modulo.getText()),
117
- )
118
- : new FunctionImporter(modulo.getText());
119
-
120
- // CONFIGURATION
121
- const config: CheckerProgrammer.IConfig = {
122
- ...configure({
123
- object: check_object({
124
- equals,
125
- undefined: OptionPredicator.undefined(project.options),
126
- assert: true,
127
- reduce: ts.factory.createLogicalAnd,
128
- positive: ts.factory.createTrue(),
129
- superfluous: () => ts.factory.createFalse(),
130
- })(project)(importer),
131
- numeric: OptionPredicator.numeric(project.options),
132
- })(project)(importer),
133
- trace: equals,
134
- addition: () => importer.declare(modulo),
135
- };
136
-
137
- config.decoder = () => (input, target, explore) => {
138
- if (
139
- target.size() === 1 &&
140
- target.objects.length === 1 &&
141
- target.isRequired() === true &&
142
- target.nullable === false
143
- ) {
144
- // ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
145
- const obj: MetadataObject = target.objects[0]!;
146
- if (
147
- obj._Is_simple(explore.from === "top" ? 0 : 1) &&
148
- (equals === false ||
149
- OptionPredicator.undefined(project.options) ===
150
- false)
151
- )
152
- return ts.factory.createLogicalAnd(
153
- ExpressionFactory.isObject({
154
- checkNull: true,
155
- checkArray: false,
156
- })(input),
157
- config.joiner.object(
158
- ts.factory.createAsExpression(
159
- input,
160
- TypeFactory.keyword("any"),
161
- ),
162
- feature_object_entries(config as any)(importer)(
163
- obj,
164
- )(
165
- ts.factory.createAsExpression(
166
- input,
167
- TypeFactory.keyword("any"),
168
- ),
169
- "top",
170
- ),
171
- ),
172
- );
173
- }
174
- return CheckerProgrammer.decode(project)(config)(importer)(
175
- input,
176
- target,
177
- explore,
178
- );
179
- };
180
-
181
- // GENERATE CHECKER
182
- return CheckerProgrammer.write(project)(config)(importer);
183
- };
184
-
185
- export const write_function_statements =
186
- (project: IProject) =>
187
- (importer: FunctionImporter) =>
188
- (collection: MetadataCollection) => {
189
- const config = configure()(project)(importer);
190
- const objects =
191
- CheckerProgrammer.write_object_functions(project)(config)(
192
- importer,
193
- )(collection);
194
- const unions =
195
- CheckerProgrammer.write_union_functions(project)(config)(
196
- importer,
197
- )(collection);
198
- const arrays =
199
- CheckerProgrammer.write_array_functions(project)(config)(
200
- importer,
201
- )(collection);
202
- const tuples =
203
- CheckerProgrammer.write_tuple_functions(project)(config)(
204
- importer,
205
- )(collection);
206
-
207
- return [
208
- ...objects.filter((_, i) =>
209
- importer.hasLocal(`${config.prefix}o${i}`),
210
- ),
211
- ...unions.filter((_, i) =>
212
- importer.hasLocal(`${config.prefix}u${i}`),
213
- ),
214
- ...arrays.filter((_, i) =>
215
- importer.hasLocal(`${config.prefix}a${i}`),
216
- ),
217
- ...tuples.filter((_, i) =>
218
- importer.hasLocal(`${config.prefix}t${i}`),
219
- ),
220
- ];
221
- };
222
-
223
- /* -----------------------------------------------------------
224
- DECODERS
225
- ----------------------------------------------------------- */
226
- export const decode = (project: IProject) => (importer: FunctionImporter) =>
227
- CheckerProgrammer.decode(project)(configure()(project)(importer))(
228
- importer,
229
- );
230
-
231
- export const decode_object =
232
- (project: IProject) => (importer: FunctionImporter) =>
233
- CheckerProgrammer.decode_object(configure()(project)(importer))(
234
- importer,
235
- );
236
-
237
- export const decode_to_json =
238
- (checkNull: boolean) =>
239
- (input: ts.Expression): ts.Expression =>
240
- ts.factory.createLogicalAnd(
241
- ExpressionFactory.isObject({
242
- checkArray: false,
243
- checkNull,
244
- })(input),
245
- ts.factory.createStrictEquality(
246
- ts.factory.createStringLiteral("function"),
247
- ValueFactory.TYPEOF(
248
- IdentifierFactory.access(input)("toJSON"),
249
- ),
250
- ),
251
- );
252
-
253
- export const decode_functional = (input: ts.Expression) =>
254
- ts.factory.createStrictEquality(
255
- ts.factory.createStringLiteral("function"),
256
- ValueFactory.TYPEOF(input),
257
- );
258
- }
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
5
+ import { MetadataCollection } from "../factories/MetadataCollection";
6
+ import { TypeFactory } from "../factories/TypeFactory";
7
+ import { ValueFactory } from "../factories/ValueFactory";
8
+
9
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
10
+
11
+ import { IProject } from "../transformers/IProject";
12
+
13
+ import { CheckerProgrammer } from "./CheckerProgrammer";
14
+ import { FunctionImporter } from "./helpers/FunctionImporeter";
15
+ import { IExpressionEntry } from "./helpers/IExpressionEntry";
16
+ import { OptionPredicator } from "./helpers/OptionPredicator";
17
+ import { disable_function_importer_declare } from "./helpers/disable_function_importer_declare";
18
+ import { check_object } from "./internal/check_object";
19
+ import { feature_object_entries } from "./internal/feature_object_entries";
20
+
21
+ export namespace IsProgrammer {
22
+ export const configure =
23
+ (options?: Partial<CONFIG.IOptions>) =>
24
+ (project: IProject) =>
25
+ (importer: FunctionImporter): CheckerProgrammer.IConfig => ({
26
+ prefix: "$i",
27
+ equals: !!options?.object,
28
+ trace: false,
29
+ path: false,
30
+ numeric: OptionPredicator.numeric({
31
+ numeric: options?.numeric,
32
+ }),
33
+ atomist: () => (entry) => () =>
34
+ [
35
+ ...(entry.expression ? [entry.expression] : []),
36
+ ...(entry.conditions.length === 0
37
+ ? []
38
+ : [
39
+ entry.conditions
40
+ .map((set) =>
41
+ set
42
+ .map((s) => s.expression)
43
+ .reduce((a, b) =>
44
+ ts.factory.createLogicalAnd(a, b),
45
+ ),
46
+ )
47
+ .reduce((a, b) =>
48
+ ts.factory.createLogicalOr(a, b),
49
+ ),
50
+ ]),
51
+ ].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
52
+ combiner: () => (type: "and" | "or") => {
53
+ const initial: ts.TrueLiteral | ts.FalseLiteral =
54
+ type === "and"
55
+ ? ts.factory.createTrue()
56
+ : ts.factory.createFalse();
57
+ const binder =
58
+ type === "and"
59
+ ? ts.factory.createLogicalAnd
60
+ : ts.factory.createLogicalOr;
61
+ return (
62
+ _input: ts.Expression,
63
+ binaries: CheckerProgrammer.IBinary[],
64
+ ) =>
65
+ binaries.length
66
+ ? binaries
67
+ .map((binary) => binary.expression)
68
+ .reduce((x, y) => binder(x, y))
69
+ : initial;
70
+ },
71
+ joiner: {
72
+ object:
73
+ options?.object ||
74
+ check_object({
75
+ equals: !!options?.object,
76
+ undefined: OptionPredicator.undefined({
77
+ undefined: options?.undefined,
78
+ }),
79
+ assert: true,
80
+ reduce: ts.factory.createLogicalAnd,
81
+ positive: ts.factory.createTrue(),
82
+ superfluous: () => ts.factory.createFalse(),
83
+ })(project)(importer),
84
+ array: (input, arrow) =>
85
+ ts.factory.createCallExpression(
86
+ IdentifierFactory.access(input)("every"),
87
+ undefined,
88
+ [arrow],
89
+ ),
90
+ failure: () => ts.factory.createFalse(),
91
+ },
92
+ success: ts.factory.createTrue(),
93
+ });
94
+
95
+ export namespace CONFIG {
96
+ export interface IOptions {
97
+ numeric: boolean;
98
+ undefined: boolean;
99
+ object: (
100
+ input: ts.Expression,
101
+ entries: IExpressionEntry<ts.Expression>[],
102
+ ) => ts.Expression;
103
+ }
104
+ }
105
+
106
+ /* -----------------------------------------------------------
107
+ WRITERS
108
+ ----------------------------------------------------------- */
109
+ export const write =
110
+ (project: IProject) =>
111
+ (modulo: ts.LeftHandSideExpression, disable?: boolean) =>
112
+ (equals: boolean) => {
113
+ const importer: FunctionImporter =
114
+ disable === <any>{}
115
+ ? disable_function_importer_declare(
116
+ new FunctionImporter(modulo.getText()),
117
+ )
118
+ : new FunctionImporter(modulo.getText());
119
+
120
+ // CONFIGURATION
121
+ const config: CheckerProgrammer.IConfig = {
122
+ ...configure({
123
+ object: check_object({
124
+ equals,
125
+ undefined: OptionPredicator.undefined(project.options),
126
+ assert: true,
127
+ reduce: ts.factory.createLogicalAnd,
128
+ positive: ts.factory.createTrue(),
129
+ superfluous: () => ts.factory.createFalse(),
130
+ })(project)(importer),
131
+ numeric: OptionPredicator.numeric(project.options),
132
+ })(project)(importer),
133
+ trace: equals,
134
+ addition: () => importer.declare(modulo),
135
+ };
136
+
137
+ config.decoder = () => (input, target, explore) => {
138
+ if (
139
+ target.size() === 1 &&
140
+ target.objects.length === 1 &&
141
+ target.isRequired() === true &&
142
+ target.nullable === false
143
+ ) {
144
+ // ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
145
+ const obj: MetadataObject = target.objects[0]!;
146
+ if (
147
+ obj._Is_simple(explore.from === "top" ? 0 : 1) &&
148
+ (equals === false ||
149
+ OptionPredicator.undefined(project.options) ===
150
+ false)
151
+ )
152
+ return ts.factory.createLogicalAnd(
153
+ ExpressionFactory.isObject({
154
+ checkNull: true,
155
+ checkArray: false,
156
+ })(input),
157
+ config.joiner.object(
158
+ ts.factory.createAsExpression(
159
+ input,
160
+ TypeFactory.keyword("any"),
161
+ ),
162
+ feature_object_entries(config as any)(importer)(
163
+ obj,
164
+ )(
165
+ ts.factory.createAsExpression(
166
+ input,
167
+ TypeFactory.keyword("any"),
168
+ ),
169
+ "top",
170
+ ),
171
+ ),
172
+ );
173
+ }
174
+ return CheckerProgrammer.decode(project)(config)(importer)(
175
+ input,
176
+ target,
177
+ explore,
178
+ );
179
+ };
180
+
181
+ // GENERATE CHECKER
182
+ return CheckerProgrammer.write(project)(config)(importer);
183
+ };
184
+
185
+ export const write_function_statements =
186
+ (project: IProject) =>
187
+ (importer: FunctionImporter) =>
188
+ (collection: MetadataCollection) => {
189
+ const config = configure()(project)(importer);
190
+ const objects =
191
+ CheckerProgrammer.write_object_functions(project)(config)(
192
+ importer,
193
+ )(collection);
194
+ const unions =
195
+ CheckerProgrammer.write_union_functions(project)(config)(
196
+ importer,
197
+ )(collection);
198
+ const arrays =
199
+ CheckerProgrammer.write_array_functions(project)(config)(
200
+ importer,
201
+ )(collection);
202
+ const tuples =
203
+ CheckerProgrammer.write_tuple_functions(project)(config)(
204
+ importer,
205
+ )(collection);
206
+
207
+ return [
208
+ ...objects.filter((_, i) =>
209
+ importer.hasLocal(`${config.prefix}o${i}`),
210
+ ),
211
+ ...unions.filter((_, i) =>
212
+ importer.hasLocal(`${config.prefix}u${i}`),
213
+ ),
214
+ ...arrays.filter((_, i) =>
215
+ importer.hasLocal(`${config.prefix}a${i}`),
216
+ ),
217
+ ...tuples.filter((_, i) =>
218
+ importer.hasLocal(`${config.prefix}t${i}`),
219
+ ),
220
+ ];
221
+ };
222
+
223
+ /* -----------------------------------------------------------
224
+ DECODERS
225
+ ----------------------------------------------------------- */
226
+ export const decode = (project: IProject) => (importer: FunctionImporter) =>
227
+ CheckerProgrammer.decode(project)(configure()(project)(importer))(
228
+ importer,
229
+ );
230
+
231
+ export const decode_object =
232
+ (project: IProject) => (importer: FunctionImporter) =>
233
+ CheckerProgrammer.decode_object(configure()(project)(importer))(
234
+ importer,
235
+ );
236
+
237
+ export const decode_to_json =
238
+ (checkNull: boolean) =>
239
+ (input: ts.Expression): ts.Expression =>
240
+ ts.factory.createLogicalAnd(
241
+ ExpressionFactory.isObject({
242
+ checkArray: false,
243
+ checkNull,
244
+ })(input),
245
+ ts.factory.createStrictEquality(
246
+ ts.factory.createStringLiteral("function"),
247
+ ValueFactory.TYPEOF(
248
+ IdentifierFactory.access(input)("toJSON"),
249
+ ),
250
+ ),
251
+ );
252
+
253
+ export const decode_functional = (input: ts.Expression) =>
254
+ ts.factory.createStrictEquality(
255
+ ts.factory.createStringLiteral("function"),
256
+ ValueFactory.TYPEOF(input),
257
+ );
258
+ }