typia 4.0.10-dev.20230615 → 4.0.10-dev.20230616
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/lib/factories/MetadataTagFactory.js +3 -3
- package/lib/factories/MetadataTagFactory.js.map +1 -1
- package/lib/factories/internal/metadata/explore_metadata.js +4 -2
- package/lib/factories/internal/metadata/explore_metadata.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_collection.js +3 -3
- package/lib/factories/internal/metadata/iterate_metadata_collection.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_resolve.js +9 -3
- package/lib/factories/internal/metadata/iterate_metadata_resolve.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_sort.js +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_sort.js.map +1 -1
- package/lib/metadata/IMetadata.d.ts +2 -1
- package/lib/metadata/IMetadataResolved.d.ts +5 -0
- package/lib/metadata/IMetadataResolved.js +3 -0
- package/lib/metadata/IMetadataResolved.js.map +1 -0
- package/lib/metadata/Metadata.d.ts +2 -1
- package/lib/metadata/Metadata.js +31 -24
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/metadata/MetadataArray.d.ts +4 -2
- package/lib/metadata/MetadataArray.js.map +1 -1
- package/lib/metadata/MetadataResolved.d.ts +12 -0
- package/lib/metadata/MetadataResolved.js +31 -0
- package/lib/metadata/MetadataResolved.js.map +1 -0
- package/lib/programmers/CloneProgrammer.js +1 -1
- package/lib/programmers/CloneProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +1 -1
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/StringifyProgrammer.js +1 -1
- package/lib/programmers/StringifyProgrammer.js.map +1 -1
- package/lib/programmers/helpers/StringifyPredicator.js +1 -1
- package/lib/programmers/helpers/StringifyPredicator.js.map +1 -1
- package/lib/programmers/internal/application_resolved.d.ts +4 -0
- package/lib/programmers/internal/application_resolved.js +50 -0
- package/lib/programmers/internal/application_resolved.js.map +1 -0
- package/lib/programmers/internal/application_schema.js +28 -5
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/transformers/features/miscellaneous/MetadataTransformer.js +1 -1
- package/lib/transformers/features/miscellaneous/MetadataTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/MetadataTagFactory.ts +3 -3
- package/src/factories/internal/metadata/emend_metadata_atomics.ts +33 -33
- package/src/factories/internal/metadata/explore_metadata.ts +40 -37
- package/src/factories/internal/metadata/iterate_metadata.ts +85 -85
- package/src/factories/internal/metadata/iterate_metadata_alias.ts +30 -30
- package/src/factories/internal/metadata/iterate_metadata_collection.ts +3 -3
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +87 -87
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -38
- package/src/factories/internal/metadata/iterate_metadata_sort.ts +2 -1
- package/src/factories/internal/metadata/iterate_metadata_union.ts +24 -24
- package/src/metadata/IMetadata.ts +2 -1
- package/src/metadata/IMetadataResolved.ts +6 -0
- package/src/metadata/Metadata.ts +17 -4
- package/src/metadata/MetadataArray.ts +4 -1
- package/src/metadata/MetadataResolved.ts +51 -0
- package/src/programmers/CloneProgrammer.ts +1 -1
- package/src/programmers/RandomProgrammer.ts +5 -1
- package/src/programmers/StringifyProgrammer.ts +983 -983
- package/src/programmers/helpers/PruneJoiner.ts +143 -143
- package/src/programmers/helpers/StringifyPredicator.ts +1 -1
- package/src/programmers/internal/application_resolved.ts +55 -0
- package/src/programmers/internal/application_schema.ts +7 -6
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +1 -1
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
|
|
5
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
-
|
|
7
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
8
|
-
|
|
9
|
-
import { metadata_to_pattern } from "../internal/metadata_to_pattern";
|
|
10
|
-
import { prune_object_properties } from "../internal/prune_object_properties";
|
|
11
|
-
import { IExpressionEntry } from "./IExpressionEntry";
|
|
12
|
-
|
|
13
|
-
export namespace PruneJoiner {
|
|
14
|
-
export const object = (
|
|
15
|
-
input: ts.Expression,
|
|
16
|
-
entries: IExpressionEntry[],
|
|
17
|
-
obj: MetadataObject,
|
|
18
|
-
): ts.ConciseBody => {
|
|
19
|
-
// PREPARE ASSETS
|
|
20
|
-
const regular = entries.filter((entry) => entry.key.isSoleLiteral());
|
|
21
|
-
const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
|
|
22
|
-
|
|
23
|
-
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
24
|
-
regular.map((entry) =>
|
|
25
|
-
ts.isBlock(entry.expression)
|
|
26
|
-
? [...entry.expression.statements]
|
|
27
|
-
: [ts.factory.createExpressionStatement(entry.expression)],
|
|
28
|
-
),
|
|
29
|
-
);
|
|
30
|
-
if (dynamic.length)
|
|
31
|
-
statements.push(
|
|
32
|
-
ts.factory.createExpressionStatement(
|
|
33
|
-
iterate_dynamic_properties({ regular, dynamic })(input),
|
|
34
|
-
),
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
statements.push(prune_object_properties(obj));
|
|
38
|
-
return ts.factory.createBlock(statements, true);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const array = (input: ts.Expression, arrow: ts.ArrowFunction) =>
|
|
42
|
-
ts.factory.createCallExpression(
|
|
43
|
-
IdentifierFactory.access(input)("forEach"),
|
|
44
|
-
undefined,
|
|
45
|
-
[arrow],
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
export const tuple = (
|
|
49
|
-
children: ts.ConciseBody[],
|
|
50
|
-
rest: ts.ConciseBody | null,
|
|
51
|
-
): ts.Block => {
|
|
52
|
-
const entire: ts.ConciseBody[] = [...children];
|
|
53
|
-
if (rest !== null) entire.push(rest);
|
|
54
|
-
|
|
55
|
-
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
56
|
-
entire.map((elem) =>
|
|
57
|
-
ts.isBlock(elem)
|
|
58
|
-
? [...elem.statements]
|
|
59
|
-
: [ts.factory.createExpressionStatement(elem)],
|
|
60
|
-
),
|
|
61
|
-
);
|
|
62
|
-
return ts.factory.createBlock(statements, true);
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const iterate_dynamic_properties =
|
|
67
|
-
(props: { regular: IExpressionEntry[]; dynamic: IExpressionEntry[] }) =>
|
|
68
|
-
(input: ts.Expression) =>
|
|
69
|
-
ts.factory.createCallExpression(
|
|
70
|
-
IdentifierFactory.access(
|
|
71
|
-
ts.factory.createCallExpression(
|
|
72
|
-
ts.factory.createIdentifier("Object.entries"),
|
|
73
|
-
undefined,
|
|
74
|
-
[input],
|
|
75
|
-
),
|
|
76
|
-
)("forEach"),
|
|
77
|
-
undefined,
|
|
78
|
-
[
|
|
79
|
-
ts.factory.createArrowFunction(
|
|
80
|
-
undefined,
|
|
81
|
-
undefined,
|
|
82
|
-
[
|
|
83
|
-
IdentifierFactory.parameter(
|
|
84
|
-
ts.factory.createArrayBindingPattern(
|
|
85
|
-
["key", "value"].map((l) =>
|
|
86
|
-
ts.factory.createBindingElement(
|
|
87
|
-
undefined,
|
|
88
|
-
undefined,
|
|
89
|
-
ts.factory.createIdentifier(l),
|
|
90
|
-
undefined,
|
|
91
|
-
),
|
|
92
|
-
),
|
|
93
|
-
),
|
|
94
|
-
),
|
|
95
|
-
],
|
|
96
|
-
undefined,
|
|
97
|
-
undefined,
|
|
98
|
-
ts.factory.createBlock(
|
|
99
|
-
[
|
|
100
|
-
ts.factory.createIfStatement(
|
|
101
|
-
ts.factory.createStrictEquality(
|
|
102
|
-
ts.factory.createIdentifier("undefined"),
|
|
103
|
-
ts.factory.createIdentifier("value"),
|
|
104
|
-
),
|
|
105
|
-
ts.factory.createReturnStatement(),
|
|
106
|
-
),
|
|
107
|
-
...props.regular.map(({ key }) =>
|
|
108
|
-
ts.factory.createIfStatement(
|
|
109
|
-
ts.factory.createStrictEquality(
|
|
110
|
-
ts.factory.createStringLiteral(
|
|
111
|
-
key.getSoleLiteral()!,
|
|
112
|
-
),
|
|
113
|
-
ts.factory.createIdentifier("key"),
|
|
114
|
-
),
|
|
115
|
-
ts.factory.createReturnStatement(),
|
|
116
|
-
),
|
|
117
|
-
),
|
|
118
|
-
...props.dynamic.map((dynamic) =>
|
|
119
|
-
ts.factory.createIfStatement(
|
|
120
|
-
ts.factory.createCallExpression(
|
|
121
|
-
ts.factory.createIdentifier(
|
|
122
|
-
`RegExp(/${metadata_to_pattern(
|
|
123
|
-
true,
|
|
124
|
-
)(dynamic.key)}/).test`,
|
|
125
|
-
),
|
|
126
|
-
undefined,
|
|
127
|
-
[ts.factory.createIdentifier("key")],
|
|
128
|
-
),
|
|
129
|
-
ts.isBlock(dynamic.expression)
|
|
130
|
-
? dynamic.expression
|
|
131
|
-
: ts.factory.createBlock([
|
|
132
|
-
ts.factory.createExpressionStatement(
|
|
133
|
-
dynamic.expression,
|
|
134
|
-
),
|
|
135
|
-
]),
|
|
136
|
-
),
|
|
137
|
-
),
|
|
138
|
-
],
|
|
139
|
-
true,
|
|
140
|
-
),
|
|
141
|
-
),
|
|
142
|
-
],
|
|
143
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
+
|
|
7
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
8
|
+
|
|
9
|
+
import { metadata_to_pattern } from "../internal/metadata_to_pattern";
|
|
10
|
+
import { prune_object_properties } from "../internal/prune_object_properties";
|
|
11
|
+
import { IExpressionEntry } from "./IExpressionEntry";
|
|
12
|
+
|
|
13
|
+
export namespace PruneJoiner {
|
|
14
|
+
export const object = (
|
|
15
|
+
input: ts.Expression,
|
|
16
|
+
entries: IExpressionEntry[],
|
|
17
|
+
obj: MetadataObject,
|
|
18
|
+
): ts.ConciseBody => {
|
|
19
|
+
// PREPARE ASSETS
|
|
20
|
+
const regular = entries.filter((entry) => entry.key.isSoleLiteral());
|
|
21
|
+
const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
|
|
22
|
+
|
|
23
|
+
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
24
|
+
regular.map((entry) =>
|
|
25
|
+
ts.isBlock(entry.expression)
|
|
26
|
+
? [...entry.expression.statements]
|
|
27
|
+
: [ts.factory.createExpressionStatement(entry.expression)],
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
if (dynamic.length)
|
|
31
|
+
statements.push(
|
|
32
|
+
ts.factory.createExpressionStatement(
|
|
33
|
+
iterate_dynamic_properties({ regular, dynamic })(input),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
statements.push(prune_object_properties(obj));
|
|
38
|
+
return ts.factory.createBlock(statements, true);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const array = (input: ts.Expression, arrow: ts.ArrowFunction) =>
|
|
42
|
+
ts.factory.createCallExpression(
|
|
43
|
+
IdentifierFactory.access(input)("forEach"),
|
|
44
|
+
undefined,
|
|
45
|
+
[arrow],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export const tuple = (
|
|
49
|
+
children: ts.ConciseBody[],
|
|
50
|
+
rest: ts.ConciseBody | null,
|
|
51
|
+
): ts.Block => {
|
|
52
|
+
const entire: ts.ConciseBody[] = [...children];
|
|
53
|
+
if (rest !== null) entire.push(rest);
|
|
54
|
+
|
|
55
|
+
const statements: ts.Statement[] = ArrayUtil.flat(
|
|
56
|
+
entire.map((elem) =>
|
|
57
|
+
ts.isBlock(elem)
|
|
58
|
+
? [...elem.statements]
|
|
59
|
+
: [ts.factory.createExpressionStatement(elem)],
|
|
60
|
+
),
|
|
61
|
+
);
|
|
62
|
+
return ts.factory.createBlock(statements, true);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const iterate_dynamic_properties =
|
|
67
|
+
(props: { regular: IExpressionEntry[]; dynamic: IExpressionEntry[] }) =>
|
|
68
|
+
(input: ts.Expression) =>
|
|
69
|
+
ts.factory.createCallExpression(
|
|
70
|
+
IdentifierFactory.access(
|
|
71
|
+
ts.factory.createCallExpression(
|
|
72
|
+
ts.factory.createIdentifier("Object.entries"),
|
|
73
|
+
undefined,
|
|
74
|
+
[input],
|
|
75
|
+
),
|
|
76
|
+
)("forEach"),
|
|
77
|
+
undefined,
|
|
78
|
+
[
|
|
79
|
+
ts.factory.createArrowFunction(
|
|
80
|
+
undefined,
|
|
81
|
+
undefined,
|
|
82
|
+
[
|
|
83
|
+
IdentifierFactory.parameter(
|
|
84
|
+
ts.factory.createArrayBindingPattern(
|
|
85
|
+
["key", "value"].map((l) =>
|
|
86
|
+
ts.factory.createBindingElement(
|
|
87
|
+
undefined,
|
|
88
|
+
undefined,
|
|
89
|
+
ts.factory.createIdentifier(l),
|
|
90
|
+
undefined,
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
],
|
|
96
|
+
undefined,
|
|
97
|
+
undefined,
|
|
98
|
+
ts.factory.createBlock(
|
|
99
|
+
[
|
|
100
|
+
ts.factory.createIfStatement(
|
|
101
|
+
ts.factory.createStrictEquality(
|
|
102
|
+
ts.factory.createIdentifier("undefined"),
|
|
103
|
+
ts.factory.createIdentifier("value"),
|
|
104
|
+
),
|
|
105
|
+
ts.factory.createReturnStatement(),
|
|
106
|
+
),
|
|
107
|
+
...props.regular.map(({ key }) =>
|
|
108
|
+
ts.factory.createIfStatement(
|
|
109
|
+
ts.factory.createStrictEquality(
|
|
110
|
+
ts.factory.createStringLiteral(
|
|
111
|
+
key.getSoleLiteral()!,
|
|
112
|
+
),
|
|
113
|
+
ts.factory.createIdentifier("key"),
|
|
114
|
+
),
|
|
115
|
+
ts.factory.createReturnStatement(),
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
...props.dynamic.map((dynamic) =>
|
|
119
|
+
ts.factory.createIfStatement(
|
|
120
|
+
ts.factory.createCallExpression(
|
|
121
|
+
ts.factory.createIdentifier(
|
|
122
|
+
`RegExp(/${metadata_to_pattern(
|
|
123
|
+
true,
|
|
124
|
+
)(dynamic.key)}/).test`,
|
|
125
|
+
),
|
|
126
|
+
undefined,
|
|
127
|
+
[ts.factory.createIdentifier("key")],
|
|
128
|
+
),
|
|
129
|
+
ts.isBlock(dynamic.expression)
|
|
130
|
+
? dynamic.expression
|
|
131
|
+
: ts.factory.createBlock([
|
|
132
|
+
ts.factory.createExpressionStatement(
|
|
133
|
+
dynamic.expression,
|
|
134
|
+
),
|
|
135
|
+
]),
|
|
136
|
+
),
|
|
137
|
+
),
|
|
138
|
+
],
|
|
139
|
+
true,
|
|
140
|
+
),
|
|
141
|
+
),
|
|
142
|
+
],
|
|
143
|
+
);
|
|
@@ -6,7 +6,7 @@ export namespace StringifyPredicator {
|
|
|
6
6
|
|
|
7
7
|
export const undefindable = (meta: Metadata): boolean =>
|
|
8
8
|
meta.required === false ||
|
|
9
|
-
(meta.resolved !== null && meta.resolved.required === false);
|
|
9
|
+
(meta.resolved !== null && meta.resolved.returns.required === false);
|
|
10
10
|
|
|
11
11
|
const ESCAPED = ['"', "\\", "\b", "\f", "\n", "\n", "\r", "\t"];
|
|
12
12
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { MetadataResolved } from "../../metadata/MetadataResolved";
|
|
3
|
+
|
|
4
|
+
import { IJsonComponents, IJsonSchema } from "../../module";
|
|
5
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
+
import { application_schema } from "./application_schema";
|
|
7
|
+
|
|
8
|
+
export const application_resolved =
|
|
9
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
10
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
11
|
+
(components: IJsonComponents) =>
|
|
12
|
+
(resolved: MetadataResolved) =>
|
|
13
|
+
(attribute: IJsonSchema.IAttribute): IJsonSchema[] => {
|
|
14
|
+
const output = application_schema(options)(blockNever)(components)(
|
|
15
|
+
resolved.returns,
|
|
16
|
+
)(attribute);
|
|
17
|
+
if (output === null) return [];
|
|
18
|
+
|
|
19
|
+
if (is_date(new Set())(resolved.original)) {
|
|
20
|
+
const string: IJsonSchema.IString | undefined = is_string(output)
|
|
21
|
+
? output
|
|
22
|
+
: is_one_of(output)
|
|
23
|
+
? output.oneOf.find(is_string)
|
|
24
|
+
: undefined;
|
|
25
|
+
if (
|
|
26
|
+
string !== undefined &&
|
|
27
|
+
string.format !== "date" &&
|
|
28
|
+
string.format !== "date-time"
|
|
29
|
+
)
|
|
30
|
+
string.format = "date-time";
|
|
31
|
+
}
|
|
32
|
+
return is_one_of(output) ? output.oneOf : [output];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const is_string = (elem: IJsonSchema): elem is IJsonSchema.IString =>
|
|
36
|
+
(elem as IJsonSchema.IString).type === "string";
|
|
37
|
+
|
|
38
|
+
const is_one_of = (elem: IJsonSchema): elem is IJsonSchema.IOneOf =>
|
|
39
|
+
Array.isArray((elem as IJsonSchema.IOneOf).oneOf);
|
|
40
|
+
|
|
41
|
+
const is_date =
|
|
42
|
+
(visited: Set<Metadata>) =>
|
|
43
|
+
(meta: Metadata): boolean => {
|
|
44
|
+
if (visited.has(meta)) return false;
|
|
45
|
+
visited.add(meta);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
meta.natives.some((name) => name === "Date") ||
|
|
49
|
+
meta.arrays.some((array) => is_date(visited)(array.value)) ||
|
|
50
|
+
meta.tuples.some((tuple) =>
|
|
51
|
+
tuple.elements.some(is_date(visited)),
|
|
52
|
+
) ||
|
|
53
|
+
meta.aliases.some((alias) => is_date(visited)(alias.value))
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -11,6 +11,7 @@ import { application_constant } from "./application_constant";
|
|
|
11
11
|
import { application_native } from "./application_native";
|
|
12
12
|
import { application_number } from "./application_number";
|
|
13
13
|
import { application_object } from "./application_object";
|
|
14
|
+
import { application_resolved } from "./application_resolved";
|
|
14
15
|
import { application_string } from "./application_string";
|
|
15
16
|
import { application_templates } from "./application_templates";
|
|
16
17
|
import { application_tuple } from "./application_tuple";
|
|
@@ -57,12 +58,12 @@ export const application_schema =
|
|
|
57
58
|
: (schema: IJsonSchema) => union.push(schema);
|
|
58
59
|
|
|
59
60
|
// toJSON() METHOD
|
|
60
|
-
if (meta.resolved !== null)
|
|
61
|
-
|
|
62
|
-
components
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
if (meta.resolved !== null)
|
|
62
|
+
union.push(
|
|
63
|
+
...application_resolved(options)(blockNever)(components)(
|
|
64
|
+
meta.resolved,
|
|
65
|
+
)(attribute),
|
|
66
|
+
);
|
|
66
67
|
|
|
67
68
|
// ATOMIC TYPES
|
|
68
69
|
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
@@ -33,7 +33,7 @@ export namespace MetadataTransformer {
|
|
|
33
33
|
const collection: MetadataCollection = new MetadataCollection();
|
|
34
34
|
const metadatas: Array<Metadata> = types.map((type) =>
|
|
35
35
|
MetadataFactory.analyze(checker)({
|
|
36
|
-
resolve:
|
|
36
|
+
resolve: true,
|
|
37
37
|
constant: true,
|
|
38
38
|
absorb: true,
|
|
39
39
|
})(collection)(type),
|