@lunora/server 1.0.0-alpha.26 → 1.0.0-alpha.28

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.
@@ -1,25 +1,25 @@
1
1
  /**
2
- * Schema-independent type machinery for the generated data model.
3
- *
4
- * `@lunora/codegen` emits `lunora/_generated/dataModel.ts` with the
5
- * schema-specific pieces (the per-table `Doc_*` / `Insert_*` interfaces, the
6
- * `DataModel` / `Relations` / index-name maps) and then binds the generics
7
- * below to them. Everything here is identical for every project, so it lives
8
- * in the shipped package rather than in generated output — evolving the query
9
- * DSL or the table-facade API no longer regenerates a single line of a user's
10
- * `_generated` directory.
11
- *
12
- * The generics are parameterized over the generated maps:
13
- * - `DM` — `DataModel`: table name → document type
14
- * - `IM` — `InsertModel`: table name → insert shape
15
- * - `REL` — `Relations`: table name → relation-descriptor map
16
- * - `RANK` — `RankIndexNamesByTable`: table name → declared rank-index names
17
- * - `SEARCH` — `SearchIndexNamesByTable`: table name → declared search-index names
18
- *
19
- * Relation descriptors are matched structurally (`{ __relationKind; __target }`)
20
- * so this module needs no reference to the project-local `OneRelation` /
21
- * `ManyRelation` aliases the codegen still emits.
22
- */
2
+ * Schema-independent type machinery for the generated data model.
3
+ *
4
+ * `@lunora/codegen` emits `lunora/_generated/dataModel.ts` with the
5
+ * schema-specific pieces (the per-table `Doc_*` / `Insert_*` interfaces, the
6
+ * `DataModel` / `Relations` / index-name maps) and then binds the generics
7
+ * below to them. Everything here is identical for every project, so it lives
8
+ * in the shipped package rather than in generated output — evolving the query
9
+ * DSL or the table-facade API no longer regenerates a single line of a user's
10
+ * `_generated` directory.
11
+ *
12
+ * The generics are parameterized over the generated maps:
13
+ * - `DM` — `DataModel`: table name → document type
14
+ * - `IM` — `InsertModel`: table name → insert shape
15
+ * - `REL` — `Relations`: table name → relation-descriptor map
16
+ * - `RANK` — `RankIndexNamesByTable`: table name → declared rank-index names
17
+ * - `SEARCH` — `SearchIndexNamesByTable`: table name → declared search-index names
18
+ *
19
+ * Relation descriptors are matched structurally (`{ __relationKind; __target }`)
20
+ * so this module needs no reference to the project-local `OneRelation` /
21
+ * `ManyRelation` aliases the codegen still emits.
22
+ */
23
23
  /** A branded id for table `TName`. Structurally a `string` at runtime. */
24
24
  type Id<TName extends string> = string & {
25
25
  readonly __table: TName;
@@ -38,7 +38,7 @@ interface WhereOperators<T> {
38
38
  notIn?: T[];
39
39
  }
40
40
  /** A typed `where` tree over a document's columns. */
41
- type Where<TDocument> = { [K in keyof TDocument]?: TDocument[K] | WhereOperators<TDocument[K]> } & {
41
+ type Where<TDocument> = { [K in keyof TDocument]?: TDocument[K] | WhereOperators<TDocument[K]>; } & {
42
42
  AND?: Where<TDocument>[];
43
43
  NOT?: Where<TDocument>;
44
44
  OR?: Where<TDocument>[];
@@ -50,53 +50,53 @@ interface QueryArgs<TDocument> {
50
50
  limit?: number;
51
51
  orderBy?: OrderBy<TDocument>[];
52
52
  /**
53
- * Project each returned row down to these columns (plus the system fields
54
- * `_id`/`_creationTime`, always retained). Trims wire payload for wide rows;
55
- * relations requested via `with` are still attached. Reactivity is unaffected —
56
- * the engine still reads the whole row to track dependencies.
57
- */
53
+ * Project each returned row down to these columns (plus the system fields
54
+ * `_id`/`_creationTime`, always retained). Trims wire payload for wide rows;
55
+ * relations requested via `with` are still attached. Reactivity is unaffected —
56
+ * the engine still reads the whole row to track dependencies.
57
+ */
58
58
  select?: ReadonlyArray<keyof TDocument & string>;
59
59
  where?: Where<TDocument>;
60
60
  }
61
61
  /**
62
- * A to-one relation predicate node. `is` matches rows whose related record
63
- * satisfies `W`; `isNot` matches rows whose related record fails `W` *or* has
64
- * no related record at all (a null/dangling FK) — Prisma's semantics.
65
- */
62
+ * A to-one relation predicate node. `is` matches rows whose related record
63
+ * satisfies `W`; `isNot` matches rows whose related record fails `W` *or* has
64
+ * no related record at all (a null/dangling FK) — Prisma's semantics.
65
+ */
66
66
  interface OneRelationWhere<W> {
67
67
  is?: W;
68
68
  isNot?: W;
69
69
  }
70
70
  /**
71
- * A to-many relation predicate node. `some` ⇒ at least one related row matches
72
- * `W`; `none` ⇒ no related row matches (childless parents included); `every` ⇒
73
- * every *readable* related row matches (vacuously true for childless parents).
74
- */
71
+ * A to-many relation predicate node. `some` ⇒ at least one related row matches
72
+ * `W`; `none` ⇒ no related row matches (childless parents included); `every` ⇒
73
+ * every *readable* related row matches (vacuously true for childless parents).
74
+ */
75
75
  interface ManyRelationWhere<W> {
76
76
  every?: W;
77
77
  none?: W;
78
78
  some?: W;
79
79
  }
80
80
  /**
81
- * The relation-predicate portion of {@link WhereOf}: each declared relation on
82
- * `T` contributes a kind-dispatched node — `one` → `{ is?; isNot? }`, `many` →
83
- * `{ some?; none?; every? }` — whose inner type is the target table's own
84
- * relation-aware `where` (so multi-hop predicates type-check inside-out).
85
- */
81
+ * The relation-predicate portion of {@link WhereOf}: each declared relation on
82
+ * `T` contributes a kind-dispatched node — `one` → `{ is?; isNot? }`, `many` →
83
+ * `{ some?; none?; every? }` — whose inner type is the target table's own
84
+ * relation-aware `where` (so multi-hop predicates type-check inside-out).
85
+ */
86
86
  type RelationWhere<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [K in keyof REL[T]]?: REL[T][K] extends {
87
87
  __relationKind: "one";
88
88
  __target: infer Target extends keyof DM;
89
89
  } ? OneRelationWhere<WhereOf<DM, REL, Target>> : REL[T][K] extends {
90
90
  __relationKind: "many";
91
91
  __target: infer Target extends keyof DM;
92
- } ? ManyRelationWhere<WhereOf<DM, REL, Target>> : never };
92
+ } ? ManyRelationWhere<WhereOf<DM, REL, Target>> : never; };
93
93
  /**
94
- * Relation-aware `where` tree — the column predicates of {@link Where} plus
95
- * Prisma-style relation predicates resolved by the `@lunora/do` pre-resolver.
96
- * `Where&lt;DM[T]>` stays the column-only structural mirror for back-compat; the
97
- * table facade threads `REL` through this richer form.
98
- */
99
- type WhereOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = RelationWhere<DM, REL, T> & { [K in keyof DM[T]]?: DM[T][K] | WhereOperators<DM[T][K]> } & {
94
+ * Relation-aware `where` tree — the column predicates of {@link Where} plus
95
+ * Prisma-style relation predicates resolved by the `@lunora/do` pre-resolver.
96
+ * `Where&lt;DM[T]>` stays the column-only structural mirror for back-compat; the
97
+ * table facade threads `REL` through this richer form.
98
+ */
99
+ type WhereOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = RelationWhere<DM, REL, T> & { [K in keyof DM[T]]?: DM[T][K] | WhereOperators<DM[T][K]>; } & {
100
100
  AND?: WhereOf<DM, REL, T>[];
101
101
  NOT?: WhereOf<DM, REL, T>;
102
102
  OR?: WhereOf<DM, REL, T>[];
@@ -105,10 +105,10 @@ type WhereOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = Rel
105
105
  interface QueryArgsOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> {
106
106
  cursor?: null | string;
107
107
  /**
108
- * Include soft-deleted rows (`.softDelete()` tables only). Default hides them;
109
- * `true` returns deleted rows alongside live ones. No effect on a table
110
- * without `.softDelete()`.
111
- */
108
+ * Include soft-deleted rows (`.softDelete()` tables only). Default hides them;
109
+ * `true` returns deleted rows alongside live ones. No effect on a table
110
+ * without `.softDelete()`.
111
+ */
112
112
  includeDeleted?: boolean;
113
113
  limit?: number;
114
114
  orderBy?: OrderBy<DM[T]>[];
@@ -128,11 +128,11 @@ type NestedSelectArgument<WK> = WK extends {
128
128
  select: infer S;
129
129
  } ? S : undefined;
130
130
  /**
131
- * The `with` argument for table `T`: each relation can be `true` (load with no
132
- * refinements) or an object. `many` relations accept `where`/`orderBy`/`limit`/
133
- * `select` plus a nested `with`; `one` relations accept `select` + a nested
134
- * `with`. The reserved `_count` key requests per-relation aggregate counts.
135
- */
131
+ * The `with` argument for table `T`: each relation can be `true` (load with no
132
+ * refinements) or an object. `many` relations accept `where`/`orderBy`/`limit`/
133
+ * `select` plus a nested `with`; `one` relations accept `select` + a nested
134
+ * `with`. The reserved `_count` key requests per-relation aggregate counts.
135
+ */
136
136
  type WithArg<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [K in keyof REL[T]]?: REL[T][K] extends {
137
137
  __relationKind: "many";
138
138
  __target: infer Target extends keyof DM;
@@ -144,15 +144,15 @@ type WithArg<DM, REL extends Record<keyof DM, object>, T extends keyof DM> = { [
144
144
  } ? boolean | {
145
145
  select?: ReadonlyArray<keyof DM[Target] & string>;
146
146
  with?: WithArg<DM, REL, Target>;
147
- } : never } & {
148
- _count?: { [K in keyof REL[T]]?: true };
147
+ } : never; } & {
148
+ _count?: { [K in keyof REL[T]]?: true; };
149
149
  };
150
150
  /**
151
- * Resolve a single relation descriptor + its with-value to the loaded type,
152
- * threading the nested `select` tuple into the projected child shape (the 5th
153
- * `LoadWith` arg) so `with: { author: { select: ["name"] } }` narrows the loaded
154
- * `author` to the selected columns + system fields.
155
- */
151
+ * Resolve a single relation descriptor + its with-value to the loaded type,
152
+ * threading the nested `select` tuple into the projected child shape (the 5th
153
+ * `LoadWith` arg) so `with: { author: { select: ["name"] } }` narrows the loaded
154
+ * `author` to the selected columns + system fields.
155
+ */
156
156
  type LoadRelation<DM, REL extends Record<keyof DM, object>, R, WK> = R extends {
157
157
  __relationKind: "one";
158
158
  __target: infer Target extends keyof DM;
@@ -161,47 +161,47 @@ type LoadRelation<DM, REL extends Record<keyof DM, object>, R, WK> = R extends {
161
161
  __target: infer Target extends keyof DM;
162
162
  } ? LoadWith<DM, REL, Target, NestedWithArgument<WK>, NestedSelectArgument<WK>>[] : never;
163
163
  /** The relation keys of `W` that were actually requested (not `false`/`undefined`). */
164
- type LoadedRelations<DM, REL extends Record<keyof DM, object>, T extends keyof DM, W> = { [K in keyof W as K extends keyof REL[T] ? (W[K] extends false | undefined ? never : K) : never]: K extends keyof REL[T] ? LoadRelation<DM, REL, REL[T][K], W[K]> : never };
164
+ type LoadedRelations<DM, REL extends Record<keyof DM, object>, T extends keyof DM, W> = { [K in keyof W as K extends keyof REL[T] ? (W[K] extends false | undefined ? never : K) : never]: K extends keyof REL[T] ? LoadRelation<DM, REL, REL[T][K], W[K]> : never; };
165
165
  /** The `_count` projection of `W`, if any. */
166
166
  type LoadedCount<W> = W extends {
167
167
  _count: infer C;
168
168
  } ? {
169
- _count: { [K in keyof C]: number };
169
+ _count: { [K in keyof C]: number; };
170
170
  } : {};
171
171
  /** System columns a `select` projection always retains, so cursors and by-id reuse keep working. */
172
172
  type SelectAlwaysKeep<DM, T extends keyof DM> = ("_creationTime" | "_id") & keyof DM[T];
173
173
  /**
174
- * `DM[T]` narrowed to the columns named by a `select` tuple `S` (plus the system
175
- * fields). `undefined` (the default — no `select`) keeps the full document.
176
- */
174
+ * `DM[T]` narrowed to the columns named by a `select` tuple `S` (plus the system
175
+ * fields). `undefined` (the default — no `select`) keeps the full document.
176
+ */
177
177
  type ProjectDoc<DM, T extends keyof DM, S> = S extends ReadonlyArray<infer K> ? (K extends keyof DM[T] ? Pick<DM[T], (K & keyof DM[T]) | SelectAlwaysKeep<DM, T>> : DM[T]) : DM[T];
178
178
  /**
179
- * `Doc&lt;T>` narrowed to exactly the relations requested in the with-arg `W` and,
180
- * when a `select` tuple `S` is supplied, to its projected columns. `S` defaults
181
- * to `undefined` so the 4-argument form (the codegen-emitted callers) keeps the
182
- * full document.
183
- */
179
+ * `Doc&lt;T>` narrowed to exactly the relations requested in the with-arg `W` and,
180
+ * when a `select` tuple `S` is supplied, to its projected columns. `S` defaults
181
+ * to `undefined` so the 4-argument form (the codegen-emitted callers) keeps the
182
+ * full document.
183
+ */
184
184
  type LoadWith<DM, REL extends Record<keyof DM, object>, T extends keyof DM, W, S = undefined> = LoadedCount<W> & LoadedRelations<DM, REL, T, W> & ProjectDoc<DM, T, S>;
185
185
  /** Reducer applied by an aggregate (`avg`/`count`/`max`/`min`/`sum`). */
186
186
  type AggregateOp = "avg" | "count" | "max" | "min" | "sum";
187
187
  /**
188
- * Query-options shape shared by every aggregate reader. The RLS-aware ctx
189
- * populates `baseWhere` so it composes here without a hard import.
190
- * `restrictsCounts: true` flips `count()` into a thrown `COUNT_RLS_UNSUPPORTED`
191
- * `LunoraError` rather than silently undercount.
192
- */
188
+ * Query-options shape shared by every aggregate reader. The RLS-aware ctx
189
+ * populates `baseWhere` so it composes here without a hard import.
190
+ * `restrictsCounts: true` flips `count()` into a thrown `COUNT_RLS_UNSUPPORTED`
191
+ * `LunoraError` rather than silently undercount.
192
+ */
193
193
  interface RestrictableQueryOptions<TDocument> {
194
194
  baseWhere?: Where<TDocument>;
195
195
  restrictsCounts?: boolean;
196
196
  where?: Where<TDocument>;
197
197
  }
198
198
  /**
199
- * Relation-aware twin of {@link RestrictableQueryOptions}. The `@lunora/do`
200
- * pre-resolver now resolves relation predicates on the `count`/`aggregate`/
201
- * `groupBy` paths too (semijoin), so the typed surface threads `REL` through
202
- * `where`/`baseWhere` to match. `rank`/`rankPage` stay column-only — they use
203
- * `where` solely to pin a partition and fail closed on a relation predicate.
204
- */
199
+ * Relation-aware twin of {@link RestrictableQueryOptions}. The `@lunora/do`
200
+ * pre-resolver now resolves relation predicates on the `count`/`aggregate`/
201
+ * `groupBy` paths too (semijoin), so the typed surface threads `REL` through
202
+ * `where`/`baseWhere` to match. `rank`/`rankPage` stay column-only — they use
203
+ * `where` solely to pin a partition and fail closed on a relation predicate.
204
+ */
205
205
  interface RestrictableQueryOptionsOf<DM, REL extends Record<keyof DM, object>, T extends keyof DM> {
206
206
  baseWhere?: WhereOf<DM, REL, T>;
207
207
  restrictsCounts?: boolean;
@@ -259,20 +259,20 @@ interface RankPage<TDocument> {
259
259
  page: TDocument[];
260
260
  }
261
261
  /**
262
- * Builder passed to `.withSearchIndex(name, q => …)`. `.search(field, query)`
263
- * runs the full-text match against the index's searchable field; `.eq(field,
264
- * value)` narrows by a declared filter field. Field names are constrained to
265
- * the table's columns.
266
- */
262
+ * Builder passed to `.withSearchIndex(name, q => …)`. `.search(field, query)`
263
+ * runs the full-text match against the index's searchable field; `.eq(field,
264
+ * value)` narrows by a declared filter field. Field names are constrained to
265
+ * the table's columns.
266
+ */
267
267
  interface SearchFilterBuilder<TDocument> {
268
268
  eq: <F extends keyof TDocument & string>(field: F, value: TDocument[F]) => SearchFilterBuilder<TDocument>;
269
269
  search: (field: keyof TDocument & string, query: string) => SearchFilterBuilder<TDocument>;
270
270
  }
271
271
  /**
272
- * Chainable reader returned by `.withSearchIndex()` — rows come back ordered
273
- * by relevance. `.paginate()` is intentionally absent (a relevance-ordered
274
- * search can't keyset-paginate); cap the result set with `.take(n)`.
275
- */
272
+ * Chainable reader returned by `.withSearchIndex()` — rows come back ordered
273
+ * by relevance. `.paginate()` is intentionally absent (a relevance-ordered
274
+ * search can't keyset-paginate); cap the result set with `.take(n)`.
275
+ */
276
276
  interface SearchReader<TDocument> {
277
277
  collect: () => Promise<TDocument[]>;
278
278
  first: () => Promise<TDocument | null>;
@@ -282,18 +282,18 @@ interface SearchReader<TDocument> {
282
282
  /** Read-only typed table accessor exposed on `QueryCtx.db.&lt;table>`. */
283
283
  interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>, T extends keyof DM> {
284
284
  /**
285
- * Reduce rows in this table to a scalar (`avg`/`max`/`min`/`sum` — `count`
286
- * lives on its own method). Routes through a declared `aggregateIndex` when
287
- * the planner can prove the request is answerable; otherwise scans.
288
- */
285
+ * Reduce rows in this table to a scalar (`avg`/`max`/`min`/`sum` — `count`
286
+ * lives on its own method). Routes through a declared `aggregateIndex` when
287
+ * the planner can prove the request is answerable; otherwise scans.
288
+ */
289
289
  aggregate: (options: TableAggregateOptionsOf<DM, REL, T>) => Promise<null | number>;
290
290
  /**
291
- * Count rows. The planner routes `where` keys that match a declared
292
- * `aggregateIndex.by` set to the indexed counter (no scan); otherwise
293
- * falls back to a SCAN. Accepts either a bare `where` tree or the broader
294
- * `RestrictableQueryOptions` shape; the latter is the seam the RLS layer
295
- * uses to inject `baseWhere` and `restrictsCounts`.
296
- */
291
+ * Count rows. The planner routes `where` keys that match a declared
292
+ * `aggregateIndex.by` set to the indexed counter (no scan); otherwise
293
+ * falls back to a SCAN. Accepts either a bare `where` tree or the broader
294
+ * `RestrictableQueryOptions` shape; the latter is the seam the RLS layer
295
+ * uses to inject `baseWhere` and `restrictsCounts`.
296
+ */
297
297
  count: (where?: RestrictableQueryOptionsOf<DM, REL, T> | WhereOf<DM, REL, T>) => Promise<number>;
298
298
  /** `true` when at least one row matches `where` (any row when omitted). RLS-filtered exactly like `findFirst`. */
299
299
  exists: (where?: WhereOf<DM, REL, T>) => Promise<boolean>;
@@ -311,45 +311,45 @@ interface TableReaderFacade<DM, REL extends Record<keyof DM, object>, RANK exten
311
311
  }) => Promise<QueryPage<LoadWith<DM, REL, T, W, S>>>;
312
312
  get: (id: Id<string & T>) => Promise<DM[T] | null>;
313
313
  /**
314
- * Group rows by the named keys and apply `agg` per group (defaults to
315
- * `count`). Answered from the counter table when an aggregate index's
316
- * `by` matches `options.by` exactly; otherwise scans.
317
- */
314
+ * Group rows by the named keys and apply `agg` per group (defaults to
315
+ * `count`). Answered from the counter table when an aggregate index's
316
+ * `by` matches `options.by` exactly; otherwise scans.
317
+ */
318
318
  groupBy: (options: TableGroupByOptionsOf<DM, REL, T>) => Promise<ReadonlyArray<GroupByEntry<DM[T]>>>;
319
319
  /**
320
- * Return the 1-based position of `options.row` within its partition
321
- * under the declared rankIndex `indexName`, plus the partition's total
322
- * row count. `null` when the row isn't in the index. Honors the same
323
- * `baseWhere` / `restrictsCounts` RLS seam as `count()`.
324
- */
320
+ * Return the 1-based position of `options.row` within its partition
321
+ * under the declared rankIndex `indexName`, plus the partition's total
322
+ * row count. `null` when the row isn't in the index. Honors the same
323
+ * `baseWhere` / `restrictsCounts` RLS seam as `count()`.
324
+ */
325
325
  rank: (indexName: RANK[T], options: TableRankOptions<DM[T]>) => Promise<null | RankResult>;
326
326
  /**
327
- * Walk the rank companion in declared sort order — sorted pagination
328
- * accelerator. `options.where` may pin the partition; `cursor`/`take`
329
- * follow the Convex-style keyset shape.
330
- */
327
+ * Walk the rank companion in declared sort order — sorted pagination
328
+ * accelerator. `options.where` may pin the partition; `cursor`/`take`
329
+ * follow the Convex-style keyset shape.
330
+ */
331
331
  rankPage: (indexName: RANK[T], options?: TableRankPageOptions<DM[T]>) => Promise<RankPage<DM[T]>>;
332
332
  /**
333
- * Restrict the query to a declared `.searchIndex()` and run a full-text
334
- * match. `indexName` is constrained to this table's search indexes
335
- * (`never` when it declares none). Returns a relevance-ordered reader —
336
- * finish with `.take(n)` / `.collect()`.
337
- */
333
+ * Restrict the query to a declared `.searchIndex()` and run a full-text
334
+ * match. `indexName` is constrained to this table's search indexes
335
+ * (`never` when it declares none). Returns a relevance-ordered reader —
336
+ * finish with `.take(n)` / `.collect()`.
337
+ */
338
338
  withSearchIndex: (indexName: SEARCH[T], search: (q: SearchFilterBuilder<DM[T]>) => SearchFilterBuilder<DM[T]>) => SearchReader<DM[T]>;
339
339
  }
340
340
  /** Read-write typed table accessor exposed on `MutationCtx.db.&lt;table>` / `ActionCtx.db.&lt;table>`. */
341
341
  interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>, T extends keyof DM> extends TableReaderFacade<DM, REL, RANK, SEARCH, T> {
342
342
  /**
343
- * Delete a row by id. On a `.softDelete()` table this flips the marker column
344
- * (and cascades as a soft delete) instead of removing the row; use
345
- * {@link TableWriterFacade.hardDelete} to force physical removal.
346
- */
343
+ * Delete a row by id. On a `.softDelete()` table this flips the marker column
344
+ * (and cascades as a soft delete) instead of removing the row; use
345
+ * {@link TableWriterFacade.hardDelete} to force physical removal.
346
+ */
347
347
  delete: (id: Id<string & T>) => Promise<void>;
348
348
  /**
349
- * Delete many rows in this table. Pass an array of ids (requested count is
350
- * returned; unknown ids are no-ops) or `{ where }` to delete matching rows
351
- * (actual removed count is returned). Atomic within a mutation.
352
- */
349
+ * Delete many rows in this table. Pass an array of ids (requested count is
350
+ * returned; unknown ids are no-ops) or `{ where }` to delete matching rows
351
+ * (actual removed count is returned). Atomic within a mutation.
352
+ */
353
353
  deleteMany: {
354
354
  (ids: ReadonlyArray<Id<string & T>>, options?: {
355
355
  limit?: number;
@@ -366,10 +366,10 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
366
366
  /** Physically remove a row (and physically cascade `onDelete`), bypassing `.softDelete()`. Same as `delete()` on a non-soft table. */
367
367
  hardDelete: (id: Id<string & T>) => Promise<void>;
368
368
  /**
369
- * Insert a document, returning its minted id. With `{ skipDuplicates: true }`
370
- * a UNIQUE-constraint breach resolves to `null` (the row already exists)
371
- * instead of throwing — the return type widens to `Id | null` on that overload.
372
- */
369
+ * Insert a document, returning its minted id. With `{ skipDuplicates: true }`
370
+ * a UNIQUE-constraint breach resolves to `null` (the row already exists)
371
+ * instead of throwing — the return type widens to `Id | null` on that overload.
372
+ */
373
373
  insert: {
374
374
  (values: IM[T], options: {
375
375
  skipDuplicates: true;
@@ -379,10 +379,10 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
379
379
  }): Promise<Id<string & T>>;
380
380
  };
381
381
  /**
382
- * Insert many documents into this table in one call, returning the minted ids
383
- * in input order. With `{ skipDuplicates: true }`, UNIQUE breaches resolve to
384
- * `null` for that row instead of failing the batch. Atomic within a mutation.
385
- */
382
+ * Insert many documents into this table in one call, returning the minted ids
383
+ * in input order. With `{ skipDuplicates: true }`, UNIQUE breaches resolve to
384
+ * `null` for that row instead of failing the batch. Atomic within a mutation.
385
+ */
386
386
  insertMany: {
387
387
  (values: ReadonlyArray<IM[T]>, options: {
388
388
  limit?: number;
@@ -395,10 +395,10 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
395
395
  };
396
396
  patch: (id: Id<string & T>, values: Partial<IM[T]>) => Promise<void>;
397
397
  /**
398
- * Patch many rows in this table. Pass an array of `{ id, values }` or
399
- * `{ where, values }` to patch matching rows with the same values. Returns
400
- * the actual patched count. Atomic within a mutation.
401
- */
398
+ * Patch many rows in this table. Pass an array of `{ id, values }` or
399
+ * `{ where, values }` to patch matching rows with the same values. Returns
400
+ * the actual patched count. Atomic within a mutation.
401
+ */
402
402
  patchMany: {
403
403
  (patches: ReadonlyArray<{
404
404
  id: Id<string & T>;
@@ -420,11 +420,11 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
420
420
  /** Un-soft-delete a row by id: clears the `.softDelete()` marker so list reads see it again. Throws on a non-soft table. */
421
421
  restore: (id: Id<string & T>) => Promise<void>;
422
422
  /**
423
- * Insert when no existing row matches `target`, otherwise patch the match with
424
- * `update` (defaulting to `create`). `target` names a `.unique()` column (or a
425
- * tuple) used to look it up. Returns the row id and whether it was `created`.
426
- * Composes `findFirst` + `insert`/`patch`, so RLS gates each step.
427
- */
423
+ * Insert when no existing row matches `target`, otherwise patch the match with
424
+ * `update` (defaulting to `create`). `target` names a `.unique()` column (or a
425
+ * tuple) used to look it up. Returns the row id and whether it was `created`.
426
+ * Composes `findFirst` + `insert`/`patch`, so RLS gates each step.
427
+ */
428
428
  upsert: (args: {
429
429
  create: IM[T];
430
430
  target: UpsertTargetOf<DM, T>;
@@ -448,7 +448,7 @@ interface TableWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends
448
448
  /** Conflict target for `upsert`/`upsertMany`: one column of table `T`, or a tuple of them. */
449
449
  type UpsertTargetOf<DM, T extends keyof DM> = ReadonlyArray<keyof DM[T] & string> | (keyof DM[T] & string);
450
450
  /** Per-table read facade — `ctx.db.&lt;table>` on a `QueryCtx`. */
451
- type DatabaseReaderFacade<DM, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>> = { readonly [T in keyof DM]: TableReaderFacade<DM, REL, RANK, SEARCH, T> };
451
+ type DatabaseReaderFacade<DM, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>> = { readonly [T in keyof DM]: TableReaderFacade<DM, REL, RANK, SEARCH, T>; };
452
452
  /** Per-table read-write facade — `ctx.db.&lt;table>` on a `MutationCtx` / `ActionCtx`. */
453
- type DatabaseWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>> = { readonly [T in keyof DM]: TableWriterFacade<DM, IM, REL, RANK, SEARCH, T> };
453
+ type DatabaseWriterFacade<DM, IM extends Record<keyof DM, object>, REL extends Record<keyof DM, object>, RANK extends Record<keyof DM, string>, SEARCH extends Record<keyof DM, string>> = { readonly [T in keyof DM]: TableWriterFacade<DM, IM, REL, RANK, SEARCH, T>; };
454
454
  export { AggregateOp, DatabaseReaderFacade, DatabaseWriterFacade, GroupByEntry, Id, LoadWith, ManyRelationWhere, OneRelationWhere, OrderBy, QueryArgs, QueryArgsOf, QueryPage, RankPage, RankResult, RestrictableQueryOptions, RestrictableQueryOptionsOf, SearchFilterBuilder, SearchReader, TableAggregateOptions, TableAggregateOptionsOf, TableGroupByOptions, TableGroupByOptionsOf, TableRankOptions, TableRankPageOptions, TableReaderFacade, TableWriterFacade, UpsertTargetOf, Where, WhereOf, WhereOperators, WithArg };