ts-proto 2.11.1 → 2.11.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/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
|
|
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
|
|
845
|
+
eitherField: { $case: "field_a"; field_a: string } | { $case: "field_b"; field_b: string } | undefined;
|
|
848
846
|
}
|
|
849
847
|
```
|
|
850
848
|
|
|
@@ -37,7 +37,7 @@ function generateNestjsServiceController(ctx, fileDesc, sourceInfo, serviceDesc)
|
|
|
37
37
|
// Return observable for interface only configuration, passing returnObservable=true and methodDesc.serverStreaming=true
|
|
38
38
|
let returns;
|
|
39
39
|
if ((0, types_1.isEmptyType)(methodDesc.outputType)) {
|
|
40
|
-
returns = (0, ts_poet_1.code) `void
|
|
40
|
+
returns = (0, ts_poet_1.code) `void | Promise<void>`;
|
|
41
41
|
}
|
|
42
42
|
else if (options.returnObservable || methodDesc.serverStreaming) {
|
|
43
43
|
returns = (0, ts_poet_1.code) `${(0, types_1.responseObservable)(ctx, methodDesc)}`;
|
|
@@ -232,7 +232,10 @@ function generateServiceClientImpl(ctx, fileDesc, serviceDesc) {
|
|
|
232
232
|
chunks.push(generateBatchingRpcMethod(ctx, batchMethod));
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
-
if (options.context &&
|
|
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
|
-
|
|
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
|
}
|