MemoryQueries

class MemoryQueries @InternalWowApi constructor(manifest: Manifest, stateTypes: Map<AggregateType, Class<*>> = emptyMap(), access: List<AccessPolicy<*>> = emptyList(), filters: List<QueryFilter> = emptyList()) : TenantQueryApi

A real read side for a processor spec (ProcessorSpec.givenQueries): the query engine of the Manifest the modules on the class path declare, over snapshots held in memory. A handler's reads run as on a node: the filters, the scope and tenant policies and the budgets apply, and the snapshots decode as the aggregates' state classes.

The Manifest and the state classes come from the modules' binding index (ModelProvider): each module's fragment, merged, and each state class the Manifest names by its binary name (#/$defs/<binary name>, as the compiler writes it), so a state is read by its class whatever the model takes, the node's QueryApi or any other service. A state a hand-written fragment names otherwise comes from the module's models, built with the dependencies given, else from the states given to it (snapshot).

sagaSpec(handlers) {
givenQueries(memoryQueries { snapshots(Stock.TYPE, "mug" to Stock(7), "cup" to Stock(0)) })
whenEvent(...) { ... }
}

Only the snapshot queries are served, with the state reads by id of the snapshots given; the events and the datasets are not. A spec builds one with memoryQueries or of.

Constructors

Link copied to clipboard
constructor(manifest: Manifest, stateTypes: Map<AggregateType, Class<*>> = emptyMap(), access: List<AccessPolicy<*>> = emptyList(), filters: List<QueryFilter> = emptyList())

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun of(caller: Caller): Queries
Link copied to clipboard
fun <S : Any> snapshot(model: AggregateModel<S>, id: String, vararg events: Any, tenantId: String = Caller.DEFAULT_TENANT, owner: Scope = Scope.NONE, deleted: Boolean = false): MemoryQueries

Holds the state events leave the aggregate id of model in as its latest snapshot, in tenantId, at the version of its last event, one commit per event: model replays them as ProcessorSpec.givenAggregate does, so the state is the one the aggregate's own sourcing builds. An event model has no sourcing function for is refused. owner and deleted are the snapshot's, as snapshot of a state takes them; its access attributes are those model reads from the state.

fun snapshot(type: AggregateType, id: String, state: Any, tenantId: String = Caller.DEFAULT_TENANT, owner: Scope = Scope.NONE, version: Int = 1, access: Map<String, Any?> = emptyMap(), deleted: Boolean = false): MemoryQueries

Holds state as the latest snapshot of the aggregate id of type in tenantId: what the snapshot queries and a state read by id of it return. owner is its scope, the owner and space the scope policies check, and access its declared access attributes by name (a single one's value, a multiple one's values).

Link copied to clipboard
fun snapshots(type: AggregateType, vararg states: Pair<String, Any>, tenantId: String = Caller.DEFAULT_TENANT): MemoryQueries

Holds each of states, an aggregate id to its state, as a snapshot of type in tenantId; see snapshot.

Link copied to clipboard
open override fun tenant(tenantId: String): SubscriptionQueries

A handler's queries of tenantId, pinned to it as on a node (InProcessQueryApi.tenant).

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open override fun trusted(): TrustedQueries