ts-proto 2.9.0 → 2.10.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.
@@ -36,7 +36,7 @@ function generateWrapDeep(ctx, fullProtoTypeName, fieldNames) {
36
36
  const struct = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}();
37
37
  ${defaultFields}
38
38
  if (object !== undefined) {
39
- for (const key of Object.keys(object)) {
39
+ for (const key of ${ctx.utils.globalThis}.Object.keys(object)) {
40
40
  ${setStatement}
41
41
  }
42
42
  }
@@ -105,7 +105,7 @@ function generateUnwrapDeep(ctx, fullProtoTypeName, fieldNames) {
105
105
  chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}): {[key: string]: any} {
106
106
  const object: { [key: string]: any } = {};
107
107
  if (message.fields) {
108
- for (const key of Object.keys(message.fields)) {
108
+ for (const key of ${ctx.utils.globalThis}.Object.keys(message.fields)) {
109
109
  object[key] = Value.unwrap(message.fields[key]);
110
110
  }
111
111
  }
@@ -168,7 +168,7 @@ function generateWrapShallow(ctx, fullProtoTypeName, fieldNames) {
168
168
  const struct = createBase${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}();
169
169
  ${defaultFields}
170
170
  if (object !== undefined) {
171
- for (const key of Object.keys(object)) {
171
+ for (const key of ${ctx.utils.globalThis}.Object.keys(object)) {
172
172
  ${setStatement}
173
173
  }
174
174
  }
@@ -280,7 +280,7 @@ function generateUnwrapShallow(ctx, fullProtoTypeName, fieldNames) {
280
280
  chunks.push((0, ts_poet_1.code) `unwrap(message: ${(0, utils_1.wrapTypeName)(ctx.options, "Struct")}): {[key: string]: any} {
281
281
  const object: { [key: string]: any } = {};
282
282
  if (message.fields) {
283
- for (const key of Object.keys(message.fields)) {
283
+ for (const key of ${ctx.utils.globalThis}.Object.keys(message.fields)) {
284
284
  object[key] = message.fields[key];
285
285
  }
286
286
  }
package/build/src/main.js CHANGED
@@ -1358,7 +1358,8 @@ function generateEncode(ctx, fullName, messageDesc) {
1358
1358
  const isOptional = (0, types_1.isOptionalProperty)(field, messageDesc.options, options, currentFile.isProto3Syntax);
1359
1359
  if ((0, types_1.isRepeated)(field)) {
1360
1360
  if ((0, types_1.isMapType)(ctx, messageDesc, field)) {
1361
- const valueType = typeMap.get(field.typeName)[2].field[1];
1361
+ const mapInfo = (0, types_1.detectMapType)(ctx, messageDesc, field);
1362
+ const valueType = mapInfo.valueField;
1362
1363
  const maybeTypeField = (0, options_1.addTypeToMessages)(options) ? `$type: '${field.typeName.slice(1)}',` : "";
1363
1364
  const entryWriteSnippet = (0, types_1.isValueType)(ctx, valueType)
1364
1365
  ? (0, ts_poet_1.code) `
@@ -1378,7 +1379,7 @@ function generateEncode(ctx, fullName, messageDesc) {
1378
1379
  }
1379
1380
  else {
1380
1381
  chunks.push((0, ts_poet_1.code) `
1381
- Object.entries(${messageProperty}${optionalAlternative}).forEach(([key, value]) => {
1382
+ ${utils.globalThis}.Object.entries(${messageProperty}${optionalAlternative}).forEach(([key, value]: [string, ${mapInfo.valueType}]) => {
1382
1383
  ${entryWriteSnippet}
1383
1384
  });
1384
1385
  `);
@@ -1533,7 +1534,7 @@ function generateEncode(ctx, fullName, messageDesc) {
1533
1534
  });
1534
1535
  if (options.unknownFields) {
1535
1536
  chunks.push((0, ts_poet_1.code) `if (message._unknownFields !== undefined) {
1536
- for (const [key, values] of Object.entries(message._unknownFields)) {
1537
+ for (const [key, values] of ${utils.globalThis}.Object.entries(message._unknownFields)) {
1537
1538
  const tag = parseInt(key, 10);
1538
1539
  for (const value of values) {
1539
1540
  writer.uint32(tag).raw(value);
@@ -1926,7 +1927,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
1926
1927
  }
1927
1928
  else {
1928
1929
  const cstr = (0, case_1.capitalize)(valueType.toCodeString([]));
1929
- return (0, ts_poet_1.code) `${cstr}(${from})`;
1930
+ return (0, ts_poet_1.code) `${utils.globalThis}.${cstr}(${from})`;
1930
1931
  }
1931
1932
  }
1932
1933
  else if ((0, types_1.isObjectId)(valueField) && options.useMongoObjectId) {
@@ -1969,13 +1970,14 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
1969
1970
  }
1970
1971
  else if ((0, types_1.isRepeated)(field)) {
1971
1972
  if ((0, types_1.isMapType)(ctx, messageDesc, field)) {
1973
+ const mapInfo = (0, types_1.detectMapType)(ctx, messageDesc, field);
1972
1974
  const fieldType = (0, types_1.toTypeName)(ctx, messageDesc, field);
1973
1975
  const i = convertFromObjectKey(ctx, messageDesc, field, "key");
1974
1976
  if ((0, types_1.shouldGenerateJSMapType)(ctx, messageDesc, field)) {
1975
1977
  const fallback = noDefaultValue ? (0, utils_1.nullOrUndefined)(options) : "new Map()";
1976
1978
  chunks.push((0, ts_poet_1.code) `
1977
1979
  ${fieldKey}: ${ctx.utils.isObject}(${jsonProperty})
1978
- ? Object.entries(${jsonProperty}).reduce<${fieldType}>((acc, [key, value]) => {
1980
+ ? (${ctx.utils.globalThis}.Object.entries(${jsonProperty}) as [string, any][]).reduce((acc: ${fieldType}, [key, value]: [string, any]) => {
1979
1981
  acc.set(${i}, ${readSnippet("value")});
1980
1982
  return acc;
1981
1983
  }, new Map())
@@ -1986,7 +1988,7 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
1986
1988
  const fallback = noDefaultValue ? (0, utils_1.nullOrUndefined)(options) : "{}";
1987
1989
  chunks.push((0, ts_poet_1.code) `
1988
1990
  ${fieldKey}: ${ctx.utils.isObject}(${jsonProperty})
1989
- ? Object.entries(${jsonProperty}).reduce<${fieldType}>((acc, [key, value]) => {
1991
+ ? (${ctx.utils.globalThis}.Object.entries(${jsonProperty}) as [string, any][]).reduce((acc: ${fieldType}, [key, value]: [string, any]) => {
1990
1992
  acc[${i}] = ${readSnippet("value")};
1991
1993
  return acc;
1992
1994
  }, {})
@@ -2216,9 +2218,10 @@ function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
2216
2218
  `);
2217
2219
  }
2218
2220
  else {
2221
+ const mapInfo = (0, types_1.detectMapType)(ctx, messageDesc, field);
2219
2222
  chunks.push((0, ts_poet_1.code) `
2220
2223
  if (${messageProperty}) {
2221
- const entries = Object.entries(${messageProperty});
2224
+ const entries = ${utils.globalThis}.Object.entries(${messageProperty}) as [string, ${mapInfo.valueType}][];
2222
2225
  if (entries.length > 0) {
2223
2226
  ${jsonProperty} = {};
2224
2227
  entries.forEach(([k, v]) => {
@@ -2390,6 +2393,7 @@ function generateFromPartial(ctx, fullName, messageDesc) {
2390
2393
  // and then use the snippet to handle repeated fields if necessary
2391
2394
  if ((0, types_1.isRepeated)(field)) {
2392
2395
  if ((0, types_1.isMapType)(ctx, messageDesc, field)) {
2396
+ const mapInfo = (0, types_1.detectMapType)(ctx, messageDesc, field);
2393
2397
  const fieldType = (0, types_1.toTypeName)(ctx, messageDesc, field);
2394
2398
  const i = convertFromObjectKey(ctx, messageDesc, field, "key");
2395
2399
  const noValueSnippet = noDefaultValue
@@ -2410,12 +2414,15 @@ function generateFromPartial(ctx, fullName, messageDesc) {
2410
2414
  }
2411
2415
  else {
2412
2416
  chunks.push((0, ts_poet_1.code) `
2413
- ${messageProperty} = ${noValueSnippet} Object.entries(${objectProperty} ?? {}).reduce<${fieldType}>((acc, [key, value]) => {
2414
- if (value !== undefined) {
2415
- acc[${i}] = ${readSnippet("value")};
2416
- }
2417
- return acc;
2418
- }, {});
2417
+ ${messageProperty} = ${noValueSnippet} (${utils.globalThis}.Object.entries(${objectProperty} ?? {}) as [string, ${mapInfo.valueType}][]).reduce(
2418
+ (acc: ${fieldType}, [key, value]: [string, ${mapInfo.valueType}]) => {
2419
+ if (value !== undefined) {
2420
+ acc[${i}] = ${readSnippet("value")};
2421
+ }
2422
+ return acc;
2423
+ },
2424
+ {},
2425
+ );
2419
2426
  `);
2420
2427
  }
2421
2428
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.9.0",
3
+ "version": "2.10.1",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",
@@ -70,7 +70,7 @@
70
70
  "uglify-js": "^3.17.4"
71
71
  },
72
72
  "dependencies": {
73
- "@bufbuild/protobuf": "^2.0.0",
73
+ "@bufbuild/protobuf": "^2.10.2",
74
74
  "case-anything": "^2.1.13",
75
75
  "ts-poet": "^6.12.0",
76
76
  "ts-proto-descriptors": "2.1.0"