# controlroom/plugin

> Every export of controlroom/plugin, with its signature and doc comment: validate, register, reset, registered, CONTRACT, PluginError, plus 4 types.

Source: https://controlroom.interlace.tools/docs/api/plugin

<!-- Generated by scripts/api-reference.ts from the built dist/*.d.ts. Do not edit; run `npx tsx scripts/api-reference.ts`. -->

```ts
import { validate, register, reset, … } from 'controlroom/plugin';
```

## Functions

### register

Validate, then keep every keymap and pane. A later entry of the same name replaces an earlier one.

```ts
function register(plugin: unknown): void;
```

| Parameter | Type |
| :-- | :-- |
| `plugin` | `unknown` |

**Returns** `void`

### registered

Copies of what has been registered: the only way in is `register()`.

```ts
function registered(): {
    keymaps: Map<string, Required<KeymapDef>>;
    panes: Map<string, PaneDef>;
};
```

**Returns** `{ keymaps: Map<string, Required<KeymapDef>>; panes: Map<string, PaneDef>; }`

### reset

Forget every registration, the built-ins included: they come back on the next use. For tests.

```ts
function reset(): void;
```

**Returns** `void`

### validate

Refuse what the schema refuses, and say why.

```ts
function validate(plugin: unknown): asserts plugin is Plugin;
```

| Parameter | Type |
| :-- | :-- |
| `plugin` | `unknown` |

**Returns** `asserts plugin is Plugin`

## Classes

### PluginError

A refused plugin says what is wrong, where, and what to do about it.

```ts
class PluginError extends Error {
    readonly code: PluginErrorCode;
    readonly fix: string;
    constructor(code: PluginErrorCode, message: string, fix: string);
}
```

## Constants

### CONTRACT

```ts
const CONTRACT = 1;
```

## Interfaces

### KeymapDef

A keymap: key spec → action name, and the label each action shows in the hint line.

```ts
interface KeymapDef {
    keys: Readonly<Record<string, string>>;
    labels?: Readonly<Record<string, string>>;
}
```

### PaneDef

A pane as data: the flagstaff component that draws it, and the label a static projection prints.

```ts
interface PaneDef {
    component: string;
    label?: string;
}
```

### Plugin

```ts
interface Plugin {
    name: string;
    contract?: number;
    keymaps?: Readonly<Record<string, KeymapDef>>;
    panes?: Readonly<Record<string, PaneDef>>;
}
```

## Types

### PluginErrorCode

The family's refusal vocabulary, the members this host can raise.

```ts
type PluginErrorCode = 'E_PLUGIN_SCHEMA' | 'E_PLUGIN_CONTRACT' | 'E_NO_CONTRIBUTION';
```
