Skip to main content

GtsStore

Struct GtsStore 

Source
pub struct GtsStore { /* private fields */ }

Implementations§

Source§

impl GtsStore

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get(&mut self, entity_id: &str) -> Option<&GtsEntity>

Source

pub fn get_schema_content(&mut self, type_id: &str) -> Result<Value, StoreError>

Gets the content of a schema by its type ID.

§Errors

See Self::get_schema_entity.

Source

pub fn items(&self) -> impl Iterator<Item = (&String, &GtsEntity)>

Source

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

StoreError::UnresolvedRefs or StoreError::CircularRef.

Source

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:

  1. Self::validate_schema_refs$ref/x-gts-ref structure;
  2. crate::schema_modifiers::validate_gts_keywords — format and top-level placement of x-gts-final/x-gts-abstract/x-gts-traits/ x-gts-traits-schema;
  3. Self::validate_schema_chain — derived-vs-base compatibility (OP#12);
  4. resolve: inline #/ and gts:// $refs into a self-contained body;
  5. 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;
  6. build the effective traits schema/values exactly once and validate them (OP#13): provided trait values are always type/enum/x-gts-ref checked; 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.

Source

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.

Source

pub fn validate_instance(&mut self, instance_id: &str) -> Result<(), StoreError>

Validates an instance against its schema.

§Errors

Returns StoreError if validation fails.

Source

pub fn cast( &mut self, instance_id: &str, target_type_id: &str, ) -> Result<GtsEntityCastResult, StoreError>

Casts an entity from one schema to another.

§Errors

Returns StoreError if the cast fails.

Source

pub fn is_minor_compatible( &mut self, old_type_id: &str, new_type_id: &str, ) -> GtsEntityCastResult

Source

pub fn build_schema_graph(&mut self, gts_id: &str) -> Value

Source

pub fn query(&self, expr: &str, limit: usize) -> GtsStoreQueryResult

Trait Implementations§

Source§

impl Default for GtsStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more