Trait atomic_lib::storelike::Storelike [−][src]
pub trait Storelike: Sized {}Show 26 methods
fn add_atoms(&self, atoms: Vec<Atom>) -> AtomicResult<()>; fn add_resource(&self, resource: &Resource) -> AtomicResult<()>; fn add_resource_unsafe(&self, resource: &Resource) -> AtomicResult<()>; fn all_resources(&self, include_external: bool) -> ResourceCollection; fn get_base_url(&self) -> &str; fn get_resource(&self, subject: &str) -> AtomicResult<Resource>; fn remove_resource(&self, subject: &str) -> AtomicResult<()>; fn set_default_agent(&self, agent: Agent); fn add_atom_to_index(&self, _atom: &Atom) -> AtomicResult<()> { ... } fn build_index(&self, include_external: bool) -> AtomicResult<()> { ... } fn get_self_url(&self) -> Option<String> { ... } fn get_default_agent(&self) -> AtomicResult<Agent> { ... } fn create_agent(&self, name: Option<&str>) -> AtomicResult<Agent> { ... } fn export(&self, include_external: bool) -> AtomicResult<String> { ... } fn fetch_resource(&self, subject: &str) -> AtomicResult<Resource> { ... } fn get_class(&self, subject: &str) -> AtomicResult<Class> { ... } fn get_classes_for_subject(&self, subject: &str) -> AtomicResult<Vec<Class>> { ... } fn get_property(&self, subject: &str) -> AtomicResult<Property> { ... } fn get_resource_extended(&self, subject: &str) -> AtomicResult<Resource> { ... } fn handle_not_found(
&self,
subject: &str,
error: Box<dyn Error>
) -> AtomicResult<Resource> { ... } fn import(&self, string: &str) -> AtomicResult<usize> { ... } fn tpf(
&self,
q_subject: Option<&str>,
q_property: Option<&str>,
q_value: Option<&str>,
include_external: bool
) -> AtomicResult<Vec<Atom>> { ... } fn get_path(
&self,
atomic_path: &str,
mapping: Option<&Mapping>
) -> AtomicResult<PathReturn> { ... } fn populate(&self) -> AtomicResult<()> { ... } fn remove_atom_from_index(&self, _atom: &Atom) -> AtomicResult<()> { ... } fn validate(&self) -> ValidationReport { ... }
Expand description
Storelike provides many useful methods for interacting with an Atomic Store. It serves as a basic store Trait, agnostic of how it functions under the hood. This is useful, because we can create methods for Storelike that will work with either in-memory stores, as well as with persistend on-disk stores.
Required methods
Adds Atoms to the store. Will replace existing Atoms that share Subject / Property combination. Validates datatypes and required props presence.
fn 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.
Does not build indexes or save versions.
In most cases, you should use resource.save() instead, which uses Commits.
fn add_resource_unsafe(&self, resource: &Resource) -> AtomicResult<()>
fn add_resource_unsafe(&self, resource: &Resource) -> AtomicResult<()>
Adds a Resource to the store. Replaces existing resource with the contents. Does not do any validations.
fn 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!
fn get_base_url(&self) -> &str
fn get_base_url(&self) -> &str
Returns the root 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.
fn 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.
fn remove_resource(&self, subject: &str) -> AtomicResult<()>
fn remove_resource(&self, subject: &str) -> AtomicResult<()>
Removes a resource from the store. Errors if not present.
fn set_default_agent(&self, agent: Agent)
fn set_default_agent(&self, agent: Agent)
Sets the default Agent for applying commits.
Provided methods
fn add_atom_to_index(&self, _atom: &Atom) -> AtomicResult<()>
fn add_atom_to_index(&self, _atom: &Atom) -> 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.
fn 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.
fn 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
fn get_default_agent(&self) -> AtomicResult<Agent>
fn get_default_agent(&self) -> AtomicResult<Agent>
Returns the default Agent for applying commits.
fn 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.
fn export(&self, include_external: bool) -> AtomicResult<String>
fn export(&self, include_external: bool) -> AtomicResult<String>
Exports the store to a big JSON-AD file
fn fetch_resource(&self, subject: &str) -> AtomicResult<Resource>
fn fetch_resource(&self, subject: &str) -> AtomicResult<Resource>
Fetches a resource, makes sure its subject matches. Save to the store.
fn 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
fn 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.
fn get_property(&self, subject: &str) -> AtomicResult<Property>
fn get_property(&self, subject: &str) -> AtomicResult<Property>
Fetches a property by URL, returns a Property instance
fn get_resource_extended(&self, subject: &str) -> AtomicResult<Resource>
fn get_resource_extended(&self, subject: &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
fn handle_not_found(
&self,
subject: &str,
error: Box<dyn Error>
) -> AtomicResult<Resource>
fn import(&self, string: &str) -> AtomicResult<usize>
fn import(&self, string: &str) -> AtomicResult<usize>
Imports a JSON-AD string, returns the amount of imported resources
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.
Example
For example, if I want to view all Resources that are instances of the class “Property”, I’d do:
use atomic_lib::Storelike; let mut store = atomic_lib::Store::init().unwrap(); store.populate(); let atoms = store.tpf( None, Some("https://atomicdata.dev/properties/isA"), Some("[\"https://atomicdata.dev/classes/Class\"]"), true ).unwrap(); assert_eq!(atoms.len(), 11)
fn get_path(
&self,
atomic_path: &str,
mapping: Option<&Mapping>
) -> AtomicResult<PathReturn>
fn get_path(
&self,
atomic_path: &str,
mapping: Option<&Mapping>
) -> 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
fn populate(&self) -> AtomicResult<()>
fn populate(&self) -> AtomicResult<()>
Loads the default store. For DBs it also adds default Collections and Endpoints.
fn remove_atom_from_index(&self, _atom: &Atom) -> AtomicResult<()>
fn remove_atom_from_index(&self, _atom: &Atom) -> AtomicResult<()>
Removes an Atom from the PropSubjectMap.
fn validate(&self) -> ValidationReport
fn validate(&self) -> ValidationReport
Performs a light validation, without fetching external data