@bufbuild/protobuf 0.0.4 → 0.0.7

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 (76) hide show
  1. package/dist/cjs/binary-encoding.js +2 -2
  2. package/dist/cjs/descriptor-registry.js +18 -60
  3. package/dist/cjs/descriptor-set.js +15 -37
  4. package/dist/cjs/google/protobuf/any_pb.js +11 -8
  5. package/dist/cjs/google/protobuf/api_pb.js +19 -18
  6. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +23 -22
  7. package/dist/cjs/google/protobuf/descriptor_pb.js +149 -148
  8. package/dist/cjs/google/protobuf/duration_pb.js +14 -12
  9. package/dist/cjs/google/protobuf/empty_pb.js +7 -6
  10. package/dist/cjs/google/protobuf/field_mask_pb.js +8 -7
  11. package/dist/cjs/google/protobuf/source_context_pb.js +7 -6
  12. package/dist/cjs/google/protobuf/struct_pb.js +26 -22
  13. package/dist/cjs/google/protobuf/timestamp_pb.js +12 -10
  14. package/dist/cjs/google/protobuf/type_pb.js +37 -33
  15. package/dist/cjs/google/protobuf/wrappers_pb.js +69 -66
  16. package/dist/cjs/index.js +40 -4
  17. package/dist/cjs/message.js +2 -1
  18. package/dist/cjs/package.json +1 -0
  19. package/dist/cjs/private/binary-format-common.js +4 -3
  20. package/dist/cjs/private/binary-format-proto2.js +3 -6
  21. package/dist/cjs/private/binary-format-proto3.js +2 -5
  22. package/dist/cjs/private/enum.js +1 -1
  23. package/dist/cjs/private/json-format-common.js +6 -5
  24. package/dist/cjs/private/message-type.js +2 -1
  25. package/dist/cjs/proto-int64.js +1 -1
  26. package/dist/cjs/proto2.js +6 -8
  27. package/dist/cjs/proto3.js +9 -12
  28. package/dist/cjs/type-registry.js +58 -13
  29. package/dist/esm/binary-encoding.js +2 -2
  30. package/dist/esm/descriptor-registry.js +18 -60
  31. package/dist/esm/descriptor-set.js +15 -37
  32. package/dist/esm/google/protobuf/any_pb.js +6 -3
  33. package/dist/esm/google/protobuf/api_pb.js +2 -1
  34. package/dist/esm/google/protobuf/compiler/plugin_pb.js +2 -1
  35. package/dist/esm/google/protobuf/descriptor_pb.js +2 -1
  36. package/dist/esm/google/protobuf/duration_pb.js +4 -2
  37. package/dist/esm/google/protobuf/empty_pb.js +2 -1
  38. package/dist/esm/google/protobuf/field_mask_pb.js +2 -1
  39. package/dist/esm/google/protobuf/source_context_pb.js +2 -1
  40. package/dist/esm/google/protobuf/struct_pb.js +6 -2
  41. package/dist/esm/google/protobuf/timestamp_pb.js +3 -1
  42. package/dist/esm/google/protobuf/type_pb.js +5 -1
  43. package/dist/esm/google/protobuf/wrappers_pb.js +4 -1
  44. package/dist/esm/index.js +25 -4
  45. package/dist/esm/message.js +2 -1
  46. package/dist/esm/private/binary-format-common.js +4 -3
  47. package/dist/esm/private/binary-format-proto2.js +3 -6
  48. package/dist/esm/private/binary-format-proto3.js +2 -5
  49. package/dist/esm/private/enum.js +1 -1
  50. package/dist/esm/private/json-format-common.js +6 -5
  51. package/dist/esm/private/message-type.js +2 -1
  52. package/dist/esm/proto-int64.js +1 -1
  53. package/dist/esm/proto2.js +6 -8
  54. package/dist/esm/proto3.js +9 -12
  55. package/dist/esm/type-registry.js +58 -13
  56. package/dist/types/google/protobuf/any_pb.d.ts +6 -2
  57. package/dist/types/google/protobuf/api_pb.d.ts +5 -2
  58. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +5 -2
  59. package/dist/types/google/protobuf/descriptor_pb.d.ts +5 -2
  60. package/dist/types/google/protobuf/duration_pb.d.ts +5 -2
  61. package/dist/types/google/protobuf/empty_pb.d.ts +5 -2
  62. package/dist/types/google/protobuf/field_mask_pb.d.ts +5 -2
  63. package/dist/types/google/protobuf/source_context_pb.d.ts +5 -2
  64. package/dist/types/google/protobuf/struct_pb.d.ts +5 -2
  65. package/dist/types/google/protobuf/timestamp_pb.d.ts +5 -2
  66. package/dist/types/google/protobuf/type_pb.d.ts +5 -2
  67. package/dist/types/google/protobuf/wrappers_pb.d.ts +5 -2
  68. package/dist/types/index.d.ts +31 -2
  69. package/dist/types/type-registry.d.ts +35 -2
  70. package/package.json +3 -3
  71. package/dist/cjs/index-runtime.js +0 -42
  72. package/dist/cjs/index-wkt.js +0 -42
  73. package/dist/esm/index-runtime.js +0 -25
  74. package/dist/esm/index-wkt.js +0 -26
  75. package/dist/types/index-runtime.d.ts +0 -19
  76. package/dist/types/index-wkt.d.ts +0 -12
@@ -147,6 +147,7 @@ function newEnumValue(proto, parent) {
147
147
  };
148
148
  }
149
149
  function newMessage(proto, parent, file, us) {
150
+ var _a;
150
151
  assert(proto.name, `invalid descriptor: missing name`);
151
152
  const nestedMessages = [];
152
153
  const fields = [];
@@ -192,7 +193,7 @@ function newMessage(proto, parent, file, us) {
192
193
  let oneof = undefined;
193
194
  if (field.oneofIndex !== undefined) {
194
195
  oneof = oneofs[field.oneofIndex];
195
- assert(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${field.number ?? -1} not found`);
196
+ assert(oneof, `invalid descriptor: oneof declaration index ${field.oneofIndex} specified by field #${(_a = field.number) !== null && _a !== void 0 ? _a : -1} not found`);
196
197
  }
197
198
  fields.push(newField(field, message, oneof));
198
199
  }
@@ -205,11 +206,12 @@ function newMessage(proto, parent, file, us) {
205
206
  return message;
206
207
  }
207
208
  function newField(proto, parent, oneof) {
209
+ var _a;
208
210
  assert(proto.name, `invalid descriptor: missing name`);
209
211
  assert(proto.number, `invalid descriptor: missing number`);
210
212
  assert(proto.type, `invalid descriptor: missing type`);
211
213
  let optional = false;
212
- let packed = proto.options?.packed === true;
214
+ let packed = ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.packed) === true;
213
215
  switch (parent.file.syntax) {
214
216
  case "proto2":
215
217
  optional =
@@ -272,6 +274,7 @@ function newField(proto, parent, oneof) {
272
274
  return field;
273
275
  }
274
276
  function resolveField(u, us) {
277
+ var _a;
275
278
  const repeated = u.proto.label === FieldDescriptorProto_Label.REPEATED;
276
279
  switch (u.type) {
277
280
  case FieldDescriptorProto_Type.MESSAGE:
@@ -279,54 +282,28 @@ function resolveField(u, us) {
279
282
  assert(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
280
283
  const refMessage = us.messages[u.proto.typeName];
281
284
  assert(refMessage, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
282
- if (refMessage.proto.options?.mapEntry !== undefined) {
283
- return {
284
- ...u,
285
- repeated: false,
286
- scalarType: undefined,
287
- message: undefined,
288
- enum: undefined,
289
- map: resolveMap(refMessage, us),
290
- };
285
+ if (((_a = refMessage.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry) !== undefined) {
286
+ return Object.assign(Object.assign({}, u), { repeated: false, scalarType: undefined, message: undefined, enum: undefined, map: resolveMap(refMessage, us) });
291
287
  }
292
- return {
293
- ...u,
294
- repeated,
295
- scalarType: undefined,
296
- message: refMessage,
297
- enum: undefined,
298
- map: undefined,
299
- };
288
+ return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: refMessage, enum: undefined, map: undefined });
300
289
  }
301
290
  case FieldDescriptorProto_Type.ENUM: {
302
291
  assert(u.proto.typeName, `invalid descriptor: ${u.toString()} has type ${FieldDescriptorProto_Type[u.type]}, but type_name is unset`);
303
292
  const refEnum = us.enums[u.proto.typeName];
304
293
  assert(refEnum, `invalid descriptor: cannot find type_name "${u.proto.typeName}" specified by ${u.toString()}`);
305
- return {
306
- ...u,
307
- repeated,
308
- scalarType: undefined,
309
- message: undefined,
310
- enum: refEnum,
311
- map: undefined,
312
- };
294
+ return Object.assign(Object.assign({}, u), { repeated, scalarType: undefined, message: undefined, enum: refEnum, map: undefined });
313
295
  }
314
296
  default: {
315
297
  const scalarType = fieldTypeToScalarType[u.type];
316
298
  assert(scalarType, `invalid descriptor: unable to convert google.protobuf.FieldDescriptorProto.Type ${FieldDescriptorProto_Type[u.type]} to ScalarType`);
317
- return {
318
- ...u,
319
- repeated,
320
- scalarType,
321
- message: undefined,
322
- enum: undefined,
323
- map: undefined,
324
- };
299
+ return Object.assign(Object.assign({}, u), { repeated,
300
+ scalarType, message: undefined, enum: undefined, map: undefined });
325
301
  }
326
302
  }
327
303
  }
328
304
  function resolveMap(mapEntry, us) {
329
- assert(mapEntry.proto.options?.mapEntry, `invalid descriptor: expected ${mapEntry.toString()} to be a map entry`);
305
+ var _a;
306
+ assert((_a = mapEntry.proto.options) === null || _a === void 0 ? void 0 : _a.mapEntry, `invalid descriptor: expected ${mapEntry.toString()} to be a map entry`);
330
307
  assert(mapEntry.fields.length === 2, `invalid descriptor: map entry ${mapEntry.toString()} has ${mapEntry.fields.length} fields`);
331
308
  const uKeyField = mapEntry.fields.find((f) => f.proto.number === 1);
332
309
  assert(uKeyField, `invalid descriptor: map entry ${mapEntry.toString()} is missing key field`);
@@ -418,6 +395,7 @@ function newService(proto, file, us) {
418
395
  return service;
419
396
  }
420
397
  function newMethod(proto, parent) {
398
+ var _a;
421
399
  assert(proto.name, `invalid descriptor: missing method descriptor name`);
422
400
  assert(proto.inputType, `invalid descriptor: missing method input type`);
423
401
  assert(proto.outputType, `invalid descriptor: missing method output type`);
@@ -435,7 +413,7 @@ function newMethod(proto, parent) {
435
413
  kind = MethodKind.Unary;
436
414
  }
437
415
  let idempotency;
438
- switch (proto.options?.idempotencyLevel) {
416
+ switch ((_a = proto.options) === null || _a === void 0 ? void 0 : _a.idempotencyLevel) {
439
417
  case MethodOptions_IdempotencyLevel.IDEMPOTENT:
440
418
  idempotency = MethodIdempotency.Idempotent;
441
419
  break;
@@ -11,7 +11,8 @@
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
- import { Message, proto3 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto3 } from "../../proto3.js";
15
16
  /**
16
17
  * `Any` contains an arbitrary serialized protocol buffer message along with a
17
18
  * URL that describes the type of the serialized message.
@@ -144,11 +145,12 @@ export class Any extends Message {
144
145
  proto3.util.initPartial(data, this);
145
146
  }
146
147
  toJson(options) {
148
+ var _a;
147
149
  if (this.typeUrl === "") {
148
150
  return {};
149
151
  }
150
152
  const typeName = this.typeUrlToName(this.typeUrl);
151
- const messageType = options?.typeRegistry?.findMessage(typeName);
153
+ const messageType = (_a = options === null || options === void 0 ? void 0 : options.typeRegistry) === null || _a === void 0 ? void 0 : _a.findMessage(typeName);
152
154
  if (!messageType) {
153
155
  throw new Error(`cannot encode message google.protobuf.Any to JSON: "${this.typeUrl}" is not in the type registry`);
154
156
  }
@@ -161,6 +163,7 @@ export class Any extends Message {
161
163
  return json;
162
164
  }
163
165
  fromJson(json, options) {
166
+ var _a;
164
167
  if (json === null || Array.isArray(json) || typeof json != "object") {
165
168
  throw new Error(`cannot decode message google.protobuf.Any from JSON: expected object but got ${json === null ? "null" : Array.isArray(json) ? "array" : typeof json}`);
166
169
  }
@@ -168,7 +171,7 @@ export class Any extends Message {
168
171
  if (typeof typeUrl != "string" || typeUrl == "") {
169
172
  throw new Error(`cannot decode message google.protobuf.Any from JSON: "@type" is empty`);
170
173
  }
171
- const typeName = this.typeUrlToName(typeUrl), messageType = options?.typeRegistry?.findMessage(typeName);
174
+ const typeName = this.typeUrlToName(typeUrl), messageType = (_a = options === null || options === void 0 ? void 0 : options.typeRegistry) === null || _a === void 0 ? void 0 : _a.findMessage(typeName);
172
175
  if (!messageType) {
173
176
  throw new Error(`cannot decode message google.protobuf.Any from JSON: ${typeUrl} is not in the type registry`);
174
177
  }
@@ -11,9 +11,10 @@
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
- import { Message, proto3 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
15
  import { Option, Syntax } from "./type_pb.js";
16
16
  import { SourceContext } from "./source_context_pb.js";
17
+ import { proto3 } from "../../proto3.js";
17
18
  /**
18
19
  * Api is a light-weight descriptor for an API Interface.
19
20
  *
@@ -11,7 +11,8 @@
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
- import { Message, proto2 } from "../../../index-runtime.js";
14
+ import { Message } from "../../../message.js";
15
+ import { proto2 } from "../../../proto2.js";
15
16
  import { FileDescriptorProto, GeneratedCodeInfo } from "../descriptor_pb.js";
16
17
  /**
17
18
  * The version number of protocol compiler.
@@ -11,7 +11,8 @@
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
- import { Message, proto2 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto2 } from "../../proto2.js";
15
16
  /**
16
17
  * The protocol compiler can output a FileDescriptorSet containing the .proto
17
18
  * files it parses.
@@ -11,7 +11,9 @@
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
- import { Message, proto3, protoInt64 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { protoInt64 } from "../../proto-int64.js";
16
+ import { proto3 } from "../../proto3.js";
15
17
  /**
16
18
  * A Duration represents a signed, fixed-length span of time represented
17
19
  * as a count of seconds and fractions of seconds at nanosecond
@@ -116,7 +118,7 @@ export class Duration extends Message {
116
118
  if (typeof match[2] == "string") {
117
119
  const nanosStr = match[2] + "0".repeat(9 - match[2].length);
118
120
  this.nanos = parseInt(nanosStr);
119
- if (longSeconds < 0n) {
121
+ if (longSeconds < protoInt64.zero) {
120
122
  this.nanos = -this.nanos;
121
123
  }
122
124
  }
@@ -11,7 +11,8 @@
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
- import { Message, proto3 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto3 } from "../../proto3.js";
15
16
  /**
16
17
  * A generic empty message that you can re-use to avoid defining duplicated
17
18
  * empty messages in your APIs. A typical example is to use it as the request
@@ -11,7 +11,8 @@
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
- import { Message, proto3 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto3 } from "../../proto3.js";
15
16
  /**
16
17
  * `FieldMask` represents a set of symbolic field paths, for example:
17
18
  *
@@ -11,7 +11,8 @@
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
- import { Message, proto3 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto3 } from "../../proto3.js";
15
16
  /**
16
17
  * `SourceContext` represents information about the source of a
17
18
  * protobuf element, like the file in which it is defined.
@@ -11,7 +11,11 @@
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
- import { Message, proto3 } from "../../index-runtime.js";
14
+ // @generated by protoc-gen-es v0.0.7 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
+ // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
16
+ /* eslint-disable */
17
+ import { proto3 } from "../../proto3.js";
18
+ import { Message } from "../../message.js";
15
19
  /**
16
20
  * `NullValue` is a singleton enumeration to represent the null value for the
17
21
  * `Value` type union.
@@ -121,7 +125,7 @@ export class Value extends Message {
121
125
  return this.kind.value;
122
126
  case "structValue":
123
127
  case "listValue":
124
- return this.kind.value.toJson({ ...options, emitDefaultValues: true });
128
+ return this.kind.value.toJson(Object.assign(Object.assign({}, options), { emitDefaultValues: true }));
125
129
  }
126
130
  throw new Error("google.protobuf.Value must have a value");
127
131
  }
@@ -11,7 +11,9 @@
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
- import { Message, proto3, protoInt64 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { protoInt64 } from "../../proto-int64.js";
16
+ import { proto3 } from "../../proto3.js";
15
17
  /**
16
18
  * A Timestamp represents a point in time independent of any time zone or local
17
19
  * calendar, encoded as a count of seconds and fractions of seconds at
@@ -11,7 +11,11 @@
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
- import { Message, proto3 } from "../../index-runtime.js";
14
+ // @generated by protoc-gen-es v0.0.7 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
+ // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
16
+ /* eslint-disable */
17
+ import { proto3 } from "../../proto3.js";
18
+ import { Message } from "../../message.js";
15
19
  import { SourceContext } from "./source_context_pb.js";
16
20
  import { Any } from "./any_pb.js";
17
21
  /**
@@ -11,7 +11,10 @@
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
- import { Message, ScalarType, proto3, protoInt64 } from "../../index-runtime.js";
14
+ import { Message } from "../../message.js";
15
+ import { proto3 } from "../../proto3.js";
16
+ import { ScalarType } from "../../field.js";
17
+ import { protoInt64 } from "../../proto-int64.js";
15
18
  /**
16
19
  * Wrapper message for `double`.
17
20
  *
package/dist/esm/index.js CHANGED
@@ -11,7 +11,28 @@
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
- // To avoid circular imports when the wkt import from ./index.js, we
15
- // use a separate ./index-runtime.js
16
- export * from "./index-runtime.js";
17
- export * from "./index-wkt.js";
14
+ export { proto3 } from "./proto3.js";
15
+ export { proto2 } from "./proto2.js";
16
+ export { protoInt64 } from "./proto-int64.js";
17
+ export { protoBase64 } from "./proto-base64.js";
18
+ export { Message, } from "./message.js";
19
+ export { ScalarType } from "./field.js";
20
+ export { MethodKind, MethodIdempotency } from "./service-type.js";
21
+ export { TypeRegistry } from "./type-registry.js";
22
+ export { DescriptorRegistry } from "./descriptor-registry.js";
23
+ export { DescriptorSet } from "./descriptor-set.js";
24
+ export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
25
+ export {} from "./json-format.js";
26
+ // ideally, we would export these types with sub-path exports:
27
+ export * from "./google/protobuf/compiler/plugin_pb.js";
28
+ export * from "./google/protobuf/api_pb.js";
29
+ export * from "./google/protobuf/any_pb.js";
30
+ export * from "./google/protobuf/descriptor_pb.js";
31
+ export * from "./google/protobuf/duration_pb.js";
32
+ export * from "./google/protobuf/empty_pb.js";
33
+ export * from "./google/protobuf/field_mask_pb.js";
34
+ export * from "./google/protobuf/source_context_pb.js";
35
+ export * from "./google/protobuf/struct_pb.js";
36
+ export * from "./google/protobuf/timestamp_pb.js";
37
+ export * from "./google/protobuf/type_pb.js";
38
+ export * from "./google/protobuf/wrappers_pb.js";
@@ -81,8 +81,9 @@ export class Message {
81
81
  * Serialize the message to a JSON string.
82
82
  */
83
83
  toJsonString(options) {
84
+ var _a;
84
85
  const value = this.toJson(options);
85
- return JSON.stringify(value, null, options?.prettySpaces ?? 0);
86
+ return JSON.stringify(value, null, (_a = options === null || options === void 0 ? void 0 : options.prettySpaces) !== null && _a !== void 0 ? _a : 0);
86
87
  }
87
88
  /**
88
89
  * Retrieve the MessageType of this message - a singleton that represents
@@ -29,17 +29,18 @@ const writeDefaults = {
29
29
  writerFactory: () => new BinaryWriter(),
30
30
  };
31
31
  function makeReadOptions(options) {
32
- return options ? { ...readDefaults, ...options } : readDefaults;
32
+ return options ? Object.assign(Object.assign({}, readDefaults), options) : readDefaults;
33
33
  }
34
34
  function makeWriteOptions(options) {
35
- return options ? { ...writeDefaults, ...options } : writeDefaults;
35
+ return options ? Object.assign(Object.assign({}, writeDefaults), options) : writeDefaults;
36
36
  }
37
37
  export function makeBinaryFormatCommon() {
38
38
  return {
39
39
  makeReadOptions,
40
40
  makeWriteOptions,
41
41
  listUnknownFields(message) {
42
- return message[unknownFieldsSymbol] ?? [];
42
+ var _a;
43
+ return (_a = message[unknownFieldsSymbol]) !== null && _a !== void 0 ? _a : [];
43
44
  },
44
45
  discardUnknownFields(message) {
45
46
  delete message[unknownFieldsSymbol];
@@ -15,9 +15,7 @@ import { ScalarType } from "../field.js";
15
15
  import { makeBinaryFormatCommon, writeMapEntry, writeMessageField, writePacked, writeScalar, } from "./binary-format-common.js";
16
16
  /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, no-case-declarations, prefer-const */
17
17
  export function makeBinaryFormatProto2() {
18
- return {
19
- ...makeBinaryFormatCommon(),
20
- writeMessage(message, writer, options) {
18
+ return Object.assign(Object.assign({}, makeBinaryFormatCommon()), { writeMessage(message, writer, options) {
21
19
  const type = message.getType();
22
20
  let field;
23
21
  try {
@@ -81,7 +79,7 @@ export function makeBinaryFormatProto2() {
81
79
  }
82
80
  catch (e) {
83
81
  let m = field
84
- ? `cannot encode field ${type.typeName}.${field?.name} to binary`
82
+ ? `cannot encode field ${type.typeName}.${field === null || field === void 0 ? void 0 : field.name} to binary`
85
83
  : `cannot encode message ${type.typeName} to binary`;
86
84
  let r = e instanceof Error ? e.message : String(e);
87
85
  throw new Error(m + (r.length > 0 ? `: ${r}` : ""));
@@ -90,6 +88,5 @@ export function makeBinaryFormatProto2() {
90
88
  this.writeUnknownFields(message, writer);
91
89
  }
92
90
  return writer;
93
- },
94
- };
91
+ } });
95
92
  }
@@ -15,9 +15,7 @@ import { ScalarType } from "../field.js";
15
15
  import { makeBinaryFormatCommon, writeMapEntry, writeMessageField, writePacked, writeScalar, } from "./binary-format-common.js";
16
16
  /* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions, prefer-const, no-case-declarations */
17
17
  export function makeBinaryFormatProto3() {
18
- return {
19
- ...makeBinaryFormatCommon(),
20
- writeMessage(message, writer, options) {
18
+ return Object.assign(Object.assign({}, makeBinaryFormatCommon()), { writeMessage(message, writer, options) {
21
19
  const type = message.getType();
22
20
  for (const field of type.fields.byNumber()) {
23
21
  let value, // this will be our field value, whether it is member of a oneof or regular field
@@ -73,6 +71,5 @@ export function makeBinaryFormatProto3() {
73
71
  this.writeUnknownFields(message, writer);
74
72
  }
75
73
  return writer;
76
- },
77
- };
74
+ } });
78
75
  }
@@ -76,7 +76,7 @@ export function makeEnumType(typeName, values
76
76
  export function makeEnum(typeName, values, opt) {
77
77
  const enumObject = {};
78
78
  for (const value of values) {
79
- const name = makeEnumValueName(value, opt?.sharedPrefix);
79
+ const name = makeEnumValueName(value, opt === null || opt === void 0 ? void 0 : opt.sharedPrefix);
80
80
  enumObject[name] = value.no;
81
81
  enumObject[value.no] = name;
82
82
  }
@@ -29,10 +29,10 @@ const jsonWriteDefaults = {
29
29
  prettySpaces: 0,
30
30
  };
31
31
  function makeReadOptions(options) {
32
- return options ? { ...jsonReadDefaults, ...options } : jsonReadDefaults;
32
+ return options ? Object.assign(Object.assign({}, jsonReadDefaults), options) : jsonReadDefaults;
33
33
  }
34
34
  function makeWriteOptions(options) {
35
- return options ? { ...jsonWriteDefaults, ...options } : jsonWriteDefaults;
35
+ return options ? Object.assign(Object.assign({}, jsonWriteDefaults), options) : jsonWriteDefaults;
36
36
  }
37
37
  export function makeJsonFormatCommon(makeWriteField) {
38
38
  const writeField = makeWriteField(writeEnum, writeScalar);
@@ -43,7 +43,7 @@ export function makeJsonFormatCommon(makeWriteField) {
43
43
  if (json == null || Array.isArray(json) || typeof json != "object") {
44
44
  throw new Error(`cannot decode message ${type.typeName} from JSON: ${this.debug(json)}`);
45
45
  }
46
- message = message ?? new type();
46
+ message = message !== null && message !== void 0 ? message : new type();
47
47
  const oneofSeen = {};
48
48
  for (const [jsonKey, jsonValue] of Object.entries(json)) {
49
49
  const field = type.fields.findJsonName(jsonKey);
@@ -382,13 +382,14 @@ function readEnum(type, json, ignoreUnknownFields) {
382
382
  case "string":
383
383
  const value = type.findName(json);
384
384
  if (value || ignoreUnknownFields) {
385
- return value?.no;
385
+ return value === null || value === void 0 ? void 0 : value.no;
386
386
  }
387
387
  break;
388
388
  }
389
389
  throw new Error(`cannot decode enum ${type.typeName} from JSON: ${debugJsonValue(json)}`);
390
390
  }
391
391
  function writeEnum(type, value, emitIntrinsicDefault, enumAsInteger) {
392
+ var _a;
392
393
  if (value === undefined) {
393
394
  return value;
394
395
  }
@@ -403,7 +404,7 @@ function writeEnum(type, value, emitIntrinsicDefault, enumAsInteger) {
403
404
  return null;
404
405
  }
405
406
  const val = type.findNumber(value);
406
- return val?.name ?? value; // if we don't know the enum value, just return the number
407
+ return (_a = val === null || val === void 0 ? void 0 : val.name) !== null && _a !== void 0 ? _a : value; // if we don't know the enum value, just return the number
407
408
  }
408
409
  function writeScalar(type, value, emitIntrinsicDefault) {
409
410
  if (value === undefined) {
@@ -16,7 +16,8 @@ import { Message, } from "../message.js";
16
16
  * Create a new message type using the given runtime.
17
17
  */
18
18
  export function makeMessageType(runtime, typeName, fields, opt) {
19
- const localName = opt?.localName ?? typeName.substring(typeName.lastIndexOf(".") + 1);
19
+ var _a;
20
+ const localName = (_a = opt === null || opt === void 0 ? void 0 : opt.localName) !== null && _a !== void 0 ? _a : typeName.substring(typeName.lastIndexOf(".") + 1);
20
21
  const type = {
21
22
  [localName]: function (data) {
22
23
  runtime.util.initFields(this);
@@ -15,7 +15,7 @@ import { int64fromString, int64toString } from "./google/varint.js";
15
15
  function makeInt64Support() {
16
16
  const dv = new DataView(new ArrayBuffer(8));
17
17
  // note that Safari 14 implements BigInt, but not the DataView methods
18
- const ok = globalThis.BigInt !== undefined && // eslint-disable-line @typescript-eslint/no-unnecessary-condition -- conditional for BigInt is very much necessary
18
+ const ok = globalThis.BigInt !== undefined &&
19
19
  typeof dv.getBigInt64 === "function" &&
20
20
  typeof dv.getBigUint64 === "function" &&
21
21
  typeof dv.setBigInt64 === "function" &&
@@ -21,9 +21,7 @@ import { makeJsonFormatProto2 } from "./private/json-format-proto2.js";
21
21
  /**
22
22
  * Provides functionality for messages defined with the proto2 syntax.
23
23
  */
24
- export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBinaryFormatProto2(), {
25
- ...makeUtilCommon(),
26
- newFieldList(fields) {
24
+ export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBinaryFormatProto2(), Object.assign(Object.assign({}, makeUtilCommon()), { newFieldList(fields) {
27
25
  return new InternalFieldList(fields, normalizeFieldInfosProto2);
28
26
  },
29
27
  initFields(target) {
@@ -52,10 +50,10 @@ export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBin
52
50
  break;
53
51
  }
54
52
  }
55
- },
56
- });
53
+ } }));
57
54
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
58
55
  function normalizeFieldInfosProto2(fieldInfos) {
56
+ var _a, _b, _c;
59
57
  const r = [];
60
58
  let o;
61
59
  for (const field of typeof fieldInfos == "function"
@@ -63,10 +61,10 @@ function normalizeFieldInfosProto2(fieldInfos) {
63
61
  : fieldInfos) {
64
62
  const f = field;
65
63
  f.localName = makeFieldName(field.name, field.oneof !== undefined);
66
- f.jsonName = field.jsonName ?? makeJsonName(field.name);
67
- f.repeated = field.repeated ?? false;
64
+ f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : makeJsonName(field.name);
65
+ f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
68
66
  // In contrast to proto3, repeated fields are unpacked except when explicitly specified.
69
- f.packed = field.packed ?? false;
67
+ f.packed = (_c = field.packed) !== null && _c !== void 0 ? _c : false;
70
68
  // We do not surface options at this time
71
69
  // f.options = field.options ?? emptyReadonlyObject;
72
70
  if (field.oneof !== undefined) {
@@ -23,9 +23,7 @@ import { makeFieldName, makeJsonName } from "./private/names.js";
23
23
  /**
24
24
  * Provides functionality for messages defined with the proto3 syntax.
25
25
  */
26
- export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBinaryFormatProto3(), {
27
- ...makeUtilCommon(),
28
- newFieldList(fields) {
26
+ export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBinaryFormatProto3(), Object.assign(Object.assign({}, makeUtilCommon()), { newFieldList(fields) {
29
27
  return new InternalFieldList(fields, normalizeFieldInfosProto3);
30
28
  },
31
29
  initFields(target) {
@@ -56,10 +54,10 @@ export const proto3 = makeProtoRuntime("proto3", makeJsonFormatProto3(), makeBin
56
54
  break;
57
55
  }
58
56
  }
59
- },
60
- });
57
+ } }));
61
58
  /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
62
59
  function normalizeFieldInfosProto3(fieldInfos) {
60
+ var _a, _b, _c;
63
61
  const r = [];
64
62
  let o;
65
63
  for (const field of typeof fieldInfos == "function"
@@ -67,19 +65,18 @@ function normalizeFieldInfosProto3(fieldInfos) {
67
65
  : fieldInfos) {
68
66
  const f = field;
69
67
  f.localName = makeFieldName(field.name, field.oneof !== undefined);
70
- f.jsonName = field.jsonName ?? makeJsonName(field.name);
71
- f.repeated = field.repeated ?? false;
68
+ f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : makeJsonName(field.name);
69
+ f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
72
70
  // From the proto3 language guide:
73
71
  // > In proto3, repeated fields of scalar numeric types are packed by default.
74
72
  // This information is incomplete - according to the conformance tests, BOOL
75
73
  // and ENUM are packed by default as well. This means only STRING and BYTES
76
74
  // are not packed by default, which makes sense because they are length-delimited.
77
75
  f.packed =
78
- field.packed ??
79
- (field.kind == "enum" ||
80
- (field.kind == "scalar" &&
81
- field.T != ScalarType.BYTES &&
82
- field.T != ScalarType.STRING));
76
+ (_c = field.packed) !== null && _c !== void 0 ? _c : (field.kind == "enum" ||
77
+ (field.kind == "scalar" &&
78
+ field.T != ScalarType.BYTES &&
79
+ field.T != ScalarType.STRING));
83
80
  // We do not surface options at this time
84
81
  // f.options = field.options ?? emptyReadonlyObject;
85
82
  if (field.oneof !== undefined) {