Skip to content

Implement input & output map functionality #27

Description

@justsml

Add a new type & exported method to support optional input & output definitions alongside the rules that need them.

export type FieldKeyMapping = Record<string, string | true>;

/**
 * An associated set of rules & their needed input values.
 */
export interface RuleMapping {
  /**
   * A object, array, or string describing a set of logical `Rule`'s
   */
  rules: Readonly<Rule>;
  /**
   * A map of input keys to their key paths from the input object.
   */
  inputMap?: FieldKeyMapping;
  /**
   * Values merged to the output of the rules.
   *
   * When `outputMap` is an object, the keys are the source value path and the values are the input value's keys.
   * ```
   * {
   *  fromKey: 'toKey.path.string[0]'
   * }
   * ```
   *
   * When outputMap is a string, it's treated as a destination path for the entire rules output.
   */
  outputMap?: string | FieldKeyMapping;
}
  • An input mapping of deeply nested input values to flat key/value inputs speeds up & simplifies the rule expressions.
    • Saves you from having to write ad-hoc data shaping code anywhere you use any given rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions