@bufbuild/protobuf 1.2.1 → 1.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 (44) hide show
  1. package/dist/cjs/binary-encoding.js +1 -1
  2. package/dist/cjs/codegen-info.js +1 -0
  3. package/dist/cjs/field.js +1 -1
  4. package/dist/cjs/google/protobuf/any_pb.js +1 -1
  5. package/dist/cjs/google/protobuf/api_pb.js +3 -3
  6. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +5 -5
  7. package/dist/cjs/google/protobuf/descriptor_pb.js +38 -38
  8. package/dist/cjs/google/protobuf/duration_pb.js +1 -1
  9. package/dist/cjs/google/protobuf/empty_pb.js +1 -1
  10. package/dist/cjs/google/protobuf/field_mask_pb.js +1 -1
  11. package/dist/cjs/google/protobuf/source_context_pb.js +1 -1
  12. package/dist/cjs/google/protobuf/struct_pb.js +5 -5
  13. package/dist/cjs/google/protobuf/timestamp_pb.js +1 -1
  14. package/dist/cjs/google/protobuf/type_pb.js +9 -9
  15. package/dist/cjs/google/protobuf/wrappers_pb.js +9 -9
  16. package/dist/cjs/index.js +5 -1
  17. package/dist/cjs/proto-delimited.js +14 -19
  18. package/dist/cjs/proto-double.js +29 -0
  19. package/dist/cjs/proto-int64.js +1 -1
  20. package/dist/cjs/service-type.js +2 -2
  21. package/dist/cjs/to-plain-message.js +67 -0
  22. package/dist/esm/codegen-info.js +1 -0
  23. package/dist/esm/google/protobuf/any_pb.js +1 -2
  24. package/dist/esm/google/protobuf/api_pb.js +3 -6
  25. package/dist/esm/google/protobuf/compiler/plugin_pb.js +4 -8
  26. package/dist/esm/google/protobuf/descriptor_pb.js +28 -56
  27. package/dist/esm/google/protobuf/duration_pb.js +1 -2
  28. package/dist/esm/google/protobuf/empty_pb.js +1 -2
  29. package/dist/esm/google/protobuf/field_mask_pb.js +1 -2
  30. package/dist/esm/google/protobuf/source_context_pb.js +1 -2
  31. package/dist/esm/google/protobuf/struct_pb.js +4 -7
  32. package/dist/esm/google/protobuf/timestamp_pb.js +1 -2
  33. package/dist/esm/google/protobuf/type_pb.js +6 -11
  34. package/dist/esm/google/protobuf/wrappers_pb.js +9 -18
  35. package/dist/esm/index.js +2 -0
  36. package/dist/esm/proto-delimited.js +14 -19
  37. package/dist/esm/proto-double.js +26 -0
  38. package/dist/esm/proto-int64.js +1 -1
  39. package/dist/esm/to-plain-message.js +63 -0
  40. package/dist/types/codegen-info.d.ts +1 -1
  41. package/dist/types/index.d.ts +2 -0
  42. package/dist/types/proto-double.d.ts +5 -0
  43. package/dist/types/to-plain-message.d.ts +9 -0
  44. package/package.json +1 -1
@@ -11,7 +11,7 @@
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
- // @generated by protoc-gen-es v1.2.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v1.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -55,7 +55,7 @@ proto3.util.setEnumType(Syntax, "google.protobuf.Syntax", [
55
55
  *
56
56
  * @generated from message google.protobuf.Type
57
57
  */
58
- class Type extends Message {
58
+ export class Type extends Message {
59
59
  constructor(data) {
60
60
  super();
61
61
  /**
@@ -120,13 +120,12 @@ Type.fields = proto3.util.newFieldList(() => [
120
120
  { no: 6, name: "syntax", kind: "enum", T: proto3.getEnumType(Syntax) },
121
121
  { no: 7, name: "edition", kind: "scalar", T: 9 /* ScalarType.STRING */ },
122
122
  ]);
123
- export { Type };
124
123
  /**
125
124
  * A single field of a message type.
126
125
  *
127
126
  * @generated from message google.protobuf.Field
128
127
  */
129
- class Field extends Message {
128
+ export class Field extends Message {
130
129
  constructor(data) {
131
130
  super();
132
131
  /**
@@ -220,7 +219,6 @@ Field.fields = proto3.util.newFieldList(() => [
220
219
  { no: 10, name: "json_name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
221
220
  { no: 11, name: "default_value", kind: "scalar", T: 9 /* ScalarType.STRING */ },
222
221
  ]);
223
- export { Field };
224
222
  /**
225
223
  * Basic field types.
226
224
  *
@@ -409,7 +407,7 @@ proto3.util.setEnumType(Field_Cardinality, "google.protobuf.Field.Cardinality",
409
407
  *
410
408
  * @generated from message google.protobuf.Enum
411
409
  */
412
- class Enum extends Message {
410
+ export class Enum extends Message {
413
411
  constructor(data) {
414
412
  super();
415
413
  /**
@@ -467,13 +465,12 @@ Enum.fields = proto3.util.newFieldList(() => [
467
465
  { no: 5, name: "syntax", kind: "enum", T: proto3.getEnumType(Syntax) },
468
466
  { no: 6, name: "edition", kind: "scalar", T: 9 /* ScalarType.STRING */ },
469
467
  ]);
470
- export { Enum };
471
468
  /**
472
469
  * Enum value definition.
473
470
  *
474
471
  * @generated from message google.protobuf.EnumValue
475
472
  */
476
- class EnumValue extends Message {
473
+ export class EnumValue extends Message {
477
474
  constructor(data) {
478
475
  super();
479
476
  /**
@@ -516,14 +513,13 @@ EnumValue.fields = proto3.util.newFieldList(() => [
516
513
  { no: 2, name: "number", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
517
514
  { no: 3, name: "options", kind: "message", T: Option, repeated: true },
518
515
  ]);
519
- export { EnumValue };
520
516
  /**
521
517
  * A protocol buffer option, which can be attached to a message, field,
522
518
  * enumeration, etc.
523
519
  *
524
520
  * @generated from message google.protobuf.Option
525
521
  */
526
- class Option extends Message {
522
+ export class Option extends Message {
527
523
  constructor(data) {
528
524
  super();
529
525
  /**
@@ -556,4 +552,3 @@ Option.fields = proto3.util.newFieldList(() => [
556
552
  { no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
557
553
  { no: 2, name: "value", kind: "message", T: Any },
558
554
  ]);
559
- export { Option };
@@ -22,7 +22,7 @@ import { protoInt64 } from "../../proto-int64.js";
22
22
  *
23
23
  * @generated from message google.protobuf.DoubleValue
24
24
  */
25
- class DoubleValue extends Message {
25
+ export class DoubleValue extends Message {
26
26
  constructor(data) {
27
27
  super();
28
28
  /**
@@ -75,7 +75,6 @@ DoubleValue.fieldWrapper = {
75
75
  return value.value;
76
76
  }
77
77
  };
78
- export { DoubleValue };
79
78
  /**
80
79
  * Wrapper message for `float`.
81
80
  *
@@ -83,7 +82,7 @@ export { DoubleValue };
83
82
  *
84
83
  * @generated from message google.protobuf.FloatValue
85
84
  */
86
- class FloatValue extends Message {
85
+ export class FloatValue extends Message {
87
86
  constructor(data) {
88
87
  super();
89
88
  /**
@@ -136,7 +135,6 @@ FloatValue.fieldWrapper = {
136
135
  return value.value;
137
136
  }
138
137
  };
139
- export { FloatValue };
140
138
  /**
141
139
  * Wrapper message for `int64`.
142
140
  *
@@ -144,7 +142,7 @@ export { FloatValue };
144
142
  *
145
143
  * @generated from message google.protobuf.Int64Value
146
144
  */
147
- class Int64Value extends Message {
145
+ export class Int64Value extends Message {
148
146
  constructor(data) {
149
147
  super();
150
148
  /**
@@ -197,7 +195,6 @@ Int64Value.fieldWrapper = {
197
195
  return value.value;
198
196
  }
199
197
  };
200
- export { Int64Value };
201
198
  /**
202
199
  * Wrapper message for `uint64`.
203
200
  *
@@ -205,7 +202,7 @@ export { Int64Value };
205
202
  *
206
203
  * @generated from message google.protobuf.UInt64Value
207
204
  */
208
- class UInt64Value extends Message {
205
+ export class UInt64Value extends Message {
209
206
  constructor(data) {
210
207
  super();
211
208
  /**
@@ -258,7 +255,6 @@ UInt64Value.fieldWrapper = {
258
255
  return value.value;
259
256
  }
260
257
  };
261
- export { UInt64Value };
262
258
  /**
263
259
  * Wrapper message for `int32`.
264
260
  *
@@ -266,7 +262,7 @@ export { UInt64Value };
266
262
  *
267
263
  * @generated from message google.protobuf.Int32Value
268
264
  */
269
- class Int32Value extends Message {
265
+ export class Int32Value extends Message {
270
266
  constructor(data) {
271
267
  super();
272
268
  /**
@@ -319,7 +315,6 @@ Int32Value.fieldWrapper = {
319
315
  return value.value;
320
316
  }
321
317
  };
322
- export { Int32Value };
323
318
  /**
324
319
  * Wrapper message for `uint32`.
325
320
  *
@@ -327,7 +322,7 @@ export { Int32Value };
327
322
  *
328
323
  * @generated from message google.protobuf.UInt32Value
329
324
  */
330
- class UInt32Value extends Message {
325
+ export class UInt32Value extends Message {
331
326
  constructor(data) {
332
327
  super();
333
328
  /**
@@ -380,7 +375,6 @@ UInt32Value.fieldWrapper = {
380
375
  return value.value;
381
376
  }
382
377
  };
383
- export { UInt32Value };
384
378
  /**
385
379
  * Wrapper message for `bool`.
386
380
  *
@@ -388,7 +382,7 @@ export { UInt32Value };
388
382
  *
389
383
  * @generated from message google.protobuf.BoolValue
390
384
  */
391
- class BoolValue extends Message {
385
+ export class BoolValue extends Message {
392
386
  constructor(data) {
393
387
  super();
394
388
  /**
@@ -441,7 +435,6 @@ BoolValue.fieldWrapper = {
441
435
  return value.value;
442
436
  }
443
437
  };
444
- export { BoolValue };
445
438
  /**
446
439
  * Wrapper message for `string`.
447
440
  *
@@ -449,7 +442,7 @@ export { BoolValue };
449
442
  *
450
443
  * @generated from message google.protobuf.StringValue
451
444
  */
452
- class StringValue extends Message {
445
+ export class StringValue extends Message {
453
446
  constructor(data) {
454
447
  super();
455
448
  /**
@@ -502,7 +495,6 @@ StringValue.fieldWrapper = {
502
495
  return value.value;
503
496
  }
504
497
  };
505
- export { StringValue };
506
498
  /**
507
499
  * Wrapper message for `bytes`.
508
500
  *
@@ -510,7 +502,7 @@ export { StringValue };
510
502
  *
511
503
  * @generated from message google.protobuf.BytesValue
512
504
  */
513
- class BytesValue extends Message {
505
+ export class BytesValue extends Message {
514
506
  constructor(data) {
515
507
  super();
516
508
  /**
@@ -563,4 +555,3 @@ BytesValue.fieldWrapper = {
563
555
  return value.value;
564
556
  }
565
557
  };
566
- export { BytesValue };
package/dist/esm/index.js CHANGED
@@ -13,6 +13,7 @@
13
13
  // limitations under the License.
14
14
  export { proto3 } from "./proto3.js";
15
15
  export { proto2 } from "./proto2.js";
16
+ export { protoDouble } from "./proto-double.js";
16
17
  export { protoInt64 } from "./proto-int64.js";
17
18
  export { protoBase64 } from "./proto-base64.js";
18
19
  export { protoDelimited } from "./proto-delimited.js";
@@ -24,6 +25,7 @@ export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
24
25
  export { createDescriptorSet } from "./create-descriptor-set.js";
25
26
  export { createRegistry } from "./create-registry.js";
26
27
  export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
28
+ export { toPlainMessage } from "./to-plain-message.js";
27
29
  // ideally, we would export these types with sub-path exports:
28
30
  export * from "./google/protobuf/compiler/plugin_pb.js";
29
31
  export * from "./google/protobuf/api_pb.js";
@@ -72,28 +72,23 @@ export const protoDelimited = {
72
72
  }
73
73
  let buffer = new Uint8Array(0);
74
74
  try {
75
- for (var _d = true, iterable_1 = __asyncValues(iterable), iterable_1_1; iterable_1_1 = yield __await(iterable_1.next()), _a = iterable_1_1.done, !_a;) {
75
+ for (var _d = true, iterable_1 = __asyncValues(iterable), iterable_1_1; iterable_1_1 = yield __await(iterable_1.next()), _a = iterable_1_1.done, !_a; _d = true) {
76
76
  _c = iterable_1_1.value;
77
77
  _d = false;
78
- try {
79
- const chunk = _c;
80
- buffer = append(buffer, chunk);
81
- for (;;) {
82
- const size = protoDelimited.peekSize(buffer);
83
- if (size.eof) {
84
- // size is incomplete, buffer more data
85
- break;
86
- }
87
- if (size.offset + size.size > buffer.byteLength) {
88
- // message is incomplete, buffer more data
89
- break;
90
- }
91
- yield yield __await(protoDelimited.dec(type, buffer));
92
- buffer = buffer.subarray(size.offset + size.size);
78
+ const chunk = _c;
79
+ buffer = append(buffer, chunk);
80
+ for (;;) {
81
+ const size = protoDelimited.peekSize(buffer);
82
+ if (size.eof) {
83
+ // size is incomplete, buffer more data
84
+ break;
93
85
  }
94
- }
95
- finally {
96
- _d = true;
86
+ if (size.offset + size.size > buffer.byteLength) {
87
+ // message is incomplete, buffer more data
88
+ break;
89
+ }
90
+ yield yield __await(protoDelimited.dec(type, buffer));
91
+ buffer = buffer.subarray(size.offset + size.size);
97
92
  }
98
93
  }
99
94
  }
@@ -0,0 +1,26 @@
1
+ // Copyright 2021-2023 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ // Export global Number constants. This is done so that we can safely use
15
+ // these global constants when generating code and be assured we're using
16
+ // the correct values. We cannot rely on globalThis since we support ES2017
17
+ // and globalThis was introduced in ES2020. We also don't want to explicitly
18
+ // generate code using, for example, Number.NaN, since this could clash with
19
+ // a message name of Number. Instead we can export them here since this will
20
+ // be in a different scope as the generated code and we are guaranteed to use
21
+ // the intended global values.
22
+ export const protoDouble = {
23
+ NaN: Number.NaN,
24
+ POSITIVE_INFINITY: Number.POSITIVE_INFINITY,
25
+ NEGATIVE_INFINITY: Number.NEGATIVE_INFINITY,
26
+ };
@@ -16,7 +16,7 @@ import { int64FromString, int64ToString, uInt64ToString, } from "./google/varint
16
16
  function makeInt64Support() {
17
17
  const dv = new DataView(new ArrayBuffer(8));
18
18
  // note that Safari 14 implements BigInt, but not the DataView methods
19
- const ok = globalThis.BigInt !== undefined &&
19
+ const ok = typeof BigInt === "function" &&
20
20
  typeof dv.getBigInt64 === "function" &&
21
21
  typeof dv.getBigUint64 === "function" &&
22
22
  typeof dv.setBigInt64 === "function" &&
@@ -0,0 +1,63 @@
1
+ // Copyright 2021-2023 Buf Technologies, Inc.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ /* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-argument,no-case-declarations */
15
+ import { Message } from "./message.js";
16
+ /**
17
+ * toPlainMessage returns a new object by striping
18
+ * all methods from a message, leaving only fields and
19
+ * oneof groups. It is recursive, meaning it applies this
20
+ * same logic to all nested message fields as well.
21
+ */
22
+ export function toPlainMessage(message) {
23
+ const type = message.getType();
24
+ const target = {};
25
+ for (const member of type.fields.byMember()) {
26
+ const source = message[member.localName];
27
+ let copy;
28
+ if (member.repeated) {
29
+ copy = source.map((e) => toPlainValue(e));
30
+ }
31
+ else if (member.kind == "map") {
32
+ copy = {};
33
+ for (const [key, v] of Object.entries(source)) {
34
+ copy[key] = toPlainValue(v);
35
+ }
36
+ }
37
+ else if (member.kind == "oneof") {
38
+ const f = member.findField(source.case);
39
+ copy = f
40
+ ? { case: source.case, value: toPlainValue(source.value) }
41
+ : { case: undefined };
42
+ }
43
+ else {
44
+ copy = toPlainValue(source);
45
+ }
46
+ target[member.localName] = copy;
47
+ }
48
+ return target;
49
+ }
50
+ function toPlainValue(value) {
51
+ if (value === undefined) {
52
+ return value;
53
+ }
54
+ if (value instanceof Message) {
55
+ return toPlainMessage(value);
56
+ }
57
+ if (value instanceof Uint8Array) {
58
+ const c = new Uint8Array(value.byteLength);
59
+ c.set(value);
60
+ return c;
61
+ }
62
+ return value;
63
+ }
@@ -13,7 +13,7 @@ interface CodegenInfo {
13
13
  readonly safeIdentifier: typeof safeIdentifier;
14
14
  readonly safeObjectProperty: typeof safeObjectProperty;
15
15
  }
16
- type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency" | "IMessageTypeRegistry";
16
+ type RuntimeSymbolName = "proto2" | "proto3" | "Message" | "PartialMessage" | "PlainMessage" | "FieldList" | "MessageType" | "BinaryReadOptions" | "BinaryWriteOptions" | "JsonReadOptions" | "JsonWriteOptions" | "JsonValue" | "JsonObject" | "protoDouble" | "protoInt64" | "ScalarType" | "MethodKind" | "MethodIdempotency" | "IMessageTypeRegistry";
17
17
  type RuntimeSymbolInfo = {
18
18
  typeOnly: boolean;
19
19
  publicImportPath: string;
@@ -1,5 +1,6 @@
1
1
  export { proto3 } from "./proto3.js";
2
2
  export { proto2 } from "./proto2.js";
3
+ export { protoDouble } from "./proto-double.js";
3
4
  export { protoInt64 } from "./proto-int64.js";
4
5
  export { protoBase64 } from "./proto-base64.js";
5
6
  export { protoDelimited } from "./proto-delimited.js";
@@ -22,6 +23,7 @@ export { createDescriptorSet } from "./create-descriptor-set.js";
22
23
  export type { IMessageTypeRegistry } from "./type-registry.js";
23
24
  export { createRegistry } from "./create-registry.js";
24
25
  export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
26
+ export { toPlainMessage } from "./to-plain-message.js";
25
27
  export * from "./google/protobuf/compiler/plugin_pb.js";
26
28
  export * from "./google/protobuf/api_pb.js";
27
29
  export * from "./google/protobuf/any_pb.js";
@@ -0,0 +1,5 @@
1
+ export declare const protoDouble: {
2
+ readonly NaN: number;
3
+ readonly POSITIVE_INFINITY: number;
4
+ readonly NEGATIVE_INFINITY: number;
5
+ };
@@ -0,0 +1,9 @@
1
+ import { Message } from "./message.js";
2
+ import type { PlainMessage } from "./message.js";
3
+ /**
4
+ * toPlainMessage returns a new object by striping
5
+ * all methods from a message, leaving only fields and
6
+ * oneof groups. It is recursive, meaning it applies this
7
+ * same logic to all nested message fields as well.
8
+ */
9
+ export declare function toPlainMessage<T extends Message<T>>(message: T): PlainMessage<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
6
6
  "repository": {