@bufbuild/protobuf 1.6.0 → 1.7.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 (151) hide show
  1. package/dist/cjs/binary-encoding.js +2 -3
  2. package/dist/cjs/binary-format.d.ts +17 -0
  3. package/dist/cjs/binary-format.js +1 -1
  4. package/dist/cjs/codegen-info.d.ts +4 -4
  5. package/dist/cjs/codegen-info.js +2 -1
  6. package/dist/cjs/create-descriptor-set.d.ts +1 -1
  7. package/dist/cjs/create-descriptor-set.js +56 -50
  8. package/dist/cjs/create-registry-from-desc.d.ts +2 -2
  9. package/dist/cjs/create-registry-from-desc.js +53 -9
  10. package/dist/cjs/create-registry.d.ts +3 -2
  11. package/dist/cjs/create-registry.js +56 -37
  12. package/dist/cjs/descriptor-set.js +1 -1
  13. package/dist/cjs/enum.js +1 -1
  14. package/dist/cjs/extension-accessor.d.ts +35 -0
  15. package/dist/cjs/extension-accessor.js +108 -0
  16. package/dist/cjs/extension.d.ts +24 -0
  17. package/dist/cjs/extension.js +15 -0
  18. package/dist/cjs/field-list.js +1 -1
  19. package/dist/cjs/field.js +1 -1
  20. package/dist/cjs/google/protobuf/any_pb.js +1 -1
  21. package/dist/cjs/google/protobuf/api_pb.js +1 -1
  22. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +1 -1
  23. package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
  24. package/dist/cjs/google/protobuf/duration_pb.js +1 -1
  25. package/dist/cjs/google/protobuf/empty_pb.js +1 -1
  26. package/dist/cjs/google/protobuf/field_mask_pb.js +1 -1
  27. package/dist/cjs/google/protobuf/source_context_pb.js +1 -1
  28. package/dist/cjs/google/protobuf/struct_pb.js +2 -2
  29. package/dist/cjs/google/protobuf/timestamp_pb.js +1 -1
  30. package/dist/cjs/google/protobuf/type_pb.js +2 -2
  31. package/dist/cjs/google/protobuf/wrappers_pb.js +1 -1
  32. package/dist/cjs/index.d.ts +3 -1
  33. package/dist/cjs/index.js +7 -2
  34. package/dist/cjs/json-format.d.ts +5 -5
  35. package/dist/cjs/json-format.js +1 -1
  36. package/dist/cjs/message-type.js +1 -1
  37. package/dist/cjs/message.js +1 -1
  38. package/dist/cjs/private/assert.js +1 -1
  39. package/dist/cjs/private/binary-format-common.d.ts +2 -3
  40. package/dist/cjs/private/binary-format-common.js +80 -78
  41. package/dist/cjs/private/binary-format-proto2.js +59 -64
  42. package/dist/cjs/private/binary-format-proto3.js +44 -40
  43. package/dist/cjs/private/enum.js +1 -1
  44. package/dist/cjs/private/extensions.d.ts +34 -0
  45. package/dist/cjs/private/extensions.js +86 -0
  46. package/dist/cjs/private/feature-set.d.ts +3 -3
  47. package/dist/cjs/private/feature-set.js +27 -32
  48. package/dist/cjs/private/field-list.js +1 -1
  49. package/dist/cjs/private/field-wrapper.d.ts +2 -2
  50. package/dist/cjs/private/field-wrapper.js +1 -1
  51. package/dist/cjs/private/field.js +1 -1
  52. package/dist/cjs/private/json-format-common.js +202 -156
  53. package/dist/cjs/private/json-format-proto2.js +2 -1
  54. package/dist/cjs/private/json-format-proto3.js +7 -5
  55. package/dist/cjs/private/message-type.js +1 -1
  56. package/dist/cjs/private/names.d.ts +2 -2
  57. package/dist/cjs/private/names.js +3 -2
  58. package/dist/cjs/private/options-map.js +1 -1
  59. package/dist/cjs/private/proto-runtime.d.ts +6 -0
  60. package/dist/cjs/private/proto-runtime.js +5 -1
  61. package/dist/cjs/private/reify-wkt.js +1 -1
  62. package/dist/cjs/private/scalars.js +1 -1
  63. package/dist/cjs/private/text-format.js +1 -1
  64. package/dist/cjs/private/util-common.js +1 -1
  65. package/dist/cjs/private/util.js +1 -1
  66. package/dist/cjs/proto-base64.js +1 -1
  67. package/dist/cjs/proto-delimited.js +1 -1
  68. package/dist/cjs/proto-double.js +1 -1
  69. package/dist/cjs/proto-int64.js +1 -1
  70. package/dist/cjs/proto2.js +1 -1
  71. package/dist/cjs/proto3.js +1 -1
  72. package/dist/cjs/service-type.js +1 -1
  73. package/dist/cjs/to-plain-message.js +1 -1
  74. package/dist/cjs/type-registry.d.ts +14 -0
  75. package/dist/cjs/type-registry.js +1 -1
  76. package/dist/esm/binary-encoding.js +2 -3
  77. package/dist/esm/binary-format.d.ts +17 -0
  78. package/dist/esm/binary-format.js +1 -1
  79. package/dist/esm/codegen-info.d.ts +4 -4
  80. package/dist/esm/codegen-info.js +2 -1
  81. package/dist/esm/create-descriptor-set.d.ts +1 -1
  82. package/dist/esm/create-descriptor-set.js +56 -50
  83. package/dist/esm/create-registry-from-desc.d.ts +2 -2
  84. package/dist/esm/create-registry-from-desc.js +53 -9
  85. package/dist/esm/create-registry.d.ts +3 -2
  86. package/dist/esm/create-registry.js +56 -37
  87. package/dist/esm/descriptor-set.js +1 -1
  88. package/dist/esm/enum.js +1 -1
  89. package/dist/esm/extension-accessor.d.ts +35 -0
  90. package/dist/esm/extension-accessor.js +101 -0
  91. package/dist/esm/extension.d.ts +24 -0
  92. package/dist/esm/extension.js +14 -0
  93. package/dist/esm/field-list.js +1 -1
  94. package/dist/esm/field.js +1 -1
  95. package/dist/esm/google/protobuf/any_pb.js +1 -1
  96. package/dist/esm/google/protobuf/api_pb.js +1 -1
  97. package/dist/esm/google/protobuf/compiler/plugin_pb.js +1 -1
  98. package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
  99. package/dist/esm/google/protobuf/duration_pb.js +1 -1
  100. package/dist/esm/google/protobuf/empty_pb.js +1 -1
  101. package/dist/esm/google/protobuf/field_mask_pb.js +1 -1
  102. package/dist/esm/google/protobuf/source_context_pb.js +1 -1
  103. package/dist/esm/google/protobuf/struct_pb.js +2 -2
  104. package/dist/esm/google/protobuf/timestamp_pb.js +1 -1
  105. package/dist/esm/google/protobuf/type_pb.js +2 -2
  106. package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
  107. package/dist/esm/index.d.ts +3 -1
  108. package/dist/esm/index.js +2 -1
  109. package/dist/esm/json-format.d.ts +5 -5
  110. package/dist/esm/json-format.js +1 -1
  111. package/dist/esm/message-type.js +1 -1
  112. package/dist/esm/message.js +1 -1
  113. package/dist/esm/private/assert.js +1 -1
  114. package/dist/esm/private/binary-format-common.d.ts +2 -3
  115. package/dist/esm/private/binary-format-common.js +80 -77
  116. package/dist/esm/private/binary-format-proto2.js +59 -64
  117. package/dist/esm/private/binary-format-proto3.js +44 -40
  118. package/dist/esm/private/enum.js +1 -1
  119. package/dist/esm/private/extensions.d.ts +34 -0
  120. package/dist/esm/private/extensions.js +81 -0
  121. package/dist/esm/private/feature-set.d.ts +3 -3
  122. package/dist/esm/private/feature-set.js +27 -32
  123. package/dist/esm/private/field-list.js +1 -1
  124. package/dist/esm/private/field-wrapper.d.ts +2 -2
  125. package/dist/esm/private/field-wrapper.js +1 -1
  126. package/dist/esm/private/field.js +1 -1
  127. package/dist/esm/private/json-format-common.js +202 -156
  128. package/dist/esm/private/json-format-proto2.js +2 -1
  129. package/dist/esm/private/json-format-proto3.js +7 -5
  130. package/dist/esm/private/message-type.js +1 -1
  131. package/dist/esm/private/names.d.ts +2 -2
  132. package/dist/esm/private/names.js +3 -2
  133. package/dist/esm/private/options-map.js +1 -1
  134. package/dist/esm/private/proto-runtime.d.ts +6 -0
  135. package/dist/esm/private/proto-runtime.js +5 -1
  136. package/dist/esm/private/reify-wkt.js +1 -1
  137. package/dist/esm/private/scalars.js +1 -1
  138. package/dist/esm/private/text-format.js +1 -1
  139. package/dist/esm/private/util-common.js +1 -1
  140. package/dist/esm/private/util.js +1 -1
  141. package/dist/esm/proto-base64.js +1 -1
  142. package/dist/esm/proto-delimited.js +1 -1
  143. package/dist/esm/proto-double.js +1 -1
  144. package/dist/esm/proto-int64.js +1 -1
  145. package/dist/esm/proto2.js +1 -1
  146. package/dist/esm/proto3.js +1 -1
  147. package/dist/esm/service-type.js +1 -1
  148. package/dist/esm/to-plain-message.js +1 -1
  149. package/dist/esm/type-registry.d.ts +14 -0
  150. package/dist/esm/type-registry.js +1 -1
  151. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -21,42 +21,9 @@ function createRegistry(...types) {
21
21
  const messages = {};
22
22
  const enums = {};
23
23
  const services = {};
24
+ const extensionsByName = new Map();
25
+ const extensionsByExtendee = new Map();
24
26
  const registry = {
25
- /**
26
- * Add a type to the registry. For messages, the types used in message
27
- * fields are added recursively. For services, the message types used
28
- * for requests and responses are added recursively.
29
- */
30
- add(type) {
31
- if ("fields" in type) {
32
- if (!this.findMessage(type.typeName)) {
33
- messages[type.typeName] = type;
34
- for (const field of type.fields.list()) {
35
- if (field.kind == "message") {
36
- this.add(field.T);
37
- }
38
- else if (field.kind == "map" && field.V.kind == "message") {
39
- this.add(field.V.T);
40
- }
41
- else if (field.kind == "enum") {
42
- this.add(field.T);
43
- }
44
- }
45
- }
46
- }
47
- else if ("methods" in type) {
48
- if (!this.findService(type.typeName)) {
49
- services[type.typeName] = type;
50
- for (const method of Object.values(type.methods)) {
51
- this.add(method.I);
52
- this.add(method.O);
53
- }
54
- }
55
- }
56
- else {
57
- enums[type.typeName] = type;
58
- }
59
- },
60
27
  findMessage(typeName) {
61
28
  return messages[typeName];
62
29
  },
@@ -66,9 +33,61 @@ function createRegistry(...types) {
66
33
  findService(typeName) {
67
34
  return services[typeName];
68
35
  },
36
+ findExtensionFor(typeName, no) {
37
+ var _a, _b;
38
+ return (_b = (_a = extensionsByExtendee.get(typeName)) === null || _a === void 0 ? void 0 : _a.get(no)) !== null && _b !== void 0 ? _b : undefined;
39
+ },
40
+ findExtension(typeName) {
41
+ var _a;
42
+ return (_a = extensionsByName.get(typeName)) !== null && _a !== void 0 ? _a : undefined;
43
+ },
69
44
  };
45
+ function addType(type) {
46
+ var _a;
47
+ if ("fields" in type) {
48
+ if (!registry.findMessage(type.typeName)) {
49
+ messages[type.typeName] = type;
50
+ type.fields.list().forEach(addField);
51
+ }
52
+ }
53
+ else if ("methods" in type) {
54
+ if (!registry.findService(type.typeName)) {
55
+ services[type.typeName] = type;
56
+ for (const method of Object.values(type.methods)) {
57
+ addType(method.I);
58
+ addType(method.O);
59
+ }
60
+ }
61
+ }
62
+ else if ("extendee" in type) {
63
+ if (!extensionsByName.has(type.typeName)) {
64
+ extensionsByName.set(type.typeName, type);
65
+ const extendeeName = type.extendee.typeName;
66
+ if (!extensionsByExtendee.has(extendeeName)) {
67
+ extensionsByExtendee.set(extendeeName, new Map());
68
+ }
69
+ (_a = extensionsByExtendee.get(extendeeName)) === null || _a === void 0 ? void 0 : _a.set(type.field.no, type);
70
+ addType(type.extendee);
71
+ addField(type.field);
72
+ }
73
+ }
74
+ else {
75
+ enums[type.typeName] = type;
76
+ }
77
+ }
78
+ function addField(field) {
79
+ if (field.kind == "message") {
80
+ addType(field.T);
81
+ }
82
+ else if (field.kind == "map" && field.V.kind == "message") {
83
+ addType(field.V.T);
84
+ }
85
+ else if (field.kind == "enum") {
86
+ addType(field.T);
87
+ }
88
+ }
70
89
  for (const type of types) {
71
- registry.add(type);
90
+ addType(type);
72
91
  }
73
92
  return registry;
74
93
  }
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
package/dist/cjs/enum.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -0,0 +1,35 @@
1
+ import type { Message } from "./message.js";
2
+ import type { BinaryReadOptions, BinaryWriteOptions } from "./binary-format.js";
3
+ import type { Extension } from "./extension.js";
4
+ /**
5
+ * Retrieve an extension value from a message.
6
+ *
7
+ * The function never returns undefined. Use hasExtension() to check whether an
8
+ * extension is set. If the extension is not set, this function returns the
9
+ * default value (if one was specified in the protobuf source), or the zero value
10
+ * (for example `0` for numeric types, `[]` for repeated extension fields, and
11
+ * an empty message instance for message fields).
12
+ *
13
+ * Extensions are stored as unknown fields on a message. To mutate an extension
14
+ * value, make sure to store the new value with setExtension() after mutating.
15
+ *
16
+ * If the extension does not extend the given message, an error is raised.
17
+ */
18
+ export declare function getExtension<E extends Message<E>, V>(message: E, extension: Extension<E, V>, options?: Partial<BinaryReadOptions>): V;
19
+ /**
20
+ * Set an extension value on a message. If the message already has a value for
21
+ * this extension, the value is replaced.
22
+ *
23
+ * If the extension does not extend the given message, an error is raised.
24
+ */
25
+ export declare function setExtension<E extends Message<E>, V>(message: E, extension: Extension<E, V>, value: V, options?: Partial<BinaryReadOptions & BinaryWriteOptions>): void;
26
+ /**
27
+ * Remove an extension value from a message.
28
+ *
29
+ * If the extension does not extend the given message, an error is raised.
30
+ */
31
+ export declare function clearExtension<E extends Message<E>, V>(message: E, extension: Extension<E, V>): void;
32
+ /**
33
+ * Check whether an extension is set on a message.
34
+ */
35
+ export declare function hasExtension<E extends Message<E>, V>(message: E, extension: Extension<E, V>): boolean;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 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.hasExtension = exports.clearExtension = exports.setExtension = exports.getExtension = void 0;
17
+ const assert_js_1 = require("./private/assert.js");
18
+ const extensions_js_1 = require("./private/extensions.js");
19
+ /**
20
+ * Retrieve an extension value from a message.
21
+ *
22
+ * The function never returns undefined. Use hasExtension() to check whether an
23
+ * extension is set. If the extension is not set, this function returns the
24
+ * default value (if one was specified in the protobuf source), or the zero value
25
+ * (for example `0` for numeric types, `[]` for repeated extension fields, and
26
+ * an empty message instance for message fields).
27
+ *
28
+ * Extensions are stored as unknown fields on a message. To mutate an extension
29
+ * value, make sure to store the new value with setExtension() after mutating.
30
+ *
31
+ * If the extension does not extend the given message, an error is raised.
32
+ */
33
+ function getExtension(message, extension, options) {
34
+ assertExtendee(extension, message);
35
+ const opt = extension.runtime.bin.makeReadOptions(options);
36
+ const ufs = (0, extensions_js_1.filterUnknownFields)(message.getType().runtime.bin.listUnknownFields(message), extension.field);
37
+ const [container, get] = (0, extensions_js_1.createExtensionContainer)(extension);
38
+ for (const uf of ufs) {
39
+ extension.runtime.bin.readField(container, opt.readerFactory(uf.data), extension.field, uf.wireType, opt);
40
+ }
41
+ return get();
42
+ }
43
+ exports.getExtension = getExtension;
44
+ /**
45
+ * Set an extension value on a message. If the message already has a value for
46
+ * this extension, the value is replaced.
47
+ *
48
+ * If the extension does not extend the given message, an error is raised.
49
+ */
50
+ function setExtension(message, extension, value, options) {
51
+ assertExtendee(extension, message);
52
+ const readOpt = extension.runtime.bin.makeReadOptions(options);
53
+ const writeOpt = extension.runtime.bin.makeWriteOptions(options);
54
+ if (hasExtension(message, extension)) {
55
+ const ufs = message
56
+ .getType()
57
+ .runtime.bin.listUnknownFields(message)
58
+ .filter((uf) => uf.no != extension.field.no);
59
+ message.getType().runtime.bin.discardUnknownFields(message);
60
+ for (const uf of ufs) {
61
+ message
62
+ .getType()
63
+ .runtime.bin.onUnknownField(message, uf.no, uf.wireType, uf.data);
64
+ }
65
+ }
66
+ const writer = writeOpt.writerFactory();
67
+ extension.runtime.bin.writeField(extension.field, value, writer, writeOpt);
68
+ const reader = readOpt.readerFactory(writer.finish());
69
+ while (reader.pos < reader.len) {
70
+ const [no, wireType] = reader.tag();
71
+ const data = reader.skip(wireType);
72
+ message.getType().runtime.bin.onUnknownField(message, no, wireType, data);
73
+ }
74
+ }
75
+ exports.setExtension = setExtension;
76
+ /**
77
+ * Remove an extension value from a message.
78
+ *
79
+ * If the extension does not extend the given message, an error is raised.
80
+ */
81
+ function clearExtension(message, extension) {
82
+ assertExtendee(extension, message);
83
+ if (hasExtension(message, extension)) {
84
+ const bin = message.getType().runtime.bin;
85
+ const ufs = bin
86
+ .listUnknownFields(message)
87
+ .filter((uf) => uf.no != extension.field.no);
88
+ bin.discardUnknownFields(message);
89
+ for (const uf of ufs) {
90
+ bin.onUnknownField(message, uf.no, uf.wireType, uf.data);
91
+ }
92
+ }
93
+ }
94
+ exports.clearExtension = clearExtension;
95
+ /**
96
+ * Check whether an extension is set on a message.
97
+ */
98
+ function hasExtension(message, extension) {
99
+ const messageType = message.getType();
100
+ return (extension.extendee.typeName === messageType.typeName &&
101
+ !!messageType.runtime.bin
102
+ .listUnknownFields(message)
103
+ .find((uf) => uf.no == extension.field.no));
104
+ }
105
+ exports.hasExtension = hasExtension;
106
+ function assertExtendee(extension, message) {
107
+ (0, assert_js_1.assert)(extension.extendee.typeName == message.getType().typeName, `extension ${extension.typeName} can only be applied to message ${extension.extendee.typeName}`);
108
+ }
@@ -0,0 +1,24 @@
1
+ import type { FieldInfo } from "./field.js";
2
+ import type { AnyMessage, Message } from "./message.js";
3
+ import type { MessageType } from "./message-type.js";
4
+ import type { ProtoRuntime } from "./private/proto-runtime.js";
5
+ export interface Extension<E extends Message<E> = AnyMessage, V = unknown> {
6
+ /**
7
+ * The fully qualified name of the extension.
8
+ */
9
+ readonly typeName: string;
10
+ /**
11
+ * The message extended by this extension.
12
+ */
13
+ readonly extendee: MessageType<E>;
14
+ /**
15
+ * Field information for this extension. Note that required fields, maps,
16
+ * oneof are not allowed in extensions. Behavior of "localName" property is
17
+ * undefined and must not be relied upon.
18
+ */
19
+ readonly field: FieldInfo;
20
+ /**
21
+ * Provides serialization and other functionality.
22
+ */
23
+ readonly runtime: ProtoRuntime;
24
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // Copyright 2021-2024 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 });
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
package/dist/cjs/field.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ exports.GeneratedCodeInfo_Annotation_Semantic = exports.GeneratedCodeInfo_Annota
21
21
  // The messages in this file describe the definitions found in .proto files.
22
22
  // A valid .proto file can be translated directly to a FileDescriptorProto
23
23
  // without any other information (e.g. without reading its imports).
24
- // @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
24
+ // @generated by protoc-gen-es v1.7.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
25
25
  // @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
26
26
  /* eslint-disable */
27
27
  const proto2_js_1 = require("../../proto2.js");
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
17
- // @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v1.7.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
17
- // @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v1.7.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -12,6 +12,8 @@ export type { FieldList } from "./field-list.js";
12
12
  export { ScalarType, LongType } from "./field.js";
13
13
  export type { MessageType } from "./message-type.js";
14
14
  export type { EnumType, EnumValueInfo } from "./enum.js";
15
+ export type { Extension } from "./extension.js";
16
+ export { getExtension, setExtension, hasExtension, clearExtension, } from "./extension-accessor.js";
15
17
  export type { ServiceType, MethodInfo, MethodInfoUnary, MethodInfoServerStreaming, MethodInfoClientStreaming, MethodInfoBiDiStreaming, } from "./service-type.js";
16
18
  export { MethodKind, MethodIdempotency } from "./service-type.js";
17
19
  export { WireType, BinaryWriter, BinaryReader } from "./binary-encoding.js";
@@ -20,7 +22,7 @@ export type { BinaryFormat, BinaryWriteOptions, BinaryReadOptions, } from "./bin
20
22
  export type { JsonFormat, JsonObject, JsonValue, JsonReadOptions, JsonWriteOptions, JsonWriteStringOptions, } from "./json-format.js";
21
23
  export type { DescriptorSet, AnyDesc, DescFile, DescEnum, DescEnumValue, DescMessage, DescOneof, DescField, DescService, DescMethod, DescExtension, DescComments, } from "./descriptor-set.js";
22
24
  export { createDescriptorSet } from "./create-descriptor-set.js";
23
- export type { IMessageTypeRegistry } from "./type-registry.js";
25
+ export type { IMessageTypeRegistry, IExtensionRegistry, } from "./type-registry.js";
24
26
  export { createRegistry } from "./create-registry.js";
25
27
  export { createRegistryFromDescriptors } from "./create-registry-from-desc.js";
26
28
  export { toPlainMessage } from "./to-plain-message.js";
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
27
27
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.toPlainMessage = exports.createRegistryFromDescriptors = exports.createRegistry = exports.createDescriptorSet = exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.MethodIdempotency = exports.MethodKind = exports.LongType = exports.ScalarType = exports.Message = exports.codegenInfo = exports.protoDelimited = exports.protoBase64 = exports.protoInt64 = exports.protoDouble = exports.proto2 = exports.proto3 = void 0;
30
+ exports.toPlainMessage = exports.createRegistryFromDescriptors = exports.createRegistry = exports.createDescriptorSet = exports.BinaryReader = exports.BinaryWriter = exports.WireType = exports.MethodIdempotency = exports.MethodKind = exports.clearExtension = exports.hasExtension = exports.setExtension = exports.getExtension = exports.LongType = exports.ScalarType = exports.Message = exports.codegenInfo = exports.protoDelimited = exports.protoBase64 = exports.protoInt64 = exports.protoDouble = exports.proto2 = exports.proto3 = void 0;
31
31
  var proto3_js_1 = require("./proto3.js");
32
32
  Object.defineProperty(exports, "proto3", { enumerable: true, get: function () { return proto3_js_1.proto3; } });
33
33
  var proto2_js_1 = require("./proto2.js");
@@ -47,6 +47,11 @@ Object.defineProperty(exports, "Message", { enumerable: true, get: function () {
47
47
  var field_js_1 = require("./field.js");
48
48
  Object.defineProperty(exports, "ScalarType", { enumerable: true, get: function () { return field_js_1.ScalarType; } });
49
49
  Object.defineProperty(exports, "LongType", { enumerable: true, get: function () { return field_js_1.LongType; } });
50
+ var extension_accessor_js_1 = require("./extension-accessor.js");
51
+ Object.defineProperty(exports, "getExtension", { enumerable: true, get: function () { return extension_accessor_js_1.getExtension; } });
52
+ Object.defineProperty(exports, "setExtension", { enumerable: true, get: function () { return extension_accessor_js_1.setExtension; } });
53
+ Object.defineProperty(exports, "hasExtension", { enumerable: true, get: function () { return extension_accessor_js_1.hasExtension; } });
54
+ Object.defineProperty(exports, "clearExtension", { enumerable: true, get: function () { return extension_accessor_js_1.clearExtension; } });
50
55
  var service_type_js_1 = require("./service-type.js");
51
56
  Object.defineProperty(exports, "MethodKind", { enumerable: true, get: function () { return service_type_js_1.MethodKind; } });
52
57
  Object.defineProperty(exports, "MethodIdempotency", { enumerable: true, get: function () { return service_type_js_1.MethodIdempotency; } });
@@ -2,7 +2,7 @@ import type { Message } from "./message.js";
2
2
  import type { MessageType } from "./message-type.js";
3
3
  import type { ScalarType } from "./field.js";
4
4
  import { LongType } from "./field.js";
5
- import type { IMessageTypeRegistry } from "./type-registry.js";
5
+ import type { IExtensionRegistry, IMessageTypeRegistry } from "./type-registry.js";
6
6
  /**
7
7
  * JsonFormat is the contract for serializing messages to and from JSON.
8
8
  * Implementations may be specific to a proto syntax, and can be reflection
@@ -52,10 +52,10 @@ export interface JsonReadOptions {
52
52
  */
53
53
  ignoreUnknownFields: boolean;
54
54
  /**
55
- * This option is required to read `google.protobuf.Any`
55
+ * This option is required to read `google.protobuf.Any` and extensions
56
56
  * from JSON format.
57
57
  */
58
- typeRegistry?: IMessageTypeRegistry;
58
+ typeRegistry?: IMessageTypeRegistry & Partial<IExtensionRegistry>;
59
59
  }
60
60
  /**
61
61
  * Options for serializing to JSON.
@@ -83,10 +83,10 @@ export interface JsonWriteOptions {
83
83
  */
84
84
  useProtoFieldName: boolean;
85
85
  /**
86
- * This option is required to write `google.protobuf.Any`
86
+ * This option is required to write `google.protobuf.Any` and extensions
87
87
  * to JSON format.
88
88
  */
89
- typeRegistry?: IMessageTypeRegistry;
89
+ typeRegistry?: IMessageTypeRegistry & Partial<IExtensionRegistry>;
90
90
  }
91
91
  /**
92
92
  * Options for serializing to JSON.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2023 Buf Technologies, Inc.
2
+ // Copyright 2021-2024 Buf Technologies, Inc.
3
3
  //
4
4
  // Licensed under the Apache License, Version 2.0 (the "License");
5
5
  // you may not use this file except in compliance with the License.
@@ -1,9 +1,8 @@
1
- import type { IBinaryReader, IBinaryWriter } from "../binary-encoding.js";
1
+ import type { IBinaryWriter } from "../binary-encoding.js";
2
2
  import type { BinaryFormat, BinaryWriteOptions } from "../binary-format.js";
3
3
  import type { FieldInfo } from "../field.js";
4
4
  import { ScalarType } from "../field.js";
5
- export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage">;
6
- export declare function readScalarLTString(reader: IBinaryReader, type: ScalarType): any;
5
+ export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage" | "writeField">;
7
6
  export declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
8
7
  kind: "map";
9
8
  }, key: any, value: any): void;