aboutsummaryrefslogtreecommitdiff
path: root/src/models/properties.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/properties.rs')
-rw-r--r--src/models/properties.rs181
1 files changed, 168 insertions, 13 deletions
diff --git a/src/models/properties.rs b/src/models/properties.rs
index 4139712..c55ce1a 100644
--- a/src/models/properties.rs
+++ b/src/models/properties.rs
@@ -1,12 +1,15 @@
-use crate::models::DatabaseId;
+use crate::models::text::RichText;
+use crate::models::{DatabaseId, PageId, User};
use serde::{Deserialize, Serialize};
-#[derive(Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
+use super::{DateTime, Number, Utc};
+
+#[derive(Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone)]
#[serde(transparent)]
pub struct PropertyId(String);
/// How the number is displayed in Notion.
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum NumberFormat {
@@ -23,11 +26,11 @@ pub enum NumberFormat {
Yuan,
}
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone)]
#[serde(transparent)]
pub struct SelectOptionId(String);
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
#[serde(rename_all = "lowercase")]
pub enum Color {
Default,
@@ -42,26 +45,26 @@ pub enum Color {
Red,
}
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct SelectOption {
name: String,
id: SelectOptionId,
color: Color,
}
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Select {
/// Sorted list of options available for this property.
options: Vec<SelectOption>,
}
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Formula {
/// Formula to evaluate for this property
expression: String,
}
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Relation {
/// The database this relation refers to.
/// New linked pages must belong to this database in order to be valid.
@@ -77,7 +80,7 @@ pub struct Relation {
synced_property_id: Option<PropertyId>,
}
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
#[serde(rename_all = "snake_case")]
pub enum RollupFunction {
CountAll,
@@ -95,7 +98,7 @@ pub enum RollupFunction {
Range,
}
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Rollup {
/// The name of the relation property this property is responsible for rolling up.
relation_property_name: String,
@@ -111,7 +114,7 @@ pub struct Rollup {
function: RollupFunction,
}
-#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum PropertyConfiguration {
@@ -132,12 +135,22 @@ pub enum PropertyConfiguration {
/// Represents a Select Property
/// See https://developers.notion.com/reference/database#select-configuration
Select { id: PropertyId, select: Select },
+ /// Represents a Multi-select Property
+ /// See https://developers.notion.com/reference/database#multi-select-configuration
+ MultiSelect {
+ id: PropertyId,
+ multi_select: Select,
+ },
/// Represents a Date Property
/// See https://developers.notion.com/reference/database#date-configuration
Date { id: PropertyId },
+ /// Represents a People Property
+ /// See https://developers.notion.com/reference/database#people-configuration
+ People { id: PropertyId },
/// Represents a File Property
/// See https://developers.notion.com/reference/database#file-configuration
- /// Documentation issue: docs claim type name is `file` but it's is in fact `files`
+ // Todo: File a bug with notion
+ // Documentation issue: docs claim type name is `file` but it is in fact `files`
Files { id: PropertyId },
/// Represents a Checkbox Property
/// See https://developers.notion.com/reference/database#checkbox-configuration
@@ -166,3 +179,145 @@ pub enum PropertyConfiguration {
/// See https://developers.notion.com/reference/database#last-edited-by-configuration
LastEditBy { id: PropertyId },
}
+
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
+pub struct SelectedValue {
+ id: SelectOptionId,
+ name: String,
+ color: Color,
+}
+
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
+pub struct DateValue {
+ // Todo: Will this work with dates (without time)?
+ // does there need to be an enum of Date|DateTime?
+ start: DateTime<Utc>,
+ end: Option<DateTime<Utc>>,
+}
+
+/// Formula property value objects represent the result of evaluating a formula
+/// described in the database's properties.
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
+#[serde(tag = "type")]
+#[serde(rename_all = "snake_case")]
+pub enum FormulaResultValue {
+ String(#[serde(rename = "string")] Option<String>),
+ Number(#[serde(rename = "number")] Option<Number>),
+ Boolean(#[serde(rename = "boolean")] Option<bool>),
+ Date(#[serde(rename = "date")] Option<DateTime<Utc>>),
+}
+
+/// Relation property value objects contain an array of page references within the relation property.
+/// A page reference is an object with an id property,
+/// with a string value (UUIDv4) corresponding to a page ID in another database.
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
+pub struct RelationValue {
+ id: PageId,
+}
+
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
+#[serde(tag = "type")]
+#[serde(rename_all = "snake_case")]
+pub enum RollupValue {
+ Number(#[serde(rename = "number")] Option<Number>),
+ Date(#[serde(rename = "date")] Option<DateTime<Utc>>),
+ // Todo: these property values don't have id properties...
+ // so this likely wont deserialize. would like to minimize duplicated code...
+ Array(#[serde(rename = "array")] Vec<PropertyValue>),
+}
+
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
+pub struct FileReference {
+ name: String,
+ url: String,
+ mime_type: String,
+}
+
+#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
+#[serde(tag = "type")]
+#[serde(rename_all = "snake_case")]
+pub enum PropertyValue {
+ // https://developers.notion.com/reference/page#title-property-values
+ Title {
+ id: PropertyId,
+ title: Vec<RichText>,
+ },
+ /// https://developers.notion.com/reference/page#rich-text-property-values
+ #[serde(rename = "rich_text")]
+ Text {
+ id: PropertyId,
+ rich_text: Vec<RichText>,
+ },
+ /// https://developers.notion.com/reference/page#number-property-values
+ Number {
+ id: PropertyId,
+ number: Number,
+ },
+ /// https://developers.notion.com/reference/page#select-property-values
+ Select {
+ id: PropertyId,
+ select: SelectedValue,
+ },
+ MultiSelect {
+ id: PropertyId,
+ multi_select: Vec<SelectedValue>,
+ },
+ Date {
+ id: PropertyId,
+ date: DateValue,
+ },
+ /// https://developers.notion.com/reference/page#formula-property-values
+ Formula {
+ id: PropertyId,
+ formula: FormulaResultValue,
+ },
+ /// https://developers.notion.com/reference/page#relation-property-values
+ Relation {
+ id: PropertyId,
+ relation: RelationValue,
+ },
+ Rollup {
+ id: PropertyId,
+ relation: Rollup,
+ },
+ People {
+ id: PropertyId,
+ people: Vec<User>,
+ },
+ Files {
+ id: PropertyId,
+ files: Vec<FileReference>,
+ },
+ Checkbox {
+ id: PropertyId,
+ checkbox: bool,
+ },
+ URL {
+ id: PropertyId,
+ url: String,
+ },
+ Email {
+ id: PropertyId,
+ email: String,
+ },
+ PhoneNumber {
+ id: PropertyId,
+ phone_number: String,
+ },
+ CreatedTime {
+ id: PropertyId,
+ created_time: DateTime<Utc>,
+ },
+ CreatedBy {
+ id: PropertyId,
+ created_by: User,
+ },
+ LastEditedTime {
+ id: PropertyId,
+ last_edited_time: DateTime<Utc>,
+ },
+ LastEditedBy {
+ id: PropertyId,
+ last_edited_by: User,
+ },
+}