gizmodel/typed
Typed data contracts: Slot, Codec, the codecs, logical Contract and the exact JSON transport of a Value. Applications, web models and generated code import only this module. It imports no SQL engine, session or executor, so a typed web model does not link the database (model/query.giz holds the typed queries and commands).
import * as Typed from "gizmodel/typed";Types
Slot
type Slot = { name: string; ty: Type; nullable: bool; }Storage/result contracts use the engine's Type, never a web-specific type registry.
name:stringty:M143.Typenullable:bool
Codec
type Codec<T> = { slot: Slot; encode: (value: T) => Value throws DbError effects {fail, alloc}; decode: (value: Value) => T throws DbError effects {fail, alloc}; }How a value of T is written to and read from a database column: its slot and the two conversions.
Opaque: create and use it through this module's functions.
Patch
type Patch = { names: Vec<string>; values: Vec<Value>; }Missing in a patch means unchanged; present NULL means an explicit clear.
names:Vec<string>values:Vec<M143.Value>
RowPatch
type RowPatch = { key: Patch; patch: Patch; }The key and the changed fields of one row.
key:M142.Patchpatch:M142.Patch
Contract
type Contract = { declaration: string; slot: Slot; meaning: string; precision: i64; width: i64; timezone: string; children: Vec<Contract>; }A logical extension is checked by its own codec and lowers to one physical Type. Structured values retain exact JSON tokens; handles/functions/Refs have no data codec.
declaration:stringslot:M142.Slotmeaning:stringprecision:i64width:i64timezone:stringchildren:Vec<M142.Contract>
Functions
textValue
function textValue(slot: Slot, text: Option<string>): Value throws DbErrorWire text is converted only at the adapter boundary, under the known column type.
Effects: fail, alloc.
jsonPatch
function jsonPatch(slots: Vec<Slot>, text: string, complete: bool): Patch throws DbErrorOne grammar owner, raw numeric tokens, decoded duplicate keys, explicit NULL and omission.
Effects: fail, alloc.
mismatch
function mismatch(): DbErrorThe error of a value that does not match its declared data type.
Effects: fail, alloc.
accepts
function accepts(slot: Slot, value: Value): boolWhether VALUE fits SLOT: its type, and NULL only when the slot takes it.
Effects: fail.
checkValues
function checkValues(slots: Vec<Slot>, values: Vec<Value>): bool throws DbErrorChecks that each of VALUES fits its slot of SLOTS.
Effects: fail, alloc.
fills
function fills(slot: Type, column: Type): boolWhether a column of type COLUMN fills a slot of type SLOT: the same type, or any scale for a decimal slot of scale -1.
Effects: fail, alloc.
checkColumns
function checkColumns(slots: Vec<Slot>, names: Vec<string>, types: Vec<Type>): bool throws DbErrorA nameless slot checks only its type at its position.
Effects: fail, alloc.
integerCodec
function integerCodec(): Codec<i64>The codec of an integer column.
Effects: fail, alloc.
textCodec
function textCodec(): Codec<string>The codec of a text column.
Effects: fail, alloc.
booleanCodec
function booleanCodec(): Codec<bool>The codec of a boolean column.
Effects: fail, alloc.
refCodec
function refCodec(): Codec<ResourceRef>A record reference stored as its one text form (Security.ResourceRef.text): one TEXT column, so equality, IN and a Space prefix use one index.
Effects: fail, alloc.
decimalCodec
function decimalCodec(scale: i64): Codec<Dec>The codec of a decimal column with SCALE.
Effects: fail, alloc.
unsignedCodec
function unsignedCodec(): Codec<u64>Unsigned integers use exact NUMERIC storage, not a signed cast or f64.
Effects: fail, alloc.
valueCodec
function valueCodec(slot: Slot): Codec<Value>The codec of a column of SLOT that keeps each value as the engine's Value: a value that SLOT does not accept fails.
Effects: fail, alloc.
optionalCodec
function optionalCodec<T>(codec: Codec<T>): Codec<Option<T>>CODEC for a column that takes NULL (none).
floatCodec
function floatCodec(): Codec<f64>The codec of a float column. Values that are not finite fail.
Effects: fail, alloc.
bytesCodec
function bytesCodec(): Codec<bytes>The codec of a binary column.
Effects: fail, alloc.
timeCodec
function timeCodec(unit: i64): Codec<i64>The codec of a time column in UNIT.
Effects: fail, alloc.
vectorCodec
function vectorCodec(dim: i64): Codec<Vec<f32>>The codec of a vector column of DIM dimensions.
Effects: fail, alloc.
scalarContract
function scalarContract(declaration: string, name: string, scalar: string, nullable: bool): Contract throws DbErrorCompiler scalar names lower to this one logical/storage contract. Web kinds are presentation projections, not a second source of storage semantics.
Effects: fail, alloc.
slotsDigest
function slotsDigest(slots: Vec<Slot>): bytesThe digest of the names, types and nullability of SLOTS.
Effects: fail, alloc.
schemaDigest
function schemaDigest(schema: Schema): bytesLogical storage contract used by schema admission. Physical index/layout choices cannot change this identity. Keys and nullability can.
Effects: fail, alloc.
contractDigest
function contractDigest(contract: Contract): bytes throws DbErrorThe digest of a storage contract. It fails when the contract is not valid.
Effects: fail, alloc.
contractValue
function contractValue(contract: Contract, text: Option<string>): Value throws DbErrorValidate logical values before their one physical representation is stored.
Effects: fail, alloc.
storageContract
function storageContract(c: Contract): bool throws DbErrorChecks that C is a valid storage contract (within its depth and size limits).
Effects: fail, alloc.
writeJsonValue
function writeJsonValue(out: mut bytes, value: Value): voidExact scalar transport. Integer/decimal/time are strings with column Type metadata; browser JSON.parse therefore never rounds a value before a component sees it.
Effects: fail, alloc.