typia 3.4.21 → 3.4.23
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 +57 -23
- package/lib/programmers/AssertProgrammer.js +79 -70
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +1 -0
- package/lib/programmers/IsProgrammer.js +4 -0
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +68 -59
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
- package/lib/programmers/helpers/OptionPredicator.js +4 -0
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +23 -21
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +5 -0
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_object.d.ts +1 -0
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/transformers/ITransformOptions.d.ts +10 -0
- package/package.json +2 -2
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/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/functional/$every.ts +11 -11
- 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/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +36 -29
- package/src/programmers/IsProgrammer.ts +5 -0
- package/src/programmers/ValidateProgrammer.ts +36 -29
- 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 +4 -0
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +47 -47
- 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_schema.ts +9 -6
- 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 -29
- package/src/programmers/internal/check_dynamic_properties.ts +164 -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 +43 -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 +26 -26
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +11 -0
- package/src/transformers/NodeTransformer.ts +19 -19
- 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
|
@@ -4,6 +4,7 @@ import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
|
4
4
|
|
|
5
5
|
// import { StatementFactory } from "../factories/StatementFactory";
|
|
6
6
|
import { IProject } from "../transformers/IProject";
|
|
7
|
+
import { ITransformOptions } from "../transformers/ITransformOptions";
|
|
7
8
|
|
|
8
9
|
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
9
10
|
import { IsProgrammer } from "./IsProgrammer";
|
|
@@ -240,8 +241,8 @@ export namespace AssertProgrammer {
|
|
|
240
241
|
trace: true,
|
|
241
242
|
numeric: OptionPredicator.numeric(project.options),
|
|
242
243
|
equals,
|
|
243
|
-
combiner: combiner(equals)(importer),
|
|
244
|
-
joiner: joiner(equals)(importer),
|
|
244
|
+
combiner: combiner(project.options)(equals)(importer),
|
|
245
|
+
joiner: joiner(project.options)(equals)(importer),
|
|
245
246
|
success: ts.factory.createTrue(),
|
|
246
247
|
},
|
|
247
248
|
importer,
|
|
@@ -277,12 +278,13 @@ export namespace AssertProgrammer {
|
|
|
277
278
|
};
|
|
278
279
|
|
|
279
280
|
const combiner =
|
|
281
|
+
(options: ITransformOptions) =>
|
|
280
282
|
(equals: boolean) =>
|
|
281
283
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
282
284
|
(explore: CheckerProgrammer.IExplore) => {
|
|
283
285
|
if (explore.tracable === false)
|
|
284
286
|
return IsProgrammer.CONFIG({
|
|
285
|
-
object: assert_object(equals)(importer),
|
|
287
|
+
object: assert_object(options)(equals)(importer),
|
|
286
288
|
numeric: true,
|
|
287
289
|
}).combiner(explore);
|
|
288
290
|
|
|
@@ -350,39 +352,44 @@ export namespace AssertProgrammer {
|
|
|
350
352
|
// );
|
|
351
353
|
};
|
|
352
354
|
|
|
353
|
-
const assert_object =
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
355
|
+
const assert_object =
|
|
356
|
+
(options: ITransformOptions) =>
|
|
357
|
+
(equals: boolean) =>
|
|
358
|
+
(importer: FunctionImporter) =>
|
|
359
|
+
check_object({
|
|
360
|
+
equals,
|
|
361
|
+
assert: true,
|
|
362
|
+
undefined: OptionPredicator.undefined(options),
|
|
363
|
+
reduce: ts.factory.createLogicalAnd,
|
|
364
|
+
positive: ts.factory.createTrue(),
|
|
365
|
+
superfluous: (value) =>
|
|
366
|
+
create_guard_call(importer)()(
|
|
367
|
+
ts.factory.createAdd(
|
|
368
|
+
ts.factory.createIdentifier("path"),
|
|
369
|
+
ts.factory.createCallExpression(
|
|
370
|
+
importer.use("join"),
|
|
371
|
+
undefined,
|
|
372
|
+
[ts.factory.createIdentifier("key")],
|
|
373
|
+
),
|
|
367
374
|
),
|
|
375
|
+
"undefined",
|
|
376
|
+
value,
|
|
368
377
|
),
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
ts.factory.createIdentifier("exceptionable"),
|
|
378
|
+
halt: (expr) =>
|
|
379
|
+
ts.factory.createLogicalOr(
|
|
380
|
+
ts.factory.createStrictEquality(
|
|
381
|
+
ts.factory.createFalse(),
|
|
382
|
+
ts.factory.createIdentifier("exceptionable"),
|
|
383
|
+
),
|
|
384
|
+
expr,
|
|
377
385
|
),
|
|
378
|
-
|
|
379
|
-
),
|
|
380
|
-
});
|
|
386
|
+
});
|
|
381
387
|
|
|
382
388
|
const joiner =
|
|
389
|
+
(options: ITransformOptions) =>
|
|
383
390
|
(equals: boolean) =>
|
|
384
391
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
385
|
-
object: assert_object(equals)(importer),
|
|
392
|
+
object: assert_object(options)(equals)(importer),
|
|
386
393
|
array: (input, arrow) =>
|
|
387
394
|
ts.factory.createCallExpression(
|
|
388
395
|
IdentifierFactory.join(input, "every"),
|
|
@@ -51,6 +51,9 @@ export namespace IsProgrammer {
|
|
|
51
51
|
options?.object ||
|
|
52
52
|
check_object({
|
|
53
53
|
equals: !!options?.object,
|
|
54
|
+
undefined: OptionPredicator.undefined({
|
|
55
|
+
undefined: options?.undefined,
|
|
56
|
+
}),
|
|
54
57
|
assert: true,
|
|
55
58
|
reduce: ts.factory.createLogicalAnd,
|
|
56
59
|
positive: ts.factory.createTrue(),
|
|
@@ -70,6 +73,7 @@ export namespace IsProgrammer {
|
|
|
70
73
|
export namespace CONFIG {
|
|
71
74
|
export interface IOptions {
|
|
72
75
|
numeric: boolean;
|
|
76
|
+
undefined: boolean;
|
|
73
77
|
object: (entries: IExpressionEntry[]) => ts.Expression;
|
|
74
78
|
}
|
|
75
79
|
}
|
|
@@ -88,6 +92,7 @@ export namespace IsProgrammer {
|
|
|
88
92
|
const config = CONFIG({
|
|
89
93
|
object: check_object({
|
|
90
94
|
equals,
|
|
95
|
+
undefined: OptionPredicator.undefined(project.options),
|
|
91
96
|
assert: true,
|
|
92
97
|
reduce: ts.factory.createLogicalAnd,
|
|
93
98
|
positive: ts.factory.createTrue(),
|
|
@@ -4,6 +4,7 @@ import { IdentifierFactory } from "../factories/IdentifierFactory";
|
|
|
4
4
|
import { StatementFactory } from "../factories/StatementFactory";
|
|
5
5
|
|
|
6
6
|
import { IProject } from "../transformers/IProject";
|
|
7
|
+
import { ITransformOptions } from "../transformers/ITransformOptions";
|
|
7
8
|
|
|
8
9
|
import { CheckerProgrammer } from "./CheckerProgrammer";
|
|
9
10
|
import { IsProgrammer } from "./IsProgrammer";
|
|
@@ -30,8 +31,8 @@ export namespace ValidateProgrammer {
|
|
|
30
31
|
trace: true,
|
|
31
32
|
numeric: OptionPredicator.numeric(project.options),
|
|
32
33
|
equals,
|
|
33
|
-
combiner: combine(equals)(importer),
|
|
34
|
-
joiner: joiner(equals)(importer),
|
|
34
|
+
combiner: combine(project.options)(equals)(importer),
|
|
35
|
+
joiner: joiner(project.options)(equals)(importer),
|
|
35
36
|
success: ts.factory.createTrue(),
|
|
36
37
|
},
|
|
37
38
|
importer,
|
|
@@ -85,12 +86,13 @@ export namespace ValidateProgrammer {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
const combine =
|
|
89
|
+
(options: ITransformOptions) =>
|
|
88
90
|
(equals: boolean) =>
|
|
89
91
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.Combiner =>
|
|
90
92
|
(explore: CheckerProgrammer.IExplore) => {
|
|
91
93
|
if (explore.tracable === false)
|
|
92
94
|
return IsProgrammer.CONFIG({
|
|
93
|
-
object: validate_object(equals)(importer),
|
|
95
|
+
object: validate_object(options)(equals)(importer),
|
|
94
96
|
numeric: true,
|
|
95
97
|
}).combiner(explore);
|
|
96
98
|
|
|
@@ -131,39 +133,44 @@ const combine =
|
|
|
131
133
|
);
|
|
132
134
|
};
|
|
133
135
|
|
|
134
|
-
const validate_object =
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
136
|
+
const validate_object =
|
|
137
|
+
(options: ITransformOptions) =>
|
|
138
|
+
(equals: boolean) =>
|
|
139
|
+
(importer: FunctionImporter) =>
|
|
140
|
+
check_object({
|
|
141
|
+
equals,
|
|
142
|
+
undefined: OptionPredicator.undefined(options),
|
|
143
|
+
assert: false,
|
|
144
|
+
reduce: ts.factory.createLogicalAnd,
|
|
145
|
+
positive: ts.factory.createTrue(),
|
|
146
|
+
superfluous: (value) =>
|
|
147
|
+
create_report_call()(
|
|
148
|
+
ts.factory.createAdd(
|
|
149
|
+
ts.factory.createIdentifier("path"),
|
|
150
|
+
ts.factory.createCallExpression(
|
|
151
|
+
importer.use("join"),
|
|
152
|
+
undefined,
|
|
153
|
+
[ts.factory.createIdentifier("key")],
|
|
154
|
+
),
|
|
148
155
|
),
|
|
156
|
+
"undefined",
|
|
157
|
+
value,
|
|
149
158
|
),
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
ts.factory.createIdentifier("exceptionable"),
|
|
159
|
+
halt: (expr) =>
|
|
160
|
+
ts.factory.createLogicalOr(
|
|
161
|
+
ts.factory.createStrictEquality(
|
|
162
|
+
ts.factory.createFalse(),
|
|
163
|
+
ts.factory.createIdentifier("exceptionable"),
|
|
164
|
+
),
|
|
165
|
+
expr,
|
|
158
166
|
),
|
|
159
|
-
|
|
160
|
-
),
|
|
161
|
-
});
|
|
167
|
+
});
|
|
162
168
|
|
|
163
169
|
const joiner =
|
|
170
|
+
(options: ITransformOptions) =>
|
|
164
171
|
(equals: boolean) =>
|
|
165
172
|
(importer: FunctionImporter): CheckerProgrammer.IConfig.IJoiner => ({
|
|
166
|
-
object: validate_object(equals)(importer),
|
|
173
|
+
object: validate_object(options)(equals)(importer),
|
|
167
174
|
array: (input, arrow) =>
|
|
168
175
|
check_everything(
|
|
169
176
|
ts.factory.createCallExpression(
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
import { Atomic } from "../../typings/Atomic";
|
|
4
|
-
|
|
5
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
-
|
|
7
|
-
export namespace AtomicPredicator {
|
|
8
|
-
export const constant =
|
|
9
|
-
(meta: Metadata) =>
|
|
10
|
-
(name: Atomic.Literal): boolean =>
|
|
11
|
-
!ArrayUtil.has(meta.atomics, (atomic) => atomic === name);
|
|
12
|
-
|
|
13
|
-
export const template = (meta: Metadata): boolean =>
|
|
14
|
-
!ArrayUtil.has(meta.atomics, (type) => type === "string");
|
|
15
|
-
}
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { Atomic } from "../../typings/Atomic";
|
|
4
|
+
|
|
5
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
+
|
|
7
|
+
export namespace AtomicPredicator {
|
|
8
|
+
export const constant =
|
|
9
|
+
(meta: Metadata) =>
|
|
10
|
+
(name: Atomic.Literal): boolean =>
|
|
11
|
+
!ArrayUtil.has(meta.atomics, (atomic) => atomic === name);
|
|
12
|
+
|
|
13
|
+
export const template = (meta: Metadata): boolean =>
|
|
14
|
+
!ArrayUtil.has(meta.atomics, (type) => type === "string");
|
|
15
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
|
|
6
|
-
export class FunctionImporter {
|
|
7
|
-
private readonly used_: Set<string> = new Set();
|
|
8
|
-
private sequence_: number = 0;
|
|
9
|
-
|
|
10
|
-
public empty(): boolean {
|
|
11
|
-
return this.used_.size === 0;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public use(name: string): ts.Identifier {
|
|
15
|
-
this.used_.add(name);
|
|
16
|
-
return ts.factory.createIdentifier("$" + name);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
|
|
20
|
-
return [...this.used_].map((name) =>
|
|
21
|
-
StatementFactory.constant(
|
|
22
|
-
"$" + name,
|
|
23
|
-
IdentifierFactory.join(modulo, name),
|
|
24
|
-
),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public increment(): number {
|
|
29
|
-
return ++this.sequence_;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
|
|
6
|
+
export class FunctionImporter {
|
|
7
|
+
private readonly used_: Set<string> = new Set();
|
|
8
|
+
private sequence_: number = 0;
|
|
9
|
+
|
|
10
|
+
public empty(): boolean {
|
|
11
|
+
return this.used_.size === 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public use(name: string): ts.Identifier {
|
|
15
|
+
this.used_.add(name);
|
|
16
|
+
return ts.factory.createIdentifier("$" + name);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public declare(modulo: ts.LeftHandSideExpression): ts.Statement[] {
|
|
20
|
+
return [...this.used_].map((name) =>
|
|
21
|
+
StatementFactory.constant(
|
|
22
|
+
"$" + name,
|
|
23
|
+
IdentifierFactory.join(modulo, name),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public increment(): number {
|
|
29
|
+
return ++this.sequence_;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
export interface IExpressionEntry {
|
|
6
|
-
input: ts.Expression;
|
|
7
|
-
key: Metadata;
|
|
8
|
-
meta: Metadata;
|
|
9
|
-
expression: ts.Expression;
|
|
10
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
export interface IExpressionEntry {
|
|
6
|
+
input: ts.Expression;
|
|
7
|
+
key: Metadata;
|
|
8
|
+
meta: Metadata;
|
|
9
|
+
expression: ts.Expression;
|
|
10
|
+
}
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
-
|
|
6
|
-
import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
|
|
7
|
-
import { stringify_regular_properties } from "../internal/stringify_regular_properties";
|
|
8
|
-
import { FunctionImporter } from "./FunctionImporeter";
|
|
9
|
-
import { IExpressionEntry } from "./IExpressionEntry";
|
|
10
|
-
|
|
11
|
-
export namespace StringifyJoiner {
|
|
12
|
-
export const object =
|
|
13
|
-
(importer: FunctionImporter) =>
|
|
14
|
-
(entries: IExpressionEntry[]): ts.Expression => {
|
|
15
|
-
// CHECK AND SORT ENTRIES
|
|
16
|
-
const regular: IExpressionEntry[] = entries.filter((entry) =>
|
|
17
|
-
entry.key.isSoleLiteral(),
|
|
18
|
-
);
|
|
19
|
-
const dynamic: IExpressionEntry[] = entries.filter(
|
|
20
|
-
(entry) => !entry.key.isSoleLiteral(),
|
|
21
|
-
);
|
|
22
|
-
if (regular.length === 0 && dynamic.length === 0)
|
|
23
|
-
return ts.factory.createStringLiteral("{}");
|
|
24
|
-
|
|
25
|
-
// PROPERTIES
|
|
26
|
-
const expressions: ts.Expression[] = [
|
|
27
|
-
...stringify_regular_properties(regular, dynamic),
|
|
28
|
-
...(dynamic.length
|
|
29
|
-
? [
|
|
30
|
-
stringify_dynamic_properties(
|
|
31
|
-
dynamic,
|
|
32
|
-
regular.map((r) => r.key.getSoleLiteral()!),
|
|
33
|
-
),
|
|
34
|
-
]
|
|
35
|
-
: []),
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
// POP LAST COMMA, IF REQUIRED
|
|
39
|
-
const filtered: ts.Expression[] =
|
|
40
|
-
(regular.length &&
|
|
41
|
-
regular[regular.length - 1]!.meta.required &&
|
|
42
|
-
dynamic.length === 0) ||
|
|
43
|
-
(regular.length === 0 && dynamic.length)
|
|
44
|
-
? expressions
|
|
45
|
-
: [
|
|
46
|
-
ts.factory.createCallExpression(
|
|
47
|
-
importer.use("tail"),
|
|
48
|
-
undefined,
|
|
49
|
-
[TemplateFactory.generate(expressions)],
|
|
50
|
-
),
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
// RETURNS WITH OBJECT BRACKET
|
|
54
|
-
return TemplateFactory.generate([
|
|
55
|
-
ts.factory.createStringLiteral(`{`),
|
|
56
|
-
...filtered,
|
|
57
|
-
ts.factory.createStringLiteral(`}`),
|
|
58
|
-
]);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export function array(
|
|
62
|
-
input: ts.Expression,
|
|
63
|
-
arrow: ts.ArrowFunction,
|
|
64
|
-
): ts.Expression {
|
|
65
|
-
return TemplateFactory.generate([
|
|
66
|
-
ts.factory.createStringLiteral(`[`),
|
|
67
|
-
ts.factory.createCallExpression(
|
|
68
|
-
ts.factory.createPropertyAccessExpression(
|
|
69
|
-
ts.factory.createCallExpression(
|
|
70
|
-
IdentifierFactory.join(input, "map"),
|
|
71
|
-
undefined,
|
|
72
|
-
[arrow],
|
|
73
|
-
),
|
|
74
|
-
ts.factory.createIdentifier("join"),
|
|
75
|
-
),
|
|
76
|
-
undefined,
|
|
77
|
-
[ts.factory.createStringLiteral(`,`)],
|
|
78
|
-
),
|
|
79
|
-
ts.factory.createStringLiteral(`]`),
|
|
80
|
-
]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function tuple(
|
|
84
|
-
children: ts.Expression[],
|
|
85
|
-
rest: ts.Expression | null,
|
|
86
|
-
): ts.Expression {
|
|
87
|
-
if (children.length === 0) return ts.factory.createStringLiteral("[]");
|
|
88
|
-
if (
|
|
89
|
-
rest === null &&
|
|
90
|
-
children.every((child) => ts.isStringLiteral(child))
|
|
91
|
-
)
|
|
92
|
-
return ts.factory.createStringLiteral(
|
|
93
|
-
"[" +
|
|
94
|
-
children
|
|
95
|
-
.map((child) => (child as ts.StringLiteral).text)
|
|
96
|
-
.join(",") +
|
|
97
|
-
"]",
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const elements: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
|
|
101
|
-
children.forEach((child, i) => {
|
|
102
|
-
elements.push(child);
|
|
103
|
-
if (i !== children.length - 1)
|
|
104
|
-
elements.push(ts.factory.createStringLiteral(`,`));
|
|
105
|
-
});
|
|
106
|
-
if (rest !== null) elements.push(rest);
|
|
107
|
-
|
|
108
|
-
elements.push(ts.factory.createStringLiteral(`]`));
|
|
109
|
-
return TemplateFactory.generate(elements);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
+
|
|
6
|
+
import { stringify_dynamic_properties } from "../internal/stringify_dynamic_properties";
|
|
7
|
+
import { stringify_regular_properties } from "../internal/stringify_regular_properties";
|
|
8
|
+
import { FunctionImporter } from "./FunctionImporeter";
|
|
9
|
+
import { IExpressionEntry } from "./IExpressionEntry";
|
|
10
|
+
|
|
11
|
+
export namespace StringifyJoiner {
|
|
12
|
+
export const object =
|
|
13
|
+
(importer: FunctionImporter) =>
|
|
14
|
+
(entries: IExpressionEntry[]): ts.Expression => {
|
|
15
|
+
// CHECK AND SORT ENTRIES
|
|
16
|
+
const regular: IExpressionEntry[] = entries.filter((entry) =>
|
|
17
|
+
entry.key.isSoleLiteral(),
|
|
18
|
+
);
|
|
19
|
+
const dynamic: IExpressionEntry[] = entries.filter(
|
|
20
|
+
(entry) => !entry.key.isSoleLiteral(),
|
|
21
|
+
);
|
|
22
|
+
if (regular.length === 0 && dynamic.length === 0)
|
|
23
|
+
return ts.factory.createStringLiteral("{}");
|
|
24
|
+
|
|
25
|
+
// PROPERTIES
|
|
26
|
+
const expressions: ts.Expression[] = [
|
|
27
|
+
...stringify_regular_properties(regular, dynamic),
|
|
28
|
+
...(dynamic.length
|
|
29
|
+
? [
|
|
30
|
+
stringify_dynamic_properties(
|
|
31
|
+
dynamic,
|
|
32
|
+
regular.map((r) => r.key.getSoleLiteral()!),
|
|
33
|
+
),
|
|
34
|
+
]
|
|
35
|
+
: []),
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
// POP LAST COMMA, IF REQUIRED
|
|
39
|
+
const filtered: ts.Expression[] =
|
|
40
|
+
(regular.length &&
|
|
41
|
+
regular[regular.length - 1]!.meta.required &&
|
|
42
|
+
dynamic.length === 0) ||
|
|
43
|
+
(regular.length === 0 && dynamic.length)
|
|
44
|
+
? expressions
|
|
45
|
+
: [
|
|
46
|
+
ts.factory.createCallExpression(
|
|
47
|
+
importer.use("tail"),
|
|
48
|
+
undefined,
|
|
49
|
+
[TemplateFactory.generate(expressions)],
|
|
50
|
+
),
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
// RETURNS WITH OBJECT BRACKET
|
|
54
|
+
return TemplateFactory.generate([
|
|
55
|
+
ts.factory.createStringLiteral(`{`),
|
|
56
|
+
...filtered,
|
|
57
|
+
ts.factory.createStringLiteral(`}`),
|
|
58
|
+
]);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export function array(
|
|
62
|
+
input: ts.Expression,
|
|
63
|
+
arrow: ts.ArrowFunction,
|
|
64
|
+
): ts.Expression {
|
|
65
|
+
return TemplateFactory.generate([
|
|
66
|
+
ts.factory.createStringLiteral(`[`),
|
|
67
|
+
ts.factory.createCallExpression(
|
|
68
|
+
ts.factory.createPropertyAccessExpression(
|
|
69
|
+
ts.factory.createCallExpression(
|
|
70
|
+
IdentifierFactory.join(input, "map"),
|
|
71
|
+
undefined,
|
|
72
|
+
[arrow],
|
|
73
|
+
),
|
|
74
|
+
ts.factory.createIdentifier("join"),
|
|
75
|
+
),
|
|
76
|
+
undefined,
|
|
77
|
+
[ts.factory.createStringLiteral(`,`)],
|
|
78
|
+
),
|
|
79
|
+
ts.factory.createStringLiteral(`]`),
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function tuple(
|
|
84
|
+
children: ts.Expression[],
|
|
85
|
+
rest: ts.Expression | null,
|
|
86
|
+
): ts.Expression {
|
|
87
|
+
if (children.length === 0) return ts.factory.createStringLiteral("[]");
|
|
88
|
+
if (
|
|
89
|
+
rest === null &&
|
|
90
|
+
children.every((child) => ts.isStringLiteral(child))
|
|
91
|
+
)
|
|
92
|
+
return ts.factory.createStringLiteral(
|
|
93
|
+
"[" +
|
|
94
|
+
children
|
|
95
|
+
.map((child) => (child as ts.StringLiteral).text)
|
|
96
|
+
.join(",") +
|
|
97
|
+
"]",
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const elements: ts.Expression[] = [ts.factory.createStringLiteral(`[`)];
|
|
101
|
+
children.forEach((child, i) => {
|
|
102
|
+
elements.push(child);
|
|
103
|
+
if (i !== children.length - 1)
|
|
104
|
+
elements.push(ts.factory.createStringLiteral(`,`));
|
|
105
|
+
});
|
|
106
|
+
if (rest !== null) elements.push(rest);
|
|
107
|
+
|
|
108
|
+
elements.push(ts.factory.createStringLiteral(`]`));
|
|
109
|
+
return TemplateFactory.generate(elements);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
|
|
3
|
-
export namespace StringifyPredicator {
|
|
4
|
-
export function require_escape(value: string): boolean {
|
|
5
|
-
return value
|
|
6
|
-
.split("")
|
|
7
|
-
.some((ch) => ESCAPED.some((escaped) => escaped === ch));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function undefindable(meta: Metadata): boolean {
|
|
11
|
-
return (
|
|
12
|
-
meta.required === false ||
|
|
13
|
-
(meta.resolved !== null && meta.resolved.required === false)
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
|
|
18
|
-
}
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
export namespace StringifyPredicator {
|
|
4
|
+
export function require_escape(value: string): boolean {
|
|
5
|
+
return value
|
|
6
|
+
.split("")
|
|
7
|
+
.some((ch) => ESCAPED.some((escaped) => escaped === ch));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function undefindable(meta: Metadata): boolean {
|
|
11
|
+
return (
|
|
12
|
+
meta.required === false ||
|
|
13
|
+
(meta.resolved !== null && meta.resolved.required === false)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
|
|
18
|
+
}
|