@rebasepro/types 0.13.1-canary.gef9608c → 0.14.0

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.
Files changed (38) hide show
  1. package/dist/call_context.d.ts +70 -4
  2. package/dist/controllers/client.d.ts +47 -74
  3. package/dist/controllers/data.d.ts +345 -33
  4. package/dist/controllers/data_driver.d.ts +106 -8
  5. package/dist/errors.d.ts +30 -4
  6. package/dist/index.es.js +217 -12
  7. package/dist/index.es.js.map +1 -1
  8. package/dist/types/admin_block.d.ts +38 -1
  9. package/dist/types/auth_adapter.d.ts +7 -0
  10. package/dist/types/backend.d.ts +2 -0
  11. package/dist/types/collections.d.ts +46 -8
  12. package/dist/types/cron.d.ts +50 -9
  13. package/dist/types/entities.d.ts +11 -0
  14. package/dist/types/entity_callbacks.d.ts +2 -1
  15. package/dist/types/index.d.ts +2 -0
  16. package/dist/types/policy.d.ts +13 -13
  17. package/dist/types/properties.d.ts +31 -6
  18. package/dist/types/rls-functions.d.ts +84 -0
  19. package/dist/types/search.d.ts +231 -0
  20. package/package.json +1 -1
  21. package/src/call_context.ts +68 -4
  22. package/src/controllers/client.ts +47 -95
  23. package/src/controllers/data.ts +356 -33
  24. package/src/controllers/data_driver.ts +144 -11
  25. package/src/errors.ts +43 -4
  26. package/src/types/admin_block.ts +84 -0
  27. package/src/types/auth_adapter.ts +7 -0
  28. package/src/types/backend.ts +2 -0
  29. package/src/types/collections.ts +47 -8
  30. package/src/types/cron.ts +51 -9
  31. package/src/types/entities.ts +12 -0
  32. package/src/types/entity_callbacks.ts +2 -1
  33. package/src/types/filter-operators.ts +17 -1
  34. package/src/types/index.ts +2 -0
  35. package/src/types/policy.ts +13 -13
  36. package/src/types/properties.ts +32 -6
  37. package/src/types/rls-functions.ts +98 -0
  38. package/src/types/search.ts +247 -0
@@ -1,8 +1,80 @@
1
+ import type { VectorSearchParams } from "./data_driver";
2
+ import type { ComputedSortField, SearchMatch } from "../types/search";
1
3
  import { Entity, EntityValues } from "../types/entities";
2
4
  import { WhereFilterOp, FieldPath, FilterValues, OrderByTuple } from "../types/filter-operators";
3
5
 
6
+ /**
7
+ * Operator-blind filter value: whatever the column holds, a list of it, or null.
8
+ *
9
+ * @deprecated Superseded by {@link WhereValueFor}, which correlates the value
10
+ * with the operator. Kept exported because it is public API and downstream code
11
+ * annotates with it; every `where()` overload in this file uses `WhereValueFor`.
12
+ */
4
13
  export type WhereValue<T> = T | T[] | null;
5
14
 
15
+ /**
16
+ * The element type of an array column, and the column's own type otherwise.
17
+ *
18
+ * A generated SDK emits an `array` property as `Array<X>` and a to-many
19
+ * relation as `Array<TargetRow>`, so this is what `array-contains` compares
20
+ * against on either.
21
+ */
22
+ export type ElementOf<T> = T extends readonly (infer E)[] ? E : T;
23
+
24
+ /**
25
+ * The `id` of a row-shaped element, and `never` for anything else.
26
+ *
27
+ * A to-many relation is emitted as `Array<TargetRow>`, but the filter compilers
28
+ * compare a relation by **id** — `buildRelationFilterPredicate` in
29
+ * `@rebasepro/server-postgres` unwraps a relation value down to its id — so
30
+ * `where("tags", "array-contains", tagId)` is the call that works, and the
31
+ * element type alone would refuse it.
32
+ */
33
+ export type IdOf<E> = E extends { id: infer I } ? I : never;
34
+
35
+ /**
36
+ * One member of an array column: its element, or — when the element is a row —
37
+ * that row's id, which is what a relation filter is actually compared against.
38
+ */
39
+ export type WhereElementOf<T> = ElementOf<T> | IdOf<ElementOf<T>>;
40
+
41
+ /**
42
+ * The value a given operator takes on a column of type `T`.
43
+ *
44
+ * `WhereValue<T>` was one value type for all sixteen operators, which made
45
+ * `array-contains` uncallable from a generated SDK — it is the one operator
46
+ * whose value is an *element* of the column rather than the column's own type,
47
+ * so on `tags: string[]` it wanted a `string[]` and the documented
48
+ * `.where("tags", "array-contains", "featured")` was a compile error. The
49
+ * spelling that did compile, `["featured"]`, builds `@> ARRAY[$1]` with the
50
+ * whole array bound as the single element and matches nothing: the correct
51
+ * query rejected, the accepted query silently wrong.
52
+ *
53
+ * The branches mirror `buildSingleFilterCondition` in `@rebasepro/server-postgres`:
54
+ *
55
+ * - `array-contains` → one element of the column (or a related row's id).
56
+ * - `in` / `not-in` / `array-contains-any` → a list of elements; a bare element
57
+ * is read as the one-element list, and `null` is a null check.
58
+ * - `like` / `ilike` / `not-like` / `not-ilike` → a SQL pattern. Always a
59
+ * string, including on numeric and date columns, which the driver casts.
60
+ * - `is-null` / `is-not-null` → nothing; the value is ignored everywhere.
61
+ * - everything else → the column's own type, or `null` for a null comparison.
62
+ *
63
+ * Distributes over `Op`, so a caller holding an unnarrowed `WhereFilterOp`
64
+ * (a dynamic filter UI, say) gets the union of every branch and stays as
65
+ * permissive as it was.
66
+ */
67
+ export type WhereValueFor<Op extends WhereFilterOp, T> =
68
+ Op extends "array-contains"
69
+ ? WhereElementOf<T>
70
+ : Op extends "in" | "not-in" | "array-contains-any"
71
+ ? readonly WhereElementOf<T>[] | WhereElementOf<T> | null
72
+ : Op extends "like" | "ilike" | "not-like" | "not-ilike"
73
+ ? string
74
+ : Op extends "is-null" | "is-not-null"
75
+ ? null | undefined
76
+ : T | null;
77
+
6
78
  export interface LogicalCondition {
7
79
  type: "and" | "or";
8
80
  conditions: (FilterCondition | LogicalCondition)[];
@@ -47,9 +119,14 @@ export interface FindParams<M extends Record<string, unknown> = Record<string, u
47
119
  /**
48
120
  * Maximum number of items to return.
49
121
  *
50
- * Defaults to {@link DEFAULT_LIST_LIMIT}, and is clamped to
51
- * {@link MAX_LIST_LIMIT}. Both bounds are applied by the backend, so a
52
- * read is never unbounded whether or not a limit was asked for.
122
+ * Omit it and the backend applies {@link DEFAULT_LIST_LIMIT}, so a read is
123
+ * never unbounded. Provide it and it must be a whole number between 1 and
124
+ * {@link MAX_LIST_LIMIT}: the backend **rejects** anything else with a 400
125
+ * rather than trimming it to fit, because a page quietly smaller than the
126
+ * one you asked for is indistinguishable from having reached the end of the
127
+ * collection. To read past the ceiling, page with `offset` — or let
128
+ * {@link SDKCollectionClient.iterate} / {@link SDKCollectionClient.findAll}
129
+ * do it for you.
53
130
  */
54
131
  limit?: number;
55
132
  /**
@@ -86,7 +163,7 @@ export interface FindParams<M extends Record<string, unknown> = Record<string, u
86
163
  * Sort order as a `[field, direction]` tuple.
87
164
  * @example orderBy: ["created_at", "desc"]
88
165
  */
89
- orderBy?: OrderByTuple<FieldPath<M>>;
166
+ orderBy?: OrderByTuple<FieldPath<M> | ComputedSortField>;
90
167
  /**
91
168
  * Relations to include in the response.
92
169
  *
@@ -96,11 +173,47 @@ export interface FindParams<M extends Record<string, unknown> = Record<string, u
96
173
  */
97
174
  include?: string[];
98
175
  /**
99
- * Full-text search string. Matched (OR-ed) across the collection's
100
- * searchable columns, then AND-ed with `where`/`logical`. This is the
101
- * value behind the query builder's `.search()` method.
176
+ * Text search string, AND-ed with `where`/`logical`. This is the value
177
+ * behind the query builder's `.search()` method.
178
+ *
179
+ * What it compiles to depends on the collection. By default — matching
180
+ * every collection that has not said otherwise — it is a case-insensitive
181
+ * substring match OR-ed across the collection's top-level `string`
182
+ * properties: it does not reach inside `map` or `array` properties, it does
183
+ * not stem or rank, and it cannot use an index.
184
+ *
185
+ * A Postgres collection that declares a `search` block instead gets a
186
+ * ranked full-text match over exactly the fields it named, and rows come
187
+ * back with a {@link FindParams.orderBy}-able `_score`.
102
188
  */
103
189
  searchString?: string;
190
+
191
+ /**
192
+ * Nearest-neighbour search over a `vector` property.
193
+ *
194
+ * Postgres only, and only for a collection that declares a property of
195
+ * type `vector`. Rows come back ordered by distance, closest first, each
196
+ * carrying a `_distance`. Combines with `where` and `logical`, which are
197
+ * applied as filters before the ordering — so this is "the nearest rows
198
+ * that also match", not "the nearest rows, then filtered".
199
+ *
200
+ * Supplying the query vector is the caller's job: rebase stores and
201
+ * searches embeddings, it does not compute them.
202
+ */
203
+ vectorSearch?: VectorSearchParams;
204
+
205
+ /**
206
+ * Ask each returned row to explain itself: which declared search fields
207
+ * matched, with a highlighted snippet from each. Populates `_matches`.
208
+ *
209
+ * Off by default because it is not free — one `ts_headline` per declared
210
+ * field per returned row, and `ts_headline` re-parses the document rather
211
+ * than reading the index. Fine for a page of results, not for an export.
212
+ *
213
+ * Ignored unless the collection declares a `search` block and the query
214
+ * carries a `searchString`; there is nothing to explain otherwise.
215
+ */
216
+ searchExplain?: boolean;
104
217
  }
105
218
 
106
219
  /**
@@ -122,35 +235,50 @@ export interface FindResponse<M extends Record<string, unknown> = Record<string,
122
235
 
123
236
 
124
237
  /**
125
- * Fluent query builder for the **admin admin** — resolves to `FindResponse<M>`
238
+ * Fluent query builder for the **admin panel** — resolves to `FindResponse<M>`
126
239
  * (Snapshot-wrapped rows).
127
240
  *
128
241
  * @internal App developers should use {@link SDKQueryBuilderInterface}
129
242
  * (flat rows, returned by `client.data.*` / `context.data.*`). This
130
- * Snapshot-flavored variant backs the admin admin internals only.
243
+ * Snapshot-flavored variant backs the admin panel internals only.
131
244
  *
132
245
  * @group Data
133
246
  */
134
247
  export interface QueryBuilderInterface<M extends Record<string, unknown> = Record<string, unknown>> {
135
- where<K extends keyof M & string>(column: K, operator: WhereFilterOp, value: WhereValue<M[K]>): this;
248
+ where<K extends keyof M & string, Op extends WhereFilterOp>(column: K, operator: Op, value: WhereValueFor<Op, M[K]>): this;
136
249
  where(logicalCondition: LogicalCondition): this;
137
- orderBy(column: keyof M & string, direction?: "asc" | "desc"): this;
250
+ orderBy(column: (keyof M & string) | ComputedSortField, direction?: "asc" | "desc"): this;
138
251
  limit(count: number): this;
139
252
  offset(count: number): this;
140
- search(searchString: string): this;
253
+ search(searchString: string, options?: { explain?: boolean }): this;
254
+
255
+ /**
256
+ * Order rows by nearest-neighbour distance to `vector`, closest first.
257
+ *
258
+ * Postgres only, over a property declared as `type: "vector"`. Each row
259
+ * comes back with a `_distance`. Any `where` on the same query filters
260
+ * before the ordering; distance decides the order.
261
+ *
262
+ * The query embedding is the caller's to produce.
263
+ */
264
+ vectorSearch(
265
+ property: string,
266
+ vector: number[],
267
+ options?: { distance?: "cosine" | "l2" | "inner_product"; threshold?: number }
268
+ ): this;
141
269
  include(...relations: string[]): this;
142
270
  find(): Promise<FindResponse<M>>;
143
271
  listen(onUpdate: (data: FindResponse<M>) => void, onError?: (error: Error) => void): () => void;
144
272
  }
145
273
 
146
274
  /**
147
- * A single collection's CRUD accessor for the **admin admin** — every method
275
+ * A single collection's CRUD accessor for the **admin panel** — every method
148
276
  * resolves to `Snapshot`-wrapped rows (`FindResponse<M>` / `Snapshot<M>`).
149
277
  *
150
278
  * @internal App developers do **not** use this. The public, symmetric surface
151
279
  * is {@link SDKCollectionClient} (flat rows), exposed as `client.data.products`
152
280
  * in the SDK and `context.data.products` in framework callbacks. This
153
- * Snapshot-flavored accessor backs the admin admin view-model only.
281
+ * Snapshot-flavored accessor backs the admin panel view-model only.
154
282
  *
155
283
  * @group Data
156
284
  */
@@ -187,6 +315,20 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
187
315
  */
188
316
  update(id: string | number, data: Partial<EntityValues<M>>): Promise<Entity<M>>;
189
317
 
318
+ /**
319
+ * Update many records in a single transaction.
320
+ *
321
+ * See {@link SDKCollectionClient.updateMany}. Optional, as `createMany` is.
322
+ */
323
+ updateMany?(updates: { id: string | number; data: Partial<EntityValues<M>> }[]): Promise<Entity<M>[]>;
324
+
325
+ /**
326
+ * Delete many records in a single transaction.
327
+ *
328
+ * See {@link SDKCollectionClient.deleteMany}. Optional, as `createMany` is.
329
+ */
330
+ deleteMany?(ids: (string | number)[]): Promise<void>;
331
+
190
332
  /**
191
333
  * Delete a record by ID.
192
334
  */
@@ -206,16 +348,37 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
206
348
 
207
349
  /**
208
350
  * Count the number of records matching the given filter.
351
+ *
352
+ * Optional on this contract because a data source need not support it, and
353
+ * required on `CollectionClient` — the HTTP implementation always has it.
354
+ * So `client.data.posts.count()` compiles in the browser while the same
355
+ * call through a `context.data` accessor needs `count?.()`, which is the
356
+ * one place the two halves of this API are not interchangeable.
209
357
  */
210
358
  count?(params?: FindParams<M>): Promise<number>;
211
359
 
212
360
  // Fluent Query Builder
213
- where<K extends keyof M & string>(column: K, operator: WhereFilterOp, value: WhereValue<M[K]>): QueryBuilderInterface<M>;
361
+ where<K extends keyof M & string, Op extends WhereFilterOp>(column: K, operator: Op, value: WhereValueFor<Op, M[K]>): QueryBuilderInterface<M>;
214
362
  where(logicalCondition: LogicalCondition): QueryBuilderInterface<M>;
215
- orderBy(column: keyof M & string, direction?: "asc" | "desc"): QueryBuilderInterface<M>;
363
+ orderBy(column: (keyof M & string) | ComputedSortField, direction?: "asc" | "desc"): QueryBuilderInterface<M>;
216
364
  limit(count: number): QueryBuilderInterface<M>;
217
365
  offset(count: number): QueryBuilderInterface<M>;
218
- search(searchString: string): QueryBuilderInterface<M>;
366
+ search(searchString: string, options?: { explain?: boolean }): QueryBuilderInterface<M>;
367
+
368
+ /**
369
+ * Order rows by nearest-neighbour distance to `vector`, closest first.
370
+ *
371
+ * Postgres only, over a property declared as `type: "vector"`. Each row
372
+ * comes back with a `_distance`. Any `where` on the same query filters
373
+ * before the ordering; distance decides the order.
374
+ *
375
+ * The query embedding is the caller's to produce.
376
+ */
377
+ vectorSearch(
378
+ property: string,
379
+ vector: number[],
380
+ options?: { distance?: "cosine" | "l2" | "inner_product"; threshold?: number }
381
+ ): QueryBuilderInterface<M>;
219
382
  include(...relations: string[]): QueryBuilderInterface<M>;
220
383
  }
221
384
 
@@ -246,12 +409,55 @@ export interface PaginationMeta {
246
409
  * @group Data
247
410
  */
248
411
  export interface FindResult<M extends Record<string, unknown> = Record<string, unknown>> {
249
- /** Array of flat rows matching the query */
250
- data: M[];
412
+ /**
413
+ * Flat rows matching the query, each carrying whatever the query computed
414
+ * for it — see {@link QueryComputedFields}.
415
+ */
416
+ data: (M & QueryComputedFields)[];
251
417
  /** Pagination metadata */
252
418
  meta: PaginationMeta;
253
419
  }
254
420
 
421
+ /**
422
+ * Values a query attaches to a row that are not columns of it.
423
+ *
424
+ * Both are absent unless the query asked for the thing that produces them, so
425
+ * both are optional — and reading one on a query that did not ask returns
426
+ * `undefined` rather than a wrong number.
427
+ *
428
+ * They live here rather than on the row type because a generated row type
429
+ * describes a *table*, and neither of these is in one. Without this, a caller
430
+ * who sorted by relevance could not then read the relevance.
431
+ *
432
+ * A `type` alias, deliberately, not an `interface`. TypeScript grants an
433
+ * implicit index signature to a type alias and withholds it from an interface,
434
+ * so `Row & QueryComputedFields` stops being assignable to
435
+ * `Record<string, unknown>` the moment this becomes an interface. Seven casts
436
+ * in one downstream app broke on exactly that.
437
+ *
438
+ * @group Data
439
+ */
440
+ export type QueryComputedFields = {
441
+ /**
442
+ * Relevance, when the collection declares a {@link SearchConfig} and the
443
+ * query carried a search string. Higher is better; the scale is not
444
+ * comparable between two different search strings.
445
+ */
446
+ _score?: number;
447
+ /**
448
+ * Which declared fields matched, and the text around each hit. Present only
449
+ * when the query asked for it — `.search(term, { explain: true })` — because
450
+ * it costs a `ts_headline` per field per row.
451
+ */
452
+ _matches?: SearchMatch[];
453
+ /**
454
+ * Distance to the query vector, when the query used
455
+ * {@link FindParams.vectorSearch}. Lower is closer, and the rows are
456
+ * already ordered by it.
457
+ */
458
+ _distance?: number;
459
+ };
460
+
255
461
  /**
256
462
  * Which column an iteration seeks on, for keyset ("seek") pagination.
257
463
  *
@@ -344,12 +550,27 @@ export type FindAllParams<M extends Record<string, unknown> = Record<string, unk
344
550
  * @group Data
345
551
  */
346
552
  export interface SDKQueryBuilderInterface<M extends Record<string, unknown> = Record<string, unknown>> {
347
- where<K extends keyof M & string>(column: K, operator: WhereFilterOp, value: WhereValue<M[K]>): this;
553
+ where<K extends keyof M & string, Op extends WhereFilterOp>(column: K, operator: Op, value: WhereValueFor<Op, M[K]>): this;
348
554
  where(logicalCondition: LogicalCondition): this;
349
- orderBy(column: keyof M & string, direction?: "asc" | "desc"): this;
555
+ orderBy(column: (keyof M & string) | ComputedSortField, direction?: "asc" | "desc"): this;
350
556
  limit(count: number): this;
351
557
  offset(count: number): this;
352
- search(searchString: string): this;
558
+ search(searchString: string, options?: { explain?: boolean }): this;
559
+
560
+ /**
561
+ * Order rows by nearest-neighbour distance to `vector`, closest first.
562
+ *
563
+ * Postgres only, over a property declared as `type: "vector"`. Each row
564
+ * comes back with a `_distance`. Any `where` on the same query filters
565
+ * before the ordering; distance decides the order.
566
+ *
567
+ * The query embedding is the caller's to produce.
568
+ */
569
+ vectorSearch(
570
+ property: string,
571
+ vector: number[],
572
+ options?: { distance?: "cosine" | "l2" | "inner_product"; threshold?: number }
573
+ ): this;
353
574
  include(...relations: string[]): this;
354
575
  find(): Promise<FindResult<M>>;
355
576
  count(): Promise<number>;
@@ -395,9 +616,20 @@ export interface WriteOptions {
395
616
  * it performs it again. On a table with a server-assigned id that is a
396
617
  * duplicate row, because the id the client chose was never used.
397
618
  *
619
+ * A key names **one** request, not a job. It records the method, the path
620
+ * and the body it was claimed for, so re-sending that exact request replays
621
+ * its answer, while the same key on a different one is refused with
622
+ * `IDEMPOTENCY_KEY_REUSED` (422) rather than silently answered with the
623
+ * first request's result. Pass a fresh key — a uuid — per call; a reusable
624
+ * business id shared by the create and the delete of one import means the
625
+ * second of them never runs.
626
+ *
398
627
  * Set by the offline queue on every replay. Honoured for 24 hours and scoped
399
- * to the authenticated user; a server that cannot store keys ignores it
400
- * rather than refusing the write.
628
+ * to the authenticated user — an unauthenticated caller has no principal to
629
+ * scope it to, so the key is ignored there. A retry sent while the first
630
+ * attempt is still being answered gets `IDEMPOTENCY_KEY_IN_PROGRESS` (409)
631
+ * and should be sent again. A server that cannot store keys ignores the
632
+ * header rather than refusing the write.
401
633
  */
402
634
  idempotencyKey?: string;
403
635
  }
@@ -507,6 +739,12 @@ export interface SDKCollectionClient<
507
739
  * Batches are capped server-side (1000 rows by default) because one batch
508
740
  * holds its locks for the whole transaction — chunk larger jobs.
509
741
  *
742
+ * Pass {@link WriteOptions.idempotencyKey} on anything that may be retried.
743
+ * A client that never sees the response cannot know whether the batch
744
+ * committed, and without a key the server cannot tell the retry from a
745
+ * second genuine import — so it performs it again, duplicating every row in
746
+ * the batch rather than just one.
747
+ *
510
748
  * @returns The written rows, in the order given.
511
749
  *
512
750
  * @example
@@ -516,7 +754,7 @@ export interface SDKCollectionClient<
516
754
  * }
517
755
  * ```
518
756
  */
519
- createMany(data: I[], options?: { upsert?: boolean }): Promise<M[]>;
757
+ createMany(data: I[], options?: { upsert?: boolean } & WriteOptions): Promise<M[]>;
520
758
 
521
759
  /**
522
760
  * Update an existing record by ID.
@@ -526,6 +764,46 @@ export interface SDKCollectionClient<
526
764
  */
527
765
  update(id: string | number, data: U): Promise<M>;
528
766
 
767
+ /**
768
+ * Update many records in a single request and a single transaction.
769
+ *
770
+ * The counterpart to {@link createMany}, and the reason it exists is the
771
+ * same: one call per row means one HTTP round trip and one transaction per
772
+ * row. Every record still runs the normal pipeline — callbacks, relations,
773
+ * row-level security — and the batch is all-or-nothing, so a rejected
774
+ * record leaves none of them written and the error names the offending
775
+ * index.
776
+ *
777
+ * Each entry is `{ id, data }` rather than a flat row carrying its own key.
778
+ * That is deliberate: on a table keyed on something other than `id` — a
779
+ * `sku`, a composite key — a flat row cannot say whether a column is the
780
+ * address or a value to write. Naming the address separately mirrors
781
+ * single-row `update(id, data)` exactly and leaves nothing to infer.
782
+ *
783
+ * An id that matches no row fails the batch with a 404 rather than being
784
+ * skipped, for the same reason `update()` does: silently updating four of
785
+ * five rows is worse than updating none.
786
+ *
787
+ * Batches share `createMany`'s server-side cap (1000 rows by default),
788
+ * because one batch holds its locks for the whole transaction.
789
+ *
790
+ * Pass {@link WriteOptions.idempotencyKey} on anything that may be retried.
791
+ * An update replayed in full is naturally idempotent, but one interleaved
792
+ * with another writer's is not — the key is what stops a lost ACK from
793
+ * re-applying a stale batch over newer data.
794
+ *
795
+ * @returns The updated rows, in the order given.
796
+ *
797
+ * @example
798
+ * ```ts
799
+ * await client.data.orders.updateMany([
800
+ * { id: "o-1", data: { status: "shipped" } },
801
+ * { id: "o-2", data: { status: "shipped" } }
802
+ * ]);
803
+ * ```
804
+ */
805
+ updateMany(updates: { id: string | number; data: U }[], options?: WriteOptions): Promise<M[]>;
806
+
529
807
  /**
530
808
  * Delete a record by ID.
531
809
  * @throws {RebaseApiError} with status 404 when the record does not exist.
@@ -533,13 +811,48 @@ export interface SDKCollectionClient<
533
811
  delete(id: string | number): Promise<void>;
534
812
 
535
813
  /**
536
- * Subscribe to a collection for real-time updates.
814
+ * Delete many records in a single request and a single transaction.
815
+ *
816
+ * Takes ids, not a filter. A filter-shaped bulk delete is a different and
817
+ * far more dangerous operation — the failure mode is an omitted or
818
+ * mistyped condition emptying a table, and it cannot be reviewed at the
819
+ * call site the way an explicit list can. Read first, then pass the ids you
820
+ * meant.
821
+ *
822
+ * `beforeDelete` and `afterDelete` fire per row, exactly as they do for
823
+ * single deletes, and returning `false` from `beforeDelete` fails the batch
824
+ * rather than quietly dropping one row from it. All-or-nothing, so an id
825
+ * that matches no row 404s the whole call.
826
+ *
827
+ * Shares `createMany`'s row cap.
828
+ *
829
+ * @example
830
+ * ```ts
831
+ * const stale = await client.data.sessions.findAll({
832
+ * where: { expires_at: ["<", cutoff] }
833
+ * });
834
+ * await client.data.sessions.deleteMany(stale.map(s => s.id as string));
835
+ * ```
537
836
  */
538
- listen?(params: FindParams<M> | undefined, onUpdate: (response: FindResult<M>) => void, onError?: (error: Error) => void): () => void;
837
+ deleteMany(ids: (string | number)[], options?: WriteOptions): Promise<void>;
539
838
 
540
839
  /**
541
- * Subscribe to a single record for real-time updates.
840
+ * The low-level realtime subscription: raw server pushes, nothing else.
841
+ *
842
+ * **Prefer `observe()`** on a client from `@rebasepro/client`, which wraps
843
+ * this one and is what a UI actually wants — it emits from the local
844
+ * database first when offline is enabled, re-emits on local writes and
845
+ * rollbacks, and de-duplicates emissions so a refresh that changes nothing
846
+ * does not call back. `listen` does none of that; it forwards what the
847
+ * socket sends.
848
+ *
849
+ * Optional because it is only present when realtime is enabled. `observe()`
850
+ * is not — it degrades to a single fetch — which is the other reason to
851
+ * reach for it instead.
542
852
  */
853
+ listen?(params: FindParams<M> | undefined, onUpdate: (response: FindResult<M>) => void, onError?: (error: Error) => void): () => void;
854
+
855
+ /** {@link listen} for a single row. Prefer `observeById()`. */
543
856
  listenById?(id: string | number, onUpdate: (row: M | undefined) => void, onError?: (error: Error) => void): () => void;
544
857
 
545
858
  /**
@@ -548,17 +861,27 @@ export interface SDKCollectionClient<
548
861
  count?(params?: FindParams<M>): Promise<number>;
549
862
 
550
863
  // Fluent Query Builder
551
- where<K extends keyof M & string>(column: K, operator: WhereFilterOp, value: WhereValue<M[K]>): SDKQueryBuilderInterface<M>;
864
+ where<K extends keyof M & string, Op extends WhereFilterOp>(column: K, operator: Op, value: WhereValueFor<Op, M[K]>): SDKQueryBuilderInterface<M>;
552
865
  where(logicalCondition: LogicalCondition): SDKQueryBuilderInterface<M>;
553
- orderBy(column: keyof M & string, direction?: "asc" | "desc"): SDKQueryBuilderInterface<M>;
866
+ orderBy(column: (keyof M & string) | ComputedSortField, direction?: "asc" | "desc"): SDKQueryBuilderInterface<M>;
554
867
  limit(count: number): SDKQueryBuilderInterface<M>;
555
868
  offset(count: number): SDKQueryBuilderInterface<M>;
556
- search(searchString: string): SDKQueryBuilderInterface<M>;
869
+ search(searchString: string, options?: { explain?: boolean }): SDKQueryBuilderInterface<M>;
870
+ /**
871
+ * Order rows by nearest-neighbour distance to `vector`, closest first.
872
+ * Postgres only, over a `type: "vector"` property. See
873
+ * {@link SDKQueryBuilderInterface.vectorSearch}.
874
+ */
875
+ vectorSearch(
876
+ property: string,
877
+ vector: number[],
878
+ options?: { distance?: "cosine" | "l2" | "inner_product"; threshold?: number }
879
+ ): SDKQueryBuilderInterface<M>;
557
880
  include(...relations: string[]): SDKQueryBuilderInterface<M>;
558
881
  }
559
882
 
560
883
  /**
561
- * The unified data access object for the **admin admin** (Entity-shaped).
884
+ * The unified data access object for the **admin panel** (Entity-shaped).
562
885
  *
563
886
  * Access collections as dynamic properties: `data.products.find(...)`. Each
564
887
  * accessor returns `Entity`-wrapped records (`{ id, path, values }`) — the
@@ -567,7 +890,7 @@ export interface SDKCollectionClient<
567
890
  *
568
891
  * @internal App developers do **not** use this — they use
569
892
  * {@link RebaseSdkData} (flat rows), which is what the SDK client and backend
570
- * `context.data` expose. This Entity-shaped map backs the admin admin only.
893
+ * `context.data` expose. This Entity-shaped map backs the admin panel only.
571
894
  *
572
895
  * @group Data
573
896
  */