@fabrika/db 0.9.0-dev.13 → 0.9.0-dev.14
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 +339 -54
- package/src/capability.ts +32 -4
- package/src/framework.ts +1 -1
- package/src/guard.ts +68 -5
- package/src/index.ts +1 -0
- package/src/job-leases.ts +3 -2
- package/src/nodes.ts +12 -0
- package/src/orm.ts +23 -13
- package/src/policy.ts +438 -39
- package/src/registry.ts +30 -1
- package/src/sql.ts +1 -2
- package/src/sqlite.ts +46 -1
- package/src/store.ts +853 -78
- package/src/tables.ts +42 -0
- package/src/vocabulary-tables.ts +14 -2
- package/types/src/authority.d.ts +94 -19
- package/types/src/capability.d.ts +31 -4
- package/types/src/framework.d.ts +1 -1
- package/types/src/guard.d.ts +8 -0
- package/types/src/index.d.ts +1 -1
- package/types/src/job-leases.d.ts +2 -1
- package/types/src/nodes.d.ts +2 -0
- package/types/src/policy.d.ts +79 -6
- package/types/src/registry.d.ts +18 -1
- package/types/src/store.d.ts +32 -7
- package/types/src/vocabulary-tables.d.ts +26 -3
package/src/tables.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// driver, so `@fabrika/app/contract` and the static contract reader in `@fabrika/check` import it.
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
|
+
AccessArtifact,
|
|
5
6
|
ColumnPolicyArtifact,
|
|
6
7
|
ConditionArtifact,
|
|
7
8
|
ConfersArtifact,
|
|
@@ -16,6 +17,7 @@ import { freeze, namesOf, ownEntry, ownKeys, setOwn } from './builtins'
|
|
|
16
17
|
import { conditionArtifact, type ConditionModel } from './conditions'
|
|
17
18
|
import { PolicyError } from './errors'
|
|
18
19
|
import {
|
|
20
|
+
type AccessModel,
|
|
19
21
|
accessTablesOf,
|
|
20
22
|
type MemberRevealModel,
|
|
21
23
|
modelOf,
|
|
@@ -188,12 +190,26 @@ function artifactOf(model: TableModel): TablePolicyArtifact {
|
|
|
188
190
|
...(model.view ? { view: true } : {}),
|
|
189
191
|
...(model.confers.length === 0 ? {} : { confers: confersArtifact(model.confers) }),
|
|
190
192
|
...(ownKeys(model.when).length === 0 ? {} : { when: whenArtifact(model.when) }),
|
|
193
|
+
...(ownKeys(model.relationWhen).length === 0 ? {} : { relationWhen: relationWhenArtifact(model.relationWhen) }),
|
|
191
194
|
...(model.reveals.length === 0 ? {} : { reveals: revealsArtifact(model.reveals) }),
|
|
192
195
|
...(model.readThrough.length === 0 ? {} : { readThrough: readThroughArtifact(model) }),
|
|
196
|
+
...writeThroughArtifact(model),
|
|
193
197
|
...(model.memberReveals.length === 0 ? {} : { memberReveals: memberRevealsArtifact(model.memberReveals) }),
|
|
198
|
+
...(model.access.length === 0 ? {} : { access: accessArtifact(model.access) }),
|
|
194
199
|
}
|
|
195
200
|
}
|
|
196
201
|
|
|
202
|
+
function accessArtifact(access: readonly AccessModel[]): Record<string, AccessArtifact> {
|
|
203
|
+
const artifact: Record<string, AccessArtifact> = {}
|
|
204
|
+
for (let index = 0; index < access.length; index++) {
|
|
205
|
+
const entry = access[index]
|
|
206
|
+
if (entry !== undefined) {
|
|
207
|
+
setOwn(artifact, entry.relation, { view: entry.view, row: entry.row, principal: entry.principal ?? null, member: entry.member ?? null })
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return artifact
|
|
211
|
+
}
|
|
212
|
+
|
|
197
213
|
function memberRevealsArtifact(reveals: readonly MemberRevealModel[]): Record<string, MemberRevealsArtifact> {
|
|
198
214
|
const artifact: Record<string, MemberRevealsArtifact> = {}
|
|
199
215
|
for (let index = 0; index < reveals.length; index++) {
|
|
@@ -203,6 +219,7 @@ function memberRevealsArtifact(reveals: readonly MemberRevealModel[]): Record<st
|
|
|
203
219
|
to: reveal.dimension,
|
|
204
220
|
actions: [...reveal.actions],
|
|
205
221
|
...(reveal.when === undefined ? {} : { when: conditionArtifact(reveal.when) }),
|
|
222
|
+
...(reveal.assign === undefined ? {} : { assign: { self: reveal.assign.self } }),
|
|
206
223
|
})
|
|
207
224
|
}
|
|
208
225
|
return artifact
|
|
@@ -217,6 +234,18 @@ function readThroughArtifact(model: TableModel): Record<string, string> {
|
|
|
217
234
|
return artifact
|
|
218
235
|
}
|
|
219
236
|
|
|
237
|
+
function writeThroughArtifact(model: TableModel): { readonly writeThrough: Record<string, string[]> } | undefined {
|
|
238
|
+
const artifact: Record<string, string[]> = {}
|
|
239
|
+
let declared = false
|
|
240
|
+
for (let index = 0; index < model.readThrough.length; index++) {
|
|
241
|
+
const path = model.readThrough[index]
|
|
242
|
+
if (path === undefined || path.writes.length === 0) continue
|
|
243
|
+
setOwn(artifact, path.dimension, [...path.writes])
|
|
244
|
+
declared = true
|
|
245
|
+
}
|
|
246
|
+
return declared ? { writeThrough: artifact } : undefined
|
|
247
|
+
}
|
|
248
|
+
|
|
220
249
|
function revealsArtifact(reveals: readonly RevealModel[]): Record<string, RevealsArtifact> {
|
|
221
250
|
const artifact: Record<string, RevealsArtifact> = {}
|
|
222
251
|
for (let index = 0; index < reveals.length; index++) {
|
|
@@ -259,6 +288,19 @@ function whenArtifact(when: Readonly<Record<string, ConditionModel>>): Record<st
|
|
|
259
288
|
return artifact
|
|
260
289
|
}
|
|
261
290
|
|
|
291
|
+
function relationWhenArtifact(
|
|
292
|
+
relationWhen: Readonly<Record<string, Readonly<Record<string, ConditionModel>>>>,
|
|
293
|
+
): Record<string, Record<string, ConditionArtifact>> {
|
|
294
|
+
const artifact: Record<string, Record<string, ConditionArtifact>> = {}
|
|
295
|
+
const relations = ownKeys(relationWhen)
|
|
296
|
+
for (let index = 0; index < relations.length; index++) {
|
|
297
|
+
const relation = relations[index] ?? ''
|
|
298
|
+
const conditions = ownEntry(relationWhen, relation)
|
|
299
|
+
if (conditions !== undefined) setOwn(artifact, relation, whenArtifact(conditions))
|
|
300
|
+
}
|
|
301
|
+
return artifact
|
|
302
|
+
}
|
|
303
|
+
|
|
262
304
|
/** One action as its text, so a single-action policy keeps the artifact and digest it had; several as a list; none as `null`. */
|
|
263
305
|
function actionArtifact(actions: readonly string[]): TableActionArtifact | null {
|
|
264
306
|
const [first] = actions
|
package/src/vocabulary-tables.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { ConditionPolicy } from './conditions'
|
|
5
5
|
import type {
|
|
6
|
+
AccessPolicy,
|
|
6
7
|
ColumnList,
|
|
7
8
|
ColumnPolicies,
|
|
8
9
|
ConfersPolicy,
|
|
@@ -105,6 +106,8 @@ interface WritableFields<Col extends string, A extends string, Ver extends Col,
|
|
|
105
106
|
readonly confers?: { readonly [relation: string]: ConfersPolicy<Col> }
|
|
106
107
|
/** Action → the condition a row must meet for it, whoever holds it. */
|
|
107
108
|
readonly when?: { readonly [action in A]?: ConditionPolicy<Col> }
|
|
109
|
+
/** Relation → action → the condition a row that relation reaches must meet for it; IAM grants are not narrowed. */
|
|
110
|
+
readonly relationWhen?: { readonly [relation: string]: { readonly [action in A]?: ConditionPolicy<Col> } }
|
|
108
111
|
/** Relation of the table's own dimension → the ancestor node a row it reaches reveals, and for which actions. */
|
|
109
112
|
readonly reveals?: { readonly [relation: string]: RevealsPolicy<Col, A> }
|
|
110
113
|
/**
|
|
@@ -112,8 +115,15 @@ interface WritableFields<Col extends string, A extends string, Ver extends Col,
|
|
|
112
115
|
* `<nearest container column>.<its column>`, the nearest container's own path.
|
|
113
116
|
*/
|
|
114
117
|
readonly readThrough?: { readonly [dimension: string]: Col | `${Col}.${string}` }
|
|
118
|
+
/**
|
|
119
|
+
* Dimension of `readThrough` → the actions a `Ref` held through that path holds, writes included; whoever inserts the
|
|
120
|
+
* path's column must hold each at the node it names.
|
|
121
|
+
*/
|
|
122
|
+
readonly writeThrough?: { readonly [dimension: string]: readonly A[] }
|
|
115
123
|
/** The table's own dimension → the ancestor node a row reveals to a grant at its node, for a `Within`'s reads. */
|
|
116
124
|
readonly memberReveals?: { readonly [dimension: string]: MemberRevealsPolicy<Col, A> }
|
|
125
|
+
/** Relation → the access view that lists the rows it reaches: the escape path, decided by the view's SQL. */
|
|
126
|
+
readonly access?: { readonly [relation: string]: AccessPolicy }
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
/**
|
|
@@ -186,12 +196,14 @@ interface ReadOnlyFields<Col extends string, A extends string> {
|
|
|
186
196
|
}
|
|
187
197
|
|
|
188
198
|
/**
|
|
189
|
-
* A view read as a child table: its parent's `Ref` and `Within` read it; nothing writes it (ADR-0072). Its `when`
|
|
190
|
-
* its read actions; a path may start at its parent column, to the parent row.
|
|
199
|
+
* A view read as a child table: its parent's `Ref` and `Within` read it; nothing writes it (ADR-0072). Its `when` and
|
|
200
|
+
* `relationWhen` narrow its read actions; a path may start at its parent column, to the parent row.
|
|
191
201
|
*/
|
|
192
202
|
type AuthoredChildViewPolicy<Table extends string, Col extends string, A extends string, S, P> = ReadOnlyFields<Col, A> & {
|
|
193
203
|
readonly scope: ChildScopes<Table, Col, S, P>
|
|
194
204
|
readonly when?: { readonly [action in A]?: ConditionPolicy<Col> }
|
|
205
|
+
/** Relation → action → the condition a row the relation reaches through the parent row must meet for it. */
|
|
206
|
+
readonly relationWhen?: { readonly [relation: string]: { readonly [action in A]?: ConditionPolicy<Col> } }
|
|
195
207
|
}
|
|
196
208
|
|
|
197
209
|
/** A view's policy as written: a read-only child, or a reference table every site reads. */
|
package/types/src/authority.d.ts
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { type OperationNode } from 'kysely';
|
|
2
|
-
import type { RefGrant, WithinGrant } from './capability';
|
|
2
|
+
import type { ContainerGrant, RefGrant, RelationHold, WithinGrant } from './capability';
|
|
3
|
+
import type { ConditionModel } from './conditions';
|
|
3
4
|
import type { ViewParentLink } from './guard';
|
|
4
5
|
import { type Container, type MemberRevealModel, type RelationSource, type RevealModel, type SecondaryPath, type TableModel } from './policy';
|
|
5
6
|
/** A relation of the layer: its source table, and the tables whose rows it reaches reveal an ancestor node. */
|
|
6
7
|
export interface LayerRelation extends RelationSource {
|
|
8
|
+
readonly kind: 'source';
|
|
7
9
|
readonly reveals: readonly RevealModel[];
|
|
10
|
+
/** The actions some table's `relationWhen` narrows the relation for: it holds them only on the rows that condition admits. */
|
|
11
|
+
readonly narrowed: readonly string[];
|
|
12
|
+
/**
|
|
13
|
+
* The source's and each reveal table's column for every dimension a row of it lies at, by table: where a hold inside
|
|
14
|
+
* a node finds whether a row that holds a destination lies inside that node.
|
|
15
|
+
*/
|
|
16
|
+
readonly placed: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
8
17
|
}
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
18
|
+
/** A relation no table confers: only access views decide what it reaches, so it has no source row to check or lock. */
|
|
19
|
+
export interface AccessRelation {
|
|
20
|
+
readonly kind: 'access';
|
|
21
|
+
readonly relation: string;
|
|
22
|
+
readonly dimension: string;
|
|
23
|
+
readonly narrowed: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** Every relation of the layer, by name, with its source table, or the mark that only access views serve it. */
|
|
26
|
+
export type RelationSources = Readonly<Record<string, LayerRelation | AccessRelation>>;
|
|
11
27
|
/** Every member reveal of the layer, by the dimension whose grants it reveals to. */
|
|
12
28
|
export type MemberReveals = Readonly<Record<string, readonly MemberRevealModel[]>>;
|
|
29
|
+
/** What a capability is held through beyond its grants: the layer's relations and its member reveals. */
|
|
30
|
+
export interface LayerReach {
|
|
31
|
+
readonly relations: RelationSources;
|
|
32
|
+
readonly members: MemberReveals;
|
|
33
|
+
}
|
|
13
34
|
export declare function relationSource(relations: RelationSources, relation: string): LayerRelation;
|
|
35
|
+
/** The relation by name, conferred or served by access views; one the layer does not know is unenforceable, never ignored. */
|
|
36
|
+
export declare function knownRelation(relations: RelationSources, relation: string): LayerRelation | AccessRelation;
|
|
14
37
|
/** A source row that confers its relation now: unexpired, and admitted by the relation's own condition. */
|
|
15
38
|
export declare function activeRow(source: RelationSource, now: Date): readonly OperationNode[];
|
|
16
39
|
/**
|
|
@@ -18,6 +41,7 @@ export declare function activeRow(source: RelationSource, now: Date): readonly O
|
|
|
18
41
|
* P.<column> = $me)`. Every check of a source row's principal is built here.
|
|
19
42
|
*/
|
|
20
43
|
export declare function namesPrincipal(source: RelationSource, principal: string): OperationNode;
|
|
44
|
+
export declare function isIn(table: string, name: string, nodes: OperationNode): OperationNode;
|
|
21
45
|
/**
|
|
22
46
|
* The rows of `table` whose `path` column names one of `nodes` of `dimension`: `T.<column> in (nodes)` at the path's own
|
|
23
47
|
* dimension, `T.<column> in (select D.<key> from D where D.<link> in (nodes))` at one above it; `undefined` elsewhere. A
|
|
@@ -26,21 +50,50 @@ export declare function namesPrincipal(source: RelationSource, principal: string
|
|
|
26
50
|
export declare function throughPath(table: string, path: SecondaryPath, dimension: string, nodes: OperationNode): OperationNode | undefined;
|
|
27
51
|
/** `select R.<ancestor> from R where R.<key> in (<the relation's nodes>) and <when>`: the nodes a reveal holds `principal` at. */
|
|
28
52
|
export declare function revealedNodes(source: RelationSource, reveal: RevealModel, principal: string, now: Date): OperationNode;
|
|
53
|
+
/** Which secondary paths a statement follows: every one for a `Within`'s read, `heldThrough` for a `Ref`, none for a move. */
|
|
54
|
+
export type PathRule = (path: SecondaryPath) => boolean;
|
|
55
|
+
export declare const everyPath: PathRule;
|
|
56
|
+
export declare const noPath: PathRule;
|
|
57
|
+
/** The paths that hold `action` for a `Ref` (`writeThrough`). */
|
|
58
|
+
export declare function heldThrough(action: string): PathRule;
|
|
29
59
|
/**
|
|
30
60
|
* The rows of `model` a relation reaches for `principal` under `action`: `T.<node> in (select S.<node> from S where
|
|
31
61
|
* S.<principal> = $me and <active>)` where `model` lies at a node of the relation's dimension, and one
|
|
32
62
|
* `T.<ancestor> in (<revealed nodes>)` per reveal of `action` to an ancestor `model` lies at. Empty where neither holds.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
63
|
+
* It also follows the secondary paths `paths` admits: the column `model` reaches the relation's dimension through, and
|
|
64
|
+
* the reveals matched through one. A hold inside a node narrows each term to the rows inside it, by `model`'s own
|
|
65
|
+
* column for the hold's dimension, and reaches none where `model` has no such column. Where `model`'s `relationWhen`
|
|
66
|
+
* narrows the relation for `action`, each term carries that condition too: `(<term> and (<narrowing>))`, so no builder
|
|
67
|
+
* of a relation's reach leaves either out.
|
|
68
|
+
*/
|
|
69
|
+
export declare function relationTerms(relations: RelationSources, model: TableModel, hold: RelationHold, principal: string, action: string, now: Date, paths: PathRule): readonly OperationNode[];
|
|
70
|
+
/**
|
|
71
|
+
* The rows of `model` its access views list for `hold`, each carrying the relation's `relationWhen` for `action`. A view
|
|
72
|
+
* bound to the hold's node decides which rows lie inside it, so the table's own column does not narrow it; a view bound
|
|
73
|
+
* to the principal alone is narrowed to the node by that column, and reaches nothing where `model` has none.
|
|
35
74
|
*/
|
|
36
|
-
export declare function
|
|
75
|
+
export declare function accessReach(model: TableModel, hold: RelationHold, principal: string, action: string, now: Date): readonly OperationNode[];
|
|
76
|
+
/** `holds` without those of a relation `narrowed` names: the holds no `relationWhen` narrows. */
|
|
77
|
+
export declare function holdsBesides(holds: readonly RelationHold[], narrowed: readonly string[]): readonly RelationHold[];
|
|
78
|
+
/** The condition `model`'s `relationWhen` puts on the rows `relation` reaches for `action`, if any. */
|
|
79
|
+
export declare function relationCondition(model: TableModel, relation: string, action: string): ConditionModel | undefined;
|
|
80
|
+
/** `(<term> and (<narrowing>))`: one branch of a reach, narrowed; the one shape the guard admits a branch's condition in. */
|
|
81
|
+
export declare function narrowedTerm(term: OperationNode, narrowing: OperationNode): OperationNode;
|
|
37
82
|
/**
|
|
38
|
-
* The rows of `model` a `Within`'s read reaches through member reveals:
|
|
39
|
-
*
|
|
40
|
-
* ancestor `model` lies at. A grant at a dimension that reveals no node for `action` is refused: the framework passes
|
|
41
|
-
* none.
|
|
83
|
+
* The rows of `model` a `Within`'s read reaches through member reveals: `revealingTerms` of its grants at revealing
|
|
84
|
+
* dimensions.
|
|
42
85
|
*/
|
|
43
86
|
export declare function memberTerms(members: MemberReveals, model: TableModel, grant: WithinGrant, now: Date): readonly OperationNode[];
|
|
87
|
+
/**
|
|
88
|
+
* The rows of `model` that `revealing`, grants of `action` at nodes of revealing dimensions, reach through member
|
|
89
|
+
* reveals: per grant, `T.<ancestor> in (select R.<ancestor> from R where R.<key> in (values) and <when>)` for each reveal
|
|
90
|
+
* of `action` to an ancestor `model` lies at, `R.<key>` the row's key or its path's column. A reveal through a path
|
|
91
|
+
* counts where `paths` admits it. A grant at a dimension that reveals no node for `action` is refused: the framework
|
|
92
|
+
* passes none.
|
|
93
|
+
*/
|
|
94
|
+
export declare function revealingTerms(members: MemberReveals, model: TableModel, holder: string, action: string, revealing: readonly ContainerGrant[], now: Date, paths: PathRule): readonly OperationNode[];
|
|
95
|
+
/** `select R.<ancestor> from R where R.<key> in (values) and <when>`: the nodes a member reveal holds at for `values`. */
|
|
96
|
+
export declare function memberRevealed(reveal: MemberRevealModel, values: readonly string[], now: Date): OperationNode;
|
|
44
97
|
/** The condition `action` holds a row of `model` under, or `undefined` when the action is not narrowed there. */
|
|
45
98
|
export declare function actionCondition(model: TableModel, action: string, now: Date): OperationNode | undefined;
|
|
46
99
|
/**
|
|
@@ -50,17 +103,39 @@ export declare function actionCondition(model: TableModel, action: string, now:
|
|
|
50
103
|
export declare function conditioned(model: TableModel, action: string, branch: OperationNode | 'all', now: Date): OperationNode;
|
|
51
104
|
/**
|
|
52
105
|
* A Ref's predicate over `links` of `model`: one equality per link of its chain (after `row`, the equality that
|
|
53
|
-
* addresses one row by its key), then, when the Ref is held through relations, a row of one of them
|
|
54
|
-
* its action's condition. A
|
|
55
|
-
* unconditioned.
|
|
106
|
+
* addresses one row by its key), then, when the Ref is held through relations or member reveals, a row of one of them
|
|
107
|
+
* at the node, and its action's condition. A Ref whose relations, revealing grants and paths together reach no row of
|
|
108
|
+
* `model` is unenforceable there, never unconditioned.
|
|
56
109
|
*/
|
|
57
|
-
export declare function refScope(
|
|
110
|
+
export declare function refScope(reach: LayerReach, model: TableModel, links: readonly Container[], grant: RefGrant, now: Date, row?: OperationNode, paths?: PathRule): OperationNode;
|
|
111
|
+
/** A child view's parent reach, split by the relations the view narrows: the rest's reach, and each such relation's own. */
|
|
112
|
+
export interface SplitReach {
|
|
113
|
+
readonly rest: OperationNode | undefined;
|
|
114
|
+
readonly relations: readonly {
|
|
115
|
+
readonly reached: OperationNode;
|
|
116
|
+
readonly condition: ConditionModel;
|
|
117
|
+
}[];
|
|
118
|
+
}
|
|
58
119
|
/**
|
|
59
120
|
* The rows of a child view whose parent row `reached` admits: `V.<column> in (select P.<key> from P where <reached>)`,
|
|
60
121
|
* after `row` when it addresses one row, then the view's own condition of `action`. For `all`, every parent row, so a
|
|
61
|
-
* row whose parent column names none is still read by no capability.
|
|
62
|
-
*
|
|
122
|
+
* row whose parent column names none is still read by no capability. Split by the relations the view narrows
|
|
123
|
+
* (`relationWhen`), one such membership per part, each narrowed relation's ANDed with the view's condition for it. No
|
|
124
|
+
* column of the view places a row: its containment rests on the parent's foreign keys (ADR-0072).
|
|
125
|
+
*/
|
|
126
|
+
export declare function viewScope(model: TableModel, parent: ViewParentLink, action: string, reached: OperationNode | 'all' | SplitReach | undefined, now: Date, row?: OperationNode, access?: readonly OperationNode[]): OperationNode;
|
|
127
|
+
/**
|
|
128
|
+
* The rows a Ref held through relations, member reveals or secondary paths needs at `model`: a relation row at the node,
|
|
129
|
+
* a revealing row the Ref's grants reveal it through, or a path `paths` admits naming a node its grants hold;
|
|
130
|
+
* `undefined` for a Ref an IAM grant holds on its chain. A part that reaches no row of `model` adds nothing; when none
|
|
131
|
+
* does, the Ref is unenforceable there, never unconditioned.
|
|
132
|
+
*/
|
|
133
|
+
export declare function relationGate(reach: LayerReach, model: TableModel, grant: RefGrant, now: Date, paths?: PathRule): OperationNode | undefined;
|
|
134
|
+
/** Every term of `grant`'s relations, member reveals and paths at `model`; empty where none reaches it. */
|
|
135
|
+
export declare function gateTerms(reach: LayerReach, model: TableModel, grant: RefGrant, now: Date, paths: PathRule): readonly OperationNode[];
|
|
136
|
+
/**
|
|
137
|
+
* The rows of `model` whose path `paths` admits names a node `grants` hold: `T.<column> in (values)` at the path's own
|
|
138
|
+
* dimension, `T.<column> in (select D.<key> from D where D.<link> in (values))` above it, through the container's column
|
|
139
|
+
* for a path through the container.
|
|
63
140
|
*/
|
|
64
|
-
export declare function
|
|
65
|
-
/** The relation rows a Ref held through relations needs at `model`, or `undefined` for a Ref an IAM grant holds. */
|
|
66
|
-
export declare function relationGate(relations: RelationSources, model: TableModel, grant: RefGrant, now: Date): OperationNode | undefined;
|
|
141
|
+
export declare function pathTerms(model: TableModel, grants: readonly ContainerGrant[], paths: PathRule): readonly OperationNode[];
|
|
@@ -51,7 +51,28 @@ export interface RefGrant {
|
|
|
51
51
|
* The relations the caller holds the action through on this object or a container, when no grant holds it: every
|
|
52
52
|
* statement of the Ref then also requires a row of one of them. Empty for a Ref an IAM grant holds.
|
|
53
53
|
*/
|
|
54
|
-
readonly relations: readonly
|
|
54
|
+
readonly relations: readonly RelationHold[];
|
|
55
|
+
/**
|
|
56
|
+
* The caller's grants of the action at nodes whose rows reveal the object, or a container on its chain, to their
|
|
57
|
+
* members (`memberReveals`), when no grant holds it: every statement of the Ref then also requires such a row, as
|
|
58
|
+
* for `relations`. Empty for a Ref an IAM grant holds.
|
|
59
|
+
*/
|
|
60
|
+
readonly revealing: readonly ContainerGrant[];
|
|
61
|
+
/**
|
|
62
|
+
* The caller's grants of the action at nodes of a dimension the object's table reads through a path that holds the
|
|
63
|
+
* action (`writeThrough`), or at containers of such a node, when no grant holds it on the chain: every statement then
|
|
64
|
+
* also requires the row to reach one of them through such a path. Empty for a Ref an IAM grant holds.
|
|
65
|
+
*/
|
|
66
|
+
readonly paths: readonly ContainerGrant[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A relation the caller holds the action through: anywhere (`inside: null`, a `~rel` entry), or only on rows that lie
|
|
70
|
+
* inside one of `inside`'s values (`~relin` entries of grants at those values): a row whose column for that dimension,
|
|
71
|
+
* its key at its own dimension, names one of them. A row with no such column is not inside, so the hold reaches none.
|
|
72
|
+
*/
|
|
73
|
+
export interface RelationHold {
|
|
74
|
+
readonly relation: string;
|
|
75
|
+
readonly inside: ContainerGrant | null;
|
|
55
76
|
}
|
|
56
77
|
/** The values of one container dimension in which the caller holds the action: `organization → [o1]`. */
|
|
57
78
|
export interface ContainerGrant {
|
|
@@ -81,10 +102,10 @@ export interface WithinGrant {
|
|
|
81
102
|
*/
|
|
82
103
|
readonly contained: readonly ContainerGrant[];
|
|
83
104
|
/**
|
|
84
|
-
* The relations through which the caller also holds the action (`~rel` entries of its token): a row lies
|
|
85
|
-
* `Within` too where a row of one of them names the caller at the row's node, read by the statement itself.
|
|
105
|
+
* The relations through which the caller also holds the action (`~rel` and `~relin` entries of its token): a row lies
|
|
106
|
+
* in the `Within` too where a row of one of them names the caller at the row's node, read by the statement itself.
|
|
86
107
|
*/
|
|
87
|
-
readonly relations: readonly
|
|
108
|
+
readonly relations: readonly RelationHold[];
|
|
88
109
|
/**
|
|
89
110
|
* The caller's grants of the action at nodes whose rows reveal the `Within`'s dimension or a container of it to their
|
|
90
111
|
* members (`memberReveals`): a row under a node such a row reveals is read too, the statement judging the revealing row.
|
|
@@ -131,4 +152,10 @@ export interface CapabilityAuthority {
|
|
|
131
152
|
* request. Every mutation checks it inside its own transaction.
|
|
132
153
|
*/
|
|
133
154
|
fence(): LeaseFence | null;
|
|
155
|
+
/**
|
|
156
|
+
* What the caller of the work running now holds of `action` in `dimension`, as a `Within` of it would carry it, with
|
|
157
|
+
* no values when it holds none; `undefined` when the work has no caller (a job attempt, a webhook delivery). An
|
|
158
|
+
* insert that hands out access through a path judges its writer by it; an authority without the method has no caller.
|
|
159
|
+
*/
|
|
160
|
+
standing?(dimension: string, action: string): WithinGrant | undefined;
|
|
134
161
|
}
|
package/types/src/framework.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type { DeliveryClaim, NewWebhookBinding, WebhookBinding, WebhookTables }
|
|
|
11
11
|
export type { JobLeases, JobLeaseState, JobOutcome, LeaseChange, LeaseProjection, OverdueClaim } from './job-leases';
|
|
12
12
|
export type { FinishWakes, JobWakes, NewWake, Wake, WakeReason } from './job-wakes';
|
|
13
13
|
export type { DataAccess, DataHandles, DataSite } from './orm';
|
|
14
|
-
export type { FrameworkTables, Locator, ProvisionalBinding, RelationCheck, RevealCheck } from './registry';
|
|
14
|
+
export type { FrameworkTables, Locator, MemberRevealCheck, PathCheck, ProvisionalBinding, RelationCheck, RevealCheck } from './registry';
|
|
15
15
|
export type { SqlMode, SqlSite, SqlTag, SqlValue } from './sql';
|
|
16
16
|
export type { FileColumnRef, QuarantinedStoredFile, ServedFile, StagedFile, StoredFileMeta, StoredFiles, StoredFileStatus } from './stored-files';
|
|
17
17
|
/** Whether `value` is an object `scoped(tables)` created, rather than a look-alike with the same fields. */
|
package/types/src/guard.d.ts
CHANGED
|
@@ -34,6 +34,14 @@ export interface ViewParentLink {
|
|
|
34
34
|
readonly column: string;
|
|
35
35
|
readonly table: string;
|
|
36
36
|
readonly key: string;
|
|
37
|
+
/** The view's own access views, which list its rows beside the parent's reach (ADR-0076). */
|
|
38
|
+
readonly access?: readonly ViewAccessLink[];
|
|
39
|
+
}
|
|
40
|
+
/** An access view of a child view: `V.<key> in (select A.<row> from A where <bindings>)`. */
|
|
41
|
+
export interface ViewAccessLink {
|
|
42
|
+
readonly key: string;
|
|
43
|
+
readonly view: string;
|
|
44
|
+
readonly row: string;
|
|
37
45
|
}
|
|
38
46
|
/** Refuses any operation tree outside the allowlist. Runs on the final tree, immediately before it is compiled. */
|
|
39
47
|
export declare function assertAllowedTree(root: OperationNode, context: GuardContext): void;
|
package/types/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AppCapability, AppGrant, CapabilityAuthority, CapabilityGrant, ContainerGrant, LeaseFence, Ref, RefGrant, RowGrant, RowRef, Within, WithinGrant, } from './capability';
|
|
1
|
+
export type { AppCapability, AppGrant, CapabilityAuthority, CapabilityGrant, ContainerGrant, LeaseFence, Ref, RefGrant, RelationHold, RowGrant, RowRef, Within, WithinGrant, } from './capability';
|
|
2
2
|
export { MAX_WITHIN_VALUES } from './capability';
|
|
3
3
|
export { applicationSchema, Database, type DatabaseEngine, type Executor, type SqlDialect, type TransactionOptions, type TransactionRunner, } from './database';
|
|
4
4
|
export type { AllowedOperator, ComparisonOperator, ConditionTuple, ListOperator, NoColumns, NullOperator, PatternOperator, Primitive, ScopedSelect, } from './description';
|
|
@@ -98,7 +98,8 @@ export declare function sqliteNowPlus(ms: string): string;
|
|
|
98
98
|
export declare function sqliteTimestamp(value: unknown, what: string): Date | null;
|
|
99
99
|
/**
|
|
100
100
|
* The database's clock inside `session`'s transaction: a queue claim compares and moves `due` by it, so no process
|
|
101
|
-
* clock decides when a row is due.
|
|
101
|
+
* clock decides when a row is due. On Postgres it is rounded up to the millisecond a `Date` holds, so it is never
|
|
102
|
+
* earlier than a `due` that `now()` wrote with microseconds.
|
|
102
103
|
*/
|
|
103
104
|
export declare function databaseNow(session: Session): Promise<Date>;
|
|
104
105
|
/**
|
package/types/src/nodes.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export declare function existsNode(table: string, key: string, scope: OperationN
|
|
|
41
41
|
export declare function acknowledgementNode(table: string, key: string, version: string | undefined, where: WhereNode): SelectQueryNode;
|
|
42
42
|
/** `select columns from table where scope limit 1`: the containment columns of one object, for the framework's locator. */
|
|
43
43
|
export declare function locateNode(table: string, columns: readonly string[], scope: OperationNode): SelectQueryNode;
|
|
44
|
+
/** `select T.<name> from T where <scope> group by T.<name>`: each value of `name` the scoped rows hold, once. */
|
|
45
|
+
export declare function valuesNode(table: string, name: string, scope: OperationNode): SelectQueryNode;
|
|
44
46
|
/**
|
|
45
47
|
* The same check, locked: `for share` keeps the row from moving until the transaction that checked it ends, `for
|
|
46
48
|
* update` also keeps every other writer and locker of it waiting.
|
package/types/src/policy.d.ts
CHANGED
|
@@ -74,6 +74,15 @@ interface WritablePolicy<Col extends string, A extends string, V extends Col, Ac
|
|
|
74
74
|
readonly when?: {
|
|
75
75
|
readonly [action in A]?: ConditionPolicy<Col>;
|
|
76
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Relation → action → a condition on the rows that relation reaches for that action: it narrows the relation's terms
|
|
79
|
+
* only, never an IAM grant, a member reveal or a path grant of the action.
|
|
80
|
+
*/
|
|
81
|
+
readonly relationWhen?: {
|
|
82
|
+
readonly [relation: string]: {
|
|
83
|
+
readonly [action in A]?: ConditionPolicy<Col>;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
77
86
|
/** Relation of this table's own dimension, or of one it reads through → the ancestor node a row the relation reaches reveals. */
|
|
78
87
|
readonly reveals?: {
|
|
79
88
|
readonly [relation: string]: RevealsPolicy<Col, A>;
|
|
@@ -87,12 +96,36 @@ interface WritablePolicy<Col extends string, A extends string, V extends Col, Ac
|
|
|
87
96
|
readonly [dimension: string]: Col | `${Col}.${string}`;
|
|
88
97
|
};
|
|
89
98
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
99
|
+
* Dimension of `readThrough` → the actions a `Ref` held through that path holds on the table's rows, writes included:
|
|
100
|
+
* a grant of one of them at the node the path names, or above it, reaches the row for that action. Whoever inserts
|
|
101
|
+
* the path's column must hold every listed action at the node it names.
|
|
102
|
+
*/
|
|
103
|
+
readonly writeThrough?: {
|
|
104
|
+
readonly [dimension: string]: readonly A[];
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* This table's own dimension, or one it reads through (`readThrough`) → the ancestor node a row reveals to its
|
|
108
|
+
* members: a grant of one of `actions` at the row's own node, or at the node its path names, holds that action at its
|
|
109
|
+
* node in `to` too, while `when` admits the row.
|
|
92
110
|
*/
|
|
93
111
|
readonly memberReveals?: {
|
|
94
112
|
readonly [dimension: string]: MemberRevealsPolicy<Col, A>;
|
|
95
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Relation → an access view that lists the rows the relation reaches: the escape path for a rule no structured
|
|
116
|
+
* declaration expresses. The view's SQL decides; the layer binds only the caller's principal and the nodes it holds
|
|
117
|
+
* the relation inside, never a handler value.
|
|
118
|
+
*/
|
|
119
|
+
readonly access?: {
|
|
120
|
+
readonly [relation: string]: AccessPolicy;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** An access view: `row` names this table's key; `principal` is compared to the caller, `member` to the nodes it holds the relation inside. */
|
|
124
|
+
export interface AccessPolicy {
|
|
125
|
+
readonly view: string;
|
|
126
|
+
readonly row: string;
|
|
127
|
+
readonly principal?: string;
|
|
128
|
+
readonly member?: string;
|
|
96
129
|
}
|
|
97
130
|
/** What a row reveals to a caller with a grant at its node: its node in `to`, for `actions`, while `when` admits the row. */
|
|
98
131
|
export interface MemberRevealsPolicy<Col extends string, A extends string> {
|
|
@@ -100,6 +133,10 @@ export interface MemberRevealsPolicy<Col extends string, A extends string> {
|
|
|
100
133
|
readonly actions: readonly A[];
|
|
101
134
|
/** A condition on the revealing row, under the same path rule as an action's `when`. */
|
|
102
135
|
readonly when?: ConditionPolicy<Col>;
|
|
136
|
+
/** Through a path, on a table with an insert action: the writer picks the node, and `self` lets it pick its own. */
|
|
137
|
+
readonly assign?: {
|
|
138
|
+
readonly self?: true;
|
|
139
|
+
};
|
|
103
140
|
}
|
|
104
141
|
/**
|
|
105
142
|
* A row of the table that a relation reaches reveals its node in `to`, an ancestor dimension of its chain: the relation
|
|
@@ -309,12 +346,26 @@ export interface TableModel {
|
|
|
309
346
|
readonly confers: readonly RelationSource[];
|
|
310
347
|
/** The condition each action of the table holds a row under; an action without one is not narrowed. */
|
|
311
348
|
readonly when: Readonly<Record<string, ConditionModel>>;
|
|
349
|
+
/** Relation → action → the condition the rows that relation reaches hold for that action under; ANDed onto its terms only. */
|
|
350
|
+
readonly relationWhen: Readonly<Record<string, Readonly<Record<string, ConditionModel>>>>;
|
|
312
351
|
/** The ancestor nodes this table's rows reveal to a relation of its own dimension or of one it reads through. */
|
|
313
352
|
readonly reveals: readonly RevealModel[];
|
|
314
353
|
/** The secondary read paths: a dimension outside the chain, by the column that holds the row's node in it. */
|
|
315
354
|
readonly readThrough: readonly SecondaryPath[];
|
|
316
355
|
/** The ancestor nodes this table's rows reveal to a grant at their own node. */
|
|
317
356
|
readonly memberReveals: readonly MemberRevealModel[];
|
|
357
|
+
/** The access views of the relations whose reach a view's SQL decides. */
|
|
358
|
+
readonly access: readonly AccessModel[];
|
|
359
|
+
}
|
|
360
|
+
/** A relation's access view over this table: `T.<key> in (select V.<row> from V where <bindings>)`. */
|
|
361
|
+
export interface AccessModel {
|
|
362
|
+
readonly relation: string;
|
|
363
|
+
/** The relation's dimension: a hold inside a node of it alone binds `member`. */
|
|
364
|
+
readonly dimension: string;
|
|
365
|
+
readonly view: string;
|
|
366
|
+
readonly row: string;
|
|
367
|
+
readonly principal: string | undefined;
|
|
368
|
+
readonly member: string | undefined;
|
|
318
369
|
}
|
|
319
370
|
/**
|
|
320
371
|
* A read path to a dimension outside the chain: `column` holds a key of `table`, which owns `dimension` and lies in
|
|
@@ -331,6 +382,8 @@ export interface SecondaryPath {
|
|
|
331
382
|
* then the container's column, and the path is read as `T.<via column> in (select C.<key> from C where …)`.
|
|
332
383
|
*/
|
|
333
384
|
readonly via: ContainerHop | undefined;
|
|
385
|
+
/** The actions a `Ref` held through the path holds on the table's rows (`writeThrough`); a `Within` reads through every path. */
|
|
386
|
+
readonly writes: readonly string[];
|
|
334
387
|
}
|
|
335
388
|
/** The row's nearest containment column, and the table and key it names. */
|
|
336
389
|
export interface ContainerHop {
|
|
@@ -349,7 +402,7 @@ export interface RevealModel {
|
|
|
349
402
|
readonly key: string;
|
|
350
403
|
/**
|
|
351
404
|
* The secondary path whose node, or an ancestor of it, the relation's nodes match. A reveal matched through one holds
|
|
352
|
-
*
|
|
405
|
+
* a `Ref` of an action only where the path does (`writeThrough`).
|
|
353
406
|
*/
|
|
354
407
|
readonly path: SecondaryPath | undefined;
|
|
355
408
|
/** The bound on an insert's delegation through `path`: `undefined` when no handler inserts a row of the table. */
|
|
@@ -370,7 +423,14 @@ export interface RevealModel {
|
|
|
370
423
|
export interface MemberRevealModel {
|
|
371
424
|
readonly source: string;
|
|
372
425
|
readonly table: string;
|
|
426
|
+
/** The column a grant's nodes match: the table's key, or `path`'s column. */
|
|
373
427
|
readonly key: string;
|
|
428
|
+
/** The secondary path whose node a grant names; a `Ref` holds an action through it only where the path does. */
|
|
429
|
+
readonly path: SecondaryPath | undefined;
|
|
430
|
+
/** The bound on an insert's pick of the node through `path`: `undefined` when no handler inserts a row of the table. */
|
|
431
|
+
readonly assign: {
|
|
432
|
+
readonly self: boolean;
|
|
433
|
+
} | undefined;
|
|
374
434
|
readonly dimension: string;
|
|
375
435
|
readonly column: string;
|
|
376
436
|
readonly actions: readonly string[];
|
|
@@ -448,11 +508,24 @@ export declare function includes(names: readonly string[], name: unknown): boole
|
|
|
448
508
|
export declare function delegates(model: TableModel): boolean;
|
|
449
509
|
/**
|
|
450
510
|
* The tables whose rows hand out access, which no raw statement writes, lowercased as the tag compares names: a relation
|
|
451
|
-
* source
|
|
452
|
-
* write revives a node a stale grant still names; and the
|
|
453
|
-
* columns decide whom a source row names and what it
|
|
511
|
+
* source, a path reveal or a path column that holds actions (`writeThrough`), whose writer the layer bounds; a
|
|
512
|
+
* member-revealing table, whose key the layer generates so no write revives a node a stale grant still names; and the
|
|
513
|
+
* tables a principal path or a relation's condition reads, whose columns decide whom a source row names and what it
|
|
514
|
+
* confers.
|
|
454
515
|
*/
|
|
455
516
|
export declare function accessTablesOf(models: TableModels): readonly string[];
|
|
517
|
+
/** A path column whose insert hands out the listed actions at the node it names: the bound its writer is held to. */
|
|
518
|
+
export interface PathWriter {
|
|
519
|
+
readonly path: SecondaryPath;
|
|
520
|
+
/** The path's own `writes` and those of every table that reads the same dimension through this table's column. */
|
|
521
|
+
readonly actions: readonly string[];
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* The columns of `model` whose insert hands out actions through a secondary path: its own paths that hold actions, and
|
|
525
|
+
* its paths that a table below follows through it (`'<link>.<column>'`) with actions of its own. Such a table is written
|
|
526
|
+
* only through the handles, so no write sets the column past the bound.
|
|
527
|
+
*/
|
|
528
|
+
export declare function pathWriters(models: Readonly<Record<string, TableModel>>, model: TableModel): readonly PathWriter[];
|
|
456
529
|
/** The column of `table` that places a row at a node of `dimension`: its key for its own dimension, else a chain link. */
|
|
457
530
|
export declare function nodeColumnOf(table: Pick<TableModel, 'scope' | 'chain'>, dimension: string): string | undefined;
|
|
458
531
|
type PolicyOf<P, T> = T extends keyof P ? P[T] : never;
|
package/types/src/registry.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Admissions } from './admissions';
|
|
2
|
+
import type { ContainerGrant, RelationHold } from './capability';
|
|
2
3
|
import type { Session } from './database';
|
|
3
4
|
import type { WebhookTables } from './framework-tables';
|
|
4
5
|
import type { JobLeases } from './job-leases';
|
|
@@ -17,7 +18,21 @@ export type RelationCheck = (relation: string, node: string, principal: string)
|
|
|
17
18
|
* Whether a row `relation` reaches for `principal` reveals `node` of `dimension` now: what a Ref held through a reveal
|
|
18
19
|
* is minted on.
|
|
19
20
|
*/
|
|
20
|
-
export type RevealCheck = (relation: string, dimension: string, node: string, principal: string) => Promise<boolean>;
|
|
21
|
+
export type RevealCheck = (relation: string, dimension: string, node: string, principal: string, action: string) => Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Of `relations` and `paths`, the caller's relations and grants of `action` that reach the object `id` of `dimension`
|
|
24
|
+
* through a secondary path that holds the action for a Ref (`writeThrough`), or through a relation row or reveal: what a
|
|
25
|
+
* Ref held through a path is minted on, and carries.
|
|
26
|
+
*/
|
|
27
|
+
export type PathCheck = (dimension: string, id: string, action: string, principal: string, relations: readonly RelationHold[], paths: readonly ContainerGrant[]) => Promise<{
|
|
28
|
+
readonly relations: readonly RelationHold[];
|
|
29
|
+
readonly paths: readonly ContainerGrant[];
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Of `values`, the caller's grants of `action` at nodes of `revealing`, those whose row reveals `node` of `dimension` to
|
|
33
|
+
* its members now: what a Ref held through member reveals is minted on, and carries.
|
|
34
|
+
*/
|
|
35
|
+
export type MemberRevealCheck = (revealing: string, values: readonly string[], dimension: string, node: string, action: string) => Promise<readonly string[]>;
|
|
21
36
|
/** What the framework writes itself: its own `fabrika_*` tables. Usable once bound. */
|
|
22
37
|
export interface FrameworkTables {
|
|
23
38
|
readonly webhooks: WebhookTables;
|
|
@@ -34,6 +49,8 @@ export interface ProvisionalBinding {
|
|
|
34
49
|
readonly locate: Locator;
|
|
35
50
|
readonly relates: RelationCheck;
|
|
36
51
|
readonly reveals: RevealCheck;
|
|
52
|
+
readonly holdsThrough: PathCheck;
|
|
53
|
+
readonly revealsToMembers: MemberRevealCheck;
|
|
37
54
|
release(): void;
|
|
38
55
|
}
|
|
39
56
|
export interface FrameworkSide {
|