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
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace TypeFactory {
|
|
4
|
-
export function resolve(
|
|
5
|
-
checker: ts.TypeChecker,
|
|
6
|
-
type: ts.Type,
|
|
7
|
-
): ts.Type | null {
|
|
8
|
-
return getReturnType(checker, type, "toJSON");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isFunction(type: ts.Type): boolean {
|
|
12
|
-
return getFunction(type) !== null;
|
|
13
|
-
}
|
|
14
|
-
function getFunction(type: ts.Type) {
|
|
15
|
-
const node = type.symbol?.declarations?.[0];
|
|
16
|
-
if (node === undefined) return null;
|
|
17
|
-
|
|
18
|
-
return ts.isFunctionLike(node)
|
|
19
|
-
? node
|
|
20
|
-
: ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
|
|
21
|
-
? ts.isFunctionLike(node.initializer)
|
|
22
|
-
? node.initializer
|
|
23
|
-
: null
|
|
24
|
-
: null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getReturnType(
|
|
28
|
-
checker: ts.TypeChecker,
|
|
29
|
-
type: ts.Type,
|
|
30
|
-
name: string,
|
|
31
|
-
): ts.Type | null {
|
|
32
|
-
// FIND TO-JSON METHOD
|
|
33
|
-
const symbol: ts.Symbol | undefined = type.getProperty(name);
|
|
34
|
-
if (!symbol) return null;
|
|
35
|
-
else if (!symbol.valueDeclaration) return null;
|
|
36
|
-
|
|
37
|
-
// GET FUNCTION DECLARATION
|
|
38
|
-
const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
|
|
39
|
-
symbol,
|
|
40
|
-
symbol.valueDeclaration,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
// RETURNS THE RETURN-TYPE
|
|
44
|
-
const signature: ts.Signature | undefined = checker.getSignaturesOfType(
|
|
45
|
-
functor,
|
|
46
|
-
ts.SignatureKind.Call,
|
|
47
|
-
)[0];
|
|
48
|
-
return signature ? signature.getReturnType() : null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function getFullName(
|
|
52
|
-
checker: ts.TypeChecker,
|
|
53
|
-
type: ts.Type,
|
|
54
|
-
symbol?: ts.Symbol,
|
|
55
|
-
): string {
|
|
56
|
-
// PRIMITIVE
|
|
57
|
-
symbol ||= type.aliasSymbol || type.getSymbol();
|
|
58
|
-
if (symbol === undefined) return checker.typeToString(type);
|
|
59
|
-
|
|
60
|
-
// UNION OR INTERSECT
|
|
61
|
-
if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
|
|
62
|
-
const joiner: string = type.isIntersection() ? " & " : " | ";
|
|
63
|
-
return type.types
|
|
64
|
-
.map((child) => getFullName(checker, child))
|
|
65
|
-
.join(joiner);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
//----
|
|
69
|
-
// SPECIALIZATION
|
|
70
|
-
//----
|
|
71
|
-
const name: string = get_name(symbol);
|
|
72
|
-
|
|
73
|
-
// CHECK GENERIC
|
|
74
|
-
const generic: readonly ts.Type[] = type.aliasSymbol
|
|
75
|
-
? type.aliasTypeArguments || []
|
|
76
|
-
: checker.getTypeArguments(type as ts.TypeReference);
|
|
77
|
-
return generic.length
|
|
78
|
-
? name === "Promise"
|
|
79
|
-
? getFullName(checker, generic[0]!)
|
|
80
|
-
: `${name}<${generic
|
|
81
|
-
.map((child) => getFullName(checker, child))
|
|
82
|
-
.join(", ")}>`
|
|
83
|
-
: name;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function explore_name(name: string, decl: ts.Node): string {
|
|
87
|
-
return ts.isModuleBlock(decl)
|
|
88
|
-
? explore_name(
|
|
89
|
-
`${decl.parent.name.getText()}.${name}`,
|
|
90
|
-
decl.parent.parent,
|
|
91
|
-
)
|
|
92
|
-
: name;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function get_name(symbol: ts.Symbol): string {
|
|
96
|
-
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
97
|
-
return parent
|
|
98
|
-
? explore_name(symbol.escapedName.toString(), parent)
|
|
99
|
-
: "__type";
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace TypeFactory {
|
|
4
|
+
export function resolve(
|
|
5
|
+
checker: ts.TypeChecker,
|
|
6
|
+
type: ts.Type,
|
|
7
|
+
): ts.Type | null {
|
|
8
|
+
return getReturnType(checker, type, "toJSON");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isFunction(type: ts.Type): boolean {
|
|
12
|
+
return getFunction(type) !== null;
|
|
13
|
+
}
|
|
14
|
+
function getFunction(type: ts.Type) {
|
|
15
|
+
const node = type.symbol?.declarations?.[0];
|
|
16
|
+
if (node === undefined) return null;
|
|
17
|
+
|
|
18
|
+
return ts.isFunctionLike(node)
|
|
19
|
+
? node
|
|
20
|
+
: ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
|
|
21
|
+
? ts.isFunctionLike(node.initializer)
|
|
22
|
+
? node.initializer
|
|
23
|
+
: null
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getReturnType(
|
|
28
|
+
checker: ts.TypeChecker,
|
|
29
|
+
type: ts.Type,
|
|
30
|
+
name: string,
|
|
31
|
+
): ts.Type | null {
|
|
32
|
+
// FIND TO-JSON METHOD
|
|
33
|
+
const symbol: ts.Symbol | undefined = type.getProperty(name);
|
|
34
|
+
if (!symbol) return null;
|
|
35
|
+
else if (!symbol.valueDeclaration) return null;
|
|
36
|
+
|
|
37
|
+
// GET FUNCTION DECLARATION
|
|
38
|
+
const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
|
|
39
|
+
symbol,
|
|
40
|
+
symbol.valueDeclaration,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// RETURNS THE RETURN-TYPE
|
|
44
|
+
const signature: ts.Signature | undefined = checker.getSignaturesOfType(
|
|
45
|
+
functor,
|
|
46
|
+
ts.SignatureKind.Call,
|
|
47
|
+
)[0];
|
|
48
|
+
return signature ? signature.getReturnType() : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getFullName(
|
|
52
|
+
checker: ts.TypeChecker,
|
|
53
|
+
type: ts.Type,
|
|
54
|
+
symbol?: ts.Symbol,
|
|
55
|
+
): string {
|
|
56
|
+
// PRIMITIVE
|
|
57
|
+
symbol ||= type.aliasSymbol || type.getSymbol();
|
|
58
|
+
if (symbol === undefined) return checker.typeToString(type);
|
|
59
|
+
|
|
60
|
+
// UNION OR INTERSECT
|
|
61
|
+
if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
|
|
62
|
+
const joiner: string = type.isIntersection() ? " & " : " | ";
|
|
63
|
+
return type.types
|
|
64
|
+
.map((child) => getFullName(checker, child))
|
|
65
|
+
.join(joiner);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//----
|
|
69
|
+
// SPECIALIZATION
|
|
70
|
+
//----
|
|
71
|
+
const name: string = get_name(symbol);
|
|
72
|
+
|
|
73
|
+
// CHECK GENERIC
|
|
74
|
+
const generic: readonly ts.Type[] = type.aliasSymbol
|
|
75
|
+
? type.aliasTypeArguments || []
|
|
76
|
+
: checker.getTypeArguments(type as ts.TypeReference);
|
|
77
|
+
return generic.length
|
|
78
|
+
? name === "Promise"
|
|
79
|
+
? getFullName(checker, generic[0]!)
|
|
80
|
+
: `${name}<${generic
|
|
81
|
+
.map((child) => getFullName(checker, child))
|
|
82
|
+
.join(", ")}>`
|
|
83
|
+
: name;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function explore_name(name: string, decl: ts.Node): string {
|
|
87
|
+
return ts.isModuleBlock(decl)
|
|
88
|
+
? explore_name(
|
|
89
|
+
`${decl.parent.name.getText()}.${name}`,
|
|
90
|
+
decl.parent.parent,
|
|
91
|
+
)
|
|
92
|
+
: name;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function get_name(symbol: ts.Symbol): string {
|
|
96
|
+
const parent = symbol.getDeclarations()?.[0]?.parent;
|
|
97
|
+
return parent
|
|
98
|
+
? explore_name(symbol.escapedName.toString(), parent)
|
|
99
|
+
: "__type";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace ValueFactory {
|
|
4
|
-
export const NULL = () => ts.factory.createNull();
|
|
5
|
-
export const UNDEFINED = () => ts.factory.createIdentifier("undefined");
|
|
6
|
-
export const BOOLEAN = (value: boolean) =>
|
|
7
|
-
value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
8
|
-
export const INPUT = (str: string = "input") =>
|
|
9
|
-
ts.factory.createIdentifier(str);
|
|
10
|
-
export const TYPEOF = (input: ts.Expression) =>
|
|
11
|
-
ts.factory.createTypeOfExpression(input);
|
|
12
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace ValueFactory {
|
|
4
|
+
export const NULL = () => ts.factory.createNull();
|
|
5
|
+
export const UNDEFINED = () => ts.factory.createIdentifier("undefined");
|
|
6
|
+
export const BOOLEAN = (value: boolean) =>
|
|
7
|
+
value ? ts.factory.createTrue() : ts.factory.createFalse();
|
|
8
|
+
export const INPUT = (str: string = "input") =>
|
|
9
|
+
ts.factory.createIdentifier(str);
|
|
10
|
+
export const TYPEOF = (input: ts.Expression) =>
|
|
11
|
+
ts.factory.createTypeOfExpression(input);
|
|
12
|
+
}
|
|
@@ -78,4 +78,24 @@ export namespace ProtocolMetadataUtil {
|
|
|
78
78
|
jsDocTags: [],
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
export function array(meta: Metadata): Metadata {
|
|
83
|
+
return Metadata.create({
|
|
84
|
+
any: false,
|
|
85
|
+
required: true,
|
|
86
|
+
nullable: false,
|
|
87
|
+
functional: false,
|
|
88
|
+
resolved: null,
|
|
89
|
+
atomics: [],
|
|
90
|
+
constants: [],
|
|
91
|
+
templates: [],
|
|
92
|
+
rest: null,
|
|
93
|
+
arrays: [meta],
|
|
94
|
+
tuples: [],
|
|
95
|
+
objects: [],
|
|
96
|
+
natives: [],
|
|
97
|
+
sets: [],
|
|
98
|
+
maps: [],
|
|
99
|
+
});
|
|
100
|
+
}
|
|
81
101
|
}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { Metadata } from "../../../metadata/Metadata";
|
|
2
2
|
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
3
3
|
|
|
4
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
4
5
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
5
6
|
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
6
7
|
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
7
8
|
import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
|
|
8
9
|
import { iterate_protocol_constant } from "./iterate_protocol_constant";
|
|
10
|
+
import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
|
|
9
11
|
|
|
10
12
|
export const iterate_protocol_map =
|
|
11
13
|
(container: "Object" | "Map") =>
|
|
12
14
|
(dict: Map<string, IProtocolMessage>) =>
|
|
13
15
|
(key: Metadata) =>
|
|
14
|
-
(value: Metadata) =>
|
|
15
|
-
|
|
16
|
+
(value: Metadata): IProtocolMap => ({
|
|
17
|
+
type: "map",
|
|
18
|
+
key: getKeyName(key),
|
|
19
|
+
value: getValueName(container)(dict)(value),
|
|
20
|
+
});
|
|
16
21
|
|
|
17
22
|
const getKeyName = (meta: Metadata) => {
|
|
18
23
|
for (const atomic of meta.atomics)
|
|
@@ -26,7 +31,8 @@ const getValueName =
|
|
|
26
31
|
(container: "Object" | "Map") =>
|
|
27
32
|
(dict: Map<string, IProtocolMessage>) =>
|
|
28
33
|
(meta: Metadata) => {
|
|
29
|
-
if (ProtocolMetadataUtil.standalone(meta))
|
|
34
|
+
if (ProtocolMetadataUtil.standalone(meta))
|
|
35
|
+
return iterate_protocol_metadata(dict)(meta)([]).oneOf[0]!.type;
|
|
30
36
|
|
|
31
37
|
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
32
38
|
`${container}.Value<${meta.getName()}>`,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IMetadataTag } from "../../../metadata/IMetadataTag";
|
|
2
2
|
import { Metadata } from "../../../metadata/Metadata";
|
|
3
3
|
|
|
4
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
4
5
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
5
6
|
import { IProtocolProperty } from "../../../messages/IProtocolProperty";
|
|
6
7
|
import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
|
|
@@ -18,7 +19,7 @@ export const iterate_protocol_metadata =
|
|
|
18
19
|
const required: boolean = meta.required && !meta.nullable;
|
|
19
20
|
const oneOf: IProtocolProperty.IOneOf[] = [];
|
|
20
21
|
|
|
21
|
-
const add = (type: string) => {
|
|
22
|
+
const add = (type: string | IProtocolMap) => {
|
|
22
23
|
if (oneOf.some((one) => one.type === type)) return;
|
|
23
24
|
oneOf.push({
|
|
24
25
|
type,
|
|
@@ -31,7 +32,11 @@ export const iterate_protocol_metadata =
|
|
|
31
32
|
meta.arrays.length === 1
|
|
32
33
|
? (["Array", meta.arrays[0]!] as const)
|
|
33
34
|
: (["Set", meta.sets[0]!] as const);
|
|
34
|
-
add(
|
|
35
|
+
add(
|
|
36
|
+
iterate_protocol_repeated(container)(true, true)(dict)(child)(
|
|
37
|
+
tags,
|
|
38
|
+
),
|
|
39
|
+
);
|
|
35
40
|
return {
|
|
36
41
|
required,
|
|
37
42
|
oneOf,
|
|
@@ -61,9 +66,17 @@ export const iterate_protocol_metadata =
|
|
|
61
66
|
for (const tuple of meta.tuples)
|
|
62
67
|
add(iterate_protocol_tuple(dict)(tuple));
|
|
63
68
|
for (const array of meta.arrays)
|
|
64
|
-
add(
|
|
69
|
+
add(
|
|
70
|
+
iterate_protocol_repeated("Array")(false, meta.bucket() === 1)(
|
|
71
|
+
dict,
|
|
72
|
+
)(array)(tags),
|
|
73
|
+
);
|
|
65
74
|
for (const set of meta.sets)
|
|
66
|
-
add(
|
|
75
|
+
add(
|
|
76
|
+
iterate_protocol_repeated("Set")(false, meta.bucket() === 1)(
|
|
77
|
+
dict,
|
|
78
|
+
)(set)(tags),
|
|
79
|
+
);
|
|
67
80
|
for (const map of meta.maps)
|
|
68
81
|
add(iterate_protocol_map("Map")(dict)(map.key)(map.value));
|
|
69
82
|
|
|
@@ -2,24 +2,33 @@ import { IMetadataTag } from "../../../metadata/IMetadataTag";
|
|
|
2
2
|
import { Metadata } from "../../../metadata/Metadata";
|
|
3
3
|
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
4
|
|
|
5
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
5
6
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
6
7
|
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
7
8
|
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
9
|
+
import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
|
|
8
10
|
|
|
9
11
|
export const iterate_protocol_repeated =
|
|
10
12
|
(container: "Array" | "Set") =>
|
|
11
|
-
(sole: boolean) =>
|
|
13
|
+
(sole: boolean, bucket: boolean) =>
|
|
12
14
|
(dict: Map<string, IProtocolMessage>) =>
|
|
13
15
|
(meta: Metadata) =>
|
|
14
|
-
(tags: IMetadataTag[]): string => {
|
|
16
|
+
(tags: IMetadataTag[]): string | IProtocolMap => {
|
|
15
17
|
sole &&= ProtocolMetadataUtil.standalone(meta);
|
|
16
|
-
if (sole === true)
|
|
18
|
+
if (sole === true)
|
|
19
|
+
return iterate_protocol_metadata(dict)(meta)(tags).oneOf[0]!.type;
|
|
17
20
|
|
|
18
21
|
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
19
|
-
`${container}
|
|
22
|
+
`${container}.${bucket ? "Element" : "Wrapper"}<${meta.getName()}>`,
|
|
20
23
|
dict.size,
|
|
21
24
|
);
|
|
22
|
-
obj.properties.push(
|
|
25
|
+
obj.properties.push(
|
|
26
|
+
ProtocolMetadataUtil.property(
|
|
27
|
+
"value",
|
|
28
|
+
bucket ? meta : ProtocolMetadataUtil.array(meta),
|
|
29
|
+
tags,
|
|
30
|
+
),
|
|
31
|
+
);
|
|
23
32
|
emplace_protocol_object(dict)(obj);
|
|
24
33
|
return obj.name;
|
|
25
34
|
};
|
package/src/functional/$every.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { TypeGuardError } from "../TypeGuardError";
|
|
2
|
-
|
|
3
|
-
export const $every = <T>(
|
|
4
|
-
array: T[],
|
|
5
|
-
pred: (value: T, i: number) => null | Omit<TypeGuardError.IProps, "method">,
|
|
6
|
-
): null | Omit<TypeGuardError.IProps, "method"> => {
|
|
7
|
-
let error: null | Omit<TypeGuardError.IProps, "method"> = null;
|
|
8
|
-
for (let i: number = 0; i < array.length; ++i)
|
|
9
|
-
if (null !== (error = pred(array[i]!, i))) return error;
|
|
10
|
-
return null;
|
|
11
|
-
};
|
|
1
|
+
import { TypeGuardError } from "../TypeGuardError";
|
|
2
|
+
|
|
3
|
+
export const $every = <T>(
|
|
4
|
+
array: T[],
|
|
5
|
+
pred: (value: T, i: number) => null | Omit<TypeGuardError.IProps, "method">,
|
|
6
|
+
): null | Omit<TypeGuardError.IProps, "method"> => {
|
|
7
|
+
let error: null | Omit<TypeGuardError.IProps, "method"> = null;
|
|
8
|
+
for (let i: number = 0; i < array.length; ++i)
|
|
9
|
+
if (null !== (error = pred(array[i]!, i))) return error;
|
|
10
|
+
return null;
|
|
11
|
+
};
|
package/src/functional/$guard.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { TypeGuardError } from "../TypeGuardError";
|
|
2
|
-
|
|
3
|
-
/* -----------------------------------------------------------
|
|
4
|
-
ASSERT V2 -> USE (NULL OR ERROR) CONDITION
|
|
5
|
-
----------------------------------------------------------- */
|
|
6
|
-
// /**
|
|
7
|
-
// * @internal
|
|
8
|
-
// */
|
|
9
|
-
// export const $guardV2 =
|
|
10
|
-
// (method: string) => (props: Omit<TypeGuardError.IProps, "method">) =>
|
|
11
|
-
// new TypeGuardError({
|
|
12
|
-
// method,
|
|
13
|
-
// path: props.path,
|
|
14
|
-
// expected: props.expected,
|
|
15
|
-
// value: props.value,
|
|
16
|
-
// });
|
|
17
|
-
|
|
18
|
-
/* -----------------------------------------------------------
|
|
19
|
-
ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
|
|
20
|
-
----------------------------------------------------------- */
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
export const $guard =
|
|
25
|
-
(method: string) =>
|
|
26
|
-
(exceptionable: boolean, props: Omit<TypeGuardError.IProps, "method">) => {
|
|
27
|
-
if (exceptionable === true)
|
|
28
|
-
throw new TypeGuardError({
|
|
29
|
-
method,
|
|
30
|
-
path: props.path,
|
|
31
|
-
expected: props.expected,
|
|
32
|
-
value: props.value,
|
|
33
|
-
});
|
|
34
|
-
return false;
|
|
35
|
-
};
|
|
1
|
+
import { TypeGuardError } from "../TypeGuardError";
|
|
2
|
+
|
|
3
|
+
/* -----------------------------------------------------------
|
|
4
|
+
ASSERT V2 -> USE (NULL OR ERROR) CONDITION
|
|
5
|
+
----------------------------------------------------------- */
|
|
6
|
+
// /**
|
|
7
|
+
// * @internal
|
|
8
|
+
// */
|
|
9
|
+
// export const $guardV2 =
|
|
10
|
+
// (method: string) => (props: Omit<TypeGuardError.IProps, "method">) =>
|
|
11
|
+
// new TypeGuardError({
|
|
12
|
+
// method,
|
|
13
|
+
// path: props.path,
|
|
14
|
+
// expected: props.expected,
|
|
15
|
+
// value: props.value,
|
|
16
|
+
// });
|
|
17
|
+
|
|
18
|
+
/* -----------------------------------------------------------
|
|
19
|
+
ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
|
|
20
|
+
----------------------------------------------------------- */
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export const $guard =
|
|
25
|
+
(method: string) =>
|
|
26
|
+
(exceptionable: boolean, props: Omit<TypeGuardError.IProps, "method">) => {
|
|
27
|
+
if (exceptionable === true)
|
|
28
|
+
throw new TypeGuardError({
|
|
29
|
+
method,
|
|
30
|
+
path: props.path,
|
|
31
|
+
expected: props.expected,
|
|
32
|
+
value: props.value,
|
|
33
|
+
});
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function $is_email(str: string): boolean {
|
|
2
|
-
return REGEX.test(str);
|
|
3
|
-
}
|
|
4
|
-
const REGEX =
|
|
5
|
-
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
|
1
|
+
export function $is_email(str: string): boolean {
|
|
2
|
+
return REGEX.test(str);
|
|
3
|
+
}
|
|
4
|
+
const REGEX =
|
|
5
|
+
/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function $is_ipv4(str: string): boolean {
|
|
2
|
-
return REGEX.test(str);
|
|
3
|
-
}
|
|
4
|
-
const REGEX =
|
|
5
|
-
/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
1
|
+
export function $is_ipv4(str: string): boolean {
|
|
2
|
+
return REGEX.test(str);
|
|
3
|
+
}
|
|
4
|
+
const REGEX =
|
|
5
|
+
/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function $is_ipv6(str: string): boolean {
|
|
2
|
-
return REGEX.test(str);
|
|
3
|
-
}
|
|
4
|
-
const REGEX =
|
|
5
|
-
/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
1
|
+
export function $is_ipv6(str: string): boolean {
|
|
2
|
+
return REGEX.test(str);
|
|
3
|
+
}
|
|
4
|
+
const REGEX =
|
|
5
|
+
/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function $is_url(str: string): boolean {
|
|
2
|
-
return REGEX.test(str);
|
|
3
|
-
}
|
|
4
|
-
const REGEX =
|
|
5
|
-
/^[a-zA-Z0-9]+:\/\/(?:www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/;
|
|
1
|
+
export function $is_url(str: string): boolean {
|
|
2
|
+
return REGEX.test(str);
|
|
3
|
+
}
|
|
4
|
+
const REGEX =
|
|
5
|
+
/^[a-zA-Z0-9]+:\/\/(?:www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export function $is_uuid(str: string): boolean {
|
|
2
|
-
return REGEX.test(str);
|
|
3
|
-
}
|
|
4
|
-
const REGEX =
|
|
5
|
-
/[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
|
|
1
|
+
export function $is_uuid(str: string): boolean {
|
|
2
|
+
return REGEX.test(str);
|
|
3
|
+
}
|
|
4
|
+
const REGEX =
|
|
5
|
+
/[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
|
package/src/functional/$join.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
export function $join(str: string): string {
|
|
2
|
-
return variable(str) ? `.${str}` : `[${JSON.stringify(str)}]`;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function variable(str: string): boolean {
|
|
6
|
-
return reserved(str) === false && /^[a-zA-Z_$][a-zA-Z_$0-9]*$/g.test(str);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function reserved(str: string): boolean {
|
|
10
|
-
return RESERVED.has(str);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const RESERVED: Set<string> = new Set([
|
|
14
|
-
"break",
|
|
15
|
-
"case",
|
|
16
|
-
"catch",
|
|
17
|
-
"class",
|
|
18
|
-
"const",
|
|
19
|
-
"continue",
|
|
20
|
-
"debugger",
|
|
21
|
-
"default",
|
|
22
|
-
"delete",
|
|
23
|
-
"do",
|
|
24
|
-
"else",
|
|
25
|
-
"enum",
|
|
26
|
-
"export",
|
|
27
|
-
"extends",
|
|
28
|
-
"false",
|
|
29
|
-
"finally",
|
|
30
|
-
"for",
|
|
31
|
-
"function",
|
|
32
|
-
"if",
|
|
33
|
-
"import",
|
|
34
|
-
"in",
|
|
35
|
-
"instanceof",
|
|
36
|
-
"new",
|
|
37
|
-
"null",
|
|
38
|
-
"return",
|
|
39
|
-
"super",
|
|
40
|
-
"switch",
|
|
41
|
-
"this",
|
|
42
|
-
"throw",
|
|
43
|
-
"true",
|
|
44
|
-
"try",
|
|
45
|
-
"typeof",
|
|
46
|
-
"var",
|
|
47
|
-
"void",
|
|
48
|
-
"while",
|
|
49
|
-
"with",
|
|
50
|
-
]);
|
|
1
|
+
export function $join(str: string): string {
|
|
2
|
+
return variable(str) ? `.${str}` : `[${JSON.stringify(str)}]`;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function variable(str: string): boolean {
|
|
6
|
+
return reserved(str) === false && /^[a-zA-Z_$][a-zA-Z_$0-9]*$/g.test(str);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function reserved(str: string): boolean {
|
|
10
|
+
return RESERVED.has(str);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const RESERVED: Set<string> = new Set([
|
|
14
|
+
"break",
|
|
15
|
+
"case",
|
|
16
|
+
"catch",
|
|
17
|
+
"class",
|
|
18
|
+
"const",
|
|
19
|
+
"continue",
|
|
20
|
+
"debugger",
|
|
21
|
+
"default",
|
|
22
|
+
"delete",
|
|
23
|
+
"do",
|
|
24
|
+
"else",
|
|
25
|
+
"enum",
|
|
26
|
+
"export",
|
|
27
|
+
"extends",
|
|
28
|
+
"false",
|
|
29
|
+
"finally",
|
|
30
|
+
"for",
|
|
31
|
+
"function",
|
|
32
|
+
"if",
|
|
33
|
+
"import",
|
|
34
|
+
"in",
|
|
35
|
+
"instanceof",
|
|
36
|
+
"new",
|
|
37
|
+
"null",
|
|
38
|
+
"return",
|
|
39
|
+
"super",
|
|
40
|
+
"switch",
|
|
41
|
+
"this",
|
|
42
|
+
"throw",
|
|
43
|
+
"true",
|
|
44
|
+
"try",
|
|
45
|
+
"typeof",
|
|
46
|
+
"var",
|
|
47
|
+
"void",
|
|
48
|
+
"while",
|
|
49
|
+
"with",
|
|
50
|
+
]);
|