@fabrika/db 0.9.0-dev.19 → 0.9.0-dev.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/authority.ts +23 -2
- package/src/capability.ts +8 -2
- package/src/file-columns.ts +28 -10
- package/src/orm-types.ts +88 -28
- package/src/orm.ts +102 -71
- package/src/policy.ts +118 -7
- package/src/registry.ts +1 -1
- package/src/store.ts +392 -87
- package/src/tables.ts +2 -1
- package/src/testing-shared.ts +1 -1
- package/src/testing-sqlite.ts +1 -1
- package/src/vocabulary-tables.ts +2 -1
- package/types/src/authority.d.ts +6 -0
- package/types/src/capability.d.ts +8 -2
- package/types/src/file-columns.d.ts +3 -3
- package/types/src/orm-types.d.ts +54 -25
- package/types/src/policy.d.ts +54 -4
- package/types/src/registry.d.ts +1 -1
- package/types/src/store.d.ts +47 -18
- package/types/src/testing-shared.d.ts +1 -1
- package/types/src/testing-sqlite.d.ts +1 -1
- package/types/src/vocabulary-tables.d.ts +2 -2
package/src/tables.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
accessTablesOf,
|
|
22
22
|
type MemberRevealModel,
|
|
23
23
|
modelOf,
|
|
24
|
+
READ_ANY,
|
|
24
25
|
type RelationSource,
|
|
25
26
|
type RevealModel,
|
|
26
27
|
type ScopeModel,
|
|
@@ -174,7 +175,7 @@ function artifactOf(model: TableModel): TablePolicyArtifact {
|
|
|
174
175
|
return {
|
|
175
176
|
scope: scopeOf(model.scope),
|
|
176
177
|
actions: {
|
|
177
|
-
read: actionArtifact(model.actions.read) ?? noReadAction(model.name),
|
|
178
|
+
read: model.actions.readAny ? READ_ANY : actionArtifact(model.actions.read) ?? noReadAction(model.name),
|
|
178
179
|
insert: actionArtifact(model.actions.insert),
|
|
179
180
|
update: actionArtifact(model.actions.update),
|
|
180
181
|
delete: actionArtifact(model.actions.delete),
|
package/src/testing-shared.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type SampleValue = Primitive | null
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* A seeded value as a backend binds it: a JSON column's value as the JSON text the layer would write for it, so a
|
|
22
|
-
* seeded row and the
|
|
22
|
+
* seeded row and the kits' cases that write the same value through the layer hold the same JSON.
|
|
23
23
|
*/
|
|
24
24
|
export function seedBinding(columns: readonly SeedColumn[], table: string, name: string, value: SampleValue): SampleValue {
|
|
25
25
|
if (value === null || !columns.some((column) => column.table === table && column.name === name && column.json)) return value
|
package/src/testing-sqlite.ts
CHANGED
|
@@ -542,7 +542,7 @@ function applicationMigrations(directory: string): SqliteMigrationBundle['migrat
|
|
|
542
542
|
/**
|
|
543
543
|
* A fresh in-memory database with the framework's and the application's migrations applied by the runner a Durable
|
|
544
544
|
* Object boots with (`@fabrika/db/sqlite-migrate`), opened with its engine (`@fabrika/db/sqlite`). Never `null`: it
|
|
545
|
-
* needs no backend, so it never skips; its type is still assignable to `@fabrika/db/testing`'s, so a
|
|
545
|
+
* needs no backend, so it never skips; its type is still assignable to `@fabrika/db/testing`'s, so a test
|
|
546
546
|
* that checks for `null` compiles against both kits.
|
|
547
547
|
*/
|
|
548
548
|
export async function testDatabase(options: TestDatabaseOptions): Promise<TestDatabase> {
|
package/src/vocabulary-tables.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type { ConditionPolicy } from './conditions'
|
|
5
5
|
import type {
|
|
6
6
|
AccessPolicy,
|
|
7
|
+
ApplicationActions,
|
|
7
8
|
ColumnList,
|
|
8
9
|
ColumnPolicies,
|
|
9
10
|
ConfersPolicy,
|
|
@@ -218,7 +219,7 @@ type ReferenceViewPolicy<Col extends string, A extends string> = ReferencePolicy
|
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
/** An application table's scope: why its rows belong to no dimension; `key` defaults to `id`. */
|
|
221
|
-
type AuthoredApplicationPolicy<Col extends string, A extends string, Ver extends Col> = WritableFields<Col, A, Ver
|
|
222
|
+
type AuthoredApplicationPolicy<Col extends string, A extends string, Ver extends Col> = WritableFields<Col, A, Ver, ApplicationActions<A>> & {
|
|
222
223
|
readonly scope: { readonly app: string } & KeyField<Col>
|
|
223
224
|
}
|
|
224
225
|
|
package/types/src/authority.d.ts
CHANGED
|
@@ -101,6 +101,12 @@ export declare function actionCondition(model: TableModel, action: string, now:
|
|
|
101
101
|
* one shape the guard admits a condition in, so a condition never stands in for the reach.
|
|
102
102
|
*/
|
|
103
103
|
export declare function conditioned(model: TableModel, action: string, branch: OperationNode | 'all', now: Date): OperationNode;
|
|
104
|
+
/**
|
|
105
|
+
* `branch`, narrowed as one role holding `actions` is: `<reach> and ((<when a>) or (<when b>))`, a row passing where any
|
|
106
|
+
* action's condition admits it, and unnarrowed when one of them has none. `actions` are those that allow the operation,
|
|
107
|
+
* at least one; for one action this is `conditioned`.
|
|
108
|
+
*/
|
|
109
|
+
export declare function conditionedAny(model: TableModel, actions: readonly string[], branch: OperationNode | 'all', now: Date): OperationNode;
|
|
104
110
|
/**
|
|
105
111
|
* A Ref's predicate over `links` of `model`: one equality per link of its chain (after `row`, the equality that
|
|
106
112
|
* addresses one row by its key), then, when the Ref is held through relations or member reveals, a row of one of them
|
|
@@ -112,11 +112,17 @@ export interface WithinGrant {
|
|
|
112
112
|
*/
|
|
113
113
|
readonly revealing: readonly ContainerGrant[];
|
|
114
114
|
}
|
|
115
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* An `app` endpoint's grant: the actions held everywhere in the application, which the proxy checked were held globally.
|
|
117
|
+
* One action for `access: { action, app: true }`; for `anyOf`, every listed action the caller holds, which act as the
|
|
118
|
+
* actions of one role: an operation, a column or a `when` admits the grant when one of them admits it.
|
|
119
|
+
*/
|
|
116
120
|
export interface AppGrant {
|
|
117
121
|
readonly kind: 'app';
|
|
118
|
-
readonly
|
|
122
|
+
readonly actions: readonly [string, ...string[]];
|
|
119
123
|
readonly principal: string;
|
|
124
|
+
/** A public procedure's workload: it reaches only the tables that name its action, never one read with `'any'`. */
|
|
125
|
+
readonly public: boolean;
|
|
120
126
|
}
|
|
121
127
|
/** A row a claim leased: the table, its key, and the containment it had then, column by column. */
|
|
122
128
|
export interface RowGrant {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type NameSet } from './builtins';
|
|
2
2
|
import { type Session } from './database';
|
|
3
3
|
import type { Primitive } from './description';
|
|
4
|
-
import type
|
|
4
|
+
import { type ReadReach, type TableModel } from './policy';
|
|
5
5
|
/** Where a site's file references belong, and what claiming a pending one needs. */
|
|
6
6
|
export interface FileBinding {
|
|
7
7
|
/** The work a reference of this site belongs to: one request, or one job attempt. */
|
|
@@ -14,11 +14,11 @@ export interface FileBinding {
|
|
|
14
14
|
scans(kind: string): boolean;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* Puts a file reference in each file column of `rows`, read
|
|
17
|
+
* Puts a file reference in each file column of `rows`, read under `reach` in `session`: one statement loads every
|
|
18
18
|
* file's metadata. Without a binding (a store's own runner) the columns keep their ids. `held` (a queue claim's) adds
|
|
19
19
|
* the actions the site holds over the whole application: a reference is readable when one of them reads the table.
|
|
20
20
|
*/
|
|
21
|
-
export declare function answerFiles<R>(model: TableModel, binding: FileBinding | undefined, session: Session, rows: R[],
|
|
21
|
+
export declare function answerFiles<R>(model: TableModel, binding: FileBinding | undefined, session: Session, rows: R[], reach: ReadReach, held?: NameSet): Promise<R[]>;
|
|
22
22
|
/**
|
|
23
23
|
* A write's value for a file column: `null`, or the id of a file reference of the column's kind. A string id, a copied
|
|
24
24
|
* object or a reference of another kind is refused; whether the site holds it is checked where the write runs.
|
package/types/src/orm-types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Selectable, Updateable } from 'kysely';
|
|
|
2
2
|
import type { RowRef } from './capability';
|
|
3
3
|
import type { ComparableColumn, ConditionTuple } from './description';
|
|
4
4
|
import type { FileReference } from './file-references';
|
|
5
|
-
import type { ActionOf, ApplicationTableName, ChildTableName, ContainerOf, DimensionOf, DimensionTableName, InsertValues, ListDimensionOf, ParentOf, Tables, UpdateValues } from './policy';
|
|
5
|
+
import type { ActionOf, ApplicationTableName, ChildTableName, ContainerOf, DimensionOf, DimensionTableName, InsertValues, ListDimensionOf, ParentOf, ReadsAny, Tables, UpdateValues } from './policy';
|
|
6
6
|
import type { AggregateRow, AggregateSpec } from './store';
|
|
7
7
|
import type { VocabularyContainerOf } from './vocabulary-tables';
|
|
8
8
|
/** A member an endpoint may not use. It has no call signature, so a call fails at its line with this message. */
|
|
@@ -74,12 +74,15 @@ export interface IndexedTable {
|
|
|
74
74
|
readonly list: string;
|
|
75
75
|
/** A child table's parent table. */
|
|
76
76
|
readonly parent: string;
|
|
77
|
+
/** `read` is `never` for a table read with `'any'` (`readsAny`). */
|
|
77
78
|
readonly actions: {
|
|
78
79
|
readonly read: string;
|
|
79
80
|
readonly insert: string;
|
|
80
81
|
readonly update: string;
|
|
81
82
|
readonly delete: string;
|
|
82
83
|
};
|
|
84
|
+
/** An application table read with `'any'`: every `app` endpoint, job and webhook reads it, no public procedure or scoped site. */
|
|
85
|
+
readonly readsAny: boolean;
|
|
83
86
|
/** The actions besides `read` with which an `app` endpoint lists every row (`actions.appRead`). */
|
|
84
87
|
readonly appRead: string;
|
|
85
88
|
/** The actions with which an `app` endpoint only counts every row (`actions.appCount`). */
|
|
@@ -115,6 +118,7 @@ type IndexedTableOf<DB, P, T extends keyof P & keyof DB & string, V = unknown> =
|
|
|
115
118
|
readonly update: ActionOf<P, T, 'update'>;
|
|
116
119
|
readonly delete: ActionOf<P, T, 'delete'>;
|
|
117
120
|
};
|
|
121
|
+
readonly readsAny: ReadsAny<P, T>;
|
|
118
122
|
readonly appRead: AppActionsOf<P, T, 'appRead'>;
|
|
119
123
|
readonly appCount: AppActionsOf<P, T, 'appCount'>;
|
|
120
124
|
readonly row: WithFiles<RowType<DB[T]>, FileColumnsOf<P, T>>;
|
|
@@ -344,19 +348,31 @@ export interface ClaimedRowHandle<T extends string, E extends IndexedTable, A ex
|
|
|
344
348
|
/** The actions table `E` names: its read, insert, update and delete actions, and each column's own write action. */
|
|
345
349
|
type NamedActions<E extends IndexedTable> = (E['actions'][keyof E['actions']] | keyof E['writes']) & string;
|
|
346
350
|
type Names<E extends IndexedTable, A extends string> = [A] extends [NamedActions<E>] ? true : false;
|
|
351
|
+
/**
|
|
352
|
+
* Whether an action of `A` is one of `Allowed`. An `app` capability of several actions, an `anyOf` endpoint's, allows
|
|
353
|
+
* what any of them allows, as one role holding them; the runtime refuses an operation none of the held ones allows.
|
|
354
|
+
*/
|
|
355
|
+
type AnyAllowed<A extends string, Allowed> = [Extract<A, Allowed>] extends [never] ? false : true;
|
|
356
|
+
/** `U`'s members as one object: the columns any action of an `app` capability updates, with their values. */
|
|
357
|
+
type Merged<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
|
|
347
358
|
type Operation = 'insert' | 'update' | 'delete';
|
|
348
|
-
/**
|
|
349
|
-
|
|
359
|
+
/**
|
|
360
|
+
* `Member` in a mutation whose action is the table's `Op` action (`Allowed`, any action of an `app` capability's);
|
|
361
|
+
* otherwise the message that says which fix applies.
|
|
362
|
+
*/
|
|
363
|
+
type Write<T extends string, E extends IndexedTable, Op extends Operation, A extends string, K extends DataKind, Member, Allowed extends boolean = [A] extends [E['actions'][Op]] ? true : false> = K extends 'mutation' ? Allowed extends true ? Member : Unavailable<`${Op} on ${T} needs the action '${E['actions'][Op] & string}', and this endpoint holds '${A}'`> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<`${Op extends 'delete' ? 'remove' : Op} writes, so it runs only in a mutation: declare the endpoint with r.mutation`>;
|
|
350
364
|
/** What an update of `T` needs, for a capability of `A` that updates nothing of it. */
|
|
351
365
|
type UpdateRefusal<T extends string, E extends IndexedTable, A extends string> = [Exclude<keyof E['writes'], E['actions']['update']>] extends [never] ? `update on ${T} needs the action '${E['actions']['update'] & string}', and this endpoint holds '${A}'` : [E['actions']['update']] extends [never] ? `update on ${T} needs a column's own write action, and this endpoint holds '${A}'` : `update on ${T} needs the action '${E['actions']['update'] & string}' or a column's own write action, and this endpoint holds '${A}'`;
|
|
352
366
|
/**
|
|
353
367
|
* `Member` in a mutation whose action updates columns of the table (the update action, or a column's own write
|
|
354
|
-
* action); otherwise the message that says which fix applies.
|
|
368
|
+
* action; `Allowed`, any action of an `app` capability's); otherwise the message that says which fix applies.
|
|
355
369
|
*/
|
|
356
|
-
type Update<T extends string, E extends IndexedTable, A extends string, K extends DataKind, Member
|
|
370
|
+
type Update<T extends string, E extends IndexedTable, A extends string, K extends DataKind, Member, Allowed extends boolean = [A] extends [keyof E['writes']] ? true : false> = K extends 'mutation' ? Allowed extends true ? Member : Unavailable<UpdateRefusal<T, E, A>> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<'update writes, so it runs only in a mutation: declare the endpoint with r.mutation'>;
|
|
357
371
|
/** An update's values: any non-empty subset of the columns a capability of `A` updates; an empty one is refused. */
|
|
358
372
|
type UpdateValuesOf<E extends IndexedTable, A extends string> = E['writes'][A & keyof E['writes']];
|
|
359
|
-
|
|
373
|
+
/** An `app` capability's update values: the columns any of its actions updates, one action's as `UpdateValuesOf`. */
|
|
374
|
+
type AppUpdateValuesOf<E extends IndexedTable, A extends string> = Merged<UpdateValuesOf<E, A>>;
|
|
375
|
+
type Read<T extends string, E extends IndexedTable, A extends string, Member, Allowed extends boolean = Names<E, A>> = Allowed extends true ? Member : Unavailable<`${T} does not name the action '${A}': read it from an endpoint whose action ${T} names, or declare unscoped`>;
|
|
360
376
|
/** One page of a keyset list; `next` is the cursor `after` takes, `null` on the last page. */
|
|
361
377
|
export interface ListPage<Row> {
|
|
362
378
|
readonly items: Row[];
|
|
@@ -442,22 +458,35 @@ type ListRefusal<T extends string, E extends IndexedTable, A extends string> = `
|
|
|
442
458
|
export type WithinTables<Ix extends AnyDbIndex, D extends string, A extends string, K extends DataKind> = {
|
|
443
459
|
readonly [T in WithinIn<Ix, D>]: WithinRows<T, Ix['tables'][T], A, K>;
|
|
444
460
|
};
|
|
445
|
-
/**
|
|
461
|
+
/**
|
|
462
|
+
* `Member` where `ctx.db.app` of action `A` lists the application table: by its read action, or any action for `'any'`;
|
|
463
|
+
* an action of `A`'s does for an `anyOf` endpoint.
|
|
464
|
+
*/
|
|
465
|
+
type AppList<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Member : AnyAllowed<A, E['actions']['read']> extends true ? Member : Unavailable<ListRefusal<T, E, A>>;
|
|
466
|
+
/** `Member` where `ctx.db.app` of action `A` (any of them) reads a row of the application table by its key. */
|
|
467
|
+
type AppGet<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Member : Read<T, E, A, Member, AnyAllowed<A, NamedActions<E>>>;
|
|
468
|
+
/** `Member` where a public procedure of action `A` reads the application table: under its read action, never `'any'`. */
|
|
469
|
+
type PublicRead<T extends string, E extends IndexedTable, A extends string, Member> = [E['readsAny']] extends [true] ? Unavailable<`a public procedure does not read ${T}: it is read with 'any', which an app endpoint, a job and a webhook hold`> : A extends E['actions']['read'] ? Member : Unavailable<ListRefusal<T, E, A>>;
|
|
470
|
+
/**
|
|
471
|
+
* An application table under the capability of an `app` endpoint of action `A`, in a site of kind `K`; an `anyOf`
|
|
472
|
+
* endpoint's `A` is its listed actions, and an operation any of them allows is typed. A column with its own read action
|
|
473
|
+
* stays hidden there (`RowFor`): which listed actions the caller holds is known only at run time.
|
|
474
|
+
*/
|
|
446
475
|
export interface ApplicationRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
|
|
447
|
-
readonly list:
|
|
448
|
-
readonly count:
|
|
449
|
-
readonly aggregate:
|
|
476
|
+
readonly list: AppList<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>;
|
|
477
|
+
readonly count: AppList<T, E, A, (options?: CountOptions<RowFor<E, A>>) => Promise<number>>;
|
|
478
|
+
readonly aggregate: AppList<T, E, A, <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>>;
|
|
450
479
|
/** One row by its key; a column that declares another read action than `A` is hidden. */
|
|
451
|
-
readonly get:
|
|
480
|
+
readonly get: AppGet<T, E, A, (key: string) => Promise<RowFor<E, A>>>;
|
|
452
481
|
/** `SELECT … FOR UPDATE` of one row by its key: a precondition read that no concurrent write overtakes. */
|
|
453
|
-
readonly getForUpdate: K extends 'mutation' ?
|
|
482
|
+
readonly getForUpdate: K extends 'mutation' ? AppGet<T, E, A, (key: string) => Promise<RowFor<E, A>>> : K extends 'job' ? Unavailable<'a job writes inside ctx.transaction((tx) => …): use tx.db there'> : Unavailable<'getForUpdate locks the row, so it runs only in a mutation: declare the endpoint with r.mutation'>;
|
|
454
483
|
/** Leases due rows of a queue table: a job's drain, before its transactions. */
|
|
455
484
|
readonly claim: Claim<T, E, A, K>;
|
|
456
|
-
readonly insert: Write<T, E, 'insert', A, K, InsertMethod<E>>;
|
|
485
|
+
readonly insert: Write<T, E, 'insert', A, K, InsertMethod<E>, AnyAllowed<A, E['actions']['insert']>>;
|
|
457
486
|
readonly update: Update<T, E, A, K, (key: string, values: {
|
|
458
|
-
[C in keyof
|
|
459
|
-
}, ...version: VersionArguments<E>) => Promise<Saved<E
|
|
460
|
-
readonly remove: Write<T, E, 'delete', A, K, (key: string, ...version: VersionArguments<E>) => Promise<void>>;
|
|
487
|
+
[C in keyof AppUpdateValuesOf<E, A>]: AppUpdateValuesOf<E, A>[C];
|
|
488
|
+
}, ...version: VersionArguments<E>) => Promise<Saved<E>>, AnyAllowed<A, keyof E['writes']>>;
|
|
489
|
+
readonly remove: Write<T, E, 'delete', A, K, (key: string, ...version: VersionArguments<E>) => Promise<void>, AnyAllowed<A, E['actions']['delete']>>;
|
|
461
490
|
}
|
|
462
491
|
/**
|
|
463
492
|
* A public procedure's insert: it answers the new row's key (and version), which the data layer generated, and reads
|
|
@@ -480,10 +509,10 @@ type PublicVersioned<T extends string, E extends IndexedTable, Member> = E['vers
|
|
|
480
509
|
* under `expectVersion`; never locked or claimed.
|
|
481
510
|
*/
|
|
482
511
|
export interface PublicApplicationRows<T extends string, E extends IndexedTable, A extends string, K extends DataKind> {
|
|
483
|
-
readonly list:
|
|
484
|
-
readonly count:
|
|
485
|
-
readonly aggregate:
|
|
486
|
-
readonly get:
|
|
512
|
+
readonly list: PublicRead<T, E, A, (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>>>;
|
|
513
|
+
readonly count: PublicRead<T, E, A, (options?: CountOptions<RowFor<E, A>>) => Promise<number>>;
|
|
514
|
+
readonly aggregate: PublicRead<T, E, A, <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]>>;
|
|
515
|
+
readonly get: PublicRead<T, E, A, (key: string) => Promise<RowFor<E, A>>>;
|
|
487
516
|
readonly getForUpdate: PublicRefusal<'lock'>;
|
|
488
517
|
readonly claim: PublicRefusal<'claim'>;
|
|
489
518
|
/** By the id a verified signed token of the request carries; answers only the new version. */
|
|
@@ -509,9 +538,9 @@ export type PublicApplicationTables<Ix extends AnyDbIndex, A extends string, K e
|
|
|
509
538
|
* (`RowFor`), or only how many rows match. A count-only action has no `aggregate`: a group or a minimum is a value.
|
|
510
539
|
*/
|
|
511
540
|
export interface AppRecordRows<T extends string, E extends IndexedTable, A extends string> {
|
|
512
|
-
readonly list:
|
|
513
|
-
readonly count:
|
|
514
|
-
readonly aggregate:
|
|
541
|
+
readonly list: AnyAllowed<A, E['actions']['read'] | E['appRead']> extends true ? (options?: ListOptions<RowFor<E, A>>) => Promise<ListPage<RowFor<E, A>>> : Unavailable<`a list of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead, and this endpoint holds '${A}'`>;
|
|
542
|
+
readonly count: AnyAllowed<A, E['actions']['read'] | E['appRead'] | E['appCount']> extends true ? (options?: CountOptions<RowFor<E, A>>) => Promise<number> : Unavailable<`a count of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead or appCount, and this endpoint holds '${A}'`>;
|
|
543
|
+
readonly aggregate: AnyAllowed<A, E['actions']['read'] | E['appRead']> extends true ? <const S extends AggregateSpec<RowFor<E, A>>>(spec: S) => Promise<AggregateRow<RowFor<E, A>, S>[]> : Unavailable<`an aggregate of ${T} needs its read action '${E['actions']['read'] & string}' or an action of its appRead, and this endpoint holds '${A}': an appCount action only counts`>;
|
|
515
544
|
}
|
|
516
545
|
/**
|
|
517
546
|
* `ctx.db.app` of an `app` endpoint: every application table, and every dimension and child table read-only, all
|
|
@@ -545,7 +574,7 @@ export interface ScopedApplicationRows<E extends IndexedTable> {
|
|
|
545
574
|
* read-only; any other is the message that names its read action.
|
|
546
575
|
*/
|
|
547
576
|
export type ScopedApplicationTables<Ix extends AnyDbIndex, A extends string> = {
|
|
548
|
-
readonly [T in Ix['applications']]: [A] extends [Ix['tables'][T]['actions']['read']] ? ScopedApplicationRows<Ix['tables'][T]> : Unavailable<`a scoped endpoint reads ${T} with its read action '${Ix['tables'][T]['actions']['read'] & string}', and this endpoint holds '${A}'`>;
|
|
577
|
+
readonly [T in Ix['applications']]: [Ix['tables'][T]['readsAny']] extends [true] ? Unavailable<`a scoped endpoint does not read ${T}: it is read with 'any', which an app endpoint, a job and a webhook hold`> : [A] extends [Ix['tables'][T]['actions']['read']] ? ScopedApplicationRows<Ix['tables'][T]> : Unavailable<`a scoped endpoint reads ${T} with its read action '${Ix['tables'][T]['actions']['read'] & string}', and this endpoint holds '${A}'`>;
|
|
549
578
|
};
|
|
550
579
|
/** A reference table: every endpoint reads it, through its read action, and none writes it. */
|
|
551
580
|
export interface ReferenceRows<E extends IndexedTable> {
|
|
@@ -634,7 +663,7 @@ type WithinFragment<Ix extends AnyDbIndex, D extends string, A extends string, M
|
|
|
634
663
|
}[TableName<Ix>];
|
|
635
664
|
/** The tables a fragment of an `app` capability of `A` reaches: as `ctx.db.app` lists them for that action. */
|
|
636
665
|
type AppFragment<Ix extends AnyDbIndex, A extends string> = {
|
|
637
|
-
[T in TableName<Ix>]: Ix['tables'][T]['mode'] extends 'app' ? (A extends NamedActions<Ix['tables'][T]> ? T : never) : Ix['tables'][T]['mode'] extends 'dimension' | 'child' ? (A extends Ix['tables'][T]['actions']['read'] | Ix['tables'][T]['appRead'] ? T : never) : never;
|
|
666
|
+
[T in TableName<Ix>]: Ix['tables'][T]['mode'] extends 'app' ? ([Ix['tables'][T]['readsAny']] extends [true] ? T : A extends NamedActions<Ix['tables'][T]> ? T : never) : Ix['tables'][T]['mode'] extends 'dimension' | 'child' ? (A extends Ix['tables'][T]['actions']['read'] | Ix['tables'][T]['appRead'] ? T : never) : never;
|
|
638
667
|
}[TableName<Ix>];
|
|
639
668
|
/**
|
|
640
669
|
* The tables `ctx.sql.scope(capability, table)` takes for a capability of type `C` on a site of mode `M`: those its
|
package/types/src/policy.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { READ_ANY } from '@fabrika/auth-core';
|
|
1
2
|
import type { Insertable, Selectable, SelectType, Updateable } from 'kysely';
|
|
2
3
|
import { type NameSet } from './builtins';
|
|
3
4
|
import { type ConditionModel, type ConditionPolicy } from './conditions';
|
|
@@ -28,12 +29,17 @@ export interface ApplicationScope<Col extends string> {
|
|
|
28
29
|
}
|
|
29
30
|
/** One action, or a list of them: a table that staff and a public procedure both read names both actions. */
|
|
30
31
|
export type TableAction<A extends string> = A | readonly A[];
|
|
32
|
+
export { READ_ANY };
|
|
31
33
|
export interface TableActions<A extends string> {
|
|
32
34
|
readonly read: TableAction<A>;
|
|
33
35
|
readonly insert?: TableAction<A>;
|
|
34
36
|
readonly update?: TableAction<A>;
|
|
35
37
|
readonly delete?: TableAction<A>;
|
|
36
38
|
}
|
|
39
|
+
/** An application table's actions: its read may be `'any'` instead of its actions (`READ_ANY`). */
|
|
40
|
+
export interface ApplicationActions<A extends string> extends Omit<TableActions<A>, 'read'> {
|
|
41
|
+
readonly read: TableAction<A> | typeof READ_ANY;
|
|
42
|
+
}
|
|
37
43
|
/**
|
|
38
44
|
* A queue table's columns (ADR-0060's drain): `due` is when a row is next claimed, `null` once it is done; `attempts`
|
|
39
45
|
* counts its claims, and a row with `maxAttempts` (default 10) of them is no longer claimed.
|
|
@@ -210,7 +216,7 @@ export interface ChildPolicy<Table extends string, Col extends string, A extends
|
|
|
210
216
|
readonly scope: ChildScope<Table, Col>;
|
|
211
217
|
}
|
|
212
218
|
/** An application table: written like a dimension table, by an `app` endpoint whose action is the operation's. */
|
|
213
|
-
export interface ApplicationPolicy<Col extends string, A extends string, V extends Col = Col> extends WritablePolicy<Col, A, V
|
|
219
|
+
export interface ApplicationPolicy<Col extends string, A extends string, V extends Col = Col> extends WritablePolicy<Col, A, V, ApplicationActions<A>> {
|
|
214
220
|
readonly scope: ApplicationScope<Col>;
|
|
215
221
|
}
|
|
216
222
|
interface ReadOnlyPolicy<Col extends string, A extends string> {
|
|
@@ -285,9 +291,17 @@ export type ScopeModel = {
|
|
|
285
291
|
readonly reason: string;
|
|
286
292
|
readonly key: string;
|
|
287
293
|
};
|
|
288
|
-
/**
|
|
294
|
+
/**
|
|
295
|
+
* Each operation's actions: any one of them allows it. `read` names at least one, unless `readAny`; an empty list
|
|
296
|
+
* allows no operation.
|
|
297
|
+
*/
|
|
289
298
|
export interface ActionModel {
|
|
290
299
|
readonly read: readonly string[];
|
|
300
|
+
/**
|
|
301
|
+
* An application table read with `'any'`: every `app` endpoint, job and webhook reads it, whatever its action; never a
|
|
302
|
+
* public procedure or a scoped site. `read` is empty then, and a `when` narrows only the writes of its action.
|
|
303
|
+
*/
|
|
304
|
+
readonly readAny: boolean;
|
|
291
305
|
readonly insert: readonly string[];
|
|
292
306
|
readonly update: readonly string[];
|
|
293
307
|
readonly delete: readonly string[];
|
|
@@ -490,6 +504,11 @@ export declare function readTables(columns: unknown, policies: unknown, vocabula
|
|
|
490
504
|
* columns that declare it as their own write action for any other; none for an action that writes nothing here.
|
|
491
505
|
*/
|
|
492
506
|
export declare function updatableBy(model: TableModel, action: string): NameSet;
|
|
507
|
+
/**
|
|
508
|
+
* The columns any of `actions` updates in `model`, as one role holding them: the union of `updatableBy` over them.
|
|
509
|
+
* One action's set is `updatableBy`'s own.
|
|
510
|
+
*/
|
|
511
|
+
export declare function updatableByAny(model: TableModel, actions: readonly string[]): NameSet;
|
|
493
512
|
/** Whether the table names `action`: one of its table actions, or a column's own write action. */
|
|
494
513
|
export declare function namesAction(model: TableModel, action: string): boolean;
|
|
495
514
|
/**
|
|
@@ -497,6 +516,28 @@ export declare function namesAction(model: TableModel, action: string): boolean;
|
|
|
497
516
|
* one. A capability reads its own row, so a write `Ref` sees the columns of its action and none of another's.
|
|
498
517
|
*/
|
|
499
518
|
export declare function visibleFor(model: TableModel, action: string): readonly string[];
|
|
519
|
+
/**
|
|
520
|
+
* The actions whose reach one read answers: an `app` capability's held actions that admit the operation, each row
|
|
521
|
+
* passing where one of them admits it (`conditionedAny`), and whether their `when` narrows the rows (`narrowed`), which
|
|
522
|
+
* it does not in a table read with `'any'`.
|
|
523
|
+
*/
|
|
524
|
+
export interface ReadReach {
|
|
525
|
+
readonly actions: readonly string[];
|
|
526
|
+
readonly narrowed: boolean;
|
|
527
|
+
}
|
|
528
|
+
/** The reach of a capability of one action, whose own condition narrows its rows. */
|
|
529
|
+
export declare function soleReach(action: string): ReadReach;
|
|
530
|
+
/**
|
|
531
|
+
* Whether every row a read of `reach` answers is a row `action` reads alone: it is one of the reaching actions, and either
|
|
532
|
+
* no `when` of its own narrows it or it alone reaches the rows. A column of its own is shown only then, so several held
|
|
533
|
+
* actions never put one action's column on another action's rows.
|
|
534
|
+
*/
|
|
535
|
+
export declare function readsAsAction(model: TableModel, action: string, reach: ReadReach): boolean;
|
|
536
|
+
/**
|
|
537
|
+
* The columns a read of `reach` answers, the union of what each reaching action reads alone: every one that declares no
|
|
538
|
+
* read action of its own, and one that does where that action reads every answered row (`readsAsAction`).
|
|
539
|
+
*/
|
|
540
|
+
export declare function visibleThrough(model: TableModel, reach: ReadReach): readonly string[];
|
|
500
541
|
/** Every action that updates a column of `model`: its update action and each column's own write action. */
|
|
501
542
|
export declare function updateActions(model: TableModel): readonly string[];
|
|
502
543
|
/** Whether `names` holds `name`: an operation's actions, the one way a policy check reads a list. */
|
|
@@ -533,12 +574,21 @@ type ScopeOf<P, T> = PolicyOf<P, T> extends {
|
|
|
533
574
|
readonly scope: infer S;
|
|
534
575
|
} ? S : never;
|
|
535
576
|
export type Operation = 'read' | 'insert' | 'update' | 'delete';
|
|
536
|
-
/**
|
|
577
|
+
/**
|
|
578
|
+
* The action, or the union of the actions, of operation `Op` on table `T`; `never` when the policy names none, and for
|
|
579
|
+
* the read of a table read with `'any'` (`ReadsAny`).
|
|
580
|
+
*/
|
|
537
581
|
export type ActionOf<P, T, Op extends Operation> = PolicyOf<P, T> extends {
|
|
538
582
|
readonly actions: infer Acts;
|
|
539
583
|
} ? Acts extends {
|
|
540
584
|
readonly [K in Op]: infer A;
|
|
541
|
-
} ? A extends string ? A : A extends readonly (infer L extends string)[] ? L : never : never : never;
|
|
585
|
+
} ? A extends typeof READ_ANY ? never : A extends string ? A : A extends readonly (infer L extends string)[] ? L : never : never : never;
|
|
586
|
+
/** Whether table `T` is read with `'any'`: by every `app` endpoint, job and webhook, whatever its action. */
|
|
587
|
+
export type ReadsAny<P, T> = PolicyOf<P, T> extends {
|
|
588
|
+
readonly actions: {
|
|
589
|
+
readonly read: typeof READ_ANY;
|
|
590
|
+
};
|
|
591
|
+
} ? true : false;
|
|
542
592
|
export type DimensionOf<P, T> = ScopeOf<P, T> extends {
|
|
543
593
|
readonly dimension: infer D extends string;
|
|
544
594
|
} ? D : never;
|
package/types/src/registry.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export interface FrameworkSide {
|
|
|
57
57
|
/** Connects the layer once and answers its binding; a call while one is connected throws. */
|
|
58
58
|
bind(runtime: DataLayerRuntime): ProvisionalBinding;
|
|
59
59
|
readonly framework: FrameworkTables;
|
|
60
|
-
/** The untyped handle over one table that `@fabrika/db/testing` hands the isolation
|
|
60
|
+
/** The untyped handle over one table that `@fabrika/db/testing` hands the policy isolation kit. */
|
|
61
61
|
probe(table: string): TableProbe;
|
|
62
62
|
/** One table's context, for the framework's own store builders (`defineStore`, `@fabrika/db/testing`). */
|
|
63
63
|
tableContext(table: string, mode: 'dimension' | 'child'): TableContext;
|
package/types/src/store.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type OperationNode, type ReturningNode } from 'kysely';
|
|
2
2
|
import { type MemberReveals, type PathRule, type RelationSources } from './authority';
|
|
3
3
|
import { type NameSet } from './builtins';
|
|
4
|
-
import { type AppGrant, type CapabilityAuthority, type Ref, type RefGrant, type Within, type WithinGrant } from './capability';
|
|
4
|
+
import { type AppGrant, type CapabilityAuthority, type CapabilityGrant, type Ref, type RefGrant, type Within, type WithinGrant } from './capability';
|
|
5
5
|
import { type ConditionModel } from './conditions';
|
|
6
6
|
import { type Database, type Session, type SqlDialect } from './database';
|
|
7
7
|
import { type ComparableColumn, type Compare, type Contains, type NoColumns, type Primitive, type ScopedSelect, type TableShape } from './description';
|
|
8
8
|
import { type FileBinding } from './file-columns';
|
|
9
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';
|
|
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 ReadReach, type SecondaryPath, type TableModel, type TableModels, type Tables, type UpdateValues, type VersionArguments } from './policy';
|
|
11
11
|
import type { ScopeTerms, ScopeUse } from './sql';
|
|
12
12
|
import { type TablePolicies } from './tables';
|
|
13
13
|
import { type RowColumns } from './temporal';
|
|
@@ -111,6 +111,8 @@ export declare function secondaryPathsOf(model: TableModel, dimension: string):
|
|
|
111
111
|
* table reaches through a secondary path, through that path's column.
|
|
112
112
|
*/
|
|
113
113
|
export declare function reachPredicate(context: TableContext, capability: unknown): OperationNode | undefined;
|
|
114
|
+
/** The actions a grant holds: an `app` grant's (several for an `anyOf` endpoint), or any other grant's one. */
|
|
115
|
+
export declare function grantActions(grant: CapabilityGrant): readonly string[];
|
|
114
116
|
/**
|
|
115
117
|
* `ctx.sql.scope`'s predicate: what the handles of `capability` match in the table for `use`, as column tests. A
|
|
116
118
|
* fragment that reads (`'read'`) needs an action the handles read the table with: any action it names for a `Ref`,
|
|
@@ -132,12 +134,24 @@ export declare function updatingRef(context: TableContext, capability: unknown,
|
|
|
132
134
|
* action or an action of `appRead`; its counts (`count`, `aggregate`) with those or an action of `appCount`.
|
|
133
135
|
*/
|
|
134
136
|
export type AppReach = 'rows' | 'counts';
|
|
137
|
+
/** What an `app` capability reads of a table: the rows (`predicate`), and the reach whose columns it answers. */
|
|
138
|
+
export interface AppRead {
|
|
139
|
+
readonly predicate: OperationNode;
|
|
140
|
+
readonly reach: ReadReach;
|
|
141
|
+
}
|
|
135
142
|
/**
|
|
136
|
-
* Every row of a dimension or child table an `app` capability reads through `ctx.db.app
|
|
137
|
-
*
|
|
143
|
+
* Every row of a dimension or child table an `app` capability reads through `ctx.db.app`, for its actions that reach
|
|
144
|
+
* `reach` (`recordReach`): each row within the condition of one of them, and the columns they read alone.
|
|
138
145
|
*/
|
|
146
|
+
export declare function appRecordRead(context: TableContext, capability: unknown, reach: AppReach): AppRead;
|
|
147
|
+
/** `appRecordRead`'s rows. */
|
|
139
148
|
export declare function appRecordPredicate(context: TableContext, capability: unknown, reach: AppReach): OperationNode;
|
|
140
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Every row a capability of an `app` endpoint reads in an application table, by the table's read actions it holds or
|
|
151
|
+
* `'any'`, and the reach whose columns it answers.
|
|
152
|
+
*/
|
|
153
|
+
export declare function appListRead(context: TableContext, capability: unknown): AppRead;
|
|
154
|
+
/** `appListRead`'s rows. */
|
|
141
155
|
export declare function appListPredicate(context: TableContext, capability: unknown): OperationNode;
|
|
142
156
|
/**
|
|
143
157
|
* Every row of an application table, for a `Ref` or a `Within` of its read action: what `ctx.db.app` of an `on`, `in`
|
|
@@ -152,6 +166,7 @@ export declare function appRowPredicate(context: TableContext, capability: unkno
|
|
|
152
166
|
*/
|
|
153
167
|
export declare function claimScope(context: TableContext, capability: unknown): {
|
|
154
168
|
readonly grant: AppGrant | WithinGrant;
|
|
169
|
+
readonly action: string;
|
|
155
170
|
readonly scope: OperationNode | undefined;
|
|
156
171
|
};
|
|
157
172
|
/**
|
|
@@ -159,15 +174,26 @@ export declare function claimScope(context: TableContext, capability: unknown):
|
|
|
159
174
|
* it was claimed, so a row moved since is not reached.
|
|
160
175
|
*/
|
|
161
176
|
export declare function claimedRowPredicate(context: TableContext, capability: unknown, operation: 'update' | 'delete'): OperationNode;
|
|
162
|
-
/** The row of an application table `key` names, as `
|
|
163
|
-
export declare function appKeyScope(model: TableModel,
|
|
177
|
+
/** The row of an application table `key` names, as `actions` reach it: within their conditions, any one admitting it. */
|
|
178
|
+
export declare function appKeyScope(model: TableModel, actions: readonly string[], key: unknown): OperationNode;
|
|
179
|
+
/** The row `key` names, as a read by key with `actions` reaches it: unconditioned in a table read with `'any'`. */
|
|
180
|
+
export declare function appGetScope(model: TableModel, actions: readonly string[], key: unknown): OperationNode;
|
|
164
181
|
/** The row of an application table `key` names. */
|
|
165
182
|
export declare function appKeyPredicate(model: TableModel, key: unknown): OperationNode;
|
|
166
183
|
/**
|
|
167
|
-
* The
|
|
168
|
-
* column's own write action. Which columns
|
|
184
|
+
* The actions of an `app` endpoint's capability that update columns of an application table, at least one: its update
|
|
185
|
+
* action, or a column's own write action. Which columns they update follows from them (`updatableByAny`).
|
|
186
|
+
*/
|
|
187
|
+
export declare function updatingApp(context: TableContext, capability: unknown): readonly string[];
|
|
188
|
+
/**
|
|
189
|
+
* An `app` capability's update of the application table row `key`: `values`, read against the columns its update
|
|
190
|
+
* actions write, and the row's scope under only those actions that write every given column, any one's condition
|
|
191
|
+
* admitting the row. So several held actions never write one action's columns on rows only another one reaches.
|
|
169
192
|
*/
|
|
170
|
-
export declare function
|
|
193
|
+
export declare function appUpdate(context: TableContext, capability: unknown, key: unknown, values: unknown): {
|
|
194
|
+
readonly scope: OperationNode;
|
|
195
|
+
readonly changes: Map<string, Primitive | null>;
|
|
196
|
+
};
|
|
171
197
|
export declare function childObjectPredicate(context: TableContext, parent: unknown, key: unknown, operation: Operation): OperationNode;
|
|
172
198
|
export declare function guard(context: TableContext, root: RootKind, scope: OperationNode | undefined): GuardContext;
|
|
173
199
|
/**
|
|
@@ -187,7 +213,10 @@ export interface Runner {
|
|
|
187
213
|
* lease (`fencedTransaction`): an attempt that lost it, or ran out of time, writes nothing.
|
|
188
214
|
*/
|
|
189
215
|
export declare function fencedWork<T>(runtime: DataLayerRuntime, work: (transaction: Session) => Promise<T>): Promise<T>;
|
|
190
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* The one action a capability holds, which its operation's checks already admitted. An `anyOf` endpoint's `app`
|
|
218
|
+
* capability that holds several is refused: it reads through `ctx.db.app`, which reads with every action it holds.
|
|
219
|
+
*/
|
|
191
220
|
export declare function heldAction(context: TableContext, capability: unknown): string;
|
|
192
221
|
/**
|
|
193
222
|
* Reads insert or update data through its own property descriptors, so no getter runs and no inherited or
|
|
@@ -198,9 +227,9 @@ export declare function readValues(values: unknown, allowed: NameSet, what: 'ins
|
|
|
198
227
|
export declare function versionArgument(context: TableContext, options: readonly unknown[]): OperationNode | undefined;
|
|
199
228
|
/**
|
|
200
229
|
* One row by its scope predicate, with `visible` columns (the table's read action's, unless a capability reads its own).
|
|
201
|
-
* `
|
|
230
|
+
* `reach` is what read it: each file column then answers a reference that reads the file only under a read action.
|
|
202
231
|
*/
|
|
203
|
-
export declare function selectOne<O>(context: TableContext, run: Runner, scope: OperationNode, visible?: readonly string[],
|
|
232
|
+
export declare function selectOne<O>(context: TableContext, run: Runner, scope: OperationNode, visible?: readonly string[], reach?: ReadReach): Promise<O>;
|
|
204
233
|
export declare function answer(context: TableContext): ReturningNode;
|
|
205
234
|
export declare function keyOf(model: TableModel): string;
|
|
206
235
|
/** An insert, in a transaction that first locks its destination and judges its writer's bounds and its condition. */
|
|
@@ -214,14 +243,14 @@ export interface OnConflict {
|
|
|
214
243
|
readonly mode: 'nothing' | 'update';
|
|
215
244
|
/** The values given for the table's update columns: what `update` sets on the conflicting row. */
|
|
216
245
|
readonly updates: ReadonlyMap<string, Primitive | null>;
|
|
217
|
-
/** The capability's
|
|
218
|
-
readonly
|
|
246
|
+
/** The capability's update actions, one of whose conditions the conflicting row must satisfy to be updated. */
|
|
247
|
+
readonly actions: readonly string[];
|
|
219
248
|
}
|
|
220
249
|
/**
|
|
221
250
|
* The `onConflict` of an insert's options, read through own data properties; `undefined` without options. `'update'`
|
|
222
|
-
* also needs the capability's
|
|
251
|
+
* also needs one of the capability's `actions` to be one of the table's update actions.
|
|
223
252
|
*/
|
|
224
|
-
export declare function onConflictOf(context: TableContext, options: unknown,
|
|
253
|
+
export declare function onConflictOf(context: TableContext, options: unknown, actions: readonly string[], given: ReadonlyMap<string, Primitive | null>): OnConflict | undefined;
|
|
225
254
|
/**
|
|
226
255
|
* The rows a write addresses: the scope predicate, and the caller's conditions beside it (an unscoped row's key, whose
|
|
227
256
|
* scope predicate is `true`).
|
|
@@ -361,7 +390,7 @@ export declare class ChildTable<DB, P, T extends string> {
|
|
|
361
390
|
aggregate<const S extends AggregateSpec<Row<DB, P, T>>>(scope: ChildListScope<P, T>, spec: S): Promise<AggregateRow<Row<DB, P, T>, S>[]>;
|
|
362
391
|
}
|
|
363
392
|
/**
|
|
364
|
-
* One table's operations without the store types, for `@fabrika/db/testing` only: the
|
|
393
|
+
* One table's operations without the store types, for `@fabrika/db/testing` only: the policy isolation kit addresses
|
|
365
394
|
* a table by name. Every runtime check of a store applies; a child row is addressed by its parent's capability and
|
|
366
395
|
* `key`, a dimension row by its capability alone.
|
|
367
396
|
*/
|
|
@@ -6,7 +6,7 @@ import type { TableProbe } from './store';
|
|
|
6
6
|
export type SampleValue = Primitive | null;
|
|
7
7
|
/**
|
|
8
8
|
* A seeded value as a backend binds it: a JSON column's value as the JSON text the layer would write for it, so a
|
|
9
|
-
* seeded row and the
|
|
9
|
+
* seeded row and the kits' cases that write the same value through the layer hold the same JSON.
|
|
10
10
|
*/
|
|
11
11
|
export declare function seedBinding(columns: readonly SeedColumn[], table: string, name: string, value: SampleValue): SampleValue;
|
|
12
12
|
/** One seeded row and where it lies. */
|
|
@@ -26,7 +26,7 @@ export declare function testDatabaseTemplate(options: Omit<TestDatabaseOptions,
|
|
|
26
26
|
/**
|
|
27
27
|
* A fresh in-memory database with the framework's and the application's migrations applied by the runner a Durable
|
|
28
28
|
* Object boots with (`@fabrika/db/sqlite-migrate`), opened with its engine (`@fabrika/db/sqlite`). Never `null`: it
|
|
29
|
-
* needs no backend, so it never skips; its type is still assignable to `@fabrika/db/testing`'s, so a
|
|
29
|
+
* needs no backend, so it never skips; its type is still assignable to `@fabrika/db/testing`'s, so a test
|
|
30
30
|
* that checks for `null` compiles against both kits.
|
|
31
31
|
*/
|
|
32
32
|
export declare function testDatabase(options: TestDatabaseOptions): Promise<TestDatabase>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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
|
+
import type { AccessPolicy, ApplicationActions, ColumnList, ColumnPolicies, ConfersPolicy, FilePolicies, MemberRevealsPolicy, RecordActions, ReferencePolicy, RevealsPolicy, TableAction, TableActions, Tables, VersionColumn } from './policy';
|
|
3
3
|
declare const databaseType: unique symbol;
|
|
4
4
|
declare const viewNames: unique symbol;
|
|
5
5
|
/**
|
|
@@ -250,7 +250,7 @@ type ReferenceViewPolicy<Col extends string, A extends string> = ReferencePolicy
|
|
|
250
250
|
};
|
|
251
251
|
};
|
|
252
252
|
/** An application table's scope: why its rows belong to no dimension; `key` defaults to `id`. */
|
|
253
|
-
type AuthoredApplicationPolicy<Col extends string, A extends string, Ver extends Col> = WritableFields<Col, A, Ver
|
|
253
|
+
type AuthoredApplicationPolicy<Col extends string, A extends string, Ver extends Col> = WritableFields<Col, A, Ver, ApplicationActions<A>> & {
|
|
254
254
|
readonly scope: {
|
|
255
255
|
readonly app: string;
|
|
256
256
|
} & KeyField<Col>;
|