notion_sdk/database/
properties.rs

1use crate::common::rich_text::RichText;
2use crate::database::date::{DateValue, FormulaResultValue};
3use crate::database::files::FileReference;
4use crate::database::formula::Formula;
5use crate::database::id::PropertyId;
6use crate::database::number::NumberDetails;
7use crate::database::relation::{Relation, RelationValue};
8use crate::database::rollup::{Rollup, RollupValue};
9use crate::database::select::{Select, SelectedValue};
10use crate::database::status::Status;
11use crate::user::User;
12use chrono::{DateTime, Utc};
13use serde::{Deserialize, Serialize};
14use serde_json::Number;
15use std::collections::HashMap;
16
17#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
18pub struct Properties {
19    #[serde(flatten)]
20    pub properties: HashMap<String, PropertyValue>,
21}
22
23#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
24#[serde(tag = "type")]
25#[serde(rename_all = "snake_case")]
26pub enum PropertyValue {
27    // <https://developers.notion.com/reference/property-object#title-configuration>
28    Title {
29        id: PropertyId,
30        title: Vec<RichText>,
31    },
32    /// <https://developers.notion.com/reference/property-object#text-configuration>
33    #[serde(rename = "rich_text")]
34    Text {
35        id: PropertyId,
36        rich_text: Vec<RichText>,
37    },
38    /// <https://developers.notion.com/reference/property-object#number-configuration>
39    Number {
40        id: PropertyId,
41        number: Option<Number>,
42    },
43    /// <https://developers.notion.com/reference/property-object#select-configuration>
44    Select {
45        id: PropertyId,
46        select: Option<SelectedValue>,
47    },
48    /// <https://developers.notion.com/reference/property-object#status-configuration>
49    Status {
50        id: PropertyId,
51        status: Option<SelectedValue>,
52    },
53    /// <https://developers.notion.com/reference/property-object#multi-select-configuration>
54    MultiSelect {
55        id: PropertyId,
56        multi_select: Option<Vec<SelectedValue>>,
57    },
58    /// <https://developers.notion.com/reference/property-object#date-configuration>
59    Date {
60        id: PropertyId,
61        date: Option<DateValue>,
62    },
63    /// <https://developers.notion.com/reference/property-object#formula-configuration>
64    Formula {
65        id: PropertyId,
66        formula: FormulaResultValue,
67    },
68    /// <https://developers.notion.com/reference/property-object#relation-configuration>
69    /// It is actually an array of relations
70    Relation {
71        id: PropertyId,
72        relation: Option<Vec<RelationValue>>,
73    },
74    /// <https://developers.notion.com/reference/property-object#rollup-configuration>
75    Rollup {
76        id: PropertyId,
77        rollup: Option<RollupValue>,
78    },
79    /// <https://developers.notion.com/reference/property-object#people-configuration>
80    People { id: PropertyId, people: Vec<User> },
81    /// <https://developers.notion.com/reference/property-object#files-configuration>
82    Files {
83        id: PropertyId,
84        files: Option<Vec<FileReference>>,
85    },
86    /// <https://developers.notion.com/reference/property-object#checkbox-configuration>
87    Checkbox { id: PropertyId, checkbox: bool },
88    /// <https://developers.notion.com/reference/property-object#url-configuration>
89    Url { id: PropertyId, url: Option<String> },
90    /// <https://developers.notion.com/reference/property-object#email-configuration>
91    Email {
92        id: PropertyId,
93        email: Option<String>,
94    },
95    /// <https://developers.notion.com/reference/property-object#phone-number-configuration>
96    PhoneNumber {
97        id: PropertyId,
98        phone_number: String,
99    },
100    /// <https://developers.notion.com/reference/property-object#created-time-configuration>
101    CreatedTime {
102        id: PropertyId,
103        created_time: DateTime<Utc>,
104    },
105    /// <https://developers.notion.com/reference/property-object#created-by-configuration>
106    CreatedBy { id: PropertyId, created_by: User },
107    /// <https://developers.notion.com/reference/property-object#last-edited-time-configuration>
108    LastEditedTime {
109        id: PropertyId,
110        last_edited_time: DateTime<Utc>,
111    },
112    /// <https://developers.notion.com/reference/property-object#last-edited-by-configuration>
113    LastEditedBy {
114        id: PropertyId,
115        last_edited_by: User,
116    },
117}
118
119#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
120#[serde(tag = "type")]
121#[serde(rename_all = "snake_case")]
122pub enum PropertyConfiguration {
123    /// Represents the special Title property required on every database.
124    /// See <https://developers.notion.com/reference/database#title-configuration>
125    Title { id: PropertyId, name: String },
126    /// Represents a Text property
127    /// <https://developers.notion.com/reference/database#text-configuration>
128    #[serde(rename = "rich_text")]
129    Text { id: PropertyId, name: String },
130    /// Represents a Number Property
131    /// See <https://developers.notion.com/reference/database#number-configuration>
132    Number {
133        id: PropertyId,
134        name: String,
135        /// How the number is displayed in Notion.
136        number: NumberDetails,
137    },
138    /// Represents a Select Property
139    /// See <https://developers.notion.com/reference/database#select-configuration>
140    Select {
141        id: PropertyId,
142        name: String,
143        select: Select,
144    },
145    /// Represents a Status property
146    Status {
147        id: PropertyId,
148        name: String,
149        status: Status,
150    },
151    /// Represents a Multi-select Property
152    /// See <https://developers.notion.com/reference/database#multi-select-configuration>
153    MultiSelect {
154        id: PropertyId,
155        name: String,
156        multi_select: Select,
157    },
158    /// Represents a Date Property
159    /// See <https://developers.notion.com/reference/database#date-configuration>
160    Date { id: PropertyId, name: String },
161    /// Represents a People Property
162    /// See <https://developers.notion.com/reference/database#people-configuration>
163    People { id: PropertyId, name: String },
164    /// Represents a File Property
165    /// See <https://developers.notion.com/reference/database#file-configuration>
166    // Todo: File a bug with notion
167    //       Documentation issue: docs claim type name is `file` but it is in fact `files`
168    Files { id: PropertyId, name: String },
169    /// Represents a Checkbox Property
170    /// See <https://developers.notion.com/reference/database#checkbox-configuration>
171    Checkbox { id: PropertyId, name: String },
172    /// Represents a URL Property
173    /// See <https://developers.notion.com/reference/database#url-configuration>
174    Url { id: PropertyId, name: String },
175    /// Represents a Email Property
176    /// See <https://developers.notion.com/reference/database#email-configuration>
177    Email { id: PropertyId, name: String },
178    /// Represents a Phone number Property
179    /// See <https://developers.notion.com/reference/database#phone-number-configuration>
180    PhoneNumber { id: PropertyId, name: String },
181    /// See <https://developers.notion.com/reference/database#formula-configuration>
182    Formula {
183        id: PropertyId,
184        name: String,
185        formula: Formula,
186    },
187    /// See <https://developers.notion.com/reference/database#relation-configuration>
188    Relation {
189        id: PropertyId,
190        name: String,
191        relation: Relation,
192    },
193    /// See <https://developers.notion.com/reference/database#rollup-configuration>
194    Rollup {
195        id: PropertyId,
196        name: String,
197        rollup: Rollup,
198    },
199    /// See <https://developers.notion.com/reference/database#created-time-configuration>
200    CreatedTime { id: PropertyId, name: String },
201    /// See <https://developers.notion.com/reference/database#created-by-configuration>
202    CreatedBy { id: PropertyId, name: String },
203    /// See <https://developers.notion.com/reference/database#last-edited-time-configuration>
204    LastEditedTime { id: PropertyId, name: String },
205    /// See <https://developers.notion.com/reference/database#last-edited-by-configuration>
206    LastEditBy { id: PropertyId, name: String },
207}