mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-07-03 19:41:48 +02:00
Split codebase (#455)
This commit is contained in:
@@ -1,34 +1,16 @@
|
||||
use crate::db_context::DbContext;
|
||||
use crate::client_db::ClientDb;
|
||||
use crate::error::Result;
|
||||
use crate::models::{
|
||||
AnyModel, Environment, Folder, GrpcRequest, HttpRequest, UpsertModelInfo, WebsocketRequest,
|
||||
Workspace, WorkspaceIden,
|
||||
};
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
use nanoid::nanoid;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use ts_rs::TS;
|
||||
use yaak_core::WorkspaceContext;
|
||||
|
||||
pub fn generate_prefixed_id(prefix: &str) -> String {
|
||||
format!("{prefix}_{}", generate_id())
|
||||
}
|
||||
|
||||
pub fn generate_id() -> String {
|
||||
generate_id_of_length(10)
|
||||
}
|
||||
|
||||
pub fn generate_id_of_length(n: usize) -> String {
|
||||
let alphabet: [char; 57] = [
|
||||
'2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||
'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C',
|
||||
'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z',
|
||||
];
|
||||
|
||||
nanoid!(n, &alphabet)
|
||||
}
|
||||
pub use yaak_database::{ModelChangeEvent, generate_id, generate_id_of_length, generate_prefixed_id};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -39,14 +21,6 @@ pub struct ModelPayload {
|
||||
pub change: ModelChangeEvent,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
#[ts(export, export_to = "gen_models.ts")]
|
||||
pub enum ModelChangeEvent {
|
||||
Upsert { created: bool },
|
||||
Delete,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
#[serde(rename_all = "snake_case", tag = "type")]
|
||||
#[ts(export, export_to = "gen_models.ts")]
|
||||
@@ -62,6 +36,30 @@ impl UpdateSource {
|
||||
pub fn from_window_label(label: impl Into<String>) -> Self {
|
||||
Self::Window { label: label.into() }
|
||||
}
|
||||
|
||||
pub fn to_db(&self) -> yaak_database::UpdateSource {
|
||||
match self {
|
||||
UpdateSource::Background => yaak_database::UpdateSource::Background,
|
||||
UpdateSource::Import => yaak_database::UpdateSource::Import,
|
||||
UpdateSource::Plugin => yaak_database::UpdateSource::Plugin,
|
||||
UpdateSource::Sync => yaak_database::UpdateSource::Sync,
|
||||
UpdateSource::Window { label } => {
|
||||
yaak_database::UpdateSource::Window { label: label.clone() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<yaak_database::UpdateSource> for UpdateSource {
|
||||
fn from(source: yaak_database::UpdateSource) -> Self {
|
||||
match source {
|
||||
yaak_database::UpdateSource::Background => UpdateSource::Background,
|
||||
yaak_database::UpdateSource::Import => UpdateSource::Import,
|
||||
yaak_database::UpdateSource::Plugin => UpdateSource::Plugin,
|
||||
yaak_database::UpdateSource::Sync => UpdateSource::Sync,
|
||||
yaak_database::UpdateSource::Window { label } => UpdateSource::Window { label },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Deserialize, Serialize)]
|
||||
@@ -86,7 +84,7 @@ pub struct BatchUpsertResult {
|
||||
}
|
||||
|
||||
pub fn get_workspace_export_resources(
|
||||
db: &DbContext,
|
||||
db: &ClientDb,
|
||||
yaak_version: &str,
|
||||
workspace_ids: Vec<&str>,
|
||||
include_private_environments: bool,
|
||||
|
||||
Reference in New Issue
Block a user