Struct noosphere_core::context::SphereContext
source · pub struct SphereContext<S>where
S: Storage + 'static,{ /* private fields */ }Expand description
A SphereContext is an accessor construct over locally replicated sphere data. It embodies both the storage layer that contains the sphere’s data as the information needed to verify a user’s intended level of access to it (e.g., local key material and ucan::Ucan-based authorization). Additionally, the SphereContext maintains a reference to an API Client that may be initialized as the network becomes available.
All interactions that pertain to a sphere, including reading or writing its contents and syncing with a gateway, flow through the SphereContext.
Implementations§
source§impl<S> SphereContext<S>where
S: Storage,
impl<S> SphereContext<S>where S: Storage,
sourcepub async fn new(
sphere_identity: Did,
author: Author<SphereContextKey>,
db: SphereDb<S>,
origin_sphere_identity: Option<Did>
) -> Result<Self>
pub async fn new( sphere_identity: Did, author: Author<SphereContextKey>, db: SphereDb<S>, origin_sphere_identity: Option<Did> ) -> Result<Self>
Instantiate a new SphereContext given a sphere Did, an Author, a SphereDb and an optional origin sphere Did. The origin sphere Did is intended to signify whether the SphereContext is a local sphere, or a global sphere that is being visited by a local author. In most cases, a SphereContext with some value set as the origin sphere Did will be read-only.
sourcepub async fn to_visitor(&self, peer_identity: &Did) -> Result<Self>
pub async fn to_visitor(&self, peer_identity: &Did) -> Result<Self>
Clone this SphereContext, setting the sphere identity to a peer’s Did
Clone this SphereContext, replacing the Author with the provided one
sourcepub async fn traverse_by_identity(
&self,
_sphere_identity: &Did
) -> Result<SphereContext<S>>
pub async fn traverse_by_identity( &self, _sphere_identity: &Did ) -> Result<SphereContext<S>>
Given a Did of a sphere, produce a SphereContext backed by the same credentials and storage primitives as this one, but that accesses the sphere referred to by the provided Did.
sourcepub async fn gateway_identity(&self) -> Result<Did>
pub async fn gateway_identity(&self) -> Result<Did>
The identity of the gateway sphere in use during this session, if any; note that this will cause a request to be made to a gateway if no handshake has yet occurred.
sourcepub async fn version(&self) -> Result<Link<MemoIpld>>
pub async fn version(&self) -> Result<Link<MemoIpld>>
The CID of the most recent local version of this sphere
The Author who is currently accessing the sphere
sourcepub async fn access(&self) -> Result<Access>
pub async fn access(&self) -> Result<Access>
The Access level that the configured Author has relative to the sphere that this SphereContext refers to.
sourcepub fn did_parser_mut(&mut self) -> &mut DidParser
pub fn did_parser_mut(&mut self) -> &mut DidParser
Get a mutable reference to the DidParser used in this SphereContext
sourcepub async fn configure_gateway_url(&mut self, url: Option<&Url>) -> Result<()>
pub async fn configure_gateway_url(&mut self, url: Option<&Url>) -> Result<()>
Sets or unsets the gateway URL that points to the gateway API that the sphere will use when it is syncing.
sourcepub fn db(&self) -> &SphereDb<S>
pub fn db(&self) -> &SphereDb<S>
Get the SphereDb instance that manages the current sphere’s block space and persisted configuration.
sourcepub fn db_mut(&mut self) -> &mut SphereDb<S>
pub fn db_mut(&mut self) -> &mut SphereDb<S>
Get a mutable reference to the SphereDb instance that manages the current sphere’s block space and persisted configuration.
sourcepub fn mutation(&self) -> &SphereMutation
pub fn mutation(&self) -> &SphereMutation
Get a read-only reference to the underlying SphereMutation that this SphereContext is tracking
sourcepub fn mutation_mut(&mut self) -> &mut SphereMutation
pub fn mutation_mut(&mut self) -> &mut SphereMutation
Get a mutable reference to the underlying SphereMutation that this SphereContext is tracking
sourcepub async fn sphere(&self) -> Result<Sphere<SphereDb<S>>>
pub async fn sphere(&self) -> Result<Sphere<SphereDb<S>>>
Get a Sphere view over the current sphere’s latest revision. This view offers lower-level access than HasSphereContext, but includes affordances to help tranversing and manipulating IPLD structures that are more convenient than working directly with raw data.