typia 5.0.0-dev.20230811 → 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 +45 -116
- 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 +19 -33
- 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 +1 -1
- package/src/factories/MetadataCollection.ts +5 -0
- package/src/factories/MetadataFactory.ts +4 -0
- package/src/factories/ProtobufFactory.ts +86 -99
- 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 +6 -4
- 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,14 +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
|
-
import { IProtocolMessage } from "../schemas/protobuf/IProtocolMessage";
|
|
6
5
|
|
|
7
6
|
import { Escaper } from "../utils/Escaper";
|
|
8
7
|
|
|
9
8
|
import { MetadataCollection } from "./MetadataCollection";
|
|
10
9
|
import { MetadataFactory } from "./MetadataFactory";
|
|
11
|
-
import { emplace_protocol_object } from "./internal/protocols/emplace_protocol_object";
|
|
12
|
-
import { iterate_protocol_main } from "./internal/protocols/iterate_protocol_main";
|
|
13
10
|
|
|
14
11
|
export namespace ProtobufFactory {
|
|
15
12
|
export const metadata =
|
|
@@ -44,37 +41,70 @@ export namespace ProtobufFactory {
|
|
|
44
41
|
return top;
|
|
45
42
|
};
|
|
46
43
|
|
|
47
|
-
export const analyze =
|
|
48
|
-
(collection: MetadataCollection) =>
|
|
49
|
-
(dict: Map<string, IProtocolMessage>) =>
|
|
50
|
-
(meta: Metadata) => {
|
|
51
|
-
// EMPLACE OBJECTS
|
|
52
|
-
for (const obj of collection.objects())
|
|
53
|
-
emplace_protocol_object(dict)(obj);
|
|
54
|
-
|
|
55
|
-
// WHEN NOT OBJECT, WRAP IT INTO A FAKE MAIN OBJECT
|
|
56
|
-
iterate_protocol_main(dict)(meta);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
44
|
const validate = (method: string) => (meta: Metadata) => {
|
|
60
45
|
//----
|
|
61
|
-
// NOT
|
|
46
|
+
// NOT SUPPORTED TYPES
|
|
62
47
|
//----
|
|
48
|
+
// PROHIBIT ANY TYPE
|
|
63
49
|
if (meta.any) throw notSupportedError({ method })("any type");
|
|
50
|
+
// PROHIBIT FUNCTIONAL TYPE
|
|
64
51
|
else if (meta.functional)
|
|
65
52
|
throw notSupportedError({ method })("functional type");
|
|
53
|
+
// PROHIBIT TUPLE TYPE
|
|
66
54
|
else if (meta.tuples.length)
|
|
67
55
|
throw notSupportedError({ method })("tuple type");
|
|
56
|
+
// PROHIBIT SET TYPE
|
|
68
57
|
else if (meta.sets.length)
|
|
69
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
|
|
70
75
|
else if (
|
|
71
76
|
meta.arrays.length &&
|
|
72
77
|
meta.arrays.some((array) => !!array.value.arrays.length)
|
|
73
78
|
)
|
|
74
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");
|
|
75
99
|
//----
|
|
76
|
-
//
|
|
100
|
+
// OBJECT CASES
|
|
77
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");
|
|
78
108
|
// MULTIPLE DYNAMIC KEY TYPED PROPERTIES
|
|
79
109
|
else if (
|
|
80
110
|
meta.objects.length &&
|
|
@@ -92,7 +122,6 @@ export namespace ProtobufFactory {
|
|
|
92
122
|
meta.objects.length &&
|
|
93
123
|
meta.objects.some(
|
|
94
124
|
(obj) =>
|
|
95
|
-
obj.properties.length &&
|
|
96
125
|
obj.properties.some((p) => p.key.isSoleLiteral()) &&
|
|
97
126
|
obj.properties.some((p) => !p.key.isSoleLiteral()),
|
|
98
127
|
)
|
|
@@ -114,29 +143,7 @@ export namespace ProtobufFactory {
|
|
|
114
143
|
throw notSupportedError({ method })(
|
|
115
144
|
`object type with invalid static key name.`,
|
|
116
145
|
);
|
|
117
|
-
//
|
|
118
|
-
else if (meta.natives.length) {
|
|
119
|
-
const banned = meta.natives
|
|
120
|
-
.map((n) => [n, BANNED_NATIVE_TYPES.get(n)] as const)
|
|
121
|
-
.filter(([_n, b]) => b !== undefined)[0];
|
|
122
|
-
if (banned !== undefined)
|
|
123
|
-
throw notSupportedError({ method })(
|
|
124
|
-
banned[1] === null
|
|
125
|
-
? banned[0]
|
|
126
|
-
: `${banned[0]}. Use ${banned[1]} instead.`,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
// MAP TYPE, BUT PROPERTY KEY TYPE IS NOT ATOMIC
|
|
130
|
-
else if (meta.maps.length && meta.maps.some((m) => !isAtomicKey(m.key)))
|
|
131
|
-
throw notSupportedError({ method })("");
|
|
132
|
-
// MAP TYPE, BUT VALUE TYPE IS ARRAY
|
|
133
|
-
else if (
|
|
134
|
-
meta.maps.length &&
|
|
135
|
-
meta.maps.some((m) => !!m.value.arrays.length)
|
|
136
|
-
)
|
|
137
|
-
throw notSupportedError({ method })(
|
|
138
|
-
"map type with array value type",
|
|
139
|
-
);
|
|
146
|
+
// DYNAMIC OBJECT, BUT PROPERTY VALUE TYPE IS ARRAY
|
|
140
147
|
else if (
|
|
141
148
|
meta.objects.length &&
|
|
142
149
|
isDynamicObject(meta.objects[0]!) &&
|
|
@@ -145,18 +152,6 @@ export namespace ProtobufFactory {
|
|
|
145
152
|
throw notSupportedError({ method })(
|
|
146
153
|
"dynamic object with array value type",
|
|
147
154
|
);
|
|
148
|
-
//----
|
|
149
|
-
// UNION TYPES
|
|
150
|
-
//----
|
|
151
|
-
// UNION IN ARRAY
|
|
152
|
-
else if (
|
|
153
|
-
meta.arrays.length &&
|
|
154
|
-
meta.arrays.some((a) => a.value.size() > 1)
|
|
155
|
-
)
|
|
156
|
-
throw notSupportedError({ method })("union type in array");
|
|
157
|
-
// UNION WITH ARRAY
|
|
158
|
-
else if (meta.size() > 1 && meta.arrays.length)
|
|
159
|
-
throw notSupportedError({ method })("union type with array type");
|
|
160
155
|
// UNION WITH DYNAMIC OBJECT
|
|
161
156
|
else if (
|
|
162
157
|
meta.size() > 1 &&
|
|
@@ -172,17 +167,51 @@ export namespace ProtobufFactory {
|
|
|
172
167
|
meta.objects.some(
|
|
173
168
|
(obj) =>
|
|
174
169
|
isDynamicObject(obj) &&
|
|
175
|
-
obj.properties.some((p) =>
|
|
170
|
+
obj.properties.some((p) => p.value.isBinaryUnion()),
|
|
176
171
|
)
|
|
177
172
|
)
|
|
178
173
|
throw notSupportedError({ method })(
|
|
179
174
|
"union type in dynamic property",
|
|
180
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
|
+
);
|
|
181
207
|
// UNION WITH MAP
|
|
182
208
|
else if (meta.size() > 1 && meta.maps.length)
|
|
183
209
|
throw notSupportedError({ method })("union type with map type");
|
|
184
210
|
// UNION IN MAP
|
|
185
|
-
else if (
|
|
211
|
+
else if (
|
|
212
|
+
meta.maps.length &&
|
|
213
|
+
meta.maps.some((m) => m.value.isBinaryUnion())
|
|
214
|
+
)
|
|
186
215
|
throw notSupportedError({ method })("union type in map");
|
|
187
216
|
};
|
|
188
217
|
}
|
|
@@ -194,50 +223,8 @@ const notSupportedError = (p: { method: string }) => (title: string) =>
|
|
|
194
223
|
`${prefix(p.method)}: protocol buffer does not support ${title}.`,
|
|
195
224
|
);
|
|
196
225
|
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
key.required &&
|
|
200
|
-
key.nullable === false &&
|
|
201
|
-
key.functional === false &&
|
|
202
|
-
key.resolved === null &&
|
|
203
|
-
key.size() ===
|
|
204
|
-
key.atomics.length +
|
|
205
|
-
key.constants
|
|
206
|
-
.map((c) => c.values.length)
|
|
207
|
-
.reduce((a, b) => a + b, 0) +
|
|
208
|
-
key.templates.length
|
|
209
|
-
) {
|
|
210
|
-
const set: Set<string> = new Set();
|
|
211
|
-
for (const atomic of key.atomics) set.add(atomic);
|
|
212
|
-
for (const constant of key.constants) set.add(constant.type);
|
|
213
|
-
if (key.templates.length) set.add("string");
|
|
214
|
-
|
|
215
|
-
return set.size === 1;
|
|
216
|
-
}
|
|
217
|
-
return false;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const isDynamicObject = (obj: MetadataObject): boolean => {
|
|
221
|
-
return (
|
|
222
|
-
obj.properties.length > 0 &&
|
|
223
|
-
obj.properties[0]!.key.isSoleLiteral() === false
|
|
224
|
-
);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const isUnion = (meta: Metadata): boolean => {
|
|
228
|
-
const count: number =
|
|
229
|
-
new Set([
|
|
230
|
-
...meta.atomics,
|
|
231
|
-
...meta.constants.map((c) => c.type),
|
|
232
|
-
...(meta.templates.length ? ["string"] : []),
|
|
233
|
-
]).size +
|
|
234
|
-
meta.arrays.length +
|
|
235
|
-
meta.tuples.length +
|
|
236
|
-
meta.natives.length +
|
|
237
|
-
meta.objects.length +
|
|
238
|
-
meta.maps.length;
|
|
239
|
-
return count > 1;
|
|
240
|
-
};
|
|
226
|
+
const isDynamicObject = (obj: MetadataObject): boolean =>
|
|
227
|
+
obj.properties[0]!.key.isSoleLiteral() === false;
|
|
241
228
|
|
|
242
229
|
const BANNED_NATIVE_TYPES: Map<string, string | null> = new Map([
|
|
243
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
|
+
}
|