You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/specta/rfc/flightscience.mdx
+36-15Lines changed: 36 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1731,13 +1731,13 @@ This all leads to a much simpler system, and it also means the job of preventing
1731
1731
1732
1732
Work for this was done on: [#483](https://github.com/specta-rs/specta/pull/483)
1733
1733
1734
-
## Semantic Types
1734
+
### Semantic Types
1735
1735
1736
1736
The work for this was done on: [#203](https://github.com/specta-rs/specta/issues/203)
1737
1737
1738
1738
I did previously call this nuanced types but that's not really true anymore.
1739
1739
1740
-
### Getting terminology right
1740
+
#### Getting terminology right
1741
1741
1742
1742
The original nuanced types feature confused two different Specta features which ended up being quite related so I wanted to clarify the terminology.
1743
1743
@@ -1749,7 +1749,7 @@ Semantic types aims to make `BigInt`, `Date`, `Uint8Array`, etc. work with Spect
1749
1749
1750
1750
The solution to this was `specta_typescript::semantic`.
1751
1751
1752
-
### Semantic Types
1752
+
#### Semantic Types
1753
1753
1754
1754
I did a massive writeup [in a comment for #203](https://github.com/specta-rs/specta/issues/203#issuecomment-4387573925) to outline my conclusion here. But in essence:
1755
1755
@@ -1765,7 +1765,7 @@ Special notes:
1765
1765
- *[1]* - BigInt's are explained later on and are less cut and dry.
1766
1766
- *[2]* - These types are actually handled by `JSON.stringify` for us so we don't need to do any special code.
1767
1767
1768
-
### `Date`, `Uint8Array` and `URL`
1768
+
#### `Date`, `Uint8Array` and `URL`
1769
1769
1770
1770
The core observation of these is that the JSON type and Rust serialization is all good. All we need is a way to change the Specta type and generate some runtime JS code.
1771
1771
@@ -1806,15 +1806,15 @@ This all comes together to allow these types to work. I have implemented this in
1806
1806
1807
1807
I have some concerns about this approach with [rspc](https://github.com/specta-rs/rspc) as by generating JS code that depends on the object shape, it requires your frontend and backend to be versioned in perfect sync. For Tauri this is how it will always be as the JS and Rust is shipped in the same binary, but for people building web APIs this is not usually the case. I have ideas for solving this but it is out of scope for now and rspc is not currently maintained so it's not a massive concern.
1808
1808
1809
-
### BigInt and special-float support in Tauri
1809
+
#### BigInt and special-float support in Tauri
1810
1810
1811
1811
BigInt's have a different constraint, there JSON representation is lossly. Mainly:
1812
1812
- When `JSON.parse` is run large integers are truncated.
1813
1813
- `NaN`, `Infinity` and `-Infinity` all become `null`
1814
1814
1815
1815
So at it's core, doing `commandResult.then((v) => BigInt(v))` will still result in truncation if `v` is a `number`. So you need a way of serializing these correctly in Rust.
1816
1816
1817
-
#### Jsone
1817
+
##### Jsone
1818
1818
1819
1819
[Jsone](https://github.com/specta-rs/jsone) is a new crate I built out of my work looking at solutions here.
1820
1820
@@ -1897,7 +1897,7 @@ This is built in so in practice it's as easy as:
1897
1897
- This remaps the type of floats like `f32` and `f64` from `number | null` to `number`.
1898
1898
- If `NaN`, `Infinity` and `-Infinity` are handled properly they will be preserved and hence `null` won't occur.
1899
1899
1900
-
#### Jsone and Tauri?
1900
+
##### Jsone and Tauri?
1901
1901
1902
1902
So can we upstream this into Tauri? Not really in a way which isn't full of footguns.
1903
1903
@@ -1909,21 +1909,21 @@ Tauri allows JSON to come into the system from outside in a lot of places. This
1909
1909
1910
1910
For more confirmation on this the current Tauri Specta versions use `serde_json::from_string` for the raw event payload, which would bypass any work done in Tauri. It's hard for all cases to be covered in Tauri when the raw JSON APIs exist.
1911
1911
1912
-
#### Solutions
1912
+
##### Solutions
1913
1913
1914
1914
Basically for Tauri Specta and TauRPC I think this is a lost cause but an opinionated RPC framework which didn't use Tauri's APIs could make it work as they would maintain full control over serialization and deserialization (looking at you [rspc](https://github.com/specta-rs/rspc) and your support for any `serde::Serializer`).
1915
1915
1916
1916
You could wrap your argument and return types of commands, events and channels manually with `Jsone` but that would both not be fun and would likely be pretty easy to miss.
1917
1917
1918
-
## Dropping Specta function code
1918
+
### Dropping Specta function code
1919
1919
1920
1920
I have talked about wanting to remove `#[specta::specta]` and `specta::function::*`. I think bringing these into the core was a mistake but at the end of the day I need to be pragmatic and removing these is just not going to make v2.
1921
1921
1922
1922
I spent some of my own time on the weekend doing up [this proposal to Tauri](https://github.com/tauri-apps/tauri/pull/15326) (and [associated implementation](https://github.com/specta-rs/tauri-specta/pull/218) in Tauri Specta). I need to run it pass the working group but I am also not really sure if it's going to happen. If it doesn't we are kinda in a limbo, not being able to remove this feature without just breaking Tauri Specta.
1923
1923
1924
1924
So tldr: we live with bad decisions until we have a solution and then I will mark it as deprecated. We could then remove it in v3 if it ever happens someday (but I hope it doesn't need to!).
1925
1925
1926
-
## TauRPC
1926
+
### TauRPC
1927
1927
1928
1928
On [#22](https://github.com/fltsci/TauRPC/pull/22) I have implemented:
1929
1929
- Typesafe error handling
@@ -1937,7 +1937,7 @@ In conclusion:
1937
1937
- If you use `chrono::DateTime`/`jiff::Timestamp`/`bytes::Bytes`/`url::Url` (and maybe more in the future) you will get a workable JS type (`Date`, `Uint8Array` or `URL`).
1938
1938
- You could expand this to your own classes, if you want to convert a Rust struct into a full JS class (for example, could be useful for a `Path` class w/ helpers for platform-agnostic path handling or something like that).
1939
1939
1940
-
## Specta Typescript improvements
1940
+
### Specta Typescript improvements
1941
1941
1942
1942
This work was done against main but working on resolving issue [#475](https://github.com/specta-rs/specta/issues/475).
1943
1943
@@ -1950,9 +1950,30 @@ Changes:
1950
1950
- Allow getting the `NamedDataType` an error occurred in back out.
1951
1951
- Restructure error enum to include some errors we didn't handle well before.
1952
1952
1953
-
## v2 release plan
1953
+
### TODOs
1954
+
1955
+
I have resolved all remaining TODO's in `specta`, `specta-macros`, `specta-typescript` and `specta-serde`.
1956
+
1957
+
### v2 release plan
1954
1958
1955
1959
I am going to do the final v2 release in a few weeks time (right now slated for the 13th of June). I know a delay is really annoying but I want to do it because:
1956
-
- I want to let the dust settle on these changes to ensure I haven't missed anything.
1957
-
- I want to give people time to try it out and catch + resolve bugs.
1958
-
- I want to test it on a large Tauri codebase of my next employer.
1960
+
- I want to let the dust settle on these changes to ensure I haven't missed anything major.
1961
+
- I want to give people time to try it out and catch + resolve bugs before the launch.
1962
+
- I want to test it on a large Tauri codebase of my next employer. I will also try and upgrade some open source ones like [Cap](https://cap.so).
1963
+
1964
+
## Conclusions
1965
+
1966
+
This marks the end of contract! I am so incredibly thankful to Flight Science for making this stuff possible and I really hope you got the value you were looking for out of it!
1967
+
1968
+
Given how much of a monumental effort this has been I don't think Specta v2 would have happened anytime soon if it were up to me working on it in my spare time. I have been dreaming of Specta v2 finally happening for literally years at this point and now it's happening which is so amazing!!!
1969
+
1970
+
TLDR:
1971
+
- Improve tests and codebase quality
1972
+
- Cleanup and make a very solid minimal core API. Improve Typescript exporter code, fix bugs and improve the default formatting of generated bindings.
1973
+
- Finish the incomplete work on decoupling Serde from Specta's core.
1974
+
- Support for all Serde attributes, including narrowing types for serialize vs deserialize phase.
1975
+
- Support for converting Rust types into JS types like `Date`, `Uint8Array`, `URL` and more.
1976
+
- Support for Typescript branded types for typesafe identifiers
1977
+
- Apply all upgrades to the Flight Science TauRPC, ready to be used internally!
1978
+
1979
+
I can't express how thankful I am! I am always going to be around so feel free to reach out if you have any questions or need help with anything!
0 commit comments