ts-proto 1.110.0 → 1.110.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 +21 -0
- package/build/generate-grpc-web.js +16 -7
- package/build/generate-services.js +7 -5
- package/build/main.js +3 -1
- package/build/options.js +1 -6
- package/build/types.js +6 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.110.3](https://github.com/stephenh/ts-proto/compare/v1.110.2...v1.110.3) (2022-04-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* regression in being able to return a Date as a GRPC return value ([#534](https://github.com/stephenh/ts-proto/issues/534)) ([22b76ec](https://github.com/stephenh/ts-proto/commit/22b76eccfc0d26309aab9e454de31ef020595be8))
|
|
7
|
+
|
|
8
|
+
## [1.110.2](https://github.com/stephenh/ts-proto/compare/v1.110.1...v1.110.2) (2022-03-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **Grpc-Web:** Fix compilation failure when a service definition contains a client streaming call. ([#535](https://github.com/stephenh/ts-proto/issues/535)) ([0c83892](https://github.com/stephenh/ts-proto/commit/0c83892693d5755c9fe848b442b5e666192103ab))
|
|
14
|
+
|
|
15
|
+
## [1.110.1](https://github.com/stephenh/ts-proto/compare/v1.110.0...v1.110.1) (2022-03-25)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* 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))
|
|
21
|
+
|
|
1
22
|
# [1.110.0](https://github.com/stephenh/ts-proto/compare/v1.109.1...v1.110.0) (2022-03-15)
|
|
2
23
|
|
|
3
24
|
|
|
@@ -28,31 +28,40 @@ function generateGrpcClientImpl(ctx, fileDesc, serviceDesc) {
|
|
|
28
28
|
utils_1.assertInstanceOf(methodDesc, utils_1.FormattedMethodDescriptor);
|
|
29
29
|
chunks.push(ts_poet_1.code `this.${methodDesc.formattedName} = this.${methodDesc.formattedName}.bind(this);`);
|
|
30
30
|
}
|
|
31
|
-
chunks.push(ts_poet_1.code `}
|
|
31
|
+
chunks.push(ts_poet_1.code `}`);
|
|
32
32
|
// Create a method for each FooService method
|
|
33
33
|
for (const methodDesc of serviceDesc.method) {
|
|
34
34
|
chunks.push(generateRpcMethod(ctx, serviceDesc, methodDesc));
|
|
35
35
|
}
|
|
36
36
|
chunks.push(ts_poet_1.code `}`);
|
|
37
|
-
return ts_poet_1.joinCode(chunks, { trim: false });
|
|
37
|
+
return ts_poet_1.joinCode(chunks, { trim: false, on: '\n' });
|
|
38
38
|
}
|
|
39
39
|
exports.generateGrpcClientImpl = generateGrpcClientImpl;
|
|
40
40
|
/** Creates the RPC methods that client code actually calls. */
|
|
41
41
|
function generateRpcMethod(ctx, serviceDesc, methodDesc) {
|
|
42
42
|
utils_1.assertInstanceOf(methodDesc, utils_1.FormattedMethodDescriptor);
|
|
43
|
-
const
|
|
44
|
-
const inputType = types_1.requestType(ctx, methodDesc);
|
|
45
|
-
const partialInputType = ts_poet_1.code `${utils.DeepPartial}<${inputType}>`;
|
|
43
|
+
const requestMessage = types_1.rawRequestType(ctx, methodDesc);
|
|
44
|
+
const inputType = types_1.requestType(ctx, methodDesc, true);
|
|
46
45
|
const returns = types_1.responsePromiseOrObservable(ctx, methodDesc);
|
|
46
|
+
if (methodDesc.clientStreaming) {
|
|
47
|
+
return ts_poet_1.code `
|
|
48
|
+
${methodDesc.formattedName}(
|
|
49
|
+
request: ${inputType},
|
|
50
|
+
metadata?: grpc.Metadata,
|
|
51
|
+
): ${returns} {
|
|
52
|
+
throw new Error('ts-proto does not yet support client streaming!');
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
}
|
|
47
56
|
const method = methodDesc.serverStreaming ? 'invoke' : 'unary';
|
|
48
57
|
return ts_poet_1.code `
|
|
49
58
|
${methodDesc.formattedName}(
|
|
50
|
-
request: ${
|
|
59
|
+
request: ${inputType},
|
|
51
60
|
metadata?: grpc.Metadata,
|
|
52
61
|
): ${returns} {
|
|
53
62
|
return this.rpc.${method}(
|
|
54
63
|
${methodDescName(serviceDesc, methodDesc)},
|
|
55
|
-
${
|
|
64
|
+
${requestMessage}.fromPartial(request),
|
|
56
65
|
metadata,
|
|
57
66
|
);
|
|
58
67
|
}
|
|
@@ -35,12 +35,10 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
35
35
|
if (options.context) {
|
|
36
36
|
params.push(ts_poet_1.code `ctx: Context`);
|
|
37
37
|
}
|
|
38
|
-
let inputType = types_1.requestType(ctx, methodDesc);
|
|
39
38
|
// the grpc-web clients auto-`fromPartial` the input before handing off to grpc-web's
|
|
40
39
|
// serde runtime, so it's okay to accept partial results from the client
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
40
|
+
const partialInput = options.outputClientImpl === 'grpc-web';
|
|
41
|
+
const inputType = types_1.requestType(ctx, methodDesc, partialInput);
|
|
44
42
|
params.push(ts_poet_1.code `request: ${inputType}`);
|
|
45
43
|
// Use metadata as last argument for interface only configuration
|
|
46
44
|
if (options.outputClientImpl === 'grpc-web') {
|
|
@@ -77,15 +75,19 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
|
|
|
77
75
|
exports.generateService = generateService;
|
|
78
76
|
function generateRegularRpcMethod(ctx, fileDesc, serviceDesc, methodDesc) {
|
|
79
77
|
utils_1.assertInstanceOf(methodDesc, utils_1.FormattedMethodDescriptor);
|
|
80
|
-
const { options } = ctx;
|
|
78
|
+
const { options, utils } = ctx;
|
|
81
79
|
const Reader = ts_poet_1.imp('Reader@protobufjs/minimal');
|
|
82
80
|
const rawInputType = types_1.rawRequestType(ctx, methodDesc);
|
|
83
81
|
const inputType = types_1.requestType(ctx, methodDesc);
|
|
84
82
|
const outputType = types_1.responseType(ctx, methodDesc);
|
|
83
|
+
const rawOutputType = types_1.responseType(ctx, methodDesc, { keepValueType: true });
|
|
85
84
|
const params = [...(options.context ? [ts_poet_1.code `ctx: Context`] : []), ts_poet_1.code `request: ${inputType}`];
|
|
86
85
|
const maybeCtx = options.context ? 'ctx,' : '';
|
|
87
86
|
let encode = ts_poet_1.code `${rawInputType}.encode(request).finish()`;
|
|
88
87
|
let decode = ts_poet_1.code `data => ${outputType}.decode(new ${Reader}(data))`;
|
|
88
|
+
if (options.useDate && rawOutputType.toString().includes('Timestamp')) {
|
|
89
|
+
decode = ts_poet_1.code `data => ${utils.fromTimestamp}(${rawOutputType}.decode(new ${Reader}(data)))`;
|
|
90
|
+
}
|
|
89
91
|
if (methodDesc.clientStreaming) {
|
|
90
92
|
encode = ts_poet_1.code `request.pipe(${ts_poet_1.imp('map@rxjs/operators')}(request => ${encode}))`;
|
|
91
93
|
}
|
package/build/main.js
CHANGED
|
@@ -138,7 +138,9 @@ function generateFile(ctx, fileDesc) {
|
|
|
138
138
|
chunks.push(generate_grpc_web_1.generateGrpcClientImpl(ctx, fileDesc, serviceDesc));
|
|
139
139
|
chunks.push(generate_grpc_web_1.generateGrpcServiceDesc(fileDesc, serviceDesc));
|
|
140
140
|
serviceDesc.method.forEach((method) => {
|
|
141
|
-
|
|
141
|
+
if (!method.clientStreaming) {
|
|
142
|
+
chunks.push(generate_grpc_web_1.generateGrpcMethodDesc(ctx, serviceDesc, method));
|
|
143
|
+
}
|
|
142
144
|
if (method.serverStreaming) {
|
|
143
145
|
hasServerStreamingMethods = true;
|
|
144
146
|
}
|
package/build/options.js
CHANGED
|
@@ -141,11 +141,6 @@ function parseParameter(parameter) {
|
|
|
141
141
|
return options;
|
|
142
142
|
}
|
|
143
143
|
function getTsPoetOpts(options) {
|
|
144
|
-
|
|
145
|
-
return { forceDefaultImport: ['protobufjs/minimal'] };
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
return {};
|
|
149
|
-
}
|
|
144
|
+
return { forceModuleImport: ['protobufjs/minimal'] };
|
|
150
145
|
}
|
|
151
146
|
exports.getTsPoetOpts = getTsPoetOpts;
|
package/build/types.js
CHANGED
|
@@ -601,16 +601,19 @@ function rawRequestType(ctx, methodDesc) {
|
|
|
601
601
|
return messageToTypeName(ctx, methodDesc.inputType);
|
|
602
602
|
}
|
|
603
603
|
exports.rawRequestType = rawRequestType;
|
|
604
|
-
function requestType(ctx, methodDesc) {
|
|
604
|
+
function requestType(ctx, methodDesc, partial = false) {
|
|
605
605
|
let typeName = rawRequestType(ctx, methodDesc);
|
|
606
|
+
if (partial) {
|
|
607
|
+
typeName = ts_poet_1.code `${ctx.utils.DeepPartial}<${typeName}>`;
|
|
608
|
+
}
|
|
606
609
|
if (methodDesc.clientStreaming) {
|
|
607
610
|
return ts_poet_1.code `${ts_poet_1.imp('Observable@rxjs')}<${typeName}>`;
|
|
608
611
|
}
|
|
609
612
|
return typeName;
|
|
610
613
|
}
|
|
611
614
|
exports.requestType = requestType;
|
|
612
|
-
function responseType(ctx, methodDesc) {
|
|
613
|
-
return messageToTypeName(ctx, methodDesc.outputType,
|
|
615
|
+
function responseType(ctx, methodDesc, typeOptions = {}) {
|
|
616
|
+
return messageToTypeName(ctx, methodDesc.outputType, typeOptions);
|
|
614
617
|
}
|
|
615
618
|
exports.responseType = responseType;
|
|
616
619
|
function responsePromise(ctx, methodDesc) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-proto",
|
|
3
|
-
"version": "1.110.
|
|
3
|
+
"version": "1.110.3",
|
|
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
|
}
|