IF Commons GitHub

sql/extensions/operations/runtime

Written to: 6 requirements: 6 proved, 0 partly, 0 failing, 0 with no test recorded. 0031-operations FR-003, 0031-operations FR-004, 0031-operations FR-005, 0031-operations FR-006, 0031-operations FR-007, 0031-operations FR-008

The runtime of operations (commons data 0031-operations): each run in one transaction, its input checked against its contract, its caller authorized, what it wrote held to what it declared, and what it must record in the audit trail recorded in the same transaction. A business outcome is a value, never an exception, so that an outcome that must be kept (a revocation after a reused token) is committed; anything thrown rolls back.

Source: commons/data/sql/extensions/operations/runtime.ts

5 of 10 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

Authorizetypeno test imports it
type Authorize = (tx: Tx, caller: string, permission: string, tenant: string | undefined) => Promise<boolean>;

Whether a caller holds a permission in a tenant; the model's, given by the project.

checkInputfunctionno test imports it
function checkInput(o: Operation, input: Readonly<Record<string, unknown>>): readonly InputError[]

The errors of an input against a contract.

defaultContextfunction
function defaultContext(pepper?: string): Context

The default of what an operation is given: the clock, random identifiers and tokens, and SHA-256; a password verifier is the application's.

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

Implementationtype
type Implementation = (tx: Tx, input: Readonly<Record<string, unknown>>, context: Context) => Promise<Outcome>;

How an operation is done.

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

InputErrortypeno test imports it
type InputError =
  | { readonly kind: "missing"; readonly input: string }
  | { readonly kind: "unknown"; readonly input: string }
  | { readonly kind: "type"; readonly input: string; readonly expected: string };

Why an operation refuses its input, as a value.

operationsfunction
function operations(schema: LogicalSchema, dialect: Dialect, driver: Driver, contracts: readonly Operation[], implementations: Readonly<Record<string, Implementation>>, options?: RuntimeOptions): Result<Runtime, readonly SetupError[]>

The operations of a model, ready to run.

ParameterWhat it is
schemathe logical schema
dialectthe dialect
driverthe database
contractsthe operations' contracts
implementationshow each is done, by name
optionsthe naming, the schema, what operations are given, how a caller is authorized and where the audit trail is written

Returns: the runtime, or why it cannot be made

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

Outcometypeno test imports it
type Outcome = { readonly status: string; readonly commit?: boolean } & Readonly<Record<string, unknown>>;

What an operation gives back: a status, what goes with it, and whether to keep what it did (it does, where it does not say).

Runtimeinterface
interface Runtime

The operations of a model, ready to run.

MemberTypeWhat it is
namesreadonly string[]
run(name: string, input: Readonly<Record<string, unknown>>, caller?: string | undefined) => Promise<Result<Outcome, RunError>>Runs an operation.

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

RuntimeOptionsinterface
interface RuntimeOptions

What a runtime is made with.

MemberTypeWhat it is
naming?Naming
schema?stringThe schema the tables are in.
context?Partial<Context>
authorize?Authorize
audit?AuditSink

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

SetupErrortypeno test imports it
type SetupError = | { readonly kind: "no-implementation"; readonly operation: string } | { readonly kind: "no-contra… (441 characters)
type SetupError =
  | { readonly kind: "no-implementation"; readonly operation: string }
  | { readonly kind: "no-contract"; readonly operation: string }
  | { readonly kind: "unknown-table"; readonly operation: string; readonly table: string }
  | { readonly kind: "no-authorizer"; readonly operation: string }
  | { readonly kind: "no-audit"; readonly operation: string }
  | { readonly kind: "no-permission"; readonly operation: string };

Why an operation cannot be set up on a database, as a value.

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