@softistx/drizzle-meilisearch 0.0.0-stage → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Steve Tsala
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,320 @@
1
- # Temporary Holding Version
1
+ # @softistx/drizzle-meilisearch
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Keeps a [Meilisearch](https://www.meilisearch.com) index in step with a
4
+ PostgreSQL table: a typed transform from a Drizzle row to a document, a full
5
+ reindex, and one call per write.
6
+
7
+ ```ts
8
+ import { createSearchSync } from '@softistx/drizzle-meilisearch';
9
+
10
+ const articleRepository = createRepository(db, articles); // @softistx/drizzle
11
+
12
+ const articleSearch = createSearchSync({
13
+ repository: articleRepository,
14
+ index: bindIndex(meili, articleIndex), // @softistx/meilisearch
15
+ toIndexId: (article) => article.id,
16
+ transform: (article) =>
17
+ article.draft ? null : { id: article.id, title: article.title },
18
+ });
19
+
20
+ const article = await articleRepository.create({ title: 'Hello' });
21
+ await articleSearch.indexRow(article); // and one call per write after that
22
+ ```
23
+
24
+ `transform` takes the table's row, typed by the table, and gives the index's
25
+ document, typed by its definition; `null` keeps a row out of the index, and
26
+ takes it out if it was in. `reindexAll()` fills the index from the table, and
27
+ removes from it whatever the table no longer gives.
28
+
29
+ **There is no `start()`, no resume point and no change following:** PostgreSQL
30
+ offers nothing like MongoDB's change stream that this package could follow, so
31
+ it removes the collage around a write — the transform, the id, the batching,
32
+ the delete of a row that stopped qualifying — and not the decision of when to
33
+ index. [The roadmap](docs/roadmap.md) says why.
34
+
35
+ > **0.x, on `@softistx/drizzle` and `@softistx/meilisearch`.** The API is still settling.
36
+
37
+ ## Install
38
+
39
+ `@softistx/drizzle-meilisearch` is public on npm, with no registry setting and no token. It moved from
40
+ `@nxgt/drizzle-meilisearch` (npm), which gets no new version: replace the name in your imports
41
+ and `package.json`.
42
+
43
+ ```sh
44
+ bun add @softistx/drizzle-meilisearch @softistx/drizzle @softistx/meilisearch drizzle-orm@rc meilisearch typescript
45
+ ```
46
+
47
+ - `@softistx/drizzle` and `@softistx/meilisearch`: required peers. The repository and
48
+ the index are theirs, and so are their options; this package creates
49
+ neither.
50
+ - `drizzle-orm` `>=1.0.0-rc.4 <2` and `meilisearch` `>=0.62.0 <1`: required
51
+ peers, as the two packages above need them.
52
+ - `typescript` `^6.0.3 || ^7.0.0`: required peer, the range every `@nxgt` package
53
+ accepts.
54
+ - A PostgreSQL database, reached through any Drizzle driver, and a
55
+ Meilisearch server, 1.x. Tested against Meilisearch 1.53.
56
+
57
+ ## Setup
58
+
59
+ The table is `@softistx/drizzle`'s and the index is `@softistx/meilisearch`'s; this
60
+ package defines neither:
61
+
62
+ ```ts
63
+ import { id, softDelete, timestamps } from '@softistx/drizzle/pg';
64
+ import { defineIndex } from '@softistx/meilisearch';
65
+ import { boolean, pgTable, text } from 'drizzle-orm/pg-core';
66
+
67
+ export const articles = pgTable('articles', {
68
+ id: id(),
69
+ title: text('title').notNull(),
70
+ draft: boolean('draft').notNull().default(false),
71
+ ...timestamps(),
72
+ ...softDelete(),
73
+ });
74
+
75
+ export interface ArticleHit {
76
+ id: string;
77
+ title: string;
78
+ }
79
+
80
+ export const articleIndex = defineIndex<ArticleHit>()({
81
+ uid: 'articles',
82
+ primaryKey: 'id',
83
+ settings: { searchableAttributes: ['title'] },
84
+ });
85
+ ```
86
+
87
+ Then, where the app starts:
88
+
89
+ ```ts
90
+ import { createRepository } from '@softistx/drizzle/pg';
91
+ import { bindIndex } from '@softistx/meilisearch';
92
+ import { createSearchSync } from '@softistx/drizzle-meilisearch';
93
+
94
+ export const articleRepository = createRepository(db, articles);
95
+ export const index = bindIndex(meili, articleIndex);
96
+ await index.sync(); // the index's settings are @softistx/meilisearch's to apply
97
+
98
+ export const articleSearch = createSearchSync({
99
+ repository: articleRepository,
100
+ index,
101
+ toIndexId: (article) => article.id,
102
+ transform: (article) =>
103
+ article.draft ? null : { id: article.id, title: article.title },
104
+ });
105
+ ```
106
+
107
+ `createSearchSync` sends nothing and opens nothing: it checks its options and
108
+ gives back an object. Every write comes from a method on it.
109
+
110
+ ## Indexing after a write
111
+
112
+ One call beside the write the application already makes. The row a repository
113
+ hands back is what the index takes:
114
+
115
+ ```ts
116
+ const article = await articleRepository.create({ title: 'Hello' });
117
+ await articleSearch.indexRow(article);
118
+
119
+ // The same call takes a row out when the transform stops wanting it.
120
+ const draft = await articleRepository.update(article.id, { draft: true });
121
+ await articleSearch.indexRow(draft); // transform gives null → removed
122
+
123
+ const rows = await articleRepository.createMany([{ title: 'a' }, { title: 'b' }]);
124
+ await articleSearch.indexRows(rows);
125
+ ```
126
+
127
+ `indexRow`, `indexRows`, `removeRow`, `remove` and `removeMany` all take
128
+ `{ wait }`, `false` by default: Meilisearch indexes asynchronously, and a
129
+ request that has just written a row should not hold its response open for it.
130
+ `{ wait: true }` is what a script or a test wants.
131
+ [Indexing after a write](docs/guide/indexing-writes.md) has the rest.
132
+
133
+ ## Taking a row out
134
+
135
+ ```ts
136
+ const deleted = await articleRepository.delete(article.id); // soft delete
137
+ await articleSearch.removeRow(deleted); // reads the id with toIndexId
138
+
139
+ const gone = await articleRepository.hardDelete(article.id);
140
+ await articleSearch.removeRow(gone); // a hard delete hands the row back too
141
+
142
+ await articleSearch.remove(id); // when all you have is the index id
143
+ ```
144
+
145
+ ## Filling the index
146
+
147
+ ```ts
148
+ const report = await articleSearch.reindexAll();
149
+ // { indexed: 1204, skipped: 17, removed: 3 }
150
+ ```
151
+
152
+ Every live row through the transform, a page at a time, then out of the index
153
+ everything the table no longer gives it — rows that were deleted, rows the
154
+ transform turned away, documents that were never this table's.
155
+ `reindexAll` always waits for Meilisearch, because what it removes is decided
156
+ by reading the index back. [Reindexing](docs/guide/reindex.md) has the
157
+ details.
158
+
159
+ A large table is a long call, so `onPage` reports where it is, after each page
160
+ is applied:
161
+
162
+ ```ts
163
+ await articleSearch.reindexAll({
164
+ onPage: ({ pages, indexed, skipped }) =>
165
+ console.log(`page ${pages}: ${indexed} indexed, ${skipped} skipped`),
166
+ });
167
+ ```
168
+
169
+ ## Errors
170
+
171
+ Every failure of a write or a reindex is a `SearchSyncError`, with the sync's
172
+ `name` as `sync` and the original error as `cause`.
173
+
174
+ | `code` | When |
175
+ | --- | --- |
176
+ | `ID_MISMATCH` | the transform gave a document whose primary key is not that row's index id |
177
+ | `NOT_A_DOCUMENT` | the transform gave something that is neither a document nor `null`. The message says its shape, never its value |
178
+ | `FAILED` | anything else: the transform threw, PostgreSQL or Meilisearch refused. The message says what the sync was doing |
179
+
180
+ ```ts
181
+ import { SearchSyncError } from '@softistx/drizzle-meilisearch';
182
+
183
+ try {
184
+ await articleSearch.indexRow(article, { wait: true });
185
+ } catch (error) {
186
+ if (error instanceof SearchSyncError && error.code === 'FAILED') {
187
+ log.error({ sync: error.sync, cause: error.cause });
188
+ } else throw error;
189
+ }
190
+ ```
191
+
192
+ An option out of range is a bare `TypeError`, not a `SearchSyncError`, and it
193
+ comes before anything is sent. `createSearchSync` throws one for a
194
+ `batchSize` or a `pageSize` that is not a whole number above zero, an empty
195
+ `name`, or a `transform` or `toIndexId` that is not a function; `reindexAll`
196
+ throws one for the `pageSize` given to the call, and names the sync it came
197
+ from:
198
+
199
+ ```ts
200
+ createSearchSync({ …, batchSize: 0 });
201
+ // TypeError: createSearchSync: batchSize must be a whole number above 0, not 0
202
+
203
+ await articleSearch.reindexAll({ pageSize: -1 });
204
+ // TypeError: reindexAll on "articles:articles": pageSize must be a whole
205
+ // number above 0, not -1
206
+ ```
207
+
208
+ ## API
209
+
210
+ ### `createSearchSync(options)`
211
+
212
+ ```ts
213
+ function createSearchSync<TTable extends PgTable, I extends AnyIndexDefinition>(
214
+ options: SearchSyncOptions<TTable, I>,
215
+ ): SearchSync<TTable, I>;
216
+ ```
217
+
218
+ `SearchSyncOptions<TTable, I>`:
219
+
220
+ | Option | Default | |
221
+ | --- | --- | --- |
222
+ | `repository: SyncRepository<TTable>` | | from `createRepository`, or one narrowed by `with(tx)`: the table and `paginateByCursor` are all this package reads |
223
+ | `index: TypedIndex<I>` | | from `bindIndex` |
224
+ | `transform: Transform<TTable, I>` | | `(row: Row<TTable>) => DocumentOf<I> \| null`, or a promise of it. `Row` is `@softistx/drizzle`'s, `DocumentOf` `@softistx/meilisearch`'s |
225
+ | `toIndexId: ToIndexId<TTable, I>` | | `(row: Row<TTable>) => IdOf<I>`. **Required** |
226
+ | `name: string` | `'<table>:<index uid>'` | what the errors carry as `sync` |
227
+ | `batchSize: number` | `500` | documents, or ids, per Meilisearch task |
228
+ | `pageSize: number` | `100` | rows `reindexAll` reads per page; above the repository's `maxPageSize`, lowered to it |
229
+
230
+ `SearchSync<TTable, I>`:
231
+
232
+ | Member | |
233
+ | --- | --- |
234
+ | `name: string` | |
235
+ | `reindexAll(options?: ReindexOptions): Promise<ReindexReport>` | `ReindexOptions` is `{ pageSize?, onPage? }`; `onPage` gets a `ReindexProgress`, `{ pages, indexed, skipped }` so far, after each page is applied, and one that throws stops the reindex as the `cause` of a `FAILED`. `ReindexReport` is `{ indexed, skipped, removed }`, all `number`. Always waits |
236
+ | `indexRow(row: Row<TTable>, options?: IndexWriteOptions): Promise<void>` | the transform decides: a document, or `null` to take the row out |
237
+ | `indexRows(rows: readonly Row<TTable>[], options?): Promise<void>` | deduplicated by index id, last one wins |
238
+ | `removeRow(row: Row<TTable>, options?): Promise<void>` | by the id `toIndexId` gives for the row |
239
+ | `remove(id: IdOf<I>, options?): Promise<void>` | by index id |
240
+ | `removeMany(ids: readonly IdOf<I>[], options?): Promise<void>` | |
241
+
242
+ `IndexWriteOptions` is `{ wait?: boolean }`, `false` by default.
243
+
244
+ `class SearchSyncError extends Error`: `code: SearchSyncErrorCode`
245
+ (`'ID_MISMATCH' | 'NOT_A_DOCUMENT' | 'FAILED'`), `sync: string`, and `cause`.
246
+ Its constructor takes `(message, options: SearchSyncErrorOptions)`, that is
247
+ `{ code, sync, cause? }`; both types are exported, along with
248
+ `SearchSyncOptions`, `SearchSync`, `SyncRepository`, `Transform`,
249
+ `ToIndexId`, `IndexWriteOptions` and `ReindexReport`.
250
+
251
+ [Wiring a sync](docs/guide/wiring.md) has each option with its snippet.
252
+
253
+ ## What does not compile
254
+
255
+ Each is a `@ts-expect-error` case in this package's type tests.
256
+
257
+ - A transform that reads a column the table does not have, or that gives a
258
+ field the index's document does not have — or leaves one out.
259
+ - A transform that gives something other than a document or `null`: a value,
260
+ or a list of documents.
261
+ - No `transform`, and no `toIndexId`: neither has a default.
262
+ - A `toIndexId` that gives another type than the index's ids — a `Date` for a
263
+ string id, a `string` for a number one — or that reads a column of another
264
+ table.
265
+ - The table itself for `repository`, or the SDK's own `Index` for `index`.
266
+ - An option this package does not have, a `batchSize` that is not a number,
267
+ or a `name` that is not a string.
268
+ - `remove(1)` on an index whose ids are strings, one row where `indexRows`
269
+ takes a list, a row of another table, `{ waitFor: true }`, or a `wait` that
270
+ is not a boolean.
271
+
272
+ ## Traps
273
+
274
+ - **`toIndexId` is required**, where the MongoDB bridge defaults it to
275
+ `String`. Drizzle 1.0's column types do not carry `.primaryKey()`, so
276
+ nothing at the type level knows which column the id is: say it in one line
277
+ per sync, `toIndexId: (row) => row.id`.
278
+ - **`wait` is `false` by default.** A write that returns has been enqueued,
279
+ not applied; read the index back only with `{ wait: true }`.
280
+ - **A `pageSize` above the repository's `maxPageSize`** (100 by default) is
281
+ silently lowered to it: asking for 1000 means ten times more pages, not
282
+ bigger ones. Raise `maxPageSize` on the repository to page in larger reads.
283
+ - **A delete does not create an index.** Meilisearch creates one on a write
284
+ of documents, never on a delete, so `remove(...)` with `{ wait: true }` on
285
+ an index nothing has written to yet fails with ``Index `articles` not
286
+ found``. Call `index.sync()` at startup, or reindex first.
287
+ - **The transform must give the row's index id** under the index's primary
288
+ key: a document under another id could never be taken out again, and is
289
+ refused with `ID_MISMATCH`.
290
+ - **`reindexAll` owns the index.** It removes every document the table does
291
+ not give it, whoever wrote it, so do not point a second writer at the same
292
+ index.
293
+ - **Index after the transaction commits.** A row indexed inside
294
+ `withTransaction` and then rolled back stays in the index; Meilisearch
295
+ takes no part in the transaction.
296
+
297
+ ## What it does not do
298
+
299
+ - **No change following.** No `start()`, no resume point, no background
300
+ worker: a row is indexed when the application says so.
301
+ - **No partial updates.** A write sends the whole document the transform
302
+ gives, never a patch.
303
+ - **Keeping the index's settings** — that is `@softistx/meilisearch`'s `sync()`.
304
+ - **Joining other tables into a document.** The transform may read them, but
305
+ a write to them does not reach the index.
306
+
307
+ ## Documentation
308
+
309
+ - [Guide index](docs/README.md) — every page, and when to read it.
310
+ - [Wiring a sync](docs/guide/wiring.md) — the repository, the index, the
311
+ transform, and every option with its default.
312
+ - [Indexing after a write](docs/guide/indexing-writes.md) — the five write
313
+ calls, `wait`, and batching.
314
+ - [Reindexing](docs/guide/reindex.md) — the full fill, and what it removes.
315
+ - [Troubleshooting](docs/troubleshooting.md) — the errors, by their message.
316
+ - [Roadmap](docs/roadmap.md) — what is next, and what is not planned.
317
+
318
+ ## License
319
+
320
+ MIT
@@ -0,0 +1,12 @@
1
+ import type { Doc, SyncContext } from './context.js';
2
+ import type { Entry } from './documents.js';
3
+ /** Adds documents, `batchSize` at a time. */
4
+ export declare function sendDocuments(ctx: SyncContext, documents: readonly Doc[], wait: boolean): Promise<void>;
5
+ /** Deletes documents by id, `batchSize` at a time. */
6
+ export declare function deleteIds(ctx: SyncContext, ids: readonly unknown[], wait: boolean): Promise<void>;
7
+ /**
8
+ * Applies entries: one per id, so adds and deletes touch different
9
+ * documents and their order does not matter.
10
+ */
11
+ export declare function send(ctx: SyncContext, entries: readonly Entry[], wait: boolean): Promise<void>;
12
+ //# sourceMappingURL=batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAyBzC,6CAA6C;AAC7C,wBAAsB,aAAa,CAClC,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,SAAS,GAAG,EAAE,EACzB,IAAI,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,sDAAsD;AACtD,wBAAsB,SAAS,CAC9B,GAAG,EAAE,WAAW,EAChB,GAAG,EAAE,SAAS,OAAO,EAAE,EACvB,IAAI,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;GAGG;AACH,wBAAsB,IAAI,CACzB,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,IAAI,EAAE,OAAO,GACX,OAAO,CAAC,IAAI,CAAC,CASf"}
@@ -0,0 +1,39 @@
1
+ import type { CursorPage } from '@softistx/drizzle';
2
+ import type { AnyIndexDefinition, TypedIndex } from '@softistx/meilisearch';
3
+ import type { PgTable } from 'drizzle-orm/pg-core';
4
+ import type { SearchSyncOptions } from './types.js';
5
+ /**
6
+ * Loosely typed: this layer works on any row and any document; the public
7
+ * types in `types.ts` are what a caller sees.
8
+ */
9
+ export type Doc = Record<string, unknown>;
10
+ /** The repository, as the layers below it read it. */
11
+ export interface LooseRepository {
12
+ readonly table: PgTable;
13
+ paginateByCursor(options?: {
14
+ after?: string | null | undefined;
15
+ limit?: number;
16
+ }): Promise<CursorPage<Doc>>;
17
+ }
18
+ /**
19
+ * What a sync works from, resolved once. Data, and the caller's own two
20
+ * functions as they were given.
21
+ */
22
+ export interface SyncContext {
23
+ readonly name: string;
24
+ readonly repository: LooseRepository;
25
+ readonly index: TypedIndex<AnyIndexDefinition>;
26
+ readonly primaryKey: string;
27
+ readonly batchSize: number;
28
+ readonly pageSize: number;
29
+ readonly transform: (row: Doc) => unknown;
30
+ readonly toIndexId: (row: Doc) => unknown;
31
+ }
32
+ /**
33
+ * A whole number above 0, or the refusal — which names the call, because
34
+ * `pageSize` is given to `createSearchSync` and again to `reindexAll`, and a
35
+ * message that named only the option would point at the wrong one.
36
+ */
37
+ export declare function positive(call: string, option: string, value: number | undefined, fallback: number): number;
38
+ export declare function createContext(options: SearchSyncOptions<PgTable, AnyIndexDefinition>): SyncContext;
39
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C,sDAAsD;AACtD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,OAAO,CAAC,EAAE;QAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;QAClC,KAAK,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;CAC1C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,MAAM,UAShB;AAED,wBAAgB,aAAa,CAC5B,OAAO,EAAE,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,CAAC,GACrD,WAAW,CA8Bb"}
@@ -0,0 +1,27 @@
1
+ import type { AnyIndexDefinition } from '@softistx/meilisearch';
2
+ import type { PgTable } from 'drizzle-orm/pg-core';
3
+ import type { SearchSync, SearchSyncOptions } from './types.js';
4
+ /**
5
+ * A table and an index, kept in step by the calls an application already
6
+ * makes. Builds nothing and opens nothing: the repository and the index are
7
+ * already bound.
8
+ *
9
+ * ```ts
10
+ * const search = createSearchSync({
11
+ * repository: users,
12
+ * index: usersIndex,
13
+ * toIndexId: (row) => row.id,
14
+ * transform: (row) =>
15
+ * row.deletedAt ? null : { id: row.id, email: row.email, name: row.name },
16
+ * });
17
+ *
18
+ * const user = await users.create({ email: 'ada@example.com' });
19
+ * await search.indexRow(user);
20
+ * ```
21
+ *
22
+ * `createSearchSync`, not `connect*`: `AGENTS.md` reserves `create*` for an
23
+ * assembly that does no I/O, and nothing here talks to PostgreSQL or to
24
+ * Meilisearch until a method is called.
25
+ */
26
+ export declare function createSearchSync<TTable extends PgTable, I extends AnyIndexDefinition>(options: SearchSyncOptions<TTable, I>): SearchSync<TTable, I>;
27
+ //# sourceMappingURL=create-search-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-search-sync.d.ts","sourceRoot":"","sources":["../src/create-search-sync.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAQ,MAAM,uBAAuB,CAAC;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,KAAK,EAIX,UAAU,EACV,iBAAiB,EACjB,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,SAAS,OAAO,EACtB,CAAC,SAAS,kBAAkB,EAC3B,OAAO,EAAE,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAwB9D"}
@@ -0,0 +1,19 @@
1
+ import type { Doc, SyncContext } from './context.js';
2
+ /** One document's fate in the index: sent, or taken out. */
3
+ export type Entry = {
4
+ kind: 'upsert';
5
+ key: string;
6
+ document: Doc;
7
+ } | {
8
+ kind: 'delete';
9
+ key: string;
10
+ id: unknown;
11
+ };
12
+ /** An id as a key: `1` and `'1'` are different ids to Meilisearch. */
13
+ export declare const keyOf: (id: unknown) => string;
14
+ /**
15
+ * What the index should hold for a row: what the transform makes of it, or
16
+ * nothing when the transform keeps it out.
17
+ */
18
+ export declare function entryOf(ctx: SyncContext, row: Doc): Promise<Entry>;
19
+ //# sourceMappingURL=documents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../src/documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGlD,4DAA4D;AAC5D,MAAM,MAAM,KAAK,GACd;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAA;CAAE,CAAC;AAEhD,sEAAsE;AACtE,eAAO,MAAM,KAAK,GAAI,IAAI,OAAO,WAAiC,CAAC;AAYnE;;;GAGG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CA4BxE"}
@@ -0,0 +1,24 @@
1
+ /** What stopped a sync, as a string to switch on. */
2
+ export type SearchSyncErrorCode =
3
+ /** The transform gave a document whose primary key is not its index id. */
4
+ 'ID_MISMATCH'
5
+ /** The transform gave something that is neither a document nor `null`. */
6
+ | 'NOT_A_DOCUMENT'
7
+ /** Anything else: the cause says what. */
8
+ | 'FAILED';
9
+ export interface SearchSyncErrorOptions {
10
+ code: SearchSyncErrorCode;
11
+ sync: string;
12
+ cause?: unknown;
13
+ }
14
+ /** An error of a sync, with the sync's name and what caused it. */
15
+ export declare class SearchSyncError extends Error {
16
+ name: string;
17
+ readonly code: SearchSyncErrorCode;
18
+ /** The sync's name. */
19
+ readonly sync: string;
20
+ constructor(message: string, options: SearchSyncErrorOptions);
21
+ }
22
+ /** `error` as a `SearchSyncError`, kept as it is when it already is one. */
23
+ export declare function failed(sync: string, doing: string, error: unknown): SearchSyncError;
24
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,MAAM,mBAAmB;AAC9B,2EAA2E;AACzE,aAAa;AACf,0EAA0E;GACxE,gBAAgB;AAClB,0CAA0C;GACxC,QAAQ,CAAC;AAEZ,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,mEAAmE;AACnE,qBAAa,eAAgB,SAAQ,KAAK;IAChC,IAAI,SAAqB;IAClC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,uBAAuB;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB;CAQ5D;AAED,4EAA4E;AAC5E,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,mBAWjE"}
@@ -0,0 +1,4 @@
1
+ export { createSearchSync } from './create-search-sync.js';
2
+ export { SearchSyncError, type SearchSyncErrorCode, type SearchSyncErrorOptions, } from './errors.js';
3
+ export type { IndexWriteOptions, ReindexOptions, ReindexProgress, ReindexReport, SearchSync, SearchSyncOptions, SyncRepository, ToIndexId, Transform, } from './types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACN,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,GAC3B,MAAM,UAAU,CAAC;AAClB,YAAY,EACX,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,SAAS,GACT,MAAM,SAAS,CAAC"}