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