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,61 +1,61 @@
|
|
|
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 { IsProgrammer } from "./IsProgrammer";
|
|
9
|
-
|
|
10
|
-
export namespace IsParseProgrammer {
|
|
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
|
-
"is",
|
|
23
|
-
IsProgrammer.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
|
-
ts.factory.createReturnStatement(
|
|
47
|
-
ts.factory.createConditionalExpression(
|
|
48
|
-
ts.factory.createCallExpression(
|
|
49
|
-
ts.factory.createIdentifier("is"),
|
|
50
|
-
undefined,
|
|
51
|
-
[ts.factory.createIdentifier("input")],
|
|
52
|
-
),
|
|
53
|
-
undefined,
|
|
54
|
-
ts.factory.createIdentifier("input"),
|
|
55
|
-
undefined,
|
|
56
|
-
ts.factory.createNull(),
|
|
57
|
-
),
|
|
58
|
-
),
|
|
59
|
-
]),
|
|
60
|
-
);
|
|
61
|
-
}
|
|
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 { IsProgrammer } from "./IsProgrammer";
|
|
9
|
+
|
|
10
|
+
export namespace IsParseProgrammer {
|
|
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
|
+
"is",
|
|
23
|
+
IsProgrammer.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
|
+
ts.factory.createReturnStatement(
|
|
47
|
+
ts.factory.createConditionalExpression(
|
|
48
|
+
ts.factory.createCallExpression(
|
|
49
|
+
ts.factory.createIdentifier("is"),
|
|
50
|
+
undefined,
|
|
51
|
+
[ts.factory.createIdentifier("input")],
|
|
52
|
+
),
|
|
53
|
+
undefined,
|
|
54
|
+
ts.factory.createIdentifier("input"),
|
|
55
|
+
undefined,
|
|
56
|
+
ts.factory.createNull(),
|
|
57
|
+
),
|
|
58
|
+
),
|
|
59
|
+
]),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -1,175 +1,175 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../factories/ExpressionFactory";
|
|
4
|
-
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
5
|
-
import { ValueFactory } from "../factories/ValueFactory";
|
|
6
|
-
|
|
7
|
-
import { MetadataObject } from "../metadata/MetadataObject";
|
|
8
|
-
|
|
9
|
-
import { IProject } from "../transformers/IProject";
|
|
10
|
-
|
|
11
|
-
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
12
|
-
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
13
|
-
import { IExpressionEntry } from "./helpers/IExpressionEntry";
|
|
14
|
-
import { OptionPredicator } from "./helpers/OptionPredicator";
|
|
15
|
-
import { check_object } from "./internal/check_object";
|
|
16
|
-
import { feature_object_entries } from "./internal/feature_object_entries";
|
|
17
|
-
|
|
18
|
-
export namespace IsProgrammer {
|
|
19
|
-
export const CONFIG = (
|
|
20
|
-
options?: Partial<CONFIG.IOptions>,
|
|
21
|
-
): CheckerProgrammer.IConfig => ({
|
|
22
|
-
functors: "$io",
|
|
23
|
-
unioners: "$iu",
|
|
24
|
-
trace: false,
|
|
25
|
-
path: false,
|
|
26
|
-
equals: !!options?.object,
|
|
27
|
-
numeric: OptionPredicator.numeric({
|
|
28
|
-
numeric: options?.numeric,
|
|
29
|
-
}),
|
|
30
|
-
combiner: () => (type: "and" | "or") => {
|
|
31
|
-
const initial: ts.TrueLiteral | ts.FalseLiteral =
|
|
32
|
-
type === "and"
|
|
33
|
-
? ts.factory.createTrue()
|
|
34
|
-
: ts.factory.createFalse();
|
|
35
|
-
const binder =
|
|
36
|
-
type === "and"
|
|
37
|
-
? ts.factory.createLogicalAnd
|
|
38
|
-
: ts.factory.createLogicalOr;
|
|
39
|
-
return (
|
|
40
|
-
_input: ts.Expression,
|
|
41
|
-
binaries: CheckerProgrammer.IBinary[],
|
|
42
|
-
) =>
|
|
43
|
-
binaries.length
|
|
44
|
-
? binaries
|
|
45
|
-
.map((binary) => binary.expression)
|
|
46
|
-
.reduce((x, y) => binder(x, y))
|
|
47
|
-
: initial;
|
|
48
|
-
},
|
|
49
|
-
joiner: {
|
|
50
|
-
object:
|
|
51
|
-
options?.object ||
|
|
52
|
-
check_object({
|
|
53
|
-
equals: !!options?.object,
|
|
54
|
-
assert: true,
|
|
55
|
-
reduce: ts.factory.createLogicalAnd,
|
|
56
|
-
positive: ts.factory.createTrue(),
|
|
57
|
-
superfluous: () => ts.factory.createFalse(),
|
|
58
|
-
}),
|
|
59
|
-
array: (input, arrow) =>
|
|
60
|
-
ts.factory.createCallExpression(
|
|
61
|
-
IdentifierFactory.join(input, "every"),
|
|
62
|
-
undefined,
|
|
63
|
-
[arrow],
|
|
64
|
-
),
|
|
65
|
-
failure: () => ts.factory.createFalse(),
|
|
66
|
-
},
|
|
67
|
-
success: ts.factory.createTrue(),
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
export namespace CONFIG {
|
|
71
|
-
export interface IOptions {
|
|
72
|
-
numeric: boolean;
|
|
73
|
-
object: (entries: IExpressionEntry[]) => ts.Expression;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/* -----------------------------------------------------------
|
|
78
|
-
GENERATORS
|
|
79
|
-
----------------------------------------------------------- */
|
|
80
|
-
export function generate(
|
|
81
|
-
project: IProject,
|
|
82
|
-
modulo: ts.LeftHandSideExpression,
|
|
83
|
-
equals: boolean = false,
|
|
84
|
-
) {
|
|
85
|
-
const importer: FunctionImporter = new FunctionImporter();
|
|
86
|
-
|
|
87
|
-
// CONFIGURATION
|
|
88
|
-
const config = CONFIG({
|
|
89
|
-
object: check_object({
|
|
90
|
-
equals,
|
|
91
|
-
assert: true,
|
|
92
|
-
reduce: ts.factory.createLogicalAnd,
|
|
93
|
-
positive: ts.factory.createTrue(),
|
|
94
|
-
superfluous: () => ts.factory.createFalse(),
|
|
95
|
-
}),
|
|
96
|
-
numeric: OptionPredicator.numeric(project.options),
|
|
97
|
-
});
|
|
98
|
-
config.trace = equals;
|
|
99
|
-
|
|
100
|
-
if (equals === false)
|
|
101
|
-
config.decoder = (input, target, explore, tags) => {
|
|
102
|
-
if (
|
|
103
|
-
target.size() === 1 &&
|
|
104
|
-
target.objects.length === 1 &&
|
|
105
|
-
target.required === true &&
|
|
106
|
-
target.nullable === false
|
|
107
|
-
) {
|
|
108
|
-
// ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
|
|
109
|
-
const obj: MetadataObject = target.objects[0]!;
|
|
110
|
-
if (obj._Is_simple())
|
|
111
|
-
return ts.factory.createLogicalAnd(
|
|
112
|
-
ExpressionFactory.isObject(input, {
|
|
113
|
-
checkNull: true,
|
|
114
|
-
checkArray: false,
|
|
115
|
-
}),
|
|
116
|
-
config.joiner.object(
|
|
117
|
-
feature_object_entries(config as any)(obj)(
|
|
118
|
-
input,
|
|
119
|
-
),
|
|
120
|
-
),
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
return CheckerProgrammer.decode(project, config, importer)(
|
|
124
|
-
input,
|
|
125
|
-
target,
|
|
126
|
-
explore,
|
|
127
|
-
tags,
|
|
128
|
-
);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// GENERATE CHECKER
|
|
132
|
-
return CheckerProgrammer.generate(project, config, importer, () =>
|
|
133
|
-
importer.declare(modulo),
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export const generate_functors = (
|
|
138
|
-
project: IProject,
|
|
139
|
-
importer: FunctionImporter,
|
|
140
|
-
) => CheckerProgrammer.generate_functors(project, CONFIG(), importer);
|
|
141
|
-
|
|
142
|
-
export const generate_unioners = (
|
|
143
|
-
project: IProject,
|
|
144
|
-
importer: FunctionImporter,
|
|
145
|
-
) => CheckerProgrammer.generate_unioners(project, CONFIG(), importer);
|
|
146
|
-
|
|
147
|
-
/* -----------------------------------------------------------
|
|
148
|
-
DECODERS
|
|
149
|
-
----------------------------------------------------------- */
|
|
150
|
-
export const decode = (project: IProject, importer: FunctionImporter) =>
|
|
151
|
-
CheckerProgrammer.decode(project, CONFIG(), importer);
|
|
152
|
-
|
|
153
|
-
export const decode_object = () =>
|
|
154
|
-
CheckerProgrammer.decode_object(CONFIG());
|
|
155
|
-
|
|
156
|
-
export function decode_to_json(input: ts.Expression): ts.Expression {
|
|
157
|
-
return ts.factory.createLogicalAnd(
|
|
158
|
-
ts.factory.createStrictEquality(
|
|
159
|
-
ts.factory.createStringLiteral("object"),
|
|
160
|
-
ValueFactory.TYPEOF(input),
|
|
161
|
-
),
|
|
162
|
-
ts.factory.createStrictEquality(
|
|
163
|
-
ts.factory.createStringLiteral("function"),
|
|
164
|
-
ValueFactory.TYPEOF(IdentifierFactory.join(input, "toJSON")),
|
|
165
|
-
),
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function decode_functional(input: ts.Expression) {
|
|
170
|
-
return ts.factory.createStrictEquality(
|
|
171
|
-
ts.factory.createStringLiteral("function"),
|
|
172
|
-
ValueFactory.TYPEOF(input),
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../factories/ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
5
|
+
import { ValueFactory } from "../factories/ValueFactory";
|
|
6
|
+
|
|
7
|
+
import { MetadataObject } from "../metadata/MetadataObject";
|
|
8
|
+
|
|
9
|
+
import { IProject } from "../transformers/IProject";
|
|
10
|
+
|
|
11
|
+
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
12
|
+
import { FunctionImporter } from "./helpers/FunctionImporeter";
|
|
13
|
+
import { IExpressionEntry } from "./helpers/IExpressionEntry";
|
|
14
|
+
import { OptionPredicator } from "./helpers/OptionPredicator";
|
|
15
|
+
import { check_object } from "./internal/check_object";
|
|
16
|
+
import { feature_object_entries } from "./internal/feature_object_entries";
|
|
17
|
+
|
|
18
|
+
export namespace IsProgrammer {
|
|
19
|
+
export const CONFIG = (
|
|
20
|
+
options?: Partial<CONFIG.IOptions>,
|
|
21
|
+
): CheckerProgrammer.IConfig => ({
|
|
22
|
+
functors: "$io",
|
|
23
|
+
unioners: "$iu",
|
|
24
|
+
trace: false,
|
|
25
|
+
path: false,
|
|
26
|
+
equals: !!options?.object,
|
|
27
|
+
numeric: OptionPredicator.numeric({
|
|
28
|
+
numeric: options?.numeric,
|
|
29
|
+
}),
|
|
30
|
+
combiner: () => (type: "and" | "or") => {
|
|
31
|
+
const initial: ts.TrueLiteral | ts.FalseLiteral =
|
|
32
|
+
type === "and"
|
|
33
|
+
? ts.factory.createTrue()
|
|
34
|
+
: ts.factory.createFalse();
|
|
35
|
+
const binder =
|
|
36
|
+
type === "and"
|
|
37
|
+
? ts.factory.createLogicalAnd
|
|
38
|
+
: ts.factory.createLogicalOr;
|
|
39
|
+
return (
|
|
40
|
+
_input: ts.Expression,
|
|
41
|
+
binaries: CheckerProgrammer.IBinary[],
|
|
42
|
+
) =>
|
|
43
|
+
binaries.length
|
|
44
|
+
? binaries
|
|
45
|
+
.map((binary) => binary.expression)
|
|
46
|
+
.reduce((x, y) => binder(x, y))
|
|
47
|
+
: initial;
|
|
48
|
+
},
|
|
49
|
+
joiner: {
|
|
50
|
+
object:
|
|
51
|
+
options?.object ||
|
|
52
|
+
check_object({
|
|
53
|
+
equals: !!options?.object,
|
|
54
|
+
assert: true,
|
|
55
|
+
reduce: ts.factory.createLogicalAnd,
|
|
56
|
+
positive: ts.factory.createTrue(),
|
|
57
|
+
superfluous: () => ts.factory.createFalse(),
|
|
58
|
+
}),
|
|
59
|
+
array: (input, arrow) =>
|
|
60
|
+
ts.factory.createCallExpression(
|
|
61
|
+
IdentifierFactory.join(input, "every"),
|
|
62
|
+
undefined,
|
|
63
|
+
[arrow],
|
|
64
|
+
),
|
|
65
|
+
failure: () => ts.factory.createFalse(),
|
|
66
|
+
},
|
|
67
|
+
success: ts.factory.createTrue(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export namespace CONFIG {
|
|
71
|
+
export interface IOptions {
|
|
72
|
+
numeric: boolean;
|
|
73
|
+
object: (entries: IExpressionEntry[]) => ts.Expression;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* -----------------------------------------------------------
|
|
78
|
+
GENERATORS
|
|
79
|
+
----------------------------------------------------------- */
|
|
80
|
+
export function generate(
|
|
81
|
+
project: IProject,
|
|
82
|
+
modulo: ts.LeftHandSideExpression,
|
|
83
|
+
equals: boolean = false,
|
|
84
|
+
) {
|
|
85
|
+
const importer: FunctionImporter = new FunctionImporter();
|
|
86
|
+
|
|
87
|
+
// CONFIGURATION
|
|
88
|
+
const config = CONFIG({
|
|
89
|
+
object: check_object({
|
|
90
|
+
equals,
|
|
91
|
+
assert: true,
|
|
92
|
+
reduce: ts.factory.createLogicalAnd,
|
|
93
|
+
positive: ts.factory.createTrue(),
|
|
94
|
+
superfluous: () => ts.factory.createFalse(),
|
|
95
|
+
}),
|
|
96
|
+
numeric: OptionPredicator.numeric(project.options),
|
|
97
|
+
});
|
|
98
|
+
config.trace = equals;
|
|
99
|
+
|
|
100
|
+
if (equals === false)
|
|
101
|
+
config.decoder = (input, target, explore, tags) => {
|
|
102
|
+
if (
|
|
103
|
+
target.size() === 1 &&
|
|
104
|
+
target.objects.length === 1 &&
|
|
105
|
+
target.required === true &&
|
|
106
|
+
target.nullable === false
|
|
107
|
+
) {
|
|
108
|
+
// ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
|
|
109
|
+
const obj: MetadataObject = target.objects[0]!;
|
|
110
|
+
if (obj._Is_simple())
|
|
111
|
+
return ts.factory.createLogicalAnd(
|
|
112
|
+
ExpressionFactory.isObject(input, {
|
|
113
|
+
checkNull: true,
|
|
114
|
+
checkArray: false,
|
|
115
|
+
}),
|
|
116
|
+
config.joiner.object(
|
|
117
|
+
feature_object_entries(config as any)(obj)(
|
|
118
|
+
input,
|
|
119
|
+
),
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return CheckerProgrammer.decode(project, config, importer)(
|
|
124
|
+
input,
|
|
125
|
+
target,
|
|
126
|
+
explore,
|
|
127
|
+
tags,
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// GENERATE CHECKER
|
|
132
|
+
return CheckerProgrammer.generate(project, config, importer, () =>
|
|
133
|
+
importer.declare(modulo),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const generate_functors = (
|
|
138
|
+
project: IProject,
|
|
139
|
+
importer: FunctionImporter,
|
|
140
|
+
) => CheckerProgrammer.generate_functors(project, CONFIG(), importer);
|
|
141
|
+
|
|
142
|
+
export const generate_unioners = (
|
|
143
|
+
project: IProject,
|
|
144
|
+
importer: FunctionImporter,
|
|
145
|
+
) => CheckerProgrammer.generate_unioners(project, CONFIG(), importer);
|
|
146
|
+
|
|
147
|
+
/* -----------------------------------------------------------
|
|
148
|
+
DECODERS
|
|
149
|
+
----------------------------------------------------------- */
|
|
150
|
+
export const decode = (project: IProject, importer: FunctionImporter) =>
|
|
151
|
+
CheckerProgrammer.decode(project, CONFIG(), importer);
|
|
152
|
+
|
|
153
|
+
export const decode_object = () =>
|
|
154
|
+
CheckerProgrammer.decode_object(CONFIG());
|
|
155
|
+
|
|
156
|
+
export function decode_to_json(input: ts.Expression): ts.Expression {
|
|
157
|
+
return ts.factory.createLogicalAnd(
|
|
158
|
+
ts.factory.createStrictEquality(
|
|
159
|
+
ts.factory.createStringLiteral("object"),
|
|
160
|
+
ValueFactory.TYPEOF(input),
|
|
161
|
+
),
|
|
162
|
+
ts.factory.createStrictEquality(
|
|
163
|
+
ts.factory.createStringLiteral("function"),
|
|
164
|
+
ValueFactory.TYPEOF(IdentifierFactory.join(input, "toJSON")),
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function decode_functional(input: ts.Expression) {
|
|
170
|
+
return ts.factory.createStrictEquality(
|
|
171
|
+
ts.factory.createStringLiteral("function"),
|
|
172
|
+
ValueFactory.TYPEOF(input),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -1,69 +1,69 @@
|
|
|
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 { IsProgrammer } from "./IsProgrammer";
|
|
9
|
-
import { StringifyProgrammer } from "./StringifyProgrammer";
|
|
10
|
-
|
|
11
|
-
export namespace IsStringifyProgrammer {
|
|
12
|
-
export const generate =
|
|
13
|
-
(project: IProject, modulo: ts.LeftHandSideExpression) =>
|
|
14
|
-
(type: ts.Type) =>
|
|
15
|
-
ts.factory.createArrowFunction(
|
|
16
|
-
undefined,
|
|
17
|
-
undefined,
|
|
18
|
-
[IdentifierFactory.parameter("input")],
|
|
19
|
-
undefined,
|
|
20
|
-
undefined,
|
|
21
|
-
ts.factory.createBlock([
|
|
22
|
-
StatementFactory.constant(
|
|
23
|
-
"is",
|
|
24
|
-
IsProgrammer.generate(
|
|
25
|
-
{
|
|
26
|
-
...project,
|
|
27
|
-
options: {
|
|
28
|
-
...project.options,
|
|
29
|
-
functional: false,
|
|
30
|
-
numeric: true,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
modulo,
|
|
34
|
-
)(type),
|
|
35
|
-
),
|
|
36
|
-
StatementFactory.constant(
|
|
37
|
-
"stringify",
|
|
38
|
-
StringifyProgrammer.generate(
|
|
39
|
-
{
|
|
40
|
-
...project,
|
|
41
|
-
options: {
|
|
42
|
-
...project.options,
|
|
43
|
-
functional: false,
|
|
44
|
-
numeric: false,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
modulo,
|
|
48
|
-
)(type),
|
|
49
|
-
),
|
|
50
|
-
ts.factory.createReturnStatement(
|
|
51
|
-
ts.factory.createConditionalExpression(
|
|
52
|
-
ts.factory.createCallExpression(
|
|
53
|
-
ts.factory.createIdentifier("is"),
|
|
54
|
-
undefined,
|
|
55
|
-
[ts.factory.createIdentifier("input")],
|
|
56
|
-
),
|
|
57
|
-
undefined,
|
|
58
|
-
ts.factory.createCallExpression(
|
|
59
|
-
ts.factory.createIdentifier("stringify"),
|
|
60
|
-
undefined,
|
|
61
|
-
[ts.factory.createIdentifier("input")],
|
|
62
|
-
),
|
|
63
|
-
undefined,
|
|
64
|
-
ts.factory.createNull(),
|
|
65
|
-
),
|
|
66
|
-
),
|
|
67
|
-
]),
|
|
68
|
-
);
|
|
69
|
-
}
|
|
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 { IsProgrammer } from "./IsProgrammer";
|
|
9
|
+
import { StringifyProgrammer } from "./StringifyProgrammer";
|
|
10
|
+
|
|
11
|
+
export namespace IsStringifyProgrammer {
|
|
12
|
+
export const generate =
|
|
13
|
+
(project: IProject, modulo: ts.LeftHandSideExpression) =>
|
|
14
|
+
(type: ts.Type) =>
|
|
15
|
+
ts.factory.createArrowFunction(
|
|
16
|
+
undefined,
|
|
17
|
+
undefined,
|
|
18
|
+
[IdentifierFactory.parameter("input")],
|
|
19
|
+
undefined,
|
|
20
|
+
undefined,
|
|
21
|
+
ts.factory.createBlock([
|
|
22
|
+
StatementFactory.constant(
|
|
23
|
+
"is",
|
|
24
|
+
IsProgrammer.generate(
|
|
25
|
+
{
|
|
26
|
+
...project,
|
|
27
|
+
options: {
|
|
28
|
+
...project.options,
|
|
29
|
+
functional: false,
|
|
30
|
+
numeric: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
modulo,
|
|
34
|
+
)(type),
|
|
35
|
+
),
|
|
36
|
+
StatementFactory.constant(
|
|
37
|
+
"stringify",
|
|
38
|
+
StringifyProgrammer.generate(
|
|
39
|
+
{
|
|
40
|
+
...project,
|
|
41
|
+
options: {
|
|
42
|
+
...project.options,
|
|
43
|
+
functional: false,
|
|
44
|
+
numeric: false,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
modulo,
|
|
48
|
+
)(type),
|
|
49
|
+
),
|
|
50
|
+
ts.factory.createReturnStatement(
|
|
51
|
+
ts.factory.createConditionalExpression(
|
|
52
|
+
ts.factory.createCallExpression(
|
|
53
|
+
ts.factory.createIdentifier("is"),
|
|
54
|
+
undefined,
|
|
55
|
+
[ts.factory.createIdentifier("input")],
|
|
56
|
+
),
|
|
57
|
+
undefined,
|
|
58
|
+
ts.factory.createCallExpression(
|
|
59
|
+
ts.factory.createIdentifier("stringify"),
|
|
60
|
+
undefined,
|
|
61
|
+
[ts.factory.createIdentifier("input")],
|
|
62
|
+
),
|
|
63
|
+
undefined,
|
|
64
|
+
ts.factory.createNull(),
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
]),
|
|
68
|
+
);
|
|
69
|
+
}
|