typia 5.0.0-dev.20230814 → 5.0.0-dev.20230818
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/ExpressionFactory.d.ts +1 -0
- package/lib/factories/ExpressionFactory.js +33 -0
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/StatementFactory.d.ts +2 -0
- package/lib/factories/StatementFactory.js +11 -0
- package/lib/factories/StatementFactory.js.map +1 -1
- package/lib/functional/$ProtobufReader.d.ts +33 -0
- package/lib/functional/$ProtobufReader.js +155 -0
- package/lib/functional/$ProtobufReader.js.map +1 -0
- package/lib/functional/$ProtobufSizer.d.ts +36 -0
- package/lib/functional/$ProtobufSizer.js +105 -0
- package/lib/functional/$ProtobufSizer.js.map +1 -0
- package/lib/functional/$ProtobufWriter.d.ts +45 -0
- package/lib/functional/$ProtobufWriter.js +107 -0
- package/lib/functional/$ProtobufWriter.js.map +1 -0
- package/lib/functional/IProtobufWriter.d.ts +15 -0
- package/lib/functional/IProtobufWriter.js +3 -0
- package/lib/functional/IProtobufWriter.js.map +1 -0
- package/lib/functional/Namespace.js +13 -6
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.js +2 -2
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/helpers/CloneJoiner.js +1 -7
- package/lib/programmers/helpers/CloneJoiner.js.map +1 -1
- package/lib/programmers/helpers/ProtobufWire.d.ts +16 -12
- package/lib/programmers/helpers/RandomRanger.js +1 -1
- package/lib/programmers/helpers/RandomRanger.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +3 -0
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +269 -127
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +8 -2
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/lib/protobuf.js +23 -9
- package/lib/protobuf.js.map +1 -1
- package/lib/schemas/metadata/MetadataObject.js +4 -0
- package/lib/schemas/metadata/MetadataObject.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +0 -4
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.js +6 -3
- package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/ExpressionFactory.ts +20 -0
- package/src/factories/StatementFactory.ts +32 -0
- package/src/functional/$ProtobufReader.ts +189 -0
- package/src/functional/$ProtobufSizer.ts +144 -0
- package/src/functional/$ProtobufWriter.ts +152 -0
- package/src/functional/IProtobufWriter.ts +18 -0
- package/src/functional/Namespace.ts +14 -7
- package/src/programmers/FeatureProgrammer.ts +2 -2
- package/src/programmers/helpers/CloneJoiner.ts +1 -25
- package/src/programmers/helpers/ProtobufWire.ts +18 -12
- package/src/programmers/helpers/RandomRanger.ts +1 -1
- package/src/programmers/json/JsonStringifyProgrammer.ts +8 -0
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +544 -201
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +4 -1
- package/src/protobuf.ts +23 -29
- package/src/schemas/metadata/MetadataObject.ts +10 -0
- package/src/transformers/CallExpressionTransformer.ts +0 -4
- package/src/transformers/features/json/JsonApplicationTransformer.ts +12 -3
- package/lib/programmers/protobuf/ProtobufSizeProgrammer.d.ts +0 -5
- package/lib/programmers/protobuf/ProtobufSizeProgrammer.js +0 -409
- package/lib/programmers/protobuf/ProtobufSizeProgrammer.js.map +0 -1
- package/lib/transformers/features/protobuf/CreateProtobufSizeTransformer.d.ts +0 -3
- package/lib/transformers/features/protobuf/CreateProtobufSizeTransformer.js +0 -10
- package/lib/transformers/features/protobuf/CreateProtobufSizeTransformer.js.map +0 -1
- package/lib/transformers/features/protobuf/ProtobufSizeTransformer.d.ts +0 -3
- package/lib/transformers/features/protobuf/ProtobufSizeTransformer.js +0 -10
- package/lib/transformers/features/protobuf/ProtobufSizeTransformer.js.map +0 -1
- package/src/programmers/protobuf/ProtobufSizeProgrammer.ts +0 -716
- package/src/transformers/features/protobuf/CreateProtobufSizeTransformer.ts +0 -9
- package/src/transformers/features/protobuf/ProtobufSizeTransformer.ts +0 -9
|
@@ -143,7 +143,10 @@ export namespace ProtobufMessageProgrammer {
|
|
|
143
143
|
const type = tags.find((t) => t.kind === "type") as
|
|
144
144
|
| IMetadataTag.INumberType
|
|
145
145
|
| undefined;
|
|
146
|
-
|
|
146
|
+
if (type?.value === undefined) return "double";
|
|
147
|
+
else if (type.value === "int") return "int32";
|
|
148
|
+
else if (type.value === "uint") return "uint32";
|
|
149
|
+
else return type.value;
|
|
147
150
|
}
|
|
148
151
|
return literal;
|
|
149
152
|
};
|
package/src/protobuf.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Namespace } from "./functional/Namespace";
|
|
2
|
+
|
|
1
3
|
import { IValidation } from "./IValidation";
|
|
2
4
|
import { Primitive } from "./Primitive";
|
|
3
5
|
|
|
@@ -34,6 +36,7 @@ export function decode<T>(input: Uint8Array): Primitive<T>;
|
|
|
34
36
|
export function decode(): never {
|
|
35
37
|
halt("decode");
|
|
36
38
|
}
|
|
39
|
+
Object.assign(decode, Namespace.protobuf.decode("decode"));
|
|
37
40
|
|
|
38
41
|
export function isDecode(input: Uint8Array): never;
|
|
39
42
|
|
|
@@ -45,6 +48,8 @@ export function isDecode<T>(input: Uint8Array): Primitive<T> | null;
|
|
|
45
48
|
export function isDecode(): never {
|
|
46
49
|
halt("isDecode");
|
|
47
50
|
}
|
|
51
|
+
Object.assign(isDecode, Namespace.is());
|
|
52
|
+
Object.assign(isDecode, Namespace.protobuf.decode("isDecode"));
|
|
48
53
|
|
|
49
54
|
export function assertDecode(input: Uint8Array): never;
|
|
50
55
|
|
|
@@ -56,6 +61,8 @@ export function assertDecode<T>(input: Uint8Array): Primitive<T>;
|
|
|
56
61
|
export function assertDecode(): never {
|
|
57
62
|
halt("assertDecode");
|
|
58
63
|
}
|
|
64
|
+
Object.assign(assertDecode, Namespace.assert("assertDecode"));
|
|
65
|
+
Object.assign(assertDecode, Namespace.protobuf.decode("assertDecode"));
|
|
59
66
|
|
|
60
67
|
export function validateDecode(input: Uint8Array): never;
|
|
61
68
|
|
|
@@ -67,22 +74,12 @@ export function validateDecode<T>(input: Uint8Array): IValidation<Primitive<T>>;
|
|
|
67
74
|
export function validateDecode(): never {
|
|
68
75
|
halt("validateDecode");
|
|
69
76
|
}
|
|
77
|
+
Object.assign(validateDecode, Namespace.validate());
|
|
78
|
+
Object.assign(validateDecode, Namespace.protobuf.decode("validateDecode"));
|
|
70
79
|
|
|
71
80
|
/* -----------------------------------------------------------
|
|
72
81
|
ENCODE
|
|
73
82
|
----------------------------------------------------------- */
|
|
74
|
-
/**
|
|
75
|
-
* @internal
|
|
76
|
-
*/
|
|
77
|
-
export function size<T>(input: T): number;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @internal
|
|
81
|
-
*/
|
|
82
|
-
export function size(): never {
|
|
83
|
-
halt("size");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
83
|
export function encode<T>(input: T): Uint16Array;
|
|
87
84
|
|
|
88
85
|
/**
|
|
@@ -91,6 +88,7 @@ export function encode<T>(input: T): Uint16Array;
|
|
|
91
88
|
export function encode(): never {
|
|
92
89
|
halt("encode");
|
|
93
90
|
}
|
|
91
|
+
Object.assign(encode, Namespace.protobuf.encode("encode"));
|
|
94
92
|
|
|
95
93
|
export function isEncode<T>(input: T): Uint16Array | null;
|
|
96
94
|
|
|
@@ -100,6 +98,8 @@ export function isEncode<T>(input: T): Uint16Array | null;
|
|
|
100
98
|
export function isEncode(): never {
|
|
101
99
|
halt("isEncode");
|
|
102
100
|
}
|
|
101
|
+
Object.assign(isEncode, Namespace.is());
|
|
102
|
+
Object.assign(isEncode, Namespace.protobuf.encode("isEncode"));
|
|
103
103
|
|
|
104
104
|
export function assertEncode<T>(input: T): Uint16Array;
|
|
105
105
|
|
|
@@ -109,6 +109,8 @@ export function assertEncode<T>(input: T): Uint16Array;
|
|
|
109
109
|
export function assertEncode(): never {
|
|
110
110
|
halt("assertEncode");
|
|
111
111
|
}
|
|
112
|
+
Object.assign(assertEncode, Namespace.assert("assertEncode"));
|
|
113
|
+
Object.assign(assertEncode, Namespace.protobuf.encode("assertEncode"));
|
|
112
114
|
|
|
113
115
|
export function validateEncode<T>(input: T): IValidation<Uint16Array>;
|
|
114
116
|
|
|
@@ -118,6 +120,8 @@ export function validateEncode<T>(input: T): IValidation<Uint16Array>;
|
|
|
118
120
|
export function validateEncode(): never {
|
|
119
121
|
halt("validateEncode");
|
|
120
122
|
}
|
|
123
|
+
Object.assign(validateEncode, Namespace.validate());
|
|
124
|
+
Object.assign(validateEncode, Namespace.protobuf.encode("validateEncode"));
|
|
121
125
|
|
|
122
126
|
/* -----------------------------------------------------------
|
|
123
127
|
FACTORY FUNCTIONS
|
|
@@ -168,23 +172,6 @@ export function createValidateDecode<T>(): (
|
|
|
168
172
|
halt("createValidateDecode");
|
|
169
173
|
}
|
|
170
174
|
|
|
171
|
-
/**
|
|
172
|
-
* @internal
|
|
173
|
-
*/
|
|
174
|
-
export function createSize(): never;
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* @internal
|
|
178
|
-
*/
|
|
179
|
-
export function createSize<T>(): (input: T) => number;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* @internal
|
|
183
|
-
*/
|
|
184
|
-
export function createSize<T>(): (input: T) => number {
|
|
185
|
-
halt("createEncode");
|
|
186
|
-
}
|
|
187
|
-
|
|
188
175
|
export function createEncode(): never;
|
|
189
176
|
export function createEncode<T>(): (input: T) => Uint8Array;
|
|
190
177
|
|
|
@@ -194,6 +181,7 @@ export function createEncode<T>(): (input: T) => Uint8Array;
|
|
|
194
181
|
export function createEncode<T>(): (input: T) => Uint8Array {
|
|
195
182
|
halt("createEncode");
|
|
196
183
|
}
|
|
184
|
+
Object.assign(createEncode, Namespace.protobuf.encode("createEncode"));
|
|
197
185
|
|
|
198
186
|
export function createIsEncode(): never;
|
|
199
187
|
export function createIsEncode<T>(): (input: T) => Uint8Array | null;
|
|
@@ -204,6 +192,8 @@ export function createIsEncode<T>(): (input: T) => Uint8Array | null;
|
|
|
204
192
|
export function createIsEncode<T>(): (input: T) => Uint8Array | null {
|
|
205
193
|
halt("createIsEncode");
|
|
206
194
|
}
|
|
195
|
+
Object.assign(createIsEncode, Namespace.is);
|
|
196
|
+
Object.assign(createIsEncode, Namespace.protobuf.encode);
|
|
207
197
|
|
|
208
198
|
export function createAssertEncode(): never;
|
|
209
199
|
export function createAssertEncode<T>(): (input: T) => Uint8Array;
|
|
@@ -214,6 +204,8 @@ export function createAssertEncode<T>(): (input: T) => Uint8Array;
|
|
|
214
204
|
export function createAssertEncode<T>(): (input: T) => Uint8Array {
|
|
215
205
|
halt("createAssertEncode");
|
|
216
206
|
}
|
|
207
|
+
Object.assign(createAssertEncode, Namespace.assert);
|
|
208
|
+
Object.assign(createAssertEncode, Namespace.protobuf.encode);
|
|
217
209
|
|
|
218
210
|
export function createValidateEncode(): never;
|
|
219
211
|
export function createValidateEncode<T>(): (
|
|
@@ -228,6 +220,8 @@ export function createValidateEncode<T>(): (
|
|
|
228
220
|
) => IValidation<Uint8Array> {
|
|
229
221
|
halt("createValidateEncode");
|
|
230
222
|
}
|
|
223
|
+
Object.assign(createValidateEncode, Namespace.validate);
|
|
224
|
+
Object.assign(createValidateEncode, Namespace.protobuf.encode);
|
|
231
225
|
|
|
232
226
|
/**
|
|
233
227
|
* @internal
|
|
@@ -70,6 +70,16 @@ export class MetadataObject {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
public _Messagable(): boolean {
|
|
77
|
+
return (
|
|
78
|
+
this.properties.length >= 1 &&
|
|
79
|
+
this.properties.every((p) => p.key.isSoleLiteral())
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
73
83
|
/**
|
|
74
84
|
* @internal
|
|
75
85
|
*/
|
|
@@ -49,7 +49,6 @@ import { CreateProtobufDecodeTransformer } from "./features/protobuf/CreateProto
|
|
|
49
49
|
import { CreateProtobufEncodeTransformer } from "./features/protobuf/CreateProtobufEncodeTransformer";
|
|
50
50
|
import { CreateProtobufIsDecodeTransformer } from "./features/protobuf/CreateProtobufIsDecodeTransformer";
|
|
51
51
|
import { CreateProtobufIsEncodeTransformer } from "./features/protobuf/CreateProtobufIsEncodeTransformer";
|
|
52
|
-
import { CreateProtobufSizeTransformer } from "./features/protobuf/CreateProtobufSizeTransformer";
|
|
53
52
|
import { CreateProtobufValidateDecodeTransformer } from "./features/protobuf/CreateProtobufValidateDecodeTransformer";
|
|
54
53
|
import { CreateProtobufValidateEncodeTransformer } from "./features/protobuf/CreateProtobufValidateEncodeTransformer";
|
|
55
54
|
import { ProtobufAssertDecodeTransformer } from "./features/protobuf/ProtobufAssertDecodeTransformer";
|
|
@@ -59,7 +58,6 @@ import { ProtobufEncodeTransformer } from "./features/protobuf/ProtobufEncodeTra
|
|
|
59
58
|
import { ProtobufIsDecodeTransformer } from "./features/protobuf/ProtobufIsDecodeTransformer";
|
|
60
59
|
import { ProtobufIsEncodeTransformer } from "./features/protobuf/ProtobufIsEncodeTransformer";
|
|
61
60
|
import { ProtobufMessageTransformer } from "./features/protobuf/ProtobufMessageTransformer";
|
|
62
|
-
import { ProtobufSizeTransformer } from "./features/protobuf/ProtobufSizeTransformer";
|
|
63
61
|
import { ProtobufValidateDecodeTransformer } from "./features/protobuf/ProtobufValidateDecodeTransformer";
|
|
64
62
|
import { ProtobufValidateEncodeTransformer } from "./features/protobuf/ProtobufValidateEncodeTransformer";
|
|
65
63
|
|
|
@@ -188,7 +186,6 @@ const FUNCTORS: Record<string, Record<string, () => Task>> = {
|
|
|
188
186
|
message: () => ProtobufMessageTransformer.transform,
|
|
189
187
|
|
|
190
188
|
// ENCODE
|
|
191
|
-
size: () => ProtobufSizeTransformer.transform,
|
|
192
189
|
encode: () => ProtobufEncodeTransformer.transform,
|
|
193
190
|
assertEncode: () => ProtobufAssertEncodeTransformer.transform,
|
|
194
191
|
isEncode: () => ProtobufIsEncodeTransformer.transform,
|
|
@@ -201,7 +198,6 @@ const FUNCTORS: Record<string, Record<string, () => Task>> = {
|
|
|
201
198
|
validateDecode: () => ProtobufValidateDecodeTransformer.transform,
|
|
202
199
|
|
|
203
200
|
// FACTORIES
|
|
204
|
-
createSize: () => CreateProtobufSizeTransformer.transform,
|
|
205
201
|
createEncode: () => CreateProtobufEncodeTransformer.transform,
|
|
206
202
|
createAssertEncode: () =>
|
|
207
203
|
CreateProtobufAssertEncodeTransformer.transform,
|
|
@@ -56,6 +56,12 @@ export namespace JsonApplicationTransformer {
|
|
|
56
56
|
validate: (meta) => {
|
|
57
57
|
if (meta.atomics.find((str) => str === "bigint"))
|
|
58
58
|
throw new Error(NO_BIGIT);
|
|
59
|
+
else if (
|
|
60
|
+
meta.arrays.some(
|
|
61
|
+
(array) => array.value.isRequired() === false,
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
throw new Error(NO_UNDEFINED_IN_ARRAY);
|
|
59
65
|
},
|
|
60
66
|
})(collection)(type),
|
|
61
67
|
);
|
|
@@ -96,7 +102,10 @@ export namespace JsonApplicationTransformer {
|
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
const NO_GENERIC_ARGUMENT =
|
|
99
|
-
"Error on typia.application(): no generic argument.";
|
|
105
|
+
"Error on typia.json.application(): no generic argument.";
|
|
100
106
|
const GENERIC_ARGUMENT =
|
|
101
|
-
"Error on typia.application(): non-specified generic argument(s).";
|
|
102
|
-
const NO_BIGIT =
|
|
107
|
+
"Error on typia.json.application(): non-specified generic argument(s).";
|
|
108
|
+
const NO_BIGIT =
|
|
109
|
+
"Error on typia.json.application(): does not allow bigint type.";
|
|
110
|
+
const NO_UNDEFINED_IN_ARRAY =
|
|
111
|
+
"Error on typia.json.application(): does not allow undefined type in array.";
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { IProject } from "../../transformers/IProject";
|
|
3
|
-
export declare namespace ProtobufSizeProgrammer {
|
|
4
|
-
const write: (project: IProject) => (modulo: ts.LeftHandSideExpression) => (type: ts.Type, name?: string | undefined) => ts.ArrowFunction;
|
|
5
|
-
}
|
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.ProtobufSizeProgrammer = void 0;
|
|
43
|
-
var typescript_1 = __importDefault(require("typescript"));
|
|
44
|
-
var ExpressionFactory_1 = require("../../factories/ExpressionFactory");
|
|
45
|
-
var IdentifierFactory_1 = require("../../factories/IdentifierFactory");
|
|
46
|
-
var MetadataCollection_1 = require("../../factories/MetadataCollection");
|
|
47
|
-
var ProtobufFactory_1 = require("../../factories/ProtobufFactory");
|
|
48
|
-
var StatementFactory_1 = require("../../factories/StatementFactory");
|
|
49
|
-
var TypeFactory_1 = require("../../factories/TypeFactory");
|
|
50
|
-
var _strlen_1 = require("../../functional/$strlen");
|
|
51
|
-
var FeatureProgrammer_1 = require("../FeatureProgrammer");
|
|
52
|
-
var IsProgrammer_1 = require("../IsProgrammer");
|
|
53
|
-
var FunctionImporeter_1 = require("../helpers/FunctionImporeter");
|
|
54
|
-
var ProtobufUtil_1 = require("../helpers/ProtobufUtil");
|
|
55
|
-
var UnionExplorer_1 = require("../helpers/UnionExplorer");
|
|
56
|
-
var check_native_1 = require("../internal/check_native");
|
|
57
|
-
var decode_union_object_1 = require("../internal/decode_union_object");
|
|
58
|
-
var ProtobufSizeProgrammer;
|
|
59
|
-
(function (ProtobufSizeProgrammer) {
|
|
60
|
-
ProtobufSizeProgrammer.write = function (project) { return function (modulo) {
|
|
61
|
-
var importer = new FunctionImporeter_1.FunctionImporter();
|
|
62
|
-
var copnfig = configure(modulo.getText())(project)(importer);
|
|
63
|
-
return FeatureProgrammer_1.FeatureProgrammer.write(project)(__assign(__assign({}, copnfig), { addition: function (collection) { return __spreadArray(__spreadArray([], __read(IsProgrammer_1.IsProgrammer.write_function_statements(project)(importer)(collection)), false), __read(importer.declare(modulo)), false); } }))(importer);
|
|
64
|
-
}; };
|
|
65
|
-
var write_object_function_body = function (project) {
|
|
66
|
-
return function (config) {
|
|
67
|
-
return function (importer) {
|
|
68
|
-
return function (obj) {
|
|
69
|
-
var explore = {
|
|
70
|
-
tracable: false,
|
|
71
|
-
source: "function",
|
|
72
|
-
from: "object",
|
|
73
|
-
postfix: "",
|
|
74
|
-
};
|
|
75
|
-
if (obj.properties.some(function (p) { return !p.key.isSoleLiteral(); })) {
|
|
76
|
-
var p = obj.properties[0];
|
|
77
|
-
return write_map_function_body(project)(config)(importer)(typescript_1.default.factory.createIdentifier("input"), p, explore, p.tags);
|
|
78
|
-
}
|
|
79
|
-
var zero = typescript_1.default.factory.createNumericLiteral(0);
|
|
80
|
-
var compute = function (p) {
|
|
81
|
-
var input = IdentifierFactory_1.IdentifierFactory.access(typescript_1.default.factory.createIdentifier("input"))(p.key.getSoleLiteral());
|
|
82
|
-
var output = typescript_1.default.factory.createAdd(typescript_1.default.factory.createNumericLiteral(4), decode(project)(config)(importer)(input, p.value, explore, p.tags));
|
|
83
|
-
if (p.value.isRequired() === true && p.value.nullable === false)
|
|
84
|
-
return output;
|
|
85
|
-
else if (p.value.isRequired() === true &&
|
|
86
|
-
p.value.nullable === true)
|
|
87
|
-
return typescript_1.default.factory.createConditionalExpression(typescript_1.default.factory.createStrictInequality(typescript_1.default.factory.createNull(), input), undefined, output, undefined, zero);
|
|
88
|
-
else if (p.value.isRequired() === false &&
|
|
89
|
-
p.value.nullable === false)
|
|
90
|
-
return typescript_1.default.factory.createConditionalExpression(typescript_1.default.factory.createStrictInequality(typescript_1.default.factory.createIdentifier("undefined"), input), undefined, output, undefined, zero);
|
|
91
|
-
else
|
|
92
|
-
return typescript_1.default.factory.createConditionalExpression(typescript_1.default.factory.createLogicalAnd(typescript_1.default.factory.createStrictInequality(typescript_1.default.factory.createIdentifier("undefined"), input), typescript_1.default.factory.createStrictInequality(typescript_1.default.factory.createNull(), input)), undefined, output, undefined, zero);
|
|
93
|
-
};
|
|
94
|
-
return obj.properties
|
|
95
|
-
.map(function (p) { return compute(p); })
|
|
96
|
-
.reduce(function (a, b) { return typescript_1.default.factory.createAdd(a, b); });
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
var write_map_function_body = function (project) {
|
|
102
|
-
return function (config) {
|
|
103
|
-
return function (importer) {
|
|
104
|
-
return function (input, entry, explore, tags) {
|
|
105
|
-
var key = typescript_1.default.factory.createIdentifier("key");
|
|
106
|
-
var value = typescript_1.default.factory.createIdentifier("value");
|
|
107
|
-
var tuple = typescript_1.default.factory.createVariableDeclarationList([
|
|
108
|
-
typescript_1.default.factory.createVariableDeclaration(typescript_1.default.factory.createArrayBindingPattern([
|
|
109
|
-
typescript_1.default.factory.createBindingElement(undefined, undefined, key),
|
|
110
|
-
typescript_1.default.factory.createBindingElement(undefined, undefined, value),
|
|
111
|
-
])),
|
|
112
|
-
], typescript_1.default.NodeFlags.Const);
|
|
113
|
-
var block = typescript_1.default.factory.createBlock([
|
|
114
|
-
decode_atomic(importer)(key, "string", []),
|
|
115
|
-
decode(project)(config)(importer)(value, entry.value, explore, tags),
|
|
116
|
-
].map(function (expr) {
|
|
117
|
-
return typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createIdentifier("size"), typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.PlusEqualsToken), expr));
|
|
118
|
-
}), true);
|
|
119
|
-
return typescript_1.default.factory.createBlock([
|
|
120
|
-
StatementFactory_1.StatementFactory.mut("size", typescript_1.default.factory.createNumericLiteral(0)),
|
|
121
|
-
typescript_1.default.factory.createForOfStatement(undefined, tuple, input, block),
|
|
122
|
-
typescript_1.default.factory.createReturnStatement(typescript_1.default.factory.createIdentifier("size")),
|
|
123
|
-
]);
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
var decode = function (project) {
|
|
129
|
-
return function (config) {
|
|
130
|
-
return function (importer) {
|
|
131
|
-
return function (input, meta, explore, tags) {
|
|
132
|
-
var unions = ProtobufUtil_1.ProtobufUtil.atomics(meta).map(function (type) { return ({
|
|
133
|
-
type: type,
|
|
134
|
-
is: function () {
|
|
135
|
-
return typescript_1.default.factory.createStrictEquality(typescript_1.default.factory.createStringLiteral(type), typescript_1.default.factory.createTypeOfExpression(input));
|
|
136
|
-
},
|
|
137
|
-
value: function () { return decode_atomic(importer)(input, type, tags); },
|
|
138
|
-
}); });
|
|
139
|
-
if (meta.arrays.length) {
|
|
140
|
-
var value = meta.arrays.length === 1
|
|
141
|
-
? function () {
|
|
142
|
-
return decode_array(project)(config)(importer)(input, meta.arrays[0], explore, tags);
|
|
143
|
-
}
|
|
144
|
-
: function () {
|
|
145
|
-
return explore_arrays(project)(config)(importer)(input, meta.arrays, explore, tags);
|
|
146
|
-
};
|
|
147
|
-
unions.push({
|
|
148
|
-
type: "array",
|
|
149
|
-
is: function () { return ExpressionFactory_1.ExpressionFactory.isArray(input); },
|
|
150
|
-
value: value,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
if (meta.objects.length)
|
|
154
|
-
unions.push({
|
|
155
|
-
type: "object",
|
|
156
|
-
is: function () {
|
|
157
|
-
return ExpressionFactory_1.ExpressionFactory.isObject({
|
|
158
|
-
checkNull: true,
|
|
159
|
-
checkArray: false,
|
|
160
|
-
})(input);
|
|
161
|
-
},
|
|
162
|
-
value: function () {
|
|
163
|
-
return explore_objects(project)(config)(importer)(input, meta, explore);
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
if (meta.maps.length)
|
|
167
|
-
unions.push({
|
|
168
|
-
type: "map",
|
|
169
|
-
is: function () { return ExpressionFactory_1.ExpressionFactory.isInstanceOf("Map")(input); },
|
|
170
|
-
value: function () {
|
|
171
|
-
return decode_map(project)(config)(importer)(input, meta.maps[0], explore, tags);
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
if (meta.natives.length && meta.natives[0] === "Uint8Array")
|
|
175
|
-
unions.push({
|
|
176
|
-
type: "native",
|
|
177
|
-
is: function () { return (0, check_native_1.check_native)("Uint8Array")(input); },
|
|
178
|
-
value: function () { return decode_binary(input); },
|
|
179
|
-
});
|
|
180
|
-
return unions.length === 1
|
|
181
|
-
? unions[0].value()
|
|
182
|
-
: typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, undefined, iterate(importer, input, unions, meta.getName())), undefined, undefined);
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
var iterate = function (importer, input, unions, expected) {
|
|
188
|
-
return typescript_1.default.factory.createBlock(__spreadArray(__spreadArray([], __read(unions.map(function (u) {
|
|
189
|
-
return typescript_1.default.factory.createIfStatement(u.is(), typescript_1.default.factory.createReturnStatement(u.value()));
|
|
190
|
-
})), false), [
|
|
191
|
-
create_throw_error(importer)(expected)(input),
|
|
192
|
-
], false), true);
|
|
193
|
-
};
|
|
194
|
-
var decode_atomic = function (importer) {
|
|
195
|
-
return function (input, type, tags) {
|
|
196
|
-
return type === "string"
|
|
197
|
-
? typescript_1.default.factory.createAdd(typescript_1.default.factory.createNumericLiteral(4), typescript_1.default.factory.createCallExpression(importer.use("strlen"), undefined, [input]))
|
|
198
|
-
: typescript_1.default.factory.createNumericLiteral(computeAtomicLength(type)(tags));
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
var decode_array = function (project) {
|
|
202
|
-
return function (config) {
|
|
203
|
-
return function (importer) {
|
|
204
|
-
return function (input, array, explore, tags) {
|
|
205
|
-
var header = function (expr) {
|
|
206
|
-
return typescript_1.default.factory.createAdd(typescript_1.default.factory.createNumericLiteral(4), expr);
|
|
207
|
-
};
|
|
208
|
-
if (array.value.isBinaryUnion() === false) {
|
|
209
|
-
var length_1 = computeFixedLength(array.value)(tags);
|
|
210
|
-
if (length_1 !== null)
|
|
211
|
-
return header(typescript_1.default.factory.createMultiply(IdentifierFactory_1.IdentifierFactory.access(input)("length"), typescript_1.default.factory.createNumericLiteral(length_1)));
|
|
212
|
-
}
|
|
213
|
-
return header(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(input)("map"), undefined, [
|
|
214
|
-
typescript_1.default.factory.createArrowFunction(undefined, undefined, [IdentifierFactory_1.IdentifierFactory.parameter("elem")], undefined, undefined, decode(project)(config)(importer)(typescript_1.default.factory.createIdentifier("elem"), array.value, explore, tags)),
|
|
215
|
-
]), undefined, [
|
|
216
|
-
typescript_1.default.factory.createArrowFunction(undefined, undefined, [
|
|
217
|
-
IdentifierFactory_1.IdentifierFactory.parameter("a"),
|
|
218
|
-
IdentifierFactory_1.IdentifierFactory.parameter("b"),
|
|
219
|
-
], undefined, undefined, typescript_1.default.factory.createAdd(typescript_1.default.factory.createIdentifier("a"), typescript_1.default.factory.createIdentifier("b"))),
|
|
220
|
-
typescript_1.default.factory.createNumericLiteral(0),
|
|
221
|
-
]));
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
var decode_object = function (importer) {
|
|
227
|
-
return FeatureProgrammer_1.FeatureProgrammer.decode_object({
|
|
228
|
-
trace: false,
|
|
229
|
-
path: false,
|
|
230
|
-
prefix: PREFIX,
|
|
231
|
-
})(importer);
|
|
232
|
-
};
|
|
233
|
-
var decode_binary = function (input) {
|
|
234
|
-
return typescript_1.default.factory.createCallExpression(IdentifierFactory_1.IdentifierFactory.access(input)("writeBytes"), undefined, [input]);
|
|
235
|
-
};
|
|
236
|
-
var decode_map = function (project) {
|
|
237
|
-
return function (config) {
|
|
238
|
-
return function (importer) {
|
|
239
|
-
return function (input, entry, explore, tags) {
|
|
240
|
-
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createArrowFunction(undefined, undefined, [], TypeFactory_1.TypeFactory.keyword("any"), undefined, write_map_function_body(project)(config)(importer)(input, entry, explore, tags)), undefined, undefined);
|
|
241
|
-
};
|
|
242
|
-
};
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
var explore_objects = function (_project) {
|
|
246
|
-
return function (config) {
|
|
247
|
-
return function (importer) {
|
|
248
|
-
return function (input, meta, explore) {
|
|
249
|
-
return meta.objects.length === 1
|
|
250
|
-
? decode_object(importer)(input, meta.objects[0], explore)
|
|
251
|
-
: typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier(importer.useLocal("".concat(config.prefix, "u").concat(meta.union_index))), undefined, FeatureProgrammer_1.FeatureProgrammer.argumentsArray(config)(explore)(input));
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
};
|
|
255
|
-
};
|
|
256
|
-
var explore_arrays = function (project) {
|
|
257
|
-
return function (config) {
|
|
258
|
-
return function (importer) {
|
|
259
|
-
return function (input, elements, explore, tags) {
|
|
260
|
-
return explore_array_like_union_types(config)(importer)(UnionExplorer_1.UnionExplorer.array({
|
|
261
|
-
checker: IsProgrammer_1.IsProgrammer.decode(project)(importer),
|
|
262
|
-
decoder: decode_array(project)(config)(importer),
|
|
263
|
-
empty: typescript_1.default.factory.createStringLiteral("[]"),
|
|
264
|
-
success: typescript_1.default.factory.createTrue(),
|
|
265
|
-
failure: function (input, expected) {
|
|
266
|
-
return create_throw_error(importer)(expected)(input);
|
|
267
|
-
},
|
|
268
|
-
}))(input, elements, explore, tags);
|
|
269
|
-
};
|
|
270
|
-
};
|
|
271
|
-
};
|
|
272
|
-
};
|
|
273
|
-
var explore_array_like_union_types = function (config) {
|
|
274
|
-
return function (importer) {
|
|
275
|
-
return function (factory) {
|
|
276
|
-
return function (input, elements, explore, tags) {
|
|
277
|
-
var arrow = function (parameters) {
|
|
278
|
-
return function (explore) {
|
|
279
|
-
return function (input) {
|
|
280
|
-
return factory(parameters)(input, elements, explore, tags, []);
|
|
281
|
-
};
|
|
282
|
-
};
|
|
283
|
-
};
|
|
284
|
-
if (elements.every(function (e) { return e.recursive === false; }))
|
|
285
|
-
typescript_1.default.factory.createCallExpression(arrow([])(explore)(input), undefined, []);
|
|
286
|
-
explore = __assign(__assign({}, explore), { source: "function", from: "array" });
|
|
287
|
-
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier(importer.emplaceUnion(config.prefix, elements.map(function (e) { return e.name; }).join(" | "), function () {
|
|
288
|
-
return arrow(FeatureProgrammer_1.FeatureProgrammer.parameterDeclarations(config)(TypeFactory_1.TypeFactory.keyword("any"))(typescript_1.default.factory.createIdentifier("input")))(__assign(__assign({}, explore), { postfix: "" }))(typescript_1.default.factory.createIdentifier("input"));
|
|
289
|
-
})), undefined, FeatureProgrammer_1.FeatureProgrammer.argumentsArray(config)(explore)(input));
|
|
290
|
-
};
|
|
291
|
-
};
|
|
292
|
-
};
|
|
293
|
-
};
|
|
294
|
-
var PREFIX = "$ps";
|
|
295
|
-
var configure = function (method) {
|
|
296
|
-
return function (project) {
|
|
297
|
-
return function (importer) {
|
|
298
|
-
var config = {
|
|
299
|
-
types: {
|
|
300
|
-
input: function (type, name) {
|
|
301
|
-
return typescript_1.default.factory.createTypeReferenceNode(name !== null && name !== void 0 ? name : TypeFactory_1.TypeFactory.getFullName(project.checker)(type));
|
|
302
|
-
},
|
|
303
|
-
output: function (type, name) {
|
|
304
|
-
return typescript_1.default.factory.createTypeReferenceNode("typia.Primitive<".concat(name !== null && name !== void 0 ? name : TypeFactory_1.TypeFactory.getFullName(project.checker)(type), ">"));
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
prefix: PREFIX,
|
|
308
|
-
trace: false,
|
|
309
|
-
path: false,
|
|
310
|
-
initializer: initializer(method),
|
|
311
|
-
decoder: function () { return decode(project)(config)(importer); },
|
|
312
|
-
objector: {
|
|
313
|
-
checker: function () { return IsProgrammer_1.IsProgrammer.decode(project)(importer); },
|
|
314
|
-
decoder: function () { return decode_object(importer); },
|
|
315
|
-
joiner: function (_input, _entries, obj) {
|
|
316
|
-
return write_object_function_body(project)(config)(importer)(obj);
|
|
317
|
-
},
|
|
318
|
-
unionizer: (0, decode_union_object_1.decode_union_object)(IsProgrammer_1.IsProgrammer.decode_object(importer))(decode_object(importer))(function (exp) { return exp; })(function (input, expected) {
|
|
319
|
-
return create_throw_error(importer)(expected)(input);
|
|
320
|
-
}),
|
|
321
|
-
failure: function (input, expected) {
|
|
322
|
-
return create_throw_error(importer)(expected)(input);
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
generator: {
|
|
326
|
-
arrays: function () { return function () { return []; }; },
|
|
327
|
-
tuples: function () { return function () { return []; }; },
|
|
328
|
-
},
|
|
329
|
-
};
|
|
330
|
-
return config;
|
|
331
|
-
};
|
|
332
|
-
};
|
|
333
|
-
};
|
|
334
|
-
var initializer = function (method) {
|
|
335
|
-
return function (_a) {
|
|
336
|
-
var checker = _a.checker;
|
|
337
|
-
return function (type) {
|
|
338
|
-
var collection = new MetadataCollection_1.MetadataCollection();
|
|
339
|
-
var meta = ProtobufFactory_1.ProtobufFactory.metadata(method)(checker)(collection)(type);
|
|
340
|
-
return [collection, meta];
|
|
341
|
-
};
|
|
342
|
-
};
|
|
343
|
-
};
|
|
344
|
-
var create_throw_error = function (importer) {
|
|
345
|
-
return function (expected) {
|
|
346
|
-
return function (value) {
|
|
347
|
-
return typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createCallExpression(importer.use("throws"), [], [
|
|
348
|
-
typescript_1.default.factory.createObjectLiteralExpression([
|
|
349
|
-
typescript_1.default.factory.createPropertyAssignment("expected", typescript_1.default.factory.createStringLiteral(expected)),
|
|
350
|
-
typescript_1.default.factory.createPropertyAssignment("value", value),
|
|
351
|
-
], true),
|
|
352
|
-
]));
|
|
353
|
-
};
|
|
354
|
-
};
|
|
355
|
-
};
|
|
356
|
-
})(ProtobufSizeProgrammer || (exports.ProtobufSizeProgrammer = ProtobufSizeProgrammer = {}));
|
|
357
|
-
var computeFixedLength = function (meta) {
|
|
358
|
-
return function (tags) {
|
|
359
|
-
if (meta.fixed_ !== undefined)
|
|
360
|
-
return meta.fixed_;
|
|
361
|
-
return (meta.fixed_ = (function () {
|
|
362
|
-
if (meta.isRequired() === false ||
|
|
363
|
-
meta.nullable ||
|
|
364
|
-
meta.natives.length ||
|
|
365
|
-
meta.maps.length ||
|
|
366
|
-
meta.isBinaryUnion())
|
|
367
|
-
return null;
|
|
368
|
-
else if (meta.arrays.length)
|
|
369
|
-
return computeFixedLength(meta.arrays[0].value)(tags);
|
|
370
|
-
var atomics = new Set(__spreadArray(__spreadArray(__spreadArray([], __read(meta.atomics), false), __read(meta.constants.map(function (c) { return c.type; })), false), __read(meta.templates.map(function () { return "string"; })), false));
|
|
371
|
-
if (atomics.size)
|
|
372
|
-
return computeAtomicLength(Array.from(atomics)[0])(tags);
|
|
373
|
-
else if (meta.objects.length) {
|
|
374
|
-
var obj = meta.objects[0];
|
|
375
|
-
if (obj.properties.some(function (p) { return !p.key.isSoleLiteral(); }))
|
|
376
|
-
return null;
|
|
377
|
-
else if (obj.properties.some(function (p) { return computeFixedLength(p.value)(p.tags) === null; }))
|
|
378
|
-
return null;
|
|
379
|
-
return obj.properties
|
|
380
|
-
.map(function (p) {
|
|
381
|
-
return (0, _strlen_1.$strlen)(p.key.getSoleLiteral()) +
|
|
382
|
-
computeFixedLength(p.value)(p.tags);
|
|
383
|
-
})
|
|
384
|
-
.reduce(function (a, b) { return a + b; }, 0);
|
|
385
|
-
}
|
|
386
|
-
return null;
|
|
387
|
-
})());
|
|
388
|
-
};
|
|
389
|
-
};
|
|
390
|
-
var computeAtomicLength = function (type) {
|
|
391
|
-
return function (tags) {
|
|
392
|
-
if (type === "string")
|
|
393
|
-
return null;
|
|
394
|
-
else if (type === "boolean")
|
|
395
|
-
return 1;
|
|
396
|
-
else if (type === "bigint")
|
|
397
|
-
return 8;
|
|
398
|
-
var shorter = tags.find(function (tag) { return tag.kind === "type"; });
|
|
399
|
-
return shorter &&
|
|
400
|
-
(shorter.value === "int" ||
|
|
401
|
-
shorter.value === "uint" ||
|
|
402
|
-
shorter.value === "int32" ||
|
|
403
|
-
shorter.value === "uint32" ||
|
|
404
|
-
shorter.value === "float")
|
|
405
|
-
? 4
|
|
406
|
-
: 8;
|
|
407
|
-
};
|
|
408
|
-
};
|
|
409
|
-
//# sourceMappingURL=ProtobufSizeProgrammer.js.map
|