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
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace ExpressionFactory {
|
|
4
|
-
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
-
return ts.factory.createStrictInequality(
|
|
6
|
-
ts.factory.createIdentifier("undefined"),
|
|
7
|
-
input,
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
-
return ts.factory.createCallExpression(
|
|
13
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
-
undefined,
|
|
15
|
-
[input],
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isObject(
|
|
20
|
-
input: ts.Expression,
|
|
21
|
-
options: {
|
|
22
|
-
checkNull: boolean;
|
|
23
|
-
checkArray: boolean;
|
|
24
|
-
},
|
|
25
|
-
): ts.Expression {
|
|
26
|
-
const conditions: ts.Expression[] = [
|
|
27
|
-
ts.factory.createStrictEquality(
|
|
28
|
-
ts.factory.createStringLiteral("object"),
|
|
29
|
-
ts.factory.createTypeOfExpression(input),
|
|
30
|
-
),
|
|
31
|
-
];
|
|
32
|
-
if (options.checkNull === true)
|
|
33
|
-
conditions.push(
|
|
34
|
-
ts.factory.createStrictInequality(
|
|
35
|
-
ts.factory.createNull(),
|
|
36
|
-
input,
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
if (options.checkArray === true)
|
|
40
|
-
conditions.push(
|
|
41
|
-
ts.factory.createStrictEquality(
|
|
42
|
-
ts.factory.createFalse(),
|
|
43
|
-
ts.factory.createCallExpression(
|
|
44
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
-
undefined,
|
|
46
|
-
[input],
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return conditions.length === 1
|
|
52
|
-
? conditions[0]!
|
|
53
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function isInstanceOf(
|
|
57
|
-
input: ts.Expression,
|
|
58
|
-
type: string,
|
|
59
|
-
): ts.Expression {
|
|
60
|
-
return ts.factory.createBinaryExpression(
|
|
61
|
-
input,
|
|
62
|
-
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
-
ts.factory.createIdentifier(type),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace ExpressionFactory {
|
|
4
|
+
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
+
return ts.factory.createStrictInequality(
|
|
6
|
+
ts.factory.createIdentifier("undefined"),
|
|
7
|
+
input,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
+
return ts.factory.createCallExpression(
|
|
13
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
+
undefined,
|
|
15
|
+
[input],
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isObject(
|
|
20
|
+
input: ts.Expression,
|
|
21
|
+
options: {
|
|
22
|
+
checkNull: boolean;
|
|
23
|
+
checkArray: boolean;
|
|
24
|
+
},
|
|
25
|
+
): ts.Expression {
|
|
26
|
+
const conditions: ts.Expression[] = [
|
|
27
|
+
ts.factory.createStrictEquality(
|
|
28
|
+
ts.factory.createStringLiteral("object"),
|
|
29
|
+
ts.factory.createTypeOfExpression(input),
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
if (options.checkNull === true)
|
|
33
|
+
conditions.push(
|
|
34
|
+
ts.factory.createStrictInequality(
|
|
35
|
+
ts.factory.createNull(),
|
|
36
|
+
input,
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
if (options.checkArray === true)
|
|
40
|
+
conditions.push(
|
|
41
|
+
ts.factory.createStrictEquality(
|
|
42
|
+
ts.factory.createFalse(),
|
|
43
|
+
ts.factory.createCallExpression(
|
|
44
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
+
undefined,
|
|
46
|
+
[input],
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return conditions.length === 1
|
|
52
|
+
? conditions[0]!
|
|
53
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isInstanceOf(
|
|
57
|
+
input: ts.Expression,
|
|
58
|
+
type: string,
|
|
59
|
+
): ts.Expression {
|
|
60
|
+
return ts.factory.createBinaryExpression(
|
|
61
|
+
input,
|
|
62
|
+
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
+
ts.factory.createIdentifier(type),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Escaper } from "../utils/Escaper";
|
|
4
|
-
|
|
5
|
-
export namespace IdentifierFactory {
|
|
6
|
-
export function generate(name: string) {
|
|
7
|
-
return Escaper.variable(name)
|
|
8
|
-
? ts.factory.createIdentifier(name)
|
|
9
|
-
: ts.factory.createStringLiteral(name);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function join(prefix: ts.Expression, name: string) {
|
|
13
|
-
const postfix = generate(name);
|
|
14
|
-
return ts.isStringLiteral(postfix)
|
|
15
|
-
? ts.factory.createElementAccessExpression(prefix, postfix)
|
|
16
|
-
: ts.factory.createPropertyAccessExpression(prefix, postfix);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function postfix(str: string): string {
|
|
20
|
-
return Escaper.variable(str)
|
|
21
|
-
? `".${str}"`
|
|
22
|
-
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function parameter(
|
|
26
|
-
name: string | ts.BindingName,
|
|
27
|
-
init?: ts.Expression,
|
|
28
|
-
) {
|
|
29
|
-
if (ts.version >= "4.8")
|
|
30
|
-
return ts.factory.createParameterDeclaration(
|
|
31
|
-
undefined,
|
|
32
|
-
undefined,
|
|
33
|
-
name,
|
|
34
|
-
undefined,
|
|
35
|
-
undefined,
|
|
36
|
-
init,
|
|
37
|
-
);
|
|
38
|
-
// eslint-disable-next-line
|
|
39
|
-
return ts.factory.createParameterDeclaration(
|
|
40
|
-
undefined,
|
|
41
|
-
undefined,
|
|
42
|
-
undefined,
|
|
43
|
-
name,
|
|
44
|
-
undefined,
|
|
45
|
-
undefined,
|
|
46
|
-
init,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// export function property(
|
|
51
|
-
// name: string | ts.PropertyName,
|
|
52
|
-
// value: ts.Expression,
|
|
53
|
-
// ): ts.PropertyDeclaration {
|
|
54
|
-
// if (ts.version >= "4.8")
|
|
55
|
-
// return ts.factory.createPropertyDeclaration(
|
|
56
|
-
// undefined,
|
|
57
|
-
// name,
|
|
58
|
-
// undefined,
|
|
59
|
-
// undefined,
|
|
60
|
-
// value,
|
|
61
|
-
// );
|
|
62
|
-
// // eslint-disable-next-line
|
|
63
|
-
// return ts.factory.createPropertyDeclaration(
|
|
64
|
-
// undefined,
|
|
65
|
-
// undefined,
|
|
66
|
-
// name,
|
|
67
|
-
// undefined,
|
|
68
|
-
// undefined,
|
|
69
|
-
// value,
|
|
70
|
-
// );
|
|
71
|
-
// }
|
|
72
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Escaper } from "../utils/Escaper";
|
|
4
|
+
|
|
5
|
+
export namespace IdentifierFactory {
|
|
6
|
+
export function generate(name: string) {
|
|
7
|
+
return Escaper.variable(name)
|
|
8
|
+
? ts.factory.createIdentifier(name)
|
|
9
|
+
: ts.factory.createStringLiteral(name);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function join(prefix: ts.Expression, name: string) {
|
|
13
|
+
const postfix = generate(name);
|
|
14
|
+
return ts.isStringLiteral(postfix)
|
|
15
|
+
? ts.factory.createElementAccessExpression(prefix, postfix)
|
|
16
|
+
: ts.factory.createPropertyAccessExpression(prefix, postfix);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function postfix(str: string): string {
|
|
20
|
+
return Escaper.variable(str)
|
|
21
|
+
? `".${str}"`
|
|
22
|
+
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parameter(
|
|
26
|
+
name: string | ts.BindingName,
|
|
27
|
+
init?: ts.Expression,
|
|
28
|
+
) {
|
|
29
|
+
if (ts.version >= "4.8")
|
|
30
|
+
return ts.factory.createParameterDeclaration(
|
|
31
|
+
undefined,
|
|
32
|
+
undefined,
|
|
33
|
+
name,
|
|
34
|
+
undefined,
|
|
35
|
+
undefined,
|
|
36
|
+
init,
|
|
37
|
+
);
|
|
38
|
+
// eslint-disable-next-line
|
|
39
|
+
return ts.factory.createParameterDeclaration(
|
|
40
|
+
undefined,
|
|
41
|
+
undefined,
|
|
42
|
+
undefined,
|
|
43
|
+
name,
|
|
44
|
+
undefined,
|
|
45
|
+
undefined,
|
|
46
|
+
init,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// export function property(
|
|
51
|
+
// name: string | ts.PropertyName,
|
|
52
|
+
// value: ts.Expression,
|
|
53
|
+
// ): ts.PropertyDeclaration {
|
|
54
|
+
// if (ts.version >= "4.8")
|
|
55
|
+
// return ts.factory.createPropertyDeclaration(
|
|
56
|
+
// undefined,
|
|
57
|
+
// name,
|
|
58
|
+
// undefined,
|
|
59
|
+
// undefined,
|
|
60
|
+
// value,
|
|
61
|
+
// );
|
|
62
|
+
// // eslint-disable-next-line
|
|
63
|
+
// return ts.factory.createPropertyDeclaration(
|
|
64
|
+
// undefined,
|
|
65
|
+
// undefined,
|
|
66
|
+
// name,
|
|
67
|
+
// undefined,
|
|
68
|
+
// undefined,
|
|
69
|
+
// value,
|
|
70
|
+
// );
|
|
71
|
+
// }
|
|
72
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "./IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
export namespace LiteralFactory {
|
|
6
|
-
export function generate(input: any): ts.Expression {
|
|
7
|
-
if (input === null) return ts.factory.createNull();
|
|
8
|
-
else if (ts.isIdentifier(input)) return input;
|
|
9
|
-
else if (input instanceof Array) return generate_array(input);
|
|
10
|
-
else if (typeof input === "object") return generate_object(input);
|
|
11
|
-
else if (typeof input === "string") return generate_string(input);
|
|
12
|
-
else if (typeof input === "boolean") return generate_value(input);
|
|
13
|
-
else if (typeof input === "number") return generate_value(input);
|
|
14
|
-
else if (typeof input === "bigint") return generate_value(input);
|
|
15
|
-
else throw new Error("Unknown type.");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function generate_object(obj: object): ts.ObjectLiteralExpression {
|
|
19
|
-
const properties = Object.entries(obj)
|
|
20
|
-
.filter((tuple) => tuple[1] !== undefined)
|
|
21
|
-
.map(([key, value]) =>
|
|
22
|
-
ts.factory.createPropertyAssignment(
|
|
23
|
-
IdentifierFactory.generate(key),
|
|
24
|
-
generate(value),
|
|
25
|
-
),
|
|
26
|
-
);
|
|
27
|
-
return ts.factory.createObjectLiteralExpression(properties, true);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function generate_array(array: any[]): ts.ArrayLiteralExpression {
|
|
31
|
-
return ts.factory.createArrayLiteralExpression(
|
|
32
|
-
array.map(generate),
|
|
33
|
-
true,
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function generate_value(value: number | boolean | bigint): ts.Identifier {
|
|
38
|
-
return ts.factory.createIdentifier(value.toString());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function generate_string(value: string): ts.StringLiteral {
|
|
42
|
-
return ts.factory.createStringLiteral(value);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "./IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
export namespace LiteralFactory {
|
|
6
|
+
export function generate(input: any): ts.Expression {
|
|
7
|
+
if (input === null) return ts.factory.createNull();
|
|
8
|
+
else if (ts.isIdentifier(input)) return input;
|
|
9
|
+
else if (input instanceof Array) return generate_array(input);
|
|
10
|
+
else if (typeof input === "object") return generate_object(input);
|
|
11
|
+
else if (typeof input === "string") return generate_string(input);
|
|
12
|
+
else if (typeof input === "boolean") return generate_value(input);
|
|
13
|
+
else if (typeof input === "number") return generate_value(input);
|
|
14
|
+
else if (typeof input === "bigint") return generate_value(input);
|
|
15
|
+
else throw new Error("Unknown type.");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function generate_object(obj: object): ts.ObjectLiteralExpression {
|
|
19
|
+
const properties = Object.entries(obj)
|
|
20
|
+
.filter((tuple) => tuple[1] !== undefined)
|
|
21
|
+
.map(([key, value]) =>
|
|
22
|
+
ts.factory.createPropertyAssignment(
|
|
23
|
+
IdentifierFactory.generate(key),
|
|
24
|
+
generate(value),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
return ts.factory.createObjectLiteralExpression(properties, true);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function generate_array(array: any[]): ts.ArrayLiteralExpression {
|
|
31
|
+
return ts.factory.createArrayLiteralExpression(
|
|
32
|
+
array.map(generate),
|
|
33
|
+
true,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function generate_value(value: number | boolean | bigint): ts.Identifier {
|
|
38
|
+
return ts.factory.createIdentifier(value.toString());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function generate_string(value: string): ts.StringLiteral {
|
|
42
|
+
return ts.factory.createStringLiteral(value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -14,9 +14,7 @@ export class MetadataCollection {
|
|
|
14
14
|
private readonly unions_: Map<string, MetadataObject[]>;
|
|
15
15
|
private index_: number;
|
|
16
16
|
|
|
17
|
-
public constructor(
|
|
18
|
-
private readonly options?: Partial<MetadataCollection.IOptions>,
|
|
19
|
-
) {
|
|
17
|
+
public constructor() {
|
|
20
18
|
this.dict_ = new Map();
|
|
21
19
|
this.names_ = new Map();
|
|
22
20
|
this.unions_ = new Map();
|
|
@@ -67,11 +65,7 @@ export class MetadataCollection {
|
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
private get_name(checker: ts.TypeChecker, type: ts.Type): string {
|
|
70
|
-
const name: string = (
|
|
71
|
-
const str: string = TypeFactory.getFullName(checker, type);
|
|
72
|
-
return this.options?.replace ? this.options.replace(str) : str;
|
|
73
|
-
})();
|
|
74
|
-
|
|
68
|
+
const name: string = TypeFactory.getFullName(checker, type);
|
|
75
69
|
const duplicates: Map<ts.Type, string> = MapUtil.take(
|
|
76
70
|
this.names_,
|
|
77
71
|
name,
|
|
@@ -87,38 +81,3 @@ export class MetadataCollection {
|
|
|
87
81
|
return addicted;
|
|
88
82
|
}
|
|
89
83
|
}
|
|
90
|
-
export namespace MetadataCollection {
|
|
91
|
-
export interface IOptions {
|
|
92
|
-
replace?(str: string): string;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function replace(str: string): string {
|
|
96
|
-
for (const [before, after] of REPLACERS)
|
|
97
|
-
str = str.split(before).join(after);
|
|
98
|
-
return str;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function escape(str: string): string {
|
|
102
|
-
for (const [before, after] of REPLACERS)
|
|
103
|
-
if (after !== "") str = str.split(after).join(before);
|
|
104
|
-
return str;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const REPLACERS: [string, string][] = [
|
|
108
|
-
["$", "_dollar_"],
|
|
109
|
-
["&", "_and_"],
|
|
110
|
-
["|", "_or_"],
|
|
111
|
-
["{", "_blt_"],
|
|
112
|
-
["}", "_bgt_"],
|
|
113
|
-
["<", "_lt_"],
|
|
114
|
-
[">", "_gt_"],
|
|
115
|
-
["(", "_lp_"],
|
|
116
|
-
[")", "_rp_"],
|
|
117
|
-
["[", "_alt_"],
|
|
118
|
-
["]", "_agt_"],
|
|
119
|
-
[",", "_comma_"],
|
|
120
|
-
["`", "_backquote_"],
|
|
121
|
-
["'", "_singlequote_"],
|
|
122
|
-
['"', "_doublequote_"],
|
|
123
|
-
[" ", "_space_"],
|
|
124
|
-
];
|
|
@@ -330,8 +330,12 @@ function validate(
|
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
function has_atomic(metadata: Metadata, type: "string" | "number"): boolean {
|
|
333
|
+
const valid =
|
|
334
|
+
type === "number"
|
|
335
|
+
? (atom: string) => atom === type || atom === "bigint"
|
|
336
|
+
: (atom: string) => atom === type;
|
|
333
337
|
return (
|
|
334
|
-
metadata.atomics.find((atom) => atom
|
|
338
|
+
metadata.atomics.find((atom) => valid(atom)) !== undefined ||
|
|
335
339
|
metadata.arrays.some((child) => has_atomic(child, type)) ||
|
|
336
340
|
metadata.tuples.some((tuple) =>
|
|
337
341
|
tuple.some((child) => has_atomic(child, type)),
|
|
@@ -9,11 +9,6 @@ import { emplace_protocol_object } from "./internal/protocols/emplace_protocol_o
|
|
|
9
9
|
import { iterate_protocol_main } from "./internal/protocols/iterate_protocol_main";
|
|
10
10
|
|
|
11
11
|
export namespace ProtocolFactory {
|
|
12
|
-
export const collection = () =>
|
|
13
|
-
new MetadataCollection({
|
|
14
|
-
replace: MetadataCollection.replace,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
12
|
export const metadata =
|
|
18
13
|
(checker: ts.TypeChecker) =>
|
|
19
14
|
(collection: MetadataCollection) =>
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace StatementFactory {
|
|
4
|
-
export function constant(name: string, initializer?: ts.Expression) {
|
|
5
|
-
return ts.factory.createVariableStatement(
|
|
6
|
-
undefined,
|
|
7
|
-
ts.factory.createVariableDeclarationList(
|
|
8
|
-
[
|
|
9
|
-
ts.factory.createVariableDeclaration(
|
|
10
|
-
name,
|
|
11
|
-
undefined,
|
|
12
|
-
undefined,
|
|
13
|
-
initializer,
|
|
14
|
-
),
|
|
15
|
-
],
|
|
16
|
-
ts.NodeFlags.Const,
|
|
17
|
-
),
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function transpile(script: string) {
|
|
22
|
-
return ts.factory.createExpressionStatement(
|
|
23
|
-
ts.factory.createIdentifier(ts.transpile(script)),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// export function require(variable: string, location: string) {
|
|
28
|
-
// return ts.factory.createImportDeclaration(
|
|
29
|
-
// undefined,
|
|
30
|
-
// undefined,
|
|
31
|
-
// ts.factory.createImportClause(
|
|
32
|
-
// false,
|
|
33
|
-
// undefined,
|
|
34
|
-
// ts.factory.createNamespaceImport(
|
|
35
|
-
// ts.factory.createIdentifier(variable),
|
|
36
|
-
// ),
|
|
37
|
-
// ),
|
|
38
|
-
// ts.factory.createStringLiteral(location),
|
|
39
|
-
// );
|
|
40
|
-
// }
|
|
41
|
-
|
|
42
|
-
// export function importModulo(variable: string, location: string) {
|
|
43
|
-
// return ts.factory.createImportDeclaration(
|
|
44
|
-
// undefined,
|
|
45
|
-
// undefined,
|
|
46
|
-
// ts.factory.createImportClause(
|
|
47
|
-
// false,
|
|
48
|
-
// undefined,
|
|
49
|
-
// ts.factory.createNamedImports([
|
|
50
|
-
// ts.factory.createImportSpecifier(
|
|
51
|
-
// false,
|
|
52
|
-
// undefined,
|
|
53
|
-
// ts.factory.createIdentifier(variable),
|
|
54
|
-
// ),
|
|
55
|
-
// ]),
|
|
56
|
-
// ),
|
|
57
|
-
// ts.factory.createStringLiteral(location),
|
|
58
|
-
// );
|
|
59
|
-
// }
|
|
60
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace StatementFactory {
|
|
4
|
+
export function constant(name: string, initializer?: ts.Expression) {
|
|
5
|
+
return ts.factory.createVariableStatement(
|
|
6
|
+
undefined,
|
|
7
|
+
ts.factory.createVariableDeclarationList(
|
|
8
|
+
[
|
|
9
|
+
ts.factory.createVariableDeclaration(
|
|
10
|
+
name,
|
|
11
|
+
undefined,
|
|
12
|
+
undefined,
|
|
13
|
+
initializer,
|
|
14
|
+
),
|
|
15
|
+
],
|
|
16
|
+
ts.NodeFlags.Const,
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function transpile(script: string) {
|
|
22
|
+
return ts.factory.createExpressionStatement(
|
|
23
|
+
ts.factory.createIdentifier(ts.transpile(script)),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// export function require(variable: string, location: string) {
|
|
28
|
+
// return ts.factory.createImportDeclaration(
|
|
29
|
+
// undefined,
|
|
30
|
+
// undefined,
|
|
31
|
+
// ts.factory.createImportClause(
|
|
32
|
+
// false,
|
|
33
|
+
// undefined,
|
|
34
|
+
// ts.factory.createNamespaceImport(
|
|
35
|
+
// ts.factory.createIdentifier(variable),
|
|
36
|
+
// ),
|
|
37
|
+
// ),
|
|
38
|
+
// ts.factory.createStringLiteral(location),
|
|
39
|
+
// );
|
|
40
|
+
// }
|
|
41
|
+
|
|
42
|
+
// export function importModulo(variable: string, location: string) {
|
|
43
|
+
// return ts.factory.createImportDeclaration(
|
|
44
|
+
// undefined,
|
|
45
|
+
// undefined,
|
|
46
|
+
// ts.factory.createImportClause(
|
|
47
|
+
// false,
|
|
48
|
+
// undefined,
|
|
49
|
+
// ts.factory.createNamedImports([
|
|
50
|
+
// ts.factory.createImportSpecifier(
|
|
51
|
+
// false,
|
|
52
|
+
// undefined,
|
|
53
|
+
// ts.factory.createIdentifier(variable),
|
|
54
|
+
// ),
|
|
55
|
+
// ]),
|
|
56
|
+
// ),
|
|
57
|
+
// ts.factory.createStringLiteral(location),
|
|
58
|
+
// );
|
|
59
|
+
// }
|
|
60
|
+
}
|