drasi_core/models/
mod.rs

1// Copyright 2024 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::fmt::{Display, Formatter};
16use std::sync::Arc;
17
18use serde_json::{Map, Value};
19use thiserror::Error;
20
21mod element;
22mod element_value;
23mod source_change;
24mod timestamp_range;
25
26pub use element::{Element, ElementMetadata, ElementReference, ElementTimestamp};
27pub use element_value::ElementPropertyMap;
28pub use element_value::ElementValue;
29pub use source_change::SourceChange;
30pub use timestamp_range::{TimestampBound, TimestampRange};
31
32#[derive(Debug, Error)]
33pub struct ConversionError {}
34
35impl Display for ConversionError {
36    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
37        write!(f, "Cannot convert")
38    }
39}
40
41#[derive(Debug, Clone)]
42pub struct QuerySourceElement {
43    pub source_label: String,
44}
45
46#[derive(Debug, Clone)]
47pub struct QuerySubscription {
48    pub id: Arc<str>,
49    pub nodes: Vec<QuerySourceElement>,
50    pub relations: Vec<QuerySourceElement>,
51    pub pipeline: Vec<Arc<str>>,
52}
53
54#[derive(Debug, Hash, PartialEq, Eq, Clone)]
55pub struct QueryJoinKey {
56    pub label: String,
57    pub property: String,
58}
59
60#[derive(Debug, Hash, PartialEq, Eq, Clone)]
61pub struct QueryJoin {
62    pub id: String,
63    pub keys: Vec<QueryJoinKey>,
64}
65
66#[derive(Debug, Clone)]
67pub struct QueryConfig {
68    pub mode: String,
69    pub query: String,
70    pub sources: QuerySources,
71    pub storage_profile: Option<String>,
72}
73
74#[derive(Debug, Clone)]
75pub struct QuerySources {
76    pub subscriptions: Vec<QuerySubscription>,
77    pub joins: Vec<QueryJoin>,
78    pub middleware: Vec<SourceMiddlewareConfig>,
79}
80
81#[derive(Debug, Clone)]
82pub struct SourceMiddlewareConfig {
83    pub kind: Arc<str>,
84    pub name: Arc<str>,
85    pub config: Map<String, Value>,
86}
87
88impl SourceMiddlewareConfig {
89    pub fn new(kind: &str, name: &str, config: Map<String, Value>) -> Self {
90        SourceMiddlewareConfig {
91            kind: Arc::from(kind),
92            name: Arc::from(name),
93            config,
94        }
95    }
96}