Transcoder overview

A transcoder is a data-type that decodes from unknown type of an expected input shape to an output type, and encodes from an output type to the expected input shape. Can be represented as printer/parsers, and transformations.

Lawful transcoders must be idempotent, and all derivable transcoders exported by schemata (unless otherwise specified) are lawful.

Added in v2.0.0


Table of contents


Constructors

errorAtIndex

A failure case at a specific index

Signature

export declare const errorAtIndex: (
  index: number,
  ...errors: RNEA.ReadonlyNonEmptyArray<TE.TranscodeError>
) => TE.TranscodeError

Added in v2.0.0

errorAtKey

A failure case at a specific key

Signature

export declare const errorAtKey: (
  key: string,
  ...errors: RNEA.ReadonlyNonEmptyArray<TE.TranscodeError>
) => TE.TranscodeError

Added in v2.0.0

errorAtUnionMember

A failure case for a union member

Signature

export declare const errorAtUnionMember: (
  member: string | number,
  ...errors: RNEA.ReadonlyNonEmptyArray<TE.TranscodeError>
) => TE.TranscodeError

Added in v2.0.0

failure

Signature

export declare const failure: <A>(e: TE.TranscodeErrors) => Either<TE.TranscodeErrors, A>

Added in v2.0.0

serializationError

A failure case for a serialization or deserialization error

Signature

export declare const serializationError: (expected: string, error: unknown, actual: unknown) => TE.TranscodeError

Added in v2.0.0

success

Signature

export declare const success: <A>(a: A) => Either<TE.TranscodeErrors, A>

Added in v2.0.0

transcodeErrors

A collection of failure cases

Signature

export declare const transcodeErrors: (...errors: RNEA.ReadonlyNonEmptyArray<TE.TranscodeError>) => TE.TranscodeErrors

Added in v2.0.0

typeMismatch

A failure case for a value that does not match the expected type

Signature

export declare const typeMismatch: (expected: string, actual: unknown) => TE.TranscodeError

Added in v2.0.0

unexpectedValue

A failure case for an unexpected value

Signature

export declare const unexpectedValue: (actual: unknown) => TE.TranscodeError

Added in v2.0.0

Destructors

drawErrorTree

Signature

export declare const drawErrorTree: (
  errors: TE.TranscodeErrors,
  configuration?: { readonly showHeading?: boolean | undefined } | undefined
) => string

Added in v2.0.0

Instance Methods

imap

Signature

export declare const imap: <A, B>(f: (a: A) => B, g: (b: B) => A) => <I>(fa: Transcoder<I, A>) => Transcoder<I, B>

Added in v2.0.0

Instances

Invariant

Signature

export declare const Invariant: Invariant2<'schemata-ts/Transcoder'>

Added in v2.0.0

Interpreters

deriveTranscoder

Interprets a schema as a decoder

Signature

export declare const deriveTranscoder: <I, O>(schema: Schema<I, O>) => Transcoder<I, O>

Added in v2.0.0

Model

Transcoder (interface)

Signature

export interface Transcoder<I, O> {
  readonly decode: (u: unknown) => Either<Const<TE.TranscodeErrors, I>, O>
  readonly encode: (o: O) => Either<Const<TE.TranscodeErrors, O>, I>
}

Added in v2.0.0

URI

URI

Signature

export declare const URI: 'schemata-ts/Transcoder'

Added in v2.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.0.0