Class LazyShape<ProvidedShape, Pointer>

Lazily loads a shape using the provider callback.

Type Parameters

  • ProvidedShape extends AnyShape

    The lazy-loaded shape.

  • Pointer

    The value returned when a cyclic reference is detected.

Hierarchy (view full)

Implements

Constructors

Properties

_applyOperations: ApplyOperationsCallback

The callback that applies Shape.operations to the shape output value.

This method returns a promise if there are async Shape.operations.

If the shape overrides only Shape._apply and doesn't override Shape._applyAsync then it's only safe to call this method as the last statement in Shape._apply. Otherwise, it may return an unexpected promise.

If the shape overrides both Shape._apply and Shape._applyAsync then this method would always synchronously return a Result inside Shape._apply.

annotations: Dict<any> = {}

The dictionary of shape annotations.

inputs: readonly unknown[]

The array of unique input types and values that are accepted by the shape.

isAsync: boolean

true if the shape allows only Shape.parseAsync and throws an error if Shape.parse is called, or false if the shape can be used in both sync and async contexts.

operations: readonly Operation[] = []

The array of operations that are applied to the shape output.

pointerProvider: ((value, options) => Pointer)

The provider callback that returns the value that is used instead of a circular reference.

Type declaration

shapeProvider: (() => ProvidedShape)

The provider callback that returns the shape to which LazyShape delegates input handling.

Type declaration

messages: Messages = defaultMessages

The mapping from an issue type to a corresponding issue message.

Methods

  • Returns input types and literal values that this shape can accept as an input.

    Returns readonly unknown[]

  • Must return true if the shape must be used in async context only, otherwise the shape can be used in both sync and async contexts. Override this method to implement a custom shape.

    Returns boolean

  • Returns true if the shape accepts given input type or value, or false otherwise.

    Parameters

    • input: unknown

      The type or value that must be checked.

    Returns boolean

  • Adds annotations to the shape.

    Parameters

    • annotations: ReadonlyDict<any>

      Annotations to add.

    Returns this

    The clone of the shape with the updated annotations.

  • Returns a sub-shape that describes a value associated with the given property name, or null if there's no such sub-shape.

    Parameters

    • key: unknown

      The key for which the sub-shape must be retrieved.

    Returns null | AnyShape

    The sub-shape or null if there's no such key in the shape.

  • Replace circular references with a placeholder.

    Type Parameters

    • Pointer extends Any

      The value returned when a cyclic reference is detected.

    Parameters

    • pointer: Pointer | ((value, options) => Pointer)

      The value that would be used instead of circular references, or a callback that returns such a value.

    Returns LazyShape<ProvidedShape, Pointer>

    The clone of the shape.

Accessors