Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 6b2affe

Browse files
author
Achim Schneider
committed
replace ts_rs with typescript-type-def
1 parent 52c5211 commit 6b2affe

File tree

9 files changed

+107
-73
lines changed

9 files changed

+107
-73
lines changed

Cargo.lock

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

crates/backend/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ clap = { version = "4.1.1" , features = [ "derive", "env" ]}
1414
serde_json = "1.0.91"
1515
serde = "1.0.152"
1616
actix-cors = "0.6.4"
17-
ts-rs = { version = "6.2.1", features = [
18-
"serde-compat",
19-
] }
17+
typescript-type-def = "0.5.5"
2018
futures = "0.3.25"
2119
hubcaps = "0.6.2"
2220
tokio-compat-02 = "0.2.0"

crates/backend/src/services/gist/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use serde::{
2222
Deserialize,
2323
Serialize,
2424
};
25-
use ts_rs::TS;
25+
use typescript_type_def::TypeDef;
2626

27-
#[derive(Deserialize, Serialize, TS, PartialEq, Debug, Clone, Eq)]
27+
#[derive(Deserialize, Serialize, TypeDef, PartialEq, Debug, Clone, Eq)]
2828
pub struct Gist {
2929
pub id: String,
3030
pub url: String,

crates/backend/src/services/gist/create.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ use serde::{
4444
};
4545
use std::collections::HashMap;
4646
use tokio_compat_02::FutureExt;
47-
use ts_rs::TS;
47+
use typescript_type_def::TypeDef;
4848

4949
// -------------------------------------------------------------------------------------------------
5050
// TYPES
5151
// -------------------------------------------------------------------------------------------------
5252

53-
#[derive(Deserialize, Serialize, TS, PartialEq, Debug, Clone, Eq)]
53+
#[derive(Deserialize, Serialize, TypeDef, PartialEq, Debug, Clone, Eq)]
5454
pub struct GistCreateRequest {
5555
pub code: String,
5656
}
5757

58-
#[derive(Deserialize, Serialize, TS, PartialEq, Debug, Clone, Eq)]
58+
#[derive(Deserialize, Serialize, TypeDef, PartialEq, Debug, Clone, Eq)]
5959
#[serde(tag = "type", content = "payload", rename_all = "SCREAMING_SNAKE_CASE")]
6060
pub enum GistCreateResponse {
6161
Success(Gist),

crates/backend/src/services/gist/load.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ use serde::{
3636
Serialize,
3737
};
3838
use tokio_compat_02::FutureExt;
39-
use ts_rs::TS;
39+
use typescript_type_def::TypeDef;
4040

4141
// -------------------------------------------------------------------------------------------------
4242
// TYPES
4343
// -------------------------------------------------------------------------------------------------
4444

45-
#[derive(Deserialize, Serialize, TS, PartialEq, Debug, Clone, Eq)]
45+
#[derive(Deserialize, Serialize, TypeDef, PartialEq, Debug, Clone, Eq)]
4646
pub struct GistLoadRequest {
4747
pub id: String,
4848
}
4949

50-
#[derive(Deserialize, Serialize, TS, PartialEq, Debug, Clone, Eq)]
50+
#[derive(Deserialize, Serialize, TypeDef, PartialEq, Debug, Clone, Eq)]
5151
#[serde(tag = "type", content = "payload", rename_all = "SCREAMING_SNAKE_CASE")]
5252
pub enum GistLoadResponse {
5353
Success(Gist),

crates/generate-bindings/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ readme = "README.md"
88

99
[dependencies]
1010
clap = { version = "4.1.1", features = [ "derive" ] }
11-
ts-rs = { version = "6.2.1", features = ["serde-compat" ] }
12-
serde = { version = "1.0.152", features = ["derive", "rc"] }
13-
quote = "1.0.23"
11+
serde = "1"
1412
backend = { path = "../backend" }
13+
typescript-type-def = "0.5.5"

crates/generate-bindings/src/main.rs

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -39,59 +39,31 @@ use backend::services::{
3939
},
4040
};
4141
use clap::Parser;
42-
use serde::Serialize;
43-
use ts_rs::TS;
42+
use std::fs::File;
43+
use typescript_type_def::write_definition_file;
4444

4545
fn main() -> std::io::Result<()> {
4646
let opts: Cli = Cli::parse();
47-
let target = opts.target;
48-
#[allow(unused_variables)]
47+
let target = opts.target.unwrap();
4948
let target = format!("{:?}/index.d.ts", &target);
5049

51-
#[derive(Serialize, TS)]
52-
#[ts(export)]
53-
#[ts(export_to = "${target}")]
54-
struct CompilationRequestWrapper(CompilationRequest);
55-
#[derive(Serialize, TS)]
56-
#[ts(export)]
57-
#[ts(export_to = "${target}")]
58-
struct CompilationResultWrapper(CompilationResult);
59-
#[derive(Serialize, TS)]
60-
#[ts(export)]
61-
#[ts(export_to = "${target}")]
62-
struct TestingRequestWrapper(TestingRequest);
63-
#[derive(Serialize, TS)]
64-
#[ts(export)]
65-
#[ts(export_to = "${target}")]
66-
struct TestingResultWrapper(TestingResult);
67-
#[derive(Serialize, TS)]
68-
#[ts(export)]
69-
#[ts(export_to = "${target}")]
70-
struct FormattingResultWrapper(FormattingResult);
71-
#[derive(Serialize, TS)]
72-
#[ts(export)]
73-
#[ts(export_to = "${target}")]
74-
struct FormattingRequestWrapper(FormattingRequest);
75-
#[derive(Serialize, TS)]
76-
#[ts(export)]
77-
#[ts(export_to = "${target}")]
78-
struct GistWrapper(Gist);
79-
#[derive(Serialize, TS)]
80-
#[ts(export)]
81-
#[ts(export_to = "${target}")]
82-
struct GistLoadResponseWrapper(GistLoadResponse);
83-
#[derive(Serialize, TS)]
84-
#[ts(export)]
85-
#[ts(export_to = "${target}")]
86-
struct GistLoadRequestWrapper(GistLoadRequest);
87-
#[derive(Serialize, TS)]
88-
#[ts(export)]
89-
#[ts(export_to = "${target}")]
90-
struct GistCreateResponseWrapper(GistCreateResponse);
91-
#[derive(Serialize, TS)]
92-
#[ts(export)]
93-
#[ts(export_to = "${target}")]
94-
struct GistCreateRequestWrapper(GistCreateRequest);
50+
type Api = (
51+
CompilationResult,
52+
CompilationRequest,
53+
TestingRequest,
54+
TestingResult,
55+
FormattingRequest,
56+
FormattingResult,
57+
Gist,
58+
GistLoadRequest,
59+
GistLoadResponse,
60+
GistCreateRequest,
61+
GistCreateResponse,
62+
);
63+
64+
let buffer = File::create(&target)?;
65+
66+
write_definition_file::<_, Api>(&buffer, Default::default()).unwrap();
9567

9668
Ok(())
9769
}

crates/sandbox/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ tokio = { version = "1.24.1", features = [
1919
] }
2020
ts-rs = { version = "6.2.1", features = [
2121
"serde-compat",
22-
] }
22+
] }
23+
typescript-type-def = "0.5.5"

crates/sandbox/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use std::{
5757
};
5858
use tempdir::TempDir;
5959
use tokio::process::Command;
60-
use ts_rs::TS;
60+
use typescript_type_def::TypeDef;
6161

6262
// -------------------------------------------------------------------------------------------------
6363
// TYPES
@@ -117,12 +117,12 @@ pub enum Error {
117117

118118
pub type Result<T, E = Error> = std::result::Result<T, E>;
119119

120-
#[derive(Deserialize, Serialize, TS, Debug, Clone)]
120+
#[derive(Deserialize, Serialize, TypeDef, Debug, Clone)]
121121
pub struct CompilationRequest {
122122
pub source: String,
123123
}
124124

125-
#[derive(Deserialize, Serialize, TS, PartialEq, Debug, Clone, Eq)]
125+
#[derive(Deserialize, Serialize, TypeDef, PartialEq, Debug, Clone, Eq)]
126126
#[serde(tag = "type", content = "payload", rename_all = "SCREAMING_SNAKE_CASE")]
127127
pub enum CompilationResult {
128128
Success {
@@ -136,24 +136,24 @@ pub enum CompilationResult {
136136
},
137137
}
138138

139-
#[derive(Deserialize, Serialize, TS, Debug, Clone)]
139+
#[derive(Deserialize, Serialize, TypeDef, Debug, Clone)]
140140
pub struct TestingRequest {
141141
pub source: String,
142142
}
143143

144-
#[derive(Deserialize, Serialize, TS, PartialEq, Debug, Clone, Eq)]
144+
#[derive(Deserialize, Serialize, TypeDef, PartialEq, Debug, Clone, Eq)]
145145
#[serde(tag = "type", content = "payload", rename_all = "SCREAMING_SNAKE_CASE")]
146146
pub enum TestingResult {
147147
Success { stdout: String, stderr: String },
148148
Error { stdout: String, stderr: String },
149149
}
150150

151-
#[derive(Deserialize, Serialize, TS, Debug, Clone)]
151+
#[derive(Deserialize, Serialize, TypeDef, Debug, Clone)]
152152
pub struct FormattingRequest {
153153
pub source: String,
154154
}
155155

156-
#[derive(Deserialize, Serialize, TS, PartialEq, Debug, Clone, Eq)]
156+
#[derive(Deserialize, Serialize, TypeDef, PartialEq, Debug, Clone, Eq)]
157157
#[serde(tag = "type", content = "payload", rename_all = "SCREAMING_SNAKE_CASE")]
158158
pub enum FormattingResult {
159159
Success { source: String, stderr: String },

0 commit comments

Comments
 (0)