diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 9ec854093..f27913d07 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -132,7 +132,7 @@ }, { "type": "shell", - "command": "typeshare ./lib/types --lang=typescript --output-file=./frontend/src/types.d.ts", + "command": "typeshare ./lib/types --lang=typescript --output-file=./frontend/src/types.d.ts && typeshare ./core --lang=typescript --output-file=./frontend/src/util/client_types.d.ts", "label": "generate typescript types", "problemMatcher": [] } diff --git a/Cargo.lock b/Cargo.lock index 2678505c8..61c95aeda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -369,6 +369,7 @@ dependencies = [ "tokio-util", "tower", "tower-http", + "typeshare", ] [[package]] diff --git a/core/Cargo.toml b/core/Cargo.toml index c812280f8..cefd2aa69 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -31,4 +31,5 @@ hmac = "0.12" sha2 = "0.10" async_timing_util = "0.1.12" futures-util = "0.3" -diff-struct = "0.5" \ No newline at end of file +diff-struct = "0.5" +typeshare = "1.0.0" \ No newline at end of file diff --git a/core/src/api/build.rs b/core/src/api/build.rs index 79fe8a1a7..2f04c6ed8 100644 --- a/core/src/api/build.rs +++ b/core/src/api/build.rs @@ -5,8 +5,9 @@ use axum::{ Extension, Json, Router, }; use helpers::handle_anyhow_error; -use mungos::{Deserialize, Document}; +use mungos::{Deserialize, Document, Serialize}; use types::{traits::Permissioned, Build, PermissionLevel}; +use typeshare::typeshare; use crate::{ auth::{RequestUser, RequestUserExtension}, @@ -14,12 +15,14 @@ use crate::{ state::{State, StateExtension}, }; -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] struct BuildId { id: String, } -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] struct CreateBuildBody { name: String, server_id: String, diff --git a/core/src/api/deployment.rs b/core/src/api/deployment.rs index 1b6d790aa..a58df733a 100644 --- a/core/src/api/deployment.rs +++ b/core/src/api/deployment.rs @@ -8,8 +8,9 @@ use axum::{ }; use futures_util::future::join_all; use helpers::handle_anyhow_error; -use mungos::{Deserialize, Document}; +use mungos::{Deserialize, Document, Serialize}; use types::{traits::Permissioned, Deployment, DeploymentWithContainer, PermissionLevel, Server}; +use typeshare::typeshare; use crate::{ auth::{RequestUser, RequestUserExtension}, @@ -17,12 +18,14 @@ use crate::{ state::{State, StateExtension}, }; -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] pub struct DeploymentId { id: String, } -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] pub struct CreateDeploymentBody { name: String, server_id: String, diff --git a/core/src/api/permissions.rs b/core/src/api/permissions.rs index 027dd721a..7bcb42f8d 100644 --- a/core/src/api/permissions.rs +++ b/core/src/api/permissions.rs @@ -1,12 +1,14 @@ use anyhow::{anyhow, Context}; use axum::{routing::post, Extension, Json, Router}; use helpers::handle_anyhow_error; -use mungos::{doc, Deserialize, Document, Update}; +use mungos::{doc, Deserialize, Document, Update, Serialize}; use types::{Build, Deployment, PermissionLevel, PermissionsTarget, Server}; +use typeshare::typeshare; use crate::{auth::RequestUserExtension, state::StateExtension}; -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] struct PermissionsUpdateBody { user_id: String, permission: PermissionLevel, @@ -14,7 +16,8 @@ struct PermissionsUpdateBody { target_id: String, } -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] struct ModifyUserEnabledBody { user_id: String, enabled: bool, diff --git a/core/src/api/procedure.rs b/core/src/api/procedure.rs index c28501f21..ba8239efb 100644 --- a/core/src/api/procedure.rs +++ b/core/src/api/procedure.rs @@ -5,8 +5,9 @@ use axum::{ Extension, Json, Router, }; use helpers::handle_anyhow_error; -use mungos::{Deserialize, Document}; +use mungos::{Deserialize, Document, Serialize}; use types::{traits::Permissioned, PermissionLevel, Procedure}; +use typeshare::typeshare; use crate::{ auth::{RequestUser, RequestUserExtension}, @@ -14,12 +15,13 @@ use crate::{ state::{State, StateExtension}, }; -#[derive(Deserialize)] +#[derive(Serialize, Deserialize)] pub struct ProcedureId { id: String, } -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] pub struct CreateProcedureBody { name: String, } diff --git a/core/src/api/secret.rs b/core/src/api/secret.rs index 9f979c764..c6484de73 100644 --- a/core/src/api/secret.rs +++ b/core/src/api/secret.rs @@ -5,21 +5,24 @@ use axum::{ Extension, Json, Router, }; use helpers::{generate_secret, handle_anyhow_error}; -use mungos::{doc, to_bson, Deserialize, Document, Update}; +use mungos::{doc, to_bson, Deserialize, Document, Update, Serialize}; use types::{monitor_timestamp, ApiSecret}; +use typeshare::typeshare; use crate::{auth::RequestUserExtension, state::StateExtension}; const SECRET_LENGTH: usize = 40; const BCRYPT_COST: u32 = 10; -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] struct CreateSecretBody { name: String, expires: Option, } -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] struct DeleteSecretPath { name: String, } diff --git a/core/src/api/server.rs b/core/src/api/server.rs index f272c71f6..d191bc999 100644 --- a/core/src/api/server.rs +++ b/core/src/api/server.rs @@ -5,11 +5,12 @@ use axum::{ Extension, Json, Router, }; use helpers::handle_anyhow_error; -use mungos::{Deserialize, Document}; +use mungos::{Deserialize, Document, Serialize}; use types::{ traits::Permissioned, BasicContainerInfo, ImageSummary, Log, Network, PermissionLevel, Server, SystemStats, }; +use typeshare::typeshare; use crate::{ auth::{RequestUser, RequestUserExtension}, @@ -17,12 +18,14 @@ use crate::{ state::{State, StateExtension}, }; -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] struct ServerId { id: String, } -#[derive(Deserialize)] +#[typeshare] +#[derive(Serialize, Deserialize)] pub struct CreateServerBody { name: String, address: String, diff --git a/frontend/src/util/client_types.d.ts b/frontend/src/util/client_types.d.ts new file mode 100644 index 000000000..759354e55 --- /dev/null +++ b/frontend/src/util/client_types.d.ts @@ -0,0 +1,58 @@ +/* + Generated by typeshare 1.0.0 +*/ + +import { PermissionLevel, PermissionsTarget } from "../types"; + +export interface BuildId { + id: string; +} + +export interface CreateBuildBody { + name: string; + server_id: string; +} + +export interface DeploymentId { + id: string; +} + +export interface CreateDeploymentBody { + name: string; + server_id: string; +} + +export interface PermissionsUpdateBody { + user_id: string; + permission: PermissionLevel; + target_type: PermissionsTarget; + target_id: string; +} + +export interface ModifyUserEnabledBody { + user_id: string; + enabled: boolean; +} + +export interface CreateProcedureBody { + name: string; +} + +export interface CreateSecretBody { + name: string; + expires?: string; +} + +export interface DeleteSecretPath { + name: string; +} + +export interface ServerId { + id: string; +} + +export interface CreateServerBody { + name: string; + address: string; +} +