# @salmonui/data/storage API reference

> 6 exported symbols of @salmonui/data/storage: 3 functions, 2 interfaces and 1 type.

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

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

## Functions

### createJsonStateStorage

Kind: function

Page: https://salmonui.dev/docs/reference/data/storage/createJsonStateStorage

```ts
function createJsonStateStorage(options: FetchTransportOptions): DataGridStateStorage;
```

State storage over the JSON protocol endpoint:
`{ v: 1, state: { op: 'load' | 'save' | 'remove', gridId, state?, expectedVersion? } }`
-> `{ v: 1, state: DataGridState | null, version?, status?: 'saved' | 'conflict' }`.

### createKeyValueStateStorage

Kind: function

Page: https://salmonui.dev/docs/reference/data/storage/createKeyValueStateStorage

```ts
function createKeyValueStateStorage(store: KeyValueStore, options?: {
    readonly prefix?: string;
}): DataGridStateStorage;
```

Key-value storage. The store is injected (never `localStorage` directly).
Versions are a counter kept beside the state, so `expectedVersion` detects
a concurrent save from another tab.

### createMemoryStore

Kind: function

Page: https://salmonui.dev/docs/reference/data/storage/createMemoryStore

```ts
function createMemoryStore(map?: Map<string, string>): KeyValueStore;
```

Wraps a `Map` as a `KeyValueStore` (tests, SSR).

## Interfaces

### DataGridStateStorage

Kind: interface

Page: https://salmonui.dev/docs/reference/data/storage/DataGridStateStorage

```ts
interface DataGridStateStorage {
    load(gridId: string, signal?: AbortSignalLike): Promise<DataGridState | null>;
    save(gridId: string, state: DataGridState, expectedVersion?: string): Promise<SaveResult>;
    remove(gridId: string): Promise<void>;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `load` | `load(gridId: string, signal?: AbortSignalLike): Promise<DataGridState \| null>;` |  |  |
| `save` | `save(gridId: string, state: DataGridState, expectedVersion?: string): Promise<SaveResult>;` |  |  |
| `remove` | `remove(gridId: string): Promise<void>;` |  |  |

### KeyValueStore

Kind: interface

Page: https://salmonui.dev/docs/reference/data/storage/KeyValueStore

```ts
interface KeyValueStore {
    getItem(key: string): string | null | undefined | Promise<string | null | undefined>;
    setItem(key: string, value: string): void | Promise<void>;
    removeItem(key: string): void | Promise<void>;
}
```

Any sync or async key-value store (`localStorage`, `sessionStorage`, IndexedDB wrappers, Redis clients, Maps).

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `getItem` | `getItem(key: string): string \| null \| undefined \| Promise<string \| null \| undefined>;` |  |  |
| `setItem` | `setItem(key: string, value: string): void \| Promise<void>;` |  |  |
| `removeItem` | `removeItem(key: string): void \| Promise<void>;` |  |  |

## Types

### SaveResult

Kind: type

Page: https://salmonui.dev/docs/reference/data/storage/SaveResult

```ts
type SaveResult = {
    readonly status: 'saved';
    readonly version?: string;
} | {
    readonly status: 'conflict';
    readonly server: DataGridState;
};
```
