ts-proto 2.20.0 → 2.21.0

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/README.markdown CHANGED
@@ -481,7 +481,9 @@ With `--ts_proto_opt=protoJsonFormat=false`, strict proto3 compliance is disable
481
481
 
482
482
  - With `--ts_proto_opt=nestJs=true`, the defaults will change to generate [NestJS protobuf](https://docs.nestjs.com/microservices/grpc) friendly types & service interfaces that can be used in both the client-side and server-side of NestJS protobuf implementations. See the [nestjs readme](NESTJS.markdown) for more information and implementation examples.
483
483
 
484
- Specifically `outputEncodeMethods`, `outputJsonMethods`, and `outputClientImpl` will all be false, `lowerCaseServiceMethods` will be true and `outputServices` will be ignored.
484
+ Specifically `outputEncodeMethods`, `outputJsonMethods`, `outputPartialMethods`, and `outputClientImpl` will all be false, `lowerCaseServiceMethods` will be true and `outputServices` will be ignored.
485
+
486
+ If `outputPartialMethods=true` is set as well, the `FooServiceClient` methods will accept `DeepPartial` requests and the `FooServiceController` methods may return `DeepPartial` responses, since any missing fields are received as their default values.
485
487
 
486
488
  Note that `addGrpcMetadata`, `addNestjsRestParameter`, `returnObservable` and `useNestjsFqnServiceName` will still be false.
487
489
 
@@ -34,20 +34,26 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
34
34
  if (options.addNestjsRestParameter) {
35
35
  params.push((0, ts_poet_1.code) `...rest: any`);
36
36
  }
37
+ // NestJS encodes the response with @grpc/proto-loader, which leaves out any missing fields,
38
+ // i.e. the client receives them as their default values, so it's okay to accept partial responses
39
+ let outputType = (0, types_1.responseType)(ctx, methodDesc);
40
+ if (options.outputPartialMethods) {
41
+ outputType = (0, ts_poet_1.code) `${ctx.utils.DeepPartial}<${outputType}>`;
42
+ }
37
43
  // Return observable for interface only configuration, passing returnObservable=true and methodDesc.serverStreaming=true
38
44
  let returns;
39
45
  if ((0, types_1.isEmptyType)(methodDesc.outputType)) {
40
46
  returns = (0, ts_poet_1.code) `void | Promise<void>`;
41
47
  }
42
48
  else if (options.returnObservable || methodDesc.serverStreaming) {
43
- returns = (0, ts_poet_1.code) `${(0, types_1.responseObservable)(ctx, methodDesc)}`;
49
+ returns = (0, ts_poet_1.code) `${(0, types_1.observableType)(ctx)}<${outputType}>`;
44
50
  }
45
51
  else {
46
52
  // generate nestjs union type
47
53
  returns = (0, ts_poet_1.code) `
48
- ${(0, types_1.responsePromise)(ctx, methodDesc)}
49
- | ${(0, types_1.responseObservable)(ctx, methodDesc)}
50
- | ${(0, types_1.responseType)(ctx, methodDesc)}
54
+ Promise<${outputType}>
55
+ | ${(0, types_1.observableType)(ctx)}<${outputType}>
56
+ | ${outputType}
51
57
  `;
52
58
  }
53
59
  chunks.push((0, ts_poet_1.code) `
@@ -84,7 +90,9 @@ function generateNestjsServiceClient(ctx, fileDesc, sourceInfo, serviceDesc) {
84
90
  if (options.context) {
85
91
  params.push((0, ts_poet_1.code) `ctx: Context`);
86
92
  }
87
- params.push((0, ts_poet_1.code) `request: ${(0, types_1.requestType)(ctx, methodDesc)}`);
93
+ // NestJS encodes the request with @grpc/proto-loader, which leaves out any missing fields,
94
+ // i.e. the server receives them as their default values, so it's okay to accept partial requests
95
+ params.push((0, ts_poet_1.code) `request: ${(0, types_1.requestType)(ctx, methodDesc, options.outputPartialMethods)}`);
88
96
  // Use metadata as last argument for interface only configuration
89
97
  if (options.addGrpcMetadata) {
90
98
  const q = options.addNestjsRestParameter ? "" : "?";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.20.0",
3
+ "version": "2.21.0",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",