Dex TypeScript SDK 1.35.0
    Preparing search index...

    Interface Codec<T>

    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" });
    interface Codec<T> {
        typeName: string;
        wireKind: WireKind;
        decode(value: Value): T;
        encode(value: T): Value;
    }

    Type Parameters

    • T

      Application value type encoded by this codec.

    Index

    Properties

    Methods

    Properties

    typeName: string

    Stable application-facing name used in mapping errors.

    wireKind: WireKind

    Wire kind normally emitted and accepted by the codec.

    Methods

    • Decodes one protocol value.

      Parameters

      • value: Value

        Value to validate and decode.

      Returns T

      The decoded application value.

    • Encodes one application value.

      Parameters

      • value: T

        Typed value to encode.

      Returns Value

      A validated Dex Value.