Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Next.JS projects in generated clients
This commit adds support for generated Typescript clients to be compitable with [Next.JS](https://nextjs.org/) applications with the new `--nextjs` argument. The existing client was not compiatble as we where using namespaces to mimic the packages within the Encore application, however namespaces are somewhat depcreated and not all transpliers support them; the key one here being Babel (which Next.JS uses under the hood). When turned on the new `--nextjs` flag, therefore prevents the code generator from emitting namespaces, and instead it uses the package name as a prefix for generated types; such as `$package_$struct`. To make NextJS development easier, this flag also tells the TypeScript code generator to generate [SWR](https://swr.vercel.app/) wrappers for all API's, while maintaining the promise based functions if direct calls are still required (i.e. to perform actions). If the original api call was: ``` const api = new Client() const rsp: Promise<Data> = api.MySvc.MyAPI("segment", { name: "bob" }) ``` The SWR wrapper will be: ``` const api = new Client() // this needs to be a singleton for the application instance const rsp: SWRResponse<Data> = api.MySvc.useMyAPI("segment", { name: "bob" }, { refreshInternval: 1000 }) ```
- Loading branch information
Showing
12 changed files
with
1,747 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.