ts-proto 1.110.1 → 1.110.4

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.4](https://github.com/stephenh/ts-proto/compare/v1.110.3...v1.110.4) (2022-04-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Use Uint8Array.forEach in base64FromBytes ([#544](https://github.com/stephenh/ts-proto/issues/544)) ([c7641ce](https://github.com/stephenh/ts-proto/commit/c7641ceb6a1c9da234245b9d808b2ded899dbbbc))
7
+
8
+ ## [1.110.3](https://github.com/stephenh/ts-proto/compare/v1.110.2...v1.110.3) (2022-04-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * 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))
14
+
15
+ ## [1.110.2](https://github.com/stephenh/ts-proto/compare/v1.110.1...v1.110.2) (2022-03-27)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **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))
21
+
1
22
  ## [1.110.1](https://github.com/stephenh/ts-proto/compare/v1.110.0...v1.110.1) (2022-03-25)
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 `}\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') {
@@ -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
- 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
  }
@@ -288,9 +290,9 @@ function makeByteUtils() {
288
290
  const btoa : (bin: string) => string = ${globalThis}.btoa || ((bin) => ${globalThis}.Buffer.from(bin, 'binary').toString('base64'));
289
291
  function base64FromBytes(arr: Uint8Array): string {
290
292
  const bin: string[] = [];
291
- for (const byte of arr) {
293
+ arr.forEach((byte) => {
292
294
  bin.push(String.fromCharCode(byte));
293
- }
295
+ });
294
296
  return btoa(bin.join(''));
295
297
  }
296
298
  `);
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, { keepValueType: true });
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.1",
3
+ "version": "1.110.4",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",