Skip to main content

reifydb_core/interface/catalog/
procedure.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_type::value::{constraint::TypeConstraint, sumtype::VariantRef};
5use serde::{Deserialize, Serialize};
6
7use crate::interface::catalog::id::{NamespaceId, ProcedureId};
8
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10pub enum ProcedureTrigger {
11	/// Invoked explicitly via CALL
12	Call,
13	/// Triggered by DISPATCH on an event variant
14	Event {
15		variant: VariantRef,
16	},
17	/// Invoked via CALL but dispatched to a registered native (Rust) implementation
18	NativeCall {
19		native_name: String,
20	},
21}
22
23impl Default for ProcedureTrigger {
24	fn default() -> Self {
25		ProcedureTrigger::Call
26	}
27}
28
29#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
30pub struct Procedure {
31	pub id: ProcedureId,
32	pub namespace: NamespaceId,
33	pub name: String,
34	pub params: Vec<ProcedureParam>,
35	pub return_type: Option<TypeConstraint>,
36	/// RQL source text, compiled on load
37	pub body: String,
38	pub trigger: ProcedureTrigger,
39	/// Test procedures can only be called from test context
40	pub is_test: bool,
41}
42
43#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
44pub struct ProcedureParam {
45	pub name: String,
46	pub param_type: TypeConstraint,
47}