@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/guard.d.ts
CHANGED
|
@@ -18,6 +18,30 @@ export interface GuardContext {
|
|
|
18
18
|
readonly lock?: 'share' | 'update' | 'claim';
|
|
19
19
|
/** An insert that does nothing on a conflict of its listed columns: `on conflict (columns) do nothing`, and no other. */
|
|
20
20
|
readonly onConflict?: 'nothing';
|
|
21
|
+
/**
|
|
22
|
+
* The tables a scope predicate's subqueries may read, each with the columns one may select: a relation's source by
|
|
23
|
+
* its node column, a condition path's target by its key. Without it, a scope holds no subquery.
|
|
24
|
+
*/
|
|
25
|
+
readonly subqueries?: Readonly<Record<string, readonly string[]>>;
|
|
26
|
+
/**
|
|
27
|
+
* A child view's parent: its scope may read the view's rows through `<column> in (select P.<key> from P where <P's
|
|
28
|
+
* reach>)`. Without it, a scope holds no such subquery.
|
|
29
|
+
*/
|
|
30
|
+
readonly through?: ViewParentLink | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** The parent a child view's scope reads its rows through: the view's parent column, the parent table and its key. */
|
|
33
|
+
export interface ViewParentLink {
|
|
34
|
+
readonly column: string;
|
|
35
|
+
readonly table: string;
|
|
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;
|
|
21
45
|
}
|
|
22
46
|
/** Refuses any operation tree outside the allowlist. Runs on the final tree, immediately before it is compiled. */
|
|
23
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
|
@@ -8,6 +8,8 @@ export declare function allOf(nodes: readonly OperationNode[]): OperationNode;
|
|
|
8
8
|
/** One node, or the OR of several in a parenthesis: inside an AND, `a and b or c` would read as `(a and b) or c`. */
|
|
9
9
|
export declare function anyOf(nodes: readonly OperationNode[]): OperationNode;
|
|
10
10
|
export declare function inList(table: string, name: string, values: readonly string[]): OperationNode;
|
|
11
|
+
/** `($1, $2, …)`: bound values, as the right operand of an `in`. */
|
|
12
|
+
export declare function valueList(values: readonly string[]): OperationNode;
|
|
11
13
|
/** The scope of a `Within` that is not limited to scope values. */
|
|
12
14
|
export declare function everything(): OperationNode;
|
|
13
15
|
/** LIKE treats `\` as its escape character by default, so the text matches literally. */
|
|
@@ -39,6 +41,8 @@ export declare function existsNode(table: string, key: string, scope: OperationN
|
|
|
39
41
|
export declare function acknowledgementNode(table: string, key: string, version: string | undefined, where: WhereNode): SelectQueryNode;
|
|
40
42
|
/** `select columns from table where scope limit 1`: the containment columns of one object, for the framework's locator. */
|
|
41
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;
|
|
42
46
|
/**
|
|
43
47
|
* The same check, locked: `for share` keeps the row from moving until the transaction that checked it ends, `for
|
|
44
48
|
* update` also keeps every other writer and locker of it waiting.
|
package/types/src/orm-types.d.ts
CHANGED
|
@@ -173,6 +173,18 @@ type ChainDimensions<P, T, V> = PolicyOf<P, T> extends {
|
|
|
173
173
|
} ? DimensionOf<P, Parent> | ChainDimensions<P, Parent, V> : never : never;
|
|
174
174
|
/** The dimensions whose `Within` lists table `T`: every dimension of its chain, and a top-level table's own. */
|
|
175
175
|
type ReachOf<P, T, V> = [ContainerOf<P, T>] extends [never] ? DimensionOf<P, T> | ChainDimensions<P, T, V> : ChainDimensions<P, T, V>;
|
|
176
|
+
/**
|
|
177
|
+
* The dimensions outside its chain whose `Within` reads table `T` through a foreign key (`readThrough`); a child view's
|
|
178
|
+
* are its parent's, as it is read through its parent row.
|
|
179
|
+
*/
|
|
180
|
+
type ReadThroughOf<P, T> = PolicyOf<P, T> extends {
|
|
181
|
+
readonly readThrough: infer R;
|
|
182
|
+
} ? keyof R & string : PolicyOf<P, T> extends {
|
|
183
|
+
readonly view: true;
|
|
184
|
+
readonly scope: {
|
|
185
|
+
readonly child: infer Parent extends string;
|
|
186
|
+
};
|
|
187
|
+
} ? ReadThroughOf<P, Parent> : never;
|
|
176
188
|
/**
|
|
177
189
|
* A row as reads return it: the generated interface itself where no column has a separate write type, so a
|
|
178
190
|
* diagnostic names it (`DealsTable`), and Kysely's `Selectable` of it otherwise.
|
|
@@ -214,9 +226,12 @@ export type DbIndex<DB, P, V = unknown> = {
|
|
|
214
226
|
readonly listed: {
|
|
215
227
|
readonly [T in DimensionTableName<P> as ListDimensionOf<P, T>]: T;
|
|
216
228
|
};
|
|
217
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* Dimension → the tables an `over` of it lists: each whose containment chain holds it, a top-level table its own, and
|
|
231
|
+
* each that reads through it (`readThrough`).
|
|
232
|
+
*/
|
|
218
233
|
readonly within: {
|
|
219
|
-
readonly [T in DimensionTableName<P> | ChildTableName<P> as ReachOf<P, T, V>]: T;
|
|
234
|
+
readonly [T in DimensionTableName<P> | ChildTableName<P> as ReachOf<P, T, V> | ReadThroughOf<P, T>]: T;
|
|
220
235
|
};
|
|
221
236
|
readonly references: ReferenceTableName<P>;
|
|
222
237
|
/** The application tables: an `app` endpoint reads and writes them. */
|
package/types/src/policy.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Insertable, Selectable, SelectType, Updateable } from 'kysely';
|
|
2
2
|
import { type NameSet } from './builtins';
|
|
3
|
+
import { type ConditionModel, type ConditionPolicy } from './conditions';
|
|
3
4
|
import type { Unavailable } from './orm-types';
|
|
4
5
|
export type { RowOf } from './orm-types';
|
|
5
6
|
import type { ColumnTypes, ColumnViews, DefineVocabularyPolicies, TableVocabulary } from './vocabulary-tables';
|
|
@@ -65,6 +66,119 @@ interface WritablePolicy<Col extends string, A extends string, V extends Col, Ac
|
|
|
65
66
|
* file reference. The table's actions are the file's authority.
|
|
66
67
|
*/
|
|
67
68
|
readonly files?: FilePolicies<Col>;
|
|
69
|
+
/** The relations this table's rows confer (`relations` of the vocabulary): each row holds one principal at one node. */
|
|
70
|
+
readonly confers?: {
|
|
71
|
+
readonly [relation: string]: ConfersPolicy<Col>;
|
|
72
|
+
};
|
|
73
|
+
/** Conditions that narrow an action of this table: a row the condition does not admit is out of that action's reach. */
|
|
74
|
+
readonly when?: {
|
|
75
|
+
readonly [action in A]?: ConditionPolicy<Col>;
|
|
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
|
+
};
|
|
86
|
+
/** Relation of this table's own dimension, or of one it reads through → the ancestor node a row the relation reaches reveals. */
|
|
87
|
+
readonly reveals?: {
|
|
88
|
+
readonly [relation: string]: RevealsPolicy<Col, A>;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Dimension outside the chain → the foreign key column a read reaches a row through: a `Within` of the dimension, or a
|
|
92
|
+
* relation at it, reads the row, and every write follows containment only. No update writes the column. Or
|
|
93
|
+
* `<nearest container column>.<its column>`: the row is read through its nearest container's own read path.
|
|
94
|
+
*/
|
|
95
|
+
readonly readThrough?: {
|
|
96
|
+
readonly [dimension: string]: Col | `${Col}.${string}`;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
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.
|
|
110
|
+
*/
|
|
111
|
+
readonly memberReveals?: {
|
|
112
|
+
readonly [dimension: string]: MemberRevealsPolicy<Col, A>;
|
|
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;
|
|
129
|
+
}
|
|
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. */
|
|
131
|
+
export interface MemberRevealsPolicy<Col extends string, A extends string> {
|
|
132
|
+
readonly to: string;
|
|
133
|
+
readonly actions: readonly A[];
|
|
134
|
+
/** A condition on the revealing row, under the same path rule as an action's `when`. */
|
|
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
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A row of the table that a relation reaches reveals its node in `to`, an ancestor dimension of its chain: the relation
|
|
143
|
+
* then holds `actions` (those of them its roles list in `via`) there, while `when` admits the row.
|
|
144
|
+
*/
|
|
145
|
+
export interface RevealsPolicy<Col extends string, A extends string> {
|
|
146
|
+
readonly to: string;
|
|
147
|
+
readonly actions: readonly A[];
|
|
148
|
+
/** A condition on the revealing row, under the same path rule as an action's `when`. */
|
|
149
|
+
readonly when?: ConditionPolicy<Col>;
|
|
150
|
+
/**
|
|
151
|
+
* Required on a reveal matched through `readThrough` of a table with an insert action: the row's writer picks the node,
|
|
152
|
+
* so an insert delegates. Without `self`, an insert that names a node where its writer holds the relation is refused.
|
|
153
|
+
*/
|
|
154
|
+
readonly assign?: {
|
|
155
|
+
readonly self?: true;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A relation source: each row says that the principal in `principal` stands in the relation to the node `node` holds,
|
|
160
|
+
* until `expires` (none: no deadline) and while `when` admits the row. Writing a row is delegation.
|
|
161
|
+
*/
|
|
162
|
+
export interface ConfersPolicy<Col extends string> {
|
|
163
|
+
/**
|
|
164
|
+
* The column that holds the principal, or `<column>.<principal column>`: one foreign key of the table into the key of
|
|
165
|
+
* the table whose column holds it. The table's `createdBy` names the row's writer (it needs `assign.self`).
|
|
166
|
+
*/
|
|
167
|
+
readonly principal: Col | `${Col}.${string}`;
|
|
168
|
+
/** The column that names the node; by default the table's column for the relation's dimension (its key or its chain). */
|
|
169
|
+
readonly node?: Col;
|
|
170
|
+
/** A timestamp column: the row confers nothing once it passed. */
|
|
171
|
+
readonly expires?: Col;
|
|
172
|
+
/** A condition on the row's own columns (no foreign-key path): `{ revoked_at: { isNull: true } }`. */
|
|
173
|
+
readonly when?: ConditionPolicy<Col>;
|
|
174
|
+
/**
|
|
175
|
+
* Inserting a row delegates the relation's actions to its principal, bounded by the inserting Ref's node: at most
|
|
176
|
+
* `maxDays` ahead (which needs `expires`), and to the inserting principal itself only with `self`.
|
|
177
|
+
*/
|
|
178
|
+
readonly assign?: {
|
|
179
|
+
readonly maxDays?: number;
|
|
180
|
+
readonly self?: true;
|
|
181
|
+
};
|
|
68
182
|
}
|
|
69
183
|
/** A table's file columns: column → the name of a file kind of the contract (`c.files`). */
|
|
70
184
|
export type FilePolicies<Col extends string> = {
|
|
@@ -136,6 +250,11 @@ export interface TableColumns<Col extends string = string, Table extends string
|
|
|
136
250
|
readonly booleans?: readonly Col[];
|
|
137
251
|
/** The JSON columns (`jsonb`, or declared `JSONB` on SQLite), written as a JSON value and never compared; absent when none. */
|
|
138
252
|
readonly json?: readonly Col[];
|
|
253
|
+
/**
|
|
254
|
+
* The columns declared NOT NULL; absent when none. A foreign key that holds a row's tenant needs its ancestor columns
|
|
255
|
+
* among them: under MATCH SIMPLE a null in one skips the whole key.
|
|
256
|
+
*/
|
|
257
|
+
readonly notNull?: readonly Col[];
|
|
139
258
|
/** A view: read-only, with no foreign key; absent for a table. */
|
|
140
259
|
readonly view?: true;
|
|
141
260
|
}
|
|
@@ -212,6 +331,8 @@ export interface TableModel {
|
|
|
212
331
|
readonly booleans: NameSet;
|
|
213
332
|
/** The JSON columns: a write binds a JSON value's text, and no condition, order or aggregate names one. */
|
|
214
333
|
readonly json: NameSet;
|
|
334
|
+
/** The columns the column list declares NOT NULL. */
|
|
335
|
+
readonly notNull: NameSet;
|
|
215
336
|
/** The table's foreign keys, from the column list; a containment column must be one to its container's key. */
|
|
216
337
|
readonly foreignKeys: readonly ForeignKey[];
|
|
217
338
|
/** A view: a child or reference table no operation but a read reaches, whose containment only its SQL states. */
|
|
@@ -221,6 +342,122 @@ export interface TableModel {
|
|
|
221
342
|
* the container's own chain; a child's parent and the parent's chain. Every predicate of a Ref covers all.
|
|
222
343
|
*/
|
|
223
344
|
readonly chain: readonly Container[];
|
|
345
|
+
/** The relations this table's rows confer, each with its columns, its condition and its delegation bound. */
|
|
346
|
+
readonly confers: readonly RelationSource[];
|
|
347
|
+
/** The condition each action of the table holds a row under; an action without one is not narrowed. */
|
|
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>>>>;
|
|
351
|
+
/** The ancestor nodes this table's rows reveal to a relation of its own dimension or of one it reads through. */
|
|
352
|
+
readonly reveals: readonly RevealModel[];
|
|
353
|
+
/** The secondary read paths: a dimension outside the chain, by the column that holds the row's node in it. */
|
|
354
|
+
readonly readThrough: readonly SecondaryPath[];
|
|
355
|
+
/** The ancestor nodes this table's rows reveal to a grant at their own node. */
|
|
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;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* A read path to a dimension outside the chain: `column` holds a key of `table`, which owns `dimension` and lies in
|
|
372
|
+
* `chain`. The column's foreign key covers every ancestor the two chains share, so the node lies in the row's own tenant.
|
|
373
|
+
*/
|
|
374
|
+
export interface SecondaryPath {
|
|
375
|
+
readonly dimension: string;
|
|
376
|
+
readonly column: string;
|
|
377
|
+
readonly table: string;
|
|
378
|
+
readonly key: string;
|
|
379
|
+
readonly chain: readonly Container[];
|
|
380
|
+
/**
|
|
381
|
+
* The nearest container whose own path this is: the row's `column` of it, its `table` and `key`. `column` above is
|
|
382
|
+
* then the container's column, and the path is read as `T.<via column> in (select C.<key> from C where …)`.
|
|
383
|
+
*/
|
|
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[];
|
|
387
|
+
}
|
|
388
|
+
/** The row's nearest containment column, and the table and key it names. */
|
|
389
|
+
export interface ContainerHop {
|
|
390
|
+
readonly column: string;
|
|
391
|
+
readonly table: string;
|
|
392
|
+
readonly key: string;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* A row of `table` that `relation` reaches reveals its node in `dimension`, held in `column`: the relation holds
|
|
396
|
+
* `actions` at that node while `when` admits the row.
|
|
397
|
+
*/
|
|
398
|
+
export interface RevealModel {
|
|
399
|
+
readonly relation: string;
|
|
400
|
+
readonly table: string;
|
|
401
|
+
/** The table's key, which the relation's nodes match unless the reveal is matched through `path`. */
|
|
402
|
+
readonly key: string;
|
|
403
|
+
/**
|
|
404
|
+
* The secondary path whose node, or an ancestor of it, the relation's nodes match. A reveal matched through one holds
|
|
405
|
+
* a `Ref` of an action only where the path does (`writeThrough`).
|
|
406
|
+
*/
|
|
407
|
+
readonly path: SecondaryPath | undefined;
|
|
408
|
+
/** The bound on an insert's delegation through `path`: `undefined` when no handler inserts a row of the table. */
|
|
409
|
+
readonly assign: {
|
|
410
|
+
readonly self: boolean;
|
|
411
|
+
} | undefined;
|
|
412
|
+
readonly dimension: string;
|
|
413
|
+
readonly column: string;
|
|
414
|
+
readonly actions: readonly string[];
|
|
415
|
+
readonly when: ConditionModel | undefined;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* A row of `table`, a node of `source` (its own dimension, keyed by `key`), reveals its node in `dimension`, held in
|
|
419
|
+
* `column`: a grant of one of `actions` at the row's node holds the action there too, for a `Within`'s reads, while
|
|
420
|
+
* `when` admits the row. Only a grant at the node itself counts, never one at a container of it: an insert would
|
|
421
|
+
* otherwise reveal the ancestor to the container's members at once.
|
|
422
|
+
*/
|
|
423
|
+
export interface MemberRevealModel {
|
|
424
|
+
readonly source: string;
|
|
425
|
+
readonly table: string;
|
|
426
|
+
/** The column a grant's nodes match: the table's key, or `path`'s column. */
|
|
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;
|
|
434
|
+
readonly dimension: string;
|
|
435
|
+
readonly column: string;
|
|
436
|
+
readonly actions: readonly string[];
|
|
437
|
+
readonly when: ConditionModel | undefined;
|
|
438
|
+
}
|
|
439
|
+
/** One relation's source table: what a relation term reads, and what a write of its rows is bounded by. */
|
|
440
|
+
export interface RelationSource {
|
|
441
|
+
readonly relation: string;
|
|
442
|
+
readonly dimension: string;
|
|
443
|
+
readonly table: string;
|
|
444
|
+
/** The source's column that decides the principal: it holds it, or it references the row of `principalPath` that does. */
|
|
445
|
+
readonly principal: string;
|
|
446
|
+
readonly principalPath: PrincipalPath | undefined;
|
|
447
|
+
readonly node: string;
|
|
448
|
+
readonly expires: string | undefined;
|
|
449
|
+
readonly when: ConditionModel | undefined;
|
|
450
|
+
/** `undefined` when the table has no insert action, so no handler writes a row of it. */
|
|
451
|
+
readonly assign: {
|
|
452
|
+
readonly maxDays: number | undefined;
|
|
453
|
+
readonly self: boolean;
|
|
454
|
+
} | undefined;
|
|
455
|
+
}
|
|
456
|
+
/** `S.<principal>` references `key` of `table`, whose `column` holds the principal the source row names. */
|
|
457
|
+
export interface PrincipalPath {
|
|
458
|
+
readonly table: string;
|
|
459
|
+
readonly key: string;
|
|
460
|
+
readonly column: string;
|
|
224
461
|
}
|
|
225
462
|
/** Every table's model by name; read it through `modelOf`, never by a plain property access. */
|
|
226
463
|
export type TableModels = Readonly<Record<string, TableModel>>;
|
|
@@ -264,6 +501,33 @@ export declare function visibleFor(model: TableModel, action: string): readonly
|
|
|
264
501
|
export declare function updateActions(model: TableModel): readonly string[];
|
|
265
502
|
/** Whether `names` holds `name`: an operation's actions, the one way a policy check reads a list. */
|
|
266
503
|
export declare function includes(names: readonly string[], name: unknown): boolean;
|
|
504
|
+
/**
|
|
505
|
+
* A row of the table hands out access that its writer places: it confers a relation, reveals through a path, or reveals
|
|
506
|
+
* its ancestor to the grants at its node. Such a row is written only through the handles, and never moves.
|
|
507
|
+
*/
|
|
508
|
+
export declare function delegates(model: TableModel): boolean;
|
|
509
|
+
/**
|
|
510
|
+
* The tables whose rows hand out access, which no raw statement writes, lowercased as the tag compares names: a relation
|
|
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.
|
|
515
|
+
*/
|
|
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[];
|
|
529
|
+
/** The column of `table` that places a row at a node of `dimension`: its key for its own dimension, else a chain link. */
|
|
530
|
+
export declare function nodeColumnOf(table: Pick<TableModel, 'scope' | 'chain'>, dimension: string): string | undefined;
|
|
267
531
|
type PolicyOf<P, T> = T extends keyof P ? P[T] : never;
|
|
268
532
|
type ScopeOf<P, T> = PolicyOf<P, T> extends {
|
|
269
533
|
readonly scope: infer S;
|
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';
|
|
@@ -11,6 +12,27 @@ import type { StoredFiles } from './stored-files';
|
|
|
11
12
|
* the session to read in (a job's transaction, which sees the object it just wrote); a statement of its own otherwise.
|
|
12
13
|
*/
|
|
13
14
|
export type Locator = (dimension: string, id: string, using?: Session) => Promise<ReadonlyMap<string, string> | null>;
|
|
15
|
+
/** Whether an active row of `relation`'s source names `principal` at `node`: what a Ref held through it is minted on. */
|
|
16
|
+
export type RelationCheck = (relation: string, node: string, principal: string) => Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Whether a row `relation` reaches for `principal` reveals `node` of `dimension` now: what a Ref held through a reveal
|
|
19
|
+
* is minted on.
|
|
20
|
+
*/
|
|
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[]>;
|
|
14
36
|
/** What the framework writes itself: its own `fabrika_*` tables. Usable once bound. */
|
|
15
37
|
export interface FrameworkTables {
|
|
16
38
|
readonly webhooks: WebhookTables;
|
|
@@ -25,6 +47,10 @@ export interface FrameworkTables {
|
|
|
25
47
|
/** A connection of the layer and its locator. Only its holder can `release` it, which lets the layer be bound again. */
|
|
26
48
|
export interface ProvisionalBinding {
|
|
27
49
|
readonly locate: Locator;
|
|
50
|
+
readonly relates: RelationCheck;
|
|
51
|
+
readonly reveals: RevealCheck;
|
|
52
|
+
readonly holdsThrough: PathCheck;
|
|
53
|
+
readonly revealsToMembers: MemberRevealCheck;
|
|
28
54
|
release(): void;
|
|
29
55
|
}
|
|
30
56
|
export interface FrameworkSide {
|
package/types/src/sql.d.ts
CHANGED
|
@@ -59,9 +59,9 @@ export interface SqlSite {
|
|
|
59
59
|
* name outside `schema` and a function outside the reviewed built-ins; on SQLite also a `sqlite_*` name, and a
|
|
60
60
|
* parameter the text writes itself. workerd's authorizer bounds SQLite's functions, PRAGMAs and DDL.
|
|
61
61
|
*/
|
|
62
|
-
export declare function classifySql(parts: readonly string[], mode: SqlMode, database: SqlDatabase): string;
|
|
62
|
+
export declare function classifySql(parts: readonly string[], mode: SqlMode, database: SqlDatabase, sources?: readonly string[]): string;
|
|
63
63
|
/**
|
|
64
64
|
* `ctx.sql` of one site. Every call first checks that the work running now is the site's invocation, then classifies
|
|
65
65
|
* the text, then binds the values; only then does it reach the session, so a refused statement sends nothing.
|
|
66
66
|
*/
|
|
67
|
-
export declare function sqlTag(site: SqlSite, database: SqlDatabase, termsOf: ScopeOf): SqlTag;
|
|
67
|
+
export declare function sqlTag(site: SqlSite, database: SqlDatabase, termsOf: ScopeOf, sources: readonly string[]): SqlTag;
|
package/types/src/store.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type OperationNode, type ReturningNode } from 'kysely';
|
|
2
|
+
import { type MemberReveals, type PathRule, type RelationSources } from './authority';
|
|
2
3
|
import { type NameSet } from './builtins';
|
|
3
4
|
import { type AppGrant, type CapabilityAuthority, type Ref, type RefGrant, type Within, type WithinGrant } from './capability';
|
|
5
|
+
import { type ConditionModel } from './conditions';
|
|
4
6
|
import { type Database, type Session, type SqlDialect } from './database';
|
|
5
7
|
import { type ComparableColumn, type Compare, type Contains, type NoColumns, type Primitive, type ScopedSelect, type TableShape } from './description';
|
|
6
8
|
import { type FileBinding } from './file-columns';
|
|
7
|
-
import type { ForeignKeyPair, GuardContext, RootKind } from './guard';
|
|
8
|
-
import { type Acknowledgement, type ActionOf, type ChildTableName, type Container, type ContainerOf, type DimensionOf, type DimensionTableName, type InsertValues, type JoinableChildren, type ListDimensionOf, type MoveAcknowledgement, type Operation, type ParentOf, type PolicyRow, type TableModel, type TableModels, type Tables, type UpdateValues, type VersionArguments } from './policy';
|
|
9
|
+
import type { ForeignKeyPair, GuardContext, RootKind, ViewParentLink } from './guard';
|
|
10
|
+
import { type Acknowledgement, type ActionOf, type ChildTableName, type Container, type ContainerOf, type DimensionOf, type DimensionTableName, type InsertValues, type JoinableChildren, type ListDimensionOf, type MoveAcknowledgement, type Operation, type ParentOf, type PathWriter, type PolicyRow, type SecondaryPath, type TableModel, type TableModels, type Tables, type UpdateValues, type VersionArguments } from './policy';
|
|
9
11
|
import type { ScopeTerms, ScopeUse } from './sql';
|
|
10
12
|
import { type TablePolicies } from './tables';
|
|
11
13
|
import { type RowColumns } from './temporal';
|
|
@@ -34,6 +36,24 @@ export interface TableContext {
|
|
|
34
36
|
/** The model of each child a select may join, by its table name. */
|
|
35
37
|
readonly children: Readonly<Record<string, TableModel>>;
|
|
36
38
|
readonly connection: Connection;
|
|
39
|
+
/** Every relation of the layer with its source table: what a relation term of any table reads. */
|
|
40
|
+
readonly relations: RelationSources;
|
|
41
|
+
/** Every member reveal of the layer, by the dimension whose grants it reveals to: what a `Within`'s read adds. */
|
|
42
|
+
readonly members: MemberReveals;
|
|
43
|
+
/** The tables a scope predicate's subqueries read, each with the column they select: what the guard admits. */
|
|
44
|
+
readonly subqueries: Readonly<Record<string, readonly string[]>>;
|
|
45
|
+
/** A child view's parent, which every capability reads the view's rows through; `undefined` for any other table. */
|
|
46
|
+
readonly through: ViewParent | undefined;
|
|
47
|
+
/** The path columns whose insert hands out actions, each with the table owning the node it names (`pathWriters`). */
|
|
48
|
+
readonly writers: readonly PathBound[];
|
|
49
|
+
}
|
|
50
|
+
/** A path column an insert writes under its bound, and the table that owns the dimension it names. */
|
|
51
|
+
export interface PathBound extends PathWriter {
|
|
52
|
+
readonly owner: TableModel;
|
|
53
|
+
}
|
|
54
|
+
/** A child view's parent link, with the parent's context: its model without conditions, as only the view's own narrow a read. */
|
|
55
|
+
export interface ViewParent extends ViewParentLink {
|
|
56
|
+
readonly context: TableContext;
|
|
37
57
|
}
|
|
38
58
|
/** The dialect of the database the layer is bound to: what a read answers and a write binds depends on it. */
|
|
39
59
|
export declare function dialectOf(context: TableContext): SqlDialect;
|
|
@@ -63,21 +83,32 @@ export declare function requiredActions(context: TableContext, operation: Operat
|
|
|
63
83
|
export declare function checkAction(context: TableContext, operation: Operation, action: string): void;
|
|
64
84
|
/** The object a Ref of the model's own dimension names, with every link of its chain. */
|
|
65
85
|
export declare function selfLinks(model: TableModel): readonly Container[];
|
|
66
|
-
/** This object, over the whole chain the Ref carries. */
|
|
67
|
-
export declare function objectPredicate(context: TableContext, capability: unknown, operation: Operation): OperationNode;
|
|
86
|
+
/** This object, over the whole chain the Ref carries; through the secondary paths `paths` admits, by default its action's. */
|
|
87
|
+
export declare function objectPredicate(context: TableContext, capability: unknown, operation: Operation, paths?: PathRule): OperationNode;
|
|
68
88
|
/** Rows of a dimension table within the scope values of its list dimension. */
|
|
69
89
|
export declare function dimensionListPredicate(context: TableContext, capability: unknown, operation: Operation): OperationNode | undefined;
|
|
70
|
-
/**
|
|
71
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Rows of a child table that belong to the parent object the Ref names, over the whole chain; with `key`, the one row
|
|
92
|
+
* of them it keys. The key's equality joins the chain's, so the action's condition narrows both.
|
|
93
|
+
*/
|
|
94
|
+
export declare function parentPredicate(context: TableContext, grant: RefGrant, key?: string): OperationNode;
|
|
72
95
|
export declare function childListPredicate(context: TableContext, capability: unknown, operation: Operation): OperationNode | undefined;
|
|
73
96
|
/**
|
|
74
97
|
* The column that places a row of `model` in `dimension`: the column of that link of its containment chain, or a
|
|
75
98
|
* top-level table's own key; `undefined` when no `Within` of the dimension reaches the table.
|
|
76
99
|
*/
|
|
77
100
|
export declare function reachColumn(model: TableModel, dimension: string): string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Whether a `Within` of `dimension` lists the table: through its containment chain or a secondary path, and a child
|
|
103
|
+
* view through its parent's, its parent's own dimension included.
|
|
104
|
+
*/
|
|
105
|
+
export declare function reachedBy(context: TableContext, dimension: string): boolean;
|
|
106
|
+
/** The secondary read paths of `model` that reach `dimension`, a dimension outside its chain: at their node or above it. */
|
|
107
|
+
export declare function secondaryPathsOf(model: TableModel, dimension: string): readonly SecondaryPath[];
|
|
78
108
|
/**
|
|
79
109
|
* Rows of a table a `Within` of any dimension of its chain lists, by the table's read action: tasks under a `Within` of
|
|
80
|
-
* `org` through their stamped `org_id`, as under one of `project` through `project_id
|
|
110
|
+
* `org` through their stamped `org_id`, as under one of `project` through `project_id`; a `Within` of a dimension the
|
|
111
|
+
* table reaches through a secondary path, through that path's column.
|
|
81
112
|
*/
|
|
82
113
|
export declare function reachPredicate(context: TableContext, capability: unknown): OperationNode | undefined;
|
|
83
114
|
/**
|
|
@@ -112,7 +143,7 @@ export declare function appListPredicate(context: TableContext, capability: unkn
|
|
|
112
143
|
* Every row of an application table, for a `Ref` or a `Within` of its read action: what `ctx.db.app` of an `on`, `in`
|
|
113
144
|
* or `over` endpoint reads, read-only, as a reference table is read. The table's read action decides who reads it.
|
|
114
145
|
*/
|
|
115
|
-
export declare function scopedApplicationRead(context: TableContext, capability: unknown): OperationNode;
|
|
146
|
+
export declare function scopedApplicationRead(context: TableContext, capability: unknown, branch?: OperationNode | 'all'): OperationNode;
|
|
116
147
|
/** One row of an application table by its key, for an `app` capability of `operation`'s action. */
|
|
117
148
|
export declare function appRowPredicate(context: TableContext, capability: unknown, key: unknown, operation: Operation): OperationNode;
|
|
118
149
|
/**
|
|
@@ -128,6 +159,8 @@ export declare function claimScope(context: TableContext, capability: unknown):
|
|
|
128
159
|
* it was claimed, so a row moved since is not reached.
|
|
129
160
|
*/
|
|
130
161
|
export declare function claimedRowPredicate(context: TableContext, capability: unknown, operation: 'update' | 'delete'): OperationNode;
|
|
162
|
+
/** The row of an application table `key` names, as `action` reaches it: within the action's condition. */
|
|
163
|
+
export declare function appKeyScope(model: TableModel, action: string, key: unknown): OperationNode;
|
|
131
164
|
/** The row of an application table `key` names. */
|
|
132
165
|
export declare function appKeyPredicate(model: TableModel, key: unknown): OperationNode;
|
|
133
166
|
/**
|
|
@@ -170,7 +203,8 @@ export declare function versionArgument(context: TableContext, options: readonly
|
|
|
170
203
|
export declare function selectOne<O>(context: TableContext, run: Runner, scope: OperationNode, visible?: readonly string[], action?: string): Promise<O>;
|
|
171
204
|
export declare function answer(context: TableContext): ReturningNode;
|
|
172
205
|
export declare function keyOf(model: TableModel): string;
|
|
173
|
-
|
|
206
|
+
/** An insert, in a transaction that first locks its destination and judges its writer's bounds and its condition. */
|
|
207
|
+
export declare function insertRow<O>(context: TableContext, run: Runner, given: ReadonlyMap<string, Primitive | null>, prepared: Pick<PreparedInsert, 'destination' | 'writer' | 'judged' | 'narrowed'> | undefined): Promise<O>;
|
|
174
208
|
/**
|
|
175
209
|
* `insert(values, { onConflict: { columns, do } })`: on a conflict of `columns` (a unique index of the table), `nothing`
|
|
176
210
|
* writes nothing and `update` sets the columns the table's update action writes, from `updates`.
|
|
@@ -180,6 +214,8 @@ export interface OnConflict {
|
|
|
180
214
|
readonly mode: 'nothing' | 'update';
|
|
181
215
|
/** The values given for the table's update columns: what `update` sets on the conflicting row. */
|
|
182
216
|
readonly updates: ReadonlyMap<string, Primitive | null>;
|
|
217
|
+
/** The capability's action, whose condition the conflicting row must satisfy to be updated. */
|
|
218
|
+
readonly action: string;
|
|
183
219
|
}
|
|
184
220
|
/**
|
|
185
221
|
* The `onConflict` of an insert's options, read through own data properties; `undefined` without options. `'update'`
|
|
@@ -198,7 +234,17 @@ export interface Addressed {
|
|
|
198
234
|
* Zero changed rows → one follow-up read in the same transaction → 404 when the object is gone, else 409. An update
|
|
199
235
|
* that sets no column writes nothing, not even the version: it reads the acknowledgement under the same conditions.
|
|
200
236
|
*/
|
|
201
|
-
export declare function updateRow<O>(context: TableContext, run: Runner, target: Addressed, given: ReadonlyMap<string, Primitive | null>, expectedVersion: OperationNode | undefined,
|
|
237
|
+
export declare function updateRow<O>(context: TableContext, run: Runner, target: Addressed, given: ReadonlyMap<string, Primitive | null>, expectedVersion: OperationNode | undefined, moved?: MovedRow): Promise<O>;
|
|
238
|
+
/**
|
|
239
|
+
* A move's destination, locked before the write, and the destination's insert conditions, which judge the moved row
|
|
240
|
+
* after it as an insert into the destination judges its row: the insert action's (`judgeInserted`), and each one
|
|
241
|
+
* `relationWhen` puts on a relation the destination `Ref` holds through (`judgeNarrowed`).
|
|
242
|
+
*/
|
|
243
|
+
export interface MovedRow {
|
|
244
|
+
readonly destination: RefGrant;
|
|
245
|
+
readonly judged: JudgedInsert | undefined;
|
|
246
|
+
readonly narrowed: readonly NarrowedInsert[];
|
|
247
|
+
}
|
|
202
248
|
/** Like `updateRow`: under `expectVersion`, a row that changed is 409 and a missing one 404. */
|
|
203
249
|
export declare function removeRow(context: TableContext, run: Runner, target: Addressed, expectedVersion?: OperationNode): Promise<void>;
|
|
204
250
|
type Columns<Row> = keyof Row & string;
|
|
@@ -238,8 +284,23 @@ export declare function aggregateRows<Row, O>(context: TableContext, run: Runner
|
|
|
238
284
|
/** An insert's row, stamped from its capability, the destination it locks, and what it does on a conflict. */
|
|
239
285
|
export interface PreparedInsert {
|
|
240
286
|
readonly row: Map<string, Primitive | null>;
|
|
287
|
+
/** The principal the insert acts for: the bound of a reveal through a secondary path is judged against it. */
|
|
288
|
+
readonly writer: string;
|
|
241
289
|
readonly destination: RefGrant | undefined;
|
|
242
290
|
readonly conflict: OnConflict | undefined;
|
|
291
|
+
/** The insert action's condition when it follows a path: judged in the insert's transaction, on the rows it names. */
|
|
292
|
+
readonly judged: JudgedInsert | undefined;
|
|
293
|
+
/** The destination's relations whose `relationWhen` for the insert follows a path: judged on the written row. */
|
|
294
|
+
readonly narrowed: readonly NarrowedInsert[];
|
|
295
|
+
}
|
|
296
|
+
export interface JudgedInsert {
|
|
297
|
+
readonly action: string;
|
|
298
|
+
readonly condition: ConditionModel;
|
|
299
|
+
}
|
|
300
|
+
/** A relation the destination `Ref` holds through, which the inserted table narrows for the insert by a condition with a path. */
|
|
301
|
+
export interface NarrowedInsert {
|
|
302
|
+
readonly relation: string;
|
|
303
|
+
readonly condition: ConditionModel;
|
|
243
304
|
}
|
|
244
305
|
/**
|
|
245
306
|
* A dimension table's insert over a capability nobody type-checked: into a container (a new UUIDv7 key, the chain from
|
|
@@ -278,7 +339,9 @@ export declare class DimensionTable<DB, P, T extends string> {
|
|
|
278
339
|
/**
|
|
279
340
|
* Moves the object to another container: the delete action at the source, the insert action at the target,
|
|
280
341
|
* whose chain is checked against the database. Every chain column changes; children that copy them follow
|
|
281
|
-
* through `ON UPDATE CASCADE` on their composite foreign key.
|
|
342
|
+
* through `ON UPDATE CASCADE` on their composite foreign key. The moved row is judged by the insert action's
|
|
343
|
+
* condition and by the `relationWhen` of each relation the target holds through, as an insert into the target is.
|
|
344
|
+
* Answers the acknowledgement and the new chain.
|
|
282
345
|
*/
|
|
283
346
|
move(ref: Ref<DimensionOf<P, T>, ActionOf<P, T, 'delete'>>, to: Ref<ContainerOf<P, T>, ActionOf<P, T, 'insert'>>): Promise<MoveAcknowledgement<P, T>>;
|
|
284
347
|
aggregate<const S extends AggregateSpec<Row<DB, P, T>>>(within: Within<ListDimensionOf<P, T>, ReadAction<P, T>>, spec: S): Promise<AggregateRow<Row<DB, P, T>, S>[]>;
|