typia 3.8.4 → 4.0.0-dev.20230502
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/README.md +9 -1
- package/lib/factories/ProtocolFactory.d.ts +8 -0
- package/lib/factories/ProtocolFactory.js +112 -0
- package/lib/factories/ProtocolFactory.js.map +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +16 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +160 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
- package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
- package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
- package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
- package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js +75 -0
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +190 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
- package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_never.js +6 -0
- package/lib/factories/internal/protocols/iterate_protocol_never.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +4 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.js +157 -0
- package/lib/factories/internal/protocols/iterate_protocol_object.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +5 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +25 -0
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
- package/lib/functional/$proto_bytes.d.ts +2 -0
- package/lib/functional/$proto_bytes.js +37 -0
- package/lib/functional/$proto_bytes.js.map +1 -0
- package/lib/functional/$proto_field.d.ts +10 -0
- package/lib/functional/$proto_field.js +42 -0
- package/lib/functional/$proto_field.js.map +1 -0
- package/lib/functional/$proto_float.d.ts +4 -0
- package/lib/functional/$proto_float.js +28 -0
- package/lib/functional/$proto_float.js.map +1 -0
- package/lib/functional/$proto_i32.d.ts +2 -0
- package/lib/functional/$proto_i32.js +23 -0
- package/lib/functional/$proto_i32.js.map +1 -0
- package/lib/functional/$proto_i64.d.ts +2 -0
- package/lib/functional/$proto_i64.js +31 -0
- package/lib/functional/$proto_i64.js.map +1 -0
- package/lib/functional/$proto_size.d.ts +6 -0
- package/lib/functional/$proto_size.js +76 -0
- package/lib/functional/$proto_size.js.map +1 -0
- package/lib/functional/$proto_string.d.ts +2 -0
- package/lib/functional/$proto_string.js +34 -0
- package/lib/functional/$proto_string.js.map +1 -0
- package/lib/functional/$varint.d.ts +6 -0
- package/lib/functional/$varint.js +99 -0
- package/lib/functional/$varint.js.map +1 -0
- package/lib/functional/$zigzag.d.ts +4 -0
- package/lib/functional/$zigzag.js +34 -0
- package/lib/functional/$zigzag.js.map +1 -0
- package/lib/messages/IProtocolMap.d.ts +5 -0
- package/lib/messages/IProtocolMap.js +3 -0
- package/lib/messages/IProtocolMap.js.map +1 -0
- package/lib/messages/IProtocolMessage.d.ts +5 -0
- package/lib/messages/IProtocolMessage.js +3 -0
- package/lib/messages/IProtocolMessage.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +12 -0
- package/lib/messages/IProtocolProperty.js +3 -0
- package/lib/messages/IProtocolProperty.js.map +1 -0
- package/lib/metadata/IMetadataTag.d.ts +3 -3
- package/lib/metadata/Metadata.js +1 -1
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +6 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/MessageProgrammer.d.ts +5 -0
- package/lib/programmers/MessageProgrammer.js +141 -0
- package/lib/programmers/MessageProgrammer.js.map +1 -0
- package/lib/transformers/CallExpressionTransformer.js +5 -3
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
- package/lib/transformers/features/protocols/MessageTransformer.js +20 -0
- package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +1 -1
- package/src/Primitive.ts +123 -123
- package/src/factories/MetadataFactory.ts +62 -62
- package/src/factories/ProtocolFactory.ts +79 -0
- package/src/factories/internal/metadata/emplace_metadata_object.ts +143 -143
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +48 -48
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +167 -0
- package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
- package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
- package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
- package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +58 -0
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +96 -0
- package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_never.ts +1 -0
- package/src/factories/internal/protocols/iterate_protocol_object.ts +110 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +34 -0
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +29 -0
- package/src/functional/$proto_bytes.ts +25 -0
- package/src/functional/$proto_field.ts +30 -0
- package/src/functional/$proto_float.ts +37 -0
- package/src/functional/$proto_i32.ts +29 -0
- package/src/functional/$proto_i64.ts +37 -0
- package/src/functional/$proto_size.ts +82 -0
- package/src/functional/$proto_string.ts +24 -0
- package/src/functional/$varint.ts +130 -0
- package/src/functional/$zigzag.ts +39 -0
- package/src/messages/IProtocolMap.ts +5 -0
- package/src/messages/IProtocolMessage.ts +6 -0
- package/src/messages/IProtocolProperty.ts +13 -0
- package/src/metadata/IMetadata.ts +26 -26
- package/src/metadata/IMetadataTag.ts +11 -3
- package/src/metadata/Metadata.ts +543 -539
- package/src/module.ts +11 -0
- package/src/programmers/CheckerProgrammer.ts +901 -901
- package/src/programmers/MessageProgrammer.ts +126 -0
- package/src/programmers/internal/application_object.ts +155 -155
- package/src/programmers/internal/application_tuple.ts +31 -31
- package/src/schemas/IJsonSchema.ts +130 -130
- package/src/transformers/CallExpressionTransformer.ts +17 -10
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -3
- package/src/transformers/features/protocols/MessageTransformer.ts +31 -0
- package/src/utils/NameEncoder.ts +32 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
function EncodeVarNumber(
|
|
2
|
+
dst: Uint8Array,
|
|
3
|
+
offset: number,
|
|
4
|
+
value: number,
|
|
5
|
+
): number {
|
|
6
|
+
value = (value | 0) >>> 0; // 32-bit integer
|
|
7
|
+
|
|
8
|
+
while (value > 127) {
|
|
9
|
+
dst[offset++] = (value & 0b01111111) | 0b10000000;
|
|
10
|
+
value >>>= 7;
|
|
11
|
+
}
|
|
12
|
+
dst[offset++] = value;
|
|
13
|
+
|
|
14
|
+
return offset;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function DecodeVarNumber(
|
|
18
|
+
buf: Uint8Array,
|
|
19
|
+
offset: number,
|
|
20
|
+
): [value: number, offset: number] {
|
|
21
|
+
let value = 0;
|
|
22
|
+
let shift = 0;
|
|
23
|
+
|
|
24
|
+
while (true) {
|
|
25
|
+
const byte = buf[offset++]!;
|
|
26
|
+
value |= (byte & 0b01111111) << shift;
|
|
27
|
+
if (byte < 128) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
shift += 7;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return [value | 0, offset];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function DecodeVarBigInt(
|
|
37
|
+
buf: Uint8Array,
|
|
38
|
+
offset: number,
|
|
39
|
+
): [value: bigint, offset: number] {
|
|
40
|
+
let value = BigInt(0);
|
|
41
|
+
let shift = BigInt(0);
|
|
42
|
+
|
|
43
|
+
while (true) {
|
|
44
|
+
const byte = buf[offset++]!;
|
|
45
|
+
value |= BigInt(byte & 0b01111111) << shift;
|
|
46
|
+
if (byte < 128) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
shift += BigInt(7);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return [BigInt.asIntN(64, value), offset];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function $varint_decode_i32(
|
|
56
|
+
buf: Uint8Array,
|
|
57
|
+
offset: number,
|
|
58
|
+
): [value: number, offset: number] {
|
|
59
|
+
const [v, o] = DecodeVarNumber(buf, offset);
|
|
60
|
+
return [v, o];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function $varint_decode_u32(
|
|
64
|
+
buf: Uint8Array,
|
|
65
|
+
offset: number,
|
|
66
|
+
): [value: number, offset: number] {
|
|
67
|
+
const [v, o] = DecodeVarNumber(buf, offset);
|
|
68
|
+
return [v >>> 0, o];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function $varint_decode_i64(
|
|
72
|
+
buf: Uint8Array,
|
|
73
|
+
offset: number,
|
|
74
|
+
): [value: bigint, offset: number] {
|
|
75
|
+
const [v, o] = DecodeVarBigInt(buf, offset);
|
|
76
|
+
return [v, o];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function $varint_decode_u64(
|
|
80
|
+
buf: Uint8Array,
|
|
81
|
+
offset: number,
|
|
82
|
+
): [value: bigint, offset: number] {
|
|
83
|
+
const [v, o] = DecodeVarBigInt(buf, offset);
|
|
84
|
+
return [BigInt.asUintN(64, v), o];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function EncodeVarBigInt(
|
|
88
|
+
dst: Uint8Array,
|
|
89
|
+
offset: number,
|
|
90
|
+
value: bigint,
|
|
91
|
+
): number {
|
|
92
|
+
value = BigInt.asUintN(64, value);
|
|
93
|
+
|
|
94
|
+
while (value > BigInt(127)) {
|
|
95
|
+
dst[offset++] = Number(value & BigInt(0b01111111)) | 0b10000000;
|
|
96
|
+
value >>= BigInt(7);
|
|
97
|
+
}
|
|
98
|
+
dst[offset++] = Number(value);
|
|
99
|
+
|
|
100
|
+
return offset;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function $varint_encode(
|
|
104
|
+
dst: Uint8Array,
|
|
105
|
+
offset: number,
|
|
106
|
+
value: number,
|
|
107
|
+
): number;
|
|
108
|
+
export function $varint_encode(
|
|
109
|
+
dst: Uint8Array,
|
|
110
|
+
offset: number,
|
|
111
|
+
value: bigint,
|
|
112
|
+
): number;
|
|
113
|
+
|
|
114
|
+
export function $varint_encode(
|
|
115
|
+
dst: Uint8Array,
|
|
116
|
+
offset: number,
|
|
117
|
+
value: number | bigint,
|
|
118
|
+
): number {
|
|
119
|
+
if (typeof value === "bigint") {
|
|
120
|
+
offset = EncodeVarBigInt(dst, offset, value);
|
|
121
|
+
} else {
|
|
122
|
+
if (value < 0) {
|
|
123
|
+
// NOTE: Protocol Buffers signed varint encoding uses two's complement of 64-bit unsigned integers.
|
|
124
|
+
offset = EncodeVarBigInt(dst, offset, BigInt(value));
|
|
125
|
+
} else {
|
|
126
|
+
offset = EncodeVarNumber(dst, offset, value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return offset;
|
|
130
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function $zigzag_encode(value: number): number;
|
|
2
|
+
export function $zigzag_encode(value: bigint): bigint;
|
|
3
|
+
export function $zigzag_encode(value: number | bigint): any {
|
|
4
|
+
// TODO: optimize (branchless solution exists)
|
|
5
|
+
|
|
6
|
+
if (typeof value === "bigint") {
|
|
7
|
+
if (value < BigInt(0)) {
|
|
8
|
+
value = -value;
|
|
9
|
+
return value * BigInt(2) - BigInt(1);
|
|
10
|
+
}
|
|
11
|
+
return value * BigInt(2);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (value < 0) {
|
|
15
|
+
value = -value;
|
|
16
|
+
return value * 2 - 1;
|
|
17
|
+
}
|
|
18
|
+
return value * 2;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function $zigzag_decode(value: number): number;
|
|
22
|
+
export function $zigzag_decode(value: bigint): bigint;
|
|
23
|
+
export function $zigzag_decode(value: number | bigint): any {
|
|
24
|
+
// TODO: optimize (branchless solution exists)
|
|
25
|
+
|
|
26
|
+
if (typeof value === "bigint") {
|
|
27
|
+
value = BigInt.asUintN(64, value);
|
|
28
|
+
if (value & BigInt(1)) {
|
|
29
|
+
return -(value + BigInt(1)) / BigInt(2);
|
|
30
|
+
}
|
|
31
|
+
return value / BigInt(2);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
value = value >>> 0;
|
|
35
|
+
if (value & 1) {
|
|
36
|
+
return -(value + 1) / 2;
|
|
37
|
+
}
|
|
38
|
+
return value / 2;
|
|
39
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IProtocolMap } from "./IProtocolMap";
|
|
2
|
+
|
|
3
|
+
export interface IProtocolProperty {
|
|
4
|
+
key: string;
|
|
5
|
+
oneOf: IProtocolProperty.IOneOf[];
|
|
6
|
+
required: boolean;
|
|
7
|
+
repeated: boolean;
|
|
8
|
+
}
|
|
9
|
+
export namespace IProtocolProperty {
|
|
10
|
+
export interface IOneOf {
|
|
11
|
+
type: string | IProtocolMap;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { Atomic } from "../typings/Atomic";
|
|
2
|
-
|
|
3
|
-
import { IMetadataConstant } from "./IMetadataConstant";
|
|
4
|
-
import { IMetadataEntry } from "./IMetadataEntry";
|
|
5
|
-
|
|
6
|
-
export interface IMetadata {
|
|
7
|
-
any: boolean;
|
|
8
|
-
required: boolean;
|
|
9
|
-
optional: boolean;
|
|
10
|
-
nullable: boolean;
|
|
11
|
-
functional: boolean;
|
|
12
|
-
|
|
13
|
-
atomics: Atomic.Literal[];
|
|
14
|
-
constants: IMetadataConstant[];
|
|
15
|
-
templates: IMetadata[][];
|
|
16
|
-
resolved: IMetadata | null;
|
|
17
|
-
|
|
18
|
-
rest: IMetadata | null;
|
|
19
|
-
arrays: IMetadata[];
|
|
20
|
-
tuples: IMetadata[][];
|
|
21
|
-
objects: string[];
|
|
22
|
-
|
|
23
|
-
natives: string[];
|
|
24
|
-
sets: IMetadata[];
|
|
25
|
-
maps: IMetadataEntry[];
|
|
26
|
-
}
|
|
1
|
+
import { Atomic } from "../typings/Atomic";
|
|
2
|
+
|
|
3
|
+
import { IMetadataConstant } from "./IMetadataConstant";
|
|
4
|
+
import { IMetadataEntry } from "./IMetadataEntry";
|
|
5
|
+
|
|
6
|
+
export interface IMetadata {
|
|
7
|
+
any: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
optional: boolean;
|
|
10
|
+
nullable: boolean;
|
|
11
|
+
functional: boolean;
|
|
12
|
+
|
|
13
|
+
atomics: Atomic.Literal[];
|
|
14
|
+
constants: IMetadataConstant[];
|
|
15
|
+
templates: IMetadata[][];
|
|
16
|
+
resolved: IMetadata | null;
|
|
17
|
+
|
|
18
|
+
rest: IMetadata | null;
|
|
19
|
+
arrays: IMetadata[];
|
|
20
|
+
tuples: IMetadata[][];
|
|
21
|
+
objects: string[];
|
|
22
|
+
|
|
23
|
+
natives: string[];
|
|
24
|
+
sets: IMetadata[];
|
|
25
|
+
maps: IMetadataEntry[];
|
|
26
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type IMetadataTag =
|
|
2
2
|
// NUMBER
|
|
3
|
-
| IMetadataTag.
|
|
3
|
+
| IMetadataTag.INumberType
|
|
4
4
|
| IMetadataTag.IMinimum
|
|
5
5
|
| IMetadataTag.IMaximum
|
|
6
6
|
| IMetadataTag.IExclusiveMinimum
|
|
@@ -22,9 +22,17 @@ export namespace IMetadataTag {
|
|
|
22
22
|
/* -----------------------------------------------------------
|
|
23
23
|
NUMBER
|
|
24
24
|
----------------------------------------------------------- */
|
|
25
|
-
export interface
|
|
25
|
+
export interface INumberType {
|
|
26
26
|
kind: "type";
|
|
27
|
-
value:
|
|
27
|
+
value:
|
|
28
|
+
| "int"
|
|
29
|
+
| "uint"
|
|
30
|
+
| "int32"
|
|
31
|
+
| "uint32"
|
|
32
|
+
| "int64"
|
|
33
|
+
| "uint64"
|
|
34
|
+
| "float"
|
|
35
|
+
| "double";
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
export interface IMinimum {
|