ts-proto 1.180.0 → 1.181.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 +5 -1
- package/build/options.d.ts +2 -0
- package/build/options.js +2 -0
- package/build/visit.js +4 -2
- package/package.json +1 -1
package/README.markdown
CHANGED
|
@@ -555,6 +555,10 @@ Generated code will be placed in the Gradle build directory.
|
|
|
555
555
|
|
|
556
556
|
- With `--ts_proto_opt=useNullAsOptional=true`, `undefined` values will be converted to `null`, and if you use `optional` label in your `.proto` file, the field will have `undefined` type as well. for example:
|
|
557
557
|
|
|
558
|
+
- With `--ts_proto_opt=typePrefix=MyPrefix`, the generated interfaces, enums, and factories will have a prefix of `MyPrefix` in their names.
|
|
559
|
+
|
|
560
|
+
- With `--ts_proto_opt=typeSuffix=MySuffix`, the generated interfaces, enums, and factories will have a suffix of `MySuffix` in their names.
|
|
561
|
+
|
|
558
562
|
```protobuf
|
|
559
563
|
message ProfileInfo {
|
|
560
564
|
int32 id = 1;
|
|
@@ -772,7 +776,7 @@ Will generate a `Foo` type with two fields: `field_a: string | undefined;` and `
|
|
|
772
776
|
|
|
773
777
|
With this output, you'll have to check both `if object.field_a` and `if object.field_b`, and if you set one, you'll have to remember to unset the other.
|
|
774
778
|
|
|
775
|
-
Instead, we recommend using the `oneof=unions-value` option, which will change the output to be an
|
|
779
|
+
Instead, we recommend using the `oneof=unions-value` option, which will change the output to be an Algebraic Data Type/ADT like:
|
|
776
780
|
|
|
777
781
|
```typescript
|
|
778
782
|
interface YourMessage {
|
package/build/options.d.ts
CHANGED
|
@@ -99,6 +99,8 @@ export type Options = {
|
|
|
99
99
|
annotateFilesWithVersion: boolean;
|
|
100
100
|
noDefaultsForOptionals: boolean;
|
|
101
101
|
bigIntLiteral: boolean;
|
|
102
|
+
typePrefix: string;
|
|
103
|
+
typeSuffix: string;
|
|
102
104
|
};
|
|
103
105
|
export declare function defaultOptions(): Options;
|
|
104
106
|
export declare function optionsFromParameter(parameter: string | undefined): Options;
|
package/build/options.js
CHANGED
package/build/visit.js
CHANGED
|
@@ -11,8 +11,9 @@ function visit(proto, sourceInfo, messageFn, options, enumFn = () => { }, tsPref
|
|
|
11
11
|
const protoFullName = protoPrefix + enumDesc.name;
|
|
12
12
|
// I.e. FooBar_ZazInner
|
|
13
13
|
const tsFullName = tsPrefix + (0, case_1.maybeSnakeToCamel)(enumDesc.name, options);
|
|
14
|
+
const tsFullNameWithAffixes = `${options.typePrefix}${tsFullName}${options.typeSuffix}`;
|
|
14
15
|
const nestedSourceInfo = sourceInfo.open(childEnumType, index);
|
|
15
|
-
enumFn(
|
|
16
|
+
enumFn(tsFullNameWithAffixes, enumDesc, nestedSourceInfo, protoFullName);
|
|
16
17
|
});
|
|
17
18
|
const messages = "messageType" in proto ? proto.messageType : proto.nestedType;
|
|
18
19
|
const childType = isRootFile ? sourceInfo_1.Fields.file.message_type : sourceInfo_1.Fields.message.nested_type;
|
|
@@ -21,8 +22,9 @@ function visit(proto, sourceInfo, messageFn, options, enumFn = () => { }, tsPref
|
|
|
21
22
|
const protoFullName = protoPrefix + message.name;
|
|
22
23
|
// I.e. FooBar_ZazInner
|
|
23
24
|
const tsFullName = tsPrefix + (0, case_1.maybeSnakeToCamel)(messageName(message), options);
|
|
25
|
+
const tsFullNameWithAffixes = `${options.typePrefix}${tsFullName}${options.typeSuffix}`;
|
|
24
26
|
const nestedSourceInfo = sourceInfo.open(childType, index);
|
|
25
|
-
messageFn(
|
|
27
|
+
messageFn(tsFullNameWithAffixes, message, nestedSourceInfo, protoFullName);
|
|
26
28
|
const delim = options.useSnakeTypeName ? "_" : "";
|
|
27
29
|
visit(message, nestedSourceInfo, messageFn, options, enumFn, tsFullName + delim, protoFullName + ".");
|
|
28
30
|
});
|