New command API and runtime JSON Schema (and TypeScript) code generation #3670
tamasfe
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I had a tool lying around that I once wrote for a project where we generated typescript code from JSON schema files, but it wasn't used anymore. Fortunately it was written in Rust, so I thought I'd strip the unneeded features and repurpose it for code generation in Tauri.
In the process I also wrote a command API that is similar to how
actix-web
creates its route handlers, which means that command handlers don't require macros as they are ordinary functions or closures.A
command
macro on functions can still be used to provide additional metadata, currently documentation from doc comments, and argument names, but it's not required for type-safe code generation.The TS code is generated at runtime, this way the generated code is always up-to-date and there is no fiddling with build scripts or macros as
rustc
does most of the work.My work pretty much touched on these issues:
It's not yet documented, but it is only ~1k loc so I believe the provided example should be enough to get an idea.
I didn't want to open a PR yet as I did not need anything from the Tauri internals and wanted to avoid the overhead of integration. I can follow-up with a PR (or anyone else for that matter) if it's desirable.
The code is available here:
https://github.com/tamasfe/tauri-commands
Beta Was this translation helpful? Give feedback.
All reactions