ts-proto 2.11.2 → 2.11.5

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
@@ -830,21 +830,19 @@ Instead, we recommend using the `oneof=unions-value` option, which will change t
830
830
 
831
831
  ```typescript
832
832
  interface YourMessage {
833
- eitherField?: { $case: "field_a"; value: string } | { $case: "field_b"; value: string };
833
+ eitherField: { $case: "field_a"; value: string } | { $case: "field_b"; value: string } | undefined;
834
834
  }
835
835
  ```
836
836
 
837
837
  As this will automatically enforce only one of `field_a` or `field_b` "being set" at a time, because the values are stored in the `eitherField` field that can only have a single value at a time.
838
838
 
839
- (Note that `eitherField` is optional b/c `oneof` in Protobuf means "at most one field" is set, and does not mean one of the fields _must_ be set.)
840
-
841
839
  In ts-proto's currently-unscheduled 2.x release, `oneof=unions-value` will become the default behavior.
842
840
 
843
841
  There is also a `oneof=unions` option, which generates a union where the field names are included in each option:
844
842
 
845
843
  ```typescript
846
844
  interface YourMessage {
847
- eitherField?: { $case: "field_a"; field_a: string } | { $case: "field_b"; field_b: string };
845
+ eitherField: { $case: "field_a"; field_a: string } | { $case: "field_b"; field_b: string } | undefined;
848
846
  }
849
847
  ```
850
848
 
@@ -47,9 +47,9 @@ function generateMethodDefinition(ctx, methodDesc) {
47
47
  return (0, ts_poet_1.code) `
48
48
  {
49
49
  name: '${methodDesc.name}',
50
- requestType: ${inputType},
50
+ requestType: ${inputType} as typeof ${inputType},
51
51
  requestStream: ${methodDesc.clientStreaming},
52
- responseType: ${outputType},
52
+ responseType: ${outputType} as typeof ${outputType},
53
53
  responseStream: ${methodDesc.serverStreaming},
54
54
  options: ${generateMethodOptions(ctx, methodDesc.options)}
55
55
  }
@@ -72,7 +72,7 @@ function generateMethodOptions(ctx, options) {
72
72
  const values = options._unknownFields[key];
73
73
  const valuesChunks = [];
74
74
  for (const value of values) {
75
- valuesChunks.push((0, ts_poet_1.code) `${ctx.options.env == "node" ? "Buffer.from" : "new Uint8Array"}([${value.join(", ")}])`);
75
+ valuesChunks.push((0, ts_poet_1.code) `${ctx.options.env == "node" ? "Buffer.from" : "new Uint8Array"}([${value.join(", ")}]) as ${ctx.options.env == "node" ? "Buffer" : "Uint8Array"}`);
76
76
  }
77
77
  unknownFieldsChunks.push((0, ts_poet_1.code) `${key}: [\n${(0, ts_poet_1.joinCode)(valuesChunks, { on: "," })}\n],`);
78
78
  }
@@ -61,9 +61,9 @@ function generateServiceDefinition(ctx, fileDesc, sourceInfo, serviceDesc) {
61
61
  const outputDecoder = (0, encode_1.generateDecoder)(ctx, methodDesc.outputType);
62
62
  chunks.push((0, ts_poet_1.code) `
63
63
  ${methodDesc.formattedName}: {
64
- path: '/${(0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)}/${methodDesc.name}',
65
- requestStream: ${methodDesc.clientStreaming},
66
- responseStream: ${methodDesc.serverStreaming},
64
+ path: '/${(0, utils_1.maybePrefixPackage)(fileDesc, serviceDesc.name)}/${methodDesc.name}' as const,
65
+ requestStream: ${methodDesc.clientStreaming} as const,
66
+ responseStream: ${methodDesc.serverStreaming} as const,
67
67
  requestSerialize: (value: ${inputType}): Buffer =>
68
68
  Buffer.from(${inputEncoder}),
69
69
  requestDeserialize: (value: Buffer): ${inputType} => ${inputDecoder},
@@ -232,7 +232,10 @@ function generateServiceClientImpl(ctx, fileDesc, serviceDesc) {
232
232
  chunks.push(generateBatchingRpcMethod(ctx, batchMethod));
233
233
  }
234
234
  }
235
- if (options.context && methodDesc.name.match(/^Get[A-Z]/)) {
235
+ if (options.context &&
236
+ methodDesc.name.match(/^Get[A-Z]/) &&
237
+ !methodDesc.serverStreaming &&
238
+ !methodDesc.clientStreaming) {
236
239
  chunks.push(generateCachingRpcMethod(ctx, fileDesc, serviceDesc, methodDesc));
237
240
  }
238
241
  else {
package/build/src/main.js CHANGED
@@ -912,7 +912,8 @@ function generateOneofProperty(ctx, messageDesc, oneofIndex, sourceInfo) {
912
912
  return (0, ts_poet_1.code) `|${combinedComments ? " // " : ""}\n ${combinedComments} { ${mbReadonly}$case: '${fieldName}', ${mbReadonly}${valueName}: ${typeName} }`;
913
913
  }));
914
914
  const name = (0, case_1.maybeSnakeToCamel)(messageDesc.oneofDecl[oneofIndex].name, options);
915
- return (0, ts_poet_1.joinCode)([...outerComments, (0, ts_poet_1.code) `${mbReadonly}${name}?:`, unionType, (0, ts_poet_1.code) `| ${(0, utils_1.nullOrUndefined)(options)},`], {
915
+ const optionalFlag = options.useOptionals === "none" ? "" : "?";
916
+ return (0, ts_poet_1.joinCode)([...outerComments, (0, ts_poet_1.code) `${mbReadonly}${name}${optionalFlag}:`, unionType, (0, ts_poet_1.code) `| ${(0, utils_1.nullOrUndefined)(options)},`], {
916
917
  on: "\n",
917
918
  });
918
919
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "2.11.2",
3
+ "version": "2.11.5",
4
4
  "description": "",
5
5
  "main": "build/src/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",