rules-machine icon indicating copy to clipboard operation
rules-machine copied to clipboard

Implement input & output map functionality

Open justsml opened this issue 1 year ago • 0 comments

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.

justsml avatar Jul 15 '22 23:07 justsml