Skip to main content

systemprompt_extension/
metadata.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
6pub struct ExtensionMetadata {
7    pub id: &'static str,
8    pub name: &'static str,
9    pub version: &'static str,
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct SchemaDefinition {
14    pub table: String,
15    pub sql: SchemaSource,
16    pub required_columns: Vec<String>,
17}
18
19impl SchemaDefinition {
20    #[must_use]
21    pub fn inline(table: impl Into<String>, sql: impl Into<String>) -> Self {
22        Self {
23            table: table.into(),
24            sql: SchemaSource::Inline(sql.into()),
25            required_columns: Vec::new(),
26        }
27    }
28
29    #[must_use]
30    pub fn file(table: impl Into<String>, path: impl Into<PathBuf>) -> Self {
31        Self {
32            table: table.into(),
33            sql: SchemaSource::File(path.into()),
34            required_columns: Vec::new(),
35        }
36    }
37
38    #[must_use]
39    pub fn with_required_columns(mut self, columns: Vec<String>) -> Self {
40        self.required_columns = columns;
41        self
42    }
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub enum SchemaSource {
47    Inline(String),
48    File(PathBuf),
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub enum SeedSource {
53    Inline(String),
54    File(PathBuf),
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct ExtensionRole {
59    pub name: String,
60    pub display_name: String,
61    pub description: String,
62    #[serde(default)]
63    pub permissions: Vec<String>,
64}
65
66impl ExtensionRole {
67    #[must_use]
68    pub fn new(
69        name: impl Into<String>,
70        display_name: impl Into<String>,
71        description: impl Into<String>,
72    ) -> Self {
73        Self {
74            name: name.into(),
75            display_name: display_name.into(),
76            description: description.into(),
77            permissions: Vec::new(),
78        }
79    }
80
81    #[must_use]
82    pub fn with_permissions(mut self, permissions: Vec<String>) -> Self {
83        self.permissions = permissions;
84        self
85    }
86}