@fabrika/db 0.9.0-dev.4 → 0.9.0-dev.41

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 (84) hide show
  1. package/package.json +39 -4
  2. package/src/admissions.ts +78 -12
  3. package/src/application-rows.ts +108 -0
  4. package/src/authority.ts +560 -0
  5. package/src/builtins.ts +21 -0
  6. package/src/capability.ts +56 -2
  7. package/src/codegen-sqlite.ts +194 -0
  8. package/src/codegen.ts +230 -41
  9. package/src/condition-nodes.ts +119 -0
  10. package/src/conditions.ts +683 -0
  11. package/src/database.ts +227 -61
  12. package/src/description.ts +37 -8
  13. package/src/errors.ts +10 -6
  14. package/src/file-columns.ts +56 -11
  15. package/src/framework-tables.ts +28 -8
  16. package/src/framework.ts +15 -5
  17. package/src/guard.ts +373 -15
  18. package/src/index.ts +17 -1
  19. package/src/job-leases.ts +228 -55
  20. package/src/job-wakes.ts +600 -0
  21. package/src/json.ts +124 -0
  22. package/src/links.ts +8 -1
  23. package/src/list-cursor.ts +82 -0
  24. package/src/migrations-sqlite.ts +210 -0
  25. package/src/migrations.ts +73 -0
  26. package/src/nodes.ts +84 -14
  27. package/src/orm-types.ts +206 -71
  28. package/src/orm.ts +425 -170
  29. package/src/policy.ts +1979 -141
  30. package/src/postgres.ts +26 -0
  31. package/src/registry.ts +55 -3
  32. package/src/request-receipts.ts +107 -0
  33. package/src/sql.ts +247 -476
  34. package/src/sqlite-bun.ts +149 -0
  35. package/src/sqlite-migrate.ts +242 -0
  36. package/src/sqlite.ts +269 -0
  37. package/src/store.ts +2292 -239
  38. package/src/stored-files.ts +188 -52
  39. package/src/tables.ts +172 -6
  40. package/src/temporal.ts +122 -9
  41. package/src/testing-shared.ts +1351 -0
  42. package/src/testing-sqlite.ts +685 -0
  43. package/src/testing.ts +310 -494
  44. package/src/vocabulary-tables.ts +159 -27
  45. package/types/src/application-rows.d.ts +58 -0
  46. package/types/src/authority.d.ts +147 -0
  47. package/types/src/builtins.d.ts +2 -0
  48. package/types/src/capability.d.ts +55 -2
  49. package/types/src/codegen-sqlite.d.ts +13 -0
  50. package/types/src/codegen.d.ts +79 -5
  51. package/types/src/condition-nodes.d.ts +9 -0
  52. package/types/src/conditions.d.ts +151 -0
  53. package/types/src/database.d.ts +81 -20
  54. package/types/src/description.d.ts +26 -8
  55. package/types/src/errors.d.ts +9 -6
  56. package/types/src/file-columns.d.ts +6 -4
  57. package/types/src/framework.d.ts +12 -5
  58. package/types/src/guard.d.ts +24 -0
  59. package/types/src/index.d.ts +5 -4
  60. package/types/src/job-leases.d.ts +40 -5
  61. package/types/src/job-wakes.d.ts +124 -0
  62. package/types/src/json.d.ts +18 -0
  63. package/types/src/list-cursor.d.ts +13 -0
  64. package/types/src/migrations-sqlite.d.ts +4 -0
  65. package/types/src/migrations.d.ts +4 -0
  66. package/types/src/nodes.d.ts +17 -2
  67. package/types/src/orm-types.d.ts +163 -71
  68. package/types/src/orm.d.ts +21 -0
  69. package/types/src/policy.d.ts +351 -23
  70. package/types/src/postgres.d.ts +12 -0
  71. package/types/src/registry.d.ts +40 -3
  72. package/types/src/request-receipts.d.ts +22 -0
  73. package/types/src/sql.d.ts +29 -21
  74. package/types/src/sqlite-bun.d.ts +21 -0
  75. package/types/src/sqlite-migrate.d.ts +28 -0
  76. package/types/src/sqlite.d.ts +24 -0
  77. package/types/src/store.d.ts +143 -34
  78. package/types/src/stored-files.d.ts +6 -2
  79. package/types/src/tables.d.ts +18 -2
  80. package/types/src/temporal.d.ts +24 -0
  81. package/types/src/testing-shared.d.ts +290 -0
  82. package/types/src/testing-sqlite.d.ts +37 -0
  83. package/types/src/testing.d.ts +2 -93
  84. package/types/src/vocabulary-tables.d.ts +169 -22
@@ -1,8 +1,8 @@
1
1
  import type { Selectable, Updateable } from 'kysely';
2
2
  import type { RowRef } from './capability';
3
- import type { ConditionTuple } from './description';
3
+ import type { ComparableColumn, ConditionTuple } from './description';
4
4
  import type { FileReference } from './file-references';
5
- import type { ActionOf, ApplicationTableName, ChildTableName, ContainerOf, DimensionOf, DimensionTableName, InsertValues, ListDimensionOf, ParentOf, Tables, UpdateValues } from './policy';
5
+ import type { ActionOf, ApplicationTableName, ChildTableName, ContainerOf, DimensionOf, DimensionTableName, InsertValues, ListDimensionOf, ParentOf, ReadsAny, Tables, UpdateValues } from './policy';
6
6
  import type { AggregateRow, AggregateSpec } from './store';
7
7
  import type { VocabularyContainerOf } from './vocabulary-tables';
8
8
  /** A member an endpoint may not use. It has no call signature, so a call fails at its line with this message. */
@@ -32,28 +32,34 @@ type AppActionsOf<P, T, F extends 'appRead' | 'appCount'> = PolicyOf<P, T> exten
32
32
  readonly [K in F]: readonly (infer A extends string)[];
33
33
  };
34
34
  } ? A : never;
35
- /** Each column that declares its own read action, by column. */
35
+ /** Each column that declares its own read actions, by column: the union of the actions it lists. */
36
36
  type ColumnReadsOf<P, T> = PolicyOf<P, T> extends {
37
37
  readonly columns: infer C;
38
38
  } ? {
39
39
  readonly [K in keyof C as C[K] extends {
40
- readonly read: string;
40
+ readonly read: string | readonly string[];
41
41
  } ? K : never]: C[K] extends {
42
- readonly read: infer A extends string;
43
- } ? A : never;
42
+ readonly read: infer A extends string | readonly string[];
43
+ } ? A extends readonly (infer L extends string)[] ? L : A : never;
44
44
  } : Record<never, never>;
45
+ /** The actions the table's `when` narrows; every action of a policy typed wider than its literal, which may hold one. */
46
+ type ConditionedOf<P, T> = PolicyOf<P, T> extends {
47
+ readonly when?: infer W;
48
+ } ? keyof NonNullable<W> & string : never;
45
49
  type ColumnPoliciesOf<P, T> = PolicyOf<P, T> extends {
46
50
  readonly columns: infer C;
47
51
  } ? C : never;
48
- /** The columns that declare `A` as their own write action. */
52
+ /** The actions a column's own `write` names: one action, or each of a list. */
53
+ type WriteActionsOf<P> = P extends {
54
+ readonly write: infer W;
55
+ } ? W extends readonly (infer L extends string)[] ? L : W extends string ? W : never : never;
56
+ /** The columns that list `A` among their own write actions. */
49
57
  type ColumnsWrittenBy<C, A> = {
50
- [K in keyof C]: C[K] extends {
51
- readonly write: A;
52
- } ? K : never;
58
+ [K in keyof C]: [A] extends [WriteActionsOf<C[K]>] ? K : never;
53
59
  }[keyof C];
54
60
  /**
55
61
  * Each action that updates the table, with the values a capability of it updates: the update action its update list,
56
- * a column's own write action the columns that declare it, and no other.
62
+ * a column's own write action the columns that list it (an update action both), and no other.
57
63
  */
58
64
  type UpdatesOf<DB, P, T extends keyof DB> = {
59
65
  readonly [A in ActionOf<P, T, 'update'>]: UpdateValues<DB, P, T>;
@@ -61,9 +67,7 @@ type UpdatesOf<DB, P, T extends keyof DB> = {
61
67
  readonly [A in ColumnWriteAction<ColumnPoliciesOf<P, T>>]: Flat<Pick<Updateable<DB[T]>, ColumnsWrittenBy<ColumnPoliciesOf<P, T>, A> & keyof Updateable<DB[T]>>>;
62
68
  };
63
69
  type ColumnWriteAction<C> = {
64
- [K in keyof C]: C[K] extends {
65
- readonly write: infer A extends string;
66
- } ? A : never;
70
+ [K in keyof C]: WriteActionsOf<C[K]>;
67
71
  }[keyof C];
68
72
  /** One table, as every handle reads it. */
69
73
  export interface IndexedTable {
@@ -74,12 +78,15 @@ export interface IndexedTable {
74
78
  readonly list: string;
75
79
  /** A child table's parent table. */
76
80
  readonly parent: string;
81
+ /** `read` is `never` for a table read with `'any'` (`readsAny`). */
77
82
  readonly actions: {
78
83
  readonly read: string;
79
84
  readonly insert: string;
80
85
  readonly update: string;
81
86
  readonly delete: string;
82
87
  };
88
+ /** An application table read with `'any'`: every `app` endpoint, job and webhook reads it, no public procedure or scoped site. */
89
+ readonly readsAny: boolean;
83
90
  /** The actions besides `read` with which an `app` endpoint lists every row (`actions.appRead`). */
84
91
  readonly appRead: string;
85
92
  /** The actions with which an `app` endpoint only counts every row (`actions.appCount`). */
@@ -88,6 +95,8 @@ export interface IndexedTable {
88
95
  readonly row: object;
89
96
  /** The columns that declare their own read action. */
90
97
  readonly reads: object;
98
+ /** The actions whose `when` narrows the rows they reach. */
99
+ readonly conditioned: string;
91
100
  readonly insert: object;
92
101
  readonly update: object;
93
102
  /** Each action that updates the table, with the values it updates (`columns: { assignee: { write: 'tasks.assign' } }`). */
@@ -101,6 +110,8 @@ export interface IndexedTable {
101
110
  readonly versioned: boolean;
102
111
  /** A queue table: its rows are claimed and finished through `row.ref`. */
103
112
  readonly queued: boolean;
113
+ /** A view: read like its scope's tables, written by no site (ADR-0072). */
114
+ readonly view: boolean;
104
115
  }
105
116
  type IndexedTableOf<DB, P, T extends keyof P & keyof DB & string, V = unknown> = {
106
117
  readonly mode: ModeOf<P, T>;
@@ -113,10 +124,12 @@ type IndexedTableOf<DB, P, T extends keyof P & keyof DB & string, V = unknown> =
113
124
  readonly update: ActionOf<P, T, 'update'>;
114
125
  readonly delete: ActionOf<P, T, 'delete'>;
115
126
  };
127
+ readonly readsAny: ReadsAny<P, T>;
116
128
  readonly appRead: AppActionsOf<P, T, 'appRead'>;
117
129
  readonly appCount: AppActionsOf<P, T, 'appCount'>;
118
130
  readonly row: WithFiles<RowType<DB[T]>, FileColumnsOf<P, T>>;
119
131
  readonly reads: ColumnReadsOf<P, T>;
132
+ readonly conditioned: ConditionedOf<P, T>;
120
133
  readonly insert: WithFiles<InsertValues<DB, P, T>, FileColumnsOf<P, T>>;
121
134
  readonly update: WithFiles<UpdateValues<DB, P, T>, FileColumnsOf<P, T>>;
122
135
  readonly writes: {
@@ -131,6 +144,9 @@ type IndexedTableOf<DB, P, T extends keyof P & keyof DB & string, V = unknown> =
131
144
  readonly queued: PolicyOf<P, T> extends {
132
145
  readonly queue: object;
133
146
  } ? true : false;
147
+ readonly view: PolicyOf<P, T> extends {
148
+ readonly view: true;
149
+ } ? true : false;
134
150
  };
135
151
  type OwnerTable<P, D> = {
136
152
  [K in keyof P]: P[K] extends {
@@ -168,6 +184,18 @@ type ChainDimensions<P, T, V> = PolicyOf<P, T> extends {
168
184
  } ? DimensionOf<P, Parent> | ChainDimensions<P, Parent, V> : never : never;
169
185
  /** The dimensions whose `Within` lists table `T`: every dimension of its chain, and a top-level table's own. */
170
186
  type ReachOf<P, T, V> = [ContainerOf<P, T>] extends [never] ? DimensionOf<P, T> | ChainDimensions<P, T, V> : ChainDimensions<P, T, V>;
187
+ /**
188
+ * The dimensions outside its chain whose `Within` reads table `T` through a foreign key (`readThrough`); a child view's
189
+ * are its parent's, as it is read through its parent row.
190
+ */
191
+ type ReadThroughOf<P, T> = PolicyOf<P, T> extends {
192
+ readonly readThrough: infer R;
193
+ } ? keyof R & string : PolicyOf<P, T> extends {
194
+ readonly view: true;
195
+ readonly scope: {
196
+ readonly child: infer Parent extends string;
197
+ };
198
+ } ? ReadThroughOf<P, Parent> : never;
171
199
  /**
172
200
  * A row as reads return it: the generated interface itself where no column has a separate write type, so a
173
201
  * diagnostic names it (`DealsTable`), and Kysely's `Selectable` of it otherwise.
@@ -209,9 +237,12 @@ export type DbIndex<DB, P, V = unknown> = {
209
237
  readonly listed: {
210
238
  readonly [T in DimensionTableName<P> as ListDimensionOf<P, T>]: T;
211
239
  };
212
- /** Dimension → the tables an `over` of it lists: each whose containment chain holds it, and a top-level table its own. */
240
+ /**
241
+ * Dimension → the tables an `over` of it lists: each whose containment chain holds it, a top-level table its own, and
242
+ * each that reads through it (`readThrough`).
243
+ */
213
244
  readonly within: {
214
- readonly [T in DimensionTableName<P> | ChildTableName<P> as ReachOf<P, T, V>]: T;
245
+ readonly [T in DimensionTableName<P> | ChildTableName<P> as ReachOf<P, T, V> | ReadThroughOf<P, T>]: T;
215
246
  };
216
247
  readonly references: ReferenceTableName<P>;
217
248
  /** The application tables: an `app` endpoint reads and writes them. */
@@ -239,18 +270,22 @@ type ChildrenOf<Ix extends AnyDbIndex, T> = Lookup<Ix['children'], T>;
239
270
  type ListedIn<Ix extends AnyDbIndex, D> = Lookup<Ix['listed'], D>;
240
271
  type WithinIn<Ix extends AnyDbIndex, D> = Lookup<Ix['within'], D>;
241
272
  /**
242
- * The columns a capability of action `A` cannot read: each that declares a read action other than exactly `A`. A
243
- * union `A` (a widened capability type) holds no single action provably, so it reads none of them.
273
+ * The columns a capability of `A` cannot read: each whose own read actions do not include every action of `A`. A union
274
+ * `A` (an `anyOf` endpoint's, or a widened capability type) reads one only where no action of it is `Conditioned`: the
275
+ * runtime answers it where every reaching action reads every row alone (`readsAsAction`), and the held ones are known
276
+ * only per request.
244
277
  */
245
- type HiddenFor<Reads, A> = {
246
- [C in keyof Reads]: [A] extends [Reads[C]] ? ([Reads[C]] extends [A] ? never : C) : C;
278
+ type HiddenFor<Reads, A, Conditioned> = {
279
+ [C in keyof Reads]: [A] extends [never] ? C : [A] extends [Reads[C]] ? (IsSingle<A> extends true ? never : [Extract<A, Conditioned>] extends [never] ? never : C) : C;
247
280
  }[keyof Reads];
281
+ /** Whether `A` is one literal, not a union of several. */
282
+ type IsSingle<A, All = A> = [A] extends [never] ? false : A extends unknown ? ([All] extends [A] ? true : false) : never;
248
283
  /**
249
- * A row as a capability of action `A` reads, filters and sorts it: a column that declares another read action is
250
- * absent. The type keeps the generated row's name, so a read of a hidden column reports
251
- * `Property 'margin' does not exist on type 'Omit<Selectable<DealsTable>, "margin">'`.
284
+ * A row as a capability of `A` reads, filters and sorts it: a column whose own read actions leave out an action of `A`
285
+ * is absent, and so is one a union `A` with a `when` may not read (`HiddenFor`). The type keeps the generated row's
286
+ * name, so a read of a hidden column reports `Property 'margin' does not exist on type 'Omit<Selectable<DealsTable>, "margin">'`.
252
287
  */
253
- export type RowFor<E extends IndexedTable, A extends string> = [HiddenFor<E['reads'], A>] extends [never] ? E['row'] : Omit<E['row'], HiddenFor<E['reads'], A>>;
288
+ export type RowFor<E extends IndexedTable, A extends string> = [HiddenFor<E['reads'], A, E['conditioned']>] extends [never] ? E['row'] : Omit<E['row'], HiddenFor<E['reads'], A, E['conditioned']>>;
254
289
  /** What a paved-road write answers: the key, and the new version of a versioned table. */
255
290
  export type Saved<E extends IndexedTable> = E['versioned'] extends true ? {
256
291
  readonly id: string;
@@ -269,7 +304,7 @@ type InsertValuesOf<E extends IndexedTable> = {
269
304
  /** `onConflict` of an insert: the columns of a unique index the migrations create, and what a conflict does. */
270
305
  export interface InsertConflict<E extends IndexedTable, M extends 'nothing' | 'update'> {
271
306
  readonly onConflict: {
272
- readonly columns: readonly (keyof E['row'] & string)[];
307
+ readonly columns: readonly ComparableColumn<E['row']>[];
273
308
  readonly do: M;
274
309
  };
275
310
  }
@@ -324,36 +359,64 @@ export interface ClaimedRowHandle<T extends string, E extends IndexedTable, A ex
324
359
  /** The actions table `E` names: its read, insert, update and delete actions, and each column's own write action. */
325
360
  type NamedActions<E extends IndexedTable> = (E['actions'][keyof E['actions']] | keyof E['writes']) & string;
326
361
  type Names<E extends IndexedTable, A extends string> = [A] extends [NamedActions<E>] ? true : false;
362
+ /**
363
+ * Whether an action of `A` is one of `Allowed`. An `app` capability of several actions, an `anyOf` endpoint's, allows
364
+ * what any of them allows, as one role holding them; the runtime refuses an operation none of the held ones allows.
365
+ */
366
+ type AnyAllowed<A extends string, Allowed> = [Extract<A, Allowed>] extends [never] ? false : true;
367
+ /** `U`'s members as one object: the columns any action of an `app` capability updates, with their values. */
368
+ type Merged<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
327
369
  type Operation = 'insert' | 'update' | 'delete';
328
- /** `Member` in a mutation whose action is the table's `Op` action; otherwise the message that says which fix applies. */
329
- type Write<T extends string, E extends IndexedTable, Op extends Operation, A extends string, K extends DataKind, Member> = K extends 'mutation' ? [A] extends [E['actions'][Op]] ? Member : Unavailable<`${Op} on ${T} needs the action '${E['actions'][Op] & string}', and this endpoint holds '${A}'`> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<`${Op extends 'delete' ? 'remove' : Op} writes, so it runs only in a mutation: declare the endpoint with r.mutation`>;
370
+ /**
371
+ * `Member` in a mutation whose action is the table's `Op` action (`Allowed`, any action of an `app` capability's);
372
+ * otherwise the message that says which fix applies.
373
+ */
374
+ type Write<T extends string, E extends IndexedTable, Op extends Operation, A extends string, K extends DataKind, Member, Allowed extends boolean = [A] extends [E['actions'][Op]] ? true : false> = K extends 'mutation' ? Allowed extends true ? Member : Unavailable<`${Op} on ${T} needs the action '${E['actions'][Op] & string}', and this endpoint holds '${A}'`> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<`${Op extends 'delete' ? 'remove' : Op} writes, so it runs only in a mutation: declare the endpoint with r.mutation`>;
330
375
  /** What an update of `T` needs, for a capability of `A` that updates nothing of it. */
331
376
  type UpdateRefusal<T extends string, E extends IndexedTable, A extends string> = [Exclude<keyof E['writes'], E['actions']['update']>] extends [never] ? `update on ${T} needs the action '${E['actions']['update'] & string}', and this endpoint holds '${A}'` : [E['actions']['update']] extends [never] ? `update on ${T} needs a column's own write action, and this endpoint holds '${A}'` : `update on ${T} needs the action '${E['actions']['update'] & string}' or a column's own write action, and this endpoint holds '${A}'`;
332
377
  /**
333
378
  * `Member` in a mutation whose action updates columns of the table (the update action, or a column's own write
334
- * action); otherwise the message that says which fix applies.
379
+ * action; `Allowed`, any action of an `app` capability's); otherwise the message that says which fix applies.
335
380
  */
336
- type Update<T extends string, E extends IndexedTable, A extends string, K extends DataKind, Member> = K extends 'mutation' ? [A] extends [keyof E['writes']] ? Member : Unavailable<UpdateRefusal<T, E, A>> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<'update writes, so it runs only in a mutation: declare the endpoint with r.mutation'>;
381
+ type Update<T extends string, E extends IndexedTable, A extends string, K extends DataKind, Member, Allowed extends boolean = [A] extends [keyof E['writes']] ? true : false> = K extends 'mutation' ? Allowed extends true ? Member : Unavailable<UpdateRefusal<T, E, A>> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<'update writes, so it runs only in a mutation: declare the endpoint with r.mutation'>;
337
382
  /** An update's values: any non-empty subset of the columns a capability of `A` updates; an empty one is refused. */
338
383
  type UpdateValuesOf<E extends IndexedTable, A extends string> = E['writes'][A & keyof E['writes']];
339
- type Read<T extends string, E extends IndexedTable, A extends string, Member> = Names<E, A> extends true ? Member : Unavailable<`${T} does not name the action '${A}': read it from an endpoint whose action ${T} names, or declare unscoped`>;
384
+ /** An `app` capability's update values: the columns any of its actions updates, one action's as `UpdateValuesOf`. */
385
+ type AppUpdateValuesOf<E extends IndexedTable, A extends string> = Merged<UpdateValuesOf<E, A>>;
386
+ type Read<T extends string, E extends IndexedTable, A extends string, Member, Allowed extends boolean = Names<E, A>> = Allowed extends true ? Member : Unavailable<`${T} does not name the action '${A}': read it from an endpoint whose action ${T} names, or declare unscoped`>;
340
387
  /** One page of a keyset list; `next` is the cursor `after` takes, `null` on the last page. */
341
388
  export interface ListPage<Row> {
342
389
  readonly items: Row[];
343
390
  readonly next: string | null;
344
391
  }
345
392
  export type OrderTerm<Row> = {
346
- [C in keyof Row & string]: readonly [C, 'asc' | 'desc'];
347
- }[keyof Row & string];
348
- export interface ListOptions<Row> {
349
- readonly where?: readonly ConditionTuple<Row>[];
350
- readonly orderBy?: readonly OrderTerm<Row>[];
393
+ [C in ComparableColumn<Row>]: readonly [C, 'asc' | 'desc'];
394
+ }[ComparableColumn<Row>];
395
+ /**
396
+ * What `list()` takes, by the conditions and order terms of its row. It is generic in those unions, not the row, so a
397
+ * handle that reads more columns, whose options take more, passes where one that reads fewer is expected.
398
+ */
399
+ export interface ListQuery<Condition, Order> {
400
+ readonly where?: readonly Condition[];
401
+ readonly orderBy?: readonly Order[];
351
402
  readonly limit?: number;
352
403
  readonly after?: string;
353
404
  }
354
- export interface CountOptions<Row> {
355
- readonly where?: readonly ConditionTuple<Row>[];
405
+ /** `ListQuery` over the columns of `Row`. */
406
+ export type ListOptions<Row> = ListQuery<ConditionTuple<Row>, OrderTerm<Row>>;
407
+ /** What `all()` takes: a list's filter and order, and no page; it answers every row or refuses past `MAX_ALL_ROWS`. */
408
+ export interface AllQuery<Condition, Order> {
409
+ readonly where?: readonly Condition[];
410
+ readonly orderBy?: readonly Order[];
356
411
  }
412
+ /** `AllQuery` over the columns of `Row`. */
413
+ export type AllOptions<Row> = AllQuery<ConditionTuple<Row>, OrderTerm<Row>>;
414
+ /** What `count()` takes: a list's filter. */
415
+ export interface CountQuery<Condition> {
416
+ readonly where?: readonly Condition[];
417
+ }
418
+ /** `CountQuery` over the columns of `Row`. */
419
+ export type CountOptions<Row> = CountQuery<ConditionTuple<Row>>;
357
420
  /** The target's own row: `ctx.db.target` (or `ctx.db.created`) of an `on`, `in` or `creates` endpoint. */
358
421
  export interface TargetRow<T extends string, E extends IndexedTable, A extends string, K extends DataKind, F extends TargetForm> {
359
422
  /** The row; a column that declares another read action than `A` is hidden. */
@@ -379,19 +442,21 @@ export interface UnownedTarget<D extends string> {
379
442
  readonly update: Unavailable<`no table owns the dimension ${D}, so ctx.db.target has no row of its own`>;
380
443
  readonly remove: Unavailable<`no table owns the dimension ${D}, so ctx.db.target has no row of its own`>;
381
444
  }
382
- /** A child table of the target: its rows are addressed by their own key under the target. */
445
+ /** A child table of the target: its rows are addressed by their own key under the target; a view's are only read. */
383
446
  export interface ChildRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
384
447
  readonly list: Read<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>;
448
+ readonly all: Read<T, E, A, (options?: AllOptions<RowFor<E, A>>) => Promise<RowFor<E, A>[]>>;
385
449
  readonly get: Read<T, E, A, (key: string) => Promise<RowFor<E, A>>>;
386
- readonly insert: Write<T, E, 'insert', A, K, InsertMethod<E>>;
387
- readonly update: Update<T, E, A, K, (key: string, values: {
450
+ readonly insert: E['view'] extends true ? Unavailable<`${T} is a view, which no site writes: write the tables it reads`> : Write<T, E, 'insert', A, K, InsertMethod<E>>;
451
+ readonly update: E['view'] extends true ? Unavailable<`${T} is a view, which no site writes: write the tables it reads`> : Update<T, E, A, K, (key: string, values: {
388
452
  [C in keyof UpdateValuesOf<E, A>]: UpdateValuesOf<E, A>[C];
389
453
  }, ...version: VersionArguments<E>) => Promise<Saved<E>>>;
390
- readonly remove: Write<T, E, 'delete', A, K, (key: string, ...version: VersionArguments<E>) => Promise<void>>;
454
+ readonly remove: E['view'] extends true ? Unavailable<`${T} is a view, which no site writes: write the tables it reads`> : Write<T, E, 'delete', A, K, (key: string, ...version: VersionArguments<E>) => Promise<void>>;
391
455
  }
392
456
  /** A dimension table the target contains: listed in it, and inserted into it by a mutation of its insert action. */
393
457
  export interface ContainedRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
394
458
  readonly list: Read<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>;
459
+ readonly all: Read<T, E, A, (options?: AllOptions<RowFor<E, A>>) => Promise<RowFor<E, A>[]>>;
395
460
  readonly insert: Write<T, E, 'insert', A, K, InsertMethod<E>>;
396
461
  }
397
462
  type SubtreeTables<Ix extends AnyDbIndex, D extends string, A extends string, K extends DataKind, F extends TargetForm> = {
@@ -409,10 +474,17 @@ export type ScopeTarget<Ix extends AnyDbIndex, D extends string, A extends strin
409
474
  /** A table listed in an `over` endpoint's dimension, read through its `Within`; a job claims a queue table's rows through it. */
410
475
  export interface WithinRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
411
476
  readonly claim: Claim<T, E, A, K>;
412
- readonly list: A extends E['actions']['read'] ? (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>> : Unavailable<ListRefusal<T, E, A>>;
413
- readonly count: A extends E['actions']['read'] ? (options?: CountOptions<RowFor<E, A>>) => Promise<number> : Unavailable<ListRefusal<T, E, A>>;
414
- readonly aggregate: A extends E['actions']['read'] ? <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]> : Unavailable<ListRefusal<T, E, A>>;
477
+ readonly list: WithinRead<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>;
478
+ readonly all: WithinRead<T, E, A, (options?: AllOptions<RowFor<E, A>>) => Promise<RowFor<E, A>[]>>;
479
+ readonly count: WithinRead<T, E, A, (options?: CountOptions<RowFor<E, A>>) => Promise<number>>;
480
+ readonly aggregate: WithinRead<T, E, A, <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>>;
415
481
  }
482
+ /**
483
+ * `Member` where a `Within` of `A` lists the table by its read action. An alias, not inline in `WithinRows`: inline, a
484
+ * `Pick` of a handle that reads more columns is refused where one of fewer is expected. A `Within` typed for a union of
485
+ * actions reads its row by the union rule (`HiddenFor`), stricter than the one action it holds at run time.
486
+ */
487
+ type WithinRead<T extends string, E extends IndexedTable, A extends string, Member> = A extends E['actions']['read'] ? Member : Unavailable<ListRefusal<T, E, A>>;
416
488
  /** Inlined where used: an alias of its own would be printed by name, with the table's index entry spelled out. */
417
489
  type ListRefusal<T extends string, E extends IndexedTable, A extends string> = `a list of ${T} needs its read action '${E['actions']['read'] & string}', and this endpoint holds '${A}'`;
418
490
  /**
@@ -422,22 +494,37 @@ type ListRefusal<T extends string, E extends IndexedTable, A extends string> = `
422
494
  export type WithinTables<Ix extends AnyDbIndex, D extends string, A extends string, K extends DataKind> = {
423
495
  readonly [T in WithinIn<Ix, D>]: WithinRows<T, Ix['tables'][T], A, K>;
424
496
  };
425
- /** An application table under the capability of an `app` endpoint of action `A`, in a site of kind `K`. */
497
+ /**
498
+ * `Member` where `ctx.db.app` of action `A` lists the application table: by its read action, or any action for `'any'`;
499
+ * an action of `A`'s does for an `anyOf` endpoint.
500
+ */
501
+ type AppList<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Member : AnyAllowed<A, E['actions']['read']> extends true ? Member : Unavailable<ListRefusal<T, E, A>>;
502
+ /** `Member` where `ctx.db.app` of action `A` (any of them) reads a row of the application table by its key. */
503
+ type AppGet<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Member : Read<T, E, A, Member, AnyAllowed<A, NamedActions<E>>>;
504
+ /** `Member` where a public procedure of action `A` reads the application table: under its read action, never `'any'`. */
505
+ type PublicRead<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Unavailable<`a public procedure does not read ${T}: it is read with 'any', which an app endpoint, a job and a webhook hold`> : A extends E['actions']['read'] ? Member : Unavailable<ListRefusal<T, E, A>>;
506
+ /**
507
+ * An application table under the capability of an `app` endpoint of action `A`, in a site of kind `K`; an `anyOf`
508
+ * endpoint's `A` is its listed actions, and an operation any of them allows is typed. A column with its own read actions
509
+ * shows only where every listed action is one of them and none has a `when` (`RowFor`): which listed actions the
510
+ * caller holds is known only at run time.
511
+ */
426
512
  export interface ApplicationRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
427
- readonly list: A extends E['actions']['read'] ? (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>> : Unavailable<ListRefusal<T, E, A>>;
428
- readonly count: A extends E['actions']['read'] ? (options?: CountOptions<RowFor<E, A>>) => Promise<number> : Unavailable<ListRefusal<T, E, A>>;
429
- readonly aggregate: A extends E['actions']['read'] ? <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]> : Unavailable<ListRefusal<T, E, A>>;
513
+ readonly list: AppList<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>;
514
+ readonly all: AppList<T, E, A, (options?: AllOptions<RowFor<E, A>>) => Promise<RowFor<E, A>[]>>;
515
+ readonly count: AppList<T, E, A, (options?: CountOptions<RowFor<E, A>>) => Promise<number>>;
516
+ readonly aggregate: AppList<T, E, A, <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>>;
430
517
  /** One row by its key; a column that declares another read action than `A` is hidden. */
431
- readonly get: Read<T, E, A, (key: string) => Promise<RowFor<E, A>>>;
518
+ readonly get: AppGet<T, E, A, (key: string) => Promise<RowFor<E, A>>>;
432
519
  /** `SELECT … FOR UPDATE` of one row by its key: a precondition read that no concurrent write overtakes. */
433
- readonly getForUpdate: K extends 'mutation' ? Read<T, E, A, (key: string) => Promise<RowFor<E, A>>> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<'getForUpdate locks the row, so it runs only in a mutation: declare the endpoint with r.mutation'>;
520
+ readonly getForUpdate: K extends 'mutation' ? AppGet<T, E, A, (key: string) => Promise<RowFor<E, A>>> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<'getForUpdate locks the row, so it runs only in a mutation: declare the endpoint with r.mutation'>;
434
521
  /** Leases due rows of a queue table: a job's drain, before its transactions. */
435
522
  readonly claim: Claim<T, E, A, K>;
436
- readonly insert: Write<T, E, 'insert', A, K, InsertMethod<E>>;
523
+ readonly insert: Write<T, E, 'insert', A, K, InsertMethod<E>, AnyAllowed<A, E['actions']['insert']>>;
437
524
  readonly update: Update<T, E, A, K, (key: string, values: {
438
- [C in keyof UpdateValuesOf<E, A>]: UpdateValuesOf<E, A>[C];
439
- }, ...version: VersionArguments<E>) => Promise<Saved<E>>>;
440
- readonly remove: Write<T, E, 'delete', A, K, (key: string, ...version: VersionArguments<E>) => Promise<void>>;
525
+ [C in keyof AppUpdateValuesOf<E, A>]: AppUpdateValuesOf<E, A>[C];
526
+ }, ...version: VersionArguments<E>) => Promise<Saved<E>>, AnyAllowed<A, keyof E['writes']>>;
527
+ readonly remove: Write<T, E, 'delete', A, K, (key: string, ...version: VersionArguments<E>) => Promise<void>, AnyAllowed<A, E['actions']['delete']>>;
441
528
  }
442
529
  /**
443
530
  * A public procedure's insert: it answers the new row's key (and version), which the data layer generated, and reads
@@ -453,17 +540,18 @@ export interface PublicInsertMethod<E extends IndexedTable> {
453
540
  }
454
541
  type PublicRefusal<Op extends string> = Unavailable<`a public procedure does not ${Op} a row: it inserts, and reads under the table's read action`>;
455
542
  /** A public procedure updates and removes only a versioned row, by an id a verified signed token of its request carries. */
456
- type PublicVersioned<T extends string, E extends IndexedTable, Member> = E['versioned'] extends true ? Member : Unavailable<`a public procedure updates and removes only a versioned row: declare version in the policy of ${T}`>;
543
+ type PublicVersioned<T extends string, E extends IndexedTable, Member> = E['versioned'] extends true ? Member : Unavailable<`a public procedure updates and removes only a versioned row: give ${T} a version column`>;
457
544
  /**
458
545
  * An application table of a public procedure of action `A`, in a site of kind `K`: read under its read action only,
459
546
  * inserted with nothing read back, and updated or removed only by the id a verified signed token of the request carries,
460
547
  * under `expectVersion`; never locked or claimed.
461
548
  */
462
549
  export interface PublicApplicationRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
463
- readonly list: ApplicationRows<T, E, A, K>['list'];
464
- readonly count: ApplicationRows<T, E, A, K>['count'];
465
- readonly aggregate: ApplicationRows<T, E, A, K>['aggregate'];
466
- readonly get: A extends E['actions']['read'] ? (key: string) => Promise<RowFor<E, A>> : Unavailable<ListRefusal<T, E, A>>;
550
+ readonly list: PublicRead<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>;
551
+ readonly all: Unavailable<'a public procedure pages its reads: read the table with list'>;
552
+ readonly count: PublicRead<T, E, A, (options?: CountOptions<RowFor<E, A>>) => Promise<number>>;
553
+ readonly aggregate: PublicRead<T, E, A, <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>>;
554
+ readonly get: PublicRead<T, E, A, (key: string) => Promise<RowFor<E, A>>>;
467
555
  readonly getForUpdate: PublicRefusal<'lock'>;
468
556
  readonly claim: PublicRefusal<'claim'>;
469
557
  /** By the id a verified signed token of the request carries; answers only the new version. */
@@ -489,9 +577,10 @@ export type PublicApplicationTables<Ix extends AnyDbIndex, A extends string, K e
489
577
  * (`RowFor`), or only how many rows match. A count-only action has no `aggregate`: a group or a minimum is a value.
490
578
  */
491
579
  export interface AppRecordRows<T extends string, E extends IndexedTable, A extends string> {
492
- readonly list: [A] extends [E['actions']['read'] | E['appRead']] ? (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>> : Unavailable<`a list of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead, and this endpoint holds '${A}'`>;
493
- readonly count: [A] extends [E['actions']['read'] | E['appRead'] | E['appCount']] ? (options?: CountOptions<RowFor<E, A>>) => Promise<number> : Unavailable<`a count of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead or appCount, and this endpoint holds '${A}'`>;
494
- readonly aggregate: [A] extends [E['actions']['read'] | E['appRead']] ? <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]> : Unavailable<`an aggregate of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead, and this endpoint holds '${A}': an appCount action only counts`>;
580
+ readonly list: AnyAllowed<A, E['actions']['read'] | E['appRead']> extends true ? (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>> : Unavailable<`a list of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead, and this endpoint holds '${A}'`>;
581
+ readonly all: AnyAllowed<A, E['actions']['read'] | E['appRead']> extends true ? (options?: AllOptions<RowFor<E, A>>) => Promise<RowFor<E, A>[]> : Unavailable<`a list of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead, and this endpoint holds '${A}'`>;
582
+ readonly count: AnyAllowed<A, E['actions']['read'] | E['appRead'] | E['appCount']> extends true ? (options?: CountOptions<RowFor<E, A>>) => Promise<number> : Unavailable<`a count of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead or appCount, and this endpoint holds '${A}'`>;
583
+ readonly aggregate: AnyAllowed<A, E['actions']['read'] | E['appRead']> extends true ? <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]> : Unavailable<`an aggregate of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead, and this endpoint holds '${A}': an appCount action only counts`>;
495
584
  }
496
585
  /**
497
586
  * `ctx.db.app` of an `app` endpoint: every application table, and every dimension and child table read-only, all
@@ -511,6 +600,7 @@ type TableRow<E extends IndexedTable> = RowFor<E, E['actions']['read']>;
511
600
  */
512
601
  export interface ScopedApplicationRows<E extends IndexedTable> {
513
602
  list(options?: ListOptions<TableRow<E>>): Promise<ListPage<TableRow<E>>>;
603
+ all(options?: AllOptions<TableRow<E>>): Promise<TableRow<E>[]>;
514
604
  count(options?: CountOptions<TableRow<E>>): Promise<number>;
515
605
  aggregate<const S extends AggregateSpec<TableRow<E>>>(spec: S): Promise<AggregateRow<TableRow<E>, S>[]>;
516
606
  /** One row by its key. */
@@ -525,11 +615,12 @@ export interface ScopedApplicationRows<E extends IndexedTable> {
525
615
  * read-only; any other is the message that names its read action.
526
616
  */
527
617
  export type ScopedApplicationTables<Ix extends AnyDbIndex, A extends string> = {
528
- readonly [T in Ix['applications']]: [A] extends [Ix['tables'][T]['actions']['read']] ? ScopedApplicationRows<Ix['tables'][T]> : Unavailable<`a scoped endpoint reads ${T} with its read action '${Ix['tables'][T]['actions']['read'] & string}', and this endpoint holds '${A}'`>;
618
+ readonly [T in Ix['applications']]: [Ix['tables'][T]['readsAny']] extends [true] ? Unavailable<`a scoped endpoint does not read ${T}: it is read with 'any', which an app endpoint, a job and a webhook hold`> : [A] extends [Ix['tables'][T]['actions']['read']] ? ScopedApplicationRows<Ix['tables'][T]> : Unavailable<`a scoped endpoint reads ${T} with its read action '${Ix['tables'][T]['actions']['read'] & string}', and this endpoint holds '${A}'`>;
529
619
  };
530
620
  /** A reference table: every endpoint reads it, through its read action, and none writes it. */
531
621
  export interface ReferenceRows<E extends IndexedTable> {
532
622
  list(options?: ListOptions<TableRow<E>>): Promise<ListPage<TableRow<E>>>;
623
+ all(options?: AllOptions<TableRow<E>>): Promise<TableRow<E>[]>;
533
624
  count(options?: CountOptions<TableRow<E>>): Promise<number>;
534
625
  }
535
626
  /** `ctx.db.reference`. */
@@ -543,21 +634,22 @@ export type UnscopedDeclaration<Table extends string, Mode extends UnscopedMode>
543
634
  readonly [T in Table]?: Mode;
544
635
  };
545
636
  /**
546
- * The tables of `U` whose mode may be `'write'` that no site writes: a reference table. A union or optional mode that
547
- * admits `'write'` counts, because the declaration it types may hold it.
637
+ * The tables of `U` whose mode may be `'write'` that no site writes: a reference table or a view. A union or optional
638
+ * mode that admits `'write'` counts, because the declaration it types may hold it.
548
639
  */
549
640
  type ReadOnlyWritten<Ix extends AnyDbIndex, U> = {
550
- [T in keyof U & TableName<Ix>]: 'write' extends U[T] ? Ix['tables'][T]['mode'] extends 'reference' ? T : never : never;
641
+ [T in keyof U & TableName<Ix>]: 'write' extends U[T] ? Ix['tables'][T]['mode'] extends 'reference' ? T : Ix['tables'][T]['view'] extends true ? T : never : never;
551
642
  }[keyof U & TableName<Ix>];
552
- type ReadOnlyMessage<T extends string> = `${T} is a reference table, which no site writes: its rows come from a migration, so declare unscoped: { ${T}: 'read' }`;
643
+ type ReadOnlyMessage<T extends string, E extends IndexedTable> = E['view'] extends true ? `${T} is a view, which no site writes: its rows come from the tables it reads, so declare unscoped: { ${T}: 'read' }` : `${T} is a reference table, which no site writes: its rows come from a migration, so declare unscoped: { ${T}: 'read' }`;
553
644
  /** An `unscoped` declaration's `'write'` of a reference table, refused at its own line. */
554
645
  export type ReadOnlyUnscoped<Ix extends AnyDbIndex, U> = [ReadOnlyWritten<Ix, U>] extends [never] ? unknown : {
555
- readonly [T in ReadOnlyWritten<Ix, U>]: Unavailable<ReadOnlyMessage<T>>;
646
+ readonly [T in ReadOnlyWritten<Ix, U>]: Unavailable<ReadOnlyMessage<T, Ix['tables'][T]>>;
556
647
  };
557
648
  type KeylessMessage<T extends string> = `${T} is a reference table, which has no key: read it with list`;
558
649
  /** A table a site declared `unscoped`: its scope predicate is `true`, and `'read'` writes nothing. */
559
650
  export interface UnscopedRows<T extends string, E extends IndexedTable, M extends UnscopedMode, K extends DataKind> {
560
651
  list(options?: ListOptions<TableRow<E>>): Promise<ListPage<TableRow<E>>>;
652
+ all(options?: AllOptions<TableRow<E>>): Promise<TableRow<E>[]>;
561
653
  count(options?: CountOptions<TableRow<E>>): Promise<number>;
562
654
  aggregate<const S extends AggregateSpec<TableRow<E>>>(spec: S): Promise<AggregateRow<TableRow<E>, S>[]>;
563
655
  readonly get: E['mode'] extends 'reference' ? Unavailable<KeylessMessage<T>> : (key: string) => Promise<TableRow<E>>;
@@ -604,8 +696,8 @@ type RefFragment<Ix extends AnyDbIndex, D extends string, A extends string> = {
604
696
  [T in TableName<Ix>]: Ix['tables'][T]['mode'] extends 'app' ? (A extends Ix['tables'][T]['actions']['read'] ? T : never) : D extends Ix['tables'][T]['refs'] ? (A extends NamedActions<Ix['tables'][T]> ? T : never) : never;
605
697
  }[TableName<Ix>];
606
698
  /**
607
- * What a `Within` writes on a `'write'` site: the target of an UPDATE or DELETE whose action it holds, a column's own
608
- * write action included (the statement's SET is checked against its columns at run time).
699
+ * What a `Within` writes on a `'write'` site: the table of a fragment of `use: 'update'` or `'delete'` whose action it
700
+ * holds, a column's own write action included (the statement's columns are the approver's to review, not checked).
609
701
  */
610
702
  type WithinWrites<E extends IndexedTable, M extends 'read' | 'write'> = M extends 'write' ? E['actions']['update'] | E['actions']['delete'] | (keyof E['writes'] & string) : never;
611
703
  /** The tables a fragment of a `Within` of `D` and `A` reaches: those it lists by their read action, or writes on `M`. */
@@ -614,7 +706,7 @@ type WithinFragment<Ix extends AnyDbIndex, D extends string, A extends string, M
614
706
  }[TableName<Ix>];
615
707
  /** The tables a fragment of an `app` capability of `A` reaches: as `ctx.db.app` lists them for that action. */
616
708
  type AppFragment<Ix extends AnyDbIndex, A extends string> = {
617
- [T in TableName<Ix>]: Ix['tables'][T]['mode'] extends 'app' ? (A extends NamedActions<Ix['tables'][T]> ? T : never) : Ix['tables'][T]['mode'] extends 'dimension' | 'child' ? (A extends Ix['tables'][T]['actions']['read'] | Ix['tables'][T]['appRead'] ? T : never) : never;
709
+ [T in TableName<Ix>]: Ix['tables'][T]['mode'] extends 'app' ? ([Ix['tables'][T]['readsAny']] extends [true] ? T : A extends NamedActions<Ix['tables'][T]> ? T : never) : Ix['tables'][T]['mode'] extends 'dimension' | 'child' ? (A extends Ix['tables'][T]['actions']['read'] | Ix['tables'][T]['appRead'] ? T : never) : never;
618
710
  }[TableName<Ix>];
619
711
  /**
620
712
  * The tables `ctx.sql.scope(capability, table)` takes for a capability of type `C` on a site of mode `M`: those its
@@ -7,6 +7,12 @@ import { type DataLayerRuntime, type TableContext } from './store';
7
7
  /** A list page holds this many rows unless the caller asks for fewer, and never more than `MAX_LIST_LIMIT`. */
8
8
  export declare const DEFAULT_LIST_LIMIT = 50;
9
9
  export declare const MAX_LIST_LIMIT = 500;
10
+ /**
11
+ * The most rows `all()` answers; past it, it refuses instead of truncating. It bounds rows, not bytes: 10 000 rows of
12
+ * ~1 KB, held two or three times over (driver, answer, response), is tens of MB of the one 128 MB Durable Object
13
+ * isolate every concurrent invocation of the environment shares. Wide rows or a growing set page with `list`.
14
+ */
15
+ export declare const MAX_ALL_ROWS = 10000;
10
16
  /** What every handle of one site, in one invocation, is made for. */
11
17
  export interface DataSite {
12
18
  /** A query reads; a mutation also writes and locks; a job reads, and writes only in its fenced transaction. */
@@ -28,6 +34,11 @@ export interface DataSite {
28
34
  * only one it holds. Absent where the framework serves no file; the columns then read as ids and refuse every write.
29
35
  */
30
36
  readonly files?: FileBinding;
37
+ /**
38
+ * The actions a job holds over the whole application: those it declares that its key's token carries. A queue claim
39
+ * answers a file reference its holder may open when one of them reads the table, as a re-read of the row would.
40
+ */
41
+ readonly holds?: readonly string[];
31
42
  /** The texts the verified signed tokens of a public procedure's request carry: the row ids it may update or remove. */
32
43
  readonly carried?: ReadonlySet<string>;
33
44
  /** Throws unless the work running now is the invocation these handles were made for. */
@@ -51,6 +62,11 @@ export interface DataHandles {
51
62
  readonly reference: object;
52
63
  /** `ctx.db.unscoped`, or `undefined` for a site that declares none. */
53
64
  readonly unscoped: object | undefined;
65
+ /**
66
+ * At most two rows of `table` whose `column` holds `value`, as an unscoped read answers them: the framework's read of
67
+ * the caller's own row (`ctx.caller` of `@fabrika/app`). No handle of an application reaches it.
68
+ */
69
+ rowsNaming(table: string, column: string, value: string): Promise<readonly Readonly<Record<string, unknown>>[]>;
54
70
  }
55
71
  /** The data side of one bound layer, which only the framework reaches (`@fabrika/db/framework`). */
56
72
  export interface DataAccess {
@@ -75,3 +91,8 @@ export interface DataLayerParts {
75
91
  fenced<T>(runtime: DataLayerRuntime, work: (session: Session) => Promise<T>): Promise<T>;
76
92
  }
77
93
  export declare function dataAccess(parts: DataLayerParts): DataAccess;
94
+ /**
95
+ * When a claim that leased rows re-arms its job, by the claim's own clock `now`: at once after a full claim, else
96
+ * at the next due row it would take but no sooner than a second after it, or never when it would take none.
97
+ */
98
+ export declare function claimRearmAt(now: Date, full: boolean, next: Date | null): Date | null;