@fabrika/db 0.9.0-dev.3 → 0.9.0-dev.30

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.
Files changed (82) hide show
  1. package/package.json +39 -4
  2. package/src/admissions.ts +78 -12
  3. package/src/application-rows.ts +108 -0
  4. package/src/authority.ts +560 -0
  5. package/src/builtins.ts +21 -0
  6. package/src/capability.ts +56 -2
  7. package/src/codegen-sqlite.ts +194 -0
  8. package/src/codegen.ts +230 -41
  9. package/src/condition-nodes.ts +119 -0
  10. package/src/conditions.ts +683 -0
  11. package/src/database.ts +227 -61
  12. package/src/description.ts +37 -8
  13. package/src/errors.ts +8 -5
  14. package/src/file-columns.ts +56 -11
  15. package/src/framework-tables.ts +28 -8
  16. package/src/framework.ts +15 -5
  17. package/src/guard.ts +373 -15
  18. package/src/index.ts +17 -1
  19. package/src/job-leases.ts +212 -55
  20. package/src/job-wakes.ts +450 -0
  21. package/src/json.ts +124 -0
  22. package/src/links.ts +8 -1
  23. package/src/migrations-sqlite.ts +181 -0
  24. package/src/migrations.ts +43 -0
  25. package/src/nodes.ts +84 -14
  26. package/src/orm-types.ts +198 -67
  27. package/src/orm.ts +383 -133
  28. package/src/policy.ts +1933 -122
  29. package/src/postgres.ts +26 -0
  30. package/src/registry.ts +55 -3
  31. package/src/request-receipts.ts +107 -0
  32. package/src/sql.ts +247 -476
  33. package/src/sqlite-bun.ts +149 -0
  34. package/src/sqlite-migrate.ts +242 -0
  35. package/src/sqlite.ts +269 -0
  36. package/src/store.ts +2292 -239
  37. package/src/stored-files.ts +188 -52
  38. package/src/tables.ts +171 -5
  39. package/src/temporal.ts +122 -9
  40. package/src/testing-shared.ts +1348 -0
  41. package/src/testing-sqlite.ts +685 -0
  42. package/src/testing.ts +310 -494
  43. package/src/vocabulary-tables.ts +159 -27
  44. package/types/src/application-rows.d.ts +58 -0
  45. package/types/src/authority.d.ts +147 -0
  46. package/types/src/builtins.d.ts +2 -0
  47. package/types/src/capability.d.ts +55 -2
  48. package/types/src/codegen-sqlite.d.ts +13 -0
  49. package/types/src/codegen.d.ts +79 -5
  50. package/types/src/condition-nodes.d.ts +9 -0
  51. package/types/src/conditions.d.ts +151 -0
  52. package/types/src/database.d.ts +81 -20
  53. package/types/src/description.d.ts +26 -8
  54. package/types/src/errors.d.ts +7 -5
  55. package/types/src/file-columns.d.ts +6 -4
  56. package/types/src/framework.d.ts +12 -5
  57. package/types/src/guard.d.ts +24 -0
  58. package/types/src/index.d.ts +5 -4
  59. package/types/src/job-leases.d.ts +34 -5
  60. package/types/src/job-wakes.d.ts +101 -0
  61. package/types/src/json.d.ts +18 -0
  62. package/types/src/migrations-sqlite.d.ts +4 -0
  63. package/types/src/migrations.d.ts +2 -0
  64. package/types/src/nodes.d.ts +17 -2
  65. package/types/src/orm-types.d.ts +155 -63
  66. package/types/src/orm.d.ts +21 -0
  67. package/types/src/policy.d.ts +344 -16
  68. package/types/src/postgres.d.ts +12 -0
  69. package/types/src/registry.d.ts +40 -3
  70. package/types/src/request-receipts.d.ts +22 -0
  71. package/types/src/sql.d.ts +29 -21
  72. package/types/src/sqlite-bun.d.ts +21 -0
  73. package/types/src/sqlite-migrate.d.ts +28 -0
  74. package/types/src/sqlite.d.ts +24 -0
  75. package/types/src/store.d.ts +143 -34
  76. package/types/src/stored-files.d.ts +6 -2
  77. package/types/src/tables.d.ts +18 -2
  78. package/types/src/temporal.d.ts +24 -0
  79. package/types/src/testing-shared.d.ts +290 -0
  80. package/types/src/testing-sqlite.d.ts +37 -0
  81. package/types/src/testing.d.ts +2 -93
  82. package/types/src/vocabulary-tables.d.ts +169 -22
@@ -0,0 +1,290 @@
1
+ import type { Database } from './database';
2
+ import type { Primitive } from './description';
3
+ import { type Tables } from './policy';
4
+ import type { TableProbe } from './store';
5
+ /** A value a test row holds in a column; `null` for a nullable column the fixture left empty. */
6
+ export type SampleValue = Primitive | null;
7
+ /**
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 kits' cases that write the same value through the layer hold the same JSON.
10
+ */
11
+ export declare function seedBinding(columns: readonly SeedColumn[], table: string, name: string, value: SampleValue): SampleValue;
12
+ /** One seeded row and where it lies. */
13
+ export interface WorldRow {
14
+ /** The row's key: the dimension value of a dimension table's row, a child's own key. */
15
+ readonly key: string;
16
+ /** A child row's parent key; `null` for a dimension table. */
17
+ readonly parent: string | null;
18
+ /** The value of the grant dimension the row lies in (`IsolationWorlds.dimension`). */
19
+ readonly scope: string;
20
+ /**
21
+ * Every dimension value the row lies in: a dimension table's own first, then each container, innermost first. A
22
+ * share link's chain is this list.
23
+ */
24
+ readonly chain: readonly {
25
+ readonly type: string;
26
+ readonly value: string;
27
+ }[];
28
+ /** The row's values of the policy's update columns: as seeded, or as stored where the database filled them. */
29
+ readonly updates: Readonly<Record<string, SampleValue>>;
30
+ /**
31
+ * The distinct value written into every text column the fixture filled itself, in this row and in its containers.
32
+ * Each occurs in no other fixture, so one found in an answer to another scope is a leaked row.
33
+ */
34
+ readonly markers: readonly string[];
35
+ /**
36
+ * The values of the text columns of a row the table already held under a known scope value (`seedWorlds`' `scopes`),
37
+ * which no fixture wrote and other rows may share; empty for a row the fixture inserted.
38
+ */
39
+ readonly stored: readonly string[];
40
+ }
41
+ /** One seeded row of an application table, which lies in no dimension. */
42
+ export interface ApplicationRow {
43
+ readonly key: string;
44
+ /** The row's values of the policy's update columns: as seeded, or as stored where the database filled them. */
45
+ readonly updates: Readonly<Record<string, SampleValue>>;
46
+ /** The distinct value written into every text column the fixture filled itself. */
47
+ readonly markers: readonly string[];
48
+ }
49
+ /** Rows of application tables seeded together for one case, and their removal once the case is over. */
50
+ export interface SeededApplicationRows {
51
+ /** Each table's row key, by table. */
52
+ readonly keys: Readonly<Record<string, string>>;
53
+ /**
54
+ * Deletes the rows, the rows their required foreign keys and file columns made the fixture insert, and every row
55
+ * that refers to one of them, however deep (what the case's handler wrote about them), in one transaction, so rows
56
+ * that refer to each other go together. A row already gone is skipped.
57
+ */
58
+ remove(): Promise<void>;
59
+ }
60
+ /** A row seeded under another: its key, and the distinct value written into every text column the fixture filled. */
61
+ export interface SeededRow {
62
+ readonly key: string;
63
+ readonly markers: readonly string[];
64
+ /** Deletes the row, the rows its foreign keys made the fixture insert, and every row that refers to them. */
65
+ readonly remove: () => Promise<void>;
66
+ }
67
+ /**
68
+ * What the isolation fixture cannot seed for a schema: a CHECK or a unique index no row it tries passes, a required
69
+ * foreign key whose referenced row it cannot seed. It is a limit of the generator, named with the constraint or the
70
+ * column, never a failure of the handler or the policy a case is about.
71
+ */
72
+ export declare class SeedLimitError extends Error {
73
+ readonly name = "SeedLimitError";
74
+ }
75
+ /** The constraint a seeded row failed, as a backend reads it off the database's error. */
76
+ export interface Violation {
77
+ readonly kind: 'check' | 'unique' | 'foreign';
78
+ /** The constraint's name, or for an unnamed CHECK on SQLite its expression, as the database reports it. */
79
+ readonly name: string;
80
+ /** The columns the database names (SQLite's unique error); `undefined` where the seeding looks them up by `name`. */
81
+ readonly columns?: readonly string[];
82
+ }
83
+ /** A seed limit of a row the database refused, with the constraint it failed: the seeding tries another row. */
84
+ export declare class ConstraintLimitError extends SeedLimitError {
85
+ readonly violation: Violation;
86
+ constructor(message: string, violation: Violation);
87
+ }
88
+ /** One row of a table in each of two containment chains that share no value. */
89
+ export interface IsolationWorlds {
90
+ /**
91
+ * The dimension a caller's grants are scoped by: a dimension table's container, or its own dimension when it has
92
+ * none; a child table's parent's.
93
+ */
94
+ readonly dimension: string;
95
+ readonly own: WorldRow;
96
+ readonly other: WorldRow;
97
+ /**
98
+ * Deletes both rows of the table it inserted, every container row it inserted when it was given known scope values,
99
+ * and every row that refers to them, however deep; the other containers stay. A case whose rows hold pinned values or
100
+ * known scope values removes them, so the next case can seed the same values again under a unique index.
101
+ */
102
+ readonly remove: () => Promise<void>;
103
+ }
104
+ /**
105
+ * Known values of dimensions, by dimension: the own world's and the other world's, which differ. A dimension whose values
106
+ * are a fixed set (an enum the input names it by) takes these instead of fresh ones.
107
+ */
108
+ export type ScopeValues = Readonly<Record<string, {
109
+ readonly own: string;
110
+ readonly other: string;
111
+ }>>;
112
+ /** What a test kit seeds through, over its migrated schema. */
113
+ export interface TestSeeding {
114
+ /**
115
+ * Seeds one row of `table` in each of two fresh chains, with every container row a table owns. `values` (column →
116
+ * value) are written into both rows of `table`: the state an endpoint's precondition needs. A text column keeps its
117
+ * marker, so a seed of one, or of a column that places the row, throws. `pins` (column → value) give a text column of
118
+ * `table` a known value instead of its marker: the value in the own row, and `<value>-other` in the other row, which
119
+ * counts among the other row's markers, so a leak of it is still found. A pin of a column that places the row, or of
120
+ * no text column, throws. `scopes` place each world in known values of a dimension instead of fresh ones: a row of
121
+ * the table that owns it with that key is used as it is stored (a migration wrote it), its containers' values with it,
122
+ * and is inserted otherwise. A stored row of `table` itself takes no `values` or `pins`: they throw. A seed that throws
123
+ * removes what it inserted.
124
+ */
125
+ seedWorlds<DB, P>(tables: Tables<DB, P>, table: string, values?: Readonly<Record<string, SampleValue>>, pins?: Readonly<Record<string, string>>, scopes?: ScopeValues): Promise<IsolationWorlds>;
126
+ /**
127
+ * Seeds one row of the application table `table`: its key, version and creator stamped, `values` (column → value)
128
+ * as given, a text column too, every other column sampled. A value for a stamped column or a file column throws.
129
+ */
130
+ seedRow<DB, P>(tables: Tables<DB, P>, table: string, values?: Readonly<Record<string, SampleValue>>): Promise<ApplicationRow>;
131
+ /**
132
+ * Seeds one row of each application table `rows` names (table → column → value), as `seedRow` does, in foreign-key
133
+ * order: a foreign key from one of them to another holds that row's key unless the values give it. Every table's
134
+ * values are checked before the first insert, and a table that fails removes the rows seeded before it. `remove`
135
+ * deletes them, the rows a required foreign key of theirs made it insert, and every row that refers to any of them,
136
+ * so the next case starts without them.
137
+ */
138
+ seedApplicationRows<DB, P>(tables: Tables<DB, P>, rows: Readonly<Record<string, Readonly<Record<string, SampleValue>>>>): Promise<SeededApplicationRows>;
139
+ /**
140
+ * Seeds one row of `table`, a child or dimension table that lies in the object `under`'s chain starts at (a row
141
+ * `seedWorlds` seeded, or a value of its chain with the values outside it), placed in that chain: the row a fixture
142
+ * names by id, such as a note's comment. Answers its key and the markers it holds.
143
+ */
144
+ seedUnder<DB, P>(tables: Tables<DB, P>, table: string, under: Pick<WorldRow, 'chain'>): Promise<SeededRow>;
145
+ /**
146
+ * Values for the policy's insert columns of `table` that its schema accepts: every required one, sampled; a file
147
+ * column a seeded file. `beside` is a row `seedWorlds` seeded that the inserted row will lie beside, in the same
148
+ * containers. A number column a unique index covers takes the next number above the largest the table holds now in the
149
+ * row's group (the index's other columns as the row will have them, its containers' from `beside`), so insert the
150
+ * values before taking the next sample, or the two share it.
151
+ */
152
+ sampleInsert<DB, P>(tables: Tables<DB, P>, table: string, beside?: WorldRow): Promise<Readonly<Record<string, SampleValue>>>;
153
+ /**
154
+ * The object key of every file the fixture seeded into a file column, oldest first. Each stands for an empty object,
155
+ * which a test's object store holds when a handler serves or opens the file.
156
+ */
157
+ seededObjects(): readonly string[];
158
+ }
159
+ export interface TestDatabase extends TestSeeding {
160
+ /** The connection `boot` binds the data layer to: on Postgres the runtime role on the migrated schema; on SQLite the database itself. */
161
+ readonly database: Database;
162
+ /** The migrated schema: `app_test_<hex>` on Postgres, `main` on SQLite. */
163
+ readonly schema: string;
164
+ /** Closes the connections and drops the schema and its roles (on SQLite: closes the in-memory database). */
165
+ close(): Promise<void>;
166
+ }
167
+ /** A column of the migrated schema, as the seeding reads it. */
168
+ export interface SeedColumn {
169
+ readonly table: string;
170
+ readonly name: string;
171
+ /** The type as the database names it, for a message. */
172
+ readonly type: string;
173
+ readonly nullable: boolean;
174
+ /** The database fills it when an insert leaves it out: a default, an identity, a generated column. */
175
+ readonly defaulted: boolean;
176
+ /** A text type that is no enum: where nothing else fills it, the fixture writes a marker into it. */
177
+ readonly text: boolean;
178
+ /** A uuid type: a key or containment column of it holds a random uuid as its scope value. */
179
+ readonly uuid: boolean;
180
+ /** A number type: where a unique index covers it, the fixture writes the next number of the row's group instead of its sample. */
181
+ readonly number: boolean;
182
+ /** A JSON column (`jsonb`, `JSONB`): its value is a JSON value, bound as the layer binds it (`seedBinding`). */
183
+ readonly json: boolean;
184
+ /**
185
+ * A sample of the column's type for a required column the test does not care about; a `SeedLimitError` for a type it
186
+ * cannot fill. `variant` 0 is the plain sample; a higher one differs from the lower ones where the type allows (another
187
+ * day, the other boolean, a larger number), for a unique index whose other columns the row cannot vary.
188
+ */
189
+ readonly sample: (variant: number) => Primitive;
190
+ }
191
+ /** A CHECK constraint of the schema, by the columns it names. */
192
+ export interface CheckConstraint {
193
+ readonly name: string;
194
+ readonly table: string;
195
+ readonly columns: readonly string[];
196
+ /** The values of a one-column `IN (…)` list the fixture writes in its place, first one first; empty for any other CHECK. */
197
+ readonly values: readonly CheckLiteral[];
198
+ /** Every text and number literal of the expression: what the fixture tries in the columns it names when a row fails it. */
199
+ readonly literals: readonly CheckLiteral[];
200
+ }
201
+ /** A literal of a CHECK expression. */
202
+ export type CheckLiteral = string | number;
203
+ /**
204
+ * A unique index of the schema (a primary key's or a UNIQUE constraint's included), by its key columns. Only an index of
205
+ * plain columns with no predicate is one: the fixture cannot tell a partial index's rows or an expression's values.
206
+ */
207
+ export interface UniqueIndex {
208
+ readonly name: string;
209
+ readonly table: string;
210
+ readonly columns: readonly string[];
211
+ /** `NULLS NOT DISTINCT`: a null in a key column collides with another row's null there. */
212
+ readonly nullsNotDistinct: boolean;
213
+ }
214
+ /** A live, empty file of `kind`, as the framework's put leaves one once a reference claims it. */
215
+ export interface SeededFile {
216
+ readonly id: string;
217
+ readonly kind: string;
218
+ readonly objectKey: string;
219
+ readonly sha256: string;
220
+ readonly objectVersion: string;
221
+ }
222
+ /** A row the fixture inserted, found again by `match` (column → value): what a removal deletes. */
223
+ export interface InsertedRow {
224
+ readonly table: string;
225
+ readonly match: ReadonlyMap<string, SampleValue>;
226
+ }
227
+ /** How many rows one removal deletes, referring rows included, before it gives up. */
228
+ export declare const MAX_REMOVED_ROWS = 10000;
229
+ /** The seed limit of a removal that reaches more than `MAX_REMOVED_ROWS` rows. */
230
+ export declare function removalLimit(): SeedLimitError;
231
+ /** What a kit gives the seeding: its schema's columns and CHECK constraints, and the statements it runs. */
232
+ export interface SeedingBackend {
233
+ readonly columns: readonly SeedColumn[];
234
+ /** Every CHECK constraint of the schema's tables; read once, on the first column that needs them. */
235
+ checks(): Promise<readonly CheckConstraint[]>;
236
+ /** Every unique index of plain columns and no predicate of the schema's tables; read once, on the first column that needs them. */
237
+ uniqueIndexes(): Promise<readonly UniqueIndex[]>;
238
+ /**
239
+ * The smallest whole number above every value `column` holds in the rows of `table` that match one of `groups`
240
+ * (`groupsWhere`), and at least 1, as the column's type holds it; `undefined` when the type holds no such number, or
241
+ * the largest is no finite number.
242
+ */
243
+ nextNumber(table: string, column: string, groups: readonly ReadonlyMap<string, SampleValue>[]): Promise<Primitive | undefined>;
244
+ /**
245
+ * Inserts one row and answers it as stored; a CHECK, foreign key or unique index it fails is a `SeedLimitError`
246
+ * (`checkLimit`, `foreignKeyLimit`, `uniqueValueLimit`).
247
+ */
248
+ insert(table: string, values: ReadonlyMap<string, SampleValue>): Promise<Readonly<Record<string, unknown>>>;
249
+ /** One row of `table` that holds `where` (column → value; every row when empty), of `columns`, or `undefined` when none does. */
250
+ firstRow(table: string, columns: readonly string[], where?: ReadonlyMap<string, SampleValue>): Promise<Readonly<Record<string, unknown>> | undefined>;
251
+ insertFile(file: SeededFile): Promise<void>;
252
+ /**
253
+ * Deletes `rows` (each found by its `match`; one already gone is skipped) and every row that refers to one of them,
254
+ * however deep, in one transaction whose foreign keys are checked once all are gone, so rows that refer to each other
255
+ * go together. No write moves or adds a referring row between finding the rows and deleting them.
256
+ */
257
+ remove(rows: readonly InsertedRow[]): Promise<void>;
258
+ }
259
+ /** The seed limit of a CHECK a seeded row fails. */
260
+ export declare function checkLimit(constraint: string, table: string): ConstraintLimitError;
261
+ /** The seed limit of a foreign key a seeded row breaks. */
262
+ export declare function foreignKeyLimit(constraint: string, table: string): ConstraintLimitError;
263
+ /** The seed limit of a number column a unique index covers whose type holds no number above the largest of the row's group. */
264
+ export declare function uniqueLimit(index: string, table: string, column: string): SeedLimitError;
265
+ /** The seed limit of a row whose values another row of the table already holds under a unique index. */
266
+ export declare function uniqueValueLimit(index: string, table: string, columns?: readonly string[]): ConstraintLimitError;
267
+ /** The seed limit of a required column whose type the fixture has no sample of. */
268
+ export declare function typeLimit(table: string, column: string, type: string): SeedLimitError;
269
+ /**
270
+ * A condition that matches a row holding every value of one of `groups` (column → value, `null` matched by `IS NULL`; an
271
+ * empty group matches every row, no group none), in the dialect's quoting and placeholders, with the values it binds.
272
+ */
273
+ export declare function groupsWhere(groups: readonly ReadonlyMap<string, SampleValue>[], quote: (identifier: string) => string, placeholder: (position: number) => string): {
274
+ where: string;
275
+ values: SampleValue[];
276
+ };
277
+ export declare function randomHex(): string;
278
+ /**
279
+ * The object version a seeded file was scanned at: whoever stocks its empty object (`seededObjects`) stores it under
280
+ * this version, so a file of a scanning kind is served as a live one is, by its scanned version.
281
+ */
282
+ export declare const SEEDED_OBJECT_VERSION = "\"seeded\"";
283
+ /** The isolation fixtures over the schema `backend` describes. */
284
+ export declare function testSeeding(backend: SeedingBackend): TestSeeding;
285
+ /**
286
+ * The untyped handle over one table of the data layer `scoped(tables)` created; it reaches the database once `boot`
287
+ * has bound that layer. Every runtime check of a store applies: kind, dimension, action and the request's authority.
288
+ * `module` is the kit's, which refuses a production process.
289
+ */
290
+ export declare function probeTable(module: string, layer: unknown, table: string): TableProbe;
@@ -0,0 +1,37 @@
1
+ import type { TableProbe } from './store';
2
+ import { type TestDatabase } from './testing-shared';
3
+ export { ChildTable, defineChildStore, defineStore, DimensionTable, type TableProbe } from './store';
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
+ export interface TestDatabaseOptions {
6
+ /** The application's `db/migrations/` directory. */
7
+ readonly migrations: string | URL;
8
+ /** The test file. `@fabrika/db/testing` names it when it skips; this kit never skips. */
9
+ readonly label: string;
10
+ /** A database migrated and seeded once (`testDatabaseTemplate`), which this one starts as a copy of. */
11
+ readonly template?: TestDatabaseTemplate;
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>;
26
+ /**
27
+ * A fresh in-memory database with the framework's and the application's migrations applied by the runner a Durable
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 test
30
+ * that checks for `null` compiles against both kits.
31
+ */
32
+ export declare function testDatabase(options: TestDatabaseOptions): Promise<TestDatabase>;
33
+ /**
34
+ * The untyped handle over one table of the data layer `scoped(tables)` created; it reaches the database once `boot`
35
+ * has bound that layer. Every runtime check of a store applies: kind, dimension, action and the request's authority.
36
+ */
37
+ export declare function tableProbe(layer: unknown, table: string): TableProbe;
@@ -1,8 +1,7 @@
1
- import { Database } from './database';
2
- import type { Primitive } from './description';
3
- import { type Tables } from './policy';
4
1
  import type { TableProbe } from './store';
2
+ import { type TestDatabase } from './testing-shared';
5
3
  export { ChildTable, defineChildStore, defineStore, DimensionTable, type TableProbe } from './store';
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';
6
5
  export declare const TEST_POSTGRES_URL = "FABRIKA_TEST_POSTGRES_URL";
7
6
  /** Set to `1` by the platform build: a missing test database is then a failure, not a skip. */
8
7
  export declare const TEST_POSTGRES_REQUIRED = "FABRIKA_TEST_POSTGRES_REQUIRED";
@@ -17,96 +16,6 @@ export interface TestDatabaseOptions {
17
16
  */
18
17
  readonly connectionWaitMs?: number;
19
18
  }
20
- /** A value a test row holds in a column; `null` for a nullable column the fixture left empty. */
21
- export type SampleValue = Primitive | null;
22
- /** One seeded row and where it lies. */
23
- export interface WorldRow {
24
- /** The row's key: the dimension value of a dimension table's row, a child's own key. */
25
- readonly key: string;
26
- /** A child row's parent key; `null` for a dimension table. */
27
- readonly parent: string | null;
28
- /** The value of the grant dimension the row lies in (`IsolationWorlds.dimension`). */
29
- readonly scope: string;
30
- /**
31
- * Every dimension value the row lies in: a dimension table's own first, then each container, innermost first. A
32
- * share link's chain is this list.
33
- */
34
- readonly chain: readonly {
35
- readonly type: string;
36
- readonly value: string;
37
- }[];
38
- /** The row's values of the policy's update columns, as seeded. */
39
- readonly updates: Readonly<Record<string, SampleValue>>;
40
- /**
41
- * The distinct value written into every text column the fixture filled itself, in this row and in its containers.
42
- * Each occurs in no other fixture, so one found in an answer to another scope is a leaked row.
43
- */
44
- readonly markers: readonly string[];
45
- }
46
- /** One seeded row of an application table, which lies in no dimension. */
47
- export interface ApplicationRow {
48
- readonly key: string;
49
- /** The row's values of the policy's update columns, as seeded. */
50
- readonly updates: Readonly<Record<string, SampleValue>>;
51
- /** The distinct value written into every text column the fixture filled itself. */
52
- readonly markers: readonly string[];
53
- }
54
- /** A row seeded under another: its key, and the distinct value written into every text column the fixture filled. */
55
- export interface SeededRow {
56
- readonly key: string;
57
- readonly markers: readonly string[];
58
- }
59
- /**
60
- * What the isolation fixture cannot seed for a schema: a CHECK its values fail, a required foreign key to a scoped table
61
- * outside the containment chain. It is a limit of the generator, named with the constraint or the column, never a
62
- * failure of the handler or the policy a case is about.
63
- */
64
- export declare class SeedLimitError extends Error {
65
- readonly name = "SeedLimitError";
66
- }
67
- /** One row of a table in each of two containment chains that share no value. */
68
- export interface IsolationWorlds {
69
- /**
70
- * The dimension a caller's grants are scoped by: a dimension table's container, or its own dimension when it has
71
- * none; a child table's parent's.
72
- */
73
- readonly dimension: string;
74
- readonly own: WorldRow;
75
- readonly other: WorldRow;
76
- }
77
- export interface TestDatabase {
78
- /** The connection `boot` binds the data layer to: the runtime role, on the migrated schema. */
79
- readonly database: Database;
80
- readonly schema: string;
81
- /**
82
- * Seeds one row of `table` in each of two fresh chains, with every container row a table owns. `values` (column →
83
- * value) are written into both rows of `table`: the state an endpoint's precondition needs. A text column keeps its
84
- * marker, so a seed of one, or of a column that places the row, throws.
85
- */
86
- seedWorlds<DB, P>(tables: Tables<DB, P>, table: string, values?: Readonly<Record<string, SampleValue>>): Promise<IsolationWorlds>;
87
- /** Seeds one row of the application table `table`: its key, version and creator stamped, every other column sampled. */
88
- seedRow<DB, P>(tables: Tables<DB, P>, table: string): Promise<ApplicationRow>;
89
- /**
90
- * Seeds one row of `table`, a child or dimension table that lies in the object of `under` (a row `seedWorlds`
91
- * seeded), placed in that row's chain: the row a fixture names by id, such as a note's comment. Answers its key and
92
- * the markers it holds.
93
- */
94
- seedUnder<DB, P>(tables: Tables<DB, P>, table: string, under: WorldRow): Promise<SeededRow>;
95
- /** Values for the policy's insert columns of `table` that its schema accepts: every required one, sampled; a file column a seeded file. */
96
- sampleInsert<DB, P>(tables: Tables<DB, P>, table: string): Promise<Readonly<Record<string, SampleValue>>>;
97
- /**
98
- * The object key of every file the fixture seeded into a file column, oldest first. Each stands for an empty object,
99
- * which a test's object store holds when a handler serves or opens the file.
100
- */
101
- seededObjects(): readonly string[];
102
- /** Closes the connections and drops the schema and its roles. */
103
- close(): Promise<void>;
104
- }
105
- /**
106
- * The object version a seeded file was scanned at: whoever stocks its empty object (`seededObjects`) stores it under
107
- * this version, so a file of a scanning kind is served as a live one is, by its scanned version.
108
- */
109
- export declare const SEEDED_OBJECT_VERSION = "\"seeded\"";
110
19
  /**
111
20
  * A fresh schema with the framework's and the application's migrations applied by the real runner (`@fabrika/platform-node`) as its
112
21
  * migration role, connected and seeded as its runtime role, or `null` after the standard skip message when