# Gate

`interface` in `core` · v0.1.0-next.5

<https://docs.seedcord.org/packages/core/0.1.0-next.5/interfaces/gate>

A precondition attached to a handler. It refuses by throwing a `Notice` (a reply) or a `Silence` (a drop with no reply), and passes by returning. `Ctx` is the context it requires, so a gate that reads a field absent on a handler's context is rejected at compile time. `Name` is captured as a literal so a mismatch error can name the gate. Build one with [`defineGate`](/packages/core/0.1.0-next.5/functions/define-gate) or [`defineEffectGate`](/packages/core/0.1.0-next.5/functions/define-effect-gate).

```ts
interface Gate<
    Ctx extends GateContextBase = GateContextBase,
    Name extends string = string
>
```

## Examples

```ts
// a factory returning a typed, agnostic gate
function MyGate(): Gate<GateContextBase, 'MyGate'> {
    return defineGate('MyGate', (ctx) => {
        if (shouldRefuse(ctx)) throw new MyNotice();
    });
}
```

## Properties

### name

```ts
readonly name: Name
```

The gate's name, surfaced in a mismatch error and joined by the combinators.

## Methods

### check

```ts
async check(ctx: Ctx): Promise<void>
```

Reads the context and refuses by throwing a Notice or a Silence, or passes by resolving.

## See also

- [defineGate](/packages/core/0.1.0-next.5/functions/define-gate)
