Converts between an application type and one Dex wire representation. Implementations should be deterministic so durable replay sees identical values.
type Order = { id: string };const orderCodec = jsonCodec<Order>({ typeName: "Order", decode(value) { if (typeof value !== "object" || value === null || !("id" in value) || typeof value.id !== "string") { throw new TypeError("invalid Order"); } return { id: value.id }; },});const encoded = orderCodec.encode({ id: "order-42" }); Copy
type Order = { id: string };const orderCodec = jsonCodec<Order>({ typeName: "Order", decode(value) { if (typeof value !== "object" || value === null || !("id" in value) || typeof value.id !== "string") { throw new TypeError("invalid Order"); } return { id: value.id }; },});const encoded = orderCodec.encode({ id: "order-42" });
Application value type encoded by this codec.
Readonly
Stable application-facing name used in mapping errors.
Wire kind normally emitted and accepted by the codec.
Decodes one protocol value.
Value to validate and decode.
The decoded application value.
Encodes one application value.
Typed value to encode.
A validated Dex Value.
Converts between an application type and one Dex wire representation. Implementations should be deterministic so durable replay sees identical values.
Example