Skip to main content

reifydb_core/interface/catalog/
procedure.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_type::value::{constraint::TypeConstraint, sumtype::SumTypeId};
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		sumtype_id: SumTypeId,
16		variant_tag: u8,
17	},
18	/// Invoked via CALL but dispatched to a registered native (Rust) implementation
19	NativeCall {
20		native_name: String,
21	},
22}
23
24impl Default for ProcedureTrigger {
25	fn default() -> Self {
26		ProcedureTrigger::Call
27	}
28}
29
30#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
31pub struct ProcedureDef {
32	pub id: ProcedureId,
33	pub namespace: NamespaceId,
34	pub name: String,
35	pub params: Vec<ProcedureParamDef>,
36	pub return_type: Option<TypeConstraint>,
37	/// RQL source text, compiled on load
38	pub body: String,
39	pub trigger: ProcedureTrigger,
40}
41
42#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
43pub struct ProcedureParamDef {
44	pub name: String,
45	pub param_type: TypeConstraint,
46}