{"version":3,"file":"operators.cjs","names":[],"sources":["../../src/utils/operators.ts"],"sourcesContent":["type Entries<T> = {\n  [K in keyof T]-?: Exclude<T[K], null | undefined> extends never ? never : [K, T[K]]\n}[keyof T][]\n\ntype Nullable<T> = T | null | undefined\n\nexport function getEntries<T extends object>(obj: T) {\n  return Object.entries(obj) as Entries<T>\n}\n\nexport function getOperatorMap<T>(type: T) {\n  // Generic operators\n  const isEq = (value: Nullable<T>, input: T) => value === input\n  const isIn = (value: Nullable<T>, input: T[]) => !!(value && input.includes(value))\n  const isNull = (value: Nullable<T>, input: boolean) =>\n    (input && value === null) || (!input && value !== null)\n\n  // String operators\n  const isLike = (value: Nullable<string>, input: string) => {\n    if (!value) return false\n\n    const regexString = [\n      input.replace(/(^%)?([^%]+)(%$)?/, '$2'),\n      input.endsWith('%') ? '' : '$',\n    ].join('')\n\n    return new RegExp(regexString, 'i').test(value)\n  }\n\n  let operatorMap = (<T extends object>(map: T) =>\n    map as T & { like?: typeof isLike; notLike?: typeof isLike })({\n    eq: isEq,\n    ne: (...args: Parameters<typeof isEq>) => !isEq(...args),\n    in: isIn,\n    notIn: (...args: Parameters<typeof isIn>) => !isIn(...args),\n    null: isNull,\n  })\n\n  if (typeof type === 'string') {\n    operatorMap = {\n      ...operatorMap,\n      like: isLike,\n      notLike: (...args: Parameters<typeof isLike>) => !isLike(...args),\n    }\n  }\n  return operatorMap\n}\n"],"mappings":"mEAMA,SAAgB,EAA6B,EAAQ,CACnD,OAAO,OAAO,QAAQ,EAAI,CAG5B,SAAgB,EAAkB,EAAS,CAEzC,IAAM,GAAQ,EAAoB,IAAa,IAAU,EACnD,GAAQ,EAAoB,IAAe,CAAC,EAAE,GAAS,EAAM,SAAS,EAAM,EAC5E,GAAU,EAAoB,IACjC,GAAS,IAAU,MAAU,CAAC,GAAS,IAAU,KAG9C,GAAU,EAAyB,IAAkB,CACzD,GAAI,CAAC,EAAO,MAAO,GAEnB,IAAM,EAAc,CAClB,EAAM,QAAQ,oBAAqB,KAAK,CACxC,EAAM,SAAS,IAAI,CAAG,GAAK,IAC5B,CAAC,KAAK,GAAG,CAEV,OAAO,IAAI,OAAO,EAAa,IAAI,CAAC,KAAK,EAAM,EAG7C,GAAkC,GACpC,GAA8D,CAC9D,GAAI,EACJ,IAAK,GAAG,IAAkC,CAAC,EAAK,GAAG,EAAK,CACxD,GAAI,EACJ,OAAQ,GAAG,IAAkC,CAAC,EAAK,GAAG,EAAK,CAC3D,KAAM,EACP,CAAC,CASF,OAPI,OAAO,GAAS,WAClB,EAAc,CACZ,GAAG,EACH,KAAM,EACN,SAAU,GAAG,IAAoC,CAAC,EAAO,GAAG,EAAK,CAClE,EAEI"}