@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
package/dist/esm/proto-int64.js
CHANGED
|
@@ -1,118 +1,130 @@
|
|
|
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
|
import { int64fromString, int64toString } from "./google/varint.js";
|
|
2
15
|
function makeInt64Support() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const MIN = BigInt("-9223372036854775808"),
|
|
13
|
-
MAX = BigInt("9223372036854775807"),
|
|
14
|
-
UMIN = BigInt("0"),
|
|
15
|
-
UMAX = BigInt("18446744073709551615");
|
|
16
|
-
return {
|
|
17
|
-
zero: BigInt(0),
|
|
18
|
-
supported: true,
|
|
19
|
-
parse(value) {
|
|
20
|
-
const bi = typeof value == "bigint" ? value : BigInt(value);
|
|
21
|
-
if (bi > MAX || bi < MIN) {
|
|
22
|
-
throw new Error(`int64 invalid: ${value}`);
|
|
23
|
-
}
|
|
24
|
-
return bi;
|
|
25
|
-
},
|
|
26
|
-
uParse(value) {
|
|
27
|
-
const bi = typeof value == "bigint" ? value : BigInt(value);
|
|
28
|
-
if (bi > UMAX || bi < UMIN) {
|
|
29
|
-
throw new Error(`uint64 invalid: ${value}`);
|
|
30
|
-
}
|
|
31
|
-
return bi;
|
|
32
|
-
},
|
|
33
|
-
enc(value) {
|
|
34
|
-
dv.setBigInt64(0, this.parse(value), true);
|
|
35
|
-
return {
|
|
36
|
-
lo: dv.getInt32(0, true),
|
|
37
|
-
hi: dv.getInt32(4, true),
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
uEnc(value) {
|
|
41
|
-
dv.setBigInt64(0, this.uParse(value), true);
|
|
16
|
+
const dv = new DataView(new ArrayBuffer(8));
|
|
17
|
+
// note that Safari 14 implements BigInt, but not the DataView methods
|
|
18
|
+
const ok = globalThis.BigInt !== undefined && // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- conditional for BigInt is very much necessary
|
|
19
|
+
typeof dv.getBigInt64 === "function" &&
|
|
20
|
+
typeof dv.getBigUint64 === "function" &&
|
|
21
|
+
typeof dv.setBigInt64 === "function" &&
|
|
22
|
+
typeof dv.setBigUint64 === "function";
|
|
23
|
+
if (ok) {
|
|
24
|
+
const MIN = BigInt("-9223372036854775808"), MAX = BigInt("9223372036854775807"), UMIN = BigInt("0"), UMAX = BigInt("18446744073709551615");
|
|
42
25
|
return {
|
|
43
|
-
|
|
44
|
-
|
|
26
|
+
zero: BigInt(0),
|
|
27
|
+
supported: true,
|
|
28
|
+
parse(value) {
|
|
29
|
+
const bi = typeof value == "bigint" ? value : BigInt(value);
|
|
30
|
+
if (bi > MAX || bi < MIN) {
|
|
31
|
+
throw new Error(`int64 invalid: ${value}`);
|
|
32
|
+
}
|
|
33
|
+
return bi;
|
|
34
|
+
},
|
|
35
|
+
uParse(value) {
|
|
36
|
+
const bi = typeof value == "bigint" ? value : BigInt(value);
|
|
37
|
+
if (bi > UMAX || bi < UMIN) {
|
|
38
|
+
throw new Error(`uint64 invalid: ${value}`);
|
|
39
|
+
}
|
|
40
|
+
return bi;
|
|
41
|
+
},
|
|
42
|
+
enc(value) {
|
|
43
|
+
dv.setBigInt64(0, this.parse(value), true);
|
|
44
|
+
return {
|
|
45
|
+
lo: dv.getInt32(0, true),
|
|
46
|
+
hi: dv.getInt32(4, true),
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
uEnc(value) {
|
|
50
|
+
dv.setBigInt64(0, this.uParse(value), true);
|
|
51
|
+
return {
|
|
52
|
+
lo: dv.getInt32(0, true),
|
|
53
|
+
hi: dv.getInt32(4, true),
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
dec(lo, hi) {
|
|
57
|
+
dv.setInt32(0, lo, true);
|
|
58
|
+
dv.setInt32(4, hi, true);
|
|
59
|
+
return dv.getBigInt64(0, true);
|
|
60
|
+
},
|
|
61
|
+
uDec(lo, hi) {
|
|
62
|
+
dv.setInt32(0, lo, true);
|
|
63
|
+
dv.setInt32(4, hi, true);
|
|
64
|
+
return dv.getBigUint64(0, true);
|
|
65
|
+
},
|
|
45
66
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
zero: "0",
|
|
70
|
+
supported: false,
|
|
71
|
+
parse(value) {
|
|
72
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
73
|
+
throw new Error(`int64 invalid: ${value}`);
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
},
|
|
77
|
+
uParse(value) {
|
|
78
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
79
|
+
throw new Error(`uint64 invalid: ${value}`);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
},
|
|
83
|
+
enc(value) {
|
|
84
|
+
if (typeof value == "string") {
|
|
85
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
86
|
+
throw new Error(`int64 invalid: ${value}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
value = value.toString(10);
|
|
91
|
+
}
|
|
92
|
+
const [, lo, hi] = int64fromString(value);
|
|
93
|
+
return { lo, hi };
|
|
94
|
+
},
|
|
95
|
+
uEnc(value) {
|
|
96
|
+
if (typeof value == "string") {
|
|
97
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
98
|
+
throw new Error(`uint64 invalid: ${value}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
value = value.toString(10);
|
|
103
|
+
}
|
|
104
|
+
const [minus, lo, hi] = int64fromString(value);
|
|
105
|
+
if (minus) {
|
|
106
|
+
throw new Error(`uint64 invalid: ${value}`);
|
|
107
|
+
}
|
|
108
|
+
return { lo, hi };
|
|
109
|
+
},
|
|
110
|
+
dec(lo, hi) {
|
|
111
|
+
const minus = (hi & 0x80000000) !== 0;
|
|
112
|
+
if (minus) {
|
|
113
|
+
// negate
|
|
114
|
+
hi = ~hi;
|
|
115
|
+
if (lo) {
|
|
116
|
+
lo = ~lo + 1;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
hi += 1;
|
|
120
|
+
}
|
|
121
|
+
return ("-" + int64toString(lo, hi));
|
|
122
|
+
}
|
|
123
|
+
return int64toString(lo, hi);
|
|
124
|
+
},
|
|
125
|
+
uDec(lo, hi) {
|
|
126
|
+
return int64toString(lo, hi);
|
|
127
|
+
},
|
|
57
128
|
};
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
zero: "0",
|
|
61
|
-
supported: false,
|
|
62
|
-
parse(value) {
|
|
63
|
-
if (!/^-?[0-9]+$/.test(value)) {
|
|
64
|
-
throw new Error(`int64 invalid: ${value}`);
|
|
65
|
-
}
|
|
66
|
-
return value;
|
|
67
|
-
},
|
|
68
|
-
uParse(value) {
|
|
69
|
-
if (!/^-?[0-9]+$/.test(value)) {
|
|
70
|
-
throw new Error(`uint64 invalid: ${value}`);
|
|
71
|
-
}
|
|
72
|
-
return value;
|
|
73
|
-
},
|
|
74
|
-
enc(value) {
|
|
75
|
-
if (typeof value == "string") {
|
|
76
|
-
if (!/^-?[0-9]+$/.test(value)) {
|
|
77
|
-
throw new Error(`int64 invalid: ${value}`);
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
value = value.toString(10);
|
|
81
|
-
}
|
|
82
|
-
const [, lo, hi] = int64fromString(value);
|
|
83
|
-
return { lo, hi };
|
|
84
|
-
},
|
|
85
|
-
uEnc(value) {
|
|
86
|
-
if (typeof value == "string") {
|
|
87
|
-
if (!/^-?[0-9]+$/.test(value)) {
|
|
88
|
-
throw new Error(`uint64 invalid: ${value}`);
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
value = value.toString(10);
|
|
92
|
-
}
|
|
93
|
-
const [minus, lo, hi] = int64fromString(value);
|
|
94
|
-
if (minus) {
|
|
95
|
-
throw new Error(`uint64 invalid: ${value}`);
|
|
96
|
-
}
|
|
97
|
-
return { lo, hi };
|
|
98
|
-
},
|
|
99
|
-
dec(lo, hi) {
|
|
100
|
-
const minus = (hi & 0x80000000) !== 0;
|
|
101
|
-
if (minus) {
|
|
102
|
-
// negate
|
|
103
|
-
hi = ~hi;
|
|
104
|
-
if (lo) {
|
|
105
|
-
lo = ~lo + 1;
|
|
106
|
-
} else {
|
|
107
|
-
hi += 1;
|
|
108
|
-
}
|
|
109
|
-
return "-" + int64toString(lo, hi);
|
|
110
|
-
}
|
|
111
|
-
return int64toString(lo, hi);
|
|
112
|
-
},
|
|
113
|
-
uDec(lo, hi) {
|
|
114
|
-
return int64toString(lo, hi);
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
129
|
}
|
|
118
130
|
export const protoInt64 = makeInt64Support();
|
package/dist/esm/proto2.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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
|
import { makeProtoRuntime } from "./private/proto-runtime.js";
|
|
2
15
|
import { makeBinaryFormatProto2 } from "./private/binary-format-proto2.js";
|
|
3
16
|
import { makeUtilCommon } from "./private/util-common.js";
|
|
@@ -8,70 +21,63 @@ import { makeJsonFormatProto2 } from "./private/json-format-proto2.js";
|
|
|
8
21
|
/**
|
|
9
22
|
* Provides functionality for messages defined with the proto2 syntax.
|
|
10
23
|
*/
|
|
11
|
-
export const proto2 = makeProtoRuntime(
|
|
12
|
-
"proto2",
|
|
13
|
-
makeJsonFormatProto2(),
|
|
14
|
-
makeBinaryFormatProto2(),
|
|
15
|
-
{
|
|
24
|
+
export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBinaryFormatProto2(), {
|
|
16
25
|
...makeUtilCommon(),
|
|
17
26
|
newFieldList(fields) {
|
|
18
|
-
|
|
27
|
+
return new InternalFieldList(fields, normalizeFieldInfosProto2);
|
|
19
28
|
},
|
|
20
29
|
initFields(target) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
for (const member of target.getType().fields.byMember()) {
|
|
31
|
+
const name = member.localName, t = target;
|
|
32
|
+
if (member.repeated) {
|
|
33
|
+
t[name] = [];
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
switch (member.kind) {
|
|
37
|
+
case "oneof":
|
|
38
|
+
t[name] = { case: undefined };
|
|
39
|
+
break;
|
|
40
|
+
case "map":
|
|
41
|
+
t[name] = {};
|
|
42
|
+
break;
|
|
43
|
+
case "scalar":
|
|
44
|
+
case "enum":
|
|
45
|
+
case "message":
|
|
46
|
+
// In contrast to proto3, enum and scalar fields have no intrinsic default value,
|
|
47
|
+
// only an optional explicit default value.
|
|
48
|
+
// Unlike proto3 intrinsic default values, proto2 explicit default values are not
|
|
49
|
+
// set on construction, because they are not omitted on the wire. If we did set
|
|
50
|
+
// default values on construction, a deserialize-serialize round-trip would add
|
|
51
|
+
// fields to a message.
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
27
54
|
}
|
|
28
|
-
switch (member.kind) {
|
|
29
|
-
case "oneof":
|
|
30
|
-
t[name] = { case: undefined };
|
|
31
|
-
break;
|
|
32
|
-
case "map":
|
|
33
|
-
t[name] = {};
|
|
34
|
-
break;
|
|
35
|
-
case "scalar":
|
|
36
|
-
case "enum":
|
|
37
|
-
case "message":
|
|
38
|
-
// In contrast to proto3, enum and scalar fields have no intrinsic default value,
|
|
39
|
-
// only an optional explicit default value.
|
|
40
|
-
// Unlike proto3 intrinsic default values, proto2 explicit default values are not
|
|
41
|
-
// set on construction, because they are not omitted on the wire. If we did set
|
|
42
|
-
// default values on construction, a deserialize-serialize round-trip would add
|
|
43
|
-
// fields to a message.
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
55
|
},
|
|
48
|
-
|
|
49
|
-
);
|
|
56
|
+
});
|
|
50
57
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
51
58
|
function normalizeFieldInfosProto2(fieldInfos) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
const r = [];
|
|
60
|
+
let o;
|
|
61
|
+
for (const field of typeof fieldInfos == "function"
|
|
62
|
+
? fieldInfos()
|
|
63
|
+
: fieldInfos) {
|
|
64
|
+
const f = field;
|
|
65
|
+
f.localName = makeFieldName(field.name, field.oneof !== undefined);
|
|
66
|
+
f.jsonName = field.jsonName ?? makeJsonName(field.name);
|
|
67
|
+
f.repeated = field.repeated ?? false;
|
|
68
|
+
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
69
|
+
f.packed = field.packed ?? false;
|
|
70
|
+
// We do not surface options at this time
|
|
71
|
+
// f.options = field.options ?? emptyReadonlyObject;
|
|
72
|
+
if (field.oneof !== undefined) {
|
|
73
|
+
const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name;
|
|
74
|
+
if (!o || o.name != ooname) {
|
|
75
|
+
o = new InternalOneofInfo(ooname);
|
|
76
|
+
}
|
|
77
|
+
f.oneof = o;
|
|
78
|
+
o.addField(f);
|
|
79
|
+
}
|
|
80
|
+
r.push(f);
|
|
73
81
|
}
|
|
74
|
-
r
|
|
75
|
-
}
|
|
76
|
-
return r;
|
|
82
|
+
return r;
|
|
77
83
|
}
|
package/dist/esm/proto3.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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
|
import { makeProtoRuntime } from "./private/proto-runtime.js";
|
|
2
15
|
import { makeBinaryFormatProto3 } from "./private/binary-format-proto3.js";
|
|
3
16
|
import { makeJsonFormatProto3 } from "./private/json-format-proto3.js";
|
|
@@ -10,81 +23,74 @@ import { makeFieldName, makeJsonName } from "./private/names.js";
|
|
|
10
23
|
/**
|
|
11
24
|
* Provides functionality for messages defined with the proto3 syntax.
|
|
12
25
|
*/
|
|
13
|
-
export const proto3 = makeProtoRuntime(
|
|
14
|
-
"proto3",
|
|
15
|
-
makeJsonFormatProto3(),
|
|
16
|
-
makeBinaryFormatProto3(),
|
|
17
|
-
{
|
|
26
|
+
export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBinaryFormatProto3(), {
|
|
18
27
|
...makeUtilCommon(),
|
|
19
28
|
newFieldList(fields) {
|
|
20
|
-
|
|
29
|
+
return new InternalFieldList(fields, normalizeFieldInfosProto3);
|
|
21
30
|
},
|
|
22
31
|
initFields(target) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
for (const member of target.getType().fields.byMember()) {
|
|
33
|
+
if (member.opt) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const name = member.localName, t = target;
|
|
37
|
+
if (member.repeated) {
|
|
38
|
+
t[name] = [];
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
switch (member.kind) {
|
|
42
|
+
case "oneof":
|
|
43
|
+
t[name] = { case: undefined };
|
|
44
|
+
break;
|
|
45
|
+
case "enum":
|
|
46
|
+
t[name] = 0;
|
|
47
|
+
break;
|
|
48
|
+
case "map":
|
|
49
|
+
t[name] = {};
|
|
50
|
+
break;
|
|
51
|
+
case "scalar":
|
|
52
|
+
t[name] = scalarDefaultValue(member.T); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
|
53
|
+
break;
|
|
54
|
+
case "message":
|
|
55
|
+
// message fields are always optional in proto3
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
26
58
|
}
|
|
27
|
-
const name = member.localName,
|
|
28
|
-
t = target;
|
|
29
|
-
if (member.repeated) {
|
|
30
|
-
t[name] = [];
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
switch (member.kind) {
|
|
34
|
-
case "oneof":
|
|
35
|
-
t[name] = { case: undefined };
|
|
36
|
-
break;
|
|
37
|
-
case "enum":
|
|
38
|
-
t[name] = 0;
|
|
39
|
-
break;
|
|
40
|
-
case "map":
|
|
41
|
-
t[name] = {};
|
|
42
|
-
break;
|
|
43
|
-
case "scalar":
|
|
44
|
-
t[name] = scalarDefaultValue(member.T); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
|
45
|
-
break;
|
|
46
|
-
case "message":
|
|
47
|
-
// message fields are always optional in proto3
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
59
|
},
|
|
52
|
-
|
|
53
|
-
);
|
|
60
|
+
});
|
|
54
61
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
55
62
|
function normalizeFieldInfosProto3(fieldInfos) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
const r = [];
|
|
64
|
+
let o;
|
|
65
|
+
for (const field of typeof fieldInfos == "function"
|
|
66
|
+
? fieldInfos()
|
|
67
|
+
: fieldInfos) {
|
|
68
|
+
const f = field;
|
|
69
|
+
f.localName = makeFieldName(field.name, field.oneof !== undefined);
|
|
70
|
+
f.jsonName = field.jsonName ?? makeJsonName(field.name);
|
|
71
|
+
f.repeated = field.repeated ?? false;
|
|
72
|
+
// From the proto3 language guide:
|
|
73
|
+
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
74
|
+
// This information is incomplete - according to the conformance tests, BOOL
|
|
75
|
+
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
76
|
+
// are not packed by default, which makes sense because they are length-delimited.
|
|
77
|
+
f.packed =
|
|
78
|
+
field.packed ??
|
|
79
|
+
(field.kind == "enum" ||
|
|
80
|
+
(field.kind == "scalar" &&
|
|
81
|
+
field.T != ScalarType.BYTES &&
|
|
82
|
+
field.T != ScalarType.STRING));
|
|
83
|
+
// We do not surface options at this time
|
|
84
|
+
// f.options = field.options ?? emptyReadonlyObject;
|
|
85
|
+
if (field.oneof !== undefined) {
|
|
86
|
+
const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name;
|
|
87
|
+
if (!o || o.name != ooname) {
|
|
88
|
+
o = new InternalOneofInfo(ooname);
|
|
89
|
+
}
|
|
90
|
+
f.oneof = o;
|
|
91
|
+
o.addField(f);
|
|
92
|
+
}
|
|
93
|
+
r.push(f);
|
|
86
94
|
}
|
|
87
|
-
r
|
|
88
|
-
}
|
|
89
|
-
return r;
|
|
95
|
+
return r;
|
|
90
96
|
}
|
package/dist/esm/service-type.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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
|
* MethodKind represents the four method types that can be declared in
|
|
3
16
|
* protobuf with the `stream` keyword:
|
|
@@ -9,10 +22,10 @@
|
|
|
9
22
|
*/
|
|
10
23
|
export var MethodKind;
|
|
11
24
|
(function (MethodKind) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
MethodKind[MethodKind["Unary"] = 0] = "Unary";
|
|
26
|
+
MethodKind[MethodKind["ServerStreaming"] = 1] = "ServerStreaming";
|
|
27
|
+
MethodKind[MethodKind["ClientStreaming"] = 2] = "ClientStreaming";
|
|
28
|
+
MethodKind[MethodKind["BiDiStreaming"] = 3] = "BiDiStreaming";
|
|
16
29
|
})(MethodKind || (MethodKind = {}));
|
|
17
30
|
/**
|
|
18
31
|
* Is this method side-effect-free (or safe in HTTP parlance), or just
|
|
@@ -26,12 +39,12 @@ export var MethodKind;
|
|
|
26
39
|
*/
|
|
27
40
|
export var MethodIdempotency;
|
|
28
41
|
(function (MethodIdempotency) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Idempotent, no side effects.
|
|
44
|
+
*/
|
|
45
|
+
MethodIdempotency[MethodIdempotency["NoSideEffects"] = 1] = "NoSideEffects";
|
|
46
|
+
/**
|
|
47
|
+
* Idempotent, but may have side effects.
|
|
48
|
+
*/
|
|
49
|
+
MethodIdempotency[MethodIdempotency["Idempotent"] = 2] = "Idempotent";
|
|
37
50
|
})(MethodIdempotency || (MethodIdempotency = {}));
|
|
@@ -1,38 +1,53 @@
|
|
|
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
|
* TypeRegistry is a basic type registry
|
|
3
16
|
*/
|
|
4
17
|
export class TypeRegistry {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
findMessage(typeName) {
|
|
11
|
-
return this.messages[typeName];
|
|
12
|
-
}
|
|
13
|
-
findEnum(typeName) {
|
|
14
|
-
return this.enums[typeName];
|
|
15
|
-
}
|
|
16
|
-
findService(typeName) {
|
|
17
|
-
return this.services[typeName];
|
|
18
|
-
}
|
|
19
|
-
add(type) {
|
|
20
|
-
if ("fields" in type) {
|
|
21
|
-
this.messages[type.typeName] = type;
|
|
22
|
-
} else if ("methods" in type) {
|
|
23
|
-
this.services[type.typeName] = type;
|
|
24
|
-
} else {
|
|
25
|
-
this.enums[type.typeName] = type;
|
|
18
|
+
constructor() {
|
|
19
|
+
this.messages = {};
|
|
20
|
+
this.enums = {};
|
|
21
|
+
this.services = {};
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
findMessage(typeName) {
|
|
24
|
+
return this.messages[typeName];
|
|
25
|
+
}
|
|
26
|
+
findEnum(typeName) {
|
|
27
|
+
return this.enums[typeName];
|
|
28
|
+
}
|
|
29
|
+
findService(typeName) {
|
|
30
|
+
return this.services[typeName];
|
|
31
|
+
}
|
|
32
|
+
add(type) {
|
|
33
|
+
if ("fields" in type) {
|
|
34
|
+
this.messages[type.typeName] = type;
|
|
35
|
+
}
|
|
36
|
+
else if ("methods" in type) {
|
|
37
|
+
this.services[type.typeName] = type;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.enums[type.typeName] = type;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
static fromIterable(types) {
|
|
44
|
+
const r = new TypeRegistry();
|
|
45
|
+
for (const t of types) {
|
|
46
|
+
r.add(t);
|
|
47
|
+
}
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
static fromTypes(...types) {
|
|
51
|
+
return TypeRegistry.fromIterable(types);
|
|
32
52
|
}
|
|
33
|
-
return r;
|
|
34
|
-
}
|
|
35
|
-
static fromTypes(...types) {
|
|
36
|
-
return TypeRegistry.fromIterable(types);
|
|
37
|
-
}
|
|
38
53
|
}
|