ts-proto 1.167.7 → 1.167.9

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.
@@ -21,15 +21,20 @@ function generateWrapDeep(ctx, fullProtoTypeName, fieldNames) {
21
21
  const chunks = [];
22
22
  if ((0, types_1.isStructTypeName)(fullProtoTypeName)) {
23
23
  let setStatement = "struct.fields[key] = Value.wrap(object[key]);";
24
+ let defaultFields = "struct.fields ??= {};";
24
25
  if (ctx.options.useMapType) {
25
26
  setStatement = "struct.fields.set(key, Value.wrap(object[key]));";
27
+ defaultFields = "struct.fields ??= new Map<string, any | undefined>();";
26
28
  }
29
+ if (ctx.options.useOptionals !== "all")
30
+ defaultFields = "";
27
31
  chunks.push((0, ts_poet_1.code) `wrap(object: {[key: string]: any} | undefined): Struct {
28
32
  const struct = createBaseStruct();
33
+ ${defaultFields}
29
34
  if (object !== undefined) {
30
- Object.keys(object).forEach(key => {
35
+ for (const key of Object.keys(object)) {
31
36
  ${setStatement}
32
- });
37
+ }
33
38
  }
34
39
  return struct;
35
40
  }`);
@@ -85,9 +90,11 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
85
90
  if (ctx.options.useMapType) {
86
91
  chunks.push((0, ts_poet_1.code) `unwrap(message: Struct): {[key: string]: any} {
87
92
  const object: { [key: string]: any } = {};
88
- [...message.fields.keys()].forEach((key) => {
89
- object[key] = Value.unwrap(message.fields.get(key));
90
- });
93
+ if (message.fields) {
94
+ for (const key of message.fields.keys()) {
95
+ object[key] = Value.unwrap(message.fields.get(key));
96
+ }
97
+ }
91
98
  return object;
92
99
  }`);
93
100
  }
@@ -95,9 +102,9 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
95
102
  chunks.push((0, ts_poet_1.code) `unwrap(message: Struct): {[key: string]: any} {
96
103
  const object: { [key: string]: any } = {};
97
104
  if (message.fields) {
98
- Object.keys(message.fields).forEach(key => {
105
+ for (const key of Object.keys(message.fields)) {
99
106
  object[key] = Value.unwrap(message.fields[key]);
100
- });
107
+ }
101
108
  }
102
109
  return object;
103
110
  }`);
@@ -148,15 +155,20 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
148
155
  const chunks = [];
149
156
  if ((0, types_1.isStructTypeName)(fullProtoTypeName)) {
150
157
  let setStatement = "struct.fields[key] = object[key];";
158
+ let defaultFields = "struct.fields ??= {};";
151
159
  if (ctx.options.useMapType) {
152
160
  setStatement = "struct.fields.set(key, object[key]);";
161
+ defaultFields = "struct.fields ??= new Map<string, any | undefined>();";
153
162
  }
163
+ if (ctx.options.useOptionals !== "all")
164
+ defaultFields = "";
154
165
  chunks.push((0, ts_poet_1.code) `wrap(object: {[key: string]: any} | undefined): Struct {
155
166
  const struct = createBaseStruct();
167
+ ${defaultFields}
156
168
  if (object !== undefined) {
157
- Object.keys(object).forEach(key => {
169
+ for (const key of Object.keys(object)) {
158
170
  ${setStatement}
159
- });
171
+ }
160
172
  }
161
173
  return struct;
162
174
  }`);
@@ -234,9 +246,11 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
234
246
  if (ctx.options.useMapType) {
235
247
  chunks.push((0, ts_poet_1.code) `unwrap(message: Struct): {[key: string]: any} {
236
248
  const object: { [key: string]: any } = {};
237
- [...message.fields.keys()].forEach((key) => {
238
- object[key] = message.fields.get(key);
239
- });
249
+ if (message.fields) {
250
+ for (const key of message.fields.keys()) {
251
+ object[key] = message.fields.get(key);
252
+ }
253
+ }
240
254
  return object;
241
255
  }`);
242
256
  }
@@ -244,9 +258,9 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
244
258
  chunks.push((0, ts_poet_1.code) `unwrap(message: Struct): {[key: string]: any} {
245
259
  const object: { [key: string]: any } = {};
246
260
  if (message.fields) {
247
- Object.keys(message.fields).forEach(key => {
261
+ for (const key of Object.keys(message.fields)) {
248
262
  object[key] = message.fields[key];
249
- });
263
+ }
250
264
  }
251
265
  return object;
252
266
  }`);
package/build/main.js CHANGED
@@ -393,8 +393,8 @@ function makeByteUtils(options) {
393
393
  return bytesFromBase64BrowserSnippet;
394
394
  default:
395
395
  return (0, ts_poet_1.code) `
396
- if (${globalThis}.Buffer) {
397
- ${bytesFromBase64NodeSnippet}
396
+ if ((${globalThis} as any).Buffer) {
397
+ ${bytesFromBase64NodeSnippet}
398
398
  } else {
399
399
  ${bytesFromBase64BrowserSnippet}
400
400
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.167.7",
3
+ "version": "1.167.9",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",