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