Guard / foldkit-guard/agent

GuardAgent

namespace · packages/guard/src/agent.ts:43

const GuardAgent = { authorize, available }

Members

GuardAgent.authorize

function · packages/guard/src/agent.ts:56

authorize<Input, Model>(
  interaction: 'Update' | 'Delete' | InteractionKey,
  row: (request: { readonly input: Input; readonly model: Model }) => MayRow,
): (request: {
  readonly input: Input
  readonly model: Model
}) => boolean | { readonly allowed: false; readonly reason: string }

A capability's authorize: the row the request names, read from the Model, must let the principal do interaction. A row not read yet, or whose read failed, refuses: there is no answer to go on. A refusal its rule explained says so, as the agent's error.

ts
authorize: GuardAgent.authorize(Archive.key, ({ input, model }) =>
  Data.get(TodoRow, input.id).read(model),
)

GuardAgent.available

function · packages/guard/src/agent.ts:72

available<Model>(
  interaction: 'Update' | 'Delete' | InteractionKey,
  row: (model: Model) => MayRow,
): (model: Model) => boolean

A capability's available, for one that acts on a row the Model alone names (the todo that is selected): offered only while that row lets the principal do interaction, so a visitor is not offered it at all.