Skip to content

std/wire

std/wire

Import from @norbital-ai/std/wire

std/wire (D6): the one wire value codec. $dec is the only tag: a decimal is { $dec: '1.20' } in both directions (Decimal.toJSON emits it); dates and instants are their ISO strings, which std's branded PlainDate/Instant already are. SQL encoding, the guest prelude (which evaluates reviveWire from its source text), the page client, ctx.existing and the test kit all read the wire through here.

Json type

type Json = null | boolean | number | string | readonly Json[] | {
    readonly [key: string]: Json;
};

A JSON value.

Source: packages/std/src/wire.ts:8

Wired type

type Wired = null | boolean | number | string | Decimal | undefined | readonly Wired[] | {
    readonly [key: string]: Wired;
};

A value the wire carries once encoded: JSON with std's Decimal at any depth; an undefined member is dropped.

Source: packages/std/src/wire.ts:11

encodeWire function

function encodeWire(value: Wired): Json

A value as the wire carries it: each Decimal as { $dec }; undefined is null in a list and dropped as a member.

Parameters

NameTypeDescription
valueWired

Source: packages/std/src/wire.ts:38

reviveWire function

function reviveWire(_key: string, value: unknown): unknown

The JSON.parse reviver of the wire: { $dec } → std's Decimal; nothing else changes. Self-contained (it reads the class std/decimal registers on globalThis), so the guest prelude runs it from reviveWire.toString(); where no std decimal is loaded, a decimal stays its exact text.

Parameters

NameTypeDescription
_keystring
valueunknown

Source: packages/std/src/wire.ts:26