@fabrika/db 0.9.0-dev.12 → 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.
@@ -15,6 +15,12 @@ export type { ColumnTypes, ColumnViews, DefineVocabularyPolicies, NormalizedPoli
15
15
  * `applicationRowRefusalText`.
16
16
  */
17
17
  export declare function applicationRowsPlan<DB, P>(tables: Tables<DB, P>, rows: Readonly<Record<string, Readonly<Record<string, unknown>>>>): ApplicationRowsPlan;
18
+ /**
19
+ * The tables whose rows hand out access, lowercased: a relation source or a path reveal, a member-revealing table, and
20
+ * the tables a principal path or a relation's condition reads. Only the data layer writes them; the migration classifier
21
+ * refuses database code that does.
22
+ */
23
+ export declare function accessTables<DB, P>(tables: Tables<DB, P>): readonly string[];
18
24
  /** Every table's policy in the form the contract artifact carries, by table name. */
19
25
  export type TablePolicies = Readonly<Record<string, TablePolicyArtifact>>;
20
26
  /** The artifact form of every policy `defineTables` (or `readTables`) checked. */
@@ -1,4 +1,5 @@
1
- import type { ColumnList, ColumnPolicies, FilePolicies, RecordActions, ReferencePolicy, TableAction, TableActions, Tables, VersionColumn } from './policy';
1
+ import type { ConditionPolicy } from './conditions';
2
+ import type { AccessPolicy, ColumnList, ColumnPolicies, ConfersPolicy, FilePolicies, MemberRevealsPolicy, RecordActions, ReferencePolicy, RevealsPolicy, TableAction, TableActions, Tables, VersionColumn } from './policy';
2
3
  declare const databaseType: unique symbol;
3
4
  declare const viewNames: unique symbol;
4
5
  /**
@@ -35,6 +36,11 @@ export interface TableVocabulary {
35
36
  readonly in?: string;
36
37
  };
37
38
  };
39
+ readonly relations?: {
40
+ readonly [relation: string]: {
41
+ readonly dimension: string;
42
+ };
43
+ };
38
44
  }
39
45
  export type VocabularyAction<V> = V extends {
40
46
  readonly actions: infer A;
@@ -92,6 +98,46 @@ interface WritableFields<Col extends string, A extends string, Ver extends Col,
92
98
  readonly columns?: ColumnPolicies<Col, A>;
93
99
  /** The file columns, each with the file kind it holds (`c.files`): a `uuid` foreign key to `fabrika_files`. */
94
100
  readonly files?: FilePolicies<Col>;
101
+ /** Relation → how a row of this table confers it: whom it names, at which node, until when. */
102
+ readonly confers?: {
103
+ readonly [relation: string]: ConfersPolicy<Col>;
104
+ };
105
+ /** Action → the condition a row must meet for it, whoever holds it. */
106
+ readonly when?: {
107
+ readonly [action in A]?: ConditionPolicy<Col>;
108
+ };
109
+ /** Relation → action → the condition a row that relation reaches must meet for it; IAM grants are not narrowed. */
110
+ readonly relationWhen?: {
111
+ readonly [relation: string]: {
112
+ readonly [action in A]?: ConditionPolicy<Col>;
113
+ };
114
+ };
115
+ /** Relation of the table's own dimension → the ancestor node a row it reaches reveals, and for which actions. */
116
+ readonly reveals?: {
117
+ readonly [relation: string]: RevealsPolicy<Col, A>;
118
+ };
119
+ /**
120
+ * Dimension outside the chain → the foreign key column a `Within`'s read reaches a row through, no update writes it; or
121
+ * `<nearest container column>.<its column>`, the nearest container's own path.
122
+ */
123
+ readonly readThrough?: {
124
+ readonly [dimension: string]: Col | `${Col}.${string}`;
125
+ };
126
+ /**
127
+ * Dimension of `readThrough` → the actions a `Ref` held through that path holds, writes included; whoever inserts the
128
+ * path's column must hold each at the node it names.
129
+ */
130
+ readonly writeThrough?: {
131
+ readonly [dimension: string]: readonly A[];
132
+ };
133
+ /** The table's own dimension → the ancestor node a row reveals to a grant at its node, for a `Within`'s reads. */
134
+ readonly memberReveals?: {
135
+ readonly [dimension: string]: MemberRevealsPolicy<Col, A>;
136
+ };
137
+ /** Relation → the access view that lists the rows it reaches: the escape path, decided by the view's SQL. */
138
+ readonly access?: {
139
+ readonly [relation: string]: AccessPolicy;
140
+ };
95
141
  }
96
142
  /**
97
143
  * The scope of the dimension the policy states (`S`, its scope as written); for any other name, the dimension alone,
@@ -172,9 +218,21 @@ interface ReadOnlyFields<Col extends string, A extends string> {
172
218
  };
173
219
  };
174
220
  }
175
- /** A view read as a child table: its parent's `Ref` and `Within` read it; nothing writes it (ADR-0072). */
221
+ /**
222
+ * A view read as a child table: its parent's `Ref` and `Within` read it; nothing writes it (ADR-0072). Its `when` and
223
+ * `relationWhen` narrow its read actions; a path may start at its parent column, to the parent row.
224
+ */
176
225
  type AuthoredChildViewPolicy<Table extends string, Col extends string, A extends string, S, P> = ReadOnlyFields<Col, A> & {
177
226
  readonly scope: ChildScopes<Table, Col, S, P>;
227
+ readonly when?: {
228
+ readonly [action in A]?: ConditionPolicy<Col>;
229
+ };
230
+ /** Relation → action → the condition a row the relation reaches through the parent row must meet for it. */
231
+ readonly relationWhen?: {
232
+ readonly [relation: string]: {
233
+ readonly [action in A]?: ConditionPolicy<Col>;
234
+ };
235
+ };
178
236
  };
179
237
  /** A view's policy as written: a read-only child, or a reference table every site reads. */
180
238
  export type VocabularyViewPolicy<Table extends string, Col extends string, A extends string, S = unknown, P = unknown> = S extends {