typia 3.5.0-dev.20221222 → 3.5.0-dev.20230124
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 +5 -2
- package/lib/executable/internal/TypiaSetupWizard.d.ts +6 -2
- package/lib/executable/internal/TypiaSetupWizard.js +23 -22
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/lib/executable/typia.js +11 -10
- package/lib/executable/typia.js.map +1 -1
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +20 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +2 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.js +7 -4
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +3 -3
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +2 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +5 -4
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
- package/lib/messages/IProtocolMap.d.ts +5 -0
- package/lib/messages/IProtocolMap.js +3 -0
- package/lib/messages/IProtocolMap.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +2 -1
- package/lib/metadata/Metadata.d.ts +1 -0
- package/lib/metadata/Metadata.js +145 -51
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +1 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +1 -0
- package/lib/programmers/CheckerProgrammer.js +147 -138
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/MessageProgrammer.js +7 -2
- package/lib/programmers/MessageProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +1 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/UnionExplorer.d.ts +23 -29
- package/lib/programmers/helpers/UnionExplorer.js +29 -41
- package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
- package/lib/programmers/internal/application_array.js +29 -27
- package/lib/programmers/internal/application_array.js.map +1 -1
- package/lib/programmers/internal/application_object.js +96 -31
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +28 -136
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/application_tuple.js +3 -2
- package/lib/programmers/internal/application_tuple.js.map +1 -1
- package/lib/programmers/internal/check_array.js +4 -32
- package/lib/programmers/internal/check_array.js.map +1 -1
- package/lib/programmers/internal/check_array_length.d.ts +1 -0
- package/lib/programmers/internal/check_array_length.js +47 -0
- package/lib/programmers/internal/check_array_length.js.map +1 -0
- package/lib/programmers/internal/check_union_array_like.d.ts +21 -0
- package/lib/programmers/internal/check_union_array_like.js +83 -0
- package/lib/programmers/internal/check_union_array_like.js.map +1 -0
- package/lib/programmers/internal/check_union_tuple.d.ts +1 -0
- package/lib/programmers/internal/check_union_tuple.js +11 -0
- package/lib/programmers/internal/check_union_tuple.js.map +1 -0
- package/lib/schemas/IJsonComponents.d.ts +4 -2
- package/lib/schemas/IJsonSchema.d.ts +2 -0
- package/package.json +4 -4
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/TypiaSetupWizard.ts +30 -21
- package/src/executable/typia.ts +48 -46
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +20 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +9 -3
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +17 -4
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +14 -5
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/messages/IProtocolMap.ts +5 -0
- package/src/messages/IProtocolProperty.ts +3 -1
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/Metadata.ts +64 -7
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +1 -1
- package/src/programmers/CheckerProgrammer.ts +252 -200
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/MessageProgrammer.ts +9 -2
- package/src/programmers/ValidateProgrammer.ts +1 -1
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +274 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +47 -45
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +153 -103
- package/src/programmers/internal/application_schema.ts +15 -68
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -25
- package/src/programmers/internal/check_array.ts +22 -44
- package/src/programmers/internal/check_array_length.ts +45 -0
- package/src/programmers/internal/check_dynamic_properties.ts +146 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_object.ts +42 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/check_union_array_like.ts +242 -0
- package/src/programmers/internal/check_union_tuple.ts +33 -0
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -24
- package/src/schemas/IJsonSchema.ts +2 -0
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -0
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
|
@@ -11,6 +11,7 @@ import { Escaper } from "../utils/Escaper";
|
|
|
11
11
|
import { MapUtil } from "../utils/MapUtil";
|
|
12
12
|
import { NameEncoder } from "../utils/NameEncoder";
|
|
13
13
|
|
|
14
|
+
import { IProtocolMap } from "../messages/IProtocolMap";
|
|
14
15
|
import { IProtocolMessage } from "../messages/IProtocolMessage";
|
|
15
16
|
|
|
16
17
|
export namespace MessageProgrammer {
|
|
@@ -53,7 +54,7 @@ export namespace MessageProgrammer {
|
|
|
53
54
|
TAB,
|
|
54
55
|
property.required ? "" : "optional ",
|
|
55
56
|
property.repeated ? "repeated " : "",
|
|
56
|
-
|
|
57
|
+
getTypeName(property.oneOf[0]!.type) + " ",
|
|
57
58
|
Escaper.variable(property.key)
|
|
58
59
|
? property.key
|
|
59
60
|
: `v${index + 1}`,
|
|
@@ -65,7 +66,7 @@ export namespace MessageProgrammer {
|
|
|
65
66
|
property.oneOf
|
|
66
67
|
.map(
|
|
67
68
|
(o, i) =>
|
|
68
|
-
`${TAB}${TAB}${
|
|
69
|
+
`${TAB}${TAB}${getTypeName(
|
|
69
70
|
o.type,
|
|
70
71
|
)} o${i} = ${index++};`,
|
|
71
72
|
)
|
|
@@ -105,6 +106,12 @@ export namespace MessageProgrammer {
|
|
|
105
106
|
if (i === accessors.length - 1) hierarchy.message = message;
|
|
106
107
|
});
|
|
107
108
|
};
|
|
109
|
+
|
|
110
|
+
function getTypeName(type: string | IProtocolMap): string {
|
|
111
|
+
return typeof type === "string"
|
|
112
|
+
? NameEncoder.encode(type)
|
|
113
|
+
: `map<${type.key}, ${getTypeName(type.value)}>`;
|
|
114
|
+
}
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
interface Hierarchy {
|
|
@@ -88,7 +88,7 @@ const combine =
|
|
|
88
88
|
(equals: boolean) =>
|
|
89
89
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
90
90
|
(explore: CheckerProgrammer.IExplore) => {
|
|
91
|
-
if (explore.tracable === false
|
|
91
|
+
if (explore.tracable === false)
|
|
92
92
|
return IsProgrammer.CONFIG({
|
|
93
93
|
object: validate_object(equals)(importer),
|
|
94
94
|
numeric: true,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Metadata } from "../../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, (atomic) => atomic === name);
|
|
12
|
-
|
|
13
|
-
export const template = (meta: Metadata): boolean =>
|
|
14
|
-
!ArrayUtil.has(meta.atomics, (type) => type === "string");
|
|
15
|
-
}
|
|
1
|
+
import { Metadata } from "../../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, (atomic) => atomic === name);
|
|
12
|
+
|
|
13
|
+
export const template = (meta: Metadata): boolean =>
|
|
14
|
+
!ArrayUtil.has(meta.atomics, (type) => type === "string");
|
|
15
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
|
|
6
|
-
export class FunctionImporter {
|
|
7
|
-
private readonly used_: Set<string> = new Set();
|
|
8
|
-
private sequence_: number = 0;
|
|
9
|
-
|
|
10
|
-
public empty(): boolean {
|
|
11
|
-
return this.used_.size === 0;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public use(name: string): ts.Identifier {
|
|
15
|
-
this.used_.add(name);
|
|
16
|
-
return ts.factory.createIdentifier("$" + name);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
|
|
20
|
-
return [...this.used_].map((name) =>
|
|
21
|
-
StatementFactory.constant(
|
|
22
|
-
"$" + name,
|
|
23
|
-
IdentifierFactory.join(modulo, name),
|
|
24
|
-
),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public increment(): number {
|
|
29
|
-
return ++this.sequence_;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
|
|
6
|
+
export class FunctionImporter {
|
|
7
|
+
private readonly used_: Set<string> = new Set();
|
|
8
|
+
private sequence_: number = 0;
|
|
9
|
+
|
|
10
|
+
public empty(): boolean {
|
|
11
|
+
return this.used_.size === 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public use(name: string): ts.Identifier {
|
|
15
|
+
this.used_.add(name);
|
|
16
|
+
return ts.factory.createIdentifier("$" + name);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
|
|
20
|
+
return [...this.used_].map((name) =>
|
|
21
|
+
StatementFactory.constant(
|
|
22
|
+
"$" + name,
|
|
23
|
+
IdentifierFactory.join(modulo, name),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public increment(): number {
|
|
29
|
+
return ++this.sequence_;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
export interface IExpressionEntry {
|
|
6
|
-
input: ts.Expression;
|
|
7
|
-
key: Metadata;
|
|
8
|
-
meta: Metadata;
|
|
9
|
-
expression: ts.Expression;
|
|
10
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
export interface IExpressionEntry {
|
|
6
|
+
input: ts.Expression;
|
|
7
|
+
key: Metadata;
|
|
8
|
+
meta: Metadata;
|
|
9
|
+
expression: ts.Expression;
|
|
10
|
+
}
|
|
@@ -1,111 +1,111 @@
|
|
|
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
|
-
(entries: IExpressionEntry[]): ts.Expression => {
|
|
15
|
-
// CHECK AND SORT ENTRIES
|
|
16
|
-
const regular: IExpressionEntry[] = entries.filter((entry) =>
|
|
17
|
-
entry.key.isSoleLiteral(),
|
|
18
|
-
);
|
|
19
|
-
const dynamic: IExpressionEntry[] = entries.filter(
|
|
20
|
-
(entry) => !entry.key.isSoleLiteral(),
|
|
21
|
-
);
|
|
22
|
-
if (regular.length === 0 && dynamic.length === 0)
|
|
23
|
-
return ts.factory.createStringLiteral("{}");
|
|
24
|
-
|
|
25
|
-
// PROPERTIES
|
|
26
|
-
const expressions: ts.Expression[] = [
|
|
27
|
-
...stringify_regular_properties(regular, dynamic),
|
|
28
|
-
...(dynamic.length
|
|
29
|
-
? [
|
|
30
|
-
stringify_dynamic_properties(
|
|
31
|
-
dynamic,
|
|
32
|
-
regular.map((r) => r.key.getSoleLiteral()!),
|
|
33
|
-
),
|
|
34
|
-
]
|
|
35
|
-
: []),
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
// POP LAST COMMA, IF REQUIRED
|
|
39
|
-
const filtered: ts.Expression[] =
|
|
40
|
-
(regular.length &&
|
|
41
|
-
regular[regular.length - 1]!.meta.required &&
|
|
42
|
-
dynamic.length === 0) ||
|
|
43
|
-
(regular.length === 0 && dynamic.length)
|
|
44
|
-
? expressions
|
|
45
|
-
: [
|
|
46
|
-
ts.factory.createCallExpression(
|
|
47
|
-
importer.use("tail"),
|
|
48
|
-
undefined,
|
|
49
|
-
[TemplateFactory.generate(expressions)],
|
|
50
|
-
),
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
// RETURNS WITH OBJECT BRACKET
|
|
54
|
-
return TemplateFactory.generate([
|
|
55
|
-
ts.factory.createStringLiteral(`{`),
|
|
56
|
-
...filtered,
|
|
57
|
-
ts.factory.createStringLiteral(`}`),
|
|
58
|
-
]);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export function array(
|
|
62
|
-
input: ts.Expression,
|
|
63
|
-
arrow: ts.ArrowFunction,
|
|
64
|
-
): ts.Expression {
|
|
65
|
-
return TemplateFactory.generate([
|
|
66
|
-
ts.factory.createStringLiteral(`[`),
|
|
67
|
-
ts.factory.createCallExpression(
|
|
68
|
-
ts.factory.createPropertyAccessExpression(
|
|
69
|
-
ts.factory.createCallExpression(
|
|
70
|
-
IdentifierFactory.join(input, "map"),
|
|
71
|
-
undefined,
|
|
72
|
-
[arrow],
|
|
73
|
-
),
|
|
74
|
-
ts.factory.createIdentifier("join"),
|
|
75
|
-
),
|
|
76
|
-
undefined,
|
|
77
|
-
[ts.factory.createStringLiteral(`,`)],
|
|
78
|
-
),
|
|
79
|
-
ts.factory.createStringLiteral(`]`),
|
|
80
|
-
]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function tuple(
|
|
84
|
-
children: ts.Expression[],
|
|
85
|
-
rest: ts.Expression | null,
|
|
86
|
-
): ts.Expression {
|
|
87
|
-
if (children.length === 0) return ts.factory.createStringLiteral("[]");
|
|
88
|
-
if (
|
|
89
|
-
rest === null &&
|
|
90
|
-
children.every((child) => ts.isStringLiteral(child))
|
|
91
|
-
)
|
|
92
|
-
return ts.factory.createStringLiteral(
|
|
93
|
-
"[" +
|
|
94
|
-
children
|
|
95
|
-
.map((child) => (child as ts.StringLiteral).text)
|
|
96
|
-
.join(",") +
|
|
97
|
-
"]",
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const elements: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
|
|
101
|
-
children.forEach((child, i) => {
|
|
102
|
-
elements.push(child);
|
|
103
|
-
if (i !== children.length - 1)
|
|
104
|
-
elements.push(ts.factory.createStringLiteral(`,`));
|
|
105
|
-
});
|
|
106
|
-
if (rest !== null) elements.push(rest);
|
|
107
|
-
|
|
108
|
-
elements.push(ts.factory.createStringLiteral(`]`));
|
|
109
|
-
return TemplateFactory.generate(elements);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
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
|
+
(entries: IExpressionEntry[]): ts.Expression => {
|
|
15
|
+
// CHECK AND SORT ENTRIES
|
|
16
|
+
const regular: IExpressionEntry[] = entries.filter((entry) =>
|
|
17
|
+
entry.key.isSoleLiteral(),
|
|
18
|
+
);
|
|
19
|
+
const dynamic: IExpressionEntry[] = entries.filter(
|
|
20
|
+
(entry) => !entry.key.isSoleLiteral(),
|
|
21
|
+
);
|
|
22
|
+
if (regular.length === 0 && dynamic.length === 0)
|
|
23
|
+
return ts.factory.createStringLiteral("{}");
|
|
24
|
+
|
|
25
|
+
// PROPERTIES
|
|
26
|
+
const expressions: ts.Expression[] = [
|
|
27
|
+
...stringify_regular_properties(regular, dynamic),
|
|
28
|
+
...(dynamic.length
|
|
29
|
+
? [
|
|
30
|
+
stringify_dynamic_properties(
|
|
31
|
+
dynamic,
|
|
32
|
+
regular.map((r) => r.key.getSoleLiteral()!),
|
|
33
|
+
),
|
|
34
|
+
]
|
|
35
|
+
: []),
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
// POP LAST COMMA, IF REQUIRED
|
|
39
|
+
const filtered: ts.Expression[] =
|
|
40
|
+
(regular.length &&
|
|
41
|
+
regular[regular.length - 1]!.meta.required &&
|
|
42
|
+
dynamic.length === 0) ||
|
|
43
|
+
(regular.length === 0 && dynamic.length)
|
|
44
|
+
? expressions
|
|
45
|
+
: [
|
|
46
|
+
ts.factory.createCallExpression(
|
|
47
|
+
importer.use("tail"),
|
|
48
|
+
undefined,
|
|
49
|
+
[TemplateFactory.generate(expressions)],
|
|
50
|
+
),
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
// RETURNS WITH OBJECT BRACKET
|
|
54
|
+
return TemplateFactory.generate([
|
|
55
|
+
ts.factory.createStringLiteral(`{`),
|
|
56
|
+
...filtered,
|
|
57
|
+
ts.factory.createStringLiteral(`}`),
|
|
58
|
+
]);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export function array(
|
|
62
|
+
input: ts.Expression,
|
|
63
|
+
arrow: ts.ArrowFunction,
|
|
64
|
+
): ts.Expression {
|
|
65
|
+
return TemplateFactory.generate([
|
|
66
|
+
ts.factory.createStringLiteral(`[`),
|
|
67
|
+
ts.factory.createCallExpression(
|
|
68
|
+
ts.factory.createPropertyAccessExpression(
|
|
69
|
+
ts.factory.createCallExpression(
|
|
70
|
+
IdentifierFactory.join(input, "map"),
|
|
71
|
+
undefined,
|
|
72
|
+
[arrow],
|
|
73
|
+
),
|
|
74
|
+
ts.factory.createIdentifier("join"),
|
|
75
|
+
),
|
|
76
|
+
undefined,
|
|
77
|
+
[ts.factory.createStringLiteral(`,`)],
|
|
78
|
+
),
|
|
79
|
+
ts.factory.createStringLiteral(`]`),
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function tuple(
|
|
84
|
+
children: ts.Expression[],
|
|
85
|
+
rest: ts.Expression | null,
|
|
86
|
+
): ts.Expression {
|
|
87
|
+
if (children.length === 0) return ts.factory.createStringLiteral("[]");
|
|
88
|
+
if (
|
|
89
|
+
rest === null &&
|
|
90
|
+
children.every((child) => ts.isStringLiteral(child))
|
|
91
|
+
)
|
|
92
|
+
return ts.factory.createStringLiteral(
|
|
93
|
+
"[" +
|
|
94
|
+
children
|
|
95
|
+
.map((child) => (child as ts.StringLiteral).text)
|
|
96
|
+
.join(",") +
|
|
97
|
+
"]",
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const elements: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
|
|
101
|
+
children.forEach((child, i) => {
|
|
102
|
+
elements.push(child);
|
|
103
|
+
if (i !== children.length - 1)
|
|
104
|
+
elements.push(ts.factory.createStringLiteral(`,`));
|
|
105
|
+
});
|
|
106
|
+
if (rest !== null) elements.push(rest);
|
|
107
|
+
|
|
108
|
+
elements.push(ts.factory.createStringLiteral(`]`));
|
|
109
|
+
return TemplateFactory.generate(elements);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
export namespace StringifyPredicator {
|
|
4
|
-
export function require_escape(value: string): boolean {
|
|
5
|
-
return value
|
|
6
|
-
.split("")
|
|
7
|
-
.some((ch) => ESCAPED.some((escaped) => escaped === ch));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function undefindable(meta: Metadata): boolean {
|
|
11
|
-
return (
|
|
12
|
-
meta.required === false ||
|
|
13
|
-
(meta.resolved !== null && meta.resolved.required === false)
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
|
|
18
|
-
}
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
export namespace StringifyPredicator {
|
|
4
|
+
export function require_escape(value: string): boolean {
|
|
5
|
+
return value
|
|
6
|
+
.split("")
|
|
7
|
+
.some((ch) => ESCAPED.some((escaped) => escaped === ch));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function undefindable(meta: Metadata): boolean {
|
|
11
|
+
return (
|
|
12
|
+
meta.required === false ||
|
|
13
|
+
(meta.resolved !== null && meta.resolved.required === false)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
|
|
18
|
+
}
|