std/wire
std/wire
导入自 @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.
源码: 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.
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
value | Wired |
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
_key | string | |
value | unknown |