ts-proto 1.88.0 → 1.89.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.89.0](https://github.com/stephenh/ts-proto/compare/v1.88.0...v1.89.0) (2021-11-24)
2
+
3
+
4
+ ### Features
5
+
6
+ * Improve map reading (fromJSON/fromPartial) ([#410](https://github.com/stephenh/ts-proto/issues/410)) ([057d438](https://github.com/stephenh/ts-proto/commit/057d438548d95c354331f7d2d767ccff952ad5c6))
7
+
1
8
  # [1.88.0](https://github.com/stephenh/ts-proto/compare/v1.87.1...v1.88.0) (2021-11-22)
2
9
 
3
10
 
package/build/main.js CHANGED
@@ -919,15 +919,14 @@ function generateFromJson(ctx, fullName, messageDesc) {
919
919
  // and then use the snippet to handle repeated fields if necessary
920
920
  if (types_1.isRepeated(field)) {
921
921
  if (types_1.isMapType(ctx, messageDesc, field)) {
922
- chunks.push(ts_poet_1.code `message.${fieldName} = {};`);
923
- chunks.push(ts_poet_1.code `if (object.${fieldName} !== undefined && object.${fieldName} !== null) {`);
922
+ const fieldType = types_1.toTypeName(ctx, messageDesc, field);
924
923
  const i = maybeCastToNumber(ctx, messageDesc, field, 'key');
925
924
  chunks.push(ts_poet_1.code `
926
- Object.entries(object.${fieldName}).forEach(([key, value]) => {
927
- message.${fieldName}[${i}] = ${readSnippet('value')};
928
- });
925
+ message.${fieldName} = Object.entries(object.${fieldName} ?? {}).reduce<${fieldType}>((acc, [key, value]) => {
926
+ acc[${i}] = ${readSnippet('value')};
927
+ return acc;
928
+ }, {});
929
929
  `);
930
- chunks.push(ts_poet_1.code `}`);
931
930
  }
932
931
  else if (types_1.isAnyValueType(field)) {
933
932
  chunks.push(ts_poet_1.code `
@@ -1164,17 +1163,16 @@ function generateFromPartial(ctx, fullName, messageDesc) {
1164
1163
  // and then use the snippet to handle repeated fields if necessary
1165
1164
  if (types_1.isRepeated(field)) {
1166
1165
  if (types_1.isMapType(ctx, messageDesc, field)) {
1167
- chunks.push(ts_poet_1.code `message.${fieldName} = {};`);
1168
- chunks.push(ts_poet_1.code `if (object.${fieldName} !== undefined && object.${fieldName} !== null) {`);
1166
+ const fieldType = types_1.toTypeName(ctx, messageDesc, field);
1169
1167
  const i = maybeCastToNumber(ctx, messageDesc, field, 'key');
1170
1168
  chunks.push(ts_poet_1.code `
1171
- Object.entries(object.${fieldName}).forEach(([key, value]) => {
1169
+ message.${fieldName} = Object.entries(object.${fieldName} ?? {}).reduce<${fieldType}>((acc, [key, value]) => {
1172
1170
  if (value !== undefined) {
1173
- message.${fieldName}[${i}] = ${readSnippet('value')};
1171
+ acc[${i}] = ${readSnippet('value')};
1174
1172
  }
1175
- });
1173
+ return acc;
1174
+ }, {});
1176
1175
  `);
1177
- chunks.push(ts_poet_1.code `}`);
1178
1176
  }
1179
1177
  else {
1180
1178
  chunks.push(ts_poet_1.code `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.88.0",
3
+ "version": "1.89.0",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",
@@ -25,9 +25,9 @@
25
25
  "@grpc/proto-loader": "^0.5.6",
26
26
  "@improbable-eng/grpc-web": "^0.14.0",
27
27
  "@improbable-eng/grpc-web-node-http-transport": "^0.14.0",
28
- "@nestjs/common": "^7.6.15",
29
- "@nestjs/core": "^7.6.15",
30
- "@nestjs/microservices": "^7.6.15",
28
+ "@nestjs/common": "^8.2.2",
29
+ "@nestjs/core": "^8.2.2",
30
+ "@nestjs/microservices": "^8.2.2",
31
31
  "@semantic-release/changelog": "^5.0.1",
32
32
  "@semantic-release/commit-analyzer": "^8.0.1",
33
33
  "@semantic-release/git": "^9.0.0",
@@ -36,11 +36,10 @@
36
36
  "@semantic-release/release-notes-generator": "^9.0.2",
37
37
  "@types/jest": "^26.0.22",
38
38
  "@types/node": "^14.14.37",
39
- "grpc": "^1.24.6",
40
39
  "jest": "^26.6.3",
41
40
  "prettier": "^2.2.1",
42
41
  "reflect-metadata": "^0.1.13",
43
- "rxjs": "^6.6.7",
42
+ "rxjs": "^7.4.0",
44
43
  "semantic-release": "^17.4.2",
45
44
  "ts-jest": "^26.5.4",
46
45
  "ts-node": "^9.1.1",