ts-proto 1.109.0 → 1.110.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 +2 -0
- package/build/generate-services.js +4 -0
- package/build/main.js +26 -28
- package/build/options.js +2 -6
- package/build/types.js +4 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.110.1](https://github.com/stephenh/ts-proto/compare/v1.110.0...v1.110.1) (2022-03-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Use a module star import for protobuf types. ([#540](https://github.com/stephenh/ts-proto/issues/540)) ([f5b7700](https://github.com/stephenh/ts-proto/commit/f5b770083dffe72338beb4a09432a2a917760eae))
|
|
7
|
+
|
|
8
|
+
# [1.110.0](https://github.com/stephenh/ts-proto/compare/v1.109.1...v1.110.0) (2022-03-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* Add generic metadata parameter to the generic service definition interface. ([#530](https://github.com/stephenh/ts-proto/issues/530)) ([0f5525a](https://github.com/stephenh/ts-proto/commit/0f5525ade80e7b69889dfd091a458e21bb14a265))
|
|
14
|
+
|
|
15
|
+
## [1.109.1](https://github.com/stephenh/ts-proto/compare/v1.109.0...v1.109.1) (2022-03-13)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* 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))
|
|
21
|
+
|
|
1
22
|
# [1.109.0](https://github.com/stephenh/ts-proto/compare/v1.108.0...v1.109.0) (2022-03-13)
|
|
2
23
|
|
|
3
24
|
|
package/README.markdown
CHANGED
|
@@ -362,6 +362,8 @@ Generated code will be placed in the Gradle build directory.
|
|
|
362
362
|
|
|
363
363
|
- With `--ts_proto_opt=outputServices=generic-definitions`, ts-proto will output generic (framework-agnostic) service definitions. These definitions contain descriptors for each method with links to request and response types, which allows to generate server and client stubs at runtime, and also generate strong types for them at compile time. An example of a library that uses this approach is [nice-grpc](https://github.com/deeplay-io/nice-grpc).
|
|
364
364
|
|
|
365
|
+
- With `--ts_proto_opt=metadataType=Foo@./some-file`, ts-proto add a generic (framework-agnostic) metadata field to the generic service definition.
|
|
366
|
+
|
|
365
367
|
- With `--ts_proto_opt=outputServices=generic-definitions,outputServices=default`, ts-proto will output both generic definitions and interfaces. This is useful if you want to rely on the interfaces, but also have some reflection capabilities at runtime.
|
|
366
368
|
|
|
367
369
|
- With `--ts_proto_opt=outputServices=false`, or `=none`, ts-proto will output NO service definitions.
|
|
@@ -52,6 +52,10 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
52
52
|
const q = options.addNestjsRestParameter ? '' : '?';
|
|
53
53
|
params.push(ts_poet_1.code `metadata${q}: ${Metadata}`);
|
|
54
54
|
}
|
|
55
|
+
else if (options.metadataType) {
|
|
56
|
+
const Metadata = ts_poet_1.imp(options.metadataType);
|
|
57
|
+
params.push(ts_poet_1.code `metadata?: ${Metadata}`);
|
|
58
|
+
}
|
|
55
59
|
if (options.addNestjsRestParameter) {
|
|
56
60
|
params.push(ts_poet_1.code `...rest: any`);
|
|
57
61
|
}
|
package/build/main.js
CHANGED
|
@@ -974,10 +974,10 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
974
974
|
}
|
|
975
975
|
else if (types_1.isMessage(field)) {
|
|
976
976
|
if (types_1.isRepeated(field) && types_1.isMapType(ctx, messageDesc, field)) {
|
|
977
|
-
const valueType =
|
|
978
|
-
if (types_1.isPrimitive(
|
|
977
|
+
const { valueField, valueType } = types_1.detectMapType(ctx, messageDesc, field);
|
|
978
|
+
if (types_1.isPrimitive(valueField)) {
|
|
979
979
|
// TODO Can we not copy/paste this from ^?
|
|
980
|
-
if (types_1.isBytes(
|
|
980
|
+
if (types_1.isBytes(valueField)) {
|
|
981
981
|
if (options.env === options_1.EnvOption.NODE) {
|
|
982
982
|
return ts_poet_1.code `Buffer.from(${utils.bytesFromBase64}(${from} as string))`;
|
|
983
983
|
}
|
|
@@ -985,37 +985,35 @@ function generateFromJson(ctx, fullName, fullTypeName, messageDesc) {
|
|
|
985
985
|
return ts_poet_1.code `${utils.bytesFromBase64}(${from} as string)`;
|
|
986
986
|
}
|
|
987
987
|
}
|
|
988
|
-
else if (types_1.isLong(
|
|
988
|
+
else if (types_1.isLong(valueField) && options.forceLong === options_1.LongOption.LONG) {
|
|
989
989
|
return ts_poet_1.code `Long.fromValue(${from} as Long | string)`;
|
|
990
990
|
}
|
|
991
|
-
else if (types_1.isEnum(
|
|
992
|
-
return ts_poet_1.code `${from} as
|
|
991
|
+
else if (types_1.isEnum(valueField)) {
|
|
992
|
+
return ts_poet_1.code `${from} as ${valueType}`;
|
|
993
993
|
}
|
|
994
994
|
else {
|
|
995
|
-
const cstr = case_1.capitalize(
|
|
995
|
+
const cstr = case_1.capitalize(valueType.toCodeString());
|
|
996
996
|
return ts_poet_1.code `${cstr}(${from})`;
|
|
997
997
|
}
|
|
998
998
|
}
|
|
999
|
-
else if (types_1.isObjectId(
|
|
999
|
+
else if (types_1.isObjectId(valueField) && options.useMongoObjectId) {
|
|
1000
1000
|
return ts_poet_1.code `${utils.fromJsonObjectId}(${from})`;
|
|
1001
1001
|
}
|
|
1002
|
-
else if (types_1.isTimestamp(
|
|
1002
|
+
else if (types_1.isTimestamp(valueField) && options.useDate === options_1.DateOption.STRING) {
|
|
1003
1003
|
return ts_poet_1.code `String(${from})`;
|
|
1004
1004
|
}
|
|
1005
|
-
else if (types_1.isTimestamp(
|
|
1005
|
+
else if (types_1.isTimestamp(valueField) &&
|
|
1006
1006
|
(options.useDate === options_1.DateOption.DATE || options.useDate === options_1.DateOption.TIMESTAMP)) {
|
|
1007
1007
|
return ts_poet_1.code `${utils.fromJsonTimestamp}(${from})`;
|
|
1008
1008
|
}
|
|
1009
|
-
else if (types_1.isValueType(ctx,
|
|
1010
|
-
|
|
1011
|
-
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}`;
|
|
1012
1011
|
}
|
|
1013
|
-
else if (types_1.isAnyValueType(
|
|
1012
|
+
else if (types_1.isAnyValueType(valueField)) {
|
|
1014
1013
|
return ts_poet_1.code `${from}`;
|
|
1015
1014
|
}
|
|
1016
1015
|
else {
|
|
1017
|
-
|
|
1018
|
-
return ts_poet_1.code `${type}.fromJSON(${from})`;
|
|
1016
|
+
return ts_poet_1.code `${valueType}.fromJSON(${from})`;
|
|
1019
1017
|
}
|
|
1020
1018
|
}
|
|
1021
1019
|
else {
|
|
@@ -1293,37 +1291,37 @@ function generateFromPartial(ctx, fullName, messageDesc) {
|
|
|
1293
1291
|
}
|
|
1294
1292
|
else if (types_1.isMessage(field)) {
|
|
1295
1293
|
if (types_1.isRepeated(field) && types_1.isMapType(ctx, messageDesc, field)) {
|
|
1296
|
-
const valueType =
|
|
1297
|
-
if (types_1.isPrimitive(
|
|
1298
|
-
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)) {
|
|
1299
1297
|
return ts_poet_1.code `${from}`;
|
|
1300
1298
|
}
|
|
1301
|
-
else if (types_1.isEnum(
|
|
1302
|
-
return ts_poet_1.code `${from} as
|
|
1299
|
+
else if (types_1.isEnum(valueField)) {
|
|
1300
|
+
return ts_poet_1.code `${from} as ${valueType}`;
|
|
1303
1301
|
}
|
|
1304
|
-
else if (types_1.isLong(
|
|
1302
|
+
else if (types_1.isLong(valueField) && options.forceLong === options_1.LongOption.LONG) {
|
|
1305
1303
|
return ts_poet_1.code `Long.fromValue(${from})`;
|
|
1306
1304
|
}
|
|
1307
1305
|
else {
|
|
1308
|
-
const cstr = case_1.capitalize(
|
|
1306
|
+
const cstr = case_1.capitalize(valueType.toCodeString());
|
|
1309
1307
|
return ts_poet_1.code `${cstr}(${from})`;
|
|
1310
1308
|
}
|
|
1311
1309
|
}
|
|
1312
|
-
else if (types_1.isAnyValueType(
|
|
1310
|
+
else if (types_1.isAnyValueType(valueField)) {
|
|
1313
1311
|
return ts_poet_1.code `${from}`;
|
|
1314
1312
|
}
|
|
1315
|
-
else if (types_1.isObjectId(
|
|
1313
|
+
else if (types_1.isObjectId(valueField) && options.useMongoObjectId) {
|
|
1316
1314
|
return ts_poet_1.code `${from} as mongodb.ObjectId`;
|
|
1317
1315
|
}
|
|
1318
|
-
else if (types_1.isTimestamp(
|
|
1316
|
+
else if (types_1.isTimestamp(valueField) &&
|
|
1319
1317
|
(options.useDate === options_1.DateOption.DATE || options.useDate === options_1.DateOption.STRING)) {
|
|
1320
1318
|
return ts_poet_1.code `${from}`;
|
|
1321
1319
|
}
|
|
1322
|
-
else if (types_1.isValueType(ctx,
|
|
1320
|
+
else if (types_1.isValueType(ctx, valueField)) {
|
|
1323
1321
|
return ts_poet_1.code `${from}`;
|
|
1324
1322
|
}
|
|
1325
1323
|
else {
|
|
1326
|
-
const type = types_1.basicTypeName(ctx,
|
|
1324
|
+
const type = types_1.basicTypeName(ctx, valueField);
|
|
1327
1325
|
return ts_poet_1.code `${type}.fromPartial(${from})`;
|
|
1328
1326
|
}
|
|
1329
1327
|
}
|
package/build/options.js
CHANGED
|
@@ -54,6 +54,7 @@ function defaultOptions() {
|
|
|
54
54
|
outputServices: [],
|
|
55
55
|
returnObservable: false,
|
|
56
56
|
addGrpcMetadata: false,
|
|
57
|
+
metadataType: undefined,
|
|
57
58
|
addNestjsRestParameter: false,
|
|
58
59
|
nestJs: false,
|
|
59
60
|
env: EnvOption.BOTH,
|
|
@@ -140,11 +141,6 @@ function parseParameter(parameter) {
|
|
|
140
141
|
return options;
|
|
141
142
|
}
|
|
142
143
|
function getTsPoetOpts(options) {
|
|
143
|
-
|
|
144
|
-
return { forceDefaultImport: ['protobufjs/minimal'] };
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
return {};
|
|
148
|
-
}
|
|
144
|
+
return { forceModuleImport: ['protobufjs/minimal'] };
|
|
149
145
|
}
|
|
150
146
|
exports.getTsPoetOpts = getTsPoetOpts;
|
package/build/types.js
CHANGED
|
@@ -588,10 +588,11 @@ function detectMapType(ctx, messageDesc, fieldDesc) {
|
|
|
588
588
|
const mapType = typeMap.get(fieldDesc.typeName)[2];
|
|
589
589
|
if (!((_a = mapType.options) === null || _a === void 0 ? void 0 : _a.mapEntry))
|
|
590
590
|
return undefined;
|
|
591
|
-
const
|
|
591
|
+
const [keyField, valueField] = mapType.field;
|
|
592
|
+
const keyType = toTypeName(ctx, messageDesc, keyField);
|
|
592
593
|
// use basicTypeName because we don't need the '| undefined'
|
|
593
|
-
const valueType = basicTypeName(ctx,
|
|
594
|
-
return { messageDesc: mapType, keyType, valueType };
|
|
594
|
+
const valueType = basicTypeName(ctx, valueField);
|
|
595
|
+
return { messageDesc: mapType, keyField, keyType, valueField, valueType };
|
|
595
596
|
}
|
|
596
597
|
return undefined;
|
|
597
598
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.110.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/plugin.js",
|
|
6
6
|
"repository": "github:stephenh/ts-proto",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"dataloader": "^1.4.0",
|
|
65
65
|
"object-hash": "^1.3.1",
|
|
66
66
|
"protobufjs": "^6.8.8",
|
|
67
|
-
"ts-poet": "^4.
|
|
67
|
+
"ts-poet": "^4.11.0",
|
|
68
68
|
"ts-proto-descriptors": "1.6.0"
|
|
69
69
|
}
|
|
70
70
|
}
|