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

One read observed runs, for caller: what it masks of a body beyond its event's schema goes to trail.

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. The caller itself was admitted before the state was read (observed).

Link copied to clipboard
suspend fun current(caller: QueryCaller, ref: AggregateRef, states: CommittedStates, check: (Snapshot<JsonNode>) -> Unit): ReadFacade.Read.Visible<Snapshot<JsonNode>>

The aggregate ref as it is now, at its log's head, as caller may see it after the entry's own check of it (its scope), which throws StateNotFoundException to refuse it: the state a read of the aggregate's history is admitted on, since the history is read as the aggregate is now, whatever it recorded then (history). The one rule of every entry's read of a state at a version or a time and of a trace:

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

The body of an event name of type at revision as caller sees it: masked as the Manifest declares, its DISPLAY values raw for a caller that reveals them, whole when it does not know the event (PayloadMasks.event).

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

The tree of state, of the history of an aggregate that current let caller see at its log's head, masked as the snapshot queries mask a state for caller, as its latest state is. 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 ReadFacade.Observed.() -> 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) and the fields it masks and reveals, named from the schemas it is masked by (maskedFields). read runs as an Observed read, whose Observed.event masks an event's body and names in the audit the fields of a scheduled command it holds. 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 reached(caller: QueryCaller, ref: AggregateRef, minVersion: Int, states: CommittedStates, check: (Snapshot<JsonNode>) -> Unit): ReadFacade.Read.Visible<Snapshot<JsonNode>>

The latest state of ref at version minVersion or later from states (read your writes), as caller may see it after the entry's own check of it (its scope), which throws StateNotFoundException to refuse it. The one rule of every entry's read of a minimum version:

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.