@bufbuild/protobuf 1.6.0 → 1.7.1

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 (153) 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 +7 -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 +6 -8
  47. package/dist/cjs/private/feature-set.js +41 -42
  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.d.ts +3 -3
  53. package/dist/cjs/private/json-format-common.js +228 -173
  54. package/dist/cjs/private/json-format-proto2.js +3 -2
  55. package/dist/cjs/private/json-format-proto3.js +8 -6
  56. package/dist/cjs/private/message-type.js +1 -1
  57. package/dist/cjs/private/names.d.ts +2 -2
  58. package/dist/cjs/private/names.js +3 -2
  59. package/dist/cjs/private/options-map.js +1 -1
  60. package/dist/cjs/private/proto-runtime.d.ts +6 -0
  61. package/dist/cjs/private/proto-runtime.js +5 -1
  62. package/dist/cjs/private/reify-wkt.js +1 -1
  63. package/dist/cjs/private/scalars.js +1 -1
  64. package/dist/cjs/private/text-format.js +1 -1
  65. package/dist/cjs/private/util-common.js +1 -1
  66. package/dist/cjs/private/util.js +1 -1
  67. package/dist/cjs/proto-base64.js +1 -1
  68. package/dist/cjs/proto-delimited.js +1 -1
  69. package/dist/cjs/proto-double.js +1 -1
  70. package/dist/cjs/proto-int64.js +1 -1
  71. package/dist/cjs/proto2.js +1 -1
  72. package/dist/cjs/proto3.js +1 -1
  73. package/dist/cjs/service-type.js +1 -1
  74. package/dist/cjs/to-plain-message.js +1 -1
  75. package/dist/cjs/type-registry.d.ts +14 -0
  76. package/dist/cjs/type-registry.js +1 -1
  77. package/dist/esm/binary-encoding.js +2 -3
  78. package/dist/esm/binary-format.d.ts +17 -0
  79. package/dist/esm/binary-format.js +1 -1
  80. package/dist/esm/codegen-info.d.ts +4 -4
  81. package/dist/esm/codegen-info.js +2 -1
  82. package/dist/esm/create-descriptor-set.d.ts +7 -1
  83. package/dist/esm/create-descriptor-set.js +57 -51
  84. package/dist/esm/create-registry-from-desc.d.ts +2 -2
  85. package/dist/esm/create-registry-from-desc.js +53 -9
  86. package/dist/esm/create-registry.d.ts +3 -2
  87. package/dist/esm/create-registry.js +56 -37
  88. package/dist/esm/descriptor-set.js +1 -1
  89. package/dist/esm/enum.js +1 -1
  90. package/dist/esm/extension-accessor.d.ts +35 -0
  91. package/dist/esm/extension-accessor.js +101 -0
  92. package/dist/esm/extension.d.ts +24 -0
  93. package/dist/esm/extension.js +14 -0
  94. package/dist/esm/field-list.js +1 -1
  95. package/dist/esm/field.js +1 -1
  96. package/dist/esm/google/protobuf/any_pb.js +1 -1
  97. package/dist/esm/google/protobuf/api_pb.js +1 -1
  98. package/dist/esm/google/protobuf/compiler/plugin_pb.js +1 -1
  99. package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
  100. package/dist/esm/google/protobuf/duration_pb.js +1 -1
  101. package/dist/esm/google/protobuf/empty_pb.js +1 -1
  102. package/dist/esm/google/protobuf/field_mask_pb.js +1 -1
  103. package/dist/esm/google/protobuf/source_context_pb.js +1 -1
  104. package/dist/esm/google/protobuf/struct_pb.js +2 -2
  105. package/dist/esm/google/protobuf/timestamp_pb.js +1 -1
  106. package/dist/esm/google/protobuf/type_pb.js +2 -2
  107. package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
  108. package/dist/esm/index.d.ts +3 -1
  109. package/dist/esm/index.js +2 -1
  110. package/dist/esm/json-format.d.ts +5 -5
  111. package/dist/esm/json-format.js +1 -1
  112. package/dist/esm/message-type.js +1 -1
  113. package/dist/esm/message.js +1 -1
  114. package/dist/esm/private/assert.js +1 -1
  115. package/dist/esm/private/binary-format-common.d.ts +2 -3
  116. package/dist/esm/private/binary-format-common.js +80 -77
  117. package/dist/esm/private/binary-format-proto2.js +59 -64
  118. package/dist/esm/private/binary-format-proto3.js +44 -40
  119. package/dist/esm/private/enum.js +1 -1
  120. package/dist/esm/private/extensions.d.ts +34 -0
  121. package/dist/esm/private/extensions.js +81 -0
  122. package/dist/esm/private/feature-set.d.ts +6 -8
  123. package/dist/esm/private/feature-set.js +40 -41
  124. package/dist/esm/private/field-list.js +1 -1
  125. package/dist/esm/private/field-wrapper.d.ts +2 -2
  126. package/dist/esm/private/field-wrapper.js +1 -1
  127. package/dist/esm/private/field.js +1 -1
  128. package/dist/esm/private/json-format-common.d.ts +3 -3
  129. package/dist/esm/private/json-format-common.js +228 -173
  130. package/dist/esm/private/json-format-proto2.js +3 -2
  131. package/dist/esm/private/json-format-proto3.js +8 -6
  132. package/dist/esm/private/message-type.js +1 -1
  133. package/dist/esm/private/names.d.ts +2 -2
  134. package/dist/esm/private/names.js +3 -2
  135. package/dist/esm/private/options-map.js +1 -1
  136. package/dist/esm/private/proto-runtime.d.ts +6 -0
  137. package/dist/esm/private/proto-runtime.js +5 -1
  138. package/dist/esm/private/reify-wkt.js +1 -1
  139. package/dist/esm/private/scalars.js +1 -1
  140. package/dist/esm/private/text-format.js +1 -1
  141. package/dist/esm/private/util-common.js +1 -1
  142. package/dist/esm/private/util.js +1 -1
  143. package/dist/esm/proto-base64.js +1 -1
  144. package/dist/esm/proto-delimited.js +1 -1
  145. package/dist/esm/proto-double.js +1 -1
  146. package/dist/esm/proto-int64.js +1 -1
  147. package/dist/esm/proto2.js +1 -1
  148. package/dist/esm/proto3.js +1 -1
  149. package/dist/esm/service-type.js +1 -1
  150. package/dist/esm/to-plain-message.js +1 -1
  151. package/dist/esm/type-registry.d.ts +14 -0
  152. package/dist/esm/type-registry.js +1 -1
  153. 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.
@@ -13,60 +13,59 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.createFeatureResolver = exports.featureSetDefaults = void 0;
16
+ exports.createFeatureResolver = void 0;
17
17
  const descriptor_pb_js_1 = require("../google/protobuf/descriptor_pb.js");
18
18
  const proto_base64_js_1 = require("../proto-base64.js");
19
19
  /**
20
- * Static edition feature defaults supported by @bufbuild/protobuf.
20
+ * Return the edition feature defaults supported by @bufbuild/protobuf.
21
21
  */
22
- exports.featureSetDefaults = descriptor_pb_js_1.FeatureSetDefaults.fromBinary(proto_base64_js_1.protoBase64.dec(
23
- /*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiABKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/));
22
+ function getFeatureSetDefaults(options) {
23
+ return descriptor_pb_js_1.FeatureSetDefaults.fromBinary(proto_base64_js_1.protoBase64.dec(
24
+ /*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiABKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/), options);
25
+ }
24
26
  /**
25
- * Create an edition feature resolver with the given feature set defaults.
27
+ * Create an edition feature resolver with the given feature set defaults, or
28
+ * the feature set defaults supported by @bufbuild/protobuf.
26
29
  */
27
- function createFeatureResolver(compiledFeatureSetDefaults) {
28
- const min = compiledFeatureSetDefaults.minimumEdition;
29
- const max = compiledFeatureSetDefaults.maximumEdition;
30
+ function createFeatureResolver(edition, compiledFeatureSetDefaults, serializationOptions) {
31
+ var _a, _b;
32
+ const fds = compiledFeatureSetDefaults !== null && compiledFeatureSetDefaults !== void 0 ? compiledFeatureSetDefaults : getFeatureSetDefaults(serializationOptions);
33
+ const min = fds.minimumEdition;
34
+ const max = fds.maximumEdition;
30
35
  if (min === undefined ||
31
36
  max === undefined ||
32
- compiledFeatureSetDefaults.defaults.some((d) => d.edition === undefined)) {
37
+ fds.defaults.some((d) => d.edition === undefined)) {
33
38
  throw new Error("Invalid FeatureSetDefaults");
34
39
  }
35
- const defaultsBinByEdition = new Map();
36
- return (edition, ...rest) => {
37
- var _a, _b;
38
- let defaultsBin = defaultsBinByEdition.get(edition);
39
- if (defaultsBin === undefined) {
40
- if (edition < min) {
41
- throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is earlier than the minimum supported edition ${descriptor_pb_js_1.Edition[min]}`);
42
- }
43
- if (max < edition) {
44
- throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is later than the maximum supported edition ${descriptor_pb_js_1.Edition[max]}`);
45
- }
46
- let highestMatch = undefined;
47
- for (const c of compiledFeatureSetDefaults.defaults) {
48
- const e = (_a = c.edition) !== null && _a !== void 0 ? _a : 0;
49
- if (e > edition) {
50
- continue;
51
- }
52
- if (highestMatch !== undefined && highestMatch.e > e) {
53
- continue;
54
- }
55
- highestMatch = {
56
- e,
57
- f: (_b = c.features) !== null && _b !== void 0 ? _b : new descriptor_pb_js_1.FeatureSet(),
58
- };
59
- }
60
- if (highestMatch === undefined) {
61
- throw new Error(`No valid default found for edition ${descriptor_pb_js_1.Edition[edition]}`);
62
- }
63
- defaultsBin = highestMatch.f.toBinary();
64
- defaultsBinByEdition.set(edition, defaultsBin);
40
+ if (edition < min) {
41
+ throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is earlier than the minimum supported edition ${descriptor_pb_js_1.Edition[min]}`);
42
+ }
43
+ if (max < edition) {
44
+ throw new Error(`Edition ${descriptor_pb_js_1.Edition[edition]} is later than the maximum supported edition ${descriptor_pb_js_1.Edition[max]}`);
45
+ }
46
+ let highestMatch = undefined;
47
+ for (const c of fds.defaults) {
48
+ const e = (_a = c.edition) !== null && _a !== void 0 ? _a : 0;
49
+ if (e > edition) {
50
+ continue;
51
+ }
52
+ if (highestMatch !== undefined && highestMatch.e > e) {
53
+ continue;
65
54
  }
66
- const f = descriptor_pb_js_1.FeatureSet.fromBinary(defaultsBin);
55
+ highestMatch = {
56
+ e,
57
+ f: (_b = c.features) !== null && _b !== void 0 ? _b : new descriptor_pb_js_1.FeatureSet(),
58
+ };
59
+ }
60
+ if (highestMatch === undefined) {
61
+ throw new Error(`No valid default found for edition ${descriptor_pb_js_1.Edition[edition]}`);
62
+ }
63
+ const featureSetBin = highestMatch.f.toBinary(serializationOptions);
64
+ return (...rest) => {
65
+ const f = descriptor_pb_js_1.FeatureSet.fromBinary(featureSetBin, serializationOptions);
67
66
  for (const c of rest) {
68
67
  if (c !== undefined) {
69
- f.fromBinary(c.toBinary());
68
+ f.fromBinary(c.toBinary(serializationOptions), serializationOptions);
70
69
  }
71
70
  }
72
71
  if (!validateMergedFeatures(f)) {
@@ -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,6 +1,6 @@
1
1
  import { Message } from "../message.js";
2
2
  import type { MessageType } from "../message-type.js";
3
- import type { DescField } from "../descriptor-set.js";
3
+ import type { DescExtension, DescField } from "../descriptor-set.js";
4
4
  import { ScalarType } from "../field.js";
5
5
  /**
6
6
  * A field wrapper unwraps a message to a primitive value that is more
@@ -22,4 +22,4 @@ export declare function wrapField<T extends Message<T>>(type: MessageType<T>, va
22
22
  * If the given field uses one of the well-known wrapper types, return
23
23
  * the primitive type it wraps.
24
24
  */
25
- export declare function getUnwrappedFieldType(field: DescField): ScalarType | undefined;
25
+ export declare function getUnwrappedFieldType(field: DescField | DescExtension): ScalarType | undefined;
@@ -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.
@@ -3,7 +3,7 @@ import type { FieldInfo } from "../field.js";
3
3
  import { ScalarType } from "../field.js";
4
4
  import type { EnumType } from "../enum.js";
5
5
  type JsonFormatWriteFieldFn = (field: FieldInfo, value: any, options: JsonWriteOptions) => JsonValue | undefined;
6
- export declare function makeJsonFormatCommon(makeWriteField: (writeEnumFn: typeof writeEnum, writeScalarFn: typeof writeScalar) => JsonFormatWriteFieldFn): JsonFormat;
7
- declare function writeEnum(type: EnumType, value: number | undefined, emitIntrinsicDefault: boolean, enumAsInteger: boolean): JsonValue | undefined;
8
- declare function writeScalar(type: ScalarType, value: any, emitIntrinsicDefault: boolean): JsonValue | undefined;
6
+ export declare function makeJsonFormatCommon(nullAsZeroValue: boolean, makeWriteField: (writeEnumFn: typeof writeEnum, writeScalarFn: typeof writeScalar) => JsonFormatWriteFieldFn): JsonFormat;
7
+ declare function writeEnum(type: EnumType, value: number | undefined, emitZeroValue: boolean, enumAsInteger: boolean): JsonValue | undefined;
8
+ declare function writeScalar(type: ScalarType, value: any, emitZeroValue: boolean): JsonValue | undefined;
9
9
  export {};