IF Commons GitHub

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 it
interface InvariantSettings

What a project says of invariants.

MemberTypeWhat 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.
guardKeyOfconst
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

unlockStatementconst
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 it
interface Invariant

One invariant of the schema.

MemberTypeWhat it is
tablestring
kind"append-only" | "at-most" | "chain" | "transitions"
saysstringWhat it holds, in words.
invariantsOffunction
function invariantsOf(tables: readonly Table[]): readonly Invariant[]

The invariants a schema declares, where each lives and what it says.

ParameterWhat it is
tablesthe tables of the logical schema

Returns: the invariants

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

invariantsfunction
function invariants(given?: InvariantSettings): StatementSource

The statement source of a project's invariants.

ParameterWhat it is
givenwhat 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 it
interface Placed extends Invariant

An invariant and where a dialect can enforce it.

MemberTypeWhat it is
by"application" | "database"
viastring
tablestring
kind"append-only" | "at-most" | "chain" | "transitions"
saysstringWhat it holds, in words.
placedfunction
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.

ParameterWhat it is
tablesthe tables of the logical schema
dialectthe dialect

Returns: each invariant, placed

Imported by 2 tests of the run (2 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.