typia 5.0.0-dev.20230805 → 5.0.0-dev.20230810
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/executable/TypiaSetupWizard.js +39 -28
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/lib/factories/{ProtocolFactory.d.ts → ProtobufFactory.d.ts} +2 -2
- package/lib/factories/ProtobufFactory.js +235 -0
- package/lib/factories/ProtobufFactory.js.map +1 -0
- package/lib/programmers/RandomProgrammer.js +1 -1
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/internal/stringify_dynamic_properties.js +1 -0
- package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.d.ts +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +160 -60
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/lib/schemas/metadata/Metadata.js +1 -1
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/transformers/features/protobuf/ProtobufMessageTransformer.js +1 -1
- package/lib/transformers/features/protobuf/ProtobufMessageTransformer.js.map +1 -1
- package/lib/utils/PatternUtil.d.ts +1 -1
- package/lib/utils/PatternUtil.js +3 -1
- package/lib/utils/PatternUtil.js.map +1 -1
- package/package.json +2 -2
- package/src/executable/TypiaSetupWizard.ts +34 -14
- package/src/factories/ProtobufFactory.ts +235 -0
- package/src/programmers/RandomProgrammer.ts +1 -3
- package/src/programmers/internal/stringify_dynamic_properties.ts +4 -0
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +113 -72
- package/src/schemas/metadata/Metadata.ts +2 -1
- package/src/transformers/features/protobuf/ProtobufMessageTransformer.ts +1 -1
- package/src/utils/PatternUtil.ts +4 -1
- package/lib/factories/ProtocolFactory.js +0 -113
- package/lib/factories/ProtocolFactory.js.map +0 -1
- package/src/factories/ProtocolFactory.ts +0 -80
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../schemas/metadata/Metadata";
|
|
4
|
-
import { IProtocolMessage } from "../schemas/protobuf/IProtocolMessage";
|
|
5
|
-
|
|
6
|
-
import { MetadataCollection } from "./MetadataCollection";
|
|
7
|
-
import { MetadataFactory } from "./MetadataFactory";
|
|
8
|
-
import { emplace_protocol_object } from "./internal/protocols/emplace_protocol_object";
|
|
9
|
-
import { iterate_protocol_main } from "./internal/protocols/iterate_protocol_main";
|
|
10
|
-
|
|
11
|
-
export namespace ProtocolFactory {
|
|
12
|
-
export const metadata =
|
|
13
|
-
(checker: ts.TypeChecker) =>
|
|
14
|
-
(collection: MetadataCollection) =>
|
|
15
|
-
(type: ts.Type) =>
|
|
16
|
-
MetadataFactory.analyze(checker)({
|
|
17
|
-
resolve: false,
|
|
18
|
-
constant: true,
|
|
19
|
-
absorb: true,
|
|
20
|
-
validate: (meta) => {
|
|
21
|
-
if (meta.any) throw new Error(ErrorMessages.NO_ANY);
|
|
22
|
-
else if (meta.functional && meta.size() !== 1)
|
|
23
|
-
throw new Error(ErrorMessages.NO_FUNCTIONAL);
|
|
24
|
-
else if (meta.objects.find((o) => o.name === "__Main"))
|
|
25
|
-
throw new Error(ErrorMessages.NO_MAIN);
|
|
26
|
-
else if (meta.objects.find((o) => o.name === "__Timestamp"))
|
|
27
|
-
throw new Error(ErrorMessages.NO_TIMESTAMP);
|
|
28
|
-
else if (
|
|
29
|
-
meta.objects.some((o) =>
|
|
30
|
-
o.properties.some((p) => !is_atomic_key(p.key)),
|
|
31
|
-
) ||
|
|
32
|
-
meta.maps.some((m) => !is_atomic_key(m.key))
|
|
33
|
-
)
|
|
34
|
-
throw new Error(ErrorMessages.NOT_ALLOWED_KEY);
|
|
35
|
-
},
|
|
36
|
-
})(collection)(type);
|
|
37
|
-
|
|
38
|
-
export const analyze =
|
|
39
|
-
(collection: MetadataCollection) =>
|
|
40
|
-
(dict: Map<string, IProtocolMessage>) =>
|
|
41
|
-
(meta: Metadata) => {
|
|
42
|
-
// EMPLACE OBJECTS
|
|
43
|
-
for (const obj of collection.objects())
|
|
44
|
-
emplace_protocol_object(dict)(obj);
|
|
45
|
-
|
|
46
|
-
// WHEN NOT OBJECT, WRAP IT INTO A FAKE MAIN OBJECT
|
|
47
|
-
iterate_protocol_main(dict)(meta);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const is_atomic_key = (key: Metadata) => {
|
|
51
|
-
if (
|
|
52
|
-
key.required &&
|
|
53
|
-
key.nullable === false &&
|
|
54
|
-
key.functional === false &&
|
|
55
|
-
key.resolved === null &&
|
|
56
|
-
key.size() ===
|
|
57
|
-
key.atomics.length +
|
|
58
|
-
key.constants
|
|
59
|
-
.map((c) => c.values.length)
|
|
60
|
-
.reduce((a, b) => a + b, 0) +
|
|
61
|
-
key.templates.length
|
|
62
|
-
) {
|
|
63
|
-
const set: Set<string> = new Set();
|
|
64
|
-
for (const atomic of key.atomics) set.add(atomic);
|
|
65
|
-
for (const constant of key.constants) set.add(constant.type);
|
|
66
|
-
if (key.templates.length) set.add("string");
|
|
67
|
-
|
|
68
|
-
return set.size === 1;
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const enum ErrorMessages {
|
|
75
|
-
NO_ANY = `Error on typia.message(): any type is not supported in protocol buffer.`,
|
|
76
|
-
NO_FUNCTIONAL = `Error on typia.message(): functional type is not supported in protocol buffer.`,
|
|
77
|
-
NO_MAIN = `Error on typia.message(): reserved type "__Main" has been detected.`,
|
|
78
|
-
NO_TIMESTAMP = `Error on typia.message(): reserved type "__Timestamp" has been detected.`,
|
|
79
|
-
NOT_ALLOWED_KEY = `Error on typia.message(): only atomic key type is supported in protocol buffer.`,
|
|
80
|
-
}
|