Skip to main content

reifydb_core/interface/catalog/
namespace.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4use crate::interface::catalog::id::{NamespaceId, RESERVED_USER_ID_START};
5
6impl NamespaceId {
7	pub const fn is_system(&self) -> bool {
8		self.0 < RESERVED_USER_ID_START
9	}
10
11	pub const ROOT: NamespaceId = NamespaceId(0);
12	pub const SYSTEM: NamespaceId = NamespaceId(1);
13	pub const DEFAULT: NamespaceId = NamespaceId(2);
14	pub const SYSTEM_CONFIG: NamespaceId = NamespaceId(3);
15	pub const SYSTEM_METRICS: NamespaceId = NamespaceId(4);
16	pub const SYSTEM_METRICS_STORAGE: NamespaceId = NamespaceId(5);
17	pub const SYSTEM_METRICS_CDC: NamespaceId = NamespaceId(6);
18	pub const SYSTEM_PROCEDURES: NamespaceId = NamespaceId(7);
19	pub const SYSTEM_BINDINGS: NamespaceId = NamespaceId(8);
20	pub const RQL: NamespaceId = NamespaceId(9);
21	pub const SYSTEM_METRICS_PROFILER: NamespaceId = NamespaceId(10);
22	pub const SYSTEM_METRICS_PROFILER_SPANS: NamespaceId = NamespaceId(11);
23	pub const SYSTEM_METRICS_RUNTIME: NamespaceId = NamespaceId(12);
24	pub const SYSTEM_METRICS_RUNTIME_MEMORY: NamespaceId = NamespaceId(13);
25	pub const SYSTEM_METRICS_RUNTIME_WATERMARKS: NamespaceId = NamespaceId(14);
26	pub const SYSTEM_METRICS_RUNTIME_OPERATORS: NamespaceId = NamespaceId(15);
27	pub const SYSTEM_METRICS_READ_BUFFER: NamespaceId = NamespaceId(34);
28	pub const SYSTEM_METRICS_INSTRUMENTS: NamespaceId = NamespaceId(38);
29	pub const SYSTEM_METRICS_EPOCH: NamespaceId = NamespaceId(39);
30	pub const SYSTEM_METRICS_LIFECYCLE: NamespaceId = NamespaceId(40);
31	pub const SYSTEM_SOURCE: NamespaceId = NamespaceId(41);
32	pub const STORAGE: NamespaceId = NamespaceId(42);
33	pub const SYSTEM_METRICS_FLOW: NamespaceId = NamespaceId(43);
34	pub const SYSTEM_METRICS_FLOW_STATE: NamespaceId = NamespaceId(44);
35	pub const GRAPHQL: NamespaceId = NamespaceId(55);
36}
37
38#[derive(Debug, Clone, PartialEq)]
39pub enum Namespace {
40	Local {
41		id: NamespaceId,
42		name: String,
43		local_name: String,
44		parent_id: NamespaceId,
45	},
46	Remote {
47		id: NamespaceId,
48		name: String,
49		local_name: String,
50		parent_id: NamespaceId,
51		address: String,
52		token: Option<String>,
53	},
54}
55
56impl Namespace {
57	pub fn id(&self) -> NamespaceId {
58		match self {
59			Namespace::Local {
60				id,
61				..
62			}
63			| Namespace::Remote {
64				id,
65				..
66			} => *id,
67		}
68	}
69
70	pub fn name(&self) -> &str {
71		match self {
72			Namespace::Local {
73				name,
74				..
75			}
76			| Namespace::Remote {
77				name,
78				..
79			} => name,
80		}
81	}
82
83	pub fn local_name(&self) -> &str {
84		match self {
85			Namespace::Local {
86				local_name,
87				..
88			}
89			| Namespace::Remote {
90				local_name,
91				..
92			} => local_name,
93		}
94	}
95
96	pub fn parent_id(&self) -> NamespaceId {
97		match self {
98			Namespace::Local {
99				parent_id,
100				..
101			}
102			| Namespace::Remote {
103				parent_id,
104				..
105			} => *parent_id,
106		}
107	}
108
109	pub fn address(&self) -> Option<&str> {
110		match self {
111			Namespace::Remote {
112				address,
113				..
114			} => Some(address),
115			_ => None,
116		}
117	}
118
119	pub fn token(&self) -> Option<&str> {
120		match self {
121			Namespace::Remote {
122				token,
123				..
124			} => token.as_deref(),
125			_ => None,
126		}
127	}
128
129	pub fn is_remote(&self) -> bool {
130		matches!(self, Namespace::Remote { .. })
131	}
132
133	pub fn system() -> Self {
134		Self::Local {
135			id: NamespaceId::SYSTEM,
136			name: "system".to_string(),
137			local_name: "system".to_string(),
138			parent_id: NamespaceId::ROOT,
139		}
140	}
141
142	pub fn default_namespace() -> Self {
143		Self::Local {
144			id: NamespaceId::DEFAULT,
145			name: "default".to_string(),
146			local_name: "default".to_string(),
147			parent_id: NamespaceId::ROOT,
148		}
149	}
150}