typia 5.2.4 → 5.2.5
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/internal/metadata/emplace_metadata_object.js +24 -0
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/functional/$stoll.d.ts +1 -0
- package/lib/functional/$stoll.js +14 -0
- package/lib/functional/$stoll.js.map +1 -0
- package/lib/functional/Namespace.js +4 -10
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +71 -63
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +2 -2
- package/lib/programmers/IsProgrammer.js +66 -64
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +50 -46
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_key.d.ts +5 -0
- package/lib/programmers/internal/check_dynamic_key.js +158 -0
- package/lib/programmers/internal/check_dynamic_key.js.map +1 -0
- package/lib/programmers/internal/check_dynamic_properties.js +69 -61
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_object.js +11 -9
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/package.json +2 -2
- package/src/CamelCase.ts +116 -116
- package/src/PascalCase.ts +116 -116
- package/src/Primitive.ts +135 -135
- package/src/Resolved.ts +116 -116
- package/src/SnakeCase.ts +156 -156
- package/src/executable/TypiaSetupWizard.ts +142 -142
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/factories/JsonMetadataFactory.ts +50 -50
- package/src/factories/MetadataCollection.ts +282 -282
- package/src/factories/internal/metadata/emplace_metadata_object.ts +28 -0
- package/src/functional/$convention.ts +40 -40
- package/src/functional/$stoll.ts +8 -0
- package/src/functional/Namespace.ts +168 -164
- package/src/module.ts +662 -662
- package/src/notations.ts +855 -855
- package/src/programmers/AssertProgrammer.ts +36 -31
- package/src/programmers/IsProgrammer.ts +13 -7
- package/src/programmers/ValidateProgrammer.ts +34 -31
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/NotationJoiner.ts +146 -146
- package/src/programmers/internal/check_dynamic_key.ts +178 -0
- package/src/programmers/internal/check_dynamic_properties.ts +19 -12
- package/src/programmers/internal/check_object.ts +8 -1
- package/src/programmers/json/JsonStringifyProgrammer.ts +1 -1
- package/src/programmers/misc/MiscCloneProgrammer.ts +790 -790
- package/src/programmers/misc/MiscPruneProgrammer.ts +552 -552
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +72 -72
- package/src/programmers/notations/NotationGeneralProgrammer.ts +720 -720
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +79 -79
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +88 -88
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +1 -1
- package/src/transformers/CallExpressionTransformer.ts +380 -380
- package/src/transformers/features/json/JsonAssertParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonIsStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonValidateParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +10 -10
- package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +17 -17
- package/src/transformers/features/notations/NotationGeneralTransformer.ts +11 -11
- package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +17 -17
- package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +12 -12
- package/src/utils/NamingConvention.ts +91 -91
- package/src/utils/StringUtil.ts +4 -4
|
@@ -91,8 +91,8 @@ export namespace AssertProgrammer {
|
|
|
91
91
|
),
|
|
92
92
|
]),
|
|
93
93
|
].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
|
|
94
|
-
combiner: combiner(equals)(importer),
|
|
95
|
-
joiner: joiner(equals)(importer),
|
|
94
|
+
combiner: combiner(equals)(project)(importer),
|
|
95
|
+
joiner: joiner(equals)(project)(importer),
|
|
96
96
|
success: ts.factory.createTrue(),
|
|
97
97
|
addition: () => importer.declare(modulo),
|
|
98
98
|
})(importer)(type, name);
|
|
@@ -148,13 +148,14 @@ export namespace AssertProgrammer {
|
|
|
148
148
|
|
|
149
149
|
const combiner =
|
|
150
150
|
(equals: boolean) =>
|
|
151
|
+
(project: IProject) =>
|
|
151
152
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
152
153
|
(explore: CheckerProgrammer.IExplore) => {
|
|
153
154
|
if (explore.tracable === false)
|
|
154
155
|
return IsProgrammer.configure({
|
|
155
|
-
object: assert_object(equals)(importer),
|
|
156
|
+
object: assert_object(equals)(project)(importer),
|
|
156
157
|
numeric: true,
|
|
157
|
-
})(importer).combiner(explore);
|
|
158
|
+
})(project)(importer).combiner(explore);
|
|
158
159
|
|
|
159
160
|
const path: string = explore.postfix
|
|
160
161
|
? `_path + ${explore.postfix}`
|
|
@@ -219,40 +220,44 @@ export namespace AssertProgrammer {
|
|
|
219
220
|
// })();
|
|
220
221
|
};
|
|
221
222
|
|
|
222
|
-
const assert_object =
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
223
|
+
const assert_object =
|
|
224
|
+
(equals: boolean) =>
|
|
225
|
+
(project: IProject) =>
|
|
226
|
+
(importer: FunctionImporter) =>
|
|
227
|
+
check_object({
|
|
228
|
+
equals,
|
|
229
|
+
assert: true,
|
|
230
|
+
undefined: true,
|
|
231
|
+
reduce: ts.factory.createLogicalAnd,
|
|
232
|
+
positive: ts.factory.createTrue(),
|
|
233
|
+
superfluous: (value) =>
|
|
234
|
+
create_guard_call(importer)()(
|
|
235
|
+
ts.factory.createAdd(
|
|
236
|
+
ts.factory.createIdentifier("_path"),
|
|
237
|
+
ts.factory.createCallExpression(
|
|
238
|
+
importer.use("join"),
|
|
239
|
+
undefined,
|
|
240
|
+
[ts.factory.createIdentifier("key")],
|
|
241
|
+
),
|
|
237
242
|
),
|
|
243
|
+
"undefined",
|
|
244
|
+
value,
|
|
238
245
|
),
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
ts.factory.createIdentifier("_exceptionable"),
|
|
246
|
+
halt: (expr) =>
|
|
247
|
+
ts.factory.createLogicalOr(
|
|
248
|
+
ts.factory.createStrictEquality(
|
|
249
|
+
ts.factory.createFalse(),
|
|
250
|
+
ts.factory.createIdentifier("_exceptionable"),
|
|
251
|
+
),
|
|
252
|
+
expr,
|
|
247
253
|
),
|
|
248
|
-
|
|
249
|
-
),
|
|
250
|
-
})(importer);
|
|
254
|
+
})(project)(importer);
|
|
251
255
|
|
|
252
256
|
const joiner =
|
|
253
257
|
(equals: boolean) =>
|
|
258
|
+
(project: IProject) =>
|
|
254
259
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
255
|
-
object: assert_object(equals)(importer),
|
|
260
|
+
object: assert_object(equals)(project)(importer),
|
|
256
261
|
array: (input, arrow) =>
|
|
257
262
|
ts.factory.createCallExpression(
|
|
258
263
|
IdentifierFactory.access(input)("every"),
|
|
@@ -21,6 +21,7 @@ import { feature_object_entries } from "./internal/feature_object_entries";
|
|
|
21
21
|
export namespace IsProgrammer {
|
|
22
22
|
export const configure =
|
|
23
23
|
(options?: Partial<CONFIG.IOptions>) =>
|
|
24
|
+
(project: IProject) =>
|
|
24
25
|
(importer: FunctionImporter): CheckerProgrammer.IConfig => ({
|
|
25
26
|
prefix: "$i",
|
|
26
27
|
equals: !!options?.object,
|
|
@@ -79,7 +80,7 @@ export namespace IsProgrammer {
|
|
|
79
80
|
reduce: ts.factory.createLogicalAnd,
|
|
80
81
|
positive: ts.factory.createTrue(),
|
|
81
82
|
superfluous: () => ts.factory.createFalse(),
|
|
82
|
-
})(importer),
|
|
83
|
+
})(project)(importer),
|
|
83
84
|
array: (input, arrow) =>
|
|
84
85
|
ts.factory.createCallExpression(
|
|
85
86
|
IdentifierFactory.access(input)("every"),
|
|
@@ -126,9 +127,9 @@ export namespace IsProgrammer {
|
|
|
126
127
|
reduce: ts.factory.createLogicalAnd,
|
|
127
128
|
positive: ts.factory.createTrue(),
|
|
128
129
|
superfluous: () => ts.factory.createFalse(),
|
|
129
|
-
})(importer),
|
|
130
|
+
})(project)(importer),
|
|
130
131
|
numeric: OptionPredicator.numeric(project.options),
|
|
131
|
-
})(importer),
|
|
132
|
+
})(project)(importer),
|
|
132
133
|
trace: equals,
|
|
133
134
|
addition: () => importer.declare(modulo),
|
|
134
135
|
};
|
|
@@ -185,7 +186,7 @@ export namespace IsProgrammer {
|
|
|
185
186
|
(project: IProject) =>
|
|
186
187
|
(importer: FunctionImporter) =>
|
|
187
188
|
(collection: MetadataCollection) => {
|
|
188
|
-
const config = configure()(importer);
|
|
189
|
+
const config = configure()(project)(importer);
|
|
189
190
|
const objects =
|
|
190
191
|
CheckerProgrammer.write_object_functions(project)(config)(
|
|
191
192
|
importer,
|
|
@@ -223,10 +224,15 @@ export namespace IsProgrammer {
|
|
|
223
224
|
DECODERS
|
|
224
225
|
----------------------------------------------------------- */
|
|
225
226
|
export const decode = (project: IProject) => (importer: FunctionImporter) =>
|
|
226
|
-
CheckerProgrammer.decode(project)(configure()(importer))(
|
|
227
|
+
CheckerProgrammer.decode(project)(configure()(project)(importer))(
|
|
228
|
+
importer,
|
|
229
|
+
);
|
|
227
230
|
|
|
228
|
-
export const decode_object =
|
|
229
|
-
|
|
231
|
+
export const decode_object =
|
|
232
|
+
(project: IProject) => (importer: FunctionImporter) =>
|
|
233
|
+
CheckerProgrammer.decode_object(configure()(project)(importer))(
|
|
234
|
+
importer,
|
|
235
|
+
);
|
|
230
236
|
|
|
231
237
|
export const decode_to_json =
|
|
232
238
|
(checkNull: boolean) =>
|
|
@@ -97,8 +97,8 @@ export namespace ValidateProgrammer {
|
|
|
97
97
|
),
|
|
98
98
|
]),
|
|
99
99
|
].reduce((x, y) => ts.factory.createLogicalAnd(x, y)),
|
|
100
|
-
combiner: combine(equals)(importer),
|
|
101
|
-
joiner: joiner(equals)(importer),
|
|
100
|
+
combiner: combine(equals)(project)(importer),
|
|
101
|
+
joiner: joiner(equals)(project)(importer),
|
|
102
102
|
success: ts.factory.createTrue(),
|
|
103
103
|
addition: () => importer.declare(modulo),
|
|
104
104
|
},
|
|
@@ -195,13 +195,14 @@ export namespace ValidateProgrammer {
|
|
|
195
195
|
|
|
196
196
|
const combine =
|
|
197
197
|
(equals: boolean) =>
|
|
198
|
+
(project: IProject) =>
|
|
198
199
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
199
200
|
(explore: CheckerProgrammer.IExplore) => {
|
|
200
201
|
if (explore.tracable === false)
|
|
201
202
|
return IsProgrammer.configure({
|
|
202
|
-
object: validate_object(equals)(importer),
|
|
203
|
+
object: validate_object(equals)(project)(importer),
|
|
203
204
|
numeric: true,
|
|
204
|
-
})(importer).combiner(explore);
|
|
205
|
+
})(project)(importer).combiner(explore);
|
|
205
206
|
|
|
206
207
|
const path: string = explore.postfix
|
|
207
208
|
? `_path + ${explore.postfix}`
|
|
@@ -240,40 +241,42 @@ const combine =
|
|
|
240
241
|
);
|
|
241
242
|
};
|
|
242
243
|
|
|
243
|
-
const validate_object =
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
ts.factory.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
244
|
+
const validate_object =
|
|
245
|
+
(equals: boolean) => (project: IProject) => (importer: FunctionImporter) =>
|
|
246
|
+
check_object({
|
|
247
|
+
equals,
|
|
248
|
+
undefined: true,
|
|
249
|
+
assert: false,
|
|
250
|
+
reduce: ts.factory.createLogicalAnd,
|
|
251
|
+
positive: ts.factory.createTrue(),
|
|
252
|
+
superfluous: (value) =>
|
|
253
|
+
create_report_call()(
|
|
254
|
+
ts.factory.createAdd(
|
|
255
|
+
ts.factory.createIdentifier("_path"),
|
|
256
|
+
ts.factory.createCallExpression(
|
|
257
|
+
importer.use("join"),
|
|
258
|
+
undefined,
|
|
259
|
+
[ts.factory.createIdentifier("key")],
|
|
260
|
+
),
|
|
258
261
|
),
|
|
262
|
+
"undefined",
|
|
263
|
+
value,
|
|
259
264
|
),
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
ts.factory.createIdentifier("_exceptionable"),
|
|
265
|
+
halt: (expr) =>
|
|
266
|
+
ts.factory.createLogicalOr(
|
|
267
|
+
ts.factory.createStrictEquality(
|
|
268
|
+
ts.factory.createFalse(),
|
|
269
|
+
ts.factory.createIdentifier("_exceptionable"),
|
|
270
|
+
),
|
|
271
|
+
expr,
|
|
268
272
|
),
|
|
269
|
-
|
|
270
|
-
),
|
|
271
|
-
})(importer);
|
|
273
|
+
})(project)(importer);
|
|
272
274
|
|
|
273
275
|
const joiner =
|
|
274
276
|
(equals: boolean) =>
|
|
277
|
+
(project: IProject) =>
|
|
275
278
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
276
|
-
object: validate_object(equals)(importer),
|
|
279
|
+
object: validate_object(equals)(project)(importer),
|
|
277
280
|
array: (input, arrow) =>
|
|
278
281
|
check_everything(
|
|
279
282
|
ts.factory.createCallExpression(
|
|
@@ -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,146 +1,146 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
-
|
|
7
|
-
import { Escaper } from "../../utils/Escaper";
|
|
8
|
-
|
|
9
|
-
import { metadata_to_pattern } from "../internal/metadata_to_pattern";
|
|
10
|
-
import { IExpressionEntry } from "./IExpressionEntry";
|
|
11
|
-
|
|
12
|
-
export namespace NotationJoiner {
|
|
13
|
-
export const object =
|
|
14
|
-
(rename: (str: string) => string) =>
|
|
15
|
-
(
|
|
16
|
-
input: ts.Expression,
|
|
17
|
-
entries: IExpressionEntry<ts.Expression>[],
|
|
18
|
-
): ts.ConciseBody => {
|
|
19
|
-
if (entries.length === 0) return ts.factory.createIdentifier("{}");
|
|
20
|
-
|
|
21
|
-
const regular = entries.filter((e) => e.key.isSoleLiteral());
|
|
22
|
-
const dynamic = entries.filter((e) => !e.key.isSoleLiteral());
|
|
23
|
-
const literal = ts.factory.createObjectLiteralExpression(
|
|
24
|
-
regular.map((entry) => {
|
|
25
|
-
const str: string = rename(entry.key.getSoleLiteral()!);
|
|
26
|
-
return ts.factory.createPropertyAssignment(
|
|
27
|
-
Escaper.variable(str)
|
|
28
|
-
? str
|
|
29
|
-
: ts.factory.createStringLiteral(str),
|
|
30
|
-
entry.expression,
|
|
31
|
-
);
|
|
32
|
-
}),
|
|
33
|
-
true,
|
|
34
|
-
);
|
|
35
|
-
if (dynamic.length === 0) return literal;
|
|
36
|
-
|
|
37
|
-
const key = ts.factory.createIdentifier("key");
|
|
38
|
-
const output = ts.factory.createIdentifier("output");
|
|
39
|
-
|
|
40
|
-
const statements: ts.Statement[] = [];
|
|
41
|
-
if (regular.length !== 0)
|
|
42
|
-
statements.push(
|
|
43
|
-
ts.factory.createIfStatement(
|
|
44
|
-
ts.factory.createCallExpression(
|
|
45
|
-
IdentifierFactory.access(
|
|
46
|
-
ts.factory.createArrayLiteralExpression(
|
|
47
|
-
regular.map((r) =>
|
|
48
|
-
ts.factory.createStringLiteral(
|
|
49
|
-
r.key.getSoleLiteral()!,
|
|
50
|
-
),
|
|
51
|
-
),
|
|
52
|
-
),
|
|
53
|
-
)("some"),
|
|
54
|
-
undefined,
|
|
55
|
-
[
|
|
56
|
-
ts.factory.createArrowFunction(
|
|
57
|
-
undefined,
|
|
58
|
-
undefined,
|
|
59
|
-
[IdentifierFactory.parameter("regular")],
|
|
60
|
-
undefined,
|
|
61
|
-
undefined,
|
|
62
|
-
ts.factory.createStrictEquality(
|
|
63
|
-
ts.factory.createIdentifier("regular"),
|
|
64
|
-
ts.factory.createIdentifier("key"),
|
|
65
|
-
),
|
|
66
|
-
),
|
|
67
|
-
],
|
|
68
|
-
),
|
|
69
|
-
ts.factory.createContinueStatement(),
|
|
70
|
-
),
|
|
71
|
-
);
|
|
72
|
-
statements.push(
|
|
73
|
-
...dynamic.map((entry) =>
|
|
74
|
-
ts.factory.createIfStatement(
|
|
75
|
-
ts.factory.createCallExpression(
|
|
76
|
-
ts.factory.createIdentifier(
|
|
77
|
-
`RegExp(/${metadata_to_pattern(true)(
|
|
78
|
-
entry.key,
|
|
79
|
-
)}/).test`,
|
|
80
|
-
),
|
|
81
|
-
undefined,
|
|
82
|
-
[key],
|
|
83
|
-
),
|
|
84
|
-
ts.factory.createBlock([
|
|
85
|
-
ts.factory.createExpressionStatement(
|
|
86
|
-
ts.factory.createBinaryExpression(
|
|
87
|
-
ts.factory.createElementAccessExpression(
|
|
88
|
-
output,
|
|
89
|
-
key,
|
|
90
|
-
),
|
|
91
|
-
ts.factory.createToken(
|
|
92
|
-
ts.SyntaxKind.EqualsToken,
|
|
93
|
-
),
|
|
94
|
-
entry.expression,
|
|
95
|
-
),
|
|
96
|
-
),
|
|
97
|
-
ts.factory.createContinueStatement(),
|
|
98
|
-
]),
|
|
99
|
-
),
|
|
100
|
-
),
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
return ts.factory.createBlock([
|
|
104
|
-
StatementFactory.constant(
|
|
105
|
-
"output",
|
|
106
|
-
ts.factory.createAsExpression(
|
|
107
|
-
literal,
|
|
108
|
-
TypeFactory.keyword("any"),
|
|
109
|
-
),
|
|
110
|
-
),
|
|
111
|
-
ts.factory.createForOfStatement(
|
|
112
|
-
undefined,
|
|
113
|
-
StatementFactory.entry("key")("value"),
|
|
114
|
-
ts.factory.createCallExpression(
|
|
115
|
-
ts.factory.createIdentifier("Object.entries"),
|
|
116
|
-
undefined,
|
|
117
|
-
[input],
|
|
118
|
-
),
|
|
119
|
-
ts.factory.createBlock(statements),
|
|
120
|
-
),
|
|
121
|
-
ts.factory.createReturnStatement(output),
|
|
122
|
-
]);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export const tuple = (
|
|
126
|
-
children: ts.Expression[],
|
|
127
|
-
rest: ts.Expression | null,
|
|
128
|
-
): ts.Expression => {
|
|
129
|
-
return ts.factory.createAsExpression(
|
|
130
|
-
ts.factory.createArrayLiteralExpression(
|
|
131
|
-
rest === null
|
|
132
|
-
? children
|
|
133
|
-
: [...children, ts.factory.createSpreadElement(rest)],
|
|
134
|
-
true,
|
|
135
|
-
),
|
|
136
|
-
TypeFactory.keyword("any"),
|
|
137
|
-
);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export const array = (input: ts.Expression, arrow: ts.Expression) =>
|
|
141
|
-
ts.factory.createCallExpression(
|
|
142
|
-
ts.factory.createPropertyAccessExpression(input, "map"),
|
|
143
|
-
undefined,
|
|
144
|
-
[arrow],
|
|
145
|
-
);
|
|
146
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
import { Escaper } from "../../utils/Escaper";
|
|
8
|
+
|
|
9
|
+
import { metadata_to_pattern } from "../internal/metadata_to_pattern";
|
|
10
|
+
import { IExpressionEntry } from "./IExpressionEntry";
|
|
11
|
+
|
|
12
|
+
export namespace NotationJoiner {
|
|
13
|
+
export const object =
|
|
14
|
+
(rename: (str: string) => string) =>
|
|
15
|
+
(
|
|
16
|
+
input: ts.Expression,
|
|
17
|
+
entries: IExpressionEntry<ts.Expression>[],
|
|
18
|
+
): ts.ConciseBody => {
|
|
19
|
+
if (entries.length === 0) return ts.factory.createIdentifier("{}");
|
|
20
|
+
|
|
21
|
+
const regular = entries.filter((e) => e.key.isSoleLiteral());
|
|
22
|
+
const dynamic = entries.filter((e) => !e.key.isSoleLiteral());
|
|
23
|
+
const literal = ts.factory.createObjectLiteralExpression(
|
|
24
|
+
regular.map((entry) => {
|
|
25
|
+
const str: string = rename(entry.key.getSoleLiteral()!);
|
|
26
|
+
return ts.factory.createPropertyAssignment(
|
|
27
|
+
Escaper.variable(str)
|
|
28
|
+
? str
|
|
29
|
+
: ts.factory.createStringLiteral(str),
|
|
30
|
+
entry.expression,
|
|
31
|
+
);
|
|
32
|
+
}),
|
|
33
|
+
true,
|
|
34
|
+
);
|
|
35
|
+
if (dynamic.length === 0) return literal;
|
|
36
|
+
|
|
37
|
+
const key = ts.factory.createIdentifier("key");
|
|
38
|
+
const output = ts.factory.createIdentifier("output");
|
|
39
|
+
|
|
40
|
+
const statements: ts.Statement[] = [];
|
|
41
|
+
if (regular.length !== 0)
|
|
42
|
+
statements.push(
|
|
43
|
+
ts.factory.createIfStatement(
|
|
44
|
+
ts.factory.createCallExpression(
|
|
45
|
+
IdentifierFactory.access(
|
|
46
|
+
ts.factory.createArrayLiteralExpression(
|
|
47
|
+
regular.map((r) =>
|
|
48
|
+
ts.factory.createStringLiteral(
|
|
49
|
+
r.key.getSoleLiteral()!,
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
),
|
|
53
|
+
)("some"),
|
|
54
|
+
undefined,
|
|
55
|
+
[
|
|
56
|
+
ts.factory.createArrowFunction(
|
|
57
|
+
undefined,
|
|
58
|
+
undefined,
|
|
59
|
+
[IdentifierFactory.parameter("regular")],
|
|
60
|
+
undefined,
|
|
61
|
+
undefined,
|
|
62
|
+
ts.factory.createStrictEquality(
|
|
63
|
+
ts.factory.createIdentifier("regular"),
|
|
64
|
+
ts.factory.createIdentifier("key"),
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
],
|
|
68
|
+
),
|
|
69
|
+
ts.factory.createContinueStatement(),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
statements.push(
|
|
73
|
+
...dynamic.map((entry) =>
|
|
74
|
+
ts.factory.createIfStatement(
|
|
75
|
+
ts.factory.createCallExpression(
|
|
76
|
+
ts.factory.createIdentifier(
|
|
77
|
+
`RegExp(/${metadata_to_pattern(true)(
|
|
78
|
+
entry.key,
|
|
79
|
+
)}/).test`,
|
|
80
|
+
),
|
|
81
|
+
undefined,
|
|
82
|
+
[key],
|
|
83
|
+
),
|
|
84
|
+
ts.factory.createBlock([
|
|
85
|
+
ts.factory.createExpressionStatement(
|
|
86
|
+
ts.factory.createBinaryExpression(
|
|
87
|
+
ts.factory.createElementAccessExpression(
|
|
88
|
+
output,
|
|
89
|
+
key,
|
|
90
|
+
),
|
|
91
|
+
ts.factory.createToken(
|
|
92
|
+
ts.SyntaxKind.EqualsToken,
|
|
93
|
+
),
|
|
94
|
+
entry.expression,
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
ts.factory.createContinueStatement(),
|
|
98
|
+
]),
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return ts.factory.createBlock([
|
|
104
|
+
StatementFactory.constant(
|
|
105
|
+
"output",
|
|
106
|
+
ts.factory.createAsExpression(
|
|
107
|
+
literal,
|
|
108
|
+
TypeFactory.keyword("any"),
|
|
109
|
+
),
|
|
110
|
+
),
|
|
111
|
+
ts.factory.createForOfStatement(
|
|
112
|
+
undefined,
|
|
113
|
+
StatementFactory.entry("key")("value"),
|
|
114
|
+
ts.factory.createCallExpression(
|
|
115
|
+
ts.factory.createIdentifier("Object.entries"),
|
|
116
|
+
undefined,
|
|
117
|
+
[input],
|
|
118
|
+
),
|
|
119
|
+
ts.factory.createBlock(statements),
|
|
120
|
+
),
|
|
121
|
+
ts.factory.createReturnStatement(output),
|
|
122
|
+
]);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const tuple = (
|
|
126
|
+
children: ts.Expression[],
|
|
127
|
+
rest: ts.Expression | null,
|
|
128
|
+
): ts.Expression => {
|
|
129
|
+
return ts.factory.createAsExpression(
|
|
130
|
+
ts.factory.createArrayLiteralExpression(
|
|
131
|
+
rest === null
|
|
132
|
+
? children
|
|
133
|
+
: [...children, ts.factory.createSpreadElement(rest)],
|
|
134
|
+
true,
|
|
135
|
+
),
|
|
136
|
+
TypeFactory.keyword("any"),
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const array = (input: ts.Expression, arrow: ts.Expression) =>
|
|
141
|
+
ts.factory.createCallExpression(
|
|
142
|
+
ts.factory.createPropertyAccessExpression(input, "map"),
|
|
143
|
+
undefined,
|
|
144
|
+
[arrow],
|
|
145
|
+
);
|
|
146
|
+
}
|