Struct atomic_lib::store::Store
source · [−]pub struct Store { /* private fields */ }
Expand description
The in-memory store of data, containing the Resources, Properties and Classes
Implementations
Trait Implementations
sourceimpl Storelike for Store
impl Storelike for Store
sourcefn add_atoms(&self, atoms: Vec<Atom>) -> AtomicResult<()>
fn add_atoms(&self, atoms: Vec<Atom>) -> AtomicResult<()>
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. Read more
sourcefn add_resource_opts(
&self,
resource: &Resource,
check_required_props: bool,
update_index: bool,
overwrite_existing: bool
) -> AtomicResult<()>
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. Read more
sourcefn all_resources(&self, _include_external: bool) -> ResourceCollection
fn all_resources(&self, _include_external: bool) -> ResourceCollection
Returns a collection with 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.
WARNING: This could be very expensive! Read more
sourcefn get_server_url(&self) -> &str
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. Read more
sourcefn get_default_agent(&self) -> AtomicResult<Agent>
fn get_default_agent(&self) -> AtomicResult<Agent>
Returns the default Agent for applying commits.
sourcefn get_resource(&self, subject: &str) -> AtomicResult<Resource>
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
. Read more
sourcefn remove_resource(&self, subject: &str) -> AtomicResult<()>
fn remove_resource(&self, subject: &str) -> AtomicResult<()>
Removes a resource from the store. Errors if not present.
sourcefn set_default_agent(&self, agent: Agent)
fn set_default_agent(&self, agent: Agent)
Sets the default Agent for applying commits.
sourcefn add_atom_to_index(
&self,
_atom: &Atom,
_resource: &Resource
) -> AtomicResult<()>
fn add_atom_to_index(
&self,
_atom: &Atom,
_resource: &Resource
) -> AtomicResult<()>
Adds an Atom to the PropSubjectMap. Overwrites if already present. The default implementation for this does not do anything, so overwrite it if your store needs indexing. Read more
sourcefn add_resource(&self, resource: &Resource) -> AtomicResult<()>
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. Read more
sourcefn build_index(&self, include_external: bool) -> AtomicResult<()>
fn build_index(&self, include_external: bool) -> AtomicResult<()>
Constructs the value index from all resources in the store. Could take a while.
sourcefn get_self_url(&self) -> Option<String>
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
Read more
sourcefn create_agent(&self, name: Option<&str>) -> AtomicResult<Agent>
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()
. Read more
sourcefn export(&self, include_external: bool) -> AtomicResult<String>
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. Read more
sourcefn fetch_resource(&self, subject: &str) -> AtomicResult<Resource>
fn fetch_resource(&self, subject: &str) -> AtomicResult<Resource>
Fetches a resource, makes sure its subject matches. Uses the default agent to sign the request. Save to the store. Read more
sourcefn get_resource_new(&self, subject: &str) -> Resource
fn get_resource_new(&self, subject: &str) -> Resource
Returns an existing resource, or creates a new one with the given Subject
sourcefn get_class(&self, subject: &str) -> AtomicResult<Class>
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
sourcefn get_classes_for_subject(&self, subject: &str) -> AtomicResult<Vec<Class>>
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. Read more
sourcefn get_property(&self, subject: &str) -> AtomicResult<Property>
fn get_property(&self, subject: &str) -> AtomicResult<Property>
Fetches a property by URL, returns a Property instance
sourcefn get_resource_extended(
&self,
subject: &str,
skip_dynamic: bool,
for_agent: Option<&str>
) -> AtomicResult<Resource>
fn get_resource_extended(
&self,
subject: &str,
skip_dynamic: bool,
for_agent: Option<&str>
) -> 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
sourcefn handle_commit(&self, _commit_response: &CommitResponse)
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. Read more
fn handle_not_found(
&self,
subject: &str,
error: AtomicError
) -> AtomicResult<Resource>
sourcefn import(&self, string: &str) -> AtomicResult<usize>
fn import(&self, string: &str) -> AtomicResult<usize>
Imports a JSON-AD string, returns the amount of imported resources
sourcefn tpf(
&self,
q_subject: Option<&str>,
q_property: Option<&str>,
q_value: Option<&Value>,
include_external: bool
) -> AtomicResult<Vec<Atom>>
fn tpf(
&self,
q_subject: Option<&str>,
q_property: Option<&str>,
q_value: Option<&Value>,
include_external: bool
) -> AtomicResult<Vec<Atom>>
Triple Pattern Fragments interface. Use this for most queries, e.g. finding all items with some property / value combination. Returns an empty array if nothing is found. Read more
sourcefn get_path(
&self,
atomic_path: &str,
mapping: Option<&Mapping>,
for_agent: Option<&str>
) -> AtomicResult<PathReturn>
fn get_path(
&self,
atomic_path: &str,
mapping: Option<&Mapping>,
for_agent: Option<&str>
) -> 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 Read more
sourcefn populate(&self) -> AtomicResult<()>
fn populate(&self) -> AtomicResult<()>
Loads the default store. For DBs it also adds default Collections and Endpoints.
sourcefn query(&self, q: &Query) -> AtomicResult<QueryResult>
fn query(&self, q: &Query) -> AtomicResult<QueryResult>
Search the Store, returns the matching subjects.
The second returned vector should be filled if query.include_resources is true.
Tries query_cache
, which you should implement yourself. Read more
sourcefn remove_atom_from_index(
&self,
_atom: &Atom,
_resource: &Resource
) -> AtomicResult<()>
fn remove_atom_from_index(
&self,
_atom: &Atom,
_resource: &Resource
) -> AtomicResult<()>
Removes an Atom from the PropSubjectMap.
sourcefn validate(&self) -> ValidationReport
fn validate(&self) -> ValidationReport
Performs a light validation, without fetching external data
Auto Trait Implementations
impl RefUnwindSafe for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl UnwindSafe for Store
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more