Expand description
Runtime-aware TypeScript type remapping.
Semantic types are Rust types whose TypeScript runtime value should be more specific than their JSON-compatible wire representation.
This enables the following default rules:
bytes::Bytesto becomeUint8Arraybytes::BytesMutto becomeUint8Arrayurl::Urlto becomeUrlchrono::DateTimeto becomeDatechrono::NaiveDateto becomeDatejiff::Timestampto becomeDatejiff::civil::Dateto becomeDate
This could also allow you to map your own Rust types into custom JavaScript types like custom classes. Refer to semantic::Configuration::define for building your own rules.
This is intended the be implemented by frameworks like Tauri Specta, TauRPC and rspc as they have control of the runtime and type layer.
WARNING: The current implementation relies on the frontend and backend being versioned in-step. This works for a Tauri desktop application but may become an issue for a HTTP API unless you have something like Skew Protection.
We will likely lift this as a hard restriction in the future!
Implementing into your own framework
§Implementing into your own framework
A framework needs to be integrated properly for this feature to work, as it requires both type-level and runtime JS to make it work properly.
I would highly recommend reading specta-rs/specta#203 and understanding it as it’s the core work which inspired this feature.
Documentation coming soon… For now refer to specta-rs/tauri-specta#219 which was the original implementation into Tauri Specta.
Structs§
- Configuration
- Configuration for runtime-aware TypeScript type remapping.
- Rule
- A rule for a specific named data type.
- Transform
- A JavaScript expression that converts between a semantic TypeScript runtime value and its JSON-compatible representation.