@bufbuild/protobuf 2.10.2 → 2.12.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 (181) hide show
  1. package/dist/cjs/clone.js +1 -1
  2. package/dist/cjs/codegenv1/enum.js +1 -1
  3. package/dist/cjs/codegenv1/extension.js +1 -1
  4. package/dist/cjs/codegenv1/file.js +1 -1
  5. package/dist/cjs/codegenv1/index.js +1 -1
  6. package/dist/cjs/codegenv1/message.js +1 -1
  7. package/dist/cjs/codegenv1/service.js +1 -1
  8. package/dist/cjs/codegenv1/symbols.js +1 -1
  9. package/dist/cjs/codegenv1/types.js +1 -1
  10. package/dist/cjs/codegenv2/boot.js +1 -1
  11. package/dist/cjs/codegenv2/embed.js +1 -1
  12. package/dist/cjs/codegenv2/enum.js +1 -1
  13. package/dist/cjs/codegenv2/extension.js +1 -1
  14. package/dist/cjs/codegenv2/file.js +1 -1
  15. package/dist/cjs/codegenv2/index.js +1 -1
  16. package/dist/cjs/codegenv2/message.js +1 -1
  17. package/dist/cjs/codegenv2/restore-json-names.js +1 -1
  18. package/dist/cjs/codegenv2/scalar.js +1 -1
  19. package/dist/cjs/codegenv2/service.js +1 -1
  20. package/dist/cjs/codegenv2/symbols.js +1 -1
  21. package/dist/cjs/codegenv2/types.js +1 -1
  22. package/dist/cjs/create.js +1 -1
  23. package/dist/cjs/descriptors.d.ts +12 -5
  24. package/dist/cjs/descriptors.js +1 -1
  25. package/dist/cjs/equals.js +1 -1
  26. package/dist/cjs/extensions.js +1 -1
  27. package/dist/cjs/fields.js +1 -1
  28. package/dist/cjs/from-binary.js +8 -8
  29. package/dist/cjs/from-json.d.ts +1 -1
  30. package/dist/cjs/from-json.js +81 -89
  31. package/dist/cjs/index.js +1 -1
  32. package/dist/cjs/is-message.js +1 -1
  33. package/dist/cjs/json-value.js +1 -1
  34. package/dist/cjs/merge.js +1 -1
  35. package/dist/cjs/proto-int64.js +1 -1
  36. package/dist/cjs/reflect/error.js +1 -1
  37. package/dist/cjs/reflect/guard.js +1 -1
  38. package/dist/cjs/reflect/index.js +1 -1
  39. package/dist/cjs/reflect/names.d.ts +11 -0
  40. package/dist/cjs/reflect/names.js +15 -1
  41. package/dist/cjs/reflect/nested-types.js +1 -1
  42. package/dist/cjs/reflect/path.d.ts +1 -1
  43. package/dist/cjs/reflect/path.js +1 -1
  44. package/dist/cjs/reflect/reflect-check.js +1 -1
  45. package/dist/cjs/reflect/reflect-types.js +1 -1
  46. package/dist/cjs/reflect/reflect.js +1 -1
  47. package/dist/cjs/reflect/scalar.js +1 -1
  48. package/dist/cjs/reflect/unsafe.js +1 -1
  49. package/dist/cjs/registry.js +25 -2
  50. package/dist/cjs/to-binary.js +1 -1
  51. package/dist/cjs/to-json.d.ts +1 -1
  52. package/dist/cjs/to-json.js +12 -15
  53. package/dist/cjs/types.d.ts +1 -1
  54. package/dist/cjs/types.js +1 -1
  55. package/dist/cjs/wire/base64-encoding.js +1 -1
  56. package/dist/cjs/wire/binary-encoding.d.ts +9 -7
  57. package/dist/cjs/wire/binary-encoding.js +19 -9
  58. package/dist/cjs/wire/index.js +1 -1
  59. package/dist/cjs/wire/size-delimited.js +1 -1
  60. package/dist/cjs/wire/text-encoding.d.ts +4 -2
  61. package/dist/cjs/wire/text-encoding.js +9 -2
  62. package/dist/cjs/wire/text-format.js +1 -1
  63. package/dist/cjs/wkt/any.js +1 -1
  64. package/dist/cjs/wkt/duration.js +1 -1
  65. package/dist/cjs/wkt/gen/google/protobuf/any_pb.js +1 -1
  66. package/dist/cjs/wkt/gen/google/protobuf/api_pb.d.ts +1 -1
  67. package/dist/cjs/wkt/gen/google/protobuf/api_pb.js +1 -1
  68. package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +2 -2
  69. package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.js +1 -1
  70. package/dist/cjs/wkt/gen/google/protobuf/cpp_features_pb.js +1 -1
  71. package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.d.ts +37 -23
  72. package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.js +2 -2
  73. package/dist/cjs/wkt/gen/google/protobuf/duration_pb.js +1 -1
  74. package/dist/cjs/wkt/gen/google/protobuf/empty_pb.js +1 -1
  75. package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.d.ts +32 -36
  76. package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.js +1 -1
  77. package/dist/cjs/wkt/gen/google/protobuf/go_features_pb.d.ts +65 -0
  78. package/dist/cjs/wkt/gen/google/protobuf/go_features_pb.js +39 -3
  79. package/dist/cjs/wkt/gen/google/protobuf/java_features_pb.js +1 -1
  80. package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.js +1 -1
  81. package/dist/cjs/wkt/gen/google/protobuf/struct_pb.js +1 -1
  82. package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.d.ts +5 -5
  83. package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.js +1 -1
  84. package/dist/cjs/wkt/gen/google/protobuf/type_pb.d.ts +3 -3
  85. package/dist/cjs/wkt/gen/google/protobuf/type_pb.js +1 -1
  86. package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.js +1 -1
  87. package/dist/cjs/wkt/index.js +1 -1
  88. package/dist/cjs/wkt/timestamp.js +1 -1
  89. package/dist/cjs/wkt/wrappers.d.ts +10 -0
  90. package/dist/cjs/wkt/wrappers.js +25 -1
  91. package/dist/esm/clone.js +1 -1
  92. package/dist/esm/codegenv1/enum.js +1 -1
  93. package/dist/esm/codegenv1/extension.js +1 -1
  94. package/dist/esm/codegenv1/file.js +1 -1
  95. package/dist/esm/codegenv1/index.js +1 -1
  96. package/dist/esm/codegenv1/message.js +1 -1
  97. package/dist/esm/codegenv1/service.js +1 -1
  98. package/dist/esm/codegenv1/symbols.js +1 -1
  99. package/dist/esm/codegenv1/types.js +1 -1
  100. package/dist/esm/codegenv2/boot.js +1 -1
  101. package/dist/esm/codegenv2/embed.js +1 -1
  102. package/dist/esm/codegenv2/enum.js +1 -1
  103. package/dist/esm/codegenv2/extension.js +1 -1
  104. package/dist/esm/codegenv2/file.js +1 -1
  105. package/dist/esm/codegenv2/index.js +1 -1
  106. package/dist/esm/codegenv2/message.js +1 -1
  107. package/dist/esm/codegenv2/restore-json-names.js +1 -1
  108. package/dist/esm/codegenv2/scalar.js +1 -1
  109. package/dist/esm/codegenv2/service.js +1 -1
  110. package/dist/esm/codegenv2/symbols.js +1 -1
  111. package/dist/esm/codegenv2/types.js +1 -1
  112. package/dist/esm/create.js +1 -1
  113. package/dist/esm/descriptors.d.ts +12 -5
  114. package/dist/esm/descriptors.js +1 -1
  115. package/dist/esm/equals.js +1 -1
  116. package/dist/esm/extensions.js +1 -1
  117. package/dist/esm/fields.js +1 -1
  118. package/dist/esm/from-binary.js +8 -8
  119. package/dist/esm/from-json.d.ts +1 -1
  120. package/dist/esm/from-json.js +82 -90
  121. package/dist/esm/index.js +1 -1
  122. package/dist/esm/is-message.js +1 -1
  123. package/dist/esm/json-value.js +1 -1
  124. package/dist/esm/merge.js +1 -1
  125. package/dist/esm/proto-int64.js +1 -1
  126. package/dist/esm/reflect/error.js +1 -1
  127. package/dist/esm/reflect/guard.js +1 -1
  128. package/dist/esm/reflect/index.js +1 -1
  129. package/dist/esm/reflect/names.d.ts +11 -0
  130. package/dist/esm/reflect/names.js +14 -1
  131. package/dist/esm/reflect/nested-types.js +1 -1
  132. package/dist/esm/reflect/path.d.ts +1 -1
  133. package/dist/esm/reflect/path.js +1 -1
  134. package/dist/esm/reflect/reflect-check.js +1 -1
  135. package/dist/esm/reflect/reflect-types.js +1 -1
  136. package/dist/esm/reflect/reflect.js +1 -1
  137. package/dist/esm/reflect/scalar.js +1 -1
  138. package/dist/esm/reflect/unsafe.js +1 -1
  139. package/dist/esm/registry.js +25 -2
  140. package/dist/esm/to-binary.js +1 -1
  141. package/dist/esm/to-json.d.ts +1 -1
  142. package/dist/esm/to-json.js +14 -17
  143. package/dist/esm/types.d.ts +1 -1
  144. package/dist/esm/types.js +1 -1
  145. package/dist/esm/wire/base64-encoding.js +1 -1
  146. package/dist/esm/wire/binary-encoding.d.ts +9 -7
  147. package/dist/esm/wire/binary-encoding.js +19 -9
  148. package/dist/esm/wire/index.js +1 -1
  149. package/dist/esm/wire/size-delimited.js +1 -1
  150. package/dist/esm/wire/text-encoding.d.ts +4 -2
  151. package/dist/esm/wire/text-encoding.js +9 -2
  152. package/dist/esm/wire/text-format.js +1 -1
  153. package/dist/esm/wkt/any.js +1 -1
  154. package/dist/esm/wkt/duration.js +1 -1
  155. package/dist/esm/wkt/gen/google/protobuf/any_pb.js +1 -1
  156. package/dist/esm/wkt/gen/google/protobuf/api_pb.d.ts +1 -1
  157. package/dist/esm/wkt/gen/google/protobuf/api_pb.js +1 -1
  158. package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.d.ts +2 -2
  159. package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.js +1 -1
  160. package/dist/esm/wkt/gen/google/protobuf/cpp_features_pb.js +1 -1
  161. package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.d.ts +37 -23
  162. package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +2 -2
  163. package/dist/esm/wkt/gen/google/protobuf/duration_pb.js +1 -1
  164. package/dist/esm/wkt/gen/google/protobuf/empty_pb.js +1 -1
  165. package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.d.ts +32 -36
  166. package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.js +1 -1
  167. package/dist/esm/wkt/gen/google/protobuf/go_features_pb.d.ts +65 -0
  168. package/dist/esm/wkt/gen/google/protobuf/go_features_pb.js +38 -2
  169. package/dist/esm/wkt/gen/google/protobuf/java_features_pb.js +1 -1
  170. package/dist/esm/wkt/gen/google/protobuf/source_context_pb.js +1 -1
  171. package/dist/esm/wkt/gen/google/protobuf/struct_pb.js +1 -1
  172. package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.d.ts +5 -5
  173. package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.js +1 -1
  174. package/dist/esm/wkt/gen/google/protobuf/type_pb.d.ts +3 -3
  175. package/dist/esm/wkt/gen/google/protobuf/type_pb.js +1 -1
  176. package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.js +1 -1
  177. package/dist/esm/wkt/index.js +1 -1
  178. package/dist/esm/wkt/timestamp.js +1 -1
  179. package/dist/esm/wkt/wrappers.d.ts +10 -0
  180. package/dist/esm/wkt/wrappers.js +24 -1
  181. package/package.json +1 -1
package/dist/cjs/clone.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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.
@@ -114,7 +114,7 @@ export interface DescEnum {
114
114
  * A prefix shared by all enum values.
115
115
  * For example, `my_enum_` for `enum MyEnum {MY_ENUM_A=0; MY_ENUM_B=1;}`
116
116
  */
117
- readonly sharedPrefix?: string;
117
+ readonly sharedPrefix?: string | undefined;
118
118
  /**
119
119
  * Marked as deprecated in the protobuf source.
120
120
  */
@@ -192,8 +192,8 @@ export interface DescMessage {
192
192
  */
193
193
  readonly oneofs: DescOneof[];
194
194
  /**
195
- * Fields and oneof groups for this message, ordered by their appearance in the
196
- * protobuf source.
195
+ * Standalone fields and oneof groups for this message, ordered by
196
+ * their appearance in the protobuf source.
197
197
  */
198
198
  readonly members: (DescField | DescOneof)[];
199
199
  /**
@@ -283,6 +283,13 @@ interface descFieldAndExtensionShared {
283
283
  * See https://protobuf.dev/programming-guides/field_presence/
284
284
  */
285
285
  readonly presence: SupportedFieldPresence;
286
+ /**
287
+ * Whether to reject invalid UTF-8 when reading this field from the binary
288
+ * wire format. Reflects the resolved `utf8_validation` feature: true for
289
+ * VERIFY (proto3 and editions 2023+ default), false for NONE (proto2
290
+ * default).
291
+ */
292
+ readonly utf8Validation: boolean;
286
293
  /**
287
294
  * The compiler-generated descriptor.
288
295
  */
@@ -620,8 +627,8 @@ export interface DescMethod {
620
627
  */
621
628
  export interface DescComments {
622
629
  readonly leadingDetached: readonly string[];
623
- readonly leading?: string;
624
- readonly trailing?: string;
630
+ readonly leading?: string | undefined;
631
+ readonly trailing?: string | undefined;
625
632
  readonly sourcePath: readonly number[];
626
633
  }
627
634
  export {};
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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.
@@ -94,7 +94,7 @@ function readField(message, reader, field, wireType, options) {
94
94
  var _a;
95
95
  switch (field.fieldKind) {
96
96
  case "scalar":
97
- message.set(field, readScalar(reader, field.scalar));
97
+ message.set(field, readScalar(reader, field.scalar, field.utf8Validation));
98
98
  break;
99
99
  case "enum":
100
100
  const val = readScalar(reader, descriptors_js_1.ScalarType.INT32);
@@ -144,12 +144,12 @@ function readMapEntry(reader, map, options) {
144
144
  const [fieldNo] = reader.tag();
145
145
  switch (fieldNo) {
146
146
  case 1:
147
- key = readScalar(reader, field.mapKey);
147
+ key = readScalar(reader, field.mapKey, field.utf8Validation);
148
148
  break;
149
149
  case 2:
150
150
  switch (field.mapKind) {
151
151
  case "scalar":
152
- val = readScalar(reader, field.scalar);
152
+ val = readScalar(reader, field.scalar, field.utf8Validation);
153
153
  break;
154
154
  case "enum":
155
155
  val = reader.int32();
@@ -191,12 +191,12 @@ function readListField(reader, wireType, list, options) {
191
191
  scalarType != descriptors_js_1.ScalarType.STRING &&
192
192
  scalarType != descriptors_js_1.ScalarType.BYTES;
193
193
  if (!packed) {
194
- list.add(readScalar(reader, scalarType));
194
+ list.add(readScalar(reader, scalarType, field.utf8Validation));
195
195
  return;
196
196
  }
197
197
  const e = reader.uint32() + reader.pos;
198
198
  while (reader.pos < e) {
199
- list.add(readScalar(reader, scalarType));
199
+ list.add(readScalar(reader, scalarType, field.utf8Validation));
200
200
  }
201
201
  }
202
202
  function readMessageField(reader, options, field, mergeMessage) {
@@ -205,10 +205,10 @@ function readMessageField(reader, options, field, mergeMessage) {
205
205
  readMessage(message, reader, options, delimited, delimited ? field.number : reader.uint32());
206
206
  return message;
207
207
  }
208
- function readScalar(reader, type) {
208
+ function readScalar(reader, type, validateUtf8 = false) {
209
209
  switch (type) {
210
210
  case descriptors_js_1.ScalarType.STRING:
211
- return reader.string();
211
+ return reader.string(validateUtf8);
212
212
  case descriptors_js_1.ScalarType.BOOL:
213
213
  return reader.bool();
214
214
  case descriptors_js_1.ScalarType.DOUBLE:
@@ -16,7 +16,7 @@ export interface JsonReadOptions {
16
16
  * This option is required to read `google.protobuf.Any` and extensions
17
17
  * from JSON format.
18
18
  */
19
- registry?: Registry;
19
+ registry?: Registry | undefined;
20
20
  }
21
21
  /**
22
22
  * Parse a message from a JSON string.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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.
@@ -25,7 +25,7 @@ const create_js_1 = require("./create.js");
25
25
  const reflect_js_1 = require("./reflect/reflect.js");
26
26
  const error_js_1 = require("./reflect/error.js");
27
27
  const reflect_check_js_1 = require("./reflect/reflect-check.js");
28
- const scalar_js_1 = require("./reflect/scalar.js");
28
+ const names_js_1 = require("./reflect/names.js");
29
29
  const base64_encoding_js_1 = require("./wire/base64-encoding.js");
30
30
  const index_js_1 = require("./wkt/index.js");
31
31
  const extensions_js_1 = require("./extensions.js");
@@ -101,11 +101,7 @@ function mergeFromJson(schema, target, json, options) {
101
101
  * Parses an enum value from JSON.
102
102
  */
103
103
  function enumFromJson(descEnum, json) {
104
- const val = readEnum(descEnum, json, false, false);
105
- if (val === tokenIgnoredUnknownEnum) {
106
- throw new Error(`cannot decode ${descEnum} from JSON: ${(0, reflect_check_js_1.formatVal)(json)}`);
107
- }
108
- return val;
104
+ return readEnum(descEnum, json, false);
109
105
  }
110
106
  /**
111
107
  * Is the given value a JSON enum value?
@@ -113,6 +109,18 @@ function enumFromJson(descEnum, json) {
113
109
  function isEnumJson(descEnum, value) {
114
110
  return undefined !== descEnum.values.find((v) => v.name === value);
115
111
  }
112
+ const messageJsonFields = new WeakMap();
113
+ function getJsonField(desc, jsonKey) {
114
+ var _a;
115
+ if (!messageJsonFields.has(desc)) {
116
+ const jsonNames = new Map();
117
+ for (const field of desc.fields) {
118
+ jsonNames.set(field.name, field).set(field.jsonName, field);
119
+ }
120
+ messageJsonFields.set(desc, jsonNames);
121
+ }
122
+ return (_a = messageJsonFields.get(desc)) === null || _a === void 0 ? void 0 : _a.get(jsonKey);
123
+ }
116
124
  function readMessage(msg, json, opts) {
117
125
  var _a;
118
126
  if (tryWktFromJson(msg, json, opts)) {
@@ -122,12 +130,8 @@ function readMessage(msg, json, opts) {
122
130
  throw new Error(`cannot decode ${msg.desc} from JSON: ${(0, reflect_check_js_1.formatVal)(json)}`);
123
131
  }
124
132
  const oneofSeen = new Map();
125
- const jsonNames = new Map();
126
- for (const field of msg.desc.fields) {
127
- jsonNames.set(field.name, field).set(field.jsonName, field);
128
- }
129
133
  for (const [jsonKey, jsonValue] of Object.entries(json)) {
130
- const field = jsonNames.get(jsonKey);
134
+ const field = getJsonField(msg.desc, jsonKey);
131
135
  if (field) {
132
136
  if (field.oneof) {
133
137
  if (jsonValue === null && field.fieldKind == "scalar") {
@@ -178,6 +182,20 @@ function readField(msg, field, json, opts) {
178
182
  break;
179
183
  }
180
184
  }
185
+ function readListOrMapItem(field, json, opts) {
186
+ if (field.scalar && json !== null) {
187
+ return scalarFromJson(field, json);
188
+ }
189
+ if (field.message && !isResetSentinelNullValue(field, json)) {
190
+ const msgValue = (0, reflect_js_1.reflect)(field.message);
191
+ readMessage(msgValue, json, opts);
192
+ return msgValue;
193
+ }
194
+ if (field.enum && !isResetSentinelNullValue(field, json)) {
195
+ return readEnum(field.enum, json, opts.ignoreUnknownFields);
196
+ }
197
+ throw new error_js_1.FieldError(field, `${field.fieldKind === "list" ? "list item" : "map value"} must not be null`);
198
+ }
181
199
  function readMapField(map, json, opts) {
182
200
  if (json === null) {
183
201
  return;
@@ -187,28 +205,11 @@ function readMapField(map, json, opts) {
187
205
  throw new error_js_1.FieldError(field, "expected object, got " + (0, reflect_check_js_1.formatVal)(json));
188
206
  }
189
207
  for (const [jsonMapKey, jsonMapValue] of Object.entries(json)) {
190
- if (jsonMapValue === null && !isSafeNullValueInListOrMap(field)) {
191
- throw new error_js_1.FieldError(field, "map value must not be null");
192
- }
193
- let value;
194
- switch (field.mapKind) {
195
- case "message":
196
- const msgValue = (0, reflect_js_1.reflect)(field.message);
197
- readMessage(msgValue, jsonMapValue, opts);
198
- value = msgValue;
199
- break;
200
- case "enum":
201
- value = readEnum(field.enum, jsonMapValue, opts.ignoreUnknownFields, true);
202
- if (value === tokenIgnoredUnknownEnum) {
203
- return;
204
- }
205
- break;
206
- case "scalar":
207
- value = scalarFromJson(field, jsonMapValue, true);
208
- break;
209
- }
210
208
  const key = mapKeyFromJson(field.mapKey, jsonMapKey);
211
- map.set(key, value);
209
+ const value = readListOrMapItem(field, jsonMapValue, opts);
210
+ if (value !== tokenIgnoredUnknownEnum) {
211
+ map.set(key, value);
212
+ }
212
213
  }
213
214
  }
214
215
  function readListField(list, json, opts) {
@@ -220,34 +221,14 @@ function readListField(list, json, opts) {
220
221
  throw new error_js_1.FieldError(field, "expected Array, got " + (0, reflect_check_js_1.formatVal)(json));
221
222
  }
222
223
  for (const jsonItem of json) {
223
- if (jsonItem === null && !isSafeNullValueInListOrMap(field)) {
224
- throw new error_js_1.FieldError(field, "list item must not be null");
225
- }
226
- switch (field.listKind) {
227
- case "message":
228
- const msgValue = (0, reflect_js_1.reflect)(field.message);
229
- readMessage(msgValue, jsonItem, opts);
230
- list.add(msgValue);
231
- break;
232
- case "enum":
233
- const enumValue = readEnum(field.enum, jsonItem, opts.ignoreUnknownFields, true);
234
- if (enumValue !== tokenIgnoredUnknownEnum) {
235
- list.add(enumValue);
236
- }
237
- break;
238
- case "scalar":
239
- list.add(scalarFromJson(field, jsonItem, true));
240
- break;
224
+ const value = readListOrMapItem(field, jsonItem, opts);
225
+ if (value !== tokenIgnoredUnknownEnum) {
226
+ list.add(value);
241
227
  }
242
228
  }
243
229
  }
244
- function isSafeNullValueInListOrMap(field) {
245
- var _a, _b;
246
- return (((_a = field.message) === null || _a === void 0 ? void 0 : _a.typeName) == "google.protobuf.Value" ||
247
- ((_b = field.enum) === null || _b === void 0 ? void 0 : _b.typeName) == "google.protobuf.NullValue");
248
- }
249
230
  function readMessageField(msg, field, json, opts) {
250
- if (json === null && field.message.typeName != "google.protobuf.Value") {
231
+ if (isResetSentinelNullValue(field, json)) {
251
232
  msg.clear(field);
252
233
  return;
253
234
  }
@@ -256,30 +237,44 @@ function readMessageField(msg, field, json, opts) {
256
237
  msg.set(field, msgValue);
257
238
  }
258
239
  function readEnumField(msg, field, json, opts) {
259
- const enumValue = readEnum(field.enum, json, opts.ignoreUnknownFields, false);
260
- if (enumValue === tokenNull) {
240
+ if (isResetSentinelNullValue(field, json)) {
261
241
  msg.clear(field);
242
+ return;
262
243
  }
263
- else if (enumValue !== tokenIgnoredUnknownEnum) {
244
+ const enumValue = readEnum(field.enum, json, opts.ignoreUnknownFields);
245
+ if (enumValue !== tokenIgnoredUnknownEnum) {
264
246
  msg.set(field, enumValue);
265
247
  }
266
248
  }
267
249
  function readScalarField(msg, field, json) {
268
- const scalarValue = scalarFromJson(field, json, false);
269
- if (scalarValue === tokenNull) {
250
+ if (json === null) {
270
251
  msg.clear(field);
271
252
  }
272
253
  else {
273
- msg.set(field, scalarValue);
254
+ msg.set(field, scalarFromJson(field, json));
274
255
  }
275
256
  }
257
+ /**
258
+ * Indicates whether a value is a sentinel for reseting a field.
259
+ *
260
+ * For this to be true, the value must be a JSON null and the field must not
261
+ * permit a present, Protobuf-serializable null.
262
+ *
263
+ * Only message google.protobuf.Value and enum google.protobuf.NullValue fields
264
+ * permit Protobuf-serializable nulls.
265
+ *
266
+ * Note that field-resetting sentinel nulls are not permitted in lists and maps.
267
+ */
268
+ function isResetSentinelNullValue(field, json) {
269
+ var _a, _b;
270
+ return (json === null &&
271
+ ((_a = field.message) === null || _a === void 0 ? void 0 : _a.typeName) != "google.protobuf.Value" &&
272
+ ((_b = field.enum) === null || _b === void 0 ? void 0 : _b.typeName) != "google.protobuf.NullValue");
273
+ }
276
274
  const tokenIgnoredUnknownEnum = Symbol();
277
- function readEnum(desc, json, ignoreUnknownFields, nullAsZeroValue) {
275
+ function readEnum(desc, json, ignoreUnknownFields) {
278
276
  if (json === null) {
279
- if (desc.typeName == "google.protobuf.NullValue") {
280
- return 0; // google.protobuf.NullValue.NULL_VALUE = 0
281
- }
282
- return nullAsZeroValue ? desc.values[0].number : tokenNull;
277
+ return desc.values[0].number;
283
278
  }
284
279
  switch (typeof json) {
285
280
  case "number":
@@ -299,14 +294,13 @@ function readEnum(desc, json, ignoreUnknownFields, nullAsZeroValue) {
299
294
  }
300
295
  throw new Error(`cannot decode ${desc} from JSON: ${(0, reflect_check_js_1.formatVal)(json)}`);
301
296
  }
302
- const tokenNull = Symbol();
303
- function scalarFromJson(field, json, nullAsZeroValue) {
304
- if (json === null) {
305
- if (nullAsZeroValue) {
306
- return (0, scalar_js_1.scalarZeroValue)(field.scalar, false);
307
- }
308
- return tokenNull;
309
- }
297
+ /**
298
+ * Try to parse a JSON value to a scalar value for the reflect API.
299
+ *
300
+ * Returns the input if the JSON value cannot be converted. Raises a FieldError
301
+ * if conversion would be ambiguous.
302
+ */
303
+ function scalarFromJson(field, json) {
310
304
  // int64, sfixed64, sint64, fixed64, uint64: Reflect supports string and number.
311
305
  // string, bool: Supported by reflect.
312
306
  switch (field.scalar) {
@@ -379,24 +373,24 @@ function scalarFromJson(field, json, nullAsZeroValue) {
379
373
  *
380
374
  * Returns the input if the JSON value cannot be converted.
381
375
  */
382
- function mapKeyFromJson(type, json) {
376
+ function mapKeyFromJson(type, jsonString) {
383
377
  switch (type) {
384
378
  case descriptors_js_1.ScalarType.BOOL:
385
- switch (json) {
379
+ switch (jsonString) {
386
380
  case "true":
387
381
  return true;
388
382
  case "false":
389
383
  return false;
390
384
  }
391
- return json;
385
+ return jsonString;
392
386
  case descriptors_js_1.ScalarType.INT32:
393
387
  case descriptors_js_1.ScalarType.FIXED32:
394
388
  case descriptors_js_1.ScalarType.UINT32:
395
389
  case descriptors_js_1.ScalarType.SFIXED32:
396
390
  case descriptors_js_1.ScalarType.SINT32:
397
- return int32FromJson(json);
391
+ return int32FromJson(jsonString);
398
392
  default:
399
- return json;
393
+ return jsonString;
400
394
  }
401
395
  }
402
396
  /**
@@ -467,7 +461,7 @@ function tryWktFromJson(msg, jsonValue, opts) {
467
461
  msg.clear(valueField);
468
462
  }
469
463
  else {
470
- msg.set(valueField, scalarFromJson(valueField, jsonValue, true));
464
+ msg.set(valueField, scalarFromJson(valueField, jsonValue));
471
465
  }
472
466
  return true;
473
467
  }
@@ -497,7 +491,7 @@ function anyFromJson(any, json, opts) {
497
491
  throw new Error(`cannot decode message ${any.$typeName} from JSON: ${typeUrl} is not in the type registry`);
498
492
  }
499
493
  const msg = (0, reflect_js_1.reflect)(desc);
500
- if (typeName.startsWith("google.protobuf.") &&
494
+ if ((0, index_js_1.hasCustomJsonRepresentation)(desc) &&
501
495
  Object.prototype.hasOwnProperty.call(json, "value")) {
502
496
  const value = json.value;
503
497
  readMessage(msg, value, opts);
@@ -565,14 +559,12 @@ function fieldMaskFromJson(fieldMask, json) {
565
559
  if (json === "") {
566
560
  return;
567
561
  }
568
- function camelToSnake(str) {
569
- if (str.includes("_")) {
562
+ fieldMask.paths = json.split(",").map((path) => {
563
+ if (path.includes("_")) {
570
564
  throw new Error(`cannot decode message ${fieldMask.$typeName} from JSON: path names must be lowerCamelCase`);
571
565
  }
572
- const sc = str.replace(/[A-Z]/g, (letter) => "_" + letter.toLowerCase());
573
- return sc[0] === "_" ? sc.substring(1) : sc;
574
- }
575
- fieldMask.paths = json.split(",").map(camelToSnake);
566
+ return (0, names_js_1.protoSnakeCase)(path);
567
+ });
576
568
  }
577
569
  function structFromJson(struct, json) {
578
570
  if (typeof json != "object" || json == null || Array.isArray(json)) {
package/dist/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // Copyright 2021-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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-2025 Buf Technologies, Inc.
2
+ // Copyright 2021-2026 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.