ts-proto 1.109.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 CHANGED
@@ -1,3 +1,24 @@
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
+
8
+ ## [1.110.1](https://github.com/stephenh/ts-proto/compare/v1.110.0...v1.110.1) (2022-03-25)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * 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))
14
+
15
+ # [1.110.0](https://github.com/stephenh/ts-proto/compare/v1.109.1...v1.110.0) (2022-03-15)
16
+
17
+
18
+ ### Features
19
+
20
+ * 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))
21
+
1
22
  ## [1.109.1](https://github.com/stephenh/ts-proto/compare/v1.109.0...v1.109.1) (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.
@@ -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 `}\n`);
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 { options, utils } = ctx;
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: ${partialInputType},
59
+ request: ${inputType},
51
60
  metadata?: grpc.Metadata,
52
61
  ): ${returns} {
53
62
  return this.rpc.${method}(
54
63
  ${methodDescName(serviceDesc, methodDesc)},
55
- ${inputType}.fromPartial(request),
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
- if (options.outputClientImpl === 'grpc-web') {
42
- inputType = ts_poet_1.code `${utils.DeepPartial}<${inputType}>`;
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') {
@@ -52,6 +50,10 @@ function generateService(ctx, fileDesc, sourceInfo, serviceDesc) {
52
50
  const q = options.addNestjsRestParameter ? '' : '?';
53
51
  params.push(ts_poet_1.code `metadata${q}: ${Metadata}`);
54
52
  }
53
+ else if (options.metadataType) {
54
+ const Metadata = ts_poet_1.imp(options.metadataType);
55
+ params.push(ts_poet_1.code `metadata?: ${Metadata}`);
56
+ }
55
57
  if (options.addNestjsRestParameter) {
56
58
  params.push(ts_poet_1.code `...rest: any`);
57
59
  }
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
- chunks.push(generate_grpc_web_1.generateGrpcMethodDesc(ctx, serviceDesc, method));
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
@@ -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
- if (options.esModuleInterop) {
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
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.109.1",
3
+ "version": "1.110.2",
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.10.0",
67
+ "ts-poet": "^4.11.0",
68
68
  "ts-proto-descriptors": "1.6.0"
69
69
  }
70
70
  }