@inixiative/json-rules 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var lodash=require('lodash'),m=require('dayjs'),A=require('dayjs/plugin/utc'),B=require('dayjs/plugin/timezone'),D=require('dayjs/plugin/isSameOrBefore'),I=require('dayjs/plugin/isSameOrAfter');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var m__default=/*#__PURE__*/_interopDefault(m);var A__default=/*#__PURE__*/_interopDefault(A);var B__default=/*#__PURE__*/_interopDefault(B);var D__default=/*#__PURE__*/_interopDefault(D);var I__default=/*#__PURE__*/_interopDefault(I);var b=(f=>(f.equal="equal",f.notEqual="notEqual",f.lessThan="lessThan",f.lessThanEqual="lessThanEqual",f.greaterThan="greaterThan",f.greaterThanEqual="greaterThanEqual",f.contains="contains",f.notContains="notContains",f.in="in",f.notIn="notIn",f.match="match",f.notMatch="notMatch",f.between="between",f.notBetween="notBetween",f.isEmpty="isEmpty",f.notEmpty="notEmpty",f.exists="exists",f.notExists="notExists",f.startsWith="startsWith",f.endsWith="endsWith",f))(b||{}),E=(n=>(n.all="all",n.any="any",n.none="none",n.atLeast="atLeast",n.atMost="atMost",n.exactly="exactly",n.empty="empty",n.notEmpty="notEmpty",n))(E||{}),$=(n=>(n.before="before",n.after="after",n.onOrBefore="onOrBefore",n.onOrAfter="onOrAfter",n.between="between",n.notBetween="notBetween",n.dayIn="dayIn",n.dayNotIn="dayNotIn",n))($||{});m__default.default.extend(A__default.default);m__default.default.extend(B__default.default);m__default.default.extend(D__default.default);m__default.default.extend(I__default.default);var q=(e,o,u)=>{let a=lodash.get(o,e.field);if(!a)throw new Error(`${e.field} is null or undefined`);let r=m__default.default(a);if(!r.isValid())throw new Error(`${e.field} is not a valid date: ${a}`);let l=i=>e.error||`${e.field} ${i}`,s=j(e,o,u,r,a),t=s[0],n=s[1];switch(e.dateOperator){case "before":return r.isBefore(t)||l(`must be before ${t.format()}`);case "after":return r.isAfter(t)||l(`must be after ${t.format()}`);case "onOrBefore":return r.isSameOrBefore(t)||l(`must be on or before ${t.format()}`);case "onOrAfter":return r.isSameOrAfter(t)||l(`must be on or after ${t.format()}`);case "between":return r.isSameOrAfter(t)&&r.isSameOrBefore(n)||l(`must be between ${t.format()} and ${n.format()}`);case "notBetween":return r.isBefore(t)||r.isAfter(n)||l(`must not be between ${t.format()} and ${n.format()}`);case "dayIn":if(!Array.isArray(e.value))throw new Error("dayIn operator requires an array of day names");let i=r.format("dddd").toLowerCase(),h=e.value.map(c=>c.toLowerCase());return h.includes(i)||l(`must be on ${h.join(" or ")}`);case "dayNotIn":if(!Array.isArray(e.value))throw new Error("dayNotIn operator requires an array of day names");let x=r.format("dddd").toLowerCase(),g=e.value.map(c=>c.toLowerCase());return !g.includes(x)||l(`must not be on ${g.join(" or ")}`);default:throw new Error("Unknown date operator")}},j=(e,o,u,a,r)=>{if(["between","notBetween"].includes(e.dateOperator)){if(!Array.isArray(e.value)||e.value.length!==2)throw new Error(`${e.dateOperator} operator requires an array of two dates`);let t=p(e.value[0],r),n=p(e.value[1],r);if(!t.isValid())throw new Error(`Invalid start date: ${e.value[0]}`);if(!n.isValid())throw new Error(`Invalid end date: ${e.value[1]}`);return [t,n]}if(["before","after","onOrBefore","onOrAfter"].includes(e.dateOperator)){let t;if(e.value!==void 0)t=e.value;else if(e.path)e.path.startsWith("$.")?t=lodash.get(o,e.path.substring(2)):t=lodash.get(u,e.path);else throw new Error("No value or path specified for date comparison");let n=p(t,r);if(!n.isValid())throw new Error(`Invalid comparison date: ${t}`);return [n,void 0]}return [m__default.default(),void 0]},p=(e,o)=>{let u=String(e);if(u.includes("Z")||u.includes("T")&&(u.includes("+")||u.match(/T.*-\d{2}:/)))return m__default.default(e);let r=String(o),l=0;if(r.includes("+")||r.includes("T")&&r.match(/T.*-\d{2}:/)){let t=r.match(/([+-])(\d{2}):(\d{2})/);t&&(l=(t[1]==="+"?1:-1)*(parseInt(t[2])*60+parseInt(t[3])));}else r.includes("Z")||(l=0);return u.match(/^\d{4}-\d{2}-\d{2}$/)?m__default.default(e+"T00:00:00").subtract(l,"minute"):m__default.default(e).subtract(l,"minute")};var T=(e,o,u)=>{let a=lodash.get(o,e.field),l=!["isEmpty","notEmpty","exists","notExists"].includes(e.operator),s=l?C(e,o,u):void 0,t=n=>e.error||`${e.field} ${n}${l?" "+JSON.stringify(s):""}`;switch(e.operator){case "equal":return a===s||t("must equal");case "notEqual":return a!==s||t("must not equal");case "lessThan":return a<s||t("must be less than");case "lessThanEqual":return a<=s||t("must be less than or equal to");case "greaterThan":return a>s||t("must be greater than");case "greaterThanEqual":return a>=s||t("must be greater than or equal to");case "in":return s?.includes(a)||t("must be one of");case "notIn":return !s?.includes(a)||t("must not be one of");case "contains":return a?.includes(s)||t("must contain");case "notContains":return !a?.includes(s)||t("must not contain");case "match":return !!a?.match(s)||t("must match pattern");case "notMatch":return !a?.match(s)||t("must not match pattern");case "between":if(!Array.isArray(s)||s.length!==2)throw new Error("between operator requires an array of two values");return a>=s[0]&&a<=s[1]||t("must be between");case "notBetween":if(!Array.isArray(s)||s.length!==2)throw new Error("notBetween operator requires an array of two values");return a<s[0]||a>s[1]||t("must not be between");case "isEmpty":return lodash.isEmpty(a)||t("must be empty");case "notEmpty":return !lodash.isEmpty(a)||t("must not be empty");case "exists":return a!==void 0||t("must exist");case "notExists":return a===void 0||t("must not exist");case "startsWith":return a?.startsWith?.(s)||t("must start with");case "endsWith":return a?.endsWith?.(s)||t("must end with");default:throw new Error("Unknown operator")}},C=(e,o,u)=>{if(e.value!==void 0)return e.value;if(e.path)return e.path.startsWith("$.")?lodash.get(o,e.path.substring(2)):lodash.get(u,e.path);throw new Error("No value or path specified")};var y=(e,o,u=o)=>typeof e=="boolean"?e:"all"in e?W(e.all,o,u,e.error):"any"in e?M(e.any,o,u,e.error):"arrayOperator"in e?N(e,o,u):"dateOperator"in e?q(e,o,u):"field"in e?T(e,o,u):"if"in e?L(e,o,u):false,W=(e,o,u,a)=>{let r=[];for(let l of e){let s=y(l,o,u);s!==true&&(typeof s=="string"?r.push(s):r.push("false"));}return r.length?a||(r.length===1?r[0]:`All conditions must pass: ${r.join(" AND ")}`):true},M=(e,o,u,a)=>{let r=[];for(let l of e){let s=y(l,o,u);if(typeof s!="string")return true;r.push(s);}return a||(r.length===1?r[0]:`At least one condition must pass: ${r.join(" OR ")}`)},L=(e,o,u)=>y(e.if,o,u)===true?y(e.then,o,u):e.else?y(e.else,o,u):true,N=(e,o,u)=>{let a=lodash.get(u,e.field);if(!Array.isArray(a))throw new Error(`${e.field} must be an array`);let r=i=>e.error||`${e.field} ${i}`,l=["all","any","none","atLeast","atMost","exactly"],s=["atLeast","atMost","exactly"];if(l.includes(e.arrayOperator)&&!e.condition)throw new Error(`${e.arrayOperator} requires a condition to check against array elements`);if(s.includes(e.arrayOperator)&&e.count===void 0)throw new Error(`${e.arrayOperator} requires a count`);let t=0,n=0;if(l.includes(e.arrayOperator)){if(!lodash.some(a,lodash.isObject))throw new Error(`${e.field} contains only primitive values. Use 'in' or 'contains' operators instead of array operators for primitive arrays`);let i=a.map(h=>y(e.condition,h,u));t=i.filter(h=>h===true).length,n=i.filter(h=>typeof h=="string").length;}switch(e.arrayOperator){case "empty":return !a.length||r("must be empty");case "notEmpty":return !!a.length||r("must not be empty");case "all":return t===a.length||r(`all elements must match (${n} failed)`);case "any":return !!t||r("at least one element must match");case "none":return !t||r(`no elements should match (${t} matched)`);case "atLeast":return t>=e.count||r(`at least ${e.count} elements must match (${t} matched)`);case "atMost":return t<=e.count||r(`at most ${e.count} elements must match (${t} matched)`);case "exactly":return t===e.count||r(`exactly ${e.count} elements must match (${t} matched)`);default:throw new Error("Unknown array operator")}};exports.ArrayOperator=E;exports.DateOperator=$;exports.Operator=b;exports.check=y;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var lodash=require('lodash'),m=require('dayjs'),A=require('dayjs/plugin/utc'),B=require('dayjs/plugin/timezone'),D=require('dayjs/plugin/isSameOrBefore'),I=require('dayjs/plugin/isSameOrAfter');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var m__default=/*#__PURE__*/_interopDefault(m);var A__default=/*#__PURE__*/_interopDefault(A);var B__default=/*#__PURE__*/_interopDefault(B);var D__default=/*#__PURE__*/_interopDefault(D);var I__default=/*#__PURE__*/_interopDefault(I);var b=(f=>(f.equals="equals",f.notEquals="notEquals",f.lessThan="lessThan",f.lessThanEquals="lessThanEquals",f.greaterThan="greaterThan",f.greaterThanEquals="greaterThanEquals",f.contains="contains",f.notContains="notContains",f.in="in",f.notIn="notIn",f.matches="matches",f.notMatches="notMatches",f.between="between",f.notBetween="notBetween",f.isEmpty="isEmpty",f.notEmpty="notEmpty",f.exists="exists",f.notExists="notExists",f.startsWith="startsWith",f.endsWith="endsWith",f))(b||{}),E=(n=>(n.all="all",n.any="any",n.none="none",n.atLeast="atLeast",n.atMost="atMost",n.exactly="exactly",n.empty="empty",n.notEmpty="notEmpty",n))(E||{}),$=(n=>(n.before="before",n.after="after",n.onOrBefore="onOrBefore",n.onOrAfter="onOrAfter",n.between="between",n.notBetween="notBetween",n.dayIn="dayIn",n.dayNotIn="dayNotIn",n))($||{});m__default.default.extend(A__default.default);m__default.default.extend(B__default.default);m__default.default.extend(D__default.default);m__default.default.extend(I__default.default);var q=(e,o,u)=>{let s=lodash.get(o,e.field);if(!s)throw new Error(`${e.field} is null or undefined`);let r=m__default.default(s);if(!r.isValid())throw new Error(`${e.field} is not a valid date: ${s}`);let l=i=>e.error||`${e.field} ${i}`,a=j(e,o,u,r,s),t=a[0],n=a[1];switch(e.dateOperator){case "before":return r.isBefore(t)||l(`must be before ${t.format()}`);case "after":return r.isAfter(t)||l(`must be after ${t.format()}`);case "onOrBefore":return r.isSameOrBefore(t)||l(`must be on or before ${t.format()}`);case "onOrAfter":return r.isSameOrAfter(t)||l(`must be on or after ${t.format()}`);case "between":return r.isSameOrAfter(t)&&r.isSameOrBefore(n)||l(`must be between ${t.format()} and ${n.format()}`);case "notBetween":return r.isBefore(t)||r.isAfter(n)||l(`must not be between ${t.format()} and ${n.format()}`);case "dayIn":if(!Array.isArray(e.value))throw new Error("dayIn operator requires an array of day names");let i=r.format("dddd").toLowerCase(),h=e.value.map(c=>c.toLowerCase());return h.includes(i)||l(`must be on ${h.join(" or ")}`);case "dayNotIn":if(!Array.isArray(e.value))throw new Error("dayNotIn operator requires an array of day names");let x=r.format("dddd").toLowerCase(),g=e.value.map(c=>c.toLowerCase());return !g.includes(x)||l(`must not be on ${g.join(" or ")}`);default:throw new Error("Unknown date operator")}},j=(e,o,u,s,r)=>{if(["between","notBetween"].includes(e.dateOperator)){if(!Array.isArray(e.value)||e.value.length!==2)throw new Error(`${e.dateOperator} operator requires an array of two dates`);let t=p(e.value[0],r),n=p(e.value[1],r);if(!t.isValid())throw new Error(`Invalid start date: ${e.value[0]}`);if(!n.isValid())throw new Error(`Invalid end date: ${e.value[1]}`);return [t,n]}if(["before","after","onOrBefore","onOrAfter"].includes(e.dateOperator)){let t;if(e.value!==void 0)t=e.value;else if(e.path)e.path.startsWith("$.")?t=lodash.get(o,e.path.substring(2)):t=lodash.get(u,e.path);else throw new Error("No value or path specified for date comparison");let n=p(t,r);if(!n.isValid())throw new Error(`Invalid comparison date: ${t}`);return [n,void 0]}return [m__default.default(),void 0]},p=(e,o)=>{let u=String(e);if(u.includes("Z")||u.includes("T")&&(u.includes("+")||u.match(/T.*-\d{2}:/)))return m__default.default(e);let r=String(o),l=0;if(r.includes("+")||r.includes("T")&&r.match(/T.*-\d{2}:/)){let t=r.match(/([+-])(\d{2}):(\d{2})/);t&&(l=(t[1]==="+"?1:-1)*(parseInt(t[2])*60+parseInt(t[3])));}else r.includes("Z")||(l=0);return u.match(/^\d{4}-\d{2}-\d{2}$/)?m__default.default(e+"T00:00:00").subtract(l,"minute"):m__default.default(e).subtract(l,"minute")};var T=(e,o,u)=>{let s=lodash.get(o,e.field),l=!["isEmpty","notEmpty","exists","notExists"].includes(e.operator),a=l?C(e,o,u):void 0,t=n=>e.error||`${e.field} ${n}${l?" "+JSON.stringify(a):""}`;switch(e.operator){case "equals":return s===a||t("must equal");case "notEquals":return s!==a||t("must not equal");case "lessThan":return s<a||t("must be less than");case "lessThanEquals":return s<=a||t("must be less than or equal to");case "greaterThan":return s>a||t("must be greater than");case "greaterThanEquals":return s>=a||t("must be greater than or equal to");case "in":return a?.includes(s)||t("must be one of");case "notIn":return !a?.includes(s)||t("must not be one of");case "contains":return s?.includes(a)||t("must contain");case "notContains":return !s?.includes(a)||t("must not contain");case "matches":return !!s?.match(a)||t("must match pattern");case "notMatches":return !s?.match(a)||t("must not match pattern");case "between":if(!Array.isArray(a)||a.length!==2)throw new Error("between operator requires an array of two values");return s>=a[0]&&s<=a[1]||t("must be between");case "notBetween":if(!Array.isArray(a)||a.length!==2)throw new Error("notBetween operator requires an array of two values");return s<a[0]||s>a[1]||t("must not be between");case "isEmpty":return lodash.isEmpty(s)||t("must be empty");case "notEmpty":return !lodash.isEmpty(s)||t("must not be empty");case "exists":return s!==void 0||t("must exist");case "notExists":return s===void 0||t("must not exist");case "startsWith":return s?.startsWith?.(a)||t("must start with");case "endsWith":return s?.endsWith?.(a)||t("must end with");default:throw new Error("Unknown operator")}},C=(e,o,u)=>{if(e.value!==void 0)return e.value;if(e.path)return e.path.startsWith("$.")?lodash.get(o,e.path.substring(2)):lodash.get(u,e.path);throw new Error("No value or path specified")};var y=(e,o,u=o)=>typeof e=="boolean"?e:"all"in e?W(e.all,o,u,e.error):"any"in e?M(e.any,o,u,e.error):"arrayOperator"in e?N(e,o,u):"dateOperator"in e?q(e,o,u):"field"in e?T(e,o,u):"if"in e?L(e,o,u):false,W=(e,o,u,s)=>{let r=[];for(let l of e){let a=y(l,o,u);a!==true&&(typeof a=="string"?r.push(a):r.push("false"));}return r.length?s||(r.length===1?r[0]:`All conditions must pass: ${r.join(" AND ")}`):true},M=(e,o,u,s)=>{let r=[];for(let l of e){let a=y(l,o,u);if(typeof a!="string")return true;r.push(a);}return s||(r.length===1?r[0]:`At least one condition must pass: ${r.join(" OR ")}`)},L=(e,o,u)=>y(e.if,o,u)===true?y(e.then,o,u):e.else?y(e.else,o,u):true,N=(e,o,u)=>{let s=lodash.get(u,e.field);if(!Array.isArray(s))throw new Error(`${e.field} must be an array`);let r=i=>e.error||`${e.field} ${i}`,l=["all","any","none","atLeast","atMost","exactly"],a=["atLeast","atMost","exactly"];if(l.includes(e.arrayOperator)&&!e.condition)throw new Error(`${e.arrayOperator} requires a condition to check against array elements`);if(a.includes(e.arrayOperator)&&e.count===void 0)throw new Error(`${e.arrayOperator} requires a count`);let t=0,n=0;if(l.includes(e.arrayOperator)){if(!lodash.some(s,lodash.isObject))throw new Error(`${e.field} contains only primitive values. Use 'in' or 'contains' operators instead of array operators for primitive arrays`);let i=s.map(h=>y(e.condition,h,u));t=i.filter(h=>h===true).length,n=i.filter(h=>typeof h=="string").length;}switch(e.arrayOperator){case "empty":return !s.length||r("must be empty");case "notEmpty":return !!s.length||r("must not be empty");case "all":return t===s.length||r(`all elements must match (${n} failed)`);case "any":return !!t||r("at least one element must match");case "none":return !t||r(`no elements should match (${t} matched)`);case "atLeast":return t>=e.count||r(`at least ${e.count} elements must match (${t} matched)`);case "atMost":return t<=e.count||r(`at most ${e.count} elements must match (${t} matched)`);case "exactly":return t===e.count||r(`exactly ${e.count} elements must match (${t} matched)`);default:throw new Error("Unknown array operator")}};exports.ArrayOperator=E;exports.DateOperator=$;exports.Operator=b;exports.check=y;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/operator.ts","../src/date.ts","../src/field.ts","../src/check.ts"],"names":["Operator","ArrayOperator","DateOperator","dayjs","utc","timezone","isSameOrBefore","isSameOrAfter","checkDate","condition","data","context","fieldValue","get","fieldDate","getError","op","dates","parseCompareDates","compareDate","endDate","dayName","allowedDays","d","day","excludedDays","startDate","parseDateWithTimezone","value","date","valueStr","fieldStr","offset","match","checkField","needsValue","getValue","isEmpty","check","conditions","all","any","checkArray","checkIfThenElse","error","errors","result","arrayValue","defaultMsg","requiresCondition","requiresCount","matches","failures","some","isObject","results","item","r"],"mappings":"2fAAO,IAAKA,OACVA,CAAAA,CAAA,KAAA,CAAQ,QACRA,CAAAA,CAAA,QAAA,CAAW,WACXA,CAAAA,CAAA,QAAA,CAAW,UAAA,CACXA,CAAAA,CAAA,cAAgB,eAAA,CAChBA,CAAAA,CAAA,YAAc,aAAA,CACdA,CAAAA,CAAA,iBAAmB,kBAAA,CACnBA,CAAAA,CAAA,QAAA,CAAW,UAAA,CACXA,EAAA,WAAA,CAAc,aAAA,CACdA,EAAA,EAAA,CAAK,IAAA,CACLA,EAAA,KAAA,CAAQ,OAAA,CACRA,CAAAA,CAAA,KAAA,CAAQ,QACRA,CAAAA,CAAA,QAAA,CAAW,WACXA,CAAAA,CAAA,OAAA,CAAU,UACVA,CAAAA,CAAA,UAAA,CAAa,YAAA,CACbA,CAAAA,CAAA,QAAU,SAAA,CACVA,CAAAA,CAAA,SAAW,UAAA,CACXA,CAAAA,CAAA,OAAS,QAAA,CACTA,CAAAA,CAAA,SAAA,CAAY,WAAA,CACZA,EAAA,UAAA,CAAa,YAAA,CACbA,EAAA,QAAA,CAAW,UAAA,CApBDA,OAAA,EAAA,CAAA,CAuBAC,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,CAAAA,CAAA,GAAA,CAAM,MACNA,CAAAA,CAAA,GAAA,CAAM,MACNA,CAAAA,CAAA,IAAA,CAAO,OACPA,CAAAA,CAAA,OAAA,CAAU,UACVA,CAAAA,CAAA,MAAA,CAAS,SACTA,CAAAA,CAAA,OAAA,CAAU,UACVA,CAAAA,CAAA,KAAA,CAAQ,QACRA,CAAAA,CAAA,QAAA,CAAW,UAAA,CARDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,IAWAC,CAAAA,CAAAA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A,UAAA,CACE,OAAO,CAAC,CAACgC,CAAAA,CAAW,MAAA,EAAUhC,CAAAA,CAAS,mBAAmB,CAAA,CAE5D,KAAA,KAAA,CACE,OAAOoC,CAAAA,GAAYJ,CAAAA,CAAW,QAAUhC,CAAAA,CAAS,CAAA,yBAAA,EAA4BqC,CAAQ,CAAA,QAAA,CAAU,EAEjG,KAAA,KAAA,CACE,OAAO,CAAC,CAACD,CAAAA,EAAWpC,EAAS,iCAAiC,CAAA,CAEhE,KAAA,MAAA,CACE,OAAO,CAACoC,CAAAA,EAAWpC,CAAAA,CAAS,6BAA6BoC,CAAO,CAAA,SAAA,CAAW,EAE7E,KAAA,SAAA,CACE,OAAOA,CAAAA,EAAW1C,CAAAA,CAAU,OAAUM,CAAAA,CAAS,CAAA,SAAA,EAAYN,EAAU,KAAK,CAAA,sBAAA,EAAyB0C,CAAO,CAAA,SAAA,CAAW,CAAA,CAEvH,KAAA,QAAA,CACE,OAAOA,GAAW1C,CAAAA,CAAU,KAAA,EAAUM,EAAS,CAAA,QAAA,EAAWN,CAAAA,CAAU,KAAK,CAAA,sBAAA,EAAyB0C,CAAO,CAAA,SAAA,CAAW,CAAA,CAEtH,eACE,OAAOA,CAAAA,GAAY1C,EAAU,KAAA,EAAUM,CAAAA,CAAS,WAAWN,CAAAA,CAAU,KAAK,yBAAyB0C,CAAO,CAAA,SAAA,CAAW,EAEvH,QACE,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAC5C,CACF","file":"index.cjs","sourcesContent":["export enum Operator {\n equal = 'equal',\n notEqual = 'notEqual',\n lessThan = 'lessThan',\n lessThanEqual = 'lessThanEqual',\n greaterThan = 'greaterThan',\n greaterThanEqual = 'greaterThanEqual',\n contains = 'contains',\n notContains = 'notContains',\n in = 'in',\n notIn = 'notIn',\n match = 'match',\n notMatch = 'notMatch',\n between = 'between',\n notBetween = 'notBetween',\n isEmpty = 'isEmpty',\n notEmpty = 'notEmpty',\n exists = 'exists',\n notExists = 'notExists',\n startsWith = 'startsWith',\n endsWith = 'endsWith',\n}\n\nexport enum ArrayOperator {\n all = 'all',\n any = 'any',\n none = 'none',\n atLeast = 'atLeast',\n atMost = 'atMost',\n exactly = 'exactly',\n empty = 'empty',\n notEmpty = 'notEmpty',\n}\n\nexport enum DateOperator {\n before = 'before',\n after = 'after',\n onOrBefore = 'onOrBefore',\n onOrAfter = 'onOrAfter',\n between = 'between',\n notBetween = 'notBetween',\n dayIn = 'dayIn', // e.g., ['monday', 'tuesday', 'friday']\n dayNotIn = 'dayNotIn',\n}\n","import { get } from 'lodash';\nimport dayjs from 'dayjs';\nimport utc from 'dayjs/plugin/utc';\nimport timezone from 'dayjs/plugin/timezone';\nimport isSameOrBefore from 'dayjs/plugin/isSameOrBefore';\nimport isSameOrAfter from 'dayjs/plugin/isSameOrAfter';\nimport type { DateRule } from './types';\nimport { DateOperator } from './operator';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\ndayjs.extend(isSameOrBefore);\ndayjs.extend(isSameOrAfter);\n\nexport const checkDate = (condition: DateRule, data: any, context: any): boolean | string => {\n const fieldValue = get(data, condition.field);\n \n if (!fieldValue) throw new Error(`${condition.field} is null or undefined`);\n \n const fieldDate = dayjs(fieldValue);\n \n if (!fieldDate.isValid()) throw new Error(`${condition.field} is not a valid date: ${fieldValue}`);\n \n const getError = (op: string) => condition.error || `${condition.field} ${op}`;\n \n // Parse comparison dates with timezone context - pass the original string to preserve offset info\n const dates = parseCompareDates(condition, data, context, fieldDate, fieldValue);\n const compareDate = dates[0];\n const endDate = dates[1];\n \n switch (condition.dateOperator) {\n case DateOperator.before:\n return fieldDate.isBefore(compareDate) || getError(`must be before ${compareDate.format()}`);\n \n case DateOperator.after:\n return fieldDate.isAfter(compareDate) || getError(`must be after ${compareDate.format()}`);\n \n case DateOperator.onOrBefore:\n return fieldDate.isSameOrBefore(compareDate) || getError(`must be on or before ${compareDate.format()}`);\n \n case DateOperator.onOrAfter:\n return fieldDate.isSameOrAfter(compareDate) || getError(`must be on or after ${compareDate.format()}`);\n \n case DateOperator.between:\n return (fieldDate.isSameOrAfter(compareDate) && fieldDate.isSameOrBefore(endDate!)) || \n getError(`must be between ${compareDate.format()} and ${endDate!.format()}`);\n \n case DateOperator.notBetween:\n return (fieldDate.isBefore(compareDate) || fieldDate.isAfter(endDate!)) || \n getError(`must not be between ${compareDate.format()} and ${endDate!.format()}`);\n \n case DateOperator.dayIn:\n if (!Array.isArray(condition.value)) throw new Error('dayIn operator requires an array of day names');\n const dayName = fieldDate.format('dddd').toLowerCase();\n const allowedDays = condition.value.map(d => d.toLowerCase());\n return allowedDays.includes(dayName) || getError(`must be on ${allowedDays.join(' or ')}`);\n \n case DateOperator.dayNotIn:\n if (!Array.isArray(condition.value)) throw new Error('dayNotIn operator requires an array of day names');\n const day = fieldDate.format('dddd').toLowerCase();\n const excludedDays = condition.value.map(d => d.toLowerCase());\n return !excludedDays.includes(day) || getError(`must not be on ${excludedDays.join(' or ')}`);\n \n default:\n throw new Error('Unknown date operator');\n }\n}\n\nconst parseCompareDates = (condition: DateRule, data: any, context: any, fieldDate: dayjs.Dayjs, fieldValue: string): [dayjs.Dayjs, dayjs.Dayjs | undefined] => {\n const requiresTwoDates = [DateOperator.between, DateOperator.notBetween];\n \n if (requiresTwoDates.includes(condition.dateOperator)) {\n if (!Array.isArray(condition.value) || condition.value.length !== 2) \n throw new Error(`${condition.dateOperator} operator requires an array of two dates`);\n const startDate = parseDateWithTimezone(condition.value[0], fieldValue);\n const endDate = parseDateWithTimezone(condition.value[1], fieldValue);\n if (!startDate.isValid()) throw new Error(`Invalid start date: ${condition.value[0]}`);\n if (!endDate.isValid()) throw new Error(`Invalid end date: ${condition.value[1]}`);\n return [startDate, endDate];\n }\n \n const requiresOneDate = [\n DateOperator.before,\n DateOperator.after,\n DateOperator.onOrBefore,\n DateOperator.onOrAfter\n ];\n \n if (requiresOneDate.includes(condition.dateOperator)) {\n let value;\n if (condition.value !== undefined) {\n value = condition.value;\n } else if (condition.path) {\n // Support $.path for current element\n if (condition.path.startsWith('$.')) {\n value = get(data, condition.path.substring(2));\n } else {\n value = get(context, condition.path);\n }\n } else {\n throw new Error('No value or path specified for date comparison');\n }\n const date = parseDateWithTimezone(value, fieldValue);\n if (!date.isValid()) throw new Error(`Invalid comparison date: ${value}`);\n return [date, undefined];\n }\n \n return [dayjs(), undefined]; // Won't be used for dayIn/dayNotIn\n}\n\nconst parseDateWithTimezone = (value: any, fieldValue: string): dayjs.Dayjs => {\n const valueStr = String(value);\n \n // Check if value has explicit timezone information\n const hasTimezone = valueStr.includes('Z') || \n (valueStr.includes('T') && (valueStr.includes('+') || valueStr.match(/T.*-\\d{2}:/)));\n \n if (hasTimezone) return dayjs(value);\n \n // No timezone info in value - interpret in field's timezone\n // Extract offset from field value\n const fieldStr = String(fieldValue);\n let offset = 0;\n \n if (fieldStr.includes('+') || (fieldStr.includes('T') && fieldStr.match(/T.*-\\d{2}:/))) {\n // Field has explicit offset like +11:00 or -08:00\n const match = fieldStr.match(/([+-])(\\d{2}):(\\d{2})/);\n if (match) {\n const sign = match[1] === '+' ? 1 : -1;\n offset = sign * (parseInt(match[2]) * 60 + parseInt(match[3]));\n }\n } else if (!fieldStr.includes('Z')) {\n // Field has no timezone, assume local time (offset 0)\n offset = 0;\n }\n // If field has Z, it's UTC (offset 0)\n \n // Create a date representing the same local time as the field's timezone\n if (valueStr.match(/^\\d{4}-\\d{2}-\\d{2}$/)) {\n // For date-only, we want midnight in the field's timezone\n const localMidnight = dayjs(value + 'T00:00:00');\n return localMidnight.subtract(offset, 'minute');\n }\n \n // For datetime without timezone, interpret as local time in field's timezone\n const localTime = dayjs(value);\n return localTime.subtract(offset, 'minute');\n}","import { get, isEmpty } from 'lodash';\nimport type { Rule } from './types';\nimport { Operator } from './operator';\n\nexport const checkField = (condition: Rule, data: any, context: any): boolean | string => {\n // Use data for field access (current element) but context remains available for path references\n const fieldValue = get(data, condition.field);\n \n // Operators that don't need a value\n const noValueOps = [Operator.isEmpty, Operator.notEmpty, Operator.exists, Operator.notExists];\n const needsValue = !noValueOps.includes(condition.operator);\n const value = needsValue ? getValue(condition, data, context) : undefined;\n \n const getError = (op: string) => condition.error || `${condition.field} ${op}${needsValue ? ' ' + JSON.stringify(value) : ''}`;\n\n switch (condition.operator) {\n case Operator.equal:\n return fieldValue === value || getError(`must equal`);\n case Operator.notEqual:\n return fieldValue !== value || getError(`must not equal`);\n case Operator.lessThan:\n return fieldValue < value || getError(`must be less than`);\n case Operator.lessThanEqual:\n return fieldValue <= value || getError(`must be less than or equal to`);\n case Operator.greaterThan:\n return fieldValue > value || getError(`must be greater than`);\n case Operator.greaterThanEqual:\n return fieldValue >= value || getError(`must be greater than or equal to`);\n case Operator.in:\n return value?.includes(fieldValue) || getError(`must be one of`);\n case Operator.notIn:\n return !value?.includes(fieldValue) || getError(`must not be one of`);\n case Operator.contains:\n return fieldValue?.includes(value) || getError(`must contain`);\n case Operator.notContains:\n return !fieldValue?.includes(value) || getError(`must not contain`);\n case Operator.match:\n return !!fieldValue?.match(value) || getError(`must match pattern`);\n case Operator.notMatch:\n return !fieldValue?.match(value) || getError(`must not match pattern`);\n case Operator.between:\n if (!Array.isArray(value) || value.length !== 2) \n throw new Error('between operator requires an array of two values');\n return (fieldValue >= value[0] && fieldValue <= value[1]) || getError(`must be between`);\n case Operator.notBetween:\n if (!Array.isArray(value) || value.length !== 2) \n throw new Error('notBetween operator requires an array of two values');\n return (fieldValue < value[0] || fieldValue > value[1]) || getError(`must not be between`);\n case Operator.isEmpty:\n return isEmpty(fieldValue) || getError(`must be empty`);\n case Operator.notEmpty:\n return !isEmpty(fieldValue) || getError(`must not be empty`);\n case Operator.exists:\n return fieldValue !== undefined || getError(`must exist`);\n case Operator.notExists:\n return fieldValue === undefined || getError(`must not exist`);\n case Operator.startsWith:\n return fieldValue?.startsWith?.(value) || getError(`must start with`);\n case Operator.endsWith:\n return fieldValue?.endsWith?.(value) || getError(`must end with`);\n default:\n throw new Error('Unknown operator');\n }\n};\n\nconst getValue = (condition: Rule, data: any, context: any): any => {\n if (condition.value !== undefined) return condition.value;\n if (condition.path) {\n // Special case: if path starts with \"$.\" use data (current element)\n if (condition.path.startsWith('$.')) {\n return get(data, condition.path.substring(2));\n }\n // Otherwise use context (root data)\n return get(context, condition.path);\n }\n throw new Error('No value or path specified');\n};","import { get, some, isObject } from 'lodash';\nimport type { Condition, ArrayRule } from './types';\nimport { ArrayOperator } from './operator';\nimport { checkDate } from './date';\nimport { checkField } from './field';\n\nexport const check = (conditions: Condition, data: any, context: any = data): boolean | string => {\n if (typeof conditions === 'boolean') return conditions;\n if ('all' in conditions) return all(conditions.all, data, context, conditions.error);\n if ('any' in conditions) return any(conditions.any, data, context, conditions.error);\n if ('arrayOperator' in conditions) return checkArray(conditions, data, context);\n if ('dateOperator' in conditions) return checkDate(conditions, data, context);\n if ('field' in conditions) return checkField(conditions, data, context);\n if ('if' in conditions) return checkIfThenElse(conditions, data, context);\n\n return false;\n}\n\nconst all = (conditions: Condition[], data: any, context: any, error?: string): boolean | string => {\n const errors: string[] = [];\n \n for (const condition of conditions) {\n const result = check(condition, data, context);\n if (result !== true) {\n // Handle both string errors and false boolean results\n if (typeof result === 'string') {\n errors.push(result);\n } else {\n // For boolean false, include it in the error message\n errors.push('false');\n }\n }\n }\n\n if (!errors.length) return true;\n if (error) return error;\n if (errors.length === 1) return errors[0];\n return `All conditions must pass: ${errors.join(' AND ')}`;\n}\n\nconst any = (conditions: Condition[], data: any, context: any, error?: string): boolean | string => {\n const errors: string[] = [];\n\n for (const condition of conditions) {\n const result = check(condition, data, context);\n if (typeof result !== 'string') return true;\n errors.push(result);\n }\n\n if (error) return error;\n if (errors.length === 1) return errors[0];\n return `At least one condition must pass: ${errors.join(' OR ')}`;\n}\n\nconst checkIfThenElse = (condition: any, data: any, context: any): boolean | string => {\n const ifResult = check(condition.if, data, context);\n \n if (ifResult === true) return check(condition.then, data, context);\n return condition.else ? check(condition.else, data, context) : true;\n}\n\nconst checkArray = (condition: ArrayRule, data: any, context: any): boolean | string => {\n const arrayValue = get(context, condition.field);\n \n if (!Array.isArray(arrayValue)) throw new Error(`${condition.field} must be an array`);\n \n const getError = (defaultMsg: string) => condition.error || `${condition.field} ${defaultMsg}`;\n \n // Operators that require a condition\n const requiresCondition = [\n ArrayOperator.all, \n ArrayOperator.any, \n ArrayOperator.none,\n ArrayOperator.atLeast,\n ArrayOperator.atMost,\n ArrayOperator.exactly\n ];\n \n // Operators that require a count\n const requiresCount = [\n ArrayOperator.atLeast,\n ArrayOperator.atMost,\n ArrayOperator.exactly\n ];\n \n if (requiresCondition.includes(condition.arrayOperator) && !condition.condition) \n throw new Error(`${condition.arrayOperator} requires a condition to check against array elements`);\n \n if (requiresCount.includes(condition.arrayOperator) && condition.count === undefined) \n throw new Error(`${condition.arrayOperator} requires a count`);\n \n // For operators that check elements, compute matches\n let matches = 0;\n let failures = 0;\n \n if (requiresCondition.includes(condition.arrayOperator)) {\n // Check if array contains any objects\n if (!some(arrayValue, isObject)) \n throw new Error(`${condition.field} contains only primitive values. Use 'in' or 'contains' operators instead of array operators for primitive arrays`);\n \n // Pass item as data (for relative field access) but keep original context (for path access)\n const results = arrayValue.map(item => check(condition.condition!, item, context));\n matches = results.filter(r => r === true).length;\n failures = results.filter(r => typeof r === 'string').length;\n }\n \n switch (condition.arrayOperator) {\n case ArrayOperator.empty:\n return !arrayValue.length || getError('must be empty');\n \n case ArrayOperator.notEmpty:\n return !!arrayValue.length || getError('must not be empty');\n \n case ArrayOperator.all:\n return matches === arrayValue.length || getError(`all elements must match (${failures} failed)`);\n \n case ArrayOperator.any:\n return !!matches || getError('at least one element must match');\n \n case ArrayOperator.none:\n return !matches || getError(`no elements should match (${matches} matched)`);\n \n case ArrayOperator.atLeast:\n return matches >= condition.count! || getError(`at least ${condition.count} elements must match (${matches} matched)`);\n \n case ArrayOperator.atMost:\n return matches <= condition.count! || getError(`at most ${condition.count} elements must match (${matches} matched)`);\n \n case ArrayOperator.exactly:\n return matches === condition.count! || getError(`exactly ${condition.count} elements must match (${matches} matched)`);\n \n default:\n throw new Error('Unknown array operator');\n }\n}"]}
1
+ {"version":3,"sources":["../src/operator.ts","../src/date.ts","../src/field.ts","../src/check.ts"],"names":["Operator","ArrayOperator","DateOperator","dayjs","utc","timezone","isSameOrBefore","isSameOrAfter","checkDate","condition","data","context","fieldValue","get","fieldDate","getError","op","dates","parseCompareDates","compareDate","endDate","dayName","allowedDays","d","day","excludedDays","startDate","parseDateWithTimezone","value","date","valueStr","fieldStr","offset","match","checkField","needsValue","getValue","isEmpty","check","conditions","all","any","checkArray","checkIfThenElse","error","errors","result","arrayValue","defaultMsg","requiresCondition","requiresCount","matches","failures","some","isObject","results","item","r"],"mappings":"2fAAO,IAAKA,OACVA,CAAAA,CAAA,MAAA,CAAS,SACTA,CAAAA,CAAA,SAAA,CAAY,YACZA,CAAAA,CAAA,QAAA,CAAW,UAAA,CACXA,CAAAA,CAAA,eAAiB,gBAAA,CACjBA,CAAAA,CAAA,YAAc,aAAA,CACdA,CAAAA,CAAA,kBAAoB,mBAAA,CACpBA,CAAAA,CAAA,QAAA,CAAW,UAAA,CACXA,EAAA,WAAA,CAAc,aAAA,CACdA,EAAA,EAAA,CAAK,IAAA,CACLA,EAAA,KAAA,CAAQ,OAAA,CACRA,CAAAA,CAAA,OAAA,CAAU,UACVA,CAAAA,CAAA,UAAA,CAAa,aACbA,CAAAA,CAAA,OAAA,CAAU,UACVA,CAAAA,CAAA,UAAA,CAAa,YAAA,CACbA,CAAAA,CAAA,QAAU,SAAA,CACVA,CAAAA,CAAA,SAAW,UAAA,CACXA,CAAAA,CAAA,OAAS,QAAA,CACTA,CAAAA,CAAA,SAAA,CAAY,WAAA,CACZA,EAAA,UAAA,CAAa,YAAA,CACbA,EAAA,QAAA,CAAW,UAAA,CApBDA,OAAA,EAAA,CAAA,CAuBAC,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,CAAAA,CAAA,GAAA,CAAM,MACNA,CAAAA,CAAA,GAAA,C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\n lessThan = 'lessThan',\n lessThanEquals = 'lessThanEquals',\n greaterThan = 'greaterThan',\n greaterThanEquals = 'greaterThanEquals',\n contains = 'contains',\n notContains = 'notContains',\n in = 'in',\n notIn = 'notIn',\n matches = 'matches',\n notMatches = 'notMatches',\n between = 'between',\n notBetween = 'notBetween',\n isEmpty = 'isEmpty',\n notEmpty = 'notEmpty',\n exists = 'exists',\n notExists = 'notExists',\n startsWith = 'startsWith',\n endsWith = 'endsWith',\n}\n\nexport enum ArrayOperator {\n all = 'all',\n any = 'any',\n none = 'none',\n atLeast = 'atLeast',\n atMost = 'atMost',\n exactly = 'exactly',\n empty = 'empty',\n notEmpty = 'notEmpty',\n}\n\nexport enum DateOperator {\n before = 'before',\n after = 'after',\n onOrBefore = 'onOrBefore',\n onOrAfter = 'onOrAfter',\n between = 'between',\n notBetween = 'notBetween',\n dayIn = 'dayIn', // e.g., ['monday', 'tuesday', 'friday']\n dayNotIn = 'dayNotIn',\n}\n","import { get } from 'lodash';\nimport dayjs from 'dayjs';\nimport utc from 'dayjs/plugin/utc';\nimport timezone from 'dayjs/plugin/timezone';\nimport isSameOrBefore from 'dayjs/plugin/isSameOrBefore';\nimport isSameOrAfter from 'dayjs/plugin/isSameOrAfter';\nimport type { DateRule } from './types';\nimport { DateOperator } from './operator';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\ndayjs.extend(isSameOrBefore);\ndayjs.extend(isSameOrAfter);\n\nexport const checkDate = (condition: DateRule, data: any, context: any): boolean | string => {\n const fieldValue = get(data, condition.field);\n \n if (!fieldValue) throw new Error(`${condition.field} is null or undefined`);\n \n const fieldDate = dayjs(fieldValue);\n \n if (!fieldDate.isValid()) throw new Error(`${condition.field} is not a valid date: ${fieldValue}`);\n \n const getError = (op: string) => condition.error || `${condition.field} ${op}`;\n \n // Parse comparison dates with timezone context - pass the original string to preserve offset info\n const dates = parseCompareDates(condition, data, context, fieldDate, fieldValue);\n const compareDate = dates[0];\n const endDate = dates[1];\n \n switch (condition.dateOperator) {\n case DateOperator.before:\n return fieldDate.isBefore(compareDate) || getError(`must be before ${compareDate.format()}`);\n \n case DateOperator.after:\n return fieldDate.isAfter(compareDate) || getError(`must be after ${compareDate.format()}`);\n \n case DateOperator.onOrBefore:\n return fieldDate.isSameOrBefore(compareDate) || getError(`must be on or before ${compareDate.format()}`);\n \n case DateOperator.onOrAfter:\n return fieldDate.isSameOrAfter(compareDate) || getError(`must be on or after ${compareDate.format()}`);\n \n case DateOperator.between:\n return (fieldDate.isSameOrAfter(compareDate) && fieldDate.isSameOrBefore(endDate!)) || \n getError(`must be between ${compareDate.format()} and ${endDate!.format()}`);\n \n case DateOperator.notBetween:\n return (fieldDate.isBefore(compareDate) || fieldDate.isAfter(endDate!)) || \n getError(`must not be between ${compareDate.format()} and ${endDate!.format()}`);\n \n case DateOperator.dayIn:\n if (!Array.isArray(condition.value)) throw new Error('dayIn operator requires an array of day names');\n const dayName = fieldDate.format('dddd').toLowerCase();\n const allowedDays = condition.value.map(d => d.toLowerCase());\n return allowedDays.includes(dayName) || getError(`must be on ${allowedDays.join(' or ')}`);\n \n case DateOperator.dayNotIn:\n if (!Array.isArray(condition.value)) throw new Error('dayNotIn operator requires an array of day names');\n const day = fieldDate.format('dddd').toLowerCase();\n const excludedDays = condition.value.map(d => d.toLowerCase());\n return !excludedDays.includes(day) || getError(`must not be on ${excludedDays.join(' or ')}`);\n \n default:\n throw new Error('Unknown date operator');\n }\n}\n\nconst parseCompareDates = (condition: DateRule, data: any, context: any, fieldDate: dayjs.Dayjs, fieldValue: string): [dayjs.Dayjs, dayjs.Dayjs | undefined] => {\n const requiresTwoDates = [DateOperator.between, DateOperator.notBetween];\n \n if (requiresTwoDates.includes(condition.dateOperator)) {\n if (!Array.isArray(condition.value) || condition.value.length !== 2) \n throw new Error(`${condition.dateOperator} operator requires an array of two dates`);\n const startDate = parseDateWithTimezone(condition.value[0], fieldValue);\n const endDate = parseDateWithTimezone(condition.value[1], fieldValue);\n if (!startDate.isValid()) throw new Error(`Invalid start date: ${condition.value[0]}`);\n if (!endDate.isValid()) throw new Error(`Invalid end date: ${condition.value[1]}`);\n return [startDate, endDate];\n }\n \n const requiresOneDate = [\n DateOperator.before,\n DateOperator.after,\n DateOperator.onOrBefore,\n DateOperator.onOrAfter\n ];\n \n if (requiresOneDate.includes(condition.dateOperator)) {\n let value;\n if (condition.value !== undefined) {\n value = condition.value;\n } else if (condition.path) {\n // Support $.path for current element\n if (condition.path.startsWith('$.')) {\n value = get(data, condition.path.substring(2));\n } else {\n value = get(context, condition.path);\n }\n } else {\n throw new Error('No value or path specified for date comparison');\n }\n const date = parseDateWithTimezone(value, fieldValue);\n if (!date.isValid()) throw new Error(`Invalid comparison date: ${value}`);\n return [date, undefined];\n }\n \n return [dayjs(), undefined]; // Won't be used for dayIn/dayNotIn\n}\n\nconst parseDateWithTimezone = (value: any, fieldValue: string): dayjs.Dayjs => {\n const valueStr = String(value);\n \n // Check if value has explicit timezone information\n const hasTimezone = valueStr.includes('Z') || \n (valueStr.includes('T') && (valueStr.includes('+') || valueStr.match(/T.*-\\d{2}:/)));\n \n if (hasTimezone) return dayjs(value);\n \n // No timezone info in value - interpret in field's timezone\n // Extract offset from field value\n const fieldStr = String(fieldValue);\n let offset = 0;\n \n if (fieldStr.includes('+') || (fieldStr.includes('T') && fieldStr.match(/T.*-\\d{2}:/))) {\n // Field has explicit offset like +11:00 or -08:00\n const match = fieldStr.match(/([+-])(\\d{2}):(\\d{2})/);\n if (match) {\n const sign = match[1] === '+' ? 1 : -1;\n offset = sign * (parseInt(match[2]) * 60 + parseInt(match[3]));\n }\n } else if (!fieldStr.includes('Z')) {\n // Field has no timezone, assume local time (offset 0)\n offset = 0;\n }\n // If field has Z, it's UTC (offset 0)\n \n // Create a date representing the same local time as the field's timezone\n if (valueStr.match(/^\\d{4}-\\d{2}-\\d{2}$/)) {\n // For date-only, we want midnight in the field's timezone\n const localMidnight = dayjs(value + 'T00:00:00');\n return localMidnight.subtract(offset, 'minute');\n }\n \n // For datetime without timezone, interpret as local time in field's timezone\n const localTime = dayjs(value);\n return localTime.subtract(offset, 'minute');\n}","import { get, isEmpty } from 'lodash';\nimport type { Rule } from './types';\nimport { Operator } from './operator';\n\nexport const checkField = (condition: Rule, data: any, context: any): boolean | string => {\n // Use data for field access (current element) but context remains available for path references\n const fieldValue = get(data, condition.field);\n \n // Operators that don't need a value\n const noValueOps = [Operator.isEmpty, Operator.notEmpty, Operator.exists, Operator.notExists];\n const needsValue = !noValueOps.includes(condition.operator);\n const value = needsValue ? getValue(condition, data, context) : undefined;\n \n const getError = (op: string) => condition.error || `${condition.field} ${op}${needsValue ? ' ' + JSON.stringify(value) : ''}`;\n\n switch (condition.operator) {\n case Operator.equals:\n return fieldValue === value || getError(`must equal`);\n case Operator.notEquals:\n return fieldValue !== value || getError(`must not equal`);\n case Operator.lessThan:\n return fieldValue < value || getError(`must be less than`);\n case Operator.lessThanEquals:\n return fieldValue <= value || getError(`must be less than or equal to`);\n case Operator.greaterThan:\n return fieldValue > value || getError(`must be greater than`);\n case Operator.greaterThanEquals:\n return fieldValue >= value || getError(`must be greater than or equal to`);\n case Operator.in:\n return value?.includes(fieldValue) || getError(`must be one of`);\n case Operator.notIn:\n return !value?.includes(fieldValue) || getError(`must not be one of`);\n case Operator.contains:\n return fieldValue?.includes(value) || getError(`must contain`);\n case Operator.notContains:\n return !fieldValue?.includes(value) || getError(`must not contain`);\n case Operator.matches:\n return !!fieldValue?.match(value) || getError(`must match pattern`);\n case Operator.notMatches:\n return !fieldValue?.match(value) || getError(`must not match pattern`);\n case Operator.between:\n if (!Array.isArray(value) || value.length !== 2) \n throw new Error('between operator requires an array of two values');\n return (fieldValue >= value[0] && fieldValue <= value[1]) || getError(`must be between`);\n case Operator.notBetween:\n if (!Array.isArray(value) || value.length !== 2) \n throw new Error('notBetween operator requires an array of two values');\n return (fieldValue < value[0] || fieldValue > value[1]) || getError(`must not be between`);\n case Operator.isEmpty:\n return isEmpty(fieldValue) || getError(`must be empty`);\n case Operator.notEmpty:\n return !isEmpty(fieldValue) || getError(`must not be empty`);\n case Operator.exists:\n return fieldValue !== undefined || getError(`must exist`);\n case Operator.notExists:\n return fieldValue === undefined || getError(`must not exist`);\n case Operator.startsWith:\n return fieldValue?.startsWith?.(value) || getError(`must start with`);\n case Operator.endsWith:\n return fieldValue?.endsWith?.(value) || getError(`must end with`);\n default:\n throw new Error('Unknown operator');\n }\n};\n\nconst getValue = (condition: Rule, data: any, context: any): any => {\n if (condition.value !== undefined) return condition.value;\n if (condition.path) {\n // Special case: if path starts with \"$.\" use data (current element)\n if (condition.path.startsWith('$.')) {\n return get(data, condition.path.substring(2));\n }\n // Otherwise use context (root data)\n return get(context, condition.path);\n }\n throw new Error('No value or path specified');\n};","import { get, some, isObject } from 'lodash';\nimport type { Condition, ArrayRule } from './types';\nimport { ArrayOperator } from './operator';\nimport { checkDate } from './date';\nimport { checkField } from './field';\n\nexport const check = (conditions: Condition, data: any, context: any = data): boolean | string => {\n if (typeof conditions === 'boolean') return conditions;\n if ('all' in conditions) return all(conditions.all, data, context, conditions.error);\n if ('any' in conditions) return any(conditions.any, data, context, conditions.error);\n if ('arrayOperator' in conditions) return checkArray(conditions, data, context);\n if ('dateOperator' in conditions) return checkDate(conditions, data, context);\n if ('field' in conditions) return checkField(conditions, data, context);\n if ('if' in conditions) return checkIfThenElse(conditions, data, context);\n\n return false;\n}\n\nconst all = (conditions: Condition[], data: any, context: any, error?: string): boolean | string => {\n const errors: string[] = [];\n \n for (const condition of conditions) {\n const result = check(condition, data, context);\n if (result !== true) {\n // Handle both string errors and false boolean results\n if (typeof result === 'string') {\n errors.push(result);\n } else {\n // For boolean false, include it in the error message\n errors.push('false');\n }\n }\n }\n\n if (!errors.length) return true;\n if (error) return error;\n if (errors.length === 1) return errors[0];\n return `All conditions must pass: ${errors.join(' AND ')}`;\n}\n\nconst any = (conditions: Condition[], data: any, context: any, error?: string): boolean | string => {\n const errors: string[] = [];\n\n for (const condition of conditions) {\n const result = check(condition, data, context);\n if (typeof result !== 'string') return true;\n errors.push(result);\n }\n\n if (error) return error;\n if (errors.length === 1) return errors[0];\n return `At least one condition must pass: ${errors.join(' OR ')}`;\n}\n\nconst checkIfThenElse = (condition: any, data: any, context: any): boolean | string => {\n const ifResult = check(condition.if, data, context);\n \n if (ifResult === true) return check(condition.then, data, context);\n return condition.else ? check(condition.else, data, context) : true;\n}\n\nconst checkArray = (condition: ArrayRule, data: any, context: any): boolean | string => {\n const arrayValue = get(context, condition.field);\n \n if (!Array.isArray(arrayValue)) throw new Error(`${condition.field} must be an array`);\n \n const getError = (defaultMsg: string) => condition.error || `${condition.field} ${defaultMsg}`;\n \n // Operators that require a condition\n const requiresCondition = [\n ArrayOperator.all, \n ArrayOperator.any, \n ArrayOperator.none,\n ArrayOperator.atLeast,\n ArrayOperator.atMost,\n ArrayOperator.exactly\n ];\n \n // Operators that require a count\n const requiresCount = [\n ArrayOperator.atLeast,\n ArrayOperator.atMost,\n ArrayOperator.exactly\n ];\n \n if (requiresCondition.includes(condition.arrayOperator) && !condition.condition) \n throw new Error(`${condition.arrayOperator} requires a condition to check against array elements`);\n \n if (requiresCount.includes(condition.arrayOperator) && condition.count === undefined) \n throw new Error(`${condition.arrayOperator} requires a count`);\n \n // For operators that check elements, compute matches\n let matches = 0;\n let failures = 0;\n \n if (requiresCondition.includes(condition.arrayOperator)) {\n // Check if array contains any objects\n if (!some(arrayValue, isObject)) \n throw new Error(`${condition.field} contains only primitive values. Use 'in' or 'contains' operators instead of array operators for primitive arrays`);\n \n // Pass item as data (for relative field access) but keep original context (for path access)\n const results = arrayValue.map(item => check(condition.condition!, item, context));\n matches = results.filter(r => r === true).length;\n failures = results.filter(r => typeof r === 'string').length;\n }\n \n switch (condition.arrayOperator) {\n case ArrayOperator.empty:\n return !arrayValue.length || getError('must be empty');\n \n case ArrayOperator.notEmpty:\n return !!arrayValue.length || getError('must not be empty');\n \n case ArrayOperator.all:\n return matches === arrayValue.length || getError(`all elements must match (${failures} failed)`);\n \n case ArrayOperator.any:\n return !!matches || getError('at least one element must match');\n \n case ArrayOperator.none:\n return !matches || getError(`no elements should match (${matches} matched)`);\n \n case ArrayOperator.atLeast:\n return matches >= condition.count! || getError(`at least ${condition.count} elements must match (${matches} matched)`);\n \n case ArrayOperator.atMost:\n return matches <= condition.count! || getError(`at most ${condition.count} elements must match (${matches} matched)`);\n \n case ArrayOperator.exactly:\n return matches === condition.count! || getError(`exactly ${condition.count} elements must match (${matches} matched)`);\n \n default:\n throw new Error('Unknown array operator');\n }\n}"]}
package/dist/index.d.cts CHANGED
@@ -1,16 +1,16 @@
1
1
  declare enum Operator {
2
- equal = "equal",
3
- notEqual = "notEqual",
2
+ equals = "equals",
3
+ notEquals = "notEquals",
4
4
  lessThan = "lessThan",
5
- lessThanEqual = "lessThanEqual",
5
+ lessThanEquals = "lessThanEquals",
6
6
  greaterThan = "greaterThan",
7
- greaterThanEqual = "greaterThanEqual",
7
+ greaterThanEquals = "greaterThanEquals",
8
8
  contains = "contains",
9
9
  notContains = "notContains",
10
10
  in = "in",
11
11
  notIn = "notIn",
12
- match = "match",
13
- notMatch = "notMatch",
12
+ matches = "matches",
13
+ notMatches = "notMatches",
14
14
  between = "between",
15
15
  notBetween = "notBetween",
16
16
  isEmpty = "isEmpty",
package/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  declare enum Operator {
2
- equal = "equal",
3
- notEqual = "notEqual",
2
+ equals = "equals",
3
+ notEquals = "notEquals",
4
4
  lessThan = "lessThan",
5
- lessThanEqual = "lessThanEqual",
5
+ lessThanEquals = "lessThanEquals",
6
6
  greaterThan = "greaterThan",
7
- greaterThanEqual = "greaterThanEqual",
7
+ greaterThanEquals = "greaterThanEquals",
8
8
  contains = "contains",
9
9
  notContains = "notContains",
10
10
  in = "in",
11
11
  notIn = "notIn",
12
- match = "match",
13
- notMatch = "notMatch",
12
+ matches = "matches",
13
+ notMatches = "notMatches",
14
14
  between = "between",
15
15
  notBetween = "notBetween",
16
16
  isEmpty = "isEmpty",
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {get,isEmpty,some,isObject}from'lodash';import m from'dayjs';import A from'dayjs/plugin/utc';import B from'dayjs/plugin/timezone';import D from'dayjs/plugin/isSameOrBefore';import I from'dayjs/plugin/isSameOrAfter';var b=(f=>(f.equal="equal",f.notEqual="notEqual",f.lessThan="lessThan",f.lessThanEqual="lessThanEqual",f.greaterThan="greaterThan",f.greaterThanEqual="greaterThanEqual",f.contains="contains",f.notContains="notContains",f.in="in",f.notIn="notIn",f.match="match",f.notMatch="notMatch",f.between="between",f.notBetween="notBetween",f.isEmpty="isEmpty",f.notEmpty="notEmpty",f.exists="exists",f.notExists="notExists",f.startsWith="startsWith",f.endsWith="endsWith",f))(b||{}),E=(n=>(n.all="all",n.any="any",n.none="none",n.atLeast="atLeast",n.atMost="atMost",n.exactly="exactly",n.empty="empty",n.notEmpty="notEmpty",n))(E||{}),$=(n=>(n.before="before",n.after="after",n.onOrBefore="onOrBefore",n.onOrAfter="onOrAfter",n.between="between",n.notBetween="notBetween",n.dayIn="dayIn",n.dayNotIn="dayNotIn",n))($||{});m.extend(A);m.extend(B);m.extend(D);m.extend(I);var q=(e,o,u)=>{let a=get(o,e.field);if(!a)throw new Error(`${e.field} is null or undefined`);let r=m(a);if(!r.isValid())throw new Error(`${e.field} is not a valid date: ${a}`);let l=i=>e.error||`${e.field} ${i}`,s=j(e,o,u,r,a),t=s[0],n=s[1];switch(e.dateOperator){case "before":return r.isBefore(t)||l(`must be before ${t.format()}`);case "after":return r.isAfter(t)||l(`must be after ${t.format()}`);case "onOrBefore":return r.isSameOrBefore(t)||l(`must be on or before ${t.format()}`);case "onOrAfter":return r.isSameOrAfter(t)||l(`must be on or after ${t.format()}`);case "between":return r.isSameOrAfter(t)&&r.isSameOrBefore(n)||l(`must be between ${t.format()} and ${n.format()}`);case "notBetween":return r.isBefore(t)||r.isAfter(n)||l(`must not be between ${t.format()} and ${n.format()}`);case "dayIn":if(!Array.isArray(e.value))throw new Error("dayIn operator requires an array of day names");let i=r.format("dddd").toLowerCase(),h=e.value.map(c=>c.toLowerCase());return h.includes(i)||l(`must be on ${h.join(" or ")}`);case "dayNotIn":if(!Array.isArray(e.value))throw new Error("dayNotIn operator requires an array of day names");let x=r.format("dddd").toLowerCase(),g=e.value.map(c=>c.toLowerCase());return !g.includes(x)||l(`must not be on ${g.join(" or ")}`);default:throw new Error("Unknown date operator")}},j=(e,o,u,a,r)=>{if(["between","notBetween"].includes(e.dateOperator)){if(!Array.isArray(e.value)||e.value.length!==2)throw new Error(`${e.dateOperator} operator requires an array of two dates`);let t=p(e.value[0],r),n=p(e.value[1],r);if(!t.isValid())throw new Error(`Invalid start date: ${e.value[0]}`);if(!n.isValid())throw new Error(`Invalid end date: ${e.value[1]}`);return [t,n]}if(["before","after","onOrBefore","onOrAfter"].includes(e.dateOperator)){let t;if(e.value!==void 0)t=e.value;else if(e.path)e.path.startsWith("$.")?t=get(o,e.path.substring(2)):t=get(u,e.path);else throw new Error("No value or path specified for date comparison");let n=p(t,r);if(!n.isValid())throw new Error(`Invalid comparison date: ${t}`);return [n,void 0]}return [m(),void 0]},p=(e,o)=>{let u=String(e);if(u.includes("Z")||u.includes("T")&&(u.includes("+")||u.match(/T.*-\d{2}:/)))return m(e);let r=String(o),l=0;if(r.includes("+")||r.includes("T")&&r.match(/T.*-\d{2}:/)){let t=r.match(/([+-])(\d{2}):(\d{2})/);t&&(l=(t[1]==="+"?1:-1)*(parseInt(t[2])*60+parseInt(t[3])));}else r.includes("Z")||(l=0);return u.match(/^\d{4}-\d{2}-\d{2}$/)?m(e+"T00:00:00").subtract(l,"minute"):m(e).subtract(l,"minute")};var T=(e,o,u)=>{let a=get(o,e.field),l=!["isEmpty","notEmpty","exists","notExists"].includes(e.operator),s=l?C(e,o,u):void 0,t=n=>e.error||`${e.field} ${n}${l?" "+JSON.stringify(s):""}`;switch(e.operator){case "equal":return a===s||t("must equal");case "notEqual":return a!==s||t("must not equal");case "lessThan":return a<s||t("must be less than");case "lessThanEqual":return a<=s||t("must be less than or equal to");case "greaterThan":return a>s||t("must be greater than");case "greaterThanEqual":return a>=s||t("must be greater than or equal to");case "in":return s?.includes(a)||t("must be one of");case "notIn":return !s?.includes(a)||t("must not be one of");case "contains":return a?.includes(s)||t("must contain");case "notContains":return !a?.includes(s)||t("must not contain");case "match":return !!a?.match(s)||t("must match pattern");case "notMatch":return !a?.match(s)||t("must not match pattern");case "between":if(!Array.isArray(s)||s.length!==2)throw new Error("between operator requires an array of two values");return a>=s[0]&&a<=s[1]||t("must be between");case "notBetween":if(!Array.isArray(s)||s.length!==2)throw new Error("notBetween operator requires an array of two values");return a<s[0]||a>s[1]||t("must not be between");case "isEmpty":return isEmpty(a)||t("must be empty");case "notEmpty":return !isEmpty(a)||t("must not be empty");case "exists":return a!==void 0||t("must exist");case "notExists":return a===void 0||t("must not exist");case "startsWith":return a?.startsWith?.(s)||t("must start with");case "endsWith":return a?.endsWith?.(s)||t("must end with");default:throw new Error("Unknown operator")}},C=(e,o,u)=>{if(e.value!==void 0)return e.value;if(e.path)return e.path.startsWith("$.")?get(o,e.path.substring(2)):get(u,e.path);throw new Error("No value or path specified")};var y=(e,o,u=o)=>typeof e=="boolean"?e:"all"in e?W(e.all,o,u,e.error):"any"in e?M(e.any,o,u,e.error):"arrayOperator"in e?N(e,o,u):"dateOperator"in e?q(e,o,u):"field"in e?T(e,o,u):"if"in e?L(e,o,u):false,W=(e,o,u,a)=>{let r=[];for(let l of e){let s=y(l,o,u);s!==true&&(typeof s=="string"?r.push(s):r.push("false"));}return r.length?a||(r.length===1?r[0]:`All conditions must pass: ${r.join(" AND ")}`):true},M=(e,o,u,a)=>{let r=[];for(let l of e){let s=y(l,o,u);if(typeof s!="string")return true;r.push(s);}return a||(r.length===1?r[0]:`At least one condition must pass: ${r.join(" OR ")}`)},L=(e,o,u)=>y(e.if,o,u)===true?y(e.then,o,u):e.else?y(e.else,o,u):true,N=(e,o,u)=>{let a=get(u,e.field);if(!Array.isArray(a))throw new Error(`${e.field} must be an array`);let r=i=>e.error||`${e.field} ${i}`,l=["all","any","none","atLeast","atMost","exactly"],s=["atLeast","atMost","exactly"];if(l.includes(e.arrayOperator)&&!e.condition)throw new Error(`${e.arrayOperator} requires a condition to check against array elements`);if(s.includes(e.arrayOperator)&&e.count===void 0)throw new Error(`${e.arrayOperator} requires a count`);let t=0,n=0;if(l.includes(e.arrayOperator)){if(!some(a,isObject))throw new Error(`${e.field} contains only primitive values. Use 'in' or 'contains' operators instead of array operators for primitive arrays`);let i=a.map(h=>y(e.condition,h,u));t=i.filter(h=>h===true).length,n=i.filter(h=>typeof h=="string").length;}switch(e.arrayOperator){case "empty":return !a.length||r("must be empty");case "notEmpty":return !!a.length||r("must not be empty");case "all":return t===a.length||r(`all elements must match (${n} failed)`);case "any":return !!t||r("at least one element must match");case "none":return !t||r(`no elements should match (${t} matched)`);case "atLeast":return t>=e.count||r(`at least ${e.count} elements must match (${t} matched)`);case "atMost":return t<=e.count||r(`at most ${e.count} elements must match (${t} matched)`);case "exactly":return t===e.count||r(`exactly ${e.count} elements must match (${t} matched)`);default:throw new Error("Unknown array operator")}};export{E as ArrayOperator,$ as DateOperator,b as Operator,y as check};//# sourceMappingURL=index.js.map
1
+ import {get,isEmpty,some,isObject}from'lodash';import m from'dayjs';import A from'dayjs/plugin/utc';import B from'dayjs/plugin/timezone';import D from'dayjs/plugin/isSameOrBefore';import I from'dayjs/plugin/isSameOrAfter';var b=(f=>(f.equals="equals",f.notEquals="notEquals",f.lessThan="lessThan",f.lessThanEquals="lessThanEquals",f.greaterThan="greaterThan",f.greaterThanEquals="greaterThanEquals",f.contains="contains",f.notContains="notContains",f.in="in",f.notIn="notIn",f.matches="matches",f.notMatches="notMatches",f.between="between",f.notBetween="notBetween",f.isEmpty="isEmpty",f.notEmpty="notEmpty",f.exists="exists",f.notExists="notExists",f.startsWith="startsWith",f.endsWith="endsWith",f))(b||{}),E=(n=>(n.all="all",n.any="any",n.none="none",n.atLeast="atLeast",n.atMost="atMost",n.exactly="exactly",n.empty="empty",n.notEmpty="notEmpty",n))(E||{}),$=(n=>(n.before="before",n.after="after",n.onOrBefore="onOrBefore",n.onOrAfter="onOrAfter",n.between="between",n.notBetween="notBetween",n.dayIn="dayIn",n.dayNotIn="dayNotIn",n))($||{});m.extend(A);m.extend(B);m.extend(D);m.extend(I);var q=(e,o,u)=>{let s=get(o,e.field);if(!s)throw new Error(`${e.field} is null or undefined`);let r=m(s);if(!r.isValid())throw new Error(`${e.field} is not a valid date: ${s}`);let l=i=>e.error||`${e.field} ${i}`,a=j(e,o,u,r,s),t=a[0],n=a[1];switch(e.dateOperator){case "before":return r.isBefore(t)||l(`must be before ${t.format()}`);case "after":return r.isAfter(t)||l(`must be after ${t.format()}`);case "onOrBefore":return r.isSameOrBefore(t)||l(`must be on or before ${t.format()}`);case "onOrAfter":return r.isSameOrAfter(t)||l(`must be on or after ${t.format()}`);case "between":return r.isSameOrAfter(t)&&r.isSameOrBefore(n)||l(`must be between ${t.format()} and ${n.format()}`);case "notBetween":return r.isBefore(t)||r.isAfter(n)||l(`must not be between ${t.format()} and ${n.format()}`);case "dayIn":if(!Array.isArray(e.value))throw new Error("dayIn operator requires an array of day names");let i=r.format("dddd").toLowerCase(),h=e.value.map(c=>c.toLowerCase());return h.includes(i)||l(`must be on ${h.join(" or ")}`);case "dayNotIn":if(!Array.isArray(e.value))throw new Error("dayNotIn operator requires an array of day names");let x=r.format("dddd").toLowerCase(),g=e.value.map(c=>c.toLowerCase());return !g.includes(x)||l(`must not be on ${g.join(" or ")}`);default:throw new Error("Unknown date operator")}},j=(e,o,u,s,r)=>{if(["between","notBetween"].includes(e.dateOperator)){if(!Array.isArray(e.value)||e.value.length!==2)throw new Error(`${e.dateOperator} operator requires an array of two dates`);let t=p(e.value[0],r),n=p(e.value[1],r);if(!t.isValid())throw new Error(`Invalid start date: ${e.value[0]}`);if(!n.isValid())throw new Error(`Invalid end date: ${e.value[1]}`);return [t,n]}if(["before","after","onOrBefore","onOrAfter"].includes(e.dateOperator)){let t;if(e.value!==void 0)t=e.value;else if(e.path)e.path.startsWith("$.")?t=get(o,e.path.substring(2)):t=get(u,e.path);else throw new Error("No value or path specified for date comparison");let n=p(t,r);if(!n.isValid())throw new Error(`Invalid comparison date: ${t}`);return [n,void 0]}return [m(),void 0]},p=(e,o)=>{let u=String(e);if(u.includes("Z")||u.includes("T")&&(u.includes("+")||u.match(/T.*-\d{2}:/)))return m(e);let r=String(o),l=0;if(r.includes("+")||r.includes("T")&&r.match(/T.*-\d{2}:/)){let t=r.match(/([+-])(\d{2}):(\d{2})/);t&&(l=(t[1]==="+"?1:-1)*(parseInt(t[2])*60+parseInt(t[3])));}else r.includes("Z")||(l=0);return u.match(/^\d{4}-\d{2}-\d{2}$/)?m(e+"T00:00:00").subtract(l,"minute"):m(e).subtract(l,"minute")};var T=(e,o,u)=>{let s=get(o,e.field),l=!["isEmpty","notEmpty","exists","notExists"].includes(e.operator),a=l?C(e,o,u):void 0,t=n=>e.error||`${e.field} ${n}${l?" "+JSON.stringify(a):""}`;switch(e.operator){case "equals":return s===a||t("must equal");case "notEquals":return s!==a||t("must not equal");case "lessThan":return s<a||t("must be less than");case "lessThanEquals":return s<=a||t("must be less than or equal to");case "greaterThan":return s>a||t("must be greater than");case "greaterThanEquals":return s>=a||t("must be greater than or equal to");case "in":return a?.includes(s)||t("must be one of");case "notIn":return !a?.includes(s)||t("must not be one of");case "contains":return s?.includes(a)||t("must contain");case "notContains":return !s?.includes(a)||t("must not contain");case "matches":return !!s?.match(a)||t("must match pattern");case "notMatches":return !s?.match(a)||t("must not match pattern");case "between":if(!Array.isArray(a)||a.length!==2)throw new Error("between operator requires an array of two values");return s>=a[0]&&s<=a[1]||t("must be between");case "notBetween":if(!Array.isArray(a)||a.length!==2)throw new Error("notBetween operator requires an array of two values");return s<a[0]||s>a[1]||t("must not be between");case "isEmpty":return isEmpty(s)||t("must be empty");case "notEmpty":return !isEmpty(s)||t("must not be empty");case "exists":return s!==void 0||t("must exist");case "notExists":return s===void 0||t("must not exist");case "startsWith":return s?.startsWith?.(a)||t("must start with");case "endsWith":return s?.endsWith?.(a)||t("must end with");default:throw new Error("Unknown operator")}},C=(e,o,u)=>{if(e.value!==void 0)return e.value;if(e.path)return e.path.startsWith("$.")?get(o,e.path.substring(2)):get(u,e.path);throw new Error("No value or path specified")};var y=(e,o,u=o)=>typeof e=="boolean"?e:"all"in e?W(e.all,o,u,e.error):"any"in e?M(e.any,o,u,e.error):"arrayOperator"in e?N(e,o,u):"dateOperator"in e?q(e,o,u):"field"in e?T(e,o,u):"if"in e?L(e,o,u):false,W=(e,o,u,s)=>{let r=[];for(let l of e){let a=y(l,o,u);a!==true&&(typeof a=="string"?r.push(a):r.push("false"));}return r.length?s||(r.length===1?r[0]:`All conditions must pass: ${r.join(" AND ")}`):true},M=(e,o,u,s)=>{let r=[];for(let l of e){let a=y(l,o,u);if(typeof a!="string")return true;r.push(a);}return s||(r.length===1?r[0]:`At least one condition must pass: ${r.join(" OR ")}`)},L=(e,o,u)=>y(e.if,o,u)===true?y(e.then,o,u):e.else?y(e.else,o,u):true,N=(e,o,u)=>{let s=get(u,e.field);if(!Array.isArray(s))throw new Error(`${e.field} must be an array`);let r=i=>e.error||`${e.field} ${i}`,l=["all","any","none","atLeast","atMost","exactly"],a=["atLeast","atMost","exactly"];if(l.includes(e.arrayOperator)&&!e.condition)throw new Error(`${e.arrayOperator} requires a condition to check against array elements`);if(a.includes(e.arrayOperator)&&e.count===void 0)throw new Error(`${e.arrayOperator} requires a count`);let t=0,n=0;if(l.includes(e.arrayOperator)){if(!some(s,isObject))throw new Error(`${e.field} contains only primitive values. Use 'in' or 'contains' operators instead of array operators for primitive arrays`);let i=s.map(h=>y(e.condition,h,u));t=i.filter(h=>h===true).length,n=i.filter(h=>typeof h=="string").length;}switch(e.arrayOperator){case "empty":return !s.length||r("must be empty");case "notEmpty":return !!s.length||r("must not be empty");case "all":return t===s.length||r(`all elements must match (${n} failed)`);case "any":return !!t||r("at least one element must match");case "none":return !t||r(`no elements should match (${t} matched)`);case "atLeast":return t>=e.count||r(`at least ${e.count} elements must match (${t} matched)`);case "atMost":return t<=e.count||r(`at most ${e.count} elements must match (${t} matched)`);case "exactly":return t===e.count||r(`exactly ${e.count} elements must match (${t} matched)`);default:throw new Error("Unknown array operator")}};export{E as ArrayOperator,$ as DateOperator,b as Operator,y as check};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/operator.ts","../src/date.ts","../src/field.ts","../src/check.ts"],"names":["Operator","ArrayOperator","DateOperator","dayjs","utc","timezone","isSameOrBefore","isSameOrAfter","checkDate","condition","data","context","fieldValue","get","fieldDate","getError","op","dates","parseCompareDates","compareDate","endDate","dayName","allowedDays","d","day","excludedDays","startDate","parseDateWithTimezone","value","date","valueStr","fieldStr","offset","match","checkField","needsValue","getValue","isEmpty","check","conditions","all","any","checkArray","checkIfThenElse","error","errors","result","arrayValue","defaultMsg","requiresCondition","requiresCount","matches","failures","some","isObject","results","item","r"],"mappings":"8NAAO,IAAKA,OACVA,CAAAA,CAAA,KAAA,CAAQ,QACRA,CAAAA,CAAA,QAAA,CAAW,WACXA,CAAAA,CAAA,QAAA,CAAW,UAAA,CACXA,CAAAA,CAAA,cAAgB,eAAA,CAChBA,CAAAA,CAAA,YAAc,aAAA,CACdA,CAAAA,CAAA,iBAAmB,kBAAA,CACnBA,CAAAA,CAAA,QAAA,CAAW,UAAA,CACXA,EAAA,WAAA,CAAc,aAAA,CACdA,EAAA,EAAA,CAAK,IAAA,CACLA,EAAA,KAAA,CAAQ,OAAA,CACRA,CAAAA,CAAA,KAAA,CAAQ,QACRA,CAAAA,CAAA,QAAA,CAAW,WACXA,CAAAA,CAAA,OAAA,CAAU,UACVA,CAAAA,CAAA,UAAA,CAAa,YAAA,CACbA,CAAAA,CAAA,QAAU,SAAA,CAC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SAAA,CAAW,CAAA,CAEtH,eACE,OAAOA,CAAAA,GAAY1C,EAAU,KAAA,EAAUM,CAAAA,CAAS,WAAWN,CAAAA,CAAU,KAAK,yBAAyB0C,CAAO,CAAA,SAAA,CAAW,EAEvH,QACE,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAC5C,CACF","file":"index.js","sourcesContent":["export enum Operator {\n equal = 'equal',\n notEqual = 'notEqual',\n lessThan = 'lessThan',\n lessThanEqual = 'lessThanEqual',\n greaterThan = 'greaterThan',\n greaterThanEqual = 'greaterThanEqual',\n contains = 'contains',\n notContains = 'notContains',\n in = 'in',\n notIn = 'notIn',\n match = 'match',\n notMatch = 'notMatch',\n between = 'between',\n notBetween = 'notBetween',\n isEmpty = 'isEmpty',\n notEmpty = 'notEmpty',\n exists = 'exists',\n notExists = 'notExists',\n startsWith = 'startsWith',\n endsWith = 'endsWith',\n}\n\nexport enum ArrayOperator {\n all = 'all',\n any = 'any',\n none = 'none',\n atLeast = 'atLeast',\n atMost = 'atMost',\n exactly = 'exactly',\n empty = 'empty',\n notEmpty = 'notEmpty',\n}\n\nexport enum DateOperator {\n before = 'before',\n after = 'after',\n onOrBefore = 'onOrBefore',\n onOrAfter = 'onOrAfter',\n between = 'between',\n notBetween = 'notBetween',\n dayIn = 'dayIn', // e.g., ['monday', 'tuesday', 'friday']\n dayNotIn = 'dayNotIn',\n}\n","import { get } from 'lodash';\nimport dayjs from 'dayjs';\nimport utc from 'dayjs/plugin/utc';\nimport timezone from 'dayjs/plugin/timezone';\nimport isSameOrBefore from 'dayjs/plugin/isSameOrBefore';\nimport isSameOrAfter from 'dayjs/plugin/isSameOrAfter';\nimport type { DateRule } from './types';\nimport { DateOperator } from './operator';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\ndayjs.extend(isSameOrBefore);\ndayjs.extend(isSameOrAfter);\n\nexport const checkDate = (condition: DateRule, data: any, context: any): boolean | string => {\n const fieldValue = get(data, condition.field);\n \n if (!fieldValue) throw new Error(`${condition.field} is null or undefined`);\n \n const fieldDate = dayjs(fieldValue);\n \n if (!fieldDate.isValid()) throw new Error(`${condition.field} is not a valid date: ${fieldValue}`);\n \n const getError = (op: string) => condition.error || `${condition.field} ${op}`;\n \n // Parse comparison dates with timezone context - pass the original string to preserve offset info\n const dates = parseCompareDates(condition, data, context, fieldDate, fieldValue);\n const compareDate = dates[0];\n const endDate = dates[1];\n \n switch (condition.dateOperator) {\n case DateOperator.before:\n return fieldDate.isBefore(compareDate) || getError(`must be before ${compareDate.format()}`);\n \n case DateOperator.after:\n return fieldDate.isAfter(compareDate) || getError(`must be after ${compareDate.format()}`);\n \n case DateOperator.onOrBefore:\n return fieldDate.isSameOrBefore(compareDate) || getError(`must be on or before ${compareDate.format()}`);\n \n case DateOperator.onOrAfter:\n return fieldDate.isSameOrAfter(compareDate) || getError(`must be on or after ${compareDate.format()}`);\n \n case DateOperator.between:\n return (fieldDate.isSameOrAfter(compareDate) && fieldDate.isSameOrBefore(endDate!)) || \n getError(`must be between ${compareDate.format()} and ${endDate!.format()}`);\n \n case DateOperator.notBetween:\n return (fieldDate.isBefore(compareDate) || fieldDate.isAfter(endDate!)) || \n getError(`must not be between ${compareDate.format()} and ${endDate!.format()}`);\n \n case DateOperator.dayIn:\n if (!Array.isArray(condition.value)) throw new Error('dayIn operator requires an array of day names');\n const dayName = fieldDate.format('dddd').toLowerCase();\n const allowedDays = condition.value.map(d => d.toLowerCase());\n return allowedDays.includes(dayName) || getError(`must be on ${allowedDays.join(' or ')}`);\n \n case DateOperator.dayNotIn:\n if (!Array.isArray(condition.value)) throw new Error('dayNotIn operator requires an array of day names');\n const day = fieldDate.format('dddd').toLowerCase();\n const excludedDays = condition.value.map(d => d.toLowerCase());\n return !excludedDays.includes(day) || getError(`must not be on ${excludedDays.join(' or ')}`);\n \n default:\n throw new Error('Unknown date operator');\n }\n}\n\nconst parseCompareDates = (condition: DateRule, data: any, context: any, fieldDate: dayjs.Dayjs, fieldValue: string): [dayjs.Dayjs, dayjs.Dayjs | undefined] => {\n const requiresTwoDates = [DateOperator.between, DateOperator.notBetween];\n \n if (requiresTwoDates.includes(condition.dateOperator)) {\n if (!Array.isArray(condition.value) || condition.value.length !== 2) \n throw new Error(`${condition.dateOperator} operator requires an array of two dates`);\n const startDate = parseDateWithTimezone(condition.value[0], fieldValue);\n const endDate = parseDateWithTimezone(condition.value[1], fieldValue);\n if (!startDate.isValid()) throw new Error(`Invalid start date: ${condition.value[0]}`);\n if (!endDate.isValid()) throw new Error(`Invalid end date: ${condition.value[1]}`);\n return [startDate, endDate];\n }\n \n const requiresOneDate = [\n DateOperator.before,\n DateOperator.after,\n DateOperator.onOrBefore,\n DateOperator.onOrAfter\n ];\n \n if (requiresOneDate.includes(condition.dateOperator)) {\n let value;\n if (condition.value !== undefined) {\n value = condition.value;\n } else if (condition.path) {\n // Support $.path for current element\n if (condition.path.startsWith('$.')) {\n value = get(data, condition.path.substring(2));\n } else {\n value = get(context, condition.path);\n }\n } else {\n throw new Error('No value or path specified for date comparison');\n }\n const date = parseDateWithTimezone(value, fieldValue);\n if (!date.isValid()) throw new Error(`Invalid comparison date: ${value}`);\n return [date, undefined];\n }\n \n return [dayjs(), undefined]; // Won't be used for dayIn/dayNotIn\n}\n\nconst parseDateWithTimezone = (value: any, fieldValue: string): dayjs.Dayjs => {\n const valueStr = String(value);\n \n // Check if value has explicit timezone information\n const hasTimezone = valueStr.includes('Z') || \n (valueStr.includes('T') && (valueStr.includes('+') || valueStr.match(/T.*-\\d{2}:/)));\n \n if (hasTimezone) return dayjs(value);\n \n // No timezone info in value - interpret in field's timezone\n // Extract offset from field value\n const fieldStr = String(fieldValue);\n let offset = 0;\n \n if (fieldStr.includes('+') || (fieldStr.includes('T') && fieldStr.match(/T.*-\\d{2}:/))) {\n // Field has explicit offset like +11:00 or -08:00\n const match = fieldStr.match(/([+-])(\\d{2}):(\\d{2})/);\n if (match) {\n const sign = match[1] === '+' ? 1 : -1;\n offset = sign * (parseInt(match[2]) * 60 + parseInt(match[3]));\n }\n } else if (!fieldStr.includes('Z')) {\n // Field has no timezone, assume local time (offset 0)\n offset = 0;\n }\n // If field has Z, it's UTC (offset 0)\n \n // Create a date representing the same local time as the field's timezone\n if (valueStr.match(/^\\d{4}-\\d{2}-\\d{2}$/)) {\n // For date-only, we want midnight in the field's timezone\n const localMidnight = dayjs(value + 'T00:00:00');\n return localMidnight.subtract(offset, 'minute');\n }\n \n // For datetime without timezone, interpret as local time in field's timezone\n const localTime = dayjs(value);\n return localTime.subtract(offset, 'minute');\n}","import { get, isEmpty } from 'lodash';\nimport type { Rule } from './types';\nimport { Operator } from './operator';\n\nexport const checkField = (condition: Rule, data: any, context: any): boolean | string => {\n // Use data for field access (current element) but context remains available for path references\n const fieldValue = get(data, condition.field);\n \n // Operators that don't need a value\n const noValueOps = [Operator.isEmpty, Operator.notEmpty, Operator.exists, Operator.notExists];\n const needsValue = !noValueOps.includes(condition.operator);\n const value = needsValue ? getValue(condition, data, context) : undefined;\n \n const getError = (op: string) => condition.error || `${condition.field} ${op}${needsValue ? ' ' + JSON.stringify(value) : ''}`;\n\n switch (condition.operator) {\n case Operator.equal:\n return fieldValue === value || getError(`must equal`);\n case Operator.notEqual:\n return fieldValue !== value || getError(`must not equal`);\n case Operator.lessThan:\n return fieldValue < value || getError(`must be less than`);\n case Operator.lessThanEqual:\n return fieldValue <= value || getError(`must be less than or equal to`);\n case Operator.greaterThan:\n return fieldValue > value || getError(`must be greater than`);\n case Operator.greaterThanEqual:\n return fieldValue >= value || getError(`must be greater than or equal to`);\n case Operator.in:\n return value?.includes(fieldValue) || getError(`must be one of`);\n case Operator.notIn:\n return !value?.includes(fieldValue) || getError(`must not be one of`);\n case Operator.contains:\n return fieldValue?.includes(value) || getError(`must contain`);\n case Operator.notContains:\n return !fieldValue?.includes(value) || getError(`must not contain`);\n case Operator.match:\n return !!fieldValue?.match(value) || getError(`must match pattern`);\n case Operator.notMatch:\n return !fieldValue?.match(value) || getError(`must not match pattern`);\n case Operator.between:\n if (!Array.isArray(value) || value.length !== 2) \n throw new Error('between operator requires an array of two values');\n return (fieldValue >= value[0] && fieldValue <= value[1]) || getError(`must be between`);\n case Operator.notBetween:\n if (!Array.isArray(value) || value.length !== 2) \n throw new Error('notBetween operator requires an array of two values');\n return (fieldValue < value[0] || fieldValue > value[1]) || getError(`must not be between`);\n case Operator.isEmpty:\n return isEmpty(fieldValue) || getError(`must be empty`);\n case Operator.notEmpty:\n return !isEmpty(fieldValue) || getError(`must not be empty`);\n case Operator.exists:\n return fieldValue !== undefined || getError(`must exist`);\n case Operator.notExists:\n return fieldValue === undefined || getError(`must not exist`);\n case Operator.startsWith:\n return fieldValue?.startsWith?.(value) || getError(`must start with`);\n case Operator.endsWith:\n return fieldValue?.endsWith?.(value) || getError(`must end with`);\n default:\n throw new Error('Unknown operator');\n }\n};\n\nconst getValue = (condition: Rule, data: any, context: any): any => {\n if (condition.value !== undefined) return condition.value;\n if (condition.path) {\n // Special case: if path starts with \"$.\" use data (current element)\n if (condition.path.startsWith('$.')) {\n return get(data, condition.path.substring(2));\n }\n // Otherwise use context (root data)\n return get(context, condition.path);\n }\n throw new Error('No value or path specified');\n};","import { get, some, isObject } from 'lodash';\nimport type { Condition, ArrayRule } from './types';\nimport { ArrayOperator } from './operator';\nimport { checkDate } from './date';\nimport { checkField } from './field';\n\nexport const check = (conditions: Condition, data: any, context: any = data): boolean | string => {\n if (typeof conditions === 'boolean') return conditions;\n if ('all' in conditions) return all(conditions.all, data, context, conditions.error);\n if ('any' in conditions) return any(conditions.any, data, context, conditions.error);\n if ('arrayOperator' in conditions) return checkArray(conditions, data, context);\n if ('dateOperator' in conditions) return checkDate(conditions, data, context);\n if ('field' in conditions) return checkField(conditions, data, context);\n if ('if' in conditions) return checkIfThenElse(conditions, data, context);\n\n return false;\n}\n\nconst all = (conditions: Condition[], data: any, context: any, error?: string): boolean | string => {\n const errors: string[] = [];\n \n for (const condition of conditions) {\n const result = check(condition, data, context);\n if (result !== true) {\n // Handle both string errors and false boolean results\n if (typeof result === 'string') {\n errors.push(result);\n } else {\n // For boolean false, include it in the error message\n errors.push('false');\n }\n }\n }\n\n if (!errors.length) return true;\n if (error) return error;\n if (errors.length === 1) return errors[0];\n return `All conditions must pass: ${errors.join(' AND ')}`;\n}\n\nconst any = (conditions: Condition[], data: any, context: any, error?: string): boolean | string => {\n const errors: string[] = [];\n\n for (const condition of conditions) {\n const result = check(condition, data, context);\n if (typeof result !== 'string') return true;\n errors.push(result);\n }\n\n if (error) return error;\n if (errors.length === 1) return errors[0];\n return `At least one condition must pass: ${errors.join(' OR ')}`;\n}\n\nconst checkIfThenElse = (condition: any, data: any, context: any): boolean | string => {\n const ifResult = check(condition.if, data, context);\n \n if (ifResult === true) return check(condition.then, data, context);\n return condition.else ? check(condition.else, data, context) : true;\n}\n\nconst checkArray = (condition: ArrayRule, data: any, context: any): boolean | string => {\n const arrayValue = get(context, condition.field);\n \n if (!Array.isArray(arrayValue)) throw new Error(`${condition.field} must be an array`);\n \n const getError = (defaultMsg: string) => condition.error || `${condition.field} ${defaultMsg}`;\n \n // Operators that require a condition\n const requiresCondition = [\n ArrayOperator.all, \n ArrayOperator.any, \n ArrayOperator.none,\n ArrayOperator.atLeast,\n ArrayOperator.atMost,\n ArrayOperator.exactly\n ];\n \n // Operators that require a count\n const requiresCount = [\n ArrayOperator.atLeast,\n ArrayOperator.atMost,\n ArrayOperator.exactly\n ];\n \n if (requiresCondition.includes(condition.arrayOperator) && !condition.condition) \n throw new Error(`${condition.arrayOperator} requires a condition to check against array elements`);\n \n if (requiresCount.includes(condition.arrayOperator) && condition.count === undefined) \n throw new Error(`${condition.arrayOperator} requires a count`);\n \n // For operators that check elements, compute matches\n let matches = 0;\n let failures = 0;\n \n if (requiresCondition.includes(condition.arrayOperator)) {\n // Check if array contains any objects\n if (!some(arrayValue, isObject)) \n throw new Error(`${condition.field} contains only primitive values. Use 'in' or 'contains' operators instead of array operators for primitive arrays`);\n \n // Pass item as data (for relative field access) but keep original context (for path access)\n const results = arrayValue.map(item => check(condition.condition!, item, context));\n matches = results.filter(r => r === true).length;\n failures = results.filter(r => typeof r === 'string').length;\n }\n \n switch (condition.arrayOperator) {\n case ArrayOperator.empty:\n return !arrayValue.length || getError('must be empty');\n \n case ArrayOperator.notEmpty:\n return !!arrayValue.length || getError('must not be empty');\n \n case ArrayOperator.all:\n return matches === arrayValue.length || getError(`all elements must match (${failures} failed)`);\n \n case ArrayOperator.any:\n return !!matches || getError('at least one element must match');\n \n case ArrayOperator.none:\n return !matches || getError(`no elements should match (${matches} matched)`);\n \n case ArrayOperator.atLeast:\n return matches >= condition.count! || getError(`at least ${condition.count} elements must match (${matches} matched)`);\n \n case ArrayOperator.atMost:\n return matches <= condition.count! || getError(`at most ${condition.count} elements must match (${matches} matched)`);\n \n case ArrayOperator.exactly:\n return matches === condition.count! || getError(`exactly ${condition.count} elements must match (${matches} matched)`);\n \n default:\n throw new Error('Unknown array operator');\n }\n}"]}
1
+ {"version":3,"sources":["../src/operator.ts","../src/date.ts","../src/field.ts","../src/check.ts"],"names":["Operator","ArrayOperator","DateOperator","dayjs","utc","timezone","isSameOrBefore","isSameOrAfter","checkDate","condition","data","context","fieldValue","get","fieldDate","getError","op","dates","parseCompareDates","compareDate","endDate","dayName","allowedDays","d","day","excludedDays","startDate","parseDateWithTimezone","value","date","valueStr","fieldStr","offset","match","checkField","needsValue","getValue","isEmpty","check","conditions","all","any","checkArray","checkIfThenElse","error","errors","result","arrayValue","defaultMsg","requiresCondition","requiresCount","matches","failures","some","isObject","results","item","r"],"mappings":"8NAAO,IAAKA,OACVA,CAAAA,CAAA,MAAA,CAAS,SACTA,CAAAA,CAAA,SAAA,CAAY,YACZA,CAAAA,CAAA,QAAA,CAAW,UAAA,CACXA,CAAAA,CAAA,eAAiB,gBAAA,CACjBA,CAAAA,CAAA,YAAc,aAAA,CACdA,CAAAA,CAAA,kBAAoB,mBAAA,CACpBA,CAAAA,CAAA,QAAA,CAAW,UAAA,CACXA,EAAA,W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,CAAAA,CAAS,CAAA,SAAA,EAAYN,EAAU,KAAK,CAAA,sBAAA,EAAyB0C,CAAO,CAAA,SAAA,CAAW,CAAA,CAEvH,KAAA,QAAA,CACE,OAAOA,GAAW1C,CAAAA,CAAU,KAAA,EAAUM,EAAS,CAAA,QAAA,EAAWN,CAAAA,CAAU,KAAK,CAAA,sBAAA,EAAyB0C,CAAO,CAAA,SAAA,CAAW,CAAA,CAEtH,eACE,OAAOA,CAAAA,GAAY1C,EAAU,KAAA,EAAUM,CAAAA,CAAS,WAAWN,CAAAA,CAAU,KAAK,yBAAyB0C,CAAO,CAAA,SAAA,CAAW,EAEvH,QACE,MAAM,IAAI,KAAA,CAAM,wBAAwB,CAC5C,CACF","file":"index.js","sourcesContent":["export enum Operator {\n equals = 'equals',\n notEquals = 'notEquals',\n lessThan = 'lessThan',\n lessThanEquals = 'lessThanEquals',\n greaterThan = 'greaterThan',\n greaterThanEquals = 'greaterThanEquals',\n contains = 'contains',\n notContains = 'notContains',\n in = 'in',\n notIn = 'notIn',\n matches = 'matches',\n notMatches = 'notMatches',\n between = 'between',\n notBetween = 'notBetween',\n isEmpty = 'isEmpty',\n notEmpty = 'notEmpty',\n exists = 'exists',\n notExists = 'notExists',\n startsWith = 'startsWith',\n endsWith = 'endsWith',\n}\n\nexport enum ArrayOperator {\n all = 'all',\n any = 'any',\n none = 'none',\n atLeast = 'atLeast',\n atMost = 'atMost',\n exactly = 'exactly',\n empty = 'empty',\n notEmpty = 'notEmpty',\n}\n\nexport enum DateOperator {\n before = 'before',\n after = 'after',\n onOrBefore = 'onOrBefore',\n onOrAfter = 'onOrAfter',\n between = 'between',\n notBetween = 'notBetween',\n dayIn = 'dayIn', // e.g., ['monday', 'tuesday', 'friday']\n dayNotIn = 'dayNotIn',\n}\n","import { get } from 'lodash';\nimport dayjs from 'dayjs';\nimport utc from 'dayjs/plugin/utc';\nimport timezone from 'dayjs/plugin/timezone';\nimport isSameOrBefore from 'dayjs/plugin/isSameOrBefore';\nimport isSameOrAfter from 'dayjs/plugin/isSameOrAfter';\nimport type { DateRule } from './types';\nimport { DateOperator } from './operator';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\ndayjs.extend(isSameOrBefore);\ndayjs.extend(isSameOrAfter);\n\nexport const checkDate = (condition: DateRule, data: any, context: any): boolean | string => {\n const fieldValue = get(data, condition.field);\n \n if (!fieldValue) throw new Error(`${condition.field} is null or undefined`);\n \n const fieldDate = dayjs(fieldValue);\n \n if (!fieldDate.isValid()) throw new Error(`${condition.field} is not a valid date: ${fieldValue}`);\n \n const getError = (op: string) => condition.error || `${condition.field} ${op}`;\n \n // Parse comparison dates with timezone context - pass the original string to preserve offset info\n const dates = parseCompareDates(condition, data, context, fieldDate, fieldValue);\n const compareDate = dates[0];\n const endDate = dates[1];\n \n switch (condition.dateOperator) {\n case DateOperator.before:\n return fieldDate.isBefore(compareDate) || getError(`must be before ${compareDate.format()}`);\n \n case DateOperator.after:\n return fieldDate.isAfter(compareDate) || getError(`must be after ${compareDate.format()}`);\n \n case DateOperator.onOrBefore:\n return fieldDate.isSameOrBefore(compareDate) || getError(`must be on or before ${compareDate.format()}`);\n \n case DateOperator.onOrAfter:\n return fieldDate.isSameOrAfter(compareDate) || getError(`must be on or after ${compareDate.format()}`);\n \n case DateOperator.between:\n return (fieldDate.isSameOrAfter(compareDate) && fieldDate.isSameOrBefore(endDate!)) || \n getError(`must be between ${compareDate.format()} and ${endDate!.format()}`);\n \n case DateOperator.notBetween:\n return (fieldDate.isBefore(compareDate) || fieldDate.isAfter(endDate!)) || \n getError(`must not be between ${compareDate.format()} and ${endDate!.format()}`);\n \n case DateOperator.dayIn:\n if (!Array.isArray(condition.value)) throw new Error('dayIn operator requires an array of day names');\n const dayName = fieldDate.format('dddd').toLowerCase();\n const allowedDays = condition.value.map(d => d.toLowerCase());\n return allowedDays.includes(dayName) || getError(`must be on ${allowedDays.join(' or ')}`);\n \n case DateOperator.dayNotIn:\n if (!Array.isArray(condition.value)) throw new Error('dayNotIn operator requires an array of day names');\n const day = fieldDate.format('dddd').toLowerCase();\n const excludedDays = condition.value.map(d => d.toLowerCase());\n return !excludedDays.includes(day) || getError(`must not be on ${excludedDays.join(' or ')}`);\n \n default:\n throw new Error('Unknown date operator');\n }\n}\n\nconst parseCompareDates = (condition: DateRule, data: any, context: any, fieldDate: dayjs.Dayjs, fieldValue: string): [dayjs.Dayjs, dayjs.Dayjs | undefined] => {\n const requiresTwoDates = [DateOperator.between, DateOperator.notBetween];\n \n if (requiresTwoDates.includes(condition.dateOperator)) {\n if (!Array.isArray(condition.value) || condition.value.length !== 2) \n throw new Error(`${condition.dateOperator} operator requires an array of two dates`);\n const startDate = parseDateWithTimezone(condition.value[0], fieldValue);\n const endDate = parseDateWithTimezone(condition.value[1], fieldValue);\n if (!startDate.isValid()) throw new Error(`Invalid start date: ${condition.value[0]}`);\n if (!endDate.isValid()) throw new Error(`Invalid end date: ${condition.value[1]}`);\n return [startDate, endDate];\n }\n \n const requiresOneDate = [\n DateOperator.before,\n DateOperator.after,\n DateOperator.onOrBefore,\n DateOperator.onOrAfter\n ];\n \n if (requiresOneDate.includes(condition.dateOperator)) {\n let value;\n if (condition.value !== undefined) {\n value = condition.value;\n } else if (condition.path) {\n // Support $.path for current element\n if (condition.path.startsWith('$.')) {\n value = get(data, condition.path.substring(2));\n } else {\n value = get(context, condition.path);\n }\n } else {\n throw new Error('No value or path specified for date comparison');\n }\n const date = parseDateWithTimezone(value, fieldValue);\n if (!date.isValid()) throw new Error(`Invalid comparison date: ${value}`);\n return [date, undefined];\n }\n \n return [dayjs(), undefined]; // Won't be used for dayIn/dayNotIn\n}\n\nconst parseDateWithTimezone = (value: any, fieldValue: string): dayjs.Dayjs => {\n const valueStr = String(value);\n \n // Check if value has explicit timezone information\n const hasTimezone = valueStr.includes('Z') || \n (valueStr.includes('T') && (valueStr.includes('+') || valueStr.match(/T.*-\\d{2}:/)));\n \n if (hasTimezone) return dayjs(value);\n \n // No timezone info in value - interpret in field's timezone\n // Extract offset from field value\n const fieldStr = String(fieldValue);\n let offset = 0;\n \n if (fieldStr.includes('+') || (fieldStr.includes('T') && fieldStr.match(/T.*-\\d{2}:/))) {\n // Field has explicit offset like +11:00 or -08:00\n const match = fieldStr.match(/([+-])(\\d{2}):(\\d{2})/);\n if (match) {\n const sign = match[1] === '+' ? 1 : -1;\n offset = sign * (parseInt(match[2]) * 60 + parseInt(match[3]));\n }\n } else if (!fieldStr.includes('Z')) {\n // Field has no timezone, assume local time (offset 0)\n offset = 0;\n }\n // If field has Z, it's UTC (offset 0)\n \n // Create a date representing the same local time as the field's timezone\n if (valueStr.match(/^\\d{4}-\\d{2}-\\d{2}$/)) {\n // For date-only, we want midnight in the field's timezone\n const localMidnight = dayjs(value + 'T00:00:00');\n return localMidnight.subtract(offset, 'minute');\n }\n \n // For datetime without timezone, interpret as local time in field's timezone\n const localTime = dayjs(value);\n return localTime.subtract(offset, 'minute');\n}","import { get, isEmpty } from 'lodash';\nimport type { Rule } from './types';\nimport { Operator } from './operator';\n\nexport const checkField = (condition: Rule, data: any, context: any): boolean | string => {\n // Use data for field access (current element) but context remains available for path references\n const fieldValue = get(data, condition.field);\n \n // Operators that don't need a value\n const noValueOps = [Operator.isEmpty, Operator.notEmpty, Operator.exists, Operator.notExists];\n const needsValue = !noValueOps.includes(condition.operator);\n const value = needsValue ? getValue(condition, data, context) : undefined;\n \n const getError = (op: string) => condition.error || `${condition.field} ${op}${needsValue ? ' ' + JSON.stringify(value) : ''}`;\n\n switch (condition.operator) {\n case Operator.equals:\n return fieldValue === value || getError(`must equal`);\n case Operator.notEquals:\n return fieldValue !== value || getError(`must not equal`);\n case Operator.lessThan:\n return fieldValue < value || getError(`must be less than`);\n case Operator.lessThanEquals:\n return fieldValue <= value || getError(`must be less than or equal to`);\n case Operator.greaterThan:\n return fieldValue > value || getError(`must be greater than`);\n case Operator.greaterThanEquals:\n return fieldValue >= value || getError(`must be greater than or equal to`);\n case Operator.in:\n return value?.includes(fieldValue) || getError(`must be one of`);\n case Operator.notIn:\n return !value?.includes(fieldValue) || getError(`must not be one of`);\n case Operator.contains:\n return fieldValue?.includes(value) || getError(`must contain`);\n case Operator.notContains:\n return !fieldValue?.includes(value) || getError(`must not contain`);\n case Operator.matches:\n return !!fieldValue?.match(value) || getError(`must match pattern`);\n case Operator.notMatches:\n return !fieldValue?.match(value) || getError(`must not match pattern`);\n case Operator.between:\n if (!Array.isArray(value) || value.length !== 2) \n throw new Error('between operator requires an array of two values');\n return (fieldValue >= value[0] && fieldValue <= value[1]) || getError(`must be between`);\n case Operator.notBetween:\n if (!Array.isArray(value) || value.length !== 2) \n throw new Error('notBetween operator requires an array of two values');\n return (fieldValue < value[0] || fieldValue > value[1]) || getError(`must not be between`);\n case Operator.isEmpty:\n return isEmpty(fieldValue) || getError(`must be empty`);\n case Operator.notEmpty:\n return !isEmpty(fieldValue) || getError(`must not be empty`);\n case Operator.exists:\n return fieldValue !== undefined || getError(`must exist`);\n case Operator.notExists:\n return fieldValue === undefined || getError(`must not exist`);\n case Operator.startsWith:\n return fieldValue?.startsWith?.(value) || getError(`must start with`);\n case Operator.endsWith:\n return fieldValue?.endsWith?.(value) || getError(`must end with`);\n default:\n throw new Error('Unknown operator');\n }\n};\n\nconst getValue = (condition: Rule, data: any, context: any): any => {\n if (condition.value !== undefined) return condition.value;\n if (condition.path) {\n // Special case: if path starts with \"$.\" use data (current element)\n if (condition.path.startsWith('$.')) {\n return get(data, condition.path.substring(2));\n }\n // Otherwise use context (root data)\n return get(context, condition.path);\n }\n throw new Error('No value or path specified');\n};","import { get, some, isObject } from 'lodash';\nimport type { Condition, ArrayRule } from './types';\nimport { ArrayOperator } from './operator';\nimport { checkDate } from './date';\nimport { checkField } from './field';\n\nexport const check = (conditions: Condition, data: any, context: any = data): boolean | string => {\n if (typeof conditions === 'boolean') return conditions;\n if ('all' in conditions) return all(conditions.all, data, context, conditions.error);\n if ('any' in conditions) return any(conditions.any, data, context, conditions.error);\n if ('arrayOperator' in conditions) return checkArray(conditions, data, context);\n if ('dateOperator' in conditions) return checkDate(conditions, data, context);\n if ('field' in conditions) return checkField(conditions, data, context);\n if ('if' in conditions) return checkIfThenElse(conditions, data, context);\n\n return false;\n}\n\nconst all = (conditions: Condition[], data: any, context: any, error?: string): boolean | string => {\n const errors: string[] = [];\n \n for (const condition of conditions) {\n const result = check(condition, data, context);\n if (result !== true) {\n // Handle both string errors and false boolean results\n if (typeof result === 'string') {\n errors.push(result);\n } else {\n // For boolean false, include it in the error message\n errors.push('false');\n }\n }\n }\n\n if (!errors.length) return true;\n if (error) return error;\n if (errors.length === 1) return errors[0];\n return `All conditions must pass: ${errors.join(' AND ')}`;\n}\n\nconst any = (conditions: Condition[], data: any, context: any, error?: string): boolean | string => {\n const errors: string[] = [];\n\n for (const condition of conditions) {\n const result = check(condition, data, context);\n if (typeof result !== 'string') return true;\n errors.push(result);\n }\n\n if (error) return error;\n if (errors.length === 1) return errors[0];\n return `At least one condition must pass: ${errors.join(' OR ')}`;\n}\n\nconst checkIfThenElse = (condition: any, data: any, context: any): boolean | string => {\n const ifResult = check(condition.if, data, context);\n \n if (ifResult === true) return check(condition.then, data, context);\n return condition.else ? check(condition.else, data, context) : true;\n}\n\nconst checkArray = (condition: ArrayRule, data: any, context: any): boolean | string => {\n const arrayValue = get(context, condition.field);\n \n if (!Array.isArray(arrayValue)) throw new Error(`${condition.field} must be an array`);\n \n const getError = (defaultMsg: string) => condition.error || `${condition.field} ${defaultMsg}`;\n \n // Operators that require a condition\n const requiresCondition = [\n ArrayOperator.all, \n ArrayOperator.any, \n ArrayOperator.none,\n ArrayOperator.atLeast,\n ArrayOperator.atMost,\n ArrayOperator.exactly\n ];\n \n // Operators that require a count\n const requiresCount = [\n ArrayOperator.atLeast,\n ArrayOperator.atMost,\n ArrayOperator.exactly\n ];\n \n if (requiresCondition.includes(condition.arrayOperator) && !condition.condition) \n throw new Error(`${condition.arrayOperator} requires a condition to check against array elements`);\n \n if (requiresCount.includes(condition.arrayOperator) && condition.count === undefined) \n throw new Error(`${condition.arrayOperator} requires a count`);\n \n // For operators that check elements, compute matches\n let matches = 0;\n let failures = 0;\n \n if (requiresCondition.includes(condition.arrayOperator)) {\n // Check if array contains any objects\n if (!some(arrayValue, isObject)) \n throw new Error(`${condition.field} contains only primitive values. Use 'in' or 'contains' operators instead of array operators for primitive arrays`);\n \n // Pass item as data (for relative field access) but keep original context (for path access)\n const results = arrayValue.map(item => check(condition.condition!, item, context));\n matches = results.filter(r => r === true).length;\n failures = results.filter(r => typeof r === 'string').length;\n }\n \n switch (condition.arrayOperator) {\n case ArrayOperator.empty:\n return !arrayValue.length || getError('must be empty');\n \n case ArrayOperator.notEmpty:\n return !!arrayValue.length || getError('must not be empty');\n \n case ArrayOperator.all:\n return matches === arrayValue.length || getError(`all elements must match (${failures} failed)`);\n \n case ArrayOperator.any:\n return !!matches || getError('at least one element must match');\n \n case ArrayOperator.none:\n return !matches || getError(`no elements should match (${matches} matched)`);\n \n case ArrayOperator.atLeast:\n return matches >= condition.count! || getError(`at least ${condition.count} elements must match (${matches} matched)`);\n \n case ArrayOperator.atMost:\n return matches <= condition.count! || getError(`at most ${condition.count} elements must match (${matches} matched)`);\n \n case ArrayOperator.exactly:\n return matches === condition.count! || getError(`exactly ${condition.count} elements must match (${matches} matched)`);\n \n default:\n throw new Error('Unknown array operator');\n }\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inixiative/json-rules",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "TypeScript-first JSON rules engine with intuitive syntax and detailed error messages",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -56,4 +56,4 @@
56
56
  "require": "./dist/index.cjs"
57
57
  }
58
58
  }
59
- }
59
+ }