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