# Gate

`interface` in `seedcord` · v0.13.0

<https://docs.seedcord.org/packages/seedcord/0.13.0/interfaces/gate>

A precondition attached to a handler. It refuses by throwing a `Notice` (a reply) or a `Silence` (a quiet drop), and passes by returning. `Ctx` is the context it requires, so a gate that reads `ctx.interaction` is rejected on an event handler at compile time. `Name` is captured as a literal so a mismatch error can name the gate. Build one with [`defineGate`](/packages/seedcord/0.13.0/functions/define-gate) or [`defineEffectGate`](/packages/seedcord/0.13.0/functions/define-effect-gate).

The bound is `GateContextBase`, not the `GateContext` union, because the base has no `kind` and so is not a union member. Binding to the union would collapse an identity gate's requirement to `never`.

```ts
interface Gate<
    Ctx extends GateContextBase = GateContext,
    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

### [GateBrand]

```ts
readonly [GateBrand]: true
```

Phantom brand that marks a real gate, you never set or read it.

### 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/seedcord/0.13.0/functions/define-gate)
