IF Commons GitHub

registry

The registry of dialects (commons lang-sql 0007-sql-emit FR-006 to FR-008): a library outside this one registers a dialect it made with defineDialect and the catalog of the functions the dialect has, and another library finds both by name. A registry starts with the base dialect ansi and its catalog; a dialect's functions are its own and those of the dialects it extends, its own replacing a parent's of the same name. Nothing here throws: a name taken, a parent that is not registered and a function that cannot be is an error value.

const registry = createRegistry();
registry.register(mine);                                  // mine extends ansi
registry.registerFunctions("mine", [{ name: "path_of", minArgs: 1, maxArgs: 1, aggregate: false }]);
registry.lookupFunction("mine", "PATH_OF");               // the function; "count" is found in ansi

Spec: 0007-sql-emit FR-006, FR-007, FR-008

Source: commons/lang-sql/src/registry.ts

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

ANSI_FUNCTIONSconstno test imports it
const ANSI_FUNCTIONS: readonly FunctionSpec[]

The functions of the common ground.

createRegistryfunction
function createRegistry(): Registry

A registry with the base dialect ansi and its functions.

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

describeRegistryErrorfunction
function describeRegistryError(e: RegistryError): string

One sentence for a registry error.

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

FunctionSpecinterface
interface FunctionSpec

A function of a dialect: its name, how many arguments it takes, and whether it aggregates.

MemberTypeWhat it is
namestring
minArgsnumber
maxArgsnumber | undefinedThe most arguments it takes; undefined where there is no most.
aggregateboolean
returns?stringThe type of what it gives, as the dialect writes a type.
summary?string

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

Registryinterfaceno test imports it
interface Registry

A registry of dialects with the catalog of functions of each.

MemberTypeWhat it is
register(dialect: Dialect) => Result<Dialect, RegistryError>Adds a dialect; the same dialect value again changes nothing.
get(name: string) => Dialect | undefinedThe dialect of a name, without regard to case.
names() => readonly string[]The names, in the order of registration.
registerFunctions(dialect: string, functions: readonly FunctionSpec[]) => Result<number, RegistryError>Adds functions to the catalog of a registered dialect; the number added.
lookupFunction(dialect: string, name: string) => FunctionSpec | undefinedA function of a dialect, found in its catalog and then in those of the dialects it extends.
functionsOf(dialect: string) => readonly FunctionSpec[]Every function the dialect finds, each name once, its own replacing its parent's.
RegistryErrortypeno test imports it
type RegistryError =
  | { readonly kind: "name-taken"; readonly name: string }
  | { readonly kind: "unknown-parent"; readonly name: string; readonly parent: string }
  | { readonly kind: "unknown-dialect"; readonly name: string }
  | { readonly kind: "bad-function"; readonly name: string; readonly why: string };

Why something was not registered.

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