{"version":3,"file":"required.mjs","names":[],"sources":["../../../../../../../../@warlock.js/seal/src/rules/core/required.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\r\nimport { isEmptyValue } from \"../../helpers/is-empty-value\";\r\nimport type { SchemaRule } from \"../../types\";\r\n\r\n/**\r\n * Required rule - value must be present and not empty\r\n */\r\nexport const requiredRule: SchemaRule = {\r\n  name: \"required\",\r\n  defaultErrorMessage: \"The :input is required\",\r\n  requiresValue: false,\r\n  sortOrder: -2,\r\n  async validate(value: any, context) {\r\n    if (isEmptyValue(value)) {\r\n      return invalidRule(this, context);\r\n    }\r\n    return VALID_RULE;\r\n  },\r\n};\r\n\r\n/**\r\n * Present rule - key must exist in the data, but value can be anything\r\n * (empty string, null are all valid as long as the key exists)\r\n */\r\nexport const presentRule: SchemaRule = {\r\n  name: \"present\",\r\n  defaultErrorMessage: \"The :input field is required\",\r\n  requiresValue: false,\r\n  sortOrder: -2,\r\n  async validate(value: any, context) {\r\n    if (value === undefined) {\r\n      return invalidRule(this, context);\r\n    }\r\n\r\n    return VALID_RULE;\r\n  },\r\n};\r\n"],"mappings":";;;;;;;;AAOA,MAAa,eAA2B;CACtC,MAAM;CACN,qBAAqB;CACrB,eAAe;CACf,WAAW;CACX,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,aAAa,KAAK,GACpB,OAAO,YAAY,MAAM,OAAO;EAElC,OAAO;CACT;AACF;;;;;AAMA,MAAa,cAA0B;CACrC,MAAM;CACN,qBAAqB;CACrB,eAAe;CACf,WAAW;CACX,MAAM,SAAS,OAAY,SAAS;EAClC,IAAI,UAAU,QACZ,OAAO,YAAY,MAAM,OAAO;EAGlC,OAAO;CACT;AACF"}