typia 5.0.0-dev.20230810 → 5.0.0-dev.20230814
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.js +1 -0
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/MetadataFactory.js +27 -0
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/ProtobufFactory.d.ts +0 -2
- package/lib/factories/ProtobufFactory.js +55 -111
- package/lib/factories/ProtobufFactory.js.map +1 -1
- package/lib/factories/StatementFactory.d.ts +1 -0
- package/lib/factories/StatementFactory.js +5 -0
- package/lib/factories/StatementFactory.js.map +1 -1
- package/lib/factories/internal/metadata/explore_metadata.js +3 -7
- package/lib/factories/internal/metadata/explore_metadata.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js +1 -0
- package/lib/factories/internal/metadata/iterate_metadata_intersection.js.map +1 -1
- package/lib/functional/$strlen.d.ts +1 -0
- package/lib/functional/$strlen.js +13 -0
- package/lib/functional/$strlen.js.map +1 -0
- package/lib/functional/Namespace.js +19 -3
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/json.js +4 -4
- package/lib/json.js.map +1 -1
- package/lib/misc.js +8 -8
- package/lib/misc.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +0 -5
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +3 -3
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/helpers/ProtobufUtil.d.ts +5 -0
- package/lib/programmers/helpers/ProtobufUtil.js +82 -0
- package/lib/programmers/helpers/ProtobufUtil.js.map +1 -0
- package/lib/programmers/helpers/ProtobufWire.d.ts +25 -0
- package/lib/{schemas/protobuf/IProtocolMap.js → programmers/helpers/ProtobufWire.js} +1 -1
- package/lib/programmers/helpers/ProtobufWire.js.map +1 -0
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +253 -5
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +23 -37
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufSizeProgrammer.d.ts +5 -0
- package/lib/programmers/protobuf/ProtobufSizeProgrammer.js +409 -0
- package/lib/programmers/protobuf/ProtobufSizeProgrammer.js.map +1 -0
- package/lib/protobuf.js +9 -1
- package/lib/protobuf.js.map +1 -1
- package/lib/schemas/metadata/Metadata.js +11 -0
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +26 -22
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufAssertDecodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufAssertDecodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufAssertEncodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufAssertEncodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufDecodeTransformer.js +1 -3
- package/lib/transformers/features/protobuf/CreateProtobufDecodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufEncodeTransformer.js +1 -3
- package/lib/transformers/features/protobuf/CreateProtobufEncodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufIsDecodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufIsDecodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufIsEncodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufIsEncodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufSizeTransformer.d.ts +3 -0
- package/lib/transformers/features/protobuf/CreateProtobufSizeTransformer.js +10 -0
- package/lib/transformers/features/protobuf/CreateProtobufSizeTransformer.js.map +1 -0
- package/lib/transformers/features/protobuf/CreateProtobufValidateDecodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufValidateDecodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufValidateEncodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/CreateProtobufValidateEncodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufAssertDecodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufAssertDecodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufAssertEncodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufAssertEncodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufDecodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufDecodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufEncodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufEncodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufIsDecodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufIsDecodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufIsEncodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufIsEncodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufMessageTransformer.d.ts +1 -1
- package/lib/transformers/features/protobuf/ProtobufMessageTransformer.js +7 -7
- package/lib/transformers/features/protobuf/ProtobufMessageTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufSizeTransformer.d.ts +3 -0
- package/lib/transformers/features/protobuf/ProtobufSizeTransformer.js +10 -0
- package/lib/transformers/features/protobuf/ProtobufSizeTransformer.js.map +1 -0
- package/lib/transformers/features/protobuf/ProtobufValidateDecodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufValidateDecodeTransformer.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufValidateEncodeTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufValidateEncodeTransformer.js.map +1 -1
- package/package.json +2 -1
- package/src/factories/MetadataCollection.ts +5 -0
- package/src/factories/MetadataFactory.ts +4 -0
- package/src/factories/ProtobufFactory.ts +106 -90
- package/src/factories/StatementFactory.ts +16 -0
- package/src/factories/internal/metadata/explore_metadata.ts +4 -6
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +1 -0
- package/src/functional/$strlen.ts +7 -0
- package/src/functional/Namespace.ts +32 -17
- package/src/json.ts +4 -4
- package/src/misc.ts +8 -8
- package/src/programmers/CheckerProgrammer.ts +0 -9
- package/src/programmers/FeatureProgrammer.ts +5 -3
- package/src/programmers/helpers/ProtobufUtil.ts +24 -0
- package/src/programmers/helpers/ProtobufWire.ts +28 -0
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +446 -5
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +12 -8
- package/src/programmers/protobuf/ProtobufSizeProgrammer.ts +716 -0
- package/src/protobuf.ts +29 -0
- package/src/schemas/metadata/Metadata.ts +26 -0
- package/src/transformers/CallExpressionTransformer.ts +32 -28
- package/src/transformers/features/protobuf/CreateProtobufAssertDecodeTransformer.ts +3 -1
- package/src/transformers/features/protobuf/CreateProtobufAssertEncodeTransformer.ts +3 -1
- package/src/transformers/features/protobuf/CreateProtobufDecodeTransformer.ts +3 -4
- package/src/transformers/features/protobuf/CreateProtobufEncodeTransformer.ts +3 -4
- package/src/transformers/features/protobuf/CreateProtobufIsDecodeTransformer.ts +3 -1
- package/src/transformers/features/protobuf/CreateProtobufIsEncodeTransformer.ts +3 -1
- package/src/transformers/features/protobuf/CreateProtobufSizeTransformer.ts +9 -0
- package/src/transformers/features/protobuf/CreateProtobufValidateDecodeTransformer.ts +3 -1
- package/src/transformers/features/protobuf/CreateProtobufValidateEncodeTransformer.ts +3 -1
- package/src/transformers/features/protobuf/ProtobufAssertDecodeTransformer.ts +1 -1
- package/src/transformers/features/protobuf/ProtobufAssertEncodeTransformer.ts +1 -1
- package/src/transformers/features/protobuf/ProtobufDecodeTransformer.ts +1 -1
- package/src/transformers/features/protobuf/ProtobufEncodeTransformer.ts +1 -1
- package/src/transformers/features/protobuf/ProtobufIsDecodeTransformer.ts +1 -1
- package/src/transformers/features/protobuf/ProtobufIsEncodeTransformer.ts +1 -1
- package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +3 -3
- package/src/transformers/features/protobuf/ProtobufSizeTransformer.ts +9 -0
- package/src/transformers/features/protobuf/ProtobufValidateDecodeTransformer.ts +3 -1
- package/src/transformers/features/protobuf/ProtobufValidateEncodeTransformer.ts +3 -1
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +0 -16
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +0 -173
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +0 -1
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +0 -3
- package/lib/factories/internal/protocols/emplace_protocol_object.js +0 -47
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +0 -1
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +0 -4
- package/lib/factories/internal/protocols/emplace_protocol_property.js +0 -20
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +0 -3
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +0 -69
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +0 -2
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +0 -30
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +0 -3
- package/lib/factories/internal/protocols/iterate_protocol_main.js +0 -17
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +0 -4
- package/lib/factories/internal/protocols/iterate_protocol_map.js +0 -75
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +0 -5
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +0 -190
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +0 -2
- package/lib/factories/internal/protocols/iterate_protocol_native.js +0 -33
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_never.js +0 -6
- package/lib/factories/internal/protocols/iterate_protocol_never.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +0 -4
- package/lib/factories/internal/protocols/iterate_protocol_object.js +0 -157
- package/lib/factories/internal/protocols/iterate_protocol_object.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +0 -5
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +0 -25
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +0 -1
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +0 -3
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +0 -46
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +0 -1
- package/lib/schemas/protobuf/IProtocolMap.d.ts +0 -5
- package/lib/schemas/protobuf/IProtocolMap.js.map +0 -1
- package/lib/schemas/protobuf/IProtocolMessage.d.ts +0 -5
- package/lib/schemas/protobuf/IProtocolMessage.js +0 -3
- package/lib/schemas/protobuf/IProtocolMessage.js.map +0 -1
- package/lib/schemas/protobuf/IProtocolProperty.d.ts +0 -12
- package/lib/schemas/protobuf/IProtocolProperty.js +0 -3
- package/lib/schemas/protobuf/IProtocolProperty.js.map +0 -1
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +0 -180
- package/src/factories/internal/protocols/emplace_protocol_object.ts +0 -25
- package/src/factories/internal/protocols/emplace_protocol_property.ts +0 -12
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +0 -34
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +0 -27
- package/src/factories/internal/protocols/iterate_protocol_main.ts +0 -19
- package/src/factories/internal/protocols/iterate_protocol_map.ts +0 -58
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +0 -96
- package/src/factories/internal/protocols/iterate_protocol_native.ts +0 -34
- package/src/factories/internal/protocols/iterate_protocol_never.ts +0 -1
- package/src/factories/internal/protocols/iterate_protocol_object.ts +0 -110
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +0 -34
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +0 -29
- package/src/schemas/protobuf/IProtocolMap.ts +0 -5
- package/src/schemas/protobuf/IProtocolMessage.ts +0 -6
- package/src/schemas/protobuf/IProtocolProperty.ts +0 -13
|
@@ -2,12 +2,11 @@ import ts from "typescript";
|
|
|
2
2
|
|
|
3
3
|
import { Metadata } from "../schemas/metadata/Metadata";
|
|
4
4
|
import { MetadataObject } from "../schemas/metadata/MetadataObject";
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
import { Escaper } from "../utils/Escaper";
|
|
6
7
|
|
|
7
8
|
import { MetadataCollection } from "./MetadataCollection";
|
|
8
9
|
import { MetadataFactory } from "./MetadataFactory";
|
|
9
|
-
import { emplace_protocol_object } from "./internal/protocols/emplace_protocol_object";
|
|
10
|
-
import { iterate_protocol_main } from "./internal/protocols/iterate_protocol_main";
|
|
11
10
|
|
|
12
11
|
export namespace ProtobufFactory {
|
|
13
12
|
export const metadata =
|
|
@@ -42,37 +41,70 @@ export namespace ProtobufFactory {
|
|
|
42
41
|
return top;
|
|
43
42
|
};
|
|
44
43
|
|
|
45
|
-
export const analyze =
|
|
46
|
-
(collection: MetadataCollection) =>
|
|
47
|
-
(dict: Map<string, IProtocolMessage>) =>
|
|
48
|
-
(meta: Metadata) => {
|
|
49
|
-
// EMPLACE OBJECTS
|
|
50
|
-
for (const obj of collection.objects())
|
|
51
|
-
emplace_protocol_object(dict)(obj);
|
|
52
|
-
|
|
53
|
-
// WHEN NOT OBJECT, WRAP IT INTO A FAKE MAIN OBJECT
|
|
54
|
-
iterate_protocol_main(dict)(meta);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
44
|
const validate = (method: string) => (meta: Metadata) => {
|
|
58
45
|
//----
|
|
59
|
-
// NOT
|
|
46
|
+
// NOT SUPPORTED TYPES
|
|
60
47
|
//----
|
|
48
|
+
// PROHIBIT ANY TYPE
|
|
61
49
|
if (meta.any) throw notSupportedError({ method })("any type");
|
|
50
|
+
// PROHIBIT FUNCTIONAL TYPE
|
|
62
51
|
else if (meta.functional)
|
|
63
52
|
throw notSupportedError({ method })("functional type");
|
|
53
|
+
// PROHIBIT TUPLE TYPE
|
|
64
54
|
else if (meta.tuples.length)
|
|
65
55
|
throw notSupportedError({ method })("tuple type");
|
|
56
|
+
// PROHIBIT SET TYPE
|
|
66
57
|
else if (meta.sets.length)
|
|
67
58
|
throw notSupportedError({ method })("Set type");
|
|
59
|
+
// NATIVE TYPE, BUT NOT Uint8Array
|
|
60
|
+
else if (meta.natives.length) {
|
|
61
|
+
const banned = meta.natives
|
|
62
|
+
.map((n) => [n, BANNED_NATIVE_TYPES.get(n)] as const)
|
|
63
|
+
.filter(([_n, b]) => b !== undefined)[0];
|
|
64
|
+
if (banned !== undefined)
|
|
65
|
+
throw notSupportedError({ method })(
|
|
66
|
+
banned[1] === null
|
|
67
|
+
? banned[0]
|
|
68
|
+
: `${banned[0]}. Use ${banned[1]} instead.`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
//----
|
|
72
|
+
// ARRRAY CASES
|
|
73
|
+
//----
|
|
74
|
+
// DO NOT ALLOW MULTI-DIMENTIONAL ARRAY
|
|
68
75
|
else if (
|
|
69
76
|
meta.arrays.length &&
|
|
70
77
|
meta.arrays.some((array) => !!array.value.arrays.length)
|
|
71
78
|
)
|
|
72
79
|
throw notSupportedError({ method })("two dimenstional array type");
|
|
80
|
+
// CHILD OF ARRAY TYPE MUST BE REQUIRED
|
|
81
|
+
else if (
|
|
82
|
+
meta.arrays.length &&
|
|
83
|
+
meta.arrays.some(
|
|
84
|
+
(array) =>
|
|
85
|
+
array.value.isRequired() === false ||
|
|
86
|
+
array.value.nullable === true,
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
throw notSupportedError({ method })("optional type in array");
|
|
90
|
+
// UNION IN ARRAY
|
|
91
|
+
else if (
|
|
92
|
+
meta.arrays.length &&
|
|
93
|
+
meta.arrays.some((a) => a.value.size() > 1)
|
|
94
|
+
)
|
|
95
|
+
throw notSupportedError({ method })("union type in array");
|
|
96
|
+
// UNION WITH ARRAY
|
|
97
|
+
else if (meta.size() > 1 && meta.arrays.length)
|
|
98
|
+
throw notSupportedError({ method })("union type with array type");
|
|
73
99
|
//----
|
|
74
|
-
//
|
|
100
|
+
// OBJECT CASES
|
|
75
101
|
//----
|
|
102
|
+
// EMPTY PROPERTY
|
|
103
|
+
else if (
|
|
104
|
+
meta.objects.length &&
|
|
105
|
+
meta.objects.some((obj) => obj.properties.length === 0)
|
|
106
|
+
)
|
|
107
|
+
throw notSupportedError({ method })("empty object type");
|
|
76
108
|
// MULTIPLE DYNAMIC KEY TYPED PROPERTIES
|
|
77
109
|
else if (
|
|
78
110
|
meta.objects.length &&
|
|
@@ -90,7 +122,6 @@ export namespace ProtobufFactory {
|
|
|
90
122
|
meta.objects.length &&
|
|
91
123
|
meta.objects.some(
|
|
92
124
|
(obj) =>
|
|
93
|
-
obj.properties.length &&
|
|
94
125
|
obj.properties.some((p) => p.key.isSoleLiteral()) &&
|
|
95
126
|
obj.properties.some((p) => !p.key.isSoleLiteral()),
|
|
96
127
|
)
|
|
@@ -98,36 +129,29 @@ export namespace ProtobufFactory {
|
|
|
98
129
|
throw notSupportedError({ method })(
|
|
99
130
|
"object type with mixed static and dynamic key typed properties. Keep statics or dynamic only.",
|
|
100
131
|
);
|
|
101
|
-
//
|
|
102
|
-
else if (meta.natives.length) {
|
|
103
|
-
const banned = meta.natives
|
|
104
|
-
.map((n) => [n, BANNED_NATIVE_TYPES.get(n)] as const)
|
|
105
|
-
.filter(([_n, b]) => b !== undefined)[0];
|
|
106
|
-
if (banned !== undefined)
|
|
107
|
-
throw notSupportedError({ method })(
|
|
108
|
-
banned[1] === null
|
|
109
|
-
? banned[0]
|
|
110
|
-
: `${banned[0]}. Use ${banned[1]} instead.`,
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
// MAP TYPE, BUT PROPERTY KEY TYPE IS NOT ATOMIC
|
|
132
|
+
// STATIC PROPERTY, BUT INVALID KEY NAME
|
|
114
133
|
else if (
|
|
115
|
-
meta.
|
|
116
|
-
meta.
|
|
134
|
+
meta.objects.length &&
|
|
135
|
+
meta.objects.some((obj) =>
|
|
136
|
+
obj.properties.some(
|
|
137
|
+
(p) =>
|
|
138
|
+
p.key.isSoleLiteral() &&
|
|
139
|
+
!Escaper.variable(p.key.getSoleLiteral()!),
|
|
140
|
+
),
|
|
141
|
+
)
|
|
117
142
|
)
|
|
118
|
-
throw notSupportedError({ method })(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// UNION IN ARRAY
|
|
143
|
+
throw notSupportedError({ method })(
|
|
144
|
+
`object type with invalid static key name.`,
|
|
145
|
+
);
|
|
146
|
+
// DYNAMIC OBJECT, BUT PROPERTY VALUE TYPE IS ARRAY
|
|
123
147
|
else if (
|
|
124
|
-
meta.
|
|
125
|
-
meta.
|
|
148
|
+
meta.objects.length &&
|
|
149
|
+
isDynamicObject(meta.objects[0]!) &&
|
|
150
|
+
meta.objects[0]!.properties.some((p) => !!p.value.arrays.length)
|
|
126
151
|
)
|
|
127
|
-
throw notSupportedError({ method })(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
throw notSupportedError({ method })("union type with array type");
|
|
152
|
+
throw notSupportedError({ method })(
|
|
153
|
+
"dynamic object with array value type",
|
|
154
|
+
);
|
|
131
155
|
// UNION WITH DYNAMIC OBJECT
|
|
132
156
|
else if (
|
|
133
157
|
meta.size() > 1 &&
|
|
@@ -143,42 +167,53 @@ export namespace ProtobufFactory {
|
|
|
143
167
|
meta.objects.some(
|
|
144
168
|
(obj) =>
|
|
145
169
|
isDynamicObject(obj) &&
|
|
146
|
-
obj.properties.some((p) =>
|
|
170
|
+
obj.properties.some((p) => p.value.isBinaryUnion()),
|
|
147
171
|
)
|
|
148
172
|
)
|
|
149
173
|
throw notSupportedError({ method })(
|
|
150
174
|
"union type in dynamic property",
|
|
151
175
|
);
|
|
176
|
+
//----
|
|
177
|
+
// MAP CASES
|
|
178
|
+
//----
|
|
179
|
+
// MAP TYPE, BUT PROPERTY KEY TYPE IS NOT STRING
|
|
180
|
+
else if (
|
|
181
|
+
meta.maps.length &&
|
|
182
|
+
meta.maps.some(
|
|
183
|
+
(m) =>
|
|
184
|
+
m.key.isBinaryUnion() ||
|
|
185
|
+
(m.key.atomics.find((v) => v === "string") === undefined &&
|
|
186
|
+
m.key.constants.find((c) => c.type === "string") ===
|
|
187
|
+
undefined),
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
throw notSupportedError({ method })("non-string key typed map");
|
|
191
|
+
// MAP TYPE, BUT PROPERTY KEY TYPE IS OPTIONAL
|
|
192
|
+
else if (
|
|
193
|
+
meta.maps.length &&
|
|
194
|
+
meta.maps.some(
|
|
195
|
+
(m) => m.key.isRequired() === false || m.key.nullable,
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
throw notSupportedError({ method })("optional key typed map");
|
|
199
|
+
// MAP TYPE, BUT VALUE TYPE IS ARRAY
|
|
200
|
+
else if (
|
|
201
|
+
meta.maps.length &&
|
|
202
|
+
meta.maps.some((m) => !!m.value.arrays.length)
|
|
203
|
+
)
|
|
204
|
+
throw notSupportedError({ method })(
|
|
205
|
+
"map type with array value type",
|
|
206
|
+
);
|
|
152
207
|
// UNION WITH MAP
|
|
153
208
|
else if (meta.size() > 1 && meta.maps.length)
|
|
154
209
|
throw notSupportedError({ method })("union type with map type");
|
|
155
210
|
// UNION IN MAP
|
|
156
|
-
else if (
|
|
211
|
+
else if (
|
|
212
|
+
meta.maps.length &&
|
|
213
|
+
meta.maps.some((m) => m.value.isBinaryUnion())
|
|
214
|
+
)
|
|
157
215
|
throw notSupportedError({ method })("union type in map");
|
|
158
216
|
};
|
|
159
|
-
|
|
160
|
-
const is_atomic_key = (key: Metadata) => {
|
|
161
|
-
if (
|
|
162
|
-
key.required &&
|
|
163
|
-
key.nullable === false &&
|
|
164
|
-
key.functional === false &&
|
|
165
|
-
key.resolved === null &&
|
|
166
|
-
key.size() ===
|
|
167
|
-
key.atomics.length +
|
|
168
|
-
key.constants
|
|
169
|
-
.map((c) => c.values.length)
|
|
170
|
-
.reduce((a, b) => a + b, 0) +
|
|
171
|
-
key.templates.length
|
|
172
|
-
) {
|
|
173
|
-
const set: Set<string> = new Set();
|
|
174
|
-
for (const atomic of key.atomics) set.add(atomic);
|
|
175
|
-
for (const constant of key.constants) set.add(constant.type);
|
|
176
|
-
if (key.templates.length) set.add("string");
|
|
177
|
-
|
|
178
|
-
return set.size === 1;
|
|
179
|
-
}
|
|
180
|
-
return false;
|
|
181
|
-
};
|
|
182
217
|
}
|
|
183
218
|
|
|
184
219
|
const prefix = (method: string) => `Error on typia.protobuf.${method}():`;
|
|
@@ -188,27 +223,8 @@ const notSupportedError = (p: { method: string }) => (title: string) =>
|
|
|
188
223
|
`${prefix(p.method)}: protocol buffer does not support ${title}.`,
|
|
189
224
|
);
|
|
190
225
|
|
|
191
|
-
const isDynamicObject = (obj: MetadataObject): boolean =>
|
|
192
|
-
|
|
193
|
-
obj.properties.length > 0 &&
|
|
194
|
-
obj.properties[0]!.key.isSoleLiteral() === false
|
|
195
|
-
);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const isUnion = (meta: Metadata): boolean => {
|
|
199
|
-
const count: number =
|
|
200
|
-
new Set([
|
|
201
|
-
...meta.atomics,
|
|
202
|
-
...meta.constants.map((c) => c.type),
|
|
203
|
-
...(meta.templates.length ? ["string"] : []),
|
|
204
|
-
]).size +
|
|
205
|
-
meta.arrays.length +
|
|
206
|
-
meta.tuples.length +
|
|
207
|
-
meta.natives.length +
|
|
208
|
-
meta.objects.length +
|
|
209
|
-
meta.maps.length;
|
|
210
|
-
return count > 1;
|
|
211
|
-
};
|
|
226
|
+
const isDynamicObject = (obj: MetadataObject): boolean =>
|
|
227
|
+
obj.properties[0]!.key.isSoleLiteral() === false;
|
|
212
228
|
|
|
213
229
|
const BANNED_NATIVE_TYPES: Map<string, string | null> = new Map([
|
|
214
230
|
["Date", "string"],
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
3
|
export namespace StatementFactory {
|
|
4
|
+
export const mut = (name: string, initializer?: ts.Expression) =>
|
|
5
|
+
ts.factory.createVariableStatement(
|
|
6
|
+
undefined,
|
|
7
|
+
ts.factory.createVariableDeclarationList(
|
|
8
|
+
[
|
|
9
|
+
ts.factory.createVariableDeclaration(
|
|
10
|
+
name,
|
|
11
|
+
undefined,
|
|
12
|
+
undefined,
|
|
13
|
+
initializer,
|
|
14
|
+
),
|
|
15
|
+
],
|
|
16
|
+
ts.NodeFlags.Let,
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
|
|
4
20
|
export const constant = (name: string, initializer?: ts.Expression) =>
|
|
5
21
|
ts.factory.createVariableStatement(
|
|
6
22
|
undefined,
|
|
@@ -18,11 +18,9 @@ export const explore_metadata =
|
|
|
18
18
|
): Metadata => {
|
|
19
19
|
// CONSTRUCT METADATA
|
|
20
20
|
const meta: Metadata = Metadata.initialize(parentResolved);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
if (type === null) return out(meta);
|
|
21
|
+
collection.entire_.add(meta);
|
|
22
|
+
|
|
23
|
+
if (type === null) return meta;
|
|
26
24
|
|
|
27
25
|
// ITERATE TYPESCRIPT TYPES
|
|
28
26
|
iterate_metadata(checker)(options)(collection)(
|
|
@@ -36,5 +34,5 @@ export const explore_metadata =
|
|
|
36
34
|
emend_metadata_atomics(meta.resolved.original);
|
|
37
35
|
emend_metadata_atomics(meta.resolved.returns);
|
|
38
36
|
}
|
|
39
|
-
return
|
|
37
|
+
return meta;
|
|
40
38
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Writer } from "protobufjs";
|
|
2
|
+
|
|
1
3
|
import { RandomGenerator } from "../utils/RandomGenerator";
|
|
2
4
|
|
|
3
5
|
import { IValidation } from "../IValidation";
|
|
@@ -19,6 +21,7 @@ import { $number } from "./$number";
|
|
|
19
21
|
import { $report } from "./$report";
|
|
20
22
|
import { $rest } from "./$rest";
|
|
21
23
|
import { $string } from "./$string";
|
|
24
|
+
import { $strlen } from "./$strlen";
|
|
22
25
|
import { $tail } from "./$tail";
|
|
23
26
|
|
|
24
27
|
/**
|
|
@@ -91,25 +94,37 @@ export namespace Namespace {
|
|
|
91
94
|
},
|
|
92
95
|
});
|
|
93
96
|
|
|
94
|
-
export
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
export namespace json {
|
|
98
|
+
export const stringify = (method: string) => ({
|
|
99
|
+
...is(),
|
|
100
|
+
number: $number,
|
|
101
|
+
string: $string,
|
|
102
|
+
tail: $tail,
|
|
103
|
+
rest: $rest,
|
|
104
|
+
throws: $throws(method),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
102
107
|
|
|
103
|
-
export
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
export namespace protobuf {
|
|
109
|
+
export const encode = (method: string) => ({
|
|
110
|
+
Writer: Writer,
|
|
111
|
+
strl: $strlen,
|
|
112
|
+
throws: $throws(method),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
108
115
|
|
|
109
|
-
export
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
export namespace misc {
|
|
117
|
+
export const clone = (method: string) => ({
|
|
118
|
+
...is(),
|
|
119
|
+
throws: $throws(method),
|
|
120
|
+
any: $any,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export const prune = (method: string) => ({
|
|
124
|
+
...is(),
|
|
125
|
+
throws: $throws(method),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
113
128
|
|
|
114
129
|
export const random = () => ({
|
|
115
130
|
generator: RandomGenerator,
|
package/src/json.ts
CHANGED
|
@@ -254,7 +254,7 @@ export function stringify<T>(input: T): string;
|
|
|
254
254
|
export function stringify(): never {
|
|
255
255
|
halt("stringify");
|
|
256
256
|
}
|
|
257
|
-
Object.assign(stringify, Namespace.stringify("stringify"));
|
|
257
|
+
Object.assign(stringify, Namespace.json.stringify("stringify"));
|
|
258
258
|
|
|
259
259
|
/**
|
|
260
260
|
* 5x faster `JSON.stringify()` function with type assertion.
|
|
@@ -309,7 +309,7 @@ export function assertStringify(): string {
|
|
|
309
309
|
halt("assertStringify");
|
|
310
310
|
}
|
|
311
311
|
Object.assign(assertStringify, Namespace.assert("assertStringify"));
|
|
312
|
-
Object.assign(assertStringify, Namespace.stringify("assertStringify"));
|
|
312
|
+
Object.assign(assertStringify, Namespace.json.stringify("assertStringify"));
|
|
313
313
|
|
|
314
314
|
/**
|
|
315
315
|
* 7x faster `JSON.stringify()` function with type checking.
|
|
@@ -365,7 +365,7 @@ export function isStringify(): string | null {
|
|
|
365
365
|
}
|
|
366
366
|
|
|
367
367
|
Object.assign(isStringify, Namespace.is());
|
|
368
|
-
Object.assign(isStringify, Namespace.stringify("isStringify"));
|
|
368
|
+
Object.assign(isStringify, Namespace.json.stringify("isStringify"));
|
|
369
369
|
|
|
370
370
|
/**
|
|
371
371
|
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
@@ -422,7 +422,7 @@ export function validateStringify(): IValidation<string> {
|
|
|
422
422
|
halt("validateStringify");
|
|
423
423
|
}
|
|
424
424
|
Object.assign(validateStringify, Namespace.validate());
|
|
425
|
-
Object.assign(validateStringify, Namespace.stringify("validateStringify"));
|
|
425
|
+
Object.assign(validateStringify, Namespace.json.stringify("validateStringify"));
|
|
426
426
|
|
|
427
427
|
/* -----------------------------------------------------------
|
|
428
428
|
FACTORY FUNCTIONS
|
package/src/misc.ts
CHANGED
|
@@ -84,7 +84,7 @@ export function clone<T>(input: T): Primitive<T>;
|
|
|
84
84
|
export function clone(): never {
|
|
85
85
|
halt("clone");
|
|
86
86
|
}
|
|
87
|
-
Object.assign(clone, Namespace.clone("clone"));
|
|
87
|
+
Object.assign(clone, Namespace.misc.clone("clone"));
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Clone a data with type assertion.
|
|
@@ -131,7 +131,7 @@ export function assertClone(): never {
|
|
|
131
131
|
halt("assertClone");
|
|
132
132
|
}
|
|
133
133
|
Object.assign(assertClone, Namespace.assert("assertClone"));
|
|
134
|
-
Object.assign(assertClone, Namespace.clone("assertClone"));
|
|
134
|
+
Object.assign(assertClone, Namespace.misc.clone("assertClone"));
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* Clone a data with type checking.
|
|
@@ -178,7 +178,7 @@ export function isClone(): never {
|
|
|
178
178
|
halt("isClone");
|
|
179
179
|
}
|
|
180
180
|
Object.assign(isClone, Namespace.is());
|
|
181
|
-
Object.assign(isClone, Namespace.clone("isClone"));
|
|
181
|
+
Object.assign(isClone, Namespace.misc.clone("isClone"));
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
184
|
* Clone a data with detailed type validation.
|
|
@@ -223,7 +223,7 @@ export function validateClone(): never {
|
|
|
223
223
|
halt("validateClone");
|
|
224
224
|
}
|
|
225
225
|
Object.assign(validateClone, Namespace.validate());
|
|
226
|
-
Object.assign(validateClone, Namespace.clone("validateClone"));
|
|
226
|
+
Object.assign(validateClone, Namespace.misc.clone("validateClone"));
|
|
227
227
|
|
|
228
228
|
/* -----------------------------------------------------------
|
|
229
229
|
PRUNE
|
|
@@ -257,7 +257,7 @@ export function prune<T extends object>(input: T): void;
|
|
|
257
257
|
export function prune(): never {
|
|
258
258
|
halt("prune");
|
|
259
259
|
}
|
|
260
|
-
Object.assign(prune, Namespace.prune("prune"));
|
|
260
|
+
Object.assign(prune, Namespace.misc.prune("prune"));
|
|
261
261
|
|
|
262
262
|
/**
|
|
263
263
|
* Prune, erase superfluous properties, with type assertion.
|
|
@@ -302,7 +302,7 @@ export function assertPrune(): unknown {
|
|
|
302
302
|
halt("assertPrune");
|
|
303
303
|
}
|
|
304
304
|
Object.assign(assertPrune, Namespace.assert("assertPrune"));
|
|
305
|
-
Object.assign(assertPrune, Namespace.prune("assertPrune"));
|
|
305
|
+
Object.assign(assertPrune, Namespace.misc.prune("assertPrune"));
|
|
306
306
|
|
|
307
307
|
/**
|
|
308
308
|
* Prune, erase superfluous properties, with type checking.
|
|
@@ -349,7 +349,7 @@ export function isPrune(): never {
|
|
|
349
349
|
halt("isPrune");
|
|
350
350
|
}
|
|
351
351
|
Object.assign(isPrune, Namespace.is());
|
|
352
|
-
Object.assign(isPrune, Namespace.prune("isPrune"));
|
|
352
|
+
Object.assign(isPrune, Namespace.misc.prune("isPrune"));
|
|
353
353
|
|
|
354
354
|
/**
|
|
355
355
|
* Prune, erase superfluous properties, with type validation.
|
|
@@ -397,7 +397,7 @@ export function validatePrune<T>(input: unknown): IValidation<T>;
|
|
|
397
397
|
export function validatePrune<T>(): IValidation<T> {
|
|
398
398
|
halt("validatePrune");
|
|
399
399
|
}
|
|
400
|
-
Object.assign(validatePrune, Namespace.prune("validatePrune"));
|
|
400
|
+
Object.assign(validatePrune, Namespace.misc.prune("validatePrune"));
|
|
401
401
|
Object.assign(validatePrune, Namespace.validate());
|
|
402
402
|
|
|
403
403
|
/* -----------------------------------------------------------
|
|
@@ -218,15 +218,6 @@ export namespace CheckerProgrammer {
|
|
|
218
218
|
resolve: false,
|
|
219
219
|
constant: true,
|
|
220
220
|
absorb: true,
|
|
221
|
-
validate: (meta) => {
|
|
222
|
-
if (
|
|
223
|
-
meta.arrays.length > 1 &&
|
|
224
|
-
meta.arrays.some((a) => a.recursive)
|
|
225
|
-
)
|
|
226
|
-
throw new Error(
|
|
227
|
-
`Repeated union array types are not supported yet.`,
|
|
228
|
-
);
|
|
229
|
-
},
|
|
230
221
|
})(collection)(type);
|
|
231
222
|
return [collection, meta];
|
|
232
223
|
},
|
|
@@ -59,7 +59,7 @@ export namespace FeatureProgrammer {
|
|
|
59
59
|
/**
|
|
60
60
|
* Object configurator.
|
|
61
61
|
*/
|
|
62
|
-
objector: IConfig.IObjector
|
|
62
|
+
objector: IConfig.IObjector<Output>;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Generator of functions for object types.
|
|
@@ -72,7 +72,9 @@ export namespace FeatureProgrammer {
|
|
|
72
72
|
output: (type: ts.Type, name?: string) => ts.TypeNode;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export interface IObjector
|
|
75
|
+
export interface IObjector<
|
|
76
|
+
Output extends ts.ConciseBody = ts.ConciseBody,
|
|
77
|
+
> {
|
|
76
78
|
/**
|
|
77
79
|
* Type checker when union object type comes.
|
|
78
80
|
*/
|
|
@@ -88,7 +90,7 @@ export namespace FeatureProgrammer {
|
|
|
88
90
|
*/
|
|
89
91
|
joiner(
|
|
90
92
|
input: ts.Expression,
|
|
91
|
-
entries: IExpressionEntry[],
|
|
93
|
+
entries: IExpressionEntry<Output>[],
|
|
92
94
|
parent: MetadataObject,
|
|
93
95
|
): ts.ConciseBody;
|
|
94
96
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
import { Atomic } from "../../typings/Atomic";
|
|
4
|
+
|
|
5
|
+
export namespace ProtobufUtil {
|
|
6
|
+
export const atomics = (meta: Metadata) => {
|
|
7
|
+
const set: Set<Atomic.Literal> = new Set();
|
|
8
|
+
|
|
9
|
+
for (const atomic of meta.atomics) set.add(atomic);
|
|
10
|
+
for (const constant of meta.constants) set.add(constant.type);
|
|
11
|
+
if (meta.templates.length) set.add("string");
|
|
12
|
+
|
|
13
|
+
return [...set].sort(
|
|
14
|
+
(x, y) => ATOMIC_ORDER.get(x)! - ATOMIC_ORDER.get(y)!,
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const ATOMIC_ORDER = new Map<Atomic.Literal, number>([
|
|
20
|
+
["boolean", 0],
|
|
21
|
+
["bigint", 1],
|
|
22
|
+
["number", 2],
|
|
23
|
+
["string", 3],
|
|
24
|
+
]);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const enum ProtobufWire {
|
|
2
|
+
/**
|
|
3
|
+
* integers
|
|
4
|
+
* bool
|
|
5
|
+
* enum
|
|
6
|
+
*/
|
|
7
|
+
VARINT = 0,
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* fixed64
|
|
11
|
+
* sfixed64
|
|
12
|
+
* double
|
|
13
|
+
*/
|
|
14
|
+
I64 = 1,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* string
|
|
18
|
+
* bytes
|
|
19
|
+
* mebedded messages
|
|
20
|
+
* packed repeated fields
|
|
21
|
+
*/
|
|
22
|
+
LEN = 2,
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* fixed, sfixed32, float
|
|
26
|
+
*/
|
|
27
|
+
I32 = 5,
|
|
28
|
+
}
|