pub struct GtsStore { /* private fields */ }Implementations§
Source§impl GtsStore
impl GtsStore
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty, reader-free store. Callers populate it explicitly via
Self::register / Self::register_schema. With no GtsReader,
get and resolution never fall back to lazy I/O — the store sees
exactly what was registered.
Sourcepub fn with_reader(reader: Box<dyn GtsReader>) -> Self
pub fn with_reader(reader: Box<dyn GtsReader>) -> Self
Store backed by a GtsReader, eagerly populated from it. get falls
back to the reader for ids not yet cached.
Sourcepub fn register(&mut self, entity: GtsEntity) -> Result<(), StoreError>
pub fn register(&mut self, entity: GtsEntity) -> Result<(), StoreError>
Registers an entity in the store.
§Errors
Returns StoreError::InvalidEntity if the entity has no effective ID.
Sourcepub fn register_schema(
&mut self,
type_id: &str,
schema: &Value,
) -> Result<(), StoreError>
pub fn register_schema( &mut self, type_id: &str, schema: &Value, ) -> Result<(), StoreError>
Registers a schema in the store.
§Errors
Returns StoreError::InvalidTypeId if type_id is not a valid GTS type id.
pub fn get(&mut self, entity_id: &str) -> Option<&GtsEntity>
Sourcepub fn get_schema_content(&mut self, type_id: &str) -> Result<Value, StoreError>
pub fn get_schema_content(&mut self, type_id: &str) -> Result<Value, StoreError>
pub fn items(&self) -> impl Iterator<Item = (&String, &GtsEntity)>
Sourcepub fn resolve_schema_refs(&self, schema: &Value) -> Result<Value, StoreError>
pub fn resolve_schema_refs(&self, schema: &Value) -> Result<Value, StoreError>
Strict $ref resolution that errors on an unresolved supported local
JSON Pointer or external GTS $ref, or a circular $ref.
§Errors
Sourcepub fn validate_schema(
&mut self,
type_id: &str,
) -> Result<ResolvedType, StoreError>
pub fn validate_schema( &mut self, type_id: &str, ) -> Result<ResolvedType, StoreError>
Fully validate a registered type schema and return its resolved
ResolvedType in a single pass. Every type it depends on (its
$id-chain ancestors and the targets of its gts:// $refs) must
already be registered.
Pipeline:
Self::validate_schema_refs—$ref/x-gts-refstructure;crate::schema_modifiers::validate_gts_keywords— format and top-level placement ofx-gts-final/x-gts-abstract/x-gts-traits/x-gts-traits-schema;Self::validate_schema_chain— derived-vs-base compatibility (OP#12);- resolve: inline
#/andgts://$refs into a self-contained body; - meta-compile the resolved body against JSON Schema — registration
defers this whenever raw
gts://refs are present, so it is done here once every dependency is inlined, catching malformed schema bodies; - build the effective traits schema/values exactly once and validate
them (OP#13): provided trait values are always type/enum/
x-gts-refchecked; the required-trait completeness check is skipped for abstract leaves.
Abstract types still type-check any trait values they provide, but skip the OP#13 completeness check (a descendant closes the required traits).
Uncached: a consumer that calls this repeatedly for the same type_id
should cache the result (safe forever — versioned ids are immutable).
crate::ops::GtsOps::validate_schema wraps this for the
/validate-type-schema endpoint, discarding the resolved artifacts.
§Errors
StoreError::ValidationError if any validation stage fails or a
dependency is missing from the store; StoreError::SchemaNotFound if the
type is not registered.
Sourcepub fn validate_payload(
&mut self,
type_id: &str,
payload: &Value,
) -> Result<(), StoreError>
pub fn validate_payload( &mut self, type_id: &str, payload: &Value, ) -> Result<(), StoreError>
Validate a caller-supplied instance payload against type_id’s schema.
Stateless: no registered instance is required, but the type and its
$ref/chain dependencies must be registered. Rejects abstract types
(OP#6) and enforces x-gts-ref.
§Errors
StoreError::ValidationError on schema-compile failure, JSON Schema
validation failure, abstract type, or x-gts-ref violation;
StoreError::SchemaNotFound if the type is not registered.