Better TS type generation

This commit is contained in:
Gregory Schier
2024-08-08 22:07:05 -07:00
parent ed300dd320
commit 8081c86ec6
12 changed files with 45 additions and 65 deletions

View File

@@ -8,7 +8,6 @@ use ts_rs::TS;
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct Settings {
pub id: String,
#[ts(type = "\"settings\"")]
@@ -72,7 +71,6 @@ impl<'s> TryFrom<&Row<'s>> for Settings {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct Workspace {
pub id: String,
#[ts(type = "\"workspace\"")]
@@ -140,7 +138,6 @@ impl Workspace {
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[ts(export)]
enum CookieDomain {
HostOnly(String),
Suffix(String),
@@ -149,14 +146,12 @@ enum CookieDomain {
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[ts(export)]
enum CookieExpires {
AtUtc(String),
SessionEnd,
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[ts(export)]
pub struct Cookie {
raw_cookie: String,
domain: CookieDomain,
@@ -166,7 +161,6 @@ pub struct Cookie {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct CookieJar {
pub id: String,
#[ts(type = "\"cookie_jar\"")]
@@ -210,7 +204,6 @@ impl<'s> TryFrom<&Row<'s>> for CookieJar {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct Environment {
pub id: String,
pub workspace_id: String,
@@ -254,7 +247,6 @@ impl<'s> TryFrom<&Row<'s>> for Environment {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct EnvironmentVariable {
#[serde(default = "default_true")]
#[ts(optional, as = "Option<bool>")]
@@ -265,7 +257,6 @@ pub struct EnvironmentVariable {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct Folder {
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
@@ -311,7 +302,6 @@ impl<'s> TryFrom<&Row<'s>> for Folder {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct HttpRequestHeader {
#[serde(default = "default_true")]
#[ts(optional, as = "Option<bool>")]
@@ -322,7 +312,6 @@ pub struct HttpRequestHeader {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct HttpUrlParameter {
#[serde(default = "default_true")]
#[ts(optional, as = "Option<bool>")]
@@ -333,7 +322,6 @@ pub struct HttpUrlParameter {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct HttpRequest {
pub created_at: NaiveDateTime,
pub updated_at: NaiveDateTime,
@@ -410,7 +398,6 @@ impl<'s> TryFrom<&Row<'s>> for HttpRequest {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct HttpResponseHeader {
pub name: String,
pub value: String,
@@ -418,7 +405,6 @@ pub struct HttpResponseHeader {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct HttpResponse {
pub id: String,
#[ts(type = "\"http_response\"")]
@@ -501,7 +487,6 @@ impl HttpResponse {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct GrpcMetadataEntry {
#[serde(default = "default_true")]
#[ts(optional, as = "Option<bool>")]
@@ -512,7 +497,6 @@ pub struct GrpcMetadataEntry {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct GrpcRequest {
pub id: String,
#[ts(type = "\"grpc_request\"")]
@@ -582,7 +566,6 @@ impl<'s> TryFrom<&Row<'s>> for GrpcRequest {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct GrpcConnection {
pub id: String,
#[ts(type = "\"grpc_connection\"")]
@@ -644,7 +627,6 @@ impl<'s> TryFrom<&Row<'s>> for GrpcConnection {
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, TS)]
#[serde(rename_all = "snake_case")]
#[ts(export)]
pub enum GrpcEventType {
Info,
Error,
@@ -662,7 +644,6 @@ impl Default for GrpcEventType {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct GrpcEvent {
pub id: String,
#[ts(type = "\"grpc_event\"")]
@@ -720,7 +701,6 @@ impl<'s> TryFrom<&Row<'s>> for GrpcEvent {
#[derive(Debug, Clone, Serialize, Deserialize, Default, TS)]
#[serde(default, rename_all = "camelCase")]
#[ts(export)]
pub struct KeyValue {
#[ts(type = "\"key_value\"")]
pub model: String,

View File

@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use ts_rs::TS;
use yaak_models::models::{Environment, Folder, GrpcRequest, HttpRequest, HttpResponse, Workspace};
use yaak_models::models::{Environment, Folder, GrpcConnection, GrpcEvent, GrpcRequest, HttpRequest, HttpResponse, KeyValue, Workspace};
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[serde(rename_all = "camelCase")]
@@ -120,13 +120,16 @@ pub struct ImportResources {
}
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[serde(rename_all = "camelCase")]
#[serde(rename_all = "camelCase", untagged)]
#[ts(export)]
pub enum Model {
Workspace(Workspace),
Environment(Environment),
Folder(Folder),
GrpcConnection(GrpcConnection),
GrpcEvent(GrpcEvent),
GrpcRequest(GrpcRequest),
HttpRequest(HttpRequest),
HttpResponse(HttpResponse),
GrpcRequest(GrpcRequest),
KeyValue(KeyValue),
Workspace(Workspace),
}