@bufbuild/protobuf 2.10.2 → 2.11.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/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.js +1 -1
  24. package/dist/cjs/equals.js +1 -1
  25. package/dist/cjs/extensions.js +1 -1
  26. package/dist/cjs/fields.js +1 -1
  27. package/dist/cjs/from-binary.js +1 -1
  28. package/dist/cjs/from-json.js +80 -88
  29. package/dist/cjs/index.js +1 -1
  30. package/dist/cjs/is-message.js +1 -1
  31. package/dist/cjs/json-value.js +1 -1
  32. package/dist/cjs/merge.js +1 -1
  33. package/dist/cjs/proto-int64.js +1 -1
  34. package/dist/cjs/reflect/error.js +1 -1
  35. package/dist/cjs/reflect/guard.js +1 -1
  36. package/dist/cjs/reflect/index.js +1 -1
  37. package/dist/cjs/reflect/names.d.ts +11 -0
  38. package/dist/cjs/reflect/names.js +15 -1
  39. package/dist/cjs/reflect/nested-types.js +1 -1
  40. package/dist/cjs/reflect/path.js +1 -1
  41. package/dist/cjs/reflect/reflect-check.js +1 -1
  42. package/dist/cjs/reflect/reflect-types.js +1 -1
  43. package/dist/cjs/reflect/reflect.js +1 -1
  44. package/dist/cjs/reflect/scalar.js +1 -1
  45. package/dist/cjs/reflect/unsafe.js +1 -1
  46. package/dist/cjs/registry.js +1 -1
  47. package/dist/cjs/to-binary.js +1 -1
  48. package/dist/cjs/to-json.js +3 -5
  49. package/dist/cjs/types.js +1 -1
  50. package/dist/cjs/wire/base64-encoding.js +1 -1
  51. package/dist/cjs/wire/binary-encoding.js +1 -1
  52. package/dist/cjs/wire/index.js +1 -1
  53. package/dist/cjs/wire/size-delimited.js +1 -1
  54. package/dist/cjs/wire/text-encoding.js +1 -1
  55. package/dist/cjs/wire/text-format.js +1 -1
  56. package/dist/cjs/wkt/any.js +1 -1
  57. package/dist/cjs/wkt/duration.js +1 -1
  58. package/dist/cjs/wkt/gen/google/protobuf/any_pb.js +1 -1
  59. package/dist/cjs/wkt/gen/google/protobuf/api_pb.js +1 -1
  60. package/dist/cjs/wkt/gen/google/protobuf/compiler/plugin_pb.js +1 -1
  61. package/dist/cjs/wkt/gen/google/protobuf/cpp_features_pb.js +1 -1
  62. package/dist/cjs/wkt/gen/google/protobuf/descriptor_pb.js +1 -1
  63. package/dist/cjs/wkt/gen/google/protobuf/duration_pb.js +1 -1
  64. package/dist/cjs/wkt/gen/google/protobuf/empty_pb.js +1 -1
  65. package/dist/cjs/wkt/gen/google/protobuf/field_mask_pb.js +1 -1
  66. package/dist/cjs/wkt/gen/google/protobuf/go_features_pb.js +1 -1
  67. package/dist/cjs/wkt/gen/google/protobuf/java_features_pb.js +1 -1
  68. package/dist/cjs/wkt/gen/google/protobuf/source_context_pb.js +1 -1
  69. package/dist/cjs/wkt/gen/google/protobuf/struct_pb.js +1 -1
  70. package/dist/cjs/wkt/gen/google/protobuf/timestamp_pb.js +1 -1
  71. package/dist/cjs/wkt/gen/google/protobuf/type_pb.js +1 -1
  72. package/dist/cjs/wkt/gen/google/protobuf/wrappers_pb.js +1 -1
  73. package/dist/cjs/wkt/index.js +1 -1
  74. package/dist/cjs/wkt/timestamp.js +1 -1
  75. package/dist/cjs/wkt/wrappers.js +1 -1
  76. package/dist/esm/clone.js +1 -1
  77. package/dist/esm/codegenv1/enum.js +1 -1
  78. package/dist/esm/codegenv1/extension.js +1 -1
  79. package/dist/esm/codegenv1/file.js +1 -1
  80. package/dist/esm/codegenv1/index.js +1 -1
  81. package/dist/esm/codegenv1/message.js +1 -1
  82. package/dist/esm/codegenv1/service.js +1 -1
  83. package/dist/esm/codegenv1/symbols.js +1 -1
  84. package/dist/esm/codegenv1/types.js +1 -1
  85. package/dist/esm/codegenv2/boot.js +1 -1
  86. package/dist/esm/codegenv2/embed.js +1 -1
  87. package/dist/esm/codegenv2/enum.js +1 -1
  88. package/dist/esm/codegenv2/extension.js +1 -1
  89. package/dist/esm/codegenv2/file.js +1 -1
  90. package/dist/esm/codegenv2/index.js +1 -1
  91. package/dist/esm/codegenv2/message.js +1 -1
  92. package/dist/esm/codegenv2/restore-json-names.js +1 -1
  93. package/dist/esm/codegenv2/scalar.js +1 -1
  94. package/dist/esm/codegenv2/service.js +1 -1
  95. package/dist/esm/codegenv2/symbols.js +1 -1
  96. package/dist/esm/codegenv2/types.js +1 -1
  97. package/dist/esm/create.js +1 -1
  98. package/dist/esm/descriptors.js +1 -1
  99. package/dist/esm/equals.js +1 -1
  100. package/dist/esm/extensions.js +1 -1
  101. package/dist/esm/fields.js +1 -1
  102. package/dist/esm/from-binary.js +1 -1
  103. package/dist/esm/from-json.js +80 -88
  104. package/dist/esm/index.js +1 -1
  105. package/dist/esm/is-message.js +1 -1
  106. package/dist/esm/json-value.js +1 -1
  107. package/dist/esm/merge.js +1 -1
  108. package/dist/esm/proto-int64.js +1 -1
  109. package/dist/esm/reflect/error.js +1 -1
  110. package/dist/esm/reflect/guard.js +1 -1
  111. package/dist/esm/reflect/index.js +1 -1
  112. package/dist/esm/reflect/names.d.ts +11 -0
  113. package/dist/esm/reflect/names.js +14 -1
  114. package/dist/esm/reflect/nested-types.js +1 -1
  115. package/dist/esm/reflect/path.js +1 -1
  116. package/dist/esm/reflect/reflect-check.js +1 -1
  117. package/dist/esm/reflect/reflect-types.js +1 -1
  118. package/dist/esm/reflect/reflect.js +1 -1
  119. package/dist/esm/reflect/scalar.js +1 -1
  120. package/dist/esm/reflect/unsafe.js +1 -1
  121. package/dist/esm/registry.js +1 -1
  122. package/dist/esm/to-binary.js +1 -1
  123. package/dist/esm/to-json.js +4 -6
  124. package/dist/esm/types.js +1 -1
  125. package/dist/esm/wire/base64-encoding.js +1 -1
  126. package/dist/esm/wire/binary-encoding.js +1 -1
  127. package/dist/esm/wire/index.js +1 -1
  128. package/dist/esm/wire/size-delimited.js +1 -1
  129. package/dist/esm/wire/text-encoding.js +1 -1
  130. package/dist/esm/wire/text-format.js +1 -1
  131. package/dist/esm/wkt/any.js +1 -1
  132. package/dist/esm/wkt/duration.js +1 -1
  133. package/dist/esm/wkt/gen/google/protobuf/any_pb.js +1 -1
  134. package/dist/esm/wkt/gen/google/protobuf/api_pb.js +1 -1
  135. package/dist/esm/wkt/gen/google/protobuf/compiler/plugin_pb.js +1 -1
  136. package/dist/esm/wkt/gen/google/protobuf/cpp_features_pb.js +1 -1
  137. package/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js +1 -1
  138. package/dist/esm/wkt/gen/google/protobuf/duration_pb.js +1 -1
  139. package/dist/esm/wkt/gen/google/protobuf/empty_pb.js +1 -1
  140. package/dist/esm/wkt/gen/google/protobuf/field_mask_pb.js +1 -1
  141. package/dist/esm/wkt/gen/google/protobuf/go_features_pb.js +1 -1
  142. package/dist/esm/wkt/gen/google/protobuf/java_features_pb.js +1 -1
  143. package/dist/esm/wkt/gen/google/protobuf/source_context_pb.js +1 -1
  144. package/dist/esm/wkt/gen/google/protobuf/struct_pb.js +1 -1
  145. package/dist/esm/wkt/gen/google/protobuf/timestamp_pb.js +1 -1
  146. package/dist/esm/wkt/gen/google/protobuf/type_pb.js +1 -1
  147. package/dist/esm/wkt/gen/google/protobuf/wrappers_pb.js +1 -1
  148. package/dist/esm/wkt/index.js +1 -1
  149. package/dist/esm/wkt/timestamp.js +1 -1
  150. package/dist/esm/wkt/wrappers.js +1 -1
  151. 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.
@@ -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.
@@ -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
  }
@@ -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.
package/dist/cjs/merge.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.
@@ -9,8 +9,19 @@ export declare function qualifiedName(desc: AnyDesc): string;
9
9
  /**
10
10
  * Converts snake_case to protoCamelCase according to the convention
11
11
  * used by protoc to convert a field name to a JSON name.
12
+ *
13
+ * See https://protobuf.com/docs/language-spec#default-json-names
14
+ *
15
+ * The function protoSnakeCase provides the reverse.
12
16
  */
13
17
  export declare function protoCamelCase(snakeCase: string): string;
18
+ /**
19
+ * Converts protoCamelCase to snake_case.
20
+ *
21
+ * This function is the reverse of function protoCamelCase. Note that some names
22
+ * are not reversible - for example, "foo__bar" -> "fooBar" -> "foo_bar".
23
+ */
24
+ export declare function protoSnakeCase(lowerCamelCase: string): string;
14
25
  /**
15
26
  * Escapes names that are reserved for ECMAScript built-in object properties.
16
27
  *
@@ -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.
@@ -15,6 +15,7 @@
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.qualifiedName = qualifiedName;
17
17
  exports.protoCamelCase = protoCamelCase;
18
+ exports.protoSnakeCase = protoSnakeCase;
18
19
  exports.safeObjectProperty = safeObjectProperty;
19
20
  /**
20
21
  * Return a fully-qualified name for a Protobuf descriptor.
@@ -46,6 +47,10 @@ function qualifiedName(desc) {
46
47
  /**
47
48
  * Converts snake_case to protoCamelCase according to the convention
48
49
  * used by protoc to convert a field name to a JSON name.
50
+ *
51
+ * See https://protobuf.com/docs/language-spec#default-json-names
52
+ *
53
+ * The function protoSnakeCase provides the reverse.
49
54
  */
50
55
  function protoCamelCase(snakeCase) {
51
56
  let capNext = false;
@@ -80,6 +85,15 @@ function protoCamelCase(snakeCase) {
80
85
  }
81
86
  return b.join("");
82
87
  }
88
+ /**
89
+ * Converts protoCamelCase to snake_case.
90
+ *
91
+ * This function is the reverse of function protoCamelCase. Note that some names
92
+ * are not reversible - for example, "foo__bar" -> "fooBar" -> "foo_bar".
93
+ */
94
+ function protoSnakeCase(lowerCamelCase) {
95
+ return lowerCamelCase.replace(/[A-Z]/g, (letter) => "_" + letter.toLowerCase());
96
+ }
83
97
  /**
84
98
  * Names that cannot be used for object properties because they are reserved
85
99
  * by built-in JavaScript properties.
@@ -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.