Skip to content

basalt / search/src / SyncRule

Interface: SyncRule<K> ​

Defined in: search/src/plugin.ts:17

Keeps an index in sync with domain events: on the given hook, either upsert a document or remove one. Wire it once and your search index maintains itself.

syncRule({ hook: 'note:created', index: 'notes', document: (p) => ({ id: p.note.id, tenantId: p.tenantId, title: p.note.title, body: p.note.body, })})

Type Parameters ​

K ​

K extends keyof BasaltHooks & string = keyof BasaltHooks & string

Properties ​

backfill? ​

> optional backfill?: () => AsyncIterable<BasaltHooks[K][]>

Defined in: search/src/plugin.ts:37

Every record this rule would ever index, in pages, for search.reindex().

A rule fed by events keeps an index current from the moment it exists and does nothing for the rows already in the database — so an application that adds search to existing data gets a box that returns nothing for everything old, and an empty result is indistinguishable from "there is none".

It yields hook payloads, not rows, so the same document function serves both directions. A second mapping written by hand is the drift this prevents: let it disagree with document and the same search returns different things depending on whether a record predates the last rebuild.

Returns ​

AsyncIterable<BasaltHooks[K][]>


document? ​

> optional document?: (payload) => SearchInput | null

Defined in: search/src/plugin.ts:21

Build the document to upsert. Return null to skip.

Parameters ​

payload ​

BasaltHooks[K]

Returns ​

SearchInput | null


hook ​

> hook: K

Defined in: search/src/plugin.ts:18


index ​

> index: string

Defined in: search/src/plugin.ts:19


remove? ​

> optional remove?: (payload) => { id: string; tenantId?: string; } | null

Defined in: search/src/plugin.ts:23

Or the identifiers to remove. Return null to skip.

Parameters ​

payload ​

BasaltHooks[K]

Returns ​

{ id: string; tenantId?: string; } | null

Released under the MIT License.