Skip to main content

triblespace_core/
metadata.rs

1//! Metadata namespace for the `triblespace` crate.
2//!
3//! This namespace is used to bootstrap the meaning of other namespaces.
4//! It defines meta attributes that are used to describe other attributes.
5
6use crate::blob::schemas::longstring::LongString;
7use crate::blob::schemas::wasmcode::WasmCode;
8use crate::id::Id;
9use crate::id_hex;
10use crate::prelude::valueschemas;
11use crate::repo::BlobStore;
12use crate::trible::TribleSet;
13use crate::value::schemas::hash;
14use crate::value::schemas::hash::Blake3;
15use core::marker::PhantomData;
16use triblespace_core_macros::attributes;
17
18/// Describes metadata that can be emitted for documentation or discovery.
19pub trait Metadata {
20    /// Returns the root identifier for this metadata description.
21    fn id(&self) -> Id;
22
23    fn describe<B>(&self, blobs: &mut B) -> Result<TribleSet, B::PutError>
24    where
25        B: BlobStore<Blake3>;
26}
27
28/// Helper trait for schema types that want to expose metadata without requiring an instance.
29pub trait ConstMetadata {
30    /// Returns the root identifier for this metadata description.
31    fn id() -> Id;
32
33    fn describe<B>(blobs: &mut B) -> Result<TribleSet, B::PutError>
34    where
35        B: BlobStore<Blake3>,
36    {
37        let _ = blobs;
38        Ok(TribleSet::new())
39    }
40}
41
42impl<S> Metadata for PhantomData<S>
43where
44    S: ConstMetadata,
45{
46    fn id(&self) -> Id {
47        <S as ConstMetadata>::id()
48    }
49
50    fn describe<B>(&self, blobs: &mut B) -> Result<TribleSet, B::PutError>
51    where
52        B: BlobStore<Blake3>,
53    {
54        <S as ConstMetadata>::describe(blobs)
55    }
56}
57
58impl<T> Metadata for T
59where
60    T: ConstMetadata,
61{
62    fn id(&self) -> Id {
63        T::id()
64    }
65
66    fn describe<B>(&self, blobs: &mut B) -> Result<TribleSet, B::PutError>
67    where
68        B: BlobStore<Blake3>,
69    {
70        let _ = blobs;
71        Ok(TribleSet::new())
72    }
73}
74
75// namespace constants
76pub const KIND_MULTI: Id = id_hex!("C36D9C16B34729D855BD6C36A624E1BF");
77/// Tag for entities that represent value schemas.
78pub const KIND_VALUE_SCHEMA: Id = id_hex!("9A169BF2383E7B1A3E019808DFE3C2EB");
79/// Tag for entities that represent blob schemas.
80pub const KIND_BLOB_SCHEMA: Id = id_hex!("CE488DB0C494C7FDBF3DF1731AED68A6");
81
82attributes! {
83    /// Optional short name for quick inspection (fits in ShortString).
84    "2E26F8BA886495A8DF04ACF0ED3ACBD4" as shortname: valueschemas::ShortString;
85    /// Optional longer description stored as a LongString handle.
86    "AE94660A55D2EE3C428D2BB299E02EC3" as description: valueschemas::Handle<hash::Blake3, LongString>;
87    "213F89E3F49628A105B3830BD3A6612C" as value_schema: valueschemas::GenId;
88    "43C134652906547383054B1E31E23DF4" as blob_schema: valueschemas::GenId;
89    "51C08CFABB2C848CE0B4A799F0EFE5EA" as hash_schema: valueschemas::GenId;
90    /// Optional WebAssembly module for formatting values governed by this schema.
91    ///
92    /// The value is a `Handle<Blake3, WasmCode>` that points to a sandboxed
93    /// formatter module (see `triblespace_core::value_formatter`).
94    "1A3D520FEDA9E1A4051EBE96E43ABAC7" as value_formatter: valueschemas::Handle<hash::Blake3, WasmCode>;
95    /// Canonical field name stored as a LongString handle.
96    "7FB28C0B48E1924687857310EE230414" as name: valueschemas::Handle<hash::Blake3, LongString>;
97    /// Preferred JSON representation (e.g. string, number, bool, object, ref, blob).
98    "A7AFC8C0FAD017CE7EC19587AF682CFF" as json_kind: valueschemas::ShortString;
99    /// Generic tag edge: link any entity to a tag entity (by Id). Reusable across domains.
100    "91C50E9FBB1F73E892EBD5FFDE46C251" as tag: valueschemas::GenId;
101}