IF Commons GitHub

aide/exec/mod

Running (commons lang-sql 0010-aide FR-008): compile turns an expression into a closure (row) => value with the logic of SQL (null where a value is not known, AND and OR with their three values), LIKE with its like-words, and the functions of an environment, and run applies a plan, or the residual of a split, to the rows of an iterable or an async iterable. No code is generated: a closure is composed of closures, so the same module runs on Bun, Node 26 and in a browser.

Spec: 0010-aide FR-008

Source: commons/lang-sql/src/aide/exec/mod.ts

4 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.

Valuetype
type Value = string | number | boolean | null;

A value of a row.

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

Rowtype
type Row = Readonly<Record<string, Value>>;

A row: values by column name.

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

Fntypeno test imports it
type Fn = (args: readonly Value[]) => Value;

A function of the environment.

Environmentinterfaceno test imports it
interface Environment

What an expression may use.

MemberTypeWhat it is
functions?ReadonlyMap<string, Fn>
params?readonly Value[]The values of ? and $n parameters.
CompileErrorinterfaceno test imports it
interface CompileError

What cannot be compiled.

MemberTypeWhat it is
startnumber
endnumber
messagestring
likeRegexfunctionno test imports it
function likeRegex(pattern: string, escape: string | undefined, caseless: boolean): RegExp

A SQL LIKE pattern as a regular expression.

globRegexfunctionno test imports it
function globRegex(pattern: string): RegExp

A GLOB pattern (*, ?, [a-z], [!a-z]; * matches any characters, / included) as a regular expression.

BUILTINSconstno test imports it
const BUILTINS: ReadonlyMap<string, Fn>

The functions every environment has.

compilefunction
function compile(expr: Expr, env?: Environment): Result<(row: Readonly<Record<string, Value>>) => Value, readonly CompileError[]>

An expression as a closure over a row; an error value for a construct that is not compiled or a function that is not known.

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

runfunction
function run(plan: Plan, rows: AsyncIterable<Readonly<Record<string, Value>>> | Iterable<Readonly<Record<string, Value>>>, env?: Environment): Promise<Result<readonly Readonly<Record<string, Value>>[], readonly CompileError[]>>

Runs a plan over rows (an iterable or an async iterable of rows) and gives the rows it selects; an error value for an expression that is not compiled.

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

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