Skip to content

Commit

Permalink
feat(ts-proto-stephenh#859): updated docs and renamed methods to toOn…
Browse files Browse the repository at this point in the history
…ly and fromOnly
  • Loading branch information
FrabatUni committed Jul 19, 2023
1 parent 088ffd7 commit 8f9d490
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ Generated code will be placed in the Gradle build directory.

This is also useful if you want "only types".

- With `--ts_proto_opt=outputJsonMethods=to-only` and `--ts_proto_opt=outputJsonMethods=from-only` you will be able to export only one between the `Message.toJSON` and `Message.fromJSON` methods.

This is useful if you're using ts-proto just to `encode` or `decode` and not for both.

- With `--ts_proto_opt=outputPartialMethods=false`, the `Message.fromPartial` and `Message.create` methods for accepting partially-formed objects/object literals will not be output.

- With `--ts_proto_opt=stringEnums=true`, the generated enum types will be string-based instead of int-based.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=decode-only,nestJs=false
outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=from-only,nestJs=false
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=encode-only,nestJs=false
outputEncodeMethods=false,outputPartialMethods=false,outputJsonMethods=to-only,nestJs=false
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri
staticMembers.push(generateDecodeTransform(fullName));
}
if (options.outputJsonMethods) {
if (options.outputJsonMethods === true || options.outputJsonMethods === "decode-only") {
if (options.outputJsonMethods === true || options.outputJsonMethods === "from-only") {
staticMembers.push(generateFromJson(ctx, fullName, fullTypeName, message));
}
if (options.outputJsonMethods === true || options.outputJsonMethods === "encode-only") {
if (options.outputJsonMethods === true || options.outputJsonMethods === "to-only") {
staticMembers.push(generateToJson(ctx, fullName, fullTypeName, message));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type Options = {
fileSuffix: string;
importSuffix: string;
outputEncodeMethods: true | false | "encode-only" | "decode-only" | "encode-no-creation";
outputJsonMethods: true | false | "encode-only" | "decode-only";
outputJsonMethods: true | false | "to-only" | "from-only";
outputPartialMethods: boolean;
outputTypeAnnotations: boolean | "static-only";
outputTypeRegistry: boolean;
Expand Down

0 comments on commit 8f9d490

Please sign in to comment.