@bufbuild/protobuf 1.3.0 → 1.3.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.
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
17
- // @generated by protoc-gen-es v1.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v1.3.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -14,7 +14,7 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
17
- // @generated by protoc-gen-es v1.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
17
+ // @generated by protoc-gen-es v1.3.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
18
18
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
19
19
  /* eslint-disable */
20
20
  const proto3_js_1 = require("../../proto3.js");
@@ -260,7 +260,7 @@ function debugJsonValue(json) {
260
260
  case "string":
261
261
  return json.length > 100 ? "string" : `"${json.split('"').join('\\"')}"`;
262
262
  default:
263
- return json.toString();
263
+ return String(json);
264
264
  }
265
265
  }
266
266
  // May throw an error. If the error message is non-blank, it should be shown.
@@ -390,6 +390,7 @@ function readEnum(type, json, ignoreUnknownFields) {
390
390
  break;
391
391
  case "string":
392
392
  const value = type.findName(json);
393
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
393
394
  if (value || ignoreUnknownFields) {
394
395
  return value === null || value === void 0 ? void 0 : value.no;
395
396
  }
@@ -45,17 +45,35 @@ function makeUtilCommon() {
45
45
  !(val instanceof sourceField.T)) {
46
46
  val = new sourceField.T(val);
47
47
  }
48
+ else if (sourceField &&
49
+ sourceField.kind === "scalar" &&
50
+ sourceField.T === field_js_1.ScalarType.BYTES) {
51
+ val = toU8Arr(val);
52
+ }
48
53
  t[localName] = { case: sk, value: val };
49
54
  break;
50
55
  case "scalar":
51
56
  case "enum":
52
- t[localName] = s[localName];
57
+ let copy = s[localName];
58
+ if (member.T === field_js_1.ScalarType.BYTES) {
59
+ copy = member.repeated
60
+ ? copy.map(toU8Arr)
61
+ : toU8Arr(copy);
62
+ }
63
+ t[localName] = copy;
53
64
  break;
54
65
  case "map":
55
66
  switch (member.V.kind) {
56
67
  case "scalar":
57
68
  case "enum":
58
- Object.assign(t[localName], s[localName]);
69
+ if (member.V.T === field_js_1.ScalarType.BYTES) {
70
+ for (const [k, v] of Object.entries(s[localName])) {
71
+ t[localName][k] = toU8Arr(v);
72
+ }
73
+ }
74
+ else {
75
+ Object.assign(t[localName], s[localName]);
76
+ }
59
77
  break;
60
78
  case "message":
61
79
  const messageType = member.V.T;
@@ -79,7 +97,14 @@ function makeUtilCommon() {
79
97
  else if (s[localName] !== undefined) {
80
98
  const val = s[localName];
81
99
  if (mt.fieldWrapper) {
82
- t[localName] = val;
100
+ if (
101
+ // We can't use BytesValue.typeName as that will create a circular import
102
+ mt.typeName === "google.protobuf.BytesValue") {
103
+ t[localName] = toU8Arr(val);
104
+ }
105
+ else {
106
+ t[localName] = val;
107
+ }
83
108
  }
84
109
  else {
85
110
  t[localName] = val instanceof mt ? val : new mt(val);
@@ -161,22 +186,22 @@ function makeUtilCommon() {
161
186
  const source = message[member.localName];
162
187
  let copy;
163
188
  if (member.repeated) {
164
- copy = source.map((e) => cloneSingularField(member, e));
189
+ copy = source.map(cloneSingularField);
165
190
  }
166
191
  else if (member.kind == "map") {
167
192
  copy = any[member.localName];
168
193
  for (const [key, v] of Object.entries(source)) {
169
- copy[key] = cloneSingularField(member.V, v);
194
+ copy[key] = cloneSingularField(v);
170
195
  }
171
196
  }
172
197
  else if (member.kind == "oneof") {
173
198
  const f = member.findField(source.case);
174
199
  copy = f
175
- ? { case: source.case, value: cloneSingularField(f, source.value) }
200
+ ? { case: source.case, value: cloneSingularField(source.value) }
176
201
  : { case: undefined };
177
202
  }
178
203
  else {
179
- copy = cloneSingularField(member, source);
204
+ copy = cloneSingularField(source);
180
205
  }
181
206
  any[member.localName] = copy;
182
207
  }
@@ -186,7 +211,7 @@ function makeUtilCommon() {
186
211
  }
187
212
  exports.makeUtilCommon = makeUtilCommon;
188
213
  // clone a single field value - i.e. the element type of repeated fields, the value type of maps
189
- function cloneSingularField(field, value) {
214
+ function cloneSingularField(value) {
190
215
  if (value === undefined) {
191
216
  return value;
192
217
  }
@@ -200,3 +225,7 @@ function cloneSingularField(field, value) {
200
225
  }
201
226
  return value;
202
227
  }
228
+ // converts any ArrayLike<number> to Uint8Array if necessary.
229
+ function toU8Arr(input) {
230
+ return input instanceof Uint8Array ? input : new Uint8Array(input);
231
+ }
@@ -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
- // @generated by protoc-gen-es v1.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v1.3.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -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
- // @generated by protoc-gen-es v1.3.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
14
+ // @generated by protoc-gen-es v1.3.1 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
15
15
  // @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
16
16
  /* eslint-disable */
17
17
  import { proto3 } from "../../proto3.js";
@@ -256,7 +256,7 @@ function debugJsonValue(json) {
256
256
  case "string":
257
257
  return json.length > 100 ? "string" : `"${json.split('"').join('\\"')}"`;
258
258
  default:
259
- return json.toString();
259
+ return String(json);
260
260
  }
261
261
  }
262
262
  // May throw an error. If the error message is non-blank, it should be shown.
@@ -386,6 +386,7 @@ function readEnum(type, json, ignoreUnknownFields) {
386
386
  break;
387
387
  case "string":
388
388
  const value = type.findName(json);
389
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
389
390
  if (value || ignoreUnknownFields) {
390
391
  return value === null || value === void 0 ? void 0 : value.no;
391
392
  }
@@ -42,17 +42,35 @@ export function makeUtilCommon() {
42
42
  !(val instanceof sourceField.T)) {
43
43
  val = new sourceField.T(val);
44
44
  }
45
+ else if (sourceField &&
46
+ sourceField.kind === "scalar" &&
47
+ sourceField.T === ScalarType.BYTES) {
48
+ val = toU8Arr(val);
49
+ }
45
50
  t[localName] = { case: sk, value: val };
46
51
  break;
47
52
  case "scalar":
48
53
  case "enum":
49
- t[localName] = s[localName];
54
+ let copy = s[localName];
55
+ if (member.T === ScalarType.BYTES) {
56
+ copy = member.repeated
57
+ ? copy.map(toU8Arr)
58
+ : toU8Arr(copy);
59
+ }
60
+ t[localName] = copy;
50
61
  break;
51
62
  case "map":
52
63
  switch (member.V.kind) {
53
64
  case "scalar":
54
65
  case "enum":
55
- Object.assign(t[localName], s[localName]);
66
+ if (member.V.T === ScalarType.BYTES) {
67
+ for (const [k, v] of Object.entries(s[localName])) {
68
+ t[localName][k] = toU8Arr(v);
69
+ }
70
+ }
71
+ else {
72
+ Object.assign(t[localName], s[localName]);
73
+ }
56
74
  break;
57
75
  case "message":
58
76
  const messageType = member.V.T;
@@ -76,7 +94,14 @@ export function makeUtilCommon() {
76
94
  else if (s[localName] !== undefined) {
77
95
  const val = s[localName];
78
96
  if (mt.fieldWrapper) {
79
- t[localName] = val;
97
+ if (
98
+ // We can't use BytesValue.typeName as that will create a circular import
99
+ mt.typeName === "google.protobuf.BytesValue") {
100
+ t[localName] = toU8Arr(val);
101
+ }
102
+ else {
103
+ t[localName] = val;
104
+ }
80
105
  }
81
106
  else {
82
107
  t[localName] = val instanceof mt ? val : new mt(val);
@@ -158,22 +183,22 @@ export function makeUtilCommon() {
158
183
  const source = message[member.localName];
159
184
  let copy;
160
185
  if (member.repeated) {
161
- copy = source.map((e) => cloneSingularField(member, e));
186
+ copy = source.map(cloneSingularField);
162
187
  }
163
188
  else if (member.kind == "map") {
164
189
  copy = any[member.localName];
165
190
  for (const [key, v] of Object.entries(source)) {
166
- copy[key] = cloneSingularField(member.V, v);
191
+ copy[key] = cloneSingularField(v);
167
192
  }
168
193
  }
169
194
  else if (member.kind == "oneof") {
170
195
  const f = member.findField(source.case);
171
196
  copy = f
172
- ? { case: source.case, value: cloneSingularField(f, source.value) }
197
+ ? { case: source.case, value: cloneSingularField(source.value) }
173
198
  : { case: undefined };
174
199
  }
175
200
  else {
176
- copy = cloneSingularField(member, source);
201
+ copy = cloneSingularField(source);
177
202
  }
178
203
  any[member.localName] = copy;
179
204
  }
@@ -182,7 +207,7 @@ export function makeUtilCommon() {
182
207
  };
183
208
  }
184
209
  // clone a single field value - i.e. the element type of repeated fields, the value type of maps
185
- function cloneSingularField(field, value) {
210
+ function cloneSingularField(value) {
186
211
  if (value === undefined) {
187
212
  return value;
188
213
  }
@@ -196,3 +221,7 @@ function cloneSingularField(field, value) {
196
221
  }
197
222
  return value;
198
223
  }
224
+ // converts any ArrayLike<number> to Uint8Array if necessary.
225
+ function toU8Arr(input) {
226
+ return input instanceof Uint8Array ? input : new Uint8Array(input);
227
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protobuf",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
6
6
  "repository": {