ts-proto 1.107.0 → 1.109.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.
- package/CHANGELOG.md +21 -0
- package/README.markdown +13 -18
- package/build/main.js +75 -37
- package/build/types.js +6 -3
- package/build/utils.js +7 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.109.1](https://github.com/stephenh/ts-proto/compare/v1.109.0...v1.109.1) (2022-03-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Type Error when map contains string enums [#382](https://github.com/stephenh/ts-proto/issues/382) ([#529](https://github.com/stephenh/ts-proto/issues/529)) ([c2107b9](https://github.com/stephenh/ts-proto/commit/c2107b96b494a500a4773ac04900a1acd13c507a))
|
|
7
|
+
|
|
8
|
+
# [1.109.0](https://github.com/stephenh/ts-proto/compare/v1.108.0...v1.109.0) (2022-03-13)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* import proto as type import if onlyTypes is set ([25d8e8b](https://github.com/stephenh/ts-proto/commit/25d8e8b9042142f1032feadc8a799b7a01115cc2))
|
|
14
|
+
|
|
15
|
+
# [1.108.0](https://github.com/stephenh/ts-proto/compare/v1.107.0...v1.108.0) (2022-03-07)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* represent field masks as `string[]` ([#525](https://github.com/stephenh/ts-proto/issues/525)) ([903b216](https://github.com/stephenh/ts-proto/commit/903b216238db025e24ec3cfb2d20063aec1a40ed))
|
|
21
|
+
|
|
1
22
|
# [1.107.0](https://github.com/stephenh/ts-proto/compare/v1.106.2...v1.107.0) (2022-03-04)
|
|
2
23
|
|
|
3
24
|
|
package/README.markdown
CHANGED
|
@@ -622,24 +622,19 @@ Their interpretation is defined by the Protobuf specification, and libraries are
|
|
|
622
622
|
|
|
623
623
|
`ts-proto` currently automatically converts these messages to their corresponding native types.
|
|
624
624
|
|
|
625
|
-
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
-
|
|
638
|
-
|
|
639
|
-
* [google.protobuf.Value](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#Value) ⇆ `any | undefined` (i.e. `number | string | boolean | null | array | object`)
|
|
640
|
-
* [google.protobuf.ListValue](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#ListValue) ⇆ `any[]`
|
|
641
|
-
* [google.protobuf.Struct](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#Struct) ⇆ `{ [key: string]: any } | undefined`
|
|
642
|
-
* [google.protobuf.FieldMask](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask) ⇆ `string[]` (only in the JSON, `FieldMask` is still a message)
|
|
625
|
+
* [google.protobuf.BoolValue](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#boolvalue) ⇆ `boolean`
|
|
626
|
+
* [google.protobuf.BytesValue](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#bytesvalue) ⇆ `Uint8Array`
|
|
627
|
+
* [google.protobuf.DoubleValue](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#doublevalue) ⇆ `number`
|
|
628
|
+
* [google.protobuf.FieldMask](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask) ⇆ `string[]`
|
|
629
|
+
* [google.protobuf.FloatValue](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#floatvalue) ⇆ `number`
|
|
630
|
+
* [google.protobuf.Int32Value](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#int32value) ⇆ `number`
|
|
631
|
+
* [google.protobuf.Int64Value](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#int64value) ⇆ `number`
|
|
632
|
+
* [google.protobuf.ListValue](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#listvalue) ⇆ `any[]`
|
|
633
|
+
* [google.protobuf.UInt32Value](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#uint32value) ⇆ `number`
|
|
634
|
+
* [google.protobuf.UInt64Value](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#uint64value) ⇆ `number`
|
|
635
|
+
* [google.protobuf.StringValue](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#stringvalue) ⇆ `string`
|
|
636
|
+
* [google.protobuf.Value](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#value) ⇆ `any` (i.e. `number | string | boolean | null | array | object`)
|
|
637
|
+
* [google.protobuf.Struct](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#struct) ⇆ `{ [key: string]: any }`
|
|
643
638
|
|
|
644
639
|
## Wrapper Types
|
|
645
640
|
|
package/build/main.js
CHANGED
|
@@ -80,8 +80,8 @@ function generateFile(ctx, fileDesc) {
|
|
|
80
80
|
staticMembers.push(generateDecode(ctx, fullName, message));
|
|
81
81
|
}
|
|
82
82
|
if (options.outputJsonMethods) {
|
|
83
|
-
staticMembers.push(generateFromJson(ctx, fullName, message));
|
|
84
|
-
staticMembers.push(generateToJson(ctx, fullName, message));
|
|
83
|
+
staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message));
|
|
84
|
+
staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message));
|
|
85
85
|
}
|
|
86
86
|
if (options.outputPartialMethods) {
|
|
87
87
|
staticMembers.push(generateFromPartial(ctx, fullName, message));
|
|
@@ -604,7 +604,7 @@ function generateDecode(ctx, fullName, messageDesc) {
|
|
|
604
604
|
else if (types_1.isValueType(ctx, field)) {
|
|
605
605
|
const type = types_1.basicTypeName(ctx, field, { keepValueType: true });
|
|
606
606
|
const unwrap = (decodedValue) => {
|
|
607
|
-
if (types_1.isListValueType(field) || types_1.isStructType(field) || types_1.isAnyValueType(field)) {
|
|
607
|
+
if (types_1.isListValueType(field) || types_1.isStructType(field) || types_1.isAnyValueType(field) || types_1.isFieldMaskType(field)) {
|
|
608
608
|
return ts_poet_1.code `${type}.unwrap(${decodedValue})`;
|
|
609
609
|
}
|
|
610
610
|
return ts_poet_1.code `${decodedValue}.value`;
|
|
@@ -729,7 +729,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
729
729
|
const maybeTypeField = options.outputTypeRegistry ? `$type: '${field.typeName.slice(1)}',` : '';
|
|
730
730
|
const type = types_1.basicTypeName(ctx, field, { keepValueType: true });
|
|
731
731
|
const wrappedValue = (place) => {
|
|
732
|
-
if (types_1.isAnyValueType(field) || types_1.isListValueType(field) || types_1.isStructType(field)) {
|
|
732
|
+
if (types_1.isAnyValueType(field) || types_1.isListValueType(field) || types_1.isStructType(field) || types_1.isFieldMaskType(field)) {
|
|
733
733
|
return ts_poet_1.code `${type}.wrap(${place})`;
|
|
734
734
|
}
|
|
735
735
|
return ts_poet_1.code `{${maybeTypeField} value: ${place}!}`;
|
|
@@ -887,7 +887,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
887
887
|
* This is very similar to decode, we loop through looking for properties, with
|
|
888
888
|
* a few special cases for https://developers.google.com/protocol-buffers/docs/proto3#json.
|
|
889
889
|
* */
|
|
890
|
-
function generateFromJson(ctx, fullName, messageDesc) {
|
|
890
|
+
function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
891
891
|
const { options, utils, typeMap } = ctx;
|
|
892
892
|
const chunks = [];
|
|
893
893
|
// create the basic function declaration
|
|
@@ -899,8 +899,18 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
899
899
|
chunks.push(ts_poet_1.code `$type: ${fullName}.$type,`);
|
|
900
900
|
}
|
|
901
901
|
const oneofFieldsCases = messageDesc.oneofDecl.map((oneof, oneofIndex) => messageDesc.field.filter(types_1.isWithinOneOf).filter((field) => field.oneofIndex === oneofIndex));
|
|
902
|
+
const canonicalFromJson = {
|
|
903
|
+
['google.protobuf.FieldMask']: {
|
|
904
|
+
paths: (from) => ts_poet_1.code `typeof(${from}) === 'string'
|
|
905
|
+
? ${from}.split(",").filter(Boolean)
|
|
906
|
+
: Array.isArray(${from}?.paths)
|
|
907
|
+
? ${from}.paths.map(String)
|
|
908
|
+
: []`,
|
|
909
|
+
},
|
|
910
|
+
};
|
|
902
911
|
// add a check for each incoming field
|
|
903
912
|
messageDesc.field.forEach((field) => {
|
|
913
|
+
var _a;
|
|
904
914
|
const fieldName = case_1.maybeSnakeToCamel(field.name, options);
|
|
905
915
|
const jsonName = utils_1.getFieldJsonName(field, options);
|
|
906
916
|
const jsonProperty = utils_1.getPropertyAccessor('object', jsonName);
|
|
@@ -944,7 +954,8 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
944
954
|
return ts_poet_1.code `${from}`;
|
|
945
955
|
}
|
|
946
956
|
else if (types_1.isFieldMaskType(field)) {
|
|
947
|
-
|
|
957
|
+
const type = types_1.basicTypeName(ctx, field, { keepValueType: true });
|
|
958
|
+
return ts_poet_1.code `${type}.unwrap(${type}.fromJSON(${from}))`;
|
|
948
959
|
}
|
|
949
960
|
else if (types_1.isListValueType(field)) {
|
|
950
961
|
return ts_poet_1.code `[...${from}]`;
|
|
@@ -963,10 +974,10 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
963
974
|
}
|
|
964
975
|
else if (types_1.isMessage(field)) {
|
|
965
976
|
if (types_1.isRepeated(field) && types_1.isMapType(ctx, messageDesc, field)) {
|
|
966
|
-
const valueType =
|
|
967
|
-
if (types_1.isPrimitive(
|
|
977
|
+
const { valueField, valueType } = types_1.detectMapType(ctx, messageDesc, field);
|
|
978
|
+
if (types_1.isPrimitive(valueField)) {
|
|
968
979
|
// TODO Can we not copy/paste this from ^?
|
|
969
|
-
if (types_1.isBytes(
|
|
980
|
+
if (types_1.isBytes(valueField)) {
|
|
970
981
|
if (options.env === options_1.EnvOption.NODE) {
|
|
971
982
|
return ts_poet_1.code `Buffer.from(${utils.bytesFromBase64}(${from} as string))`;
|
|
972
983
|
}
|
|
@@ -974,37 +985,35 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
974
985
|
return ts_poet_1.code `${utils.bytesFromBase64}(${from} as string)`;
|
|
975
986
|
}
|
|
976
987
|
}
|
|
977
|
-
else if (types_1.isLong(
|
|
988
|
+
else if (types_1.isLong(valueField) && options.forceLong === options_1.LongOption.LONG) {
|
|
978
989
|
return ts_poet_1.code `Long.fromValue(${from} as Long | string)`;
|
|
979
990
|
}
|
|
980
|
-
else if (types_1.isEnum(
|
|
981
|
-
return ts_poet_1.code `${from} as
|
|
991
|
+
else if (types_1.isEnum(valueField)) {
|
|
992
|
+
return ts_poet_1.code `${from} as ${valueType}`;
|
|
982
993
|
}
|
|
983
994
|
else {
|
|
984
|
-
const cstr = case_1.capitalize(
|
|
995
|
+
const cstr = case_1.capitalize(valueType.toCodeString());
|
|
985
996
|
return ts_poet_1.code `${cstr}(${from})`;
|
|
986
997
|
}
|
|
987
998
|
}
|
|
988
|
-
else if (types_1.isObjectId(
|
|
999
|
+
else if (types_1.isObjectId(valueField) && options.useMongoObjectId) {
|
|
989
1000
|
return ts_poet_1.code `${utils.fromJsonObjectId}(${from})`;
|
|
990
1001
|
}
|
|
991
|
-
else if (types_1.isTimestamp(
|
|
1002
|
+
else if (types_1.isTimestamp(valueField) && options.useDate === options_1.DateOption.STRING) {
|
|
992
1003
|
return ts_poet_1.code `String(${from})`;
|
|
993
1004
|
}
|
|
994
|
-
else if (types_1.isTimestamp(
|
|
1005
|
+
else if (types_1.isTimestamp(valueField) &&
|
|
995
1006
|
(options.useDate === options_1.DateOption.DATE || options.useDate === options_1.DateOption.TIMESTAMP)) {
|
|
996
1007
|
return ts_poet_1.code `${utils.fromJsonTimestamp}(${from})`;
|
|
997
1008
|
}
|
|
998
|
-
else if (types_1.isValueType(ctx,
|
|
999
|
-
|
|
1000
|
-
return ts_poet_1.code `${from} as ${type}`;
|
|
1009
|
+
else if (types_1.isValueType(ctx, valueField)) {
|
|
1010
|
+
return ts_poet_1.code `${from} as ${valueType}`;
|
|
1001
1011
|
}
|
|
1002
|
-
else if (types_1.isAnyValueType(
|
|
1012
|
+
else if (types_1.isAnyValueType(valueField)) {
|
|
1003
1013
|
return ts_poet_1.code `${from}`;
|
|
1004
1014
|
}
|
|
1005
1015
|
else {
|
|
1006
|
-
|
|
1007
|
-
return ts_poet_1.code `${type}.fromJSON(${from})`;
|
|
1016
|
+
return ts_poet_1.code `${valueType}.fromJSON(${from})`;
|
|
1008
1017
|
}
|
|
1009
1018
|
}
|
|
1010
1019
|
else {
|
|
@@ -1017,7 +1026,10 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
1017
1026
|
}
|
|
1018
1027
|
};
|
|
1019
1028
|
// and then use the snippet to handle repeated fields if necessary
|
|
1020
|
-
if (
|
|
1029
|
+
if ((_a = canonicalFromJson[fullTypeName]) === null || _a === void 0 ? void 0 : _a[fieldName]) {
|
|
1030
|
+
chunks.push(ts_poet_1.code `${fieldName}: ${canonicalFromJson[fullTypeName][fieldName]('object')},`);
|
|
1031
|
+
}
|
|
1032
|
+
else if (types_1.isRepeated(field)) {
|
|
1021
1033
|
if (types_1.isMapType(ctx, messageDesc, field)) {
|
|
1022
1034
|
const fieldType = types_1.toTypeName(ctx, messageDesc, field);
|
|
1023
1035
|
const i = maybeCastToNumber(ctx, messageDesc, field, 'key');
|
|
@@ -1090,9 +1102,24 @@ function generateFromJson(ctx, fullName, messageDesc) {
|
|
|
1090
1102
|
chunks.push(ts_poet_1.code `}`);
|
|
1091
1103
|
return ts_poet_1.joinCode(chunks, { on: '\n' });
|
|
1092
1104
|
}
|
|
1093
|
-
function
|
|
1105
|
+
function generateCanonicalToJson(fullName, fullProtobufTypeName) {
|
|
1106
|
+
if (types_1.isFieldMaskTypeName(fullProtobufTypeName)) {
|
|
1107
|
+
return ts_poet_1.code `
|
|
1108
|
+
toJSON(message: ${fullName}): string {
|
|
1109
|
+
return message.paths.join(',');
|
|
1110
|
+
}
|
|
1111
|
+
`;
|
|
1112
|
+
}
|
|
1113
|
+
return undefined;
|
|
1114
|
+
}
|
|
1115
|
+
function generateToJson(ctx, fullName, fullProtobufTypeName, messageDesc) {
|
|
1094
1116
|
const { options, utils, typeMap } = ctx;
|
|
1095
1117
|
const chunks = [];
|
|
1118
|
+
const canonicalToJson = generateCanonicalToJson(fullName, fullProtobufTypeName);
|
|
1119
|
+
if (canonicalToJson) {
|
|
1120
|
+
chunks.push(canonicalToJson);
|
|
1121
|
+
return ts_poet_1.joinCode(chunks, { on: '\n' });
|
|
1122
|
+
}
|
|
1096
1123
|
// create the basic function declaration
|
|
1097
1124
|
chunks.push(ts_poet_1.code `
|
|
1098
1125
|
toJSON(${messageDesc.field.length > 0 ? 'message' : '_'}: ${fullName}): unknown {
|
|
@@ -1165,7 +1192,8 @@ function generateToJson(ctx, fullName, messageDesc) {
|
|
|
1165
1192
|
return ts_poet_1.code `${from}`;
|
|
1166
1193
|
}
|
|
1167
1194
|
else if (types_1.isFieldMaskType(field)) {
|
|
1168
|
-
|
|
1195
|
+
const type = types_1.basicTypeName(ctx, field, { keepValueType: true });
|
|
1196
|
+
return ts_poet_1.code `${type}.toJSON(${type}.wrap(${from}))`;
|
|
1169
1197
|
}
|
|
1170
1198
|
else if (types_1.isMessage(field) && !types_1.isValueType(ctx, field) && !types_1.isMapType(ctx, messageDesc, field)) {
|
|
1171
1199
|
const type = types_1.basicTypeName(ctx, field, { keepValueType: true });
|
|
@@ -1263,37 +1291,37 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1263
1291
|
}
|
|
1264
1292
|
else if (types_1.isMessage(field)) {
|
|
1265
1293
|
if (types_1.isRepeated(field) && types_1.isMapType(ctx, messageDesc, field)) {
|
|
1266
|
-
const valueType =
|
|
1267
|
-
if (types_1.isPrimitive(
|
|
1268
|
-
if (types_1.isBytes(
|
|
1294
|
+
const { valueField, valueType } = types_1.detectMapType(ctx, messageDesc, field);
|
|
1295
|
+
if (types_1.isPrimitive(valueField)) {
|
|
1296
|
+
if (types_1.isBytes(valueField)) {
|
|
1269
1297
|
return ts_poet_1.code `${from}`;
|
|
1270
1298
|
}
|
|
1271
|
-
else if (types_1.isEnum(
|
|
1272
|
-
return ts_poet_1.code `${from} as
|
|
1299
|
+
else if (types_1.isEnum(valueField)) {
|
|
1300
|
+
return ts_poet_1.code `${from} as ${valueType}`;
|
|
1273
1301
|
}
|
|
1274
|
-
else if (types_1.isLong(
|
|
1302
|
+
else if (types_1.isLong(valueField) && options.forceLong === options_1.LongOption.LONG) {
|
|
1275
1303
|
return ts_poet_1.code `Long.fromValue(${from})`;
|
|
1276
1304
|
}
|
|
1277
1305
|
else {
|
|
1278
|
-
const cstr = case_1.capitalize(
|
|
1306
|
+
const cstr = case_1.capitalize(valueType.toCodeString());
|
|
1279
1307
|
return ts_poet_1.code `${cstr}(${from})`;
|
|
1280
1308
|
}
|
|
1281
1309
|
}
|
|
1282
|
-
else if (types_1.isAnyValueType(
|
|
1310
|
+
else if (types_1.isAnyValueType(valueField)) {
|
|
1283
1311
|
return ts_poet_1.code `${from}`;
|
|
1284
1312
|
}
|
|
1285
|
-
else if (types_1.isObjectId(
|
|
1313
|
+
else if (types_1.isObjectId(valueField) && options.useMongoObjectId) {
|
|
1286
1314
|
return ts_poet_1.code `${from} as mongodb.ObjectId`;
|
|
1287
1315
|
}
|
|
1288
|
-
else if (types_1.isTimestamp(
|
|
1316
|
+
else if (types_1.isTimestamp(valueField) &&
|
|
1289
1317
|
(options.useDate === options_1.DateOption.DATE || options.useDate === options_1.DateOption.STRING)) {
|
|
1290
1318
|
return ts_poet_1.code `${from}`;
|
|
1291
1319
|
}
|
|
1292
|
-
else if (types_1.isValueType(ctx,
|
|
1320
|
+
else if (types_1.isValueType(ctx, valueField)) {
|
|
1293
1321
|
return ts_poet_1.code `${from}`;
|
|
1294
1322
|
}
|
|
1295
1323
|
else {
|
|
1296
|
-
const type = types_1.basicTypeName(ctx,
|
|
1324
|
+
const type = types_1.basicTypeName(ctx, valueField);
|
|
1297
1325
|
return ts_poet_1.code `${type}.fromPartial(${from})`;
|
|
1298
1326
|
}
|
|
1299
1327
|
}
|
|
@@ -1431,6 +1459,11 @@ function generateWrap(ctx, fullProtoTypeName) {
|
|
|
1431
1459
|
return result;
|
|
1432
1460
|
}`);
|
|
1433
1461
|
}
|
|
1462
|
+
if (types_1.isFieldMaskTypeName(fullProtoTypeName)) {
|
|
1463
|
+
chunks.push(ts_poet_1.code `wrap(paths: string[]): FieldMask {
|
|
1464
|
+
return {paths: paths};
|
|
1465
|
+
}`);
|
|
1466
|
+
}
|
|
1434
1467
|
return chunks;
|
|
1435
1468
|
}
|
|
1436
1469
|
function generateUnwrap(ctx, fullProtoTypeName) {
|
|
@@ -1488,6 +1521,11 @@ function generateUnwrap(ctx, fullProtoTypeName) {
|
|
|
1488
1521
|
return message.values;
|
|
1489
1522
|
}`);
|
|
1490
1523
|
}
|
|
1524
|
+
if (types_1.isFieldMaskTypeName(fullProtoTypeName)) {
|
|
1525
|
+
chunks.push(ts_poet_1.code `unwrap(message: FieldMask): string[] {
|
|
1526
|
+
return message.paths;
|
|
1527
|
+
}`);
|
|
1528
|
+
}
|
|
1491
1529
|
return chunks;
|
|
1492
1530
|
}
|
|
1493
1531
|
exports.contextTypeVar = 'Context extends DataLoaders';
|
package/build/types.js
CHANGED
|
@@ -458,6 +458,8 @@ function valueTypeName(ctx, typeName) {
|
|
|
458
458
|
return ts_poet_1.code `any`;
|
|
459
459
|
case '.google.protobuf.Struct':
|
|
460
460
|
return ts_poet_1.code `{[key: string]: any}`;
|
|
461
|
+
case '.google.protobuf.FieldMask':
|
|
462
|
+
return ts_poet_1.code `string[]`;
|
|
461
463
|
default:
|
|
462
464
|
return undefined;
|
|
463
465
|
}
|
|
@@ -586,10 +588,11 @@ function detectMapType(ctx, messageDesc, fieldDesc) {
|
|
|
586
588
|
const mapType = typeMap.get(fieldDesc.typeName)[2];
|
|
587
589
|
if (!((_a = mapType.options) === null || _a === void 0 ? void 0 : _a.mapEntry))
|
|
588
590
|
return undefined;
|
|
589
|
-
const
|
|
591
|
+
const [keyField, valueField] = mapType.field;
|
|
592
|
+
const keyType = toTypeName(ctx, messageDesc, keyField);
|
|
590
593
|
// use basicTypeName because we don't need the '| undefined'
|
|
591
|
-
const valueType = basicTypeName(ctx,
|
|
592
|
-
return { messageDesc: mapType, keyType, valueType };
|
|
594
|
+
const valueType = basicTypeName(ctx, valueField);
|
|
595
|
+
return { messageDesc: mapType, keyField, keyType, valueField, valueType };
|
|
593
596
|
}
|
|
594
597
|
return undefined;
|
|
595
598
|
}
|
package/build/utils.js
CHANGED
|
@@ -170,6 +170,12 @@ function getPropertyAccessor(objectName, propertyName, optional = false) {
|
|
|
170
170
|
}
|
|
171
171
|
exports.getPropertyAccessor = getPropertyAccessor;
|
|
172
172
|
function impProto(options, module, type) {
|
|
173
|
-
|
|
173
|
+
const importString = `${type}@./${module}${options.fileSuffix}`;
|
|
174
|
+
if (options.onlyTypes) {
|
|
175
|
+
return ts_poet_1.imp('t:' + importString);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return ts_poet_1.imp(importString);
|
|
179
|
+
}
|
|
174
180
|
}
|
|
175
181
|
exports.impProto = impProto;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.109.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"build": "yarn tsc",
|
|
12
12
|
"build:test": "yarn proto2bin && yarn proto2pbjs && yarn bin2ts",
|
|
13
13
|
"build:test:local": "yarn proto2bin:local && yarn proto2pbjs:local && yarn bin2ts:local",
|
|
14
|
+
"prepare": "yarn build",
|
|
14
15
|
"proto2bin": "docker-compose run --rm protoc update-bins.sh",
|
|
15
16
|
"proto2bin-node": "docker-compose run --rm node update-bins.sh",
|
|
16
17
|
"proto2pbjs": "docker-compose run --rm protoc pbjs.sh",
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
"dataloader": "^1.4.0",
|
|
64
65
|
"object-hash": "^1.3.1",
|
|
65
66
|
"protobufjs": "^6.8.8",
|
|
66
|
-
"ts-poet": "^4.
|
|
67
|
+
"ts-poet": "^4.10.0",
|
|
67
68
|
"ts-proto-descriptors": "1.6.0"
|
|
68
69
|
}
|
|
69
70
|
}
|