ts-proto 1.110.1 → 1.110.2
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/generate-grpc-web.js +16 -7
- package/build/generate-services.js +2 -4
- package/build/main.js +3 -1
- package/build/types.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.110.2](https://github.com/stephenh/ts-proto/compare/v1.110.1...v1.110.2) (2022-03-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **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))
|
|
7
|
+
|
|
1
8
|
## [1.110.1](https://github.com/stephenh/ts-proto/compare/v1.110.0...v1.110.1) (2022-03-25)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -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') {
|
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/types.js
CHANGED
|
@@ -601,8 +601,11 @@ 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
|
}
|