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::Fragment;
13use crate::trible::TribleSet;
14use crate::value::schemas::hash;
15use crate::value::schemas::hash::Blake3;
16use core::marker::PhantomData;
17use triblespace_core_macros::attributes;
18
19/// Emits metadata that can be used for documentation or discovery.
20pub trait Describe {
21    fn describe<B>(&self, blobs: &mut B) -> Result<Fragment, B::PutError>
22    where
23        B: BlobStore<Blake3>;
24}
25
26/// Helper trait for types with a stable compile-time identifier.
27pub trait ConstId {
28    const ID: Id;
29}
30
31/// Helper trait for schema types that want to expose metadata without requiring an instance.
32pub trait ConstDescribe: ConstId {
33    fn describe<B>(blobs: &mut B) -> Result<Fragment, B::PutError>
34    where
35        B: BlobStore<Blake3>,
36    {
37        let _ = blobs;
38        Ok(Fragment::rooted(Self::ID, TribleSet::new()))
39    }
40}
41
42impl<S> Describe for PhantomData<S>
43where
44    S: ConstDescribe,
45{
46    fn describe<B>(&self, blobs: &mut B) -> Result<Fragment, B::PutError>
47    where
48        B: BlobStore<Blake3>,
49    {
50        <S as ConstDescribe>::describe(blobs)
51    }
52}
53
54impl<T> Describe for T
55where
56    T: ConstDescribe,
57{
58    fn describe<B>(&self, blobs: &mut B) -> Result<Fragment, B::PutError>
59    where
60        B: BlobStore<Blake3>,
61    {
62        <T as ConstDescribe>::describe(blobs)
63    }
64}
65
66// namespace constants
67pub const KIND_MULTI: Id = id_hex!("C36D9C16B34729D855BD6C36A624E1BF");
68/// Tag for entities that represent value schemas.
69pub const KIND_VALUE_SCHEMA: Id = id_hex!("9A169BF2383E7B1A3E019808DFE3C2EB");
70/// Tag for entities that represent blob schemas.
71pub const KIND_BLOB_SCHEMA: Id = id_hex!("CE488DB0C494C7FDBF3DF1731AED68A6");
72/// Tag for entities that describe an attribute usage in some source context.
73pub const KIND_ATTRIBUTE_USAGE: Id = id_hex!("45759727A79C28D657EC06D5C6013649");
74/// Tag for entities that describe a protocol.
75pub const KIND_PROTOCOL: Id = id_hex!("A04AD649FA28DC5904385532E9C8EF74");
76/// Tag for entities that are themselves tag/marker constants (e.g. kind discriminants).
77pub const KIND_TAG: Id = id_hex!("452584B4C1CAE0B77F44408E6F194A31");
78
79attributes! {
80    /// Optional long-form description stored as a LongString handle.
81    ///
82    /// This attribute is general-purpose: it can describe any entity. Schema
83    /// metadata uses it for documenting value/blob schemas, but it is equally
84    /// valid for domain entities.
85    "AE94660A55D2EE3C428D2BB299E02EC3" as description: valueschemas::Handle<hash::Blake3, LongString>;
86    "213F89E3F49628A105B3830BD3A6612C" as value_schema: valueschemas::GenId;
87    "43C134652906547383054B1E31E23DF4" as blob_schema: valueschemas::GenId;
88    "51C08CFABB2C848CE0B4A799F0EFE5EA" as hash_schema: valueschemas::GenId;
89    /// Optional WebAssembly module for formatting values governed by this schema.
90    ///
91    /// The value is a `Handle<Blake3, WasmCode>` that points to a sandboxed
92    /// formatter module (see `triblespace_core::value_formatter`).
93    "1A3D520FEDA9E1A4051EBE96E43ABAC7" as value_formatter: valueschemas::Handle<hash::Blake3, WasmCode>;
94    /// Long-form name stored as a LongString handle.
95    ///
96    /// Names are contextual: multiple usages of the same attribute may carry
97    /// different names depending on the codebase or domain. Use attribute
98    /// usage entities (tagged with KIND_ATTRIBUTE_USAGE) when you need to
99    /// capture multiple names for the same attribute id.
100    "7FB28C0B48E1924687857310EE230414" as name: valueschemas::Handle<hash::Blake3, LongString>;
101    /// Link a usage annotation entity to the attribute it describes.
102    "F10DE6D8E60E0E86013F1B867173A85C" as attribute: valueschemas::GenId;
103    /// Optional provenance string for a usage annotation.
104    "A56350FD00EC220B4567FE15A5CD68B8" as source: valueschemas::Handle<hash::Blake3, LongString>;
105    /// Optional module path for the usage annotation (from `module_path!()`).
106    "BCB94C7439215641A3E9760CE3F4F432" as source_module: valueschemas::Handle<hash::Blake3, LongString>;
107    /// Preferred JSON representation (e.g. string, number, bool, object, ref, blob).
108    "A7AFC8C0FAD017CE7EC19587AF682CFF" as json_kind: valueschemas::ShortString;
109    /// Generic tag edge: link any entity to a tag entity (by Id). Reusable across domains.
110    "91C50E9FBB1F73E892EBD5FFDE46C251" as tag: valueschemas::GenId;
111}