@bufbuild/protobuf 2.12.1 → 2.13.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 (64) hide show
  1. package/README.md +2 -2
  2. package/dist/commonjs/codegenv1/symbols.d.ts +5 -0
  3. package/dist/commonjs/codegenv2/enum.d.ts +15 -4
  4. package/dist/commonjs/codegenv2/enum.js +18 -0
  5. package/dist/commonjs/codegenv2/symbols.d.ts +10 -0
  6. package/dist/commonjs/codegenv2/symbols.js +2 -0
  7. package/dist/commonjs/create.js +3 -3
  8. package/dist/commonjs/descriptors.d.ts +2 -2
  9. package/dist/commonjs/index.d.ts +1 -0
  10. package/dist/commonjs/index.js +1 -0
  11. package/dist/commonjs/reflect/reflect.js +3 -2
  12. package/dist/commonjs/reflect/unsafe.js +1 -1
  13. package/dist/commonjs/registry.js +19 -19
  14. package/dist/commonjs/to-binary.js +1 -1
  15. package/dist/commonjs/to-json.js +2 -2
  16. package/dist/commonjs/txtpb/from-text.d.ts +35 -0
  17. package/dist/commonjs/txtpb/from-text.js +684 -0
  18. package/dist/commonjs/txtpb/index.d.ts +4 -0
  19. package/dist/commonjs/txtpb/index.js +21 -0
  20. package/dist/commonjs/txtpb/is-group-like.d.ts +19 -0
  21. package/dist/commonjs/txtpb/is-group-like.js +47 -0
  22. package/dist/commonjs/txtpb/reader.d.ts +91 -0
  23. package/dist/commonjs/txtpb/reader.js +481 -0
  24. package/dist/commonjs/txtpb/to-text.d.ts +34 -0
  25. package/dist/commonjs/txtpb/to-text.js +358 -0
  26. package/dist/commonjs/txtpb/writer.d.ts +76 -0
  27. package/dist/commonjs/txtpb/writer.js +220 -0
  28. package/dist/commonjs/types.d.ts +7 -0
  29. package/dist/commonjs/unknown-enum.d.ts +10 -0
  30. package/dist/commonjs/unknown-enum.js +26 -0
  31. package/dist/commonjs/wire/size-delimited.d.ts +19 -1
  32. package/dist/commonjs/wire/size-delimited.js +54 -16
  33. package/dist/esm/codegenv1/symbols.d.ts +5 -0
  34. package/dist/esm/codegenv2/enum.d.ts +15 -4
  35. package/dist/esm/codegenv2/enum.js +17 -0
  36. package/dist/esm/codegenv2/symbols.d.ts +10 -0
  37. package/dist/esm/codegenv2/symbols.js +2 -0
  38. package/dist/esm/create.js +3 -3
  39. package/dist/esm/descriptors.d.ts +2 -2
  40. package/dist/esm/index.d.ts +1 -0
  41. package/dist/esm/index.js +1 -0
  42. package/dist/esm/reflect/reflect.js +3 -2
  43. package/dist/esm/reflect/unsafe.js +1 -1
  44. package/dist/esm/registry.js +19 -19
  45. package/dist/esm/to-binary.js +1 -1
  46. package/dist/esm/to-json.js +2 -2
  47. package/dist/esm/txtpb/from-text.d.ts +35 -0
  48. package/dist/esm/txtpb/from-text.js +680 -0
  49. package/dist/esm/txtpb/index.d.ts +4 -0
  50. package/dist/esm/txtpb/index.js +15 -0
  51. package/dist/esm/txtpb/is-group-like.d.ts +19 -0
  52. package/dist/esm/txtpb/is-group-like.js +44 -0
  53. package/dist/esm/txtpb/reader.d.ts +91 -0
  54. package/dist/esm/txtpb/reader.js +477 -0
  55. package/dist/esm/txtpb/to-text.d.ts +34 -0
  56. package/dist/esm/txtpb/to-text.js +355 -0
  57. package/dist/esm/txtpb/writer.d.ts +76 -0
  58. package/dist/esm/txtpb/writer.js +214 -0
  59. package/dist/esm/types.d.ts +7 -0
  60. package/dist/esm/unknown-enum.d.ts +10 -0
  61. package/dist/esm/unknown-enum.js +23 -0
  62. package/dist/esm/wire/size-delimited.d.ts +19 -1
  63. package/dist/esm/wire/size-delimited.js +54 -16
  64. package/package.json +16 -3
@@ -0,0 +1,10 @@
1
+ import type { DescEnum } from "./descriptors.js";
2
+ import type { UnknownEnum } from "./types.js";
3
+ /**
4
+ * Open enums can contain numeric values that are not in the set of values
5
+ * defined by the enum.
6
+ *
7
+ * This function returns true for those values, and narrows the type to
8
+ * `UnknownEnum`.
9
+ */
10
+ export declare function isUnknownEnum(desc: DescEnum, value: number): value is UnknownEnum;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // Copyright 2021-2026 Buf Technologies, Inc.
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.isUnknownEnum = isUnknownEnum;
17
+ /**
18
+ * Open enums can contain numeric values that are not in the set of values
19
+ * defined by the enum.
20
+ *
21
+ * This function returns true for those values, and narrows the type to
22
+ * `UnknownEnum`.
23
+ */
24
+ function isUnknownEnum(desc, value) {
25
+ return desc.value[value] === undefined;
26
+ }
@@ -12,6 +12,20 @@ import type { BinaryReadOptions } from "../from-binary.js";
12
12
  * For details, see https://github.com/protocolbuffers/protobuf/issues/10229
13
13
  */
14
14
  export declare function sizeDelimitedEncode<Desc extends DescMessage>(messageDesc: Desc, message: MessageShape<Desc>, options?: BinaryWriteOptions): Uint8Array;
15
+ /**
16
+ * Options for parsing size-delimited messages from a stream.
17
+ */
18
+ export interface SizeDelimitedDecodeOptions extends BinaryReadOptions {
19
+ /**
20
+ * Limit the size of a single message in the stream, in bytes.
21
+ *
22
+ * If a message in the stream declares a size exceeding this limit, an
23
+ * error is raised before the message is buffered.
24
+ *
25
+ * The default limit is 64 MiB.
26
+ */
27
+ readMaxBytes: number;
28
+ }
15
29
  /**
16
30
  * Parse a stream of size-delimited messages.
17
31
  *
@@ -20,8 +34,12 @@ export declare function sizeDelimitedEncode<Desc extends DescMessage>(messageDes
20
34
  *
21
35
  * This size-delimited format is compatible with other implementations.
22
36
  * For details, see https://github.com/protocolbuffers/protobuf/issues/10229
37
+ *
38
+ * Messages exceeding the limit given with the option readMaxBytes raise an
39
+ * error. The limit is 64 MiB by default. All other options are the
40
+ * standard binary read options, passed through to decode each message.
23
41
  */
24
- export declare function sizeDelimitedDecodeStream<Desc extends DescMessage>(messageDesc: Desc, iterable: AsyncIterable<Uint8Array>, options?: Partial<BinaryReadOptions>): AsyncIterableIterator<MessageShape<Desc>>;
42
+ export declare function sizeDelimitedDecodeStream<Desc extends DescMessage>(messageDesc: Desc, iterable: AsyncIterable<Uint8Array>, options?: Partial<SizeDelimitedDecodeOptions>): AsyncIterableIterator<MessageShape<Desc>>;
25
43
  /**
26
44
  * Decodes the size from the given size-delimited message, which may be
27
45
  * incomplete.
@@ -53,6 +53,34 @@ function sizeDelimitedEncode(messageDesc, message, options) {
53
53
  writer.bytes((0, to_binary_js_1.toBinary)(messageDesc, message, options));
54
54
  return writer.finish();
55
55
  }
56
+ // Default for SizeDelimitedDecodeOptions.readMaxBytes.
57
+ const defaultReadMaxBytes = 64 * 1024 * 1024; // 64 MiB
58
+ /**
59
+ * A growable byte buffer. Used in place of a resizable ArrayBuffer, which is
60
+ * not widely available.
61
+ */
62
+ class ByteBuffer {
63
+ constructor() {
64
+ this.buffer = new Uint8Array(0);
65
+ this.length = 0;
66
+ }
67
+ get byteLength() {
68
+ return this.length;
69
+ }
70
+ bytes() {
71
+ return this.buffer.subarray(0, this.length);
72
+ }
73
+ append(chunk) {
74
+ const newByteLength = this.length + chunk.byteLength;
75
+ if (newByteLength > this.buffer.byteLength) {
76
+ const grown = new Uint8Array(Math.max(this.buffer.byteLength * 2, newByteLength));
77
+ grown.set(this.buffer.subarray(0, this.length));
78
+ this.buffer = grown;
79
+ }
80
+ this.buffer.set(chunk, this.length);
81
+ this.length += chunk.byteLength;
82
+ }
83
+ }
56
84
  /**
57
85
  * Parse a stream of size-delimited messages.
58
86
  *
@@ -61,43 +89,53 @@ function sizeDelimitedEncode(messageDesc, message, options) {
61
89
  *
62
90
  * This size-delimited format is compatible with other implementations.
63
91
  * For details, see https://github.com/protocolbuffers/protobuf/issues/10229
92
+ *
93
+ * Messages exceeding the limit given with the option readMaxBytes raise an
94
+ * error. The limit is 64 MiB by default. All other options are the
95
+ * standard binary read options, passed through to decode each message.
64
96
  */
65
97
  function sizeDelimitedDecodeStream(messageDesc, iterable, options) {
66
98
  return __asyncGenerator(this, arguments, function* sizeDelimitedDecodeStream_1() {
67
99
  var _a, e_1, _b, _c;
68
- // append chunk to buffer, returning updated buffer
69
- function append(buffer, chunk) {
70
- const n = new Uint8Array(buffer.byteLength + chunk.byteLength);
71
- n.set(buffer);
72
- n.set(chunk, buffer.length);
73
- return n;
74
- }
75
- let buffer = new Uint8Array(0);
100
+ var _d;
101
+ const readMaxBytes = (_d = options === null || options === void 0 ? void 0 : options.readMaxBytes) !== null && _d !== void 0 ? _d : defaultReadMaxBytes;
102
+ let buffer = new ByteBuffer();
76
103
  try {
77
- 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) {
104
+ for (var _e = true, iterable_1 = __asyncValues(iterable), iterable_1_1; iterable_1_1 = yield __await(iterable_1.next()), _a = iterable_1_1.done, !_a; _e = true) {
78
105
  _c = iterable_1_1.value;
79
- _d = false;
106
+ _e = false;
80
107
  const chunk = _c;
81
- buffer = append(buffer, chunk);
108
+ buffer.append(chunk);
109
+ const bytes = buffer.bytes();
110
+ let offset = 0;
82
111
  for (;;) {
83
- const size = sizeDelimitedPeek(buffer);
112
+ const size = sizeDelimitedPeek(bytes.subarray(offset));
84
113
  if (size.eof) {
85
114
  // size is incomplete, buffer more data
86
115
  break;
87
116
  }
88
- if (size.offset + size.size > buffer.byteLength) {
117
+ if (size.size > readMaxBytes) {
118
+ throw new Error(`message size ${size.size} is larger than configured readMaxBytes ${readMaxBytes}`);
119
+ }
120
+ const messageStart = offset + size.offset;
121
+ const messageEnd = messageStart + size.size;
122
+ if (messageEnd > bytes.byteLength) {
89
123
  // message is incomplete, buffer more data
90
124
  break;
91
125
  }
92
- yield yield __await((0, from_binary_js_1.fromBinary)(messageDesc, buffer.subarray(size.offset, size.offset + size.size), options));
93
- buffer = buffer.subarray(size.offset + size.size);
126
+ yield yield __await((0, from_binary_js_1.fromBinary)(messageDesc, bytes.subarray(messageStart, messageEnd), options));
127
+ offset = messageEnd;
128
+ }
129
+ if (offset > 0) {
130
+ buffer = new ByteBuffer();
131
+ buffer.append(bytes.subarray(offset));
94
132
  }
95
133
  }
96
134
  }
97
135
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
98
136
  finally {
99
137
  try {
100
- if (!_d && !_a && (_b = iterable_1.return)) yield __await(_b.call(iterable_1));
138
+ if (!_e && !_a && (_b = iterable_1.return)) yield __await(_b.call(iterable_1));
101
139
  }
102
140
  finally { if (e_1) throw e_1.error; }
103
141
  }
@@ -132,4 +132,9 @@ export declare const symbols: {
132
132
  readonly bootstrapWktFrom: "../../json-value.js";
133
133
  readonly from: "@bufbuild/protobuf";
134
134
  };
135
+ readonly UnknownEnum: {
136
+ readonly typeOnly: true;
137
+ readonly bootstrapWktFrom: "../../types.js";
138
+ readonly from: "@bufbuild/protobuf";
139
+ };
135
140
  };
@@ -9,10 +9,21 @@ import type { JsonValue } from "../json-value.js";
9
9
  export declare function enumDesc<Shape extends number, JsonType extends JsonValue = JsonValue>(file: DescFile, path: number, ...paths: number[]): GenEnum<Shape, JsonType>;
10
10
  /**
11
11
  * Construct a TypeScript enum object at runtime from a descriptor.
12
+ *
13
+ * The returned object is identical to a transpiled TS enum and includes the
14
+ * reverse mapping, see https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
12
15
  */
13
- export declare function tsEnum(desc: DescEnum): enumObject;
14
- type enumObject = {
16
+ export declare function tsEnum(desc: DescEnum): {
15
17
  [key: number]: string;
16
- [k: string]: number | string;
18
+ [k: string]: string | number;
19
+ };
20
+ /**
21
+ * Construct an object enum at runtime from a descriptor.
22
+ *
23
+ * The returned object is a record of enum value name to integer value. It's
24
+ * a subset of transpiled TS enums - it does not include the reverse mapping,
25
+ * and only supports lookup by value name.
26
+ */
27
+ export declare function objEnum(desc: DescEnum): {
28
+ [key: string]: number;
17
29
  };
18
- export {};
@@ -25,6 +25,9 @@ export function enumDesc(file, path, ...paths) {
25
25
  }
26
26
  /**
27
27
  * Construct a TypeScript enum object at runtime from a descriptor.
28
+ *
29
+ * The returned object is identical to a transpiled TS enum and includes the
30
+ * reverse mapping, see https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
28
31
  */
29
32
  export function tsEnum(desc) {
30
33
  const enumObject = {};
@@ -34,3 +37,17 @@ export function tsEnum(desc) {
34
37
  }
35
38
  return enumObject;
36
39
  }
40
+ /**
41
+ * Construct an object enum at runtime from a descriptor.
42
+ *
43
+ * The returned object is a record of enum value name to integer value. It's
44
+ * a subset of transpiled TS enums - it does not include the reverse mapping,
45
+ * and only supports lookup by value name.
46
+ */
47
+ export function objEnum(desc) {
48
+ const enumObject = {};
49
+ for (const value of desc.values) {
50
+ enumObject[value.localName] = value.number;
51
+ }
52
+ return enumObject;
53
+ }
@@ -70,6 +70,11 @@ export declare const symbols: {
70
70
  readonly bootstrapWktFrom: "../../json-value.js";
71
71
  readonly from: "@bufbuild/protobuf";
72
72
  };
73
+ readonly UnknownEnum: {
74
+ readonly typeOnly: true;
75
+ readonly bootstrapWktFrom: "../../types.js";
76
+ readonly from: "@bufbuild/protobuf";
77
+ };
73
78
  readonly codegen: {
74
79
  readonly boot: {
75
80
  readonly typeOnly: false;
@@ -106,6 +111,11 @@ export declare const symbols: {
106
111
  readonly bootstrapWktFrom: "../../codegenv2/enum.js";
107
112
  readonly from: string;
108
113
  };
114
+ readonly objEnum: {
115
+ readonly typeOnly: false;
116
+ readonly bootstrapWktFrom: "../../codegenv2/enum.js";
117
+ readonly from: string;
118
+ };
109
119
  readonly GenFile: {
110
120
  readonly typeOnly: true;
111
121
  readonly bootstrapWktFrom: "../../codegenv2/types.js";
@@ -52,6 +52,7 @@ export const symbols = {
52
52
  protoInt64: { typeOnly: false, bootstrapWktFrom: "../../proto-int64.js", from: packageName },
53
53
  JsonValue: { typeOnly: true, bootstrapWktFrom: "../../json-value.js", from: packageName },
54
54
  JsonObject: { typeOnly: true, bootstrapWktFrom: "../../json-value.js", from: packageName },
55
+ UnknownEnum: { typeOnly: true, bootstrapWktFrom: "../../types.js", from: packageName },
55
56
  codegen: {
56
57
  boot: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/boot.js", from: packageName + "/codegenv2" },
57
58
  fileDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/file.js", from: packageName + "/codegenv2" },
@@ -60,6 +61,7 @@ export const symbols = {
60
61
  messageDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/message.js", from: packageName + "/codegenv2" },
61
62
  serviceDesc: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/service.js", from: packageName + "/codegenv2" },
62
63
  tsEnum: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/enum.js", from: packageName + "/codegenv2" },
64
+ objEnum: { typeOnly: false, bootstrapWktFrom: "../../codegenv2/enum.js", from: packageName + "/codegenv2" },
63
65
  GenFile: { typeOnly: true, bootstrapWktFrom: "../../codegenv2/types.js", from: packageName + "/codegenv2" },
64
66
  GenEnum: { typeOnly: true, bootstrapWktFrom: "../../codegenv2/types.js", from: packageName + "/codegenv2" },
65
67
  GenExtension: { typeOnly: true, bootstrapWktFrom: "../../codegenv2/types.js", from: packageName + "/codegenv2" },
@@ -17,11 +17,11 @@ import { scalarZeroValue } from "./reflect/scalar.js";
17
17
  import { isObject } from "./reflect/guard.js";
18
18
  import { unsafeGet, unsafeOneofCase, unsafeSet } from "./reflect/unsafe.js";
19
19
  import { isWrapperDesc } from "./wkt/wrappers.js";
20
- // bootstrap-inject google.protobuf.Edition.EDITION_PROTO3: const $name: Edition.$localName = $number;
20
+ // bootstrap-inject google.protobuf.Edition.EDITION_PROTO3: const $name = $number;
21
21
  const EDITION_PROTO3 = 999;
22
- // bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name: Edition.$localName = $number;
22
+ // bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name = $number;
23
23
  const EDITION_PROTO2 = 998;
24
- // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
24
+ // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name = $number;
25
25
  const IMPLICIT = 2;
26
26
  /**
27
27
  * Create a new message instance.
@@ -1,7 +1,7 @@
1
1
  import type { DescriptorProto, Edition, EnumDescriptorProto, EnumValueDescriptorProto, FeatureSet_FieldPresence, FieldDescriptorProto, FileDescriptorProto, MethodDescriptorProto, MethodOptions_IdempotencyLevel, OneofDescriptorProto, ServiceDescriptorProto } from "./wkt/gen/google/protobuf/descriptor_pb.js";
2
2
  import type { ScalarValue } from "./reflect/scalar.js";
3
- export type SupportedEdition = Extract<Edition, Edition.EDITION_PROTO2 | Edition.EDITION_PROTO3 | Edition.EDITION_2023 | Edition.EDITION_2024>;
4
- type SupportedFieldPresence = Extract<FeatureSet_FieldPresence, FeatureSet_FieldPresence.EXPLICIT | FeatureSet_FieldPresence.IMPLICIT | FeatureSet_FieldPresence.LEGACY_REQUIRED>;
3
+ export type SupportedEdition = Extract<Edition, typeof Edition.EDITION_PROTO2 | typeof Edition.EDITION_PROTO3 | typeof Edition.EDITION_2023 | typeof Edition.EDITION_2024>;
4
+ type SupportedFieldPresence = Extract<FeatureSet_FieldPresence, typeof FeatureSet_FieldPresence.EXPLICIT | typeof FeatureSet_FieldPresence.IMPLICIT | typeof FeatureSet_FieldPresence.LEGACY_REQUIRED>;
5
5
  /**
6
6
  * Scalar value types. This is a subset of field types declared by protobuf
7
7
  * enum google.protobuf.FieldDescriptorProto.Type The types GROUP and MESSAGE
@@ -16,3 +16,4 @@ export * from "./from-json.js";
16
16
  export * from "./merge.js";
17
17
  export { hasExtension, getExtension, setExtension, clearExtension, hasOption, getOption, } from "./extensions.js";
18
18
  export * from "./proto-int64.js";
19
+ export * from "./unknown-enum.js";
package/dist/esm/index.js CHANGED
@@ -26,3 +26,4 @@ export * from "./from-json.js";
26
26
  export * from "./merge.js";
27
27
  export { hasExtension, getExtension, setExtension, clearExtension, hasOption, getOption, } from "./extensions.js";
28
28
  export * from "./proto-int64.js";
29
+ export * from "./unknown-enum.js";
@@ -20,6 +20,8 @@ import { isWrapper, isWrapperDesc } from "../wkt/wrappers.js";
20
20
  import { scalarZeroValue } from "./scalar.js";
21
21
  import { protoInt64 } from "../proto-int64.js";
22
22
  import { isObject, isReflectList, isReflectMap, isReflectMessage, } from "./guard.js";
23
+ // google.protobuf.NullValue.NULL_VALUE;
24
+ const NULL_VALUE = 0;
23
25
  /**
24
26
  * Create a ReflectMessage.
25
27
  */
@@ -510,8 +512,7 @@ function wktValueToReflect(json) {
510
512
  break;
511
513
  case "object":
512
514
  if (json === null) {
513
- const nullValue = 0;
514
- value.kind = { case: "nullValue", value: nullValue };
515
+ value.kind = { case: "nullValue", value: NULL_VALUE };
515
516
  }
516
517
  else if (Array.isArray(json)) {
517
518
  const listValue = {
@@ -12,7 +12,7 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  import { isScalarZeroValue, scalarZeroValue } from "./scalar.js";
15
- // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
15
+ // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name = $number;
16
16
  const IMPLICIT = 2;
17
17
  export const unsafeLocal = Symbol.for("reflect unsafe local");
18
18
  /**
@@ -187,43 +187,43 @@ function initBaseRegistry(inputs) {
187
187
  }
188
188
  return registry;
189
189
  }
190
- // bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name: Edition.$localName = $number;
190
+ // bootstrap-inject google.protobuf.Edition.EDITION_PROTO2: const $name = $number;
191
191
  const EDITION_PROTO2 = 998;
192
- // bootstrap-inject google.protobuf.Edition.EDITION_PROTO3: const $name: Edition.$localName = $number;
192
+ // bootstrap-inject google.protobuf.Edition.EDITION_PROTO3: const $name = $number;
193
193
  const EDITION_PROTO3 = 999;
194
- // bootstrap-inject google.protobuf.Edition.EDITION_UNSTABLE: const $name: Edition.$localName = $number;
194
+ // bootstrap-inject google.protobuf.Edition.EDITION_UNSTABLE: const $name = $number;
195
195
  const EDITION_UNSTABLE = 9999;
196
- // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_STRING: const $name: FieldDescriptorProto_Type.$localName = $number;
196
+ // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_STRING: const $name = $number;
197
197
  const TYPE_STRING = 9;
198
- // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_GROUP: const $name: FieldDescriptorProto_Type.$localName = $number;
198
+ // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_GROUP: const $name = $number;
199
199
  const TYPE_GROUP = 10;
200
- // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_MESSAGE: const $name: FieldDescriptorProto_Type.$localName = $number;
200
+ // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_MESSAGE: const $name = $number;
201
201
  const TYPE_MESSAGE = 11;
202
- // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_BYTES: const $name: FieldDescriptorProto_Type.$localName = $number;
202
+ // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_BYTES: const $name = $number;
203
203
  const TYPE_BYTES = 12;
204
- // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_ENUM: const $name: FieldDescriptorProto_Type.$localName = $number;
204
+ // bootstrap-inject google.protobuf.FieldDescriptorProto.Type.TYPE_ENUM: const $name = $number;
205
205
  const TYPE_ENUM = 14;
206
- // bootstrap-inject google.protobuf.FieldDescriptorProto.Label.LABEL_REPEATED: const $name: FieldDescriptorProto_Label.$localName = $number;
206
+ // bootstrap-inject google.protobuf.FieldDescriptorProto.Label.LABEL_REPEATED: const $name = $number;
207
207
  const LABEL_REPEATED = 3;
208
- // bootstrap-inject google.protobuf.FieldDescriptorProto.Label.LABEL_REQUIRED: const $name: FieldDescriptorProto_Label.$localName = $number;
208
+ // bootstrap-inject google.protobuf.FieldDescriptorProto.Label.LABEL_REQUIRED: const $name = $number;
209
209
  const LABEL_REQUIRED = 2;
210
- // bootstrap-inject google.protobuf.FieldOptions.JSType.JS_STRING: const $name: FieldOptions_JSType.$localName = $number;
210
+ // bootstrap-inject google.protobuf.FieldOptions.JSType.JS_STRING: const $name = $number;
211
211
  const JS_STRING = 1;
212
- // bootstrap-inject google.protobuf.MethodOptions.IdempotencyLevel.IDEMPOTENCY_UNKNOWN: const $name: MethodOptions_IdempotencyLevel.$localName = $number;
212
+ // bootstrap-inject google.protobuf.MethodOptions.IdempotencyLevel.IDEMPOTENCY_UNKNOWN: const $name = $number;
213
213
  const IDEMPOTENCY_UNKNOWN = 0;
214
- // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.EXPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
214
+ // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.EXPLICIT: const $name = $number;
215
215
  const EXPLICIT = 1;
216
- // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
216
+ // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name = $number;
217
217
  const IMPLICIT = 2;
218
- // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name: FeatureSet_FieldPresence.$localName = $number;
218
+ // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name = $number;
219
219
  const LEGACY_REQUIRED = 3;
220
- // bootstrap-inject google.protobuf.FeatureSet.RepeatedFieldEncoding.PACKED: const $name: FeatureSet_RepeatedFieldEncoding.$localName = $number;
220
+ // bootstrap-inject google.protobuf.FeatureSet.RepeatedFieldEncoding.PACKED: const $name = $number;
221
221
  const PACKED = 1;
222
- // bootstrap-inject google.protobuf.FeatureSet.MessageEncoding.DELIMITED: const $name: FeatureSet_MessageEncoding.$localName = $number;
222
+ // bootstrap-inject google.protobuf.FeatureSet.MessageEncoding.DELIMITED: const $name = $number;
223
223
  const DELIMITED = 2;
224
- // bootstrap-inject google.protobuf.FeatureSet.EnumType.OPEN: const $name: FeatureSet_EnumType.$localName = $number;
224
+ // bootstrap-inject google.protobuf.FeatureSet.EnumType.OPEN: const $name = $number;
225
225
  const OPEN = 1;
226
- // bootstrap-inject google.protobuf.FeatureSet.Utf8Validation.VERIFY: const $name: FeatureSet_Utf8Validation.$localName = $number;
226
+ // bootstrap-inject google.protobuf.FeatureSet.Utf8Validation.VERIFY: const $name = $number;
227
227
  const VERIFY = 2;
228
228
  // biome-ignore format: want this to read well
229
229
  // bootstrap-inject defaults: EDITION_PROTO2 to EDITION_2024: export const minimumEdition: SupportedEdition = $minimumEdition, maximumEdition: SupportedEdition = $maximumEdition;
@@ -14,7 +14,7 @@
14
14
  import { reflect } from "./reflect/reflect.js";
15
15
  import { BinaryWriter, WireType } from "./wire/binary-encoding.js";
16
16
  import { ScalarType } from "./descriptors.js";
17
- // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name: FeatureSet_FieldPresence.$localName = $number;
17
+ // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name = $number;
18
18
  const LEGACY_REQUIRED = 3;
19
19
  // Default options for serializing binary data.
20
20
  const writeDefaults = {
@@ -19,9 +19,9 @@ import { hasCustomJsonRepresentation, isWrapperDesc } from "./wkt/wrappers.js";
19
19
  import { base64Encode } from "./wire/index.js";
20
20
  import { createExtensionContainer, getExtension } from "./extensions.js";
21
21
  import { checkField, formatVal } from "./reflect/reflect-check.js";
22
- // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name: FeatureSet_FieldPresence.$localName = $number;
22
+ // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.LEGACY_REQUIRED: const $name = $number;
23
23
  const LEGACY_REQUIRED = 3;
24
- // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name: FeatureSet_FieldPresence.$localName = $number;
24
+ // bootstrap-inject google.protobuf.FeatureSet.FieldPresence.IMPLICIT: const $name = $number;
25
25
  const IMPLICIT = 2;
26
26
  // Default options for serializing to JSON.
27
27
  const jsonWriteDefaults = {
@@ -0,0 +1,35 @@
1
+ import { type DescMessage } from "../descriptors.js";
2
+ import type { Registry } from "../registry.js";
3
+ import type { MessageShape } from "../types.js";
4
+ /**
5
+ * Options for parsing the protobuf text format.
6
+ */
7
+ export interface TextReadOptions {
8
+ /**
9
+ * The registry to resolve `google.protobuf.Any` and extensions. Parsing an
10
+ * Any in its expanded form, or an extension field, requires it.
11
+ */
12
+ registry?: Registry | undefined;
13
+ /**
14
+ * The maximum depth of nested messages to parse. A message nesting deeper
15
+ * than this fails with an error instead of exhausting the call stack.
16
+ * Defaults to 100.
17
+ */
18
+ recursionLimit: number;
19
+ }
20
+ /**
21
+ * Parse a message from the protobuf text format.
22
+ *
23
+ * Requires BigInt: throws immediately if the environment does not support it.
24
+ */
25
+ export declare function fromText<Desc extends DescMessage>(schema: Desc, text: string, options?: Partial<TextReadOptions>): MessageShape<Desc>;
26
+ /**
27
+ * Parse a message from the protobuf text format, merging into the target.
28
+ *
29
+ * Repeated fields are appended, singular fields are overwritten (last wins),
30
+ * message fields are merged, and map entries are added (overwriting an existing
31
+ * key).
32
+ *
33
+ * Requires BigInt: throws immediately if the environment does not support it.
34
+ */
35
+ export declare function mergeFromText<Desc extends DescMessage>(schema: Desc, target: MessageShape<Desc>, text: string, options?: Partial<TextReadOptions>): MessageShape<Desc>;