typia 3.4.13 → 3.4.14
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 +9 -8
- package/lib/factories/internal/iterate_metadata_object.js +4 -2
- package/lib/factories/internal/iterate_metadata_object.js.map +1 -1
- package/package.json +1 -1
- 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 +175 -175
- package/src/executable/typia.ts +46 -46
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/MetadataCollection.ts +122 -122
- package/src/factories/MetadataFactory.ts +46 -46
- package/src/factories/MetadataTagFactory.ts +347 -347
- 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/MetadataHelper.ts +12 -12
- package/src/factories/internal/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/explore_metadata.ts +91 -91
- package/src/factories/internal/iterate_metadata.ts +80 -80
- package/src/factories/internal/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/iterate_metadata_object.ts +48 -45
- package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/iterate_metadata_union.ts +59 -59
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$number.ts +19 -19
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTag.ts +122 -122
- package/src/metadata/Metadata.ts +477 -477
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/module.ts +1535 -1535
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertParseProgrammer.ts +45 -45
- package/src/programmers/AssertProgrammer.ts +444 -444
- package/src/programmers/AssertStringifyProgrammer.ts +45 -45
- package/src/programmers/CheckerProgrammer.ts +804 -804
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +51 -51
- package/src/programmers/IsProgrammer.ts +172 -172
- package/src/programmers/IsStringifyProgrammer.ts +49 -49
- package/src/programmers/StringifyProgrammer.ts +756 -756
- package/src/programmers/ValidateParseProgrammer.ts +49 -49
- package/src/programmers/ValidateProgrammer.ts +236 -236
- package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +11 -11
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +437 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +103 -103
- package/src/programmers/internal/application_schema.ts +221 -221
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +25 -25
- package/src/programmers/internal/check_array.ts +44 -44
- package/src/programmers/internal/check_dynamic_properties.ts +146 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_number.ts +178 -178
- package/src/programmers/internal/check_object.ts +42 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +24 -24
- package/src/schemas/IJsonSchema.ts +92 -92
- package/src/transform.ts +20 -20
- package/src/transformers/CallExpressionTransformer.ts +124 -124
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +4 -4
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +36 -36
- 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,51 +1,51 @@
|
|
|
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(project, modulo)(type),
|
|
24
|
-
),
|
|
25
|
-
ts.factory.createExpressionStatement(
|
|
26
|
-
ts.factory.createBinaryExpression(
|
|
27
|
-
ts.factory.createIdentifier("input"),
|
|
28
|
-
ts.SyntaxKind.EqualsToken,
|
|
29
|
-
ts.factory.createCallExpression(
|
|
30
|
-
ts.factory.createIdentifier("JSON.parse"),
|
|
31
|
-
undefined,
|
|
32
|
-
[ts.factory.createIdentifier("input")],
|
|
33
|
-
),
|
|
34
|
-
),
|
|
35
|
-
),
|
|
36
|
-
ts.factory.createReturnStatement(
|
|
37
|
-
ts.factory.createConditionalExpression(
|
|
38
|
-
ts.factory.createCallExpression(
|
|
39
|
-
ts.factory.createIdentifier("is"),
|
|
40
|
-
undefined,
|
|
41
|
-
[ts.factory.createIdentifier("input")],
|
|
42
|
-
),
|
|
43
|
-
undefined,
|
|
44
|
-
ts.factory.createIdentifier("input"),
|
|
45
|
-
undefined,
|
|
46
|
-
ts.factory.createNull(),
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
]),
|
|
50
|
-
);
|
|
51
|
-
}
|
|
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(project, modulo)(type),
|
|
24
|
+
),
|
|
25
|
+
ts.factory.createExpressionStatement(
|
|
26
|
+
ts.factory.createBinaryExpression(
|
|
27
|
+
ts.factory.createIdentifier("input"),
|
|
28
|
+
ts.SyntaxKind.EqualsToken,
|
|
29
|
+
ts.factory.createCallExpression(
|
|
30
|
+
ts.factory.createIdentifier("JSON.parse"),
|
|
31
|
+
undefined,
|
|
32
|
+
[ts.factory.createIdentifier("input")],
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
),
|
|
36
|
+
ts.factory.createReturnStatement(
|
|
37
|
+
ts.factory.createConditionalExpression(
|
|
38
|
+
ts.factory.createCallExpression(
|
|
39
|
+
ts.factory.createIdentifier("is"),
|
|
40
|
+
undefined,
|
|
41
|
+
[ts.factory.createIdentifier("input")],
|
|
42
|
+
),
|
|
43
|
+
undefined,
|
|
44
|
+
ts.factory.createIdentifier("input"),
|
|
45
|
+
undefined,
|
|
46
|
+
ts.factory.createNull(),
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
]),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -1,172 +1,172 @@
|
|
|
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 { check_object } from "./internal/check_object";
|
|
15
|
-
import { feature_object_entries } from "./internal/feature_object_entries";
|
|
16
|
-
|
|
17
|
-
export namespace IsProgrammer {
|
|
18
|
-
export const CONFIG = (
|
|
19
|
-
options?: Partial<CONFIG.IOptions>,
|
|
20
|
-
): CheckerProgrammer.IConfig => ({
|
|
21
|
-
functors: "$io",
|
|
22
|
-
unioners: "$iu",
|
|
23
|
-
trace: false,
|
|
24
|
-
path: false,
|
|
25
|
-
equals: !!options?.object,
|
|
26
|
-
numeric: !!options?.numeric,
|
|
27
|
-
combiner: () => (type: "and" | "or") => {
|
|
28
|
-
const initial: ts.TrueLiteral | ts.FalseLiteral =
|
|
29
|
-
type === "and"
|
|
30
|
-
? ts.factory.createTrue()
|
|
31
|
-
: ts.factory.createFalse();
|
|
32
|
-
const binder =
|
|
33
|
-
type === "and"
|
|
34
|
-
? ts.factory.createLogicalAnd
|
|
35
|
-
: ts.factory.createLogicalOr;
|
|
36
|
-
return (
|
|
37
|
-
_input: ts.Expression,
|
|
38
|
-
binaries: CheckerProgrammer.IBinary[],
|
|
39
|
-
) =>
|
|
40
|
-
binaries.length
|
|
41
|
-
? binaries
|
|
42
|
-
.map((binary) => binary.expression)
|
|
43
|
-
.reduce((x, y) => binder(x, y))
|
|
44
|
-
: initial;
|
|
45
|
-
},
|
|
46
|
-
joiner: {
|
|
47
|
-
object:
|
|
48
|
-
options?.object ||
|
|
49
|
-
check_object({
|
|
50
|
-
equals: !!options?.object,
|
|
51
|
-
assert: true,
|
|
52
|
-
reduce: ts.factory.createLogicalAnd,
|
|
53
|
-
positive: ts.factory.createTrue(),
|
|
54
|
-
superfluous: () => ts.factory.createFalse(),
|
|
55
|
-
}),
|
|
56
|
-
array: (input, arrow) =>
|
|
57
|
-
ts.factory.createCallExpression(
|
|
58
|
-
IdentifierFactory.join(input, "every"),
|
|
59
|
-
undefined,
|
|
60
|
-
[arrow],
|
|
61
|
-
),
|
|
62
|
-
failure: () => ts.factory.createFalse(),
|
|
63
|
-
},
|
|
64
|
-
success: ts.factory.createTrue(),
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
export namespace CONFIG {
|
|
68
|
-
export interface IOptions {
|
|
69
|
-
numeric: boolean;
|
|
70
|
-
object: (entries: IExpressionEntry[]) => ts.Expression;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/* -----------------------------------------------------------
|
|
75
|
-
GENERATORS
|
|
76
|
-
----------------------------------------------------------- */
|
|
77
|
-
export function generate(
|
|
78
|
-
project: IProject,
|
|
79
|
-
modulo: ts.LeftHandSideExpression,
|
|
80
|
-
equals: boolean = false,
|
|
81
|
-
) {
|
|
82
|
-
const importer: FunctionImporter = new FunctionImporter();
|
|
83
|
-
|
|
84
|
-
// CONFIGURATION
|
|
85
|
-
const config = CONFIG({
|
|
86
|
-
object: check_object({
|
|
87
|
-
equals,
|
|
88
|
-
assert: true,
|
|
89
|
-
reduce: ts.factory.createLogicalAnd,
|
|
90
|
-
positive: ts.factory.createTrue(),
|
|
91
|
-
superfluous: () => ts.factory.createFalse(),
|
|
92
|
-
}),
|
|
93
|
-
numeric: !!project.options.numeric,
|
|
94
|
-
});
|
|
95
|
-
config.trace = equals;
|
|
96
|
-
|
|
97
|
-
if (equals === false)
|
|
98
|
-
config.decoder = (input, target, explore, tags) => {
|
|
99
|
-
if (
|
|
100
|
-
target.size() === 1 &&
|
|
101
|
-
target.objects.length === 1 &&
|
|
102
|
-
target.required === true &&
|
|
103
|
-
target.nullable === false
|
|
104
|
-
) {
|
|
105
|
-
// ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
|
|
106
|
-
const obj: MetadataObject = target.objects[0]!;
|
|
107
|
-
if (obj._Is_simple())
|
|
108
|
-
return ts.factory.createLogicalAnd(
|
|
109
|
-
ExpressionFactory.isObject(input, {
|
|
110
|
-
checkNull: true,
|
|
111
|
-
checkArray: false,
|
|
112
|
-
}),
|
|
113
|
-
config.joiner.object(
|
|
114
|
-
feature_object_entries(config as any)(obj)(
|
|
115
|
-
input,
|
|
116
|
-
),
|
|
117
|
-
),
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
return CheckerProgrammer.decode(project, config, importer)(
|
|
121
|
-
input,
|
|
122
|
-
target,
|
|
123
|
-
explore,
|
|
124
|
-
tags,
|
|
125
|
-
);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// GENERATE CHECKER
|
|
129
|
-
return CheckerProgrammer.generate(project, config, importer, () =>
|
|
130
|
-
importer.declare(modulo),
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export const generate_functors = (
|
|
135
|
-
project: IProject,
|
|
136
|
-
importer: FunctionImporter,
|
|
137
|
-
) => CheckerProgrammer.generate_functors(project, CONFIG(), importer);
|
|
138
|
-
|
|
139
|
-
export const generate_unioners = (
|
|
140
|
-
project: IProject,
|
|
141
|
-
importer: FunctionImporter,
|
|
142
|
-
) => CheckerProgrammer.generate_unioners(project, CONFIG(), importer);
|
|
143
|
-
|
|
144
|
-
/* -----------------------------------------------------------
|
|
145
|
-
DECODERS
|
|
146
|
-
----------------------------------------------------------- */
|
|
147
|
-
export const decode = (project: IProject, importer: FunctionImporter) =>
|
|
148
|
-
CheckerProgrammer.decode(project, CONFIG(), importer);
|
|
149
|
-
|
|
150
|
-
export const decode_object = () =>
|
|
151
|
-
CheckerProgrammer.decode_object(CONFIG());
|
|
152
|
-
|
|
153
|
-
export function decode_to_json(input: ts.Expression): ts.Expression {
|
|
154
|
-
return ts.factory.createLogicalAnd(
|
|
155
|
-
ts.factory.createStrictEquality(
|
|
156
|
-
ts.factory.createStringLiteral("object"),
|
|
157
|
-
ValueFactory.TYPEOF(input),
|
|
158
|
-
),
|
|
159
|
-
ts.factory.createStrictEquality(
|
|
160
|
-
ts.factory.createStringLiteral("function"),
|
|
161
|
-
ValueFactory.TYPEOF(IdentifierFactory.join(input, "toJSON")),
|
|
162
|
-
),
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export function decode_functional(input: ts.Expression) {
|
|
167
|
-
return ts.factory.createStrictEquality(
|
|
168
|
-
ts.factory.createStringLiteral("function"),
|
|
169
|
-
ValueFactory.TYPEOF(input),
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
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 { check_object } from "./internal/check_object";
|
|
15
|
+
import { feature_object_entries } from "./internal/feature_object_entries";
|
|
16
|
+
|
|
17
|
+
export namespace IsProgrammer {
|
|
18
|
+
export const CONFIG = (
|
|
19
|
+
options?: Partial<CONFIG.IOptions>,
|
|
20
|
+
): CheckerProgrammer.IConfig => ({
|
|
21
|
+
functors: "$io",
|
|
22
|
+
unioners: "$iu",
|
|
23
|
+
trace: false,
|
|
24
|
+
path: false,
|
|
25
|
+
equals: !!options?.object,
|
|
26
|
+
numeric: !!options?.numeric,
|
|
27
|
+
combiner: () => (type: "and" | "or") => {
|
|
28
|
+
const initial: ts.TrueLiteral | ts.FalseLiteral =
|
|
29
|
+
type === "and"
|
|
30
|
+
? ts.factory.createTrue()
|
|
31
|
+
: ts.factory.createFalse();
|
|
32
|
+
const binder =
|
|
33
|
+
type === "and"
|
|
34
|
+
? ts.factory.createLogicalAnd
|
|
35
|
+
: ts.factory.createLogicalOr;
|
|
36
|
+
return (
|
|
37
|
+
_input: ts.Expression,
|
|
38
|
+
binaries: CheckerProgrammer.IBinary[],
|
|
39
|
+
) =>
|
|
40
|
+
binaries.length
|
|
41
|
+
? binaries
|
|
42
|
+
.map((binary) => binary.expression)
|
|
43
|
+
.reduce((x, y) => binder(x, y))
|
|
44
|
+
: initial;
|
|
45
|
+
},
|
|
46
|
+
joiner: {
|
|
47
|
+
object:
|
|
48
|
+
options?.object ||
|
|
49
|
+
check_object({
|
|
50
|
+
equals: !!options?.object,
|
|
51
|
+
assert: true,
|
|
52
|
+
reduce: ts.factory.createLogicalAnd,
|
|
53
|
+
positive: ts.factory.createTrue(),
|
|
54
|
+
superfluous: () => ts.factory.createFalse(),
|
|
55
|
+
}),
|
|
56
|
+
array: (input, arrow) =>
|
|
57
|
+
ts.factory.createCallExpression(
|
|
58
|
+
IdentifierFactory.join(input, "every"),
|
|
59
|
+
undefined,
|
|
60
|
+
[arrow],
|
|
61
|
+
),
|
|
62
|
+
failure: () => ts.factory.createFalse(),
|
|
63
|
+
},
|
|
64
|
+
success: ts.factory.createTrue(),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export namespace CONFIG {
|
|
68
|
+
export interface IOptions {
|
|
69
|
+
numeric: boolean;
|
|
70
|
+
object: (entries: IExpressionEntry[]) => ts.Expression;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* -----------------------------------------------------------
|
|
75
|
+
GENERATORS
|
|
76
|
+
----------------------------------------------------------- */
|
|
77
|
+
export function generate(
|
|
78
|
+
project: IProject,
|
|
79
|
+
modulo: ts.LeftHandSideExpression,
|
|
80
|
+
equals: boolean = false,
|
|
81
|
+
) {
|
|
82
|
+
const importer: FunctionImporter = new FunctionImporter();
|
|
83
|
+
|
|
84
|
+
// CONFIGURATION
|
|
85
|
+
const config = CONFIG({
|
|
86
|
+
object: check_object({
|
|
87
|
+
equals,
|
|
88
|
+
assert: true,
|
|
89
|
+
reduce: ts.factory.createLogicalAnd,
|
|
90
|
+
positive: ts.factory.createTrue(),
|
|
91
|
+
superfluous: () => ts.factory.createFalse(),
|
|
92
|
+
}),
|
|
93
|
+
numeric: !!project.options.numeric,
|
|
94
|
+
});
|
|
95
|
+
config.trace = equals;
|
|
96
|
+
|
|
97
|
+
if (equals === false)
|
|
98
|
+
config.decoder = (input, target, explore, tags) => {
|
|
99
|
+
if (
|
|
100
|
+
target.size() === 1 &&
|
|
101
|
+
target.objects.length === 1 &&
|
|
102
|
+
target.required === true &&
|
|
103
|
+
target.nullable === false
|
|
104
|
+
) {
|
|
105
|
+
// ONLY WHEN OBJECT WITH SOME ATOMIC PROPERTIES
|
|
106
|
+
const obj: MetadataObject = target.objects[0]!;
|
|
107
|
+
if (obj._Is_simple())
|
|
108
|
+
return ts.factory.createLogicalAnd(
|
|
109
|
+
ExpressionFactory.isObject(input, {
|
|
110
|
+
checkNull: true,
|
|
111
|
+
checkArray: false,
|
|
112
|
+
}),
|
|
113
|
+
config.joiner.object(
|
|
114
|
+
feature_object_entries(config as any)(obj)(
|
|
115
|
+
input,
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return CheckerProgrammer.decode(project, config, importer)(
|
|
121
|
+
input,
|
|
122
|
+
target,
|
|
123
|
+
explore,
|
|
124
|
+
tags,
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// GENERATE CHECKER
|
|
129
|
+
return CheckerProgrammer.generate(project, config, importer, () =>
|
|
130
|
+
importer.declare(modulo),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const generate_functors = (
|
|
135
|
+
project: IProject,
|
|
136
|
+
importer: FunctionImporter,
|
|
137
|
+
) => CheckerProgrammer.generate_functors(project, CONFIG(), importer);
|
|
138
|
+
|
|
139
|
+
export const generate_unioners = (
|
|
140
|
+
project: IProject,
|
|
141
|
+
importer: FunctionImporter,
|
|
142
|
+
) => CheckerProgrammer.generate_unioners(project, CONFIG(), importer);
|
|
143
|
+
|
|
144
|
+
/* -----------------------------------------------------------
|
|
145
|
+
DECODERS
|
|
146
|
+
----------------------------------------------------------- */
|
|
147
|
+
export const decode = (project: IProject, importer: FunctionImporter) =>
|
|
148
|
+
CheckerProgrammer.decode(project, CONFIG(), importer);
|
|
149
|
+
|
|
150
|
+
export const decode_object = () =>
|
|
151
|
+
CheckerProgrammer.decode_object(CONFIG());
|
|
152
|
+
|
|
153
|
+
export function decode_to_json(input: ts.Expression): ts.Expression {
|
|
154
|
+
return ts.factory.createLogicalAnd(
|
|
155
|
+
ts.factory.createStrictEquality(
|
|
156
|
+
ts.factory.createStringLiteral("object"),
|
|
157
|
+
ValueFactory.TYPEOF(input),
|
|
158
|
+
),
|
|
159
|
+
ts.factory.createStrictEquality(
|
|
160
|
+
ts.factory.createStringLiteral("function"),
|
|
161
|
+
ValueFactory.TYPEOF(IdentifierFactory.join(input, "toJSON")),
|
|
162
|
+
),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function decode_functional(input: ts.Expression) {
|
|
167
|
+
return ts.factory.createStrictEquality(
|
|
168
|
+
ts.factory.createStringLiteral("function"),
|
|
169
|
+
ValueFactory.TYPEOF(input),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
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(project, modulo)(type),
|
|
25
|
-
),
|
|
26
|
-
StatementFactory.constant(
|
|
27
|
-
"stringify",
|
|
28
|
-
StringifyProgrammer.generate(project, modulo)(type),
|
|
29
|
-
),
|
|
30
|
-
ts.factory.createReturnStatement(
|
|
31
|
-
ts.factory.createConditionalExpression(
|
|
32
|
-
ts.factory.createCallExpression(
|
|
33
|
-
ts.factory.createIdentifier("is"),
|
|
34
|
-
undefined,
|
|
35
|
-
[ts.factory.createIdentifier("input")],
|
|
36
|
-
),
|
|
37
|
-
undefined,
|
|
38
|
-
ts.factory.createCallExpression(
|
|
39
|
-
ts.factory.createIdentifier("stringify"),
|
|
40
|
-
undefined,
|
|
41
|
-
[ts.factory.createIdentifier("input")],
|
|
42
|
-
),
|
|
43
|
-
undefined,
|
|
44
|
-
ts.factory.createNull(),
|
|
45
|
-
),
|
|
46
|
-
),
|
|
47
|
-
]),
|
|
48
|
-
);
|
|
49
|
-
}
|
|
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(project, modulo)(type),
|
|
25
|
+
),
|
|
26
|
+
StatementFactory.constant(
|
|
27
|
+
"stringify",
|
|
28
|
+
StringifyProgrammer.generate(project, modulo)(type),
|
|
29
|
+
),
|
|
30
|
+
ts.factory.createReturnStatement(
|
|
31
|
+
ts.factory.createConditionalExpression(
|
|
32
|
+
ts.factory.createCallExpression(
|
|
33
|
+
ts.factory.createIdentifier("is"),
|
|
34
|
+
undefined,
|
|
35
|
+
[ts.factory.createIdentifier("input")],
|
|
36
|
+
),
|
|
37
|
+
undefined,
|
|
38
|
+
ts.factory.createCallExpression(
|
|
39
|
+
ts.factory.createIdentifier("stringify"),
|
|
40
|
+
undefined,
|
|
41
|
+
[ts.factory.createIdentifier("input")],
|
|
42
|
+
),
|
|
43
|
+
undefined,
|
|
44
|
+
ts.factory.createNull(),
|
|
45
|
+
),
|
|
46
|
+
),
|
|
47
|
+
]),
|
|
48
|
+
);
|
|
49
|
+
}
|