add additional typescript type gen from core

This commit is contained in:
mbecker20
2022-12-18 06:00:23 +00:00
parent 090c4a6dc7
commit 11a4379fb6
10 changed files with 97 additions and 20 deletions

2
.vscode/tasks.json vendored
View File

@@ -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": []
}

1
Cargo.lock generated
View File

@@ -369,6 +369,7 @@ dependencies = [
"tokio-util",
"tower",
"tower-http",
"typeshare",
]
[[package]]

View File

@@ -31,4 +31,5 @@ hmac = "0.12"
sha2 = "0.10"
async_timing_util = "0.1.12"
futures-util = "0.3"
diff-struct = "0.5"
diff-struct = "0.5"
typeshare = "1.0.0"

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,
}

View File

@@ -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<String>,
}
#[derive(Deserialize)]
#[typeshare]
#[derive(Serialize, Deserialize)]
struct DeleteSecretPath {
name: String,
}

View File

@@ -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,

58
frontend/src/util/client_types.d.ts vendored Normal file
View File

@@ -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;
}