ts-proto 1.83.2 → 1.83.3
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 +7 -0
- package/build/main.js +17 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.83.3](https://github.com/stephenh/ts-proto/compare/v1.83.2...v1.83.3) (2021-10-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* fix codegen for maps with wrapper value type ([#370](https://github.com/stephenh/ts-proto/issues/370)) ([dd2481d](https://github.com/stephenh/ts-proto/commit/dd2481df0835faafc561aad4a4d0c9c2ff9d868a))
|
|
7
|
+
|
|
1
8
|
## [1.83.2](https://github.com/stephenh/ts-proto/compare/v1.83.1...v1.83.2) (2021-10-26)
|
|
2
9
|
|
|
3
10
|
|
package/build/main.js
CHANGED
|
@@ -632,10 +632,18 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
632
632
|
}
|
|
633
633
|
if (types_1.isRepeated(field)) {
|
|
634
634
|
if (types_1.isMapType(ctx, messageDesc, field)) {
|
|
635
|
+
const valueType = typeMap.get(field.typeName)[2].field[1];
|
|
635
636
|
const maybeTypeField = options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : '';
|
|
637
|
+
const entryWriteSnippet = types_1.isValueType(ctx, valueType)
|
|
638
|
+
? ts_poet_1.code `
|
|
639
|
+
if (value !== undefined) {
|
|
640
|
+
${writeSnippet(`{ ${maybeTypeField} key: key as any, value }`)};
|
|
641
|
+
}
|
|
642
|
+
`
|
|
643
|
+
: writeSnippet(`{ ${maybeTypeField} key: key as any, value }`);
|
|
636
644
|
chunks.push(ts_poet_1.code `
|
|
637
645
|
Object.entries(message.${fieldName}).forEach(([key, value]) => {
|
|
638
|
-
${
|
|
646
|
+
${entryWriteSnippet}
|
|
639
647
|
});
|
|
640
648
|
`);
|
|
641
649
|
}
|
|
@@ -814,6 +822,10 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
814
822
|
(options.useDate === options_1.DateOption.DATE || options.useDate === options_1.DateOption.TIMESTAMP)) {
|
|
815
823
|
return ts_poet_1.code `${utils.fromJsonTimestamp}(${from})`;
|
|
816
824
|
}
|
|
825
|
+
else if (types_1.isValueType(ctx, valueType)) {
|
|
826
|
+
const type = types_1.basicTypeName(ctx, valueType);
|
|
827
|
+
return ts_poet_1.code `${from} as ${type}`;
|
|
828
|
+
}
|
|
817
829
|
else {
|
|
818
830
|
const type = types_1.basicTypeName(ctx, valueType);
|
|
819
831
|
return ts_poet_1.code `${type}.fromJSON(${from})`;
|
|
@@ -917,7 +929,7 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
917
929
|
else if (types_1.isTimestamp(valueType) && options.useDate === options_1.DateOption.TIMESTAMP) {
|
|
918
930
|
return ts_poet_1.code `${utils.fromTimestamp}(${from}).toISOString()`;
|
|
919
931
|
}
|
|
920
|
-
else if (types_1.isScalar(valueType)) {
|
|
932
|
+
else if (types_1.isScalar(valueType) || types_1.isValueType(ctx, valueType)) {
|
|
921
933
|
return ts_poet_1.code `${from}`;
|
|
922
934
|
}
|
|
923
935
|
else {
|
|
@@ -1024,6 +1036,9 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1024
1036
|
(options.useDate === options_1.DateOption.DATE || options.useDate === options_1.DateOption.STRING)) {
|
|
1025
1037
|
return ts_poet_1.code `${from}`;
|
|
1026
1038
|
}
|
|
1039
|
+
else if (types_1.isValueType(ctx, valueType)) {
|
|
1040
|
+
return ts_poet_1.code `${from}`;
|
|
1041
|
+
}
|
|
1027
1042
|
else {
|
|
1028
1043
|
const type = types_1.basicTypeName(ctx, valueType);
|
|
1029
1044
|
return ts_poet_1.code `${type}.fromPartial(${from})`;
|