diff --git a/Cargo.toml b/Cargo.toml index ec4ee56..d8eb94e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -129,7 +129,7 @@ glam = { version = "0.24", optional = true, default-features = false, features = tokio = { version = "1.30", optional = true, default-features = false, features = ["sync"] } url = { version = "2.4.0", optional = true, default-features = false } either = { version = "1.9.0", optional = true, default-features = false } -bevy_ecs = { version = "0.11.3", optional = true, default-features = false } +bevy_ecs = { version = "0.12.0", optional = true, default-features = false } thiserror = "1.0.44" paste = "1.0.14" ctor = { version = "0.2.4", optional = true } diff --git a/src/serde.rs b/src/serde.rs index c77b1a9..d9e6fb3 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -77,9 +77,9 @@ pub(crate) fn is_valid_ty(dt: &DataType, type_map: &TypeMap) -> Result<(), Serde let ty = type_map .get(&ty.sid) .as_ref() - .expect("Reference type not found") + .unwrap_or_else(|| panic!("Reference type not found for: {}", ty.sid.type_name)) .as_ref() - .expect("Type was never populated"); // TODO: Error properly + .unwrap_or_else(|| panic!("Type '{}' was never populated.", ty.sid.type_name)); // TODO: Error properly is_valid_ty(&ty.inner, type_map)?; } diff --git a/src/type/impls.rs b/src/type/impls.rs index f924b54..6a7117b 100644 --- a/src/type/impls.rs +++ b/src/type/impls.rs @@ -587,132 +587,77 @@ const _: () = { #[derive(Type)] #[specta(remote = glam::DVec2, crate = crate, export = false)] #[allow(dead_code)] - struct DVec2 { - x: f64, - y: f64, - } + struct DVec2([f64; 2]); #[derive(Type)] #[specta(remote = glam::IVec2, crate = crate, export = false)] #[allow(dead_code)] - struct IVec2 { - x: i32, - y: i32, - } + struct IVec2([i32; 2]); #[derive(Type)] #[specta(remote = glam::DMat2, crate = crate, export = false)] #[allow(dead_code)] - struct DMat2 { - pub x_axis: glam::DVec2, - pub y_axis: glam::DVec2, - } + struct DMat2([f64; 4]); #[derive(Type)] #[specta(remote = glam::DAffine2, crate = crate, export = false)] #[allow(dead_code)] - struct DAffine2 { - matrix2: glam::DMat2, - translation: glam::DVec2, - } + struct DAffine2([f64; 6]); #[derive(Type)] #[specta(remote = glam::Vec2, crate = crate, export = false)] #[allow(dead_code)] - struct Vec2 { - pub x: f32, - pub y: f32, - } + struct Vec2([f32; 2]); #[derive(Type)] #[specta(remote = glam::Vec3, crate = crate, export = false)] #[allow(dead_code)] - struct Vec3 { - pub x: f32, - pub y: f32, - pub z: f32, - } + struct Vec3([f32; 3]); #[derive(Type)] #[specta(remote = glam::Vec3A, crate = crate, export = false)] #[allow(dead_code)] - struct Vec3A { - pub x: f32, - pub y: f32, - pub z: f32, - } + struct Vec3A([f32; 3]); #[derive(Type)] #[specta(remote = glam::Vec4, crate = crate, export = false)] #[allow(dead_code)] - struct Vec4 { - x: f32, - y: f32, - z: f32, - w: f32, - } + struct Vec4([f32; 4]); #[derive(Type)] #[specta(remote = glam::Mat2, crate = crate, export = false)] #[allow(dead_code)] - struct Mat2 { - pub x_axis: glam::Vec2, - pub y_axis: glam::Vec2, - } + struct Mat2([f32; 4]); #[derive(Type)] #[specta(remote = glam::Mat3, crate = crate, export = false)] #[allow(dead_code)] - struct Mat3 { - pub x_axis: glam::Vec3, - pub y_axis: glam::Vec3, - pub z_axis: glam::Vec3, - } + struct Mat3([f32; 9]); #[derive(Type)] #[specta(remote = glam::Mat3A, crate = crate, export = false)] #[allow(dead_code)] - struct Mat3A { - pub x_axis: glam::Vec3A, - pub y_axis: glam::Vec3A, - pub z_axis: glam::Vec3A, - } + struct Mat3A([f32; 9]); #[derive(Type)] #[specta(remote = glam::Mat4, crate = crate, export = false)] #[allow(dead_code)] - struct Mat4 { - pub x_axis: glam::Vec4, - pub y_axis: glam::Vec4, - pub z_axis: glam::Vec4, - pub w_axis: glam::Vec4, - } + struct Mat4([f32; 16]); #[derive(Type)] #[specta(remote = glam::Quat, crate = crate, export = false)] #[allow(dead_code)] - struct Quat { - pub x: f32, - pub y: f32, - pub z: f32, - pub w: f32, - } + struct Quat([f32; 4]); #[derive(Type)] #[specta(remote = glam::Affine2, crate = crate, export = false)] #[allow(dead_code)] - struct Affine2 { - pub matrix2: glam::Mat2, - pub translation: glam::Vec2, - } + struct Affine2([f32; 6]); #[derive(Type)] #[specta(remote = glam::Affine3A, crate = crate, export = false)] #[allow(dead_code)] - struct Affine3A { - matrix3: glam::Mat3A, - translation: glam::Vec3A, - } + struct Affine3A([f32; 12]); }; #[cfg(feature = "url")] @@ -780,15 +725,7 @@ impl Type for either::Either { #[cfg(feature = "bevy_ecs")] const _: () = { #[derive(Type)] - #[specta(remote = bevy_ecs::entity::Entity, crate = crate, export = false)] - #[allow(dead_code)] - struct Entity { - generation: u32, - index: u32, - } - - #[derive(Type)] - #[specta(remote = bevy_ecs::world::WorldId, crate = crate, export = false)] + #[specta(rename = "bevy_ecs::entity::Entity", remote = bevy_ecs::entity::Entity, crate = crate, export = false)] #[allow(dead_code)] - struct WorldId(usize); + struct EntityDef(u64); }; diff --git a/tests/lib.rs b/tests/lib.rs index ede0db9..061725e 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -13,6 +13,7 @@ mod functions; mod macro_decls; mod map_keys; mod optional; +mod remote_impls; mod rename; mod reserved_keywords; mod selection; diff --git a/tests/remote_impls.rs b/tests/remote_impls.rs new file mode 100644 index 0000000..8267bf5 --- /dev/null +++ b/tests/remote_impls.rs @@ -0,0 +1,43 @@ +#[test] +#[cfg(feature = "glam")] +fn typescript_types_glam() { + use crate::ts::assert_ts; + + assert_ts!(glam::DVec2, "[number, number]"); + assert_ts!(glam::IVec2, "[number, number]"); + assert_ts!(glam::DMat2, "[number, number, number, number]"); + assert_ts!( + glam::DAffine2, + "[number, number, number, number, number, number]" + ); + assert_ts!(glam::Vec2, "[number, number]"); + assert_ts!(glam::Vec3, "[number, number, number]"); + assert_ts!(glam::Vec3A, "[number, number, number]"); + assert_ts!(glam::Vec4, "[number, number, number, number]"); + assert_ts!(glam::Mat2, "[number, number, number, number]"); + assert_ts!( + glam::Mat3, + "[number, number, number, number, number, number, number, number, number]" + ); + assert_ts!( + glam::Mat3A, + "[number, number, number, number, number, number, number, number, number]" + ); + assert_ts!(glam::Mat4, "[number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]"); + assert_ts!(glam::Quat, "[number, number, number, number]"); + assert_ts!( + glam::Affine2, + "[number, number, number, number, number, number]" + ); + assert_ts!(glam::Affine3A, "[number, number, number, number, number, number, number, number, number, number, number, number]"); +} + +#[test] +#[cfg(feature = "bevy_ecs")] +fn typescript_types_bevy_ecs() { + use specta::ts::ExportPath; + + use crate::ts::assert_ts; + + assert_ts!(error; bevy_ecs::entity::Entity, specta::ts::ExportError::BigIntForbidden(ExportPath::new_unsafe("bevy_ecs::entity::Entity -> u64"))); +} diff --git a/tests/ts.rs b/tests/ts.rs index d564d5d..e4698ac 100644 --- a/tests/ts.rs +++ b/tests/ts.rs @@ -280,9 +280,6 @@ fn typescript_types() { // https://github.com/oscartbeaumont/specta/issues/156 assert_ts!(Vec, r#"({ A: string } | { B: number })[]"#); - - #[cfg(feature = "glam")] - assert_ts!(glam::DVec2, "{ x: number; y: number }"); } #[derive(Type)]