{"version":3,"file":"array-rules.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/array/array-rules.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Unique array rule - array must contain unique values\r\n */\r\nexport const uniqueArrayRule: SchemaRule = {\r\n  name: \"uniqueArray\",\r\n  description: \"The array must contain unique values\",\r\n  defaultErrorMessage: \"The :input must contain unique values\",\r\n  async validate(value: any, context) {\r\n    const uniqueValues = new Set(value);\r\n\r\n    if (uniqueValues.size === value.length) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    return invalidRule(this, context);\r\n  },\r\n};\r\n\r\n/**\r\n * Sorted array rule - array must be sorted\r\n */\r\nexport const sortedArrayRule: SchemaRule<{\r\n  direction?: \"asc\" | \"desc\";\r\n}> = {\r\n  name: \"sortedArray\",\r\n  description: \"The array must be sorted\",\r\n  defaultErrorMessage: \"The :input must be sorted\",\r\n  async validate(value: any[], context) {\r\n    if (!Array.isArray(value) || value.length <= 1) {\r\n      return VALID_RULE;\r\n    }\r\n\r\n    const direction = this.context.options.direction ?? \"asc\";\r\n    this.context.translatableParams.direction = direction;\r\n\r\n    for (let i = 0; i < value.length - 1; i++) {\r\n      const current = value[i];\r\n      const next = value[i + 1];\r\n\r\n      if (direction === \"asc\") {\r\n        if (current > next) {\r\n          return invalidRule(this, context);\r\n        }\r\n      } else {\r\n        if (current < next) {\r\n          return invalidRule(this, context);\r\n        }\r\n      }\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n"],"mappings":";;;;;;;AAMA,MAAa,kBAA8B;CACzC,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAGlC,IAAI,IAFqB,IAAI,KAEd,CAAC,CAAC,SAAS,MAAM,QAC9B,OAAO;EAGT,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;AAKA,MAAa,kBAER;CACH,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAc,SAAS;EACpC,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,UAAU,GAC3C,OAAO;EAGT,MAAM,YAAY,KAAK,QAAQ,QAAQ,aAAa;EACpD,KAAK,QAAQ,mBAAmB,YAAY;EAE5C,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,SAAS,GAAG,KAAK;GACzC,MAAM,UAAU,MAAM;GACtB,MAAM,OAAO,MAAM,IAAI;GAEvB,IAAI,cAAc,OAChB;QAAI,UAAU,MACZ,OAAO,YAAY,MAAM,OAAO;GAClC,OAEA,IAAI,UAAU,MACZ,OAAO,YAAY,MAAM,OAAO;EAGtC;EAEA,OAAO;CACT;AACF"}