Skip to main content

time_tracker_plugin_sdk/
extensions.rs

1//! Extension types for plugins to extend Core entities
2
3/// Entity types that can be extended
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum EntityType {
6    Activity,
7    ManualEntry,
8    Category,
9}
10
11/// Types of extensions
12#[derive(Debug, Clone, PartialEq)]
13pub enum ExtensionType {
14    DatabaseSchema,
15    Model,
16    DataHook,
17    Query,
18    UIForm,
19}
20
21/// Schema change operations
22#[derive(Debug, Clone)]
23pub enum SchemaChange {
24    /// Create a new table
25    CreateTable {
26        table: String,
27        columns: Vec<TableColumn>,
28    },
29    /// Add a column to an existing table
30    AddColumn {
31        table: String,
32        column: String,
33        column_type: String,
34        default: Option<String>,
35        foreign_key: Option<ForeignKey>,
36    },
37    /// Add an index
38    AddIndex {
39        table: String,
40        index: String,
41        columns: Vec<String>,
42    },
43    /// Add a foreign key constraint
44    AddForeignKey {
45        table: String,
46        column: String,
47        foreign_table: String,
48        foreign_column: String,
49    },
50}
51
52/// Table column definition for CreateTable
53#[derive(Debug, Clone)]
54pub struct TableColumn {
55    pub name: String,
56    pub column_type: String,
57    pub primary_key: bool,
58    pub nullable: bool,
59    pub default: Option<String>,
60    pub foreign_key: Option<ForeignKey>,
61}
62
63/// Foreign key definition
64#[derive(Debug, Clone)]
65pub struct ForeignKey {
66    pub table: String,
67    pub column: String,
68}
69
70/// Model field definition
71#[derive(Debug, Clone)]
72pub struct ModelField {
73    pub name: String,
74    pub type_: String,
75    pub optional: bool,
76}
77
78/// Query filter function type
79pub type QueryFilterFn = Box<dyn Fn(Vec<serde_json::Value>, std::collections::HashMap<String, serde_json::Value>) -> Result<Vec<serde_json::Value>, String> + Send + Sync>;
80
81/// Query filter
82pub struct QueryFilter {
83    pub name: String,
84    pub filter_fn: QueryFilterFn,
85}
86
87impl std::fmt::Debug for QueryFilter {
88    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89        f.debug_struct("QueryFilter")
90            .field("name", &self.name)
91            .field("filter_fn", &"<function>")
92            .finish()
93    }
94}
95
96/// Schema extension definition (used by plugins to declare their schema)
97#[derive(Debug, Clone)]
98pub struct SchemaExtension {
99    pub entity_type: EntityType,
100    pub schema_changes: Vec<SchemaChange>,
101}