aboutsummaryrefslogtreecommitdiff
path: root/src/models/search.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/search.rs')
-rw-r--r--src/models/search.rs98
1 files changed, 84 insertions, 14 deletions
diff --git a/src/models/search.rs b/src/models/search.rs
index 5b2b928..c9e7e91 100644
--- a/src/models/search.rs
+++ b/src/models/search.rs
@@ -257,17 +257,20 @@ pub enum PropertyCondition {
Files(FilesCondition),
Relation(RelationCondition),
Formula(FormulaCondition),
- /// Returns pages when **any** of the filters inside the provided vector match.
- Or(Vec<PropertyCondition>),
- /// Returns pages when **all** of the filters inside the provided vector match.
- And(Vec<PropertyCondition>),
}
#[derive(Serialize, Debug, Eq, PartialEq, Clone)]
-pub struct FilterCondition {
- pub property: String,
- #[serde(flatten)]
- pub condition: PropertyCondition,
+#[serde(untagged)]
+pub enum FilterCondition {
+ Property {
+ property: String,
+ #[serde(flatten)]
+ condition: PropertyCondition,
+ },
+ /// Returns pages when **all** of the filters inside the provided vector match.
+ And { and: Vec<FilterCondition> },
+ /// Returns pages when **any** of the filters inside the provided vector match.
+ Or { or: Vec<FilterCondition> },
}
#[derive(Serialize, Debug, Eq, PartialEq, Hash, Copy, Clone)]
@@ -376,13 +379,15 @@ impl From<NotionSearch> for SearchRequest {
#[cfg(test)]
mod tests {
mod text_filters {
- use crate::models::search::PropertyCondition::RichText;
- use crate::models::search::{FilterCondition, TextCondition};
+ use crate::models::search::PropertyCondition::{Checkbox, Number, RichText, Select};
+ use crate::models::search::{
+ CheckboxCondition, FilterCondition, NumberCondition, SelectCondition, TextCondition,
+ };
use serde_json::json;
#[test]
fn text_property_equals() -> Result<(), Box<dyn std::error::Error>> {
- let json = serde_json::to_value(&FilterCondition {
+ let json = serde_json::to_value(&FilterCondition::Property {
property: "Name".to_string(),
condition: RichText(TextCondition::Equals("Test".to_string())),
})?;
@@ -396,7 +401,7 @@ mod tests {
#[test]
fn text_property_contains() -> Result<(), Box<dyn std::error::Error>> {
- let json = serde_json::to_value(&FilterCondition {
+ let json = serde_json::to_value(&FilterCondition::Property {
property: "Name".to_string(),
condition: RichText(TextCondition::Contains("Test".to_string())),
})?;
@@ -410,7 +415,7 @@ mod tests {
#[test]
fn text_property_is_empty() -> Result<(), Box<dyn std::error::Error>> {
- let json = serde_json::to_value(&FilterCondition {
+ let json = serde_json::to_value(&FilterCondition::Property {
property: "Name".to_string(),
condition: RichText(TextCondition::IsEmpty),
})?;
@@ -424,7 +429,7 @@ mod tests {
#[test]
fn text_property_is_not_empty() -> Result<(), Box<dyn std::error::Error>> {
- let json = serde_json::to_value(&FilterCondition {
+ let json = serde_json::to_value(&FilterCondition::Property {
property: "Name".to_string(),
condition: RichText(TextCondition::IsNotEmpty),
})?;
@@ -435,5 +440,70 @@ mod tests {
Ok(())
}
+
+ #[test]
+ fn compound_query_and() -> Result<(), Box<dyn std::error::Error>> {
+ let json = serde_json::to_value(&FilterCondition::And {
+ and: vec![
+ FilterCondition::Property {
+ property: "Seen".to_string(),
+ condition: Checkbox(CheckboxCondition::Equals(false)),
+ },
+ FilterCondition::Property {
+ property: "Yearly visitor count".to_string(),
+ condition: Number(NumberCondition::GreaterThan(serde_json::Number::from(
+ 1000000,
+ ))),
+ },
+ ],
+ })?;
+ assert_eq!(
+ dbg!(json),
+ json!({"and":[
+ {"property":"Seen","checkbox":{"equals":false}},
+ {"property":"Yearly visitor count","number":{"greater_than":1000000}}
+ ]})
+ );
+
+ Ok(())
+ }
+
+ #[test]
+ fn compound_query_or() -> Result<(), Box<dyn std::error::Error>> {
+ let json = serde_json::to_value(&FilterCondition::Or {
+ or: vec![
+ FilterCondition::Property {
+ property: "Description".to_string(),
+ condition: RichText(TextCondition::Contains("fish".to_string())),
+ },
+ FilterCondition::And {
+ and: vec![
+ FilterCondition::Property {
+ property: "Food group".to_string(),
+ condition: Select(SelectCondition::Equals(
+ "🥦Vegetable".to_string(),
+ )),
+ },
+ FilterCondition::Property {
+ property: "Is protein rich?".to_string(),
+ condition: Checkbox(CheckboxCondition::Equals(true)),
+ },
+ ],
+ },
+ ],
+ })?;
+ assert_eq!(
+ dbg!(json),
+ json!({"or":[
+ {"property":"Description","rich_text":{"contains":"fish"}},
+ {"and":[
+ {"property":"Food group","select":{"equals":"🥦Vegetable"}},
+ {"property":"Is protein rich?","checkbox":{"equals":true}}
+ ]}
+ ]})
+ );
+
+ Ok(())
+ }
}
}
mmit message (Expand)AuthorFilesLines 2022-12-05Fix crash when passing unexpected type to .writer()Gravatar Jarred Sumner 1-1/+6 2022-12-05Introduce `console.write(text, or, arrayBufferLike)`Gravatar Jarred Sumner 1-1/+43 2022-12-05Introduce `Bun.indexOfLine`Gravatar Jarred Sumner 1-0/+61 2022-12-05Fix alignment edgecaseGravatar Jarred Sumner 2-3/+3 2022-12-05Make `console` an `AsyncIterable`Gravatar Jarred Sumner 17-116/+635 2022-12-05Update Process.hGravatar Jarred Sumner 1-0/+7 2022-12-05microbenchGravatar Jarred Sumner 1-1/+38 2022-12-05`process.stdin` exists but doesn't totally work yetGravatar Jarred Sumner 3-31/+150 2022-12-05[Bun.stdin] Fix handling ttyGravatar Jarred Sumner 2-4/+18 2022-12-05[internal] Add some logs for string encodingGravatar Jarred Sumner 1-1/+11 2022-12-05Fix "is not event emitter" errrorGravatar Jarred Sumner 1-4/+5 2022-12-05more tests for event emitter weirdnessGravatar Jarred Sumner 1-0/+59 2022-12-05"Fix" monkey-patching EventEmitter prototypeGravatar Jarred Sumner 4-35/+73 2022-12-04Update test-test.test.tsGravatar Jarred Sumner 1-0/+8 2022-12-04[bun:test] Fix crash when `test("foo")` is called without passing a functionGravatar Jarred Sumner 1-6/+13 2022-12-04Clean up more casesGravatar Jarred Sumner 1-6/+6 2022-12-04Fix race condition in child_processGravatar Jarred Sumner 1-9/+17 2022-12-04Update ZigGeneratedClasses.cppGravatar Jarred Sumner 1-0/+16 2022-12-04Handle exception when creating stdout/stderrGravatar Jarred Sumner 1-3/+10 2022-12-04Update ffi.zigGravatar Jarred Sumner 1-6/+6 2022-12-04Update child_processGravatar Jarred Sumner 5-22/+23 2022-12-04[breaking] `onExit` callback in Bun.spawn sets the first property to be the S...Gravatar Jarred Sumner 2-5/+40 2022-12-04[Bun.spawn] Introduce `Subprocess.prototype.signalCode`Gravatar Jarred Sumner 2-39/+118 2022-12-04Fix console.log sometimes incorrectly reporting undefinedGravatar Jarred Sumner 1-4/+4 2022-12-04[test] Ensure console.log(globalThis) doesn't crashGravatar Jarred Sumner 1-0/+1 2022-12-04Rename fileGravatar Jarred Sumner 1-0/+0 2022-12-04[internal] Make string comparisons fasterGravatar Jarred Sumner 25-256/+150 2022-12-04Fix running zig testsGravatar Jarred Sumner 1-1/+1 2022-12-04Mildly faster startup timeGravatar Jarred Sumner 11-52/+63 2022-12-04:scissors:Gravatar Jarred Sumner 3-3/+3 2022-12-04Add some basic tests for process.stdoutGravatar Jarred Sumner 9-58/+124 2022-12-04Re-add missing globalGravatar Jarred Sumner 1-0/+1 2022-12-04Silence incorrect test failureGravatar Jarred Sumner 1-0/+1 2022-12-04content-range is inclusiveGravatar Jarred Sumner 1-1/+1 2022-12-04Update README.mdGravatar Jarred Sumner 1-6/+33 2022-12-04[Bun.serve] Implement `Content-Range` support with `Bun.file()`Gravatar Jarred Sumner 5-16/+286 2022-12-04[may revert later] Coerce Infinity to max int 64, -Infinity & NaN to min int64Gravatar Jarred Sumner 1-2/+22 2022-12-03Update .gitignoreGravatar Jarred Sumner 1-0/+1 2022-12-03[test] Add a couple tests for subarray toEqualGravatar Jarred Sumner 1-0/+3 2022-12-03[fetch] Fix bug where .arrayBuffer() on an empty Response body returned a `Ui...Gravatar Jarred Sumner 1-1/+1 2022-12-03Don't invalidate previous file descriptro to avoid tripping assertionGravatar Jarred Sumner 1-5/+0 2022-12-03miscGravatar Jarred Sumner 3-1/+31 2022-12-03Add missing typeGravatar Jarred Sumner 1-0/+5 2022-12-03`process.stdout` and `process.stderr`Gravatar Jarred Sumner 15-564/+1537 2022-12-03simdutf ascii validation is about 20% faster on arm64 than our zig simd @Vect...Gravatar Jarred Sumner 1-0/+3 2022-12-03typo in readme (#1576)Gravatar Reed Jones 1-2/+2