Doubter - v5.1.1-next.e4e15ab
    Preparing search index...

    Class RecordShape<KeysShape, ValuesShape>

    The shape that describes an object with string keys and values that conform the given shape.

    Type Parameters

    • KeysShape extends Shape<string, PropertyKey>

      The shape of record keys.

    • ValuesShape extends AnyShape

      The shape of record values.

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    _options: undefined | IssueOptions | Message

    The issue options or the issue message.

    annotations: Dict = {}

    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.

    keysShape: KeysShape

    The shape of record keys.

    operations: readonly Operation[] = []

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

    valuesShape: ValuesShape

    The shape of record values.

    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

        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

      Returns null | AnyShape

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

    • Synchronously parses the value.

      Parameters

      • input: unknown

        The value to parse.

      • Optionaloptions: ParseOptions

        Parsing options.

      Returns Record

      The value that conforms the output type of the shape.

      Error if the shape doesn't support the sync parsing, see Shape.isAsync.

      ValidationError if any issues occur during parsing.

    • Asynchronously parses the value and returns undefined value if parsing fails.

      Parameters

      • input: unknown

        The value to parse.

      Returns Promisify<
          undefined
          | Record<KeysShape[typeof OUTPUT], ValuesShape[typeof OUTPUT]>,
      >

      The value that conforms the output type of the shape.

    • Asynchronously parses the value and returns the default value if parsing fails.

      Type Parameters

      • DefaultValue

        The default value that is returned if parsing fails.

      Parameters

      • input: unknown

        The value to parse.

      • defaultValue: DefaultValue

        The default value that is returned if parsing fails.

      • Optionaloptions: ParseOptions

        Parsing options.

      Returns Promisify<
          | Record<KeysShape[typeof OUTPUT], ValuesShape[typeof OUTPUT]>
          | DefaultValue,
      >

      The value that conforms the output type of the shape.

    Plugin Methods

    • Defines an all-or-nothing relationship between keys where if one of the keys is present, all of them are required as well.

      Parameters

      • keys: KeysShape[typeof OUTPUT][]

        The keys of which, if one present, all are required.

      • Optionaloptions: IssueOptions | Message

        The issue options or the issue message.

      Returns this

      The clone of the shape.

    • Defines a relationship between keys where not all peers can be present at the same time.

      Parameters

      • keys: KeysShape[typeof OUTPUT][]

        The keys of which, if one present, the others may not all be present.

      • Optionaloptions: IssueOptions | Message

        The issue options or the issue message.

      Returns this

      The clone of the shape.

    • Defines a relationship between keys where at least one of the keys is required (and more than one is allowed).

      Parameters

      • keys: KeysShape[typeof OUTPUT][]

        The keys of which at least one must appear.

      • Optionaloptions: IssueOptions | Message

        The issue options or the issue message.

      Returns this

      The clone of the shape.

    • Defines an exclusive relationship between a set of keys where only one is allowed but none are required.

      Parameters

      • keys: KeysShape[typeof OUTPUT][]

        The exclusive keys that must not appear together but where none are required.

      • Optionaloptions: IssueOptions | Message

        The issue options or the issue message.

      Returns this

      The clone of the shape.

    • Defines an exclusive relationship between a set of keys where one of them is required but not at the same time.

      Parameters

      • keys: KeysShape[typeof OUTPUT][]

        The exclusive keys that must not appear together but where one of them is required.

      • Optionaloptions: IssueOptions | Message

        The issue options or the issue message.

      Returns this

      The clone of the shape.