@fabrika/db 0.9.0-dev.5 → 0.9.0-dev.50
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 +62 -22
- package/src/codegen.ts +181 -42
- package/src/condition-nodes.ts +119 -0
- package/src/conditions.ts +683 -0
- package/src/description.ts +37 -8
- package/src/errors.ts +8 -4
- 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 +124 -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 +21 -6
- package/src/notifications.ts +152 -0
- package/src/orm-types.ts +208 -74
- package/src/orm.ts +368 -146
- package/src/policy.ts +1973 -141
- 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-bun.ts +41 -14
- package/src/sqlite-migrate.ts +102 -1
- package/src/sqlite.ts +46 -1
- package/src/store.ts +1930 -167
- package/src/tables.ts +156 -6
- package/src/temporal.ts +8 -1
- package/src/testing-shared.ts +758 -140
- package/src/testing-sqlite.ts +212 -40
- package/src/testing.ts +151 -22
- package/src/vocabulary-tables.ts +159 -27
- 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 +26 -8
- package/types/src/errors.d.ts +7 -4
- 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 +18 -0
- package/types/src/list-cursor.d.ts +13 -0
- package/types/src/migrations.d.ts +5 -0
- package/types/src/nodes.d.ts +4 -0
- package/types/src/notifications.d.ts +37 -0
- package/types/src/orm-types.d.ts +165 -73
- package/types/src/orm.d.ts +21 -0
- package/types/src/policy.d.ts +347 -23
- 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-bun.d.ts +11 -3
- 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 +4 -1
- package/types/src/testing-shared.d.ts +112 -23
- package/types/src/testing-sqlite.d.ts +17 -2
- package/types/src/testing.d.ts +1 -1
- package/types/src/vocabulary-tables.d.ts +169 -22
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import type { TableProbe } from './store';
|
|
2
2
|
import { type TestDatabase } from './testing-shared';
|
|
3
3
|
export { ChildTable, defineChildStore, defineStore, DimensionTable, type TableProbe } from './store';
|
|
4
|
-
export { type ApplicationRow, type IsolationWorlds, type SampleValue, SEEDED_OBJECT_VERSION, type SeededApplicationRows, type SeededRow, SeedLimitError, type TestDatabase, type WorldRow, } from './testing-shared';
|
|
4
|
+
export { type ApplicationRow, type IsolationWorlds, type SampleValue, type ScopeValues, SEEDED_OBJECT_VERSION, type SeededApplicationRows, type SeededRow, SeedLimitError, type TestDatabase, type WorldRow, } from './testing-shared';
|
|
5
5
|
export interface TestDatabaseOptions {
|
|
6
6
|
/** The application's `db/migrations/` directory. */
|
|
7
7
|
readonly migrations: string | URL;
|
|
8
8
|
/** The test file. `@fabrika/db/testing` names it when it skips; this kit never skips. */
|
|
9
9
|
readonly label: string;
|
|
10
|
+
/** A database migrated and seeded once (`testDatabaseTemplate`), which this one starts as a copy of. */
|
|
11
|
+
readonly template?: TestDatabaseTemplate;
|
|
10
12
|
}
|
|
13
|
+
/** A migrated database with its base seed, as an image every `testDatabase({ template })` copies. */
|
|
14
|
+
export interface TestDatabaseTemplate {
|
|
15
|
+
/** The migrations it was migrated with: a database of other migrations does not start from it. */
|
|
16
|
+
readonly migrations: string;
|
|
17
|
+
readonly image: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Migrates a database once, runs `seed` in it, and keeps it as the image each `testDatabase({ template })` starts as a
|
|
21
|
+
* copy of: in milliseconds, without migrating or seeding again.
|
|
22
|
+
*/
|
|
23
|
+
export declare function testDatabaseTemplate(options: Omit<TestDatabaseOptions, 'template'> & {
|
|
24
|
+
readonly seed?: (database: TestDatabase) => Promise<void>;
|
|
25
|
+
}): Promise<TestDatabaseTemplate>;
|
|
11
26
|
/**
|
|
12
27
|
* A fresh in-memory database with the framework's and the application's migrations applied by the runner a Durable
|
|
13
28
|
* Object boots with (`@fabrika/db/sqlite-migrate`), opened with its engine (`@fabrika/db/sqlite`). Never `null`: it
|
|
14
|
-
* 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
|
|
15
30
|
* that checks for `null` compiles against both kits.
|
|
16
31
|
*/
|
|
17
32
|
export declare function testDatabase(options: TestDatabaseOptions): Promise<TestDatabase>;
|
package/types/src/testing.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TableProbe } from './store';
|
|
2
2
|
import { type TestDatabase } from './testing-shared';
|
|
3
3
|
export { ChildTable, defineChildStore, defineStore, DimensionTable, type TableProbe } from './store';
|
|
4
|
-
export { type ApplicationRow, type IsolationWorlds, type SampleValue, SEEDED_OBJECT_VERSION, type SeededApplicationRows, type SeededRow, SeedLimitError, type TestDatabase, type WorldRow, } from './testing-shared';
|
|
4
|
+
export { type ApplicationRow, type IsolationWorlds, type SampleValue, type ScopeValues, SEEDED_OBJECT_VERSION, type SeededApplicationRows, type SeededRow, SeedLimitError, type TestDatabase, type WorldRow, } from './testing-shared';
|
|
5
5
|
export declare const TEST_POSTGRES_URL = "FABRIKA_TEST_POSTGRES_URL";
|
|
6
6
|
/** Set to `1` by the platform build: a missing test database is then a failure, not a skip. */
|
|
7
7
|
export declare const TEST_POSTGRES_REQUIRED = "FABRIKA_TEST_POSTGRES_REQUIRED";
|
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ConditionPolicy } from './conditions';
|
|
2
|
+
import type { AccessPolicy, ApplicationActions, ColumnList, ColumnPolicies, ConfersPolicy, FilePolicies, MemberRevealsPolicy, RecordActions, ReferencePolicy, RevealsPolicy, TableAction, TableActions, Tables, VersionColumn } from './policy';
|
|
2
3
|
declare const databaseType: unique symbol;
|
|
4
|
+
declare const viewNames: unique symbol;
|
|
3
5
|
/**
|
|
4
|
-
* The generated column list (`src/db/schema.generated.ts`), which also carries the schema's row types
|
|
5
|
-
* `defineTables(vocabulary, columns)` takes no type argument. The
|
|
6
|
+
* The generated column list (`src/db/schema.generated.ts`), which also carries the schema's row types and the names of
|
|
7
|
+
* its views, so that `defineTables(vocabulary, columns)` takes no type argument. The brands are type-only: no value
|
|
8
|
+
* has either property.
|
|
6
9
|
*/
|
|
7
|
-
export type TypedColumnList<DB> = ColumnList<DB> & {
|
|
10
|
+
export type TypedColumnList<DB, Views extends keyof DB & string = never> = ColumnList<DB> & {
|
|
8
11
|
readonly [databaseType]?: DB;
|
|
12
|
+
readonly [viewNames]?: {
|
|
13
|
+
readonly views: Views;
|
|
14
|
+
};
|
|
9
15
|
};
|
|
10
16
|
/** The row types a typed column list carries; `never` for a list without them. */
|
|
11
17
|
export type ColumnTypes<C> = typeof databaseType extends keyof C ? C extends {
|
|
12
18
|
readonly [databaseType]?: infer DB;
|
|
13
19
|
} ? Exclude<DB, undefined> : never : never;
|
|
20
|
+
/** The views a typed column list names; `never` for a list without views. */
|
|
21
|
+
export type ColumnViews<C> = typeof viewNames extends keyof C ? C extends {
|
|
22
|
+
readonly [viewNames]?: {
|
|
23
|
+
readonly views: infer Views extends string;
|
|
24
|
+
};
|
|
25
|
+
} ? Views : never : never;
|
|
14
26
|
/**
|
|
15
27
|
* What `defineTables(vocabulary, columns)` reads of `@fabrika/app/contract`'s `defineVocabulary` result: the action
|
|
16
28
|
* and dimension names, and each dimension's container. `@fabrika/db` does not import `@fabrika/app`.
|
|
@@ -24,6 +36,11 @@ export interface TableVocabulary {
|
|
|
24
36
|
readonly in?: string;
|
|
25
37
|
};
|
|
26
38
|
};
|
|
39
|
+
readonly relations?: {
|
|
40
|
+
readonly [relation: string]: {
|
|
41
|
+
readonly dimension: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
27
44
|
}
|
|
28
45
|
export type VocabularyAction<V> = V extends {
|
|
29
46
|
readonly actions: infer A;
|
|
@@ -72,15 +89,64 @@ export type VocabularyChildScope<Table extends string, Col extends string> = {
|
|
|
72
89
|
readonly column?: Col;
|
|
73
90
|
readonly inherit?: readonly Col[];
|
|
74
91
|
} & KeyField<Col>;
|
|
75
|
-
|
|
92
|
+
/** A written table whose `version` column is not an INTEGER names its version column: `version` would be it otherwise. */
|
|
93
|
+
interface NamesItsVersionColumn<Ver extends string> {
|
|
94
|
+
readonly version: Ver;
|
|
95
|
+
}
|
|
96
|
+
/** `version` defaults to the `version` column, so it is required only where that column holds no number. */
|
|
97
|
+
type VersionField<Col extends string, Ver extends Col> = 'version' extends Col ? 'version' extends Ver ? {
|
|
98
|
+
readonly version?: Ver;
|
|
99
|
+
} : NamesItsVersionColumn<Ver> : {
|
|
100
|
+
readonly version?: Ver;
|
|
101
|
+
};
|
|
102
|
+
interface WritableFields<Col extends string, A extends string, Acts = TableActions<A>> {
|
|
76
103
|
readonly actions: Acts;
|
|
77
104
|
readonly insert?: readonly Col[];
|
|
78
105
|
readonly update?: readonly Col[];
|
|
79
|
-
readonly version?: Ver;
|
|
80
106
|
readonly createdBy?: Col;
|
|
81
107
|
readonly columns?: ColumnPolicies<Col, A>;
|
|
82
108
|
/** The file columns, each with the file kind it holds (`c.files`): a `uuid` foreign key to `fabrika_files`. */
|
|
83
109
|
readonly files?: FilePolicies<Col>;
|
|
110
|
+
/** Relation → how a row of this table confers it: whom it names, at which node, until when. */
|
|
111
|
+
readonly confers?: {
|
|
112
|
+
readonly [relation: string]: ConfersPolicy<Col>;
|
|
113
|
+
};
|
|
114
|
+
/** Action → the condition a row must meet for it, whoever holds it. */
|
|
115
|
+
readonly when?: {
|
|
116
|
+
readonly [action in A]?: ConditionPolicy<Col>;
|
|
117
|
+
};
|
|
118
|
+
/** Relation → action → the condition a row that relation reaches must meet for it; IAM grants are not narrowed. */
|
|
119
|
+
readonly relationWhen?: {
|
|
120
|
+
readonly [relation: string]: {
|
|
121
|
+
readonly [action in A]?: ConditionPolicy<Col>;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
/** Relation of the table's own dimension → the ancestor node a row it reaches reveals, and for which actions. */
|
|
125
|
+
readonly reveals?: {
|
|
126
|
+
readonly [relation: string]: RevealsPolicy<Col, A>;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Dimension outside the chain → the foreign key column a `Within`'s read reaches a row through, no update writes it; or
|
|
130
|
+
* `<nearest container column>.<its column>`, the nearest container's own path.
|
|
131
|
+
*/
|
|
132
|
+
readonly readThrough?: {
|
|
133
|
+
readonly [dimension: string]: Col | `${Col}.${string}`;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Dimension of `readThrough` → the actions a `Ref` held through that path holds, writes included; whoever inserts the
|
|
137
|
+
* path's column must hold each at the node it names.
|
|
138
|
+
*/
|
|
139
|
+
readonly writeThrough?: {
|
|
140
|
+
readonly [dimension: string]: readonly A[];
|
|
141
|
+
};
|
|
142
|
+
/** The table's own dimension → the ancestor node a row reveals to a grant at its node, for a `Within`'s reads. */
|
|
143
|
+
readonly memberReveals?: {
|
|
144
|
+
readonly [dimension: string]: MemberRevealsPolicy<Col, A>;
|
|
145
|
+
};
|
|
146
|
+
/** Relation → the access view that lists the rows it reaches: the escape path, decided by the view's SQL. */
|
|
147
|
+
readonly access?: {
|
|
148
|
+
readonly [relation: string]: AccessPolicy;
|
|
149
|
+
};
|
|
84
150
|
}
|
|
85
151
|
/**
|
|
86
152
|
* The scope of the dimension the policy states (`S`, its scope as written); for any other name, the dimension alone,
|
|
@@ -128,14 +194,72 @@ type ChildScopes<Table extends string, Col extends string, S, P> = unknown exten
|
|
|
128
194
|
} ? T : never;
|
|
129
195
|
}[keyof P] & string;
|
|
130
196
|
} : ChildTableScope<Parent, StatedDimensionOf<P, Parent>, Col> : VocabularyChildScope<Table, Col>;
|
|
131
|
-
type AuthoredDimensionPolicy<Col extends string, A extends string, V, Ver extends Col, S> = WritableFields<Col, A,
|
|
197
|
+
type AuthoredDimensionPolicy<Col extends string, A extends string, V, Ver extends Col, S> = WritableFields<Col, A, RecordActions<A>> & VersionField<Col, Ver> & {
|
|
132
198
|
readonly scope: DimensionScopes<V, Col, S>;
|
|
133
199
|
};
|
|
134
|
-
type AuthoredChildPolicy<Table extends string, Col extends string, A extends string, Ver extends Col, S, P> = WritableFields<Col, A,
|
|
200
|
+
type AuthoredChildPolicy<Table extends string, Col extends string, A extends string, Ver extends Col, S, P> = WritableFields<Col, A, RecordActions<A>> & VersionField<Col, Ver> & {
|
|
135
201
|
readonly scope: ChildScopes<Table, Col, S, P>;
|
|
136
202
|
};
|
|
203
|
+
/** What a view's policy holds besides its scope: read actions only, no write list and no stamped column. */
|
|
204
|
+
type ViewIsReadOnly = 'a view is never written: its actions are read, appRead and appCount';
|
|
205
|
+
/** The write actions a view's policy may not name, each typed as the message: a literal is not checked for excess keys. */
|
|
206
|
+
interface NoWriteActions {
|
|
207
|
+
readonly insert?: ViewIsReadOnly;
|
|
208
|
+
readonly update?: ViewIsReadOnly;
|
|
209
|
+
readonly delete?: ViewIsReadOnly;
|
|
210
|
+
}
|
|
211
|
+
interface ReadOnlyFields<Col extends string, A extends string> {
|
|
212
|
+
readonly actions: {
|
|
213
|
+
readonly read: TableAction<A>;
|
|
214
|
+
readonly appRead?: readonly A[];
|
|
215
|
+
readonly appCount?: readonly A[];
|
|
216
|
+
} & NoWriteActions;
|
|
217
|
+
readonly insert?: never;
|
|
218
|
+
readonly update?: never;
|
|
219
|
+
readonly version?: never;
|
|
220
|
+
readonly createdBy?: never;
|
|
221
|
+
readonly queue?: never;
|
|
222
|
+
readonly files?: never;
|
|
223
|
+
readonly columns?: {
|
|
224
|
+
readonly [C in Col]?: {
|
|
225
|
+
readonly read: TableAction<A>;
|
|
226
|
+
readonly write?: never;
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* A view read as a child table: its parent's `Ref` and `Within` read it; nothing writes it (ADR-0072). Its `when` and
|
|
232
|
+
* `relationWhen` narrow its read actions; a path may start at its parent column, to the parent row.
|
|
233
|
+
*/
|
|
234
|
+
type AuthoredChildViewPolicy<Table extends string, Col extends string, A extends string, S, P> = ReadOnlyFields<Col, A> & {
|
|
235
|
+
readonly scope: ChildScopes<Table, Col, S, P>;
|
|
236
|
+
readonly when?: {
|
|
237
|
+
readonly [action in A]?: ConditionPolicy<Col>;
|
|
238
|
+
};
|
|
239
|
+
/** Relation → action → the condition a row the relation reaches through the parent row must meet for it. */
|
|
240
|
+
readonly relationWhen?: {
|
|
241
|
+
readonly [relation: string]: {
|
|
242
|
+
readonly [action in A]?: ConditionPolicy<Col>;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
/** A view's policy as written: a read-only child, or a reference table every site reads. */
|
|
247
|
+
export type VocabularyViewPolicy<Table extends string, Col extends string, A extends string, S = unknown, P = unknown> = S extends {
|
|
248
|
+
readonly child: unknown;
|
|
249
|
+
} ? AuthoredChildViewPolicy<Table, Col, A, S, P> : S extends {
|
|
250
|
+
readonly reference: unknown;
|
|
251
|
+
} ? ReferenceViewPolicy<Col, A> : AuthoredChildViewPolicy<Table, Col, A, S, P> | ReferenceViewPolicy<Col, A>;
|
|
252
|
+
type ReferenceViewPolicy<Col extends string, A extends string> = ReferencePolicy<Col, A> & {
|
|
253
|
+
readonly actions: NoWriteActions;
|
|
254
|
+
readonly columns?: {
|
|
255
|
+
readonly [C in Col]?: {
|
|
256
|
+
readonly read: TableAction<A>;
|
|
257
|
+
readonly write?: never;
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
};
|
|
137
261
|
/** An application table's scope: why its rows belong to no dimension; `key` defaults to `id`. */
|
|
138
|
-
type AuthoredApplicationPolicy<Col extends string, A extends string, Ver extends Col> = WritableFields<Col, A, Ver> & {
|
|
262
|
+
type AuthoredApplicationPolicy<Col extends string, A extends string, Ver extends Col> = WritableFields<Col, A, ApplicationActions<A>> & VersionField<Col, Ver> & {
|
|
139
263
|
readonly scope: {
|
|
140
264
|
readonly app: string;
|
|
141
265
|
} & KeyField<Col>;
|
|
@@ -158,13 +282,18 @@ type StatedScope<P, T> = T extends keyof P ? P[T] extends {
|
|
|
158
282
|
} ? S : unknown : unknown;
|
|
159
283
|
/** The policy of table `T` with nothing stated: every form, every dimension's scope, any parent. */
|
|
160
284
|
type AnyTablePolicy<DB, V, T extends keyof DB & string> = VocabularyTablePolicy<keyof DB & string, keyof DB[T] & string, VocabularyAction<V>, V, VersionColumn<DB[T]>>;
|
|
285
|
+
/** The policy of view `T` with nothing stated: both forms, any parent. */
|
|
286
|
+
type AnyViewPolicy<DB, V, T extends keyof DB & string> = VocabularyViewPolicy<keyof DB & string, keyof DB[T] & string, VocabularyAction<V>>;
|
|
161
287
|
/**
|
|
162
|
-
* Every table of the schema, and no other, maps to a policy; a
|
|
163
|
-
* `P` is the policies as written, which picks each table's form by the scope it
|
|
164
|
-
* map's own annotation states nothing narrower, so it is checked against every
|
|
288
|
+
* Every table of the schema, and no other, maps to a policy; a view `Views` names may (ADR-0072). A misspelt action or
|
|
289
|
+
* dimension fails at its own line. `P` is the policies as written, which picks each table's form by the scope it
|
|
290
|
+
* states; a policy written under this map's own annotation states nothing narrower, so it is checked against every
|
|
291
|
+
* form.
|
|
165
292
|
*/
|
|
166
|
-
export type VocabularyPolicyMap<DB, V, P = unknown> = {
|
|
167
|
-
readonly [T in keyof DB & string]: AnyTablePolicy<DB, V, T> extends (T extends keyof P ? P[T] : unknown) ? AnyTablePolicy<DB, V, T> : VocabularyTablePolicy<keyof DB & string, keyof DB[T] & string, VocabularyAction<V>, V, VersionColumn<DB[T]>, StatedScope<P, T>, P>;
|
|
293
|
+
export type VocabularyPolicyMap<DB, V, P = unknown, Views extends string = never> = {
|
|
294
|
+
readonly [T in Exclude<keyof DB & string, Views>]: AnyTablePolicy<DB, V, T> extends (T extends keyof P ? P[T] : unknown) ? AnyTablePolicy<DB, V, T> : VocabularyTablePolicy<keyof DB & string, keyof DB[T] & string, VocabularyAction<V>, V, VersionColumn<DB[T]>, StatedScope<P, T>, P>;
|
|
295
|
+
} & {
|
|
296
|
+
readonly [T in Views & keyof DB & string]?: AnyViewPolicy<DB, V, T> extends (T extends keyof P ? P[T] : unknown) ? AnyViewPolicy<DB, V, T> : VocabularyViewPolicy<keyof DB & string, keyof DB[T] & string, VocabularyAction<V>, StatedScope<P, T>, P>;
|
|
168
297
|
};
|
|
169
298
|
type Flat<T> = {
|
|
170
299
|
[K in keyof T]: T[K];
|
|
@@ -207,19 +336,37 @@ type NormalScope<S, V, P> = S extends {
|
|
|
207
336
|
readonly app: R;
|
|
208
337
|
readonly key: KeyOf<S>;
|
|
209
338
|
} : S;
|
|
339
|
+
/** A view's normalized policy says so, which the handle types read: no site writes it. */
|
|
340
|
+
type ViewMark<T, Views> = T extends Views ? {
|
|
341
|
+
readonly view: true;
|
|
342
|
+
} : unknown;
|
|
343
|
+
/** A written table's `version` and `created_by` columns are its version and creator unless its policy names others. */
|
|
344
|
+
type Conventions<Row, Pol> = (Pol extends {
|
|
345
|
+
readonly version: string;
|
|
346
|
+
} ? unknown : 'version' extends keyof Row ? {
|
|
347
|
+
readonly version: 'version';
|
|
348
|
+
} : unknown) & (Pol extends {
|
|
349
|
+
readonly createdBy: string;
|
|
350
|
+
} ? unknown : 'created_by' extends keyof Row ? {
|
|
351
|
+
readonly createdBy: 'created_by';
|
|
352
|
+
} : unknown);
|
|
353
|
+
/** Only a dimension, child or application table is written; a view and a reference table get no convention. */
|
|
354
|
+
type WrittenConventions<DB, T, Pol, S, Views> = T extends Views ? unknown : S extends {
|
|
355
|
+
readonly reference: unknown;
|
|
356
|
+
} ? unknown : Conventions<T extends keyof DB ? DB[T] : never, Pol>;
|
|
210
357
|
/**
|
|
211
|
-
* The policies as the layer models them: every dimension table's key and container,
|
|
212
|
-
*
|
|
358
|
+
* The policies as the layer models them: every dimension table's key and container, every child's key and column,
|
|
359
|
+
* and a written table's version and creator, stated as the vocabulary and the conventions derive them; each view marked.
|
|
213
360
|
*/
|
|
214
|
-
export type NormalizedPolicies<P, V> = {
|
|
361
|
+
export type NormalizedPolicies<DB, P, V, Views = never> = {
|
|
215
362
|
readonly [T in keyof P]: P[T] extends {
|
|
216
363
|
readonly scope: infer S;
|
|
217
|
-
} ? Flat<Omit<P[T], 'scope'> & {
|
|
364
|
+
} ? Flat<Omit<P[T], 'scope' | 'view'> & {
|
|
218
365
|
readonly scope: NormalScope<S, V, P>;
|
|
219
|
-
}> : P[T];
|
|
366
|
+
} & ViewMark<T, Views> & WrittenConventions<DB, T, P[T], S, Views>> : P[T];
|
|
220
367
|
};
|
|
221
|
-
/** Takes the policies of exactly the tables of the schema, written in the vocabulary form. */
|
|
222
|
-
export type DefineVocabularyPolicies<DB, V> = <const P extends VocabularyPolicyMap<DB, V, P>>(policies: P & {
|
|
368
|
+
/** Takes the policies of exactly the tables of the schema, and of any of its views, written in the vocabulary form. */
|
|
369
|
+
export type DefineVocabularyPolicies<DB, V, Views extends string = never> = <const P extends VocabularyPolicyMap<DB, V, P, Views>>(policies: P & {
|
|
223
370
|
readonly [K in Exclude<keyof P, keyof DB>]: never;
|
|
224
|
-
}) => Tables<DB, NormalizedPolicies<P, V>>;
|
|
371
|
+
}) => Tables<DB, NormalizedPolicies<DB, P, V, Views>>;
|
|
225
372
|
export {};
|