@react-querybuilder/core 8.16.0 → 8.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +43 -4
- package/dist/cjs/react-querybuilder_core.cjs.development.js +182 -18
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +43 -4
- 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-BeJJH9BI.mjs.map +1 -1
- package/dist/convertQuery-Lx2HQa0m.js.map +1 -1
- package/dist/formatQuery.d.mts +42 -3
- package/dist/formatQuery.d.ts +42 -3
- package/dist/formatQuery.js +182 -18
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +180 -19
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-BHlzBLM_.d.mts → import-BXXgiPlr.d.mts} +2 -2
- package/dist/{import-C6imciDf.d.ts → import-DqzM2MBd.d.ts} +2 -2
- package/dist/{index-D-Iej37L.d.mts → index-CR-tk4Ci.d.mts} +3 -3
- package/dist/{index-Cjapnb-H.d.ts → index-NSVgGj45.d.ts} +3 -3
- package/dist/objectUtils-Bzug_QfX.js.map +1 -1
- package/dist/objectUtils-D96eEEzL.mjs.map +1 -1
- package/dist/parseCEL.d.mts +2 -2
- package/dist/parseCEL.d.ts +2 -2
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseCypher.d.mts +1 -1
- package/dist/parseCypher.d.ts +1 -1
- package/dist/parseCypher.js.map +1 -1
- package/dist/parseCypher.mjs.map +1 -1
- package/dist/parseGremlin.d.mts +1 -1
- package/dist/parseGremlin.d.ts +1 -1
- package/dist/parseGremlin.js.map +1 -1
- package/dist/parseGremlin.mjs.map +1 -1
- package/dist/parseJSONata.d.mts +2 -2
- package/dist/parseJSONata.d.ts +2 -2
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs.map +1 -1
- package/dist/parseJsonLogic.d.mts +2 -2
- package/dist/parseJsonLogic.d.ts +2 -2
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.d.mts +2 -2
- package/dist/parseMongoDB.d.ts +2 -2
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/parseSPARQL.d.mts +1 -1
- package/dist/parseSPARQL.d.ts +1 -1
- package/dist/parseSPARQL.js.map +1 -1
- package/dist/parseSPARQL.mjs.map +1 -1
- package/dist/parseSQL.d.mts +2 -2
- package/dist/parseSQL.d.ts +2 -2
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.d.mts +2 -2
- package/dist/parseSpEL.d.ts +2 -2
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/prepareQueryObjects-BoG5Rt8z.js.map +1 -1
- package/dist/prepareQueryObjects-uA10ZpZX.mjs.map +1 -1
- package/dist/react-querybuilder_core.d.mts +43 -4
- package/dist/react-querybuilder_core.legacy-esm.d.ts +43 -4
- package/dist/react-querybuilder_core.legacy-esm.js +192 -31
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +180 -19
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +43 -4
- 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 -1
- package/dist/transformQuery.d.ts +1 -1
- package/dist/transformQuery.js.map +1 -1
- package/dist/transformQuery.mjs.map +1 -1
- package/dist/utils-ChLG90DP.mjs.map +1 -1
- package/dist/utils-Qwkq2Q0F.js.map +1 -1
- package/package.json +19 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertQuery-BeJJH9BI.mjs","names":[],"sources":["../src/utils/convertQuery.ts"],"sourcesContent":["import type {\n RuleGroupArray,\n RuleGroupICArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\n ToRuleGroupType,\n ToRuleGroupTypeIC,\n} from '../types';\nimport { isRuleGroup, isRuleGroupType, isRuleGroupTypeIC } from './isRuleGroup';\nimport { lc } from './misc';\n\nconst combinatorLevels = ['or', 'xor', 'and'] as const;\n\nconst isSameString = (a: unknown, b: string) => lc(a) === b;\n\nconst generateRuleGroupICWithConsistentCombinators = (\n rg: RuleGroupTypeIC,\n baseCombinatorLevel: number = 0\n): RuleGroupTypeIC => {\n const baseCombinator = combinatorLevels[baseCombinatorLevel];\n\n // oxlint-disable-next-line typescript/no-explicit-any\n if (!rg.rules.includes(baseCombinator as any)) {\n // No instances of this combinator, so group based on the next\n // combinator level if at least two levels remain\n return baseCombinatorLevel < combinatorLevels.length - 2\n ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1)\n : rg;\n }\n\n const newRules = [...rg.rules] as RuleGroupICArray;\n let cursor = 0;\n\n // Group all chains of combinators in the rule array that are not the base combinator\n while (cursor < newRules.length - 2) {\n if (isSameString(newRules[cursor + 1], baseCombinator)) {\n cursor += 2;\n continue;\n }\n\n let nextBaseCombinatorIndex = -1;\n for (let i = cursor + 2; i < newRules.length; i++) {\n if (typeof newRules[i] === 'string' && lc(newRules[i]) === baseCombinator) {\n nextBaseCombinatorIndex = i;\n break;\n }\n }\n\n if (nextBaseCombinatorIndex === -1) {\n // No more instances of this combinator, so group all remaining rules and exit the loop\n newRules.splice(\n cursor,\n newRules.length,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor) as any },\n baseCombinatorLevel + 1\n )\n );\n break;\n } else {\n // Group all rules between the current cursor and the next instance of the base combinator\n newRules.splice(\n cursor,\n nextBaseCombinatorIndex - cursor,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor, nextBaseCombinatorIndex) as any },\n baseCombinatorLevel + 1\n )\n );\n }\n }\n\n return { ...rg, rules: newRules };\n};\n\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.\n *\n * This function is idempotent: {@link RuleGroupType} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertFromIC = <RG extends RuleGroupTypeAny>(rg: RG): ToRuleGroupType<RG> => {\n if (isRuleGroupType(rg)) {\n return rg as ToRuleGroupType<RG>;\n }\n const processedRG = generateRuleGroupICWithConsistentCombinators(rg);\n const rules: RuleGroupArray = [];\n let combinator = 'and';\n for (const [idx, r] of processedRG.rules.entries()) {\n if (typeof r === 'string') {\n if (idx === 1) combinator = r;\n } else {\n rules.push(isRuleGroup(r) ? convertFromIC(r) : r);\n }\n }\n return { ...processedRG, combinator, rules } as ToRuleGroupType<RG>;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}.\n *\n * This function is idempotent: {@link RuleGroupTypeIC} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertToIC = <RG extends RuleGroupTypeAny>(rg: RG): ToRuleGroupTypeIC<RG> => {\n if (isRuleGroupTypeIC(rg)) {\n return rg as ToRuleGroupTypeIC<RG>;\n }\n const { combinator, ...queryWithoutCombinator } = rg;\n const rules: (RuleGroupTypeIC | RuleType | string)[] = [];\n const { length } = rg.rules;\n for (let idx = 0; idx < length; idx++) {\n const r = rg.rules[idx];\n if (isRuleGroup(r)) {\n rules.push(convertToIC(r));\n } else {\n rules.push(r);\n }\n if (combinator && idx < length - 1) {\n rules.push(combinator);\n }\n }\n return { ...queryWithoutCombinator, rules } as ToRuleGroupTypeIC<RG>;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}. For a more explicit\n * operation, use {@link convertToIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupType): RuleGroupTypeIC;\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}. For a more explicit\n * operation, use {@link convertFromIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupTypeIC): RuleGroupType;\nfunction convertQuery(query: RuleGroupType | RuleGroupTypeIC): RuleGroupType | RuleGroupTypeIC {\n return isRuleGroupTypeIC(query) ? convertFromIC(query) : convertToIC(query);\n}\n\nexport { convertQuery };\n"],"mappings":";;AAaA,MAAM,mBAAmB;CAAC;CAAM;CAAO;
|
|
1
|
+
{"version":3,"file":"convertQuery-BeJJH9BI.mjs","names":[],"sources":["../src/utils/convertQuery.ts"],"sourcesContent":["import type {\n RuleGroupArray,\n RuleGroupICArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\n ToRuleGroupType,\n ToRuleGroupTypeIC,\n} from '../types';\nimport { isRuleGroup, isRuleGroupType, isRuleGroupTypeIC } from './isRuleGroup';\nimport { lc } from './misc';\n\nconst combinatorLevels = ['or', 'xor', 'and'] as const;\n\nconst isSameString = (a: unknown, b: string) => lc(a) === b;\n\nconst generateRuleGroupICWithConsistentCombinators = (\n rg: RuleGroupTypeIC,\n baseCombinatorLevel: number = 0\n): RuleGroupTypeIC => {\n const baseCombinator = combinatorLevels[baseCombinatorLevel];\n\n // oxlint-disable-next-line typescript/no-explicit-any\n if (!rg.rules.includes(baseCombinator as any)) {\n // No instances of this combinator, so group based on the next\n // combinator level if at least two levels remain\n return baseCombinatorLevel < combinatorLevels.length - 2\n ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1)\n : rg;\n }\n\n const newRules = [...rg.rules] as RuleGroupICArray;\n let cursor = 0;\n\n // Group all chains of combinators in the rule array that are not the base combinator\n while (cursor < newRules.length - 2) {\n if (isSameString(newRules[cursor + 1], baseCombinator)) {\n cursor += 2;\n continue;\n }\n\n let nextBaseCombinatorIndex = -1;\n for (let i = cursor + 2; i < newRules.length; i++) {\n if (typeof newRules[i] === 'string' && lc(newRules[i]) === baseCombinator) {\n nextBaseCombinatorIndex = i;\n break;\n }\n }\n\n if (nextBaseCombinatorIndex === -1) {\n // No more instances of this combinator, so group all remaining rules and exit the loop\n newRules.splice(\n cursor,\n newRules.length,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor) as any },\n baseCombinatorLevel + 1\n )\n );\n break;\n } else {\n // Group all rules between the current cursor and the next instance of the base combinator\n newRules.splice(\n cursor,\n nextBaseCombinatorIndex - cursor,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor, nextBaseCombinatorIndex) as any },\n baseCombinatorLevel + 1\n )\n );\n }\n }\n\n return { ...rg, rules: newRules };\n};\n\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.\n *\n * This function is idempotent: {@link RuleGroupType} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertFromIC = <RG extends RuleGroupTypeAny>(rg: RG): ToRuleGroupType<RG> => {\n if (isRuleGroupType(rg)) {\n return rg as ToRuleGroupType<RG>;\n }\n const processedRG = generateRuleGroupICWithConsistentCombinators(rg);\n const rules: RuleGroupArray = [];\n let combinator = 'and';\n for (const [idx, r] of processedRG.rules.entries()) {\n if (typeof r === 'string') {\n if (idx === 1) combinator = r;\n } else {\n rules.push(isRuleGroup(r) ? convertFromIC(r) : r);\n }\n }\n return { ...processedRG, combinator, rules } as ToRuleGroupType<RG>;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}.\n *\n * This function is idempotent: {@link RuleGroupTypeIC} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertToIC = <RG extends RuleGroupTypeAny>(rg: RG): ToRuleGroupTypeIC<RG> => {\n if (isRuleGroupTypeIC(rg)) {\n return rg as ToRuleGroupTypeIC<RG>;\n }\n const { combinator, ...queryWithoutCombinator } = rg;\n const rules: (RuleGroupTypeIC | RuleType | string)[] = [];\n const { length } = rg.rules;\n for (let idx = 0; idx < length; idx++) {\n const r = rg.rules[idx];\n if (isRuleGroup(r)) {\n rules.push(convertToIC(r));\n } else {\n rules.push(r);\n }\n if (combinator && idx < length - 1) {\n rules.push(combinator);\n }\n }\n return { ...queryWithoutCombinator, rules } as ToRuleGroupTypeIC<RG>;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}. For a more explicit\n * operation, use {@link convertToIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupType): RuleGroupTypeIC;\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}. For a more explicit\n * operation, use {@link convertFromIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupTypeIC): RuleGroupType;\nfunction convertQuery(query: RuleGroupType | RuleGroupTypeIC): RuleGroupType | RuleGroupTypeIC {\n return isRuleGroupTypeIC(query) ? convertFromIC(query) : convertToIC(query);\n}\n\nexport { convertQuery };\n"],"mappings":";;AAaA,MAAM,mBAAmB;CAAC;CAAM;CAAO;AAAK;AAE5C,MAAM,gBAAgB,GAAY,MAAc,GAAG,CAAC,MAAM;AAE1D,MAAM,gDACJ,IACA,sBAA8B,MACV;CACpB,MAAM,iBAAiB,iBAAiB;CAGxC,IAAI,CAAC,GAAG,MAAM,SAAS,cAAqB,GAG1C,OAAO,sBAAsB,iBAAiB,SAAS,IACnD,6CAA6C,IAAI,sBAAsB,CAAC,IACxE;CAGN,MAAM,WAAW,CAAC,GAAG,GAAG,KAAK;CAC7B,IAAI,SAAS;CAGb,OAAO,SAAS,SAAS,SAAS,GAAG;EACnC,IAAI,aAAa,SAAS,SAAS,IAAI,cAAc,GAAG;GACtD,UAAU;GACV;EACF;EAEA,IAAI,0BAA0B;EAC9B,KAAK,IAAI,IAAI,SAAS,GAAG,IAAI,SAAS,QAAQ,KAC5C,IAAI,OAAO,SAAS,OAAO,YAAY,GAAG,SAAS,EAAE,MAAM,gBAAgB;GACzE,0BAA0B;GAC1B;EACF;EAGF,IAAI,4BAA4B,IAAI;GAElC,SAAS,OACP,QACA,SAAS,QACT,6CAEE,EAAE,OAAO,SAAS,MAAM,MAAM,EAAS,GACvC,sBAAsB,CACxB,CACF;GACA;EACF,OAEE,SAAS,OACP,QACA,0BAA0B,QAC1B,6CAEE,EAAE,OAAO,SAAS,MAAM,QAAQ,uBAAuB,EAAS,GAChE,sBAAsB,CACxB,CACF;CAEJ;CAEA,OAAO;EAAE,GAAG;EAAI,OAAO;CAAS;AAClC;;;;;;;;;AAUA,MAAa,iBAA8C,OAAgC;CACzF,IAAI,gBAAgB,EAAE,GACpB,OAAO;CAET,MAAM,cAAc,6CAA6C,EAAE;CACnE,MAAM,QAAwB,CAAC;CAC/B,IAAI,aAAa;CACjB,KAAK,MAAM,CAAC,KAAK,MAAM,YAAY,MAAM,QAAQ,GAC/C,IAAI,OAAO,MAAM;MACX,QAAQ,GAAG,aAAa;CAAA,OAE5B,MAAM,KAAK,YAAY,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC;CAGpD,OAAO;EAAE,GAAG;EAAa;EAAY;CAAM;AAC7C;;;;;;;;;AAUA,MAAa,eAA4C,OAAkC;CACzF,IAAI,kBAAkB,EAAE,GACtB,OAAO;CAET,MAAM,EAAE,YAAY,GAAG,2BAA2B;CAClD,MAAM,QAAiD,CAAC;CACxD,MAAM,EAAE,WAAW,GAAG;CACtB,KAAK,IAAI,MAAM,GAAG,MAAM,QAAQ,OAAO;EACrC,MAAM,IAAI,GAAG,MAAM;EACnB,IAAI,YAAY,CAAC,GACf,MAAM,KAAK,YAAY,CAAC,CAAC;OAEzB,MAAM,KAAK,CAAC;EAEd,IAAI,cAAc,MAAM,SAAS,GAC/B,MAAM,KAAK,UAAU;CAEzB;CACA,OAAO;EAAE,GAAG;EAAwB;CAAM;AAC5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertQuery-Lx2HQa0m.js","names":["lc","isRuleGroupType","isRuleGroup","isRuleGroupTypeIC"],"sources":["../src/utils/convertQuery.ts"],"sourcesContent":["import type {\n RuleGroupArray,\n RuleGroupICArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\n ToRuleGroupType,\n ToRuleGroupTypeIC,\n} from '../types';\nimport { isRuleGroup, isRuleGroupType, isRuleGroupTypeIC } from './isRuleGroup';\nimport { lc } from './misc';\n\nconst combinatorLevels = ['or', 'xor', 'and'] as const;\n\nconst isSameString = (a: unknown, b: string) => lc(a) === b;\n\nconst generateRuleGroupICWithConsistentCombinators = (\n rg: RuleGroupTypeIC,\n baseCombinatorLevel: number = 0\n): RuleGroupTypeIC => {\n const baseCombinator = combinatorLevels[baseCombinatorLevel];\n\n // oxlint-disable-next-line typescript/no-explicit-any\n if (!rg.rules.includes(baseCombinator as any)) {\n // No instances of this combinator, so group based on the next\n // combinator level if at least two levels remain\n return baseCombinatorLevel < combinatorLevels.length - 2\n ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1)\n : rg;\n }\n\n const newRules = [...rg.rules] as RuleGroupICArray;\n let cursor = 0;\n\n // Group all chains of combinators in the rule array that are not the base combinator\n while (cursor < newRules.length - 2) {\n if (isSameString(newRules[cursor + 1], baseCombinator)) {\n cursor += 2;\n continue;\n }\n\n let nextBaseCombinatorIndex = -1;\n for (let i = cursor + 2; i < newRules.length; i++) {\n if (typeof newRules[i] === 'string' && lc(newRules[i]) === baseCombinator) {\n nextBaseCombinatorIndex = i;\n break;\n }\n }\n\n if (nextBaseCombinatorIndex === -1) {\n // No more instances of this combinator, so group all remaining rules and exit the loop\n newRules.splice(\n cursor,\n newRules.length,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor) as any },\n baseCombinatorLevel + 1\n )\n );\n break;\n } else {\n // Group all rules between the current cursor and the next instance of the base combinator\n newRules.splice(\n cursor,\n nextBaseCombinatorIndex - cursor,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor, nextBaseCombinatorIndex) as any },\n baseCombinatorLevel + 1\n )\n );\n }\n }\n\n return { ...rg, rules: newRules };\n};\n\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.\n *\n * This function is idempotent: {@link RuleGroupType} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertFromIC = <RG extends RuleGroupTypeAny>(rg: RG): ToRuleGroupType<RG> => {\n if (isRuleGroupType(rg)) {\n return rg as ToRuleGroupType<RG>;\n }\n const processedRG = generateRuleGroupICWithConsistentCombinators(rg);\n const rules: RuleGroupArray = [];\n let combinator = 'and';\n for (const [idx, r] of processedRG.rules.entries()) {\n if (typeof r === 'string') {\n if (idx === 1) combinator = r;\n } else {\n rules.push(isRuleGroup(r) ? convertFromIC(r) : r);\n }\n }\n return { ...processedRG, combinator, rules } as ToRuleGroupType<RG>;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}.\n *\n * This function is idempotent: {@link RuleGroupTypeIC} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertToIC = <RG extends RuleGroupTypeAny>(rg: RG): ToRuleGroupTypeIC<RG> => {\n if (isRuleGroupTypeIC(rg)) {\n return rg as ToRuleGroupTypeIC<RG>;\n }\n const { combinator, ...queryWithoutCombinator } = rg;\n const rules: (RuleGroupTypeIC | RuleType | string)[] = [];\n const { length } = rg.rules;\n for (let idx = 0; idx < length; idx++) {\n const r = rg.rules[idx];\n if (isRuleGroup(r)) {\n rules.push(convertToIC(r));\n } else {\n rules.push(r);\n }\n if (combinator && idx < length - 1) {\n rules.push(combinator);\n }\n }\n return { ...queryWithoutCombinator, rules } as ToRuleGroupTypeIC<RG>;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}. For a more explicit\n * operation, use {@link convertToIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupType): RuleGroupTypeIC;\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}. For a more explicit\n * operation, use {@link convertFromIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupTypeIC): RuleGroupType;\nfunction convertQuery(query: RuleGroupType | RuleGroupTypeIC): RuleGroupType | RuleGroupTypeIC {\n return isRuleGroupTypeIC(query) ? convertFromIC(query) : convertToIC(query);\n}\n\nexport { convertQuery };\n"],"mappings":";;AAaA,MAAM,mBAAmB;CAAC;CAAM;CAAO;
|
|
1
|
+
{"version":3,"file":"convertQuery-Lx2HQa0m.js","names":["lc","isRuleGroupType","isRuleGroup","isRuleGroupTypeIC"],"sources":["../src/utils/convertQuery.ts"],"sourcesContent":["import type {\n RuleGroupArray,\n RuleGroupICArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\n ToRuleGroupType,\n ToRuleGroupTypeIC,\n} from '../types';\nimport { isRuleGroup, isRuleGroupType, isRuleGroupTypeIC } from './isRuleGroup';\nimport { lc } from './misc';\n\nconst combinatorLevels = ['or', 'xor', 'and'] as const;\n\nconst isSameString = (a: unknown, b: string) => lc(a) === b;\n\nconst generateRuleGroupICWithConsistentCombinators = (\n rg: RuleGroupTypeIC,\n baseCombinatorLevel: number = 0\n): RuleGroupTypeIC => {\n const baseCombinator = combinatorLevels[baseCombinatorLevel];\n\n // oxlint-disable-next-line typescript/no-explicit-any\n if (!rg.rules.includes(baseCombinator as any)) {\n // No instances of this combinator, so group based on the next\n // combinator level if at least two levels remain\n return baseCombinatorLevel < combinatorLevels.length - 2\n ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1)\n : rg;\n }\n\n const newRules = [...rg.rules] as RuleGroupICArray;\n let cursor = 0;\n\n // Group all chains of combinators in the rule array that are not the base combinator\n while (cursor < newRules.length - 2) {\n if (isSameString(newRules[cursor + 1], baseCombinator)) {\n cursor += 2;\n continue;\n }\n\n let nextBaseCombinatorIndex = -1;\n for (let i = cursor + 2; i < newRules.length; i++) {\n if (typeof newRules[i] === 'string' && lc(newRules[i]) === baseCombinator) {\n nextBaseCombinatorIndex = i;\n break;\n }\n }\n\n if (nextBaseCombinatorIndex === -1) {\n // No more instances of this combinator, so group all remaining rules and exit the loop\n newRules.splice(\n cursor,\n newRules.length,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor) as any },\n baseCombinatorLevel + 1\n )\n );\n break;\n } else {\n // Group all rules between the current cursor and the next instance of the base combinator\n newRules.splice(\n cursor,\n nextBaseCombinatorIndex - cursor,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: newRules.slice(cursor, nextBaseCombinatorIndex) as any },\n baseCombinatorLevel + 1\n )\n );\n }\n }\n\n return { ...rg, rules: newRules };\n};\n\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.\n *\n * This function is idempotent: {@link RuleGroupType} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertFromIC = <RG extends RuleGroupTypeAny>(rg: RG): ToRuleGroupType<RG> => {\n if (isRuleGroupType(rg)) {\n return rg as ToRuleGroupType<RG>;\n }\n const processedRG = generateRuleGroupICWithConsistentCombinators(rg);\n const rules: RuleGroupArray = [];\n let combinator = 'and';\n for (const [idx, r] of processedRG.rules.entries()) {\n if (typeof r === 'string') {\n if (idx === 1) combinator = r;\n } else {\n rules.push(isRuleGroup(r) ? convertFromIC(r) : r);\n }\n }\n return { ...processedRG, combinator, rules } as ToRuleGroupType<RG>;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}.\n *\n * This function is idempotent: {@link RuleGroupTypeIC} queries will be\n * returned as-is.\n *\n * @group Query Tools\n */\nexport const convertToIC = <RG extends RuleGroupTypeAny>(rg: RG): ToRuleGroupTypeIC<RG> => {\n if (isRuleGroupTypeIC(rg)) {\n return rg as ToRuleGroupTypeIC<RG>;\n }\n const { combinator, ...queryWithoutCombinator } = rg;\n const rules: (RuleGroupTypeIC | RuleType | string)[] = [];\n const { length } = rg.rules;\n for (let idx = 0; idx < length; idx++) {\n const r = rg.rules[idx];\n if (isRuleGroup(r)) {\n rules.push(convertToIC(r));\n } else {\n rules.push(r);\n }\n if (combinator && idx < length - 1) {\n rules.push(combinator);\n }\n }\n return { ...queryWithoutCombinator, rules } as ToRuleGroupTypeIC<RG>;\n};\n\n/**\n * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}. For a more explicit\n * operation, use {@link convertToIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupType): RuleGroupTypeIC;\n/**\n * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}. For a more explicit\n * operation, use {@link convertFromIC}.\n *\n * @group Query Tools\n */\nfunction convertQuery(query: RuleGroupTypeIC): RuleGroupType;\nfunction convertQuery(query: RuleGroupType | RuleGroupTypeIC): RuleGroupType | RuleGroupTypeIC {\n return isRuleGroupTypeIC(query) ? convertFromIC(query) : convertToIC(query);\n}\n\nexport { convertQuery };\n"],"mappings":";;AAaA,MAAM,mBAAmB;CAAC;CAAM;CAAO;AAAK;AAE5C,MAAM,gBAAgB,GAAY,MAAcA,oBAAAA,GAAG,CAAC,MAAM;AAE1D,MAAM,gDACJ,IACA,sBAA8B,MACV;CACpB,MAAM,iBAAiB,iBAAiB;CAGxC,IAAI,CAAC,GAAG,MAAM,SAAS,cAAqB,GAG1C,OAAO,sBAAsB,iBAAiB,SAAS,IACnD,6CAA6C,IAAI,sBAAsB,CAAC,IACxE;CAGN,MAAM,WAAW,CAAC,GAAG,GAAG,KAAK;CAC7B,IAAI,SAAS;CAGb,OAAO,SAAS,SAAS,SAAS,GAAG;EACnC,IAAI,aAAa,SAAS,SAAS,IAAI,cAAc,GAAG;GACtD,UAAU;GACV;EACF;EAEA,IAAI,0BAA0B;EAC9B,KAAK,IAAI,IAAI,SAAS,GAAG,IAAI,SAAS,QAAQ,KAC5C,IAAI,OAAO,SAAS,OAAO,YAAYA,oBAAAA,GAAG,SAAS,EAAE,MAAM,gBAAgB;GACzE,0BAA0B;GAC1B;EACF;EAGF,IAAI,4BAA4B,IAAI;GAElC,SAAS,OACP,QACA,SAAS,QACT,6CAEE,EAAE,OAAO,SAAS,MAAM,MAAM,EAAS,GACvC,sBAAsB,CACxB,CACF;GACA;EACF,OAEE,SAAS,OACP,QACA,0BAA0B,QAC1B,6CAEE,EAAE,OAAO,SAAS,MAAM,QAAQ,uBAAuB,EAAS,GAChE,sBAAsB,CACxB,CACF;CAEJ;CAEA,OAAO;EAAE,GAAG;EAAI,OAAO;CAAS;AAClC;;;;;;;;;AAUA,MAAa,iBAA8C,OAAgC;CACzF,IAAIC,oBAAAA,gBAAgB,EAAE,GACpB,OAAO;CAET,MAAM,cAAc,6CAA6C,EAAE;CACnE,MAAM,QAAwB,CAAC;CAC/B,IAAI,aAAa;CACjB,KAAK,MAAM,CAAC,KAAK,MAAM,YAAY,MAAM,QAAQ,GAC/C,IAAI,OAAO,MAAM;MACX,QAAQ,GAAG,aAAa;CAAA,OAE5B,MAAM,KAAKC,oBAAAA,YAAY,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC;CAGpD,OAAO;EAAE,GAAG;EAAa;EAAY;CAAM;AAC7C;;;;;;;;;AAUA,MAAa,eAA4C,OAAkC;CACzF,IAAIC,oBAAAA,kBAAkB,EAAE,GACtB,OAAO;CAET,MAAM,EAAE,YAAY,GAAG,2BAA2B;CAClD,MAAM,QAAiD,CAAC;CACxD,MAAM,EAAE,WAAW,GAAG;CACtB,KAAK,IAAI,MAAM,GAAG,MAAM,QAAQ,OAAO;EACrC,MAAM,IAAI,GAAG,MAAM;EACnB,IAAID,oBAAAA,YAAY,CAAC,GACf,MAAM,KAAK,YAAY,CAAC,CAAC;OAEzB,MAAM,KAAK,CAAC;EAEd,IAAI,cAAc,MAAM,SAAS,GAC/B,MAAM,KAAK,UAAU;CAEzB;CACA,OAAO;EAAE,GAAG;EAAwB;CAAM;AAC5C"}
|
package/dist/formatQuery.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { A as SetRequired, O as RuleType, S as RuleGroupTypeAny, _ as ValueProcessorLegacy, a as ExportOperatorMap, c as NLTranslationKey, d as ParameterizedSQL, f as RQBJsonLogic, g as ValueProcessorByRule, h as SQLPreset, i as ExportObjectFormats, l as NLTranslations, m as RuleProcessor, n as DiagnosticsResult, o as FormatQueryOptions, p as RuleGroupProcessor, r as ExportFormat, s as GroupVariantCondition, t as ConstituentWordOrder, u as ParameterizedNamedSQL, v as ValueProcessorOptions } from "./index-
|
|
1
|
+
import { A as SetRequired, O as RuleType, S as RuleGroupTypeAny, _ as ValueProcessorLegacy, a as ExportOperatorMap, c as NLTranslationKey, d as ParameterizedSQL, f as RQBJsonLogic, g as ValueProcessorByRule, h as SQLPreset, i as ExportObjectFormats, l as NLTranslations, m as RuleProcessor, n as DiagnosticsResult, o as FormatQueryOptions, p as RuleGroupProcessor, r as ExportFormat, s as GroupVariantCondition, t as ConstituentWordOrder, u as ParameterizedNamedSQL, v as ValueProcessorOptions } from "./index-CR-tk4Ci.mjs";
|
|
2
2
|
import { Column, Operators, SQL, Table } from "drizzle-orm";
|
|
3
3
|
import { WhereOptions } from "sequelize";
|
|
4
|
+
import { eq } from "@tanstack/db";
|
|
4
5
|
|
|
5
6
|
//#region src/utils/formatQuery/defaultRuleProcessorCEL.d.ts
|
|
6
7
|
/**
|
|
@@ -213,6 +214,23 @@ declare const defaultRuleGroupProcessorSpEL: RuleGroupProcessor<string>;
|
|
|
213
214
|
*/
|
|
214
215
|
declare const defaultRuleGroupProcessorSQL: RuleGroupProcessor<string>;
|
|
215
216
|
//#endregion
|
|
217
|
+
//#region src/utils/formatQuery/tanStackDbTypes.d.ts
|
|
218
|
+
type TanStackDbWhereCallbackReturnType = ReturnType<typeof eq>;
|
|
219
|
+
type TanStackDbWhereCallback = (refs: Record<string, unknown>) => TanStackDbWhereCallbackReturnType;
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/utils/formatQuery/defaultRuleGroupProcessorTanStackDB.d.ts
|
|
222
|
+
/**
|
|
223
|
+
* Default rule group processor used by {@link formatQuery} for the "tanstack_db" format.
|
|
224
|
+
* Returns a `WhereCallback` suitable for TanStack DB's `.where()` method.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* const where = formatQuery(query, { format: 'tanstack_db', context: { tanstackDb: tsdb } });
|
|
228
|
+
* const results = useLiveQuery(q => q.from({ todo: todosCollection }).where(where));
|
|
229
|
+
*
|
|
230
|
+
* @group Export
|
|
231
|
+
*/
|
|
232
|
+
declare const defaultRuleGroupProcessorTanStackDB: RuleGroupProcessor<TanStackDbWhereCallback>;
|
|
233
|
+
//#endregion
|
|
216
234
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorDiagnostics.d.ts
|
|
217
235
|
/**
|
|
218
236
|
* Rule group processor used by {@link formatQuery} for "diagnostics" format.
|
|
@@ -338,6 +356,11 @@ declare const defaultRuleProcessorPrisma: RuleProcessor;
|
|
|
338
356
|
declare const defaultRuleProcessorSequelize: RuleProcessor;
|
|
339
357
|
//#endregion
|
|
340
358
|
//#region src/utils/formatQuery/defaultRuleProcessorSPARQL.d.ts
|
|
359
|
+
/** Auto-prefix a SPARQL variable name with `?` unless it's already prefixed, a URI, or a prefixed name.
|
|
360
|
+
*
|
|
361
|
+
* @group Export
|
|
362
|
+
*/
|
|
363
|
+
declare const sparqlVar: (name: string) => string;
|
|
341
364
|
/**
|
|
342
365
|
* Default rule processor used by {@link formatQuery} for "sparql" format.
|
|
343
366
|
*
|
|
@@ -359,6 +382,14 @@ declare const defaultOperatorProcessorSQL: RuleProcessor;
|
|
|
359
382
|
*/
|
|
360
383
|
declare const defaultRuleProcessorSQL: RuleProcessor;
|
|
361
384
|
//#endregion
|
|
385
|
+
//#region src/utils/formatQuery/defaultRuleProcessorTanStackDB.d.ts
|
|
386
|
+
/**
|
|
387
|
+
* Default rule processor used by {@link formatQuery} for the "tanstack_db" format.
|
|
388
|
+
*
|
|
389
|
+
* @group Export
|
|
390
|
+
*/
|
|
391
|
+
declare const defaultRuleProcessorTanStackDB: RuleProcessor;
|
|
392
|
+
//#endregion
|
|
362
393
|
//#region src/utils/formatQuery/defaultValueProcessorNL.d.ts
|
|
363
394
|
/**
|
|
364
395
|
* Default value processor used by {@link formatQuery} for "natural_language" format.
|
|
@@ -472,7 +503,15 @@ declare function formatQuery(ruleGroup: RuleGroupTypeAny, options: "drizzle" | (
|
|
|
472
503
|
format: "drizzle";
|
|
473
504
|
})): ReturnType<typeof defaultRuleGroupProcessorDrizzle>;
|
|
474
505
|
/**
|
|
475
|
-
* Generates a
|
|
506
|
+
* Generates a TanStack DB WhereCallback from an RQB query object. The callback can
|
|
507
|
+
* be passed directly to TanStack DB's `.where()` method.
|
|
508
|
+
*
|
|
509
|
+
* @group Export
|
|
510
|
+
*/
|
|
511
|
+
declare function formatQuery(ruleGroup: RuleGroupTypeAny, options: "tanstack_db" | (FormatQueryOptions & {
|
|
512
|
+
format: "tanstack_db";
|
|
513
|
+
})): ReturnType<typeof defaultRuleGroupProcessorTanStackDB>;
|
|
514
|
+
/**
|
|
476
515
|
* be assigned to the `where` property in the Sequelize query functions.
|
|
477
516
|
*
|
|
478
517
|
* @group Export
|
|
@@ -762,5 +801,5 @@ declare const defaultValueProcessorMongoDBByRule: RuleProcessor;
|
|
|
762
801
|
*/
|
|
763
802
|
declare const defaultValueProcessorSpELByRule: RuleProcessor;
|
|
764
803
|
//#endregion
|
|
765
|
-
export { bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, cypherCombinatorMap, defaultCELValueProcessor, defaultExportOperatorMap, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorCypher, defaultRuleGroupProcessorDiagnostics, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorGremlin, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSPARQL, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorCypher, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorGremlin, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSPARQL, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, formatQuery, formatQueryOptionPresets, getNLTranslataion, getQuoteFieldNamesWithArray, getQuotedFieldName, isValidValue, isValueProcessorLegacy, jsonLogicAdditionalOperators, mapSQLOperator, mongoDbFallback, mongoOperators, normalizeConstituentWordOrder, numerifyValues, prismaFallback, prismaOperators, processMatchMode, shouldRenderAsNumber, sqlDialectPresets };
|
|
804
|
+
export { bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, cypherCombinatorMap, defaultCELValueProcessor, defaultExportOperatorMap, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorCypher, defaultRuleGroupProcessorDiagnostics, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorGremlin, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSPARQL, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleGroupProcessorTanStackDB, defaultRuleProcessorCEL, defaultRuleProcessorCypher, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorGremlin, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSPARQL, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultRuleProcessorTanStackDB, defaultSpELValueProcessor, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, formatQuery, formatQueryOptionPresets, getNLTranslataion, getQuoteFieldNamesWithArray, getQuotedFieldName, isValidValue, isValueProcessorLegacy, jsonLogicAdditionalOperators, mapSQLOperator, mongoDbFallback, mongoOperators, normalizeConstituentWordOrder, numerifyValues, prismaFallback, prismaOperators, processMatchMode, shouldRenderAsNumber, sparqlVar, sqlDialectPresets };
|
|
766
805
|
//# sourceMappingURL=formatQuery.d.mts.map
|
package/dist/formatQuery.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { A as SetRequired, O as RuleType, S as RuleGroupTypeAny, _ as ValueProcessorLegacy, a as ExportOperatorMap, c as NLTranslationKey, d as ParameterizedSQL, f as RQBJsonLogic, g as ValueProcessorByRule, h as SQLPreset, i as ExportObjectFormats, l as NLTranslations, m as RuleProcessor, n as DiagnosticsResult, o as FormatQueryOptions, p as RuleGroupProcessor, r as ExportFormat, s as GroupVariantCondition, t as ConstituentWordOrder, u as ParameterizedNamedSQL, v as ValueProcessorOptions } from "./index-
|
|
1
|
+
import { A as SetRequired, O as RuleType, S as RuleGroupTypeAny, _ as ValueProcessorLegacy, a as ExportOperatorMap, c as NLTranslationKey, d as ParameterizedSQL, f as RQBJsonLogic, g as ValueProcessorByRule, h as SQLPreset, i as ExportObjectFormats, l as NLTranslations, m as RuleProcessor, n as DiagnosticsResult, o as FormatQueryOptions, p as RuleGroupProcessor, r as ExportFormat, s as GroupVariantCondition, t as ConstituentWordOrder, u as ParameterizedNamedSQL, v as ValueProcessorOptions } from "./index-NSVgGj45.js";
|
|
2
2
|
import { Column, Operators, SQL, Table } from "drizzle-orm";
|
|
3
3
|
import { WhereOptions } from "sequelize";
|
|
4
|
+
import { eq } from "@tanstack/db";
|
|
4
5
|
|
|
5
6
|
//#region src/utils/formatQuery/defaultRuleProcessorCEL.d.ts
|
|
6
7
|
/**
|
|
@@ -213,6 +214,23 @@ declare const defaultRuleGroupProcessorSpEL: RuleGroupProcessor<string>;
|
|
|
213
214
|
*/
|
|
214
215
|
declare const defaultRuleGroupProcessorSQL: RuleGroupProcessor<string>;
|
|
215
216
|
//#endregion
|
|
217
|
+
//#region src/utils/formatQuery/tanStackDbTypes.d.ts
|
|
218
|
+
type TanStackDbWhereCallbackReturnType = ReturnType<typeof eq>;
|
|
219
|
+
type TanStackDbWhereCallback = (refs: Record<string, unknown>) => TanStackDbWhereCallbackReturnType;
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/utils/formatQuery/defaultRuleGroupProcessorTanStackDB.d.ts
|
|
222
|
+
/**
|
|
223
|
+
* Default rule group processor used by {@link formatQuery} for the "tanstack_db" format.
|
|
224
|
+
* Returns a `WhereCallback` suitable for TanStack DB's `.where()` method.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* const where = formatQuery(query, { format: 'tanstack_db', context: { tanstackDb: tsdb } });
|
|
228
|
+
* const results = useLiveQuery(q => q.from({ todo: todosCollection }).where(where));
|
|
229
|
+
*
|
|
230
|
+
* @group Export
|
|
231
|
+
*/
|
|
232
|
+
declare const defaultRuleGroupProcessorTanStackDB: RuleGroupProcessor<TanStackDbWhereCallback>;
|
|
233
|
+
//#endregion
|
|
216
234
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorDiagnostics.d.ts
|
|
217
235
|
/**
|
|
218
236
|
* Rule group processor used by {@link formatQuery} for "diagnostics" format.
|
|
@@ -338,6 +356,11 @@ declare const defaultRuleProcessorPrisma: RuleProcessor;
|
|
|
338
356
|
declare const defaultRuleProcessorSequelize: RuleProcessor;
|
|
339
357
|
//#endregion
|
|
340
358
|
//#region src/utils/formatQuery/defaultRuleProcessorSPARQL.d.ts
|
|
359
|
+
/** Auto-prefix a SPARQL variable name with `?` unless it's already prefixed, a URI, or a prefixed name.
|
|
360
|
+
*
|
|
361
|
+
* @group Export
|
|
362
|
+
*/
|
|
363
|
+
declare const sparqlVar: (name: string) => string;
|
|
341
364
|
/**
|
|
342
365
|
* Default rule processor used by {@link formatQuery} for "sparql" format.
|
|
343
366
|
*
|
|
@@ -359,6 +382,14 @@ declare const defaultOperatorProcessorSQL: RuleProcessor;
|
|
|
359
382
|
*/
|
|
360
383
|
declare const defaultRuleProcessorSQL: RuleProcessor;
|
|
361
384
|
//#endregion
|
|
385
|
+
//#region src/utils/formatQuery/defaultRuleProcessorTanStackDB.d.ts
|
|
386
|
+
/**
|
|
387
|
+
* Default rule processor used by {@link formatQuery} for the "tanstack_db" format.
|
|
388
|
+
*
|
|
389
|
+
* @group Export
|
|
390
|
+
*/
|
|
391
|
+
declare const defaultRuleProcessorTanStackDB: RuleProcessor;
|
|
392
|
+
//#endregion
|
|
362
393
|
//#region src/utils/formatQuery/defaultValueProcessorNL.d.ts
|
|
363
394
|
/**
|
|
364
395
|
* Default value processor used by {@link formatQuery} for "natural_language" format.
|
|
@@ -472,7 +503,15 @@ declare function formatQuery(ruleGroup: RuleGroupTypeAny, options: "drizzle" | (
|
|
|
472
503
|
format: "drizzle";
|
|
473
504
|
})): ReturnType<typeof defaultRuleGroupProcessorDrizzle>;
|
|
474
505
|
/**
|
|
475
|
-
* Generates a
|
|
506
|
+
* Generates a TanStack DB WhereCallback from an RQB query object. The callback can
|
|
507
|
+
* be passed directly to TanStack DB's `.where()` method.
|
|
508
|
+
*
|
|
509
|
+
* @group Export
|
|
510
|
+
*/
|
|
511
|
+
declare function formatQuery(ruleGroup: RuleGroupTypeAny, options: "tanstack_db" | (FormatQueryOptions & {
|
|
512
|
+
format: "tanstack_db";
|
|
513
|
+
})): ReturnType<typeof defaultRuleGroupProcessorTanStackDB>;
|
|
514
|
+
/**
|
|
476
515
|
* be assigned to the `where` property in the Sequelize query functions.
|
|
477
516
|
*
|
|
478
517
|
* @group Export
|
|
@@ -762,5 +801,5 @@ declare const defaultValueProcessorMongoDBByRule: RuleProcessor;
|
|
|
762
801
|
*/
|
|
763
802
|
declare const defaultValueProcessorSpELByRule: RuleProcessor;
|
|
764
803
|
//#endregion
|
|
765
|
-
export { bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, cypherCombinatorMap, defaultCELValueProcessor, defaultExportOperatorMap, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorCypher, defaultRuleGroupProcessorDiagnostics, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorGremlin, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSPARQL, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorCypher, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorGremlin, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSPARQL, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, formatQuery, formatQueryOptionPresets, getNLTranslataion, getQuoteFieldNamesWithArray, getQuotedFieldName, isValidValue, isValueProcessorLegacy, jsonLogicAdditionalOperators, mapSQLOperator, mongoDbFallback, mongoOperators, normalizeConstituentWordOrder, numerifyValues, prismaFallback, prismaOperators, processMatchMode, shouldRenderAsNumber, sqlDialectPresets };
|
|
804
|
+
export { bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, cypherCombinatorMap, defaultCELValueProcessor, defaultExportOperatorMap, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorCypher, defaultRuleGroupProcessorDiagnostics, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorGremlin, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSPARQL, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleGroupProcessorTanStackDB, defaultRuleProcessorCEL, defaultRuleProcessorCypher, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorGremlin, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSPARQL, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultRuleProcessorTanStackDB, defaultSpELValueProcessor, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, formatQuery, formatQueryOptionPresets, getNLTranslataion, getQuoteFieldNamesWithArray, getQuotedFieldName, isValidValue, isValueProcessorLegacy, jsonLogicAdditionalOperators, mapSQLOperator, mongoDbFallback, mongoOperators, normalizeConstituentWordOrder, numerifyValues, prismaFallback, prismaOperators, processMatchMode, shouldRenderAsNumber, sparqlVar, sqlDialectPresets };
|
|
766
805
|
//# sourceMappingURL=formatQuery.d.ts.map
|
package/dist/formatQuery.js
CHANGED
|
@@ -524,7 +524,7 @@ const defaultValueProcessorByRule = ({ operator, value, valueSource }, { escapeQ
|
|
|
524
524
|
valsOneAndTwoOnly[0] = secondNum;
|
|
525
525
|
valsOneAndTwoOnly[1] = firstNum;
|
|
526
526
|
}
|
|
527
|
-
return (valueIsField ? valsOneAndTwoOnly.map((v) => wrapFieldName(v)) : valsOneAndTwoOnly.every((v) => require_utils.shouldRenderAsNumber(v, parseNumbers)) ? valsOneAndTwoOnly.map((v) => require_utils.parseNumber(v, { parseNumbers: "strict" })) : valsOneAndTwoOnly.map((v) => wrapAndEscape(v))).join(` ${translations?.and ?? "and"} `);
|
|
527
|
+
return (valueIsField ? valsOneAndTwoOnly.map((v) => wrapFieldName(v)) : valsOneAndTwoOnly.every((v) => require_utils.shouldRenderAsNumber(v, parseNumbers)) ? valsOneAndTwoOnly.map((v) => require_utils.parseNumber(v, { parseNumbers: "strict" })) : valsOneAndTwoOnly.map((v) => wrapAndEscape(v))).join(` ${translations?.betweenAnd ?? translations?.and ?? "and"} `);
|
|
528
528
|
}
|
|
529
529
|
case "contains":
|
|
530
530
|
case "doesnotcontain": return valueIsField ? concat(quoteValue("%"), wrapFieldName(value), quoteValue("%")) : quoteValue(`%${escapeValue(value)}%`);
|
|
@@ -619,6 +619,10 @@ const defaultRuleProcessorDrizzle = (rule, _options) => {
|
|
|
619
619
|
const operatorLC = require_objectUtils.lc(operator);
|
|
620
620
|
const valueIsField = valueSource === "field";
|
|
621
621
|
const asFieldOrValue = (v) => valueIsField ? columns[v] : v;
|
|
622
|
+
const maybeParseNumber = (v) => {
|
|
623
|
+
if (valueIsField || !parseNumbers) return asFieldOrValue(v);
|
|
624
|
+
return require_utils.shouldRenderAsNumber(v, true) ? require_utils.parseNumber(v, { parseNumbers: true }) : v;
|
|
625
|
+
};
|
|
622
626
|
if (!column) return void 0;
|
|
623
627
|
const matchEval = require_utils.processMatchMode(rule);
|
|
624
628
|
if (matchEval === false) return;
|
|
@@ -649,12 +653,12 @@ const defaultRuleProcessorDrizzle = (rule, _options) => {
|
|
|
649
653
|
}
|
|
650
654
|
}
|
|
651
655
|
switch (operatorLC) {
|
|
652
|
-
case "=": return eq(column,
|
|
653
|
-
case "!=": return ne(column,
|
|
654
|
-
case ">": return gt(column,
|
|
655
|
-
case "<": return lt(column,
|
|
656
|
-
case ">=": return gte(column,
|
|
657
|
-
case "<=": return lte(column,
|
|
656
|
+
case "=": return eq(column, maybeParseNumber(value));
|
|
657
|
+
case "!=": return ne(column, maybeParseNumber(value));
|
|
658
|
+
case ">": return gt(column, maybeParseNumber(value));
|
|
659
|
+
case "<": return lt(column, maybeParseNumber(value));
|
|
660
|
+
case ">=": return gte(column, maybeParseNumber(value));
|
|
661
|
+
case "<=": return lte(column, maybeParseNumber(value));
|
|
658
662
|
case "beginswith":
|
|
659
663
|
case "doesnotbeginwith": return (operatorLC === "doesnotbeginwith" ? notLike : like)(column, valueIsField ? sql`${asFieldOrValue(value)} || '%'` : `${value}%`);
|
|
660
664
|
case "contains":
|
|
@@ -665,7 +669,7 @@ const defaultRuleProcessorDrizzle = (rule, _options) => {
|
|
|
665
669
|
case "notnull": return isNotNull(column);
|
|
666
670
|
case "in":
|
|
667
671
|
case "notin": {
|
|
668
|
-
const valueAsArray = require_utils.toArray(value).map((v) =>
|
|
672
|
+
const valueAsArray = require_utils.toArray(value).map((v) => maybeParseNumber(v));
|
|
669
673
|
return operatorLC === "notin" ? notInArray(column, valueAsArray) : inArray(column, valueAsArray);
|
|
670
674
|
}
|
|
671
675
|
case "between":
|
|
@@ -999,7 +1003,7 @@ const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
|
|
|
999
1003
|
let firstRule = true;
|
|
1000
1004
|
for (const rule of rg2.rules) {
|
|
1001
1005
|
if (typeof rule === "string") {
|
|
1002
|
-
precedingCombinator =
|
|
1006
|
+
precedingCombinator = `${translations.ruleSeparator ?? ", "}${translations[rule] ?? rule} `;
|
|
1003
1007
|
continue;
|
|
1004
1008
|
}
|
|
1005
1009
|
if (require_objectUtils.isRuleGroup(rule)) {
|
|
@@ -1041,7 +1045,8 @@ const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
|
|
|
1041
1045
|
const [prefixTL, suffixTL] = ["groupPrefix", "groupSuffix"].map((key) => rg2.not ? isXOR ? require_utils.getNLTranslataion(key, translations, ["not", "xor"]) : require_utils.getNLTranslataion(key, translations, ["not"]) : isXOR ? require_utils.getNLTranslataion(key, translations, ["xor"]) : require_utils.getNLTranslataion(key, translations));
|
|
1042
1046
|
const prefix = mustWrap ? `${prefixTL} (`.trim() : "";
|
|
1043
1047
|
const suffix = mustWrap ? `) ${suffixTL}`.trim() : "";
|
|
1044
|
-
|
|
1048
|
+
const sep = translations.ruleSeparator ?? ", ";
|
|
1049
|
+
return `${prefix}${processedRules.join(require_objectUtils.isRuleGroupType(rg2) ? `${sep}${translations[combinator] ?? combinator} ` : "")}${suffix}`;
|
|
1045
1050
|
};
|
|
1046
1051
|
return processRuleGroup(ruleGroup, true);
|
|
1047
1052
|
};
|
|
@@ -1329,6 +1334,142 @@ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
|
|
|
1329
1334
|
return processRuleGroup(ruleGroup, true);
|
|
1330
1335
|
};
|
|
1331
1336
|
//#endregion
|
|
1337
|
+
//#region src/utils/formatQuery/defaultRuleProcessorTanStackDB.ts
|
|
1338
|
+
/**
|
|
1339
|
+
* Default rule processor used by {@link formatQuery} for the "tanstack_db" format.
|
|
1340
|
+
*
|
|
1341
|
+
* @group Export
|
|
1342
|
+
*/
|
|
1343
|
+
const defaultRuleProcessorTanStackDB = (rule, _options) => {
|
|
1344
|
+
const { parseNumbers, preserveValueOrder, context = {} } = _options ?? ( /* v8 ignore start -- @preserve */ {});
|
|
1345
|
+
const ops = context.tanStackDbOperators;
|
|
1346
|
+
const refs = context._tanstackDbRefs;
|
|
1347
|
+
const primaryRef = context._tanstackDbPrimaryRef;
|
|
1348
|
+
if (!ops || !refs || !primaryRef) return void 0;
|
|
1349
|
+
const { and, eq, gt, gte, inArray, isNull, like, lt, lte, not } = ops;
|
|
1350
|
+
const resolveField = (fieldName) => {
|
|
1351
|
+
const dotIdx = fieldName.indexOf(".");
|
|
1352
|
+
if (dotIdx > 0) {
|
|
1353
|
+
const prefix = fieldName.slice(0, dotIdx);
|
|
1354
|
+
const rest = fieldName.slice(dotIdx + 1);
|
|
1355
|
+
if (refs[prefix]) return refs[prefix][rest];
|
|
1356
|
+
}
|
|
1357
|
+
return refs[primaryRef][fieldName];
|
|
1358
|
+
};
|
|
1359
|
+
const { field, operator, value, valueSource } = rule;
|
|
1360
|
+
const column = resolveField(field);
|
|
1361
|
+
const operatorLC = require_objectUtils.lc(operator);
|
|
1362
|
+
const valueIsField = valueSource === "field";
|
|
1363
|
+
const asFieldOrValue = (v) => valueIsField ? resolveField(v) : v;
|
|
1364
|
+
const maybeParseNumber = (v) => {
|
|
1365
|
+
if (valueIsField || !parseNumbers) return asFieldOrValue(v);
|
|
1366
|
+
return require_utils.shouldRenderAsNumber(v, true) ? require_utils.parseNumber(v, { parseNumbers: true }) : v;
|
|
1367
|
+
};
|
|
1368
|
+
switch (operatorLC) {
|
|
1369
|
+
case "=": return eq(column, maybeParseNumber(value));
|
|
1370
|
+
case "!=": return not(eq(column, maybeParseNumber(value)));
|
|
1371
|
+
case ">": return gt(column, maybeParseNumber(value));
|
|
1372
|
+
case "<": return lt(column, maybeParseNumber(value));
|
|
1373
|
+
case ">=": return gte(column, maybeParseNumber(value));
|
|
1374
|
+
case "<=": return lte(column, maybeParseNumber(value));
|
|
1375
|
+
case "beginswith":
|
|
1376
|
+
case "doesnotbeginwith": {
|
|
1377
|
+
const expr = like(column, valueIsField ? void 0 : `${value}%`);
|
|
1378
|
+
return operatorLC === "doesnotbeginwith" ? not(expr) : expr;
|
|
1379
|
+
}
|
|
1380
|
+
case "contains":
|
|
1381
|
+
case "doesnotcontain": {
|
|
1382
|
+
const expr = like(column, valueIsField ? void 0 : `%${value}%`);
|
|
1383
|
+
return operatorLC === "doesnotcontain" ? not(expr) : expr;
|
|
1384
|
+
}
|
|
1385
|
+
case "endswith":
|
|
1386
|
+
case "doesnotendwith": {
|
|
1387
|
+
const expr = like(column, valueIsField ? void 0 : `%${value}`);
|
|
1388
|
+
return operatorLC === "doesnotendwith" ? not(expr) : expr;
|
|
1389
|
+
}
|
|
1390
|
+
case "null": return isNull(column);
|
|
1391
|
+
case "notnull": return not(isNull(column));
|
|
1392
|
+
case "in":
|
|
1393
|
+
case "notin": {
|
|
1394
|
+
const expr = inArray(column, require_utils.toArray(value).map((v) => maybeParseNumber(v)));
|
|
1395
|
+
return operatorLC === "notin" ? not(expr) : expr;
|
|
1396
|
+
}
|
|
1397
|
+
case "between":
|
|
1398
|
+
case "notbetween": {
|
|
1399
|
+
const valueAsArray = require_utils.toArray(value);
|
|
1400
|
+
if (valueAsArray.length >= 2 && require_utils.isValidValue(valueAsArray[0]) && require_utils.isValidValue(valueAsArray[1])) {
|
|
1401
|
+
let [first, second] = valueAsArray;
|
|
1402
|
+
const shouldParseNumbers = !(parseNumbers === false);
|
|
1403
|
+
if (!valueIsField && require_utils.shouldRenderAsNumber(first, shouldParseNumbers) && require_utils.shouldRenderAsNumber(second, shouldParseNumbers)) {
|
|
1404
|
+
const firstNum = require_utils.parseNumber(first, { parseNumbers: shouldParseNumbers });
|
|
1405
|
+
const secondNum = require_utils.parseNumber(second, { parseNumbers: shouldParseNumbers });
|
|
1406
|
+
if (!preserveValueOrder && secondNum < firstNum) {
|
|
1407
|
+
const tempNum = secondNum;
|
|
1408
|
+
second = firstNum;
|
|
1409
|
+
first = tempNum;
|
|
1410
|
+
} else {
|
|
1411
|
+
first = firstNum;
|
|
1412
|
+
second = secondNum;
|
|
1413
|
+
}
|
|
1414
|
+
} else if (valueIsField) {
|
|
1415
|
+
first = asFieldOrValue(first);
|
|
1416
|
+
second = asFieldOrValue(second);
|
|
1417
|
+
}
|
|
1418
|
+
const expr = and(gte(column, first), lte(column, second));
|
|
1419
|
+
return operatorLC === "notbetween" ? not(expr) : expr;
|
|
1420
|
+
}
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
default: return;
|
|
1424
|
+
}
|
|
1425
|
+
};
|
|
1426
|
+
//#endregion
|
|
1427
|
+
//#region src/utils/formatQuery/defaultRuleGroupProcessorTanStackDB.ts
|
|
1428
|
+
/**
|
|
1429
|
+
* Default rule group processor used by {@link formatQuery} for the "tanstack_db" format.
|
|
1430
|
+
* Returns a `WhereCallback` suitable for TanStack DB's `.where()` method.
|
|
1431
|
+
*
|
|
1432
|
+
* @example
|
|
1433
|
+
* const where = formatQuery(query, { format: 'tanstack_db', context: { tanstackDb: tsdb } });
|
|
1434
|
+
* const results = useLiveQuery(q => q.from({ todo: todosCollection }).where(where));
|
|
1435
|
+
*
|
|
1436
|
+
* @group Export
|
|
1437
|
+
*/
|
|
1438
|
+
const defaultRuleGroupProcessorTanStackDB = (ruleGroup, options) => (refs) => {
|
|
1439
|
+
const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, validateRule, validationMap, context = {} } = options;
|
|
1440
|
+
const ops = context.tanStackDbOperators;
|
|
1441
|
+
if (!ops) return void 0;
|
|
1442
|
+
const { and, eq, not, or } = ops;
|
|
1443
|
+
const fallback = eq(1, 1);
|
|
1444
|
+
const refKeys = Object.keys(refs);
|
|
1445
|
+
/* v8 ignore next -- @preserve */
|
|
1446
|
+
if (refKeys.length === 0) return fallback;
|
|
1447
|
+
const ruleProcessor = defaultRuleProcessorTanStackDB;
|
|
1448
|
+
const processRuleGroup = (rg) => {
|
|
1449
|
+
if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return;
|
|
1450
|
+
const processedRules = rg.rules.map((rule) => {
|
|
1451
|
+
if (require_objectUtils.isRuleGroup(rule)) return processRuleGroup(rule);
|
|
1452
|
+
const [validationResult, fieldValidator] = validateRule(rule);
|
|
1453
|
+
if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return;
|
|
1454
|
+
const fieldData = require_utils.getOption(fields, rule.field);
|
|
1455
|
+
return ruleProcessor(rule, {
|
|
1456
|
+
...options,
|
|
1457
|
+
parseNumbers: getParseNumberBoolean(fieldData?.inputType),
|
|
1458
|
+
fieldData,
|
|
1459
|
+
context: {
|
|
1460
|
+
...context,
|
|
1461
|
+
_tanstackDbRefs: refs,
|
|
1462
|
+
_tanstackDbPrimaryRef: refKeys[0]
|
|
1463
|
+
}
|
|
1464
|
+
});
|
|
1465
|
+
}).filter(Boolean);
|
|
1466
|
+
if (processedRules.length === 0) return fallback;
|
|
1467
|
+
const ruleGroupExpr = processedRules.length === 1 ? processedRules[0] : rg.combinator === "or" ? or(...processedRules) : and(...processedRules);
|
|
1468
|
+
return rg.not ? not(ruleGroupExpr) : ruleGroupExpr;
|
|
1469
|
+
};
|
|
1470
|
+
return processRuleGroup(require_convertQuery.convertFromIC(ruleGroup)) ?? fallback;
|
|
1471
|
+
};
|
|
1472
|
+
//#endregion
|
|
1332
1473
|
//#region src/utils/formatQuery/defaultRuleGroupProcessorDiagnostics.ts
|
|
1333
1474
|
const numericInputTypes = new Set([
|
|
1334
1475
|
"number",
|
|
@@ -2168,6 +2309,8 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
|
|
|
2168
2309
|
const orTL = t.or ?? "or";
|
|
2169
2310
|
const trueTL = t.true ?? "true";
|
|
2170
2311
|
const falseTL = t.false ?? "false";
|
|
2312
|
+
const listSep = t.listSeparator ?? ", ";
|
|
2313
|
+
const useOxfordComma = !t.listSeparator;
|
|
2171
2314
|
switch (operatorLowerCase) {
|
|
2172
2315
|
case "null":
|
|
2173
2316
|
case "notnull": return "";
|
|
@@ -2187,7 +2330,8 @@ const defaultValueProcessorNL = (rule, opts = {}) => {
|
|
|
2187
2330
|
if (valueAsArray.length === 0) return "";
|
|
2188
2331
|
const valStringArray = valueAsArray.map((v) => valueIsField ? wrapFieldName(require_utils.getOption(fields ?? [], v)?.label ?? v) : require_utils.shouldRenderAsNumber(v, parseNumbers) ? `${require_utils.trimIfString(v)}` : `${wrapAndEscape(v)}`);
|
|
2189
2332
|
if (valStringArray.length === 1) return valStringArray[0];
|
|
2190
|
-
|
|
2333
|
+
const oxfordComma = useOxfordComma && valStringArray.length > 2 ? "," : "";
|
|
2334
|
+
return `(${`${valStringArray.slice(0, -1).join(listSep)}${oxfordComma} ${orTL} ${valStringArray.at(-1)}`})`;
|
|
2191
2335
|
}
|
|
2192
2336
|
}
|
|
2193
2337
|
if (typeof rule.value === "boolean") return rule.value ? trueTL : falseTL;
|
|
@@ -2300,7 +2444,14 @@ const defaultRuleProcessorNL = (rule, opts) => {
|
|
|
2300
2444
|
V: operatorProcessor(rule, opts),
|
|
2301
2445
|
O: value
|
|
2302
2446
|
};
|
|
2303
|
-
|
|
2447
|
+
const translations = opts?.translations ?? {};
|
|
2448
|
+
const suffixMap = {
|
|
2449
|
+
S: translations.afterSubject ?? " ",
|
|
2450
|
+
V: translations.afterVerb ?? " ",
|
|
2451
|
+
O: translations.afterObject ?? " "
|
|
2452
|
+
};
|
|
2453
|
+
const wordOrderTuple = require_utils.normalizeConstituentWordOrder(wordOrder).filter((term) => wordOrderMap[term] !== "");
|
|
2454
|
+
return wordOrderTuple.map((term, i) => `${wordOrderMap[term]}${i < wordOrderTuple.length - 1 ? suffixMap[term] : ""}`).join("").trim();
|
|
2304
2455
|
};
|
|
2305
2456
|
//#endregion
|
|
2306
2457
|
//#region src/utils/formatQuery/defaultRuleProcessorSQL.ts
|
|
@@ -2594,6 +2745,11 @@ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder,
|
|
|
2594
2745
|
//#endregion
|
|
2595
2746
|
//#region src/utils/formatQuery/defaultRuleProcessorSPARQL.ts
|
|
2596
2747
|
const escapeDoubleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`);
|
|
2748
|
+
/** Auto-prefix a SPARQL variable name with `?` unless it's already prefixed, a URI, or a prefixed name.
|
|
2749
|
+
*
|
|
2750
|
+
* @group Export
|
|
2751
|
+
*/
|
|
2752
|
+
const sparqlVar = (name) => /^[?<]/.test(name) || name.includes(":") ? name : `?${name}`;
|
|
2597
2753
|
/**
|
|
2598
2754
|
* Default rule processor used by {@link formatQuery} for "sparql" format.
|
|
2599
2755
|
*
|
|
@@ -2601,14 +2757,15 @@ const escapeDoubleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escape
|
|
|
2601
2757
|
*/
|
|
2602
2758
|
const defaultRuleProcessorSPARQL = (rule, opts = {}) => {
|
|
2603
2759
|
const { escapeQuotes, parseNumbers } = opts;
|
|
2604
|
-
const { field, operator, value, valueSource } = rule;
|
|
2760
|
+
const { field: rawField, operator, value, valueSource } = rule;
|
|
2605
2761
|
const valueIsField = valueSource === "field";
|
|
2606
2762
|
const operatorTL = operator.toLowerCase();
|
|
2763
|
+
const field = sparqlVar(rawField);
|
|
2607
2764
|
const fmtVal = (v) => {
|
|
2608
2765
|
if (v === null || v === void 0) return "\"\"";
|
|
2609
2766
|
if (typeof v === "boolean") return `"${v}"^^xsd:boolean`;
|
|
2610
2767
|
if (typeof v === "bigint") return String(v);
|
|
2611
|
-
if (valueIsField) return require_utils.trimIfString(v);
|
|
2768
|
+
if (valueIsField) return sparqlVar(require_utils.trimIfString(v));
|
|
2612
2769
|
if (typeof v === "number" || require_utils.shouldRenderAsNumber(v, parseNumbers)) return require_utils.trimIfString(v);
|
|
2613
2770
|
const s = typeof v === "string" ? v : JSON.stringify(v) ?? "";
|
|
2614
2771
|
if (s.startsWith("?") || s.startsWith("<") || s.includes(":")) return s;
|
|
@@ -2633,12 +2790,12 @@ const defaultRuleProcessorSPARQL = (rule, opts = {}) => {
|
|
|
2633
2790
|
case "in": {
|
|
2634
2791
|
const items = require_utils.toArray(value).map(fmtVal);
|
|
2635
2792
|
if (!items.length) return "";
|
|
2636
|
-
return
|
|
2793
|
+
return `${field} IN (${items.join(", ")})`;
|
|
2637
2794
|
}
|
|
2638
2795
|
case "notin": {
|
|
2639
2796
|
const items = require_utils.toArray(value).map(fmtVal);
|
|
2640
2797
|
if (!items.length) return "";
|
|
2641
|
-
return
|
|
2798
|
+
return `${field} NOT IN (${items.join(", ")})`;
|
|
2642
2799
|
}
|
|
2643
2800
|
case "between": {
|
|
2644
2801
|
const arr = require_utils.toArray(value);
|
|
@@ -2701,6 +2858,7 @@ const defaultRuleProcessors = {
|
|
|
2701
2858
|
sequelize: defaultRuleProcessorSequelize,
|
|
2702
2859
|
spel: defaultRuleProcessorSpEL,
|
|
2703
2860
|
sql: defaultRuleProcessorSQL,
|
|
2861
|
+
tanstack_db: defaultRuleProcessorTanStackDB,
|
|
2704
2862
|
cypher: defaultRuleProcessorCypher,
|
|
2705
2863
|
gql: defaultRuleProcessorCypher,
|
|
2706
2864
|
sparql: defaultRuleProcessorSPARQL,
|
|
@@ -2727,6 +2885,7 @@ const defaultOperatorProcessors = {
|
|
|
2727
2885
|
sequelize: defaultOperatorProcessor,
|
|
2728
2886
|
spel: defaultOperatorProcessor,
|
|
2729
2887
|
sql: defaultOperatorProcessorSQL,
|
|
2888
|
+
tanstack_db: defaultOperatorProcessor,
|
|
2730
2889
|
cypher: defaultOperatorProcessor,
|
|
2731
2890
|
gql: defaultOperatorProcessor,
|
|
2732
2891
|
sparql: defaultOperatorProcessor,
|
|
@@ -2773,7 +2932,8 @@ const valueProcessorCanActAsRuleProcessor = new Set([
|
|
|
2773
2932
|
"mongodb",
|
|
2774
2933
|
"prisma",
|
|
2775
2934
|
"sequelize",
|
|
2776
|
-
"spel"
|
|
2935
|
+
"spel",
|
|
2936
|
+
"tanstack_db"
|
|
2777
2937
|
]);
|
|
2778
2938
|
const sqlFormats = new Set([
|
|
2779
2939
|
"sql",
|
|
@@ -2819,7 +2979,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
2819
2979
|
} : format === "parameterized_named" ? {
|
|
2820
2980
|
sql: fallbackExpression,
|
|
2821
2981
|
params: {}
|
|
2822
|
-
} : format === "mongodb" ? `{${fallbackExpression}}` : format === "mongodb_query" ? mongoDbFallback : format === "prisma" ? prismaFallback : format === "jsonlogic" ? false : format === "elasticsearch" ? {} : format === "drizzle" || format === "sequelize" ? void 0 : fallbackExpression;
|
|
2982
|
+
} : format === "mongodb" ? `{${fallbackExpression}}` : format === "mongodb_query" ? mongoDbFallback : format === "prisma" ? prismaFallback : format === "jsonlogic" ? false : format === "elasticsearch" ? {} : format === "drizzle" || format === "sequelize" || format === "tanstack_db" ? void 0 : fallbackExpression;
|
|
2823
2983
|
}
|
|
2824
2984
|
} else validationMap = validationResult;
|
|
2825
2985
|
}
|
|
@@ -2879,6 +3039,7 @@ function formatQuery(ruleGroup, optionParam = {}) {
|
|
|
2879
3039
|
case "ldap": return defaultRuleGroupProcessorLDAP(ruleGroup, finalOptions);
|
|
2880
3040
|
case "prisma": return defaultRuleGroupProcessorPrisma(ruleGroup, finalOptions);
|
|
2881
3041
|
case "drizzle": return defaultRuleGroupProcessorDrizzle(ruleGroup, finalOptions);
|
|
3042
|
+
case "tanstack_db": return defaultRuleGroupProcessorTanStackDB(ruleGroup, finalOptions);
|
|
2882
3043
|
case "sequelize": return defaultRuleGroupProcessorSequelize(ruleGroup, finalOptions);
|
|
2883
3044
|
case "cypher":
|
|
2884
3045
|
case "gql": return defaultRuleGroupProcessorCypher(ruleGroup, finalOptions);
|
|
@@ -2967,6 +3128,7 @@ exports.defaultRuleGroupProcessorSPARQL = defaultRuleGroupProcessorSPARQL;
|
|
|
2967
3128
|
exports.defaultRuleGroupProcessorSQL = defaultRuleGroupProcessorSQL;
|
|
2968
3129
|
exports.defaultRuleGroupProcessorSequelize = defaultRuleGroupProcessorSequelize;
|
|
2969
3130
|
exports.defaultRuleGroupProcessorSpEL = defaultRuleGroupProcessorSpEL;
|
|
3131
|
+
exports.defaultRuleGroupProcessorTanStackDB = defaultRuleGroupProcessorTanStackDB;
|
|
2970
3132
|
exports.defaultRuleProcessorCEL = defaultRuleProcessorCEL;
|
|
2971
3133
|
exports.defaultRuleProcessorCypher = defaultRuleProcessorCypher;
|
|
2972
3134
|
exports.defaultRuleProcessorDrizzle = defaultRuleProcessorDrizzle;
|
|
@@ -2984,6 +3146,7 @@ exports.defaultRuleProcessorSPARQL = defaultRuleProcessorSPARQL;
|
|
|
2984
3146
|
exports.defaultRuleProcessorSQL = defaultRuleProcessorSQL;
|
|
2985
3147
|
exports.defaultRuleProcessorSequelize = defaultRuleProcessorSequelize;
|
|
2986
3148
|
exports.defaultRuleProcessorSpEL = defaultRuleProcessorSpEL;
|
|
3149
|
+
exports.defaultRuleProcessorTanStackDB = defaultRuleProcessorTanStackDB;
|
|
2987
3150
|
exports.defaultSpELValueProcessor = defaultSpELValueProcessor;
|
|
2988
3151
|
exports.defaultValueProcessor = defaultValueProcessor;
|
|
2989
3152
|
exports.defaultValueProcessorByRule = defaultValueProcessorByRule;
|
|
@@ -3008,6 +3171,7 @@ exports.prismaFallback = prismaFallback;
|
|
|
3008
3171
|
exports.prismaOperators = require_utils.prismaOperators;
|
|
3009
3172
|
exports.processMatchMode = require_utils.processMatchMode;
|
|
3010
3173
|
exports.shouldRenderAsNumber = require_utils.shouldRenderAsNumber;
|
|
3174
|
+
exports.sparqlVar = sparqlVar;
|
|
3011
3175
|
exports.sqlDialectPresets = sqlDialectPresets;
|
|
3012
3176
|
|
|
3013
3177
|
//# sourceMappingURL=formatQuery.js.map
|