typia 3.5.0-dev.20230107 → 3.5.0-dev.20230125
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/internal/protocols/ProtocolMetadataUtil.d.ts +5 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +80 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -1
- package/lib/factories/internal/protocols/emplace_protocol_object.js +0 -3
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +2 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.js +21 -17
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +34 -36
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_never.js +6 -0
- package/lib/factories/internal/protocols/iterate_protocol_never.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.js +157 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +2 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +5 -4
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -1
- package/lib/messages/IProtocolMap.d.ts +5 -0
- package/lib/messages/IProtocolMap.js +3 -0
- package/lib/messages/IProtocolMap.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +2 -1
- package/lib/metadata/Metadata.d.ts +1 -0
- package/lib/metadata/Metadata.js +114 -23
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/programmers/MessageProgrammer.js +13 -6
- package/lib/programmers/MessageProgrammer.js.map +1 -1
- package/lib/programmers/internal/application_array.js +29 -27
- package/lib/programmers/internal/application_array.js.map +1 -1
- package/lib/programmers/internal/application_object.js +96 -31
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +28 -138
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/application_tuple.js +3 -2
- package/lib/programmers/internal/application_tuple.js.map +1 -1
- package/lib/schemas/IJsonComponents.d.ts +4 -2
- package/lib/schemas/IJsonSchema.d.ts +2 -0
- package/package.json +2 -1
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +82 -0
- package/src/factories/internal/protocols/emplace_protocol_object.ts +1 -3
- package/src/factories/internal/protocols/iterate_protocol_map.ts +29 -9
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +38 -18
- package/src/factories/internal/protocols/iterate_protocol_never.ts +1 -0
- package/src/factories/internal/protocols/iterate_protocol_object.ts +110 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +14 -5
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +5 -1
- package/src/messages/IProtocolMap.ts +5 -0
- package/src/messages/IProtocolProperty.ts +3 -1
- package/src/metadata/Metadata.ts +56 -1
- package/src/programmers/MessageProgrammer.ts +17 -7
- package/src/programmers/internal/application_array.ts +2 -0
- package/src/programmers/internal/application_object.ts +70 -20
- package/src/programmers/internal/application_schema.ts +15 -73
- package/src/programmers/internal/application_tuple.ts +6 -2
- package/src/schemas/IJsonComponents.ts +5 -3
- package/src/schemas/IJsonSchema.ts +2 -0
|
@@ -3,6 +3,8 @@ import { Metadata } from "../../../metadata/Metadata";
|
|
|
3
3
|
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
4
|
import { MetadataProperty } from "../../../metadata/MetadataProperty";
|
|
5
5
|
|
|
6
|
+
import { Atomic } from "../../../typings/Atomic";
|
|
7
|
+
|
|
6
8
|
export namespace ProtocolMetadataUtil {
|
|
7
9
|
export function size(meta: Metadata): number {
|
|
8
10
|
return (
|
|
@@ -78,4 +80,84 @@ export namespace ProtocolMetadataUtil {
|
|
|
78
80
|
jsDocTags: [],
|
|
79
81
|
});
|
|
80
82
|
}
|
|
83
|
+
|
|
84
|
+
export function array(meta: Metadata): Metadata {
|
|
85
|
+
return Metadata.create({
|
|
86
|
+
any: false,
|
|
87
|
+
required: true,
|
|
88
|
+
nullable: false,
|
|
89
|
+
functional: false,
|
|
90
|
+
resolved: null,
|
|
91
|
+
atomics: [],
|
|
92
|
+
constants: [],
|
|
93
|
+
templates: [],
|
|
94
|
+
rest: null,
|
|
95
|
+
arrays: [meta],
|
|
96
|
+
tuples: [],
|
|
97
|
+
objects: [],
|
|
98
|
+
natives: [],
|
|
99
|
+
sets: [],
|
|
100
|
+
maps: [],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function atomic(type: Atomic.Literal): Metadata {
|
|
105
|
+
return Metadata.create({
|
|
106
|
+
any: false,
|
|
107
|
+
required: true,
|
|
108
|
+
nullable: false,
|
|
109
|
+
functional: false,
|
|
110
|
+
resolved: null,
|
|
111
|
+
atomics: [type],
|
|
112
|
+
constants: [],
|
|
113
|
+
templates: [],
|
|
114
|
+
rest: null,
|
|
115
|
+
arrays: [],
|
|
116
|
+
tuples: [],
|
|
117
|
+
objects: [],
|
|
118
|
+
natives: [],
|
|
119
|
+
sets: [],
|
|
120
|
+
maps: [],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function reference(obj: MetadataObject): Metadata {
|
|
125
|
+
return Metadata.create({
|
|
126
|
+
any: false,
|
|
127
|
+
required: true,
|
|
128
|
+
nullable: false,
|
|
129
|
+
functional: false,
|
|
130
|
+
resolved: null,
|
|
131
|
+
atomics: [],
|
|
132
|
+
constants: [],
|
|
133
|
+
templates: [],
|
|
134
|
+
rest: null,
|
|
135
|
+
arrays: [],
|
|
136
|
+
tuples: [],
|
|
137
|
+
objects: [obj],
|
|
138
|
+
natives: [],
|
|
139
|
+
sets: [],
|
|
140
|
+
maps: [],
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function map(elem: Metadata.Entry): Metadata {
|
|
145
|
+
return Metadata.create({
|
|
146
|
+
any: false,
|
|
147
|
+
required: true,
|
|
148
|
+
nullable: false,
|
|
149
|
+
functional: false,
|
|
150
|
+
resolved: null,
|
|
151
|
+
atomics: [],
|
|
152
|
+
constants: [],
|
|
153
|
+
templates: [],
|
|
154
|
+
rest: null,
|
|
155
|
+
arrays: [],
|
|
156
|
+
tuples: [],
|
|
157
|
+
objects: [],
|
|
158
|
+
natives: [],
|
|
159
|
+
sets: [],
|
|
160
|
+
maps: [elem],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
81
163
|
}
|
|
@@ -8,9 +8,7 @@ export const emplace_protocol_object =
|
|
|
8
8
|
if (dict.has(object.name)) return;
|
|
9
9
|
|
|
10
10
|
const regular = object.properties.filter((p) => p.key.isSoleLiteral());
|
|
11
|
-
const dynamic = object.properties.filter((p) => !p.key.isSoleLiteral());
|
|
12
|
-
|
|
13
|
-
if (!regular.length || dynamic.length) return;
|
|
11
|
+
// const dynamic = object.properties.filter((p) => !p.key.isSoleLiteral());
|
|
14
12
|
|
|
15
13
|
const output: IProtocolMessage = {
|
|
16
14
|
name: object.name,
|
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
import { Metadata } from "../../../metadata/Metadata";
|
|
2
2
|
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
3
3
|
|
|
4
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
4
5
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
5
6
|
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
6
7
|
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
7
8
|
import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
|
|
8
9
|
import { iterate_protocol_constant } from "./iterate_protocol_constant";
|
|
10
|
+
import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
|
|
9
11
|
|
|
10
12
|
export const iterate_protocol_map =
|
|
11
|
-
(
|
|
13
|
+
(sole: boolean) =>
|
|
12
14
|
(dict: Map<string, IProtocolMessage>) =>
|
|
13
|
-
(
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
(prop: Metadata.Entry): string | IProtocolMap => {
|
|
16
|
+
if (sole === true)
|
|
17
|
+
return {
|
|
18
|
+
type: "map",
|
|
19
|
+
key: getKeyName(prop.key),
|
|
20
|
+
value: getValueName(dict)(prop.value),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
24
|
+
`Map.Wrapper<${prop.key.getName()}, ${prop.value.getName()}>`,
|
|
25
|
+
dict.size,
|
|
26
|
+
);
|
|
27
|
+
obj.properties.push(
|
|
28
|
+
ProtocolMetadataUtil.property(
|
|
29
|
+
"value",
|
|
30
|
+
ProtocolMetadataUtil.map(prop),
|
|
31
|
+
[],
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
emplace_protocol_object(dict)(obj);
|
|
35
|
+
return obj.name;
|
|
36
|
+
};
|
|
16
37
|
|
|
17
38
|
const getKeyName = (meta: Metadata) => {
|
|
18
39
|
for (const atomic of meta.atomics)
|
|
@@ -23,13 +44,12 @@ const getKeyName = (meta: Metadata) => {
|
|
|
23
44
|
};
|
|
24
45
|
|
|
25
46
|
const getValueName =
|
|
26
|
-
(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (ProtocolMetadataUtil.standalone(meta)) return meta.getName();
|
|
47
|
+
(dict: Map<string, IProtocolMessage>) => (meta: Metadata) => {
|
|
48
|
+
if (ProtocolMetadataUtil.standalone(meta))
|
|
49
|
+
return iterate_protocol_metadata(dict)(meta)([]).oneOf[0]!.type;
|
|
30
50
|
|
|
31
51
|
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
32
|
-
|
|
52
|
+
`Map.Value<${meta.getName()}>`,
|
|
33
53
|
dict.size,
|
|
34
54
|
);
|
|
35
55
|
obj.properties.push(ProtocolMetadataUtil.property("value", meta, []));
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { IMetadataTag } from "../../../metadata/IMetadataTag";
|
|
2
2
|
import { Metadata } from "../../../metadata/Metadata";
|
|
3
3
|
|
|
4
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
4
5
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
5
6
|
import { IProtocolProperty } from "../../../messages/IProtocolProperty";
|
|
6
7
|
import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
|
|
7
8
|
import { iterate_protocol_constant } from "./iterate_protocol_constant";
|
|
8
9
|
import { iterate_protocol_map } from "./iterate_protocol_map";
|
|
9
10
|
import { iterate_protocol_native } from "./iterate_protocol_native";
|
|
11
|
+
import { iterate_protocol_never } from "./iterate_protocol_never";
|
|
12
|
+
import { iterate_protocol_object } from "./iterate_protocol_object";
|
|
10
13
|
import { iterate_protocol_repeated } from "./iterate_protocol_repeated";
|
|
11
14
|
import { iterate_protocol_tuple } from "./iterate_protocol_tuple";
|
|
12
15
|
|
|
@@ -15,10 +18,20 @@ export const iterate_protocol_metadata =
|
|
|
15
18
|
(meta: Metadata) =>
|
|
16
19
|
(tags: IMetadataTag[]): Omit<IProtocolProperty, "key"> => {
|
|
17
20
|
// PREPARE ASSETS
|
|
18
|
-
const
|
|
19
|
-
const
|
|
21
|
+
const sole: boolean = meta.size() === 1;
|
|
22
|
+
const bucket: boolean = sole && meta.bucket() === 1;
|
|
23
|
+
const required: boolean =
|
|
24
|
+
(meta.required && !meta.nullable) ||
|
|
25
|
+
(sole &&
|
|
26
|
+
(meta.arrays.length === 1 ||
|
|
27
|
+
meta.sets.length === 1 ||
|
|
28
|
+
meta.maps.length === 1 ||
|
|
29
|
+
(meta.objects.length === 1 &&
|
|
30
|
+
meta.objects[0]!.properties.length === 1 &&
|
|
31
|
+
!meta.objects[0]!.properties[0]?.key.isSoleLiteral())));
|
|
20
32
|
|
|
21
|
-
const
|
|
33
|
+
const oneOf: IProtocolProperty.IOneOf[] = [];
|
|
34
|
+
const add = (type: string | IProtocolMap) => {
|
|
22
35
|
if (oneOf.some((one) => one.type === type)) return;
|
|
23
36
|
oneOf.push({
|
|
24
37
|
type,
|
|
@@ -26,12 +39,16 @@ export const iterate_protocol_metadata =
|
|
|
26
39
|
};
|
|
27
40
|
|
|
28
41
|
// WHEN SINGULAR ARRAY TYPE
|
|
29
|
-
if (
|
|
42
|
+
if (sole && meta.arrays.length + meta.sets.length === 1) {
|
|
30
43
|
const [container, child] =
|
|
31
44
|
meta.arrays.length === 1
|
|
32
45
|
? (["Array", meta.arrays[0]!] as const)
|
|
33
46
|
: (["Set", meta.sets[0]!] as const);
|
|
34
|
-
add(
|
|
47
|
+
add(
|
|
48
|
+
iterate_protocol_repeated(container)(true, true)(dict)(child)(
|
|
49
|
+
tags,
|
|
50
|
+
),
|
|
51
|
+
);
|
|
35
52
|
return {
|
|
36
53
|
required,
|
|
37
54
|
oneOf,
|
|
@@ -45,27 +62,30 @@ export const iterate_protocol_metadata =
|
|
|
45
62
|
for (const constant of meta.constants)
|
|
46
63
|
add(iterate_protocol_constant(constant));
|
|
47
64
|
if (meta.templates.length) add("string");
|
|
65
|
+
if (meta.size() === 0) add(iterate_protocol_never());
|
|
48
66
|
|
|
49
|
-
//
|
|
67
|
+
// OBJECT TYPES
|
|
50
68
|
for (const obj of meta.objects)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
add(
|
|
54
|
-
iterate_protocol_map("Object")(dict)(prop.key)(
|
|
55
|
-
prop.value,
|
|
56
|
-
),
|
|
57
|
-
);
|
|
58
|
-
} else add(obj.name);
|
|
69
|
+
add(iterate_protocol_object(sole)(dict)(obj));
|
|
70
|
+
for (const map of meta.maps) add(iterate_protocol_map(sole)(dict)(map));
|
|
59
71
|
for (const native of meta.natives)
|
|
60
72
|
add(iterate_protocol_native(dict)(native));
|
|
73
|
+
|
|
74
|
+
// ARRAY TYPES
|
|
61
75
|
for (const tuple of meta.tuples)
|
|
62
76
|
add(iterate_protocol_tuple(dict)(tuple));
|
|
63
77
|
for (const array of meta.arrays)
|
|
64
|
-
add(
|
|
78
|
+
add(
|
|
79
|
+
iterate_protocol_repeated("Array")(false, bucket)(dict)(array)(
|
|
80
|
+
tags,
|
|
81
|
+
),
|
|
82
|
+
);
|
|
65
83
|
for (const set of meta.sets)
|
|
66
|
-
add(
|
|
67
|
-
|
|
68
|
-
|
|
84
|
+
add(
|
|
85
|
+
iterate_protocol_repeated("Set")(false, bucket)(dict)(set)(
|
|
86
|
+
tags,
|
|
87
|
+
),
|
|
88
|
+
);
|
|
69
89
|
|
|
70
90
|
// RETURNS
|
|
71
91
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const iterate_protocol_never = () => "uint32";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Metadata } from "../../../metadata/Metadata";
|
|
2
|
+
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
3
|
+
import { MetadataProperty } from "../../../metadata/MetadataProperty";
|
|
4
|
+
|
|
5
|
+
import { Atomic } from "../../../typings/Atomic";
|
|
6
|
+
|
|
7
|
+
import { MapUtil } from "../../../utils/MapUtil";
|
|
8
|
+
|
|
9
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
10
|
+
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
11
|
+
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
12
|
+
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
13
|
+
import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
|
|
14
|
+
|
|
15
|
+
export const iterate_protocol_object =
|
|
16
|
+
(sole: boolean) =>
|
|
17
|
+
(dict: Map<string, IProtocolMessage>) =>
|
|
18
|
+
(obj: MetadataObject): string | IProtocolMap => {
|
|
19
|
+
// ONLY REGULAR PROPERTIES
|
|
20
|
+
const statics: MetadataProperty[] = obj.properties.filter(filter(true));
|
|
21
|
+
const dynamics: Metadata.Entry[] = aggregate(
|
|
22
|
+
obj.properties.filter(filter(false)),
|
|
23
|
+
);
|
|
24
|
+
if (dynamics.length === 0) return obj.name;
|
|
25
|
+
|
|
26
|
+
const regular: MetadataObject | undefined = statics.length
|
|
27
|
+
? (() => {
|
|
28
|
+
const r: MetadataObject = ProtocolMetadataUtil.object(
|
|
29
|
+
`${obj.name}.__Regular`,
|
|
30
|
+
dict.size,
|
|
31
|
+
);
|
|
32
|
+
r.properties.push(...statics);
|
|
33
|
+
emplace_protocol_object(dict)(r);
|
|
34
|
+
return r;
|
|
35
|
+
})()
|
|
36
|
+
: undefined;
|
|
37
|
+
|
|
38
|
+
// ONLY ONE TYPED DYNAMIC PROPERTY EXISTS
|
|
39
|
+
if (regular === undefined && dynamics.length === 1 && sole === true) {
|
|
40
|
+
const { key, value } = dynamics[0]!;
|
|
41
|
+
return {
|
|
42
|
+
type: "map",
|
|
43
|
+
key: key.getName(),
|
|
44
|
+
value: ProtocolMetadataUtil.standalone(value)
|
|
45
|
+
? iterate_protocol_metadata(dict)(value)([]).oneOf[0]!.type
|
|
46
|
+
: (() => {
|
|
47
|
+
const wrapper = ProtocolMetadataUtil.object(
|
|
48
|
+
`${obj.name}.__Wrapper`,
|
|
49
|
+
dict.size,
|
|
50
|
+
);
|
|
51
|
+
wrapper.properties.push(
|
|
52
|
+
ProtocolMetadataUtil.property("value", value, []),
|
|
53
|
+
);
|
|
54
|
+
emplace_protocol_object(dict)(wrapper);
|
|
55
|
+
return wrapper.name;
|
|
56
|
+
})(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// DO WRAP
|
|
61
|
+
const wrapper: MetadataObject = ProtocolMetadataUtil.object(
|
|
62
|
+
`${obj.name}.__Wrapper`,
|
|
63
|
+
dict.size,
|
|
64
|
+
);
|
|
65
|
+
if (regular !== undefined)
|
|
66
|
+
wrapper.properties.push(
|
|
67
|
+
ProtocolMetadataUtil.property(
|
|
68
|
+
"regular",
|
|
69
|
+
ProtocolMetadataUtil.reference(regular),
|
|
70
|
+
[],
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
wrapper.properties.push(
|
|
74
|
+
...dynamics.map((map, i) =>
|
|
75
|
+
ProtocolMetadataUtil.property(
|
|
76
|
+
`__map_${i}`,
|
|
77
|
+
ProtocolMetadataUtil.map(map),
|
|
78
|
+
[],
|
|
79
|
+
),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
emplace_protocol_object(dict)(wrapper);
|
|
83
|
+
return wrapper.name;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const filter = (regular: boolean) => (prop: MetadataProperty) =>
|
|
87
|
+
regular === prop.key.isSoleLiteral();
|
|
88
|
+
|
|
89
|
+
const aggregate = (properties: MetadataProperty[]): Metadata.Entry[] => {
|
|
90
|
+
const unique: Map<Atomic.Literal, MetadataProperty[]> = new Map();
|
|
91
|
+
for (const prop of properties) {
|
|
92
|
+
if (prop.key.templates)
|
|
93
|
+
MapUtil.take(unique, "string", () => []).push(prop);
|
|
94
|
+
for (const type of prop.key.atomics)
|
|
95
|
+
MapUtil.take(unique, type, () => []).push(prop);
|
|
96
|
+
for (const { type } of prop.key.constants)
|
|
97
|
+
MapUtil.take(unique, type, () => []).push(prop);
|
|
98
|
+
}
|
|
99
|
+
const output: Metadata.Entry[] = [];
|
|
100
|
+
for (const [key, properties] of unique) {
|
|
101
|
+
const value: Metadata = properties
|
|
102
|
+
.map((x) => x.value)
|
|
103
|
+
.reduce((x, y) => Metadata.merge(x, y));
|
|
104
|
+
output.push({
|
|
105
|
+
key: ProtocolMetadataUtil.atomic(key),
|
|
106
|
+
value,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return output;
|
|
110
|
+
};
|
|
@@ -2,24 +2,33 @@ import { IMetadataTag } from "../../../metadata/IMetadataTag";
|
|
|
2
2
|
import { Metadata } from "../../../metadata/Metadata";
|
|
3
3
|
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
4
|
|
|
5
|
+
import { IProtocolMap } from "../../../messages/IProtocolMap";
|
|
5
6
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
6
7
|
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
7
8
|
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
9
|
+
import { iterate_protocol_metadata } from "./iterate_protocol_metadata";
|
|
8
10
|
|
|
9
11
|
export const iterate_protocol_repeated =
|
|
10
12
|
(container: "Array" | "Set") =>
|
|
11
|
-
(sole: boolean) =>
|
|
13
|
+
(sole: boolean, bucket: boolean) =>
|
|
12
14
|
(dict: Map<string, IProtocolMessage>) =>
|
|
13
15
|
(meta: Metadata) =>
|
|
14
|
-
(tags: IMetadataTag[]): string => {
|
|
16
|
+
(tags: IMetadataTag[]): string | IProtocolMap => {
|
|
15
17
|
sole &&= ProtocolMetadataUtil.standalone(meta);
|
|
16
|
-
if (sole === true)
|
|
18
|
+
if (sole === true)
|
|
19
|
+
return iterate_protocol_metadata(dict)(meta)(tags).oneOf[0]!.type;
|
|
17
20
|
|
|
18
21
|
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
19
|
-
`${container}
|
|
22
|
+
`${container}.${bucket ? "Element" : "Wrapper"}<${meta.getName()}>`,
|
|
20
23
|
dict.size,
|
|
21
24
|
);
|
|
22
|
-
obj.properties.push(
|
|
25
|
+
obj.properties.push(
|
|
26
|
+
ProtocolMetadataUtil.property(
|
|
27
|
+
"value",
|
|
28
|
+
bucket ? meta : ProtocolMetadataUtil.array(meta),
|
|
29
|
+
tags,
|
|
30
|
+
),
|
|
31
|
+
);
|
|
23
32
|
emplace_protocol_object(dict)(obj);
|
|
24
33
|
return obj.name;
|
|
25
34
|
};
|
|
@@ -17,7 +17,11 @@ export const iterate_protocol_tuple =
|
|
|
17
17
|
);
|
|
18
18
|
obj.properties.push(
|
|
19
19
|
...tuple.map((value, i) =>
|
|
20
|
-
ProtocolMetadataUtil.property(
|
|
20
|
+
ProtocolMetadataUtil.property(
|
|
21
|
+
`v${i}`,
|
|
22
|
+
value.rest ? ProtocolMetadataUtil.array(value.rest) : value,
|
|
23
|
+
[],
|
|
24
|
+
),
|
|
21
25
|
),
|
|
22
26
|
);
|
|
23
27
|
emplace_protocol_object(dict)(obj);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { IProtocolMap } from "./IProtocolMap";
|
|
2
|
+
|
|
1
3
|
export interface IProtocolProperty {
|
|
2
4
|
key: string;
|
|
3
5
|
oneOf: IProtocolProperty.IOneOf[];
|
|
@@ -6,6 +8,6 @@ export interface IProtocolProperty {
|
|
|
6
8
|
}
|
|
7
9
|
export namespace IProtocolProperty {
|
|
8
10
|
export interface IOneOf {
|
|
9
|
-
type: string;
|
|
11
|
+
type: string | IProtocolMap;
|
|
10
12
|
}
|
|
11
13
|
}
|
package/src/metadata/Metadata.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Atomic } from "../typings/Atomic";
|
|
2
2
|
import { ClassProperties } from "../typings/ClassProperties";
|
|
3
3
|
|
|
4
|
+
import { ArrayUtil } from "../utils/ArrayUtil";
|
|
5
|
+
|
|
4
6
|
import { IMetadata } from "./IMetadata";
|
|
5
7
|
import { IMetadataObject } from "./IMetadataObject";
|
|
6
8
|
import { MetadataConstant } from "./MetadataConstant";
|
|
@@ -417,6 +419,58 @@ export namespace Metadata {
|
|
|
417
419
|
// SUCCESS
|
|
418
420
|
return true;
|
|
419
421
|
}
|
|
422
|
+
|
|
423
|
+
export function merge(x: Metadata, y: Metadata): Metadata {
|
|
424
|
+
const output: Metadata = Metadata.create({
|
|
425
|
+
any: x.any || y.any,
|
|
426
|
+
nullable: x.nullable || y.nullable,
|
|
427
|
+
required: x.required && y.required,
|
|
428
|
+
functional: x.functional || y.functional,
|
|
429
|
+
|
|
430
|
+
resolved:
|
|
431
|
+
x.resolved !== null && y.resolved !== null
|
|
432
|
+
? merge(x.resolved, y.resolved)
|
|
433
|
+
: x.resolved || y.resolved,
|
|
434
|
+
atomics: [...new Set([...x.atomics, ...y.atomics])],
|
|
435
|
+
constants: [...x.constants],
|
|
436
|
+
templates: x.templates.slice(),
|
|
437
|
+
|
|
438
|
+
rest:
|
|
439
|
+
x.rest !== null && y.rest !== null
|
|
440
|
+
? merge(x.rest, y.rest)
|
|
441
|
+
: x.rest ?? y.rest,
|
|
442
|
+
arrays: x.arrays.slice(),
|
|
443
|
+
tuples: x.tuples.slice(),
|
|
444
|
+
objects: x.objects.slice(),
|
|
445
|
+
|
|
446
|
+
natives: [...new Set([...x.natives, ...y.natives])],
|
|
447
|
+
sets: x.sets.slice(),
|
|
448
|
+
maps: x.maps.slice(),
|
|
449
|
+
});
|
|
450
|
+
for (const constant of y.constants) {
|
|
451
|
+
const target: MetadataConstant = ArrayUtil.take(
|
|
452
|
+
output.constants,
|
|
453
|
+
(elem) => elem.type === constant.type,
|
|
454
|
+
() => ({
|
|
455
|
+
type: constant.type,
|
|
456
|
+
values: [],
|
|
457
|
+
}),
|
|
458
|
+
);
|
|
459
|
+
for (const value of constant.values)
|
|
460
|
+
ArrayUtil.add(target.values, value);
|
|
461
|
+
}
|
|
462
|
+
for (const array of y.arrays)
|
|
463
|
+
ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
|
|
464
|
+
for (const obj of y.objects)
|
|
465
|
+
ArrayUtil.set(output.objects, obj, (elem) => elem.name);
|
|
466
|
+
|
|
467
|
+
if (x.rest !== null)
|
|
468
|
+
ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
|
|
469
|
+
if (y.rest !== null)
|
|
470
|
+
ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
|
|
471
|
+
|
|
472
|
+
return output;
|
|
473
|
+
}
|
|
420
474
|
}
|
|
421
475
|
|
|
422
476
|
function getName(metadata: Metadata): string {
|
|
@@ -457,7 +511,8 @@ function getName(metadata: Metadata): string {
|
|
|
457
511
|
elements.push(`Map<${map.key.getName()}, ${map.value.getName()}>`);
|
|
458
512
|
|
|
459
513
|
// ARRAY
|
|
460
|
-
if (metadata.rest !== null)
|
|
514
|
+
if (metadata.rest !== null)
|
|
515
|
+
elements.push(`Rest<${metadata.rest.getName()}>`);
|
|
461
516
|
for (const tuple of metadata.tuples)
|
|
462
517
|
elements.push(`[${tuple.map((elem) => elem.getName()).join(", ")}]`);
|
|
463
518
|
for (const array of metadata.arrays)
|
|
@@ -11,6 +11,7 @@ import { Escaper } from "../utils/Escaper";
|
|
|
11
11
|
import { MapUtil } from "../utils/MapUtil";
|
|
12
12
|
import { NameEncoder } from "../utils/NameEncoder";
|
|
13
13
|
|
|
14
|
+
import { IProtocolMap } from "../messages/IProtocolMap";
|
|
14
15
|
import { IProtocolMessage } from "../messages/IProtocolMessage";
|
|
15
16
|
|
|
16
17
|
export namespace MessageProgrammer {
|
|
@@ -48,26 +49,29 @@ export namespace MessageProgrammer {
|
|
|
48
49
|
if (message !== null)
|
|
49
50
|
elements.push(
|
|
50
51
|
...message.properties.map((property) => {
|
|
52
|
+
const key: string =
|
|
53
|
+
Escaper.variable(property.key) &&
|
|
54
|
+
property.key.indexOf("$") === -1
|
|
55
|
+
? property.key
|
|
56
|
+
: `v${index + 1}`;
|
|
51
57
|
if (property.oneOf.length === 1)
|
|
52
58
|
return [
|
|
53
59
|
TAB,
|
|
54
60
|
property.required ? "" : "optional ",
|
|
55
61
|
property.repeated ? "repeated " : "",
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
? property.key
|
|
59
|
-
: `v${index + 1}`,
|
|
62
|
+
getTypeName(property.oneOf[0]!.type) + " ",
|
|
63
|
+
key,
|
|
60
64
|
" = ",
|
|
61
65
|
`${index++};`,
|
|
62
66
|
].join("");
|
|
63
67
|
return (
|
|
64
|
-
`${TAB}oneof ${
|
|
68
|
+
`${TAB}oneof ${key} {\n` +
|
|
65
69
|
property.oneOf
|
|
66
70
|
.map(
|
|
67
71
|
(o, i) =>
|
|
68
|
-
`${TAB}${TAB}${
|
|
72
|
+
`${TAB}${TAB}${getTypeName(
|
|
69
73
|
o.type,
|
|
70
|
-
)}
|
|
74
|
+
)} ${key}_o${i} = ${index++};`,
|
|
71
75
|
)
|
|
72
76
|
.join("\n") +
|
|
73
77
|
`\n${TAB}}`
|
|
@@ -105,6 +109,12 @@ export namespace MessageProgrammer {
|
|
|
105
109
|
if (i === accessors.length - 1) hierarchy.message = message;
|
|
106
110
|
});
|
|
107
111
|
};
|
|
112
|
+
|
|
113
|
+
function getTypeName(type: string | IProtocolMap): string {
|
|
114
|
+
return typeof type === "string"
|
|
115
|
+
? NameEncoder.encode(type)
|
|
116
|
+
: `map<${type.key}, ${getTypeName(type.value)}>`;
|
|
117
|
+
}
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
interface Hierarchy {
|
|
@@ -11,6 +11,7 @@ import { application_schema } from "./application_schema";
|
|
|
11
11
|
export const application_array =
|
|
12
12
|
(options: ApplicationProgrammer.IOptions) =>
|
|
13
13
|
(components: IJsonComponents) =>
|
|
14
|
+
(tuple?: IJsonSchema.ITuple) =>
|
|
14
15
|
(
|
|
15
16
|
metadata: Metadata,
|
|
16
17
|
nullable: boolean,
|
|
@@ -24,6 +25,7 @@ export const application_array =
|
|
|
24
25
|
attribute,
|
|
25
26
|
),
|
|
26
27
|
nullable,
|
|
28
|
+
"x-typia-tuple": tuple,
|
|
27
29
|
...attribute,
|
|
28
30
|
};
|
|
29
31
|
|