Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement input & output map functionality #27

Open
justsml opened this issue Jul 15, 2022 · 0 comments
Open

Implement input & output map functionality #27

justsml opened this issue Jul 15, 2022 · 0 comments

Comments

@justsml
Copy link
Contributor

justsml commented Jul 15, 2022

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant