Skip to content

Commit

Permalink
fix: google protobuf timestamps don't properly get suffixed when useD…
Browse files Browse the repository at this point in the history
…ate=false and prefix/suffix (#1146)
  • Loading branch information
halkeye authored Dec 9, 2024
1 parent eed4d40 commit 53f799e
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 1 deletion.
228 changes: 228 additions & 0 deletions integration/suffix-usedate/google/protobuf/timestamp.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integration/suffix-usedate/parameters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
useDate=false,typeSuffix=NoUseDateS,typePrefix=NoUseDateP
18 changes: 18 additions & 0 deletions integration/suffix-usedate/suffix-no-usedate-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NoUseDatePSuffixTypeNoUseDateS } from "./suffix-no-usedate-type";

describe("suffix", () => {
it("generates types correctly", () => {
const obj: NoUseDatePSuffixTypeNoUseDateS = {
createdAt: { seconds: 1317826080, nanos: 0 },
};
expect(obj).toBeTruthy();

// make sure all conversions to and from handle prefixes and suffixes
//
const json = NoUseDatePSuffixTypeNoUseDateS.toJSON(obj);

expect(json).toEqual({ createdAt: "2011-10-05T14:48:00.000Z" });

expect(NoUseDatePSuffixTypeNoUseDateS.fromJSON(json)).toEqual(obj);
});
});
6 changes: 6 additions & 0 deletions integration/suffix-usedate/suffix-no-usedate-type.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";
import "google/protobuf/timestamp.proto";

message SuffixType {
google.protobuf.Timestamp created_at = 9;
}
121 changes: 121 additions & 0 deletions integration/suffix-usedate/suffix-no-usedate-type.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ function makeTimestampMethods(
} else if (typeof o === "string") {
return ${toTimestamp}(new ${bytes.globalThis}.Date(o));
} else {
return Timestamp.fromJSON(o);
return ${options.typePrefix}Timestamp${options.typeSuffix}.fromJSON(o);
}
}
`,
Expand Down

0 comments on commit 53f799e

Please sign in to comment.