Skip to content

v1.0.0

Compare
Choose a tag to compare
@oscartbeaumont oscartbeaumont released this 23 Feb 07:17
· 225 commits to main since this release

A much-anticipated release for Specta coming with a major internal refactor and huge improvements to type safety and error handling.

This release is a v1.0.0 to ensure Specta follows the semantic versioning standard set forth by Cargo. The internal API is not currently stable as it will likely undergo major changes in future releases to support the exporting of types into languages other than Typescript.

Below are some of the major changes for this release:

Overhaul error handling

The main external change of this release is a significant improvement in error handling across the board. A major refactor of the Type macro has taken place to ensure the errors are significantly more helpful.

For example, these are some of the new errors you may come across when using Specta:

error: specta: found string literal containing an unsupported inflection
 --> tests/macro/compile_error.rs:7:22
  |
7 | #[serde(rename_all = "camelCase123")]
  |                      ^^^^^^^^^^^^^^

error: specta: trait objects are not currently supported.
  --> tests/macro/compile_error.rs:13:34
   |
13 |     pub(crate) cause: Option<Box<dyn std::error::Error + Send + Sync>>,
   |                                  ^^^

error: specta: Found unsupported container attribute 'noshot'
  --> tests/macro/compile_error.rs:75:10
   |
75 | #[specta(noshot = true)]
   |          ^^^^^^

error: specta: Found unsupported container attribute 'noshot'
  --> tests/macro/compile_error.rs:79:10
   |
79 | #[specta(noshot)]
   |          ^^^^^^

error: specta: Found unsupported field attribute 'noshot'
  --> tests/macro/compile_error.rs:84:14
   |
84 |     #[specta(noshot = true)]
   |              ^^^^^^

error: specta: Found unsupported field attribute 'noshot'
  --> tests/macro/compile_error.rs:90:14
   |
90 |     #[specta(noshot)]
   |              ^^^^^^

The Typescript exporter has already been redesigned to use statically typed errors. This change means all of the functions which previously returned Result<String, String>, now return Result<String, TsExportError>

Strict BigInt handling

Previously Specta would export the Rust types isize, usize, i64, u64, i128, u128 as a Typescript BigInt. This however is problematic when used for web backends. JSON.parse will truncate BigInt types when deserializing your JSON on the frontend leading to unintentional bugs.

With this release exporting a BigInt type by default will result in an error. If you would like to export them, you can control the behavior using ExportConfiguration and BigIntExportBehavior (example). This also allows library authors building on top of Specta to set the capabilities of their IPC bus, so you can prevent mistakes from making it into production!

Drop OpenAPI support

The existing OpenAPI support was half-baked and should have never been released. With future improvements, it will be rereleased once the handling of generic types has been worked out. If you were using this feature please open a GH discussion or send a message on Discord and we can work on getting a beta version of it supported for your use case.

Major internal refactors

I am going to spare the exact details but anything manually working with Type (the trait not macro) or anything in the datatype module will likely require changes. This will mainly affect library authors using Specta. These changes make it impossible to represent many invalid types that could previously be constructed. This allowed for removing many runtime errors and significantly improved the readability of the Specta codebase!

Huge thanks to @Brendonovich for his help on a lot of this work!

Do open an issue on GitHub or ask a question in Discord if you are having problems upgrading your code!