@fabrika/db 0.9.0-dev.19 → 0.9.0-dev.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/authority.ts +23 -2
- package/src/capability.ts +8 -2
- package/src/file-columns.ts +28 -10
- package/src/orm-types.ts +88 -28
- package/src/orm.ts +102 -71
- package/src/policy.ts +118 -7
- package/src/registry.ts +1 -1
- package/src/store.ts +392 -87
- package/src/tables.ts +2 -1
- package/src/testing-shared.ts +1 -1
- package/src/testing-sqlite.ts +1 -1
- package/src/vocabulary-tables.ts +2 -1
- package/types/src/authority.d.ts +6 -0
- package/types/src/capability.d.ts +8 -2
- package/types/src/file-columns.d.ts +3 -3
- package/types/src/orm-types.d.ts +54 -25
- package/types/src/policy.d.ts +54 -4
- package/types/src/registry.d.ts +1 -1
- package/types/src/store.d.ts +47 -18
- package/types/src/testing-shared.d.ts +1 -1
- package/types/src/testing-sqlite.d.ts +1 -1
- package/types/src/vocabulary-tables.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/db",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -92,9 +92,9 @@
|
|
|
92
92
|
"test": "bun test"
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
96
|
-
"@fabrika/platform": "0.9.0-dev.
|
|
97
|
-
"@fabrika/platform-node": "0.9.0-dev.
|
|
95
|
+
"@fabrika/auth-core": "0.9.0-dev.20",
|
|
96
|
+
"@fabrika/platform": "0.9.0-dev.20",
|
|
97
|
+
"@fabrika/platform-node": "0.9.0-dev.20",
|
|
98
98
|
"kysely": "0.29.6",
|
|
99
99
|
"kysely-postgres-js": "5.0.1",
|
|
100
100
|
"zod": "^3.25.76"
|
package/src/authority.ts
CHANGED
|
@@ -402,9 +402,30 @@ export function actionCondition(model: TableModel, action: string, now: Date): O
|
|
|
402
402
|
* one shape the guard admits a condition in, so a condition never stands in for the reach.
|
|
403
403
|
*/
|
|
404
404
|
export function conditioned(model: TableModel, action: string, branch: OperationNode | 'all', now: Date): OperationNode {
|
|
405
|
+
return conditionedAny(model, [action], branch, now)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* `branch`, narrowed as one role holding `actions` is: `<reach> and ((<when a>) or (<when b>))`, a row passing where any
|
|
410
|
+
* action's condition admits it, and unnarrowed when one of them has none. `actions` are those that allow the operation,
|
|
411
|
+
* at least one; for one action this is `conditioned`.
|
|
412
|
+
*/
|
|
413
|
+
export function conditionedAny(model: TableModel, actions: readonly string[], branch: OperationNode | 'all', now: Date): OperationNode {
|
|
405
414
|
const reach = branch === 'all' ? ValueNode.createImmediate(true) : branch
|
|
406
|
-
|
|
407
|
-
|
|
415
|
+
if (actions.length === 0) {
|
|
416
|
+
throw new CapabilityError('unenforceable', `no action allows this operation on ${model.name}`)
|
|
417
|
+
}
|
|
418
|
+
const conditions: OperationNode[] = []
|
|
419
|
+
for (let index = 0; index < actions.length; index++) {
|
|
420
|
+
const action = actions[index]
|
|
421
|
+
if (action === undefined) continue
|
|
422
|
+
const condition = actionCondition(model, action, now)
|
|
423
|
+
if (condition === undefined) {
|
|
424
|
+
return reach
|
|
425
|
+
}
|
|
426
|
+
conditions[conditions.length] = ParensNode.create(condition)
|
|
427
|
+
}
|
|
428
|
+
return AndNode.create(reach, anyOf(conditions))
|
|
408
429
|
}
|
|
409
430
|
|
|
410
431
|
/**
|
package/src/capability.ts
CHANGED
|
@@ -106,11 +106,17 @@ export interface WithinGrant {
|
|
|
106
106
|
readonly revealing: readonly ContainerGrant[]
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* An `app` endpoint's grant: the actions held everywhere in the application, which the proxy checked were held globally.
|
|
111
|
+
* One action for `access: { action, app: true }`; for `anyOf`, every listed action the caller holds, which act as the
|
|
112
|
+
* actions of one role: an operation, a column or a `when` admits the grant when one of them admits it.
|
|
113
|
+
*/
|
|
110
114
|
export interface AppGrant {
|
|
111
115
|
readonly kind: 'app'
|
|
112
|
-
readonly
|
|
116
|
+
readonly actions: readonly [string, ...string[]]
|
|
113
117
|
readonly principal: string
|
|
118
|
+
/** A public procedure's workload: it reaches only the tables that name its action, never one read with `'any'`. */
|
|
119
|
+
readonly public: boolean
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
/** A row a claim leased: the table, its key, and the containment it had then, column by column. */
|
package/src/file-columns.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { Primitive } from './description'
|
|
|
9
9
|
import { NotFoundError, QueryRefusedError } from './errors'
|
|
10
10
|
import { fileHoldingOf, fileReference, holdsFile } from './file-references'
|
|
11
11
|
import { isPlainIdentifier } from './identifier'
|
|
12
|
-
import type
|
|
12
|
+
import { includes, type ReadReach, readsAsAction, type TableModel } from './policy'
|
|
13
13
|
import { claimStoredFile, lockStoredFile, stampStoredFile, storedFilesMetadata } from './stored-files'
|
|
14
14
|
|
|
15
15
|
/** Where a site's file references belong, and what claiming a pending one needs. */
|
|
@@ -25,29 +25,47 @@ export interface FileBinding {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Whether a reference read
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* Whether a reference read under `reach` (one action, or an `anyOf` endpoint's held actions that read the row) lets its
|
|
29
|
+
* holder serve, open and copy the file: a table read action, or the column's own read action, that reads every answered
|
|
30
|
+
* row alone (`readsAsAction`), or a table read action among `held`, the actions a job holds over the whole application.
|
|
31
|
+
* When every action of the reach is a table read action, each answered row was admitted by one that alone reads it,
|
|
32
|
+
* so a column without its own read action is readable. A column with its own read action is answered only under that
|
|
33
|
+
* action (`visibleThrough`), so `held` never widens it. A table read with `'any'` admits whoever read the row: the
|
|
34
|
+
* store refused every other reader.
|
|
31
35
|
*/
|
|
32
|
-
function readsFile(model: TableModel, column: string,
|
|
36
|
+
function readsFile(model: TableModel, column: string, reach: ReadReach, held: NameSet): boolean {
|
|
33
37
|
const own = hasOwn(model.columnReads, column) ? model.columnReads[column] : undefined
|
|
34
38
|
if (own !== undefined) {
|
|
35
|
-
return own
|
|
39
|
+
return readsAsAction(model, own, reach)
|
|
40
|
+
}
|
|
41
|
+
if (model.actions.readAny || readsThroughEvery(model, reach)) {
|
|
42
|
+
return true
|
|
36
43
|
}
|
|
37
44
|
const reads = model.actions.read
|
|
38
45
|
for (let index = 0; index < reads.length; index++) {
|
|
39
46
|
const read = reads[index]
|
|
40
|
-
if (read
|
|
47
|
+
if (read !== undefined && (readsAsAction(model, read, reach) || inSet(held, read))) {
|
|
41
48
|
return true
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
return false
|
|
45
52
|
}
|
|
46
53
|
|
|
54
|
+
/** Whether the reach holds at least one action and each is one of the table's read actions. */
|
|
55
|
+
function readsThroughEvery(model: TableModel, reach: ReadReach): boolean {
|
|
56
|
+
const actions = reach.actions
|
|
57
|
+
for (let index = 0; index < actions.length; index++) {
|
|
58
|
+
if (!includes(model.actions.read, actions[index])) {
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return actions.length > 0
|
|
63
|
+
}
|
|
64
|
+
|
|
47
65
|
const NONE_HELD: NameSet = nameSet([])
|
|
48
66
|
|
|
49
67
|
/**
|
|
50
|
-
* Puts a file reference in each file column of `rows`, read
|
|
68
|
+
* Puts a file reference in each file column of `rows`, read under `reach` in `session`: one statement loads every
|
|
51
69
|
* file's metadata. Without a binding (a store's own runner) the columns keep their ids. `held` (a queue claim's) adds
|
|
52
70
|
* the actions the site holds over the whole application: a reference is readable when one of them reads the table.
|
|
53
71
|
*/
|
|
@@ -56,7 +74,7 @@ export async function answerFiles<R>(
|
|
|
56
74
|
binding: FileBinding | undefined,
|
|
57
75
|
session: Session,
|
|
58
76
|
rows: R[],
|
|
59
|
-
|
|
77
|
+
reach: ReadReach,
|
|
60
78
|
held: NameSet = NONE_HELD,
|
|
61
79
|
): Promise<R[]> {
|
|
62
80
|
const columns = ownKeys(model.files)
|
|
@@ -86,7 +104,7 @@ export async function answerFiles<R>(
|
|
|
86
104
|
if (meta === undefined) {
|
|
87
105
|
throw new QueryRefusedError('unexpected_row', `${model.name}.${column} references a file that is not stored`)
|
|
88
106
|
}
|
|
89
|
-
defineValue(row, column, fileReference(meta, binding.holder, readsFile(model, column,
|
|
107
|
+
defineValue(row, column, fileReference(meta, binding.holder, readsFile(model, column, reach, held)))
|
|
90
108
|
}
|
|
91
109
|
}
|
|
92
110
|
return rows
|
package/src/orm-types.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
InsertValues,
|
|
17
17
|
ListDimensionOf,
|
|
18
18
|
ParentOf,
|
|
19
|
+
ReadsAny,
|
|
19
20
|
Tables,
|
|
20
21
|
UpdateValues,
|
|
21
22
|
} from './policy'
|
|
@@ -81,7 +82,10 @@ export interface IndexedTable {
|
|
|
81
82
|
readonly list: string
|
|
82
83
|
/** A child table's parent table. */
|
|
83
84
|
readonly parent: string
|
|
85
|
+
/** `read` is `never` for a table read with `'any'` (`readsAny`). */
|
|
84
86
|
readonly actions: { readonly read: string; readonly insert: string; readonly update: string; readonly delete: string }
|
|
87
|
+
/** An application table read with `'any'`: every `app` endpoint, job and webhook reads it, no public procedure or scoped site. */
|
|
88
|
+
readonly readsAny: boolean
|
|
85
89
|
/** The actions besides `read` with which an `app` endpoint lists every row (`actions.appRead`). */
|
|
86
90
|
readonly appRead: string
|
|
87
91
|
/** The actions with which an `app` endpoint only counts every row (`actions.appCount`). */
|
|
@@ -118,6 +122,7 @@ type IndexedTableOf<DB, P, T extends keyof P & keyof DB & string, V = unknown> =
|
|
|
118
122
|
readonly update: ActionOf<P, T, 'update'>
|
|
119
123
|
readonly delete: ActionOf<P, T, 'delete'>
|
|
120
124
|
}
|
|
125
|
+
readonly readsAny: ReadsAny<P, T>
|
|
121
126
|
readonly appRead: AppActionsOf<P, T, 'appRead'>
|
|
122
127
|
readonly appCount: AppActionsOf<P, T, 'appCount'>
|
|
123
128
|
readonly row: WithFiles<RowType<DB[T]>, FileColumnsOf<P, T>>
|
|
@@ -314,11 +319,30 @@ type NamedActions<E extends IndexedTable> = (E['actions'][keyof E['actions']] |
|
|
|
314
319
|
|
|
315
320
|
type Names<E extends IndexedTable, A extends string> = [A] extends [NamedActions<E>] ? true : false
|
|
316
321
|
|
|
322
|
+
/**
|
|
323
|
+
* Whether an action of `A` is one of `Allowed`. An `app` capability of several actions, an `anyOf` endpoint's, allows
|
|
324
|
+
* what any of them allows, as one role holding them; the runtime refuses an operation none of the held ones allows.
|
|
325
|
+
*/
|
|
326
|
+
type AnyAllowed<A extends string, Allowed> = [Extract<A, Allowed>] extends [never] ? false : true
|
|
327
|
+
|
|
328
|
+
/** `U`'s members as one object: the columns any action of an `app` capability updates, with their values. */
|
|
329
|
+
type Merged<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never
|
|
330
|
+
|
|
317
331
|
type Operation = 'insert' | 'update' | 'delete'
|
|
318
332
|
|
|
319
|
-
/**
|
|
320
|
-
|
|
321
|
-
|
|
333
|
+
/**
|
|
334
|
+
* `Member` in a mutation whose action is the table's `Op` action (`Allowed`, any action of an `app` capability's);
|
|
335
|
+
* otherwise the message that says which fix applies.
|
|
336
|
+
*/
|
|
337
|
+
type Write<
|
|
338
|
+
T extends string,
|
|
339
|
+
E extends IndexedTable,
|
|
340
|
+
Op extends Operation,
|
|
341
|
+
A extends string,
|
|
342
|
+
K extends DataKind,
|
|
343
|
+
Member,
|
|
344
|
+
Allowed extends boolean = [A] extends [E['actions'][Op]] ? true : false,
|
|
345
|
+
> = K extends 'mutation' ? Allowed extends true ? Member
|
|
322
346
|
: Unavailable<`${Op} on ${T} needs the action '${E['actions'][Op] & string}', and this endpoint holds '${A}'`>
|
|
323
347
|
: K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'>
|
|
324
348
|
: Unavailable<`${Op extends 'delete' ? 'remove' : Op} writes, so it runs only in a mutation: declare the endpoint with r.mutation`>
|
|
@@ -331,17 +355,26 @@ type UpdateRefusal<T extends string, E extends IndexedTable, A extends string> =
|
|
|
331
355
|
|
|
332
356
|
/**
|
|
333
357
|
* `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.
|
|
358
|
+
* action; `Allowed`, any action of an `app` capability's); otherwise the message that says which fix applies.
|
|
335
359
|
*/
|
|
336
|
-
type Update<
|
|
337
|
-
|
|
360
|
+
type Update<
|
|
361
|
+
T extends string,
|
|
362
|
+
E extends IndexedTable,
|
|
363
|
+
A extends string,
|
|
364
|
+
K extends DataKind,
|
|
365
|
+
Member,
|
|
366
|
+
Allowed extends boolean = [A] extends [keyof E['writes']] ? true : false,
|
|
367
|
+
> = K extends 'mutation' ? Allowed extends true ? Member : Unavailable<UpdateRefusal<T, E, A>>
|
|
338
368
|
: K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'>
|
|
339
369
|
: Unavailable<'update writes, so it runs only in a mutation: declare the endpoint with r.mutation'>
|
|
340
370
|
|
|
341
371
|
/** An update's values: any non-empty subset of the columns a capability of `A` updates; an empty one is refused. */
|
|
342
372
|
type UpdateValuesOf<E extends IndexedTable, A extends string> = E['writes'][A & keyof E['writes']]
|
|
343
373
|
|
|
344
|
-
|
|
374
|
+
/** An `app` capability's update values: the columns any of its actions updates, one action's as `UpdateValuesOf`. */
|
|
375
|
+
type AppUpdateValuesOf<E extends IndexedTable, A extends string> = Merged<UpdateValuesOf<E, A>>
|
|
376
|
+
|
|
377
|
+
type Read<T extends string, E extends IndexedTable, A extends string, Member, Allowed extends boolean = Names<E, A>> = Allowed extends true ? Member
|
|
345
378
|
: Unavailable<`${T} does not name the action '${A}': read it from an endpoint whose action ${T} names, or declare unscoped`>
|
|
346
379
|
|
|
347
380
|
/** One page of a keyset list; `next` is the cursor `after` takes, `null` on the last page. */
|
|
@@ -460,31 +493,52 @@ export type WithinTables<Ix extends AnyDbIndex, D extends string, A extends stri
|
|
|
460
493
|
readonly [T in WithinIn<Ix, D>]: WithinRows<T, Ix['tables'][T], A, K>
|
|
461
494
|
}
|
|
462
495
|
|
|
463
|
-
/**
|
|
496
|
+
/**
|
|
497
|
+
* `Member` where `ctx.db.app` of action `A` lists the application table: by its read action, or any action for `'any'`;
|
|
498
|
+
* an action of `A`'s does for an `anyOf` endpoint.
|
|
499
|
+
*/
|
|
500
|
+
type AppList<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Member
|
|
501
|
+
: AnyAllowed<A, E['actions']['read']> extends true ? Member
|
|
502
|
+
: Unavailable<ListRefusal<T, E, A>>
|
|
503
|
+
|
|
504
|
+
/** `Member` where `ctx.db.app` of action `A` (any of them) reads a row of the application table by its key. */
|
|
505
|
+
type AppGet<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Member
|
|
506
|
+
: Read<T, E, A, Member, AnyAllowed<A, NamedActions<E>>>
|
|
507
|
+
|
|
508
|
+
/** `Member` where a public procedure of action `A` reads the application table: under its read action, never `'any'`. */
|
|
509
|
+
type PublicRead<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Unavailable<
|
|
510
|
+
`a public procedure does not read ${T}: it is read with 'any', which an app endpoint, a job and a webhook hold`
|
|
511
|
+
>
|
|
512
|
+
: A extends E['actions']['read'] ? Member
|
|
513
|
+
: Unavailable<ListRefusal<T, E, A>>
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* An application table under the capability of an `app` endpoint of action `A`, in a site of kind `K`; an `anyOf`
|
|
517
|
+
* endpoint's `A` is its listed actions, and an operation any of them allows is typed. A column with its own read action
|
|
518
|
+
* stays hidden there (`RowFor`): which listed actions the caller holds is known only at run time.
|
|
519
|
+
*/
|
|
464
520
|
export interface ApplicationRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
|
|
465
|
-
readonly list:
|
|
466
|
-
|
|
467
|
-
readonly
|
|
468
|
-
readonly aggregate: A extends E['actions']['read']
|
|
469
|
-
? <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>
|
|
470
|
-
: Unavailable<ListRefusal<T, E, A>>
|
|
521
|
+
readonly list: AppList<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>
|
|
522
|
+
readonly count: AppList<T, E, A, (options?: CountOptions<RowFor<E, A>>) => Promise<number>>
|
|
523
|
+
readonly aggregate: AppList<T, E, A, <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>>
|
|
471
524
|
/** One row by its key; a column that declares another read action than `A` is hidden. */
|
|
472
|
-
readonly get:
|
|
525
|
+
readonly get: AppGet<T, E, A, (key: string) => Promise<RowFor<E, A>>>
|
|
473
526
|
/** `SELECT … FOR UPDATE` of one row by its key: a precondition read that no concurrent write overtakes. */
|
|
474
|
-
readonly getForUpdate: K extends 'mutation' ?
|
|
527
|
+
readonly getForUpdate: K extends 'mutation' ? AppGet<T, E, A, (key: string) => Promise<RowFor<E, A>>>
|
|
475
528
|
: K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'>
|
|
476
529
|
: Unavailable<'getForUpdate locks the row, so it runs only in a mutation: declare the endpoint with r.mutation'>
|
|
477
530
|
/** Leases due rows of a queue table: a job's drain, before its transactions. */
|
|
478
531
|
readonly claim: Claim<T, E, A, K>
|
|
479
|
-
readonly insert: Write<T, E, 'insert', A, K, InsertMethod<E>>
|
|
532
|
+
readonly insert: Write<T, E, 'insert', A, K, InsertMethod<E>, AnyAllowed<A, E['actions']['insert']>>
|
|
480
533
|
readonly update: Update<
|
|
481
534
|
T,
|
|
482
535
|
E,
|
|
483
536
|
A,
|
|
484
537
|
K,
|
|
485
|
-
(key: string, values: { [C in keyof
|
|
538
|
+
(key: string, values: { [C in keyof AppUpdateValuesOf<E, A>]: AppUpdateValuesOf<E, A>[C] }, ...version: VersionArguments<E>) => Promise<Saved<E>>,
|
|
539
|
+
AnyAllowed<A, keyof E['writes']>
|
|
486
540
|
>
|
|
487
|
-
readonly remove: Write<T, E, 'delete', A, K, (key: string, ...version: VersionArguments<E>) => Promise<void>>
|
|
541
|
+
readonly remove: Write<T, E, 'delete', A, K, (key: string, ...version: VersionArguments<E>) => Promise<void>, AnyAllowed<A, E['actions']['delete']>>
|
|
488
542
|
}
|
|
489
543
|
|
|
490
544
|
/**
|
|
@@ -508,10 +562,10 @@ type PublicVersioned<T extends string, E extends IndexedTable, Member> = E['vers
|
|
|
508
562
|
* under `expectVersion`; never locked or claimed.
|
|
509
563
|
*/
|
|
510
564
|
export interface PublicApplicationRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
|
|
511
|
-
readonly list:
|
|
512
|
-
readonly count:
|
|
513
|
-
readonly aggregate:
|
|
514
|
-
readonly get:
|
|
565
|
+
readonly list: PublicRead<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>
|
|
566
|
+
readonly count: PublicRead<T, E, A, (options?: CountOptions<RowFor<E, A>>) => Promise<number>>
|
|
567
|
+
readonly aggregate: PublicRead<T, E, A, <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>>
|
|
568
|
+
readonly get: PublicRead<T, E, A, (key: string) => Promise<RowFor<E, A>>>
|
|
515
569
|
readonly getForUpdate: PublicRefusal<'lock'>
|
|
516
570
|
readonly claim: PublicRefusal<'claim'>
|
|
517
571
|
/** By the id a verified signed token of the request carries; answers only the new version. */
|
|
@@ -545,15 +599,17 @@ export type PublicApplicationTables<Ix extends AnyDbIndex, A extends string, K e
|
|
|
545
599
|
* (`RowFor`), or only how many rows match. A count-only action has no `aggregate`: a group or a minimum is a value.
|
|
546
600
|
*/
|
|
547
601
|
export interface AppRecordRows<T extends string, E extends IndexedTable, A extends string> {
|
|
548
|
-
readonly list:
|
|
602
|
+
readonly list: AnyAllowed<A, E['actions']['read'] | E['appRead']> extends true
|
|
603
|
+
? (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>
|
|
549
604
|
: Unavailable<
|
|
550
605
|
`a list of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead, and this endpoint holds '${A}'`
|
|
551
606
|
>
|
|
552
|
-
readonly count:
|
|
607
|
+
readonly count: AnyAllowed<A, E['actions']['read'] | E['appRead'] | E['appCount']> extends true
|
|
608
|
+
? (options?: CountOptions<RowFor<E, A>>) => Promise<number>
|
|
553
609
|
: Unavailable<
|
|
554
610
|
`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}'`
|
|
555
611
|
>
|
|
556
|
-
readonly aggregate:
|
|
612
|
+
readonly aggregate: AnyAllowed<A, E['actions']['read'] | E['appRead']> extends true
|
|
557
613
|
? <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>
|
|
558
614
|
: Unavailable<
|
|
559
615
|
`an aggregate of ${T} needs its read action '${
|
|
@@ -597,7 +653,10 @@ export interface ScopedApplicationRows<E extends IndexedTable> {
|
|
|
597
653
|
* read-only; any other is the message that names its read action.
|
|
598
654
|
*/
|
|
599
655
|
export type ScopedApplicationTables<Ix extends AnyDbIndex, A extends string> = {
|
|
600
|
-
readonly [T in Ix['applications']]: [
|
|
656
|
+
readonly [T in Ix['applications']]: [Ix['tables'][T]['readsAny']] extends [true] ? Unavailable<
|
|
657
|
+
`a scoped endpoint does not read ${T}: it is read with 'any', which an app endpoint, a job and a webhook hold`
|
|
658
|
+
>
|
|
659
|
+
: [A] extends [Ix['tables'][T]['actions']['read']] ? ScopedApplicationRows<Ix['tables'][T]>
|
|
601
660
|
: Unavailable<
|
|
602
661
|
`a scoped endpoint reads ${T} with its read action '${Ix['tables'][T]['actions']['read'] & string}', and this endpoint holds '${A}'`
|
|
603
662
|
>
|
|
@@ -721,7 +780,8 @@ type WithinFragment<Ix extends AnyDbIndex, D extends string, A extends string, M
|
|
|
721
780
|
|
|
722
781
|
/** The tables a fragment of an `app` capability of `A` reaches: as `ctx.db.app` lists them for that action. */
|
|
723
782
|
type AppFragment<Ix extends AnyDbIndex, A extends string> = {
|
|
724
|
-
[T in TableName<Ix>]: Ix['tables'][T]['mode'] extends 'app'
|
|
783
|
+
[T in TableName<Ix>]: Ix['tables'][T]['mode'] extends 'app'
|
|
784
|
+
? ([Ix['tables'][T]['readsAny']] extends [true] ? T : A extends NamedActions<Ix['tables'][T]> ? T : never)
|
|
725
785
|
: Ix['tables'][T]['mode'] extends 'dimension' | 'child' ? (A extends Ix['tables'][T]['actions']['read'] | Ix['tables'][T]['appRead'] ? T : never)
|
|
726
786
|
: never
|
|
727
787
|
}[TableName<Ix>]
|