pub struct Context {
pub auth: AuthBlock,
pub requested_format: ContentType,
pub backend_manager: Option<Arc<BackendManager>>,
pub root_directory: Arc<str>,
pub pubsub_lookup: Option<PubSubLookupFn>,
/* private fields */
}Expand description
Request context. Five typed blocks per ADR-011 plus host-only side fields.
The shape after Wave-3 collapse (2026-05-25):
- WIT-mirrored blocks crossing the ABI:
request,lineage,routing(optional),identity(optional — the resolved view). - Host-side auth state consumed by the dispatch pipeline:
auth: AuthBlockholdingidentity_input(wire-level credential),access(resolvedUser+Role), andpermission(per-requestTablePermissioncache). - Host-only side-channel for backend manager, pubsub lookup, parsed JSON body, requested content-type, and rootDirectory.
auth.identity_input is renamed from the old flat auth_identity
field to avoid colliding with the WIT-side identity block above
(which is the post-auth resolved shape that crosses the ABI).
Clone is implemented manually so the wasm-only LazyBacking
field can be reset on clone (the underlying Box<dyn WitContextHandle> isn’t itself Clone). Cloned wasm Contexts
inherit eager fields only — host code paths use Clone freely.
Fields§
§auth: AuthBlockHost-side authentication/authorization state consumed by the dispatch pipeline.
requested_format: ContentTypeNegotiated response content-type (from the Accept header).
backend_manager: Option<Arc<BackendManager>>Backend manager for table access; None on contexts without storage.
root_directory: Arc<str>Deployment root directory (rootDirectory), used to resolve on-disk paths.
pubsub_lookup: Option<PubSubLookupFn>Lookup for a table’s PubSub manager; None when pub/sub is unavailable.
Implementations§
Source§impl Context
impl Context
Sourcepub fn from_request(
method: Method,
path: impl Into<EcoString>,
body: Bytes,
headers: HeaderMap,
) -> Self
pub fn from_request( method: Method, path: impl Into<EcoString>, body: Bytes, headers: HeaderMap, ) -> Self
Create a Context from a raw inbound request. Subsequent layers fill in
routing (router), identity (auth pipeline), and other side fields.
Sourcepub fn placeholder() -> Self
pub fn placeholder() -> Self
Vacant Context used as a swap target for Tower Service<Context> chains.
Sourcepub fn for_service(
app_id: Arc<str>,
root_directory: Arc<str>,
backend_manager: Option<Arc<BackendManager>>,
pubsub_lookup: Option<PubSubLookupFn>,
) -> Self
pub fn for_service( app_id: Arc<str>, root_directory: Arc<str>, backend_manager: Option<Arc<BackendManager>>, pubsub_lookup: Option<PubSubLookupFn>, ) -> Self
Context for on_ready / queue-worker / scheduled dispatch.
Sourcepub const fn routing(&self) -> Option<&Routing>
pub const fn routing(&self) -> Option<&Routing>
The routing block, when the router has populated it. None
only on raw-request contexts that bypassed the router (e.g.
test fixtures, queue-worker dispatch). Most call sites should
reach for the flat accessors (app_id(), resource_id(),
database(), etc.) instead.
Sourcepub const fn query_params_mut(&mut self) -> &mut HashMap<String, String>
pub const fn query_params_mut(&mut self) -> &mut HashMap<String, String>
Mutable access to the query-param map. Used by routing code
that augments the parsed query with synthetic keys (_search,
path-extracted values, etc.) before downstream handlers
observe it.
Sourcepub fn query_params(&self) -> &HashMap<String, String>
pub fn query_params(&self) -> &HashMap<String, String>
The parsed query-param map.
Sourcepub fn app_id(&self) -> Arc<str> ⓘ
pub fn app_id(&self) -> Arc<str> ⓘ
Application id from routing, or empty Arc<str> when unrouted.
Sourcepub fn resource_id(&self) -> Arc<str> ⓘ
pub fn resource_id(&self) -> Arc<str> ⓘ
Resource (table) id from routing, or empty Arc<str> when unrouted.
Sourcepub fn is_collection(&self) -> bool
pub fn is_collection(&self) -> bool
true when this is a collection-level operation (no record key).
Sourcepub fn database(&self) -> Arc<str> ⓘ
pub fn database(&self) -> Arc<str> ⓘ
Database name. Settled at request-routing time from
TableDefinition.database (or the default "data" when the
table doesn’t specify). Distinct from app_id — the
@database schema directive can point a table at a database
shared across apps. Returns empty string when no routing.
Sourcepub fn table_name(&self) -> Arc<str> ⓘ
pub fn table_name(&self) -> Arc<str> ⓘ
Table name. For table-backed resources the resource name IS the table name.
Sourcepub fn set_method(&mut self, m: Method)
pub fn set_method(&mut self, m: Method)
Set the request method.
Sourcepub fn set_headers(&mut self, h: HeaderMap)
pub fn set_headers(&mut self, h: HeaderMap)
Set the request headers.
Sourcepub const fn set_protocol(&mut self, p: Protocol)
pub const fn set_protocol(&mut self, p: Protocol)
Set the wire protocol.
Sourcepub fn set_query_params(&mut self, q: HashMap<String, String>)
pub fn set_query_params(&mut self, q: HashMap<String, String>)
Replace the parsed query-param map.
Sourcepub fn set_app_id(&mut self, app_id: Arc<str>)
pub fn set_app_id(&mut self, app_id: Arc<str>)
Set the routing app id (creating a Routing block if absent).
Sourcepub fn set_resource_id(&mut self, resource_id: Arc<str>)
pub fn set_resource_id(&mut self, resource_id: Arc<str>)
Set the routing resource id (creating a Routing block if absent).
Sourcepub fn set_path_id(&mut self, key: impl Into<String>)
pub fn set_path_id(&mut self, key: impl Into<String>)
Set the routing record key (empty string clears it to collection-level).
Sourcepub fn set_is_collection(&mut self, is_coll: bool)
pub fn set_is_collection(&mut self, is_coll: bool)
Clear the record key when is_coll is true (makes the op collection-level).
Sourcepub fn set_database(&mut self, db: Arc<str>)
pub fn set_database(&mut self, db: Arc<str>)
Set the database field on the current Routing (creating a
Routing block if none exists). Called by the router after it
resolves the target table’s @database directive.
Sourcepub fn set_table_name(&mut self, name: Arc<str>)
pub fn set_table_name(&mut self, name: Arc<str>)
Set the routing table name (aliases the resource id for table-backed resources).
Sourcepub fn app_id_str(&self) -> &str
pub fn app_id_str(&self) -> &str
Application ID as &str.
Sourcepub fn resource_id_str(&self) -> &str
pub fn resource_id_str(&self) -> &str
Resource ID as &str — borrow-returning counterpart to
resource_id() (which returns an owned Arc<str>).
Sourcepub fn pubsub(&self, table_name: &str) -> Option<Arc<PubSubManager>>
pub fn pubsub(&self, table_name: &str) -> Option<Arc<PubSubManager>>
PubSub manager for a named table.
Sourcepub fn require_backend(&self, name: &str) -> Result<Arc<dyn KvBackend>>
pub fn require_backend(&self, name: &str) -> Result<Arc<dyn KvBackend>>
Raw table backend accessor that errors when missing.
§Errors
YetiError::Internal when no backend is attached or registered for name.
Sourcepub fn query_int(&self, name: &str, default: i64) -> i64
pub fn query_int(&self, name: &str, default: i64) -> i64
A named query parameter parsed as i64, falling back to default.
Sourcepub fn query_bool(&self, name: &str, default: bool) -> bool
pub fn query_bool(&self, name: &str, default: bool) -> bool
A named query parameter parsed as a bool (true/1/yes/on),
falling back to default.
Sourcepub fn table_context(&self) -> (&str, &str)
pub fn table_context(&self) -> (&str, &str)
Get the database and table name as a pair (for permission checks).
Database comes from routing.database (settled at routing time
from the table’s @database directive); table comes from
routing.resource.
Sourcepub fn database_str(&self) -> &str
pub fn database_str(&self) -> &str
Database name as &str. See Self::database for the full
distinction between database and app_id.
Sourcepub fn table_name_str(&self) -> &str
pub fn table_name_str(&self) -> &str
Table name as &str. For table-backed resources, the resource name
IS the table name.
Sourcepub fn json_body(&self) -> Option<&Value>
pub fn json_body(&self) -> Option<&Value>
The request body parsed as JSON — lazily on first call, cached
thereafter. None for an empty or non-JSON body. Requests that
never read it (e.g. public/super-user writes that skip
attribute-level permission checks) never pay the parse. Goes
through body() so the wasm lazy backing materializes request
first.
Sourcepub fn parse_body(&mut self)
pub fn parse_body(&mut self)
Force the lazy Context::json_body parse now. Useful when a
later &self reader shouldn’t pay the cost, or to pre-warm the
cache. No-op once cached or for an empty body.
Sourcepub const fn access(&self) -> &Access
pub const fn access(&self) -> &Access
Resolved Access for this request. Defaults to Access::None
when unauthenticated.
Sourcepub const fn permission(&self) -> &TablePermission
pub const fn permission(&self) -> &TablePermission
Cached per-request TablePermission decision.
Sourcepub const fn auth_identity(&self) -> Option<&AuthIdentity>
pub const fn auth_identity(&self) -> Option<&AuthIdentity>
Wire-level authentication claim produced by an
AuthProvider::authenticate() call. None for unauthenticated
requests.
Sourcepub fn request_id(&self) -> &str
pub fn request_id(&self) -> &str
Request id (UUIDv7) — stamped by the inbound router, propagates
through HLC + logs.
Sourcepub fn parent_id(&self) -> Option<&str>
pub fn parent_id(&self) -> Option<&str>
Parent request id when this request was triggered by another (e.g. queue worker dispatching a job’s child call).
Sourcepub fn correlation_id(&self) -> Option<&str>
pub fn correlation_id(&self) -> Option<&str>
Cross-request correlation id (e.g. customer’s X-Correlation-Id
header). None when no correlation was passed.
Sourcepub fn deployment(&self) -> &str
pub fn deployment(&self) -> &str
Deployment hash — identifies the yeti-fabric node that produced
this request. Defaults to "local" for single-tenant dev.
Sourcepub const fn hlc(&self) -> Hlc
pub const fn hlc(&self) -> Hlc
Hybrid Logical Clock stamp at request receipt. Copy, so
returned by value.
Sourcepub const fn identity(&self) -> Option<&Identity>
pub const fn identity(&self) -> Option<&Identity>
Resolved request identity — None for unauthenticated requests
or paths that bypass the auth pipeline (public endpoints).
Sourcepub fn principal(&self) -> Option<&str>
pub fn principal(&self) -> Option<&str>
Convenience: the authenticated principal (username / email /
service id) when the request resolved an identity. Equivalent
to ctx.identity().and_then(|i| i.principal.as_deref()).
Sourcepub fn roles(&self) -> &[String]
pub fn roles(&self) -> &[String]
Convenience: the authenticated role set, or empty slice when
unauthenticated. Always-safe-to-iterate shape; for permission
checks prefer Self::permissions which carries the resolved
super_user bit + per-resource ops mask.
Sourcepub fn permissions(&self) -> Option<&Permissions>
pub fn permissions(&self) -> Option<&Permissions>
Convenience: the resolved permission bundle (super_user +
per-resource op mask). Returns a default-empty Permissions
when unauthenticated so call sites can chain .super_user
without an outer Option dance.
Sourcepub fn auth_method(&self) -> AuthMethod
pub fn auth_method(&self) -> AuthMethod
Convenience: the authentication method (basic / jwt / oauth / api-key / service-token / none).
Sourcepub fn set_request_id(&mut self, id: impl Into<String>)
pub fn set_request_id(&mut self, id: impl Into<String>)
Set the request id.
Sourcepub fn set_parent_id(&mut self, parent: Option<String>)
pub fn set_parent_id(&mut self, parent: Option<String>)
Set the parent request id.
Sourcepub fn set_correlation_id(&mut self, c: Option<String>)
pub fn set_correlation_id(&mut self, c: Option<String>)
Set the cross-request correlation id.
Sourcepub fn set_deployment(&mut self, d: impl Into<String>)
pub fn set_deployment(&mut self, d: impl Into<String>)
Set the deployment hash.
Sourcepub fn set_identity(&mut self, identity: Option<Identity>)
pub fn set_identity(&mut self, identity: Option<Identity>)
Set the resolved identity block.
Sourcepub fn set_routing(&mut self, routing: Option<Routing>)
pub fn set_routing(&mut self, routing: Option<Routing>)
Set the routing block.
Sourcepub fn set_access(&mut self, access: Access)
pub fn set_access(&mut self, access: Access)
Set the resolved Access.
Sourcepub fn set_permission(&mut self, p: TablePermission)
pub fn set_permission(&mut self, p: TablePermission)
Set the cached TablePermission decision.
Sourcepub fn set_auth_identity(&mut self, id: Option<AuthIdentity>)
pub fn set_auth_identity(&mut self, id: Option<AuthIdentity>)
Set the wire-level authentication claim.
Sourcepub const fn access_mut(&mut self) -> &mut Access
pub const fn access_mut(&mut self) -> &mut Access
Mutable Access for the auth pipeline’s save/restore pattern:
std::mem::take(ctx.access_mut()) swaps in Access::default()
so the resolver runs against a clean slate, then restoration
writes back via Self::set_access.
Sourcepub const fn auth_identity_mut(&mut self) -> &mut Option<AuthIdentity>
pub const fn auth_identity_mut(&mut self) -> &mut Option<AuthIdentity>
Mutable wire-level authentication claim (companion to
Self::access_mut for the same save/restore pattern).