feat(database): add DatabaseInterface.ts with abstract class for CRUD operations
This commit is contained in:
@@ -0,0 +1,290 @@
|
||||
export type User = {
|
||||
id: string;
|
||||
email: string;
|
||||
password_hash: string;
|
||||
display_name: string;
|
||||
role: string;
|
||||
is_active: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
|
||||
export type Session = {
|
||||
id: string;
|
||||
user_id: string;
|
||||
token_hash: string;
|
||||
expires_at: string;
|
||||
created_at?: string;
|
||||
ip_address?: string;
|
||||
user_agent?: string;
|
||||
};
|
||||
|
||||
export type Project = {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
owner_id: string;
|
||||
units: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
thumbnail_path?: string;
|
||||
};
|
||||
|
||||
export type ProjectMember = {
|
||||
id: string;
|
||||
project_id: string;
|
||||
user_id: string;
|
||||
role: string;
|
||||
invited_at?: string;
|
||||
accepted_at?: string;
|
||||
};
|
||||
|
||||
export type Layer = {
|
||||
id: string;
|
||||
project_id: string;
|
||||
name: string;
|
||||
visible: number;
|
||||
locked: number;
|
||||
color?: string;
|
||||
line_type?: string;
|
||||
transparency: number;
|
||||
sort_order: number;
|
||||
created_at?: string;
|
||||
};
|
||||
|
||||
export type Element = {
|
||||
id: string;
|
||||
project_id: string;
|
||||
layer_id?: string;
|
||||
element_type: string;
|
||||
geometry: string;
|
||||
style?: string;
|
||||
metadata?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
|
||||
export type Block = {
|
||||
id: string;
|
||||
project_id: string;
|
||||
name: string;
|
||||
base_element_ids: string;
|
||||
created_at?: string;
|
||||
};
|
||||
|
||||
export type BlockInstance = {
|
||||
id: string;
|
||||
project_id: string;
|
||||
block_id: string;
|
||||
layer_id?: string;
|
||||
position_x: number;
|
||||
position_y: number;
|
||||
rotation: number;
|
||||
scale_x: number;
|
||||
scale_y: number;
|
||||
created_at?: string;
|
||||
};
|
||||
|
||||
export type BackgroundImage = {
|
||||
id: string;
|
||||
project_id: string;
|
||||
file_path: string;
|
||||
position_x: number;
|
||||
position_y: number;
|
||||
scale: number;
|
||||
rotation: number;
|
||||
opacity: number;
|
||||
created_at?: string;
|
||||
};
|
||||
|
||||
export type Version = {
|
||||
id: string;
|
||||
project_id: string;
|
||||
label?: string;
|
||||
description?: string;
|
||||
snapshot_data: Buffer;
|
||||
created_by?: string;
|
||||
created_at?: string;
|
||||
};
|
||||
|
||||
export type Plugin = {
|
||||
id: string;
|
||||
name: string;
|
||||
version: string;
|
||||
display_name: string;
|
||||
description?: string;
|
||||
manifest: string;
|
||||
is_active: number;
|
||||
installed_at?: string;
|
||||
activated_at?: string;
|
||||
};
|
||||
|
||||
export type Setting = {
|
||||
id: string;
|
||||
user_id?: string;
|
||||
key: string;
|
||||
value: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
|
||||
export type AIConfig = {
|
||||
id: string;
|
||||
scope: string;
|
||||
project_id?: string;
|
||||
api_base_url?: string;
|
||||
api_key_encrypted?: string;
|
||||
model: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
};
|
||||
|
||||
export type Webhook = {
|
||||
id: string;
|
||||
project_id: string;
|
||||
url: string;
|
||||
event: string;
|
||||
is_active: number;
|
||||
created_at?: string;
|
||||
};
|
||||
|
||||
export type AuditLog = {
|
||||
id: string;
|
||||
user_id?: string;
|
||||
project_id?: string;
|
||||
action: string;
|
||||
details?: string;
|
||||
ip_address?: string;
|
||||
created_at?: string;
|
||||
};
|
||||
|
||||
export interface DatabaseInterface {
|
||||
// Users
|
||||
createUser(user: Omit<User, 'id'>): Promise<User>;
|
||||
getUserById(id: string): Promise<User | null>;
|
||||
getUserByEmail(email: string): Promise<User | null>;
|
||||
updateUser(id: string, updates: Partial<User>): Promise<User>;
|
||||
deleteUser(id: string): Promise<boolean>;
|
||||
getAllUsers(): Promise<User[]>;
|
||||
|
||||
// Sessions
|
||||
createSession(session: Omit<Session, 'id'>): Promise<Session>;
|
||||
getSessionById(id: string): Promise<Session | null>;
|
||||
getSessionByToken(token_hash: string): Promise<Session | null>;
|
||||
updateSession(id: string, updates: Partial<Session>): Promise<Session>;
|
||||
deleteSession(id: string): Promise<boolean>;
|
||||
deleteExpiredSessions(): Promise<number>;
|
||||
|
||||
// Projects
|
||||
createProject(project: Omit<Project, 'id' | 'created_at' | 'updated_at'>): Promise<Project>;
|
||||
getProjectById(id: string): Promise<Project | null>;
|
||||
getProjectsByOwner(owner_id: string): Promise<Project[]>;
|
||||
updateProject(id: string, updates: Partial<Project>): Promise<Project>;
|
||||
deleteProject(id: string): Promise<boolean>;
|
||||
getAllProjects(): Promise<Project[]>;
|
||||
|
||||
// Project Members
|
||||
createProjectMember(member: Omit<ProjectMember, 'id'>): Promise<ProjectMember>;
|
||||
getProjectMemberById(id: string): Promise<ProjectMember | null>;
|
||||
getProjectMembers(project_id: string): Promise<ProjectMember[]>;
|
||||
updateProjectMember(id: string, updates: Partial<ProjectMember>): Promise<ProjectMember>;
|
||||
deleteProjectMember(id: string): Promise<boolean>;
|
||||
isProjectMember(project_id: string, user_id: string): Promise<boolean>;
|
||||
|
||||
// Layers
|
||||
createLayer(layer: Omit<Layer, 'id'>): Promise<Layer>;
|
||||
getLayerById(id: string): Promise<Layer | null>;
|
||||
getLayersByProject(project_id: string): Promise<Layer[]>;
|
||||
updateLayer(id: string, updates: Partial<Layer>): Promise<Layer>;
|
||||
deleteLayer(id: string): Promise<boolean>;
|
||||
getAllLayers(): Promise<Layer[]>;
|
||||
|
||||
// Elements
|
||||
createElement(element: Omit<Element, 'id'>): Promise<Element>;
|
||||
getElementById(id: string): Promise<Element | null>;
|
||||
getElementsByProject(project_id: string): Promise<Element[]>;
|
||||
getElementsByLayer(layer_id: string): Promise<Element[]>;
|
||||
updateElement(id: string, updates: Partial<Element>): Promise<Element>;
|
||||
deleteElement(id: string): Promise<boolean>;
|
||||
getAllElements(): Promise<Element[]>;
|
||||
|
||||
// Blocks
|
||||
createBlock(block: Omit<Block, 'id'>): Promise<Block>;
|
||||
getBlockById(id: string): Promise<Block | null>;
|
||||
getBlocksByProject(project_id: string): Promise<Block[]>;
|
||||
updateBlock(id: string, updates: Partial<Block>): Promise<Block>;
|
||||
deleteBlock(id: string): Promise<boolean>;
|
||||
getAllBlocks(): Promise<Block[]>;
|
||||
|
||||
// Block Instances
|
||||
createBlockInstance(instance: Omit<BlockInstance, 'id'>): Promise<BlockInstance>;
|
||||
getBlockInstanceById(id: string): Promise<BlockInstance | null>;
|
||||
getBlockInstancesByProject(project_id: string): Promise<BlockInstance[]>;
|
||||
getBlockInstancesByBlock(block_id: string): Promise<BlockInstance[]>;
|
||||
updateBlockInstance(id: string, updates: Partial<BlockInstance>): Promise<BlockInstance>;
|
||||
deleteBlockInstance(id: string): Promise<boolean>;
|
||||
getAllBlockInstances(): Promise<BlockInstance[]>;
|
||||
|
||||
// Background Images
|
||||
createBackgroundImage(image: Omit<BackgroundImage, 'id'>): Promise<BackgroundImage>;
|
||||
getBackgroundImageById(id: string): Promise<BackgroundImage | null>;
|
||||
getBackgroundImagesByProject(project_id: string): Promise<BackgroundImage[]>;
|
||||
updateBackgroundImage(id: string, updates: Partial<BackgroundImage>): Promise<BackgroundImage>;
|
||||
deleteBackgroundImage(id: string): Promise<boolean>;
|
||||
getAllBackgroundImages(): Promise<BackgroundImage[]>;
|
||||
|
||||
// Versions
|
||||
createVersion(version: Omit<Version, 'id'>): Promise<Version>;
|
||||
getVersionById(id: string): Promise<Version | null>;
|
||||
getVersionsByProject(project_id: string): Promise<Version[]>;
|
||||
updateVersion(id: string, updates: Partial<Version>): Promise<Version>;
|
||||
deleteVersion(id: string): Promise<boolean>;
|
||||
getAllVersions(): Promise<Version[]>;
|
||||
|
||||
// Plugins
|
||||
createPlugin(plugin: Omit<Plugin, 'id' | 'installed_at' | 'activated_at'>): Promise<Plugin>;
|
||||
getPluginById(id: string): Promise<Plugin | null>;
|
||||
getPluginByName(name: string): Promise<Plugin | null>;
|
||||
updatePlugin(id: string, updates: Partial<Plugin>): Promise<Plugin>;
|
||||
deletePlugin(id: string): Promise<boolean>;
|
||||
getAllPlugins(): Promise<Plugin[]>;
|
||||
getActivePlugins(): Promise<Plugin[]>;
|
||||
|
||||
// Settings
|
||||
createSetting(setting: Omit<Setting, 'id'>): Promise<Setting>;
|
||||
getSettingById(id: string): Promise<Setting | null>;
|
||||
getSettingByKey(key: string, user_id?: string): Promise<Setting | null>;
|
||||
updateSetting(id: string, updates: Partial<Setting>): Promise<Setting>;
|
||||
deleteSetting(id: string): Promise<boolean>;
|
||||
getAllSettings(): Promise<Setting[]>;
|
||||
|
||||
// AI Config
|
||||
createAIConfig(config: Omit<AIConfig, 'id'>): Promise<AIConfig>;
|
||||
getAIConfigById(id: string): Promise<AIConfig | null>;
|
||||
getAIConfigByProject(project_id: string): Promise<AIConfig | null>;
|
||||
updateAIConfig(id: string, updates: Partial<AIConfig>): Promise<AIConfig>;
|
||||
deleteAIConfig(id: string): Promise<boolean>;
|
||||
getAllAIConfigs(): Promise<AIConfig[]>;
|
||||
|
||||
// Webhooks
|
||||
createWebhook(webhook: Omit<Webhook, 'id'>): Promise<Webhook>;
|
||||
getWebhookById(id: string): Promise<Webhook | null>;
|
||||
getWebhooksByProject(project_id: string): Promise<Webhook[]>;
|
||||
updateWebhook(id: string, updates: Partial<Webhook>): Promise<Webhook>;
|
||||
deleteWebhook(id: string): Promise<boolean>;
|
||||
getAllWebhooks(): Promise<Webhook[]>;
|
||||
|
||||
// Audit Log
|
||||
createAuditLog(log: Omit<AuditLog, 'id'>): Promise<AuditLog>;
|
||||
getAuditLogById(id: string): Promise<AuditLog | null>;
|
||||
getAuditLogsByUser(user_id: string): Promise<AuditLog[]>;
|
||||
getAuditLogsByProject(project_id: string): Promise<AuditLog[]>;
|
||||
getAllAuditLogs(): Promise<AuditLog[]>;
|
||||
|
||||
// Migration
|
||||
runMigration(migrationScript: string): Promise<void>;
|
||||
getMigrationVersion(): Promise<number>;
|
||||
setMigrationVersion(version: number): Promise<void>;
|
||||
|
||||
// Utility
|
||||
close(): Promise<void>;
|
||||
}
|
||||
Reference in New Issue
Block a user