typia 3.5.0-dev.20221219 → 3.5.0-dev.20221222
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 +58 -16
- package/lib/executable/internal/TypiaSetupWizard.js +2 -1
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -77
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/MetadataTagFactory.js +4 -1
- package/lib/factories/MetadataTagFactory.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +0 -1
- package/lib/factories/ProtocolFactory.js +0 -6
- package/lib/factories/ProtocolFactory.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_object.js +4 -2
- package/lib/factories/internal/metadata/iterate_metadata_object.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_main.js +2 -3
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -1
- package/lib/functional/$number.js +2 -9
- package/lib/functional/$number.js.map +1 -1
- package/lib/programmers/AssertParseProgrammer.js +12 -1
- package/lib/programmers/AssertParseProgrammer.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +2 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/AssertStringifyProgrammer.js +13 -2
- package/lib/programmers/AssertStringifyProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +6 -0
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/IsParseProgrammer.js +12 -1
- package/lib/programmers/IsParseProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.js +5 -2
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/IsStringifyProgrammer.js +13 -2
- package/lib/programmers/IsStringifyProgrammer.js.map +1 -1
- package/lib/programmers/MessageProgrammer.js +11 -6
- package/lib/programmers/MessageProgrammer.js.map +1 -1
- package/lib/programmers/StringifyProgrammer.js +6 -1
- package/lib/programmers/StringifyProgrammer.js.map +1 -1
- package/lib/programmers/ValidateParseProgrammer.js +12 -1
- package/lib/programmers/ValidateParseProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +2 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/ValidateStringifyProgrammer.js +13 -2
- package/lib/programmers/ValidateStringifyProgrammer.js.map +1 -1
- package/lib/programmers/helpers/OptionPredicator.d.ts +2 -1
- package/lib/programmers/helpers/OptionPredicator.js +8 -6
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/internal/application_object.js +9 -9
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +12 -6
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_bigint.d.ts +3 -0
- package/lib/programmers/internal/check_bigint.js +97 -0
- package/lib/programmers/internal/check_bigint.js.map +1 -0
- package/lib/programmers/internal/check_number.js +21 -23
- package/lib/programmers/internal/check_number.js.map +1 -1
- package/lib/schemas/IJsonSchema.d.ts +3 -5
- package/lib/transformers/ITransformOptions.d.ts +43 -2
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +5 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/stringifiers/StringifyTransformer.js +12 -1
- package/lib/transformers/features/stringifiers/StringifyTransformer.js.map +1 -1
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +3 -2
- 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 +7 -3
- package/src/executable/typia.ts +46 -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/MetadataCollection.ts +2 -43
- package/src/factories/MetadataTagFactory.ts +5 -1
- package/src/factories/ProtocolFactory.ts +0 -5
- 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/metadata/iterate_metadata_object.ts +6 -3
- package/src/factories/internal/protocols/iterate_protocol_main.ts +2 -3
- package/src/factories/internal/protocols/iterate_protocol_map.ts +3 -5
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +1 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +3 -6
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +3 -6
- 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/$number.ts +2 -9
- 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/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/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/AssertParseProgrammer.ts +11 -1
- package/src/programmers/AssertProgrammer.ts +3 -2
- package/src/programmers/AssertStringifyProgrammer.ts +22 -2
- package/src/programmers/CheckerProgrammer.ts +6 -0
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +11 -1
- package/src/programmers/IsProgrammer.ts +5 -2
- package/src/programmers/IsStringifyProgrammer.ts +22 -2
- package/src/programmers/MessageProgrammer.ts +12 -6
- package/src/programmers/StringifyProgrammer.ts +7 -1
- package/src/programmers/ValidateParseProgrammer.ts +11 -1
- package/src/programmers/ValidateProgrammer.ts +2 -1
- package/src/programmers/ValidateStringifyProgrammer.ts +22 -2
- 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/OptionPredicator.ts +7 -10
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +437 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +45 -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.ts +1 -1
- 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 +103 -103
- package/src/programmers/internal/application_schema.ts +15 -5
- 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 +25 -25
- package/src/programmers/internal/check_array.ts +44 -44
- package/src/programmers/internal/check_bigint.ts +85 -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_number.ts +45 -51
- 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/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 +24 -24
- package/src/schemas/IJsonSchema.ts +4 -6
- 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/ITransformOptions.ts +45 -2
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +6 -3
- 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/StringifyTransformer.ts +11 -1
- 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/NameEncoder.ts +32 -0
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.d.ts +0 -5
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.js +0 -29
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.js.map +0 -1
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +0 -41
|
@@ -20,7 +20,17 @@ export namespace IsParseProgrammer {
|
|
|
20
20
|
ts.factory.createBlock([
|
|
21
21
|
StatementFactory.constant(
|
|
22
22
|
"is",
|
|
23
|
-
IsProgrammer.generate(
|
|
23
|
+
IsProgrammer.generate(
|
|
24
|
+
{
|
|
25
|
+
...project,
|
|
26
|
+
options: {
|
|
27
|
+
...project.options,
|
|
28
|
+
functional: false,
|
|
29
|
+
numeric: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
modulo,
|
|
33
|
+
)(type),
|
|
24
34
|
),
|
|
25
35
|
ts.factory.createExpressionStatement(
|
|
26
36
|
ts.factory.createBinaryExpression(
|
|
@@ -11,6 +11,7 @@ import { IProject } from "../transformers/IProject";
|
|
|
11
11
|
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
12
12
|
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
13
13
|
import { IExpressionEntry } from "./helpers/IExpressionEntry";
|
|
14
|
+
import { OptionPredicator } from "./helpers/OptionPredicator";
|
|
14
15
|
import { check_object } from "./internal/check_object";
|
|
15
16
|
import { feature_object_entries } from "./internal/feature_object_entries";
|
|
16
17
|
|
|
@@ -23,7 +24,9 @@ export namespace IsProgrammer {
|
|
|
23
24
|
trace: false,
|
|
24
25
|
path: false,
|
|
25
26
|
equals: !!options?.object,
|
|
26
|
-
numeric:
|
|
27
|
+
numeric: OptionPredicator.numeric({
|
|
28
|
+
numeric: options?.numeric,
|
|
29
|
+
}),
|
|
27
30
|
combiner: () => (type: "and" | "or") => {
|
|
28
31
|
const initial: ts.TrueLiteral | ts.FalseLiteral =
|
|
29
32
|
type === "and"
|
|
@@ -90,7 +93,7 @@ export namespace IsProgrammer {
|
|
|
90
93
|
positive: ts.factory.createTrue(),
|
|
91
94
|
superfluous: () => ts.factory.createFalse(),
|
|
92
95
|
}),
|
|
93
|
-
numeric:
|
|
96
|
+
numeric: OptionPredicator.numeric(project.options),
|
|
94
97
|
});
|
|
95
98
|
config.trace = equals;
|
|
96
99
|
|
|
@@ -21,11 +21,31 @@ export namespace IsStringifyProgrammer {
|
|
|
21
21
|
ts.factory.createBlock([
|
|
22
22
|
StatementFactory.constant(
|
|
23
23
|
"is",
|
|
24
|
-
IsProgrammer.generate(
|
|
24
|
+
IsProgrammer.generate(
|
|
25
|
+
{
|
|
26
|
+
...project,
|
|
27
|
+
options: {
|
|
28
|
+
...project.options,
|
|
29
|
+
functional: false,
|
|
30
|
+
numeric: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
modulo,
|
|
34
|
+
)(type),
|
|
25
35
|
),
|
|
26
36
|
StatementFactory.constant(
|
|
27
37
|
"stringify",
|
|
28
|
-
StringifyProgrammer.generate(
|
|
38
|
+
StringifyProgrammer.generate(
|
|
39
|
+
{
|
|
40
|
+
...project,
|
|
41
|
+
options: {
|
|
42
|
+
...project.options,
|
|
43
|
+
functional: false,
|
|
44
|
+
numeric: false,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
modulo,
|
|
48
|
+
)(type),
|
|
29
49
|
),
|
|
30
50
|
ts.factory.createReturnStatement(
|
|
31
51
|
ts.factory.createConditionalExpression(
|
|
@@ -7,7 +7,9 @@ import { Metadata } from "../metadata/Metadata";
|
|
|
7
7
|
|
|
8
8
|
import { IProject } from "../transformers/IProject";
|
|
9
9
|
|
|
10
|
+
import { Escaper } from "../utils/Escaper";
|
|
10
11
|
import { MapUtil } from "../utils/MapUtil";
|
|
12
|
+
import { NameEncoder } from "../utils/NameEncoder";
|
|
11
13
|
|
|
12
14
|
import { IProtocolMessage } from "../messages/IProtocolMessage";
|
|
13
15
|
|
|
@@ -16,7 +18,7 @@ export namespace MessageProgrammer {
|
|
|
16
18
|
({ checker }: IProject) =>
|
|
17
19
|
(type: ts.Type) => {
|
|
18
20
|
// PARSE TARGET TYPE
|
|
19
|
-
const collection: MetadataCollection =
|
|
21
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
20
22
|
const metadata: Metadata =
|
|
21
23
|
ProtocolFactory.metadata(checker)(collection)(type);
|
|
22
24
|
|
|
@@ -42,7 +44,7 @@ export namespace MessageProgrammer {
|
|
|
42
44
|
const { key, message, children } = hierarchy;
|
|
43
45
|
let index: number = 1;
|
|
44
46
|
|
|
45
|
-
const elements: string[] = [`message ${key} {`];
|
|
47
|
+
const elements: string[] = [`message ${NameEncoder.encode(key)} {`];
|
|
46
48
|
if (message !== null)
|
|
47
49
|
elements.push(
|
|
48
50
|
...message.properties.map((property) => {
|
|
@@ -51,9 +53,11 @@ export namespace MessageProgrammer {
|
|
|
51
53
|
TAB,
|
|
52
54
|
property.required ? "" : "optional ",
|
|
53
55
|
property.repeated ? "repeated " : "",
|
|
54
|
-
property.oneOf[0]!.type + " ",
|
|
55
|
-
property.key
|
|
56
|
-
|
|
56
|
+
NameEncoder.encode(property.oneOf[0]!.type) + " ",
|
|
57
|
+
Escaper.variable(property.key)
|
|
58
|
+
? property.key
|
|
59
|
+
: `v${index + 1}`,
|
|
60
|
+
" = ",
|
|
57
61
|
`${index++};`,
|
|
58
62
|
].join("");
|
|
59
63
|
return (
|
|
@@ -61,7 +65,9 @@ export namespace MessageProgrammer {
|
|
|
61
65
|
property.oneOf
|
|
62
66
|
.map(
|
|
63
67
|
(o, i) =>
|
|
64
|
-
`${TAB}${TAB}${
|
|
68
|
+
`${TAB}${TAB}${NameEncoder.encode(
|
|
69
|
+
o.type,
|
|
70
|
+
)} o${i} = ${index++};`,
|
|
65
71
|
)
|
|
66
72
|
.join("\n") +
|
|
67
73
|
`\n${TAB}}`
|
|
@@ -498,7 +498,7 @@ export namespace StringifyProgrammer {
|
|
|
498
498
|
);
|
|
499
499
|
else if (
|
|
500
500
|
type === "number" &&
|
|
501
|
-
OptionPredicator.numeric(project.options
|
|
501
|
+
OptionPredicator.numeric(project.options)
|
|
502
502
|
)
|
|
503
503
|
input = ts.factory.createCallExpression(
|
|
504
504
|
importer.use("number"),
|
|
@@ -700,6 +700,10 @@ export namespace StringifyProgrammer {
|
|
|
700
700
|
{
|
|
701
701
|
resolve: true,
|
|
702
702
|
constant: true,
|
|
703
|
+
validate: (meta) => {
|
|
704
|
+
if (meta.atomics.find((str) => str === "bigint"))
|
|
705
|
+
throw new Error(NO_BIGINT);
|
|
706
|
+
},
|
|
703
707
|
},
|
|
704
708
|
);
|
|
705
709
|
return [collection, meta];
|
|
@@ -754,3 +758,5 @@ interface IUnion {
|
|
|
754
758
|
is: () => ts.Expression;
|
|
755
759
|
value: () => ts.Expression;
|
|
756
760
|
}
|
|
761
|
+
|
|
762
|
+
const NO_BIGINT = "Error on typia.stringify(): does not allow bigint type.";
|
|
@@ -20,7 +20,17 @@ export namespace ValidateParseProgrammer {
|
|
|
20
20
|
ts.factory.createBlock([
|
|
21
21
|
StatementFactory.constant(
|
|
22
22
|
"validate",
|
|
23
|
-
ValidateProgrammer.generate(
|
|
23
|
+
ValidateProgrammer.generate(
|
|
24
|
+
{
|
|
25
|
+
...project,
|
|
26
|
+
options: {
|
|
27
|
+
...project.options,
|
|
28
|
+
functional: false,
|
|
29
|
+
numeric: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
modulo,
|
|
33
|
+
)(type),
|
|
24
34
|
),
|
|
25
35
|
ts.factory.createExpressionStatement(
|
|
26
36
|
ts.factory.createBinaryExpression(
|
|
@@ -8,6 +8,7 @@ import { IProject } from "../transformers/IProject";
|
|
|
8
8
|
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
9
9
|
import { IsProgrammer } from "./IsProgrammer";
|
|
10
10
|
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
11
|
+
import { OptionPredicator } from "./helpers/OptionPredicator";
|
|
11
12
|
import { check_everything } from "./internal/check_everything";
|
|
12
13
|
import { check_object } from "./internal/check_object";
|
|
13
14
|
|
|
@@ -27,7 +28,7 @@ export namespace ValidateProgrammer {
|
|
|
27
28
|
unioners: "$vu",
|
|
28
29
|
path: true,
|
|
29
30
|
trace: true,
|
|
30
|
-
numeric:
|
|
31
|
+
numeric: OptionPredicator.numeric(project.options),
|
|
31
32
|
equals,
|
|
32
33
|
combiner: combine(equals)(importer),
|
|
33
34
|
joiner: joiner(equals)(importer),
|
|
@@ -21,11 +21,31 @@ export namespace ValidateStringifyProgrammer {
|
|
|
21
21
|
ts.factory.createBlock([
|
|
22
22
|
StatementFactory.constant(
|
|
23
23
|
"validate",
|
|
24
|
-
ValidateProgrammer.generate(
|
|
24
|
+
ValidateProgrammer.generate(
|
|
25
|
+
{
|
|
26
|
+
...project,
|
|
27
|
+
options: {
|
|
28
|
+
...project.options,
|
|
29
|
+
functional: false,
|
|
30
|
+
numeric: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
modulo,
|
|
34
|
+
)(type),
|
|
25
35
|
),
|
|
26
36
|
StatementFactory.constant(
|
|
27
37
|
"stringify",
|
|
28
|
-
StringifyProgrammer.generate(
|
|
38
|
+
StringifyProgrammer.generate(
|
|
39
|
+
{
|
|
40
|
+
...project,
|
|
41
|
+
options: {
|
|
42
|
+
...project.options,
|
|
43
|
+
functional: false,
|
|
44
|
+
numeric: false,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
modulo,
|
|
48
|
+
)(type),
|
|
29
49
|
),
|
|
30
50
|
StatementFactory.constant(
|
|
31
51
|
"output",
|
|
@@ -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,18 +1,15 @@
|
|
|
1
1
|
import { ITransformOptions } from "../../transformers/ITransformOptions";
|
|
2
2
|
|
|
3
3
|
export namespace OptionPredicator {
|
|
4
|
+
export function numeric(options: ITransformOptions): boolean {
|
|
5
|
+
return finite(options) || options.numeric === true;
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
export function functional(options: ITransformOptions): boolean {
|
|
5
|
-
return options.functional
|
|
9
|
+
return options.functional === true;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
|
-
export function
|
|
9
|
-
options
|
|
10
|
-
from: "checker" | "stringify",
|
|
11
|
-
): boolean {
|
|
12
|
-
return (
|
|
13
|
-
options.numeric === undefined ||
|
|
14
|
-
options.numeric === true ||
|
|
15
|
-
options.numeric === from
|
|
16
|
-
);
|
|
12
|
+
export function finite(options: ITransformOptions): boolean {
|
|
13
|
+
return options.finite === true;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
@@ -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
|
+
}
|