# @salmonui/data/stream API reference

> 5 exported symbols of @salmonui/data/stream: 1 function and 4 interfaces.

Canonical: https://salmonui.dev/docs/reference/data/stream

```ts
import { … } from '@salmonui/data/stream';
```

## Functions

### createLiveDataSource

Kind: function

Page: https://salmonui.dev/docs/reference/data/stream/createLiveDataSource

```ts
function createLiveDataSource<Row>(options: LiveDataSourceOptions<Row>): LiveDataSource<Row>;
```

## Interfaces

### LiveDataSource

Kind: interface

Page: https://salmonui.dev/docs/reference/data/stream/LiveDataSource

```ts
interface LiveDataSource<Row> extends DataSource<Row> {
    readonly mode: 'live';
    read(request: DataSourceRequest): Promise<DataSourceResult<Row>>;
    subscribe(listener: (event: DataSourceEvent<Row>) => void): () => void;
    getRows(): readonly Row[];
    close(): void;
}
```

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `mode` | `readonly mode: 'live';` |  |  |
| `read` | `read(request: DataSourceRequest): Promise<DataSourceResult<Row>>;` |  |  |
| `subscribe` | `subscribe(listener: (event: DataSourceEvent<Row>) => void): () => void;` |  |  |
| `getRows` | `getRows(): readonly Row[];` |  |  |
| `close` | `close(): void;` |  | Closes the stream. |
| `write` | `write?: ((request: WriteRequest<Row>) => Promise<WriteResult<Row>>);` | optional, inherited |  |
| `capabilities` | `capabilities?: Partial<DataSourceCapabilities>;` | optional, inherited |  |

### LiveDataSourceOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/data/stream/LiveDataSourceOptions

```ts
interface LiveDataSourceOptions<Row> {
    readonly initial: DataSource<Row>;
    readonly getRowId: (row: Row) => RowId;
    readonly connect: (query: DataQuery, emit: LiveEmitter<Row>, signal: AbortSignalLike) => void | (() => void);
    readonly reconnect?: {
        readonly attempts: number;
        readonly delayMs: number | ((attempt: number) => number);
    };
    readonly fields?: readonly string[];
    readonly scheduler?: Scheduler;
    readonly onConflict?: (conflict: ConflictSnapshot<Row>) => void;
    readonly onError?: (error: unknown) => void;
}
```

Members (8):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `initial` | `readonly initial: DataSource<Row>;` |  | Snapshot read (local or remote). |
| `getRowId` | `readonly getRowId: (row: Row) => RowId;` |  |  |
| `connect` | `readonly connect: (query: DataQuery, emit: LiveEmitter<Row>, signal: AbortSignalLike) => void \| (() => void);` |  | Opens the stream for a query; return a cleanup function. Re-called per structural query. |
| `reconnect` | `readonly reconnect?: {     readonly attempts: number;     readonly delayMs: number \| ((attempt: number) => number); };` | optional |  |
| `fields` | `readonly fields?: readonly string[];` | optional | Tuple header for `message()`: rows stay tuples in this order. Omit for object rows. |
| `scheduler` | `readonly scheduler?: Scheduler;` | optional |  |
| `onConflict` | `readonly onConflict?: (conflict: ConflictSnapshot<Row>) => void;` | optional |  |
| `onError` | `readonly onError?: (error: unknown) => void;` | optional |  |

### LiveEmitter

Kind: interface

Page: https://salmonui.dev/docs/reference/data/stream/LiveEmitter

```ts
interface LiveEmitter<Row> {
    replace(rows: readonly Row[], totalRowCount?: number): void;
    patch(patch: LivePatch<Row>): void;
    message(message: WireLiveMessage): void;
    conflict(conflict: ConflictSnapshot<Row>): void;
    fail(error: unknown): void;
}
```

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `replace` | `replace(rows: readonly Row[], totalRowCount?: number): void;` |  |  |
| `patch` | `patch(patch: LivePatch<Row>): void;` |  |  |
| `message` | `message(message: WireLiveMessage): void;` |  | Applies a JSON-protocol live message (tuples, dictionaries). |
| `conflict` | `conflict(conflict: ConflictSnapshot<Row>): void;` |  |  |
| `fail` | `fail(error: unknown): void;` |  |  |

### LivePatch

Kind: interface

Page: https://salmonui.dev/docs/reference/data/stream/LivePatch

```ts
interface LivePatch<Row> {
    readonly upsert?: readonly Row[];
    readonly remove?: readonly RowId[];
    readonly append?: readonly Row[];
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `upsert` | `readonly upsert?: readonly Row[];` | optional |  |
| `remove` | `readonly remove?: readonly RowId[];` | optional |  |
| `append` | `readonly append?: readonly Row[];` | optional |  |
