ReadFacade

class ReadFacade(visibility: (AggregateType) -> QueryGateway?, masks: PayloadMasks = PayloadMasks.NONE, observer: QueryObserver = QueryObserver.NONE, targets: QueryTargets = QueryTargets.DEFAULT, authorizer: ReadAuthorizer = ReadAuthorizer.ALLOW_ALL)

The one read path of every entry that reads an aggregate's state (HTTP, synchronous calls, ops): read the state, check that the caller may see it, mask it. read loads a state (its latest, at a version or a time, as the entry asks, from the runtime's state reads), hands it to admitted, which checks it against the snapshot query policies of its type (StateVisibility: the caller scope and the application's policies, through the type's snapshot query gateway or, when its snapshots are not queried, its policy gateway) and masks it as the snapshot queries mask a state; event masks an event body the same way.

A query policy that refuses the caller throws its query error, which the entry answers as its own problem.

An entry runs each state read in observed, so that observer (the query log and the application's observers, the audit trail among them) sees it as it sees a query.

Constructors

Link copied to clipboard
constructor(visibility: (AggregateType) -> QueryGateway?, masks: PayloadMasks = PayloadMasks.NONE, observer: QueryObserver = QueryObserver.NONE, targets: QueryTargets = QueryTargets.DEFAULT, authorizer: ReadAuthorizer = ReadAuthorizer.ALLOW_ALL)

Types

Link copied to clipboard
Link copied to clipboard
sealed interface Read<out V>

What reading a state found: Missing, Hidden from the caller, or Visible with its masked tree.

Functions

Link copied to clipboard
suspend fun admitted(caller: QueryCaller, state: Snapshot<JsonNode>): JsonNode?

The tree of state as caller may see it, masked, or null when its policies hide it from the caller. An HTTP caller naming a scope or tenants it may not is refused first (QueryTargets.recheck).

Link copied to clipboard
fun event(type: AggregateType, name: String, body: JsonNode): JsonNode

The body of an event name of type as every caller sees it: masked as the Manifest declares.

Link copied to clipboard
suspend fun history(state: Snapshot<JsonNode>): JsonNode

The tree of state, of the history of an aggregate whose latest state admitted let the caller see, masked as the snapshot queries mask a state. No policy is evaluated on it again: an aggregate's history is read as the aggregate is now, whatever it recorded then.

Link copied to clipboard
suspend fun <T> observed(type: AggregateType, what: StateRead, caller: QueryCaller, rows: (T) -> Long = { 1 }, read: suspend () -> T): T

Runs read, one state read of type for caller asking what, observed as a query is: observer starts it as a stage of work of StateRead.queryType, is told how it ended, and audits it with the rows it returned (one state, or the commits of a trace). A read answered as not found throws me.ahoo.wow.query.state.StateNotFoundException, whose reason only the audit records.

Link copied to clipboard
suspend fun <V : Any> read(caller: QueryCaller, load: suspend () -> V?, committed: (V) -> Snapshot<JsonNode>, check: (V) -> Unit = {}): ReadFacade.Read<V>

Reads a state with load, and admits it for caller: committed gives what its policies read of the view load found, after the entry's own check of it (its scope, say), which throws to refuse it.