Skip to main content

GtsStore

Struct GtsStore 

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

Implementations§

Source§

impl GtsStore

Source

pub fn new(reader: Option<Box<dyn GtsReader>>) -> Self

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::InvalidSchemaId if the type_id doesn’t end with ‘~’.

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

Returns StoreError::SchemaNotFound if the schema is not found.

Source

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

Source

pub fn resolve_schema_refs(&self, schema: &Value) -> Value

Resolve all $ref references in a JSON Schema by inlining the referenced schemas.

This method recursively traverses the schema, finds all $ref references, and replaces them with the actual schema content from the store. The result is a fully inlined schema with no external references.

§Arguments
  • schema - The JSON Schema value that may contain $ref references
§Returns

A new serde_json::Value with all $ref references resolved and inlined.

§Example
use gts::GtsStore;
let store = GtsStore::new();

// Add schemas to store
store.add_schema_json("parent.v1~", parent_schema)?;
store.add_schema_json("child.v1~", child_schema_with_ref)?;

// Resolve references
let inlined = store.resolve_schema_refs(&child_schema_with_ref);
assert!(!inlined.to_string().contains("$ref"));
Source

pub fn validate_schema(&mut self, gts_id: &str) -> Result<(), StoreError>

Validates a schema against JSON Schema meta-schema and x-gts-ref constraints.

§Errors

Returns StoreError if validation fails.

Source

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

Validates an instance against its schema.

§Errors

Returns StoreError if validation fails.

Source

pub fn cast( &mut self, from_id: &str, target_schema_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_schema_id: &str, new_schema_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

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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