@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.
- package/package.json +4 -4
- package/src/authority.ts +539 -0
- package/src/builtins.ts +21 -0
- package/src/capability.ts +43 -0
- package/src/codegen.ts +11 -1
- package/src/condition-nodes.ts +119 -0
- package/src/conditions.ts +683 -0
- package/src/description.ts +3 -0
- package/src/framework.ts +1 -1
- package/src/guard.ts +365 -15
- package/src/index.ts +1 -0
- package/src/job-leases.ts +3 -2
- package/src/nodes.ts +21 -6
- package/src/orm-types.ts +13 -2
- package/src/orm.ts +85 -37
- package/src/policy.ts +1596 -39
- package/src/registry.ts +40 -0
- package/src/sql.ts +23 -5
- package/src/sqlite.ts +46 -1
- package/src/store.ts +1529 -69
- package/src/tables.ts +143 -2
- package/src/vocabulary-tables.ts +35 -1
- package/types/src/authority.d.ts +141 -0
- package/types/src/builtins.d.ts +2 -0
- package/types/src/capability.d.ts +42 -0
- package/types/src/condition-nodes.d.ts +9 -0
- package/types/src/conditions.d.ts +151 -0
- package/types/src/description.d.ts +3 -0
- package/types/src/framework.d.ts +1 -1
- package/types/src/guard.d.ts +24 -0
- package/types/src/index.d.ts +1 -1
- package/types/src/job-leases.d.ts +2 -1
- package/types/src/nodes.d.ts +4 -0
- package/types/src/orm-types.d.ts +17 -2
- package/types/src/policy.d.ts +264 -0
- package/types/src/registry.d.ts +26 -0
- package/types/src/sql.d.ts +2 -2
- package/types/src/store.d.ts +74 -11
- package/types/src/tables.d.ts +6 -0
- package/types/src/vocabulary-tables.d.ts +60 -2
package/types/src/tables.d.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
/**
|
|
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 {
|