Remote / foldkit-remote-domain/lower

Lower

namespace · packages/remote-domain/src/lower/index.ts:9

const Lower = { check, write }

A declared write lowered into one Domain aggregate: check says what keeps it out of one, and write derives the command, its Rejections, decide, evolve, the reply, the by-id View and the adapter's two bindings.

In the guides

Members

Lower.check

function · packages/remote-domain/src/lower/check.ts:82

check(write: AnyWrite): ReadonlyArray<LoweringFinding>

What keeps write out of one aggregate: each rule, precondition, invariant or context value that reads another row (OutsideBoundary), and each member it reads or sets that is not one of its Entity's stored fields (NotPersisted). Empty when it can be lowered.

Lower.write

function · packages/remote-domain/src/lower/write.ts:269

write<
  M extends LowerableMutation,
  User,
  PrincipalId extends Domain.Middleware.Provides<Ms>,
  const Ms extends Domain.Middleware.List,
  Listed extends ListedEvent<EntityOf<M>>,
  Ev extends Domain.Event.Any,
>(
  mutation: M,
  config: LowerConfig<M, User, PrincipalId, Ms, Listed, Ev>,
): Lowered<M, PrincipalId, Ms, Listed, Ev>

Lowers a declared update into one Domain aggregate's command. Throws, listing each, where Lower.check finds what keeps it out of one aggregate, and where the write's id key is not id.

The aggregate's state is its row (none until listed is recorded) and the operations it last decided. decide lands the write through RemoteServer.write(mutation, GuardServer.writer(entity, policy, RemoteServer.memoryWriter(store, entity), { revision })) over that row and records record(after, before, input). Each refusal is the Rejection of the same tag; a guard's refusal is Forbidden, or Unauthenticated for a visitor, as a server answers it. To who the guard lets write, an operation decided before with another request (another commandId digest) is Reused, whatever the write would have answered: a retry is never a second, different write. That holds only for commandIds the adapter made (${mutation}:${operation}:${digest}); Domain answers a resent commandId from its own record without calling decide at all.