Metakit / @doeixd/metakit/interpreter

InterpreterBackend

interface · packages/metakit/src/interpreterBackend.ts:60

interface InterpreterBackend {
  readonly name: string
  readonly foreign: Expr.ForeignImplementations
  readonly eval: <Env, A>(
    expr: Expr.Expr<Env, A>,
    env: Env,
  ) => Effect.Effect<A | null, Node.Refusal>
  readonly judge: <Env>(
    expr: Expr.Expr<Env, boolean>,
    partial: Expr.PartialEnv<Env>,
  ) => Effect.Effect<Verdict.Verdict<Node.Refusal>>
  readonly residualize: <Env, A>(
    expr: Expr.Expr<Env, A>,
    partial: Expr.PartialEnv<Env>,
  ) => Effect.Effect<Expr.Expr<Env, A>>
  readonly step: <State, Input, Emit, Supplied>(
    transition: Transition.Transition<State, Input, Emit, Supplied>,
    state: NoInfer<State>,
    input: NoInfer<Input>,
    ...args: Transition.SuppliedArgs<Supplied>
  ) => Effect.Effect<StepOutput<State, Emit>, Transition.Refused>
  readonly runFn: <P extends Fn.ParamSchemas, R>(
    fn: Fn.Fn<P, R>,
    args: Fn.ParamValues<P>,
  ) => Effect.Effect<R, Fn.FnContractError>
  readonly allow: <
    Row,
    Principal,
    Rules extends Readonly<
      Record<string, Expr.Expr<Policy.PolicyEnv<Row, Principal>, boolean>>
    >,
  >(
    policy: Policy.Policy<Row, Principal, Rules>,
    rule: NoInfer<Policy.RuleOf<Rules>>,
    env: NoInfer<Policy.PolicyEnv<Row, Principal>>,
  ) => Effect.Effect<boolean>
  readonly rebind?: (options: {
    readonly name?: string | undefined
    readonly foreign: Expr.ForeignImplementations
    readonly allowlist?: ReadonlyArray<Node.ForeignOp> | undefined
  }) => InterpreterBackend
}

Implementation contract for a MetaKit interpreter backend.

Members

InterpreterBackend.name

property · packages/metakit/src/interpreterBackend.ts:61

readonly name: string

InterpreterBackend.foreign

property · packages/metakit/src/interpreterBackend.ts:63

readonly foreign: Expr.ForeignImplementations

Foreign operation implementations ambiently available to this backend.

InterpreterBackend.eval

property · packages/metakit/src/interpreterBackend.ts:65

readonly eval: <Env, A>(
  expr: Expr.Expr<Env, A>,
  env: Env,
) => Effect.Effect<A | null, Node.Refusal>

Evaluate an expression, failing with Node.Refusal if evaluation is refused.

InterpreterBackend.judge

property · packages/metakit/src/interpreterBackend.ts:70

readonly judge: <Env>(
  expr: Expr.Expr<Env, boolean>,
  partial: Expr.PartialEnv<Env>,
) => Effect.Effect<Verdict.Verdict<Node.Refusal>>

Partially evaluate a boolean expression against a partial environment.

InterpreterBackend.residualize

property · packages/metakit/src/interpreterBackend.ts:75

readonly residualize: <Env, A>(
  expr: Expr.Expr<Env, A>,
  partial: Expr.PartialEnv<Env>,
) => Effect.Effect<Expr.Expr<Env, A>>

Residualize an expression against a partial environment.

InterpreterBackend.step

property · packages/metakit/src/interpreterBackend.ts:80

readonly step: <State, Input, Emit, Supplied>(
  transition: Transition.Transition<State, Input, Emit, Supplied>,
  state: NoInfer<State>,
  input: NoInfer<Input>,
  ...args: Transition.SuppliedArgs<Supplied>
) => Effect.Effect<StepOutput<State, Emit>, Transition.Refused>

Execute a transition (guard + writes + emissions), failing with Transition.Refused.

InterpreterBackend.runFn

property · packages/metakit/src/interpreterBackend.ts:87

readonly runFn: <P extends Fn.ParamSchemas, R>(
  fn: Fn.Fn<P, R>,
  args: Fn.ParamValues<P>,
) => Effect.Effect<R, Fn.FnContractError>

Execute a Fn with contract checking (runChecked).

InterpreterBackend.allow

property · packages/metakit/src/interpreterBackend.ts:92

readonly allow: <
  Row,
  Principal,
  Rules extends Readonly<
    Record<string, Expr.Expr<Policy.PolicyEnv<Row, Principal>, boolean>>
  >,
>(
  policy: Policy.Policy<Row, Principal, Rules>,
  rule: NoInfer<Policy.RuleOf<Rules>>,
  env: NoInfer<Policy.PolicyEnv<Row, Principal>>,
) => Effect.Effect<boolean>

Evaluate rule, one of policy.rules; a rule of another policy throws.

InterpreterBackend.rebind

property · packages/metakit/src/interpreterBackend.ts:106

readonly rebind?: (options: {
  readonly name?: string | undefined
  readonly foreign: Expr.ForeignImplementations
  readonly allowlist?: ReadonlyArray<Node.ForeignOp> | undefined
}) => InterpreterBackend

Return a copy of this backend with foreign (and optionally name / allowlist) updated while preserving any surrounding middleware wrappers (withTracing, withObserver). A supplied allowlist only narrows access.