typia 5.0.0-dev.20230808 → 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/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/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/package.json +1 -1
- package/src/factories/ProtobufFactory.ts +235 -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/lib/factories/ProtocolFactory.js +0 -113
- package/lib/factories/ProtocolFactory.js.map +0 -1
- package/src/factories/ProtocolFactory.ts +0 -80
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.ProtocolFactory = void 0;
|
|
15
|
-
var MetadataFactory_1 = require("./MetadataFactory");
|
|
16
|
-
var emplace_protocol_object_1 = require("./internal/protocols/emplace_protocol_object");
|
|
17
|
-
var iterate_protocol_main_1 = require("./internal/protocols/iterate_protocol_main");
|
|
18
|
-
var ProtocolFactory;
|
|
19
|
-
(function (ProtocolFactory) {
|
|
20
|
-
ProtocolFactory.metadata = function (checker) {
|
|
21
|
-
return function (collection) {
|
|
22
|
-
return function (type) {
|
|
23
|
-
return MetadataFactory_1.MetadataFactory.analyze(checker)({
|
|
24
|
-
resolve: false,
|
|
25
|
-
constant: true,
|
|
26
|
-
absorb: true,
|
|
27
|
-
validate: function (meta) {
|
|
28
|
-
if (meta.any)
|
|
29
|
-
throw new Error("Error on typia.message(): any type is not supported in protocol buffer.");
|
|
30
|
-
else if (meta.functional && meta.size() !== 1)
|
|
31
|
-
throw new Error("Error on typia.message(): functional type is not supported in protocol buffer.");
|
|
32
|
-
else if (meta.objects.find(function (o) { return o.name === "__Main"; }))
|
|
33
|
-
throw new Error("Error on typia.message(): reserved type \"__Main\" has been detected.");
|
|
34
|
-
else if (meta.objects.find(function (o) { return o.name === "__Timestamp"; }))
|
|
35
|
-
throw new Error("Error on typia.message(): reserved type \"__Timestamp\" has been detected.");
|
|
36
|
-
else if (meta.objects.some(function (o) {
|
|
37
|
-
return o.properties.some(function (p) { return !is_atomic_key(p.key); });
|
|
38
|
-
}) ||
|
|
39
|
-
meta.maps.some(function (m) { return !is_atomic_key(m.key); }))
|
|
40
|
-
throw new Error("Error on typia.message(): only atomic key type is supported in protocol buffer.");
|
|
41
|
-
},
|
|
42
|
-
})(collection)(type);
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
ProtocolFactory.analyze = function (collection) {
|
|
47
|
-
return function (dict) {
|
|
48
|
-
return function (meta) {
|
|
49
|
-
var e_1, _a;
|
|
50
|
-
try {
|
|
51
|
-
for (var _b = __values(collection.objects()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
52
|
-
var obj = _c.value;
|
|
53
|
-
(0, emplace_protocol_object_1.emplace_protocol_object)(dict)(obj);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e_1) throw e_1.error; }
|
|
62
|
-
}
|
|
63
|
-
(0, iterate_protocol_main_1.iterate_protocol_main)(dict)(meta);
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
var is_atomic_key = function (key) {
|
|
68
|
-
var e_2, _a, e_3, _b;
|
|
69
|
-
if (key.required &&
|
|
70
|
-
key.nullable === false &&
|
|
71
|
-
key.functional === false &&
|
|
72
|
-
key.resolved === null &&
|
|
73
|
-
key.size() ===
|
|
74
|
-
key.atomics.length +
|
|
75
|
-
key.constants
|
|
76
|
-
.map(function (c) { return c.values.length; })
|
|
77
|
-
.reduce(function (a, b) { return a + b; }, 0) +
|
|
78
|
-
key.templates.length) {
|
|
79
|
-
var set = new Set();
|
|
80
|
-
try {
|
|
81
|
-
for (var _c = __values(key.atomics), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
82
|
-
var atomic = _d.value;
|
|
83
|
-
set.add(atomic);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
87
|
-
finally {
|
|
88
|
-
try {
|
|
89
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
90
|
-
}
|
|
91
|
-
finally { if (e_2) throw e_2.error; }
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
for (var _e = __values(key.constants), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
95
|
-
var constant = _f.value;
|
|
96
|
-
set.add(constant.type);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
100
|
-
finally {
|
|
101
|
-
try {
|
|
102
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
103
|
-
}
|
|
104
|
-
finally { if (e_3) throw e_3.error; }
|
|
105
|
-
}
|
|
106
|
-
if (key.templates.length)
|
|
107
|
-
set.add("string");
|
|
108
|
-
return set.size === 1;
|
|
109
|
-
}
|
|
110
|
-
return false;
|
|
111
|
-
};
|
|
112
|
-
})(ProtocolFactory || (exports.ProtocolFactory = ProtocolFactory = {}));
|
|
113
|
-
//# sourceMappingURL=ProtocolFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProtocolFactory.js","sourceRoot":"","sources":["../../src/factories/ProtocolFactory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAMA,qDAAoD;AACpD,wFAAuF;AACvF,oFAAmF;AAEnF,IAAiB,eAAe,CA6D/B;AA7DD,WAAiB,eAAe;IACf,wBAAQ,GACjB,UAAC,OAAuB;QACxB,OAAA,UAAC,UAA8B;YAC/B,OAAA,UAAC,IAAa;gBACV,OAAA,iCAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;oBAC7B,OAAO,EAAE,KAAK;oBACd,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;oBACZ,QAAQ,EAAE,UAAC,IAAI;wBACX,IAAI,IAAI,CAAC,GAAG;4BAAE,MAAM,IAAI,KAAK,2EAAsB,CAAC;6BAC/C,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC;4BACzC,MAAM,IAAI,KAAK,kFAA6B,CAAC;6BAC5C,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAnB,CAAmB,CAAC;4BAClD,MAAM,IAAI,KAAK,yEAAuB,CAAC;6BACtC,IAAI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BACN,GAAG,CAAC,OAAO,CAAC,MAAM;oBACd,GAAG,CAAC,SAAS;yBACR,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,MAAM,CAAC,MAAM,EAAf,CAAe,CAAC;yBAC3B,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,CAAC,EAAL,CAAK,EAAE,CAAC,CAAC;oBAC/B,GAAG,CAAC,SAAS,CAAC,MAAM,EAC9B;YACE,IAAM,GAAG,GAAgB,IAAI,GAAG,EAAE,CAAC;;gBACnC,KAAqB,IAAA,KAAA,SAAA,GAAG,CAAC,OAAO,CAAA,gBAAA;oBAA3B,IAAM,MAAM,WAAA;oBAAiB,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;iBAAA;;;;;;;;;;gBAClD,KAAuB,IAAA,KAAA,SAAA,GAAG,CAAC,SAAS,CAAA,gBAAA;oBAA/B,IAAM,QAAQ,WAAA;oBAAmB,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;iBAAA;;;;;;;;;YAC7D,IAAI,GAAG,CAAC,SAAS,CAAC,MAAM;gBAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAE5C,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC;SACzB;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;AACN,CAAC,EA7DgB,eAAe,+BAAf,eAAe,QA6D/B"}
|
|
@@ -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
|
-
}
|