Millwork
    Preparing search index...

    Interface Codec<Raw, Value, Options>

    A codec turns a raw wire value into a rich value and back.

    • hydrate is forgiving. Bad wire data gives undefined and a report through onInvalid. It never throws, so one bad field does not fail a whole response.
    • serialize is strict. A value of the wrong type throws a TypeError.
    • equals compares two values. Dirty checks use it.
    • Hydrated plain objects and arrays are frozen. To change a value, set a new one.
    interface Codec<Raw, Value, Options = undefined> {
        name: string;
        equals(a: Value, b: Value): boolean;
        hydrate(raw: Raw | null | undefined, options?: Options): Value | undefined;
        isValue(input: unknown): input is Value;
        key?(value: Value): unknown;
        parse?(raw: Raw | null | undefined, options?: Options): Value;
        serialize(value: Value | null | undefined, options?: Options): Raw | null;
    }

    Type Parameters

    • Raw
    • Value
    • Options = undefined
    Index
    name: string
    • Turns a raw wire value into a value. It returns undefined for null, undefined or bad input.

      Parameters

      • raw: Raw | null | undefined
      • Optionaloptions: Options

      Returns Value | undefined

    • Optional. Gives a primitive key for a value. Two values that equals says are equal have the same key. setOf uses it to find duplicates fast.

      Parameters

      Returns unknown

    • The strict, quiet read. It throws on bad input, and on null or undefined, and sends no report to onInvalid. Composite codecs and validation use it. defineCodec always sets it.

      Parameters

      • raw: Raw | null | undefined
      • Optionaloptions: Options

      Returns Value