typia 3.4.15 → 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 +48 -7
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -75
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +8 -0
- package/lib/factories/ProtocolFactory.js +119 -0
- package/lib/factories/ProtocolFactory.js.map +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
- package/lib/functional/$proto_bytes.d.ts +2 -0
- package/lib/functional/$proto_bytes.js +37 -0
- package/lib/functional/$proto_bytes.js.map +1 -0
- package/lib/functional/$proto_field.d.ts +10 -0
- package/lib/functional/$proto_field.js +42 -0
- package/lib/functional/$proto_field.js.map +1 -0
- package/lib/functional/$proto_float.d.ts +4 -0
- package/lib/functional/$proto_float.js +28 -0
- package/lib/functional/$proto_float.js.map +1 -0
- package/lib/functional/$proto_i32.d.ts +2 -0
- package/lib/functional/$proto_i32.js +23 -0
- package/lib/functional/$proto_i32.js.map +1 -0
- package/lib/functional/$proto_i64.d.ts +2 -0
- package/lib/functional/$proto_i64.js +31 -0
- package/lib/functional/$proto_i64.js.map +1 -0
- package/lib/functional/$proto_size.d.ts +6 -0
- package/lib/functional/$proto_size.js +76 -0
- package/lib/functional/$proto_size.js.map +1 -0
- package/lib/functional/$proto_string.d.ts +2 -0
- package/lib/functional/$proto_string.js +34 -0
- package/lib/functional/$proto_string.js.map +1 -0
- package/lib/functional/$varint.d.ts +6 -0
- package/lib/functional/$varint.js +99 -0
- package/lib/functional/$varint.js.map +1 -0
- package/lib/functional/$zigzag.d.ts +4 -0
- package/lib/functional/$zigzag.js +34 -0
- package/lib/functional/$zigzag.js.map +1 -0
- package/lib/messages/IProtocolMessage.d.ts +5 -0
- package/lib/messages/IProtocolMessage.js +3 -0
- package/lib/messages/IProtocolMessage.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +11 -0
- package/lib/messages/IProtocolProperty.js +3 -0
- package/lib/messages/IProtocolProperty.js.map +1 -0
- package/lib/metadata/IMetadataTag.d.ts +7 -3
- package/lib/metadata/Metadata.js +1 -1
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +5 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/MessageProgrammer.d.ts +5 -0
- package/lib/programmers/MessageProgrammer.js +134 -0
- package/lib/programmers/MessageProgrammer.js.map +1 -0
- 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 +5 -3
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +3 -1
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
- package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
- package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
- 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 +2 -3
- package/src/executable/internal/TypiaSetupWizard.ts +173 -173
- package/src/factories/MetadataCollection.ts +83 -122
- package/src/factories/MetadataFactory.ts +47 -47
- package/src/factories/MetadataTagFactory.ts +351 -351
- package/src/factories/ProtocolFactory.ts +92 -0
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/metadata/explore_metadata.ts +92 -92
- package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
- package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
- package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
- package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
- package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
- package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
- package/src/functional/$number.ts +12 -12
- package/src/functional/$proto_bytes.ts +25 -0
- package/src/functional/$proto_field.ts +30 -0
- package/src/functional/$proto_float.ts +37 -0
- package/src/functional/$proto_i32.ts +29 -0
- package/src/functional/$proto_i64.ts +37 -0
- package/src/functional/$proto_size.ts +82 -0
- package/src/functional/$proto_string.ts +24 -0
- package/src/functional/$varint.ts +130 -0
- package/src/functional/$zigzag.ts +39 -0
- package/src/messages/IProtocolMessage.ts +6 -0
- package/src/messages/IProtocolProperty.ts +11 -0
- package/src/metadata/IMetadataTag.ts +137 -122
- package/src/metadata/Metadata.ts +479 -477
- package/src/module.ts +1547 -1535
- package/src/programmers/AssertParseProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +445 -445
- package/src/programmers/AssertStringifyProgrammer.ts +65 -65
- package/src/programmers/CheckerProgrammer.ts +810 -810
- package/src/programmers/IsParseProgrammer.ts +61 -61
- package/src/programmers/IsProgrammer.ts +175 -175
- package/src/programmers/IsStringifyProgrammer.ts +69 -69
- package/src/programmers/MessageProgrammer.ts +116 -0
- package/src/programmers/StringifyProgrammer.ts +762 -762
- package/src/programmers/ValidateParseProgrammer.ts +59 -59
- package/src/programmers/ValidateProgrammer.ts +237 -237
- package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_object.ts +5 -5
- package/src/programmers/internal/application_schema.ts +231 -228
- package/src/programmers/internal/check_bigint.ts +85 -85
- package/src/programmers/internal/check_number.ts +175 -175
- package/src/schemas/IJsonSchema.ts +90 -90
- package/src/transformers/CallExpressionTransformer.ts +131 -124
- package/src/transformers/ITransformOptions.ts +47 -47
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
- package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
- package/src/utils/NameEncoder.ts +32 -0
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../factories/StatementFactory";
|
|
5
|
-
|
|
6
|
-
import { IProject } from "../transformers/IProject";
|
|
7
|
-
|
|
8
|
-
import { ValidateProgrammer } from "./ValidateProgrammer";
|
|
9
|
-
|
|
10
|
-
export namespace ValidateParseProgrammer {
|
|
11
|
-
export const generate =
|
|
12
|
-
(project: IProject, modulo: ts.LeftHandSideExpression) =>
|
|
13
|
-
(type: ts.Type) =>
|
|
14
|
-
ts.factory.createArrowFunction(
|
|
15
|
-
undefined,
|
|
16
|
-
undefined,
|
|
17
|
-
[IdentifierFactory.parameter("input")],
|
|
18
|
-
undefined,
|
|
19
|
-
undefined,
|
|
20
|
-
ts.factory.createBlock([
|
|
21
|
-
StatementFactory.constant(
|
|
22
|
-
"validate",
|
|
23
|
-
ValidateProgrammer.generate(
|
|
24
|
-
{
|
|
25
|
-
...project,
|
|
26
|
-
options: {
|
|
27
|
-
...project.options,
|
|
28
|
-
functional: false,
|
|
29
|
-
numeric: false,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
modulo,
|
|
33
|
-
)(type),
|
|
34
|
-
),
|
|
35
|
-
ts.factory.createExpressionStatement(
|
|
36
|
-
ts.factory.createBinaryExpression(
|
|
37
|
-
ts.factory.createIdentifier("input"),
|
|
38
|
-
ts.SyntaxKind.EqualsToken,
|
|
39
|
-
ts.factory.createCallExpression(
|
|
40
|
-
ts.factory.createIdentifier("JSON.parse"),
|
|
41
|
-
undefined,
|
|
42
|
-
[ts.factory.createIdentifier("input")],
|
|
43
|
-
),
|
|
44
|
-
),
|
|
45
|
-
),
|
|
46
|
-
StatementFactory.constant(
|
|
47
|
-
"output",
|
|
48
|
-
ts.factory.createCallExpression(
|
|
49
|
-
ts.factory.createIdentifier("validate"),
|
|
50
|
-
undefined,
|
|
51
|
-
[ts.factory.createIdentifier("input")],
|
|
52
|
-
),
|
|
53
|
-
),
|
|
54
|
-
ts.factory.createReturnStatement(
|
|
55
|
-
ts.factory.createIdentifier("output"),
|
|
56
|
-
),
|
|
57
|
-
]),
|
|
58
|
-
);
|
|
59
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../factories/StatementFactory";
|
|
5
|
+
|
|
6
|
+
import { IProject } from "../transformers/IProject";
|
|
7
|
+
|
|
8
|
+
import { ValidateProgrammer } from "./ValidateProgrammer";
|
|
9
|
+
|
|
10
|
+
export namespace ValidateParseProgrammer {
|
|
11
|
+
export const generate =
|
|
12
|
+
(project: IProject, modulo: ts.LeftHandSideExpression) =>
|
|
13
|
+
(type: ts.Type) =>
|
|
14
|
+
ts.factory.createArrowFunction(
|
|
15
|
+
undefined,
|
|
16
|
+
undefined,
|
|
17
|
+
[IdentifierFactory.parameter("input")],
|
|
18
|
+
undefined,
|
|
19
|
+
undefined,
|
|
20
|
+
ts.factory.createBlock([
|
|
21
|
+
StatementFactory.constant(
|
|
22
|
+
"validate",
|
|
23
|
+
ValidateProgrammer.generate(
|
|
24
|
+
{
|
|
25
|
+
...project,
|
|
26
|
+
options: {
|
|
27
|
+
...project.options,
|
|
28
|
+
functional: false,
|
|
29
|
+
numeric: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
modulo,
|
|
33
|
+
)(type),
|
|
34
|
+
),
|
|
35
|
+
ts.factory.createExpressionStatement(
|
|
36
|
+
ts.factory.createBinaryExpression(
|
|
37
|
+
ts.factory.createIdentifier("input"),
|
|
38
|
+
ts.SyntaxKind.EqualsToken,
|
|
39
|
+
ts.factory.createCallExpression(
|
|
40
|
+
ts.factory.createIdentifier("JSON.parse"),
|
|
41
|
+
undefined,
|
|
42
|
+
[ts.factory.createIdentifier("input")],
|
|
43
|
+
),
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
StatementFactory.constant(
|
|
47
|
+
"output",
|
|
48
|
+
ts.factory.createCallExpression(
|
|
49
|
+
ts.factory.createIdentifier("validate"),
|
|
50
|
+
undefined,
|
|
51
|
+
[ts.factory.createIdentifier("input")],
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
ts.factory.createReturnStatement(
|
|
55
|
+
ts.factory.createIdentifier("output"),
|
|
56
|
+
),
|
|
57
|
+
]),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -1,237 +1,237 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../factories/StatementFactory";
|
|
5
|
-
|
|
6
|
-
import { IProject } from "../transformers/IProject";
|
|
7
|
-
|
|
8
|
-
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
9
|
-
import { IsProgrammer } from "./IsProgrammer";
|
|
10
|
-
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
11
|
-
import { OptionPredicator } from "./helpers/OptionPredicator";
|
|
12
|
-
import { check_everything } from "./internal/check_everything";
|
|
13
|
-
import { check_object } from "./internal/check_object";
|
|
14
|
-
|
|
15
|
-
export namespace ValidateProgrammer {
|
|
16
|
-
export const generate =
|
|
17
|
-
(
|
|
18
|
-
project: IProject,
|
|
19
|
-
modulo: ts.LeftHandSideExpression,
|
|
20
|
-
equals: boolean = false,
|
|
21
|
-
) =>
|
|
22
|
-
(type: ts.Type) => {
|
|
23
|
-
const importer: FunctionImporter = new FunctionImporter();
|
|
24
|
-
const program: ts.ArrowFunction = CheckerProgrammer.generate(
|
|
25
|
-
project,
|
|
26
|
-
{
|
|
27
|
-
functors: "$vo",
|
|
28
|
-
unioners: "$vu",
|
|
29
|
-
path: true,
|
|
30
|
-
trace: true,
|
|
31
|
-
numeric: OptionPredicator.numeric(project.options),
|
|
32
|
-
equals,
|
|
33
|
-
combiner: combine(equals)(importer),
|
|
34
|
-
joiner: joiner(equals)(importer),
|
|
35
|
-
success: ts.factory.createTrue(),
|
|
36
|
-
},
|
|
37
|
-
importer,
|
|
38
|
-
)(type);
|
|
39
|
-
|
|
40
|
-
return ts.factory.createArrowFunction(
|
|
41
|
-
undefined,
|
|
42
|
-
undefined,
|
|
43
|
-
[IdentifierFactory.parameter("input")],
|
|
44
|
-
undefined,
|
|
45
|
-
undefined,
|
|
46
|
-
ts.factory.createBlock(
|
|
47
|
-
[
|
|
48
|
-
StatementFactory.constant(
|
|
49
|
-
"errors",
|
|
50
|
-
ts.factory.createArrayLiteralExpression([]),
|
|
51
|
-
),
|
|
52
|
-
StatementFactory.constant(
|
|
53
|
-
"$report",
|
|
54
|
-
ts.factory.createCallExpression(
|
|
55
|
-
IdentifierFactory.join(modulo, "report"),
|
|
56
|
-
[],
|
|
57
|
-
[ts.factory.createIdentifier("errors")],
|
|
58
|
-
),
|
|
59
|
-
),
|
|
60
|
-
...importer.declare(modulo),
|
|
61
|
-
ts.factory.createExpressionStatement(
|
|
62
|
-
ts.factory.createCallExpression(
|
|
63
|
-
program,
|
|
64
|
-
undefined,
|
|
65
|
-
[
|
|
66
|
-
ts.factory.createIdentifier("input"),
|
|
67
|
-
ts.factory.createStringLiteral("$input"),
|
|
68
|
-
ts.factory.createTrue(),
|
|
69
|
-
],
|
|
70
|
-
),
|
|
71
|
-
),
|
|
72
|
-
StatementFactory.constant(
|
|
73
|
-
"success",
|
|
74
|
-
ts.factory.createStrictEquality(
|
|
75
|
-
ts.factory.createNumericLiteral(0),
|
|
76
|
-
ts.factory.createIdentifier("errors.length"),
|
|
77
|
-
),
|
|
78
|
-
),
|
|
79
|
-
ts.factory.createReturnStatement(create_output()),
|
|
80
|
-
],
|
|
81
|
-
true,
|
|
82
|
-
),
|
|
83
|
-
);
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const combine =
|
|
88
|
-
(equals: boolean) =>
|
|
89
|
-
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
90
|
-
(explore: CheckerProgrammer.IExplore) => {
|
|
91
|
-
if (explore.tracable === false && explore.from !== "top")
|
|
92
|
-
return IsProgrammer.CONFIG({
|
|
93
|
-
object: validate_object(equals)(importer),
|
|
94
|
-
numeric: true,
|
|
95
|
-
}).combiner(explore);
|
|
96
|
-
|
|
97
|
-
const path: string = explore.postfix
|
|
98
|
-
? `path + ${explore.postfix}`
|
|
99
|
-
: "path";
|
|
100
|
-
return (logic) => (input, binaries, expected) =>
|
|
101
|
-
logic === "and"
|
|
102
|
-
? binaries
|
|
103
|
-
.map((binary) =>
|
|
104
|
-
binary.combined
|
|
105
|
-
? binary.expression
|
|
106
|
-
: ts.factory.createLogicalOr(
|
|
107
|
-
binary.expression,
|
|
108
|
-
create_report_call(
|
|
109
|
-
explore.source === "top"
|
|
110
|
-
? ts.factory.createTrue()
|
|
111
|
-
: ts.factory.createIdentifier(
|
|
112
|
-
"exceptionable",
|
|
113
|
-
),
|
|
114
|
-
)(
|
|
115
|
-
ts.factory.createIdentifier(path),
|
|
116
|
-
expected,
|
|
117
|
-
input,
|
|
118
|
-
),
|
|
119
|
-
),
|
|
120
|
-
)
|
|
121
|
-
.reduce(ts.factory.createLogicalAnd)
|
|
122
|
-
: ts.factory.createLogicalOr(
|
|
123
|
-
binaries
|
|
124
|
-
.map((binary) => binary.expression)
|
|
125
|
-
.reduce(ts.factory.createLogicalOr),
|
|
126
|
-
create_report_call(
|
|
127
|
-
explore.source === "top"
|
|
128
|
-
? ts.factory.createTrue()
|
|
129
|
-
: ts.factory.createIdentifier("exceptionable"),
|
|
130
|
-
)(ts.factory.createIdentifier(path), expected, input),
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
|
|
135
|
-
check_object({
|
|
136
|
-
equals,
|
|
137
|
-
assert: false,
|
|
138
|
-
reduce: ts.factory.createLogicalAnd,
|
|
139
|
-
positive: ts.factory.createTrue(),
|
|
140
|
-
superfluous: (value) =>
|
|
141
|
-
create_report_call()(
|
|
142
|
-
ts.factory.createAdd(
|
|
143
|
-
ts.factory.createIdentifier("path"),
|
|
144
|
-
ts.factory.createCallExpression(
|
|
145
|
-
importer.use("join"),
|
|
146
|
-
undefined,
|
|
147
|
-
[ts.factory.createIdentifier("key")],
|
|
148
|
-
),
|
|
149
|
-
),
|
|
150
|
-
"undefined",
|
|
151
|
-
value,
|
|
152
|
-
),
|
|
153
|
-
halt: (expr) =>
|
|
154
|
-
ts.factory.createLogicalOr(
|
|
155
|
-
ts.factory.createStrictEquality(
|
|
156
|
-
ts.factory.createFalse(),
|
|
157
|
-
ts.factory.createIdentifier("exceptionable"),
|
|
158
|
-
),
|
|
159
|
-
expr,
|
|
160
|
-
),
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
const joiner =
|
|
164
|
-
(equals: boolean) =>
|
|
165
|
-
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
166
|
-
object: validate_object(equals)(importer),
|
|
167
|
-
array: (input, arrow) =>
|
|
168
|
-
check_everything(
|
|
169
|
-
ts.factory.createCallExpression(
|
|
170
|
-
IdentifierFactory.join(input, "map"),
|
|
171
|
-
undefined,
|
|
172
|
-
[arrow],
|
|
173
|
-
),
|
|
174
|
-
),
|
|
175
|
-
failure: (value, expected, explore) =>
|
|
176
|
-
create_report_call(
|
|
177
|
-
explore?.from === "top"
|
|
178
|
-
? ts.factory.createTrue()
|
|
179
|
-
: ts.factory.createIdentifier("exceptionable"),
|
|
180
|
-
)(
|
|
181
|
-
ts.factory.createIdentifier(
|
|
182
|
-
explore?.postfix ? `path + ${explore.postfix}` : "path",
|
|
183
|
-
),
|
|
184
|
-
expected,
|
|
185
|
-
value,
|
|
186
|
-
),
|
|
187
|
-
tuple: (binaries) =>
|
|
188
|
-
check_everything(
|
|
189
|
-
ts.factory.createArrayLiteralExpression(binaries, true),
|
|
190
|
-
),
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
function create_output() {
|
|
194
|
-
return ts.factory.createObjectLiteralExpression(
|
|
195
|
-
[
|
|
196
|
-
ts.factory.createShorthandPropertyAssignment("success"),
|
|
197
|
-
ts.factory.createShorthandPropertyAssignment("errors"),
|
|
198
|
-
ts.factory.createPropertyAssignment(
|
|
199
|
-
"data",
|
|
200
|
-
ts.factory.createConditionalExpression(
|
|
201
|
-
ts.factory.createIdentifier("success"),
|
|
202
|
-
undefined,
|
|
203
|
-
ts.factory.createIdentifier("input"),
|
|
204
|
-
undefined,
|
|
205
|
-
ts.factory.createIdentifier("undefined"),
|
|
206
|
-
),
|
|
207
|
-
),
|
|
208
|
-
],
|
|
209
|
-
true,
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const create_report_call =
|
|
214
|
-
(exceptionable?: ts.Expression) =>
|
|
215
|
-
(
|
|
216
|
-
path: ts.Expression,
|
|
217
|
-
expected: string,
|
|
218
|
-
value: ts.Expression,
|
|
219
|
-
): ts.Expression =>
|
|
220
|
-
ts.factory.createCallExpression(
|
|
221
|
-
ts.factory.createIdentifier("$report"),
|
|
222
|
-
undefined,
|
|
223
|
-
[
|
|
224
|
-
exceptionable || ts.factory.createIdentifier("exceptionable"),
|
|
225
|
-
ts.factory.createObjectLiteralExpression(
|
|
226
|
-
[
|
|
227
|
-
ts.factory.createPropertyAssignment("path", path),
|
|
228
|
-
ts.factory.createPropertyAssignment(
|
|
229
|
-
"expected",
|
|
230
|
-
ts.factory.createStringLiteral(expected),
|
|
231
|
-
),
|
|
232
|
-
ts.factory.createPropertyAssignment("value", value),
|
|
233
|
-
],
|
|
234
|
-
true,
|
|
235
|
-
),
|
|
236
|
-
],
|
|
237
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../factories/StatementFactory";
|
|
5
|
+
|
|
6
|
+
import { IProject } from "../transformers/IProject";
|
|
7
|
+
|
|
8
|
+
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
9
|
+
import { IsProgrammer } from "./IsProgrammer";
|
|
10
|
+
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
11
|
+
import { OptionPredicator } from "./helpers/OptionPredicator";
|
|
12
|
+
import { check_everything } from "./internal/check_everything";
|
|
13
|
+
import { check_object } from "./internal/check_object";
|
|
14
|
+
|
|
15
|
+
export namespace ValidateProgrammer {
|
|
16
|
+
export const generate =
|
|
17
|
+
(
|
|
18
|
+
project: IProject,
|
|
19
|
+
modulo: ts.LeftHandSideExpression,
|
|
20
|
+
equals: boolean = false,
|
|
21
|
+
) =>
|
|
22
|
+
(type: ts.Type) => {
|
|
23
|
+
const importer: FunctionImporter = new FunctionImporter();
|
|
24
|
+
const program: ts.ArrowFunction = CheckerProgrammer.generate(
|
|
25
|
+
project,
|
|
26
|
+
{
|
|
27
|
+
functors: "$vo",
|
|
28
|
+
unioners: "$vu",
|
|
29
|
+
path: true,
|
|
30
|
+
trace: true,
|
|
31
|
+
numeric: OptionPredicator.numeric(project.options),
|
|
32
|
+
equals,
|
|
33
|
+
combiner: combine(equals)(importer),
|
|
34
|
+
joiner: joiner(equals)(importer),
|
|
35
|
+
success: ts.factory.createTrue(),
|
|
36
|
+
},
|
|
37
|
+
importer,
|
|
38
|
+
)(type);
|
|
39
|
+
|
|
40
|
+
return ts.factory.createArrowFunction(
|
|
41
|
+
undefined,
|
|
42
|
+
undefined,
|
|
43
|
+
[IdentifierFactory.parameter("input")],
|
|
44
|
+
undefined,
|
|
45
|
+
undefined,
|
|
46
|
+
ts.factory.createBlock(
|
|
47
|
+
[
|
|
48
|
+
StatementFactory.constant(
|
|
49
|
+
"errors",
|
|
50
|
+
ts.factory.createArrayLiteralExpression([]),
|
|
51
|
+
),
|
|
52
|
+
StatementFactory.constant(
|
|
53
|
+
"$report",
|
|
54
|
+
ts.factory.createCallExpression(
|
|
55
|
+
IdentifierFactory.join(modulo, "report"),
|
|
56
|
+
[],
|
|
57
|
+
[ts.factory.createIdentifier("errors")],
|
|
58
|
+
),
|
|
59
|
+
),
|
|
60
|
+
...importer.declare(modulo),
|
|
61
|
+
ts.factory.createExpressionStatement(
|
|
62
|
+
ts.factory.createCallExpression(
|
|
63
|
+
program,
|
|
64
|
+
undefined,
|
|
65
|
+
[
|
|
66
|
+
ts.factory.createIdentifier("input"),
|
|
67
|
+
ts.factory.createStringLiteral("$input"),
|
|
68
|
+
ts.factory.createTrue(),
|
|
69
|
+
],
|
|
70
|
+
),
|
|
71
|
+
),
|
|
72
|
+
StatementFactory.constant(
|
|
73
|
+
"success",
|
|
74
|
+
ts.factory.createStrictEquality(
|
|
75
|
+
ts.factory.createNumericLiteral(0),
|
|
76
|
+
ts.factory.createIdentifier("errors.length"),
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
ts.factory.createReturnStatement(create_output()),
|
|
80
|
+
],
|
|
81
|
+
true,
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const combine =
|
|
88
|
+
(equals: boolean) =>
|
|
89
|
+
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
90
|
+
(explore: CheckerProgrammer.IExplore) => {
|
|
91
|
+
if (explore.tracable === false && explore.from !== "top")
|
|
92
|
+
return IsProgrammer.CONFIG({
|
|
93
|
+
object: validate_object(equals)(importer),
|
|
94
|
+
numeric: true,
|
|
95
|
+
}).combiner(explore);
|
|
96
|
+
|
|
97
|
+
const path: string = explore.postfix
|
|
98
|
+
? `path + ${explore.postfix}`
|
|
99
|
+
: "path";
|
|
100
|
+
return (logic) => (input, binaries, expected) =>
|
|
101
|
+
logic === "and"
|
|
102
|
+
? binaries
|
|
103
|
+
.map((binary) =>
|
|
104
|
+
binary.combined
|
|
105
|
+
? binary.expression
|
|
106
|
+
: ts.factory.createLogicalOr(
|
|
107
|
+
binary.expression,
|
|
108
|
+
create_report_call(
|
|
109
|
+
explore.source === "top"
|
|
110
|
+
? ts.factory.createTrue()
|
|
111
|
+
: ts.factory.createIdentifier(
|
|
112
|
+
"exceptionable",
|
|
113
|
+
),
|
|
114
|
+
)(
|
|
115
|
+
ts.factory.createIdentifier(path),
|
|
116
|
+
expected,
|
|
117
|
+
input,
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
.reduce(ts.factory.createLogicalAnd)
|
|
122
|
+
: ts.factory.createLogicalOr(
|
|
123
|
+
binaries
|
|
124
|
+
.map((binary) => binary.expression)
|
|
125
|
+
.reduce(ts.factory.createLogicalOr),
|
|
126
|
+
create_report_call(
|
|
127
|
+
explore.source === "top"
|
|
128
|
+
? ts.factory.createTrue()
|
|
129
|
+
: ts.factory.createIdentifier("exceptionable"),
|
|
130
|
+
)(ts.factory.createIdentifier(path), expected, input),
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const validate_object = (equals: boolean) => (importer: FunctionImporter) =>
|
|
135
|
+
check_object({
|
|
136
|
+
equals,
|
|
137
|
+
assert: false,
|
|
138
|
+
reduce: ts.factory.createLogicalAnd,
|
|
139
|
+
positive: ts.factory.createTrue(),
|
|
140
|
+
superfluous: (value) =>
|
|
141
|
+
create_report_call()(
|
|
142
|
+
ts.factory.createAdd(
|
|
143
|
+
ts.factory.createIdentifier("path"),
|
|
144
|
+
ts.factory.createCallExpression(
|
|
145
|
+
importer.use("join"),
|
|
146
|
+
undefined,
|
|
147
|
+
[ts.factory.createIdentifier("key")],
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
"undefined",
|
|
151
|
+
value,
|
|
152
|
+
),
|
|
153
|
+
halt: (expr) =>
|
|
154
|
+
ts.factory.createLogicalOr(
|
|
155
|
+
ts.factory.createStrictEquality(
|
|
156
|
+
ts.factory.createFalse(),
|
|
157
|
+
ts.factory.createIdentifier("exceptionable"),
|
|
158
|
+
),
|
|
159
|
+
expr,
|
|
160
|
+
),
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const joiner =
|
|
164
|
+
(equals: boolean) =>
|
|
165
|
+
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
166
|
+
object: validate_object(equals)(importer),
|
|
167
|
+
array: (input, arrow) =>
|
|
168
|
+
check_everything(
|
|
169
|
+
ts.factory.createCallExpression(
|
|
170
|
+
IdentifierFactory.join(input, "map"),
|
|
171
|
+
undefined,
|
|
172
|
+
[arrow],
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
failure: (value, expected, explore) =>
|
|
176
|
+
create_report_call(
|
|
177
|
+
explore?.from === "top"
|
|
178
|
+
? ts.factory.createTrue()
|
|
179
|
+
: ts.factory.createIdentifier("exceptionable"),
|
|
180
|
+
)(
|
|
181
|
+
ts.factory.createIdentifier(
|
|
182
|
+
explore?.postfix ? `path + ${explore.postfix}` : "path",
|
|
183
|
+
),
|
|
184
|
+
expected,
|
|
185
|
+
value,
|
|
186
|
+
),
|
|
187
|
+
tuple: (binaries) =>
|
|
188
|
+
check_everything(
|
|
189
|
+
ts.factory.createArrayLiteralExpression(binaries, true),
|
|
190
|
+
),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
function create_output() {
|
|
194
|
+
return ts.factory.createObjectLiteralExpression(
|
|
195
|
+
[
|
|
196
|
+
ts.factory.createShorthandPropertyAssignment("success"),
|
|
197
|
+
ts.factory.createShorthandPropertyAssignment("errors"),
|
|
198
|
+
ts.factory.createPropertyAssignment(
|
|
199
|
+
"data",
|
|
200
|
+
ts.factory.createConditionalExpression(
|
|
201
|
+
ts.factory.createIdentifier("success"),
|
|
202
|
+
undefined,
|
|
203
|
+
ts.factory.createIdentifier("input"),
|
|
204
|
+
undefined,
|
|
205
|
+
ts.factory.createIdentifier("undefined"),
|
|
206
|
+
),
|
|
207
|
+
),
|
|
208
|
+
],
|
|
209
|
+
true,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const create_report_call =
|
|
214
|
+
(exceptionable?: ts.Expression) =>
|
|
215
|
+
(
|
|
216
|
+
path: ts.Expression,
|
|
217
|
+
expected: string,
|
|
218
|
+
value: ts.Expression,
|
|
219
|
+
): ts.Expression =>
|
|
220
|
+
ts.factory.createCallExpression(
|
|
221
|
+
ts.factory.createIdentifier("$report"),
|
|
222
|
+
undefined,
|
|
223
|
+
[
|
|
224
|
+
exceptionable || ts.factory.createIdentifier("exceptionable"),
|
|
225
|
+
ts.factory.createObjectLiteralExpression(
|
|
226
|
+
[
|
|
227
|
+
ts.factory.createPropertyAssignment("path", path),
|
|
228
|
+
ts.factory.createPropertyAssignment(
|
|
229
|
+
"expected",
|
|
230
|
+
ts.factory.createStringLiteral(expected),
|
|
231
|
+
),
|
|
232
|
+
ts.factory.createPropertyAssignment("value", value),
|
|
233
|
+
],
|
|
234
|
+
true,
|
|
235
|
+
),
|
|
236
|
+
],
|
|
237
|
+
);
|