sql/extensions/invariants/mod
Written to: 5 requirements: 5 proved, 0 partly, 0 failing, 0 with no test recorded. 0043-sql-invariants FR-001, 0043-sql-invariants FR-002, 0043-sql-invariants FR-003, 0043-sql-invariants FR-004, 0043-sql-invariants FR-005
Invariants in the database (commons data 0043-sql-invariants): what governance says must always be true of the records of a concept (they are only added, they form a chain, a status moves only along the moves it may, a number never goes above another) written as triggers, so that the database refuses what breaks it for every client, including a statement typed by hand that never passed through an application. A dialect that cannot say them is an error value by default, never a silent loss.
Source: commons/data/sql/extensions/invariants/mod.ts
5 of 8 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.
InvariantSettingsinterfaceno test imports itinterface InvariantSettings
What a project says of invariants.
| Member | Type | What it is |
|---|
unsupported? | "carry" | "refuse" | What to do where the dialect has no triggers: refuse (an error value, the default) or carry (no statements; the invariant is only declared). |
guard? | false | { readonly unlock?: string | undefined; } | Where the dialect has event triggers (PostgreSQL), the guard that refuses to weaken the invariants (0043-sql-invariants FR-007): on by default, false to leave it out. unlock is the hash of a secret (guardKeyOf) that lets a session that knows it change them (unlockStatement), as a migration must; without one nothing but a superuser's disabling of the guard can. |
const guardKeyOf: (secret: string) => string
The hash of a secret that unlocks the guard, to give as guard.unlock; the secret itself is kept outside the database.
Imported by 13 tests of the run (13 passed, 0 failed): the library's results
const unlockStatement: (secret: string, local?: boolean) => string
The statement that unlocks the guard for the session (or, where local, for the transaction) that runs it.
Imported by 13 tests of the run (13 passed, 0 failed): the library's results
Invariantinterfaceno test imports itinterface Invariant
One invariant of the schema.
| Member | Type | What it is |
|---|
table | string | |
kind | "append-only" | "at-most" | "chain" | "transitions" | |
says | string | What it holds, in words. |
function invariantsOf(tables: readonly Table[]): readonly Invariant[]
The invariants a schema declares, where each lives and what it says.
| Parameter | What it is |
|---|
tables | the tables of the logical schema |
Returns: the invariants
Imported by 13 tests of the run (13 passed, 0 failed): the library's results
function invariants(given?: InvariantSettings): StatementSource
The statement source of a project's invariants.
| Parameter | What it is |
|---|
given | what a project says |
Returns: a statement source
Imported by 37 tests of the run (37 passed, 0 failed): the library's results
Placedinterfaceno test imports itinterface Placed extends Invariant
An invariant and where a dialect can enforce it.
| Member | Type | What it is |
|---|
by | "application" | "database" | |
via | string | |
table | string | |
kind | "append-only" | "at-most" | "chain" | "transitions" | |
says | string | What it holds, in words. |
function placed(tables: readonly Table[], dialect: Dialect): readonly Placed[]
The invariants of a schema, each with where the dialect enforces it: in the database, or by the application's runtime where the dialect has no way to do it in the database.
| Parameter | What it is |
|---|
tables | the tables of the logical schema |
dialect | the dialect |
Returns: each invariant, placed
Imported by 2 tests of the run (2 passed, 0 failed): the library's results