Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions src/base/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,63 @@ pub struct SimpleSemanticsQueryHandlerSpec {
pub default_similarity_metric: VectorSimilarityMetric,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct AuthEntryReference {
pub struct AuthEntryReference<T> {
pub key: String,
_phantom: std::marker::PhantomData<T>,
}

impl<T> std::fmt::Debug for AuthEntryReference<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "AuthEntryReference({})", self.key)
}
}

impl<T> std::fmt::Display for AuthEntryReference<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "AuthEntryReference({})", self.key)
}
}

impl<T> Clone for AuthEntryReference<T> {
fn clone(&self) -> Self {
Self {
key: self.key.clone(),
_phantom: std::marker::PhantomData,
}
}
}

impl<T> Serialize for AuthEntryReference<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.key.serialize(serializer)
}
}

impl<'de, T> Deserialize<'de> for AuthEntryReference<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
Ok(Self {
key: String::deserialize(deserializer)?,
_phantom: std::marker::PhantomData,
})
}
}

impl<T> PartialEq for AuthEntryReference<T> {
fn eq(&self, other: &Self) -> bool {
self.key == other.key
}
}

impl<T> Eq for AuthEntryReference<T> {}

impl<T> std::hash::Hash for AuthEntryReference<T> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.key.hash(state);
}
}
8 changes: 4 additions & 4 deletions src/ops/storages/neo4j.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ pub struct ConnectionSpec {

#[derive(Debug, Deserialize)]
pub struct Spec {
connection: spec::AuthEntryReference,
connection: spec::AuthEntryReference<ConnectionSpec>,
mapping: GraphElementMapping,
}

#[derive(Debug, Deserialize)]
pub struct Declaration {
connection: spec::AuthEntryReference,
connection: spec::AuthEntryReference<ConnectionSpec>,
#[serde(flatten)]
decl: GraphDeclarations,
}
Expand Down Expand Up @@ -92,7 +92,7 @@ impl std::fmt::Display for ElementType {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub struct GraphElement {
connection: AuthEntryReference,
connection: AuthEntryReference<ConnectionSpec>,
typ: ElementType,
}

Expand Down Expand Up @@ -156,7 +156,7 @@ struct AnalyzedNodeLabelInfo {
}

pub struct ExportContext {
connection_ref: AuthEntryReference,
connection_ref: AuthEntryReference<ConnectionSpec>,
graph: Arc<Graph>,

create_order: u8,
Expand Down
2 changes: 1 addition & 1 deletion src/setup/auth_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl AuthRegistry {
Ok(())
}

pub fn get<T: DeserializeOwned>(&self, entry_ref: &spec::AuthEntryReference) -> Result<T> {
pub fn get<T: DeserializeOwned>(&self, entry_ref: &spec::AuthEntryReference<T>) -> Result<T> {
let entries = self.entries.read().unwrap();
match entries.get(&entry_ref.key) {
Some(value) => Ok(serde_json::from_value(value.clone())?),
Expand Down