typia 5.2.7-dev.20231109 → 5.3.0-dev.20231112
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/MetadataCollection.d.ts +2 -2
- package/lib/factories/MetadataFactory.js +3 -2
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/internal/metadata/MetadataHelper.js +3 -2
- package/lib/factories/internal/metadata/MetadataHelper.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_constant.js +13 -8
- package/lib/factories/internal/metadata/iterate_metadata_constant.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js +8 -5
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
- package/lib/functional/$from.d.ts +3 -0
- package/lib/functional/$from.js +9 -0
- package/lib/functional/$from.js.map +1 -0
- package/lib/functional/Namespace.js +7 -0
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/module.d.ts +1 -0
- package/lib/module.js +2 -5
- package/lib/module.js.map +1 -1
- package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
- package/lib/programmers/internal/check_string.js +7 -4
- package/lib/programmers/internal/check_string.js.map +1 -1
- package/lib/programmers/internal/metadata_to_pattern.js +3 -1
- package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
- package/lib/reflect.d.ts +3 -0
- package/lib/reflect.js +13 -0
- package/lib/reflect.js.map +1 -0
- package/lib/schemas/metadata/IMetadataApplication.d.ts +2 -2
- package/lib/schemas/metadata/{IMetadataCollection.d.ts → IMetadataComponents.d.ts} +1 -1
- package/lib/schemas/metadata/{IMetadataCollection.js → IMetadataComponents.js} +1 -1
- package/lib/schemas/metadata/IMetadataComponents.js.map +1 -0
- package/lib/schemas/metadata/IMetadataConstant.d.ts +1 -1
- package/lib/schemas/metadata/IMetadataTypeTag.d.ts +2 -2
- package/lib/schemas/metadata/Metadata.d.ts +2 -2
- package/lib/schemas/metadata/Metadata.js +81 -167
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/schemas/metadata/MetadataAlias.js +1 -1
- package/lib/schemas/metadata/MetadataAlias.js.map +1 -1
- package/lib/schemas/metadata/MetadataApplication.d.ts +13 -0
- package/lib/schemas/metadata/MetadataApplication.js +30 -0
- package/lib/schemas/metadata/MetadataApplication.js.map +1 -0
- package/lib/schemas/metadata/MetadataArrayType.js +1 -1
- package/lib/schemas/metadata/MetadataArrayType.js.map +1 -1
- package/lib/schemas/metadata/MetadataAtomic.d.ts +1 -0
- package/lib/schemas/metadata/MetadataAtomic.js +28 -1
- package/lib/schemas/metadata/MetadataAtomic.js.map +1 -1
- package/lib/schemas/metadata/MetadataComponents.d.ts +16 -0
- package/lib/schemas/metadata/MetadataComponents.js +151 -0
- package/lib/schemas/metadata/MetadataComponents.js.map +1 -0
- package/lib/schemas/metadata/MetadataConstant.d.ts +9 -1
- package/lib/schemas/metadata/MetadataConstant.js +29 -0
- package/lib/schemas/metadata/MetadataConstant.js.map +1 -1
- package/lib/schemas/metadata/MetadataEscaped.js +4 -4
- package/lib/schemas/metadata/MetadataEscaped.js.map +1 -1
- package/lib/schemas/metadata/MetadataObject.js +2 -2
- package/lib/schemas/metadata/MetadataObject.js.map +1 -1
- package/lib/schemas/metadata/MetadataProperty.js +4 -4
- package/lib/schemas/metadata/MetadataProperty.js.map +1 -1
- package/lib/schemas/metadata/MetadataTupleType.js +1 -1
- package/lib/schemas/metadata/MetadataTupleType.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +5 -2
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.d.ts +5 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +58 -0
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -0
- package/package.json +1 -1
- package/src/factories/MetadataCollection.ts +2 -2
- package/src/factories/MetadataFactory.ts +7 -4
- package/src/factories/internal/metadata/MetadataHelper.ts +7 -4
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +10 -8
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +9 -8
- package/src/functional/$from.ts +5 -0
- package/src/functional/Namespace.ts +7 -0
- package/src/module.ts +1 -19
- package/src/programmers/helpers/ProtobufUtil.ts +3 -2
- package/src/programmers/internal/check_string.ts +5 -2
- package/src/programmers/internal/metadata_to_pattern.ts +3 -1
- package/src/reflect.ts +24 -0
- package/src/schemas/metadata/IMetadataApplication.ts +2 -2
- package/src/schemas/metadata/{IMetadataCollection.ts → IMetadataComponents.ts} +1 -1
- package/src/schemas/metadata/IMetadataConstant.ts +1 -1
- package/src/schemas/metadata/IMetadataTypeTag.ts +2 -2
- package/src/schemas/metadata/Metadata.ts +17 -85
- package/src/schemas/metadata/MetadataAlias.ts +1 -1
- package/src/schemas/metadata/MetadataApplication.ts +44 -0
- package/src/schemas/metadata/MetadataArrayType.ts +1 -1
- package/src/schemas/metadata/MetadataAtomic.ts +28 -1
- package/src/schemas/metadata/MetadataComponents.ts +98 -0
- package/src/schemas/metadata/MetadataConstant.ts +44 -1
- package/src/schemas/metadata/MetadataEscaped.ts +4 -4
- package/src/schemas/metadata/MetadataObject.ts +2 -2
- package/src/schemas/metadata/MetadataProperty.ts +4 -7
- package/src/schemas/metadata/MetadataTupleType.ts +1 -1
- package/src/transformers/CallExpressionTransformer.ts +5 -2
- package/src/transformers/features/{misc/MetadataTransformer.ts → reflect/ReflectMetadataTransformer.ts} +19 -5
- package/lib/schemas/metadata/IMetadataCollection.js.map +0 -1
- package/lib/transformers/features/misc/MetadataTransformer.d.ts +0 -5
- package/lib/transformers/features/misc/MetadataTransformer.js +0 -54
- package/lib/transformers/features/misc/MetadataTransformer.js.map +0 -1
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
-
import { Writable } from "../../typings/Writable";
|
|
3
2
|
|
|
4
3
|
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
5
4
|
|
|
6
5
|
import { IMetadata } from "./IMetadata";
|
|
7
|
-
import { IMetadataCollection } from "./IMetadataCollection";
|
|
8
6
|
import { IMetadataDictionary } from "./IMetadataDictionary";
|
|
9
7
|
import { IMetadataTypeTag } from "./IMetadataTypeTag";
|
|
10
8
|
import { MetadataAlias } from "./MetadataAlias";
|
|
11
9
|
import { MetadataArray } from "./MetadataArray";
|
|
12
|
-
import { MetadataArrayType } from "./MetadataArrayType";
|
|
13
10
|
import { MetadataAtomic } from "./MetadataAtomic";
|
|
14
11
|
import { MetadataConstant } from "./MetadataConstant";
|
|
15
12
|
import { MetadataEscaped } from "./MetadataEscaped";
|
|
16
13
|
import { MetadataObject } from "./MetadataObject";
|
|
17
|
-
import { MetadataProperty } from "./MetadataProperty";
|
|
18
14
|
import { MetadataTuple } from "./MetadataTuple";
|
|
19
|
-
import { MetadataTupleType } from "./MetadataTupleType";
|
|
20
15
|
|
|
21
16
|
export class Metadata {
|
|
22
17
|
public any: boolean;
|
|
@@ -86,7 +81,7 @@ export class Metadata {
|
|
|
86
81
|
* @internal
|
|
87
82
|
*/
|
|
88
83
|
public static initialize(parentResolved: boolean = false): Metadata {
|
|
89
|
-
const meta: Metadata =
|
|
84
|
+
const meta: Metadata = Metadata.create({
|
|
90
85
|
any: false,
|
|
91
86
|
nullable: false,
|
|
92
87
|
required: true,
|
|
@@ -120,10 +115,7 @@ export class Metadata {
|
|
|
120
115
|
functional: this.functional,
|
|
121
116
|
|
|
122
117
|
atomics: this.atomics.map((a) => a.toJSON()),
|
|
123
|
-
constants: this.constants.map((c) => (
|
|
124
|
-
type: c.type,
|
|
125
|
-
values: c.values.slice() as any,
|
|
126
|
-
})),
|
|
118
|
+
constants: this.constants.map((c) => c.toJSON()),
|
|
127
119
|
templates: this.templates.map((tpl) =>
|
|
128
120
|
tpl.map((meta) => meta.toJSON()),
|
|
129
121
|
),
|
|
@@ -150,85 +142,24 @@ export class Metadata {
|
|
|
150
142
|
};
|
|
151
143
|
}
|
|
152
144
|
|
|
153
|
-
public static from(
|
|
154
|
-
|
|
155
|
-
collection: IMetadataCollection,
|
|
156
|
-
): Metadata {
|
|
157
|
-
const dict: IMetadataDictionary = {
|
|
158
|
-
objects: new Map(
|
|
159
|
-
collection.objects.map((obj) => [
|
|
160
|
-
obj.name,
|
|
161
|
-
MetadataObject._From_without_properties(obj),
|
|
162
|
-
]),
|
|
163
|
-
),
|
|
164
|
-
aliases: new Map(
|
|
165
|
-
collection.aliases.map((alias) => [
|
|
166
|
-
alias.name,
|
|
167
|
-
MetadataAlias._From_without_value(alias),
|
|
168
|
-
]),
|
|
169
|
-
),
|
|
170
|
-
arrays: new Map(
|
|
171
|
-
collection.arrays.map((arr) => [
|
|
172
|
-
arr.name,
|
|
173
|
-
MetadataArrayType._From_without_value(arr),
|
|
174
|
-
]),
|
|
175
|
-
),
|
|
176
|
-
tuples: new Map(
|
|
177
|
-
collection.tuples.map((tpl) => [
|
|
178
|
-
tpl.name,
|
|
179
|
-
MetadataTupleType._From_without_elements(tpl),
|
|
180
|
-
]),
|
|
181
|
-
),
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
for (const obj of collection.objects) {
|
|
185
|
-
const initialized = dict.objects.get(obj.name)!;
|
|
186
|
-
initialized.properties.push(
|
|
187
|
-
...obj.properties.map((prop) =>
|
|
188
|
-
MetadataProperty._From(prop, dict),
|
|
189
|
-
),
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
for (const alias of collection.aliases)
|
|
193
|
-
Writable(dict.aliases.get(alias.name)!).value = this._From(
|
|
194
|
-
alias.value,
|
|
195
|
-
dict,
|
|
196
|
-
);
|
|
197
|
-
for (const array of collection.arrays)
|
|
198
|
-
Writable(dict.arrays.get(array.name)!).value = this._From(
|
|
199
|
-
array.value,
|
|
200
|
-
dict,
|
|
201
|
-
);
|
|
202
|
-
for (const tuple of collection.tuples)
|
|
203
|
-
Writable(dict.tuples.get(tuple.name)!).elements =
|
|
204
|
-
tuple.elements.map((elem) => this._From(elem, dict));
|
|
205
|
-
|
|
206
|
-
return this._From(meta, dict);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @internal
|
|
211
|
-
*/
|
|
212
|
-
public static _From(meta: IMetadata, dict: IMetadataDictionary): Metadata {
|
|
213
|
-
return this.create({
|
|
145
|
+
public static from(meta: IMetadata, dict: IMetadataDictionary): Metadata {
|
|
146
|
+
return Metadata.create({
|
|
214
147
|
any: meta.any,
|
|
215
148
|
required: meta.required,
|
|
216
149
|
optional: meta.optional,
|
|
217
150
|
nullable: meta.nullable,
|
|
218
151
|
functional: meta.functional,
|
|
219
152
|
|
|
220
|
-
constants: meta.constants.
|
|
221
|
-
atomics: meta.atomics.map(
|
|
222
|
-
MetadataAtomic.create({ type: a.type, tags: a.tags }),
|
|
223
|
-
),
|
|
153
|
+
constants: meta.constants.map(MetadataConstant.from),
|
|
154
|
+
atomics: meta.atomics.map(MetadataAtomic.from),
|
|
224
155
|
templates: meta.templates.map((tpl) =>
|
|
225
|
-
tpl.map((meta) => this.
|
|
156
|
+
tpl.map((meta) => this.from(meta, dict)),
|
|
226
157
|
),
|
|
227
158
|
escaped: meta.escaped
|
|
228
|
-
? MetadataEscaped.
|
|
159
|
+
? MetadataEscaped.from(meta.escaped, dict)
|
|
229
160
|
: null,
|
|
230
161
|
|
|
231
|
-
rest: meta.rest ? this.
|
|
162
|
+
rest: meta.rest ? this.from(meta.rest, dict) : null,
|
|
232
163
|
arrays: meta.arrays.map((ref) => {
|
|
233
164
|
const type = dict.arrays.get(ref.name);
|
|
234
165
|
if (type === undefined)
|
|
@@ -269,10 +200,10 @@ export class Metadata {
|
|
|
269
200
|
}),
|
|
270
201
|
|
|
271
202
|
natives: meta.natives.slice(),
|
|
272
|
-
sets: meta.sets.map((meta) => this.
|
|
203
|
+
sets: meta.sets.map((meta) => this.from(meta, dict)),
|
|
273
204
|
maps: meta.maps.map((entry) => ({
|
|
274
|
-
key: this.
|
|
275
|
-
value: this.
|
|
205
|
+
key: this.from(entry.key, dict),
|
|
206
|
+
value: this.from(entry.value, dict),
|
|
276
207
|
})),
|
|
277
208
|
});
|
|
278
209
|
}
|
|
@@ -565,10 +496,11 @@ export namespace Metadata {
|
|
|
565
496
|
const target: MetadataConstant = ArrayUtil.take(
|
|
566
497
|
output.constants,
|
|
567
498
|
(elem) => elem.type === constant.type,
|
|
568
|
-
() =>
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
499
|
+
() =>
|
|
500
|
+
MetadataConstant.create({
|
|
501
|
+
type: constant.type,
|
|
502
|
+
values: [],
|
|
503
|
+
}),
|
|
572
504
|
);
|
|
573
505
|
for (const value of constant.values)
|
|
574
506
|
ArrayUtil.add(target.values, value);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
+
|
|
3
|
+
import { IMetadataApplication } from "./IMetadataApplication";
|
|
4
|
+
import { Metadata } from "./Metadata";
|
|
5
|
+
import { MetadataComponents } from "./MetadataComponents";
|
|
6
|
+
|
|
7
|
+
export class MetadataApplication {
|
|
8
|
+
public readonly metadatas: Metadata[];
|
|
9
|
+
public readonly components: MetadataComponents;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @hidden
|
|
13
|
+
*/
|
|
14
|
+
private constructor(props: ClassProperties<MetadataApplication>) {
|
|
15
|
+
this.metadatas = props.metadatas;
|
|
16
|
+
this.components = props.components;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
public static create(
|
|
23
|
+
props: ClassProperties<MetadataApplication>,
|
|
24
|
+
): MetadataApplication {
|
|
25
|
+
return new MetadataApplication(props);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static from(app: IMetadataApplication): MetadataApplication {
|
|
29
|
+
const components: MetadataComponents = MetadataComponents.from(
|
|
30
|
+
app.components,
|
|
31
|
+
);
|
|
32
|
+
const metadatas: Metadata[] = app.metadatas.map((metadata) =>
|
|
33
|
+
Metadata.from(metadata, components.dictionary),
|
|
34
|
+
);
|
|
35
|
+
return MetadataApplication.create({ metadatas, components });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public toJSON(): IMetadataApplication {
|
|
39
|
+
return {
|
|
40
|
+
metadatas: this.metadatas.map((metadata) => metadata.toJSON()),
|
|
41
|
+
components: this.components.toJSON(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -27,7 +27,7 @@ export class MetadataArrayType {
|
|
|
27
27
|
public static _From_without_value(
|
|
28
28
|
props: Omit<IMetadataArrayType, "value">,
|
|
29
29
|
): MetadataArrayType {
|
|
30
|
-
return
|
|
30
|
+
return MetadataArrayType.create({
|
|
31
31
|
name: props.name,
|
|
32
32
|
value: null!,
|
|
33
33
|
index: props.index,
|
|
@@ -23,6 +23,27 @@ export class MetadataAtomic {
|
|
|
23
23
|
return new MetadataAtomic(props);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
public static from(json: IMetadataAtomic): MetadataAtomic {
|
|
27
|
+
return MetadataAtomic.create({
|
|
28
|
+
type: json.type,
|
|
29
|
+
tags: json.tags.map((row) =>
|
|
30
|
+
row.map((tag) => ({
|
|
31
|
+
target: tag.target,
|
|
32
|
+
name: tag.name,
|
|
33
|
+
kind: tag.kind,
|
|
34
|
+
value:
|
|
35
|
+
typeof tag.value === "object" &&
|
|
36
|
+
tag.value?.type === "bigint" &&
|
|
37
|
+
typeof tag.value.value === "string"
|
|
38
|
+
? BigInt(tag.value.value)
|
|
39
|
+
: tag.value,
|
|
40
|
+
validate: tag.validate,
|
|
41
|
+
exclusive: tag.exclusive,
|
|
42
|
+
})),
|
|
43
|
+
),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
26
47
|
public getName(): string {
|
|
27
48
|
return (this.name_ ??= (() => {
|
|
28
49
|
if (this.tags.length === 0) return this.type;
|
|
@@ -49,7 +70,13 @@ export class MetadataAtomic {
|
|
|
49
70
|
target: tag.target,
|
|
50
71
|
name: tag.name,
|
|
51
72
|
kind: tag.kind,
|
|
52
|
-
value:
|
|
73
|
+
value:
|
|
74
|
+
typeof tag.value === "bigint"
|
|
75
|
+
? {
|
|
76
|
+
type: "bigint",
|
|
77
|
+
value: tag.value.toString(),
|
|
78
|
+
}
|
|
79
|
+
: tag.value,
|
|
53
80
|
validate: tag.validate,
|
|
54
81
|
exclusive: tag.exclusive,
|
|
55
82
|
})),
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
+
import { Writable } from "../../typings/Writable";
|
|
3
|
+
|
|
4
|
+
import { IMetadataComponents } from "./IMetadataComponents";
|
|
5
|
+
import { IMetadataDictionary } from "./IMetadataDictionary";
|
|
6
|
+
import { Metadata } from "./Metadata";
|
|
7
|
+
import { MetadataAlias } from "./MetadataAlias";
|
|
8
|
+
import { MetadataArrayType } from "./MetadataArrayType";
|
|
9
|
+
import { MetadataObject } from "./MetadataObject";
|
|
10
|
+
import { MetadataProperty } from "./MetadataProperty";
|
|
11
|
+
import { MetadataTupleType } from "./MetadataTupleType";
|
|
12
|
+
|
|
13
|
+
export class MetadataComponents {
|
|
14
|
+
public readonly aliases: MetadataAlias[];
|
|
15
|
+
public readonly objects: MetadataObject[];
|
|
16
|
+
public readonly arrays: MetadataArrayType[];
|
|
17
|
+
public readonly tuples: MetadataTupleType[];
|
|
18
|
+
public readonly dictionary: IMetadataDictionary;
|
|
19
|
+
|
|
20
|
+
private constructor(props: ClassProperties<MetadataComponents>) {
|
|
21
|
+
this.aliases = props.aliases;
|
|
22
|
+
this.objects = props.objects;
|
|
23
|
+
this.arrays = props.arrays;
|
|
24
|
+
this.tuples = props.tuples;
|
|
25
|
+
this.dictionary = props.dictionary;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static from(json: IMetadataComponents): MetadataComponents {
|
|
29
|
+
// INITIALIZE COMPONENTS
|
|
30
|
+
const dictionary: IMetadataDictionary = {
|
|
31
|
+
objects: new Map(
|
|
32
|
+
json.objects.map((obj) => [
|
|
33
|
+
obj.name,
|
|
34
|
+
MetadataObject._From_without_properties(obj),
|
|
35
|
+
]),
|
|
36
|
+
),
|
|
37
|
+
aliases: new Map(
|
|
38
|
+
json.aliases.map((alias) => [
|
|
39
|
+
alias.name,
|
|
40
|
+
MetadataAlias._From_without_value(alias),
|
|
41
|
+
]),
|
|
42
|
+
),
|
|
43
|
+
arrays: new Map(
|
|
44
|
+
json.arrays.map((arr) => [
|
|
45
|
+
arr.name,
|
|
46
|
+
MetadataArrayType._From_without_value(arr),
|
|
47
|
+
]),
|
|
48
|
+
),
|
|
49
|
+
tuples: new Map(
|
|
50
|
+
json.tuples.map((tpl) => [
|
|
51
|
+
tpl.name,
|
|
52
|
+
MetadataTupleType._From_without_elements(tpl),
|
|
53
|
+
]),
|
|
54
|
+
),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// CONSTRUCT METADATA OF THEM
|
|
58
|
+
for (const obj of json.objects)
|
|
59
|
+
dictionary.objects
|
|
60
|
+
.get(obj.name)!
|
|
61
|
+
.properties.push(
|
|
62
|
+
...obj.properties.map((prop) =>
|
|
63
|
+
MetadataProperty.from(prop, dictionary),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
for (const alias of json.aliases)
|
|
67
|
+
Writable(dictionary.aliases.get(alias.name)!).value = Metadata.from(
|
|
68
|
+
alias.value,
|
|
69
|
+
dictionary,
|
|
70
|
+
);
|
|
71
|
+
for (const array of json.arrays)
|
|
72
|
+
Writable(dictionary.arrays.get(array.name)!).value = Metadata.from(
|
|
73
|
+
array.value,
|
|
74
|
+
dictionary,
|
|
75
|
+
);
|
|
76
|
+
for (const tuple of json.tuples)
|
|
77
|
+
Writable(dictionary.tuples.get(tuple.name)!).elements =
|
|
78
|
+
tuple.elements.map((elem) => Metadata.from(elem, dictionary));
|
|
79
|
+
|
|
80
|
+
// FINALIZE
|
|
81
|
+
return new MetadataComponents({
|
|
82
|
+
aliases: [...dictionary.aliases.values()],
|
|
83
|
+
objects: [...dictionary.objects.values()],
|
|
84
|
+
arrays: [...dictionary.arrays.values()],
|
|
85
|
+
tuples: [...dictionary.tuples.values()],
|
|
86
|
+
dictionary,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public toJSON(): IMetadataComponents {
|
|
91
|
+
return {
|
|
92
|
+
aliases: this.aliases.map((alias) => alias.toJSON()),
|
|
93
|
+
objects: this.objects.map((object) => object.toJSON()),
|
|
94
|
+
arrays: this.arrays.map((array) => array.toJSON()),
|
|
95
|
+
tuples: this.tuples.map((tuple) => tuple.toJSON()),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
import { ClassProperties } from "../../typings/ClassProperties";
|
|
2
|
+
|
|
1
3
|
import { IMetadataConstant } from "./IMetadataConstant";
|
|
4
|
+
import { IMetadataTypeTag } from "./IMetadataTypeTag";
|
|
5
|
+
|
|
6
|
+
export class MetadataConstant {
|
|
7
|
+
public readonly type: "boolean" | "bigint" | "number" | "string";
|
|
8
|
+
public readonly values: boolean[] | bigint[] | number[] | string[];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
public tags?: IMetadataTypeTag[][] | undefined;
|
|
14
|
+
|
|
15
|
+
private constructor(props: ClassProperties<MetadataConstant>) {
|
|
16
|
+
this.type = props.type;
|
|
17
|
+
this.values = props.values;
|
|
18
|
+
this.tags = props.tags;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static create(
|
|
22
|
+
props: ClassProperties<MetadataConstant>,
|
|
23
|
+
): MetadataConstant {
|
|
24
|
+
return new MetadataConstant(props);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static from(json: IMetadataConstant): MetadataConstant {
|
|
28
|
+
return MetadataConstant.create({
|
|
29
|
+
type: json.type,
|
|
30
|
+
values:
|
|
31
|
+
json.type === "bigint"
|
|
32
|
+
? json.values.map((v) => BigInt(v))
|
|
33
|
+
: (json.values as any[]),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
2
36
|
|
|
3
|
-
|
|
37
|
+
public toJSON(): IMetadataConstant {
|
|
38
|
+
return {
|
|
39
|
+
type: this.type,
|
|
40
|
+
values:
|
|
41
|
+
this.type === "bigint"
|
|
42
|
+
? this.values.map((v) => v.toString())
|
|
43
|
+
: (this.values as any[]),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -19,13 +19,13 @@ export class MetadataEscaped {
|
|
|
19
19
|
/**
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
public static
|
|
22
|
+
public static from(
|
|
23
23
|
props: IMetadataEscaped,
|
|
24
24
|
dict: IMetadataDictionary,
|
|
25
25
|
): MetadataEscaped {
|
|
26
|
-
return
|
|
27
|
-
original: Metadata.
|
|
28
|
-
returns: Metadata.
|
|
26
|
+
return MetadataEscaped.create({
|
|
27
|
+
original: Metadata.from(props.original, dict),
|
|
28
|
+
returns: Metadata.from(props.returns, dict),
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -37,7 +37,7 @@ export class MetadataObject {
|
|
|
37
37
|
this.index = props.index;
|
|
38
38
|
this.validated = props.validated;
|
|
39
39
|
this.recursive = props.recursive;
|
|
40
|
-
this.nullables =
|
|
40
|
+
this.nullables = props.nullables.slice();
|
|
41
41
|
|
|
42
42
|
this.tagged_ = false;
|
|
43
43
|
}
|
|
@@ -57,7 +57,7 @@ export class MetadataObject {
|
|
|
57
57
|
public static _From_without_properties(
|
|
58
58
|
obj: IMetadataObject,
|
|
59
59
|
): MetadataObject {
|
|
60
|
-
return
|
|
60
|
+
return MetadataObject.create({
|
|
61
61
|
name: obj.name,
|
|
62
62
|
properties: [],
|
|
63
63
|
description: obj.description,
|
|
@@ -36,13 +36,10 @@ export class MetadataProperty {
|
|
|
36
36
|
/**
|
|
37
37
|
* @internal
|
|
38
38
|
*/
|
|
39
|
-
public static
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return this.create({
|
|
44
|
-
key: Metadata._From(property.key, dict),
|
|
45
|
-
value: Metadata._From(property.value, dict),
|
|
39
|
+
public static from(property: IMetadataProperty, dict: IMetadataDictionary) {
|
|
40
|
+
return MetadataProperty.create({
|
|
41
|
+
key: Metadata.from(property.key, dict),
|
|
42
|
+
value: Metadata.from(property.value, dict),
|
|
46
43
|
description: property.description,
|
|
47
44
|
jsDocTags: property.jsDocTags.slice(),
|
|
48
45
|
});
|
|
@@ -33,7 +33,7 @@ export class MetadataTupleType {
|
|
|
33
33
|
public static _From_without_elements(
|
|
34
34
|
props: Omit<IMetadataTupleType, "elements">,
|
|
35
35
|
): MetadataTupleType {
|
|
36
|
-
return
|
|
36
|
+
return MetadataTupleType.create({
|
|
37
37
|
name: props.name,
|
|
38
38
|
index: props.index,
|
|
39
39
|
elements: null!,
|
|
@@ -45,7 +45,6 @@ import { JsonIsStringifyTransformer } from "./features/json/JsonIsStringifyTrans
|
|
|
45
45
|
import { JsonStringifyTransformer } from "./features/json/JsonStringifyTransformer";
|
|
46
46
|
import { JsonValidateParseTransformer } from "./features/json/JsonValidateParseTransformer";
|
|
47
47
|
import { JsonValidateStringifyTransformer } from "./features/json/JsonValidateStringifyTransformer";
|
|
48
|
-
import { MetadataTransformer } from "./features/misc/MetadataTransformer";
|
|
49
48
|
import { MiscAssertCloneTransformer } from "./features/misc/MiscAssertCloneTransformer";
|
|
50
49
|
import { MiscAssertPruneTransformer } from "./features/misc/MiscAssertPruneTransformer";
|
|
51
50
|
import { MiscCloneTransformer } from "./features/misc/MiscCloneTransformer";
|
|
@@ -88,6 +87,7 @@ import { ProtobufIsEncodeTransformer } from "./features/protobuf/ProtobufIsEncod
|
|
|
88
87
|
import { ProtobufMessageTransformer } from "./features/protobuf/ProtobufMessageTransformer";
|
|
89
88
|
import { ProtobufValidateDecodeTransformer } from "./features/protobuf/ProtobufValidateDecodeTransformer";
|
|
90
89
|
import { ProtobufValidateEncodeTransformer } from "./features/protobuf/ProtobufValidateEncodeTransformer";
|
|
90
|
+
import { ReflectMetadataTransformer } from "./features/reflect/ReflectMetadataTransformer";
|
|
91
91
|
|
|
92
92
|
export namespace CallExpressionTransformer {
|
|
93
93
|
export const transform =
|
|
@@ -174,7 +174,7 @@ const FUNCTORS: Record<string, Record<string, () => Task>> = {
|
|
|
174
174
|
|
|
175
175
|
// RANDOM + INTERNAL
|
|
176
176
|
random: () => RandomTransformer.transform,
|
|
177
|
-
metadata: () =>
|
|
177
|
+
metadata: () => ReflectMetadataTransformer.transform,
|
|
178
178
|
|
|
179
179
|
// FACTORIES
|
|
180
180
|
createAssert: () => CreateAssertTransformer.transform(false),
|
|
@@ -270,6 +270,9 @@ const FUNCTORS: Record<string, Record<string, () => Task>> = {
|
|
|
270
270
|
createValidateDecode: () =>
|
|
271
271
|
ProtobufCreateValidateDecodeTransformer.transform,
|
|
272
272
|
},
|
|
273
|
+
reflect: {
|
|
274
|
+
metadata: () => ReflectMetadataTransformer.transform,
|
|
275
|
+
},
|
|
273
276
|
misc: {
|
|
274
277
|
literals: () => (project) => () =>
|
|
275
278
|
MiscLiteralsTransformer.transform(project),
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
+
import { IdentifierFactory } from "../../../factories/IdentifierFactory";
|
|
3
4
|
import { LiteralFactory } from "../../../factories/LiteralFactory";
|
|
4
5
|
import { MetadataCollection } from "../../../factories/MetadataCollection";
|
|
5
6
|
import { MetadataFactory } from "../../../factories/MetadataFactory";
|
|
7
|
+
import { TypeFactory } from "../../../factories/TypeFactory";
|
|
6
8
|
|
|
7
9
|
import { IMetadataApplication } from "../../../schemas/metadata/IMetadataApplication";
|
|
8
10
|
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
@@ -10,9 +12,10 @@ import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
|
10
12
|
import { IProject } from "../../IProject";
|
|
11
13
|
import { TransformerError } from "../../TransformerError";
|
|
12
14
|
|
|
13
|
-
export namespace
|
|
15
|
+
export namespace ReflectMetadataTransformer {
|
|
14
16
|
export const transform =
|
|
15
17
|
(project: IProject) =>
|
|
18
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
16
19
|
(expression: ts.CallExpression): ts.Expression => {
|
|
17
20
|
if (!expression.typeArguments?.length)
|
|
18
21
|
throw new TransformerError({
|
|
@@ -32,7 +35,7 @@ export namespace MetadataTransformer {
|
|
|
32
35
|
);
|
|
33
36
|
if (types.some((t) => t.isTypeParameter()))
|
|
34
37
|
throw new TransformerError({
|
|
35
|
-
code: "typia.metadata",
|
|
38
|
+
code: "typia.reflect.metadata",
|
|
36
39
|
message: "non-specified generic argument(s).",
|
|
37
40
|
});
|
|
38
41
|
|
|
@@ -48,7 +51,7 @@ export namespace MetadataTransformer {
|
|
|
48
51
|
absorb: true,
|
|
49
52
|
})(collection)(type);
|
|
50
53
|
if (result.success === false)
|
|
51
|
-
throw TransformerError.from("typia.metadata")(
|
|
54
|
+
throw TransformerError.from("typia.reflect.metadata")(
|
|
52
55
|
result.errors,
|
|
53
56
|
);
|
|
54
57
|
return result.data;
|
|
@@ -57,8 +60,19 @@ export namespace MetadataTransformer {
|
|
|
57
60
|
// CONVERT TO PRIMITIVE TYPE
|
|
58
61
|
const app: IMetadataApplication = {
|
|
59
62
|
metadatas: metadatas.map((metadata) => metadata.toJSON()),
|
|
60
|
-
|
|
63
|
+
components: collection.toJSON(),
|
|
61
64
|
};
|
|
62
|
-
return
|
|
65
|
+
return ts.factory.createCallExpression(
|
|
66
|
+
IdentifierFactory.access(
|
|
67
|
+
ts.factory.createParenthesizedExpression(
|
|
68
|
+
ts.factory.createAsExpression(
|
|
69
|
+
modulo,
|
|
70
|
+
TypeFactory.keyword("any"),
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
)("from"),
|
|
74
|
+
undefined,
|
|
75
|
+
[LiteralFactory.generate(app)],
|
|
76
|
+
);
|
|
63
77
|
};
|
|
64
78
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IMetadataCollection.js","sourceRoot":"","sources":["../../../src/schemas/metadata/IMetadataCollection.ts"],"names":[],"mappings":""}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MetadataTransformer = void 0;
|
|
7
|
-
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
-
var LiteralFactory_1 = require("../../../factories/LiteralFactory");
|
|
9
|
-
var MetadataCollection_1 = require("../../../factories/MetadataCollection");
|
|
10
|
-
var MetadataFactory_1 = require("../../../factories/MetadataFactory");
|
|
11
|
-
var TransformerError_1 = require("../../TransformerError");
|
|
12
|
-
var MetadataTransformer;
|
|
13
|
-
(function (MetadataTransformer) {
|
|
14
|
-
MetadataTransformer.transform = function (project) {
|
|
15
|
-
return function (expression) {
|
|
16
|
-
var _a;
|
|
17
|
-
if (!((_a = expression.typeArguments) === null || _a === void 0 ? void 0 : _a.length))
|
|
18
|
-
throw new TransformerError_1.TransformerError({
|
|
19
|
-
code: "typia.metadata",
|
|
20
|
-
message: "no generic argument.",
|
|
21
|
-
});
|
|
22
|
-
var top = expression.typeArguments[0];
|
|
23
|
-
if (!typescript_1.default.isTupleTypeNode(top))
|
|
24
|
-
return expression;
|
|
25
|
-
else if (top.elements.some(function (child) { return !typescript_1.default.isTypeNode(child); }))
|
|
26
|
-
return expression;
|
|
27
|
-
var types = top.elements.map(function (child) {
|
|
28
|
-
return project.checker.getTypeFromTypeNode(child);
|
|
29
|
-
});
|
|
30
|
-
if (types.some(function (t) { return t.isTypeParameter(); }))
|
|
31
|
-
throw new TransformerError_1.TransformerError({
|
|
32
|
-
code: "typia.metadata",
|
|
33
|
-
message: "non-specified generic argument(s).",
|
|
34
|
-
});
|
|
35
|
-
var collection = new MetadataCollection_1.MetadataCollection();
|
|
36
|
-
var metadatas = types.map(function (type) {
|
|
37
|
-
var result = MetadataFactory_1.MetadataFactory.analyze(project.checker, project.context)({
|
|
38
|
-
escape: true,
|
|
39
|
-
constant: true,
|
|
40
|
-
absorb: true,
|
|
41
|
-
})(collection)(type);
|
|
42
|
-
if (result.success === false)
|
|
43
|
-
throw TransformerError_1.TransformerError.from("typia.metadata")(result.errors);
|
|
44
|
-
return result.data;
|
|
45
|
-
});
|
|
46
|
-
var app = {
|
|
47
|
-
metadatas: metadatas.map(function (metadata) { return metadata.toJSON(); }),
|
|
48
|
-
collection: collection.toJSON(),
|
|
49
|
-
};
|
|
50
|
-
return LiteralFactory_1.LiteralFactory.generate(app);
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
})(MetadataTransformer || (exports.MetadataTransformer = MetadataTransformer = {}));
|
|
54
|
-
//# sourceMappingURL=MetadataTransformer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MetadataTransformer.js","sourceRoot":"","sources":["../../../../src/transformers/features/misc/MetadataTransformer.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,oEAAmE;AACnE,4EAA2E;AAC3E,sEAAqE;AAMrE,2DAA0D;AAE1D,IAAiB,mBAAmB,CAmDnC;AAnDD,WAAiB,mBAAmB;IACnB,6BAAS,GAClB,UAAC,OAAiB;QAClB,OAAA,UAAC,UAA6B;;YAC1B,IAAI,CAAC,CAAA,MAAA,UAAU,CAAC,aAAa,0CAAE,MAAM,CAAA;gBACjC,MAAM,IAAI,mCAAgB,CAAC;oBACvB,IAAI,EAAE,gBAAgB;oBACtB,OAAO,EAAE,sBAAsB;iBAClC,CAAC,CAAC;YAGP,IAAM,GAAG,GAAY,UAAU,CAAC,aAAa,CAAC,CAAC,CAAE,CAAC;YAClD,IAAI,CAAC,oBAAE,CAAC,eAAe,CAAC,GAAG,CAAC;gBAAE,OAAO,UAAU,CAAC;iBAC3C,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAC,KAAK,IAAK,OAAA,CAAC,oBAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAArB,CAAqB,CAAC;gBACxD,OAAO,UAAU,CAAC;YAGtB,IAAM,KAAK,GAAc,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAC,KAAK;gBAC5C,OAAA,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAoB,CAAC;YAAzD,CAAyD,CAC5D,CAAC;YACF,IAAI,KAAK,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,eAAe,EAAE,EAAnB,CAAmB,CAAC;gBACtC,MAAM,IAAI,mCAAgB,CAAC;oBACvB,IAAI,EAAE,gBAAgB;oBACtB,OAAO,EAAE,oCAAoC;iBAChD,CAAC,CAAC;YAGP,IAAM,UAAU,GAAuB,IAAI,uCAAkB,EAAE,CAAC;YAChE,IAAM,SAAS,GAAoB,KAAK,CAAC,GAAG,CAAC,UAAC,IAAI;gBAC9C,IAAM,MAAM,GAAG,iCAAe,CAAC,OAAO,CAClC,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,OAAO,CAClB,CAAC;oBACE,MAAM,EAAE,IAAI;oBACZ,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;iBACf,CAAC,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;gBACrB,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK;oBACxB,MAAM,mCAAgB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CACzC,MAAM,CAAC,MAAM,CAChB,CAAC;gBACN,OAAO,MAAM,CAAC,IAAI,CAAC;YACvB,CAAC,CAAC,CAAC;YAGH,IAAM,GAAG,GAAyB;gBAC9B,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,UAAC,QAAQ,IAAK,OAAA,QAAQ,CAAC,MAAM,EAAE,EAAjB,CAAiB,CAAC;gBACzD,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE;aAClC,CAAC;YACF,OAAO,+BAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC;IA/CD,CA+CC,CAAC;AACV,CAAC,EAnDgB,mBAAmB,mCAAnB,mBAAmB,QAmDnC"}
|