Skip to content

Commit 008e53b

Browse files
complete writeup for last phase
1 parent 0680683 commit 008e53b

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

content/docs/specta/rfc/flightscience.mdx

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,13 +1731,13 @@ This all leads to a much simpler system, and it also means the job of preventing
17311731

17321732
Work for this was done on: [#483](https://github.com/specta-rs/specta/pull/483)
17331733

1734-
## Semantic Types
1734+
### Semantic Types
17351735

17361736
The work for this was done on: [#203](https://github.com/specta-rs/specta/issues/203)
17371737

17381738
I did previously call this nuanced types but that's not really true anymore.
17391739

1740-
### Getting terminology right
1740+
#### Getting terminology right
17411741

17421742
The original nuanced types feature confused two different Specta features which ended up being quite related so I wanted to clarify the terminology.
17431743

@@ -1749,7 +1749,7 @@ Semantic types aims to make `BigInt`, `Date`, `Uint8Array`, etc. work with Spect
17491749

17501750
The solution to this was `specta_typescript::semantic`.
17511751

1752-
### Semantic Types
1752+
#### Semantic Types
17531753

17541754
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:
17551755

@@ -1765,7 +1765,7 @@ Special notes:
17651765
- *[1]* - BigInt's are explained later on and are less cut and dry.
17661766
- *[2]* - These types are actually handled by `JSON.stringify` for us so we don't need to do any special code.
17671767

1768-
### `Date`, `Uint8Array` and `URL`
1768+
#### `Date`, `Uint8Array` and `URL`
17691769

17701770
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.
17711771

@@ -1806,15 +1806,15 @@ This all comes together to allow these types to work. I have implemented this in
18061806

18071807
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.
18081808

1809-
### BigInt and special-float support in Tauri
1809+
#### BigInt and special-float support in Tauri
18101810

18111811
BigInt's have a different constraint, there JSON representation is lossly. Mainly:
18121812
- When `JSON.parse` is run large integers are truncated.
18131813
- `NaN`, `Infinity` and `-Infinity` all become `null`
18141814

18151815
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.
18161816

1817-
#### Jsone
1817+
##### Jsone
18181818

18191819
[Jsone](https://github.com/specta-rs/jsone) is a new crate I built out of my work looking at solutions here.
18201820

@@ -1897,7 +1897,7 @@ This is built in so in practice it's as easy as:
18971897
- This remaps the type of floats like `f32` and `f64` from `number | null` to `number`.
18981898
- If `NaN`, `Infinity` and `-Infinity` are handled properly they will be preserved and hence `null` won't occur.
18991899

1900-
#### Jsone and Tauri?
1900+
##### Jsone and Tauri?
19011901

19021902
So can we upstream this into Tauri? Not really in a way which isn't full of footguns.
19031903

@@ -1909,21 +1909,21 @@ Tauri allows JSON to come into the system from outside in a lot of places. This
19091909

19101910
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.
19111911

1912-
#### Solutions
1912+
##### Solutions
19131913

19141914
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`).
19151915

19161916
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.
19171917

1918-
## Dropping Specta function code
1918+
### Dropping Specta function code
19191919

19201920
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.
19211921

19221922
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.
19231923

19241924
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!).
19251925

1926-
## TauRPC
1926+
### TauRPC
19271927

19281928
On [#22](https://github.com/fltsci/TauRPC/pull/22) I have implemented:
19291929
- Typesafe error handling
@@ -1937,7 +1937,7 @@ In conclusion:
19371937
- 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`).
19381938
- 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).
19391939

1940-
## Specta Typescript improvements
1940+
### Specta Typescript improvements
19411941

19421942
This work was done against main but working on resolving issue [#475](https://github.com/specta-rs/specta/issues/475).
19431943

@@ -1950,9 +1950,30 @@ Changes:
19501950
- Allow getting the `NamedDataType` an error occurred in back out.
19511951
- Restructure error enum to include some errors we didn't handle well before.
19521952

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
19541958

19551959
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

Comments
 (0)