{"version":3,"file":"required-when-rule.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/conditional/required-when-rule.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\nimport { isEmptyValue } from \"../../helpers/is-empty-value\";\nimport type { SchemaContext, SchemaRule } from \"../../types\";\n\n/**\n * Required when callback returns true.\n *\n * The callback receives only the SchemaContext (not the value),\n * because \"required\" is about surrounding conditions, not the field itself.\n *\n * @example\n * ```ts\n * v.string().requiredWhen((context) => {\n *   return context.allData.notificationMethod === 'email';\n * })\n * ```\n */\nexport const requiredWhenRule: SchemaRule<{\n  callback: (context: SchemaContext) => boolean | Promise<boolean>;\n}> = {\n  name: \"requiredWhen\",\n  defaultErrorMessage: \"The :input is required\",\n  requiresValue: false,\n  sortOrder: -2,\n  async validate(value, context) {\n    const shouldBeRequired = await this.context.options.callback?.(context);\n\n    if (shouldBeRequired && isEmptyValue(value)) {\n      return invalidRule(this, context);\n    }\n\n    return VALID_RULE;\n  },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAa,mBAER;CACH,MAAM;CACN,qBAAqB;CACrB,eAAe;CACf,WAAW;CACX,MAAM,SAAS,OAAO,SAAS;EAG7B,IAAI,MAF2B,KAAK,QAAQ,QAAQ,WAAW,OAAO,KAE9C,aAAa,KAAK,GACxC,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF"}