IF Commons GitHub

sql/extensions/kinds/kinds

Written to: 4 requirements: 4 proved, 0 partly, 0 failing, 0 with no test recorded. 0026-sql-kinds FR-001, 0026-sql-kinds FR-002, 0026-sql-kinds FR-003, 0026-sql-kinds FR-004

Kinds (commons data 0026-sql-kinds): reference data kept as CSV, read into typed rows, checked against a table of a logical schema, written as a TypeScript module, and given to integrations and ephemeral targets as they are.

Source: commons/data/sql/extensions/kinds/kinds.ts

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

CheckErrortypeno test imports it
type CheckError =
  | { readonly kind: "unknown-table"; readonly table: string }
  | { readonly kind: "unknown-column"; readonly table: string; readonly column: string }
  | { readonly kind: "missing-required"; readonly table: string; readonly columns: readonly string[] }
  | { readonly kind: "empty-required"; readonly table: string; readonly column: string; readonly line: number };

Why a seed that a kind defines does not hold, as a value.

checkKindsfunction
function checkKinds(kinds: Kinds, schema: LogicalSchema, table: string): readonly CheckError[]

Checks rows against a table of a schema.

ParameterWhat it is
kindsthe rows
schemathe logical schema
tablethe table, by the words of its name

Returns: nothing wrong, or what is

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

Kindsinterface
interface Kinds

The rows of a file.

MemberTypeWhat it is
namestring
columnsreadonly { readonly name: string; readonly type: KindType; readonly nullable: boolean; }[]
rowsreadonly Readonly<Record<string, Cell>>[]
keyreadonly string[]

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

kindsFromCsvfunction
function kindsFromCsv(text: string, options: KindsOptions): Result<Kinds, readonly KindsError[]>

Typed rows from CSV text.

ParameterWhat it is
textthe text, with a header
optionsthe name, types, delimiter and key

Returns: the rows, or why not

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

KindsErrortypeno test imports it
type KindsError = | { readonly kind: "header"; readonly why: string } | { readonly kind: "fields"; readonly line: nu… (464 characters)
type KindsError =
  | { readonly kind: "header"; readonly why: string }
  | { readonly kind: "fields"; readonly line: number; readonly expected: number; readonly found: number }
  | { readonly kind: "type"; readonly line: number; readonly column: string; readonly expected: KindType; readonly value: string }
  | { readonly kind: "duplicate-key"; readonly line: number; readonly key: readonly Cell[] }
  | { readonly kind: "unknown-key"; readonly column: string };

Why a kind cannot be defined or used, as a value.

kindsModulefunction
function kindsModule(kinds: Kinds, options?: { readonly source?: string | undefined; readonly typeName?: string | undefined; readonly constName?: string | undefined; }): string

A TypeScript module of the rows.

ParameterWhat it is
kindsthe rows
optionsthe file's name for the header, and the names of the type and the array

Returns: the text of the module

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

KindsOptionsinterfaceno test imports it
interface KindsOptions

What a file is read with.

MemberTypeWhat it is
namestringThe name of what the rows are of, for the module.
types?Readonly<Record<string, KindType>>The types of columns, by header; text where not said.
delimiter?stringThe delimiter; a comma where not said.
key?readonly string[]The columns of the key; the first column where not said.
KindTypetypeno test imports it
type KindType = "text" | "integer" | "number" | "boolean";

The type of a member of a kind: text, integer, number or boolean.

rowsOfconst
const rowsOf: (kinds: Kinds) => readonly Readonly<Record<string, Cell>>[]

The rows as the records integrations and ephemeral targets take.

ParameterWhat it is
kindsthe rows

Returns: the records

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

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