typia 6.7.2 → 6.8.0-dev.20240811
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/programmers/internal/application_bigint.d.ts +1 -0
- package/lib/programmers/internal/application_bigint.js +14 -0
- package/lib/programmers/internal/application_bigint.js.map +1 -0
- package/lib/programmers/internal/application_v30_schema.js +10 -12
- package/lib/programmers/internal/application_v30_schema.js.map +1 -1
- package/lib/programmers/internal/application_v31_constant.js +3 -1
- package/lib/programmers/internal/application_v31_constant.js.map +1 -1
- package/lib/programmers/internal/application_v31_schema.js +10 -12
- package/lib/programmers/internal/application_v31_schema.js.map +1 -1
- package/lib/tags/Constant.d.ts +2 -2
- package/lib/tags/Default.d.ts +5 -1
- package/lib/tags/ExclusiveMaximum.d.ts +9 -5
- package/lib/tags/ExclusiveMinimum.d.ts +9 -5
- package/lib/tags/JsonSchemaPlugin.d.ts +1 -1
- package/lib/tags/Maximum.d.ts +8 -5
- package/lib/tags/Minimum.d.ts +8 -5
- package/lib/tags/MultipleOf.d.ts +7 -4
- package/package.json +2 -2
- package/src/factories/CommentFactory.ts +79 -79
- package/src/factories/MetadataCollection.ts +274 -274
- package/src/factories/MetadataFactory.ts +272 -272
- package/src/factories/StatementFactory.ts +74 -74
- package/src/factories/TypeFactory.ts +118 -118
- package/src/factories/internal/metadata/emplace_metadata_array_type.ts +42 -42
- package/src/factories/internal/metadata/emplace_metadata_object.ts +176 -176
- package/src/factories/internal/metadata/iterate_metadata.ts +94 -94
- package/src/factories/internal/metadata/iterate_metadata_array.ts +63 -63
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +62 -62
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +76 -76
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +213 -213
- package/src/factories/internal/metadata/iterate_metadata_map.ts +50 -50
- package/src/factories/internal/metadata/iterate_metadata_native.ts +220 -220
- package/src/factories/internal/metadata/iterate_metadata_object.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_set.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_template.ts +44 -44
- package/src/factories/internal/metadata/iterate_metadata_union.ts +27 -27
- package/src/programmers/internal/application_bigint.ts +25 -0
- package/src/programmers/internal/application_v30_alias.ts +52 -52
- package/src/programmers/internal/application_v30_object.ts +149 -149
- package/src/programmers/internal/application_v30_schema.ts +162 -159
- package/src/programmers/internal/application_v30_tuple.ts +33 -33
- package/src/programmers/internal/application_v31_constant.ts +4 -1
- package/src/programmers/internal/application_v31_schema.ts +159 -157
- package/src/programmers/json/JsonApplicationProgrammer.ts +82 -82
- package/src/schemas/metadata/IMetadataConstantValue.ts +11 -11
- package/src/schemas/metadata/IMetadataTemplate.ts +7 -7
- package/src/tags/Constant.ts +2 -2
- package/src/tags/Default.ts +7 -3
- package/src/tags/ExclusiveMaximum.ts +12 -6
- package/src/tags/ExclusiveMinimum.ts +12 -6
- package/src/tags/JsonSchemaPlugin.ts +1 -1
- package/src/tags/Maximum.ts +9 -8
- package/src/tags/Minimum.ts +9 -8
- package/src/tags/MultipleOf.ts +9 -8
- package/src/tags/Type.ts +32 -32
- package/src/transformers/FileTransformer.ts +91 -91
- package/src/transformers/features/CreateRandomTransformer.ts +40 -40
- package/src/transformers/features/RandomTransformer.ts +44 -44
- package/src/transformers/features/json/JsonApplicationTransformer.ts +124 -124
- package/src/transformers/features/misc/MiscLiteralsTransformer.ts +32 -32
- package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +33 -33
- package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +62 -62
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IMetadataTypeTag } from "../../../schemas/metadata/IMetadataTypeTag";
|
|
4
|
-
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
5
|
-
import { MetadataAtomic } from "../../../schemas/metadata/MetadataAtomic";
|
|
6
|
-
import { MetadataConstant } from "../../../schemas/metadata/MetadataConstant";
|
|
7
|
-
import { MetadataConstantValue } from "../../../schemas/metadata/MetadataConstantValue";
|
|
8
|
-
import { MetadataTemplate } from "../../../schemas/metadata/MetadataTemplate";
|
|
9
|
-
|
|
10
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
11
|
-
|
|
12
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
-
import { MetadataTypeTagFactory } from "../../MetadataTypeTagFactory";
|
|
15
|
-
import { explore_metadata } from "./explore_metadata";
|
|
16
|
-
import { iterate_metadata } from "./iterate_metadata";
|
|
17
|
-
import { iterate_metadata_array } from "./iterate_metadata_array";
|
|
18
|
-
|
|
19
|
-
export const iterate_metadata_intersection =
|
|
20
|
-
(checker: ts.TypeChecker) =>
|
|
21
|
-
(options: MetadataFactory.IOptions) =>
|
|
22
|
-
(collection: MetadataCollection) =>
|
|
23
|
-
(errors: MetadataFactory.IError[]) =>
|
|
24
|
-
(
|
|
25
|
-
meta: Metadata,
|
|
26
|
-
type: ts.Type,
|
|
27
|
-
explore: MetadataFactory.IExplore,
|
|
28
|
-
): boolean => {
|
|
29
|
-
if (!type.isIntersection()) return false;
|
|
30
|
-
if (
|
|
31
|
-
// ONLY OBJECT TYPED INTERSECTION
|
|
32
|
-
type.types.every(
|
|
33
|
-
(child) =>
|
|
34
|
-
(child.getFlags() & ts.TypeFlags.Object) !== 0 &&
|
|
35
|
-
!checker.isArrayType(child) &&
|
|
36
|
-
!checker.isTupleType(child),
|
|
37
|
-
)
|
|
38
|
-
)
|
|
39
|
-
return false;
|
|
40
|
-
|
|
41
|
-
// COSTRUCT FAKE METADATA LIST
|
|
42
|
-
const fakeCollection: MetadataCollection = collection.clone();
|
|
43
|
-
const fakeErrors: MetadataFactory.IError[] = [];
|
|
44
|
-
const children: Metadata[] = [
|
|
45
|
-
...new Map(
|
|
46
|
-
type.types.map((t) => {
|
|
47
|
-
const m: Metadata = explore_metadata(checker)({
|
|
48
|
-
...options,
|
|
49
|
-
absorb: true,
|
|
50
|
-
})(fakeCollection)(fakeErrors)(t, {
|
|
51
|
-
...explore,
|
|
52
|
-
aliased: false,
|
|
53
|
-
});
|
|
54
|
-
return [m.getName(), m] as const;
|
|
55
|
-
}),
|
|
56
|
-
).values(),
|
|
57
|
-
];
|
|
58
|
-
if (fakeErrors.length) {
|
|
59
|
-
errors.push(...fakeErrors);
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ONLY ONE CHILD AFTER REMOVING DUPLICATES
|
|
64
|
-
if (children.length === 1) {
|
|
65
|
-
iterate_metadata(checker)(options)(collection)(errors)(
|
|
66
|
-
meta,
|
|
67
|
-
type.types[0]!,
|
|
68
|
-
explore,
|
|
69
|
-
);
|
|
70
|
-
return true;
|
|
71
|
-
} else if (children.every((c) => c.objects.length === c.size()))
|
|
72
|
-
// ONLY OBJECT TYPED INTERSECTION (DETAILED)
|
|
73
|
-
return false;
|
|
74
|
-
|
|
75
|
-
// VALIDATE EACH TYPES
|
|
76
|
-
const nonsensible = () => {
|
|
77
|
-
errors.push({
|
|
78
|
-
name: children.map((c) => c.getName()).join(" & "),
|
|
79
|
-
explore: { ...explore },
|
|
80
|
-
messages: ["nonsensible intersection"],
|
|
81
|
-
});
|
|
82
|
-
return true;
|
|
83
|
-
};
|
|
84
|
-
const individuals: (readonly [Metadata, number])[] = children
|
|
85
|
-
.map((child, i) => [child, i] as const)
|
|
86
|
-
.filter(
|
|
87
|
-
([c]) =>
|
|
88
|
-
(c.size() === 1 &&
|
|
89
|
-
(c.atomics.length === 1 ||
|
|
90
|
-
(c.constants.length === 1 &&
|
|
91
|
-
c.constants[0]!.values.length === 1) ||
|
|
92
|
-
c.arrays.length === 1)) ||
|
|
93
|
-
c.templates.length === 1,
|
|
94
|
-
);
|
|
95
|
-
if (individuals.length !== 1) return nonsensible();
|
|
96
|
-
|
|
97
|
-
const objects: Metadata[] = children.filter(
|
|
98
|
-
(c) =>
|
|
99
|
-
c.nullable === false &&
|
|
100
|
-
c.isRequired() === true &&
|
|
101
|
-
c.objects.length &&
|
|
102
|
-
c.objects.length === c.size() &&
|
|
103
|
-
c.objects.every((o) => o.properties.every((p) => p.value.optional)),
|
|
104
|
-
);
|
|
105
|
-
const arrays: Set<string> = new Set(
|
|
106
|
-
individuals.map(([c]) => c.arrays.map((a) => a.type.name)).flat(),
|
|
107
|
-
);
|
|
108
|
-
const atomics: Set<"boolean" | "bigint" | "number" | "string"> = new Set(
|
|
109
|
-
individuals.map(([c]) => [...c.atomics.map((a) => a.type)]).flat(),
|
|
110
|
-
);
|
|
111
|
-
const constants: Metadata[] = individuals
|
|
112
|
-
.filter((i) => i[0].constants.length === 1)
|
|
113
|
-
.map(([m]) => m);
|
|
114
|
-
const templates: Metadata[] = individuals
|
|
115
|
-
.filter((i) => i[0].templates.length === 1)
|
|
116
|
-
.map(([m]) => m);
|
|
117
|
-
|
|
118
|
-
// ESCAPE WHEN ONLY CONSTANT TYPES EXIST
|
|
119
|
-
if (
|
|
120
|
-
atomics.size + constants.length + arrays.size + templates.length > 1 ||
|
|
121
|
-
individuals.length + objects.length !== children.length
|
|
122
|
-
)
|
|
123
|
-
return nonsensible();
|
|
124
|
-
|
|
125
|
-
// RE-GENERATE TYPE
|
|
126
|
-
const target: "boolean" | "bigint" | "number" | "string" | "array" =
|
|
127
|
-
arrays.size
|
|
128
|
-
? "array"
|
|
129
|
-
: atomics.size
|
|
130
|
-
? atomics.values().next().value
|
|
131
|
-
: constants.length
|
|
132
|
-
? constants[0]!.constants[0]!.type
|
|
133
|
-
: "string";
|
|
134
|
-
if (target === "array") {
|
|
135
|
-
const name: string = arrays.values().next().value;
|
|
136
|
-
if (!meta.arrays.some((a) => a.type.name === name)) {
|
|
137
|
-
iterate_metadata_array(checker)(options)(collection)(errors)(
|
|
138
|
-
meta,
|
|
139
|
-
type.types[individuals.find((i) => i[0].arrays.length === 1)![1]]!,
|
|
140
|
-
{
|
|
141
|
-
...explore,
|
|
142
|
-
aliased: false,
|
|
143
|
-
escaped: false,
|
|
144
|
-
},
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
} else if (atomics.size)
|
|
148
|
-
ArrayUtil.add(
|
|
149
|
-
meta.atomics,
|
|
150
|
-
MetadataAtomic.create({
|
|
151
|
-
type: atomics.values().next().value as "string",
|
|
152
|
-
tags: [],
|
|
153
|
-
}),
|
|
154
|
-
(a, b) => a.type === b.type,
|
|
155
|
-
);
|
|
156
|
-
else if (constants.length)
|
|
157
|
-
ArrayUtil.take(
|
|
158
|
-
ArrayUtil.take(
|
|
159
|
-
meta.constants,
|
|
160
|
-
(o) => o.type === target,
|
|
161
|
-
() =>
|
|
162
|
-
MetadataConstant.create({
|
|
163
|
-
type: target,
|
|
164
|
-
values: [],
|
|
165
|
-
}),
|
|
166
|
-
).values,
|
|
167
|
-
(o) => o.value === constants[0]!.constants[0]!.values[0]!.value,
|
|
168
|
-
() =>
|
|
169
|
-
MetadataConstantValue.create({
|
|
170
|
-
value: constants[0]!.constants[0]!.values[0]!.value,
|
|
171
|
-
tags: [],
|
|
172
|
-
}),
|
|
173
|
-
);
|
|
174
|
-
else if (templates.length)
|
|
175
|
-
ArrayUtil.take(
|
|
176
|
-
meta.templates,
|
|
177
|
-
(o) => o.getBaseName() === templates[0]!.templates[0]!.getBaseName(),
|
|
178
|
-
() =>
|
|
179
|
-
MetadataTemplate.create({
|
|
180
|
-
row: templates[0]!.templates[0]!.row,
|
|
181
|
-
tags: [],
|
|
182
|
-
}),
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
// ASSIGN TAGS
|
|
186
|
-
if (objects.length) {
|
|
187
|
-
const tags: IMetadataTypeTag[] = MetadataTypeTagFactory.analyze(errors)(
|
|
188
|
-
target,
|
|
189
|
-
)(objects.map((om) => om.objects).flat(), explore);
|
|
190
|
-
if (tags.length)
|
|
191
|
-
if (target === "array") meta.arrays.at(-1)!.tags.push(tags);
|
|
192
|
-
else if (atomics.size)
|
|
193
|
-
meta.atomics.find((a) => a.type === target)!.tags.push(tags);
|
|
194
|
-
else if (constants.length) {
|
|
195
|
-
const constant: MetadataConstant = meta.constants.find(
|
|
196
|
-
(c) => c.type === target,
|
|
197
|
-
)!;
|
|
198
|
-
const value: MetadataConstantValue = constant.values.find(
|
|
199
|
-
(v) => v.value === constants[0]!.constants[0]!.values[0]!.value,
|
|
200
|
-
)!;
|
|
201
|
-
value.tags ??= [];
|
|
202
|
-
value.tags.push(tags);
|
|
203
|
-
} else if (templates.length) {
|
|
204
|
-
const template: MetadataTemplate = meta.templates.find(
|
|
205
|
-
(t) =>
|
|
206
|
-
t.getBaseName() === templates[0]!.templates[0]!.getBaseName(),
|
|
207
|
-
)!;
|
|
208
|
-
template.tags ??= [];
|
|
209
|
-
template.tags.push(tags);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return true;
|
|
213
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IMetadataTypeTag } from "../../../schemas/metadata/IMetadataTypeTag";
|
|
4
|
+
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
5
|
+
import { MetadataAtomic } from "../../../schemas/metadata/MetadataAtomic";
|
|
6
|
+
import { MetadataConstant } from "../../../schemas/metadata/MetadataConstant";
|
|
7
|
+
import { MetadataConstantValue } from "../../../schemas/metadata/MetadataConstantValue";
|
|
8
|
+
import { MetadataTemplate } from "../../../schemas/metadata/MetadataTemplate";
|
|
9
|
+
|
|
10
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
11
|
+
|
|
12
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
+
import { MetadataTypeTagFactory } from "../../MetadataTypeTagFactory";
|
|
15
|
+
import { explore_metadata } from "./explore_metadata";
|
|
16
|
+
import { iterate_metadata } from "./iterate_metadata";
|
|
17
|
+
import { iterate_metadata_array } from "./iterate_metadata_array";
|
|
18
|
+
|
|
19
|
+
export const iterate_metadata_intersection =
|
|
20
|
+
(checker: ts.TypeChecker) =>
|
|
21
|
+
(options: MetadataFactory.IOptions) =>
|
|
22
|
+
(collection: MetadataCollection) =>
|
|
23
|
+
(errors: MetadataFactory.IError[]) =>
|
|
24
|
+
(
|
|
25
|
+
meta: Metadata,
|
|
26
|
+
type: ts.Type,
|
|
27
|
+
explore: MetadataFactory.IExplore,
|
|
28
|
+
): boolean => {
|
|
29
|
+
if (!type.isIntersection()) return false;
|
|
30
|
+
if (
|
|
31
|
+
// ONLY OBJECT TYPED INTERSECTION
|
|
32
|
+
type.types.every(
|
|
33
|
+
(child) =>
|
|
34
|
+
(child.getFlags() & ts.TypeFlags.Object) !== 0 &&
|
|
35
|
+
!checker.isArrayType(child) &&
|
|
36
|
+
!checker.isTupleType(child),
|
|
37
|
+
)
|
|
38
|
+
)
|
|
39
|
+
return false;
|
|
40
|
+
|
|
41
|
+
// COSTRUCT FAKE METADATA LIST
|
|
42
|
+
const fakeCollection: MetadataCollection = collection.clone();
|
|
43
|
+
const fakeErrors: MetadataFactory.IError[] = [];
|
|
44
|
+
const children: Metadata[] = [
|
|
45
|
+
...new Map(
|
|
46
|
+
type.types.map((t) => {
|
|
47
|
+
const m: Metadata = explore_metadata(checker)({
|
|
48
|
+
...options,
|
|
49
|
+
absorb: true,
|
|
50
|
+
})(fakeCollection)(fakeErrors)(t, {
|
|
51
|
+
...explore,
|
|
52
|
+
aliased: false,
|
|
53
|
+
});
|
|
54
|
+
return [m.getName(), m] as const;
|
|
55
|
+
}),
|
|
56
|
+
).values(),
|
|
57
|
+
];
|
|
58
|
+
if (fakeErrors.length) {
|
|
59
|
+
errors.push(...fakeErrors);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ONLY ONE CHILD AFTER REMOVING DUPLICATES
|
|
64
|
+
if (children.length === 1) {
|
|
65
|
+
iterate_metadata(checker)(options)(collection)(errors)(
|
|
66
|
+
meta,
|
|
67
|
+
type.types[0]!,
|
|
68
|
+
explore,
|
|
69
|
+
);
|
|
70
|
+
return true;
|
|
71
|
+
} else if (children.every((c) => c.objects.length === c.size()))
|
|
72
|
+
// ONLY OBJECT TYPED INTERSECTION (DETAILED)
|
|
73
|
+
return false;
|
|
74
|
+
|
|
75
|
+
// VALIDATE EACH TYPES
|
|
76
|
+
const nonsensible = () => {
|
|
77
|
+
errors.push({
|
|
78
|
+
name: children.map((c) => c.getName()).join(" & "),
|
|
79
|
+
explore: { ...explore },
|
|
80
|
+
messages: ["nonsensible intersection"],
|
|
81
|
+
});
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
84
|
+
const individuals: (readonly [Metadata, number])[] = children
|
|
85
|
+
.map((child, i) => [child, i] as const)
|
|
86
|
+
.filter(
|
|
87
|
+
([c]) =>
|
|
88
|
+
(c.size() === 1 &&
|
|
89
|
+
(c.atomics.length === 1 ||
|
|
90
|
+
(c.constants.length === 1 &&
|
|
91
|
+
c.constants[0]!.values.length === 1) ||
|
|
92
|
+
c.arrays.length === 1)) ||
|
|
93
|
+
c.templates.length === 1,
|
|
94
|
+
);
|
|
95
|
+
if (individuals.length !== 1) return nonsensible();
|
|
96
|
+
|
|
97
|
+
const objects: Metadata[] = children.filter(
|
|
98
|
+
(c) =>
|
|
99
|
+
c.nullable === false &&
|
|
100
|
+
c.isRequired() === true &&
|
|
101
|
+
c.objects.length &&
|
|
102
|
+
c.objects.length === c.size() &&
|
|
103
|
+
c.objects.every((o) => o.properties.every((p) => p.value.optional)),
|
|
104
|
+
);
|
|
105
|
+
const arrays: Set<string> = new Set(
|
|
106
|
+
individuals.map(([c]) => c.arrays.map((a) => a.type.name)).flat(),
|
|
107
|
+
);
|
|
108
|
+
const atomics: Set<"boolean" | "bigint" | "number" | "string"> = new Set(
|
|
109
|
+
individuals.map(([c]) => [...c.atomics.map((a) => a.type)]).flat(),
|
|
110
|
+
);
|
|
111
|
+
const constants: Metadata[] = individuals
|
|
112
|
+
.filter((i) => i[0].constants.length === 1)
|
|
113
|
+
.map(([m]) => m);
|
|
114
|
+
const templates: Metadata[] = individuals
|
|
115
|
+
.filter((i) => i[0].templates.length === 1)
|
|
116
|
+
.map(([m]) => m);
|
|
117
|
+
|
|
118
|
+
// ESCAPE WHEN ONLY CONSTANT TYPES EXIST
|
|
119
|
+
if (
|
|
120
|
+
atomics.size + constants.length + arrays.size + templates.length > 1 ||
|
|
121
|
+
individuals.length + objects.length !== children.length
|
|
122
|
+
)
|
|
123
|
+
return nonsensible();
|
|
124
|
+
|
|
125
|
+
// RE-GENERATE TYPE
|
|
126
|
+
const target: "boolean" | "bigint" | "number" | "string" | "array" =
|
|
127
|
+
arrays.size
|
|
128
|
+
? "array"
|
|
129
|
+
: atomics.size
|
|
130
|
+
? atomics.values().next().value
|
|
131
|
+
: constants.length
|
|
132
|
+
? constants[0]!.constants[0]!.type
|
|
133
|
+
: "string";
|
|
134
|
+
if (target === "array") {
|
|
135
|
+
const name: string = arrays.values().next().value;
|
|
136
|
+
if (!meta.arrays.some((a) => a.type.name === name)) {
|
|
137
|
+
iterate_metadata_array(checker)(options)(collection)(errors)(
|
|
138
|
+
meta,
|
|
139
|
+
type.types[individuals.find((i) => i[0].arrays.length === 1)![1]]!,
|
|
140
|
+
{
|
|
141
|
+
...explore,
|
|
142
|
+
aliased: false,
|
|
143
|
+
escaped: false,
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
} else if (atomics.size)
|
|
148
|
+
ArrayUtil.add(
|
|
149
|
+
meta.atomics,
|
|
150
|
+
MetadataAtomic.create({
|
|
151
|
+
type: atomics.values().next().value as "string",
|
|
152
|
+
tags: [],
|
|
153
|
+
}),
|
|
154
|
+
(a, b) => a.type === b.type,
|
|
155
|
+
);
|
|
156
|
+
else if (constants.length)
|
|
157
|
+
ArrayUtil.take(
|
|
158
|
+
ArrayUtil.take(
|
|
159
|
+
meta.constants,
|
|
160
|
+
(o) => o.type === target,
|
|
161
|
+
() =>
|
|
162
|
+
MetadataConstant.create({
|
|
163
|
+
type: target,
|
|
164
|
+
values: [],
|
|
165
|
+
}),
|
|
166
|
+
).values,
|
|
167
|
+
(o) => o.value === constants[0]!.constants[0]!.values[0]!.value,
|
|
168
|
+
() =>
|
|
169
|
+
MetadataConstantValue.create({
|
|
170
|
+
value: constants[0]!.constants[0]!.values[0]!.value,
|
|
171
|
+
tags: [],
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
else if (templates.length)
|
|
175
|
+
ArrayUtil.take(
|
|
176
|
+
meta.templates,
|
|
177
|
+
(o) => o.getBaseName() === templates[0]!.templates[0]!.getBaseName(),
|
|
178
|
+
() =>
|
|
179
|
+
MetadataTemplate.create({
|
|
180
|
+
row: templates[0]!.templates[0]!.row,
|
|
181
|
+
tags: [],
|
|
182
|
+
}),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// ASSIGN TAGS
|
|
186
|
+
if (objects.length) {
|
|
187
|
+
const tags: IMetadataTypeTag[] = MetadataTypeTagFactory.analyze(errors)(
|
|
188
|
+
target,
|
|
189
|
+
)(objects.map((om) => om.objects).flat(), explore);
|
|
190
|
+
if (tags.length)
|
|
191
|
+
if (target === "array") meta.arrays.at(-1)!.tags.push(tags);
|
|
192
|
+
else if (atomics.size)
|
|
193
|
+
meta.atomics.find((a) => a.type === target)!.tags.push(tags);
|
|
194
|
+
else if (constants.length) {
|
|
195
|
+
const constant: MetadataConstant = meta.constants.find(
|
|
196
|
+
(c) => c.type === target,
|
|
197
|
+
)!;
|
|
198
|
+
const value: MetadataConstantValue = constant.values.find(
|
|
199
|
+
(v) => v.value === constants[0]!.constants[0]!.values[0]!.value,
|
|
200
|
+
)!;
|
|
201
|
+
value.tags ??= [];
|
|
202
|
+
value.tags.push(tags);
|
|
203
|
+
} else if (templates.length) {
|
|
204
|
+
const template: MetadataTemplate = meta.templates.find(
|
|
205
|
+
(t) =>
|
|
206
|
+
t.getBaseName() === templates[0]!.templates[0]!.getBaseName(),
|
|
207
|
+
)!;
|
|
208
|
+
template.tags ??= [];
|
|
209
|
+
template.tags.push(tags);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
};
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
6
|
-
|
|
7
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
8
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
9
|
-
import { TypeFactory } from "../../TypeFactory";
|
|
10
|
-
import { explore_metadata } from "./explore_metadata";
|
|
11
|
-
|
|
12
|
-
export const iterate_metadata_map =
|
|
13
|
-
(checker: ts.TypeChecker) =>
|
|
14
|
-
(options: MetadataFactory.IOptions) =>
|
|
15
|
-
(collection: MetadataCollection) =>
|
|
16
|
-
(errors: MetadataFactory.IError[]) =>
|
|
17
|
-
(
|
|
18
|
-
meta: Metadata,
|
|
19
|
-
type: ts.Type,
|
|
20
|
-
explore: MetadataFactory.IExplore,
|
|
21
|
-
): boolean => {
|
|
22
|
-
type = checker.getApparentType(type);
|
|
23
|
-
|
|
24
|
-
const name = TypeFactory.getFullName(checker)(type, type.getSymbol());
|
|
25
|
-
const generic = type.aliasSymbol
|
|
26
|
-
? type.aliasTypeArguments
|
|
27
|
-
: checker.getTypeArguments(type as ts.TypeReference);
|
|
28
|
-
if (name.substring(0, 4) !== "Map<" || generic?.length !== 2) return false;
|
|
29
|
-
|
|
30
|
-
const key: ts.Type = generic[0]!;
|
|
31
|
-
const value: ts.Type = generic[1]!;
|
|
32
|
-
|
|
33
|
-
ArrayUtil.set(
|
|
34
|
-
meta.maps,
|
|
35
|
-
{
|
|
36
|
-
key: explore_metadata(checker)(options)(collection)(errors)(key, {
|
|
37
|
-
...explore,
|
|
38
|
-
escaped: false,
|
|
39
|
-
aliased: false,
|
|
40
|
-
}),
|
|
41
|
-
value: explore_metadata(checker)(options)(collection)(errors)(value, {
|
|
42
|
-
...explore,
|
|
43
|
-
escaped: false,
|
|
44
|
-
aliased: false,
|
|
45
|
-
}),
|
|
46
|
-
},
|
|
47
|
-
(elem) => `Map<${elem.key.getName()}, ${elem.value.getName()}>`,
|
|
48
|
-
);
|
|
49
|
-
return true;
|
|
50
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
6
|
+
|
|
7
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
8
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
9
|
+
import { TypeFactory } from "../../TypeFactory";
|
|
10
|
+
import { explore_metadata } from "./explore_metadata";
|
|
11
|
+
|
|
12
|
+
export const iterate_metadata_map =
|
|
13
|
+
(checker: ts.TypeChecker) =>
|
|
14
|
+
(options: MetadataFactory.IOptions) =>
|
|
15
|
+
(collection: MetadataCollection) =>
|
|
16
|
+
(errors: MetadataFactory.IError[]) =>
|
|
17
|
+
(
|
|
18
|
+
meta: Metadata,
|
|
19
|
+
type: ts.Type,
|
|
20
|
+
explore: MetadataFactory.IExplore,
|
|
21
|
+
): boolean => {
|
|
22
|
+
type = checker.getApparentType(type);
|
|
23
|
+
|
|
24
|
+
const name = TypeFactory.getFullName(checker)(type, type.getSymbol());
|
|
25
|
+
const generic = type.aliasSymbol
|
|
26
|
+
? type.aliasTypeArguments
|
|
27
|
+
: checker.getTypeArguments(type as ts.TypeReference);
|
|
28
|
+
if (name.substring(0, 4) !== "Map<" || generic?.length !== 2) return false;
|
|
29
|
+
|
|
30
|
+
const key: ts.Type = generic[0]!;
|
|
31
|
+
const value: ts.Type = generic[1]!;
|
|
32
|
+
|
|
33
|
+
ArrayUtil.set(
|
|
34
|
+
meta.maps,
|
|
35
|
+
{
|
|
36
|
+
key: explore_metadata(checker)(options)(collection)(errors)(key, {
|
|
37
|
+
...explore,
|
|
38
|
+
escaped: false,
|
|
39
|
+
aliased: false,
|
|
40
|
+
}),
|
|
41
|
+
value: explore_metadata(checker)(options)(collection)(errors)(value, {
|
|
42
|
+
...explore,
|
|
43
|
+
escaped: false,
|
|
44
|
+
aliased: false,
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
(elem) => `Map<${elem.key.getName()}, ${elem.value.getName()}>`,
|
|
48
|
+
);
|
|
49
|
+
return true;
|
|
50
|
+
};
|