Skip to main content

relate_executor/
catalog_meta.rs

1//! Neutral catalog metadata shared by the built-in function and procedure
2//! registries (CIP-84/CIP-113/CIP-157): one formal parameter/return-column
3//! shape and one typed deprecation record.
4//!
5//! Both [`crate::function_registry`] and [`crate::procedure_registry`]
6//! import these types, so neither registry owns the other's vocabulary.
7//! [`DeprecatedBy`] and [`DeprecationForm`] are re-exported at the crate
8//! root because the notification readers outside this crate name them
9//! (`relate_executor::{DeprecatedBy, DeprecationForm}`). [`ProcArgMeta`]
10//! stays crate-internal: a caller outside this crate reads a public
11//! [`crate::ProcSignature`]'s parameters through
12//! `ProcSignature::parameters`/`return_columns`, never by naming the
13//! parameter type, so it needs no public path of its own.
14
15use relate_model::CypherValue;
16
17/// One formal parameter or return column of a built-in function or
18/// procedure: the `name`/`description`/`type`/`isDeprecated`/`default`
19/// shape CIP-84's `argumentDescription`/`returnDescription` maps carry
20/// (`default` only when the parameter actually has one).
21pub(crate) struct ProcArgMeta {
22    pub name: &'static str,
23    pub description: &'static str,
24    pub type_str: &'static str,
25    pub deprecated: bool,
26    pub default: Option<&'static str>,
27}
28
29impl ProcArgMeta {
30    /// Compact constructor for the common case: no description, not
31    /// deprecated, no default.
32    pub(crate) const fn new(name: &'static str, type_str: &'static str) -> Self {
33        Self::described(name, "", type_str)
34    }
35
36    /// Compact constructor for a parameter with a default value; not
37    /// deprecated.
38    pub(crate) const fn with_default(
39        name: &'static str,
40        description: &'static str,
41        type_str: &'static str,
42        default: &'static str,
43    ) -> Self {
44        Self {
45            name,
46            description,
47            type_str,
48            deprecated: false,
49            default: Some(default),
50        }
51    }
52
53    /// Compact constructor with a description; not deprecated, no default.
54    pub(crate) const fn described(
55        name: &'static str,
56        description: &'static str,
57        type_str: &'static str,
58    ) -> Self {
59        Self {
60            name,
61            description,
62            type_str,
63            deprecated: false,
64            default: None,
65        }
66    }
67}
68
69/// A catalog entry's replacement (CIP-157's `deprecatedBy`): the display
70/// text `SHOW FUNCTIONS`/`SHOW PROCEDURES` render and the replacement's
71/// syntactic form. The form keeps a function/procedure identifier apart
72/// from a Cypher clause, so a notification remedy can name each one for
73/// what it is instead of guessing from the string.
74#[derive(Clone, Copy, Debug, PartialEq, Eq)]
75pub struct DeprecatedBy {
76    /// The exact `deprecatedBy` cell CIP-157 pins for the catalog rows.
77    display: &'static str,
78    form: DeprecationForm,
79}
80
81/// The replacement's syntactic form (the notification remedy's rendering).
82#[derive(Clone, Copy, Debug, PartialEq, Eq)]
83pub enum DeprecationForm {
84    /// A function or procedure identifier, optionally a call
85    /// (`elementId`, `elementId(n)`).
86    Identifier(&'static str),
87    /// A Cypher clause (`SEARCH`).
88    Clause(&'static str),
89}
90
91impl DeprecatedBy {
92    /// A replacement whose catalog display text is the identifier itself.
93    pub const fn identifier(identifier: &'static str) -> Self {
94        Self {
95            display: identifier,
96            form: DeprecationForm::Identifier(identifier),
97        }
98    }
99
100    /// A replacement whose catalog display text is the clause's name.
101    pub const fn clause(clause: &'static str) -> Self {
102        Self {
103            display: clause,
104            form: DeprecationForm::Clause(clause),
105        }
106    }
107
108    /// A replacement whose catalog display is prose prefixed by the
109    /// identifier to render (CIP-157's `id` cell).
110    pub const fn identified(identifier: &'static str, display: &'static str) -> Self {
111        Self {
112            display,
113            form: DeprecationForm::Identifier(identifier),
114        }
115    }
116
117    /// The catalog's `deprecatedBy` display text.
118    pub fn display(self) -> &'static str {
119        self.display
120    }
121
122    /// The replacement's syntactic form.
123    pub fn form(self) -> DeprecationForm {
124        self.form
125    }
126}
127
128/// One row cell's list of strings -- the one spelling every catalog-style
129/// `CypherValue` renderer reads (the SHOW catalogs' role/argument cells,
130/// the graph-type view's properties/constraints cells).
131pub(crate) fn string_list(values: impl IntoIterator<Item = String>) -> CypherValue {
132    CypherValue::List(values.into_iter().map(CypherValue::Str).collect())
133}