@react-querybuilder/core 8.9.1 → 8.10.0

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.
Files changed (106) hide show
  1. package/dist/arrayUtils-C9sO4qLO.mjs +50 -0
  2. package/dist/arrayUtils-C9sO4qLO.mjs.map +1 -0
  3. package/dist/arrayUtils-QxZOZTf6.js +73 -0
  4. package/dist/arrayUtils-QxZOZTf6.js.map +1 -0
  5. package/dist/basic-BmpEwexQ.d.mts +363 -0
  6. package/dist/basic-CDDA-KZa.d.ts +363 -0
  7. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +569 -1252
  8. package/dist/cjs/react-querybuilder_core.cjs.development.js +430 -140
  9. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  10. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +569 -1252
  11. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  12. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  13. package/dist/convertQuery-BUgyz1GA.mjs +75 -0
  14. package/dist/convertQuery-BUgyz1GA.mjs.map +1 -0
  15. package/dist/export-Ccjfea21.d.mts +453 -0
  16. package/dist/{export-DyrnTh6K.d.ts → export-GUuxJ7zR.d.ts} +3 -2
  17. package/dist/formatQuery.d.mts +668 -0
  18. package/dist/formatQuery.d.ts +3 -2
  19. package/dist/formatQuery.js +217 -87
  20. package/dist/formatQuery.js.map +1 -1
  21. package/dist/formatQuery.mjs +2496 -0
  22. package/dist/formatQuery.mjs.map +1 -0
  23. package/dist/{import-Cksobmln.d.ts → import-D-hm1phN.d.ts} +2 -2
  24. package/dist/import-Dxevzw_-.d.mts +28 -0
  25. package/dist/isRuleGroup-CGe_rb2w.mjs +40 -0
  26. package/dist/isRuleGroup-CGe_rb2w.mjs.map +1 -0
  27. package/dist/isRuleGroup-DqAs2x4E.js.map +1 -1
  28. package/dist/{optGroupUtils-CXLgyg2i.js → optGroupUtils-B0hTpodo.js} +114 -1
  29. package/dist/optGroupUtils-B0hTpodo.js.map +1 -0
  30. package/dist/optGroupUtils-DrubUpx0.mjs +185 -0
  31. package/dist/optGroupUtils-DrubUpx0.mjs.map +1 -0
  32. package/dist/parseCEL.d.mts +315 -0
  33. package/dist/parseCEL.d.ts +292 -11
  34. package/dist/parseCEL.js +114 -30
  35. package/dist/parseCEL.js.map +1 -1
  36. package/dist/parseCEL.mjs +2631 -0
  37. package/dist/parseCEL.mjs.map +1 -0
  38. package/dist/parseJSONata.d.mts +37 -0
  39. package/dist/parseJSONata.d.ts +3 -2
  40. package/dist/parseJSONata.js +49 -77
  41. package/dist/parseJSONata.js.map +1 -1
  42. package/dist/parseJSONata.mjs +267 -0
  43. package/dist/parseJSONata.mjs.map +1 -0
  44. package/dist/parseJsonLogic.d.mts +37 -0
  45. package/dist/parseJsonLogic.d.ts +4 -3
  46. package/dist/parseJsonLogic.js +5 -6
  47. package/dist/parseJsonLogic.js.map +1 -1
  48. package/dist/parseJsonLogic.mjs +190 -0
  49. package/dist/parseJsonLogic.mjs.map +1 -0
  50. package/dist/parseMongoDB.d.mts +80 -0
  51. package/dist/parseMongoDB.d.ts +3 -2
  52. package/dist/parseMongoDB.js +15 -16
  53. package/dist/parseMongoDB.js.map +1 -1
  54. package/dist/parseMongoDB.mjs +266 -0
  55. package/dist/parseMongoDB.mjs.map +1 -0
  56. package/dist/parseNumber-B_-sR6d5.mjs +24 -0
  57. package/dist/parseNumber-B_-sR6d5.mjs.map +1 -0
  58. package/dist/{parseNumber-Bcys1kOH.js → parseNumber-D4iQDxK-.js} +1 -1
  59. package/dist/{parseNumber-Bcys1kOH.js.map → parseNumber-D4iQDxK-.js.map} +1 -1
  60. package/dist/parseSQL.d.mts +38 -0
  61. package/dist/parseSQL.d.ts +3 -2
  62. package/dist/parseSQL.js +11 -15
  63. package/dist/parseSQL.js.map +1 -1
  64. package/dist/parseSQL.mjs +6622 -0
  65. package/dist/parseSQL.mjs.map +1 -0
  66. package/dist/parseSpEL.d.mts +35 -0
  67. package/dist/parseSpEL.d.ts +3 -2
  68. package/dist/parseSpEL.js +7 -9
  69. package/dist/parseSpEL.js.map +1 -1
  70. package/dist/parseSpEL.mjs +272 -0
  71. package/dist/parseSpEL.mjs.map +1 -0
  72. package/dist/{prepareQueryObjects-BqFEs4eV.js → prepareQueryObjects-BOUWfel5.js} +4 -5
  73. package/dist/prepareQueryObjects-BOUWfel5.js.map +1 -0
  74. package/dist/prepareQueryObjects-CJNpnGcJ.mjs +153 -0
  75. package/dist/prepareQueryObjects-CJNpnGcJ.mjs.map +1 -0
  76. package/dist/query-builder-layout.css +1 -1
  77. package/dist/query-builder-layout.css.map +1 -1
  78. package/dist/query-builder.css +1 -1
  79. package/dist/query-builder.css.map +1 -1
  80. package/dist/react-querybuilder_core.d.mts +569 -1252
  81. package/dist/react-querybuilder_core.legacy-esm.d.ts +569 -1252
  82. package/dist/react-querybuilder_core.legacy-esm.js +430 -136
  83. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  84. package/dist/react-querybuilder_core.mjs +426 -141
  85. package/dist/react-querybuilder_core.mjs.map +1 -1
  86. package/dist/react-querybuilder_core.production.d.mts +569 -1252
  87. package/dist/react-querybuilder_core.production.mjs +1 -1
  88. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  89. package/dist/styles/_layout.scss +61 -17
  90. package/dist/styles/_main.scss +17 -4
  91. package/dist/{transformQuery-FL_nlpp5.js → transformQuery-CWDPogO5.js} +1 -1
  92. package/dist/{transformQuery-FL_nlpp5.js.map → transformQuery-CWDPogO5.js.map} +1 -1
  93. package/dist/transformQuery-DHvtgDgZ.mjs +41 -0
  94. package/dist/transformQuery-DHvtgDgZ.mjs.map +1 -0
  95. package/dist/transformQuery.d.mts +118 -0
  96. package/dist/transformQuery.d.ts +1 -1
  97. package/dist/transformQuery.js +1 -1
  98. package/dist/transformQuery.mjs +4 -0
  99. package/package.json +78 -28
  100. package/dist/arrayUtils-D5EoIsKP.js +0 -164
  101. package/dist/arrayUtils-D5EoIsKP.js.map +0 -1
  102. package/dist/basic-C8xXKHIA.d.ts +0 -1235
  103. package/dist/objectUtils-BBZSfZJz.js +0 -17
  104. package/dist/objectUtils-BBZSfZJz.js.map +0 -1
  105. package/dist/optGroupUtils-CXLgyg2i.js.map +0 -1
  106. package/dist/prepareQueryObjects-BqFEs4eV.js.map +0 -1
@@ -0,0 +1,75 @@
1
+ import { isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, lc } from "./isRuleGroup-CGe_rb2w.mjs";
2
+ import { produce } from "immer";
3
+
4
+ //#region src/utils/convertQuery.ts
5
+ const combinatorLevels = [
6
+ "or",
7
+ "xor",
8
+ "and"
9
+ ];
10
+ const isSameString = (a, b) => lc(a) === b;
11
+ const generateRuleGroupICWithConsistentCombinators = (rg, baseCombinatorLevel = 0) => {
12
+ const baseCombinator = combinatorLevels[baseCombinatorLevel];
13
+ if (!rg.rules.includes(baseCombinator)) return baseCombinatorLevel < combinatorLevels.length - 2 ? generateRuleGroupICWithConsistentCombinators(rg, baseCombinatorLevel + 1) : rg;
14
+ return produce(rg, (draft) => {
15
+ let cursor = 0;
16
+ while (cursor < draft.rules.length - 2) {
17
+ if (isSameString(draft.rules[cursor + 1], baseCombinator)) {
18
+ cursor += 2;
19
+ continue;
20
+ }
21
+ const nextBaseCombinatorIndex = draft.rules.findIndex((r, i) => i > cursor && typeof r === "string" && lc(r) === baseCombinator);
22
+ if (nextBaseCombinatorIndex === -1) {
23
+ draft.rules.splice(cursor, draft.rules.length, generateRuleGroupICWithConsistentCombinators({ rules: draft.rules.slice(cursor) }, baseCombinatorLevel + 1));
24
+ break;
25
+ } else draft.rules.splice(cursor, nextBaseCombinatorIndex - cursor, generateRuleGroupICWithConsistentCombinators({ rules: draft.rules.slice(cursor, nextBaseCombinatorIndex) }, baseCombinatorLevel + 1));
26
+ }
27
+ });
28
+ };
29
+ /**
30
+ * Converts a {@link RuleGroupTypeIC} to {@link RuleGroupType}.
31
+ *
32
+ * This function is idempotent: {@link RuleGroupType} queries will be
33
+ * returned as-is.
34
+ *
35
+ * @group Query Tools
36
+ */
37
+ const convertFromIC = (rg) => {
38
+ if (isRuleGroupType(rg)) return rg;
39
+ const processedRG = generateRuleGroupICWithConsistentCombinators(rg);
40
+ const rulesAsMixedList = processedRG.rules.map((r) => typeof r === "string" || !isRuleGroup(r) ? r : convertFromIC(r));
41
+ const combinator = rulesAsMixedList.length < 2 ? "and" : rulesAsMixedList[1];
42
+ const rules = rulesAsMixedList.filter((r) => typeof r !== "string");
43
+ return {
44
+ ...processedRG,
45
+ combinator,
46
+ rules
47
+ };
48
+ };
49
+ /**
50
+ * Converts a {@link RuleGroupType} to {@link RuleGroupTypeIC}.
51
+ *
52
+ * This function is idempotent: {@link RuleGroupTypeIC} queries will be
53
+ * returned as-is.
54
+ *
55
+ * @group Query Tools
56
+ */
57
+ const convertToIC = (rg) => {
58
+ if (isRuleGroupTypeIC(rg)) return rg;
59
+ const { combinator,...queryWithoutCombinator } = rg;
60
+ const rules = [];
61
+ const { length } = rg.rules;
62
+ for (const [idx, r] of rg.rules.entries()) {
63
+ if (isRuleGroup(r)) rules.push(convertToIC(r));
64
+ else rules.push(r);
65
+ if (combinator && idx < length - 1) rules.push(combinator);
66
+ }
67
+ return {
68
+ ...queryWithoutCombinator,
69
+ rules
70
+ };
71
+ };
72
+
73
+ //#endregion
74
+ export { convertFromIC, convertToIC };
75
+ //# sourceMappingURL=convertQuery-BUgyz1GA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertQuery-BUgyz1GA.mjs","names":["rules: (RuleGroupTypeIC | RuleType | string)[]"],"sources":["../src/utils/convertQuery.ts"],"sourcesContent":["import { produce } from 'immer';\nimport type {\n RuleGroupArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\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 return produce(rg, draft => {\n let cursor = 0;\n\n // Group all chains of combinators in the rule array that are not the base combinator\n while (cursor < draft.rules.length - 2) {\n if (isSameString(draft.rules[cursor + 1], baseCombinator)) {\n cursor += 2;\n continue;\n }\n\n const nextBaseCombinatorIndex = draft.rules.findIndex(\n (r, i) => i > cursor && typeof r === 'string' && lc(r) === baseCombinator\n );\n\n if (nextBaseCombinatorIndex === -1) {\n // No more instances of this combinator, so group all remaining rules and exit the loop\n draft.rules.splice(\n cursor,\n draft.rules.length,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: draft.rules.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 draft.rules.splice(\n cursor,\n nextBaseCombinatorIndex - cursor,\n generateRuleGroupICWithConsistentCombinators(\n // oxlint-disable-next-line typescript/no-explicit-any\n { rules: draft.rules.slice(cursor, nextBaseCombinatorIndex) as any },\n baseCombinatorLevel + 1\n )\n );\n }\n }\n });\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 RuleGroupType = RuleGroupType>(\n rg: RuleGroupTypeAny\n): RG => {\n if (isRuleGroupType(rg)) {\n return rg as RG;\n }\n const processedRG = generateRuleGroupICWithConsistentCombinators(rg);\n const rulesAsMixedList = processedRG.rules.map(r =>\n typeof r === 'string' || !isRuleGroup(r) ? r : convertFromIC(r)\n );\n const combinator = rulesAsMixedList.length < 2 ? 'and' : (rulesAsMixedList[1] as string);\n const rules = rulesAsMixedList.filter(r => typeof r !== 'string') as RuleGroupArray;\n return { ...processedRG, combinator, rules } as 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 = <RGIC extends RuleGroupTypeIC = RuleGroupTypeIC>(\n rg: RuleGroupTypeAny\n): RGIC => {\n if (isRuleGroupTypeIC(rg)) {\n return rg as RGIC;\n }\n const { combinator, ...queryWithoutCombinator } = rg;\n const rules: (RuleGroupTypeIC | RuleType | string)[] = [];\n const { length } = rg.rules;\n for (const [idx, r] of rg.rules.entries()) {\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 RGIC;\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":";;;;AAWA,MAAM,mBAAmB;CAAC;CAAM;CAAO;CAAM;AAE7C,MAAM,gBAAgB,GAAY,MAAc,GAAG,EAAE,KAAK;AAE1D,MAAM,gDACJ,IACA,sBAA8B,MACV;CACpB,MAAM,iBAAiB,iBAAiB;AAGxC,KAAI,CAAC,GAAG,MAAM,SAAS,eAAsB,CAG3C,QAAO,sBAAsB,iBAAiB,SAAS,IACnD,6CAA6C,IAAI,sBAAsB,EAAE,GACzE;AAGN,QAAO,QAAQ,KAAI,UAAS;EAC1B,IAAI,SAAS;AAGb,SAAO,SAAS,MAAM,MAAM,SAAS,GAAG;AACtC,OAAI,aAAa,MAAM,MAAM,SAAS,IAAI,eAAe,EAAE;AACzD,cAAU;AACV;;GAGF,MAAM,0BAA0B,MAAM,MAAM,WACzC,GAAG,MAAM,IAAI,UAAU,OAAO,MAAM,YAAY,GAAG,EAAE,KAAK,eAC5D;AAED,OAAI,4BAA4B,IAAI;AAElC,UAAM,MAAM,OACV,QACA,MAAM,MAAM,QACZ,6CAEE,EAAE,OAAO,MAAM,MAAM,MAAM,OAAO,EAAS,EAC3C,sBAAsB,EACvB,CACF;AACD;SAGA,OAAM,MAAM,OACV,QACA,0BAA0B,QAC1B,6CAEE,EAAE,OAAO,MAAM,MAAM,MAAM,QAAQ,wBAAwB,EAAS,EACpE,sBAAsB,EACvB,CACF;;GAGL;;;;;;;;;;AAWJ,MAAa,iBACX,OACO;AACP,KAAI,gBAAgB,GAAG,CACrB,QAAO;CAET,MAAM,cAAc,6CAA6C,GAAG;CACpE,MAAM,mBAAmB,YAAY,MAAM,KAAI,MAC7C,OAAO,MAAM,YAAY,CAAC,YAAY,EAAE,GAAG,IAAI,cAAc,EAAE,CAChE;CACD,MAAM,aAAa,iBAAiB,SAAS,IAAI,QAAS,iBAAiB;CAC3E,MAAM,QAAQ,iBAAiB,QAAO,MAAK,OAAO,MAAM,SAAS;AACjE,QAAO;EAAE,GAAG;EAAa;EAAY;EAAO;;;;;;;;;;AAW9C,MAAa,eACX,OACS;AACT,KAAI,kBAAkB,GAAG,CACvB,QAAO;CAET,MAAM,EAAE,WAAY,GAAG,2BAA2B;CAClD,MAAMA,QAAiD,EAAE;CACzD,MAAM,EAAE,WAAW,GAAG;AACtB,MAAK,MAAM,CAAC,KAAK,MAAM,GAAG,MAAM,SAAS,EAAE;AACzC,MAAI,YAAY,EAAE,CAChB,OAAM,KAAK,YAAY,EAAE,CAAC;MAE1B,OAAM,KAAK,EAAE;AAEf,MAAI,cAAc,MAAM,SAAS,EAC/B,OAAM,KAAK,WAAW;;AAG1B,QAAO;EAAE,GAAG;EAAwB;EAAO"}
@@ -0,0 +1,453 @@
1
+ import { DefaultOperatorName, FlexibleOptionList, FullField, FullOperator, FullOptionList, InputType, ParseNumbersPropConfig, QueryValidator, RuleGroupTypeAny, RuleType, RuleValidator, ValidationMap, ValidationResult, ValueSource } from "./basic-BmpEwexQ.mjs";
2
+ import { RulesLogic } from "json-logic-js";
3
+ import { Except } from "type-fest";
4
+
5
+ //#region src/types/export.d.ts
6
+
7
+ /**
8
+ * Available export formats for {@link formatQuery}.
9
+ *
10
+ * @group Export
11
+ */
12
+ type ExportFormat = "json" | "sql" | "json_without_ids" | "parameterized" | "parameterized_named" | "mongodb" | "mongodb_query" | "cel" | "jsonlogic" | "spel" | "elasticsearch" | "jsonata" | "natural_language" | "ldap" | "drizzle" | "prisma" | "sequelize";
13
+ /**
14
+ * Export formats for {@link formatQuery} that produce objects instead of strings.
15
+ *
16
+ * @group Export
17
+ */
18
+ type ExportObjectFormats = "parameterized" | "parameterized_named" | "jsonlogic" | "elasticsearch" | "jsonata" | "mongodb_query";
19
+ /**
20
+ * Available presets for the "sql" export format.
21
+ *
22
+ * @group Export
23
+ */
24
+ type SQLPreset = "ansi" | "sqlite" | "postgresql" | "mysql" | "mssql" | "oracle";
25
+ /**
26
+ * A map of operators to strings to be used in the output of {@link formatQuery}. If the
27
+ * result can differ based on the `valueSource`, the key should map to an array where the
28
+ * second element represents the string to be used when `valueSource` is "field". The first
29
+ * element will be used in all other cases.
30
+ *
31
+ * @group Export
32
+ */
33
+ type ExportOperatorMap = Partial<Record<Lowercase<DefaultOperatorName> | DefaultOperatorName, string | [string, string]>>;
34
+ /**
35
+ * Options object shape for {@link formatQuery}.
36
+ *
37
+ * @group Export
38
+ */
39
+ interface FormatQueryOptions {
40
+ /**
41
+ * The {@link ExportFormat}.
42
+ */
43
+ format?: ExportFormat;
44
+ /**
45
+ * This function will be used to process the `operator` from each rule
46
+ * for query language formats. If not defined, the appropriate
47
+ * `defaultOperatorProcessor*` for the format will be used.
48
+ */
49
+ operatorProcessor?: RuleProcessor;
50
+ /**
51
+ * This function will be used to process the `value` from each rule
52
+ * for query language formats. If not defined, the appropriate
53
+ * `defaultValueProcessor*` for the format will be used.
54
+ */
55
+ valueProcessor?: ValueProcessorLegacy | ValueProcessorByRule;
56
+ /**
57
+ * This function will be used to process each rule. If not defined, the appropriate
58
+ * `defaultRuleProcessor*` for the given format will be used.
59
+ */
60
+ ruleProcessor?: RuleProcessor;
61
+ /**
62
+ * This function will be used to process each rule group. If not defined, the appropriate
63
+ * `defaultRuleGroupProcessor*` for the format will be used.
64
+ *
65
+ * If this function is defined, it will override the `format` option. This also allows
66
+ * `formatQuery` to produce completely custom output formats.
67
+ */
68
+ ruleGroupProcessor?: RuleGroupProcessor;
69
+ /**
70
+ * In the "sql", "parameterized", "parameterized_named", and "jsonata" export
71
+ * formats, field names will be bracketed by this string. If an array of strings
72
+ * is passed, field names will be preceded by the first element and
73
+ * succeeded by the second element.
74
+ *
75
+ * Tip: Use `fieldIdentifierSeparator` to bracket identifiers individually within field names.
76
+ *
77
+ * @default '' // the empty string
78
+ *
79
+ * @example
80
+ * formatQuery(query, { format: 'sql', quoteFieldNamesWith: '"' })
81
+ * // `"First name" = 'Steve'`
82
+ *
83
+ * @example
84
+ * formatQuery(query, { format: 'sql', quoteFieldNamesWith: ['[', ']'] })
85
+ * // "[First name] = 'Steve'"
86
+ */
87
+ quoteFieldNamesWith?: string | [string, string];
88
+ /**
89
+ * When used in conjunction with the `quoteFieldNamesWith` option, field names will
90
+ * be split by this string, each part being individually processed as per the rules
91
+ * of the `quoteFieldNamesWith` configuration. The parts will then be re-joined
92
+ * by the same string.
93
+ *
94
+ * A common value for this option is `'.'`.
95
+ *
96
+ * A value of `''` (the empty string) will disable splitting/rejoining.
97
+ *
98
+ * @default ''
99
+ *
100
+ * @example
101
+ * formatQuery(query, {
102
+ * format: 'sql',
103
+ * quoteFieldNamesWith: ['[', ']'],
104
+ * fieldIdentifierSeparator: '.',
105
+ * })
106
+ * // "[dbo].[Musicians].[First name] = 'Steve'"
107
+ */
108
+ fieldIdentifierSeparator?: string;
109
+ /**
110
+ * Character to use for quoting string values in the SQL format.
111
+ * @default `'`
112
+ */
113
+ quoteValuesWith?: string;
114
+ /**
115
+ * Validator function for the entire query. Can be the same function passed
116
+ * as `validator` prop to {@link QueryBuilder}.
117
+ */
118
+ validator?: QueryValidator;
119
+ /**
120
+ * This can be the same {@link FullField} array passed to {@link QueryBuilder}, but
121
+ * really all you need to provide is the `name` and `validator` for each field.
122
+ *
123
+ * The full field object from this array, where the field's identifying property
124
+ * matches the rule's `field`, will be passed to the rule processor.
125
+ */
126
+ fields?: FlexibleOptionList<FullField>;
127
+ /**
128
+ * This can be the same `getOperators` function passed to {@link QueryBuilder}.
129
+ *
130
+ * The full operator object from this array, where the operator's identifying property
131
+ * matches the rule's `operator`, will be passed to the rule processor.
132
+ */
133
+ getOperators?(field: string, misc: {
134
+ fieldData: FullField;
135
+ }): FlexibleOptionList<FullOperator> | null;
136
+ /**
137
+ * This string will be inserted in place of invalid groups for non-JSON formats.
138
+ * Defaults to `'(1 = 1)'` for "sql"/"parameterized"/"parameterized_named" and
139
+ * `'$and:[{$expr:true}]'` for "mongodb".
140
+ */
141
+ fallbackExpression?: string;
142
+ /**
143
+ * This string will be placed in front of named parameters (aka bind variables)
144
+ * when using the "parameterized_named" export format.
145
+ *
146
+ * @default ":"
147
+ */
148
+ paramPrefix?: string;
149
+ /**
150
+ * Maintains the parameter prefix in the `params` object keys when using the
151
+ * "parameterized_named" export format. Recommended when using SQLite.
152
+ *
153
+ * @default false
154
+ *
155
+ * @example
156
+ * console.log(formatQuery(query, {
157
+ * format: "parameterized_named",
158
+ * paramPrefix: "$",
159
+ * paramsKeepPrefix: true
160
+ * }).params)
161
+ * // { $firstName: "Stev" }
162
+ * // Default (`paramsKeepPrefix` is `false`):
163
+ * // { firstName: "Stev" }
164
+ */
165
+ paramsKeepPrefix?: boolean;
166
+ /**
167
+ * Renders parameter placeholders as a series of sequential numbers
168
+ * instead of '?' like the default. This option will respect the
169
+ * `paramPrefix` option like the 'parameterized_named' format.
170
+ *
171
+ * @default false
172
+ */
173
+ numberedParams?: boolean;
174
+ /**
175
+ * Preserves the order of values for "between" and "notBetween" rules, even if a larger
176
+ * value comes before a smaller value (which will always evaluate to false).
177
+ */
178
+ preserveValueOrder?: boolean;
179
+ /**
180
+ * Renders values as either `number`-types or unquoted strings, as
181
+ * appropriate and when possible. Each `string`-type value is evaluated
182
+ * against {@link numericRegex} to determine if it can be represented as a
183
+ * plain numeric value. If so, `parseFloat` is used to convert it to a number.
184
+ */
185
+ parseNumbers?: ParseNumbersPropConfig;
186
+ /**
187
+ * Any rules where the field is equal to this value will be ignored.
188
+ *
189
+ * @default '~'
190
+ */
191
+ placeholderFieldName?: string;
192
+ /**
193
+ * Any rules where the operator is equal to this value will be ignored.
194
+ *
195
+ * @default '~'
196
+ */
197
+ placeholderOperatorName?: string;
198
+ /**
199
+ * Any rules where the value is equal to this value will be ignored.
200
+ *
201
+ * @default '~'
202
+ */
203
+ placeholderValueName?: string;
204
+ /**
205
+ * Operator to use when concatenating wildcard characters and field names in "sql" format.
206
+ * The ANSI standard is `||`, while SQL Server uses `+`. MySQL does not implement a concatenation
207
+ * operator by default, and therefore requires use of the `CONCAT` function.
208
+ *
209
+ * If `concatOperator` is set to `"CONCAT"` (case-insensitive), the `CONCAT` function will be
210
+ * used. Note that Oracle SQL does not support more than two values in the `CONCAT` function,
211
+ * so this option should not be used in that context. The default setting (`"||"`) is already
212
+ * compatible with Oracle SQL.
213
+ *
214
+ * @default '||'
215
+ */
216
+ concatOperator?: "||" | "+" | "CONCAT" | (string & {});
217
+ /**
218
+ * Option presets to maximize compatibility with various SQL dialects.
219
+ */
220
+ preset?: SQLPreset;
221
+ /**
222
+ * Map of operators to their translations for the "natural_language" format. If the
223
+ * result can differ based on the `valueSource`, the key should map to an array where the
224
+ * second element represents the string to be used when `valueSource` is "field". The first
225
+ * element will be used in all other cases.
226
+ */
227
+ operatorMap?: ExportOperatorMap;
228
+ /**
229
+ * [Constituent word order](https://en.wikipedia.org/wiki/Word_order#Constituent_word_orders)
230
+ * for the "natural_language" format. Can be abbreviated like "SVO" or spelled out like
231
+ * "subject-verb-object".
232
+ *
233
+ * - Subject = field
234
+ * - Verb = operator
235
+ * - Object = value
236
+ */
237
+ wordOrder?: ConstituentWordOrderString | Lowercase<ConstituentWordOrderString> | ({} & string);
238
+ /**
239
+ * Translatable strings used by the "natural_language" format.
240
+ */
241
+ translations?: Partial<Record<NLTranslationKey, string>>;
242
+ context?: Record<string, any>;
243
+ }
244
+ /**
245
+ * Options object for {@link ValueProcessorByRule} functions.
246
+ *
247
+ * @group Export
248
+ */
249
+ interface ValueProcessorOptions extends FormatQueryOptions {
250
+ valueProcessor?: ValueProcessorByRule;
251
+ escapeQuotes?: boolean;
252
+ /**
253
+ * The full field object, if `fields` was provided in the
254
+ * {@link formatQuery} options parameter.
255
+ */
256
+ fieldData?: FullField;
257
+ /**
258
+ * Included for the "parameterized_named" format only. Keys of this object represent
259
+ * field names and values represent the current list of parameter names for that
260
+ * field based on the query rules processed up to that point. Use this list to
261
+ * ensure that parameter names generated by the custom rule processor are unique.
262
+ */
263
+ fieldParamNames?: Record<string, string[]>;
264
+ /**
265
+ * Included for the "parameterized_named" format only. Call this function with a
266
+ * field name to get a unique parameter name, as yet unused during query processing.
267
+ */
268
+ getNextNamedParam?: (field: string) => string;
269
+ /**
270
+ * Additional prefix and suffix characters to wrap the value in. Useful for augmenting
271
+ * the default value processor results with special syntax (e.g., for dates or function
272
+ * calls).
273
+ */
274
+ wrapValueWith?: [string, string];
275
+ /**
276
+ * Parse numbers in the rule value.
277
+ *
278
+ * @default false
279
+ */
280
+ parseNumbers?: boolean;
281
+ }
282
+ /**
283
+ * Options object curated by {@link formatQuery} and passed to a {@link RuleGroupProcessor}.
284
+ *
285
+ * @group Export
286
+ */
287
+ interface FormatQueryFinalOptions extends Required<Except<FormatQueryOptions, "context" | "valueProcessor" | "validator" | "placeholderValueName" | "ruleGroupProcessor" | "parseNumbers">> {
288
+ fields: FullOptionList<FullField>;
289
+ getParseNumberBoolean: (inputType?: InputType | null) => boolean | undefined;
290
+ parseNumbers?: ParseNumbersPropConfig | undefined;
291
+ placeholderValueName?: string | undefined;
292
+ valueProcessor: ValueProcessorByRule;
293
+ validator?: QueryValidator;
294
+ validateRule: FormatQueryValidateRule;
295
+ validationMap: ValidationMap;
296
+ context?: Record<string, unknown>;
297
+ }
298
+ /**
299
+ * Function that produces a processed value for a given {@link RuleType}.
300
+ *
301
+ * @group Export
302
+ */
303
+ type ValueProcessorByRule = (rule: RuleType, options?: ValueProcessorOptions) => string;
304
+ /**
305
+ * Function that produces a processed value for a given `field`, `operator`, `value`,
306
+ * and `valueSource`.
307
+ *
308
+ * @group Export
309
+ */
310
+ type ValueProcessorLegacy = (field: string, operator: string, value: any, valueSource?: ValueSource) => string;
311
+ /**
312
+ * Function to produce a result that {@link formatQuery} uses when processing a
313
+ * {@link RuleType} object.
314
+ *
315
+ * See the default rule processor for each format to know what type to return.
316
+ * | Format | Default rule processor |
317
+ * | ------------------------ | ----------------------------------------- |
318
+ * | `sql` | {@link defaultRuleProcessorSQL} |
319
+ * | `parameterized` | {@link defaultRuleProcessorParameterized} |
320
+ * | `parameterized_named` | {@link defaultRuleProcessorParameterized} |
321
+ * | `mongodb` _(deprecated)_ | {@link defaultRuleProcessorMongoDB} |
322
+ * | `mongodb_query` | {@link defaultRuleProcessorMongoDBQuery} |
323
+ * | `cel` | {@link defaultRuleProcessorCEL} |
324
+ * | `spel` | {@link defaultRuleProcessorSpEL} |
325
+ * | `jsonlogic` | {@link defaultRuleProcessorJsonLogic} |
326
+ * | `elasticsearch` | {@link defaultRuleProcessorElasticSearch} |
327
+ * | `jsonata` | {@link defaultRuleProcessorJSONata} |
328
+ *
329
+ * @group Export
330
+ */
331
+ type RuleProcessor = (rule: RuleType, options?: ValueProcessorOptions, meta?: {
332
+ processedParams?: Record<string, any> | any[];
333
+ context?: Record<string, any>;
334
+ }) => any;
335
+ /**
336
+ * Function to produce a result that {@link formatQuery} uses when processing a
337
+ * {@link RuleGroupType} or {@link RuleGroupTypeIC} object.
338
+ *
339
+ * See the default rule group processor for each format to know what type to return.
340
+ * | Format | Default rule group processor |
341
+ * | ------------------------ | ---------------------------------------------- |
342
+ * | `sql` | {@link defaultRuleGroupProcessorSQL} |
343
+ * | `parameterized` | {@link defaultRuleGroupProcessorParameterized} |
344
+ * | `parameterized_named` | {@link defaultRuleGroupProcessorParameterized} |
345
+ * | `mongodb` _(deprecated)_ | {@link defaultRuleGroupProcessorMongoDB} |
346
+ * | `mongodb_query` | {@link defaultRuleGroupProcessorMongoDBQuery} |
347
+ * | `cel` | {@link defaultRuleGroupProcessorCEL} |
348
+ * | `spel` | {@link defaultRuleGroupProcessorSpEL} |
349
+ * | `jsonlogic` | {@link defaultRuleGroupProcessorJsonLogic} |
350
+ * | `elasticsearch` | {@link defaultRuleGroupProcessorElasticSearch} |
351
+ * | `jsonata` | {@link defaultRuleGroupProcessorJSONata} |
352
+ *
353
+ * @group Export
354
+ */
355
+ type RuleGroupProcessor<TResult = unknown> = (ruleGroup: RuleGroupTypeAny, options: FormatQueryFinalOptions, meta?: {
356
+ processedParams?: Record<string, any> | any[];
357
+ context?: Record<string, any>;
358
+ }) => TResult;
359
+ /**
360
+ * Rule validator for {@link formatQuery}.
361
+ *
362
+ * @group Export
363
+ */
364
+ type FormatQueryValidateRule = (rule: RuleType) => readonly [boolean | ValidationResult | undefined, RuleValidator | undefined];
365
+ /**
366
+ * Object produced by {@link formatQuery} for the `"parameterized"` format.
367
+ *
368
+ * @group Export
369
+ */
370
+ interface ParameterizedSQL {
371
+ /** The SQL `WHERE` clause fragment with `?` placeholders for each value. */
372
+ sql: string;
373
+ /**
374
+ * Parameter values in the same order their respective placeholders
375
+ * appear in the `sql` string.
376
+ */
377
+ params: any[];
378
+ }
379
+ /**
380
+ * Object produced by {@link formatQuery} for the `"parameterized_named"` format.
381
+ *
382
+ * @group Export
383
+ */
384
+ interface ParameterizedNamedSQL {
385
+ /** The SQL `WHERE` clause fragment with bind variable placeholders for each value. */
386
+ sql: string;
387
+ /**
388
+ * Map of bind variable names from the `sql` string to the associated values.
389
+ */
390
+ params: Record<string, any>;
391
+ }
392
+ /**
393
+ * @group Export
394
+ */
395
+ interface RQBJsonLogicStartsWith {
396
+ startsWith: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
397
+ }
398
+ /**
399
+ * @group Export
400
+ */
401
+ interface RQBJsonLogicEndsWith {
402
+ endsWith: [RQBJsonLogic, RQBJsonLogic, ...RQBJsonLogic[]];
403
+ }
404
+ /**
405
+ * JsonLogic rule object with additional operators generated by {@link formatQuery}
406
+ * and accepted by {@link parseJsonLogic!parseJsonLogic}.
407
+ *
408
+ * @group Export
409
+ */
410
+ type RQBJsonLogic = RulesLogic<RQBJsonLogicStartsWith | RQBJsonLogicEndsWith>;
411
+ /**
412
+ * Constituent word order (as array) for the "natural_language" format.
413
+ *
414
+ * - S (subject) = field
415
+ * - V (verb) = operator
416
+ * - O (object) = value
417
+ *
418
+ * @group Export
419
+ */
420
+ type ConstituentWordOrder = ["S", "V", "O"] | ["S", "O", "V"] | ["O", "S", "V"] | ["O", "V", "S"] | ["V", "S", "O"] | ["V", "O", "S"];
421
+ /**
422
+ * Constituent word order (as string) for the "natural_language" format.
423
+ *
424
+ * - S (subject) = field
425
+ * - V (verb) = operator
426
+ * - O (object) = value
427
+ *
428
+ * @group Export
429
+ */
430
+ type ConstituentWordOrderString = "SVO" | "SOV" | "OSV" | "OVS" | "VSO" | "VOS";
431
+ type RepeatStrings<S extends string[], Depth extends number[] = []> = Depth["length"] extends 2 ? "" : "" | `_${S[number]}${RepeatStrings<S, [...Depth, 1]>}`;
432
+ type ZeroOrMoreGroupVariants = RepeatStrings<["xor", "not"]>;
433
+ /**
434
+ * Rule group condition identifier for the "natural_language" format.
435
+ *
436
+ * @group Export
437
+ */
438
+ type GroupVariantCondition = "not" | "xor";
439
+ /**
440
+ * Keys for the `translations` config object used by the "natural_language" format.
441
+ *
442
+ * @group Export
443
+ */
444
+ type NLTranslationKey = "and" | "or" | "true" | "false" | `groupPrefix${ZeroOrMoreGroupVariants}` | `groupSuffix${ZeroOrMoreGroupVariants}`;
445
+ /**
446
+ * `translations` config object for "natural_language" format.
447
+ *
448
+ * @group Export
449
+ */
450
+ type NLTranslations = Partial<Record<NLTranslationKey, string>>;
451
+ //#endregion
452
+ export { ConstituentWordOrder, ExportFormat, ExportObjectFormats, ExportOperatorMap, FormatQueryOptions, GroupVariantCondition, NLTranslationKey, NLTranslations, ParameterizedNamedSQL, ParameterizedSQL, RQBJsonLogic, RuleGroupProcessor, RuleProcessor, SQLPreset, ValueProcessorByRule, ValueProcessorLegacy, ValueProcessorOptions };
453
+ //# sourceMappingURL=export-Ccjfea21.d.mts.map
@@ -1,5 +1,6 @@
1
- import { DefaultOperatorName, Except, FlexibleOptionList, FullField, FullOperator, FullOptionList, InputType, ParseNumbersPropConfig, QueryValidator, RuleGroupTypeAny, RuleType, RuleValidator, ValidationMap, ValidationResult, ValueSource } from "./basic-C8xXKHIA.js";
1
+ import { DefaultOperatorName, FlexibleOptionList, FullField, FullOperator, FullOptionList, InputType, ParseNumbersPropConfig, QueryValidator, RuleGroupTypeAny, RuleType, RuleValidator, ValidationMap, ValidationResult, ValueSource } from "./basic-CDDA-KZa.js";
2
2
  import { RulesLogic } from "json-logic-js";
3
+ import { Except } from "type-fest";
3
4
 
4
5
  //#region src/types/export.d.ts
5
6
 
@@ -449,4 +450,4 @@ type NLTranslationKey = "and" | "or" | "true" | "false" | `groupPrefix${ZeroOrMo
449
450
  type NLTranslations = Partial<Record<NLTranslationKey, string>>;
450
451
  //#endregion
451
452
  export { ConstituentWordOrder, ExportFormat, ExportObjectFormats, ExportOperatorMap, FormatQueryOptions, GroupVariantCondition, NLTranslationKey, NLTranslations, ParameterizedNamedSQL, ParameterizedSQL, RQBJsonLogic, RuleGroupProcessor, RuleProcessor, SQLPreset, ValueProcessorByRule, ValueProcessorLegacy, ValueProcessorOptions };
452
- //# sourceMappingURL=export-DyrnTh6K.d.ts.map
453
+ //# sourceMappingURL=export-GUuxJ7zR.d.ts.map