# @salmonui/data/lookup API reference

> 6 exported symbols of @salmonui/data/lookup: 2 functions and 4 interfaces.

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

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

## Functions

### createJsonLookup

Kind: function

Page: https://salmonui.dev/docs/reference/data/lookup/createJsonLookup

```ts
function createJsonLookup(options: JsonLookupOptions): CachedLookup;
```

Cached lookup over the JSON protocol endpoint:
`{ v: 1, lookup: { name, keys, keyField, displayField } }` -> `{ v: 1, rows }`.

### createLookup

Kind: function

Page: https://salmonui.dev/docs/reference/data/lookup/createLookup

```ts
function createLookup(options: LookupOptions): CachedLookup;
```

Wraps a loader as a cached Data Grid engine `LookupSource`. One lookup may back several columns and grids.

## Interfaces

### CachedLookup

Kind: interface

Page: https://salmonui.dev/docs/reference/data/lookup/CachedLookup

```ts
interface CachedLookup {
    load(request: LookupRequest): Promise<readonly unknown[]>;
    peek(key: Json): unknown;
    invalidate(key?: Json): void;
    readonly loads: number;
}
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `load` | `load(request: LookupRequest): Promise<readonly unknown[]>;` |  |  |
| `peek` | `peek(key: Json): unknown;` |  | Cached row of a key: the row, null when known missing, undefined when not cached. |
| `invalidate` | `invalidate(key?: Json): void;` |  | Drops every entry (or one key). |
| `loads` | `readonly loads: number;` |  | Loader calls so far (instrumentation). |

### JsonLookupOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/data/lookup/JsonLookupOptions

```ts
interface JsonLookupOptions extends FetchTransportOptions {
    readonly name: string;
    readonly ttl?: number;
    readonly scheduler?: Scheduler;
}
```

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `name` | `readonly name: string;` |  | Lookup name the server knows (`createJsonQueryHandler(rows, { lookups: { [name]: rows } })`). |
| `ttl` | `readonly ttl?: number;` | optional |  |
| `scheduler` | `readonly scheduler?: Scheduler;` | optional |  |
| `url` | `url: string;` | inherited |  |
| `fetch` | `fetch?: FetchLike;` | optional, inherited | Injected fetch. Defaults to `globalThis.fetch`, read lazily per request. |
| `headers` | `headers?: Readonly<Record<string, string>> \| (() => Readonly<Record<string, string>>);` | optional, inherited |  |
| `requestInit` | `requestInit?: Omit<FetchRequestInit, "body" \| "headers" \| "method" \| "signal">;` | optional, inherited |  |

### LookupOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/data/lookup/LookupOptions

```ts
interface LookupOptions {
    load(request: LookupRequest): readonly unknown[] | Promise<readonly unknown[]>;
    readonly keyField?: string;
    readonly ttl?: number;
    readonly scheduler?: Scheduler;
}
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `load` | `load(request: LookupRequest): readonly unknown[] \| Promise<readonly unknown[]>;` |  | Loads the rows of `keys` (only keys not cached). May return extra rows; they are cached too. |
| `keyField` | `readonly keyField?: string;` | optional | Field of the returned rows holding the looked-up value. Default: the request's `keyField`. Dot paths allowed. |
| `ttl` | `readonly ttl?: number;` | optional | Entry lifetime in ms. Default: never expires. |
| `scheduler` | `readonly scheduler?: Scheduler;` | optional |  |

### LookupRequest

Kind: interface

Page: https://salmonui.dev/docs/reference/data/lookup/LookupRequest

```ts
interface LookupRequest {
    readonly keys: readonly Json[];
    readonly keyField: string;
    readonly displayField: string;
    readonly signal: AbortSignalLike;
}
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `keys` | `readonly keys: readonly Json[];` |  |  |
| `keyField` | `readonly keyField: string;` |  |  |
| `displayField` | `readonly displayField: string;` |  |  |
| `signal` | `readonly signal: AbortSignalLike;` |  |  |
