{"version":3,"file":"config.mjs","names":[],"sources":["../../../../../../@warlock.js/seal/src/config.ts"],"sourcesContent":["/**\r\n * Seal Configuration\r\n *\r\n * Global configuration for the Seal validation library\r\n */\r\n\r\nimport type { AttributeTranslation, RuleTranslation } from \"./types\";\r\n\r\nexport type TranslateRuleCallback = (\r\n  ruleTranslation: RuleTranslation,\r\n) => string;\r\n\r\nexport type TranslateAttributeCallback = (\r\n  attributeTranslation: AttributeTranslation,\r\n) => string;\r\n\r\nexport type SealConfig = {\r\n  /**\r\n   * Translation function for error messages\r\n   * Default: returns the key with attributes replaced\r\n   */\r\n  translateRule?: TranslateRuleCallback;\r\n  /**\r\n   * Translation function for attribute messages\r\n   */\r\n  translateAttribute?: TranslateAttributeCallback;\r\n\r\n  /**\r\n   * Default to first error only in validation\r\n   * Default: true\r\n   */\r\n  firstErrorOnly?: boolean;\r\n};\r\n\r\n/**\r\n * Global Seal configuration\r\n */\r\nconst config: SealConfig = {\r\n  firstErrorOnly: true,\r\n};\r\n\r\n/**\r\n * Configure Seal globally\r\n *\r\n * @example\r\n * ```ts\r\n * import { configureSeal } from \"@warlock.js/seal\";\r\n * import { trans } from \"@mongez/localization\";\r\n *\r\n * configureSeal({\r\n *   translateRule: (ruleTranslation) => trans(`validation.${ruleTranslation.rule.name}`, ruleTranslation.attributes),\r\n *   translateAttribute: (attributeTranslation) => trans(`validation.attributes.${attributeTranslation.rule.name}.${attributeTranslation.attribute}`, attributeTranslation.context.allValues),\r\n * });\r\n * ```\r\n */\r\nexport function configureSeal(options: Partial<SealConfig>): void {\r\n  Object.assign(config, options);\r\n}\r\n\r\n/**\r\n * Get current Seal configuration\r\n */\r\nexport function getSealConfig(): SealConfig {\r\n  return config;\r\n}\r\n\r\n/**\r\n * Reset configuration to defaults\r\n */\r\nexport function resetSealConfig(): void {\r\n  delete config.translateRule;\r\n  delete config.translateAttribute;\r\n\r\n  config.firstErrorOnly = true;\r\n}\r\n"],"mappings":";;;;AAqCA,MAAM,SAAqB,EACzB,gBAAgB,KAClB;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,SAAoC;CAChE,OAAO,OAAO,QAAQ,OAAO;AAC/B;;;;AAKA,SAAgB,gBAA4B;CAC1C,OAAO;AACT;;;;AAKA,SAAgB,kBAAwB;CACtC,OAAO,OAAO;CACd,OAAO,OAAO;CAEd,OAAO,iBAAiB;AAC1B"}