Struct Store

Source
pub struct Store { /* private fields */ }
Expand description

The in-memory store of data, containing the Resources, Properties and Classes It uses the default_agent as the default client.

Implementations§

Source§

impl Store

Source

pub fn init() -> AtomicResult<Store>

Creates an empty Store. Run .populate() to get useful standard models loaded into your store.

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Storelike for Store

Source§

fn add_atoms(&self, atoms: Vec<Atom>) -> AtomicResult<()>

👎Deprecated since 0.28.0: The atoms abstraction has been deprecated in favor of Resources
Adds Atoms to the store. Will replace existing Atoms that share Subject / Property combination. Validates datatypes and required props presence.
Source§

fn add_resource_opts( &self, resource: &Resource, check_required_props: bool, update_index: bool, overwrite_existing: bool, ) -> AtomicResult<()>

Adds a Resource to the store. Replaces existing resource with the contents. Does not do any validations.
Source§

fn all_resources( &self, _include_external: bool, ) -> Box<dyn Iterator<Item = Resource>>

Returns an iterator that iterates over all resources in the store. If Include_external is false, this is filtered by selecting only resoureces that match the self URL of the store.
Source§

fn get_server_url(&self) -> &str

Returns the base URL where the default store is. E.g. https://example.com This is where deltas should be sent to. Also useful for Subject URL generation.
Source§

fn get_self_url(&self) -> Option<String>

Returns the root URL where this instance of the store is hosted. Should return None if this is simply a client and not a server. E.g. https://example.com
Source§

fn get_default_agent(&self) -> AtomicResult<Agent>

Returns the default Agent for applying commits.
Source§

fn get_resource(&self, subject: &str) -> AtomicResult<Resource>

Returns a full Resource with native Values. Note that this does not construct dynamic Resources, such as collections. If you’re not sure what to use, use get_resource_extended.
Source§

fn remove_resource(&self, subject: &str) -> AtomicResult<()>

Removes a resource from the store. Errors if not present.
Source§

fn set_default_agent(&self, agent: Agent)

Sets the default Agent for applying commits.
Source§

fn query(&self, q: &Query) -> AtomicResult<QueryResult>

Search the Store, returns the matching subjects.
Source§

fn add_resource(&self, resource: &Resource) -> AtomicResult<()>

Adds a Resource to the store. Replaces existing resource with the contents. Updates the index. Validates the fields (checks required props). In most cases, you should use resource.save() instead, which uses Commits.
Source§

fn apply_commit( &self, commit: Commit, opts: &CommitOpts, ) -> AtomicResult<CommitResponse>

Takes a Commit and applies it to the Store. This includes changing the resource, writing the changes, verifying the checks specified in your CommitOpts The returned CommitResponse contains the new resource and the saved Commit Resource.
Source§

fn get_value(&self, subject: &str, property: &str) -> AtomicResult<Value>

Returns a single Value from a Resource
Source§

fn create_agent(&self, name: Option<&str>) -> AtomicResult<Agent>

Create an Agent, storing its public key. An Agent is required for signing Commits. Returns a tuple of (subject, private_key). Make sure to store the private_key somewhere safe! Does not create a Commit - the recommended way is to use agent.to_resource().save_locally().
Source§

fn export(&self, include_external: bool) -> AtomicResult<String>

Exports the store to a big JSON-AD file. Sorts the export by first exporting Property Resources, which makes importing faster and more dependent.
Source§

fn fetch_resource( &self, subject: &str, client_agent: Option<&Agent>, ) -> AtomicResult<Resource>

Fetches a resource, makes sure its subject matches. Save to the store. Uses client_agent for Authentication.
Source§

fn get_resource_new(&self, subject: &str) -> Resource

Returns an existing resource, or creates a new one with the given Subject
Source§

fn get_class(&self, subject: &str) -> AtomicResult<Class>

Retrieves a Class from the store by subject URL and converts it into a Class useful for forms
Source§

fn get_classes_for_subject(&self, subject: &str) -> AtomicResult<Vec<Class>>

Finds all classes (isA) for any subject. Returns an empty vector if there are none.
Source§

fn get_property(&self, subject: &str) -> AtomicResult<Property>

Fetches a property by URL, returns a Property instance
Source§

fn get_resource_extended( &self, subject: &str, skip_dynamic: bool, for_agent: &ForAgent, ) -> AtomicResult<Resource>

Get’s the resource, parses the Query parameters and calculates dynamic properties. Defaults to get_resource if store doesn’t support extended resources If for_agent is None, no authorization checks will be done, and all resources will return. If you want public only resurces, pass Some(crate::authentication::public_agent) as the agent. Read more
Source§

fn handle_commit(&self, _commit_response: &CommitResponse)

This function is called whenever a Commit is applied. Implement this if you want to have custom handlers for Commits.
Source§

fn handle_not_found( &self, subject: &str, _error: AtomicError, for_agent: Option<&Agent>, ) -> AtomicResult<Resource>

Source§

fn import(&self, string: &str, parse_opts: &ParseOpts) -> AtomicResult<usize>

Imports a JSON-AD string, returns the amount of imported resources.
Source§

fn get_path( &self, atomic_path: &str, mapping: Option<&Mapping>, for_agent: &ForAgent, ) -> AtomicResult<PathReturn>

Accepts an Atomic Path string, returns the result value (resource or property value) E.g. https://example.com description or thing isa 0 https://docs.atomicdata.dev/core/paths.html The for_agent argument is used to check if the user has rights to the resource. You can pass None if you don’t care about the rights (e.g. in client side apps) If you want to perform read rights checks, pass Some for_agent subject
Source§

fn post_resource( &self, _subject: &str, _body: Vec<u8>, _for_agent: &ForAgent, ) -> AtomicResult<Resource>

Handles a HTTP POST request to the store. This is where [crate::endpoints::Endpoint] are used.
Source§

fn populate(&self) -> AtomicResult<()>

Loads the default store. For DBs it also adds default Collections and Endpoints.
Source§

fn validate(&self) -> ValidationReport

Performs a light validation, without fetching external data

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnwindSafe for Store

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,