qualia_core_db/modalities/logic/shacl_extensions/
config.rs1use crate::webizen::SlgOpcode;
8
9#[derive(Debug, Clone)]
13pub struct LogConfiguration {
14 pub max_memory_logs: u32,
15 pub max_disk_logs: u32,
16 pub flush_interval_ms: u32,
17}
18
19#[derive(Debug, Clone)]
21pub struct LogLevel {
22 pub allowed_levels: Vec<String>, }
24
25#[derive(Debug, Clone)]
27pub struct LogEntry {
28 pub require_timestamp: bool,
29 pub require_context: bool,
30 pub max_message_length: u32,
31 pub allow_data_payload: bool,
32}
33
34#[derive(Debug, Clone)]
36pub struct LogRetention {
37 pub max_age_days: u32,
38 pub max_size_mb: u32,
39 pub backup_before_cleanup: bool,
40}
41
42#[derive(Debug, Clone)]
44pub struct LogExportFormat {
45 pub allowed_formats: Vec<String>, pub max_export_size_mb: u32,
47}
48
49#[derive(Debug, Clone)]
53pub struct SystemTrayConfiguration {
54 pub max_menu_items: u8,
55 pub require_separator_logic: bool,
56 pub allow_nested_menus: bool,
57}
58
59#[derive(Debug, Clone)]
61pub struct TrayMenuItem {
62 pub require_label: bool,
63 pub require_action: bool,
64 pub max_label_length: u32,
65 pub allow_icons: bool,
66}
67
68#[derive(Debug, Clone)]
70pub struct TrayStatusIndicator {
71 pub allow_live_updates: bool,
72 pub update_interval_ms: u32,
73 pub max_status_length: u32,
74}
75
76#[derive(Debug, Clone)]
78pub struct TrayAction {
79 pub require_window_context: bool,
80 pub allow_async_actions: bool,
81 pub timeout_ms: u32,
82}
83
84#[derive(Debug, Clone)]
88pub struct StorageConfiguration {
89 pub min_quota_gb: u32,
90 pub max_quota_gb: u32,
91 pub require_absolute_path: bool,
92 pub allowed_path_patterns: Vec<String>,
93}
94
95#[derive(Debug, Clone)]
97pub struct NetworkConfiguration {
98 pub allowed_ports: Vec<u16>,
99 pub require_port_conflict_check: bool,
100 pub default_host: String,
101}
102
103#[derive(Debug, Clone)]
105pub struct TaxRecipientConfiguration {
106 pub require_ilp_address: bool,
107 pub min_share_percent: u8,
108 pub max_share_percent: u8,
109 pub allow_nym_routing: bool,
110 pub total_share_validation: bool,
111}
112
113#[derive(Debug, Clone)]
115pub struct SecurityConfiguration {
116 pub require_encryption: bool,
117 pub allowed_cipher_suites: Vec<String>,
118 pub min_key_length_bits: u16,
119}
120
121impl LogConfiguration {
124 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
126 vec![
127 SlgOpcode::CheckMaxInclusive(self.max_memory_logs as f64),
128 SlgOpcode::CheckMaxInclusive(self.max_disk_logs as f64),
129 SlgOpcode::CheckMinInclusive(self.flush_interval_ms as f64),
130 ]
131 }
132}
133
134impl LogLevel {
135 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
137 self.allowed_levels
139 .iter()
140 .map(|level| SlgOpcode::CheckHasValue(crate::q_hash(level)))
141 .collect()
142 }
143}
144
145impl LogEntry {
146 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
148 let mut opcodes = Vec::new();
149 if self.require_timestamp {
150 opcodes.push(SlgOpcode::CheckMinCount(1));
151 }
152 if self.require_context {
153 opcodes.push(SlgOpcode::CheckMinCount(1));
154 }
155 if self.max_message_length > 0 {
156 opcodes.push(SlgOpcode::CheckMaxLength(self.max_message_length));
157 }
158 if !self.allow_data_payload {
159 opcodes.push(SlgOpcode::CheckMaxCount(3)); }
161 opcodes
162 }
163}
164
165impl LogRetention {
166 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
168 vec![
169 SlgOpcode::CheckMaxInclusive(self.max_age_days as f64),
170 SlgOpcode::CheckMaxInclusive(self.max_size_mb as f64),
171 ]
172 }
173}
174
175impl LogExportFormat {
176 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
178 let mut opcodes = vec![SlgOpcode::CheckMaxInclusive(self.max_export_size_mb as f64)];
179 for format in &self.allowed_formats {
181 opcodes.push(SlgOpcode::CheckHasValue(crate::q_hash(format)));
182 }
183 opcodes
184 }
185}
186
187impl SystemTrayConfiguration {
188 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
190 vec![SlgOpcode::CheckMaxInclusive(self.max_menu_items as f64)]
191 }
192}
193
194impl TrayMenuItem {
195 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
197 let mut opcodes = Vec::new();
198 if self.require_label {
199 opcodes.push(SlgOpcode::CheckMinCount(1));
200 }
201 if self.require_action {
202 opcodes.push(SlgOpcode::CheckMinCount(1));
203 }
204 if self.max_label_length > 0 {
205 opcodes.push(SlgOpcode::CheckMaxLength(self.max_label_length));
206 }
207 opcodes
208 }
209}
210
211impl TrayStatusIndicator {
212 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
214 vec![
215 SlgOpcode::CheckMaxLength(self.max_status_length),
216 SlgOpcode::CheckMinInclusive(self.update_interval_ms as f64),
217 ]
218 }
219}
220
221impl TrayAction {
222 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
224 vec![SlgOpcode::CheckMaxInclusive(self.timeout_ms as f64)]
225 }
226}
227
228impl StorageConfiguration {
229 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
231 let mut opcodes = vec![
232 SlgOpcode::CheckMinInclusive(self.min_quota_gb as f64),
233 SlgOpcode::CheckMaxInclusive(self.max_quota_gb as f64),
234 ];
235 if self.require_absolute_path {
236 opcodes.push(SlgOpcode::CheckMinCount(1));
237 }
238 opcodes
239 }
240}
241
242impl NetworkConfiguration {
243 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
245 let mut opcodes = Vec::new();
246 for port in &self.allowed_ports {
247 opcodes.push(SlgOpcode::CheckHasValue(*port as u64));
248 }
249 opcodes
250 }
251}
252
253impl TaxRecipientConfiguration {
254 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
256 vec![
257 SlgOpcode::CheckMinInclusive(self.min_share_percent as f64),
258 SlgOpcode::CheckMaxInclusive(self.max_share_percent as f64),
259 ]
260 }
261}
262
263impl SecurityConfiguration {
264 pub fn to_opcodes(&self) -> Vec<SlgOpcode> {
266 vec![SlgOpcode::CheckMinInclusive(
267 self.min_key_length_bits as f64,
268 )]
269 }
270}
271
272pub fn get_shacl_extensions_ttl() -> &'static str {
276 r#"
277@prefix q42: <https://webizen.org/q42#> .
278@prefix sh: <http://www.w3.org/ns/shacl#> .
279@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
280
281# ── Logging System Constraints ─────────────────────────────────────────────
282
283q42:LogConfiguration a sh:NodeShape ;
284 sh:property [
285 sh:path q42:maxMemoryLogs ;
286 sh:datatype xsd:integer ;
287 sh:minInclusive 1 ;
288 sh:maxInclusive 100000 ;
289 sh:message "Maximum memory logs must be between 1 and 100000" ;
290 ] ;
291 sh:property [
292 sh:path q42:maxDiskLogs ;
293 sh:datatype xsd:integer ;
294 sh:minInclusive 1 ;
295 sh:maxInclusive 1000000 ;
296 sh:message "Maximum disk logs must be between 1 and 1000000" ;
297 ] ;
298 sh:property [
299 sh:path q42:flushIntervalMs ;
300 sh:datatype xsd:integer ;
301 sh:minInclusive 100 ;
302 sh:maxInclusive 60000 ;
303 sh:message "Flush interval must be between 100ms and 60000ms" ;
304 ] .
305
306q42:LogLevel a sh:NodeShape ;
307 sh:property [
308 sh:path q42:allowedLevels ;
309 sh:in ("DEBUG" "INFO" "WARN" "ERROR" "CRITICAL") ;
310 sh:message "Log level must be one of: DEBUG, INFO, WARN, ERROR, CRITICAL" ;
311 ] .
312
313q42:LogEntry a sh:NodeShape ;
314 sh:property [
315 sh:path q42:timestamp ;
316 sh:datatype xsd:dateTime ;
317 sh:minCount 1 ;
318 sh:message "Log entry must have a timestamp" ;
319 ] ;
320 sh:property [
321 sh:path q42:level ;
322 sh:datatype xsd:string ;
323 sh:minCount 1 ;
324 sh:message "Log entry must have a level" ;
325 ] ;
326 sh:property [
327 sh:path q42:message ;
328 sh:datatype xsd:string ;
329 sh:maxLength 10000 ;
330 sh:message "Log message must not exceed 10000 characters" ;
331 ] .
332
333q42:LogRetention a sh:NodeShape ;
334 sh:property [
335 sh:path q42:maxAgeDays ;
336 sh:datatype xsd:integer ;
337 sh:minInclusive 1 ;
338 sh:maxInclusive 365 ;
339 sh:message "Log retention age must be between 1 and 365 days" ;
340 ] ;
341 sh:property [
342 sh:path q42:maxSizeMb ;
343 sh:datatype xsd:integer ;
344 sh:minInclusive 1 ;
345 sh:maxInclusive 10240 ;
346 sh:message "Log retention size must be between 1MB and 10GB" ;
347 ] .
348
349# ── System Tray Constraints ─────────────────────────────────────────────────
350
351q42:SystemTrayConfiguration a sh:NodeShape ;
352 sh:property [
353 sh:path q42:maxMenuItems ;
354 sh:datatype xsd:integer ;
355 sh:minInclusive 1 ;
356 sh:maxInclusive 20 ;
357 sh:message "System tray can have at most 20 menu items" ;
358 ] .
359
360q42:TrayMenuItem a sh:NodeShape ;
361 sh:property [
362 sh:path q42:label ;
363 sh:datatype xsd:string ;
364 sh:minCount 1 ;
365 sh:maxLength 50 ;
366 sh:message "Tray menu item must have a label (max 50 characters)" ;
367 ] ;
368 sh:property [
369 sh:path q42:action ;
370 sh:datatype xsd:string ;
371 sh:minCount 1 ;
372 sh:message "Tray menu item must have an action" ;
373 ] .
374
375q42:TrayStatusIndicator a sh:NodeShape ;
376 sh:property [
377 sh:path q42:statusText ;
378 sh:datatype xsd:string ;
379 sh:maxLength 100 ;
380 sh:message "Status text must not exceed 100 characters" ;
381 ] ;
382 sh:property [
383 sh:path q42:updateIntervalMs ;
384 sh:datatype xsd:integer ;
385 sh:minInclusive 100 ;
386 sh:maxInclusive 10000 ;
387 sh:message "Update interval must be between 100ms and 10000ms" ;
388 ] .
389
390# ── Enhanced Settings Constraints ─────────────────────────────────────────────
391
392q42:StorageConfiguration a sh:NodeShape ;
393 sh:property [
394 sh:path q42:storageQuotaGb ;
395 sh:datatype xsd:integer ;
396 sh:minInclusive 1 ;
397 sh:maxInclusive 1000 ;
398 sh:message "Storage quota must be between 1GB and 1000GB" ;
399 ] ;
400 sh:property [
401 sh:path q42:storagePath ;
402 sh:datatype xsd:string ;
403 sh:minCount 1 ;
404 sh:pattern "^/" ;
405 sh:message "Storage path must be an absolute path" ;
406 ] .
407
408q42:NetworkConfiguration a sh:NodeShape ;
409 sh:property [
410 sh:path q42:daemonPort ;
411 sh:datatype xsd:integer ;
412 sh:minInclusive 1024 ;
413 sh:maxInclusive 65535 ;
414 sh:message "Daemon port must be between 1024 and 65535" ;
415 ] ;
416 sh:property [
417 sh:path q42:daemonHost ;
418 sh:datatype xsd:string ;
419 sh:pattern "^(localhost|127\\.0\\.0\\.1|0\\.0\\.0\\.0)$" ;
420 sh:message "Daemon host must be localhost, 127.0.0.1, or 0.0.0.0" ;
421 ] .
422
423q42:TaxRecipientConfiguration a sh:NodeShape ;
424 sh:property [
425 sh:path q42:sharePercent ;
426 sh:datatype xsd:integer ;
427 sh:minInclusive 0 ;
428 sh:maxInclusive 100 ;
429 sh:message "Share percent must be between 0 and 100" ;
430 ] ;
431 sh:property [
432 sh:path q42:ilpAddress ;
433 sh:datatype xsd:string ;
434 sh:minCount 1 ;
435 sh:pattern "^\\$ilp\\." ;
436 sh:message "ILP address must start with $ilp." ;
437 ] .
438
439q42:SecurityConfiguration a sh:NodeShape ;
440 sh:property [
441 sh:path q42:minKeyLengthBits ;
442 sh:datatype xsd:integer ;
443 sh:minInclusive 128 ;
444 sh:maxInclusive 4096 ;
445 sh:message "Key length must be between 128 and 4096 bits" ;
446 ] ;
447 sh:property [
448 sh:path q42:requireEncryption ;
449 sh:datatype xsd:boolean ;
450 sh:message "Require encryption must be a boolean" ;
451 ] .
452"#
453}