Skip to main content

fiberplane_models/
workspaces.rs

1pub use crate::labels::Label;
2use crate::names::Name;
3use crate::timestamps::Timestamp;
4use crate::{data_sources::SelectedDataSources, front_matter_schemas::FrontMatterSchema};
5use base64uuid::Base64Uuid;
6#[cfg(feature = "fp-bindgen")]
7use fp_bindgen::prelude::Serializable;
8use serde::{Deserialize, Serialize};
9use std::collections::BTreeMap;
10use strum_macros::Display;
11use typed_builder::TypedBuilder;
12
13/// Workspace representation.
14#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TypedBuilder)]
15#[cfg_attr(
16    feature = "fp-bindgen",
17    derive(Serializable),
18    fp(rust_module = "fiberplane_models::workspaces")
19)]
20#[non_exhaustive]
21#[serde(rename_all = "camelCase")]
22pub struct Workspace {
23    #[builder(setter(into))]
24    pub id: Base64Uuid,
25
26    pub name: Name,
27
28    #[builder(setter(into))]
29    pub display_name: String,
30
31    #[serde(rename = "type")]
32    pub ty: WorkspaceType,
33
34    #[builder(setter(into))]
35    pub owner_id: Base64Uuid,
36
37    #[builder(default)]
38    pub default_data_sources: SelectedDataSources,
39
40    #[builder(setter(into))]
41    pub created_at: Timestamp,
42
43    #[builder(setter(into))]
44    pub updated_at: Timestamp,
45
46    #[builder(default)]
47    pub front_matter_schemas: BTreeMap<String, FrontMatterSchema>,
48}
49
50#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, Display)]
51#[cfg_attr(
52    feature = "fp-bindgen",
53    derive(Serializable),
54    fp(rust_module = "fiberplane_models::workspaces")
55)]
56#[non_exhaustive]
57#[serde(rename_all = "snake_case")]
58pub enum WorkspaceType {
59    Personal,
60    Organization,
61}
62
63/// Payload to be able to invite someone to a workspace.
64#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
65#[cfg_attr(
66    feature = "fp-bindgen",
67    derive(Serializable),
68    fp(rust_module = "fiberplane_models::workspaces")
69)]
70#[non_exhaustive]
71#[serde(rename_all = "camelCase")]
72pub struct NewWorkspaceInvite {
73    pub email: String,
74
75    #[serde(default)]
76    pub role: AuthRole,
77}
78
79impl NewWorkspaceInvite {
80    pub fn new(email: impl Into<String>, role: AuthRole) -> Self {
81        Self {
82            email: email.into(),
83            role,
84        }
85    }
86}
87
88/// Response received from create a new workspace endpoint.
89#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
90#[cfg_attr(
91    feature = "fp-bindgen",
92    derive(Serializable),
93    fp(rust_module = "fiberplane_models::workspaces")
94)]
95#[non_exhaustive]
96#[serde(rename_all = "camelCase")]
97pub struct WorkspaceInviteResponse {
98    #[builder(setter(into))]
99    pub url: String,
100}
101
102/// Payload to create a new organization workspace.
103#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TypedBuilder)]
104#[cfg_attr(
105    feature = "fp-bindgen",
106    derive(Serializable),
107    fp(rust_module = "fiberplane_models::workspaces")
108)]
109#[non_exhaustive]
110#[serde(rename_all = "camelCase")]
111pub struct NewWorkspace {
112    pub name: Name,
113
114    /// The display name of the workspace. The `name` will be used if none is provided.
115    #[builder(default, setter(into, strip_option))]
116    #[serde(default, skip_serializing_if = "Option::is_none")]
117    pub display_name: Option<String>,
118
119    #[builder(default, setter(into, strip_option))]
120    #[serde(default, skip_serializing_if = "Option::is_none")]
121    pub default_data_sources: Option<SelectedDataSources>,
122
123    #[builder(default, setter(strip_option))]
124    #[serde(default, skip_serializing_if = "Option::is_none")]
125    pub front_matter_schemas: Option<WorkspaceFrontMatterSchemas>,
126}
127
128impl NewWorkspace {
129    pub fn new(name: Name) -> Self {
130        Self {
131            name,
132            display_name: None,
133            default_data_sources: None,
134            front_matter_schemas: None,
135        }
136    }
137}
138
139#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, Default, TypedBuilder)]
140#[cfg_attr(
141    feature = "fp-bindgen",
142    derive(Serializable),
143    fp(rust_module = "fiberplane_models::workspaces")
144)]
145#[serde(rename_all = "camelCase")]
146#[non_exhaustive]
147pub struct NewWorkspaceFrontMatterSchema {
148    pub name: String,
149    pub schema: FrontMatterSchema,
150}
151
152#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, Default)]
153#[cfg_attr(
154    feature = "fp-bindgen",
155    derive(Serializable),
156    fp(rust_module = "fiberplane_models::workspaces")
157)]
158#[non_exhaustive]
159#[repr(transparent)]
160pub struct WorkspaceFrontMatterSchemas(pub BTreeMap<String, FrontMatterSchema>);
161
162impl std::ops::Deref for WorkspaceFrontMatterSchemas {
163    type Target = BTreeMap<String, FrontMatterSchema>;
164
165    fn deref(&self) -> &Self::Target {
166        &self.0
167    }
168}
169
170impl std::ops::DerefMut for WorkspaceFrontMatterSchemas {
171    fn deref_mut(&mut self) -> &mut Self::Target {
172        &mut self.0
173    }
174}
175
176impl From<BTreeMap<String, FrontMatterSchema>> for WorkspaceFrontMatterSchemas {
177    fn from(value: BTreeMap<String, FrontMatterSchema>) -> Self {
178        Self(value)
179    }
180}
181
182impl FromIterator<(String, FrontMatterSchema)> for WorkspaceFrontMatterSchemas {
183    fn from_iter<T: IntoIterator<Item = (String, FrontMatterSchema)>>(iter: T) -> Self {
184        iter.into_iter()
185            .collect::<BTreeMap<String, FrontMatterSchema>>()
186            .into()
187    }
188}
189
190/// Payload to update workspace settings
191#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TypedBuilder)]
192#[cfg_attr(
193    feature = "fp-bindgen",
194    derive(Serializable),
195    fp(rust_module = "fiberplane_models::workspaces")
196)]
197#[non_exhaustive]
198#[serde(rename_all = "camelCase")]
199pub struct UpdateWorkspace {
200    #[builder(default, setter(into, strip_option))]
201    #[serde(default, skip_serializing_if = "Option::is_none")]
202    pub display_name: Option<String>,
203
204    #[builder(default, setter(into, strip_option))]
205    #[serde(default, skip_serializing_if = "Option::is_none")]
206    pub owner: Option<Base64Uuid>,
207
208    #[builder(default, setter(strip_option))]
209    #[serde(default, skip_serializing_if = "Option::is_none")]
210    pub default_data_sources: Option<SelectedDataSources>,
211
212    #[builder(default, setter(strip_option))]
213    #[serde(default, skip_serializing_if = "Option::is_none")]
214    pub front_matter_schemas: Option<BTreeMap<String, FrontMatterSchema>>,
215}
216
217/// Payload to update a workspace members' role
218#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
219#[cfg_attr(
220    feature = "fp-bindgen",
221    derive(Serializable),
222    fp(rust_module = "fiberplane_models::workspaces")
223)]
224#[non_exhaustive]
225#[serde(rename_all = "camelCase")]
226pub struct UpdateWorkspaceUser {
227    #[builder(default, setter(strip_option))]
228    #[serde(default, skip_serializing_if = "Option::is_none")]
229    pub role: Option<AuthRole>,
230}
231
232#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, Display)]
233#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
234#[cfg_attr(
235    feature = "fp-bindgen",
236    derive(Serializable),
237    fp(rust_module = "fiberplane_models::workspaces")
238)]
239#[non_exhaustive]
240#[serde(rename_all = "snake_case")]
241pub enum AuthRole {
242    #[strum(serialize = "Viewer")]
243    Read,
244    #[strum(serialize = "Editor")]
245    Write,
246    Admin,
247}
248
249impl Default for AuthRole {
250    fn default() -> Self {
251        Self::Write
252    }
253}
254
255#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
256#[cfg_attr(
257    feature = "fp-bindgen",
258    derive(Serializable),
259    fp(rust_module = "fiberplane_models::workspaces")
260)]
261#[non_exhaustive]
262#[serde(rename_all = "camelCase")]
263pub struct WorkspaceInvite {
264    /// ID of the invitation.
265    #[builder(setter(into))]
266    pub id: Base64Uuid,
267
268    /// ID of the user who sent the invitation.
269    #[builder(setter(into))]
270    pub sender: Base64Uuid,
271
272    /// Email address of the invitee.
273    #[builder(setter(into))]
274    pub receiver: String,
275
276    /// Timestamp at which the invitation was created.
277    #[builder(setter(into))]
278    pub created_at: Timestamp,
279
280    /// Timestamp at which the invitation expires.
281    #[builder(setter(into))]
282    pub expires_at: Timestamp,
283}
284
285#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, TypedBuilder)]
286#[cfg_attr(
287    feature = "fp-bindgen",
288    derive(Serializable),
289    fp(rust_module = "fiberplane_models::workspaces")
290)]
291#[non_exhaustive]
292#[serde(rename_all = "camelCase")]
293pub struct Membership {
294    #[builder(setter(into))]
295    pub id: Base64Uuid,
296
297    #[builder(setter(into))]
298    pub email: String,
299
300    #[builder(setter(into))]
301    pub name: String,
302
303    pub role: AuthRole,
304}