@bufbuild/protobuf 1.7.2 → 1.9.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 (127) hide show
  1. package/dist/cjs/binary-encoding.d.ts +2 -2
  2. package/dist/cjs/codegen-info.d.ts +6 -1
  3. package/dist/cjs/codegen-info.js +4 -3
  4. package/dist/cjs/create-descriptor-set.js +45 -33
  5. package/dist/cjs/create-registry-from-desc.js +60 -110
  6. package/dist/cjs/descriptor-set.d.ts +13 -9
  7. package/dist/cjs/field.d.ts +25 -51
  8. package/dist/cjs/field.js +0 -66
  9. package/dist/cjs/google/protobuf/compiler/plugin_pb.d.ts +18 -0
  10. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +2 -0
  11. package/dist/cjs/google/protobuf/descriptor_pb.d.ts +33 -33
  12. package/dist/cjs/google/protobuf/descriptor_pb.js +23 -10
  13. package/dist/cjs/google/protobuf/struct_pb.js +1 -1
  14. package/dist/cjs/google/protobuf/type_pb.js +1 -1
  15. package/dist/cjs/google/protobuf/wrappers_pb.js +19 -19
  16. package/dist/cjs/index.d.ts +4 -2
  17. package/dist/cjs/index.js +6 -4
  18. package/dist/cjs/is-message.d.ts +22 -0
  19. package/dist/cjs/is-message.js +52 -0
  20. package/dist/cjs/json-format.d.ts +1 -2
  21. package/dist/cjs/message.d.ts +1 -0
  22. package/dist/cjs/message.js +1 -0
  23. package/dist/cjs/private/binary-format.d.ts +7 -0
  24. package/dist/cjs/private/{binary-format-common.js → binary-format.js} +150 -53
  25. package/dist/cjs/private/extensions.js +1 -1
  26. package/dist/cjs/private/feature-set.js +1 -1
  27. package/dist/cjs/private/field-normalize.d.ts +9 -0
  28. package/dist/cjs/private/field-normalize.js +69 -0
  29. package/dist/cjs/private/field-wrapper.d.ts +1 -1
  30. package/dist/cjs/private/field-wrapper.js +12 -12
  31. package/dist/cjs/private/field.d.ts +1 -0
  32. package/dist/cjs/private/field.js +1 -0
  33. package/dist/cjs/private/json-format.d.ts +2 -0
  34. package/dist/cjs/private/{json-format-common.js → json-format.js} +261 -170
  35. package/dist/cjs/private/names.js +3 -3
  36. package/dist/cjs/private/proto-runtime.d.ts +1 -1
  37. package/dist/cjs/private/proto-runtime.js +8 -4
  38. package/dist/cjs/private/reflect.d.ts +9 -0
  39. package/dist/cjs/private/reflect.js +79 -0
  40. package/dist/cjs/private/reify-wkt.js +11 -11
  41. package/dist/cjs/private/scalars.d.ts +9 -18
  42. package/dist/cjs/private/scalars.js +36 -80
  43. package/dist/cjs/private/text-format.d.ts +1 -1
  44. package/dist/cjs/private/text-format.js +17 -17
  45. package/dist/cjs/private/util-common.js +20 -14
  46. package/dist/cjs/proto-delimited.js +2 -3
  47. package/dist/cjs/proto2.js +29 -68
  48. package/dist/cjs/proto3.js +30 -77
  49. package/dist/cjs/scalar.d.ts +53 -0
  50. package/dist/cjs/scalar.js +81 -0
  51. package/dist/cjs/to-plain-message.js +3 -4
  52. package/dist/esm/binary-encoding.d.ts +2 -2
  53. package/dist/esm/codegen-info.d.ts +6 -1
  54. package/dist/esm/codegen-info.js +6 -5
  55. package/dist/esm/create-descriptor-set.js +22 -10
  56. package/dist/esm/create-registry-from-desc.js +62 -111
  57. package/dist/esm/descriptor-set.d.ts +13 -9
  58. package/dist/esm/descriptor-set.js +1 -1
  59. package/dist/esm/field.d.ts +25 -51
  60. package/dist/esm/field.js +1 -65
  61. package/dist/esm/google/protobuf/compiler/plugin_pb.d.ts +18 -0
  62. package/dist/esm/google/protobuf/compiler/plugin_pb.js +2 -0
  63. package/dist/esm/google/protobuf/descriptor_pb.d.ts +33 -33
  64. package/dist/esm/google/protobuf/descriptor_pb.js +23 -10
  65. package/dist/esm/google/protobuf/struct_pb.js +1 -1
  66. package/dist/esm/google/protobuf/type_pb.js +1 -1
  67. package/dist/esm/google/protobuf/wrappers_pb.js +1 -1
  68. package/dist/esm/index.d.ts +4 -2
  69. package/dist/esm/index.js +2 -1
  70. package/dist/esm/is-message.d.ts +22 -0
  71. package/dist/esm/is-message.js +48 -0
  72. package/dist/esm/json-format.d.ts +1 -2
  73. package/dist/esm/json-format.js +1 -1
  74. package/dist/esm/message.d.ts +1 -0
  75. package/dist/esm/message.js +1 -0
  76. package/dist/esm/private/binary-format.d.ts +7 -0
  77. package/dist/esm/private/{binary-format-common.js → binary-format.js} +126 -25
  78. package/dist/esm/private/extensions.js +2 -2
  79. package/dist/esm/private/feature-set.js +1 -1
  80. package/dist/esm/private/field-normalize.d.ts +9 -0
  81. package/dist/esm/private/field-normalize.js +65 -0
  82. package/dist/esm/private/field-wrapper.d.ts +1 -1
  83. package/dist/esm/private/field-wrapper.js +3 -2
  84. package/dist/esm/private/field.d.ts +1 -0
  85. package/dist/esm/private/field.js +1 -0
  86. package/dist/esm/private/json-format.d.ts +2 -0
  87. package/dist/esm/private/{json-format-common.js → json-format.js} +228 -136
  88. package/dist/esm/private/names.js +3 -3
  89. package/dist/esm/private/proto-runtime.d.ts +1 -1
  90. package/dist/esm/private/proto-runtime.js +8 -4
  91. package/dist/esm/private/reflect.d.ts +9 -0
  92. package/dist/esm/private/reflect.js +74 -0
  93. package/dist/esm/private/reify-wkt.js +1 -1
  94. package/dist/esm/private/scalars.d.ts +9 -18
  95. package/dist/esm/private/scalars.js +15 -59
  96. package/dist/esm/private/text-format.d.ts +1 -1
  97. package/dist/esm/private/text-format.js +1 -1
  98. package/dist/esm/private/util-common.js +13 -6
  99. package/dist/esm/proto-delimited.js +2 -3
  100. package/dist/esm/proto2.js +29 -68
  101. package/dist/esm/proto3.js +31 -78
  102. package/dist/esm/scalar.d.ts +53 -0
  103. package/dist/esm/scalar.js +78 -0
  104. package/dist/esm/to-plain-message.js +3 -2
  105. package/package.json +4 -10
  106. package/dist/cjs/private/binary-format-common.d.ts +0 -13
  107. package/dist/cjs/private/binary-format-proto2.d.ts +0 -2
  108. package/dist/cjs/private/binary-format-proto2.js +0 -91
  109. package/dist/cjs/private/binary-format-proto3.d.ts +0 -2
  110. package/dist/cjs/private/binary-format-proto3.js +0 -83
  111. package/dist/cjs/private/json-format-common.d.ts +0 -9
  112. package/dist/cjs/private/json-format-proto2.d.ts +0 -2
  113. package/dist/cjs/private/json-format-proto2.js +0 -103
  114. package/dist/cjs/private/json-format-proto3.d.ts +0 -2
  115. package/dist/cjs/private/json-format-proto3.js +0 -94
  116. package/dist/esm/private/binary-format-common.d.ts +0 -13
  117. package/dist/esm/private/binary-format-proto2.d.ts +0 -2
  118. package/dist/esm/private/binary-format-proto2.js +0 -87
  119. package/dist/esm/private/binary-format-proto3.d.ts +0 -2
  120. package/dist/esm/private/binary-format-proto3.js +0 -79
  121. package/dist/esm/private/json-format-common.d.ts +0 -9
  122. package/dist/esm/private/json-format-proto2.d.ts +0 -2
  123. package/dist/esm/private/json-format-proto2.js +0 -99
  124. package/dist/esm/private/json-format-proto3.d.ts +0 -2
  125. package/dist/esm/private/json-format-proto3.js +0 -90
  126. package/dist/proxy/index.d.ts +0 -1
  127. package/dist/proxy/index.js +0 -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
- import { scalarDefaultValue } from "./scalars.js";
14
+ import { scalarZeroValue } from "./scalars.js";
15
15
  import { WireType } from "../binary-encoding.js";
16
16
  /**
17
17
  * Create a new extension using the given runtime.
@@ -55,7 +55,7 @@ function initExtensionField(ext) {
55
55
  case "enum":
56
56
  return field.T.values[0].no;
57
57
  case "scalar":
58
- return scalarDefaultValue(field.T, field.L);
58
+ return scalarZeroValue(field.T, field.L);
59
59
  case "message":
60
60
  // eslint-disable-next-line no-case-declarations
61
61
  const T = field.T, value = new T();
@@ -18,7 +18,7 @@ import { protoBase64 } from "../proto-base64.js";
18
18
  */
19
19
  function getFeatureSetDefaults(options) {
20
20
  return FeatureSetDefaults.fromBinary(protoBase64.dec(
21
- /*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiABKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/), options);
21
+ /*upstream-inject-feature-defaults-start*/ "ChESDAgBEAIYAiADKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH" /*upstream-inject-feature-defaults-end*/), options);
22
22
  }
23
23
  /**
24
24
  * Create an edition feature resolver with the given feature set defaults, or
@@ -0,0 +1,9 @@
1
+ import type { FieldListSource } from "./field-list.js";
2
+ import type { FieldInfo } from "../field.js";
3
+ /**
4
+ * Convert a collection of field info to an array of normalized FieldInfo.
5
+ *
6
+ * The argument `packedByDefault` specifies whether fields that do not specify
7
+ * `packed` should be packed (proto3) or unpacked (proto2).
8
+ */
9
+ export declare function normalizeFieldInfos(fieldInfos: FieldListSource, packedByDefault: boolean): FieldInfo[];
@@ -0,0 +1,65 @@
1
+ // Copyright 2021-2024 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
+ import { InternalOneofInfo } from "./field.js";
15
+ import { fieldJsonName, localFieldName } from "./names.js";
16
+ import { LongType, ScalarType } from "../scalar.js";
17
+ /**
18
+ * Convert a collection of field info to an array of normalized FieldInfo.
19
+ *
20
+ * The argument `packedByDefault` specifies whether fields that do not specify
21
+ * `packed` should be packed (proto3) or unpacked (proto2).
22
+ */
23
+ export function normalizeFieldInfos(fieldInfos, packedByDefault) {
24
+ var _a, _b, _c, _d, _e, _f;
25
+ const r = [];
26
+ let o;
27
+ for (const field of typeof fieldInfos == "function"
28
+ ? fieldInfos()
29
+ : fieldInfos) {
30
+ const f = field;
31
+ f.localName = localFieldName(field.name, field.oneof !== undefined);
32
+ f.jsonName = (_a = field.jsonName) !== null && _a !== void 0 ? _a : fieldJsonName(field.name);
33
+ f.repeated = (_b = field.repeated) !== null && _b !== void 0 ? _b : false;
34
+ if (field.kind == "scalar") {
35
+ f.L = (_c = field.L) !== null && _c !== void 0 ? _c : LongType.BIGINT;
36
+ }
37
+ f.delimited = (_d = field.delimited) !== null && _d !== void 0 ? _d : false;
38
+ f.req = (_e = field.req) !== null && _e !== void 0 ? _e : false;
39
+ f.opt = (_f = field.opt) !== null && _f !== void 0 ? _f : false;
40
+ if (field.packed === undefined) {
41
+ if (packedByDefault) {
42
+ f.packed =
43
+ field.kind == "enum" ||
44
+ (field.kind == "scalar" &&
45
+ field.T != ScalarType.BYTES &&
46
+ field.T != ScalarType.STRING);
47
+ }
48
+ else {
49
+ f.packed = false;
50
+ }
51
+ }
52
+ // We do not surface options at this time
53
+ // f.options = field.options ?? emptyReadonlyObject;
54
+ if (field.oneof !== undefined) {
55
+ const ooname = typeof field.oneof == "string" ? field.oneof : field.oneof.name;
56
+ if (!o || o.name != ooname) {
57
+ o = new InternalOneofInfo(ooname);
58
+ }
59
+ f.oneof = o;
60
+ o.addField(f);
61
+ }
62
+ r.push(f);
63
+ }
64
+ return r;
65
+ }
@@ -1,7 +1,7 @@
1
1
  import { Message } from "../message.js";
2
2
  import type { MessageType } from "../message-type.js";
3
3
  import type { DescExtension, DescField } from "../descriptor-set.js";
4
- import { ScalarType } from "../field.js";
4
+ import { ScalarType } from "../scalar.js";
5
5
  /**
6
6
  * A field wrapper unwraps a message to a primitive value that is more
7
7
  * ergonomic for use as a message field.
@@ -12,13 +12,14 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  import { Message } from "../message.js";
15
- import { ScalarType } from "../field.js";
15
+ import { ScalarType } from "../scalar.js";
16
+ import { isMessage } from "../is-message.js";
16
17
  /**
17
18
  * Wrap a primitive message field value in its corresponding wrapper
18
19
  * message. This function is idempotent.
19
20
  */
20
21
  export function wrapField(type, value) {
21
- if (value instanceof Message || !type.fieldWrapper) {
22
+ if (isMessage(value) || !type.fieldWrapper) {
22
23
  return value;
23
24
  }
24
25
  return type.fieldWrapper.wrapField(value);
@@ -6,6 +6,7 @@ export declare class InternalOneofInfo implements OneofInfo {
6
6
  readonly repeated = false;
7
7
  readonly packed = false;
8
8
  readonly opt = false;
9
+ readonly req = false;
9
10
  readonly default: undefined;
10
11
  readonly fields: FieldInfo[];
11
12
  private _lookup?;
@@ -19,6 +19,7 @@ export class InternalOneofInfo {
19
19
  this.repeated = false;
20
20
  this.packed = false;
21
21
  this.opt = false;
22
+ this.req = false;
22
23
  this.default = undefined;
23
24
  this.fields = [];
24
25
  this.name = name;
@@ -0,0 +1,2 @@
1
+ import type { JsonFormat } from "../json-format.js";
2
+ export declare function makeJsonFormat(): JsonFormat;