@bufbuild/protobuf 0.0.9 → 0.1.1
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 +1 -1
- package/dist/cjs/create-registry-from-desc.js +10 -116
- package/dist/cjs/create-registry.js +1 -1
- package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
- package/dist/cjs/google/protobuf/empty_pb.js +0 -1
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/google/varint.js +85 -37
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/private/binary-format-proto2.js +1 -1
- package/dist/cjs/private/json-format-common.js +6 -6
- package/dist/cjs/proto-int64.js +23 -40
- package/dist/esm/create-registry-from-desc.js +9 -114
- package/dist/esm/create-registry.js +1 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
- package/dist/esm/google/protobuf/empty_pb.js +0 -1
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/varint.js +81 -34
- package/dist/esm/index.js +0 -3
- package/dist/esm/private/binary-format-proto2.js +1 -1
- package/dist/esm/private/json-format-common.js +6 -6
- package/dist/esm/proto-int64.js +24 -41
- package/dist/types/create-registry-from-desc.d.ts +0 -34
- package/dist/types/create-registry.d.ts +1 -1
- package/dist/types/google/protobuf/descriptor_pb.d.ts +6 -6
- package/dist/types/google/protobuf/empty_pb.d.ts +0 -1
- package/dist/types/google/varint.d.ts +21 -9
- package/dist/types/index.d.ts +0 -3
- package/dist/types/json-format.d.ts +1 -1
- package/dist/types/message.d.ts +3 -1
- package/dist/types/proto-int64.d.ts +14 -13
- package/package.json +5 -8
- package/dist/cjs/legacy-descriptor-registry.js +0 -468
- package/dist/cjs/legacy-descriptor-set.js +0 -453
- package/dist/cjs/legacy-type-registry.js +0 -104
- package/dist/esm/legacy-descriptor-registry.js +0 -464
- package/dist/esm/legacy-descriptor-set.js +0 -449
- package/dist/esm/legacy-type-registry.js +0 -100
- package/dist/types/legacy-descriptor-registry.d.ts +0 -45
- package/dist/types/legacy-descriptor-set.d.ts +0 -152
- package/dist/types/legacy-type-registry.d.ts +0 -44
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @bufbuild/protobuf
|
|
2
2
|
|
|
3
3
|
This package provides the runtime library for the code generator plugin
|
|
4
|
-
[
|
|
4
|
+
[protoc-gen-es](https://www.npmjs.com/package/@bufbuild/protoc-gen-es).
|
|
5
5
|
|
|
6
6
|
## Protocol Buffers for ECMAScript
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// See the License for the specific language governing permissions and
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
16
|
+
exports.createRegistryFromDescriptors = void 0;
|
|
17
17
|
const assert_js_1 = require("./private/assert.js");
|
|
18
18
|
const proto3_js_1 = require("./proto3.js");
|
|
19
19
|
const proto2_js_1 = require("./proto2.js");
|
|
@@ -138,7 +138,7 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
138
138
|
const methods = {};
|
|
139
139
|
for (const method of desc.methods) {
|
|
140
140
|
const I = this.findMessage(method.input.typeName);
|
|
141
|
-
const O = this.findMessage(method.
|
|
141
|
+
const O = this.findMessage(method.output.typeName);
|
|
142
142
|
(0, assert_js_1.assert)(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
|
|
143
143
|
(0, assert_js_1.assert)(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
|
|
144
144
|
const m = {
|
|
@@ -160,116 +160,6 @@ function createRegistryFromDescriptors(input, replaceWkt = true) {
|
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
162
|
exports.createRegistryFromDescriptors = createRegistryFromDescriptors;
|
|
163
|
-
/**
|
|
164
|
-
* DescriptorRegistry is a type registry that dynamically creates types
|
|
165
|
-
* from a set of google.protobuf.FileDescriptorProto.
|
|
166
|
-
*
|
|
167
|
-
* By default, all well-known types with a specialized JSON representation
|
|
168
|
-
* are replaced with their generated counterpart in this package.
|
|
169
|
-
*/
|
|
170
|
-
class DescriptorRegistry {
|
|
171
|
-
constructor(descriptorSet, replaceWkt = true) {
|
|
172
|
-
this.enums = {};
|
|
173
|
-
this.messages = {};
|
|
174
|
-
this.services = {};
|
|
175
|
-
this.desc = descriptorSet;
|
|
176
|
-
if (replaceWkt) {
|
|
177
|
-
for (const mt of wkMessages) {
|
|
178
|
-
this.messages[mt.typeName] = mt;
|
|
179
|
-
}
|
|
180
|
-
for (const et of wkEnums) {
|
|
181
|
-
this.enums[et.typeName] = et;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Conveniently create a DescriptorRegistry from a FileDescriptorSet,
|
|
187
|
-
* or a FileDescriptorSet in binary format.
|
|
188
|
-
*/
|
|
189
|
-
static fromFileDescriptorSet(input) {
|
|
190
|
-
return new DescriptorRegistry((0, create_descriptor_set_js_1.createDescriptorSet)(input));
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* May raise an error on invalid descriptors.
|
|
194
|
-
*/
|
|
195
|
-
findEnum(typeName) {
|
|
196
|
-
const existing = this.enums[typeName];
|
|
197
|
-
if (existing) {
|
|
198
|
-
return existing;
|
|
199
|
-
}
|
|
200
|
-
const desc = this.desc.enums.get(typeName);
|
|
201
|
-
if (!desc) {
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
const runtime = desc.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
|
|
205
|
-
const type = runtime.makeEnumType(typeName, desc.values.map((u) => ({
|
|
206
|
-
no: u.number,
|
|
207
|
-
name: u.name,
|
|
208
|
-
localName: (0, names_js_1.localName)(u),
|
|
209
|
-
})), {});
|
|
210
|
-
this.enums[typeName] = type;
|
|
211
|
-
return type;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* May raise an error on invalid descriptors.
|
|
215
|
-
*/
|
|
216
|
-
findMessage(typeName) {
|
|
217
|
-
const existing = this.messages[typeName];
|
|
218
|
-
if (existing) {
|
|
219
|
-
return existing;
|
|
220
|
-
}
|
|
221
|
-
const desc = this.desc.messages.get(typeName);
|
|
222
|
-
if (!desc) {
|
|
223
|
-
return undefined;
|
|
224
|
-
}
|
|
225
|
-
const runtime = desc.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
|
|
226
|
-
const fields = [];
|
|
227
|
-
const type = runtime.makeMessageType(typeName, () => fields, {
|
|
228
|
-
localName: (0, names_js_1.localName)(desc),
|
|
229
|
-
});
|
|
230
|
-
this.messages[typeName] = type;
|
|
231
|
-
for (const field of desc.fields) {
|
|
232
|
-
const fieldInfo = makeFieldInfo(field, this);
|
|
233
|
-
fields.push(fieldInfo);
|
|
234
|
-
}
|
|
235
|
-
return type;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* May raise an error on invalid descriptors.
|
|
239
|
-
*/
|
|
240
|
-
findService(typeName) {
|
|
241
|
-
const existing = this.services[typeName];
|
|
242
|
-
if (existing) {
|
|
243
|
-
return existing;
|
|
244
|
-
}
|
|
245
|
-
const desc = this.desc.services.get(typeName);
|
|
246
|
-
if (!desc) {
|
|
247
|
-
return undefined;
|
|
248
|
-
}
|
|
249
|
-
const methods = {};
|
|
250
|
-
for (const method of desc.methods) {
|
|
251
|
-
const I = this.findMessage(method.input.typeName);
|
|
252
|
-
const O = this.findMessage(method.input.typeName);
|
|
253
|
-
(0, assert_js_1.assert)(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
|
|
254
|
-
(0, assert_js_1.assert)(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
|
|
255
|
-
const m = {
|
|
256
|
-
name: method.name,
|
|
257
|
-
localName: (0, names_js_1.localName)(method),
|
|
258
|
-
I,
|
|
259
|
-
O,
|
|
260
|
-
kind: method.methodKind,
|
|
261
|
-
idempotency: method.idempotency,
|
|
262
|
-
options: {},
|
|
263
|
-
};
|
|
264
|
-
methods[m.localName] = m;
|
|
265
|
-
}
|
|
266
|
-
return (this.services[typeName] = {
|
|
267
|
-
typeName: desc.typeName,
|
|
268
|
-
methods,
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
exports.DescriptorRegistry = DescriptorRegistry;
|
|
273
163
|
function makeFieldInfo(desc, resolver) {
|
|
274
164
|
switch (desc.kind) {
|
|
275
165
|
case "map_field":
|
|
@@ -291,8 +181,9 @@ function makeFieldInfo(desc, resolver) {
|
|
|
291
181
|
function makeMapFieldInfo(field, resolver) {
|
|
292
182
|
const base = {
|
|
293
183
|
kind: "map",
|
|
294
|
-
name: field.name,
|
|
295
184
|
no: field.number,
|
|
185
|
+
name: field.name,
|
|
186
|
+
jsonName: field.jsonName,
|
|
296
187
|
K: field.mapKey,
|
|
297
188
|
};
|
|
298
189
|
if (field.mapValue.message) {
|
|
@@ -318,9 +209,10 @@ function makeMapFieldInfo(field, resolver) {
|
|
|
318
209
|
}
|
|
319
210
|
function makeScalarFieldInfo(field) {
|
|
320
211
|
const base = {
|
|
212
|
+
kind: "scalar",
|
|
321
213
|
no: field.number,
|
|
322
214
|
name: field.name,
|
|
323
|
-
|
|
215
|
+
jsonName: field.jsonName,
|
|
324
216
|
T: field.scalar,
|
|
325
217
|
};
|
|
326
218
|
if (field.repeated) {
|
|
@@ -338,9 +230,10 @@ function makeMessageFieldInfo(field, resolver) {
|
|
|
338
230
|
const messageType = resolver.findMessage(field.message.typeName);
|
|
339
231
|
(0, assert_js_1.assert)(messageType, `message "${field.message.typeName}" for ${field.toString()} not found`);
|
|
340
232
|
const base = {
|
|
233
|
+
kind: "message",
|
|
341
234
|
no: field.number,
|
|
342
235
|
name: field.name,
|
|
343
|
-
|
|
236
|
+
jsonName: field.jsonName,
|
|
344
237
|
T: messageType,
|
|
345
238
|
};
|
|
346
239
|
if (field.repeated) {
|
|
@@ -358,9 +251,10 @@ function makeEnumFieldInfo(field, resolver) {
|
|
|
358
251
|
const enumType = resolver.findEnum(field.enum.typeName);
|
|
359
252
|
(0, assert_js_1.assert)(enumType, `enum "${field.enum.typeName}" for ${field.toString()} not found`);
|
|
360
253
|
const base = {
|
|
254
|
+
kind: "enum",
|
|
361
255
|
no: field.number,
|
|
362
256
|
name: field.name,
|
|
363
|
-
|
|
257
|
+
jsonName: field.jsonName,
|
|
364
258
|
T: enumType,
|
|
365
259
|
};
|
|
366
260
|
if (field.repeated) {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.createRegistry = void 0;
|
|
17
17
|
/**
|
|
18
|
-
* Create a new registry from the given types.
|
|
18
|
+
* Create a new registry from the given types.
|
|
19
19
|
*/
|
|
20
20
|
function createRegistry(...types) {
|
|
21
21
|
const messages = {};
|
|
@@ -1169,8 +1169,8 @@ UninterpretedOption.fields = proto2_js_1.proto2.util.newFieldList(() => [
|
|
|
1169
1169
|
* The name of the uninterpreted option. Each string represents a segment in
|
|
1170
1170
|
* a dot-separated name. is_extension is true iff a segment represents an
|
|
1171
1171
|
* extension (denoted with parentheses in options specs in .proto files).
|
|
1172
|
-
* E.g.,{ ["foo", false], ["bar.baz", true], ["
|
|
1173
|
-
* "foo.(bar.baz).
|
|
1172
|
+
* E.g.,{ ["foo", false], ["bar.baz", true], ["moo", false] } represents
|
|
1173
|
+
* "foo.(bar.baz).moo".
|
|
1174
1174
|
*
|
|
1175
1175
|
* @generated from message google.protobuf.UninterpretedOption.NamePart
|
|
1176
1176
|
*/
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v0.
|
|
17
|
+
// @generated by protoc-gen-es v0.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v0.
|
|
17
|
+
// @generated by protoc-gen-es v0.1.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
// standalone and requires a support library to be linked with it. This
|
|
33
33
|
// support library is itself covered by the above license.
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.varint32read = exports.varint32write = exports.
|
|
35
|
+
exports.varint32read = exports.varint32write = exports.uInt64ToString = exports.int64ToString = exports.int64FromString = exports.varint64write = exports.varint64read = void 0;
|
|
36
36
|
/* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */
|
|
37
37
|
/**
|
|
38
38
|
* Read a 64 bit varint as two JS numbers.
|
|
@@ -112,22 +112,20 @@ function varint64write(lo, hi, bytes) {
|
|
|
112
112
|
}
|
|
113
113
|
exports.varint64write = varint64write;
|
|
114
114
|
// constants for binary math
|
|
115
|
-
const TWO_PWR_32_DBL =
|
|
115
|
+
const TWO_PWR_32_DBL = 0x100000000;
|
|
116
116
|
/**
|
|
117
117
|
* Parse decimal string of 64 bit integer value as two JS numbers.
|
|
118
118
|
*
|
|
119
|
-
*
|
|
120
|
-
* [0]: minus sign?
|
|
121
|
-
* [1]: low bits
|
|
122
|
-
* [2]: high bits
|
|
119
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
123
120
|
*
|
|
124
|
-
*
|
|
121
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
125
122
|
*/
|
|
126
|
-
function
|
|
123
|
+
function int64FromString(dec) {
|
|
127
124
|
// Check for minus sign.
|
|
128
|
-
|
|
129
|
-
if (minus)
|
|
125
|
+
const minus = dec[0] === "-";
|
|
126
|
+
if (minus) {
|
|
130
127
|
dec = dec.slice(1);
|
|
128
|
+
}
|
|
131
129
|
// Work 6 decimal digits at a time, acting like we're converting base 1e6
|
|
132
130
|
// digits to binary. This is safe to do with floating point math because
|
|
133
131
|
// Number.isSafeInteger(ALL_32_BITS * 1e6) == true.
|
|
@@ -149,19 +147,47 @@ function int64fromString(dec) {
|
|
|
149
147
|
add1e6digit(-18, -12);
|
|
150
148
|
add1e6digit(-12, -6);
|
|
151
149
|
add1e6digit(-6);
|
|
152
|
-
return
|
|
150
|
+
return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
|
|
153
151
|
}
|
|
154
|
-
exports.
|
|
152
|
+
exports.int64FromString = int64FromString;
|
|
155
153
|
/**
|
|
156
|
-
*
|
|
154
|
+
* Losslessly converts a 64-bit signed integer in 32:32 split representation
|
|
155
|
+
* into a decimal string.
|
|
156
|
+
*
|
|
157
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
158
|
+
*
|
|
159
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
160
|
+
*/
|
|
161
|
+
function int64ToString(lo, hi) {
|
|
162
|
+
let bits = newBits(lo, hi);
|
|
163
|
+
// If we're treating the input as a signed value and the high bit is set, do
|
|
164
|
+
// a manual two's complement conversion before the decimal conversion.
|
|
165
|
+
const negative = (bits.hi & 0x80000000);
|
|
166
|
+
if (negative) {
|
|
167
|
+
bits = negate(bits.lo, bits.hi);
|
|
168
|
+
}
|
|
169
|
+
const result = uInt64ToString(bits.lo, bits.hi);
|
|
170
|
+
return negative ? "-" + result : result;
|
|
171
|
+
}
|
|
172
|
+
exports.int64ToString = int64ToString;
|
|
173
|
+
/**
|
|
174
|
+
* Losslessly converts a 64-bit unsigned integer in 32:32 split representation
|
|
175
|
+
* into a decimal string.
|
|
176
|
+
*
|
|
177
|
+
* Copyright 2008 Google Inc. All rights reserved.
|
|
157
178
|
*
|
|
158
|
-
*
|
|
179
|
+
* See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
|
|
159
180
|
*/
|
|
160
|
-
function
|
|
181
|
+
function uInt64ToString(lo, hi) {
|
|
182
|
+
({ lo, hi } = toUnsigned(lo, hi));
|
|
161
183
|
// Skip the expensive conversion if the number is small enough to use the
|
|
162
184
|
// built-in conversions.
|
|
163
|
-
|
|
164
|
-
|
|
185
|
+
// Number.MAX_SAFE_INTEGER = 0x001FFFFF FFFFFFFF, thus any number with
|
|
186
|
+
// highBits <= 0x1FFFFF can be safely expressed with a double and retain
|
|
187
|
+
// integer precision.
|
|
188
|
+
// Proven by: Number.isSafeInteger(0x1FFFFF * 2**32 + 0xFFFFFFFF) == true.
|
|
189
|
+
if (hi <= 0x1FFFFF) {
|
|
190
|
+
return String(TWO_PWR_32_DBL * hi + lo);
|
|
165
191
|
}
|
|
166
192
|
// What this code is doing is essentially converting the input number from
|
|
167
193
|
// base-2 to base-1e7, which allows us to represent the 64-bit range with
|
|
@@ -172,17 +198,17 @@ function int64toString(bitsLow, bitsHigh) {
|
|
|
172
198
|
// 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
|
|
173
199
|
// Split 32:32 representation into 16:24:24 representation so our
|
|
174
200
|
// intermediate digits don't overflow.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
201
|
+
const low = lo & 0xFFFFFF;
|
|
202
|
+
const mid = ((lo >>> 24) | (hi << 8)) & 0xFFFFFF;
|
|
203
|
+
const high = (hi >> 16) & 0xFFFF;
|
|
178
204
|
// Assemble our three base-1e7 digits, ignoring carries. The maximum
|
|
179
205
|
// value in a digit at this step is representable as a 48-bit integer, which
|
|
180
206
|
// can be stored in a 64-bit floating point number.
|
|
181
|
-
let digitA = low + mid * 6777216 + high * 6710656;
|
|
182
|
-
let digitB = mid + high * 8147497;
|
|
183
|
-
let digitC = high * 2;
|
|
207
|
+
let digitA = low + (mid * 6777216) + (high * 6710656);
|
|
208
|
+
let digitB = mid + (high * 8147497);
|
|
209
|
+
let digitC = (high * 2);
|
|
184
210
|
// Apply carries from A to B and from B to C.
|
|
185
|
-
|
|
211
|
+
const base = 10000000;
|
|
186
212
|
if (digitA >= base) {
|
|
187
213
|
digitB += Math.floor(digitA / base);
|
|
188
214
|
digitA %= base;
|
|
@@ -191,21 +217,43 @@ function int64toString(bitsLow, bitsHigh) {
|
|
|
191
217
|
digitC += Math.floor(digitB / base);
|
|
192
218
|
digitB %= base;
|
|
193
219
|
}
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
220
|
+
// If digitC is 0, then we should have returned in the trivial code path
|
|
221
|
+
// at the top for non-safe integers. Given this, we can assume both digitB
|
|
222
|
+
// and digitA need leading zeros.
|
|
223
|
+
return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) +
|
|
224
|
+
decimalFrom1e7WithLeadingZeros(digitA);
|
|
225
|
+
}
|
|
226
|
+
exports.uInt64ToString = uInt64ToString;
|
|
227
|
+
function toUnsigned(lo, hi) {
|
|
228
|
+
return { lo: lo >>> 0, hi: hi >>> 0 };
|
|
229
|
+
}
|
|
230
|
+
function newBits(lo, hi) {
|
|
231
|
+
return { lo: lo | 0, hi: hi | 0 };
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Returns two's compliment negation of input.
|
|
235
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers
|
|
236
|
+
*/
|
|
237
|
+
function negate(lowBits, highBits) {
|
|
238
|
+
highBits = ~highBits;
|
|
239
|
+
if (lowBits) {
|
|
240
|
+
lowBits = ~lowBits + 1;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
// If lowBits is 0, then bitwise-not is 0xFFFFFFFF,
|
|
244
|
+
// adding 1 to that, results in 0x100000000, which leaves
|
|
245
|
+
// the low bits 0x0 and simply adds one to the high bits.
|
|
246
|
+
highBits += 1;
|
|
201
247
|
}
|
|
202
|
-
return (
|
|
203
|
-
decimalFrom1e7(digitB, /*needLeadingZeros=*/ digitC) +
|
|
204
|
-
// If the final 1e7 digit didn't need leading zeros, we would have
|
|
205
|
-
// returned via the trivial code path at the top.
|
|
206
|
-
decimalFrom1e7(digitA, /*needLeadingZeros=*/ 1));
|
|
248
|
+
return newBits(lowBits, highBits);
|
|
207
249
|
}
|
|
208
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Returns decimal representation of digit1e7 with leading zeros.
|
|
252
|
+
*/
|
|
253
|
+
const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
|
|
254
|
+
const partial = String(digit1e7);
|
|
255
|
+
return "0000000".slice(partial.length) + partial;
|
|
256
|
+
};
|
|
209
257
|
/**
|
|
210
258
|
* Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
|
|
211
259
|
*
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
27
27
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.
|
|
30
|
+
exports.createRegistryFromDescriptors = exports.createRegistry = exports.createDescriptorSet = exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.MethodIdempotency = exports.MethodKind = exports.ScalarType = exports.Message = exports.codegenInfo = exports.protoBase64 = exports.protoInt64 = exports.proto2 = exports.proto3 = void 0;
|
|
31
31
|
var proto3_js_1 = require("./proto3.js");
|
|
32
32
|
Object.defineProperty(exports, "proto3", { enumerable: true, get: function () { return proto3_js_1.proto3; } });
|
|
33
33
|
var proto2_js_1 = require("./proto2.js");
|
|
@@ -58,12 +58,6 @@ var create_registry_js_1 = require("./create-registry.js");
|
|
|
58
58
|
Object.defineProperty(exports, "createRegistry", { enumerable: true, get: function () { return create_registry_js_1.createRegistry; } });
|
|
59
59
|
var create_registry_from_desc_js_1 = require("./create-registry-from-desc.js");
|
|
60
60
|
Object.defineProperty(exports, "createRegistryFromDescriptors", { enumerable: true, get: function () { return create_registry_from_desc_js_1.createRegistryFromDescriptors; } });
|
|
61
|
-
var legacy_descriptor_registry_js_1 = require("./legacy-descriptor-registry.js");
|
|
62
|
-
Object.defineProperty(exports, "LegacyDescriptorRegistry", { enumerable: true, get: function () { return legacy_descriptor_registry_js_1.LegacyDescriptorRegistry; } });
|
|
63
|
-
var legacy_descriptor_set_js_1 = require("./legacy-descriptor-set.js");
|
|
64
|
-
Object.defineProperty(exports, "LegacyDescriptorSet", { enumerable: true, get: function () { return legacy_descriptor_set_js_1.LegacyDescriptorSet; } });
|
|
65
|
-
var legacy_type_registry_js_1 = require("./legacy-type-registry.js");
|
|
66
|
-
Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return legacy_type_registry_js_1.TypeRegistry; } });
|
|
67
61
|
// ideally, we would export these types with sub-path exports:
|
|
68
62
|
__exportStar(require("./google/protobuf/compiler/plugin_pb.js"), exports);
|
|
69
63
|
__exportStar(require("./google/protobuf/api_pb.js"), exports);
|
|
@@ -37,7 +37,7 @@ function makeBinaryFormatProto2() {
|
|
|
37
37
|
// In contrast to proto3, we raise an error if a non-optional (proto2 required)
|
|
38
38
|
// field is missing a value.
|
|
39
39
|
if (value === undefined && !field.oneof && !field.opt) {
|
|
40
|
-
throw new Error(`cannot encode field ${type.typeName}.${field.name} to
|
|
40
|
+
throw new Error(`cannot encode field ${type.typeName}.${field.name} to binary: required field not set`);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
switch (field.kind) {
|
|
@@ -76,12 +76,12 @@ function makeJsonFormatCommon(makeWriteField) {
|
|
|
76
76
|
continue;
|
|
77
77
|
}
|
|
78
78
|
if (!Array.isArray(jsonValue)) {
|
|
79
|
-
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON:
|
|
79
|
+
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`);
|
|
80
80
|
}
|
|
81
81
|
const targetArray = target[localName];
|
|
82
82
|
for (const jsonItem of jsonValue) {
|
|
83
83
|
if (jsonItem === null) {
|
|
84
|
-
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON:
|
|
84
|
+
throw new Error(`cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonItem)}`);
|
|
85
85
|
}
|
|
86
86
|
let val;
|
|
87
87
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- "map" is invalid for repeated fields
|
|
@@ -99,7 +99,7 @@ function makeJsonFormatCommon(makeWriteField) {
|
|
|
99
99
|
val = readScalar(field.T, jsonItem);
|
|
100
100
|
}
|
|
101
101
|
catch (e) {
|
|
102
|
-
let m = `cannot decode field ${type.typeName}.${field.name} from JSON:
|
|
102
|
+
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonItem)}`;
|
|
103
103
|
if (e instanceof Error && e.message.length > 0) {
|
|
104
104
|
m += `: ${e.message}`;
|
|
105
105
|
}
|
|
@@ -137,7 +137,7 @@ function makeJsonFormatCommon(makeWriteField) {
|
|
|
137
137
|
val = readScalar(field.V.T, jsonMapValue);
|
|
138
138
|
}
|
|
139
139
|
catch (e) {
|
|
140
|
-
let m = `cannot decode map value for field ${type.typeName}.${field.name} from JSON:
|
|
140
|
+
let m = `cannot decode map value for field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
|
|
141
141
|
if (e instanceof Error && e.message.length > 0) {
|
|
142
142
|
m += `: ${e.message}`;
|
|
143
143
|
}
|
|
@@ -155,7 +155,7 @@ function makeJsonFormatCommon(makeWriteField) {
|
|
|
155
155
|
: jsonMapKey).toString()] = val;
|
|
156
156
|
}
|
|
157
157
|
catch (e) {
|
|
158
|
-
let m = `cannot decode map key for field ${type.typeName}.${field.name} from JSON:
|
|
158
|
+
let m = `cannot decode map key for field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
|
|
159
159
|
if (e instanceof Error && e.message.length > 0) {
|
|
160
160
|
m += `: ${e.message}`;
|
|
161
161
|
}
|
|
@@ -190,7 +190,7 @@ function makeJsonFormatCommon(makeWriteField) {
|
|
|
190
190
|
target[localName] = readScalar(field.T, jsonValue);
|
|
191
191
|
}
|
|
192
192
|
catch (e) {
|
|
193
|
-
let m = `cannot decode field ${type.typeName}.${field.name} from JSON:
|
|
193
|
+
let m = `cannot decode field ${type.typeName}.${field.name} from JSON: ${this.debug(jsonValue)}`;
|
|
194
194
|
if (e instanceof Error && e.message.length > 0) {
|
|
195
195
|
m += `: ${e.message}`;
|
|
196
196
|
}
|
package/dist/cjs/proto-int64.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.protoInt64 = void 0;
|
|
17
|
+
const assert_js_1 = require("./private/assert.js");
|
|
17
18
|
const varint_js_1 = require("./google/varint.js");
|
|
18
19
|
function makeInt64Support() {
|
|
19
20
|
const dv = new DataView(new ArrayBuffer(8));
|
|
@@ -22,7 +23,10 @@ function makeInt64Support() {
|
|
|
22
23
|
typeof dv.getBigInt64 === "function" &&
|
|
23
24
|
typeof dv.getBigUint64 === "function" &&
|
|
24
25
|
typeof dv.setBigInt64 === "function" &&
|
|
25
|
-
typeof dv.setBigUint64 === "function"
|
|
26
|
+
typeof dv.setBigUint64 === "function" &&
|
|
27
|
+
(typeof process != "object" ||
|
|
28
|
+
typeof process.env != "object" ||
|
|
29
|
+
process.env.BUF_BIGINT_DISABLE !== "1");
|
|
26
30
|
if (ok) {
|
|
27
31
|
const MIN = BigInt("-9223372036854775808"), MAX = BigInt("9223372036854775807"), UMIN = BigInt("0"), UMAX = BigInt("18446744073709551615");
|
|
28
32
|
return {
|
|
@@ -68,65 +72,44 @@ function makeInt64Support() {
|
|
|
68
72
|
},
|
|
69
73
|
};
|
|
70
74
|
}
|
|
75
|
+
const assertInt64String = (value) => (0, assert_js_1.assert)(/^-?[0-9]+$/.test(value), `int64 invalid: ${value}`);
|
|
76
|
+
const assertUInt64String = (value) => (0, assert_js_1.assert)(/^[0-9]+$/.test(value), `uint64 invalid: ${value}`);
|
|
71
77
|
return {
|
|
72
78
|
zero: "0",
|
|
73
79
|
supported: false,
|
|
74
80
|
parse(value) {
|
|
75
|
-
if (
|
|
76
|
-
|
|
81
|
+
if (typeof value != "string") {
|
|
82
|
+
value = value.toString();
|
|
77
83
|
}
|
|
84
|
+
assertInt64String(value);
|
|
78
85
|
return value;
|
|
79
86
|
},
|
|
80
87
|
uParse(value) {
|
|
81
|
-
if (
|
|
82
|
-
|
|
88
|
+
if (typeof value != "string") {
|
|
89
|
+
value = value.toString();
|
|
83
90
|
}
|
|
91
|
+
assertUInt64String(value);
|
|
84
92
|
return value;
|
|
85
93
|
},
|
|
86
94
|
enc(value) {
|
|
87
|
-
if (typeof value
|
|
88
|
-
|
|
89
|
-
throw new Error(`int64 invalid: ${value}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
value = value.toString(10);
|
|
95
|
+
if (typeof value != "string") {
|
|
96
|
+
value = value.toString();
|
|
94
97
|
}
|
|
95
|
-
|
|
96
|
-
return
|
|
98
|
+
assertInt64String(value);
|
|
99
|
+
return (0, varint_js_1.int64FromString)(value);
|
|
97
100
|
},
|
|
98
101
|
uEnc(value) {
|
|
99
|
-
if (typeof value
|
|
100
|
-
|
|
101
|
-
throw new Error(`uint64 invalid: ${value}`);
|
|
102
|
-
}
|
|
102
|
+
if (typeof value != "string") {
|
|
103
|
+
value = value.toString();
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
const [minus, lo, hi] = (0, varint_js_1.int64fromString)(value);
|
|
108
|
-
if (minus) {
|
|
109
|
-
throw new Error(`uint64 invalid: ${value}`);
|
|
110
|
-
}
|
|
111
|
-
return { lo, hi };
|
|
105
|
+
assertUInt64String(value);
|
|
106
|
+
return (0, varint_js_1.int64FromString)(value);
|
|
112
107
|
},
|
|
113
108
|
dec(lo, hi) {
|
|
114
|
-
|
|
115
|
-
if (minus) {
|
|
116
|
-
// negate
|
|
117
|
-
hi = ~hi;
|
|
118
|
-
if (lo) {
|
|
119
|
-
lo = ~lo + 1;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
hi += 1;
|
|
123
|
-
}
|
|
124
|
-
return ("-" + (0, varint_js_1.int64toString)(lo, hi));
|
|
125
|
-
}
|
|
126
|
-
return (0, varint_js_1.int64toString)(lo, hi);
|
|
109
|
+
return (0, varint_js_1.int64ToString)(lo, hi);
|
|
127
110
|
},
|
|
128
111
|
uDec(lo, hi) {
|
|
129
|
-
return (0, varint_js_1.
|
|
112
|
+
return (0, varint_js_1.uInt64ToString)(lo, hi);
|
|
130
113
|
},
|
|
131
114
|
};
|
|
132
115
|
}
|