Skip to content

Commit

Permalink
🎉 release 2.0.0-rc.17
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Aug 1, 2024
1 parent 9e282f0 commit 607ac29
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 82 deletions.
6 changes: 3 additions & 3 deletions specta-jsdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default = []
workspace = true

[dependencies]
specta = { version = "=2.0.0-rc.16", path = "../specta" }
specta-typescript = { version = "=0.0.3", path = "../specta-typescript" }
specta = { version = "=2.0.0-rc.17", path = "../specta" }
specta-typescript = { version = "=0.0.4", path = "../specta-typescript" }
# TODO: Don't depend on serde
specta-serde = { version = "=0.0.3", path = "../specta-serde" }
specta-serde = { version = "=0.0.4", path = "../specta-serde" }
2 changes: 1 addition & 1 deletion specta-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "specta-macros"
description = "Macros for specta. Don't use directly!"
version = "2.0.0-rc.16"
version = "2.0.0-rc.17"
authors = ["Oscar Beaumont <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions specta-serde/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "specta-serde"
description = "Serde support for Specta"
version = "0.0.3"
version = "0.0.4"
authors = ["Oscar Beaumont <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -19,5 +19,5 @@ rustdoc-args = ["--cfg", "docsrs"]
workspace = true

[dependencies]
specta = { version = "=2.0.0-rc.16", path = "../specta" }
specta = { version = "=2.0.0-rc.17", path = "../specta" }
thiserror = "1.0.61"
6 changes: 3 additions & 3 deletions specta-typescript/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "specta-typescript"
description = "Export your Rust types to TypeScript"
version = "0.0.3"
version = "0.0.4"
authors = ["Oscar Beaumont <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -25,7 +25,7 @@ function = ["specta/function"]
workspace = true

[dependencies]
specta = { version = "=2.0.0-rc.16", path = "../specta" }
specta = { version = "=2.0.0-rc.17", path = "../specta" }
# TODO: Don't depend on serde
specta-serde = { version = "=0.0.3", path = "../specta-serde" }
specta-serde = { version = "=0.0.4", path = "../specta-serde" }
thiserror = "1.0.61"
6 changes: 3 additions & 3 deletions specta-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "specta-util"
description = "High-level utilities for working with Specta"
version = "0.0.3"
version = "0.0.4"
authors = ["Oscar Beaumont <[email protected]>"]
edition = "2021"
license = "MIT"
Expand All @@ -27,7 +27,7 @@ serde = []
workspace = true

[dependencies]
specta = { version = "=2.0.0-rc.16", path = "../specta" }
specta-macros = { version = "=2.0.0-rc.16", path = "../specta-macros", default-features = false, optional = true }
specta = { version = "=2.0.0-rc.17", path = "../specta" }
specta-macros = { version = "=2.0.0-rc.17", path = "../specta-macros", default-features = false, optional = true }
ctor = { version = "0.2.8", default-features = false, optional = true }
serde = "1.0.204" # TODO: Can we remove this or at least make it optional behind the `serde` flag
4 changes: 2 additions & 2 deletions specta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "specta"
description = "Easily export your Rust types to other languages"
version = "2.0.0-rc.16"
version = "2.0.0-rc.17"
authors = ["Oscar Beaumont <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -84,7 +84,7 @@ interop = ["dep:specta1"]
workspace = true

[dependencies]
specta-macros = { version = "=2.0.0-rc.16", optional = true, path = "../specta-macros" }
specta-macros = { version = "=2.0.0-rc.17", optional = true, path = "../specta-macros" }
paste = { version = "1", optional = true }
thiserror = "1.0.61"

Expand Down
36 changes: 26 additions & 10 deletions tests/tests/datatype.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use specta::datatype::{DataType, LiteralType, PrimitiveType, StructType};
use specta::datatype::{DataType, FunctionResultVariant, LiteralType, PrimitiveType, StructType};
use specta_datatype_from::DataTypeFrom;
use specta_typescript as ts;

Expand Down Expand Up @@ -54,7 +54,11 @@ fn test_datatype() {
])
.into();
assert_eq!(
ts::datatype(&Default::default(), &val, &Default::default()),
ts::datatype(
&Default::default(),
&FunctionResultVariant::Value(val.clone()),
&Default::default()
),
Ok("\"A\" | \"B\"".into())
);
assert_eq!(
Expand All @@ -76,7 +80,7 @@ fn test_datatype() {
assert_eq!(
ts::datatype(
&Default::default(),
&val.clone().to_anonymous(),
&FunctionResultVariant::Value(val.clone().to_anonymous()),
&Default::default()
),
Ok("{ queries: \"A\" | \"B\" }".into())
Expand All @@ -100,7 +104,7 @@ fn test_datatype() {
assert_eq!(
ts::datatype(
&Default::default(),
&val.clone().to_anonymous(),
&FunctionResultVariant::Value(val.clone().to_anonymous()),
&Default::default()
),
Ok("{ queries: \"A\" | \"B\" }".into())
Expand All @@ -127,7 +131,7 @@ fn test_datatype() {
assert_eq!(
ts::datatype(
&Default::default(),
&val.clone().to_anonymous(),
&FunctionResultVariant::Value(val.clone().to_anonymous()),
&Default::default()
),
Ok("{ queries: { queries: \"A\" | \"B\" } }".into())
Expand All @@ -141,21 +145,29 @@ fn test_datatype() {
}])
.into();
assert_eq!(
ts::datatype(&Default::default(), &val, &Default::default()),
ts::datatype(
&Default::default(),
&FunctionResultVariant::Value(val),
&Default::default()
),
Ok("{ queries: \"A\" | \"B\" }".into())
);

let val: DataType = Procedures7().into();
assert_eq!(
ts::datatype(&Default::default(), &val, &Default::default()),
ts::datatype(
&Default::default(),
&FunctionResultVariant::Value(val),
&Default::default()
),
Ok("null".into()) // This is equivalent of `()` Because this is a `TupleType` not an `EnumType`.
);

let val: StructType = Procedures8 {}.into();
assert_eq!(
ts::datatype(
&Default::default(),
&val.clone().to_anonymous(),
&FunctionResultVariant::Value(val.clone().to_anonymous()),
&Default::default()
),
Ok("Record<string, never>".into())
Expand All @@ -164,15 +176,19 @@ fn test_datatype() {
let val: DataType =
Procedures9(DataType::Any, DataType::Primitive(PrimitiveType::String)).into();
assert_eq!(
ts::datatype(&Default::default(), &val, &Default::default()),
ts::datatype(
&Default::default(),
&FunctionResultVariant::Value(val),
&Default::default()
),
Ok("[any, string]".into())
);

let val: StructType = Procedures10 { a: DataType::Any }.into();
assert_eq!(
ts::datatype(
&Default::default(),
&val.clone().to_anonymous(),
&FunctionResultVariant::Value(val.clone().to_anonymous()),
&Default::default()
),
Ok("{ b: any }".into())
Expand Down
115 changes: 57 additions & 58 deletions tests/tests/typescript/export_function_header.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
#![allow(deprecated)]
// #![allow(deprecated)]

use specta::{datatype::Function, function::fn_datatype, specta, TypeMap};
use specta_typescript::export_function_header;
// use specta::{datatype::Function, function::fn_datatype, specta, TypeMap};

#[specta]
fn a() {}
#[specta]
fn b() -> () {}
#[specta]
async fn c() {}
#[specta]
fn d() -> String {
"todo".into()
}
#[specta]
fn e(a: String) {}
#[specta]
fn f(a: String, b: i32) {}
#[specta]
#[deprecated]
fn g() {}
// #[specta]
// fn a() {}
// #[specta]
// fn b() -> () {}
// #[specta]
// async fn c() {}
// #[specta]
// fn d() -> String {
// "todo".into()
// }
// #[specta]
// fn e(a: String) {}
// #[specta]
// fn f(a: String, b: i32) {}
// #[specta]
// #[deprecated]
// fn g() {}

#[test]
fn test_export_function_header() {
assert(
fn_datatype!(a)(&mut TypeMap::default()),
Ok("export function a();"),
);
assert(
fn_datatype!(b)(&mut TypeMap::default()),
Ok("export function b(): null;"),
);
assert(
fn_datatype!(c)(&mut TypeMap::default()),
Ok("export async function c();"),
);
assert(
fn_datatype!(d)(&mut TypeMap::default()),
Ok("export function d(): string;"),
);
assert(
fn_datatype!(e)(&mut TypeMap::default()),
Ok("export function e(a: string);"),
);
assert(
fn_datatype!(f)(&mut TypeMap::default()),
Ok("export function f(a: string, b: number);"),
);
assert(
fn_datatype!(g)(&mut TypeMap::default()),
Ok("/**\n * @deprecated\n */\nexport function g();"),
);
}
// #[test]
// fn test_export_function_header() {
// assert(
// fn_datatype!(a)(&mut TypeMap::default()),
// Ok("export function a();"),
// );
// assert(
// fn_datatype!(b)(&mut TypeMap::default()),
// Ok("export function b(): null;"),
// );
// assert(
// fn_datatype!(c)(&mut TypeMap::default()),
// Ok("export async function c();"),
// );
// assert(
// fn_datatype!(d)(&mut TypeMap::default()),
// Ok("export function d(): string;"),
// );
// assert(
// fn_datatype!(e)(&mut TypeMap::default()),
// Ok("export function e(a: string);"),
// );
// assert(
// fn_datatype!(f)(&mut TypeMap::default()),
// Ok("export function f(a: string, b: number);"),
// );
// assert(
// fn_datatype!(g)(&mut TypeMap::default()),
// Ok("/**\n * @deprecated\n */\nexport function g();"),
// );
// }

#[track_caller]
fn assert(dt: Function, result: specta_typescript::Result<&str>) {
match export_function_header(dt, &Default::default()) {
Ok(s) => assert_eq!(result, Ok(s.as_str())),
Err(e) => assert_eq!(result, Err(e)),
}
}
// #[track_caller]
// fn assert(dt: Function, result: specta_typescript::Result<&str>) {
// match export_function_header(dt, &Default::default()) {
// Ok(s) => assert_eq!(result, Ok(s.as_str())),
// Err(e) => assert_eq!(result, Err(e)),
// }
// }

0 comments on commit 607ac29

Please sign in to comment.