{"version":3,"file":"equality-conditional-methods.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/validators/methods/equality-conditional-methods.ts"],"sourcesContent":["import { equalsFieldRule, notEqualsFieldRule } from \"../../rules\";\r\nimport { equalRule } from \"../../rules/core/equal\";\r\nimport { whenRule } from \"../../rules/core/when\";\r\nimport type { WhenRuleOptions } from \"../../types\";\r\nimport { BaseValidator } from \"../base-validator\";\r\n\r\n/**\r\n * Marker re-exported by the validators barrel so the dts bundler keeps this\r\n * module (and its `declare module` augmentation) in the bundled `.d.ts`.\r\n */\r\nexport const equalityConditionalMethodsApplied = true;\r\n\r\ndeclare module \"../base-validator\" {\r\n  interface BaseValidator {\r\n    /**\r\n     * Value must be equal to the given value\r\n     */\r\n    equal(value: any, errorMessage?: string): this;\r\n\r\n    /**\r\n     * Value must be the same as another field's value\r\n     */\r\n    sameAs(field: string, errorMessage?: string): this;\r\n\r\n    /**\r\n     * Value must be the same as another sibling field's value\r\n     */\r\n    sameAsSibling(field: string, errorMessage?: string): this;\r\n\r\n    /**\r\n     * Value must be different from another field's value\r\n     */\r\n    differentFrom(field: string, errorMessage?: string): this;\r\n\r\n    /**\r\n     * Value must be different from another sibling field's value\r\n     */\r\n    differentFromSibling(field: string, errorMessage?: string): this;\r\n\r\n    /**\r\n     * Apply different validation rules based on another field's value (global scope)\r\n     *\r\n     * Use this when you need to apply completely different validators\r\n     * based on another field's value (not just required/optional).\r\n     *\r\n     * @param field - Field name to check (can be nested with dot notation)\r\n     * @param options - Validation options per field value\r\n     *\r\n     * @example\r\n     * ```ts\r\n     * // Different allowed values based on user type\r\n     * v.object({\r\n     *   userType: v.string().in(['admin', 'user']),\r\n     *   role: v.string().when('userType', {\r\n     *     is: {\r\n     *       admin: v.string().in(['super', 'moderator']),\r\n     *       user: v.string().in(['member', 'guest'])\r\n     *     },\r\n     *     otherwise: v.string().optional()\r\n     *   })\r\n     * })\r\n     *\r\n     * // Different validation rules based on type\r\n     * v.object({\r\n     *   contactType: v.string().in(['email', 'phone']),\r\n     *   contact: v.string().when('contactType', {\r\n     *     is: {\r\n     *       email: v.string().email(),\r\n     *       phone: v.string().pattern(/^\\d{10}$/)\r\n     *     }\r\n     *   })\r\n     * })\r\n     * ```\r\n     * @category Conditional Validation\r\n     */\r\n    when(field: string, options: Omit<WhenRuleOptions, \"field\" | \"scope\">): this;\r\n\r\n    /**\r\n     * Apply different validation rules based on sibling field's value\r\n     *\r\n     * Use this for nested objects where you need to check a field\r\n     * within the same parent object.\r\n     *\r\n     * @param siblingField - Sibling field name to check\r\n     * @param options - Validation options per field value\r\n     *\r\n     * @example\r\n     * ```ts\r\n     * // Array of users with role-based permissions\r\n     * v.array(v.object({\r\n     *   userType: v.string().in(['admin', 'user']),\r\n     *   permissions: v.string().whenSibling('userType', {\r\n     *     is: {\r\n     *       admin: v.string().in(['read', 'write', 'delete']),\r\n     *       user: v.string().in(['read'])\r\n     *     }\r\n     *   })\r\n     * }))\r\n     * ```\r\n     * @category Conditional Validation\r\n     */\r\n    whenSibling(siblingField: string, options: Omit<WhenRuleOptions, \"field\" | \"scope\">): this;\r\n  }\r\n}\r\n\r\n/**\r\n * Value must be equal to the given value\r\n */\r\nBaseValidator.prototype.equal = function (value: any, errorMessage?: string) {\r\n  return this.addRule(equalRule, errorMessage, { value });\r\n};\r\n\r\n/**\r\n * Value must be the same as another field's value\r\n */\r\nBaseValidator.prototype.sameAs = function (field: string, errorMessage?: string) {\r\n  return this.addRule(equalsFieldRule, errorMessage, {\r\n    field,\r\n    scope: \"global\",\r\n  });\r\n};\r\n\r\n/**\r\n * Value must be the same as another sibling field's value\r\n */\r\nBaseValidator.prototype.sameAsSibling = function (field: string, errorMessage?: string) {\r\n  return this.addRule(equalsFieldRule, errorMessage, {\r\n    field,\r\n    scope: \"sibling\",\r\n  });\r\n};\r\n\r\n/**\r\n * Value must be different from another field's value\r\n */\r\nBaseValidator.prototype.differentFrom = function (field: string, errorMessage?: string) {\r\n  return this.addRule(notEqualsFieldRule, errorMessage, {\r\n    field,\r\n    scope: \"global\",\r\n  });\r\n};\r\n\r\n/**\r\n * Value must be different from another sibling field's value\r\n */\r\nBaseValidator.prototype.differentFromSibling = function (field: string, errorMessage?: string) {\r\n  return this.addRule(notEqualsFieldRule, errorMessage, {\r\n    field,\r\n    scope: \"sibling\",\r\n  });\r\n};\r\n\r\n/**\r\n * Apply different validation rules based on another field's value (global scope)\r\n *\r\n * Use this when you need to apply completely different validators\r\n * based on another field's value (not just required/optional).\r\n *\r\n * @param field - Field name to check (can be nested with dot notation)\r\n * @param options - Validation options per field value\r\n *\r\n * @example\r\n * ```ts\r\n * // Different allowed values based on user type\r\n * v.object({\r\n *   userType: v.string().in(['admin', 'user']),\r\n *   role: v.string().when('userType', {\r\n *     is: {\r\n *       admin: v.string().in(['super', 'moderator']),\r\n *       user: v.string().in(['member', 'guest'])\r\n *     },\r\n *     otherwise: v.string().optional()\r\n *   })\r\n * })\r\n *\r\n * // Different validation rules based on type\r\n * v.object({\r\n *   contactType: v.string().in(['email', 'phone']),\r\n *   contact: v.string().when('contactType', {\r\n *     is: {\r\n *       email: v.string().email(),\r\n *       phone: v.string().pattern(/^\\d{10}$/)\r\n *     }\r\n *   })\r\n * })\r\n * ```\r\n * @category Conditional Validation\r\n */\r\nBaseValidator.prototype.when = function (\r\n  field: string,\r\n  options: Omit<WhenRuleOptions, \"field\" | \"scope\">,\r\n) {\r\n  return this.addRule(whenRule, undefined, {\r\n    field,\r\n    is: options.is,\r\n    otherwise: options.otherwise,\r\n    scope: \"global\",\r\n  });\r\n};\r\n\r\n/**\r\n * Apply different validation rules based on sibling field's value\r\n *\r\n * Use this for nested objects where you need to check a field\r\n * within the same parent object.\r\n *\r\n * @param siblingField - Sibling field name to check\r\n * @param options - Validation options per field value\r\n *\r\n * @example\r\n * ```ts\r\n * // Array of users with role-based permissions\r\n * v.array(v.object({\r\n *   userType: v.string().in(['admin', 'user']),\r\n *   permissions: v.string().whenSibling('userType', {\r\n *     is: {\r\n *       admin: v.string().in(['read', 'write', 'delete']),\r\n *       user: v.string().in(['read'])\r\n *     }\r\n *   })\r\n * }))\r\n * ```\r\n * @category Conditional Validation\r\n */\r\nBaseValidator.prototype.whenSibling = function (\r\n  siblingField: string,\r\n  options: Omit<WhenRuleOptions, \"field\" | \"scope\">,\r\n) {\r\n  return this.addRule(whenRule, undefined, {\r\n    field: siblingField,\r\n    is: options.is,\r\n    otherwise: options.otherwise,\r\n    scope: \"sibling\",\r\n  });\r\n};\r\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,oCAAoC;;;;AAkGjD,cAAc,UAAU,QAAQ,SAAU,OAAY,cAAuB;CAC3E,OAAO,KAAK,QAAQ,WAAW,cAAc,EAAE,MAAM,CAAC;AACxD;;;;AAKA,cAAc,UAAU,SAAS,SAAU,OAAe,cAAuB;CAC/E,OAAO,KAAK,QAAQ,iBAAiB,cAAc;EACjD;EACA,OAAO;CACT,CAAC;AACH;;;;AAKA,cAAc,UAAU,gBAAgB,SAAU,OAAe,cAAuB;CACtF,OAAO,KAAK,QAAQ,iBAAiB,cAAc;EACjD;EACA,OAAO;CACT,CAAC;AACH;;;;AAKA,cAAc,UAAU,gBAAgB,SAAU,OAAe,cAAuB;CACtF,OAAO,KAAK,QAAQ,oBAAoB,cAAc;EACpD;EACA,OAAO;CACT,CAAC;AACH;;;;AAKA,cAAc,UAAU,uBAAuB,SAAU,OAAe,cAAuB;CAC7F,OAAO,KAAK,QAAQ,oBAAoB,cAAc;EACpD;EACA,OAAO;CACT,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,cAAc,UAAU,OAAO,SAC7B,OACA,SACA;CACA,OAAO,KAAK,QAAQ,UAAU,QAAW;EACvC;EACA,IAAI,QAAQ;EACZ,WAAW,QAAQ;EACnB,OAAO;CACT,CAAC;AACH;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,cAAc,UAAU,cAAc,SACpC,cACA,SACA;CACA,OAAO,KAAK,QAAQ,UAAU,QAAW;EACvC,OAAO;EACP,IAAI,QAAQ;EACZ,WAAW,QAAQ;EACnB,OAAO;CACT,CAAC;AACH"}