typia 3.8.2 → 3.8.3
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/README.md +1 -1
- package/lib/Primitive.d.ts +10 -10
- package/lib/factories/MetadataFactory.d.ts +1 -1
- package/lib/factories/MetadataFactory.js +1 -1
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js +3 -1
- package/lib/factories/internal/metadata/emplace_metadata_object.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_tuple.js +2 -0
- package/lib/factories/internal/metadata/iterate_metadata_tuple.js.map +1 -1
- package/lib/metadata/IMetadata.d.ts +1 -0
- package/lib/metadata/Metadata.d.ts +1 -0
- package/lib/metadata/Metadata.js +5 -0
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +17 -6
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/internal/application_object.js +1 -0
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_tuple.js +1 -1
- package/lib/programmers/internal/application_tuple.js.map +1 -1
- package/lib/schemas/IJsonSchema.d.ts +1 -0
- package/package.json +1 -1
- package/src/Primitive.ts +123 -120
- package/src/executable/TypiaGenerateWizard.ts +85 -85
- package/src/executable/TypiaSetupWizard.ts +133 -133
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/PackageManager.ts +71 -71
- package/src/executable/typia.ts +52 -52
- package/src/factories/CommentFactory.ts +14 -14
- package/src/factories/ExpressionFactory.ts +70 -70
- package/src/factories/IdentifierFactory.ts +63 -63
- package/src/factories/LiteralFactory.ts +39 -39
- package/src/factories/MetadataCollection.ts +121 -121
- package/src/factories/MetadataFactory.ts +62 -62
- package/src/factories/MetadataTagFactory.ts +297 -297
- package/src/factories/StatementFactory.ts +24 -24
- package/src/factories/TemplateFactory.ts +58 -58
- package/src/factories/TypeFactory.ts +124 -124
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +143 -140
- package/src/factories/internal/metadata/iterate_metadata.ts +67 -67
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +219 -219
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +48 -44
- package/src/factories/internal/metadata/iterate_metadata_union.ts +57 -57
- package/src/functional/$any.ts +2 -2
- package/src/functional/$is_between.ts +2 -2
- package/src/functional/$is_custom.ts +14 -14
- package/src/functional/$is_date.ts +3 -3
- package/src/functional/$is_datetime.ts +2 -2
- package/src/functional/$is_email.ts +4 -4
- package/src/functional/$is_ipv4.ts +4 -4
- package/src/functional/$is_ipv6.ts +4 -4
- package/src/functional/$is_url.ts +4 -4
- package/src/functional/$is_uuid.ts +4 -4
- package/src/functional/$join.ts +46 -46
- package/src/functional/$number.ts +12 -12
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +5 -5
- package/src/metadata/IMetadata.ts +1 -0
- package/src/metadata/Metadata.ts +539 -533
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +127 -127
- package/src/module.ts +2043 -2043
- package/src/programmers/ApplicationProgrammer.ts +62 -62
- package/src/programmers/AssertCloneProgrammer.ts +79 -79
- package/src/programmers/AssertParseProgrammer.ts +74 -74
- package/src/programmers/AssertProgrammer.ts +285 -285
- package/src/programmers/AssertPruneProgrammer.ts +76 -76
- package/src/programmers/AssertStringifyProgrammer.ts +74 -74
- package/src/programmers/CheckerProgrammer.ts +901 -875
- package/src/programmers/CloneProgrammer.ts +389 -389
- package/src/programmers/FeatureProgrammer.ts +500 -500
- package/src/programmers/IsCloneProgrammer.ts +86 -86
- package/src/programmers/IsParseProgrammer.ts +80 -80
- package/src/programmers/IsProgrammer.ts +212 -212
- package/src/programmers/IsPruneProgrammer.ts +81 -81
- package/src/programmers/IsStringifyProgrammer.ts +84 -84
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/PruneProgrammer.ts +347 -347
- package/src/programmers/RandomProgrammer.ts +423 -423
- package/src/programmers/StringifyProgrammer.ts +798 -798
- package/src/programmers/TypiaProgrammer.ts +129 -129
- package/src/programmers/ValidateCloneProgrammer.ts +93 -93
- package/src/programmers/ValidateParseProgrammer.ts +78 -78
- package/src/programmers/ValidateProgrammer.ts +316 -316
- package/src/programmers/ValidatePruneProgrammer.ts +86 -86
- package/src/programmers/ValidateStringifyProgrammer.ts +92 -92
- package/src/programmers/helpers/CloneJoiner.ts +131 -131
- package/src/programmers/helpers/FunctionImporeter.ts +54 -54
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/helpers/PruneJoiner.ts +144 -144
- package/src/programmers/helpers/StringifyJoinder.ts +113 -113
- package/src/programmers/helpers/StringifyPredicator.ts +12 -12
- package/src/programmers/helpers/UnionExplorer.ts +275 -275
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +36 -36
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +30 -30
- package/src/programmers/internal/application_default_string.ts +33 -33
- package/src/programmers/internal/application_native.ts +32 -32
- package/src/programmers/internal/application_number.ts +73 -73
- package/src/programmers/internal/application_object.ts +155 -154
- package/src/programmers/internal/application_schema.ts +213 -213
- package/src/programmers/internal/application_string.ts +45 -45
- package/src/programmers/internal/application_templates.ts +26 -26
- package/src/programmers/internal/application_tuple.ts +31 -29
- package/src/programmers/internal/check_array.ts +30 -30
- package/src/programmers/internal/check_custom.ts +31 -31
- package/src/programmers/internal/check_dynamic_properties.ts +194 -194
- package/src/programmers/internal/check_everything.ts +28 -28
- package/src/programmers/internal/check_native.ts +21 -21
- package/src/programmers/internal/check_string_tags.ts +67 -67
- package/src/programmers/internal/check_union_array_like.ts +271 -271
- package/src/programmers/internal/check_union_tuple.ts +33 -33
- package/src/programmers/internal/random_custom.ts +29 -29
- package/src/programmers/internal/stringify_dynamic_properties.ts +167 -167
- package/src/programmers/internal/stringify_native.ts +7 -7
- package/src/programmers/internal/stringify_regular_properties.ts +83 -83
- package/src/schemas/IJsonSchema.ts +130 -129
- package/src/transform.ts +17 -17
- package/src/transformers/CallExpressionTransformer.ts +177 -177
- package/src/transformers/FileTransformer.ts +47 -47
- package/src/transformers/NodeTransformer.ts +13 -13
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
- package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +39 -39
- package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +28 -28
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +52 -52
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +42 -42
- package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/validators/AssertTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateAssertTransformer.ts +13 -13
- package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
- package/src/transformers/features/validators/IsTransformer.ts +11 -11
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +97 -97
- package/src/utils/ArrayUtil.ts +44 -44
- package/src/utils/Escaper.ts +45 -45
- package/src/utils/MapUtil.ts +12 -12
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/RandomGenerator.ts +81 -81
|
@@ -1,54 +1,54 @@
|
|
|
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
|
-
export class FunctionImporter {
|
|
8
|
-
private readonly used_: Set<string> = new Set();
|
|
9
|
-
private readonly local_: Set<string> = new Set();
|
|
10
|
-
private sequence_: number = 0;
|
|
11
|
-
|
|
12
|
-
public empty(): boolean {
|
|
13
|
-
return this.used_.size === 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public use(name: string): ts.Identifier {
|
|
17
|
-
this.used_.add(name);
|
|
18
|
-
return ts.factory.createIdentifier("$" + name);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public useLocal(name: string): string {
|
|
22
|
-
this.local_.add(name);
|
|
23
|
-
return name;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public hasLocal(name: string): boolean {
|
|
27
|
-
return this.local_.has(name);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
|
|
31
|
-
return [...this.used_].map((name) =>
|
|
32
|
-
StatementFactory.constant(
|
|
33
|
-
"$" + name,
|
|
34
|
-
IdentifierFactory.access(
|
|
35
|
-
ts.factory.createParenthesizedExpression(
|
|
36
|
-
ts.factory.createAsExpression(
|
|
37
|
-
modulo,
|
|
38
|
-
TypeFactory.keyword("any"),
|
|
39
|
-
),
|
|
40
|
-
),
|
|
41
|
-
)(name),
|
|
42
|
-
),
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public increment(): number {
|
|
47
|
-
return ++this.sequence_;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public trace(): void {
|
|
51
|
-
console.log(...this.used_);
|
|
52
|
-
console.log(...this.local_);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
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
|
+
export class FunctionImporter {
|
|
8
|
+
private readonly used_: Set<string> = new Set();
|
|
9
|
+
private readonly local_: Set<string> = new Set();
|
|
10
|
+
private sequence_: number = 0;
|
|
11
|
+
|
|
12
|
+
public empty(): boolean {
|
|
13
|
+
return this.used_.size === 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public use(name: string): ts.Identifier {
|
|
17
|
+
this.used_.add(name);
|
|
18
|
+
return ts.factory.createIdentifier("$" + name);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public useLocal(name: string): string {
|
|
22
|
+
this.local_.add(name);
|
|
23
|
+
return name;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public hasLocal(name: string): boolean {
|
|
27
|
+
return this.local_.has(name);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
|
|
31
|
+
return [...this.used_].map((name) =>
|
|
32
|
+
StatementFactory.constant(
|
|
33
|
+
"$" + name,
|
|
34
|
+
IdentifierFactory.access(
|
|
35
|
+
ts.factory.createParenthesizedExpression(
|
|
36
|
+
ts.factory.createAsExpression(
|
|
37
|
+
modulo,
|
|
38
|
+
TypeFactory.keyword("any"),
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
)(name),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public increment(): number {
|
|
47
|
+
return ++this.sequence_;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public trace(): void {
|
|
51
|
+
console.log(...this.used_);
|
|
52
|
+
console.log(...this.local_);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ITransformOptions } from "../../transformers/ITransformOptions";
|
|
2
|
-
|
|
3
|
-
export namespace OptionPredicator {
|
|
4
|
-
export const numeric = (options: ITransformOptions): boolean =>
|
|
5
|
-
finite(options) || options.numeric === true;
|
|
6
|
-
|
|
7
|
-
export const functional = (options: ITransformOptions): boolean =>
|
|
8
|
-
options.functional === true;
|
|
9
|
-
|
|
10
|
-
export const finite = (options: ITransformOptions): boolean =>
|
|
11
|
-
options.finite === true;
|
|
12
|
-
|
|
13
|
-
export const undefined = (options: ITransformOptions): boolean =>
|
|
14
|
-
options.undefined !== false;
|
|
15
|
-
}
|
|
1
|
+
import { ITransformOptions } from "../../transformers/ITransformOptions";
|
|
2
|
+
|
|
3
|
+
export namespace OptionPredicator {
|
|
4
|
+
export const numeric = (options: ITransformOptions): boolean =>
|
|
5
|
+
finite(options) || options.numeric === true;
|
|
6
|
+
|
|
7
|
+
export const functional = (options: ITransformOptions): boolean =>
|
|
8
|
+
options.functional === true;
|
|
9
|
+
|
|
10
|
+
export const finite = (options: ITransformOptions): boolean =>
|
|
11
|
+
options.finite === true;
|
|
12
|
+
|
|
13
|
+
export const undefined = (options: ITransformOptions): boolean =>
|
|
14
|
+
options.undefined !== false;
|
|
15
|
+
}
|
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
-
|
|
7
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
8
|
-
|
|
9
|
-
import { metadata_to_pattern } from "../internal/metadata_to_pattern";
|
|
10
|
-
import { prune_object_properties } from "../internal/prune_object_properties";
|
|
11
|
-
import { IExpressionEntry } from "./IExpressionEntry";
|
|
12
|
-
|
|
13
|
-
export namespace PruneJoiner {
|
|
14
|
-
export const object = (
|
|
15
|
-
input: ts.Expression,
|
|
16
|
-
entries: IExpressionEntry[],
|
|
17
|
-
obj: MetadataObject,
|
|
18
|
-
): ts.ConciseBody => {
|
|
19
|
-
// PREPARE ASSETS
|
|
20
|
-
const regular = entries.filter((entry) => entry.key.isSoleLiteral());
|
|
21
|
-
const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
|
|
22
|
-
|
|
23
|
-
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
24
|
-
regular.map((entry) =>
|
|
25
|
-
ts.isBlock(entry.expression)
|
|
26
|
-
? [...entry.expression.statements]
|
|
27
|
-
: [ts.factory.createExpressionStatement(entry.expression)],
|
|
28
|
-
),
|
|
29
|
-
);
|
|
30
|
-
if (dynamic.length)
|
|
31
|
-
statements.push(
|
|
32
|
-
ts.factory.createExpressionStatement(
|
|
33
|
-
iterate_dynamic_properties({ regular, dynamic })(input),
|
|
34
|
-
),
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
statements.push(prune_object_properties(obj));
|
|
38
|
-
return ts.factory.createBlock(statements, true);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const array = (input: ts.Expression, arrow: ts.ArrowFunction) =>
|
|
42
|
-
ts.factory.createCallExpression(
|
|
43
|
-
IdentifierFactory.access(input)("forEach"),
|
|
44
|
-
undefined,
|
|
45
|
-
[arrow],
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
export const tuple = (
|
|
49
|
-
children: ts.ConciseBody[],
|
|
50
|
-
rest: ts.ConciseBody | null,
|
|
51
|
-
): ts.Block => {
|
|
52
|
-
const entire: ts.ConciseBody[] = [...children];
|
|
53
|
-
if (rest !== null) entire.push(rest);
|
|
54
|
-
|
|
55
|
-
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
56
|
-
entire.map((elem) =>
|
|
57
|
-
ts.isBlock(elem)
|
|
58
|
-
? [...elem.statements]
|
|
59
|
-
: [ts.factory.createExpressionStatement(elem)],
|
|
60
|
-
),
|
|
61
|
-
);
|
|
62
|
-
return ts.factory.createBlock(statements, true);
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const iterate_dynamic_properties =
|
|
67
|
-
(props: { regular: IExpressionEntry[]; dynamic: IExpressionEntry[] }) =>
|
|
68
|
-
(input: ts.Expression) =>
|
|
69
|
-
ts.factory.createCallExpression(
|
|
70
|
-
IdentifierFactory.join(
|
|
71
|
-
ts.factory.createCallExpression(
|
|
72
|
-
ts.factory.createIdentifier("Object.entries"),
|
|
73
|
-
undefined,
|
|
74
|
-
[input],
|
|
75
|
-
),
|
|
76
|
-
"forEach",
|
|
77
|
-
),
|
|
78
|
-
undefined,
|
|
79
|
-
[
|
|
80
|
-
ts.factory.createArrowFunction(
|
|
81
|
-
undefined,
|
|
82
|
-
undefined,
|
|
83
|
-
[
|
|
84
|
-
IdentifierFactory.parameter(
|
|
85
|
-
ts.factory.createArrayBindingPattern(
|
|
86
|
-
["key", "value"].map((l) =>
|
|
87
|
-
ts.factory.createBindingElement(
|
|
88
|
-
undefined,
|
|
89
|
-
undefined,
|
|
90
|
-
ts.factory.createIdentifier(l),
|
|
91
|
-
undefined,
|
|
92
|
-
),
|
|
93
|
-
),
|
|
94
|
-
),
|
|
95
|
-
),
|
|
96
|
-
],
|
|
97
|
-
undefined,
|
|
98
|
-
undefined,
|
|
99
|
-
ts.factory.createBlock(
|
|
100
|
-
[
|
|
101
|
-
ts.factory.createIfStatement(
|
|
102
|
-
ts.factory.createStrictEquality(
|
|
103
|
-
ts.factory.createIdentifier("undefined"),
|
|
104
|
-
ts.factory.createIdentifier("value"),
|
|
105
|
-
),
|
|
106
|
-
ts.factory.createReturnStatement(),
|
|
107
|
-
),
|
|
108
|
-
...props.regular.map(({ key }) =>
|
|
109
|
-
ts.factory.createIfStatement(
|
|
110
|
-
ts.factory.createStrictEquality(
|
|
111
|
-
ts.factory.createStringLiteral(
|
|
112
|
-
key.getSoleLiteral()!,
|
|
113
|
-
),
|
|
114
|
-
ts.factory.createIdentifier("key"),
|
|
115
|
-
),
|
|
116
|
-
ts.factory.createReturnStatement(),
|
|
117
|
-
),
|
|
118
|
-
),
|
|
119
|
-
...props.dynamic.map((dynamic) =>
|
|
120
|
-
ts.factory.createIfStatement(
|
|
121
|
-
ts.factory.createCallExpression(
|
|
122
|
-
ts.factory.createIdentifier(
|
|
123
|
-
`RegExp(/${metadata_to_pattern(
|
|
124
|
-
true,
|
|
125
|
-
)(dynamic.key)}/).test`,
|
|
126
|
-
),
|
|
127
|
-
undefined,
|
|
128
|
-
[ts.factory.createIdentifier("key")],
|
|
129
|
-
),
|
|
130
|
-
ts.isBlock(dynamic.expression)
|
|
131
|
-
? dynamic.expression
|
|
132
|
-
: ts.factory.createBlock([
|
|
133
|
-
ts.factory.createExpressionStatement(
|
|
134
|
-
dynamic.expression,
|
|
135
|
-
),
|
|
136
|
-
]),
|
|
137
|
-
),
|
|
138
|
-
),
|
|
139
|
-
],
|
|
140
|
-
true,
|
|
141
|
-
),
|
|
142
|
-
),
|
|
143
|
-
],
|
|
144
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
+
|
|
7
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
8
|
+
|
|
9
|
+
import { metadata_to_pattern } from "../internal/metadata_to_pattern";
|
|
10
|
+
import { prune_object_properties } from "../internal/prune_object_properties";
|
|
11
|
+
import { IExpressionEntry } from "./IExpressionEntry";
|
|
12
|
+
|
|
13
|
+
export namespace PruneJoiner {
|
|
14
|
+
export const object = (
|
|
15
|
+
input: ts.Expression,
|
|
16
|
+
entries: IExpressionEntry[],
|
|
17
|
+
obj: MetadataObject,
|
|
18
|
+
): ts.ConciseBody => {
|
|
19
|
+
// PREPARE ASSETS
|
|
20
|
+
const regular = entries.filter((entry) => entry.key.isSoleLiteral());
|
|
21
|
+
const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
|
|
22
|
+
|
|
23
|
+
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
24
|
+
regular.map((entry) =>
|
|
25
|
+
ts.isBlock(entry.expression)
|
|
26
|
+
? [...entry.expression.statements]
|
|
27
|
+
: [ts.factory.createExpressionStatement(entry.expression)],
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
if (dynamic.length)
|
|
31
|
+
statements.push(
|
|
32
|
+
ts.factory.createExpressionStatement(
|
|
33
|
+
iterate_dynamic_properties({ regular, dynamic })(input),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
statements.push(prune_object_properties(obj));
|
|
38
|
+
return ts.factory.createBlock(statements, true);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const array = (input: ts.Expression, arrow: ts.ArrowFunction) =>
|
|
42
|
+
ts.factory.createCallExpression(
|
|
43
|
+
IdentifierFactory.access(input)("forEach"),
|
|
44
|
+
undefined,
|
|
45
|
+
[arrow],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export const tuple = (
|
|
49
|
+
children: ts.ConciseBody[],
|
|
50
|
+
rest: ts.ConciseBody | null,
|
|
51
|
+
): ts.Block => {
|
|
52
|
+
const entire: ts.ConciseBody[] = [...children];
|
|
53
|
+
if (rest !== null) entire.push(rest);
|
|
54
|
+
|
|
55
|
+
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
56
|
+
entire.map((elem) =>
|
|
57
|
+
ts.isBlock(elem)
|
|
58
|
+
? [...elem.statements]
|
|
59
|
+
: [ts.factory.createExpressionStatement(elem)],
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
return ts.factory.createBlock(statements, true);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const iterate_dynamic_properties =
|
|
67
|
+
(props: { regular: IExpressionEntry[]; dynamic: IExpressionEntry[] }) =>
|
|
68
|
+
(input: ts.Expression) =>
|
|
69
|
+
ts.factory.createCallExpression(
|
|
70
|
+
IdentifierFactory.join(
|
|
71
|
+
ts.factory.createCallExpression(
|
|
72
|
+
ts.factory.createIdentifier("Object.entries"),
|
|
73
|
+
undefined,
|
|
74
|
+
[input],
|
|
75
|
+
),
|
|
76
|
+
"forEach",
|
|
77
|
+
),
|
|
78
|
+
undefined,
|
|
79
|
+
[
|
|
80
|
+
ts.factory.createArrowFunction(
|
|
81
|
+
undefined,
|
|
82
|
+
undefined,
|
|
83
|
+
[
|
|
84
|
+
IdentifierFactory.parameter(
|
|
85
|
+
ts.factory.createArrayBindingPattern(
|
|
86
|
+
["key", "value"].map((l) =>
|
|
87
|
+
ts.factory.createBindingElement(
|
|
88
|
+
undefined,
|
|
89
|
+
undefined,
|
|
90
|
+
ts.factory.createIdentifier(l),
|
|
91
|
+
undefined,
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
),
|
|
96
|
+
],
|
|
97
|
+
undefined,
|
|
98
|
+
undefined,
|
|
99
|
+
ts.factory.createBlock(
|
|
100
|
+
[
|
|
101
|
+
ts.factory.createIfStatement(
|
|
102
|
+
ts.factory.createStrictEquality(
|
|
103
|
+
ts.factory.createIdentifier("undefined"),
|
|
104
|
+
ts.factory.createIdentifier("value"),
|
|
105
|
+
),
|
|
106
|
+
ts.factory.createReturnStatement(),
|
|
107
|
+
),
|
|
108
|
+
...props.regular.map(({ key }) =>
|
|
109
|
+
ts.factory.createIfStatement(
|
|
110
|
+
ts.factory.createStrictEquality(
|
|
111
|
+
ts.factory.createStringLiteral(
|
|
112
|
+
key.getSoleLiteral()!,
|
|
113
|
+
),
|
|
114
|
+
ts.factory.createIdentifier("key"),
|
|
115
|
+
),
|
|
116
|
+
ts.factory.createReturnStatement(),
|
|
117
|
+
),
|
|
118
|
+
),
|
|
119
|
+
...props.dynamic.map((dynamic) =>
|
|
120
|
+
ts.factory.createIfStatement(
|
|
121
|
+
ts.factory.createCallExpression(
|
|
122
|
+
ts.factory.createIdentifier(
|
|
123
|
+
`RegExp(/${metadata_to_pattern(
|
|
124
|
+
true,
|
|
125
|
+
)(dynamic.key)}/).test`,
|
|
126
|
+
),
|
|
127
|
+
undefined,
|
|
128
|
+
[ts.factory.createIdentifier("key")],
|
|
129
|
+
),
|
|
130
|
+
ts.isBlock(dynamic.expression)
|
|
131
|
+
? dynamic.expression
|
|
132
|
+
: ts.factory.createBlock([
|
|
133
|
+
ts.factory.createExpressionStatement(
|
|
134
|
+
dynamic.expression,
|
|
135
|
+
),
|
|
136
|
+
]),
|
|
137
|
+
),
|
|
138
|
+
),
|
|
139
|
+
],
|
|
140
|
+
true,
|
|
141
|
+
),
|
|
142
|
+
),
|
|
143
|
+
],
|
|
144
|
+
);
|
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
-
|
|
6
|
-
import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
|
|
7
|
-
import { stringify_regular_properties } from "../internal/stringify_regular_properties";
|
|
8
|
-
import { FunctionImporter } from "./FunctionImporeter";
|
|
9
|
-
import { IExpressionEntry } from "./IExpressionEntry";
|
|
10
|
-
|
|
11
|
-
export namespace StringifyJoiner {
|
|
12
|
-
export const object =
|
|
13
|
-
(importer: FunctionImporter) =>
|
|
14
|
-
(
|
|
15
|
-
_input: ts.Expression,
|
|
16
|
-
entries: IExpressionEntry<ts.Expression>[],
|
|
17
|
-
): ts.Expression => {
|
|
18
|
-
// CHECK AND SORT ENTRIES
|
|
19
|
-
if (entries.length === 0)
|
|
20
|
-
return ts.factory.createStringLiteral("{}");
|
|
21
|
-
|
|
22
|
-
// PROPERTIES
|
|
23
|
-
const regular: IExpressionEntry<ts.Expression>[] = entries.filter(
|
|
24
|
-
(entry) => entry.key.isSoleLiteral(),
|
|
25
|
-
);
|
|
26
|
-
const dynamic: IExpressionEntry<ts.Expression>[] = entries.filter(
|
|
27
|
-
(entry) => !entry.key.isSoleLiteral(),
|
|
28
|
-
);
|
|
29
|
-
const expressions: ts.Expression[] = [
|
|
30
|
-
...stringify_regular_properties(regular, dynamic),
|
|
31
|
-
...(dynamic.length
|
|
32
|
-
? [
|
|
33
|
-
stringify_dynamic_properties(
|
|
34
|
-
dynamic,
|
|
35
|
-
regular.map((r) => r.key.getSoleLiteral()!),
|
|
36
|
-
),
|
|
37
|
-
]
|
|
38
|
-
: []),
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
// POP LAST COMMA, IF REQUIRED
|
|
42
|
-
const filtered: ts.Expression[] =
|
|
43
|
-
(regular.length &&
|
|
44
|
-
regular[regular.length - 1]!.meta.required &&
|
|
45
|
-
dynamic.length === 0) ||
|
|
46
|
-
(regular.length === 0 && dynamic.length)
|
|
47
|
-
? expressions
|
|
48
|
-
: [
|
|
49
|
-
ts.factory.createCallExpression(
|
|
50
|
-
importer.use("tail"),
|
|
51
|
-
undefined,
|
|
52
|
-
[TemplateFactory.generate(expressions)],
|
|
53
|
-
),
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
// RETURNS WITH OBJECT BRACKET
|
|
57
|
-
return TemplateFactory.generate([
|
|
58
|
-
ts.factory.createStringLiteral(`{`),
|
|
59
|
-
...filtered,
|
|
60
|
-
ts.factory.createStringLiteral(`}`),
|
|
61
|
-
]);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const array = (
|
|
65
|
-
input: ts.Expression,
|
|
66
|
-
arrow: ts.ArrowFunction,
|
|
67
|
-
): ts.Expression =>
|
|
68
|
-
TemplateFactory.generate([
|
|
69
|
-
ts.factory.createStringLiteral(`[`),
|
|
70
|
-
ts.factory.createCallExpression(
|
|
71
|
-
ts.factory.createPropertyAccessExpression(
|
|
72
|
-
ts.factory.createCallExpression(
|
|
73
|
-
IdentifierFactory.access(input)("map"),
|
|
74
|
-
undefined,
|
|
75
|
-
[arrow],
|
|
76
|
-
),
|
|
77
|
-
ts.factory.createIdentifier("join"),
|
|
78
|
-
),
|
|
79
|
-
undefined,
|
|
80
|
-
[ts.factory.createStringLiteral(`,`)],
|
|
81
|
-
),
|
|
82
|
-
ts.factory.createStringLiteral(`]`),
|
|
83
|
-
]);
|
|
84
|
-
|
|
85
|
-
export const tuple = (
|
|
86
|
-
children: ts.Expression[],
|
|
87
|
-
rest: ts.Expression | null,
|
|
88
|
-
): ts.Expression => {
|
|
89
|
-
if (children.length === 0) return ts.factory.createStringLiteral("[]");
|
|
90
|
-
if (
|
|
91
|
-
rest === null &&
|
|
92
|
-
children.every((child) => ts.isStringLiteral(child))
|
|
93
|
-
)
|
|
94
|
-
return ts.factory.createStringLiteral(
|
|
95
|
-
"[" +
|
|
96
|
-
children
|
|
97
|
-
.map((child) => (child as ts.StringLiteral).text)
|
|
98
|
-
.join(",") +
|
|
99
|
-
"]",
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const elements: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
|
|
103
|
-
children.forEach((child, i) => {
|
|
104
|
-
elements.push(child);
|
|
105
|
-
if (i !== children.length - 1)
|
|
106
|
-
elements.push(ts.factory.createStringLiteral(`,`));
|
|
107
|
-
});
|
|
108
|
-
if (rest !== null) elements.push(rest);
|
|
109
|
-
|
|
110
|
-
elements.push(ts.factory.createStringLiteral(`]`));
|
|
111
|
-
return TemplateFactory.generate(elements);
|
|
112
|
-
};
|
|
113
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
+
|
|
6
|
+
import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
|
|
7
|
+
import { stringify_regular_properties } from "../internal/stringify_regular_properties";
|
|
8
|
+
import { FunctionImporter } from "./FunctionImporeter";
|
|
9
|
+
import { IExpressionEntry } from "./IExpressionEntry";
|
|
10
|
+
|
|
11
|
+
export namespace StringifyJoiner {
|
|
12
|
+
export const object =
|
|
13
|
+
(importer: FunctionImporter) =>
|
|
14
|
+
(
|
|
15
|
+
_input: ts.Expression,
|
|
16
|
+
entries: IExpressionEntry<ts.Expression>[],
|
|
17
|
+
): ts.Expression => {
|
|
18
|
+
// CHECK AND SORT ENTRIES
|
|
19
|
+
if (entries.length === 0)
|
|
20
|
+
return ts.factory.createStringLiteral("{}");
|
|
21
|
+
|
|
22
|
+
// PROPERTIES
|
|
23
|
+
const regular: IExpressionEntry<ts.Expression>[] = entries.filter(
|
|
24
|
+
(entry) => entry.key.isSoleLiteral(),
|
|
25
|
+
);
|
|
26
|
+
const dynamic: IExpressionEntry<ts.Expression>[] = entries.filter(
|
|
27
|
+
(entry) => !entry.key.isSoleLiteral(),
|
|
28
|
+
);
|
|
29
|
+
const expressions: ts.Expression[] = [
|
|
30
|
+
...stringify_regular_properties(regular, dynamic),
|
|
31
|
+
...(dynamic.length
|
|
32
|
+
? [
|
|
33
|
+
stringify_dynamic_properties(
|
|
34
|
+
dynamic,
|
|
35
|
+
regular.map((r) => r.key.getSoleLiteral()!),
|
|
36
|
+
),
|
|
37
|
+
]
|
|
38
|
+
: []),
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
// POP LAST COMMA, IF REQUIRED
|
|
42
|
+
const filtered: ts.Expression[] =
|
|
43
|
+
(regular.length &&
|
|
44
|
+
regular[regular.length - 1]!.meta.required &&
|
|
45
|
+
dynamic.length === 0) ||
|
|
46
|
+
(regular.length === 0 && dynamic.length)
|
|
47
|
+
? expressions
|
|
48
|
+
: [
|
|
49
|
+
ts.factory.createCallExpression(
|
|
50
|
+
importer.use("tail"),
|
|
51
|
+
undefined,
|
|
52
|
+
[TemplateFactory.generate(expressions)],
|
|
53
|
+
),
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
// RETURNS WITH OBJECT BRACKET
|
|
57
|
+
return TemplateFactory.generate([
|
|
58
|
+
ts.factory.createStringLiteral(`{`),
|
|
59
|
+
...filtered,
|
|
60
|
+
ts.factory.createStringLiteral(`}`),
|
|
61
|
+
]);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const array = (
|
|
65
|
+
input: ts.Expression,
|
|
66
|
+
arrow: ts.ArrowFunction,
|
|
67
|
+
): ts.Expression =>
|
|
68
|
+
TemplateFactory.generate([
|
|
69
|
+
ts.factory.createStringLiteral(`[`),
|
|
70
|
+
ts.factory.createCallExpression(
|
|
71
|
+
ts.factory.createPropertyAccessExpression(
|
|
72
|
+
ts.factory.createCallExpression(
|
|
73
|
+
IdentifierFactory.access(input)("map"),
|
|
74
|
+
undefined,
|
|
75
|
+
[arrow],
|
|
76
|
+
),
|
|
77
|
+
ts.factory.createIdentifier("join"),
|
|
78
|
+
),
|
|
79
|
+
undefined,
|
|
80
|
+
[ts.factory.createStringLiteral(`,`)],
|
|
81
|
+
),
|
|
82
|
+
ts.factory.createStringLiteral(`]`),
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
export const tuple = (
|
|
86
|
+
children: ts.Expression[],
|
|
87
|
+
rest: ts.Expression | null,
|
|
88
|
+
): ts.Expression => {
|
|
89
|
+
if (children.length === 0) return ts.factory.createStringLiteral("[]");
|
|
90
|
+
if (
|
|
91
|
+
rest === null &&
|
|
92
|
+
children.every((child) => ts.isStringLiteral(child))
|
|
93
|
+
)
|
|
94
|
+
return ts.factory.createStringLiteral(
|
|
95
|
+
"[" +
|
|
96
|
+
children
|
|
97
|
+
.map((child) => (child as ts.StringLiteral).text)
|
|
98
|
+
.join(",") +
|
|
99
|
+
"]",
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const elements: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
|
|
103
|
+
children.forEach((child, i) => {
|
|
104
|
+
elements.push(child);
|
|
105
|
+
if (i !== children.length - 1)
|
|
106
|
+
elements.push(ts.factory.createStringLiteral(`,`));
|
|
107
|
+
});
|
|
108
|
+
if (rest !== null) elements.push(rest);
|
|
109
|
+
|
|
110
|
+
elements.push(ts.factory.createStringLiteral(`]`));
|
|
111
|
+
return TemplateFactory.generate(elements);
|
|
112
|
+
};
|
|
113
|
+
}
|