1#![allow(clippy::too_many_arguments)]
6
7use serde::{Deserialize, Serialize};
8use spatio_types::geo::{DistanceMetric, Point, Polygon};
9use spatio_types::point::Point3d;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct UpsertOptions {
14 pub ttl: std::time::Duration,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct LocationUpdate {
19 pub timestamp: f64,
20 pub position: Point3d,
21 pub metadata: Vec<u8>,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct Stats {
26 pub object_count: usize,
27 pub memory_usage_bytes: usize,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct CurrentLocation {
32 pub object_id: String,
33 pub position: Point3d,
34 pub metadata: Vec<u8>,
35}
36
37#[allow(clippy::too_many_arguments)]
38#[tarpc::service]
39pub trait SpatioService {
40 async fn upsert(
41 namespace: String,
42 id: String,
43 point: Point3d,
44 metadata: serde_json::Value,
45 opts: Option<UpsertOptions>,
46 ) -> Result<(), String>;
47
48 async fn get(namespace: String, id: String) -> Result<Option<CurrentLocation>, String>;
49
50 async fn delete(namespace: String, id: String) -> Result<(), String>;
51
52 async fn query_radius(
53 namespace: String,
54 center: Point3d,
55 radius: f64,
56 limit: usize,
57 ) -> Result<Vec<(CurrentLocation, f64)>, String>;
58
59 async fn knn(
60 namespace: String,
61 center: Point3d,
62 k: usize,
63 ) -> Result<Vec<(CurrentLocation, f64)>, String>;
64
65 async fn query_bbox(
66 namespace: String,
67 min_x: f64,
68 min_y: f64,
69 max_x: f64,
70 max_y: f64,
71 limit: usize,
72 ) -> Result<Vec<CurrentLocation>, String>;
73
74 async fn query_cylinder(
75 namespace: String,
76 center: Point,
77 min_z: f64,
78 max_z: f64,
79 radius: f64,
80 limit: usize,
81 ) -> Result<Vec<(CurrentLocation, f64)>, String>;
82
83 async fn query_trajectory(
84 namespace: String,
85 id: String,
86 start_time: Option<f64>,
87 end_time: Option<f64>,
88 limit: usize,
89 ) -> Result<Vec<LocationUpdate>, String>;
90
91 async fn insert_trajectory(
92 namespace: String,
93 id: String,
94 trajectory: Vec<(f64, Point3d, serde_json::Value)>,
95 ) -> Result<(), String>;
96
97 async fn query_bbox_3d(
98 namespace: String,
99 min_x: f64,
100 min_y: f64,
101 min_z: f64,
102 max_x: f64,
103 max_y: f64,
104 max_z: f64,
105 limit: usize,
106 ) -> Result<Vec<CurrentLocation>, String>;
107
108 async fn query_near(
109 namespace: String,
110 id: String,
111 radius: f64,
112 limit: usize,
113 ) -> Result<Vec<(CurrentLocation, f64)>, String>;
114
115 async fn contains(
116 namespace: String,
117 polygon: Polygon,
118 limit: usize,
119 ) -> Result<Vec<CurrentLocation>, String>;
120
121 async fn distance(
122 namespace: String,
123 id1: String,
124 id2: String,
125 metric: Option<DistanceMetric>,
126 ) -> Result<Option<f64>, String>;
127
128 async fn distance_to(
129 namespace: String,
130 id: String,
131 point: Point,
132 metric: Option<DistanceMetric>,
133 ) -> Result<Option<f64>, String>;
134
135 async fn convex_hull(namespace: String) -> Result<Option<Polygon>, String>;
136
137 async fn bounding_box(
138 namespace: String,
139 ) -> Result<Option<spatio_types::bbox::BoundingBox2D>, String>;
140
141 async fn stats() -> Stats;
142}