{"version":3,"file":"enum.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/common/enum.ts"],"sourcesContent":["import { invalidRule, resolveTranslation, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Enum rule - value must be one of the enum values\r\n */\r\nexport const enumRule: SchemaRule<{ enum: any }> = {\r\n  name: \"enum\",\r\n  defaultErrorMessage: \"The :input must be one of the following values: :enum\",\r\n  async validate(value: any, context) {\r\n    const enumValues = this.context.options.enum;\r\n\r\n    if (enumValues.includes(value)) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    // Translate each enum value individually, then join into a display string\r\n    this.context.translationParams.enum = enumValues\r\n      .map((v: any) =>\r\n        resolveTranslation({ key: String(v), rawValue: String(v), rule: this, context }),\r\n      )\r\n      .join(\", \");\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * In rule - value must be in the given array\r\n */\r\nexport const inRule: SchemaRule<{ values: any[] }> = {\r\n  name: \"in\",\r\n  defaultErrorMessage: \"The :input must be one of the following values: :values\",\r\n  async validate(value: any, context) {\r\n    if (this.context.options.values.includes(value)) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    // Translate each value individually, then join\r\n    this.context.translationParams.values = this.context.options.values\r\n      .map((v: any) =>\r\n        resolveTranslation({ key: String(v), rawValue: String(v), rule: this, context }),\r\n      )\r\n      .join(\", \");\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Allowed values rule - value must be one of allowed values\r\n */\r\nexport const allowedValuesRule: SchemaRule<{ allowedValues: any[] }> = {\r\n  name: \"allowedValues\",\r\n  defaultErrorMessage: \"The :input must be one of the allowed values\",\r\n  async validate(value: any, context) {\r\n    if (this.context.options.allowedValues.includes(value)) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    // Translate each value individually, then join\r\n    this.context.translationParams.allowedValues = this.context.options.allowedValues\r\n      .map((v: any) =>\r\n        resolveTranslation({ key: String(v), rawValue: String(v), rule: this, context }),\r\n      )\r\n      .join(\", \");\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Not allowed values rule - value must not be in forbidden list\r\n */\r\nexport const notAllowedValuesRule: SchemaRule<{ notAllowedValues: any[] }> = {\r\n  name: \"notAllowedValues\",\r\n  defaultErrorMessage: \"The :input contains a forbidden value\",\r\n  async validate(value: any, context) {\r\n    if (!this.context.options.notAllowedValues.includes(value)) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    // Translate each value individually, then join\r\n    this.context.translationParams.notAllowedValues = this.context.options.notAllowedValues\r\n      .map((v: any) =>\r\n        resolveTranslation({ key: String(v), rawValue: String(v), rule: this, context }),\r\n      )\r\n      .join(\", \");\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,WAAsC;CACjD,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,aAAa,KAAK,QAAQ,QAAQ;EAExC,IAAI,WAAW,SAAS,KAAK,GAC3B,OAAO;EAIT,KAAK,QAAQ,kBAAkB,OAAO,WACnC,KAAK,MACJ,mBAAmB;GAAE,KAAK,OAAO,CAAC;GAAG,UAAU,OAAO,CAAC;GAAG,MAAM;GAAM;EAAQ,CAAC,CACjF,CAAC,CACA,KAAK,IAAI;EAEZ,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,SAAwC;CACnD,MAAM;CACN,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,KAAK,QAAQ,QAAQ,OAAO,SAAS,KAAK,GAC5C,OAAO;EAIT,KAAK,QAAQ,kBAAkB,SAAS,KAAK,QAAQ,QAAQ,OAC1D,KAAK,MACJ,mBAAmB;GAAE,KAAK,OAAO,CAAC;GAAG,UAAU,OAAO,CAAC;GAAG,MAAM;GAAM;EAAQ,CAAC,CACjF,CAAC,CACA,KAAK,IAAI;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