@bufbuild/protobuf 2.2.4 → 2.3.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 (70) hide show
  1. package/dist/cjs/clone.js +4 -6
  2. package/dist/cjs/codegenv1/boot.js +1 -1
  3. package/dist/cjs/codegenv1/embed.js +0 -1
  4. package/dist/cjs/codegenv1/file.js +1 -1
  5. package/dist/cjs/codegenv1/symbols.js +1 -1
  6. package/dist/cjs/create.js +0 -1
  7. package/dist/cjs/equals.js +2 -1
  8. package/dist/cjs/extensions.js +3 -3
  9. package/dist/cjs/from-binary.js +5 -3
  10. package/dist/cjs/from-json.js +8 -10
  11. package/dist/cjs/proto-int64.js +4 -1
  12. package/dist/cjs/reflect/guard.js +2 -1
  13. package/dist/cjs/reflect/index.d.ts +1 -0
  14. package/dist/cjs/reflect/index.js +1 -0
  15. package/dist/cjs/reflect/names.d.ts +8 -0
  16. package/dist/cjs/reflect/names.js +28 -0
  17. package/dist/cjs/reflect/path.d.ts +107 -0
  18. package/dist/cjs/reflect/path.js +376 -0
  19. package/dist/cjs/reflect/reflect-check.js +3 -3
  20. package/dist/cjs/reflect/reflect-types.d.ts +1 -1
  21. package/dist/cjs/reflect/reflect.js +9 -7
  22. package/dist/cjs/reflect/scalar.js +4 -5
  23. package/dist/cjs/reflect/unsafe.d.ts +3 -6
  24. package/dist/cjs/reflect/unsafe.js +11 -10
  25. package/dist/cjs/registry.js +17 -25
  26. package/dist/cjs/to-binary.js +1 -1
  27. package/dist/cjs/to-json.d.ts +6 -0
  28. package/dist/cjs/to-json.js +16 -18
  29. package/dist/cjs/wire/base64-encoding.js +4 -3
  30. package/dist/cjs/wire/binary-encoding.js +7 -6
  31. package/dist/cjs/wire/text-encoding.js +1 -1
  32. package/dist/cjs/wire/text-format.js +3 -4
  33. package/dist/cjs/wire/varint.js +0 -1
  34. package/dist/cjs/wkt/timestamp.js +3 -2
  35. package/dist/esm/clone.js +4 -6
  36. package/dist/esm/codegenv1/boot.js +1 -1
  37. package/dist/esm/codegenv1/embed.js +0 -1
  38. package/dist/esm/codegenv1/file.js +1 -1
  39. package/dist/esm/codegenv1/symbols.js +1 -1
  40. package/dist/esm/create.js +0 -2
  41. package/dist/esm/equals.js +2 -1
  42. package/dist/esm/extensions.js +3 -3
  43. package/dist/esm/from-binary.js +5 -3
  44. package/dist/esm/from-json.js +8 -10
  45. package/dist/esm/proto-int64.js +4 -1
  46. package/dist/esm/reflect/guard.js +2 -1
  47. package/dist/esm/reflect/index.d.ts +1 -0
  48. package/dist/esm/reflect/index.js +1 -0
  49. package/dist/esm/reflect/names.d.ts +8 -0
  50. package/dist/esm/reflect/names.js +27 -0
  51. package/dist/esm/reflect/path.d.ts +107 -0
  52. package/dist/esm/reflect/path.js +369 -0
  53. package/dist/esm/reflect/reflect-check.js +3 -3
  54. package/dist/esm/reflect/reflect-types.d.ts +1 -1
  55. package/dist/esm/reflect/reflect-types.js +0 -1
  56. package/dist/esm/reflect/reflect.js +9 -7
  57. package/dist/esm/reflect/scalar.js +4 -5
  58. package/dist/esm/reflect/unsafe.d.ts +3 -6
  59. package/dist/esm/reflect/unsafe.js +11 -10
  60. package/dist/esm/registry.js +17 -25
  61. package/dist/esm/to-binary.js +1 -1
  62. package/dist/esm/to-json.d.ts +6 -0
  63. package/dist/esm/to-json.js +16 -18
  64. package/dist/esm/wire/base64-encoding.js +4 -3
  65. package/dist/esm/wire/binary-encoding.js +7 -6
  66. package/dist/esm/wire/text-encoding.js +1 -1
  67. package/dist/esm/wire/text-format.js +3 -4
  68. package/dist/esm/wire/varint.js +0 -1
  69. package/dist/esm/wkt/timestamp.js +3 -2
  70. package/package.json +9 -24
@@ -65,7 +65,6 @@ function createFileRegistry(...args) {
65
65
  const input = args[0];
66
66
  const resolve = args[1];
67
67
  const seen = new Set();
68
- // eslint-disable-next-line no-inner-declarations
69
68
  function recurseDeps(file) {
70
69
  const deps = [];
71
70
  for (const protoFileName of file.dependency) {
@@ -121,13 +120,11 @@ function createBaseRegistry() {
121
120
  },
122
121
  addFile(file, skipTypes, withDeps) {
123
122
  files.set(file.proto.name, file);
124
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
125
123
  if (!skipTypes) {
126
124
  for (const type of (0, nested_types_js_1.nestedTypes)(file)) {
127
125
  this.add(type);
128
126
  }
129
127
  }
130
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
131
128
  if (withDeps) {
132
129
  for (const f of file.dependencies) {
133
130
  this.addFile(f, skipTypes, withDeps);
@@ -138,7 +135,9 @@ function createBaseRegistry() {
138
135
  if (desc.kind == "extension") {
139
136
  let numberToExt = extendees.get(desc.extendee.typeName);
140
137
  if (!numberToExt) {
141
- extendees.set(desc.extendee.typeName, (numberToExt = new Map()));
138
+ extendees.set(desc.extendee.typeName,
139
+ // biome-ignore lint/suspicious/noAssignInExpressions: no
140
+ (numberToExt = new Map()));
142
141
  }
143
142
  numberToExt.set(desc.number, desc);
144
143
  }
@@ -228,7 +227,7 @@ const PACKED = 1;
228
227
  const DELIMITED = 2;
229
228
  // bootstrap-inject google.protobuf.FeatureSet.EnumType.OPEN: const $name: FeatureSet_EnumType.$localName = $number;
230
229
  const OPEN = 1;
231
- // prettier-ignore
230
+ // biome-ignore format: want this to read well
232
231
  // bootstrap-inject defaults: EDITION_PROTO2 to EDITION_2023: export const minimumEdition: SupportedEdition = $minimumEdition, maximumEdition: SupportedEdition = $maximumEdition;
233
232
  // generated from protoc v30.0
234
233
  exports.minimumEdition = 998, exports.maximumEdition = 1000;
@@ -377,7 +376,7 @@ function addFields(message, reg, mapEntries) {
377
376
  * parent type, if any.
378
377
  */
379
378
  function addEnum(proto, file, parent, reg) {
380
- var _a, _b, _c;
379
+ var _a, _b, _c, _d, _e;
381
380
  const sharedPrefix = findEnumSharedPrefix(proto.name, proto.value);
382
381
  const desc = {
383
382
  kind: "enum",
@@ -397,25 +396,26 @@ function addEnum(proto, file, parent, reg) {
397
396
  };
398
397
  desc.open = isEnumOpen(desc);
399
398
  reg.add(desc);
400
- proto.value.forEach((proto) => {
401
- var _a, _b;
402
- const name = proto.name;
403
- desc.values.push((desc.value[proto.number] = {
399
+ for (const p of proto.value) {
400
+ const name = p.name;
401
+ desc.values.push(
402
+ // biome-ignore lint/suspicious/noAssignInExpressions: no
403
+ (desc.value[p.number] = {
404
404
  kind: "enum_value",
405
- proto,
406
- deprecated: (_b = (_a = proto.options) === null || _a === void 0 ? void 0 : _a.deprecated) !== null && _b !== void 0 ? _b : false,
405
+ proto: p,
406
+ deprecated: (_d = (_c = proto.options) === null || _c === void 0 ? void 0 : _c.deprecated) !== null && _d !== void 0 ? _d : false,
407
407
  parent: desc,
408
408
  name,
409
409
  localName: (0, names_js_1.safeObjectProperty)(sharedPrefix == undefined
410
410
  ? name
411
411
  : name.substring(sharedPrefix.length)),
412
- number: proto.number,
412
+ number: p.number,
413
413
  toString() {
414
414
  return `enum value ${desc.typeName}.${name}`;
415
415
  },
416
416
  }));
417
- });
418
- ((_c = parent === null || parent === void 0 ? void 0 : parent.nestedEnums) !== null && _c !== void 0 ? _c : file.enums).push(desc);
417
+ }
418
+ ((_e = parent === null || parent === void 0 ? void 0 : parent.nestedEnums) !== null && _e !== void 0 ? _e : file.enums).push(desc);
419
419
  }
420
420
  /**
421
421
  * Create a descriptor for a message, including nested types, and add it to our
@@ -617,14 +617,12 @@ function newField(proto, parentOrFile, reg, oneof, mapEntries) {
617
617
  case TYPE_GROUP:
618
618
  field.listKind = "message";
619
619
  field.message = reg.getMessage(trimLeadingDot(proto.typeName));
620
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
621
620
  assert(field.message);
622
621
  field.delimitedEncoding = isDelimitedEncoding(proto, parentOrFile);
623
622
  break;
624
623
  case TYPE_ENUM:
625
624
  field.listKind = "enum";
626
625
  field.enum = reg.getEnum(trimLeadingDot(proto.typeName));
627
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
628
626
  assert(field.enum);
629
627
  break;
630
628
  default:
@@ -642,9 +640,7 @@ function newField(proto, parentOrFile, reg, oneof, mapEntries) {
642
640
  case TYPE_GROUP:
643
641
  field.fieldKind = "message";
644
642
  field.message = reg.getMessage(trimLeadingDot(proto.typeName));
645
- assert(
646
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
647
- field.message, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
643
+ assert(field.message, `invalid FieldDescriptorProto: type_name ${proto.typeName} not found`);
648
644
  field.delimitedEncoding = isDelimitedEncoding(proto, parentOrFile);
649
645
  field.getDefaultValue = () => undefined;
650
646
  break;
@@ -781,9 +777,7 @@ function findOneof(proto, allOneofs) {
781
777
  return undefined;
782
778
  }
783
779
  const oneof = allOneofs[proto.oneofIndex];
784
- assert(
785
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
786
- oneof, `invalid FieldDescriptorProto: oneof #${proto.oneofIndex} for field #${proto.number} not found`);
780
+ assert(oneof, `invalid FieldDescriptorProto: oneof #${proto.oneofIndex} for field #${proto.number} not found`);
787
781
  return oneof;
788
782
  }
789
783
  /**
@@ -820,7 +814,6 @@ function isPackedField(proto, parent) {
820
814
  if (proto.label != LABEL_REPEATED) {
821
815
  return false;
822
816
  }
823
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
824
817
  switch (proto.type) {
825
818
  case TYPE_STRING:
826
819
  case TYPE_BYTES:
@@ -907,7 +900,6 @@ function resolveFeature(name, ref) {
907
900
  * Assert that condition is truthy or throw error (with message)
908
901
  */
909
902
  function assert(condition, msg) {
910
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
911
903
  if (!condition) {
912
904
  throw new Error(msg);
913
905
  }
@@ -35,7 +35,7 @@ function writeFields(writer, opts, msg) {
35
35
  for (const f of msg.sortedFields) {
36
36
  if (!msg.isSet(f)) {
37
37
  if (f.presence == LEGACY_REQUIRED) {
38
- throw new Error(`cannot encode field ${msg.desc.typeName}.${f.name} to binary: required field not set`);
38
+ throw new Error(`cannot encode ${f} to binary: required field not set`);
39
39
  }
40
40
  continue;
41
41
  }
@@ -38,6 +38,12 @@ export interface JsonWriteOptions {
38
38
  * Options for serializing to JSON.
39
39
  */
40
40
  export interface JsonWriteStringOptions extends JsonWriteOptions {
41
+ /**
42
+ * Format JSON with indentation. Indicates the number of space characters to
43
+ * be used as indentation.
44
+ *
45
+ * This option is passed to JSON.stringify as `space`.
46
+ */
41
47
  prettySpaces: number;
42
48
  }
43
49
  /**
@@ -24,7 +24,6 @@ const wrappers_js_1 = require("./wkt/wrappers.js");
24
24
  const index_js_2 = require("./wire/index.js");
25
25
  const extensions_js_1 = require("./extensions.js");
26
26
  const reflect_check_js_1 = require("./reflect/reflect-check.js");
27
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
28
27
  // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name: FeatureSet_FieldPresence.$localName = $number;
29
28
  const LEGACY_REQUIRED = 3;
30
29
  // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
@@ -63,7 +62,7 @@ function enumToJson(descEnum, value) {
63
62
  }
64
63
  const name = (_a = descEnum.value[value]) === null || _a === void 0 ? void 0 : _a.name;
65
64
  if (name === undefined) {
66
- throw new Error(`${String(value)} is not a value in ${descEnum.toString()}`);
65
+ throw new Error(`${value} is not a value in ${descEnum}`);
67
66
  }
68
67
  return name;
69
68
  }
@@ -76,7 +75,7 @@ function reflectToJson(msg, opts) {
76
75
  for (const f of msg.sortedFields) {
77
76
  if (!msg.isSet(f)) {
78
77
  if (f.presence == LEGACY_REQUIRED) {
79
- throw new Error(`cannot encode field ${msg.desc.typeName}.${f.name} to JSON: required field not set`);
78
+ throw new Error(`cannot encode ${f} to JSON: required field not set`);
80
79
  }
81
80
  if (!opts.alwaysEmitImplicit || f.presence !== IMPLICIT) {
82
81
  // Fields with implicit presence omit zero values (e.g. empty string) by default
@@ -90,21 +89,21 @@ function reflectToJson(msg, opts) {
90
89
  }
91
90
  if (opts.registry) {
92
91
  const tagSeen = new Set();
93
- for (const uf of (_a = msg.getUnknown()) !== null && _a !== void 0 ? _a : []) {
92
+ for (const { no } of (_a = msg.getUnknown()) !== null && _a !== void 0 ? _a : []) {
94
93
  // Same tag can appear multiple times, so we
95
94
  // keep track and skip identical ones.
96
- if (tagSeen.has(uf.no)) {
97
- continue;
98
- }
99
- const extension = opts.registry.getExtensionFor(msg.desc, uf.no);
100
- if (!extension) {
101
- continue;
102
- }
103
- const value = (0, extensions_js_1.getExtension)(msg.message, extension);
104
- const [container, field] = (0, extensions_js_1.createExtensionContainer)(extension, value);
105
- const jsonValue = fieldToJson(field, container.get(field), opts);
106
- if (jsonValue !== undefined) {
107
- json[extension.jsonName] = jsonValue;
95
+ if (!tagSeen.has(no)) {
96
+ tagSeen.add(no);
97
+ const extension = opts.registry.getExtensionFor(msg.desc, no);
98
+ if (!extension) {
99
+ continue;
100
+ }
101
+ const value = (0, extensions_js_1.getExtension)(msg.message, extension);
102
+ const [container, field] = (0, extensions_js_1.createExtensionContainer)(extension, value);
103
+ const jsonValue = fieldToJson(field, container.get(field), opts);
104
+ if (jsonValue !== undefined) {
105
+ json[extension.jsonName] = jsonValue;
106
+ }
108
107
  }
109
108
  }
110
109
  }
@@ -202,7 +201,7 @@ function scalarToJson(field, value) {
202
201
  if (typeof value != "number") {
203
202
  throw new Error(`cannot encode ${field} to JSON: ${(_b = (0, reflect_check_js_1.checkField)(field, value)) === null || _b === void 0 ? void 0 : _b.message}`);
204
203
  }
205
- if (isNaN(value))
204
+ if (Number.isNaN(value))
206
205
  return "NaN";
207
206
  if (value === Number.POSITIVE_INFINITY)
208
207
  return "Infinity";
@@ -322,7 +321,6 @@ function durationToJson(val) {
322
321
  function fieldMaskToJson(val) {
323
322
  return val.paths
324
323
  .map((p) => {
325
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
326
324
  if (p.match(/_[0-9]?_/g) || p.match(/[A-Z]/g)) {
327
325
  throw new Error(`cannot encode message ${val.$typeName} to JSON: lowerCamelCase of path name "` +
328
326
  p +
@@ -15,7 +15,6 @@
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.base64Decode = base64Decode;
17
17
  exports.base64Encode = base64Encode;
18
- /* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unnecessary-condition, prefer-const */
19
18
  /**
20
19
  * Decodes a base64 string to a byte array.
21
20
  *
@@ -46,7 +45,6 @@ function base64Decode(base64Str) {
46
45
  // @ts-expect-error TS7029: Fallthrough case in switch
47
46
  case "=":
48
47
  groupPos = 0; // reset state when padding found
49
- // eslint-disable-next-line no-fallthrough
50
48
  case "\n":
51
49
  case "\r":
52
50
  case "\t":
@@ -139,7 +137,10 @@ function getEncodeTable(encoding) {
139
137
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
140
138
  encodeTableUrl = encodeTableStd.slice(0, -2).concat("-", "_");
141
139
  }
142
- return encoding == "url" ? encodeTableUrl : encodeTableStd;
140
+ return encoding == "url"
141
+ ? // biome-ignore lint/style/noNonNullAssertion: TS fails to narrow down
142
+ encodeTableUrl
143
+ : encodeTableStd;
143
144
  }
144
145
  function getDecodeTable() {
145
146
  if (!decodeTable) {
@@ -17,7 +17,6 @@ exports.BinaryReader = exports.BinaryWriter = exports.INT32_MIN = exports.INT32_
17
17
  const varint_js_1 = require("./varint.js");
18
18
  const proto_int64_js_1 = require("../proto-int64.js");
19
19
  const text_encoding_js_1 = require("./text-encoding.js");
20
- /* eslint-disable prefer-const,no-case-declarations,@typescript-eslint/restrict-plus-operands */
21
20
  /**
22
21
  * Protobuf binary format wire types.
23
22
  *
@@ -278,7 +277,7 @@ class BinaryWriter {
278
277
  * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
279
278
  */
280
279
  sint64(value) {
281
- let tc = proto_int64_js_1.protoInt64.enc(value),
280
+ const tc = proto_int64_js_1.protoInt64.enc(value),
282
281
  // zigzag encode
283
282
  sign = tc.hi >> 31, lo = (tc.lo << 1) ^ sign, hi = ((tc.hi << 1) | (tc.lo >>> 31)) ^ sign;
284
283
  (0, varint_js_1.varint64write)(lo, hi, this.buf);
@@ -288,7 +287,7 @@ class BinaryWriter {
288
287
  * Write a `uint64` value, an unsigned 64-bit varint.
289
288
  */
290
289
  uint64(value) {
291
- let tc = proto_int64_js_1.protoInt64.uEnc(value);
290
+ const tc = proto_int64_js_1.protoInt64.uEnc(value);
292
291
  (0, varint_js_1.varint64write)(tc.lo, tc.hi, this.buf);
293
292
  return this;
294
293
  }
@@ -330,11 +329,9 @@ class BinaryReader {
330
329
  // ignore
331
330
  }
332
331
  break;
333
- // eslint-disable-next-line
334
332
  // @ts-expect-error TS7029: Fallthrough case in switch
335
333
  case WireType.Bit64:
336
334
  this.pos += 4;
337
- // eslint-disable-next-line no-fallthrough
338
335
  case WireType.Bit32:
339
336
  this.pos += 4;
340
337
  break;
@@ -415,12 +412,14 @@ class BinaryReader {
415
412
  * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
416
413
  */
417
414
  fixed32() {
415
+ // biome-ignore lint/suspicious/noAssignInExpressions: no
418
416
  return this.view.getUint32((this.pos += 4) - 4, true);
419
417
  }
420
418
  /**
421
419
  * Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
422
420
  */
423
421
  sfixed32() {
422
+ // biome-ignore lint/suspicious/noAssignInExpressions: no
424
423
  return this.view.getInt32((this.pos += 4) - 4, true);
425
424
  }
426
425
  /**
@@ -439,12 +438,14 @@ class BinaryReader {
439
438
  * Read a `float` field, 32-bit floating point number.
440
439
  */
441
440
  float() {
441
+ // biome-ignore lint/suspicious/noAssignInExpressions: no
442
442
  return this.view.getFloat32((this.pos += 4) - 4, true);
443
443
  }
444
444
  /**
445
445
  * Read a `double` field, a 64-bit floating point number.
446
446
  */
447
447
  double() {
448
+ // biome-ignore lint/suspicious/noAssignInExpressions: no
448
449
  return this.view.getFloat64((this.pos += 8) - 8, true);
449
450
  }
450
451
  /**
@@ -501,7 +502,7 @@ function assertFloat32(arg) {
501
502
  if (typeof arg == "string") {
502
503
  const o = arg;
503
504
  arg = Number(arg);
504
- if (isNaN(arg) && o !== "NaN") {
505
+ if (Number.isNaN(arg) && o !== "NaN") {
505
506
  throw new Error("invalid float32: " + o);
506
507
  }
507
508
  }
@@ -44,7 +44,7 @@ function getTextEncoding() {
44
44
  encodeURIComponent(text);
45
45
  return true;
46
46
  }
47
- catch (e) {
47
+ catch (_) {
48
48
  return false;
49
49
  }
50
50
  },
@@ -17,7 +17,6 @@ exports.parseTextFormatEnumValue = parseTextFormatEnumValue;
17
17
  exports.parseTextFormatScalarValue = parseTextFormatScalarValue;
18
18
  const descriptors_js_1 = require("../descriptors.js");
19
19
  const proto_int64_js_1 = require("../proto-int64.js");
20
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
21
20
  /**
22
21
  * Parse an enum value from the Protobuf text format.
23
22
  *
@@ -140,7 +139,7 @@ function unescapeBytesDefaultValue(str) {
140
139
  return false;
141
140
  }
142
141
  const n = parseInt(s + t, 8);
143
- if (isNaN(n)) {
142
+ if (Number.isNaN(n)) {
144
143
  return false;
145
144
  }
146
145
  b.push(n);
@@ -153,7 +152,7 @@ function unescapeBytesDefaultValue(str) {
153
152
  return false;
154
153
  }
155
154
  const n = parseInt(s + t, 16);
156
- if (isNaN(n)) {
155
+ if (Number.isNaN(n)) {
157
156
  return false;
158
157
  }
159
158
  b.push(n);
@@ -166,7 +165,7 @@ function unescapeBytesDefaultValue(str) {
166
165
  return false;
167
166
  }
168
167
  const n = parseInt(s + t, 16);
169
- if (isNaN(n)) {
168
+ if (Number.isNaN(n)) {
170
169
  return false;
171
170
  }
172
171
  const chunk = new Uint8Array(4);
@@ -39,7 +39,6 @@ exports.int64ToString = int64ToString;
39
39
  exports.uInt64ToString = uInt64ToString;
40
40
  exports.varint32write = varint32write;
41
41
  exports.varint32read = varint32read;
42
- /* eslint-disable prefer-const,@typescript-eslint/restrict-plus-operands */
43
42
  /**
44
43
  * Read a 64 bit varint as two JS numbers.
45
44
  *
@@ -43,9 +43,10 @@ function timestampDate(timestamp) {
43
43
  * Create a google.protobuf.Timestamp message from a Unix timestamp in milliseconds.
44
44
  */
45
45
  function timestampFromMs(timestampMs) {
46
+ const seconds = Math.floor(timestampMs / 1000);
46
47
  return (0, create_js_1.create)(timestamp_pb_js_1.TimestampSchema, {
47
- seconds: proto_int64_js_1.protoInt64.parse(Math.floor(timestampMs / 1000)),
48
- nanos: (timestampMs % 1000) * 1000000,
48
+ seconds: proto_int64_js_1.protoInt64.parse(seconds),
49
+ nanos: (timestampMs - seconds * 1000) * 1000000,
49
50
  });
50
51
  }
51
52
  /**
package/dist/esm/clone.js CHANGED
@@ -27,24 +27,22 @@ function cloneReflect(i) {
27
27
  continue;
28
28
  }
29
29
  switch (f.fieldKind) {
30
- default: {
31
- o.set(f, cloneSingular(f, i.get(f)));
32
- break;
33
- }
34
30
  case "list":
35
- // eslint-disable-next-line no-case-declarations
36
31
  const list = o.get(f);
37
32
  for (const item of i.get(f)) {
38
33
  list.add(cloneSingular(f, item));
39
34
  }
40
35
  break;
41
36
  case "map":
42
- // eslint-disable-next-line no-case-declarations
43
37
  const map = o.get(f);
44
38
  for (const entry of i.get(f).entries()) {
45
39
  map.set(entry[0], cloneSingular(f, entry[1]));
46
40
  }
47
41
  break;
42
+ default: {
43
+ o.set(f, cloneSingular(f, i.get(f)));
44
+ break;
45
+ }
48
46
  }
49
47
  }
50
48
  const unknown = i.getUnknown();
@@ -25,7 +25,7 @@ export function boot(boot) {
25
25
  const root = bootFileDescriptorProto(boot);
26
26
  root.messageType.forEach(restoreJsonNames);
27
27
  const reg = createFileRegistry(root, () => undefined);
28
- // non-null assertion because we just created the registry from the file we look up
28
+ // biome-ignore lint/style/noNonNullAssertion: non-null assertion because we just created the registry from the file we look up
29
29
  return reg.getFile(root.name);
30
30
  }
31
31
  /**
@@ -230,7 +230,6 @@ function createEnumDescriptorBoot(proto) {
230
230
  * Assert that condition is truthy or throw error.
231
231
  */
232
232
  function assert(condition) {
233
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -- we want the implicit conversion to boolean
234
233
  if (!condition) {
235
234
  throw new Error();
236
235
  }
@@ -27,6 +27,6 @@ export function fileDesc(b64, imports) {
27
27
  root.messageType.forEach(restoreJsonNames);
28
28
  root.dependency = (_a = imports === null || imports === void 0 ? void 0 : imports.map((f) => f.proto.name)) !== null && _a !== void 0 ? _a : [];
29
29
  const reg = createFileRegistry(root, (protoFileName) => imports === null || imports === void 0 ? void 0 : imports.find((f) => f.proto.name === protoFileName));
30
- // non-null assertion because we just created the registry from the file we look up
30
+ // biome-ignore lint/style/noNonNullAssertion: non-null assertion because we just created the registry from the file we look up
31
31
  return reg.getFile(root.name);
32
32
  }
@@ -35,7 +35,7 @@ export const wktPublicImportPaths = {
35
35
  /**
36
36
  * @private
37
37
  */
38
- // prettier-ignore
38
+ // biome-ignore format: want this to read well
39
39
  export const symbols = {
40
40
  isMessage: { typeOnly: false, bootstrapWktFrom: "../../is-message.js", from: packageName },
41
41
  Message: { typeOnly: true, bootstrapWktFrom: "../../types.js", from: packageName },
@@ -14,7 +14,6 @@
14
14
  import { isMessage } from "./is-message.js";
15
15
  import { ScalarType, } from "./descriptors.js";
16
16
  import { scalarZeroValue } from "./reflect/scalar.js";
17
- import { FieldError } from "./reflect/error.js";
18
17
  import { isObject } from "./reflect/guard.js";
19
18
  import { unsafeGet, unsafeOneofCase, unsafeSet } from "./reflect/unsafe.js";
20
19
  import { isWrapperDesc } from "./wkt/wrappers.js";
@@ -62,7 +61,6 @@ function initMessage(messageDesc, message, init) {
62
61
  else {
63
62
  field = member;
64
63
  }
65
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check -- no need to convert enum
66
64
  switch (field.fieldKind) {
67
65
  case "message":
68
66
  value = toMessage(field, value);
@@ -162,7 +162,8 @@ function unknownEquals(a, b, registry) {
162
162
  return false;
163
163
  }
164
164
  for (let i = 0; i < unknownA.length; i++) {
165
- const a = unknownA[i], b = unknownB[i];
165
+ const a = unknownA[i];
166
+ const b = unknownB[i];
166
167
  if (a.no != b.no) {
167
168
  return false;
168
169
  }
@@ -38,7 +38,7 @@ export function getExtension(message, extension) {
38
38
  const [container, field, get] = createExtensionContainer(extension);
39
39
  for (const uf of ufs) {
40
40
  readField(container, new BinaryReader(uf.data), field, uf.wireType, {
41
- readUnknownFields: false,
41
+ readUnknownFields: true,
42
42
  });
43
43
  }
44
44
  return get();
@@ -55,7 +55,7 @@ export function setExtension(message, extension, value) {
55
55
  const ufs = ((_a = message.$unknown) !== null && _a !== void 0 ? _a : []).filter((uf) => uf.no !== extension.number);
56
56
  const [container, field] = createExtensionContainer(extension, value);
57
57
  const writer = new BinaryWriter();
58
- writeField(writer, { writeUnknownFields: false }, container, field);
58
+ writeField(writer, { writeUnknownFields: true }, container, field);
59
59
  const reader = new BinaryReader(writer.finish());
60
60
  while (reader.pos < reader.len) {
61
61
  const [no, wireType] = reader.tag();
@@ -142,7 +142,7 @@ export function createExtensionContainer(extension, value) {
142
142
  () => {
143
143
  const value = container[localName];
144
144
  if (value === undefined) {
145
- // Only message fields are undefined, rest will have a zero value.
145
+ // biome-ignore lint/style/noNonNullAssertion: Only message fields are undefined, rest will have a zero value.
146
146
  const desc = extension.message;
147
147
  if (isWrapperDesc(desc)) {
148
148
  return scalarZeroValue(desc.fields[0].scalar, desc.fields[0].longAsString);
@@ -54,7 +54,8 @@ export function mergeFromBinary(schema, target, bytes, options) {
54
54
  function readMessage(message, reader, options, delimited, lengthOrDelimitedFieldNo) {
55
55
  var _a;
56
56
  const end = delimited ? reader.len : reader.pos + lengthOrDelimitedFieldNo;
57
- let fieldNo, wireType;
57
+ let fieldNo;
58
+ let wireType;
58
59
  const unknownFields = (_a = message.getUnknown()) !== null && _a !== void 0 ? _a : [];
59
60
  while (reader.pos < end) {
60
61
  [fieldNo, wireType] = reader.tag();
@@ -73,7 +74,7 @@ function readMessage(message, reader, options, delimited, lengthOrDelimitedField
73
74
  }
74
75
  if (delimited) {
75
76
  if (wireType != WireType.EndGroup || fieldNo !== lengthOrDelimitedFieldNo) {
76
- throw new Error(`invalid end group tag`);
77
+ throw new Error("invalid end group tag");
77
78
  }
78
79
  }
79
80
  if (unknownFields.length > 0) {
@@ -105,7 +106,8 @@ export function readField(message, reader, field, wireType, options) {
105
106
  // Read a map field, expecting key field = 1, value field = 2
106
107
  function readMapEntry(reader, map, options) {
107
108
  const field = map.field();
108
- let key, val;
109
+ let key;
110
+ let val;
109
111
  const end = reader.pos + reader.uint32();
110
112
  while (reader.pos < end) {
111
113
  const [fieldNo] = reader.tag();
@@ -11,7 +11,6 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- /* eslint-disable no-case-declarations,@typescript-eslint/restrict-template-expressions */
15
14
  import { ScalarType, } from "./descriptors.js";
16
15
  import { protoInt64 } from "./proto-int64.js";
17
16
  import { create } from "./create.js";
@@ -96,7 +95,7 @@ export function mergeFromJson(schema, target, json, options) {
96
95
  export function enumFromJson(descEnum, json) {
97
96
  const val = readEnum(descEnum, json, false, false);
98
97
  if (val === tokenIgnoredUnknownEnum) {
99
- throw new Error(`cannot decode ${String(descEnum)} from JSON: ${formatVal(json)}`);
98
+ throw new Error(`cannot decode ${descEnum} from JSON: ${formatVal(json)}`);
100
99
  }
101
100
  return val;
102
101
  }
@@ -139,6 +138,7 @@ function readMessage(msg, json, opts) {
139
138
  let extension = undefined;
140
139
  if (jsonKey.startsWith("[") &&
141
140
  jsonKey.endsWith("]") &&
141
+ // biome-ignore lint/suspicious/noAssignInExpressions: no
142
142
  (extension = (_a = opts.registry) === null || _a === void 0 ? void 0 : _a.getExtension(jsonKey.substring(1, jsonKey.length - 1))) &&
143
143
  extension.extendee.typeName === msg.desc.typeName) {
144
144
  const [container, field, get] = createExtensionContainer(extension);
@@ -268,7 +268,6 @@ function readEnum(desc, json, ignoreUnknownFields, nullAsZeroValue) {
268
268
  }
269
269
  return nullAsZeroValue ? desc.values[0].number : tokenNull;
270
270
  }
271
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
272
271
  switch (typeof json) {
273
272
  case "number":
274
273
  if (Number.isInteger(json)) {
@@ -297,7 +296,6 @@ function scalarFromJson(field, json, nullAsZeroValue) {
297
296
  }
298
297
  // int64, sfixed64, sint64, fixed64, uint64: Reflect supports string and number.
299
298
  // string, bool: Supported by reflect.
300
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
301
299
  switch (field.scalar) {
302
300
  // float, double: JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity".
303
301
  // Either numbers or strings are accepted. Exponent notation is also accepted.
@@ -310,11 +308,11 @@ function scalarFromJson(field, json, nullAsZeroValue) {
310
308
  if (json === "-Infinity")
311
309
  return Number.NEGATIVE_INFINITY;
312
310
  if (typeof json == "number") {
313
- if (isNaN(json)) {
311
+ if (Number.isNaN(json)) {
314
312
  // NaN must be encoded with string constants
315
313
  throw new FieldError(field, "unexpected NaN number");
316
314
  }
317
- if (!isFinite(json)) {
315
+ if (!Number.isFinite(json)) {
318
316
  // Infinity must be encoded with string constants
319
317
  throw new FieldError(field, "unexpected infinite number");
320
318
  }
@@ -330,7 +328,7 @@ function scalarFromJson(field, json, nullAsZeroValue) {
330
328
  break;
331
329
  }
332
330
  const float = Number(json);
333
- if (!isFinite(float)) {
331
+ if (!Number.isFinite(float)) {
334
332
  // Infinity and NaN must be encoded with string constants
335
333
  break;
336
334
  }
@@ -371,7 +369,6 @@ function scalarFromJson(field, json, nullAsZeroValue) {
371
369
  function mapKeyFromJson(type, json) {
372
370
  switch (type) {
373
371
  case ScalarType.BOOL:
374
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
375
372
  switch (json) {
376
373
  case "true":
377
374
  return true;
@@ -489,11 +486,12 @@ function anyFromJson(any, json, opts) {
489
486
  const msg = reflect(desc);
490
487
  if (typeName.startsWith("google.protobuf.") &&
491
488
  Object.prototype.hasOwnProperty.call(json, "value")) {
492
- const value = json["value"];
489
+ const value = json.value;
493
490
  readMessage(msg, value, opts);
494
491
  }
495
492
  else {
496
493
  const copy = Object.assign({}, json);
494
+ // biome-ignore lint/performance/noDelete: <explanation>
497
495
  delete copy["@type"];
498
496
  readMessage(msg, copy, opts);
499
497
  }
@@ -508,7 +506,7 @@ function timestampFromJson(timestamp, json) {
508
506
  throw new Error(`cannot decode message ${timestamp.$typeName} from JSON: invalid RFC 3339 string`);
509
507
  }
510
508
  const ms = Date.parse(
511
- //prettier-ignore
509
+ // biome-ignore format: want this to read well
512
510
  matches[1] + "-" + matches[2] + "-" + matches[3] + "T" + matches[4] + ":" + matches[5] + ":" + matches[6] + (matches[8] ? matches[8] : "Z"));
513
511
  if (Number.isNaN(ms)) {
514
512
  throw new Error(`cannot decode message ${timestamp.$typeName} from JSON: invalid RFC 3339 string`);