@react-querybuilder/core 8.14.0 → 8.14.1
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/{basic-Dxm6jWFu.d.ts → basic-BXJVfD0P.d.ts} +68 -50
- package/dist/{basic-GFsWfi0Z.d.mts → basic-CNIjb6rI.d.mts} +68 -50
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +178 -127
- package/dist/cjs/react-querybuilder_core.cjs.development.js +299 -251
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +178 -127
- package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
- package/dist/{convertQuery-DAj92cbM.mjs → convertQuery-B5Qm_6ut.mjs} +30 -22
- package/dist/convertQuery-B5Qm_6ut.mjs.map +1 -0
- package/dist/convertQuery-DfZehtnd.js +94 -0
- package/dist/convertQuery-DfZehtnd.js.map +1 -0
- package/dist/{export-_wipiqJZ.d.mts → export-6x7MilFR.d.mts} +2 -3
- package/dist/{export-6VbkhCrf.d.ts → export-CpJOQuZv.d.ts} +2 -3
- package/dist/formatQuery.d.mts +4 -3
- package/dist/formatQuery.d.ts +4 -3
- package/dist/formatQuery.js +18 -50
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +17 -49
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-D8M7awTx.d.ts → import-B5Iq8XmL.d.ts} +2 -3
- package/dist/{import-DRmutNSr.d.mts → import-Bltb2mT4.d.mts} +2 -3
- package/dist/{isRuleGroup-Cjk1Q2mj.js → isRuleGroup-BCwaLzDj.js} +38 -40
- package/dist/isRuleGroup-BCwaLzDj.js.map +1 -0
- package/dist/{isRuleGroup-DztIOOKa.mjs → isRuleGroup-LzP0HCKh.mjs} +2 -4
- package/dist/isRuleGroup-LzP0HCKh.mjs.map +1 -0
- package/dist/parseCEL.d.mts +2 -2
- package/dist/parseCEL.d.ts +2 -2
- package/dist/parseCEL.js +9 -11
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +7 -10
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseJSONata.d.mts +2 -3
- package/dist/parseJSONata.d.ts +2 -3
- package/dist/parseJSONata.js +37 -5611
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +11 -13
- package/dist/parseJSONata.mjs.map +1 -1
- package/dist/parseJsonLogic.d.mts +3 -4
- package/dist/parseJsonLogic.d.ts +3 -4
- package/dist/parseJsonLogic.js +20 -21
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs +19 -21
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.d.mts +2 -3
- package/dist/parseMongoDB.d.ts +2 -3
- package/dist/parseMongoDB.js +7 -8
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs +6 -8
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/parseSQL.d.mts +2 -3
- package/dist/parseSQL.d.ts +2 -3
- package/dist/parseSQL.js +9 -11
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +7 -10
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.d.mts +2 -3
- package/dist/parseSpEL.d.ts +2 -3
- package/dist/parseSpEL.js +11 -2700
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +7 -9
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-BxWvIPI4.js → prepareQueryObjects-Dc8rqsYM.js} +49 -34
- package/dist/prepareQueryObjects-Dc8rqsYM.js.map +1 -0
- package/dist/{prepareQueryObjects-BBayjIn2.mjs → prepareQueryObjects-tMukQHT9.mjs} +34 -18
- package/dist/prepareQueryObjects-tMukQHT9.mjs.map +1 -0
- package/dist/react-querybuilder_core.d.mts +178 -127
- package/dist/react-querybuilder_core.legacy-esm.d.ts +178 -127
- package/dist/react-querybuilder_core.legacy-esm.js +296 -279
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +288 -247
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +178 -127
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/transformQuery.d.mts +1 -2
- package/dist/transformQuery.d.ts +1 -2
- package/dist/transformQuery.js +44 -2
- package/dist/transformQuery.js.map +1 -0
- package/dist/transformQuery.mjs +43 -2
- package/dist/transformQuery.mjs.map +1 -0
- package/dist/{utils-nQU7WCM9.mjs → utils-DQoYnxpa.mjs} +32 -84
- package/dist/utils-DQoYnxpa.mjs.map +1 -0
- package/dist/{utils-CR1ToTMW.js → utils-EsYRkPtf.js} +182 -246
- package/dist/utils-EsYRkPtf.js.map +1 -0
- package/package.json +25 -17
- package/dist/chunk-U64pC571.js +0 -41
- package/dist/convertQuery-DAj92cbM.mjs.map +0 -1
- package/dist/convertQuery-DRldbzhZ.js +0 -87
- package/dist/convertQuery-DRldbzhZ.js.map +0 -1
- package/dist/isRuleGroup-Cjk1Q2mj.js.map +0 -1
- package/dist/isRuleGroup-DztIOOKa.mjs.map +0 -1
- package/dist/prepareQueryObjects-BBayjIn2.mjs.map +0 -1
- package/dist/prepareQueryObjects-BxWvIPI4.js.map +0 -1
- package/dist/transformQuery-ClBRfnFg.js +0 -54
- package/dist/transformQuery-ClBRfnFg.js.map +0 -1
- package/dist/transformQuery-DUpbpqjX.mjs +0 -48
- package/dist/transformQuery-DUpbpqjX.mjs.map +0 -1
- package/dist/utils-CR1ToTMW.js.map +0 -1
- package/dist/utils-nQU7WCM9.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseJsonLogic.mjs","names":["emptyRuleGroup: DefaultRuleGroupType","rule","rule: DefaultRuleType | false","operator: DefaultOperatorName","value: any","valueSource: ValueSource | undefined","match: MatchConfig","field","finalQuery: DefaultRuleGroupType"],"sources":["../src/utils/parseJsonLogic/utils.ts","../src/utils/parseJsonLogic/parseJsonLogic.ts"],"sourcesContent":["import type {\n JsonLogicAll,\n JsonLogicAnd,\n JsonLogicDoubleNegation,\n JsonLogicEqual,\n JsonLogicGreaterThan,\n JsonLogicGreaterThanOrEqual,\n JsonLogicInArray,\n JsonLogicInString,\n JsonLogicLessThan,\n JsonLogicLessThanOrEqual,\n JsonLogicNegation,\n JsonLogicNone,\n JsonLogicNotEqual,\n JsonLogicOr,\n JsonLogicSome,\n JsonLogicStrictEqual,\n JsonLogicStrictNotEqual,\n JsonLogicVar,\n RQBJsonLogicEndsWith,\n RQBJsonLogicStartsWith,\n RQBJsonLogicVar,\n} from '../../types';\nimport { isPojo } from '../misc';\nimport type { JsonLogicBetweenExclusive, JsonLogicBetweenInclusive } from './types';\n\n// Standard JsonLogic operations\nexport const isJsonLogicVar = (\n logic: unknown\n): logic is JsonLogicVar<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'var' in logic;\nexport const isRQBJsonLogicVar = (logic: unknown): logic is RQBJsonLogicVar =>\n isJsonLogicVar(logic) && typeof logic.var === 'string';\nexport const isJsonLogicEqual = (logic: unknown): logic is JsonLogicEqual =>\n isPojo(logic) && '==' in logic;\nexport const isJsonLogicStrictEqual = (logic: unknown): logic is JsonLogicStrictEqual =>\n isPojo(logic) && '===' in logic;\nexport const isJsonLogicNotEqual = (logic: unknown): logic is JsonLogicNotEqual =>\n isPojo(logic) && '!=' in logic;\nexport const isJsonLogicStrictNotEqual = (logic: unknown): logic is JsonLogicStrictNotEqual =>\n isPojo(logic) && '!==' in logic;\nexport const isJsonLogicNegation = (logic: unknown): logic is JsonLogicNegation =>\n isPojo(logic) && '!' in logic;\nexport const isJsonLogicDoubleNegation = (logic: unknown): logic is JsonLogicDoubleNegation =>\n isPojo(logic) && '!!' in logic;\nexport const isJsonLogicOr = (\n logic: unknown\n): logic is JsonLogicOr<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'or' in logic;\nexport const isJsonLogicAnd = (\n logic: unknown\n): logic is JsonLogicAnd<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'and' in logic;\nexport const isJsonLogicGreaterThan = (\n logic: unknown\n): logic is JsonLogicGreaterThan<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && '>' in logic;\nexport const isJsonLogicGreaterThanOrEqual = (\n logic: unknown\n): logic is JsonLogicGreaterThanOrEqual<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && '>=' in logic;\nexport const isJsonLogicLessThan = (\n logic: unknown\n): logic is JsonLogicLessThan<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && '<' in logic && logic['<'].length === 2;\nexport const isJsonLogicLessThanOrEqual = (\n logic: unknown\n): logic is JsonLogicLessThanOrEqual<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && '<=' in logic && logic['<='].length === 2;\nexport const isJsonLogicInArray = (\n logic: unknown\n): logic is JsonLogicInArray<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'in' in logic && Array.isArray(logic.in[1]);\nexport const isJsonLogicInString = (\n logic: unknown\n): logic is JsonLogicInString<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'in' in logic && !Array.isArray(logic.in[1]);\nexport const isJsonLogicAll = (\n logic: unknown\n): logic is JsonLogicAll<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'all' in logic;\nexport const isJsonLogicNone = (\n logic: unknown\n): logic is JsonLogicNone<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'none' in logic;\nexport const isJsonLogicSome = (\n logic: unknown\n): logic is JsonLogicSome<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'some' in logic;\n\n// \"Between\" operations are special cases of '<' and '<='\nexport const isJsonLogicBetweenExclusive = (logic: unknown): logic is JsonLogicBetweenExclusive =>\n isPojo(logic) && '<' in logic && Array.isArray(logic['<']) && logic['<'].length === 3;\nexport const isJsonLogicBetweenInclusive = (logic: unknown): logic is JsonLogicBetweenInclusive =>\n isPojo(logic) && '<=' in logic && Array.isArray(logic['<=']) && logic['<='].length === 3;\n\n// RQB extensions\nexport const isRQBJsonLogicStartsWith = (logic: unknown): logic is RQBJsonLogicStartsWith =>\n isPojo(logic) && 'startsWith' in logic;\nexport const isRQBJsonLogicEndsWith = (logic: unknown): logic is RQBJsonLogicEndsWith =>\n isPojo(logic) && 'endsWith' in logic;\n\n// Type guards for unused JsonLogic operations\n\n// import type {\n// JsonLogicCat,\n// JsonLogicDifference,\n// JsonLogicFilter,\n// JsonLogicIf,\n// JsonLogicLog,\n// JsonLogicMap,\n// JsonLogicMax,\n// JsonLogicMerge,\n// JsonLogicMin,\n// JsonLogicMissing,\n// JsonLogicMissingSome,\n// JsonLogicProduct,\n// JsonLogicQuotient,\n// JsonLogicReduce,\n// JsonLogicRemainder,\n// JsonLogicSubstr,\n// JsonLogicSum,\n// } from '../../types';\n//\n// export const isJsonLogicMissing = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMissing<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'missing' in logic;\n// export const isJsonLogicMissingSome = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMissingSome<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'missing_some' in logic;\n// export const isJsonLogicIf = (logic: RQBJsonLogic): logic is JsonLogicIf =>\n// isPojo(logic) && 'if' in logic;\n// export const isJsonLogicMax = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMax<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'max' in logic;\n// export const isJsonLogicMin = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMin<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'min' in logic;\n// export const isJsonLogicSum = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicSum<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '+' in logic;\n// export const isJsonLogicDifference = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicDifference<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '-' in logic;\n// export const isJsonLogicProduct = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicProduct<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '*' in logic;\n// export const isJsonLogicQuotient = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicQuotient<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '/' in logic;\n// export const isJsonLogicRemainder = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicRemainder<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '%' in logic;\n// export const isJsonLogicMap = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMap<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'map' in logic;\n// export const isJsonLogicFilter = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicFilter<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'filter' in logic;\n// export const isJsonLogicReduce = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicReduce<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'reduce' in logic;\n// export const isJsonLogicMerge = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMerge<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'merge' in logic;\n// export const isJsonLogicCat = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicCat<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'cat' in logic;\n// export const isJsonLogicSubstr = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicSubstr<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'substr' in logic;\n// export const isJsonLogicLog = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicLog<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'log' in logic;\n","import type { Except } from 'type-fest';\nimport { defaultOperatorNegationMap } from '../../defaults';\nimport type {\n DefaultOperatorName,\n DefaultRuleGroupType,\n DefaultRuleGroupTypeAny,\n DefaultRuleGroupTypeIC,\n DefaultRuleType,\n MatchConfig,\n RQBJsonLogic,\n RQBJsonLogicVar,\n RuleGroupTypeAny,\n RuleType,\n ValueSource,\n} from '../../types';\nimport type { ParserCommonOptions } from '../../types/import';\nimport { joinWith } from '../arrayUtils';\nimport { convertToIC } from '../convertQuery';\nimport { isRuleGroup, isRuleGroupType } from '../isRuleGroup';\nimport { isPojo } from '../misc';\nimport { objectKeys } from '../objectUtils';\nimport { fieldIsValidUtil, getFieldsArray } from '../parserUtils';\nimport { prepareRuleGroup } from '../prepareQueryObjects';\nimport {\n isJsonLogicAll,\n isJsonLogicAnd,\n isJsonLogicBetweenExclusive,\n isJsonLogicBetweenInclusive,\n isJsonLogicDoubleNegation,\n isJsonLogicEqual,\n isJsonLogicGreaterThan,\n isJsonLogicGreaterThanOrEqual,\n isJsonLogicInArray,\n isJsonLogicInString,\n isJsonLogicLessThan,\n isJsonLogicLessThanOrEqual,\n isJsonLogicNegation,\n isJsonLogicNone,\n isJsonLogicNotEqual,\n isJsonLogicOr,\n isJsonLogicSome,\n isJsonLogicStrictEqual,\n isJsonLogicStrictNotEqual,\n isRQBJsonLogicEndsWith,\n isRQBJsonLogicStartsWith,\n isRQBJsonLogicVar,\n} from './utils';\n\n/**\n * Options object for {@link parseJsonLogic}.\n */\nexport interface ParseJsonLogicOptions extends ParserCommonOptions {\n // oxlint-disable-next-line typescript/no-explicit-any\n jsonLogicOperations?: Record<string, (value: any) => RuleType | RuleGroupTypeAny | false>;\n}\n\nconst emptyRuleGroup: DefaultRuleGroupType = { combinator: 'and', rules: [] };\n\n/**\n * Converts a JsonLogic object into a query suitable for the\n * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\nfunction parseJsonLogic(rqbJsonLogic: string | RQBJsonLogic): DefaultRuleGroupType;\n/**\n * Converts a JsonLogic object into a query suitable for the\n * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\nfunction parseJsonLogic(\n rqbJsonLogic: string | RQBJsonLogic,\n options: Except<ParseJsonLogicOptions, 'independentCombinators'> & {\n independentCombinators?: false;\n }\n): DefaultRuleGroupType;\n/**\n * Converts a JsonLogic object into a query suitable for the\n * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).\n */\nfunction parseJsonLogic(\n rqbJsonLogic: string | RQBJsonLogic,\n options: Except<ParseJsonLogicOptions, 'independentCombinators'> & {\n independentCombinators: true;\n }\n): DefaultRuleGroupTypeIC;\nfunction parseJsonLogic(\n rqbJsonLogic: string | RQBJsonLogic,\n options: ParseJsonLogicOptions = {}\n): DefaultRuleGroupTypeAny {\n const fieldsFlat = getFieldsArray(options.fields);\n const { getValueSources, listsAsArrays, jsonLogicOperations } = options;\n\n const fieldIsValid = (\n fieldName: string,\n operator: DefaultOperatorName,\n subordinateFieldName?: string\n ) =>\n fieldIsValidUtil({\n fieldName,\n fieldsFlat,\n operator,\n subordinateFieldName,\n getValueSources,\n });\n\n // Overload 1: Always return a rule group or false for the outermost logic object\n function processLogic(logic: RQBJsonLogic, outermost: true): DefaultRuleGroupType | false;\n // Overload 2: If not the outermost object, return value could also be a rule\n function processLogic(\n logic: RQBJsonLogic,\n outermost?: false\n ): DefaultRuleGroupType | DefaultRuleType | false;\n // Implementation\n function processLogic(\n logic: RQBJsonLogic,\n outermost?: boolean\n ): DefaultRuleGroupType | DefaultRuleType | false {\n // Bail if the outermost logic is not a plain object\n if (outermost && !isPojo(logic)) {\n return false;\n }\n const [key, keyValue] = Object.entries(logic || {})?.[0] ?? [];\n\n // Custom operations process logic\n if (jsonLogicOperations && objectKeys(jsonLogicOperations).includes(key)) {\n const rule = jsonLogicOperations[key](keyValue) as DefaultRuleType;\n return rule\n ? outermost && !isRuleGroup(rule)\n ? { combinator: 'and', rules: [rule] }\n : rule\n : false;\n }\n\n // Rule groups\n if (isJsonLogicAnd(logic)) {\n return {\n combinator: 'and',\n rules: logic.and.map(l => processLogic(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[],\n };\n } else if (isJsonLogicOr(logic)) {\n return {\n combinator: 'or',\n rules: logic.or.map(l => processLogic(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[],\n };\n } else if (isJsonLogicNegation(logic)) {\n const rule = processLogic(logic['!']);\n if (rule) {\n if (\n !isRuleGroupType(rule) &&\n (rule.operator === 'between' ||\n rule.operator === 'in' ||\n rule.operator === 'contains' ||\n rule.operator === 'beginsWith' ||\n rule.operator === 'endsWith')\n ) {\n const newRule = { ...rule, operator: defaultOperatorNegationMap[rule.operator] };\n if (outermost) {\n return { combinator: 'and', rules: [newRule] };\n }\n return newRule;\n } else if (isJsonLogicBetweenExclusive(logic['!']) || isRuleGroupType(rule)) {\n return { ...rule, not: true };\n }\n return { combinator: 'and', rules: [rule], not: true };\n }\n return false;\n } else if (isJsonLogicDoubleNegation(logic)) {\n const rule = processLogic(logic['!!']);\n return rule || false;\n }\n\n // All other keys represent rules\n let rule: DefaultRuleType | false = false;\n let field = '';\n let operator: DefaultOperatorName = '=';\n // oxlint-disable-next-line typescript/no-explicit-any\n let value: any = '';\n let valueSource: ValueSource | undefined = undefined;\n\n if (\n // Basic boolean operations\n isJsonLogicEqual(logic) ||\n isJsonLogicStrictEqual(logic) ||\n isJsonLogicNotEqual(logic) ||\n isJsonLogicStrictNotEqual(logic) ||\n isJsonLogicGreaterThan(logic) ||\n isJsonLogicGreaterThanOrEqual(logic) ||\n isJsonLogicLessThan(logic) ||\n isJsonLogicLessThanOrEqual(logic) ||\n isJsonLogicInString(logic) ||\n isRQBJsonLogicStartsWith(logic) ||\n isRQBJsonLogicEndsWith(logic)\n ) {\n const [first, second] = keyValue;\n if (isRQBJsonLogicVar(first) && !isPojo(second)) {\n field = first.var;\n value = second;\n } else if (!isPojo(first) && isRQBJsonLogicVar(second)) {\n field = second.var;\n value = first;\n } else if (isRQBJsonLogicVar(first) && isRQBJsonLogicVar(second)) {\n field = first.var;\n value = second.var;\n valueSource = 'field';\n } else {\n return false;\n }\n\n // Translate operator if necessary\n if (isJsonLogicEqual(logic) || isJsonLogicStrictEqual(logic)) {\n operator = value === null ? 'null' : '=';\n } else if (isJsonLogicNotEqual(logic) || isJsonLogicStrictNotEqual(logic)) {\n operator = value === null ? 'notNull' : '!=';\n } else if (isJsonLogicInString(logic)) {\n operator = 'contains';\n } else if (isRQBJsonLogicStartsWith(logic)) {\n operator = 'beginsWith';\n } else if (isRQBJsonLogicEndsWith(logic)) {\n operator = 'endsWith';\n } else {\n operator = key as DefaultOperatorName;\n }\n\n if (fieldIsValid(field, operator, valueSource === 'field' ? value : undefined)) {\n rule = { field, operator, value, valueSource };\n }\n } else if (\n (isJsonLogicAll(logic) && isRQBJsonLogicVar(logic['all'][0])) ||\n (isJsonLogicNone(logic) && isRQBJsonLogicVar(logic['none'][0])) ||\n (isJsonLogicSome(logic) && isRQBJsonLogicVar(logic['some'][0]))\n ) {\n // The array coverage functions must have a field as their first element.\n // Otherwise we'd be comparing values to values, which is not supported.\n const match: MatchConfig = {\n mode: isJsonLogicNone(logic) ? 'none' : isJsonLogicSome(logic) ? 'some' : 'all',\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any\n const [{ var: field }, operation] = (logic as any)[match.mode];\n const matcher = processLogic(operation);\n\n // TODO: Support operations that evaluate array member properties\n if (!matcher) return false;\n\n rule = {\n field,\n operator: '=',\n match,\n value: isRuleGroup(matcher) ? matcher : { combinator: 'and', rules: [matcher] },\n };\n } else if (isJsonLogicBetweenExclusive(logic) && isRQBJsonLogicVar(logic['<'][1])) {\n field = logic['<'][1].var;\n const values = [logic['<'][0], logic['<'][2]];\n // istanbul ignore else\n if (\n values.every(v => isRQBJsonLogicVar(v)) ||\n values.every(el => typeof el === 'string') ||\n values.every(el => typeof el === 'number') ||\n values.every(el => typeof el === 'boolean')\n ) {\n return (\n processLogic({\n and: [{ '>': [{ var: field }, values[0]] }, { '<': [{ var: field }, values[1]] }],\n }) || /* istanbul ignore next */ false\n );\n }\n } else if (isJsonLogicBetweenInclusive(logic) && isRQBJsonLogicVar(logic['<='][1])) {\n field = logic['<='][1].var;\n operator = 'between';\n const values = [logic['<='][0], logic['<='][2]];\n if (logic['<='].every(v => isRQBJsonLogicVar(v))) {\n const vars = values as RQBJsonLogicVar[];\n valueSource = 'field';\n const fieldList = vars.map(el => el.var).filter(sf => fieldIsValid(field, operator, sf));\n value = listsAsArrays ? fieldList : joinWith(fieldList, ',');\n } else {\n // istanbul ignore else\n if (\n values.every(el => typeof el === 'string') ||\n values.every(el => typeof el === 'number') ||\n values.every(el => typeof el === 'boolean')\n ) {\n value = listsAsArrays\n ? values\n : joinWith(\n values.map(el => `${el}`),\n ','\n );\n }\n }\n\n if (fieldIsValid(field, operator) && value.length >= 2) {\n rule = { field, operator, value, valueSource };\n }\n } else if (isJsonLogicInArray(logic) && isRQBJsonLogicVar(keyValue[0])) {\n field = keyValue[0].var;\n operator = 'in';\n if (logic.in[1].every(v => isRQBJsonLogicVar(v))) {\n valueSource = 'field';\n const fieldList = logic.in[1]\n .map(el => el.var)\n .filter(sf => fieldIsValid(field, operator, sf));\n value = listsAsArrays ? fieldList : joinWith(fieldList, ',');\n } else {\n // istanbul ignore else\n if (\n logic.in[1].every(el => typeof el === 'string') ||\n logic.in[1].every(el => typeof el === 'number') ||\n logic.in[1].every(el => typeof el === 'boolean')\n ) {\n value = listsAsArrays\n ? logic.in[1]\n : joinWith(\n logic.in[1].map(el => `${el}`),\n ','\n );\n }\n }\n\n // istanbul ignore else\n if (value.length > 0) {\n rule = { field, operator, value, valueSource };\n }\n }\n\n return rule ? (outermost ? { combinator: 'and', rules: [rule] } : rule) : false;\n }\n\n const prepare = options.generateIDs ? prepareRuleGroup : <T>(g: T) => g;\n\n let logicRoot = rqbJsonLogic;\n if (typeof rqbJsonLogic === 'string') {\n try {\n logicRoot = JSON.parse(rqbJsonLogic);\n } catch {\n return prepare(emptyRuleGroup);\n }\n }\n\n const result = processLogic(logicRoot, true);\n const finalQuery: DefaultRuleGroupType = result || emptyRuleGroup;\n return prepare(\n options.independentCombinators ? convertToIC<DefaultRuleGroupTypeIC>(finalQuery) : finalQuery\n );\n}\n\nexport { parseJsonLogic };\n"],"mappings":";;;;;;AA2BA,MAAa,kBACX,UAEA,OAAO,MAAM,IAAI,SAAS;AAC5B,MAAa,qBAAqB,UAChC,eAAe,MAAM,IAAI,OAAO,MAAM,QAAQ;AAChD,MAAa,oBAAoB,UAC/B,OAAO,MAAM,IAAI,QAAQ;AAC3B,MAAa,0BAA0B,UACrC,OAAO,MAAM,IAAI,SAAS;AAC5B,MAAa,uBAAuB,UAClC,OAAO,MAAM,IAAI,QAAQ;AAC3B,MAAa,6BAA6B,UACxC,OAAO,MAAM,IAAI,SAAS;AAC5B,MAAa,uBAAuB,UAClC,OAAO,MAAM,IAAI,OAAO;AAC1B,MAAa,6BAA6B,UACxC,OAAO,MAAM,IAAI,QAAQ;AAC3B,MAAa,iBACX,UAEA,OAA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}
|
|
1
|
+
{"version":3,"file":"parseJsonLogic.mjs","names":[],"sources":["../src/utils/parseJsonLogic/utils.ts","../src/utils/parseJsonLogic/parseJsonLogic.ts"],"sourcesContent":["import type {\n JsonLogicAll,\n JsonLogicAnd,\n JsonLogicDoubleNegation,\n JsonLogicEqual,\n JsonLogicGreaterThan,\n JsonLogicGreaterThanOrEqual,\n JsonLogicInArray,\n JsonLogicInString,\n JsonLogicLessThan,\n JsonLogicLessThanOrEqual,\n JsonLogicNegation,\n JsonLogicNone,\n JsonLogicNotEqual,\n JsonLogicOr,\n JsonLogicSome,\n JsonLogicStrictEqual,\n JsonLogicStrictNotEqual,\n JsonLogicVar,\n RQBJsonLogicEndsWith,\n RQBJsonLogicStartsWith,\n RQBJsonLogicVar,\n} from '../../types';\nimport { isPojo } from '../misc';\nimport type { JsonLogicBetweenExclusive, JsonLogicBetweenInclusive } from './types';\n\n// Standard JsonLogic operations\nexport const isJsonLogicVar = (\n logic: unknown\n): logic is JsonLogicVar<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'var' in logic;\nexport const isRQBJsonLogicVar = (logic: unknown): logic is RQBJsonLogicVar =>\n isJsonLogicVar(logic) && typeof logic.var === 'string';\nexport const isJsonLogicEqual = (logic: unknown): logic is JsonLogicEqual =>\n isPojo(logic) && '==' in logic;\nexport const isJsonLogicStrictEqual = (logic: unknown): logic is JsonLogicStrictEqual =>\n isPojo(logic) && '===' in logic;\nexport const isJsonLogicNotEqual = (logic: unknown): logic is JsonLogicNotEqual =>\n isPojo(logic) && '!=' in logic;\nexport const isJsonLogicStrictNotEqual = (logic: unknown): logic is JsonLogicStrictNotEqual =>\n isPojo(logic) && '!==' in logic;\nexport const isJsonLogicNegation = (logic: unknown): logic is JsonLogicNegation =>\n isPojo(logic) && '!' in logic;\nexport const isJsonLogicDoubleNegation = (logic: unknown): logic is JsonLogicDoubleNegation =>\n isPojo(logic) && '!!' in logic;\nexport const isJsonLogicOr = (\n logic: unknown\n): logic is JsonLogicOr<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'or' in logic;\nexport const isJsonLogicAnd = (\n logic: unknown\n): logic is JsonLogicAnd<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'and' in logic;\nexport const isJsonLogicGreaterThan = (\n logic: unknown\n): logic is JsonLogicGreaterThan<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && '>' in logic;\nexport const isJsonLogicGreaterThanOrEqual = (\n logic: unknown\n): logic is JsonLogicGreaterThanOrEqual<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && '>=' in logic;\nexport const isJsonLogicLessThan = (\n logic: unknown\n): logic is JsonLogicLessThan<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && '<' in logic && logic['<'].length === 2;\nexport const isJsonLogicLessThanOrEqual = (\n logic: unknown\n): logic is JsonLogicLessThanOrEqual<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && '<=' in logic && logic['<='].length === 2;\nexport const isJsonLogicInArray = (\n logic: unknown\n): logic is JsonLogicInArray<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'in' in logic && Array.isArray(logic.in[1]);\nexport const isJsonLogicInString = (\n logic: unknown\n): logic is JsonLogicInString<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'in' in logic && !Array.isArray(logic.in[1]);\nexport const isJsonLogicAll = (\n logic: unknown\n): logic is JsonLogicAll<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'all' in logic;\nexport const isJsonLogicNone = (\n logic: unknown\n): logic is JsonLogicNone<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'none' in logic;\nexport const isJsonLogicSome = (\n logic: unknown\n): logic is JsonLogicSome<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n isPojo(logic) && 'some' in logic;\n\n// \"Between\" operations are special cases of '<' and '<='\nexport const isJsonLogicBetweenExclusive = (logic: unknown): logic is JsonLogicBetweenExclusive =>\n isPojo(logic) && '<' in logic && Array.isArray(logic['<']) && logic['<'].length === 3;\nexport const isJsonLogicBetweenInclusive = (logic: unknown): logic is JsonLogicBetweenInclusive =>\n isPojo(logic) && '<=' in logic && Array.isArray(logic['<=']) && logic['<='].length === 3;\n\n// RQB extensions\nexport const isRQBJsonLogicStartsWith = (logic: unknown): logic is RQBJsonLogicStartsWith =>\n isPojo(logic) && 'startsWith' in logic;\nexport const isRQBJsonLogicEndsWith = (logic: unknown): logic is RQBJsonLogicEndsWith =>\n isPojo(logic) && 'endsWith' in logic;\n\n// Type guards for unused JsonLogic operations\n\n// import type {\n// JsonLogicCat,\n// JsonLogicDifference,\n// JsonLogicFilter,\n// JsonLogicIf,\n// JsonLogicLog,\n// JsonLogicMap,\n// JsonLogicMax,\n// JsonLogicMerge,\n// JsonLogicMin,\n// JsonLogicMissing,\n// JsonLogicMissingSome,\n// JsonLogicProduct,\n// JsonLogicQuotient,\n// JsonLogicReduce,\n// JsonLogicRemainder,\n// JsonLogicSubstr,\n// JsonLogicSum,\n// } from '../../types';\n//\n// export const isJsonLogicMissing = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMissing<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'missing' in logic;\n// export const isJsonLogicMissingSome = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMissingSome<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'missing_some' in logic;\n// export const isJsonLogicIf = (logic: RQBJsonLogic): logic is JsonLogicIf =>\n// isPojo(logic) && 'if' in logic;\n// export const isJsonLogicMax = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMax<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'max' in logic;\n// export const isJsonLogicMin = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMin<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'min' in logic;\n// export const isJsonLogicSum = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicSum<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '+' in logic;\n// export const isJsonLogicDifference = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicDifference<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '-' in logic;\n// export const isJsonLogicProduct = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicProduct<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '*' in logic;\n// export const isJsonLogicQuotient = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicQuotient<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '/' in logic;\n// export const isJsonLogicRemainder = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicRemainder<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && '%' in logic;\n// export const isJsonLogicMap = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMap<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'map' in logic;\n// export const isJsonLogicFilter = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicFilter<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'filter' in logic;\n// export const isJsonLogicReduce = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicReduce<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'reduce' in logic;\n// export const isJsonLogicMerge = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicMerge<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'merge' in logic;\n// export const isJsonLogicCat = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicCat<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'cat' in logic;\n// export const isJsonLogicSubstr = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicSubstr<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'substr' in logic;\n// export const isJsonLogicLog = (\n// logic: RQBJsonLogic\n// ): logic is JsonLogicLog<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith> =>\n// isPojo(logic) && 'log' in logic;\n","import type { Except } from 'type-fest';\nimport { defaultOperatorNegationMap } from '../../defaults';\nimport type {\n DefaultOperatorName,\n DefaultRuleGroupType,\n DefaultRuleGroupTypeAny,\n DefaultRuleGroupTypeIC,\n DefaultRuleType,\n MatchConfig,\n RQBJsonLogic,\n RQBJsonLogicVar,\n RuleGroupTypeAny,\n RuleType,\n ValueSource,\n} from '../../types';\nimport type { ParserCommonOptions } from '../../types/import';\nimport { joinWith } from '../arrayUtils';\nimport { convertToIC } from '../convertQuery';\nimport { isRuleGroup, isRuleGroupType } from '../isRuleGroup';\nimport { isPojo } from '../misc';\nimport { objectKeys } from '../objectUtils';\nimport { fieldIsValidUtil, getFieldsArray } from '../parserUtils';\nimport { prepareRuleGroup } from '../prepareQueryObjects';\nimport {\n isJsonLogicAll,\n isJsonLogicAnd,\n isJsonLogicBetweenExclusive,\n isJsonLogicBetweenInclusive,\n isJsonLogicDoubleNegation,\n isJsonLogicEqual,\n isJsonLogicGreaterThan,\n isJsonLogicGreaterThanOrEqual,\n isJsonLogicInArray,\n isJsonLogicInString,\n isJsonLogicLessThan,\n isJsonLogicLessThanOrEqual,\n isJsonLogicNegation,\n isJsonLogicNone,\n isJsonLogicNotEqual,\n isJsonLogicOr,\n isJsonLogicSome,\n isJsonLogicStrictEqual,\n isJsonLogicStrictNotEqual,\n isRQBJsonLogicEndsWith,\n isRQBJsonLogicStartsWith,\n isRQBJsonLogicVar,\n} from './utils';\n\n/**\n * Options object for {@link parseJsonLogic}.\n */\nexport interface ParseJsonLogicOptions extends ParserCommonOptions {\n // oxlint-disable-next-line typescript/no-explicit-any\n jsonLogicOperations?: Record<string, (value: any) => RuleType | RuleGroupTypeAny | false>;\n}\n\nconst emptyRuleGroup: DefaultRuleGroupType = { combinator: 'and', rules: [] };\n\n/**\n * Converts a JsonLogic object into a query suitable for the\n * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\nfunction parseJsonLogic(rqbJsonLogic: string | RQBJsonLogic): DefaultRuleGroupType;\n/**\n * Converts a JsonLogic object into a query suitable for the\n * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\nfunction parseJsonLogic(\n rqbJsonLogic: string | RQBJsonLogic,\n options: Except<ParseJsonLogicOptions, 'independentCombinators'> & {\n independentCombinators?: false;\n }\n): DefaultRuleGroupType;\n/**\n * Converts a JsonLogic object into a query suitable for the\n * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).\n */\nfunction parseJsonLogic(\n rqbJsonLogic: string | RQBJsonLogic,\n options: Except<ParseJsonLogicOptions, 'independentCombinators'> & {\n independentCombinators: true;\n }\n): DefaultRuleGroupTypeIC;\nfunction parseJsonLogic(\n rqbJsonLogic: string | RQBJsonLogic,\n options: ParseJsonLogicOptions = {}\n): DefaultRuleGroupTypeAny {\n const fieldsFlat = getFieldsArray(options.fields);\n const { getValueSources, listsAsArrays, jsonLogicOperations } = options;\n\n const fieldIsValid = (\n fieldName: string,\n operator: DefaultOperatorName,\n subordinateFieldName?: string\n ) =>\n fieldIsValidUtil({\n fieldName,\n fieldsFlat,\n operator,\n subordinateFieldName,\n getValueSources,\n });\n\n // Overload 1: Always return a rule group or false for the outermost logic object\n function processLogic(logic: RQBJsonLogic, outermost: true): DefaultRuleGroupType | false;\n // Overload 2: If not the outermost object, return value could also be a rule\n function processLogic(\n logic: RQBJsonLogic,\n outermost?: false\n ): DefaultRuleGroupType | DefaultRuleType | false;\n // Implementation\n function processLogic(\n logic: RQBJsonLogic,\n outermost?: boolean\n ): DefaultRuleGroupType | DefaultRuleType | false {\n // Bail if the outermost logic is not a plain object\n if (outermost && !isPojo(logic)) {\n return false;\n }\n const [key, keyValue] = Object.entries(logic || {})?.[0] ?? [];\n\n // Custom operations process logic\n if (jsonLogicOperations && objectKeys(jsonLogicOperations).includes(key)) {\n const rule = jsonLogicOperations[key](keyValue) as DefaultRuleType;\n return rule\n ? outermost && !isRuleGroup(rule)\n ? { combinator: 'and', rules: [rule] }\n : rule\n : false;\n }\n\n // Rule groups\n if (isJsonLogicAnd(logic)) {\n return {\n combinator: 'and',\n rules: logic.and.map(l => processLogic(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[],\n };\n } else if (isJsonLogicOr(logic)) {\n return {\n combinator: 'or',\n rules: logic.or.map(l => processLogic(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[],\n };\n } else if (isJsonLogicNegation(logic)) {\n const rule = processLogic(logic['!']);\n if (rule) {\n if (\n !isRuleGroupType(rule) &&\n (rule.operator === 'between' ||\n rule.operator === 'in' ||\n rule.operator === 'contains' ||\n rule.operator === 'beginsWith' ||\n rule.operator === 'endsWith')\n ) {\n const newRule = { ...rule, operator: defaultOperatorNegationMap[rule.operator] };\n if (outermost) {\n return { combinator: 'and', rules: [newRule] };\n }\n return newRule;\n } else if (isJsonLogicBetweenExclusive(logic['!']) || isRuleGroupType(rule)) {\n return { ...rule, not: true };\n }\n return { combinator: 'and', rules: [rule], not: true };\n }\n return false;\n } else if (isJsonLogicDoubleNegation(logic)) {\n const rule = processLogic(logic['!!']);\n return rule || false;\n }\n\n // All other keys represent rules\n let rule: DefaultRuleType | false = false;\n let field = '';\n let operator: DefaultOperatorName = '=';\n // oxlint-disable-next-line typescript/no-explicit-any\n let value: any = '';\n let valueSource: ValueSource | undefined = undefined;\n\n if (\n // Basic boolean operations\n isJsonLogicEqual(logic) ||\n isJsonLogicStrictEqual(logic) ||\n isJsonLogicNotEqual(logic) ||\n isJsonLogicStrictNotEqual(logic) ||\n isJsonLogicGreaterThan(logic) ||\n isJsonLogicGreaterThanOrEqual(logic) ||\n isJsonLogicLessThan(logic) ||\n isJsonLogicLessThanOrEqual(logic) ||\n isJsonLogicInString(logic) ||\n isRQBJsonLogicStartsWith(logic) ||\n isRQBJsonLogicEndsWith(logic)\n ) {\n const [first, second] = keyValue;\n if (isRQBJsonLogicVar(first) && !isPojo(second)) {\n field = first.var;\n value = second;\n } else if (!isPojo(first) && isRQBJsonLogicVar(second)) {\n field = second.var;\n value = first;\n } else if (isRQBJsonLogicVar(first) && isRQBJsonLogicVar(second)) {\n field = first.var;\n value = second.var;\n valueSource = 'field';\n } else {\n return false;\n }\n\n // Translate operator if necessary\n if (isJsonLogicEqual(logic) || isJsonLogicStrictEqual(logic)) {\n operator = value === null ? 'null' : '=';\n } else if (isJsonLogicNotEqual(logic) || isJsonLogicStrictNotEqual(logic)) {\n operator = value === null ? 'notNull' : '!=';\n } else if (isJsonLogicInString(logic)) {\n operator = 'contains';\n } else if (isRQBJsonLogicStartsWith(logic)) {\n operator = 'beginsWith';\n } else if (isRQBJsonLogicEndsWith(logic)) {\n operator = 'endsWith';\n } else {\n operator = key as DefaultOperatorName;\n }\n\n if (fieldIsValid(field, operator, valueSource === 'field' ? value : undefined)) {\n rule = { field, operator, value, valueSource };\n }\n } else if (\n (isJsonLogicAll(logic) && isRQBJsonLogicVar(logic['all'][0])) ||\n (isJsonLogicNone(logic) && isRQBJsonLogicVar(logic['none'][0])) ||\n (isJsonLogicSome(logic) && isRQBJsonLogicVar(logic['some'][0]))\n ) {\n // The array coverage functions must have a field as their first element.\n // Otherwise we'd be comparing values to values, which is not supported.\n const match: MatchConfig = {\n mode: isJsonLogicNone(logic) ? 'none' : isJsonLogicSome(logic) ? 'some' : 'all',\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any\n const [{ var: fld }, operation] = (logic as any)[match.mode];\n const matcher = processLogic(operation);\n\n // TODO: Support operations that evaluate array member properties\n if (!matcher) return false;\n\n rule = {\n field: fld,\n operator: '=',\n match,\n value: isRuleGroup(matcher) ? matcher : { combinator: 'and', rules: [matcher] },\n };\n } else if (isJsonLogicBetweenExclusive(logic) && isRQBJsonLogicVar(logic['<'][1])) {\n field = logic['<'][1].var;\n const values = [logic['<'][0], logic['<'][2]];\n // istanbul ignore else\n if (\n values.every(v => isRQBJsonLogicVar(v)) ||\n values.every(el => typeof el === 'string') ||\n values.every(el => typeof el === 'number') ||\n values.every(el => typeof el === 'boolean')\n ) {\n return (\n processLogic({\n and: [{ '>': [{ var: field }, values[0]] }, { '<': [{ var: field }, values[1]] }],\n }) || /* istanbul ignore next */ false\n );\n }\n } else if (isJsonLogicBetweenInclusive(logic) && isRQBJsonLogicVar(logic['<='][1])) {\n field = logic['<='][1].var;\n operator = 'between';\n const values = [logic['<='][0], logic['<='][2]];\n if (logic['<='].every(v => isRQBJsonLogicVar(v))) {\n const vars = values as RQBJsonLogicVar[];\n valueSource = 'field';\n const fieldList = vars.map(el => el.var).filter(sf => fieldIsValid(field, operator, sf));\n value = listsAsArrays ? fieldList : joinWith(fieldList, ',');\n } else {\n // istanbul ignore else\n if (\n values.every(el => typeof el === 'string') ||\n values.every(el => typeof el === 'number') ||\n values.every(el => typeof el === 'boolean')\n ) {\n value = listsAsArrays\n ? values\n : joinWith(\n values.map(el => `${el}`),\n ','\n );\n }\n }\n\n if (fieldIsValid(field, operator) && value.length >= 2) {\n rule = { field, operator, value, valueSource };\n }\n } else if (isJsonLogicInArray(logic) && isRQBJsonLogicVar(keyValue[0])) {\n field = keyValue[0].var;\n operator = 'in';\n if (logic.in[1].every(v => isRQBJsonLogicVar(v))) {\n valueSource = 'field';\n const fieldList = logic.in[1]\n .map(el => el.var)\n .filter(sf => fieldIsValid(field, operator, sf));\n value = listsAsArrays ? fieldList : joinWith(fieldList, ',');\n } else {\n // istanbul ignore else\n if (\n logic.in[1].every(el => typeof el === 'string') ||\n logic.in[1].every(el => typeof el === 'number') ||\n logic.in[1].every(el => typeof el === 'boolean')\n ) {\n value = listsAsArrays\n ? logic.in[1]\n : joinWith(\n logic.in[1].map(el => `${el}`),\n ','\n );\n }\n }\n\n // istanbul ignore else\n if (value.length > 0) {\n rule = { field, operator, value, valueSource };\n }\n }\n\n return rule ? (outermost ? { combinator: 'and', rules: [rule] } : rule) : false;\n }\n\n const prepare = options.generateIDs ? prepareRuleGroup : <T>(g: T) => g;\n\n let logicRoot = rqbJsonLogic;\n if (typeof rqbJsonLogic === 'string') {\n try {\n logicRoot = JSON.parse(rqbJsonLogic);\n } catch {\n return prepare(emptyRuleGroup);\n }\n }\n\n const result = processLogic(logicRoot, true);\n const finalQuery: DefaultRuleGroupType = result || emptyRuleGroup;\n return prepare(\n options.independentCombinators ? convertToIC<DefaultRuleGroupTypeIC>(finalQuery) : finalQuery\n );\n}\n\nexport { parseJsonLogic };\n"],"mappings":";;;;;AA2BA,MAAa,kBACX,UAEA,OAAO,MAAM,IAAI,SAAS;AAC5B,MAAa,qBAAqB,UAChC,eAAe,MAAM,IAAI,OAAO,MAAM,QAAQ;AAChD,MAAa,oBAAoB,UAC/B,OAAO,MAAM,IAAI,QAAQ;AAC3B,MAAa,0BAA0B,UACrC,OAAO,MAAM,IAAI,SAAS;AAC5B,MAAa,uBAAuB,UAClC,OAAO,MAAM,IAAI,QAAQ;AAC3B,MAAa,6BAA6B,UACxC,OAAO,MAAM,IAAI,SAAS;AAC5B,MAAa,uBAAuB,UAClC,OAAO,MAAM,IAAI,OAAO;AAC1B,MAAa,6BAA6B,UACxC,OAAO,MAAM,IAAI,QAAQ;AAC3B,MAAa,iBACX,UAEA,OAAO,MAAM,IAAI,QA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ANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { C as Except, _ as RuleGroupType, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType, v as RuleType } from "./basic-
|
|
2
|
-
import { t as ParserCommonOptions } from "./import-
|
|
1
|
+
import { C as Except, _ as RuleGroupType, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType, v as RuleType } from "./basic-CNIjb6rI.mjs";
|
|
2
|
+
import { t as ParserCommonOptions } from "./import-Bltb2mT4.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/parseMongoDB/parseMongoDB.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Options object for {@link parseMongoDB}.
|
|
8
7
|
*/
|
package/dist/parseMongoDB.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { C as Except, _ as RuleGroupType, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType, v as RuleType } from "./basic-
|
|
2
|
-
import { t as ParserCommonOptions } from "./import-
|
|
1
|
+
import { C as Except, _ as RuleGroupType, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType, v as RuleType } from "./basic-BXJVfD0P.js";
|
|
2
|
+
import { t as ParserCommonOptions } from "./import-B5Iq8XmL.js";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/parseMongoDB/parseMongoDB.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Options object for {@link parseMongoDB}.
|
|
8
7
|
*/
|
package/dist/parseMongoDB.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils = require("./utils-EsYRkPtf.js");
|
|
3
|
+
const require_isRuleGroup = require("./isRuleGroup-BCwaLzDj.js");
|
|
4
|
+
const require_convertQuery = require("./convertQuery-DfZehtnd.js");
|
|
5
|
+
const require_prepareQueryObjects = require("./prepareQueryObjects-Dc8rqsYM.js");
|
|
6
6
|
//#region src/utils/parseMongoDB/utils.ts
|
|
7
7
|
const getRegExStr = (re) => typeof re === "string" ? re : re.source;
|
|
8
8
|
const isPrimitive = (v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
@@ -14,7 +14,6 @@ const mongoDbToRqbOperatorMap = {
|
|
|
14
14
|
$lt: "<",
|
|
15
15
|
$lte: "<="
|
|
16
16
|
};
|
|
17
|
-
|
|
18
17
|
//#endregion
|
|
19
18
|
//#region src/utils/parseMongoDB/parseMongoDB.ts
|
|
20
19
|
const emptyRuleGroup = {
|
|
@@ -201,7 +200,7 @@ function parseMongoDB(mongoDbRules, options = {}) {
|
|
|
201
200
|
"not",
|
|
202
201
|
...require_utils.objectKeys(additionalOperators).map((o) => o.replace(/^\$/, ""))
|
|
203
202
|
];
|
|
204
|
-
const acceptedOpsRegExp =
|
|
203
|
+
const acceptedOpsRegExp = new RegExp(`^\\$(${allOps.join("|")})$`);
|
|
205
204
|
const operators = require_utils.objectKeys(keyValue).filter((o) => acceptedOpsRegExp.test(o)).sort();
|
|
206
205
|
if (operators.length === 0) return false;
|
|
207
206
|
if ("$not" in keyValue && require_isRuleGroup.isPojo(keyValue.$not)) {
|
|
@@ -259,7 +258,7 @@ function parseMongoDB(mongoDbRules, options = {}) {
|
|
|
259
258
|
} : emptyRuleGroup;
|
|
260
259
|
return prepare(options.independentCombinators ? require_convertQuery.convertToIC(finalQuery) : finalQuery);
|
|
261
260
|
}
|
|
262
|
-
|
|
263
261
|
//#endregion
|
|
264
262
|
exports.parseMongoDB = parseMongoDB;
|
|
263
|
+
|
|
265
264
|
//# sourceMappingURL=parseMongoDB.js.map
|
package/dist/parseMongoDB.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseMongoDB.js","names":["mongoDbToRqbOperatorMap: Partial<\n Record<MongoDbSupportedOperators, DefaultOperatorName>\n>","emptyRuleGroup: DefaultRuleGroupType","getFieldsArray","fieldIsValidUtil","operator: DefaultOperatorName","value: any","joinWith","isPojo","objectKeys","isRuleGroupType","defaultOperatorNegationMap","betweenRule: DefaultRuleType | false","notRule: DefaultRuleType | DefaultRuleGroupType | false","prepareRuleGroup","finalQuery: DefaultRuleGroupType","convertToIC"],"sources":["../src/utils/parseMongoDB/utils.ts","../src/utils/parseMongoDB/parseMongoDB.ts"],"sourcesContent":["import type { DefaultOperatorName } from '../../types';\nimport type { MongoDbSupportedOperators } from './types';\n\nexport const getRegExStr = (re: string | RegExp): string =>\n typeof re === 'string' ? re : re.source;\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isPrimitive = (v: any): v is string | number | boolean =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean';\n\nexport const mongoDbToRqbOperatorMap: Partial<\n Record<MongoDbSupportedOperators, DefaultOperatorName>\n> = {\n $eq: '=',\n $ne: '!=',\n $gt: '>',\n $gte: '>=',\n $lt: '<',\n $lte: '<=',\n} satisfies Partial<Record<MongoDbSupportedOperators, DefaultOperatorName>>;\n","import type { Except } from 'type-fest';\nimport { defaultOperatorNegationMap } from '../../defaults';\nimport type {\n DefaultOperatorName,\n DefaultRuleGroupType,\n DefaultRuleGroupTypeAny,\n DefaultRuleGroupTypeIC,\n DefaultRuleType,\n RuleGroupType,\n RuleType,\n} from '../../types';\nimport type { ParserCommonOptions } from '../../types/import';\nimport { joinWith } from '../arrayUtils';\nimport { convertToIC } from '../convertQuery';\nimport { isRuleGroupType } from '../isRuleGroup';\nimport { isPojo } from '../misc';\nimport { objectKeys } from '../objectUtils';\nimport { fieldIsValidUtil, getFieldsArray } from '../parserUtils';\nimport { prepareRuleGroup } from '../prepareQueryObjects';\nimport type { MongoDbSupportedOperators } from './types';\nimport { getRegExStr, isPrimitive, mongoDbToRqbOperatorMap } from './utils';\n\n/**\n * Options object for {@link parseMongoDB}.\n */\nexport interface ParseMongoDbOptions extends ParserCommonOptions {\n /**\n * When `true`, MongoDB rules in the form of `{ fieldName: { $not: { <...rule> } } }`\n * will be parsed into a rule group with the `not` attribute set to `true`. By default\n * (i.e., when this attribute is `false`), such \"`$not`\" rules will be parsed into a\n * rule with a negated operator.\n *\n * For example, with `preventOperatorNegation` set to `true`, a MongoDB rule like this...\n *\n * ```ts\n * { fieldName: { $not: { $eq: 1 } } }\n * ```\n *\n * ...would yield a rule group like this:\n *\n * ```ts\n * {\n * combinator: 'and',\n * not: true,\n * rules: [{ field: 'fieldName', operator: '=', value: 1 }]\n * }\n * ```\n *\n * By default, the same MongoDB rule would yield a rule like this:\n *\n * ```ts\n * { field: 'fieldName', operator: '!=', value: 1 }\n * // negated operator ^\n * ```\n *\n * @default false\n */\n preventOperatorNegation?: boolean;\n /**\n * Map of additional operators to their respective processing functions. Operators\n * must begin with `\"$\"`. Processing functions should return either a {@link index!RuleType RuleType}\n * or {@link index!RuleGroupType RuleGroupType}.\n *\n * (The functions should _not_ return {@link index!RuleGroupTypeIC RuleGroupTypeIC}, even if using independent\n * combinators. If the `independentCombinators` option is `true`, `parseMongoDB`\n * will convert the final query to {@link index!RuleGroupTypeIC RuleGroupTypeIC} before returning it.)\n *\n * @default {}\n */\n additionalOperators?: Record<\n `$${string}`,\n (\n field: string,\n operator: string,\n // oxlint-disable-next-line typescript/no-explicit-any\n value: any,\n options: ParserCommonOptions\n ) => RuleType | RuleGroupType\n >;\n}\n\nconst emptyRuleGroup: DefaultRuleGroupType = { combinator: 'and', rules: [] };\n\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nfunction parseMongoDB(mongoDbRules: string | Record<string, any>): DefaultRuleGroupType;\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: Except<ParseMongoDbOptions, 'independentCombinators'> & {\n independentCombinators?: false;\n }\n): DefaultRuleGroupType;\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).\n */\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: Except<ParseMongoDbOptions, 'independentCombinators'> & {\n independentCombinators: true;\n }\n): DefaultRuleGroupTypeIC;\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: ParseMongoDbOptions = {}\n): DefaultRuleGroupTypeAny {\n const listsAsArrays = !!options.listsAsArrays;\n const fieldsFlat = getFieldsArray(options.fields);\n const getValueSources = options.getValueSources;\n const additionalOperators = options.additionalOperators ?? {};\n const preventOperatorNegation = !!options.preventOperatorNegation;\n const { additionalOperators: _ao, ...otherOptions } = options;\n\n const fieldIsValid = (\n fieldName: string,\n operator: DefaultOperatorName,\n subordinateFieldName?: string\n ) =>\n fieldIsValidUtil({\n fieldName,\n fieldsFlat,\n operator,\n subordinateFieldName,\n getValueSources,\n });\n\n function processMongoDbQueryBooleanOperator(\n field: string,\n mdbOperator: MongoDbSupportedOperators,\n // oxlint-disable-next-line typescript/no-explicit-any\n keyValue: any\n ): DefaultRuleType | false {\n let operator: DefaultOperatorName = '=';\n // oxlint-disable-next-line typescript/no-explicit-any\n let value: any = '';\n\n // istanbul ignore else\n if (\n mdbOperator === '$eq' ||\n mdbOperator === '$ne' ||\n mdbOperator === '$gt' ||\n mdbOperator === '$gte' ||\n mdbOperator === '$lt' ||\n mdbOperator === '$lte'\n ) {\n if (mdbOperator === '$ne' && keyValue === null) {\n if (fieldIsValid(field, 'notNull')) {\n return { field, operator: 'notNull', value: null };\n }\n } else {\n operator = mongoDbToRqbOperatorMap[mdbOperator]!;\n if (fieldIsValid(field, operator)) {\n return { field, operator, value: keyValue };\n }\n }\n } else if (mdbOperator === '$regex' && /^[^$^]$|^[^^].*[^$]$/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'contains')) {\n return {\n field,\n operator: 'contains',\n value: getRegExStr(keyValue),\n };\n }\n } else if (mdbOperator === '$regex' && /^\\^.*[^$]/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'beginsWith')) {\n return {\n field,\n operator: 'beginsWith',\n value: getRegExStr(keyValue).replace(/^\\^/, ''),\n };\n }\n } else if (mdbOperator === '$regex' && /[^^].*\\$/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'endsWith')) {\n return {\n field,\n operator: 'endsWith',\n value: getRegExStr(keyValue).replace(/\\$$/, ''),\n };\n }\n } else if (mdbOperator === '$in' && Array.isArray(keyValue)) {\n if (fieldIsValid(field, 'in')) {\n value = listsAsArrays\n ? keyValue\n : joinWith(\n keyValue.map(v => `${v}`),\n ','\n );\n return { field, operator: 'in', value };\n }\n } else if (mdbOperator === '$nin' && Array.isArray(keyValue) && fieldIsValid(field, 'notIn')) {\n value = listsAsArrays\n ? keyValue\n : joinWith(\n keyValue.map(v => `${v}`),\n ','\n );\n return { field, operator: 'notIn', value };\n }\n\n return false;\n }\n\n function processMongoDbQueryObjectKey(\n key: string,\n // oxlint-disable-next-line typescript/no-explicit-any\n keyValue: any\n ): DefaultRuleType | DefaultRuleGroupType | false {\n let field = '';\n\n // istanbul ignore else\n if (key === '$and') {\n if (!Array.isArray(keyValue) || keyValue.length === 0 || !keyValue.every(v => isPojo(v))) {\n return false;\n }\n\n // Check if this should result in a \"between\" clause\n if (keyValue.length === 2 && keyValue.every(kv => objectKeys(kv).length === 1)) {\n const [rule1, rule2] = keyValue;\n const [ruleKey1, ruleKey2] = keyValue.map(kv => objectKeys(kv)[0]);\n if (\n ruleKey1 === ruleKey2 &&\n isPojo(rule1[ruleKey1]) &&\n objectKeys(rule1[ruleKey1]).length === 1 &&\n isPojo(rule2[ruleKey2]) &&\n objectKeys(rule2[ruleKey2]).length === 1 &&\n (('$gte' in rule1[ruleKey1] &&\n '$lte' in rule2[ruleKey2] &&\n rule2[ruleKey2].$lte >= rule1[ruleKey1].$gte) ||\n ('$lte' in rule1[ruleKey1] &&\n '$gte' in rule2[ruleKey2] &&\n rule1[ruleKey1].$lte >= rule2[ruleKey2].$gte))\n ) {\n const [val1, val2] = [\n rule1[ruleKey1].$gte ?? rule1[ruleKey1].$lte,\n rule2[ruleKey2].$lte ?? rule2[ruleKey2].$gte,\n ];\n let value = listsAsArrays ? [val1, val2] : joinWith([val1, val2], ',');\n if (val1 > val2) {\n value = listsAsArrays ? [val2, val1] : joinWith([val2, val1], ',');\n }\n return { field: ruleKey1, operator: 'between', value };\n }\n }\n\n const rules = keyValue.map(l => processMongoDbQueryObject(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[];\n\n return rules.length > 0 ? { combinator: 'and', rules } : false;\n } else if (key === '$or') {\n if (!Array.isArray(keyValue) || keyValue.length === 0 || !keyValue.every(v => isPojo(v))) {\n return false;\n }\n\n // Check if this should result in \"notBetween\"\n if (keyValue.length === 2 && keyValue.every(kv => objectKeys(kv).length === 1)) {\n const [rule1, rule2] = keyValue;\n const [ruleKey1, ruleKey2] = keyValue.map(kv => objectKeys(kv)[0]);\n if (\n ruleKey1 === ruleKey2 &&\n isPojo(rule1[ruleKey1]) &&\n objectKeys(rule1[ruleKey1]).length === 1 &&\n isPojo(rule2[ruleKey2]) &&\n objectKeys(rule2[ruleKey2]).length === 1 &&\n (('$gt' in rule1[ruleKey1] &&\n '$lt' in rule2[ruleKey2] &&\n rule1[ruleKey1].$gt >= rule2[ruleKey2].$lt) ||\n ('$lt' in rule1[ruleKey1] &&\n '$gt' in rule2[ruleKey2] &&\n rule2[ruleKey2].$gt >= rule1[ruleKey1].$lt))\n ) {\n const [val1, val2] = [\n rule1[ruleKey1].$gt ?? rule1[ruleKey1].$lt,\n rule2[ruleKey2].$lt ?? rule2[ruleKey2].$gt,\n ];\n let value = listsAsArrays ? [val1, val2] : `${val1},${val2}`;\n if (val1 > val2) {\n value = listsAsArrays ? [val2, val1] : `${val2},${val1}`;\n }\n return { field: ruleKey1, operator: 'notBetween', value };\n }\n }\n\n const rules = keyValue.map(l => processMongoDbQueryObject(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[];\n\n return rules.length > 0 ? { combinator: 'or', rules } : false;\n } else if (key === '$not' && isPojo(keyValue)) {\n const ruleOrGroup = processMongoDbQueryObject(keyValue);\n if (ruleOrGroup) {\n if (isRuleGroupType(ruleOrGroup)) {\n return ruleOrGroup.not\n ? { combinator: 'and', rules: [ruleOrGroup], not: true }\n : { ...ruleOrGroup, not: true };\n }\n return preventOperatorNegation\n ? { combinator: 'and', rules: [ruleOrGroup], not: true }\n : { ...ruleOrGroup, operator: defaultOperatorNegationMap[ruleOrGroup.operator] };\n }\n return false;\n } else if (key === '$expr') {\n const op = objectKeys(keyValue)[0] as MongoDbSupportedOperators;\n if (\n /^\\$(eq|gte?|lte?|n?in)$/.test(op) &&\n Array.isArray(keyValue[op]) &&\n keyValue[op].length === 2 &&\n typeof keyValue[op][0] === 'string' &&\n keyValue[op][0].startsWith('$')\n ) {\n field = keyValue[op][0].replace(/^\\$/, '');\n const val = keyValue[op][1];\n if (\n (typeof val === 'string' && val.startsWith('$')) ||\n (Array.isArray(val) &&\n val.every(v => typeof v === 'string') &&\n val.every(v => v.startsWith('$')))\n ) {\n const valForProcessing = Array.isArray(val)\n ? val.map(v => v.replace(/^\\$/, ''))\n : val.replace(/^\\$/, '');\n const tempRule = processMongoDbQueryBooleanOperator(field, op, valForProcessing);\n if (tempRule) {\n if (\n typeof tempRule.value === 'string' &&\n !fieldIsValid(field, tempRule.operator, tempRule.value)\n ) {\n return false;\n }\n return { ...tempRule, valueSource: 'field' };\n }\n }\n return processMongoDbQueryBooleanOperator(field, op, keyValue[op][1]);\n }\n } else if (/^[^$]/.test(key)) {\n field = key;\n\n if (isPrimitive(keyValue)) {\n if (fieldIsValid(field, '=')) {\n return { field, operator: '=', value: keyValue };\n }\n } else if (keyValue === null) {\n if (fieldIsValid(field, 'null')) {\n return { field, operator: 'null', value: keyValue };\n }\n } else if (isPojo(keyValue)) {\n let betweenRule: DefaultRuleType | false = false;\n let notRule: DefaultRuleType | DefaultRuleGroupType | false = false;\n const additionalOpKeys = objectKeys(additionalOperators).map(o => o.replace(/^\\$/, ''));\n const allOps = ['eq', 'ne', 'gte?', 'lte?', 'n?in', 'regex', 'not', ...additionalOpKeys];\n const acceptedOpsRegExp = new RegExp(`^\\\\$(${allOps.join('|')})$`);\n\n const operators = objectKeys<Record<MongoDbSupportedOperators, unknown>>(keyValue)\n .filter(o => acceptedOpsRegExp.test(o))\n // oxlint-disable-next-line no-array-sort\n .sort();\n\n if (operators.length === 0) {\n return false;\n }\n\n if ('$not' in keyValue && isPojo(keyValue.$not)) {\n const invertedNotRule = processMongoDbQueryObject({ [field]: keyValue.$not });\n if (invertedNotRule) {\n if (isRuleGroupType(invertedNotRule)) {\n notRule = { ...invertedNotRule, not: true };\n } else {\n notRule = preventOperatorNegation\n ? { combinator: 'and', rules: [invertedNotRule], not: true }\n : {\n ...invertedNotRule,\n operator: defaultOperatorNegationMap[invertedNotRule.operator],\n };\n }\n }\n }\n\n if ('$gte' in keyValue && '$lte' in keyValue) {\n // This is (at least) a compact \"between\" clause\n betweenRule = {\n field,\n operator: 'between',\n value: listsAsArrays\n ? [keyValue.$gte, keyValue.$lte]\n : `${keyValue.$gte},${keyValue.$lte}`,\n };\n }\n\n const rules = operators\n // filter out $not\n .filter(op => !(notRule && op === '$not'))\n // filter out $gte and $lte if they were both present\n .filter(op => !(betweenRule && (op === '$gte' || op === '$lte')))\n .map(op =>\n op in additionalOperators && typeof additionalOperators[op] === 'function'\n ? additionalOperators[op](field, op, keyValue[op], otherOptions)\n : processMongoDbQueryBooleanOperator(field, op, keyValue[op])\n )\n .filter(Boolean) as (DefaultRuleGroupType | DefaultRuleType)[];\n\n if (notRule) {\n rules.unshift(notRule);\n }\n\n if (betweenRule) {\n rules.unshift(betweenRule);\n }\n\n if (rules.length === 0) {\n return false;\n }\n if (rules.length === 1) {\n return rules[0];\n }\n return { combinator: 'and', rules };\n }\n }\n\n return false;\n }\n\n function processMongoDbQueryObject(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbQueryObject: Record<string, any>\n ): DefaultRuleGroupType | DefaultRuleType | false {\n const rules = objectKeys(mongoDbQueryObject)\n .map(k => processMongoDbQueryObjectKey(k, mongoDbQueryObject[k]))\n .filter(Boolean) as DefaultRuleGroupType[];\n return rules.length === 1 ? rules[0] : rules.length > 1 ? { combinator: 'and', rules } : false;\n }\n\n const prepare = options.generateIDs ? prepareRuleGroup : <T>(g: T) => g;\n\n let mongoDbPOJO = mongoDbRules;\n if (typeof mongoDbRules === 'string') {\n try {\n mongoDbPOJO = JSON.parse(mongoDbRules);\n } catch {\n return prepare(emptyRuleGroup);\n }\n }\n\n // Bail if the mongoDbPOJO is not actually a POJO\n if (!isPojo(mongoDbPOJO)) {\n return prepare(emptyRuleGroup);\n }\n\n const result = processMongoDbQueryObject(mongoDbPOJO);\n const finalQuery: DefaultRuleGroupType = result\n ? isRuleGroupType(result)\n ? result\n : { combinator: 'and', rules: [result] }\n : emptyRuleGroup;\n return prepare(\n options.independentCombinators ? convertToIC<DefaultRuleGroupTypeIC>(finalQuery) : finalQuery\n );\n}\n\nexport { parseMongoDB };\n"],"mappings":";;;;;;AAGA,MAAa,eAAe,OAC1B,OAAO,OAAO,WAAW,KAAK,GAAG;AAGnC,MAAa,eAAe,MAC1B,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM;AAEjE,MAAaA,0BAET;CACF,KAAK;CACL,KAAK;CACL,KA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AO;EAAE,GACxC;AACJ,QAAO,QACL,QAAQ,yBAAyBM,iCAAoC,WAAW,GAAG,WACpF"}
|
|
1
|
+
{"version":3,"file":"parseMongoDB.js","names":["getFieldsArray","fieldIsValidUtil","joinWith","isPojo","objectKeys","isRuleGroupType","defaultOperatorNegationMap","prepareRuleGroup","convertToIC"],"sources":["../src/utils/parseMongoDB/utils.ts","../src/utils/parseMongoDB/parseMongoDB.ts"],"sourcesContent":["import type { DefaultOperatorName } from '../../types';\nimport type { MongoDbSupportedOperators } from './types';\n\nexport const getRegExStr = (re: string | RegExp): string =>\n typeof re === 'string' ? re : re.source;\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isPrimitive = (v: any): v is string | number | boolean =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean';\n\nexport const mongoDbToRqbOperatorMap: Partial<\n Record<MongoDbSupportedOperators, DefaultOperatorName>\n> = {\n $eq: '=',\n $ne: '!=',\n $gt: '>',\n $gte: '>=',\n $lt: '<',\n $lte: '<=',\n} satisfies Partial<Record<MongoDbSupportedOperators, DefaultOperatorName>>;\n","import type { Except } from 'type-fest';\nimport { defaultOperatorNegationMap } from '../../defaults';\nimport type {\n DefaultOperatorName,\n DefaultRuleGroupType,\n DefaultRuleGroupTypeAny,\n DefaultRuleGroupTypeIC,\n DefaultRuleType,\n RuleGroupType,\n RuleType,\n} from '../../types';\nimport type { ParserCommonOptions } from '../../types/import';\nimport { joinWith } from '../arrayUtils';\nimport { convertToIC } from '../convertQuery';\nimport { isRuleGroupType } from '../isRuleGroup';\nimport { isPojo } from '../misc';\nimport { objectKeys } from '../objectUtils';\nimport { fieldIsValidUtil, getFieldsArray } from '../parserUtils';\nimport { prepareRuleGroup } from '../prepareQueryObjects';\nimport type { MongoDbSupportedOperators } from './types';\nimport { getRegExStr, isPrimitive, mongoDbToRqbOperatorMap } from './utils';\n\n/**\n * Options object for {@link parseMongoDB}.\n */\nexport interface ParseMongoDbOptions extends ParserCommonOptions {\n /**\n * When `true`, MongoDB rules in the form of `{ fieldName: { $not: { <...rule> } } }`\n * will be parsed into a rule group with the `not` attribute set to `true`. By default\n * (i.e., when this attribute is `false`), such \"`$not`\" rules will be parsed into a\n * rule with a negated operator.\n *\n * For example, with `preventOperatorNegation` set to `true`, a MongoDB rule like this...\n *\n * ```ts\n * { fieldName: { $not: { $eq: 1 } } }\n * ```\n *\n * ...would yield a rule group like this:\n *\n * ```ts\n * {\n * combinator: 'and',\n * not: true,\n * rules: [{ field: 'fieldName', operator: '=', value: 1 }]\n * }\n * ```\n *\n * By default, the same MongoDB rule would yield a rule like this:\n *\n * ```ts\n * { field: 'fieldName', operator: '!=', value: 1 }\n * // negated operator ^\n * ```\n *\n * @default false\n */\n preventOperatorNegation?: boolean;\n /**\n * Map of additional operators to their respective processing functions. Operators\n * must begin with `\"$\"`. Processing functions should return either a {@link index!RuleType RuleType}\n * or {@link index!RuleGroupType RuleGroupType}.\n *\n * (The functions should _not_ return {@link index!RuleGroupTypeIC RuleGroupTypeIC}, even if using independent\n * combinators. If the `independentCombinators` option is `true`, `parseMongoDB`\n * will convert the final query to {@link index!RuleGroupTypeIC RuleGroupTypeIC} before returning it.)\n *\n * @default {}\n */\n additionalOperators?: Record<\n `$${string}`,\n (\n field: string,\n operator: string,\n // oxlint-disable-next-line typescript/no-explicit-any\n value: any,\n options: ParserCommonOptions\n ) => RuleType | RuleGroupType\n >;\n}\n\nconst emptyRuleGroup: DefaultRuleGroupType = { combinator: 'and', rules: [] };\n\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nfunction parseMongoDB(mongoDbRules: string | Record<string, any>): DefaultRuleGroupType;\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: Except<ParseMongoDbOptions, 'independentCombinators'> & {\n independentCombinators?: false;\n }\n): DefaultRuleGroupType;\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).\n */\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: Except<ParseMongoDbOptions, 'independentCombinators'> & {\n independentCombinators: true;\n }\n): DefaultRuleGroupTypeIC;\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: ParseMongoDbOptions = {}\n): DefaultRuleGroupTypeAny {\n const listsAsArrays = !!options.listsAsArrays;\n const fieldsFlat = getFieldsArray(options.fields);\n const getValueSources = options.getValueSources;\n const additionalOperators = options.additionalOperators ?? {};\n const preventOperatorNegation = !!options.preventOperatorNegation;\n const { additionalOperators: _ao, ...otherOptions } = options;\n\n const fieldIsValid = (\n fieldName: string,\n operator: DefaultOperatorName,\n subordinateFieldName?: string\n ) =>\n fieldIsValidUtil({\n fieldName,\n fieldsFlat,\n operator,\n subordinateFieldName,\n getValueSources,\n });\n\n function processMongoDbQueryBooleanOperator(\n field: string,\n mdbOperator: MongoDbSupportedOperators,\n // oxlint-disable-next-line typescript/no-explicit-any\n keyValue: any\n ): DefaultRuleType | false {\n let operator: DefaultOperatorName = '=';\n // oxlint-disable-next-line typescript/no-explicit-any\n let value: any = '';\n\n // istanbul ignore else\n if (\n mdbOperator === '$eq' ||\n mdbOperator === '$ne' ||\n mdbOperator === '$gt' ||\n mdbOperator === '$gte' ||\n mdbOperator === '$lt' ||\n mdbOperator === '$lte'\n ) {\n if (mdbOperator === '$ne' && keyValue === null) {\n if (fieldIsValid(field, 'notNull')) {\n return { field, operator: 'notNull', value: null };\n }\n } else {\n operator = mongoDbToRqbOperatorMap[mdbOperator]!;\n if (fieldIsValid(field, operator)) {\n return { field, operator, value: keyValue };\n }\n }\n } else if (mdbOperator === '$regex' && /^[^$^]$|^[^^].*[^$]$/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'contains')) {\n return {\n field,\n operator: 'contains',\n value: getRegExStr(keyValue),\n };\n }\n } else if (mdbOperator === '$regex' && /^\\^.*[^$]/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'beginsWith')) {\n return {\n field,\n operator: 'beginsWith',\n value: getRegExStr(keyValue).replace(/^\\^/, ''),\n };\n }\n } else if (mdbOperator === '$regex' && /[^^].*\\$/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'endsWith')) {\n return {\n field,\n operator: 'endsWith',\n value: getRegExStr(keyValue).replace(/\\$$/, ''),\n };\n }\n } else if (mdbOperator === '$in' && Array.isArray(keyValue)) {\n if (fieldIsValid(field, 'in')) {\n value = listsAsArrays\n ? keyValue\n : joinWith(\n keyValue.map(v => `${v}`),\n ','\n );\n return { field, operator: 'in', value };\n }\n } else if (mdbOperator === '$nin' && Array.isArray(keyValue) && fieldIsValid(field, 'notIn')) {\n value = listsAsArrays\n ? keyValue\n : joinWith(\n keyValue.map(v => `${v}`),\n ','\n );\n return { field, operator: 'notIn', value };\n }\n\n return false;\n }\n\n function processMongoDbQueryObjectKey(\n key: string,\n // oxlint-disable-next-line typescript/no-explicit-any\n keyValue: any\n ): DefaultRuleType | DefaultRuleGroupType | false {\n let field = '';\n\n // istanbul ignore else\n if (key === '$and') {\n if (!Array.isArray(keyValue) || keyValue.length === 0 || !keyValue.every(v => isPojo(v))) {\n return false;\n }\n\n // Check if this should result in a \"between\" clause\n if (keyValue.length === 2 && keyValue.every(kv => objectKeys(kv).length === 1)) {\n const [rule1, rule2] = keyValue;\n const [ruleKey1, ruleKey2] = keyValue.map(kv => objectKeys(kv)[0]);\n if (\n ruleKey1 === ruleKey2 &&\n isPojo(rule1[ruleKey1]) &&\n objectKeys(rule1[ruleKey1]).length === 1 &&\n isPojo(rule2[ruleKey2]) &&\n objectKeys(rule2[ruleKey2]).length === 1 &&\n (('$gte' in rule1[ruleKey1] &&\n '$lte' in rule2[ruleKey2] &&\n rule2[ruleKey2].$lte >= rule1[ruleKey1].$gte) ||\n ('$lte' in rule1[ruleKey1] &&\n '$gte' in rule2[ruleKey2] &&\n rule1[ruleKey1].$lte >= rule2[ruleKey2].$gte))\n ) {\n const [val1, val2] = [\n rule1[ruleKey1].$gte ?? rule1[ruleKey1].$lte,\n rule2[ruleKey2].$lte ?? rule2[ruleKey2].$gte,\n ];\n let value = listsAsArrays ? [val1, val2] : joinWith([val1, val2], ',');\n if (val1 > val2) {\n value = listsAsArrays ? [val2, val1] : joinWith([val2, val1], ',');\n }\n return { field: ruleKey1, operator: 'between', value };\n }\n }\n\n const rules = keyValue.map(l => processMongoDbQueryObject(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[];\n\n return rules.length > 0 ? { combinator: 'and', rules } : false;\n } else if (key === '$or') {\n if (!Array.isArray(keyValue) || keyValue.length === 0 || !keyValue.every(v => isPojo(v))) {\n return false;\n }\n\n // Check if this should result in \"notBetween\"\n if (keyValue.length === 2 && keyValue.every(kv => objectKeys(kv).length === 1)) {\n const [rule1, rule2] = keyValue;\n const [ruleKey1, ruleKey2] = keyValue.map(kv => objectKeys(kv)[0]);\n if (\n ruleKey1 === ruleKey2 &&\n isPojo(rule1[ruleKey1]) &&\n objectKeys(rule1[ruleKey1]).length === 1 &&\n isPojo(rule2[ruleKey2]) &&\n objectKeys(rule2[ruleKey2]).length === 1 &&\n (('$gt' in rule1[ruleKey1] &&\n '$lt' in rule2[ruleKey2] &&\n rule1[ruleKey1].$gt >= rule2[ruleKey2].$lt) ||\n ('$lt' in rule1[ruleKey1] &&\n '$gt' in rule2[ruleKey2] &&\n rule2[ruleKey2].$gt >= rule1[ruleKey1].$lt))\n ) {\n const [val1, val2] = [\n rule1[ruleKey1].$gt ?? rule1[ruleKey1].$lt,\n rule2[ruleKey2].$lt ?? rule2[ruleKey2].$gt,\n ];\n let value = listsAsArrays ? [val1, val2] : `${val1},${val2}`;\n if (val1 > val2) {\n value = listsAsArrays ? [val2, val1] : `${val2},${val1}`;\n }\n return { field: ruleKey1, operator: 'notBetween', value };\n }\n }\n\n const rules = keyValue.map(l => processMongoDbQueryObject(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[];\n\n return rules.length > 0 ? { combinator: 'or', rules } : false;\n } else if (key === '$not' && isPojo(keyValue)) {\n const ruleOrGroup = processMongoDbQueryObject(keyValue);\n if (ruleOrGroup) {\n if (isRuleGroupType(ruleOrGroup)) {\n return ruleOrGroup.not\n ? { combinator: 'and', rules: [ruleOrGroup], not: true }\n : { ...ruleOrGroup, not: true };\n }\n return preventOperatorNegation\n ? { combinator: 'and', rules: [ruleOrGroup], not: true }\n : { ...ruleOrGroup, operator: defaultOperatorNegationMap[ruleOrGroup.operator] };\n }\n return false;\n } else if (key === '$expr') {\n const op = objectKeys(keyValue)[0] as MongoDbSupportedOperators;\n if (\n /^\\$(eq|gte?|lte?|n?in)$/.test(op) &&\n Array.isArray(keyValue[op]) &&\n keyValue[op].length === 2 &&\n typeof keyValue[op][0] === 'string' &&\n keyValue[op][0].startsWith('$')\n ) {\n field = keyValue[op][0].replace(/^\\$/, '');\n const val = keyValue[op][1];\n if (\n (typeof val === 'string' && val.startsWith('$')) ||\n (Array.isArray(val) &&\n val.every(v => typeof v === 'string') &&\n val.every(v => v.startsWith('$')))\n ) {\n const valForProcessing = Array.isArray(val)\n ? val.map(v => v.replace(/^\\$/, ''))\n : val.replace(/^\\$/, '');\n const tempRule = processMongoDbQueryBooleanOperator(field, op, valForProcessing);\n if (tempRule) {\n if (\n typeof tempRule.value === 'string' &&\n !fieldIsValid(field, tempRule.operator, tempRule.value)\n ) {\n return false;\n }\n return { ...tempRule, valueSource: 'field' };\n }\n }\n return processMongoDbQueryBooleanOperator(field, op, keyValue[op][1]);\n }\n } else if (/^[^$]/.test(key)) {\n field = key;\n\n if (isPrimitive(keyValue)) {\n if (fieldIsValid(field, '=')) {\n return { field, operator: '=', value: keyValue };\n }\n } else if (keyValue === null) {\n if (fieldIsValid(field, 'null')) {\n return { field, operator: 'null', value: keyValue };\n }\n } else if (isPojo(keyValue)) {\n let betweenRule: DefaultRuleType | false = false;\n let notRule: DefaultRuleType | DefaultRuleGroupType | false = false;\n const additionalOpKeys = objectKeys(additionalOperators).map(o => o.replace(/^\\$/, ''));\n const allOps = ['eq', 'ne', 'gte?', 'lte?', 'n?in', 'regex', 'not', ...additionalOpKeys];\n const acceptedOpsRegExp = new RegExp(`^\\\\$(${allOps.join('|')})$`);\n\n const operators = objectKeys<Record<MongoDbSupportedOperators, unknown>>(keyValue)\n .filter(o => acceptedOpsRegExp.test(o))\n // oxlint-disable-next-line no-array-sort\n .sort();\n\n if (operators.length === 0) {\n return false;\n }\n\n if ('$not' in keyValue && isPojo(keyValue.$not)) {\n const invertedNotRule = processMongoDbQueryObject({ [field]: keyValue.$not });\n if (invertedNotRule) {\n if (isRuleGroupType(invertedNotRule)) {\n notRule = { ...invertedNotRule, not: true };\n } else {\n notRule = preventOperatorNegation\n ? { combinator: 'and', rules: [invertedNotRule], not: true }\n : {\n ...invertedNotRule,\n operator: defaultOperatorNegationMap[invertedNotRule.operator],\n };\n }\n }\n }\n\n if ('$gte' in keyValue && '$lte' in keyValue) {\n // This is (at least) a compact \"between\" clause\n betweenRule = {\n field,\n operator: 'between',\n value: listsAsArrays\n ? [keyValue.$gte, keyValue.$lte]\n : `${keyValue.$gte},${keyValue.$lte}`,\n };\n }\n\n const rules = operators\n // filter out $not\n .filter(op => !(notRule && op === '$not'))\n // filter out $gte and $lte if they were both present\n .filter(op => !(betweenRule && (op === '$gte' || op === '$lte')))\n .map(op =>\n op in additionalOperators && typeof additionalOperators[op] === 'function'\n ? additionalOperators[op](field, op, keyValue[op], otherOptions)\n : processMongoDbQueryBooleanOperator(field, op, keyValue[op])\n )\n .filter(Boolean) as (DefaultRuleGroupType | DefaultRuleType)[];\n\n if (notRule) {\n rules.unshift(notRule);\n }\n\n if (betweenRule) {\n rules.unshift(betweenRule);\n }\n\n if (rules.length === 0) {\n return false;\n }\n if (rules.length === 1) {\n return rules[0];\n }\n return { combinator: 'and', rules };\n }\n }\n\n return false;\n }\n\n function processMongoDbQueryObject(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbQueryObject: Record<string, any>\n ): DefaultRuleGroupType | DefaultRuleType | false {\n const rules = objectKeys(mongoDbQueryObject)\n .map(k => processMongoDbQueryObjectKey(k, mongoDbQueryObject[k]))\n .filter(Boolean) as DefaultRuleGroupType[];\n return rules.length === 1 ? rules[0] : rules.length > 1 ? { combinator: 'and', rules } : false;\n }\n\n const prepare = options.generateIDs ? prepareRuleGroup : <T>(g: T) => g;\n\n let mongoDbPOJO = mongoDbRules;\n if (typeof mongoDbRules === 'string') {\n try {\n mongoDbPOJO = JSON.parse(mongoDbRules);\n } catch {\n return prepare(emptyRuleGroup);\n }\n }\n\n // Bail if the mongoDbPOJO is not actually a POJO\n if (!isPojo(mongoDbPOJO)) {\n return prepare(emptyRuleGroup);\n }\n\n const result = processMongoDbQueryObject(mongoDbPOJO);\n const finalQuery: DefaultRuleGroupType = result\n ? isRuleGroupType(result)\n ? result\n : { combinator: 'and', rules: [result] }\n : emptyRuleGroup;\n return prepare(\n options.independentCombinators ? convertToIC<DefaultRuleGroupTypeIC>(finalQuery) : finalQuery\n );\n}\n\nexport { parseMongoDB };\n"],"mappings":";;;;;;AAGA,MAAa,eAAe,OAC1B,OAAO,OAAO,WAAW,KAAK,GAAG;AAGnC,MAAa,eAAe,MAC1B,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM;AAEjE,MAAa,0BAET;CACF,KAAK;CACL,KAAK;CACL,KAAK;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ACJ,oBAAAA,OAAO,YAAY,CACtB,QAAO,QAAQ,eAAe;CAGhC,MAAM,SAAS,0BAA0B,YAAY;CACrD,MAAM,aAAmC,SACrCE,oBAAAA,gBAAgB,OAAO,GACrB,SACA;EAAE,YAAY;EAAO,OAAO,CAAC,OAAO;EAAE,GACxC;AACJ,QAAO,QACL,QAAQ,yBAAyBG,qBAAAA,YAAoC,WAAW,GAAG,WACpF"}
|
package/dist/parseMongoDB.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { A as defaultOperatorNegationMap, D as joinWith, T as objectKeys } from "./utils-
|
|
2
|
-
import { i as isPojo, n as isRuleGroupType } from "./isRuleGroup-
|
|
3
|
-
import { n as convertToIC } from "./convertQuery-
|
|
4
|
-
import { n as fieldIsValidUtil, r as getFieldsArray, t as prepareRuleGroup } from "./prepareQueryObjects-
|
|
5
|
-
|
|
1
|
+
import { A as defaultOperatorNegationMap, D as joinWith, T as objectKeys } from "./utils-DQoYnxpa.mjs";
|
|
2
|
+
import { i as isPojo, n as isRuleGroupType } from "./isRuleGroup-LzP0HCKh.mjs";
|
|
3
|
+
import { n as convertToIC } from "./convertQuery-B5Qm_6ut.mjs";
|
|
4
|
+
import { n as fieldIsValidUtil, r as getFieldsArray, t as prepareRuleGroup } from "./prepareQueryObjects-tMukQHT9.mjs";
|
|
6
5
|
//#region src/utils/parseMongoDB/utils.ts
|
|
7
6
|
const getRegExStr = (re) => typeof re === "string" ? re : re.source;
|
|
8
7
|
const isPrimitive = (v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean";
|
|
@@ -14,7 +13,6 @@ const mongoDbToRqbOperatorMap = {
|
|
|
14
13
|
$lt: "<",
|
|
15
14
|
$lte: "<="
|
|
16
15
|
};
|
|
17
|
-
|
|
18
16
|
//#endregion
|
|
19
17
|
//#region src/utils/parseMongoDB/parseMongoDB.ts
|
|
20
18
|
const emptyRuleGroup = {
|
|
@@ -201,7 +199,7 @@ function parseMongoDB(mongoDbRules, options = {}) {
|
|
|
201
199
|
"not",
|
|
202
200
|
...objectKeys(additionalOperators).map((o) => o.replace(/^\$/, ""))
|
|
203
201
|
];
|
|
204
|
-
const acceptedOpsRegExp =
|
|
202
|
+
const acceptedOpsRegExp = new RegExp(`^\\$(${allOps.join("|")})$`);
|
|
205
203
|
const operators = objectKeys(keyValue).filter((o) => acceptedOpsRegExp.test(o)).sort();
|
|
206
204
|
if (operators.length === 0) return false;
|
|
207
205
|
if ("$not" in keyValue && isPojo(keyValue.$not)) {
|
|
@@ -259,7 +257,7 @@ function parseMongoDB(mongoDbRules, options = {}) {
|
|
|
259
257
|
} : emptyRuleGroup;
|
|
260
258
|
return prepare(options.independentCombinators ? convertToIC(finalQuery) : finalQuery);
|
|
261
259
|
}
|
|
262
|
-
|
|
263
260
|
//#endregion
|
|
264
261
|
export { parseMongoDB };
|
|
262
|
+
|
|
265
263
|
//# sourceMappingURL=parseMongoDB.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseMongoDB.mjs","names":["mongoDbToRqbOperatorMap: Partial<\n Record<MongoDbSupportedOperators, DefaultOperatorName>\n>","emptyRuleGroup: DefaultRuleGroupType","operator: DefaultOperatorName","value: any","betweenRule: DefaultRuleType | false","notRule: DefaultRuleType | DefaultRuleGroupType | false","finalQuery: DefaultRuleGroupType"],"sources":["../src/utils/parseMongoDB/utils.ts","../src/utils/parseMongoDB/parseMongoDB.ts"],"sourcesContent":["import type { DefaultOperatorName } from '../../types';\nimport type { MongoDbSupportedOperators } from './types';\n\nexport const getRegExStr = (re: string | RegExp): string =>\n typeof re === 'string' ? re : re.source;\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isPrimitive = (v: any): v is string | number | boolean =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean';\n\nexport const mongoDbToRqbOperatorMap: Partial<\n Record<MongoDbSupportedOperators, DefaultOperatorName>\n> = {\n $eq: '=',\n $ne: '!=',\n $gt: '>',\n $gte: '>=',\n $lt: '<',\n $lte: '<=',\n} satisfies Partial<Record<MongoDbSupportedOperators, DefaultOperatorName>>;\n","import type { Except } from 'type-fest';\nimport { defaultOperatorNegationMap } from '../../defaults';\nimport type {\n DefaultOperatorName,\n DefaultRuleGroupType,\n DefaultRuleGroupTypeAny,\n DefaultRuleGroupTypeIC,\n DefaultRuleType,\n RuleGroupType,\n RuleType,\n} from '../../types';\nimport type { ParserCommonOptions } from '../../types/import';\nimport { joinWith } from '../arrayUtils';\nimport { convertToIC } from '../convertQuery';\nimport { isRuleGroupType } from '../isRuleGroup';\nimport { isPojo } from '../misc';\nimport { objectKeys } from '../objectUtils';\nimport { fieldIsValidUtil, getFieldsArray } from '../parserUtils';\nimport { prepareRuleGroup } from '../prepareQueryObjects';\nimport type { MongoDbSupportedOperators } from './types';\nimport { getRegExStr, isPrimitive, mongoDbToRqbOperatorMap } from './utils';\n\n/**\n * Options object for {@link parseMongoDB}.\n */\nexport interface ParseMongoDbOptions extends ParserCommonOptions {\n /**\n * When `true`, MongoDB rules in the form of `{ fieldName: { $not: { <...rule> } } }`\n * will be parsed into a rule group with the `not` attribute set to `true`. By default\n * (i.e., when this attribute is `false`), such \"`$not`\" rules will be parsed into a\n * rule with a negated operator.\n *\n * For example, with `preventOperatorNegation` set to `true`, a MongoDB rule like this...\n *\n * ```ts\n * { fieldName: { $not: { $eq: 1 } } }\n * ```\n *\n * ...would yield a rule group like this:\n *\n * ```ts\n * {\n * combinator: 'and',\n * not: true,\n * rules: [{ field: 'fieldName', operator: '=', value: 1 }]\n * }\n * ```\n *\n * By default, the same MongoDB rule would yield a rule like this:\n *\n * ```ts\n * { field: 'fieldName', operator: '!=', value: 1 }\n * // negated operator ^\n * ```\n *\n * @default false\n */\n preventOperatorNegation?: boolean;\n /**\n * Map of additional operators to their respective processing functions. Operators\n * must begin with `\"$\"`. Processing functions should return either a {@link index!RuleType RuleType}\n * or {@link index!RuleGroupType RuleGroupType}.\n *\n * (The functions should _not_ return {@link index!RuleGroupTypeIC RuleGroupTypeIC}, even if using independent\n * combinators. If the `independentCombinators` option is `true`, `parseMongoDB`\n * will convert the final query to {@link index!RuleGroupTypeIC RuleGroupTypeIC} before returning it.)\n *\n * @default {}\n */\n additionalOperators?: Record<\n `$${string}`,\n (\n field: string,\n operator: string,\n // oxlint-disable-next-line typescript/no-explicit-any\n value: any,\n options: ParserCommonOptions\n ) => RuleType | RuleGroupType\n >;\n}\n\nconst emptyRuleGroup: DefaultRuleGroupType = { combinator: 'and', rules: [] };\n\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nfunction parseMongoDB(mongoDbRules: string | Record<string, any>): DefaultRuleGroupType;\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: Except<ParseMongoDbOptions, 'independentCombinators'> & {\n independentCombinators?: false;\n }\n): DefaultRuleGroupType;\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).\n */\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: Except<ParseMongoDbOptions, 'independentCombinators'> & {\n independentCombinators: true;\n }\n): DefaultRuleGroupTypeIC;\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: ParseMongoDbOptions = {}\n): DefaultRuleGroupTypeAny {\n const listsAsArrays = !!options.listsAsArrays;\n const fieldsFlat = getFieldsArray(options.fields);\n const getValueSources = options.getValueSources;\n const additionalOperators = options.additionalOperators ?? {};\n const preventOperatorNegation = !!options.preventOperatorNegation;\n const { additionalOperators: _ao, ...otherOptions } = options;\n\n const fieldIsValid = (\n fieldName: string,\n operator: DefaultOperatorName,\n subordinateFieldName?: string\n ) =>\n fieldIsValidUtil({\n fieldName,\n fieldsFlat,\n operator,\n subordinateFieldName,\n getValueSources,\n });\n\n function processMongoDbQueryBooleanOperator(\n field: string,\n mdbOperator: MongoDbSupportedOperators,\n // oxlint-disable-next-line typescript/no-explicit-any\n keyValue: any\n ): DefaultRuleType | false {\n let operator: DefaultOperatorName = '=';\n // oxlint-disable-next-line typescript/no-explicit-any\n let value: any = '';\n\n // istanbul ignore else\n if (\n mdbOperator === '$eq' ||\n mdbOperator === '$ne' ||\n mdbOperator === '$gt' ||\n mdbOperator === '$gte' ||\n mdbOperator === '$lt' ||\n mdbOperator === '$lte'\n ) {\n if (mdbOperator === '$ne' && keyValue === null) {\n if (fieldIsValid(field, 'notNull')) {\n return { field, operator: 'notNull', value: null };\n }\n } else {\n operator = mongoDbToRqbOperatorMap[mdbOperator]!;\n if (fieldIsValid(field, operator)) {\n return { field, operator, value: keyValue };\n }\n }\n } else if (mdbOperator === '$regex' && /^[^$^]$|^[^^].*[^$]$/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'contains')) {\n return {\n field,\n operator: 'contains',\n value: getRegExStr(keyValue),\n };\n }\n } else if (mdbOperator === '$regex' && /^\\^.*[^$]/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'beginsWith')) {\n return {\n field,\n operator: 'beginsWith',\n value: getRegExStr(keyValue).replace(/^\\^/, ''),\n };\n }\n } else if (mdbOperator === '$regex' && /[^^].*\\$/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'endsWith')) {\n return {\n field,\n operator: 'endsWith',\n value: getRegExStr(keyValue).replace(/\\$$/, ''),\n };\n }\n } else if (mdbOperator === '$in' && Array.isArray(keyValue)) {\n if (fieldIsValid(field, 'in')) {\n value = listsAsArrays\n ? keyValue\n : joinWith(\n keyValue.map(v => `${v}`),\n ','\n );\n return { field, operator: 'in', value };\n }\n } else if (mdbOperator === '$nin' && Array.isArray(keyValue) && fieldIsValid(field, 'notIn')) {\n value = listsAsArrays\n ? keyValue\n : joinWith(\n keyValue.map(v => `${v}`),\n ','\n );\n return { field, operator: 'notIn', value };\n }\n\n return false;\n }\n\n function processMongoDbQueryObjectKey(\n key: string,\n // oxlint-disable-next-line typescript/no-explicit-any\n keyValue: any\n ): DefaultRuleType | DefaultRuleGroupType | false {\n let field = '';\n\n // istanbul ignore else\n if (key === '$and') {\n if (!Array.isArray(keyValue) || keyValue.length === 0 || !keyValue.every(v => isPojo(v))) {\n return false;\n }\n\n // Check if this should result in a \"between\" clause\n if (keyValue.length === 2 && keyValue.every(kv => objectKeys(kv).length === 1)) {\n const [rule1, rule2] = keyValue;\n const [ruleKey1, ruleKey2] = keyValue.map(kv => objectKeys(kv)[0]);\n if (\n ruleKey1 === ruleKey2 &&\n isPojo(rule1[ruleKey1]) &&\n objectKeys(rule1[ruleKey1]).length === 1 &&\n isPojo(rule2[ruleKey2]) &&\n objectKeys(rule2[ruleKey2]).length === 1 &&\n (('$gte' in rule1[ruleKey1] &&\n '$lte' in rule2[ruleKey2] &&\n rule2[ruleKey2].$lte >= rule1[ruleKey1].$gte) ||\n ('$lte' in rule1[ruleKey1] &&\n '$gte' in rule2[ruleKey2] &&\n rule1[ruleKey1].$lte >= rule2[ruleKey2].$gte))\n ) {\n const [val1, val2] = [\n rule1[ruleKey1].$gte ?? rule1[ruleKey1].$lte,\n rule2[ruleKey2].$lte ?? rule2[ruleKey2].$gte,\n ];\n let value = listsAsArrays ? [val1, val2] : joinWith([val1, val2], ',');\n if (val1 > val2) {\n value = listsAsArrays ? [val2, val1] : joinWith([val2, val1], ',');\n }\n return { field: ruleKey1, operator: 'between', value };\n }\n }\n\n const rules = keyValue.map(l => processMongoDbQueryObject(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[];\n\n return rules.length > 0 ? { combinator: 'and', rules } : false;\n } else if (key === '$or') {\n if (!Array.isArray(keyValue) || keyValue.length === 0 || !keyValue.every(v => isPojo(v))) {\n return false;\n }\n\n // Check if this should result in \"notBetween\"\n if (keyValue.length === 2 && keyValue.every(kv => objectKeys(kv).length === 1)) {\n const [rule1, rule2] = keyValue;\n const [ruleKey1, ruleKey2] = keyValue.map(kv => objectKeys(kv)[0]);\n if (\n ruleKey1 === ruleKey2 &&\n isPojo(rule1[ruleKey1]) &&\n objectKeys(rule1[ruleKey1]).length === 1 &&\n isPojo(rule2[ruleKey2]) &&\n objectKeys(rule2[ruleKey2]).length === 1 &&\n (('$gt' in rule1[ruleKey1] &&\n '$lt' in rule2[ruleKey2] &&\n rule1[ruleKey1].$gt >= rule2[ruleKey2].$lt) ||\n ('$lt' in rule1[ruleKey1] &&\n '$gt' in rule2[ruleKey2] &&\n rule2[ruleKey2].$gt >= rule1[ruleKey1].$lt))\n ) {\n const [val1, val2] = [\n rule1[ruleKey1].$gt ?? rule1[ruleKey1].$lt,\n rule2[ruleKey2].$lt ?? rule2[ruleKey2].$gt,\n ];\n let value = listsAsArrays ? [val1, val2] : `${val1},${val2}`;\n if (val1 > val2) {\n value = listsAsArrays ? [val2, val1] : `${val2},${val1}`;\n }\n return { field: ruleKey1, operator: 'notBetween', value };\n }\n }\n\n const rules = keyValue.map(l => processMongoDbQueryObject(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[];\n\n return rules.length > 0 ? { combinator: 'or', rules } : false;\n } else if (key === '$not' && isPojo(keyValue)) {\n const ruleOrGroup = processMongoDbQueryObject(keyValue);\n if (ruleOrGroup) {\n if (isRuleGroupType(ruleOrGroup)) {\n return ruleOrGroup.not\n ? { combinator: 'and', rules: [ruleOrGroup], not: true }\n : { ...ruleOrGroup, not: true };\n }\n return preventOperatorNegation\n ? { combinator: 'and', rules: [ruleOrGroup], not: true }\n : { ...ruleOrGroup, operator: defaultOperatorNegationMap[ruleOrGroup.operator] };\n }\n return false;\n } else if (key === '$expr') {\n const op = objectKeys(keyValue)[0] as MongoDbSupportedOperators;\n if (\n /^\\$(eq|gte?|lte?|n?in)$/.test(op) &&\n Array.isArray(keyValue[op]) &&\n keyValue[op].length === 2 &&\n typeof keyValue[op][0] === 'string' &&\n keyValue[op][0].startsWith('$')\n ) {\n field = keyValue[op][0].replace(/^\\$/, '');\n const val = keyValue[op][1];\n if (\n (typeof val === 'string' && val.startsWith('$')) ||\n (Array.isArray(val) &&\n val.every(v => typeof v === 'string') &&\n val.every(v => v.startsWith('$')))\n ) {\n const valForProcessing = Array.isArray(val)\n ? val.map(v => v.replace(/^\\$/, ''))\n : val.replace(/^\\$/, '');\n const tempRule = processMongoDbQueryBooleanOperator(field, op, valForProcessing);\n if (tempRule) {\n if (\n typeof tempRule.value === 'string' &&\n !fieldIsValid(field, tempRule.operator, tempRule.value)\n ) {\n return false;\n }\n return { ...tempRule, valueSource: 'field' };\n }\n }\n return processMongoDbQueryBooleanOperator(field, op, keyValue[op][1]);\n }\n } else if (/^[^$]/.test(key)) {\n field = key;\n\n if (isPrimitive(keyValue)) {\n if (fieldIsValid(field, '=')) {\n return { field, operator: '=', value: keyValue };\n }\n } else if (keyValue === null) {\n if (fieldIsValid(field, 'null')) {\n return { field, operator: 'null', value: keyValue };\n }\n } else if (isPojo(keyValue)) {\n let betweenRule: DefaultRuleType | false = false;\n let notRule: DefaultRuleType | DefaultRuleGroupType | false = false;\n const additionalOpKeys = objectKeys(additionalOperators).map(o => o.replace(/^\\$/, ''));\n const allOps = ['eq', 'ne', 'gte?', 'lte?', 'n?in', 'regex', 'not', ...additionalOpKeys];\n const acceptedOpsRegExp = new RegExp(`^\\\\$(${allOps.join('|')})$`);\n\n const operators = objectKeys<Record<MongoDbSupportedOperators, unknown>>(keyValue)\n .filter(o => acceptedOpsRegExp.test(o))\n // oxlint-disable-next-line no-array-sort\n .sort();\n\n if (operators.length === 0) {\n return false;\n }\n\n if ('$not' in keyValue && isPojo(keyValue.$not)) {\n const invertedNotRule = processMongoDbQueryObject({ [field]: keyValue.$not });\n if (invertedNotRule) {\n if (isRuleGroupType(invertedNotRule)) {\n notRule = { ...invertedNotRule, not: true };\n } else {\n notRule = preventOperatorNegation\n ? { combinator: 'and', rules: [invertedNotRule], not: true }\n : {\n ...invertedNotRule,\n operator: defaultOperatorNegationMap[invertedNotRule.operator],\n };\n }\n }\n }\n\n if ('$gte' in keyValue && '$lte' in keyValue) {\n // This is (at least) a compact \"between\" clause\n betweenRule = {\n field,\n operator: 'between',\n value: listsAsArrays\n ? [keyValue.$gte, keyValue.$lte]\n : `${keyValue.$gte},${keyValue.$lte}`,\n };\n }\n\n const rules = operators\n // filter out $not\n .filter(op => !(notRule && op === '$not'))\n // filter out $gte and $lte if they were both present\n .filter(op => !(betweenRule && (op === '$gte' || op === '$lte')))\n .map(op =>\n op in additionalOperators && typeof additionalOperators[op] === 'function'\n ? additionalOperators[op](field, op, keyValue[op], otherOptions)\n : processMongoDbQueryBooleanOperator(field, op, keyValue[op])\n )\n .filter(Boolean) as (DefaultRuleGroupType | DefaultRuleType)[];\n\n if (notRule) {\n rules.unshift(notRule);\n }\n\n if (betweenRule) {\n rules.unshift(betweenRule);\n }\n\n if (rules.length === 0) {\n return false;\n }\n if (rules.length === 1) {\n return rules[0];\n }\n return { combinator: 'and', rules };\n }\n }\n\n return false;\n }\n\n function processMongoDbQueryObject(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbQueryObject: Record<string, any>\n ): DefaultRuleGroupType | DefaultRuleType | false {\n const rules = objectKeys(mongoDbQueryObject)\n .map(k => processMongoDbQueryObjectKey(k, mongoDbQueryObject[k]))\n .filter(Boolean) as DefaultRuleGroupType[];\n return rules.length === 1 ? rules[0] : rules.length > 1 ? { combinator: 'and', rules } : false;\n }\n\n const prepare = options.generateIDs ? prepareRuleGroup : <T>(g: T) => g;\n\n let mongoDbPOJO = mongoDbRules;\n if (typeof mongoDbRules === 'string') {\n try {\n mongoDbPOJO = JSON.parse(mongoDbRules);\n } catch {\n return prepare(emptyRuleGroup);\n }\n }\n\n // Bail if the mongoDbPOJO is not actually a POJO\n if (!isPojo(mongoDbPOJO)) {\n return prepare(emptyRuleGroup);\n }\n\n const result = processMongoDbQueryObject(mongoDbPOJO);\n const finalQuery: DefaultRuleGroupType = result\n ? isRuleGroupType(result)\n ? result\n : { combinator: 'and', rules: [result] }\n : emptyRuleGroup;\n return prepare(\n options.independentCombinators ? convertToIC<DefaultRuleGroupTypeIC>(finalQuery) : finalQuery\n );\n}\n\nexport { parseMongoDB };\n"],"mappings":";;;;;;AAGA,MAAa,eAAe,OAC1B,OAAO,OAAO,WAAW,KAAK,GAAG;AAGnC,MAAa,eAAe,MAC1B,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM;AAEjE,MAAaA,0BAET;CACF,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACP;;;;AC8DD,MAAMC,iBAAuC;CAAE,YAAY;CAAO,OAAO,EAAE;CAAE;AAiC7E,SAAS,aAEP,cACA,UAA+B,EAAE,EACR;CACzB,MAAM,gBAAgB,CAAC,CAAC,QAAQ;CAChC,MAAM,aAAa,eAAe,QAAQ,OAAO;CACjD,MAAM,kBAAkB,QAAQ;CAChC,MAAM,sBAAsB,QAAQ,uBAAuB,EAAE;CAC7D,MAAM,0BAA0B,CAAC,CAAC,QAAQ;CAC1C,MAAM,EAAE,qBAAqB,KAAK,GAAG,iBAAiB;CAEtD,MAAM,gBACJ,WACA,UACA,yBAEA,iBAAiB;EACf;EACA;EACA;EACA;EACA;EACD,CAAC;CAEJ,SAAS,mCACP,OACA,aAEA,UACyB;EACzB,IAAIC,WAAgC;EAEpC,IAAIC,QAAa;;AAGjB,MACE,gBAAgB,SAChB,gBAAgB,SAChB,gBAAgB,SAChB,gBAAgB,UAChB,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EP,oBACgD;EAChD,MAAM,QAAQ,WAAW,mBAAmB,CACzC,KAAI,MAAK,6BAA6B,GAAG,mBAAmB,GAAG,CAAC,CAChE,OAAO,QAAQ;AAClB,SAAO,MAAM,WAAW,IAAI,MAAM,KAAK,MAAM,SAAS,IAAI;GAAE,YAAY;GAAO;GAAO,GAAG;;CAG3F,MAAM,UAAU,QAAQ,cAAc,oBAAuB,MAAS;CAEtE,IAAI,cAAc;AAClB,KAAI,OAAO,iBAAiB,SAC1B,KAAI;AACF,gBAAc,KAAK,MAAM,aAAa;SAChC;AACN,SAAO,QAAQ,eAAe;;AAKlC,KAAI,CAAC,OAAO,YAAY,CACtB,QAAO,QAAQ,eAAe;CAGhC,MAAM,SAAS,0BAA0B,YAAY;CACrD,MAAMC,aAAmC,SACrC,gBAAgB,OAAO,GACrB,SACA;EAAE,YAAY;EAAO,OAAO,CAAC,OAAO;EAAE,GACxC;AACJ,QAAO,QACL,QAAQ,yBAAyB,YAAoC,WAAW,GAAG,WACpF"}
|
|
1
|
+
{"version":3,"file":"parseMongoDB.mjs","names":[],"sources":["../src/utils/parseMongoDB/utils.ts","../src/utils/parseMongoDB/parseMongoDB.ts"],"sourcesContent":["import type { DefaultOperatorName } from '../../types';\nimport type { MongoDbSupportedOperators } from './types';\n\nexport const getRegExStr = (re: string | RegExp): string =>\n typeof re === 'string' ? re : re.source;\n\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isPrimitive = (v: any): v is string | number | boolean =>\n typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean';\n\nexport const mongoDbToRqbOperatorMap: Partial<\n Record<MongoDbSupportedOperators, DefaultOperatorName>\n> = {\n $eq: '=',\n $ne: '!=',\n $gt: '>',\n $gte: '>=',\n $lt: '<',\n $lte: '<=',\n} satisfies Partial<Record<MongoDbSupportedOperators, DefaultOperatorName>>;\n","import type { Except } from 'type-fest';\nimport { defaultOperatorNegationMap } from '../../defaults';\nimport type {\n DefaultOperatorName,\n DefaultRuleGroupType,\n DefaultRuleGroupTypeAny,\n DefaultRuleGroupTypeIC,\n DefaultRuleType,\n RuleGroupType,\n RuleType,\n} from '../../types';\nimport type { ParserCommonOptions } from '../../types/import';\nimport { joinWith } from '../arrayUtils';\nimport { convertToIC } from '../convertQuery';\nimport { isRuleGroupType } from '../isRuleGroup';\nimport { isPojo } from '../misc';\nimport { objectKeys } from '../objectUtils';\nimport { fieldIsValidUtil, getFieldsArray } from '../parserUtils';\nimport { prepareRuleGroup } from '../prepareQueryObjects';\nimport type { MongoDbSupportedOperators } from './types';\nimport { getRegExStr, isPrimitive, mongoDbToRqbOperatorMap } from './utils';\n\n/**\n * Options object for {@link parseMongoDB}.\n */\nexport interface ParseMongoDbOptions extends ParserCommonOptions {\n /**\n * When `true`, MongoDB rules in the form of `{ fieldName: { $not: { <...rule> } } }`\n * will be parsed into a rule group with the `not` attribute set to `true`. By default\n * (i.e., when this attribute is `false`), such \"`$not`\" rules will be parsed into a\n * rule with a negated operator.\n *\n * For example, with `preventOperatorNegation` set to `true`, a MongoDB rule like this...\n *\n * ```ts\n * { fieldName: { $not: { $eq: 1 } } }\n * ```\n *\n * ...would yield a rule group like this:\n *\n * ```ts\n * {\n * combinator: 'and',\n * not: true,\n * rules: [{ field: 'fieldName', operator: '=', value: 1 }]\n * }\n * ```\n *\n * By default, the same MongoDB rule would yield a rule like this:\n *\n * ```ts\n * { field: 'fieldName', operator: '!=', value: 1 }\n * // negated operator ^\n * ```\n *\n * @default false\n */\n preventOperatorNegation?: boolean;\n /**\n * Map of additional operators to their respective processing functions. Operators\n * must begin with `\"$\"`. Processing functions should return either a {@link index!RuleType RuleType}\n * or {@link index!RuleGroupType RuleGroupType}.\n *\n * (The functions should _not_ return {@link index!RuleGroupTypeIC RuleGroupTypeIC}, even if using independent\n * combinators. If the `independentCombinators` option is `true`, `parseMongoDB`\n * will convert the final query to {@link index!RuleGroupTypeIC RuleGroupTypeIC} before returning it.)\n *\n * @default {}\n */\n additionalOperators?: Record<\n `$${string}`,\n (\n field: string,\n operator: string,\n // oxlint-disable-next-line typescript/no-explicit-any\n value: any,\n options: ParserCommonOptions\n ) => RuleType | RuleGroupType\n >;\n}\n\nconst emptyRuleGroup: DefaultRuleGroupType = { combinator: 'and', rules: [] };\n\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nfunction parseMongoDB(mongoDbRules: string | Record<string, any>): DefaultRuleGroupType;\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).\n */\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: Except<ParseMongoDbOptions, 'independentCombinators'> & {\n independentCombinators?: false;\n }\n): DefaultRuleGroupType;\n/**\n * Converts a MongoDB query object or parseable string into a query suitable\n * for the {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props\n * ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).\n */\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: Except<ParseMongoDbOptions, 'independentCombinators'> & {\n independentCombinators: true;\n }\n): DefaultRuleGroupTypeIC;\nfunction parseMongoDB(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbRules: string | Record<string, any>,\n options: ParseMongoDbOptions = {}\n): DefaultRuleGroupTypeAny {\n const listsAsArrays = !!options.listsAsArrays;\n const fieldsFlat = getFieldsArray(options.fields);\n const getValueSources = options.getValueSources;\n const additionalOperators = options.additionalOperators ?? {};\n const preventOperatorNegation = !!options.preventOperatorNegation;\n const { additionalOperators: _ao, ...otherOptions } = options;\n\n const fieldIsValid = (\n fieldName: string,\n operator: DefaultOperatorName,\n subordinateFieldName?: string\n ) =>\n fieldIsValidUtil({\n fieldName,\n fieldsFlat,\n operator,\n subordinateFieldName,\n getValueSources,\n });\n\n function processMongoDbQueryBooleanOperator(\n field: string,\n mdbOperator: MongoDbSupportedOperators,\n // oxlint-disable-next-line typescript/no-explicit-any\n keyValue: any\n ): DefaultRuleType | false {\n let operator: DefaultOperatorName = '=';\n // oxlint-disable-next-line typescript/no-explicit-any\n let value: any = '';\n\n // istanbul ignore else\n if (\n mdbOperator === '$eq' ||\n mdbOperator === '$ne' ||\n mdbOperator === '$gt' ||\n mdbOperator === '$gte' ||\n mdbOperator === '$lt' ||\n mdbOperator === '$lte'\n ) {\n if (mdbOperator === '$ne' && keyValue === null) {\n if (fieldIsValid(field, 'notNull')) {\n return { field, operator: 'notNull', value: null };\n }\n } else {\n operator = mongoDbToRqbOperatorMap[mdbOperator]!;\n if (fieldIsValid(field, operator)) {\n return { field, operator, value: keyValue };\n }\n }\n } else if (mdbOperator === '$regex' && /^[^$^]$|^[^^].*[^$]$/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'contains')) {\n return {\n field,\n operator: 'contains',\n value: getRegExStr(keyValue),\n };\n }\n } else if (mdbOperator === '$regex' && /^\\^.*[^$]/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'beginsWith')) {\n return {\n field,\n operator: 'beginsWith',\n value: getRegExStr(keyValue).replace(/^\\^/, ''),\n };\n }\n } else if (mdbOperator === '$regex' && /[^^].*\\$/.test(getRegExStr(keyValue))) {\n if (fieldIsValid(field, 'endsWith')) {\n return {\n field,\n operator: 'endsWith',\n value: getRegExStr(keyValue).replace(/\\$$/, ''),\n };\n }\n } else if (mdbOperator === '$in' && Array.isArray(keyValue)) {\n if (fieldIsValid(field, 'in')) {\n value = listsAsArrays\n ? keyValue\n : joinWith(\n keyValue.map(v => `${v}`),\n ','\n );\n return { field, operator: 'in', value };\n }\n } else if (mdbOperator === '$nin' && Array.isArray(keyValue) && fieldIsValid(field, 'notIn')) {\n value = listsAsArrays\n ? keyValue\n : joinWith(\n keyValue.map(v => `${v}`),\n ','\n );\n return { field, operator: 'notIn', value };\n }\n\n return false;\n }\n\n function processMongoDbQueryObjectKey(\n key: string,\n // oxlint-disable-next-line typescript/no-explicit-any\n keyValue: any\n ): DefaultRuleType | DefaultRuleGroupType | false {\n let field = '';\n\n // istanbul ignore else\n if (key === '$and') {\n if (!Array.isArray(keyValue) || keyValue.length === 0 || !keyValue.every(v => isPojo(v))) {\n return false;\n }\n\n // Check if this should result in a \"between\" clause\n if (keyValue.length === 2 && keyValue.every(kv => objectKeys(kv).length === 1)) {\n const [rule1, rule2] = keyValue;\n const [ruleKey1, ruleKey2] = keyValue.map(kv => objectKeys(kv)[0]);\n if (\n ruleKey1 === ruleKey2 &&\n isPojo(rule1[ruleKey1]) &&\n objectKeys(rule1[ruleKey1]).length === 1 &&\n isPojo(rule2[ruleKey2]) &&\n objectKeys(rule2[ruleKey2]).length === 1 &&\n (('$gte' in rule1[ruleKey1] &&\n '$lte' in rule2[ruleKey2] &&\n rule2[ruleKey2].$lte >= rule1[ruleKey1].$gte) ||\n ('$lte' in rule1[ruleKey1] &&\n '$gte' in rule2[ruleKey2] &&\n rule1[ruleKey1].$lte >= rule2[ruleKey2].$gte))\n ) {\n const [val1, val2] = [\n rule1[ruleKey1].$gte ?? rule1[ruleKey1].$lte,\n rule2[ruleKey2].$lte ?? rule2[ruleKey2].$gte,\n ];\n let value = listsAsArrays ? [val1, val2] : joinWith([val1, val2], ',');\n if (val1 > val2) {\n value = listsAsArrays ? [val2, val1] : joinWith([val2, val1], ',');\n }\n return { field: ruleKey1, operator: 'between', value };\n }\n }\n\n const rules = keyValue.map(l => processMongoDbQueryObject(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[];\n\n return rules.length > 0 ? { combinator: 'and', rules } : false;\n } else if (key === '$or') {\n if (!Array.isArray(keyValue) || keyValue.length === 0 || !keyValue.every(v => isPojo(v))) {\n return false;\n }\n\n // Check if this should result in \"notBetween\"\n if (keyValue.length === 2 && keyValue.every(kv => objectKeys(kv).length === 1)) {\n const [rule1, rule2] = keyValue;\n const [ruleKey1, ruleKey2] = keyValue.map(kv => objectKeys(kv)[0]);\n if (\n ruleKey1 === ruleKey2 &&\n isPojo(rule1[ruleKey1]) &&\n objectKeys(rule1[ruleKey1]).length === 1 &&\n isPojo(rule2[ruleKey2]) &&\n objectKeys(rule2[ruleKey2]).length === 1 &&\n (('$gt' in rule1[ruleKey1] &&\n '$lt' in rule2[ruleKey2] &&\n rule1[ruleKey1].$gt >= rule2[ruleKey2].$lt) ||\n ('$lt' in rule1[ruleKey1] &&\n '$gt' in rule2[ruleKey2] &&\n rule2[ruleKey2].$gt >= rule1[ruleKey1].$lt))\n ) {\n const [val1, val2] = [\n rule1[ruleKey1].$gt ?? rule1[ruleKey1].$lt,\n rule2[ruleKey2].$lt ?? rule2[ruleKey2].$gt,\n ];\n let value = listsAsArrays ? [val1, val2] : `${val1},${val2}`;\n if (val1 > val2) {\n value = listsAsArrays ? [val2, val1] : `${val2},${val1}`;\n }\n return { field: ruleKey1, operator: 'notBetween', value };\n }\n }\n\n const rules = keyValue.map(l => processMongoDbQueryObject(l)).filter(Boolean) as (\n | DefaultRuleType\n | DefaultRuleGroupType\n )[];\n\n return rules.length > 0 ? { combinator: 'or', rules } : false;\n } else if (key === '$not' && isPojo(keyValue)) {\n const ruleOrGroup = processMongoDbQueryObject(keyValue);\n if (ruleOrGroup) {\n if (isRuleGroupType(ruleOrGroup)) {\n return ruleOrGroup.not\n ? { combinator: 'and', rules: [ruleOrGroup], not: true }\n : { ...ruleOrGroup, not: true };\n }\n return preventOperatorNegation\n ? { combinator: 'and', rules: [ruleOrGroup], not: true }\n : { ...ruleOrGroup, operator: defaultOperatorNegationMap[ruleOrGroup.operator] };\n }\n return false;\n } else if (key === '$expr') {\n const op = objectKeys(keyValue)[0] as MongoDbSupportedOperators;\n if (\n /^\\$(eq|gte?|lte?|n?in)$/.test(op) &&\n Array.isArray(keyValue[op]) &&\n keyValue[op].length === 2 &&\n typeof keyValue[op][0] === 'string' &&\n keyValue[op][0].startsWith('$')\n ) {\n field = keyValue[op][0].replace(/^\\$/, '');\n const val = keyValue[op][1];\n if (\n (typeof val === 'string' && val.startsWith('$')) ||\n (Array.isArray(val) &&\n val.every(v => typeof v === 'string') &&\n val.every(v => v.startsWith('$')))\n ) {\n const valForProcessing = Array.isArray(val)\n ? val.map(v => v.replace(/^\\$/, ''))\n : val.replace(/^\\$/, '');\n const tempRule = processMongoDbQueryBooleanOperator(field, op, valForProcessing);\n if (tempRule) {\n if (\n typeof tempRule.value === 'string' &&\n !fieldIsValid(field, tempRule.operator, tempRule.value)\n ) {\n return false;\n }\n return { ...tempRule, valueSource: 'field' };\n }\n }\n return processMongoDbQueryBooleanOperator(field, op, keyValue[op][1]);\n }\n } else if (/^[^$]/.test(key)) {\n field = key;\n\n if (isPrimitive(keyValue)) {\n if (fieldIsValid(field, '=')) {\n return { field, operator: '=', value: keyValue };\n }\n } else if (keyValue === null) {\n if (fieldIsValid(field, 'null')) {\n return { field, operator: 'null', value: keyValue };\n }\n } else if (isPojo(keyValue)) {\n let betweenRule: DefaultRuleType | false = false;\n let notRule: DefaultRuleType | DefaultRuleGroupType | false = false;\n const additionalOpKeys = objectKeys(additionalOperators).map(o => o.replace(/^\\$/, ''));\n const allOps = ['eq', 'ne', 'gte?', 'lte?', 'n?in', 'regex', 'not', ...additionalOpKeys];\n const acceptedOpsRegExp = new RegExp(`^\\\\$(${allOps.join('|')})$`);\n\n const operators = objectKeys<Record<MongoDbSupportedOperators, unknown>>(keyValue)\n .filter(o => acceptedOpsRegExp.test(o))\n // oxlint-disable-next-line no-array-sort\n .sort();\n\n if (operators.length === 0) {\n return false;\n }\n\n if ('$not' in keyValue && isPojo(keyValue.$not)) {\n const invertedNotRule = processMongoDbQueryObject({ [field]: keyValue.$not });\n if (invertedNotRule) {\n if (isRuleGroupType(invertedNotRule)) {\n notRule = { ...invertedNotRule, not: true };\n } else {\n notRule = preventOperatorNegation\n ? { combinator: 'and', rules: [invertedNotRule], not: true }\n : {\n ...invertedNotRule,\n operator: defaultOperatorNegationMap[invertedNotRule.operator],\n };\n }\n }\n }\n\n if ('$gte' in keyValue && '$lte' in keyValue) {\n // This is (at least) a compact \"between\" clause\n betweenRule = {\n field,\n operator: 'between',\n value: listsAsArrays\n ? [keyValue.$gte, keyValue.$lte]\n : `${keyValue.$gte},${keyValue.$lte}`,\n };\n }\n\n const rules = operators\n // filter out $not\n .filter(op => !(notRule && op === '$not'))\n // filter out $gte and $lte if they were both present\n .filter(op => !(betweenRule && (op === '$gte' || op === '$lte')))\n .map(op =>\n op in additionalOperators && typeof additionalOperators[op] === 'function'\n ? additionalOperators[op](field, op, keyValue[op], otherOptions)\n : processMongoDbQueryBooleanOperator(field, op, keyValue[op])\n )\n .filter(Boolean) as (DefaultRuleGroupType | DefaultRuleType)[];\n\n if (notRule) {\n rules.unshift(notRule);\n }\n\n if (betweenRule) {\n rules.unshift(betweenRule);\n }\n\n if (rules.length === 0) {\n return false;\n }\n if (rules.length === 1) {\n return rules[0];\n }\n return { combinator: 'and', rules };\n }\n }\n\n return false;\n }\n\n function processMongoDbQueryObject(\n // oxlint-disable-next-line typescript/no-explicit-any\n mongoDbQueryObject: Record<string, any>\n ): DefaultRuleGroupType | DefaultRuleType | false {\n const rules = objectKeys(mongoDbQueryObject)\n .map(k => processMongoDbQueryObjectKey(k, mongoDbQueryObject[k]))\n .filter(Boolean) as DefaultRuleGroupType[];\n return rules.length === 1 ? rules[0] : rules.length > 1 ? { combinator: 'and', rules } : false;\n }\n\n const prepare = options.generateIDs ? prepareRuleGroup : <T>(g: T) => g;\n\n let mongoDbPOJO = mongoDbRules;\n if (typeof mongoDbRules === 'string') {\n try {\n mongoDbPOJO = JSON.parse(mongoDbRules);\n } catch {\n return prepare(emptyRuleGroup);\n }\n }\n\n // Bail if the mongoDbPOJO is not actually a POJO\n if (!isPojo(mongoDbPOJO)) {\n return prepare(emptyRuleGroup);\n }\n\n const result = processMongoDbQueryObject(mongoDbPOJO);\n const finalQuery: DefaultRuleGroupType = result\n ? isRuleGroupType(result)\n ? result\n : { combinator: 'and', rules: [result] }\n : emptyRuleGroup;\n return prepare(\n options.independentCombinators ? convertToIC<DefaultRuleGroupTypeIC>(finalQuery) : finalQuery\n );\n}\n\nexport { parseMongoDB };\n"],"mappings":";;;;;AAGA,MAAa,eAAe,OAC1B,OAAO,OAAO,WAAW,KAAK,GAAG;AAGnC,MAAa,eAAe,MAC1B,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,OAAO,MAAM;AAEjE,MAAa,0BAET;CACF,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACP;;;AC8DD,MAAM,iBAAuC;CAAE,YAAY;CAAO,OAAO,EAAE;CAAE;AAiC7E,SAAS,aAEP,cACA,UAA+B,EAAE,EACR;CACzB,MAAM,gBAAgB,CAAC,CAAC,QAAQ;CAChC,MAAM,aAAa,eAAe,QAAQ,OAAO;CACjD,MAAM,kBAAkB,QAAQ;CAChC,MAAM,sBAAsB,QAAQ,uBAAuB,EAAE;CAC7D,MAAM,0BAA0B,CAAC,CAAC,QAAQ;CAC1C,MAAM,EAAE,qBAAqB,KAAK,GAAG,iBAAiB;CAEtD,MAAM,gBACJ,WACA,UACA,yBAEA,iBAAiB;EACf;EACA;EACA;EACA;EACA;EACD,CAAC;CAEJ,SAAS,mCACP,OACA,aAEA,UACyB;EACzB,IAAI,WAAgC;EAEpC,IAAI,QAAa;;AAGjB,MACE,gBAAgB,SAChB,gBAAgB,SAChB,gBAAgB,SAChB,gBAAgB,UAChB,gBAAgB,SAChB,gBAAgB,OAEhB,KAAI,gBAAgB,SAAS,aAAa;OACpC,aAAa,OAAO,UAAU,CAChC,QAAO;IAAE;IAAO,UAAU;IAAW,OAAO;IAAM;SAE/C;AACL,cAAW,wBAAwB;AACnC,OAAI,a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MAAM,UAAU,QAAQ,cAAc,oBAAuB,MAAS;CAEtE,IAAI,cAAc;AAClB,KAAI,OAAO,iBAAiB,SAC1B,KAAI;AACF,gBAAc,KAAK,MAAM,aAAa;SAChC;AACN,SAAO,QAAQ,eAAe;;AAKlC,KAAI,CAAC,OAAO,YAAY,CACtB,QAAO,QAAQ,eAAe;CAGhC,MAAM,SAAS,0BAA0B,YAAY;CACrD,MAAM,aAAmC,SACrC,gBAAgB,OAAO,GACrB,SACA;EAAE,YAAY;EAAO,OAAO,CAAC,OAAO;EAAE,GACxC;AACJ,QAAO,QACL,QAAQ,yBAAyB,YAAoC,WAAW,GAAG,WACpF"}
|
package/dist/parseSQL.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { C as Except, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType } from "./basic-
|
|
2
|
-
import { t as ParserCommonOptions } from "./import-
|
|
1
|
+
import { C as Except, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType } from "./basic-CNIjb6rI.mjs";
|
|
2
|
+
import { t as ParserCommonOptions } from "./import-Bltb2mT4.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/parseSQL/parseSQL.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Options object for {@link parseSQL}.
|
|
8
7
|
*/
|
package/dist/parseSQL.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { C as Except, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType } from "./basic-
|
|
2
|
-
import { t as ParserCommonOptions } from "./import-
|
|
1
|
+
import { C as Except, d as DefaultRuleGroupTypeIC, g as DefaultRuleGroupType } from "./basic-BXJVfD0P.js";
|
|
2
|
+
import { t as ParserCommonOptions } from "./import-B5Iq8XmL.js";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/parseSQL/parseSQL.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Options object for {@link parseSQL}.
|
|
8
7
|
*/
|
package/dist/parseSQL.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const require_utils = require(
|
|
3
|
-
const require_isRuleGroup = require(
|
|
4
|
-
const require_prepareQueryObjects = require(
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils = require("./utils-EsYRkPtf.js");
|
|
3
|
+
const require_isRuleGroup = require("./isRuleGroup-BCwaLzDj.js");
|
|
4
|
+
const require_prepareQueryObjects = require("./prepareQueryObjects-Dc8rqsYM.js");
|
|
5
|
+
require("./parseJSONata.js");
|
|
5
6
|
let _ts_jison_parser = require("@ts-jison/parser");
|
|
6
7
|
let _ts_jison_lexer = require("@ts-jison/lexer");
|
|
7
|
-
|
|
8
8
|
//#region src/utils/parseSQL/sqlParser.ts
|
|
9
9
|
/**
|
|
10
10
|
* parser generated by @ts-jison/parser-generator 0.4.1-alpha.2
|
|
@@ -5883,7 +5883,6 @@ var SQLLexer = class extends _ts_jison_lexer.JisonLexer {
|
|
|
5883
5883
|
}
|
|
5884
5884
|
}
|
|
5885
5885
|
};
|
|
5886
|
-
|
|
5887
5886
|
//#endregion
|
|
5888
5887
|
//#region src/utils/parseSQL/utils.ts
|
|
5889
5888
|
const isSQLLiteralValue = (v) => v?.type === "String" || v?.type === "Number" || v?.type === "Boolean";
|
|
@@ -6026,7 +6025,6 @@ const generateMixedAndXorOrList = (expr) => {
|
|
|
6026
6025
|
else returnArray.expressions.push(o);
|
|
6027
6026
|
return returnArray;
|
|
6028
6027
|
};
|
|
6029
|
-
|
|
6030
6028
|
//#endregion
|
|
6031
6029
|
//#region src/utils/parseSQL/parseSQL.ts
|
|
6032
6030
|
function parseSQL(sql, options = {}) {
|
|
@@ -6085,12 +6083,12 @@ function parseSQL(sql, options = {}) {
|
|
|
6085
6083
|
case "OrExpression":
|
|
6086
6084
|
case "XorExpression": {
|
|
6087
6085
|
if (ic) {
|
|
6088
|
-
const rules
|
|
6086
|
+
const rules = generateFlatAndOrList(expr).map((v) => {
|
|
6089
6087
|
if (typeof v === "string") return v;
|
|
6090
6088
|
return processSQLExpression(v);
|
|
6091
6089
|
});
|
|
6092
|
-
if (rules
|
|
6093
|
-
return { rules
|
|
6090
|
+
if (rules.includes(null)) return null;
|
|
6091
|
+
return { rules };
|
|
6094
6092
|
}
|
|
6095
6093
|
const andXorOrList = generateMixedAndXorOrList(expr);
|
|
6096
6094
|
const { combinator } = andXorOrList;
|
|
@@ -6273,7 +6271,7 @@ function parseSQL(sql, options = {}) {
|
|
|
6273
6271
|
...ic ? {} : { combinator: "and" }
|
|
6274
6272
|
});
|
|
6275
6273
|
}
|
|
6276
|
-
|
|
6277
6274
|
//#endregion
|
|
6278
6275
|
exports.parseSQL = parseSQL;
|
|
6276
|
+
|
|
6279
6277
|
//# sourceMappingURL=parseSQL.js.map
|