Skip to content

Commit 766bb5e

Browse files
authored
Add ts-rs cargo feature to derive ts-rs (#708)
* Add ts-rs cargo feature to derive ts-rs * Add derive PartialEq for all modeling commands * Fix empty variant structs to have a field to work with ts-rs
1 parent 7d3f93e commit 766bb5e

File tree

21 files changed

+605
-143
lines changed

21 files changed

+605
-143
lines changed

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modeling-cmds-macros-impl/src/modeling_cmd_enum.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ pub fn generate(input: ItemMod) -> TokenStream {
5454
/// Definition of each modeling command.
5555
#input
5656
/// Commands that the KittyCAD engine can execute.
57-
#[derive(Debug, Clone, Serialize, Deserialize)]
57+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5858
#[cfg_attr(feature = "derive-jsonschema-on-enums", derive(schemars::JsonSchema))]
5959
#[serde(rename_all = "snake_case", tag = "type")]
60+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
61+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
6062
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
6163
pub enum ModelingCmd {#(
6264
#[doc = #docs]

modeling-cmds/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ serde_bytes = "0.11.15"
3636
serde_json = { version = "1.0.134", optional = true }
3737
slog = { version = "2.7.0", optional = true }
3838
tabled = { version = "0.17", optional = true }
39+
ts-rs = { version = "10.1.0", optional = true, features = [
40+
"uuid-impl",
41+
"no-serde-warnings",
42+
"serde-json-impl",
43+
] }
3944
uuid = { version = "1.11.0", features = ["serde", "v4", "js"] }
4045
webrtc = { version = "0.11", optional = true }
4146

@@ -46,6 +51,7 @@ workspace = true
4651
default = []
4752
derive-jsonschema-on-enums = []
4853
tabled = ["dep:tabled"]
54+
ts-rs = ["dep:ts-rs"]
4955
slog = ["dep:slog"]
5056
cxx = ["dep:cxx"]
5157
convert_client_crate = ["dep:kittycad"]

modeling-cmds/src/coord.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
1010
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
1111
#[serde(rename_all = "snake_case")]
1212
#[display(style = "snake_case")]
13+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
14+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
1315
pub enum Axis {
1416
/// 'Y' axis.
1517
Y = 1,
@@ -21,6 +23,8 @@ pub enum Axis {
2123
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
2224
#[serde(rename_all = "snake_case")]
2325
#[display(style = "snake_case")]
26+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
27+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
2428
pub enum Direction {
2529
/// Increasing numbers.
2630
Positive = 1,
@@ -42,6 +46,8 @@ impl std::ops::Mul for Direction {
4246
/// An [`Axis`] paired with a [`Direction`].
4347
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
4448
#[display("({axis}, {direction})")]
49+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
50+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
4551
pub struct AxisDirectionPair {
4652
/// Axis specifier.
4753
pub axis: Axis,
@@ -59,6 +65,8 @@ pub struct AxisDirectionPair {
5965
/// [cglearn.eu](https://cglearn.eu/pub/computer-graphics/introduction-to-geometry#material-coordinate-systems-1)
6066
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
6167
#[display("forward: {forward}, up: {up}")]
68+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
69+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
6270
pub struct System {
6371
/// Axis the front face of a model looks along.
6472
pub forward: AxisDirectionPair,

0 commit comments

Comments
 (0)