@bufbuild/protobuf 0.0.10 → 0.1.0

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.
Files changed (38) hide show
  1. package/dist/cjs/create-registry-from-desc.js +2 -112
  2. package/dist/cjs/create-registry.js +1 -1
  3. package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
  4. package/dist/cjs/google/protobuf/empty_pb.js +0 -1
  5. package/dist/cjs/google/protobuf/struct_pb.js +1 -1
  6. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  7. package/dist/cjs/google/varint.js +85 -37
  8. package/dist/cjs/index.js +1 -7
  9. package/dist/cjs/private/json-format-common.js +6 -6
  10. package/dist/cjs/proto-int64.js +23 -40
  11. package/dist/esm/create-registry-from-desc.js +1 -110
  12. package/dist/esm/create-registry.js +1 -1
  13. package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
  14. package/dist/esm/google/protobuf/empty_pb.js +0 -1
  15. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  16. package/dist/esm/google/protobuf/type_pb.js +1 -1
  17. package/dist/esm/google/varint.js +81 -34
  18. package/dist/esm/index.js +0 -3
  19. package/dist/esm/private/json-format-common.js +6 -6
  20. package/dist/esm/proto-int64.js +24 -41
  21. package/dist/types/create-registry-from-desc.d.ts +0 -34
  22. package/dist/types/create-registry.d.ts +1 -1
  23. package/dist/types/google/protobuf/descriptor_pb.d.ts +6 -6
  24. package/dist/types/google/protobuf/empty_pb.d.ts +0 -1
  25. package/dist/types/google/varint.d.ts +21 -9
  26. package/dist/types/index.d.ts +0 -3
  27. package/dist/types/message.d.ts +3 -1
  28. package/dist/types/proto-int64.d.ts +14 -13
  29. package/package.json +5 -9
  30. package/dist/cjs/legacy-descriptor-registry.js +0 -468
  31. package/dist/cjs/legacy-descriptor-set.js +0 -453
  32. package/dist/cjs/legacy-type-registry.js +0 -104
  33. package/dist/esm/legacy-descriptor-registry.js +0 -464
  34. package/dist/esm/legacy-descriptor-set.js +0 -449
  35. package/dist/esm/legacy-type-registry.js +0 -100
  36. package/dist/types/legacy-descriptor-registry.d.ts +0 -45
  37. package/dist/types/legacy-descriptor-set.d.ts +0 -152
  38. package/dist/types/legacy-type-registry.d.ts +0 -44
@@ -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.DescriptorRegistry = exports.createRegistryFromDescriptors = void 0;
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.input.typeName);
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":
@@ -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. Note that
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], ["qux", false] } represents
1173
- * "foo.(bar.baz).qux".
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
  */
@@ -25,7 +25,6 @@ const proto3_js_1 = require("../../proto3.js");
25
25
  * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
26
26
  * }
27
27
  *
28
- * The JSON representation for `Empty` is empty JSON object `{}`.
29
28
  *
30
29
  * @generated from message google.protobuf.Empty
31
30
  */
@@ -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.0.10 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.1.0 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.0.10 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v0.1.0 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.int64toString = exports.int64fromString = exports.varint64write = exports.varint64read = void 0;
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 = (1 << 16) * (1 << 16);
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
- * Returns tuple:
120
- * [0]: minus sign?
121
- * [1]: low bits
122
- * [2]: high bits
119
+ * Copyright 2008 Google Inc. All rights reserved.
123
120
  *
124
- * Copyright 2008 Google Inc.
121
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
125
122
  */
126
- function int64fromString(dec) {
123
+ function int64FromString(dec) {
127
124
  // Check for minus sign.
128
- let minus = dec[0] == "-";
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 [minus, lowBits, highBits];
150
+ return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
153
151
  }
154
- exports.int64fromString = int64fromString;
152
+ exports.int64FromString = int64FromString;
155
153
  /**
156
- * Format 64 bit integer value (as two JS numbers) to decimal string.
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
- * Copyright 2008 Google Inc.
179
+ * See https://github.com/protocolbuffers/protobuf-javascript/blob/a428c58273abad07c66071d9753bc4d1289de426/experimental/runtime/int64.js#L10
159
180
  */
160
- function int64toString(bitsLow, bitsHigh) {
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
- if (bitsHigh <= 0x1fffff) {
164
- return "" + (TWO_PWR_32_DBL * bitsHigh + bitsLow);
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
- let low = bitsLow & 0xffffff;
176
- let mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xffffff;
177
- let high = (bitsHigh >> 16) & 0xffff;
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
- let base = 10000000;
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
- // Convert base-1e7 digits to base-10, with optional leading zeroes.
195
- function decimalFrom1e7(digit1e7, needLeadingZeros) {
196
- let partial = digit1e7 ? String(digit1e7) : "";
197
- if (needLeadingZeros) {
198
- return "0000000".slice(partial.length) + partial;
199
- }
200
- return partial;
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 (decimalFrom1e7(digitC, /*needLeadingZeros=*/ 0) +
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
- exports.int64toString = int64toString;
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.TypeRegistry = exports.LegacyDescriptorSet = exports.LegacyDescriptorRegistry = 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;
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);
@@ -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: "${this.debug(jsonValue)}"`);
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: "${this.debug(jsonItem)}"`);
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: "${this.debug(jsonItem)}"`;
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: "${this.debug(jsonValue)}"`;
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: "${this.debug(jsonValue)}"`;
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: "${this.debug(jsonValue)}"`;
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
  }
@@ -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 (!/^-?[0-9]+$/.test(value)) {
76
- throw new Error(`int64 invalid: ${value}`);
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 (!/^-?[0-9]+$/.test(value)) {
82
- throw new Error(`uint64 invalid: ${value}`);
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 == "string") {
88
- if (!/^-?[0-9]+$/.test(value)) {
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
- const [, lo, hi] = (0, varint_js_1.int64fromString)(value);
96
- return { lo, hi };
98
+ assertInt64String(value);
99
+ return (0, varint_js_1.int64FromString)(value);
97
100
  },
98
101
  uEnc(value) {
99
- if (typeof value == "string") {
100
- if (!/^-?[0-9]+$/.test(value)) {
101
- throw new Error(`uint64 invalid: ${value}`);
102
- }
102
+ if (typeof value != "string") {
103
+ value = value.toString();
103
104
  }
104
- else {
105
- value = value.toString(10);
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
- const minus = (hi & 0x80000000) !== 0;
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.int64toString)(lo, hi);
112
+ return (0, varint_js_1.uInt64ToString)(lo, hi);
130
113
  },
131
114
  };
132
115
  }
@@ -135,7 +135,7 @@ export function createRegistryFromDescriptors(input, replaceWkt = true) {
135
135
  const methods = {};
136
136
  for (const method of desc.methods) {
137
137
  const I = this.findMessage(method.input.typeName);
138
- const O = this.findMessage(method.input.typeName);
138
+ const O = this.findMessage(method.output.typeName);
139
139
  assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
140
140
  assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
141
141
  const m = {
@@ -156,115 +156,6 @@ export function createRegistryFromDescriptors(input, replaceWkt = true) {
156
156
  },
157
157
  };
158
158
  }
159
- /**
160
- * DescriptorRegistry is a type registry that dynamically creates types
161
- * from a set of google.protobuf.FileDescriptorProto.
162
- *
163
- * By default, all well-known types with a specialized JSON representation
164
- * are replaced with their generated counterpart in this package.
165
- */
166
- export class DescriptorRegistry {
167
- constructor(descriptorSet, replaceWkt = true) {
168
- this.enums = {};
169
- this.messages = {};
170
- this.services = {};
171
- this.desc = descriptorSet;
172
- if (replaceWkt) {
173
- for (const mt of wkMessages) {
174
- this.messages[mt.typeName] = mt;
175
- }
176
- for (const et of wkEnums) {
177
- this.enums[et.typeName] = et;
178
- }
179
- }
180
- }
181
- /**
182
- * Conveniently create a DescriptorRegistry from a FileDescriptorSet,
183
- * or a FileDescriptorSet in binary format.
184
- */
185
- static fromFileDescriptorSet(input) {
186
- return new DescriptorRegistry(createDescriptorSet(input));
187
- }
188
- /**
189
- * May raise an error on invalid descriptors.
190
- */
191
- findEnum(typeName) {
192
- const existing = this.enums[typeName];
193
- if (existing) {
194
- return existing;
195
- }
196
- const desc = this.desc.enums.get(typeName);
197
- if (!desc) {
198
- return undefined;
199
- }
200
- const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
201
- const type = runtime.makeEnumType(typeName, desc.values.map((u) => ({
202
- no: u.number,
203
- name: u.name,
204
- localName: localName(u),
205
- })), {});
206
- this.enums[typeName] = type;
207
- return type;
208
- }
209
- /**
210
- * May raise an error on invalid descriptors.
211
- */
212
- findMessage(typeName) {
213
- const existing = this.messages[typeName];
214
- if (existing) {
215
- return existing;
216
- }
217
- const desc = this.desc.messages.get(typeName);
218
- if (!desc) {
219
- return undefined;
220
- }
221
- const runtime = desc.file.syntax == "proto3" ? proto3 : proto2;
222
- const fields = [];
223
- const type = runtime.makeMessageType(typeName, () => fields, {
224
- localName: localName(desc),
225
- });
226
- this.messages[typeName] = type;
227
- for (const field of desc.fields) {
228
- const fieldInfo = makeFieldInfo(field, this);
229
- fields.push(fieldInfo);
230
- }
231
- return type;
232
- }
233
- /**
234
- * May raise an error on invalid descriptors.
235
- */
236
- findService(typeName) {
237
- const existing = this.services[typeName];
238
- if (existing) {
239
- return existing;
240
- }
241
- const desc = this.desc.services.get(typeName);
242
- if (!desc) {
243
- return undefined;
244
- }
245
- const methods = {};
246
- for (const method of desc.methods) {
247
- const I = this.findMessage(method.input.typeName);
248
- const O = this.findMessage(method.input.typeName);
249
- assert(I, `message "${method.input.typeName}" for ${method.toString()} not found`);
250
- assert(O, `output message "${method.output.typeName}" for ${method.toString()} not found`);
251
- const m = {
252
- name: method.name,
253
- localName: localName(method),
254
- I,
255
- O,
256
- kind: method.methodKind,
257
- idempotency: method.idempotency,
258
- options: {},
259
- };
260
- methods[m.localName] = m;
261
- }
262
- return (this.services[typeName] = {
263
- typeName: desc.typeName,
264
- methods,
265
- });
266
- }
267
- }
268
159
  function makeFieldInfo(desc, resolver) {
269
160
  switch (desc.kind) {
270
161
  case "map_field":