@bufbuild/protobuf 0.0.1-alpha.1 → 0.0.2-alpha.2
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/dist/cjs/binary-encoding.js +414 -409
- package/dist/cjs/binary-format.js +13 -0
- package/dist/cjs/descriptor-registry.js +420 -449
- package/dist/cjs/descriptor-set.js +429 -513
- package/dist/cjs/enum.js +13 -0
- package/dist/cjs/field-list.js +13 -0
- package/dist/cjs/field.js +43 -30
- package/dist/cjs/google/protobuf/any_pb.js +122 -140
- package/dist/cjs/google/protobuf/api_pb.js +177 -224
- package/dist/cjs/google/protobuf/compiler/plugin_pb.js +125 -227
- package/dist/cjs/google/protobuf/descriptor_pb.js +1029 -1888
- package/dist/cjs/google/protobuf/duration_pb.js +72 -88
- package/dist/cjs/google/protobuf/empty_pb.js +17 -17
- package/dist/cjs/google/protobuf/field_mask_pb.js +77 -94
- package/dist/cjs/google/protobuf/source_context_pb.js +25 -25
- package/dist/cjs/google/protobuf/struct_pb.js +144 -181
- package/dist/cjs/google/protobuf/timestamp_pb.js +86 -123
- package/dist/cjs/google/protobuf/type_pb.js +406 -462
- package/dist/cjs/google/protobuf/wrappers_pb.js +407 -470
- package/dist/cjs/google/varint.js +166 -171
- package/dist/cjs/index.js +41 -122
- package/dist/cjs/json-format.js +13 -0
- package/dist/cjs/message-type.js +13 -0
- package/dist/cjs/message.js +89 -85
- package/dist/cjs/private/assert.js +33 -26
- package/dist/cjs/private/base64.js +93 -79
- package/dist/cjs/private/binary-format-common.js +208 -208
- package/dist/cjs/private/binary-format-proto2.js +88 -109
- package/dist/cjs/private/binary-format-proto3.js +70 -90
- package/dist/cjs/private/enum.js +77 -44
- package/dist/cjs/private/field-list.js +64 -50
- package/dist/cjs/private/field-wrapper.js +21 -10
- package/dist/cjs/private/field.js +35 -25
- package/dist/cjs/private/json-format-common.js +427 -440
- package/dist/cjs/private/json-format-proto2.js +91 -89
- package/dist/cjs/private/json-format-proto3.js +82 -93
- package/dist/cjs/private/message-type.js +39 -27
- package/dist/cjs/private/names.js +71 -62
- package/dist/cjs/private/options-map.js +13 -0
- package/dist/cjs/private/proto-runtime.js +25 -16
- package/dist/cjs/private/scalars.js +113 -103
- package/dist/cjs/private/util-common.js +193 -210
- package/dist/cjs/private/util.js +13 -0
- package/dist/cjs/proto-int64.js +123 -111
- package/dist/cjs/proto2.js +63 -63
- package/dist/cjs/proto3.js +74 -74
- package/dist/cjs/service-type.js +27 -17
- package/dist/cjs/type-registry.js +46 -31
- package/dist/esm/binary-encoding.js +414 -414
- package/dist/esm/binary-format.js +13 -0
- package/dist/esm/descriptor-registry.js +422 -458
- package/dist/esm/descriptor-set.js +430 -478
- package/dist/esm/enum.js +13 -0
- package/dist/esm/field-list.js +13 -0
- package/dist/esm/field.js +42 -29
- package/dist/esm/google/protobuf/any_pb.js +122 -140
- package/dist/esm/google/protobuf/api_pb.js +177 -197
- package/dist/esm/google/protobuf/compiler/plugin_pb.js +123 -216
- package/dist/esm/google/protobuf/descriptor_pb.js +1013 -1804
- package/dist/esm/google/protobuf/duration_pb.js +72 -88
- package/dist/esm/google/protobuf/empty_pb.js +17 -17
- package/dist/esm/google/protobuf/field_mask_pb.js +77 -94
- package/dist/esm/google/protobuf/source_context_pb.js +25 -25
- package/dist/esm/google/protobuf/struct_pb.js +143 -180
- package/dist/esm/google/protobuf/timestamp_pb.js +86 -123
- package/dist/esm/google/protobuf/type_pb.js +401 -421
- package/dist/esm/google/protobuf/wrappers_pb.js +406 -397
- package/dist/esm/google/varint.js +165 -164
- package/dist/esm/index.js +14 -1
- package/dist/esm/json-format.js +13 -0
- package/dist/esm/message-type.js +13 -0
- package/dist/esm/message.js +89 -85
- package/dist/esm/private/assert.js +32 -21
- package/dist/esm/private/base64.js +92 -78
- package/dist/esm/private/binary-format-common.js +209 -207
- package/dist/esm/private/binary-format-proto2.js +89 -81
- package/dist/esm/private/binary-format-proto3.js +71 -67
- package/dist/esm/private/enum.js +75 -43
- package/dist/esm/private/field-list.js +64 -50
- package/dist/esm/private/field-wrapper.js +21 -10
- package/dist/esm/private/field.js +35 -22
- package/dist/esm/private/json-format-common.js +427 -435
- package/dist/esm/private/json-format-proto2.js +89 -81
- package/dist/esm/private/json-format-proto3.js +79 -80
- package/dist/esm/private/message-type.js +40 -28
- package/dist/esm/private/names.js +70 -57
- package/dist/esm/private/options-map.js +13 -0
- package/dist/esm/private/proto-runtime.js +26 -12
- package/dist/esm/private/scalars.js +112 -99
- package/dist/esm/private/util-common.js +193 -192
- package/dist/esm/private/util.js +13 -0
- package/dist/esm/proto-int64.js +123 -111
- package/dist/esm/proto2.js +63 -57
- package/dist/esm/proto3.js +74 -68
- package/dist/esm/service-type.js +25 -12
- package/dist/esm/type-registry.js +46 -31
- package/dist/types/binary-encoding.d.ts +398 -398
- package/dist/types/binary-format.d.ts +69 -91
- package/dist/types/descriptor-registry.d.ts +23 -29
- package/dist/types/descriptor-set.d.ts +107 -128
- package/dist/types/enum.d.ts +21 -21
- package/dist/types/field-list.d.ts +21 -21
- package/dist/types/field.d.ts +191 -231
- package/dist/types/google/protobuf/any_pb.d.ts +56 -77
- package/dist/types/google/protobuf/api_pb.d.ts +144 -187
- package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +195 -257
- package/dist/types/google/protobuf/descriptor_pb.d.ts +1360 -1737
- package/dist/types/google/protobuf/duration_pb.d.ts +30 -50
- package/dist/types/google/protobuf/empty_pb.d.ts +9 -28
- package/dist/types/google/protobuf/field_mask_pb.d.ts +17 -37
- package/dist/types/google/protobuf/source_context_pb.d.ts +16 -35
- package/dist/types/google/protobuf/struct_pb.d.ts +64 -115
- package/dist/types/google/protobuf/timestamp_pb.d.ts +31 -51
- package/dist/types/google/protobuf/type_pb.d.ts +355 -422
- package/dist/types/google/protobuf/wrappers_pb.d.ts +181 -297
- package/dist/types/google/varint.d.ts +6 -13
- package/dist/types/index.d.ts +4 -27
- package/dist/types/json-format.d.ts +70 -89
- package/dist/types/message-type.d.ts +37 -45
- package/dist/types/message.d.ts +62 -87
- package/dist/types/private/assert.d.ts +1 -4
- package/dist/types/private/binary-format-common.d.ts +6 -32
- package/dist/types/private/enum.d.ts +13 -11
- package/dist/types/private/field-list.d.ts +14 -21
- package/dist/types/private/field-wrapper.d.ts +4 -10
- package/dist/types/private/field.d.ts +12 -12
- package/dist/types/private/json-format-common.d.ts +5 -27
- package/dist/types/private/message-type.d.ts +12 -7
- package/dist/types/private/names.d.ts +1 -4
- package/dist/types/private/options-map.d.ts +1 -1
- package/dist/types/private/proto-runtime.d.ts +34 -42
- package/dist/types/private/scalars.d.ts +5 -12
- package/dist/types/private/util-common.d.ts +1 -4
- package/dist/types/private/util.d.ts +29 -41
- package/dist/types/proto-int64.d.ts +42 -42
- package/dist/types/service-type.d.ts +36 -56
- package/dist/types/type-registry.d.ts +13 -15
- package/package.json +2 -3
|
@@ -1,41 +1,52 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
/**
|
|
2
15
|
* Assert that condition is truthy or throw error (with message)
|
|
3
16
|
*/
|
|
4
17
|
export function assert(condition, msg) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
|
|
19
|
+
if (!condition) {
|
|
20
|
+
throw new Error(msg);
|
|
21
|
+
}
|
|
9
22
|
}
|
|
10
|
-
const FLOAT32_MAX = 3.4028234663852886e38,
|
|
11
|
-
FLOAT32_MIN = -3.4028234663852886e38,
|
|
12
|
-
UINT32_MAX = 0xffffffff,
|
|
13
|
-
INT32_MAX = 0x7fffffff,
|
|
14
|
-
INT32_MIN = -0x80000000;
|
|
23
|
+
const FLOAT32_MAX = 3.4028234663852886e38, FLOAT32_MIN = -3.4028234663852886e38, UINT32_MAX = 0xffffffff, INT32_MAX = 0x7fffffff, INT32_MIN = -0x80000000;
|
|
15
24
|
/**
|
|
16
25
|
* Assert a valid signed protobuf 32-bit integer.
|
|
17
26
|
*/
|
|
18
27
|
export function assertInt32(arg) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
if (typeof arg !== "number")
|
|
29
|
+
throw new Error("invalid int 32: " + typeof arg);
|
|
30
|
+
if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
|
|
31
|
+
throw new Error("invalid int 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
|
|
22
32
|
}
|
|
23
33
|
/**
|
|
24
34
|
* Assert a valid unsigned protobuf 32-bit integer.
|
|
25
35
|
*/
|
|
26
36
|
export function assertUInt32(arg) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
if (typeof arg !== "number")
|
|
38
|
+
throw new Error("invalid uint 32: " + typeof arg);
|
|
39
|
+
if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
|
|
40
|
+
throw new Error("invalid uint 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
|
|
31
41
|
}
|
|
32
42
|
/**
|
|
33
43
|
* Assert a valid protobuf float value.
|
|
34
44
|
*/
|
|
35
45
|
export function assertFloat32(arg) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
if (typeof arg !== "number")
|
|
47
|
+
throw new Error("invalid float 32: " + typeof arg);
|
|
48
|
+
if (!Number.isFinite(arg))
|
|
49
|
+
return;
|
|
50
|
+
if (arg > FLOAT32_MAX || arg < FLOAT32_MIN)
|
|
51
|
+
throw new Error("invalid float 32: " + arg); // eslint-disable-line @typescript-eslint/restrict-plus-operands -- we want the implicit conversion to string
|
|
41
52
|
}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
1
14
|
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
|
|
2
15
|
// lookup table from base64 character to byte
|
|
3
|
-
let encTable =
|
|
4
|
-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
16
|
+
let encTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
|
|
5
17
|
// lookup table from base64 character *code* to byte because lookup by number is fast
|
|
6
18
|
let decTable = [];
|
|
7
19
|
for (let i = 0; i < encTable.length; i++)
|
|
8
|
-
|
|
20
|
+
decTable[encTable[i].charCodeAt(0)] = i;
|
|
9
21
|
// support base64url variants
|
|
10
22
|
decTable["-".charCodeAt(0)] = encTable.indexOf("+");
|
|
11
23
|
decTable["_".charCodeAt(0)] = encTable.indexOf("/");
|
|
@@ -21,57 +33,59 @@ decTable["_".charCodeAt(0)] = encTable.indexOf("/");
|
|
|
21
33
|
* no padding
|
|
22
34
|
*/
|
|
23
35
|
export function base64decode(base64Str) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
// estimate byte size, not accounting for inner padding and whitespace
|
|
37
|
+
let es = (base64Str.length * 3) / 4;
|
|
38
|
+
// if (es % 3 !== 0)
|
|
39
|
+
// throw new Error("invalid base64 string");
|
|
40
|
+
if (base64Str[base64Str.length - 2] == "=")
|
|
41
|
+
es -= 2;
|
|
42
|
+
else if (base64Str[base64Str.length - 1] == "=")
|
|
43
|
+
es -= 1;
|
|
44
|
+
let bytes = new Uint8Array(es), bytePos = 0, // position in byte array
|
|
32
45
|
groupPos = 0, // position in base64 group
|
|
33
46
|
b, // current byte
|
|
34
47
|
p = 0; // previous byte
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
for (let i = 0; i < base64Str.length; i++) {
|
|
49
|
+
b = decTable[base64Str.charCodeAt(i)];
|
|
50
|
+
if (b === undefined) {
|
|
51
|
+
switch (base64Str[i]) {
|
|
52
|
+
// @ts-ignore TS7029: Fallthrough case in switch
|
|
53
|
+
case "=":
|
|
54
|
+
groupPos = 0; // reset state when padding found
|
|
55
|
+
// @ts-ignore TS7029: Fallthrough case in switch
|
|
56
|
+
case "\n":
|
|
57
|
+
case "\r":
|
|
58
|
+
case "\t":
|
|
59
|
+
case " ":
|
|
60
|
+
continue; // skip white-space, and padding
|
|
61
|
+
default:
|
|
62
|
+
throw Error("invalid base64 string.");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
switch (groupPos) {
|
|
66
|
+
case 0:
|
|
67
|
+
p = b;
|
|
68
|
+
groupPos = 1;
|
|
69
|
+
break;
|
|
70
|
+
case 1:
|
|
71
|
+
bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
|
|
72
|
+
p = b;
|
|
73
|
+
groupPos = 2;
|
|
74
|
+
break;
|
|
75
|
+
case 2:
|
|
76
|
+
bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
|
|
77
|
+
p = b;
|
|
78
|
+
groupPos = 3;
|
|
79
|
+
break;
|
|
80
|
+
case 3:
|
|
81
|
+
bytes[bytePos++] = ((p & 3) << 6) | b;
|
|
82
|
+
groupPos = 0;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
51
85
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
groupPos = 1;
|
|
56
|
-
break;
|
|
57
|
-
case 1:
|
|
58
|
-
bytes[bytePos++] = (p << 2) | ((b & 48) >> 4);
|
|
59
|
-
p = b;
|
|
60
|
-
groupPos = 2;
|
|
61
|
-
break;
|
|
62
|
-
case 2:
|
|
63
|
-
bytes[bytePos++] = ((p & 15) << 4) | ((b & 60) >> 2);
|
|
64
|
-
p = b;
|
|
65
|
-
groupPos = 3;
|
|
66
|
-
break;
|
|
67
|
-
case 3:
|
|
68
|
-
bytes[bytePos++] = ((p & 3) << 6) | b;
|
|
69
|
-
groupPos = 0;
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (groupPos == 1) throw Error("invalid base64 string.");
|
|
74
|
-
return bytes.subarray(0, bytePos);
|
|
86
|
+
if (groupPos == 1)
|
|
87
|
+
throw Error("invalid base64 string.");
|
|
88
|
+
return bytes.subarray(0, bytePos);
|
|
75
89
|
}
|
|
76
90
|
/**
|
|
77
91
|
* Encodes a byte array to a base64 string.
|
|
@@ -79,35 +93,35 @@ export function base64decode(base64Str) {
|
|
|
79
93
|
* Does not insert newlines.
|
|
80
94
|
*/
|
|
81
95
|
export function base64encode(bytes) {
|
|
82
|
-
|
|
83
|
-
groupPos = 0, // position in base64 group
|
|
96
|
+
let base64 = "", groupPos = 0, // position in base64 group
|
|
84
97
|
b, // current byte
|
|
85
98
|
p = 0; // carry over from previous byte
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
100
|
+
b = bytes[i];
|
|
101
|
+
switch (groupPos) {
|
|
102
|
+
case 0:
|
|
103
|
+
base64 += encTable[b >> 2];
|
|
104
|
+
p = (b & 3) << 4;
|
|
105
|
+
groupPos = 1;
|
|
106
|
+
break;
|
|
107
|
+
case 1:
|
|
108
|
+
base64 += encTable[p | (b >> 4)];
|
|
109
|
+
p = (b & 15) << 2;
|
|
110
|
+
groupPos = 2;
|
|
111
|
+
break;
|
|
112
|
+
case 2:
|
|
113
|
+
base64 += encTable[p | (b >> 6)];
|
|
114
|
+
base64 += encTable[b & 63];
|
|
115
|
+
groupPos = 0;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// padding required?
|
|
120
|
+
if (groupPos) {
|
|
121
|
+
base64 += encTable[p];
|
|
122
|
+
base64 += "=";
|
|
123
|
+
if (groupPos == 1)
|
|
124
|
+
base64 += "=";
|
|
104
125
|
}
|
|
105
|
-
|
|
106
|
-
// padding required?
|
|
107
|
-
if (groupPos) {
|
|
108
|
-
base64 += encTable[p];
|
|
109
|
-
base64 += "=";
|
|
110
|
-
if (groupPos == 1) base64 += "=";
|
|
111
|
-
}
|
|
112
|
-
return base64;
|
|
126
|
+
return base64;
|
|
113
127
|
}
|