Skip to content
Functioncorev0.10.0

defineGate

Builds a Gate from a check. The check refuses by throwing a Notice or a Silence and passes by returning. The required context is inferred from ctx, so annotate it as narrowly as the fields the check reads. No annotation defaults to GateContextBase, an agnostic gate that fits every handler.

See also:defineEffectGate, the @Gated decorator from your transport package

defineGate<Name, Ctx>(
    name: Name,
    fn: (ctx: Ctx) => void | Promise<void>
): Gate<Ctx, Name>

Name

The gate's name, captured as a literal for mismatch errors.

Name

The gate's name, captured as a literal for mismatch errors.

Ctx

The context the check reads, inferred from the ctx annotation.

Ctx

The context the check reads, inferred from the ctx annotation.

name

name: Name

The gate's name, used in mismatch errors.

fn

fn: (ctx: Ctx) => void | Promise<void>

The check, which refuses by throwing a Notice or a Silence and passes by returning.