Skip to main content

systemprompt_extension/
metadata.rs

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