@fabrika/db 0.9.0-dev.7 → 0.9.0-dev.70
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 +9 -5
- package/src/authority.ts +560 -0
- package/src/builtins.ts +21 -0
- package/src/capability.ts +51 -2
- package/src/codegen-sqlite.ts +69 -13
- package/src/codegen.ts +181 -42
- package/src/condition-nodes.ts +119 -0
- package/src/conditions.ts +683 -0
- package/src/description.ts +67 -9
- package/src/errors.ts +9 -5
- package/src/file-columns.ts +52 -10
- package/src/framework.ts +5 -2
- package/src/guard.ts +365 -15
- package/src/index.ts +8 -0
- package/src/job-leases.ts +19 -2
- package/src/job-wakes.ts +183 -33
- package/src/json.ts +187 -0
- package/src/list-cursor.ts +82 -0
- package/src/migrations-sqlite.ts +93 -0
- package/src/migrations.ts +99 -0
- package/src/nodes.ts +33 -14
- package/src/notifications.ts +152 -0
- package/src/orm-types.ts +216 -77
- package/src/orm.ts +417 -158
- package/src/policy.ts +2043 -131
- package/src/push-subscriptions.ts +287 -0
- package/src/registry.ts +50 -1
- package/src/request-receipts.ts +107 -0
- package/src/sql.ts +39 -11
- package/src/sqlite-migrate.ts +102 -1
- package/src/sqlite.ts +46 -1
- package/src/store.ts +1958 -167
- package/src/tables.ts +156 -6
- package/src/temporal.ts +39 -4
- package/src/testing-shared.ts +872 -148
- package/src/testing-sqlite.ts +215 -40
- package/src/testing.ts +151 -22
- package/src/vocabulary-tables.ts +172 -26
- package/types/src/authority.d.ts +147 -0
- package/types/src/builtins.d.ts +2 -0
- package/types/src/capability.d.ts +50 -2
- package/types/src/codegen-sqlite.d.ts +8 -1
- package/types/src/codegen.d.ts +54 -10
- package/types/src/condition-nodes.d.ts +9 -0
- package/types/src/conditions.d.ts +151 -0
- package/types/src/description.d.ts +40 -9
- package/types/src/errors.d.ts +8 -5
- package/types/src/file-columns.d.ts +6 -4
- package/types/src/framework.d.ts +5 -2
- package/types/src/guard.d.ts +24 -0
- package/types/src/index.d.ts +4 -3
- package/types/src/job-leases.d.ts +8 -1
- package/types/src/job-wakes.d.ts +28 -5
- package/types/src/json.d.ts +35 -0
- package/types/src/list-cursor.d.ts +13 -0
- package/types/src/migrations.d.ts +5 -0
- package/types/src/nodes.d.ts +5 -1
- package/types/src/notifications.d.ts +37 -0
- package/types/src/orm-types.d.ts +167 -75
- package/types/src/orm.d.ts +21 -0
- package/types/src/policy.d.ts +378 -27
- package/types/src/push-subscriptions.d.ts +49 -0
- package/types/src/registry.d.ts +36 -1
- package/types/src/request-receipts.d.ts +22 -0
- package/types/src/sql.d.ts +2 -2
- package/types/src/sqlite-migrate.d.ts +32 -0
- package/types/src/store.d.ts +118 -31
- package/types/src/tables.d.ts +8 -2
- package/types/src/temporal.d.ts +7 -1
- package/types/src/testing-shared.d.ts +125 -26
- package/types/src/testing-sqlite.d.ts +17 -2
- package/types/src/testing.d.ts +1 -1
- package/types/src/vocabulary-tables.d.ts +176 -22
package/src/vocabulary-tables.ts
CHANGED
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
// The table policies of the vocabulary form, `defineTables(vocabulary, columns)`: how an application writes them, with
|
|
2
2
|
// containment taken from the vocabulary, and the normalized policies the kit and the handles read. Types only.
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { ConditionPolicy } from './conditions'
|
|
5
|
+
import type {
|
|
6
|
+
AccessPolicy,
|
|
7
|
+
ApplicationActions,
|
|
8
|
+
ColumnList,
|
|
9
|
+
ColumnPolicies,
|
|
10
|
+
ConfersPolicy,
|
|
11
|
+
FilePolicies,
|
|
12
|
+
JsonColumn,
|
|
13
|
+
JsonPolicies,
|
|
14
|
+
MemberRevealsPolicy,
|
|
15
|
+
RecordActions,
|
|
16
|
+
ReferencePolicy,
|
|
17
|
+
RevealsPolicy,
|
|
18
|
+
TableAction,
|
|
19
|
+
TableActions,
|
|
20
|
+
Tables,
|
|
21
|
+
VersionColumn,
|
|
22
|
+
} from './policy'
|
|
5
23
|
|
|
6
24
|
declare const databaseType: unique symbol
|
|
25
|
+
declare const viewNames: unique symbol
|
|
7
26
|
|
|
8
27
|
/**
|
|
9
|
-
* The generated column list (`src/db/schema.generated.ts`), which also carries the schema's row types
|
|
10
|
-
* `defineTables(vocabulary, columns)` takes no type argument. The
|
|
28
|
+
* The generated column list (`src/db/schema.generated.ts`), which also carries the schema's row types and the names of
|
|
29
|
+
* its views, so that `defineTables(vocabulary, columns)` takes no type argument. The brands are type-only: no value
|
|
30
|
+
* has either property.
|
|
11
31
|
*/
|
|
12
|
-
export type TypedColumnList<DB> = ColumnList<DB> & {
|
|
32
|
+
export type TypedColumnList<DB, Views extends keyof DB & string = never> = ColumnList<DB> & {
|
|
33
|
+
readonly [databaseType]?: DB
|
|
34
|
+
readonly [viewNames]?: { readonly views: Views }
|
|
35
|
+
}
|
|
13
36
|
|
|
14
37
|
/** The row types a typed column list carries; `never` for a list without them. */
|
|
15
38
|
export type ColumnTypes<C> = typeof databaseType extends keyof C ? C extends { readonly [databaseType]?: infer DB } ? Exclude<DB, undefined> : never
|
|
16
39
|
: never
|
|
17
40
|
|
|
41
|
+
/** The views a typed column list names; `never` for a list without views. */
|
|
42
|
+
export type ColumnViews<C> = typeof viewNames extends keyof C
|
|
43
|
+
? C extends { readonly [viewNames]?: { readonly views: infer Views extends string } } ? Views : never
|
|
44
|
+
: never
|
|
45
|
+
|
|
18
46
|
/**
|
|
19
47
|
* What `defineTables(vocabulary, columns)` reads of `@fabrika/app/contract`'s `defineVocabulary` result: the action
|
|
20
48
|
* and dimension names, and each dimension's container. `@fabrika/db` does not import `@fabrika/app`.
|
|
@@ -22,6 +50,7 @@ export type ColumnTypes<C> = typeof databaseType extends keyof C ? C extends { r
|
|
|
22
50
|
export interface TableVocabulary {
|
|
23
51
|
readonly actions: { readonly [action: string]: string }
|
|
24
52
|
readonly dimensions: { readonly [dimension: string]: { readonly in?: string } }
|
|
53
|
+
readonly relations?: { readonly [relation: string]: { readonly dimension: string } }
|
|
25
54
|
}
|
|
26
55
|
|
|
27
56
|
export type VocabularyAction<V> = V extends { readonly actions: infer A } ? keyof A & string : never
|
|
@@ -67,15 +96,46 @@ export type VocabularyChildScope<Table extends string, Col extends string> =
|
|
|
67
96
|
& { readonly child: Table; readonly column?: Col; readonly inherit?: readonly Col[] }
|
|
68
97
|
& KeyField<Col>
|
|
69
98
|
|
|
70
|
-
|
|
99
|
+
/** A written table whose `version` column is not an INTEGER names its version column: `version` would be it otherwise. */
|
|
100
|
+
interface NamesItsVersionColumn<Ver extends string> {
|
|
101
|
+
readonly version: Ver
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** `version` defaults to the `version` column, so it is required only where that column holds no number. */
|
|
105
|
+
type VersionField<Col extends string, Ver extends Col> = 'version' extends Col
|
|
106
|
+
? 'version' extends Ver ? { readonly version?: Ver } : NamesItsVersionColumn<Ver>
|
|
107
|
+
: { readonly version?: Ver }
|
|
108
|
+
|
|
109
|
+
interface WritableFields<Col extends string, A extends string, Acts = TableActions<A>> {
|
|
71
110
|
readonly actions: Acts
|
|
72
111
|
readonly insert?: readonly Col[]
|
|
73
112
|
readonly update?: readonly Col[]
|
|
74
|
-
readonly version?: Ver
|
|
75
113
|
readonly createdBy?: Col
|
|
76
114
|
readonly columns?: ColumnPolicies<Col, A>
|
|
77
115
|
/** The file columns, each with the file kind it holds (`c.files`): a `uuid` foreign key to `fabrika_files`. */
|
|
78
116
|
readonly files?: FilePolicies<Col>
|
|
117
|
+
/** Relation → how a row of this table confers it: whom it names, at which node, until when. */
|
|
118
|
+
readonly confers?: { readonly [relation: string]: ConfersPolicy<Col> }
|
|
119
|
+
/** Action → the condition a row must meet for it, whoever holds it. */
|
|
120
|
+
readonly when?: { readonly [action in A]?: ConditionPolicy<Col> }
|
|
121
|
+
/** Relation → action → the condition a row that relation reaches must meet for it; IAM grants are not narrowed. */
|
|
122
|
+
readonly relationWhen?: { readonly [relation: string]: { readonly [action in A]?: ConditionPolicy<Col> } }
|
|
123
|
+
/** Relation of the table's own dimension → the ancestor node a row it reaches reveals, and for which actions. */
|
|
124
|
+
readonly reveals?: { readonly [relation: string]: RevealsPolicy<Col, A> }
|
|
125
|
+
/**
|
|
126
|
+
* Dimension outside the chain → the foreign key column a `Within`'s read reaches a row through, no update writes it; or
|
|
127
|
+
* `<nearest container column>.<its column>`, the nearest container's own path.
|
|
128
|
+
*/
|
|
129
|
+
readonly readThrough?: { readonly [dimension: string]: Col | `${Col}.${string}` }
|
|
130
|
+
/**
|
|
131
|
+
* Dimension of `readThrough` → the actions a `Ref` held through that path holds, writes included; whoever inserts the
|
|
132
|
+
* path's column must hold each at the node it names.
|
|
133
|
+
*/
|
|
134
|
+
readonly writeThrough?: { readonly [dimension: string]: readonly A[] }
|
|
135
|
+
/** The table's own dimension → the ancestor node a row reveals to a grant at its node, for a `Within`'s reads. */
|
|
136
|
+
readonly memberReveals?: { readonly [dimension: string]: MemberRevealsPolicy<Col, A> }
|
|
137
|
+
/** Relation → the access view that lists the rows it reaches: the escape path, decided by the view's SQL. */
|
|
138
|
+
readonly access?: { readonly [relation: string]: AccessPolicy }
|
|
79
139
|
}
|
|
80
140
|
|
|
81
141
|
/**
|
|
@@ -118,19 +178,69 @@ type ChildScopes<Table extends string, Col extends string, S, P> = unknown exten
|
|
|
118
178
|
: ChildTableScope<Parent, StatedDimensionOf<P, Parent>, Col>
|
|
119
179
|
: VocabularyChildScope<Table, Col>
|
|
120
180
|
|
|
121
|
-
type AuthoredDimensionPolicy<Col extends string, A extends string, V, Ver extends Col, S> =
|
|
122
|
-
|
|
123
|
-
|
|
181
|
+
type AuthoredDimensionPolicy<Col extends string, A extends string, V, Ver extends Col, S> =
|
|
182
|
+
& WritableFields<Col, A, RecordActions<A>>
|
|
183
|
+
& VersionField<Col, Ver>
|
|
184
|
+
& {
|
|
185
|
+
readonly scope: DimensionScopes<V, Col, S>
|
|
186
|
+
}
|
|
124
187
|
type AuthoredChildPolicy<Table extends string, Col extends string, A extends string, Ver extends Col, S, P> =
|
|
125
|
-
& WritableFields<Col, A,
|
|
188
|
+
& WritableFields<Col, A, RecordActions<A>>
|
|
189
|
+
& VersionField<Col, Ver>
|
|
126
190
|
& {
|
|
127
191
|
readonly scope: ChildScopes<Table, Col, S, P>
|
|
128
192
|
}
|
|
129
|
-
/**
|
|
130
|
-
type
|
|
131
|
-
|
|
193
|
+
/** What a view's policy holds besides its scope: read actions only, no write list and no stamped column. */
|
|
194
|
+
type ViewIsReadOnly = 'a view is never written: its actions are read, appRead and appCount'
|
|
195
|
+
|
|
196
|
+
/** The write actions a view's policy may not name, each typed as the message: a literal is not checked for excess keys. */
|
|
197
|
+
interface NoWriteActions {
|
|
198
|
+
readonly insert?: ViewIsReadOnly
|
|
199
|
+
readonly update?: ViewIsReadOnly
|
|
200
|
+
readonly delete?: ViewIsReadOnly
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
interface ReadOnlyFields<Col extends string, A extends string> {
|
|
204
|
+
readonly actions: { readonly read: TableAction<A>; readonly appRead?: readonly A[]; readonly appCount?: readonly A[] } & NoWriteActions
|
|
205
|
+
readonly insert?: never
|
|
206
|
+
readonly update?: never
|
|
207
|
+
readonly version?: never
|
|
208
|
+
readonly createdBy?: never
|
|
209
|
+
readonly queue?: never
|
|
210
|
+
readonly files?: never
|
|
211
|
+
readonly columns?: { readonly [C in Col]?: { readonly read: TableAction<A>; readonly write?: never } }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* A view read as a child table: its parent's `Ref` and `Within` read it; nothing writes it (ADR-0072). Its `when` and
|
|
216
|
+
* `relationWhen` narrow its read actions; a path may start at its parent column, to the parent row.
|
|
217
|
+
*/
|
|
218
|
+
type AuthoredChildViewPolicy<Table extends string, Col extends string, A extends string, S, P> = ReadOnlyFields<Col, A> & {
|
|
219
|
+
readonly scope: ChildScopes<Table, Col, S, P>
|
|
220
|
+
readonly when?: { readonly [action in A]?: ConditionPolicy<Col> }
|
|
221
|
+
/** Relation → action → the condition a row the relation reaches through the parent row must meet for it. */
|
|
222
|
+
readonly relationWhen?: { readonly [relation: string]: { readonly [action in A]?: ConditionPolicy<Col> } }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** A view's policy as written: a read-only child, or a reference table every site reads. */
|
|
226
|
+
export type VocabularyViewPolicy<Table extends string, Col extends string, A extends string, S = unknown, P = unknown> = S extends
|
|
227
|
+
{ readonly child: unknown } ? AuthoredChildViewPolicy<Table, Col, A, S, P>
|
|
228
|
+
: S extends { readonly reference: unknown } ? ReferenceViewPolicy<Col, A>
|
|
229
|
+
: AuthoredChildViewPolicy<Table, Col, A, S, P> | ReferenceViewPolicy<Col, A>
|
|
230
|
+
|
|
231
|
+
type ReferenceViewPolicy<Col extends string, A extends string> = ReferencePolicy<Col, A> & {
|
|
232
|
+
readonly actions: NoWriteActions
|
|
233
|
+
readonly columns?: { readonly [C in Col]?: { readonly read: TableAction<A>; readonly write?: never } }
|
|
132
234
|
}
|
|
133
235
|
|
|
236
|
+
/** An application table's scope: why its rows belong to no dimension; `key` defaults to `id`. */
|
|
237
|
+
type AuthoredApplicationPolicy<Col extends string, A extends string, Ver extends Col> =
|
|
238
|
+
& WritableFields<Col, A, ApplicationActions<A>>
|
|
239
|
+
& VersionField<Col, Ver>
|
|
240
|
+
& {
|
|
241
|
+
readonly scope: { readonly app: string } & KeyField<Col>
|
|
242
|
+
}
|
|
243
|
+
|
|
134
244
|
/**
|
|
135
245
|
* One table's policy as an application writes it under a vocabulary. `S` is its scope as written: its mode picks the
|
|
136
246
|
* one policy form a mistake is reported against, rather than a union of all four. `P` is every policy as written.
|
|
@@ -157,14 +267,35 @@ type AnyTablePolicy<DB, V, T extends keyof DB & string> = VocabularyTablePolicy<
|
|
|
157
267
|
VersionColumn<DB[T]>
|
|
158
268
|
>
|
|
159
269
|
|
|
270
|
+
/** The policy of view `T` with nothing stated: both forms, any parent. */
|
|
271
|
+
type AnyViewPolicy<DB, V, T extends keyof DB & string> = VocabularyViewPolicy<keyof DB & string, keyof DB[T] & string, VocabularyAction<V>>
|
|
272
|
+
|
|
160
273
|
/**
|
|
161
|
-
* Every table of the schema, and no other, maps to a policy; a
|
|
162
|
-
* `P` is the policies as written, which picks each table's form by the scope it
|
|
163
|
-
* map's own annotation states nothing narrower, so it is checked against every
|
|
274
|
+
* Every table of the schema, and no other, maps to a policy; a view `Views` names may (ADR-0072). A misspelt action or
|
|
275
|
+
* dimension fails at its own line. `P` is the policies as written, which picks each table's form by the scope it
|
|
276
|
+
* states; a policy written under this map's own annotation states nothing narrower, so it is checked against every
|
|
277
|
+
* form.
|
|
164
278
|
*/
|
|
165
|
-
export type VocabularyPolicyMap<DB, V, P = unknown> =
|
|
166
|
-
|
|
167
|
-
|
|
279
|
+
export type VocabularyPolicyMap<DB, V, P = unknown, Views extends string = never> =
|
|
280
|
+
& {
|
|
281
|
+
readonly [T in Exclude<keyof DB & string, Views>]:
|
|
282
|
+
& (AnyTablePolicy<DB, V, T> extends (T extends keyof P ? P[T] : unknown) ? AnyTablePolicy<DB, V, T>
|
|
283
|
+
: VocabularyTablePolicy<keyof DB & string, keyof DB[T] & string, VocabularyAction<V>, V, VersionColumn<DB[T]>, StatedScope<P, T>, P>)
|
|
284
|
+
& JsonField<DB[T]>
|
|
285
|
+
}
|
|
286
|
+
& {
|
|
287
|
+
readonly [T in Views & keyof DB & string]?:
|
|
288
|
+
& (AnyViewPolicy<DB, V, T> extends (T extends keyof P ? P[T] : unknown) ? AnyViewPolicy<DB, V, T>
|
|
289
|
+
: VocabularyViewPolicy<keyof DB & string, keyof DB[T] & string, VocabularyAction<V>, StatedScope<P, T>, P>)
|
|
290
|
+
& JsonField<DB[T]>
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Column → the zod schema of a JSON column (`jsonb`, or `JSONB` on SQLite): each write is parsed by it before it is
|
|
295
|
+
* stored, and each read value too; the handle types read its output and write its input.
|
|
296
|
+
*/
|
|
297
|
+
interface JsonField<Row> {
|
|
298
|
+
readonly json?: JsonPolicies<JsonColumn<Row>>
|
|
168
299
|
}
|
|
169
300
|
|
|
170
301
|
type Flat<T> = { [K in keyof T]: T[K] }
|
|
@@ -192,15 +323,30 @@ type NormalScope<S, V, P> = S extends { readonly dimension: infer D extends stri
|
|
|
192
323
|
: S extends { readonly app: infer R extends string } ? { readonly app: R; readonly key: KeyOf<S> }
|
|
193
324
|
: S
|
|
194
325
|
|
|
326
|
+
/** A view's normalized policy says so, which the handle types read: no site writes it. */
|
|
327
|
+
type ViewMark<T, Views> = T extends Views ? { readonly view: true } : unknown
|
|
328
|
+
|
|
329
|
+
/** A written table's `version` and `created_by` columns are its version and creator unless its policy names others. */
|
|
330
|
+
type Conventions<Row, Pol> =
|
|
331
|
+
& (Pol extends { readonly version: string } ? unknown : 'version' extends keyof Row ? { readonly version: 'version' } : unknown)
|
|
332
|
+
& (Pol extends { readonly createdBy: string } ? unknown : 'created_by' extends keyof Row ? { readonly createdBy: 'created_by' } : unknown)
|
|
333
|
+
|
|
334
|
+
/** Only a dimension, child or application table is written; a view and a reference table get no convention. */
|
|
335
|
+
type WrittenConventions<DB, T, Pol, S, Views> = T extends Views ? unknown
|
|
336
|
+
: S extends { readonly reference: unknown } ? unknown
|
|
337
|
+
: Conventions<T extends keyof DB ? DB[T] : never, Pol>
|
|
338
|
+
|
|
195
339
|
/**
|
|
196
|
-
* The policies as the layer models them: every dimension table's key and container,
|
|
197
|
-
*
|
|
340
|
+
* The policies as the layer models them: every dimension table's key and container, every child's key and column,
|
|
341
|
+
* and a written table's version and creator, stated as the vocabulary and the conventions derive them; each view marked.
|
|
198
342
|
*/
|
|
199
|
-
export type NormalizedPolicies<P, V> = {
|
|
200
|
-
readonly [T in keyof P]: P[T] extends { readonly scope: infer S }
|
|
343
|
+
export type NormalizedPolicies<DB, P, V, Views = never> = {
|
|
344
|
+
readonly [T in keyof P]: P[T] extends { readonly scope: infer S }
|
|
345
|
+
? Flat<Omit<P[T], 'scope' | 'view'> & { readonly scope: NormalScope<S, V, P> } & ViewMark<T, Views> & WrittenConventions<DB, T, P[T], S, Views>>
|
|
346
|
+
: P[T]
|
|
201
347
|
}
|
|
202
348
|
|
|
203
|
-
/** Takes the policies of exactly the tables of the schema, written in the vocabulary form. */
|
|
204
|
-
export type DefineVocabularyPolicies<DB, V> = <const P extends VocabularyPolicyMap<DB, V, P>>(
|
|
349
|
+
/** Takes the policies of exactly the tables of the schema, and of any of its views, written in the vocabulary form. */
|
|
350
|
+
export type DefineVocabularyPolicies<DB, V, Views extends string = never> = <const P extends VocabularyPolicyMap<DB, V, P, Views>>(
|
|
205
351
|
policies: P & { readonly [K in Exclude<keyof P, keyof DB>]: never },
|
|
206
|
-
) => Tables<DB, NormalizedPolicies<P, V>>
|
|
352
|
+
) => Tables<DB, NormalizedPolicies<DB, P, V, Views>>
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { type OperationNode } from 'kysely';
|
|
2
|
+
import type { ContainerGrant, RefGrant, RelationHold, WithinGrant } from './capability';
|
|
3
|
+
import type { ConditionModel } from './conditions';
|
|
4
|
+
import type { ViewParentLink } from './guard';
|
|
5
|
+
import { type Container, type MemberRevealModel, type RelationSource, type RevealModel, type SecondaryPath, type TableModel } from './policy';
|
|
6
|
+
/** A relation of the layer: its source table, and the tables whose rows it reaches reveal an ancestor node. */
|
|
7
|
+
export interface LayerRelation extends RelationSource {
|
|
8
|
+
readonly kind: 'source';
|
|
9
|
+
readonly reveals: readonly RevealModel[];
|
|
10
|
+
/** The actions some table's `relationWhen` narrows the relation for: it holds them only on the rows that condition admits. */
|
|
11
|
+
readonly narrowed: readonly string[];
|
|
12
|
+
/**
|
|
13
|
+
* The source's and each reveal table's column for every dimension a row of it lies at, by table: where a hold inside
|
|
14
|
+
* a node finds whether a row that holds a destination lies inside that node.
|
|
15
|
+
*/
|
|
16
|
+
readonly placed: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
17
|
+
}
|
|
18
|
+
/** A relation no table confers: only access views decide what it reaches, so it has no source row to check or lock. */
|
|
19
|
+
export interface AccessRelation {
|
|
20
|
+
readonly kind: 'access';
|
|
21
|
+
readonly relation: string;
|
|
22
|
+
readonly dimension: string;
|
|
23
|
+
readonly narrowed: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** Every relation of the layer, by name, with its source table, or the mark that only access views serve it. */
|
|
26
|
+
export type RelationSources = Readonly<Record<string, LayerRelation | AccessRelation>>;
|
|
27
|
+
/** Every member reveal of the layer, by the dimension whose grants it reveals to. */
|
|
28
|
+
export type MemberReveals = Readonly<Record<string, readonly MemberRevealModel[]>>;
|
|
29
|
+
/** What a capability is held through beyond its grants: the layer's relations and its member reveals. */
|
|
30
|
+
export interface LayerReach {
|
|
31
|
+
readonly relations: RelationSources;
|
|
32
|
+
readonly members: MemberReveals;
|
|
33
|
+
}
|
|
34
|
+
export declare function relationSource(relations: RelationSources, relation: string): LayerRelation;
|
|
35
|
+
/** The relation by name, conferred or served by access views; one the layer does not know is unenforceable, never ignored. */
|
|
36
|
+
export declare function knownRelation(relations: RelationSources, relation: string): LayerRelation | AccessRelation;
|
|
37
|
+
/** A source row that confers its relation now: unexpired, and admitted by the relation's own condition. */
|
|
38
|
+
export declare function activeRow(source: RelationSource, now: Date): readonly OperationNode[];
|
|
39
|
+
/**
|
|
40
|
+
* A source row naming `principal`: `S.<principal> = $me`, or through its path `S.<column> in (select P.<key> from P where
|
|
41
|
+
* P.<column> = $me)`. Every check of a source row's principal is built here.
|
|
42
|
+
*/
|
|
43
|
+
export declare function namesPrincipal(source: RelationSource, principal: string): OperationNode;
|
|
44
|
+
export declare function isIn(table: string, name: string, nodes: OperationNode): OperationNode;
|
|
45
|
+
/**
|
|
46
|
+
* The rows of `table` whose `path` column names one of `nodes` of `dimension`: `T.<column> in (nodes)` at the path's own
|
|
47
|
+
* dimension, `T.<column> in (select D.<key> from D where D.<link> in (nodes))` at one above it; `undefined` elsewhere. A
|
|
48
|
+
* path through the nearest container reads the container's: `T.<link> in (select C.<key> from C where <C's term>)`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function throughPath(table: string, path: SecondaryPath, dimension: string, nodes: OperationNode): OperationNode | undefined;
|
|
51
|
+
/** `select R.<ancestor> from R where R.<key> in (<the relation's nodes>) and <when>`: the nodes a reveal holds `principal` at. */
|
|
52
|
+
export declare function revealedNodes(source: RelationSource, reveal: RevealModel, principal: string, now: Date): OperationNode;
|
|
53
|
+
/** Which secondary paths a statement follows: every one for a `Within`'s read, `heldThrough` for a `Ref`, none for a move. */
|
|
54
|
+
export type PathRule = (path: SecondaryPath) => boolean;
|
|
55
|
+
export declare const everyPath: PathRule;
|
|
56
|
+
export declare const noPath: PathRule;
|
|
57
|
+
/** The paths that hold `action` for a `Ref` (`writeThrough`). */
|
|
58
|
+
export declare function heldThrough(action: string): PathRule;
|
|
59
|
+
/**
|
|
60
|
+
* The rows of `model` a relation reaches for `principal` under `action`: `T.<node> in (select S.<node> from S where
|
|
61
|
+
* S.<principal> = $me and <active>)` where `model` lies at a node of the relation's dimension, and one
|
|
62
|
+
* `T.<ancestor> in (<revealed nodes>)` per reveal of `action` to an ancestor `model` lies at. Empty where neither holds.
|
|
63
|
+
* It also follows the secondary paths `paths` admits: the column `model` reaches the relation's dimension through, and
|
|
64
|
+
* the reveals matched through one. A hold inside a node narrows each term to the rows inside it, by `model`'s own
|
|
65
|
+
* column for the hold's dimension, and reaches none where `model` has no such column. Where `model`'s `relationWhen`
|
|
66
|
+
* narrows the relation for `action`, each term carries that condition too: `(<term> and (<narrowing>))`, so no builder
|
|
67
|
+
* of a relation's reach leaves either out.
|
|
68
|
+
*/
|
|
69
|
+
export declare function relationTerms(relations: RelationSources, model: TableModel, hold: RelationHold, principal: string, action: string, now: Date, paths: PathRule): readonly OperationNode[];
|
|
70
|
+
/**
|
|
71
|
+
* The rows of `model` its access views list for `hold`, each carrying the relation's `relationWhen` for `action`. A view
|
|
72
|
+
* bound to the hold's node decides which rows lie inside it, so the table's own column does not narrow it; a view bound
|
|
73
|
+
* to the principal alone is narrowed to the node by that column, and reaches nothing where `model` has none.
|
|
74
|
+
*/
|
|
75
|
+
export declare function accessReach(model: TableModel, hold: RelationHold, principal: string, action: string, now: Date): readonly OperationNode[];
|
|
76
|
+
/** `holds` without those of a relation `narrowed` names: the holds no `relationWhen` narrows. */
|
|
77
|
+
export declare function holdsBesides(holds: readonly RelationHold[], narrowed: readonly string[]): readonly RelationHold[];
|
|
78
|
+
/** The condition `model`'s `relationWhen` puts on the rows `relation` reaches for `action`, if any. */
|
|
79
|
+
export declare function relationCondition(model: TableModel, relation: string, action: string): ConditionModel | undefined;
|
|
80
|
+
/** `(<term> and (<narrowing>))`: one branch of a reach, narrowed; the one shape the guard admits a branch's condition in. */
|
|
81
|
+
export declare function narrowedTerm(term: OperationNode, narrowing: OperationNode): OperationNode;
|
|
82
|
+
/**
|
|
83
|
+
* The rows of `model` a `Within`'s read reaches through member reveals: `revealingTerms` of its grants at revealing
|
|
84
|
+
* dimensions.
|
|
85
|
+
*/
|
|
86
|
+
export declare function memberTerms(members: MemberReveals, model: TableModel, grant: WithinGrant, now: Date): readonly OperationNode[];
|
|
87
|
+
/**
|
|
88
|
+
* The rows of `model` that `revealing`, grants of `action` at nodes of revealing dimensions, reach through member
|
|
89
|
+
* reveals: per grant, `T.<ancestor> in (select R.<ancestor> from R where R.<key> in (values) and <when>)` for each reveal
|
|
90
|
+
* of `action` to an ancestor `model` lies at, `R.<key>` the row's key or its path's column. A reveal through a path
|
|
91
|
+
* counts where `paths` admits it. A grant at a dimension that reveals no node for `action` is refused: the framework
|
|
92
|
+
* passes none.
|
|
93
|
+
*/
|
|
94
|
+
export declare function revealingTerms(members: MemberReveals, model: TableModel, holder: string, action: string, revealing: readonly ContainerGrant[], now: Date, paths: PathRule): readonly OperationNode[];
|
|
95
|
+
/** `select R.<ancestor> from R where R.<key> in (values) and <when>`: the nodes a member reveal holds at for `values`. */
|
|
96
|
+
export declare function memberRevealed(reveal: MemberRevealModel, values: readonly string[], now: Date): OperationNode;
|
|
97
|
+
/** The condition `action` holds a row of `model` under, or `undefined` when the action is not narrowed there. */
|
|
98
|
+
export declare function actionCondition(model: TableModel, action: string, now: Date): OperationNode | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* `branch`, narrowed by the condition of `action`: `<reach> and (<when>)`, for a global grant `true and (<when>)`, the
|
|
101
|
+
* one shape the guard admits a condition in, so a condition never stands in for the reach.
|
|
102
|
+
*/
|
|
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;
|
|
110
|
+
/**
|
|
111
|
+
* A Ref's predicate over `links` of `model`: one equality per link of its chain (after `row`, the equality that
|
|
112
|
+
* addresses one row by its key), then, when the Ref is held through relations or member reveals, a row of one of them
|
|
113
|
+
* at the node, and its action's condition. A Ref whose relations, revealing grants and paths together reach no row of
|
|
114
|
+
* `model` is unenforceable there, never unconditioned.
|
|
115
|
+
*/
|
|
116
|
+
export declare function refScope(reach: LayerReach, model: TableModel, links: readonly Container[], grant: RefGrant, now: Date, row?: OperationNode, paths?: PathRule): OperationNode;
|
|
117
|
+
/** A child view's parent reach, split by the relations the view narrows: the rest's reach, and each such relation's own. */
|
|
118
|
+
export interface SplitReach {
|
|
119
|
+
readonly rest: OperationNode | undefined;
|
|
120
|
+
readonly relations: readonly {
|
|
121
|
+
readonly reached: OperationNode;
|
|
122
|
+
readonly condition: ConditionModel;
|
|
123
|
+
}[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The rows of a child view whose parent row `reached` admits: `V.<column> in (select P.<key> from P where <reached>)`,
|
|
127
|
+
* after `row` when it addresses one row, then the view's own condition of `action`. For `all`, every parent row, so a
|
|
128
|
+
* row whose parent column names none is still read by no capability. Split by the relations the view narrows
|
|
129
|
+
* (`relationWhen`), one such membership per part, each narrowed relation's ANDed with the view's condition for it. No
|
|
130
|
+
* column of the view places a row: its containment rests on the parent's foreign keys (ADR-0072).
|
|
131
|
+
*/
|
|
132
|
+
export declare function viewScope(model: TableModel, parent: ViewParentLink, action: string, reached: OperationNode | 'all' | SplitReach | undefined, now: Date, row?: OperationNode, access?: readonly OperationNode[]): OperationNode;
|
|
133
|
+
/**
|
|
134
|
+
* The rows a Ref held through relations, member reveals or secondary paths needs at `model`: a relation row at the node,
|
|
135
|
+
* a revealing row the Ref's grants reveal it through, or a path `paths` admits naming a node its grants hold;
|
|
136
|
+
* `undefined` for a Ref an IAM grant holds on its chain. A part that reaches no row of `model` adds nothing; when none
|
|
137
|
+
* does, the Ref is unenforceable there, never unconditioned.
|
|
138
|
+
*/
|
|
139
|
+
export declare function relationGate(reach: LayerReach, model: TableModel, grant: RefGrant, now: Date, paths?: PathRule): OperationNode | undefined;
|
|
140
|
+
/** Every term of `grant`'s relations, member reveals and paths at `model`; empty where none reaches it. */
|
|
141
|
+
export declare function gateTerms(reach: LayerReach, model: TableModel, grant: RefGrant, now: Date, paths: PathRule): readonly OperationNode[];
|
|
142
|
+
/**
|
|
143
|
+
* The rows of `model` whose path `paths` admits names a node `grants` hold: `T.<column> in (values)` at the path's own
|
|
144
|
+
* dimension, `T.<column> in (select D.<key> from D where D.<link> in (values))` above it, through the container's column
|
|
145
|
+
* for a path through the container.
|
|
146
|
+
*/
|
|
147
|
+
export declare function pathTerms(model: TableModel, grants: readonly ContainerGrant[], paths: PathRule): readonly OperationNode[];
|
package/types/src/builtins.d.ts
CHANGED
|
@@ -40,3 +40,5 @@ export declare function setOwn<V>(record: Record<string, V>, key: string, value:
|
|
|
40
40
|
export declare function defineValue(target: object, key: string, value: unknown): void;
|
|
41
41
|
/** An own property of a record, or undefined: an inherited one is never read. */
|
|
42
42
|
export declare function ownEntry<V>(record: Readonly<Record<string, V>>, key: string): V | undefined;
|
|
43
|
+
/** A copy of a plain object's own data properties; anything else (an instance, a symbol key, an accessor) is refused. */
|
|
44
|
+
export declare function plainRecord(value: unknown, what: string): Readonly<Record<string, unknown>>;
|
|
@@ -47,6 +47,32 @@ export interface RefGrant {
|
|
|
47
47
|
readonly id: string;
|
|
48
48
|
/** The values of the containers this object lies in, by dimension (`workspace → w1` for a note). */
|
|
49
49
|
readonly chain: ReadonlyMap<string, string>;
|
|
50
|
+
/**
|
|
51
|
+
* The relations the caller holds the action through on this object or a container, when no grant holds it: every
|
|
52
|
+
* statement of the Ref then also requires a row of one of them. Empty for a Ref an IAM grant holds.
|
|
53
|
+
*/
|
|
54
|
+
readonly relations: readonly RelationHold[];
|
|
55
|
+
/**
|
|
56
|
+
* The caller's grants of the action at nodes whose rows reveal the object, or a container on its chain, to their
|
|
57
|
+
* members (`memberReveals`), when no grant holds it: every statement of the Ref then also requires such a row, as
|
|
58
|
+
* for `relations`. Empty for a Ref an IAM grant holds.
|
|
59
|
+
*/
|
|
60
|
+
readonly revealing: readonly ContainerGrant[];
|
|
61
|
+
/**
|
|
62
|
+
* The caller's grants of the action at nodes of a dimension the object's table reads through a path that holds the
|
|
63
|
+
* action (`writeThrough`), or at containers of such a node, when no grant holds it on the chain: every statement then
|
|
64
|
+
* also requires the row to reach one of them through such a path. Empty for a Ref an IAM grant holds.
|
|
65
|
+
*/
|
|
66
|
+
readonly paths: readonly ContainerGrant[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A relation the caller holds the action through: anywhere (`inside: null`, a `~rel` entry), or only on rows that lie
|
|
70
|
+
* inside one of `inside`'s values (`~relin` entries of grants at those values): a row whose column for that dimension,
|
|
71
|
+
* its key at its own dimension, names one of them. A row with no such column is not inside, so the hold reaches none.
|
|
72
|
+
*/
|
|
73
|
+
export interface RelationHold {
|
|
74
|
+
readonly relation: string;
|
|
75
|
+
readonly inside: ContainerGrant | null;
|
|
50
76
|
}
|
|
51
77
|
/** The values of one container dimension in which the caller holds the action: `organization → [o1]`. */
|
|
52
78
|
export interface ContainerGrant {
|
|
@@ -75,12 +101,28 @@ export interface WithinGrant {
|
|
|
75
101
|
* the action: a row that lies in one of their values is listed, as a single-object read of it is allowed.
|
|
76
102
|
*/
|
|
77
103
|
readonly contained: readonly ContainerGrant[];
|
|
104
|
+
/**
|
|
105
|
+
* The relations through which the caller also holds the action (`~rel` and `~relin` entries of its token): a row lies
|
|
106
|
+
* in the `Within` too where a row of one of them names the caller at the row's node, read by the statement itself.
|
|
107
|
+
*/
|
|
108
|
+
readonly relations: readonly RelationHold[];
|
|
109
|
+
/**
|
|
110
|
+
* The caller's grants of the action at nodes whose rows reveal the `Within`'s dimension or a container of it to their
|
|
111
|
+
* members (`memberReveals`): a row under a node such a row reveals is read too, the statement judging the revealing row.
|
|
112
|
+
*/
|
|
113
|
+
readonly revealing: readonly ContainerGrant[];
|
|
78
114
|
}
|
|
79
|
-
/**
|
|
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
|
+
*/
|
|
80
120
|
export interface AppGrant {
|
|
81
121
|
readonly kind: 'app';
|
|
82
|
-
readonly
|
|
122
|
+
readonly actions: readonly [string, ...string[]];
|
|
83
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;
|
|
84
126
|
}
|
|
85
127
|
/** A row a claim leased: the table, its key, and the containment it had then, column by column. */
|
|
86
128
|
export interface RowGrant {
|
|
@@ -116,4 +158,10 @@ export interface CapabilityAuthority {
|
|
|
116
158
|
* request. Every mutation checks it inside its own transaction.
|
|
117
159
|
*/
|
|
118
160
|
fence(): LeaseFence | null;
|
|
161
|
+
/**
|
|
162
|
+
* What the caller of the work running now holds of `action` in `dimension`, as a `Within` of it would carry it, with
|
|
163
|
+
* no values when it holds none; `undefined` when the work has no caller (a job attempt, a webhook delivery). An
|
|
164
|
+
* insert that hands out access through a path judges its writer by it; an authority without the method has no caller.
|
|
165
|
+
*/
|
|
166
|
+
standing?(dimension: string, action: string): WithinGrant | undefined;
|
|
119
167
|
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite';
|
|
2
|
+
import { type GeneratedModule } from './codegen';
|
|
1
3
|
import { type SqliteMigrationBundle } from './sqlite-migrate';
|
|
2
4
|
/**
|
|
3
5
|
* Applies `bundles` (the framework's `fabrika`, then the application's `app`) to a fresh in-memory database and renders
|
|
4
6
|
* the module for `SCHEMA_FILE` from its application tables. Deterministic for given migrations.
|
|
5
7
|
*/
|
|
6
|
-
export declare function generateSqliteSchema(bundles: readonly SqliteMigrationBundle[]): Promise<
|
|
8
|
+
export declare function generateSqliteSchema(bundles: readonly SqliteMigrationBundle[]): Promise<GeneratedModule>;
|
|
9
|
+
/**
|
|
10
|
+
* `read` of a fresh in-memory database with foreign keys enforced and `bundles` applied, as the Durable Object applies
|
|
11
|
+
* them; the database is closed after. `fabrika-check` plans the backup of an application's schema with it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function withMigratedSqlite<T>(bundles: readonly SqliteMigrationBundle[], read: (db: Database) => T): Promise<T>;
|
package/types/src/codegen.d.ts
CHANGED
|
@@ -7,11 +7,14 @@ export interface ScalarType {
|
|
|
7
7
|
readonly select: string;
|
|
8
8
|
readonly write?: string;
|
|
9
9
|
}
|
|
10
|
+
/** A JSON column: a read answers the parsed value, which the handler parses with a schema; a write binds a JSON value. */
|
|
11
|
+
export declare const JSON_COLUMN: ScalarType;
|
|
10
12
|
export declare class CodegenError extends Error {
|
|
11
13
|
name: string;
|
|
12
14
|
}
|
|
13
15
|
declare const catalogColumnSchema: z.ZodObject<{
|
|
14
16
|
table_name: z.ZodString;
|
|
17
|
+
view: z.ZodBoolean;
|
|
15
18
|
column_name: z.ZodString;
|
|
16
19
|
type_name: z.ZodString;
|
|
17
20
|
type_type: z.ZodString;
|
|
@@ -22,6 +25,9 @@ declare const catalogColumnSchema: z.ZodObject<{
|
|
|
22
25
|
no: "no";
|
|
23
26
|
always: "always";
|
|
24
27
|
}>;
|
|
28
|
+
computed: z.ZodBoolean;
|
|
29
|
+
formatted_type: z.ZodString;
|
|
30
|
+
keyed: z.ZodBoolean;
|
|
25
31
|
enum_labels: z.ZodArray<z.ZodString>;
|
|
26
32
|
}, z.core.$strip>;
|
|
27
33
|
export type CatalogColumn = z.infer<typeof catalogColumnSchema>;
|
|
@@ -46,13 +52,43 @@ export interface Catalog {
|
|
|
46
52
|
export declare function introspectSchema(url: string, schema: string, objects: readonly DatabaseObject[]): Promise<readonly CatalogColumn[]>;
|
|
47
53
|
/** `introspectSchema`, with the foreign keys between the schema's tables. */
|
|
48
54
|
export declare function introspectCatalog(url: string, schema: string, objects: readonly DatabaseObject[]): Promise<Catalog>;
|
|
55
|
+
/** `table.column`: how a message names a column. */
|
|
56
|
+
export declare function columnPath(column: NamedColumn): string;
|
|
49
57
|
/** What the renderer needs of a column beyond its name, whichever database it was read from. */
|
|
50
58
|
export interface DescribedColumn {
|
|
51
59
|
readonly scalar: ScalarType;
|
|
52
60
|
readonly nullable: boolean;
|
|
53
61
|
readonly generated: 'no' | 'default' | 'always';
|
|
54
|
-
/** The column list field that names the column: a day, a timestamp, or (on SQLite) a boolean. */
|
|
55
|
-
readonly list: 'dates' | 'timestamps' | 'booleans' | undefined;
|
|
62
|
+
/** The column list field that names the column: a day, a timestamp, a JSON column, or (on SQLite) a boolean. */
|
|
63
|
+
readonly list: 'dates' | 'timestamps' | 'booleans' | 'json' | undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A column `describe` leaves out of the module: a generated column, or a view's column, of a type the data layer does
|
|
67
|
+
* not read.
|
|
68
|
+
*/
|
|
69
|
+
export interface LeftOut {
|
|
70
|
+
/** The column's type, as its author wrote it (empty: a SQLite view's expression, which has none). */
|
|
71
|
+
readonly leftOut: string;
|
|
72
|
+
readonly of: LeftOutKind;
|
|
73
|
+
}
|
|
74
|
+
/** Why a column is left out rather than refused: it is computed, by a generated column or by a view. */
|
|
75
|
+
export type LeftOutKind = 'generated' | 'view';
|
|
76
|
+
/** A column the module leaves out; only `ctx.sql` reaches it. */
|
|
77
|
+
export interface LeftOutColumn {
|
|
78
|
+
readonly table: string;
|
|
79
|
+
readonly column: string;
|
|
80
|
+
/** Its type, as its author wrote it. */
|
|
81
|
+
readonly type: string;
|
|
82
|
+
readonly of: LeftOutKind;
|
|
83
|
+
}
|
|
84
|
+
/** What codegen says of a left-out column: in the module, `name` is the column; in its output, `table.column`. */
|
|
85
|
+
export declare function leftOutText(name: string, type: string, of: LeftOutKind): string;
|
|
86
|
+
/** Why a left-out column refuses the schema: the table would lose a key, or a foreign key a column. */
|
|
87
|
+
export declare function leftOutRefusal(path: string, what: string): CodegenError;
|
|
88
|
+
/** The text of `SCHEMA_FILE`, and the columns it leaves out, for the command to name. */
|
|
89
|
+
export interface GeneratedModule {
|
|
90
|
+
readonly source: string;
|
|
91
|
+
readonly leftOut: readonly LeftOutColumn[];
|
|
56
92
|
}
|
|
57
93
|
/** A foreign key as the renderer reads it: the columns of `table_name` that reference `referenced_table`. */
|
|
58
94
|
export interface ForeignKeyColumns {
|
|
@@ -66,17 +102,25 @@ export interface NamedColumn {
|
|
|
66
102
|
readonly table_name: string;
|
|
67
103
|
readonly column_name: string;
|
|
68
104
|
}
|
|
105
|
+
/** A column of a table or of a view, as `renderTables` reads it. */
|
|
106
|
+
export interface RelationColumn extends NamedColumn {
|
|
107
|
+
/** The relation is a view: read-only, with no key or foreign key. */
|
|
108
|
+
readonly view: boolean;
|
|
109
|
+
}
|
|
69
110
|
/**
|
|
70
|
-
* The generated module: one interface per application table, the `DB` map Kysely and `defineTables` take,
|
|
71
|
-
* runtime column list with each table's foreign keys to application tables
|
|
72
|
-
* `fabrika db codegen --verify` can compare text.
|
|
111
|
+
* The generated module: one interface per application table and view, the `DB` map Kysely and `defineTables` take,
|
|
112
|
+
* and the runtime column list with each table's foreign keys to application tables and each view marked; with the
|
|
113
|
+
* columns it leaves out. Deterministic for a given catalog, so `fabrika db codegen --verify` can compare text.
|
|
73
114
|
*/
|
|
74
|
-
export declare function renderSchema(catalog: readonly CatalogColumn[], foreignKeys?: readonly CatalogForeignKey[]):
|
|
115
|
+
export declare function renderSchema(catalog: readonly CatalogColumn[], foreignKeys?: readonly CatalogForeignKey[]): GeneratedModule;
|
|
75
116
|
/**
|
|
76
|
-
* `renderSchema` over columns of any database: `describe` gives each column's types and list field,
|
|
77
|
-
*
|
|
117
|
+
* `renderSchema` over columns of any database: `describe` gives each column's types and list field, refuses a type the
|
|
118
|
+
* data layer does not read, or answers `LeftOut` for a generated column or a view's column of such a type. That column
|
|
119
|
+
* is left out of the module but for a comment where it stands, so no handle reads or writes it and only `ctx.sql`
|
|
120
|
+
* reaches it; a foreign key that names it, and a table it would leave without a column, are refused, and a view left
|
|
121
|
+
* without a column is left out whole. A foreign key's `constraint_name` is not rendered; keys keep the given order.
|
|
78
122
|
*/
|
|
79
|
-
export declare function renderTables<C extends
|
|
123
|
+
export declare function renderTables<C extends RelationColumn>(catalog: readonly C[], foreignKeys: readonly ForeignKeyColumns[], describe: (column: C) => DescribedColumn | LeftOut): GeneratedModule;
|
|
80
124
|
/** Introspects the migrated schema, checked against the migrations' manifest, and renders the module for `SCHEMA_FILE`. */
|
|
81
|
-
export declare function generateSchema(url: string, schema: string, objects: readonly DatabaseObject[]): Promise<
|
|
125
|
+
export declare function generateSchema(url: string, schema: string, objects: readonly DatabaseObject[]): Promise<GeneratedModule>;
|
|
82
126
|
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type OperationNode } from 'kysely';
|
|
2
|
+
import { type ConditionModel } from './conditions';
|
|
3
|
+
/** The predicate of `condition` over `table`'s rows; `now` is the statement's clock, bound as a value. */
|
|
4
|
+
export declare function conditionNode(table: string, condition: ConditionModel, now: Date): OperationNode;
|
|
5
|
+
/**
|
|
6
|
+
* `select table.key from table where <where>`: the one subquery shape the guard admits in a scope predicate. Without
|
|
7
|
+
* `where`, every row's key: only a child view's parent subquery takes that form.
|
|
8
|
+
*/
|
|
9
|
+
export declare function subquery(table: string, key: string, where?: OperationNode): OperationNode;
|