@react-querybuilder/core 8.9.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 (80) hide show
  1. package/README.md +84 -0
  2. package/dist/arrayUtils-D5EoIsKP.js +164 -0
  3. package/dist/arrayUtils-D5EoIsKP.js.map +1 -0
  4. package/dist/basic-C8xXKHIA.d.ts +1235 -0
  5. package/dist/cjs/index.d.ts +1 -0
  6. package/dist/cjs/index.js +6 -0
  7. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +4786 -0
  8. package/dist/cjs/react-querybuilder_core.cjs.development.js +4033 -0
  9. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -0
  10. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +4786 -0
  11. package/dist/cjs/react-querybuilder_core.cjs.production.js +2 -0
  12. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -0
  13. package/dist/convertQuery-DAqoID3O.js +87 -0
  14. package/dist/convertQuery-DAqoID3O.js.map +1 -0
  15. package/dist/export-DyrnTh6K.d.ts +452 -0
  16. package/dist/formatQuery.d.ts +667 -0
  17. package/dist/formatQuery.js +2428 -0
  18. package/dist/formatQuery.js.map +1 -0
  19. package/dist/import-Cksobmln.d.ts +28 -0
  20. package/dist/isRuleGroup-DqAs2x4E.js +120 -0
  21. package/dist/isRuleGroup-DqAs2x4E.js.map +1 -0
  22. package/dist/objectUtils-BBZSfZJz.js +17 -0
  23. package/dist/objectUtils-BBZSfZJz.js.map +1 -0
  24. package/dist/optGroupUtils-CXLgyg2i.js +138 -0
  25. package/dist/optGroupUtils-CXLgyg2i.js.map +1 -0
  26. package/dist/parseCEL.d.ts +34 -0
  27. package/dist/parseCEL.js +2593 -0
  28. package/dist/parseCEL.js.map +1 -0
  29. package/dist/parseJSONata.d.ts +36 -0
  30. package/dist/parseJSONata.js +5884 -0
  31. package/dist/parseJSONata.js.map +1 -0
  32. package/dist/parseJsonLogic.d.ts +36 -0
  33. package/dist/parseJsonLogic.js +191 -0
  34. package/dist/parseJsonLogic.js.map +1 -0
  35. package/dist/parseMongoDB.d.ts +79 -0
  36. package/dist/parseMongoDB.js +267 -0
  37. package/dist/parseMongoDB.js.map +1 -0
  38. package/dist/parseNumber-Bcys1kOH.js +31 -0
  39. package/dist/parseNumber-Bcys1kOH.js.map +1 -0
  40. package/dist/parseSQL.d.ts +37 -0
  41. package/dist/parseSQL.js +6626 -0
  42. package/dist/parseSQL.js.map +1 -0
  43. package/dist/parseSpEL.d.ts +34 -0
  44. package/dist/parseSpEL.js +2911 -0
  45. package/dist/parseSpEL.js.map +1 -0
  46. package/dist/prepareQueryObjects-BqFEs4eV.js +172 -0
  47. package/dist/prepareQueryObjects-BqFEs4eV.js.map +1 -0
  48. package/dist/query-builder-layout.css +1 -0
  49. package/dist/query-builder-layout.css.map +1 -0
  50. package/dist/query-builder-layout.scss +4 -0
  51. package/dist/query-builder.css +1 -0
  52. package/dist/query-builder.css.map +1 -0
  53. package/dist/query-builder.scss +2 -0
  54. package/dist/react-querybuilder_core.d.mts +4786 -0
  55. package/dist/react-querybuilder_core.legacy-esm.d.ts +4786 -0
  56. package/dist/react-querybuilder_core.legacy-esm.js +3916 -0
  57. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -0
  58. package/dist/react-querybuilder_core.mjs +3852 -0
  59. package/dist/react-querybuilder_core.mjs.map +1 -0
  60. package/dist/react-querybuilder_core.production.d.mts +4786 -0
  61. package/dist/react-querybuilder_core.production.mjs +2 -0
  62. package/dist/react-querybuilder_core.production.mjs.map +1 -0
  63. package/dist/styles/_functions.scss +14 -0
  64. package/dist/styles/_layout.scss +201 -0
  65. package/dist/styles/_main.scss +114 -0
  66. package/dist/styles/_root.scss +66 -0
  67. package/dist/styles/_variables.scss +66 -0
  68. package/dist/transformQuery-FL_nlpp5.js +47 -0
  69. package/dist/transformQuery-FL_nlpp5.js.map +1 -0
  70. package/dist/transformQuery.d.ts +118 -0
  71. package/dist/transformQuery.js +4 -0
  72. package/formatQuery/package.json +4 -0
  73. package/package.json +146 -0
  74. package/parseCEL/package.json +4 -0
  75. package/parseJSONata/package.json +4 -0
  76. package/parseJsonLogic/package.json +4 -0
  77. package/parseMongoDB/package.json +4 -0
  78. package/parseSQL/package.json +4 -0
  79. package/parseSpEL/package.json +4 -0
  80. package/transformQuery/package.json +4 -0
@@ -0,0 +1,2428 @@
1
+ const require_isRuleGroup = require('./isRuleGroup-DqAs2x4E.js');
2
+ const require_arrayUtils = require('./arrayUtils-D5EoIsKP.js');
3
+ const require_parseNumber = require('./parseNumber-Bcys1kOH.js');
4
+ const require_transformQuery = require('./transformQuery-FL_nlpp5.js');
5
+ const require_optGroupUtils = require('./optGroupUtils-CXLgyg2i.js');
6
+ const require_convertQuery = require('./convertQuery-DAqoID3O.js');
7
+ let immer = require("immer");
8
+ immer = require_isRuleGroup.__toESM(immer);
9
+
10
+ //#region src/utils/isRuleOrGroupValid.ts
11
+ /**
12
+ * Determines if an object is useful as a validation result.
13
+ */
14
+ const isValidationResult = (vr) => require_isRuleGroup.isPojo(vr) && typeof vr.valid === "boolean";
15
+ /**
16
+ * Determines if a rule or group is valid based on a validation result (if defined)
17
+ * or a validator function. Returns `true` if neither are defined.
18
+ */
19
+ const isRuleOrGroupValid = (rg, validationResult, validator) => {
20
+ if (typeof validationResult === "boolean") return validationResult;
21
+ if (isValidationResult(validationResult)) return validationResult.valid;
22
+ if (typeof validator === "function" && !require_isRuleGroup.isRuleGroup(rg)) {
23
+ const vr = validator(rg);
24
+ if (typeof vr === "boolean") return vr;
25
+ // istanbul ignore else
26
+ if (isValidationResult(vr)) return vr.valid;
27
+ }
28
+ return true;
29
+ };
30
+
31
+ //#endregion
32
+ //#region src/utils/getParseNumberMethod.ts
33
+ const getParseNumberMethod = ({ parseNumbers, inputType }) => {
34
+ if (typeof parseNumbers === "string") {
35
+ const [method, level] = parseNumbers.split("-");
36
+ if (level === "limited") return inputType === "number" ? method : false;
37
+ return method;
38
+ }
39
+ return parseNumbers ? "strict" : false;
40
+ };
41
+
42
+ //#endregion
43
+ //#region src/utils/formatQuery/utils.ts
44
+ /**
45
+ * Maps a {@link DefaultOperatorName} to a SQL operator.
46
+ *
47
+ * @group Export
48
+ */
49
+ const mapSQLOperator = (rqbOperator) => {
50
+ switch (require_isRuleGroup.lc(rqbOperator)) {
51
+ case "null": return "is null";
52
+ case "notnull": return "is not null";
53
+ case "notin": return "not in";
54
+ case "notbetween": return "not between";
55
+ case "contains":
56
+ case "beginswith":
57
+ case "endswith": return "like";
58
+ case "doesnotcontain":
59
+ case "doesnotbeginwith":
60
+ case "doesnotendwith": return "not like";
61
+ default: return rqbOperator;
62
+ }
63
+ };
64
+ /**
65
+ * Maps a (lowercase) {@link DefaultOperatorName} to a MongoDB operator.
66
+ *
67
+ * @group Export
68
+ */
69
+ const mongoOperators = {
70
+ "=": "$eq",
71
+ "!=": "$ne",
72
+ "<": "$lt",
73
+ "<=": "$lte",
74
+ ">": "$gt",
75
+ ">=": "$gte",
76
+ in: "$in",
77
+ notin: "$nin",
78
+ notIn: "$nin"
79
+ };
80
+ /**
81
+ * Maps a (lowercase) {@link DefaultOperatorName} to a Prisma ORM operator.
82
+ *
83
+ * @group Export
84
+ */
85
+ const prismaOperators = {
86
+ "=": "equals",
87
+ "!=": "not",
88
+ "<": "lt",
89
+ "<=": "lte",
90
+ ">": "gt",
91
+ ">=": "gte",
92
+ in: "in",
93
+ notin: "notIn"
94
+ };
95
+ /**
96
+ * Maps a {@link DefaultCombinatorName} to a CEL combinator.
97
+ *
98
+ * @group Export
99
+ */
100
+ const celCombinatorMap = {
101
+ and: "&&",
102
+ or: "||"
103
+ };
104
+ /**
105
+ * Register these operators with `jsonLogic` before applying the result
106
+ * of `formatQuery(query, 'jsonlogic')`.
107
+ *
108
+ * @example
109
+ * ```
110
+ * for (const [op, func] of Object.entries(jsonLogicAdditionalOperators)) {
111
+ * jsonLogic.add_operation(op, func);
112
+ * }
113
+ * jsonLogic.apply({ "startsWith": [{ "var": "firstName" }, "Stev"] }, data);
114
+ * ```
115
+ *
116
+ * @group Export
117
+ */
118
+ const jsonLogicAdditionalOperators = {
119
+ startsWith: (a, b) => typeof a === "string" && a.startsWith(b),
120
+ endsWith: (a, b) => typeof a === "string" && a.endsWith(b)
121
+ };
122
+ /**
123
+ * Converts all `string`-type `value` properties of a query object into `number` where appropriate.
124
+ *
125
+ * Used by {@link formatQuery} for the `json*` formats when `parseNumbers` is `true`.
126
+ *
127
+ * @group Export
128
+ */
129
+ const numerifyValues = (rg, options) => ({
130
+ ...rg,
131
+ rules: rg.rules.map((r) => {
132
+ if (typeof r === "string") return r;
133
+ if (require_isRuleGroup.isRuleGroup(r)) return numerifyValues(r, options);
134
+ const fieldData = require_optGroupUtils.getOption(options.fields, r.field);
135
+ const parseNumbers = getParseNumberMethod({
136
+ parseNumbers: options.parseNumbers,
137
+ inputType: fieldData?.inputType
138
+ });
139
+ if (Array.isArray(r.value)) return {
140
+ ...r,
141
+ value: r.value.map((v) => require_parseNumber.parseNumber(v, { parseNumbers }))
142
+ };
143
+ const valAsArray = require_arrayUtils.toArray(r.value, { retainEmptyStrings: true }).map((v) => require_parseNumber.parseNumber(v, { parseNumbers }));
144
+ if (valAsArray.every((v) => typeof v === "number")) {
145
+ // istanbul ignore else
146
+ if (valAsArray.length > 1) return {
147
+ ...r,
148
+ value: valAsArray
149
+ };
150
+ else if (valAsArray.length === 1) return {
151
+ ...r,
152
+ value: valAsArray[0]
153
+ };
154
+ }
155
+ return r;
156
+ })
157
+ });
158
+ /**
159
+ * Determines whether a value is _anything_ except an empty `string` or `NaN`.
160
+ *
161
+ * @group Export
162
+ */
163
+ const isValidValue = (value) => typeof value === "string" && value.length > 0 || typeof value === "number" && !Number.isNaN(value) || typeof value !== "string" && typeof value !== "number";
164
+ /**
165
+ * Determines whether {@link formatQuery} should render the given value as a number.
166
+ * As long as `parseNumbers` is `true`, `number` and `bigint` values will return `true` and
167
+ * `string` values will return `true` if they test positive against {@link numericRegex}.
168
+ *
169
+ * @group Export
170
+ */
171
+ const shouldRenderAsNumber = (value, parseNumbers) => !!parseNumbers && (typeof value === "number" || typeof value === "bigint" || typeof value === "string" && require_isRuleGroup.numericRegex.test(value));
172
+ /**
173
+ * Used by {@link formatQuery} to determine whether the given value processor is a
174
+ * "legacy" value processor by counting the number of arguments. Legacy value
175
+ * processors take 3 arguments (not counting any arguments with default values), while
176
+ * rule-based value processors take no more than 2 arguments.
177
+ *
178
+ * @group Export
179
+ */
180
+ const isValueProcessorLegacy = (valueProcessor) => valueProcessor.length >= 3;
181
+ /**
182
+ * Converts the `quoteFieldNamesWith` option into an array of two strings.
183
+ * If the option is a string, the array elements are both that string.
184
+ *
185
+ * @default
186
+ * ['', '']
187
+ *
188
+ * @group Export
189
+ */
190
+ const getQuoteFieldNamesWithArray = (quoteFieldNamesWith = ["", ""]) => Array.isArray(quoteFieldNamesWith) ? quoteFieldNamesWith : typeof quoteFieldNamesWith === "string" ? [quoteFieldNamesWith, quoteFieldNamesWith] : quoteFieldNamesWith ?? ["", ""];
191
+ /**
192
+ * Given a field name and relevant {@link ValueProcessorOptions}, returns the field name
193
+ * wrapped in the configured quote character(s).
194
+ *
195
+ * @group Export
196
+ */
197
+ const getQuotedFieldName = (fieldName, { quoteFieldNamesWith, fieldIdentifierSeparator }) => {
198
+ const [qPre, qPost] = getQuoteFieldNamesWithArray(quoteFieldNamesWith);
199
+ return typeof fieldIdentifierSeparator === "string" && fieldIdentifierSeparator.length > 0 ? require_arrayUtils.joinWith(require_arrayUtils.splitBy(fieldName, fieldIdentifierSeparator).map((part) => `${qPre}${part}${qPost}`), fieldIdentifierSeparator) : `${qPre}${fieldName}${qPost}`;
200
+ };
201
+ const defaultWordOrder = [
202
+ "S",
203
+ "V",
204
+ "O"
205
+ ];
206
+ /**
207
+ * Given a [Constituent word order](https://en.wikipedia.org/wiki/Word_order#Constituent_word_orders)
208
+ * like "svo" or "sov", returns a permutation of `["S", "V", "O"]` based on the first occurrence of
209
+ * each letter in the input string (case insensitive). This widens the valid input from abbreviations
210
+ * like "svo" to more expressive strings like "subject-verb-object" or "sub ver obj". Any missing
211
+ * letters are appended in the default order "SVO" (e.g., "object" would yield `["O", "S", "V"]`).
212
+ *
213
+ * @group Export
214
+ */
215
+ const normalizeConstituentWordOrder = (input) => {
216
+ const result = [];
217
+ const letterSet = new Set(defaultWordOrder);
218
+ for (const char of input.toUpperCase()) if (letterSet.has(char)) {
219
+ result.push(char);
220
+ letterSet.delete(char);
221
+ if (letterSet.size === 0) break;
222
+ }
223
+ for (const letter of defaultWordOrder) if (letterSet.has(letter)) result.push(letter);
224
+ return result;
225
+ };
226
+ /**
227
+ * Default translations used by {@link formatQuery} for "natural_language" format.
228
+ *
229
+ * @group Export
230
+ */
231
+ const defaultNLTranslations = {
232
+ groupPrefix: "",
233
+ groupPrefix_not_xor: "either zero or more than one of",
234
+ groupPrefix_xor: "exactly one of",
235
+ groupSuffix: "is true",
236
+ groupSuffix_not: "is not true"
237
+ };
238
+ /**
239
+ * Note: This function assumes `conditions.length > 0`
240
+ */
241
+ const translationMatchFilter = (key, keyToTest, conditions) => keyToTest.startsWith(key) && conditions.every((c) => keyToTest.includes(`_${c}`) && keyToTest.match(/_/g)?.length === conditions.length);
242
+ /**
243
+ * Used by {@link formatQuery} to get a translation based on certain conditions
244
+ * for the "natural_language" format.
245
+ *
246
+ * @group Export
247
+ */
248
+ const getNLTranslataion = (key, translations, conditions = []) => conditions.length === 0 ? translations[key] ?? defaultNLTranslations[key] ?? "" : Object.entries(translations).find(([keyToTest]) => translationMatchFilter(key, keyToTest, conditions))?.[1] ?? Object.entries(defaultNLTranslations).find(([keyToTest]) => translationMatchFilter(key, keyToTest, conditions))?.[1] ?? defaultNLTranslations[key] ?? "";
249
+ const processMatchMode = (rule) => {
250
+ const { mode, threshold } = rule.match ?? {};
251
+ if (mode) {
252
+ if (!require_isRuleGroup.isRuleGroup(rule.value)) return false;
253
+ const matchModeLC = require_isRuleGroup.lc(mode);
254
+ const matchModeCoerced = matchModeLC === "atleast" && threshold === 1 ? "some" : matchModeLC === "atmost" && threshold === 0 ? "none" : matchModeLC;
255
+ if ((matchModeCoerced === "atleast" || matchModeCoerced === "atmost" || matchModeCoerced === "exactly") && (typeof threshold !== "number" || threshold < 0)) return false;
256
+ return {
257
+ mode: matchModeCoerced,
258
+ threshold
259
+ };
260
+ }
261
+ };
262
+ /**
263
+ * "Replacer" method for JSON.stringify's second argument. Converts `bigint` values to
264
+ * objects with a `$bigint` property having a value of a string representation of
265
+ * the actual `bigint`-type value.
266
+ *
267
+ * Inverse of {@link bigIntJsonParseReviver}.
268
+ *
269
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
270
+ */
271
+ const bigIntJsonStringifyReplacer = (_key, value) => typeof value === "bigint" ? { $bigint: value.toString() } : value;
272
+ /**
273
+ * "Reviver" method for JSON.parse's second argument. Converts objects having a single
274
+ * `$bigint: string` property to an actual `bigint` value.
275
+ *
276
+ * Inverse of {@link bigIntJsonStringifyReplacer}.
277
+ *
278
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
279
+ */
280
+ const bigIntJsonParseReviver = (_key, value) => require_isRuleGroup.isPojo(value) && Object.keys(value).length === 1 && typeof value.$bigint === "string" ? BigInt(value.$bigint) : value;
281
+
282
+ //#endregion
283
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorCEL.ts
284
+ /**
285
+ * Rule group processor used by {@link formatQuery} for "cel" format.
286
+ *
287
+ * @group Export
288
+ */
289
+ const defaultRuleGroupProcessorCEL = (ruleGroup, options) => {
290
+ const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
291
+ const processRuleGroup = (rg, outermost) => {
292
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? fallbackExpression : "";
293
+ const expression = rg.rules.map((rule) => {
294
+ if (typeof rule === "string") return celCombinatorMap[rule];
295
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule);
296
+ const [validationResult, fieldValidator] = validateRule(rule);
297
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return "";
298
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
299
+ return ruleProcessor(rule, {
300
+ ...options,
301
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
302
+ escapeQuotes: (rule.valueSource ?? "value") === "value",
303
+ fieldData
304
+ });
305
+ }).filter(Boolean).join(require_isRuleGroup.isRuleGroupType(rg) ? ` ${celCombinatorMap[rg.combinator]} ` : " ");
306
+ const [prefix, suffix] = rg.not || !outermost ? [`${rg.not ? "!" : ""}(`, ")"] : ["", ""];
307
+ return expression ? `${prefix}${expression}${suffix}` : fallbackExpression;
308
+ };
309
+ return processRuleGroup(ruleGroup, true);
310
+ };
311
+
312
+ //#endregion
313
+ //#region src/utils/formatQuery/defaultRuleProcessorCEL.ts
314
+ const shouldNegate$2 = (op) => op.startsWith("not") || op.startsWith("doesnot");
315
+ const escapeDoubleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`);
316
+ /**
317
+ * Default rule processor used by {@link formatQuery} for "cel" format.
318
+ *
319
+ * @group Export
320
+ */
321
+ const defaultRuleProcessorCEL = (rule, opts = {}) => {
322
+ const { escapeQuotes, parseNumbers, preserveValueOrder } = opts;
323
+ const { field, operator, value, valueSource } = rule;
324
+ const valueIsField = valueSource === "field";
325
+ const operatorTL = require_isRuleGroup.lc(operator === "=" ? "==" : operator);
326
+ const useBareValue = typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || shouldRenderAsNumber(value, parseNumbers);
327
+ const matchEval = processMatchMode(rule);
328
+ if (matchEval === false) return "";
329
+ else if (matchEval) {
330
+ const { mode, threshold } = matchEval;
331
+ const arrayElementAlias = "elem_alias";
332
+ const celQuery = require_transformQuery.transformQuery(rule.value, { ruleProcessor: (r) => ({
333
+ ...r,
334
+ field: `${arrayElementAlias}${r.field ? `.${r.field}` : ""}`
335
+ }) });
336
+ const nestedArrayFilter = defaultRuleGroupProcessorCEL(celQuery, opts);
337
+ switch (mode) {
338
+ case "all": return `${field}.all(${arrayElementAlias}, ${nestedArrayFilter})`;
339
+ case "none":
340
+ case "some": return `${mode === "none" ? "!" : ""}${field}.exists(${arrayElementAlias}, ${nestedArrayFilter})`;
341
+ case "atleast":
342
+ case "atmost":
343
+ case "exactly": {
344
+ const totalCount = `double(${field}.size())`;
345
+ const filteredCount = `${field}.filter(${arrayElementAlias}, ${nestedArrayFilter}).size()`;
346
+ const op = mode === "atleast" ? ">=" : mode === "atmost" ? "<=" : "==";
347
+ if (threshold > 0 && threshold < 1) return `${filteredCount} ${op} (${totalCount} * ${threshold})`;
348
+ return `${filteredCount} ${op} ${threshold}`;
349
+ }
350
+ }
351
+ }
352
+ switch (operatorTL) {
353
+ case "<":
354
+ case "<=":
355
+ case "==":
356
+ case "!=":
357
+ case ">":
358
+ case ">=": return `${field} ${operatorTL} ${valueIsField || useBareValue ? require_arrayUtils.trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`}`;
359
+ case "contains":
360
+ case "doesnotcontain": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.contains(${valueIsField ? require_arrayUtils.trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`;
361
+ case "beginswith":
362
+ case "doesnotbeginwith": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.startsWith(${valueIsField ? require_arrayUtils.trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`;
363
+ case "endswith":
364
+ case "doesnotendwith": return `${shouldNegate$2(operatorTL) ? "!" : ""}${field}.endsWith(${valueIsField ? require_arrayUtils.trimIfString(value) : `"${escapeDoubleQuotes(value, escapeQuotes)}"`})`;
365
+ case "null": return `${field} == null`;
366
+ case "notnull": return `${field} != null`;
367
+ case "in":
368
+ case "notin": {
369
+ const [prefix, suffix] = shouldNegate$2(operatorTL) ? ["!(", ")"] : ["", ""];
370
+ const valueAsArray = require_arrayUtils.toArray(value);
371
+ return `${prefix}${field} in [${valueAsArray.map((val) => valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${require_arrayUtils.trimIfString(val)}` : `"${escapeDoubleQuotes(val, escapeQuotes)}"`).join(", ")}]${suffix}`;
372
+ }
373
+ case "between":
374
+ case "notbetween": {
375
+ const valueAsArray = require_arrayUtils.toArray(value);
376
+ if (valueAsArray.length >= 2 && !require_isRuleGroup.nullOrUndefinedOrEmpty(valueAsArray[0]) && !require_isRuleGroup.nullOrUndefinedOrEmpty(valueAsArray[1])) {
377
+ const [first, second] = valueAsArray;
378
+ const shouldParseNumbers = !(parseNumbers === false);
379
+ const firstNum = shouldRenderAsNumber(first, shouldParseNumbers) ? require_parseNumber.parseNumber(first, { parseNumbers: shouldParseNumbers }) : NaN;
380
+ const secondNum = shouldRenderAsNumber(second, shouldParseNumbers) ? require_parseNumber.parseNumber(second, { parseNumbers: shouldParseNumbers }) : NaN;
381
+ let firstValue = Number.isNaN(firstNum) ? valueIsField ? `${first}` : `"${escapeDoubleQuotes(first, escapeQuotes)}"` : firstNum;
382
+ let secondValue = Number.isNaN(secondNum) ? valueIsField ? `${second}` : `"${escapeDoubleQuotes(second, escapeQuotes)}"` : secondNum;
383
+ if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
384
+ const tempNum = secondNum;
385
+ secondValue = firstNum;
386
+ firstValue = tempNum;
387
+ }
388
+ return operatorTL === "between" ? `(${field} >= ${firstValue} && ${field} <= ${secondValue})` : `(${field} < ${firstValue} || ${field} > ${secondValue})`;
389
+ } else return "";
390
+ }
391
+ }
392
+ return "";
393
+ };
394
+
395
+ //#endregion
396
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorMongoDBQuery.ts
397
+ /**
398
+ * Default fallback object used by {@link formatQuery} for "mongodb_query" format.
399
+ *
400
+ * @group Export
401
+ */
402
+ const mongoDbFallback = { $and: [{ $expr: true }] };
403
+ /**
404
+ * Rule group processor used by {@link formatQuery} for "mongodb_query" format.
405
+ *
406
+ * @group Export
407
+ */
408
+ const defaultRuleGroupProcessorMongoDBQuery = (ruleGroup, options, meta) => {
409
+ const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
410
+ const processRuleGroup = (rg, outermost) => {
411
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? mongoDbFallback : false;
412
+ const combinator = `$${require_isRuleGroup.lc(rg.combinator)}`;
413
+ let hasChildRules = false;
414
+ const expressions = rg.rules.map((rule) => {
415
+ if (require_isRuleGroup.isRuleGroup(rule)) {
416
+ const processedRuleGroup = processRuleGroup(rule);
417
+ if (processedRuleGroup) {
418
+ hasChildRules = true;
419
+ return processedRuleGroup;
420
+ }
421
+ return false;
422
+ }
423
+ const [validationResult, fieldValidator] = validateRule(rule);
424
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return false;
425
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
426
+ return ruleProcessor(rule, {
427
+ ...options,
428
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
429
+ fieldData
430
+ }, meta);
431
+ }).filter(Boolean);
432
+ return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : mongoDbFallback;
433
+ };
434
+ return processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
435
+ };
436
+
437
+ //#endregion
438
+ //#region src/utils/formatQuery/defaultRuleProcessorMongoDBQuery.ts
439
+ const processNumber$1 = (value, fallback, parseNumbers = false) => shouldRenderAsNumber(value, parseNumbers || typeof value === "bigint") ? Number(require_parseNumber.parseNumber(value, { parseNumbers: "strict" })) : fallback;
440
+ /**
441
+ * Default rule processor used by {@link formatQuery} for "mongodb_query" format.
442
+ *
443
+ * @group Export
444
+ */
445
+ const defaultRuleProcessorMongoDBQuery = (rule, options = {}) => {
446
+ const { field, operator, value, valueSource } = rule;
447
+ const { parseNumbers, preserveValueOrder, context } = options;
448
+ const valueIsField = valueSource === "field";
449
+ const { avoidFieldsAsKeys } = context ?? {};
450
+ const matchEval = processMatchMode(rule);
451
+ if (matchEval === false) return;
452
+ else if (matchEval) {
453
+ const { mode, threshold } = matchEval;
454
+ const totalCount = { $size: { $ifNull: [`$${field}`, []] } };
455
+ const subQueryNoAggCtx = defaultRuleGroupProcessorMongoDBQuery(require_transformQuery.transformQuery(value, { ruleProcessor: (r) => ({
456
+ ...r,
457
+ field: r.field ? `${field}.${r.field}` : field
458
+ }) }), {
459
+ ...options,
460
+ ruleProcessor: defaultRuleProcessorMongoDBQuery,
461
+ context: {
462
+ ...options.context,
463
+ avoidFieldsAsKeys: false
464
+ }
465
+ });
466
+ const subQueryWithAggCtx = defaultRuleGroupProcessorMongoDBQuery(require_transformQuery.transformQuery(value, { ruleProcessor: (r) => ({
467
+ ...r,
468
+ field: r.field ? `$item.${r.field}` : "$item"
469
+ }) }), {
470
+ ...options,
471
+ ruleProcessor: defaultRuleProcessorMongoDBQuery,
472
+ context: {
473
+ ...options.context,
474
+ avoidFieldsAsKeys: true
475
+ }
476
+ });
477
+ const filteredCount = { $size: { $ifNull: [{ $filter: {
478
+ input: `$${field}`,
479
+ as: "item",
480
+ cond: { $and: [subQueryWithAggCtx] }
481
+ } }, []] } };
482
+ switch (mode) {
483
+ case "all": return { $expr: { $eq: [filteredCount, totalCount] } };
484
+ case "none": return { $nor: [subQueryNoAggCtx] };
485
+ case "some": return subQueryNoAggCtx;
486
+ case "atleast":
487
+ case "atmost":
488
+ case "exactly": {
489
+ const op = mode === "atleast" ? mongoOperators[">="] : mode === "atmost" ? mongoOperators["<="] : mongoOperators["="];
490
+ if (threshold > 0 && threshold < 1) return { $expr: { [op]: [filteredCount, { $multiply: [totalCount, threshold] }] } };
491
+ return { $expr: { [op]: [filteredCount, threshold] } };
492
+ }
493
+ }
494
+ }
495
+ if (operator === "=" && !valueIsField) return avoidFieldsAsKeys ? { $eq: [`$${field}`, processNumber$1(value, value, parseNumbers)] } : { [field]: processNumber$1(value, value, parseNumbers) };
496
+ const operatorLC = require_isRuleGroup.lc(operator);
497
+ switch (operatorLC) {
498
+ case "<":
499
+ case "<=":
500
+ case "=":
501
+ case "!=":
502
+ case ">":
503
+ case ">=": {
504
+ const mongoOperator = mongoOperators[operatorLC];
505
+ return valueIsField ? { [mongoOperator]: [`$${field}`, `$${value}`] } : avoidFieldsAsKeys ? { $and: [{ $ne: [`$${field}`, null] }, { [mongoOperator]: [`$${field}`, processNumber$1(value, value, parseNumbers)] }] } : { [field]: { [mongoOperator]: processNumber$1(value, value, parseNumbers) } };
506
+ }
507
+ case "contains": return valueIsField ? { $where: `this.${field}.includes(this.${value})` } : avoidFieldsAsKeys ? { $regexMatch: {
508
+ input: `$${field}`,
509
+ regex: value
510
+ } } : { [field]: { $regex: value } };
511
+ case "beginswith": return valueIsField ? { $where: `this.${field}.startsWith(this.${value})` } : avoidFieldsAsKeys ? { $regexMatch: {
512
+ input: `$${field}`,
513
+ regex: `^${value}`
514
+ } } : { [field]: { $regex: `^${value}` } };
515
+ case "endswith": return valueIsField ? { $where: `this.${field}.endsWith(this.${value})` } : avoidFieldsAsKeys ? { $regexMatch: {
516
+ input: `$${field}`,
517
+ regex: `${value}$`
518
+ } } : { [field]: { $regex: `${value}$` } };
519
+ case "doesnotcontain": return valueIsField ? { $where: `!this.${field}.includes(this.${value})` } : avoidFieldsAsKeys ? { $not: { $regexMatch: {
520
+ input: `$${field}`,
521
+ regex: value
522
+ } } } : { [field]: { $not: { $regex: value } } };
523
+ case "doesnotbeginwith": return valueIsField ? { $where: `!this.${field}.startsWith(this.${value})` } : avoidFieldsAsKeys ? { $not: { $regexMatch: {
524
+ input: `$${field}`,
525
+ regex: `^${value}`
526
+ } } } : { [field]: { $not: { $regex: `^${value}` } } };
527
+ case "doesnotendwith": return valueIsField ? { $where: `!this.${field}.endsWith(this.${value})` } : avoidFieldsAsKeys ? { $not: { $regexMatch: {
528
+ input: `$${field}`,
529
+ regex: `${value}$`
530
+ } } } : { [field]: { $not: { $regex: `${value}$` } } };
531
+ case "null": return avoidFieldsAsKeys ? { $eq: [`$${field}`, null] } : { [field]: null };
532
+ case "notnull": return avoidFieldsAsKeys ? { $ne: [`$${field}`, null] } : { [field]: { $ne: null } };
533
+ case "in":
534
+ case "notin": {
535
+ const valueAsArray = require_arrayUtils.toArray(value);
536
+ return valueIsField ? { $where: `${operatorLC === "notin" ? "!" : ""}[${valueAsArray.map((val) => `this.${val}`).join(",")}].includes(this.${field})` } : avoidFieldsAsKeys ? operatorLC === "notin" ? { $not: { [mongoOperators.in]: [`$${field}`, valueAsArray.map((val) => processNumber$1(val, val, parseNumbers))] } } : { [mongoOperators[operatorLC]]: [`$${field}`, valueAsArray.map((val) => processNumber$1(val, val, parseNumbers))] } : { [field]: { [mongoOperators[operatorLC]]: valueAsArray.map((val) => processNumber$1(val, val, parseNumbers)) } };
537
+ }
538
+ case "between":
539
+ case "notbetween": {
540
+ const valueAsArray = require_arrayUtils.toArray(value);
541
+ if (valueAsArray.length >= 2 && isValidValue(valueAsArray[0]) && isValidValue(valueAsArray[1])) {
542
+ const [first, second] = valueAsArray;
543
+ const firstNum = processNumber$1(first, NaN, true);
544
+ const secondNum = processNumber$1(second, NaN, true);
545
+ let firstValue = valueIsField ? first : Number.isNaN(firstNum) ? first : firstNum;
546
+ let secondValue = valueIsField ? second : Number.isNaN(secondNum) ? second : secondNum;
547
+ if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
548
+ const tempNum = secondNum;
549
+ secondValue = firstNum;
550
+ firstValue = tempNum;
551
+ }
552
+ if (operatorLC === "between") return valueIsField ? {
553
+ $gte: [`$${field}`, `$${firstValue}`],
554
+ $lte: [`$${field}`, `$${secondValue}`]
555
+ } : avoidFieldsAsKeys ? { $and: [{ $gte: [`$${field}`, firstValue] }, { $lte: [`$${field}`, secondValue] }] } : { [field]: {
556
+ $gte: firstValue,
557
+ $lte: secondValue
558
+ } };
559
+ else return valueIsField ? { $or: [{ $lt: [`$${field}`, `$${firstValue}`] }, { $gt: [`$${field}`, `$${secondValue}`] }] } : avoidFieldsAsKeys ? { $or: [{ $lt: [`$${field}`, firstValue] }, { $gt: [`$${field}`, secondValue] }] } : { $or: [{ [field]: { $lt: firstValue } }, { [field]: { $gt: secondValue } }] };
560
+ } else return "";
561
+ }
562
+ }
563
+ return "";
564
+ };
565
+
566
+ //#endregion
567
+ //#region src/utils/formatQuery/defaultRuleProcessorMongoDB.ts
568
+ /**
569
+ * Default rule processor used by {@link formatQuery} for "mongodb" format.
570
+ *
571
+ * Note that the "mongodb" format is deprecated in favor of the "mongodb_query" format.
572
+ *
573
+ * @group Export
574
+ */
575
+ const defaultRuleProcessorMongoDB = (rule, options) => {
576
+ const queryObj = defaultRuleProcessorMongoDBQuery(rule, options);
577
+ return queryObj ? JSON.stringify(queryObj) : "";
578
+ };
579
+
580
+ //#endregion
581
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorSpEL.ts
582
+ /**
583
+ * Default rule processor used by {@link formatQuery} for "spel" format.
584
+ *
585
+ * @group Export
586
+ */
587
+ const defaultRuleGroupProcessorSpEL = (ruleGroup, options) => {
588
+ const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
589
+ const processRuleGroup = (rg, outermost) => {
590
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? fallbackExpression : "";
591
+ const expression = rg.rules.map((rule) => {
592
+ if (typeof rule === "string") return rule;
593
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule);
594
+ const [validationResult, fieldValidator] = validateRule(rule);
595
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return "";
596
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
597
+ return ruleProcessor(rule, {
598
+ ...options,
599
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
600
+ escapeQuotes: (rule.valueSource ?? "value") === "value",
601
+ fieldData
602
+ });
603
+ }).filter(Boolean).join(require_isRuleGroup.isRuleGroupType(rg) ? ` ${rg.combinator} ` : " ");
604
+ const [prefix, suffix] = rg.not || !outermost ? [`${rg.not ? "!" : ""}(`, ")"] : ["", ""];
605
+ return expression ? `${prefix}${expression}${suffix}` : fallbackExpression;
606
+ };
607
+ return processRuleGroup(ruleGroup, true);
608
+ };
609
+
610
+ //#endregion
611
+ //#region src/utils/formatQuery/defaultRuleProcessorSpEL.ts
612
+ const shouldNegate$1 = (op) => op.startsWith("not") || op.startsWith("doesnot");
613
+ const wrapInNegation = (clause, negate$1) => negate$1 ? `!(${clause})` : clause;
614
+ const escapeSingleQuotes = (v, escapeQuotes) => typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`'`, `\\'`);
615
+ /**
616
+ * Default rule processor used by {@link formatQuery} for "spel" format.
617
+ *
618
+ * @group Export
619
+ */
620
+ const defaultRuleProcessorSpEL = (rule, opts = {}) => {
621
+ const { field, operator, value, valueSource } = rule;
622
+ const { escapeQuotes, parseNumbers, preserveValueOrder } = opts;
623
+ const valueIsField = valueSource === "field";
624
+ const operatorTL = require_isRuleGroup.lc(operator === "=" ? "==" : operator);
625
+ const useBareValue = typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || shouldRenderAsNumber(value, parseNumbers);
626
+ const matchEval = processMatchMode(rule);
627
+ if (matchEval === false) return "";
628
+ else if (matchEval) {
629
+ const { mode, threshold } = matchEval;
630
+ const nestedArrayFilter = defaultRuleGroupProcessorSpEL(require_transformQuery.transformQuery(rule.value, { ruleProcessor: (r) => ({
631
+ ...r,
632
+ field: r.field || "#this"
633
+ }) }), opts);
634
+ const totalCount = `${field}.size()`;
635
+ const filteredCount = `${field}.?[${nestedArrayFilter}].size()`;
636
+ switch (mode) {
637
+ case "all": return `${filteredCount} == ${totalCount}`;
638
+ case "none": return `${filteredCount} == 0`;
639
+ case "some": return `${filteredCount} >= 1`;
640
+ case "atleast":
641
+ case "atmost":
642
+ case "exactly": {
643
+ const op = mode === "atleast" ? ">=" : mode === "atmost" ? "<=" : "==";
644
+ if (threshold > 0 && threshold < 1) return `${filteredCount} ${op} (${totalCount} * ${threshold})`;
645
+ return `${filteredCount} ${op} ${threshold}`;
646
+ }
647
+ }
648
+ }
649
+ switch (operatorTL) {
650
+ case "<":
651
+ case "<=":
652
+ case "==":
653
+ case "!=":
654
+ case ">":
655
+ case ">=": return `${field} ${operatorTL} ${valueIsField || useBareValue ? require_arrayUtils.trimIfString(value) : `'${escapeSingleQuotes(value, escapeQuotes)}'`}`;
656
+ case "contains":
657
+ case "doesnotcontain": return wrapInNegation(`${field} matches ${valueIsField || useBareValue ? require_arrayUtils.trimIfString(value) : `'${escapeSingleQuotes(value, escapeQuotes)}'`}`, shouldNegate$1(operatorTL));
658
+ case "beginswith":
659
+ case "doesnotbeginwith": {
660
+ const valueTL = valueIsField ? `'^'.concat(${require_arrayUtils.trimIfString(value)})` : `'${typeof value === "string" && !value.startsWith("^") || useBareValue ? "^" : ""}${escapeSingleQuotes(value, escapeQuotes)}'`;
661
+ return wrapInNegation(`${field} matches ${valueTL}`, shouldNegate$1(operatorTL));
662
+ }
663
+ case "endswith":
664
+ case "doesnotendwith": {
665
+ const valueTL = valueIsField ? `${require_arrayUtils.trimIfString(value)}.concat('$')` : `'${escapeSingleQuotes(value, escapeQuotes)}${typeof value === "string" && !value.endsWith("$") || useBareValue ? "$" : ""}'`;
666
+ return wrapInNegation(`${field} matches ${valueTL}`, shouldNegate$1(operatorTL));
667
+ }
668
+ case "null": return `${field} == null`;
669
+ case "notnull": return `${field} != null`;
670
+ case "in":
671
+ case "notin": {
672
+ const negate$1 = shouldNegate$1(operatorTL) ? "!" : "";
673
+ const valueAsArray = require_arrayUtils.toArray(value);
674
+ return valueAsArray.length > 0 ? `${negate$1}(${valueAsArray.map((val) => `${field} == ${valueIsField || shouldRenderAsNumber(val, parseNumbers) ? `${require_arrayUtils.trimIfString(val)}` : `'${escapeSingleQuotes(val, escapeQuotes)}'`}`).join(" or ")})` : "";
675
+ }
676
+ case "between":
677
+ case "notbetween": {
678
+ const valueAsArray = require_arrayUtils.toArray(value);
679
+ if (valueAsArray.length >= 2 && !require_isRuleGroup.nullOrUndefinedOrEmpty(valueAsArray[0]) && !require_isRuleGroup.nullOrUndefinedOrEmpty(valueAsArray[1])) {
680
+ const [first, second] = valueAsArray;
681
+ const shouldParseNumbers = !(parseNumbers === false);
682
+ const firstNum = shouldRenderAsNumber(first, shouldParseNumbers) ? require_parseNumber.parseNumber(first, { parseNumbers: shouldParseNumbers }) : NaN;
683
+ const secondNum = shouldRenderAsNumber(second, shouldParseNumbers) ? require_parseNumber.parseNumber(second, { parseNumbers: shouldParseNumbers }) : NaN;
684
+ let firstValue = Number.isNaN(firstNum) ? valueIsField ? `${first}` : `'${escapeSingleQuotes(first, escapeQuotes)}'` : firstNum;
685
+ let secondValue = Number.isNaN(secondNum) ? valueIsField ? `${second}` : `'${escapeSingleQuotes(second, escapeQuotes)}'` : secondNum;
686
+ if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
687
+ const tempNum = secondNum;
688
+ secondValue = firstNum;
689
+ firstValue = tempNum;
690
+ }
691
+ return operatorTL === "between" ? `(${field} >= ${firstValue} and ${field} <= ${secondValue})` : `(${field} < ${firstValue} or ${field} > ${secondValue})`;
692
+ } else return "";
693
+ }
694
+ }
695
+ return "";
696
+ };
697
+
698
+ //#endregion
699
+ //#region src/utils/formatQuery/defaultValueProcessorByRule.ts
700
+ const escapeStringValueQuotes$1 = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
701
+ /**
702
+ * Default value processor used by {@link formatQuery} for "sql" format.
703
+ *
704
+ * @group Export
705
+ */
706
+ const defaultValueProcessorByRule = ({ operator, value, valueSource }, { escapeQuotes, parseNumbers, preserveValueOrder, quoteFieldNamesWith, quoteValuesWith, concatOperator = "||", fieldIdentifierSeparator, wrapValueWith = ["", ""], translations } = {}) => {
707
+ const valueIsField = valueSource === "field";
708
+ const operatorLowerCase = require_isRuleGroup.lc(operator);
709
+ const quoteChar = quoteValuesWith || "'";
710
+ const quoteValue = (v) => `${wrapValueWith[0]}${quoteChar}${v}${quoteChar}${wrapValueWith[1]}`;
711
+ const escapeValue = (v) => escapeStringValueQuotes$1(v, quoteChar, escapeQuotes);
712
+ const wrapAndEscape = (v) => quoteValue(escapeValue(v));
713
+ const wrapFieldName = (v) => getQuotedFieldName(v, {
714
+ quoteFieldNamesWith,
715
+ fieldIdentifierSeparator
716
+ });
717
+ const concat = (...values) => concatOperator.toUpperCase() === "CONCAT" ? `CONCAT(${values.join(", ")})` : values.join(` ${concatOperator} `);
718
+ switch (operatorLowerCase) {
719
+ case "null":
720
+ case "notnull": return "";
721
+ case "in":
722
+ case "notin": {
723
+ const valueAsArray = require_arrayUtils.toArray(value);
724
+ if (valueAsArray.length > 0) return `(${valueAsArray.map((v) => valueIsField ? wrapFieldName(v) : shouldRenderAsNumber(v, parseNumbers) ? `${require_arrayUtils.trimIfString(v)}` : `${wrapAndEscape(v)}`).join(", ")})`;
725
+ return "";
726
+ }
727
+ case "between":
728
+ case "notbetween": {
729
+ const valueAsArray = require_arrayUtils.toArray(value, { retainEmptyStrings: true });
730
+ if (valueAsArray.length < 2 || !isValidValue(valueAsArray[0]) || !isValidValue(valueAsArray[1])) return "";
731
+ const [first, second] = valueAsArray;
732
+ const firstNum = shouldRenderAsNumber(first, parseNumbers) ? require_parseNumber.parseNumber(first, { parseNumbers: "strict" }) : NaN;
733
+ const secondNum = shouldRenderAsNumber(second, parseNumbers) ? require_parseNumber.parseNumber(second, { parseNumbers: "strict" }) : NaN;
734
+ const firstValue = Number.isNaN(firstNum) ? valueIsField ? `${first}` : first : firstNum;
735
+ const secondValue = Number.isNaN(secondNum) ? valueIsField ? `${second}` : second : secondNum;
736
+ const valsOneAndTwoOnly = [firstValue, secondValue];
737
+ if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
738
+ valsOneAndTwoOnly[0] = secondNum;
739
+ valsOneAndTwoOnly[1] = firstNum;
740
+ }
741
+ return (valueIsField ? valsOneAndTwoOnly.map((v) => wrapFieldName(v)) : valsOneAndTwoOnly.every((v) => shouldRenderAsNumber(v, parseNumbers)) ? valsOneAndTwoOnly.map((v) => require_parseNumber.parseNumber(v, { parseNumbers: "strict" })) : valsOneAndTwoOnly.map((v) => wrapAndEscape(v))).join(` ${translations?.and ?? "and"} `);
742
+ }
743
+ case "contains":
744
+ case "doesnotcontain": return valueIsField ? concat(quoteValue("%"), wrapFieldName(value), quoteValue("%")) : quoteValue(`%${escapeValue(value)}%`);
745
+ case "beginswith":
746
+ case "doesnotbeginwith": return valueIsField ? concat(wrapFieldName(value), quoteValue("%")) : quoteValue(`${escapeValue(value)}%`);
747
+ case "endswith":
748
+ case "doesnotendwith": return valueIsField ? concat(quoteValue("%"), wrapFieldName(value)) : quoteValue(`%${escapeValue(value)}`);
749
+ }
750
+ if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
751
+ return valueIsField ? wrapFieldName(value) : shouldRenderAsNumber(value, parseNumbers) ? `${require_arrayUtils.trimIfString(value)}` : `${wrapAndEscape(value)}`;
752
+ };
753
+
754
+ //#endregion
755
+ //#region src/utils/formatQuery/defaultRuleProcessorDrizzle.ts
756
+ /**
757
+ * Default rule processor used by {@link formatQuery} for the "drizzle" format.
758
+ *
759
+ * @group Export
760
+ */
761
+ const defaultRuleProcessorDrizzle = (rule, _options) => {
762
+ const opts = _options ?? ( /* istanbul ignore next */ {});
763
+ // istanbul ignore next
764
+ const { parseNumbers, preserveValueOrder, context = {} } = opts;
765
+ const { columns, drizzleOperators, useRawFields } = context;
766
+ if (!columns || !drizzleOperators) return;
767
+ const { between, eq, gt, gte, inArray, isNotNull, isNull, like, lt, lte, ne, notBetween, notInArray, notLike, sql } = drizzleOperators;
768
+ const { field, operator, value, valueSource } = rule;
769
+ const column = useRawFields && /[a-z][a-z0-9]*/i.test(field) ? sql.raw(field) : columns[field];
770
+ const operatorLC = require_isRuleGroup.lc(operator);
771
+ const valueIsField = valueSource === "field";
772
+ const asFieldOrValue = (v) => valueIsField ? columns[v] : v;
773
+ if (!column) return;
774
+ const matchEval = processMatchMode(rule);
775
+ if (matchEval === false) return;
776
+ else if (matchEval) {
777
+ if (opts.preset !== "postgresql") return;
778
+ const { mode, threshold } = matchEval;
779
+ const arrayElementAlias = "elem_alias";
780
+ const sqlQuery = require_transformQuery.transformQuery(rule.value, { ruleProcessor: (r) => ({
781
+ ...r,
782
+ field: arrayElementAlias
783
+ }) });
784
+ const nestedArrayFilter = defaultRuleGroupProcessorDrizzle(sqlQuery, {
785
+ ...opts,
786
+ context: {
787
+ ...opts.context,
788
+ useRawFields: true
789
+ }
790
+ });
791
+ switch (mode) {
792
+ case "all": return sql`(select count(*) from unnest(${column}) as ${sql.raw(arrayElementAlias)} where ${nestedArrayFilter({}, drizzleOperators)}) = array_length(${column}, 1)`;
793
+ case "none": return sql`not exists (select 1 from unnest(${column}) as ${sql.raw(arrayElementAlias)} where ${nestedArrayFilter({}, drizzleOperators)})`;
794
+ case "some": return sql`exists (select 1 from unnest(${column}) as ${sql.raw(arrayElementAlias)} where ${nestedArrayFilter({}, drizzleOperators)})`;
795
+ case "atleast":
796
+ case "atmost":
797
+ case "exactly": {
798
+ const op = mode === "atleast" ? ">=" : mode === "atmost" ? "<=" : "=";
799
+ return threshold > 0 && threshold < 1 ? sql`(select count(*) / array_length(${column}, 1) from unnest(${column}) as ${sql.raw(arrayElementAlias)} where ${nestedArrayFilter({}, drizzleOperators)}) ${sql.raw(`${op} ${threshold}`)}` : sql`(select count(*) from unnest(${column}) as ${sql.raw(arrayElementAlias)} where ${nestedArrayFilter({}, drizzleOperators)}) ${sql.raw(`${op} ${threshold}`)}`;
800
+ }
801
+ }
802
+ }
803
+ switch (operatorLC) {
804
+ case "=": return eq(column, asFieldOrValue(value));
805
+ case "!=": return ne(column, asFieldOrValue(value));
806
+ case ">": return gt(column, asFieldOrValue(value));
807
+ case "<": return lt(column, asFieldOrValue(value));
808
+ case ">=": return gte(column, asFieldOrValue(value));
809
+ case "<=": return lte(column, asFieldOrValue(value));
810
+ case "beginswith":
811
+ case "doesnotbeginwith": return (operatorLC === "doesnotbeginwith" ? notLike : like)(column, valueIsField ? sql`${asFieldOrValue(value)} || '%'` : `${value}%`);
812
+ case "contains":
813
+ case "doesnotcontain": return (operatorLC === "doesnotcontain" ? notLike : like)(column, valueIsField ? sql`'%' || ${asFieldOrValue(value)} || '%'` : `%${value}%`);
814
+ case "endswith":
815
+ case "doesnotendwith": return (operatorLC === "doesnotendwith" ? notLike : like)(column, valueIsField ? sql`'%' || ${asFieldOrValue(value)}` : `%${value}`);
816
+ case "null": return isNull(column);
817
+ case "notnull": return isNotNull(column);
818
+ case "in":
819
+ case "notin": {
820
+ const valueAsArray = require_arrayUtils.toArray(value).map((v) => asFieldOrValue(v));
821
+ return operatorLC === "notin" ? notInArray(column, valueAsArray) : inArray(column, valueAsArray);
822
+ }
823
+ case "between":
824
+ case "notbetween": {
825
+ const valueAsArray = require_arrayUtils.toArray(value);
826
+ if (valueAsArray.length >= 2 && isValidValue(valueAsArray[0]) && isValidValue(valueAsArray[1])) {
827
+ let [first, second] = valueAsArray;
828
+ const shouldParseNumbers = !(parseNumbers === false);
829
+ if (!valueIsField && shouldRenderAsNumber(first, shouldParseNumbers) && shouldRenderAsNumber(second, shouldParseNumbers)) {
830
+ const firstNum = require_parseNumber.parseNumber(first, { parseNumbers: shouldParseNumbers });
831
+ const secondNum = require_parseNumber.parseNumber(second, { parseNumbers: shouldParseNumbers });
832
+ if (!preserveValueOrder && secondNum < firstNum) {
833
+ const tempNum = secondNum;
834
+ second = firstNum;
835
+ first = tempNum;
836
+ } else {
837
+ first = firstNum;
838
+ second = secondNum;
839
+ }
840
+ } else if (valueIsField) {
841
+ first = asFieldOrValue(first);
842
+ second = asFieldOrValue(second);
843
+ }
844
+ return operatorLC === "notbetween" ? notBetween(column, first, second) : between(column, first, second);
845
+ }
846
+ return;
847
+ }
848
+ default: return;
849
+ }
850
+ };
851
+
852
+ //#endregion
853
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorDrizzle.ts
854
+ /**
855
+ * Default rule group processor used by {@link formatQuery} for the "drizzle" format. The returned
856
+ * function can be assigned to the `where` property in the Drizzle relational queries API.
857
+ *
858
+ * @example
859
+ * const where = formatQuery(query, 'drizzle');
860
+ * const results = db.query.users.findMany({ where });
861
+ *
862
+ * @returns Function that takes a Drizzle table config and an object of Drizzle operators.
863
+ *
864
+ * @group Export
865
+ */
866
+ const defaultRuleGroupProcessorDrizzle = (ruleGroup, options, _meta) => (columns, drizzleOperators) => {
867
+ const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, validateRule, validationMap } = options;
868
+ if (!columns || !drizzleOperators) return;
869
+ const { and, not, or } = drizzleOperators;
870
+ const query = require_isRuleGroup.isRuleGroupType(ruleGroup) ? ruleGroup : require_convertQuery.convertFromIC(ruleGroup);
871
+ const ruleProcessor = defaultRuleProcessorDrizzle;
872
+ const processRuleGroup = (rg, _outermost) => {
873
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return;
874
+ const processedRules = rg.rules.map((rule) => {
875
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule);
876
+ const [validationResult, fieldValidator] = validateRule(rule);
877
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return;
878
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
879
+ return ruleProcessor(rule, {
880
+ ...options,
881
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
882
+ fieldData,
883
+ context: {
884
+ ...options.context,
885
+ columns,
886
+ drizzleOperators
887
+ }
888
+ });
889
+ }).filter(Boolean);
890
+ if (processedRules.length === 0) return;
891
+ const ruleGroupSQL = rg.combinator === "or" ? or(...processedRules) : and(...processedRules);
892
+ return rg.not ? not(ruleGroupSQL) : ruleGroupSQL;
893
+ };
894
+ return processRuleGroup(query, true);
895
+ };
896
+
897
+ //#endregion
898
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorElasticSearch.ts
899
+ /**
900
+ * Rule group processor used by {@link formatQuery} for "elasticsearch" format.
901
+ *
902
+ * @group Export
903
+ */
904
+ const defaultRuleGroupProcessorElasticSearch = (ruleGroup, options) => {
905
+ const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
906
+ const query = require_convertQuery.convertFromIC(ruleGroup);
907
+ const processRuleGroup = (rg) => {
908
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return false;
909
+ const processedRules = rg.rules.map((rule) => {
910
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule);
911
+ const [validationResult, fieldValidator] = validateRule(rule);
912
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return false;
913
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
914
+ return ruleProcessor(rule, {
915
+ ...options,
916
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
917
+ fieldData
918
+ });
919
+ }).filter(Boolean);
920
+ if (processedRules.length === 0) return false;
921
+ return { bool: rg.not ? { must_not: /^or$/i.test(rg.combinator) ? { bool: { should: processedRules } } : processedRules } : { [/^or$/i.test(rg.combinator) ? "should" : "must"]: processedRules } };
922
+ };
923
+ const processedRuleGroup = processRuleGroup(query);
924
+ return processedRuleGroup === false ? {} : processedRuleGroup;
925
+ };
926
+
927
+ //#endregion
928
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorJSONata.ts
929
+ /**
930
+ * Rule group processor used by {@link formatQuery} for "jsonata" format.
931
+ *
932
+ * @group Export
933
+ */
934
+ const defaultRuleGroupProcessorJSONata = (ruleGroup, options) => {
935
+ const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
936
+ const processRuleGroup = (rg, outermost) => {
937
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? fallbackExpression : "";
938
+ const expression = rg.rules.map((rule) => {
939
+ if (typeof rule === "string") return rule;
940
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule);
941
+ const [validationResult, fieldValidator] = validateRule(rule);
942
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return "";
943
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
944
+ return ruleProcessor(rule, {
945
+ ...options,
946
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
947
+ escapeQuotes: (rule.valueSource ?? "value") === "value",
948
+ fieldData
949
+ });
950
+ }).filter(Boolean).join(require_isRuleGroup.isRuleGroupType(rg) ? ` ${rg.combinator} ` : " ");
951
+ const [prefix, suffix] = rg.not || !outermost ? [`${rg.not ? "$not" : ""}(`, ")"] : ["", ""];
952
+ return expression ? `${prefix}${expression}${suffix}` : fallbackExpression;
953
+ };
954
+ return processRuleGroup(ruleGroup, true);
955
+ };
956
+
957
+ //#endregion
958
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorJsonLogic.ts
959
+ /**
960
+ * Rule group processor used by {@link formatQuery} for "jsonlogic" format.
961
+ *
962
+ * @group Export
963
+ */
964
+ const defaultRuleGroupProcessorJsonLogic = (ruleGroup, options) => {
965
+ const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
966
+ const query = require_convertQuery.convertFromIC(ruleGroup);
967
+ const processRuleGroup = (rg, _outermost) => {
968
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return false;
969
+ const processedRules = rg.rules.map((rule) => {
970
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule);
971
+ const [validationResult, fieldValidator] = validateRule(rule);
972
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return false;
973
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
974
+ return ruleProcessor(rule, {
975
+ ...options,
976
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
977
+ fieldData
978
+ });
979
+ }).filter(Boolean);
980
+ if (processedRules.length === 0) return false;
981
+ const jsonRuleGroup = { [rg.combinator]: processedRules };
982
+ return rg.not ? { "!": jsonRuleGroup } : jsonRuleGroup;
983
+ };
984
+ return processRuleGroup(query, true);
985
+ };
986
+
987
+ //#endregion
988
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorLDAP.ts
989
+ /**
990
+ * Rule group processor used by {@link formatQuery} for "ldap" format.
991
+ *
992
+ * @group Export
993
+ */
994
+ const defaultRuleGroupProcessorLDAP = (ruleGroup, options) => {
995
+ const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
996
+ const query = require_convertQuery.convertFromIC(ruleGroup);
997
+ const processRuleGroup = (rg, outermost) => {
998
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? fallbackExpression : "";
999
+ const rules = rg.rules.map((rule) => {
1000
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule);
1001
+ const [validationResult, fieldValidator] = validateRule(rule);
1002
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return "";
1003
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
1004
+ return ruleProcessor(rule, {
1005
+ ...options,
1006
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
1007
+ escapeQuotes: (rule.valueSource ?? "value") === "value",
1008
+ fieldData
1009
+ });
1010
+ }).filter(Boolean);
1011
+ const expression = rules.join("");
1012
+ const [notPrefix, notSuffix] = rg.not ? ["(!", ")"] : ["", ""];
1013
+ const [prefix, suffix] = rules.length > 1 ? [`${notPrefix}(${rg.combinator === "or" ? "|" : "&"}`, `)${notSuffix}`] : [notPrefix, notSuffix];
1014
+ return expression ? `${prefix}${expression}${suffix}` : fallbackExpression;
1015
+ };
1016
+ return processRuleGroup(query, true);
1017
+ };
1018
+
1019
+ //#endregion
1020
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorMongoDB.ts
1021
+ const isBracketed = (str) => str.startsWith("{") && str.endsWith("}");
1022
+ /**
1023
+ * Rule group processor used by {@link formatQuery} for "mongodb" format.
1024
+ *
1025
+ * Note that the "mongodb" format is deprecated in favor of the "mongodb_query" format.
1026
+ *
1027
+ * @group Export
1028
+ */
1029
+ const defaultRuleGroupProcessorMongoDB = (ruleGroup, options, meta) => {
1030
+ const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
1031
+ const processRuleGroup = (rg, outermost) => {
1032
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? fallbackExpression : "";
1033
+ const combinator = `"$${require_isRuleGroup.lc(rg.combinator)}"`;
1034
+ let hasChildRules = false;
1035
+ const expressions = rg.rules.map((rule) => {
1036
+ if (require_isRuleGroup.isRuleGroup(rule)) {
1037
+ const processedRuleGroup = processRuleGroup(rule);
1038
+ if (processedRuleGroup) {
1039
+ hasChildRules = true;
1040
+ return isBracketed(processedRuleGroup) ? processedRuleGroup : `{${processedRuleGroup}}`;
1041
+ }
1042
+ return "";
1043
+ }
1044
+ const [validationResult, fieldValidator] = validateRule(rule);
1045
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return "";
1046
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
1047
+ return ruleProcessor(rule, {
1048
+ ...options,
1049
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
1050
+ fieldData
1051
+ }, meta);
1052
+ }).filter(Boolean);
1053
+ return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : `${combinator}:[${expressions.join(",")}]` : fallbackExpression;
1054
+ };
1055
+ const processedQuery = processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
1056
+ return isBracketed(processedQuery) ? processedQuery : `{${processedQuery}}`;
1057
+ };
1058
+
1059
+ //#endregion
1060
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorNL.ts
1061
+ /**
1062
+ * Rule group processor used by {@link formatQuery} for "natural_language" format.
1063
+ *
1064
+ * @group Export
1065
+ */
1066
+ const defaultRuleGroupProcessorNL = (ruleGroup, options) => {
1067
+ const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, translations, validateRule, validationMap } = options;
1068
+ const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
1069
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
1070
+ const rg2 = require_isRuleGroup.isRuleGroupTypeIC(rg) && rg.rules.some((r) => typeof r === "string" && require_isRuleGroup.lc(r) === "xor") ? require_convertQuery.convertFromIC(rg) : rg;
1071
+ const processedRules = rg2.rules.map((rule) => {
1072
+ if (typeof rule === "string") return `, ${translations[rule] ?? rule} `;
1073
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule, rg2.rules.length === 1 && !(rg2.not || /^xor$/i.test(rg2.combinator ?? "")));
1074
+ const [validationResult, fieldValidator] = validateRule(rule);
1075
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return "";
1076
+ const escapeQuotes = (rule.valueSource ?? "value") === "value";
1077
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
1078
+ return ruleProcessor(rule, {
1079
+ ...options,
1080
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
1081
+ escapeQuotes,
1082
+ fieldData
1083
+ });
1084
+ });
1085
+ if (processedRules.length === 0) return fallbackExpression;
1086
+ const isXOR = require_isRuleGroup.lc(rg2.combinator ?? "") === "xor";
1087
+ const combinator = isXOR ? rg2.combinator.slice(1) : rg2.combinator;
1088
+ const mustWrap = rg2.not || !outermostOrLonelyInGroup || isXOR && processedRules.length > 1;
1089
+ const [prefixTL, suffixTL] = ["groupPrefix", "groupSuffix"].map((key) => rg2.not ? isXOR ? getNLTranslataion(key, translations, ["not", "xor"]) : getNLTranslataion(key, translations, ["not"]) : isXOR ? getNLTranslataion(key, translations, ["xor"]) : getNLTranslataion(key, translations));
1090
+ const prefix = mustWrap ? `${prefixTL} (`.trim() : "";
1091
+ const suffix = mustWrap ? `) ${suffixTL}`.trim() : "";
1092
+ return `${prefix}${processedRules.filter(Boolean).join(require_isRuleGroup.isRuleGroupType(rg2) ? `, ${translations[combinator] ?? combinator} ` : "")}${suffix}`;
1093
+ };
1094
+ return processRuleGroup(ruleGroup, true);
1095
+ };
1096
+
1097
+ //#endregion
1098
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorParameterized.ts
1099
+ /**
1100
+ * Rule group processor used by {@link formatQuery} for "parameterized" and
1101
+ * "parameterized_named" formats.
1102
+ *
1103
+ * @group Export
1104
+ */
1105
+ const defaultRuleGroupProcessorParameterized = (ruleGroup, options) => {
1106
+ const { format, fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
1107
+ const parameterized = format === "parameterized";
1108
+ const params = [];
1109
+ const paramsNamed = {};
1110
+ const fieldParams = /* @__PURE__ */ new Map();
1111
+ const getNextNamedParam = (field) => {
1112
+ if (!fieldParams.has(field)) fieldParams.set(field, /* @__PURE__ */ new Set());
1113
+ const nextNamedParam = `${field}_${fieldParams.get(field).size + 1}`;
1114
+ fieldParams.get(field).add(nextNamedParam);
1115
+ return nextNamedParam;
1116
+ };
1117
+ const processRule = (rule) => {
1118
+ const [validationResult, fieldValidator] = validateRule(rule);
1119
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return "";
1120
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
1121
+ const fieldParamNames = Object.fromEntries([...fieldParams.entries()].map(([f, s]) => [f, [...s]]));
1122
+ const processedRule = ruleProcessor(rule, {
1123
+ ...options,
1124
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
1125
+ getNextNamedParam,
1126
+ fieldParamNames,
1127
+ fieldData
1128
+ }, { processedParams: params });
1129
+ if (!require_isRuleGroup.isPojo(processedRule)) return "";
1130
+ const { sql, params: customParams } = processedRule;
1131
+ if (typeof sql !== "string" || !sql) return "";
1132
+ // istanbul ignore else
1133
+ if (format === "parameterized" && Array.isArray(customParams)) params.push(...customParams);
1134
+ else if (format === "parameterized_named" && require_isRuleGroup.isPojo(customParams)) {
1135
+ Object.assign(paramsNamed, customParams);
1136
+ for (const p of Object.keys(customParams)) fieldParams.get(rule.field)?.add(p);
1137
+ }
1138
+ return sql;
1139
+ };
1140
+ const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
1141
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
1142
+ const processedRules = rg.rules.map((rule) => {
1143
+ if (typeof rule === "string") return rule;
1144
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule, rg.rules.length === 1);
1145
+ return processRule(rule);
1146
+ }).filter(Boolean);
1147
+ if (processedRules.length === 0) return fallbackExpression;
1148
+ return `${rg.not ? "NOT " : ""}(${processedRules.join(require_isRuleGroup.isRuleGroupType(rg) ? ` ${rg.combinator} ` : " ")})`;
1149
+ };
1150
+ if (parameterized) return {
1151
+ sql: processRuleGroup(ruleGroup, true),
1152
+ params
1153
+ };
1154
+ return {
1155
+ sql: processRuleGroup(ruleGroup, true),
1156
+ params: paramsNamed
1157
+ };
1158
+ };
1159
+
1160
+ //#endregion
1161
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorPrisma.ts
1162
+ /**
1163
+ * Default fallback object used by {@link formatQuery} for "prisma" format.
1164
+ *
1165
+ * @group Export
1166
+ */
1167
+ const prismaFallback = {};
1168
+ /**
1169
+ * Rule group processor used by {@link formatQuery} for "prisma" format.
1170
+ *
1171
+ * @group Export
1172
+ */
1173
+ const defaultRuleGroupProcessorPrisma = (ruleGroup, options) => {
1174
+ const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
1175
+ const processRuleGroup = (rg, outermost) => {
1176
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermost ? prismaFallback : void 0;
1177
+ const combinator = rg.combinator.toUpperCase();
1178
+ let hasChildRules = false;
1179
+ const expressions = rg.rules.map((rule) => {
1180
+ if (require_isRuleGroup.isRuleGroup(rule)) {
1181
+ const processedRuleGroup = processRuleGroup(rule);
1182
+ if (processedRuleGroup) {
1183
+ hasChildRules = true;
1184
+ return processedRuleGroup;
1185
+ }
1186
+ return;
1187
+ }
1188
+ const [validationResult, fieldValidator] = validateRule(rule);
1189
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return;
1190
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
1191
+ return ruleProcessor(rule, {
1192
+ ...options,
1193
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
1194
+ fieldData
1195
+ });
1196
+ }).filter(Boolean);
1197
+ return expressions.length > 0 ? expressions.length === 1 && !hasChildRules ? expressions[0] : { [combinator]: expressions } : prismaFallback;
1198
+ };
1199
+ const result = processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
1200
+ return ruleGroup.not ? { NOT: result } : result;
1201
+ };
1202
+
1203
+ //#endregion
1204
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorSequelize.ts
1205
+ /**
1206
+ * Rule group processor used by {@link formatQuery} for "sequelize" format.
1207
+ *
1208
+ * @group Export
1209
+ */
1210
+ const defaultRuleGroupProcessorSequelize = (ruleGroup, options) => {
1211
+ // istanbul ignore next
1212
+ const { fields, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap, context = {} } = options;
1213
+ const { sequelizeOperators: Op } = context;
1214
+ if (!Op) return;
1215
+ const processRuleGroup = (rg, _outermost) => {
1216
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return;
1217
+ const combinator = rg.combinator.toUpperCase();
1218
+ let hasChildRules = false;
1219
+ const expressions = rg.rules.map((rule) => {
1220
+ if (require_isRuleGroup.isRuleGroup(rule)) {
1221
+ const processedRuleGroup = processRuleGroup(rule);
1222
+ if (processedRuleGroup) {
1223
+ hasChildRules = true;
1224
+ return processedRuleGroup;
1225
+ }
1226
+ return;
1227
+ }
1228
+ const [validationResult, fieldValidator] = validateRule(rule);
1229
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return;
1230
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
1231
+ return ruleProcessor(rule, {
1232
+ ...options,
1233
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
1234
+ fieldData
1235
+ });
1236
+ }).filter(Boolean);
1237
+ if (expressions.length === 0) return;
1238
+ const result = expressions.length === 1 && !hasChildRules ? expressions[0] : { [require_isRuleGroup.lc(combinator) === "or" ? Op.or : Op.and]: expressions };
1239
+ return rg.not ? { [Op.not]: result } : result;
1240
+ };
1241
+ return processRuleGroup(require_convertQuery.convertFromIC(ruleGroup), true);
1242
+ };
1243
+
1244
+ //#endregion
1245
+ //#region src/utils/formatQuery/defaultRuleGroupProcessorSQL.ts
1246
+ /**
1247
+ * Default rule processor used by {@link formatQuery} for "sql" format.
1248
+ *
1249
+ * @group Export
1250
+ */
1251
+ const defaultRuleGroupProcessorSQL = (ruleGroup, options) => {
1252
+ const { fields, fallbackExpression, getParseNumberBoolean, placeholderFieldName, placeholderOperatorName, placeholderValueName, ruleProcessor, validateRule, validationMap } = options;
1253
+ const processRuleGroup = (rg, outermostOrLonelyInGroup) => {
1254
+ if (!isRuleOrGroupValid(rg, validationMap[rg.id ?? ""])) return outermostOrLonelyInGroup ? fallbackExpression : "";
1255
+ const processedRules = rg.rules.map((rule) => {
1256
+ if (typeof rule === "string") return rule;
1257
+ if (require_isRuleGroup.isRuleGroup(rule)) return processRuleGroup(rule, rg.rules.length === 1);
1258
+ const [validationResult, fieldValidator] = validateRule(rule);
1259
+ if (!isRuleOrGroupValid(rule, validationResult, fieldValidator) || rule.field === placeholderFieldName || rule.operator === placeholderOperatorName || placeholderValueName !== void 0 && rule.value === placeholderValueName) return "";
1260
+ const escapeQuotes = (rule.valueSource ?? "value") === "value";
1261
+ const fieldData = require_optGroupUtils.getOption(fields, rule.field);
1262
+ return ruleProcessor(rule, {
1263
+ ...options,
1264
+ parseNumbers: getParseNumberBoolean(fieldData?.inputType),
1265
+ escapeQuotes,
1266
+ fieldData
1267
+ });
1268
+ }).filter(Boolean);
1269
+ if (processedRules.length === 0) return fallbackExpression;
1270
+ return `${rg.not ? "NOT " : ""}(${processedRules.join(require_isRuleGroup.isRuleGroupType(rg) ? ` ${rg.combinator} ` : " ")})`;
1271
+ };
1272
+ return processRuleGroup(ruleGroup, true);
1273
+ };
1274
+
1275
+ //#endregion
1276
+ //#region src/utils/formatQuery/defaultRuleProcessorElasticSearch.ts
1277
+ const rangeOperatorMap = {
1278
+ "<": "lt",
1279
+ "<=": "lte",
1280
+ ">": "gt",
1281
+ ">=": "gte"
1282
+ };
1283
+ const negateIfNotOp$1 = (op, elasticSearchRule) => op.startsWith("not") || op.startsWith("doesnot") ? { bool: { must_not: elasticSearchRule } } : elasticSearchRule;
1284
+ const escapeSQ = (s) => s?.replace(/('|\\)/g, `\\$1`);
1285
+ const textFunctionMap = {
1286
+ beginswith: "startsWith",
1287
+ doesnotbeginwith: "startsWith",
1288
+ doesnotcontain: "contains",
1289
+ doesnotendwith: "endsWith",
1290
+ endswith: "endsWith"
1291
+ };
1292
+ const getTextScript = (f, o, v) => {
1293
+ const script = `doc['${f}'].value.${textFunctionMap[o] ?? o}(doc['${v}'].value)`;
1294
+ return o.startsWith("d") ? `!${script}` : script;
1295
+ };
1296
+ const valueRenderer = (v, parseNumbers) => typeof v === "boolean" ? v : shouldRenderAsNumber(v, parseNumbers) ? require_parseNumber.parseNumber(v, { parseNumbers }) : v;
1297
+ /**
1298
+ * Default rule processor used by {@link formatQuery} for "elasticsearch" format.
1299
+ *
1300
+ * @group Export
1301
+ */
1302
+ const defaultRuleProcessorElasticSearch = (rule, options = {}) => {
1303
+ const { field, operator, value, valueSource } = rule;
1304
+ const { parseNumbers, preserveValueOrder } = options;
1305
+ const operatorLC = require_isRuleGroup.lc(operator);
1306
+ if (processMatchMode(rule)) return false;
1307
+ if (valueSource === "field") {
1308
+ if (require_arrayUtils.toArray(value).some((v) => typeof v !== "string")) return false;
1309
+ const fieldForScript = escapeSQ(field);
1310
+ switch (operatorLC) {
1311
+ case "=":
1312
+ case "!=":
1313
+ case ">":
1314
+ case ">=":
1315
+ case "<":
1316
+ case "<=": {
1317
+ const operatorForScript = operatorLC === "=" ? "==" : operatorLC;
1318
+ const valueForScript = escapeSQ(value);
1319
+ return valueForScript ? { bool: { filter: { script: { script: `doc['${fieldForScript}'].value ${operatorForScript} doc['${valueForScript}'].value` } } } } : false;
1320
+ }
1321
+ case "in":
1322
+ case "notin": {
1323
+ const valueAsArray = require_arrayUtils.toArray(value);
1324
+ if (valueAsArray.length > 0) {
1325
+ const arr = valueAsArray.map((v) => ({ bool: { filter: { script: { script: `doc['${fieldForScript}'].value == doc['${v}'].value` } } } }));
1326
+ return { bool: operatorLC === "in" ? { should: arr } : { must_not: arr } };
1327
+ }
1328
+ return false;
1329
+ }
1330
+ case "between":
1331
+ case "notbetween": {
1332
+ const valueAsArray = require_arrayUtils.toArray(value);
1333
+ if (valueAsArray.length >= 2 && valueAsArray[0] && valueAsArray[1]) {
1334
+ const script = `doc['${fieldForScript}'].value >= doc['${valueAsArray[0]}'].value && doc['${fieldForScript}'].value <= doc['${valueAsArray[1]}'].value`;
1335
+ return { bool: { filter: { script: { script: operatorLC === "notbetween" ? `!(${script})` : script } } } };
1336
+ }
1337
+ return false;
1338
+ }
1339
+ case "contains":
1340
+ case "doesnotcontain":
1341
+ case "beginswith":
1342
+ case "doesnotbeginwith":
1343
+ case "endswith":
1344
+ case "doesnotendwith": {
1345
+ const valueForScript = escapeSQ(value);
1346
+ if (!valueForScript) return false;
1347
+ return { bool: { filter: { script: { script: getTextScript(fieldForScript, operatorLC, valueForScript) } } } };
1348
+ }
1349
+ }
1350
+ }
1351
+ switch (operatorLC) {
1352
+ case "<":
1353
+ case "<=":
1354
+ case ">":
1355
+ case ">=": return { range: { [field]: { [rangeOperatorMap[operatorLC]]: valueRenderer(value, parseNumbers) } } };
1356
+ case "=": return { term: { [field]: valueRenderer(value, parseNumbers) } };
1357
+ case "!=": return { bool: { must_not: { term: { [field]: valueRenderer(value, parseNumbers) } } } };
1358
+ case "null": return { bool: { must_not: { exists: { field } } } };
1359
+ case "notnull": return { exists: { field } };
1360
+ case "in":
1361
+ case "notin": {
1362
+ const valueAsArray = require_arrayUtils.toArray(value).map((v) => valueRenderer(v, parseNumbers));
1363
+ if (valueAsArray.length > 0) {
1364
+ const arr = valueAsArray.map((v) => ({ term: { [field]: valueRenderer(v, parseNumbers) } }));
1365
+ return { bool: operatorLC === "in" ? { should: arr } : { must_not: arr } };
1366
+ }
1367
+ return false;
1368
+ }
1369
+ case "between":
1370
+ case "notbetween": {
1371
+ const valueAsArray = require_arrayUtils.toArray(value);
1372
+ if (valueAsArray.length >= 2 && isValidValue(valueAsArray[0]) && isValidValue(valueAsArray[1])) {
1373
+ let [first, second] = valueAsArray;
1374
+ const shouldParseNumbers = !(parseNumbers === false);
1375
+ if (shouldRenderAsNumber(first, shouldParseNumbers) && shouldRenderAsNumber(second, shouldParseNumbers)) {
1376
+ const firstNum = require_parseNumber.parseNumber(first, { parseNumbers: shouldParseNumbers });
1377
+ const secondNum = require_parseNumber.parseNumber(second, { parseNumbers: shouldParseNumbers });
1378
+ if (!preserveValueOrder && secondNum < firstNum) {
1379
+ const tempNum = secondNum;
1380
+ second = firstNum;
1381
+ first = tempNum;
1382
+ } else {
1383
+ first = firstNum;
1384
+ second = secondNum;
1385
+ }
1386
+ }
1387
+ return negateIfNotOp$1(operatorLC, { range: { [field]: {
1388
+ gte: first,
1389
+ lte: second
1390
+ } } });
1391
+ }
1392
+ return false;
1393
+ }
1394
+ case "contains":
1395
+ case "doesnotcontain": return negateIfNotOp$1(operatorLC, { regexp: { [field]: { value: `.*${value}.*` } } });
1396
+ case "beginswith":
1397
+ case "doesnotbeginwith": return negateIfNotOp$1(operatorLC, { regexp: { [field]: { value: `${value}.*` } } });
1398
+ case "endswith":
1399
+ case "doesnotendwith": return negateIfNotOp$1(operatorLC, { regexp: { [field]: { value: `.*${value}` } } });
1400
+ }
1401
+ return false;
1402
+ };
1403
+
1404
+ //#endregion
1405
+ //#region src/utils/formatQuery/defaultRuleProcessorJSONata.ts
1406
+ const shouldNegate = (op) => op.startsWith("not") || op.startsWith("doesnot");
1407
+ const quote = (v, escapeQuotes) => `"${typeof v !== "string" || !escapeQuotes ? `${v}` : v.replaceAll(`"`, `\\"`)}"`;
1408
+ const negate = (clause, negate$1) => negate$1 ? `$not(${clause})` : clause;
1409
+ const escapeStringRegex = (s) => `${s}`.replaceAll(/[/$()*+.?[\\\]^{|}]/g, String.raw`\$&`).replaceAll("-", String.raw`\x2d`);
1410
+ /**
1411
+ * Default rule processor used by {@link formatQuery} for "jsonata" format.
1412
+ *
1413
+ * @group Export
1414
+ */
1415
+ const defaultRuleProcessorJSONata = (rule, options = {}) => {
1416
+ const { field, operator, value, valueSource } = rule;
1417
+ const { escapeQuotes, parseNumbers, preserveValueOrder, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "" } = options;
1418
+ const valueIsField = valueSource === "field";
1419
+ const useBareValue = typeof value === "number" || typeof value === "boolean" || typeof value === "bigint" || shouldRenderAsNumber(value, parseNumbers);
1420
+ const qfn = (f) => getQuotedFieldName(f, {
1421
+ quoteFieldNamesWith,
1422
+ fieldIdentifierSeparator
1423
+ });
1424
+ const matchEval = processMatchMode(rule);
1425
+ if (matchEval === false) return;
1426
+ else if (matchEval) {
1427
+ const { mode, threshold } = matchEval;
1428
+ const totalCount = `$count(${qfn(field)})`;
1429
+ const filteredCount = `$count($filter(${qfn(field)}, function($v) {${defaultRuleGroupProcessorJSONata(require_transformQuery.transformQuery(value, { ruleProcessor: (r) => ({
1430
+ ...r,
1431
+ field: r.field ? `$v.${r.field}` : "$v"
1432
+ }) }), options)}}))`;
1433
+ switch (mode) {
1434
+ case "all": return `${filteredCount} = ${totalCount}`;
1435
+ case "none": return `${filteredCount} = 0`;
1436
+ case "some": return `${filteredCount} > 0`;
1437
+ case "atleast":
1438
+ case "atmost":
1439
+ case "exactly": {
1440
+ const op = mode === "atleast" ? ">=" : mode === "atmost" ? "<=" : "=";
1441
+ if (threshold > 0 && threshold < 1) return `${filteredCount} ${op} (${totalCount} * ${threshold})`;
1442
+ return `${filteredCount} ${op} ${threshold}`;
1443
+ }
1444
+ }
1445
+ }
1446
+ const operatorLC = require_isRuleGroup.lc(operator);
1447
+ switch (operatorLC) {
1448
+ case "<":
1449
+ case "<=":
1450
+ case "=":
1451
+ case "!=":
1452
+ case ">":
1453
+ case ">=": return `${qfn(field)} ${operatorLC} ${valueIsField ? qfn(require_arrayUtils.trimIfString(value)) : useBareValue ? require_arrayUtils.trimIfString(value) : quote(value, escapeQuotes)}`;
1454
+ case "contains":
1455
+ case "doesnotcontain": return negate(`$contains(${qfn(field)}, ${valueIsField ? qfn(require_arrayUtils.trimIfString(value)) : quote(value, escapeQuotes)})`, shouldNegate(operatorLC));
1456
+ case "beginswith":
1457
+ case "doesnotbeginwith": return negate(valueIsField ? `$substring(${qfn(field)}, 0, $length(${qfn(require_arrayUtils.trimIfString(value))})) = ${qfn(require_arrayUtils.trimIfString(value))}` : `$contains(${qfn(field)}, /^${escapeStringRegex(value)}/)`, shouldNegate(operatorLC));
1458
+ case "endswith":
1459
+ case "doesnotendwith": return negate(valueIsField ? `$substring(${qfn(field)}, $length(${qfn(field)}) - $length(${qfn(require_arrayUtils.trimIfString(value))})) = ${qfn(require_arrayUtils.trimIfString(value))}` : `$contains(${qfn(field)}, /${escapeStringRegex(value)}$/)`, shouldNegate(operatorLC));
1460
+ case "null": return `${qfn(field)} = null`;
1461
+ case "notnull": return `${qfn(field)} != null`;
1462
+ case "in":
1463
+ case "notin": {
1464
+ const valueAsArray = require_arrayUtils.toArray(value);
1465
+ return negate(`${qfn(field)} in [${valueAsArray.map((val) => valueIsField ? `${qfn(require_arrayUtils.trimIfString(val))}` : shouldRenderAsNumber(val, parseNumbers) ? `${require_arrayUtils.trimIfString(val)}` : quote(val, escapeQuotes)).join(", ")}]`, shouldNegate(operatorLC));
1466
+ }
1467
+ case "between":
1468
+ case "notbetween": {
1469
+ const valueAsArray = require_arrayUtils.toArray(value);
1470
+ if (valueAsArray.length < 2 || require_isRuleGroup.nullOrUndefinedOrEmpty(valueAsArray[0]) || require_isRuleGroup.nullOrUndefinedOrEmpty(valueAsArray[1])) return "";
1471
+ const [first, second] = valueAsArray;
1472
+ const shouldParseNumbers = !(parseNumbers === false);
1473
+ const firstNum = shouldRenderAsNumber(first, shouldParseNumbers) ? require_parseNumber.parseNumber(first, { parseNumbers: shouldParseNumbers }) : NaN;
1474
+ const secondNum = shouldRenderAsNumber(second, shouldParseNumbers) ? require_parseNumber.parseNumber(second, { parseNumbers: shouldParseNumbers }) : NaN;
1475
+ let firstValue = Number.isNaN(firstNum) ? valueIsField ? `${first}` : first : firstNum;
1476
+ let secondValue = Number.isNaN(secondNum) ? valueIsField ? `${second}` : second : secondNum;
1477
+ if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
1478
+ const tempNum = secondNum;
1479
+ secondValue = firstNum;
1480
+ firstValue = tempNum;
1481
+ }
1482
+ const renderAsNumbers = shouldRenderAsNumber(first, parseNumbers) && shouldRenderAsNumber(second, parseNumbers);
1483
+ const getValueString = (raw, val) => valueIsField ? qfn(raw) : renderAsNumbers ? val : quote(val, escapeQuotes);
1484
+ const expression = `${qfn(field)} >= ${getValueString(first, firstValue)} and ${qfn(field)} <= ${getValueString(second, secondValue)}`;
1485
+ return operatorLC === "between" ? `(${expression})` : negate(expression, true);
1486
+ }
1487
+ }
1488
+ return "";
1489
+ };
1490
+
1491
+ //#endregion
1492
+ //#region src/utils/formatQuery/defaultRuleProcessorJsonLogic.ts
1493
+ const convertOperator = (op) => op.replace(/^(=)$/, "$1=").replace(/^notnull$/i, "!=").replace(/^null$/i, "==");
1494
+ const negateIfNotOp = (op, jsonRule) => op.startsWith("not") || op.startsWith("doesnot") ? { "!": jsonRule } : jsonRule;
1495
+ /**
1496
+ * Default rule processor used by {@link formatQuery} for "jsonlogic" format.
1497
+ *
1498
+ * @group Export
1499
+ */
1500
+ const defaultRuleProcessorJsonLogic = (rule, options = {}) => {
1501
+ const { field, operator, value, valueSource } = rule;
1502
+ const { parseNumbers, preserveValueOrder } = options;
1503
+ const valueIsField = valueSource === "field";
1504
+ const fieldObject = { var: field };
1505
+ const fieldOrNumberRenderer = (v) => valueIsField ? { var: `${v}` } : shouldRenderAsNumber(v, parseNumbers) ? require_parseNumber.parseNumber(v, { parseNumbers }) : v;
1506
+ const matchEval = processMatchMode(rule);
1507
+ if (matchEval === false) return false;
1508
+ else if (matchEval) {
1509
+ const { mode, threshold } = matchEval;
1510
+ switch (mode) {
1511
+ case "all":
1512
+ case "none":
1513
+ case "some": return { [mode]: [{ var: field }, value.rules.length === 1 && !require_isRuleGroup.isRuleGroup(value.rules[0]) ? defaultRuleProcessorJsonLogic(value.rules[0], options) : defaultRuleGroupProcessorJsonLogic(value, options)] };
1514
+ case "atleast":
1515
+ case "atmost":
1516
+ case "exactly": {
1517
+ const op = mode === "atleast" ? ">=" : mode === "atmost" ? "<=" : "==";
1518
+ const filteredCount = { reduce: [
1519
+ { filter: [{ var: field }, value.rules.length === 1 && !require_isRuleGroup.isRuleGroup(value.rules[0]) ? defaultRuleProcessorJsonLogic(value.rules[0], options) : defaultRuleGroupProcessorJsonLogic(value, options)] },
1520
+ { "+": [1, { var: "accumulator" }] },
1521
+ 0
1522
+ ] };
1523
+ if (threshold > 0 && threshold < 1) {
1524
+ const totalCount = { reduce: [
1525
+ { var: field },
1526
+ { "+": [1, { var: "accumulator" }] },
1527
+ 0
1528
+ ] };
1529
+ return { [op]: [filteredCount, { "*": [totalCount, threshold] }] };
1530
+ }
1531
+ return { [op]: [filteredCount, threshold] };
1532
+ }
1533
+ }
1534
+ }
1535
+ const operatorLC = require_isRuleGroup.lc(operator);
1536
+ switch (operatorLC) {
1537
+ case "<":
1538
+ case "<=":
1539
+ case "=":
1540
+ case "!=":
1541
+ case ">":
1542
+ case ">=": return { [convertOperator(operatorLC)]: [fieldObject, fieldOrNumberRenderer(value)] };
1543
+ case "null":
1544
+ case "notnull": return { [`${operatorLC === "notnull" ? "!" : "="}=`]: [fieldObject, null] };
1545
+ case "in":
1546
+ case "notin": {
1547
+ const valueAsArray = require_arrayUtils.toArray(value).map((v) => fieldOrNumberRenderer(v));
1548
+ return negateIfNotOp(operatorLC, { in: [fieldObject, valueAsArray] });
1549
+ }
1550
+ case "between":
1551
+ case "notbetween": {
1552
+ const valueAsArray = require_arrayUtils.toArray(value);
1553
+ if (valueAsArray.length >= 2 && isValidValue(valueAsArray[0]) && isValidValue(valueAsArray[1])) {
1554
+ let [first, second] = valueAsArray;
1555
+ const shouldParseNumbers = !(parseNumbers === false);
1556
+ if (!valueIsField && shouldRenderAsNumber(first, shouldParseNumbers) && shouldRenderAsNumber(second, shouldParseNumbers)) {
1557
+ const firstNum = require_parseNumber.parseNumber(first, { parseNumbers: shouldParseNumbers });
1558
+ const secondNum = require_parseNumber.parseNumber(second, { parseNumbers: shouldParseNumbers });
1559
+ if (!preserveValueOrder && secondNum < firstNum) {
1560
+ const tempNum = secondNum;
1561
+ second = firstNum;
1562
+ first = tempNum;
1563
+ } else {
1564
+ first = firstNum;
1565
+ second = secondNum;
1566
+ }
1567
+ } else if (valueIsField) {
1568
+ first = { var: first };
1569
+ second = { var: second };
1570
+ }
1571
+ return negateIfNotOp(operatorLC, { "<=": [
1572
+ first,
1573
+ fieldObject,
1574
+ second
1575
+ ] });
1576
+ }
1577
+ return false;
1578
+ }
1579
+ case "contains":
1580
+ case "doesnotcontain": {
1581
+ const jsonRule = { in: [fieldOrNumberRenderer(value), fieldObject] };
1582
+ return negateIfNotOp(operatorLC, jsonRule);
1583
+ }
1584
+ case "beginswith":
1585
+ case "doesnotbeginwith": {
1586
+ const jsonRule = { startsWith: [fieldObject, fieldOrNumberRenderer(value)] };
1587
+ return negateIfNotOp(operatorLC, jsonRule);
1588
+ }
1589
+ case "endswith":
1590
+ case "doesnotendwith": {
1591
+ const jsonRule = { endsWith: [fieldObject, fieldOrNumberRenderer(value)] };
1592
+ return negateIfNotOp(operatorLC, jsonRule);
1593
+ }
1594
+ }
1595
+ return false;
1596
+ };
1597
+
1598
+ //#endregion
1599
+ //#region src/utils/formatQuery/defaultRuleProcessorLDAP.ts
1600
+ const negateIf = (clause, negate$1) => negate$1 ? `(!${clause})` : `${clause}`;
1601
+ const ldapEscape = (s) => `${require_arrayUtils.trimIfString(s)}`.replaceAll(/[()&|=<>~*\\/]/g, (m) => `\\${m.codePointAt(0).toString(16)}`);
1602
+ /**
1603
+ * Default rule processor used by {@link formatQuery} for "ldap" format.
1604
+ *
1605
+ * @group Export
1606
+ */
1607
+ const defaultRuleProcessorLDAP = (rule, options = {}) => {
1608
+ const { field, operator, value, valueSource } = rule;
1609
+ const { preserveValueOrder } = options;
1610
+ const operatorLC = require_isRuleGroup.lc(operator);
1611
+ if (valueSource === "field" || require_isRuleGroup.nullOrUndefinedOrEmpty(value) && operatorLC !== "null" && operatorLC !== "notnull" || processMatchMode(rule)) return "";
1612
+ switch (operatorLC) {
1613
+ case "=":
1614
+ case "!=": return negateIf(`(${field}=${ldapEscape(value)})`, operatorLC === "!=");
1615
+ case ">":
1616
+ case ">=": return `(${field}>=${ldapEscape(value)})`;
1617
+ case "<":
1618
+ case "<=": return `(${field}<=${ldapEscape(value)})`;
1619
+ case "contains":
1620
+ case "doesnotcontain": return negateIf(`(${field}=*${ldapEscape(value)}*)`, operatorLC === "doesnotcontain");
1621
+ case "beginswith":
1622
+ case "doesnotbeginwith": return negateIf(`(${field}=${ldapEscape(value)}*)`, operatorLC === "doesnotbeginwith");
1623
+ case "endswith":
1624
+ case "doesnotendwith": return negateIf(`(${field}=*${ldapEscape(value)})`, operatorLC === "doesnotendwith");
1625
+ case "null":
1626
+ case "notnull": return negateIf(`(${field}=*)`, operatorLC === "notnull");
1627
+ case "in":
1628
+ case "notin": {
1629
+ const valueAsArray = require_arrayUtils.toArray(value);
1630
+ return negateIf(`(|${valueAsArray.map((val) => `(${field}=${ldapEscape(val)})`).join("")})`, operatorLC === "notin");
1631
+ }
1632
+ case "between":
1633
+ case "notbetween": {
1634
+ const valueAsArray = require_arrayUtils.toArray(value);
1635
+ if (valueAsArray.length < 2 || require_isRuleGroup.nullOrUndefinedOrEmpty(valueAsArray[0]) || require_isRuleGroup.nullOrUndefinedOrEmpty(valueAsArray[1])) return "";
1636
+ const [first, second] = valueAsArray;
1637
+ const firstNum = shouldRenderAsNumber(first, true) ? require_parseNumber.parseNumber(first, { parseNumbers: true }) : NaN;
1638
+ const secondNum = shouldRenderAsNumber(second, true) ? require_parseNumber.parseNumber(second, { parseNumbers: true }) : NaN;
1639
+ let firstValue = Number.isNaN(firstNum) ? first : firstNum;
1640
+ let secondValue = Number.isNaN(secondNum) ? second : secondNum;
1641
+ if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
1642
+ const tempNum = secondNum;
1643
+ secondValue = firstNum;
1644
+ firstValue = tempNum;
1645
+ }
1646
+ return negateIf(`(&(${field}>=${ldapEscape(firstValue)})(${field}<=${ldapEscape(secondValue)}))`, operatorLC === "notbetween");
1647
+ }
1648
+ }
1649
+ // istanbul ignore next
1650
+ return "";
1651
+ };
1652
+
1653
+ //#endregion
1654
+ //#region src/utils/formatQuery/defaultValueProcessorNL.ts
1655
+ const escapeStringValueQuotes = (v, quoteChar, escapeQuotes) => escapeQuotes && typeof v === "string" ? v.replaceAll(`${quoteChar}`, `${quoteChar}${quoteChar}`) : v;
1656
+ /**
1657
+ * Default value processor used by {@link formatQuery} for "natural_language" format.
1658
+ *
1659
+ * @group Export
1660
+ */
1661
+ const defaultValueProcessorNL = (rule, opts = {}) => {
1662
+ const { escapeQuotes, fields, parseNumbers, quoteFieldNamesWith, quoteValuesWith, fieldIdentifierSeparator, translations } = opts;
1663
+ const valueIsField = rule.valueSource === "field";
1664
+ const operatorLowerCase = require_isRuleGroup.lc(rule.operator);
1665
+ const quoteChar = quoteValuesWith || "'";
1666
+ const quoteValue = (v) => `${quoteChar}${v}${quoteChar}`;
1667
+ const escapeValue = (v) => escapeStringValueQuotes(v, quoteChar, escapeQuotes);
1668
+ const wrapAndEscape = (v) => quoteValue(escapeValue(v));
1669
+ const wrapFieldName = (v) => getQuotedFieldName(v, {
1670
+ quoteFieldNamesWith,
1671
+ fieldIdentifierSeparator
1672
+ });
1673
+ const t = translations ?? ( /* istanbul ignore next */ {});
1674
+ const orTL = t.or ?? "or";
1675
+ const trueTL = t.true ?? "true";
1676
+ const falseTL = t.false ?? "false";
1677
+ switch (operatorLowerCase) {
1678
+ case "null":
1679
+ case "notnull": return "";
1680
+ case "between":
1681
+ case "notbetween": {
1682
+ if (!valueIsField) return defaultValueProcessorByRule(rule, opts);
1683
+ const valueAsArray = require_arrayUtils.toArray(rule.value, { retainEmptyStrings: true }).slice(0, 2).map((v) => wrapFieldName(require_optGroupUtils.getOption(fields ?? [], v)?.label ?? v));
1684
+ if (valueAsArray.length < 2 || !isValidValue(valueAsArray[0]) || !isValidValue(valueAsArray[1])) return "";
1685
+ return defaultValueProcessorByRule({
1686
+ ...rule,
1687
+ value: valueAsArray
1688
+ }, opts);
1689
+ }
1690
+ case "in":
1691
+ case "notin": {
1692
+ const valueAsArray = require_arrayUtils.toArray(rule.value);
1693
+ if (valueAsArray.length === 0) return "";
1694
+ const valStringArray = valueAsArray.map((v) => valueIsField ? wrapFieldName(require_optGroupUtils.getOption(fields ?? [], v)?.label ?? v) : shouldRenderAsNumber(v, parseNumbers) ? `${require_arrayUtils.trimIfString(v)}` : `${wrapAndEscape(v)}`);
1695
+ return `${valStringArray.slice(0, -1).join(", ")}${valStringArray.length > 2 ? "," : ""} ${orTL} ${valStringArray.at(-1)}`;
1696
+ }
1697
+ }
1698
+ if (typeof rule.value === "boolean") return rule.value ? trueTL : falseTL;
1699
+ return valueIsField ? wrapFieldName(require_optGroupUtils.getOption(fields ?? [], rule.value)?.label ?? rule.value) : shouldRenderAsNumber(rule.value, parseNumbers) ? `${require_arrayUtils.trimIfString(rule.value)}` : `${wrapAndEscape(rule.value)}`;
1700
+ };
1701
+
1702
+ //#endregion
1703
+ //#region src/utils/formatQuery/defaultRuleProcessorNL.ts
1704
+ /**
1705
+ * Default operator map used by {@link formatQuery} for "natural_language" format.
1706
+ *
1707
+ * @group Export
1708
+ */
1709
+ const defaultExportOperatorMap = {
1710
+ "=": ["is", "is the same as the value in"],
1711
+ "!=": ["is not", "is not the same as the value in"],
1712
+ "<": ["is less than", "is less than the value in"],
1713
+ ">": ["is greater than", "is greater than the value in"],
1714
+ "<=": ["is less than or equal to", "is less than or equal to the value in"],
1715
+ ">=": ["is greater than or equal to", "is greater than or equal to the value in"],
1716
+ contains: ["contains", "contains the value in"],
1717
+ beginswith: ["starts with", "starts with the value in"],
1718
+ endswith: ["ends with", "ends with the value in"],
1719
+ doesnotcontain: ["does not contain", "does not contain the value in"],
1720
+ doesnotbeginwith: ["does not start with", "does not start with the value in"],
1721
+ doesnotendwith: ["does not end with", "does not end with the value in"],
1722
+ null: "is null",
1723
+ notnull: "is not null",
1724
+ in: ["is one of the values", "is the same as a value in"],
1725
+ notin: ["is not one of the values", "is not the same as any value in"],
1726
+ between: ["is between", "is between the values in"],
1727
+ notbetween: ["is not between", "is not between the values in"]
1728
+ };
1729
+ /* istanbul ignore next */
1730
+ const defaultGetOperators = () => [];
1731
+ /**
1732
+ * Default operator processor used by {@link formatQuery} for "natural_language" format.
1733
+ *
1734
+ * @group Export
1735
+ */
1736
+ const defaultOperatorProcessorNL = (rule, opts = {}) => {
1737
+ const { field, operator, valueSource = "value" } = rule;
1738
+ // istanbul ignore next
1739
+ const { getOperators = defaultGetOperators, operatorMap: operatorMapParam = defaultExportOperatorMap } = opts;
1740
+ const mapOperatorMap = new Map(Object.entries(defaultExportOperatorMap));
1741
+ for (const [key, value] of Object.entries(operatorMapParam)) mapOperatorMap.set(require_isRuleGroup.lc(key), value);
1742
+ const operatorMap = Object.fromEntries(mapOperatorMap);
1743
+ const { value: operatorNL, label } = require_optGroupUtils.getOption(require_optGroupUtils.toFullOptionList(getOperators(field, { fieldData: opts.fieldData ?? {
1744
+ name: field,
1745
+ value: field,
1746
+ label: field
1747
+ } }) ?? []), operator) ?? {
1748
+ name: operator,
1749
+ value: operator,
1750
+ label: operator
1751
+ };
1752
+ const operatorTL = operatorMap[operatorNL] ?? operatorMap[require_isRuleGroup.lc(operatorNL)] ?? [label, label];
1753
+ return typeof operatorTL === "string" ? operatorTL : operatorTL[valueSource === "field" ? 1 : 0];
1754
+ };
1755
+ /**
1756
+ * Default rule processor used by {@link formatQuery} for "natural_language" format.
1757
+ *
1758
+ * @group Export
1759
+ */
1760
+ const defaultRuleProcessorNL = (rule, opts) => {
1761
+ const { field, operator } = rule;
1762
+ // istanbul ignore next
1763
+ const { fieldData, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "", quoteValuesWith = `'`, operatorProcessor = defaultOperatorProcessorNL, valueProcessor = defaultValueProcessorNL, concatOperator = "||", wordOrder = "SVO" } = opts ?? ( /* istanbul ignore next */ {});
1764
+ const processedField = getQuotedFieldName(fieldData?.label ?? field, {
1765
+ quoteFieldNamesWith,
1766
+ fieldIdentifierSeparator
1767
+ });
1768
+ const matchEval = processMatchMode(rule);
1769
+ if (matchEval === false) return "";
1770
+ else if (matchEval) {
1771
+ const { mode, threshold } = matchEval;
1772
+ const nestedArrayFilter = defaultRuleGroupProcessorNL(rule.value, {
1773
+ ...opts,
1774
+ fields: require_optGroupUtils.toFullOptionList(fieldData?.subproperties ?? [])
1775
+ });
1776
+ const hsp = (fieldData?.subproperties?.length ?? 0) > 0;
1777
+ switch (mode) {
1778
+ case "all": return `(${hsp ? "for " : ""}every item in ${processedField}${hsp ? "," : ""} ${nestedArrayFilter})`;
1779
+ case "none": return `(${hsp ? "for " : ""}no item in ${processedField}${hsp ? "," : ""} ${nestedArrayFilter})`;
1780
+ case "some": return `(${hsp ? "for " : ""}at least one item in ${processedField}${hsp ? "," : ""} ${nestedArrayFilter})`;
1781
+ case "atleast":
1782
+ case "atmost":
1783
+ case "exactly": {
1784
+ const mm = mode.replace("at", "at ");
1785
+ if (threshold > 0 && threshold < 1) return `(${hsp ? "for " : ""}${mm} ${threshold * 100}% of the items in ${processedField}${hsp ? "," : ""} ${nestedArrayFilter})`;
1786
+ return `(${hsp ? "for " : ""}${mm} ${threshold} of the items in ${processedField}${hsp ? "," : ""} ${nestedArrayFilter})`;
1787
+ }
1788
+ }
1789
+ }
1790
+ const value = valueProcessor(rule, {
1791
+ ...opts,
1792
+ quoteFieldNamesWith,
1793
+ fieldIdentifierSeparator,
1794
+ quoteValuesWith,
1795
+ concatOperator
1796
+ });
1797
+ const operatorLC = require_isRuleGroup.lc(operator);
1798
+ if ((operatorLC === "in" || operatorLC === "notin" || operatorLC === "between" || operatorLC === "notbetween") && !value) return "";
1799
+ const processedOperator = operatorProcessor(rule, opts);
1800
+ const wordOrderMap = {
1801
+ S: processedField,
1802
+ V: processedOperator,
1803
+ O: value
1804
+ };
1805
+ return normalizeConstituentWordOrder(wordOrder).map((term) => `${wordOrderMap[term]}`).join(" ").trim();
1806
+ };
1807
+
1808
+ //#endregion
1809
+ //#region src/utils/formatQuery/defaultRuleProcessorSQL.ts
1810
+ /**
1811
+ * Default operator processor used by {@link formatQuery} for "sql" and "parameterized*" formats.
1812
+ *
1813
+ * @group Export
1814
+ */
1815
+ const defaultOperatorProcessorSQL = (rule) => require_isRuleGroup.lc(mapSQLOperator(rule.operator));
1816
+ /**
1817
+ * Default rule processor used by {@link formatQuery} for "sql" format.
1818
+ *
1819
+ * @group Export
1820
+ */
1821
+ const defaultRuleProcessorSQL = (rule, opts = {}) => {
1822
+ const { quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator = "", quoteValuesWith = `'`, operatorProcessor = defaultOperatorProcessorSQL, valueProcessor = defaultValueProcessorByRule, concatOperator = "||" } = opts;
1823
+ const wrapFieldName = (v) => getQuotedFieldName(v, {
1824
+ quoteFieldNamesWith,
1825
+ fieldIdentifierSeparator
1826
+ });
1827
+ const ruleField = wrapFieldName(rule.field);
1828
+ const matchEval = processMatchMode(rule);
1829
+ if (matchEval === false) return;
1830
+ else if (matchEval) {
1831
+ if (opts?.preset !== "postgresql") return "";
1832
+ const { mode, threshold } = matchEval;
1833
+ const arrayElementAlias = "elem_alias";
1834
+ const nestedArrayFilter = defaultRuleGroupProcessorSQL(require_transformQuery.transformQuery(rule.value, { ruleProcessor: (r) => ({
1835
+ ...r,
1836
+ field: arrayElementAlias
1837
+ }) }), opts);
1838
+ switch (mode) {
1839
+ case "all": return `(select count(*) from unnest(${ruleField}) as ${wrapFieldName(arrayElementAlias)} where ${nestedArrayFilter}) = array_length(${ruleField}, 1)`;
1840
+ case "none": return `not exists (select 1 from unnest(${ruleField}) as ${wrapFieldName(arrayElementAlias)} where ${nestedArrayFilter})`;
1841
+ case "some": return `exists (select 1 from unnest(${ruleField}) as ${wrapFieldName(arrayElementAlias)} where ${nestedArrayFilter})`;
1842
+ case "atleast":
1843
+ case "atmost":
1844
+ case "exactly": {
1845
+ const op = mode === "atleast" ? ">=" : mode === "atmost" ? "<=" : "=";
1846
+ return `(select count(*)${threshold > 0 && threshold < 1 ? ` / array_length(${ruleField}, 1)` : ""} from unnest(${ruleField}) as ${wrapFieldName(arrayElementAlias)} where ${nestedArrayFilter}) ${op} ${threshold}`;
1847
+ }
1848
+ }
1849
+ }
1850
+ const value = valueProcessor(rule, {
1851
+ ...opts,
1852
+ quoteFieldNamesWith,
1853
+ fieldIdentifierSeparator,
1854
+ quoteValuesWith,
1855
+ concatOperator
1856
+ });
1857
+ const operator = operatorProcessor(rule, opts);
1858
+ const operatorLowerCase = require_isRuleGroup.lc(operator);
1859
+ if ((operatorLowerCase === "in" || operatorLowerCase === "not in" || operatorLowerCase === "between" || operatorLowerCase === "not between") && !value) return "";
1860
+ return `${ruleField} ${operator} ${value}`.trim();
1861
+ };
1862
+
1863
+ //#endregion
1864
+ //#region src/utils/formatQuery/defaultRuleProcessorParameterized.ts
1865
+ /**
1866
+ * Default rule processor used by {@link formatQuery} for "parameterized" and
1867
+ * "parameterized_named" formats.
1868
+ *
1869
+ * @group Export
1870
+ */
1871
+ const defaultRuleProcessorParameterized = (rule, opts, meta) => {
1872
+ // istanbul ignore next
1873
+ const { fieldData, format, getNextNamedParam, parseNumbers, paramPrefix, paramsKeepPrefix, numberedParams, quoteFieldNamesWith = ["", ""], fieldIdentifierSeparator, concatOperator, operatorProcessor = defaultOperatorProcessorSQL, valueProcessor = defaultValueProcessorByRule } = opts ?? {};
1874
+ const { processedParams = [] } = meta ?? {};
1875
+ const parameterized = format === "parameterized";
1876
+ const params = [];
1877
+ const paramsNamed = {};
1878
+ const finalize = (sql) => parameterized ? {
1879
+ sql,
1880
+ params
1881
+ } : {
1882
+ sql,
1883
+ params: paramsNamed
1884
+ };
1885
+ const wrapFieldName = (v) => getQuotedFieldName(v, {
1886
+ quoteFieldNamesWith,
1887
+ fieldIdentifierSeparator
1888
+ });
1889
+ const ruleField = wrapFieldName(rule.field);
1890
+ const matchEval = processMatchMode(rule);
1891
+ if (matchEval === false) return;
1892
+ else if (matchEval) {
1893
+ if (opts?.preset !== "postgresql") return finalize("");
1894
+ const { mode, threshold } = matchEval;
1895
+ const arrayElementAlias = "elem_alias";
1896
+ const { sql: nestedSQL, params: nestedParams } = defaultRuleGroupProcessorParameterized(require_transformQuery.transformQuery(rule.value, { ruleProcessor: (r) => ({
1897
+ ...r,
1898
+ field: arrayElementAlias
1899
+ }) }), {
1900
+ ...opts,
1901
+ fields: []
1902
+ });
1903
+ // istanbul ignore else
1904
+ if (Array.isArray(nestedParams)) params.push(...nestedParams);
1905
+ else Object.assign(paramsNamed, nestedParams);
1906
+ switch (mode) {
1907
+ case "all": return finalize(`(select count(*) from unnest(${ruleField}) as ${wrapFieldName(arrayElementAlias)} where ${nestedSQL}) = array_length(${ruleField}, 1)`);
1908
+ case "none": return finalize(`not exists (select 1 from unnest(${ruleField}) as ${wrapFieldName(arrayElementAlias)} where ${nestedSQL})`);
1909
+ case "some": return finalize(`exists (select 1 from unnest(${ruleField}) as ${wrapFieldName(arrayElementAlias)} where ${nestedSQL})`);
1910
+ case "atleast":
1911
+ case "atmost":
1912
+ case "exactly": {
1913
+ const op = mode === "atleast" ? ">=" : mode === "atmost" ? "<=" : "=";
1914
+ return finalize(`(select count(*)${threshold > 0 && threshold < 1 ? ` / array_length(${ruleField}, 1)` : ""} from unnest(${ruleField}) as ${wrapFieldName(arrayElementAlias)} where ${nestedSQL}) ${op} ${threshold}`);
1915
+ }
1916
+ }
1917
+ }
1918
+ const value = valueProcessor(rule, {
1919
+ parseNumbers,
1920
+ quoteFieldNamesWith,
1921
+ concatOperator,
1922
+ fieldData,
1923
+ format
1924
+ });
1925
+ const sqlOperator = operatorProcessor(rule, opts);
1926
+ const sqlOperatorLowerCase = require_isRuleGroup.lc(sqlOperator);
1927
+ const [qPre, qPost] = quoteFieldNamesWith;
1928
+ if ((sqlOperatorLowerCase === "in" || sqlOperatorLowerCase === "not in" || sqlOperatorLowerCase === "between" || sqlOperatorLowerCase === "not between") && !value) return finalize("");
1929
+ else if (sqlOperatorLowerCase === "is null" || sqlOperatorLowerCase === "is not null") return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator}`);
1930
+ else if (rule.valueSource === "field") return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${value}`.trim());
1931
+ else if (sqlOperatorLowerCase === "in" || sqlOperatorLowerCase === "not in") {
1932
+ const splitValue = require_arrayUtils.toArray(rule.value);
1933
+ if (parameterized) {
1934
+ for (const v of splitValue) params.push(shouldRenderAsNumber(v, parseNumbers) ? require_parseNumber.parseNumber(v, { parseNumbers }) : v);
1935
+ return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} (${splitValue.map((_v, i) => numberedParams ? `${paramPrefix}${processedParams.length + 1 + splitValue.length - (splitValue.length - i)}` : "?").join(", ")})`);
1936
+ }
1937
+ const inParams = [];
1938
+ for (const v of splitValue) {
1939
+ const thisParamName = getNextNamedParam(rule.field);
1940
+ inParams.push(`${paramPrefix}${thisParamName}`);
1941
+ paramsNamed[`${paramsKeepPrefix ? paramPrefix : ""}${thisParamName}`] = shouldRenderAsNumber(v, parseNumbers) ? require_parseNumber.parseNumber(v, { parseNumbers }) : v;
1942
+ }
1943
+ return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} (${inParams.join(", ")})`);
1944
+ } else if (sqlOperatorLowerCase === "between" || sqlOperatorLowerCase === "not between") {
1945
+ const [first, second] = require_arrayUtils.toArray(rule.value, { retainEmptyStrings: true }).slice(0, 2).map((v) => shouldRenderAsNumber(v, parseNumbers) ? require_parseNumber.parseNumber(v, { parseNumbers }) : v);
1946
+ if (parameterized) {
1947
+ params.push(first, second);
1948
+ return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${numberedParams ? `${paramPrefix}${processedParams.length + 1}` : "?"} and ${numberedParams ? `${paramPrefix}${processedParams.length + 2}` : "?"}`);
1949
+ }
1950
+ const firstParamName = getNextNamedParam(rule.field);
1951
+ const secondParamName = getNextNamedParam(rule.field);
1952
+ paramsNamed[`${paramsKeepPrefix ? paramPrefix : ""}${firstParamName}`] = first;
1953
+ paramsNamed[`${paramsKeepPrefix ? paramPrefix : ""}${secondParamName}`] = second;
1954
+ return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${paramPrefix}${firstParamName} and ${paramPrefix}${secondParamName}`);
1955
+ }
1956
+ let paramValue = rule.value;
1957
+ if (typeof rule.value === "string") if (shouldRenderAsNumber(rule.value, parseNumbers)) paramValue = require_parseNumber.parseNumber(rule.value, { parseNumbers });
1958
+ else paramValue = /^'.*'$/g.test(value) ? value.replaceAll(/(^'|'$)/g, "") : value;
1959
+ let paramName = "";
1960
+ if (parameterized) params.push(paramValue);
1961
+ else {
1962
+ paramName = getNextNamedParam(rule.field);
1963
+ paramsNamed[`${paramsKeepPrefix ? paramPrefix : ""}${paramName}`] = paramValue;
1964
+ }
1965
+ return finalize(`${qPre}${rule.field}${qPost} ${sqlOperator} ${parameterized ? numberedParams ? `${paramPrefix}${processedParams.length + 1}` : "?" : `${paramPrefix}${paramName}`}`.trim());
1966
+ };
1967
+
1968
+ //#endregion
1969
+ //#region src/utils/formatQuery/defaultRuleProcessorPrisma.ts
1970
+ const processNumber = (value, fallback, parseNumbers) => shouldRenderAsNumber(value, !!parseNumbers || typeof value === "bigint") ? Number(require_parseNumber.parseNumber(value, { parseNumbers: !!parseNumbers })) : fallback;
1971
+ /**
1972
+ * Default rule processor used by {@link formatQuery} for "prisma" format.
1973
+ *
1974
+ * @group Export
1975
+ */
1976
+ const defaultRuleProcessorPrisma = (rule, options = {}) => {
1977
+ const { field, operator, value, valueSource } = rule;
1978
+ // istanbul ignore next
1979
+ const { parseNumbers, preserveValueOrder } = options;
1980
+ if (valueSource === "field" || processMatchMode(rule)) return;
1981
+ const operatorLC = require_isRuleGroup.lc(operator);
1982
+ switch (operatorLC) {
1983
+ case "=": return { [field]: processNumber(value, value, parseNumbers) };
1984
+ case "!=":
1985
+ case "<":
1986
+ case "<=":
1987
+ case ">":
1988
+ case ">=": {
1989
+ const prismaOperator = prismaOperators[operatorLC];
1990
+ return { [field]: { [prismaOperator]: processNumber(value, value, parseNumbers) } };
1991
+ }
1992
+ case "contains": return { [field]: { contains: value } };
1993
+ case "beginswith": return { [field]: { startsWith: value } };
1994
+ case "endswith": return { [field]: { endsWith: value } };
1995
+ case "doesnotcontain": return { NOT: { [field]: { contains: value } } };
1996
+ case "doesnotbeginwith": return { NOT: { [field]: { startsWith: value } } };
1997
+ case "doesnotendwith": return { NOT: { [field]: { endsWith: value } } };
1998
+ case "null": return { [field]: null };
1999
+ case "notnull": return { [field]: { not: null } };
2000
+ case "in":
2001
+ case "notin": {
2002
+ const valueAsArray = require_arrayUtils.toArray(value);
2003
+ return { [field]: { [prismaOperators[operatorLC]]: valueAsArray.map((val) => processNumber(val, val, parseNumbers)) } };
2004
+ }
2005
+ case "between":
2006
+ case "notbetween": {
2007
+ const valueAsArray = require_arrayUtils.toArray(value);
2008
+ if (valueAsArray.length >= 2 && isValidValue(valueAsArray[0]) && isValidValue(valueAsArray[1])) {
2009
+ const [first, second] = valueAsArray;
2010
+ const shouldParseNumbers = !(parseNumbers === false);
2011
+ const firstNum = shouldRenderAsNumber(first, shouldParseNumbers) ? require_parseNumber.parseNumber(first, { parseNumbers }) : NaN;
2012
+ const secondNum = shouldRenderAsNumber(second, shouldParseNumbers) ? require_parseNumber.parseNumber(second, { parseNumbers }) : NaN;
2013
+ let firstValue = Number.isNaN(firstNum) ? first : firstNum;
2014
+ let secondValue = Number.isNaN(secondNum) ? second : secondNum;
2015
+ if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
2016
+ const tempNum = secondNum;
2017
+ secondValue = firstNum;
2018
+ firstValue = tempNum;
2019
+ }
2020
+ return operatorLC === "between" ? { [field]: {
2021
+ gte: firstValue,
2022
+ lte: secondValue
2023
+ } } : { OR: [{ [field]: { lt: firstValue } }, { [field]: { gt: secondValue } }] };
2024
+ } else return "";
2025
+ }
2026
+ }
2027
+ return "";
2028
+ };
2029
+
2030
+ //#endregion
2031
+ //#region src/utils/formatQuery/defaultRuleProcessorSequelize.ts
2032
+ /**
2033
+ * Default rule processor used by {@link formatQuery} for the "sequelize" format.
2034
+ *
2035
+ * @group Export
2036
+ */
2037
+ const defaultRuleProcessorSequelize = (rule, { parseNumbers, preserveValueOrder, context = {} } = {}) => {
2038
+ const { sequelizeOperators: Op, sequelizeCol: col, sequelizeFn: fn } = context;
2039
+ if (processMatchMode(rule)) return;
2040
+ const { field, operator, value, valueSource } = rule;
2041
+ const valueIsField = valueSource === "field";
2042
+ const operatorLC = require_isRuleGroup.lc(operator);
2043
+ if (!Op || valueIsField && (!col || !fn && [
2044
+ "doesnotcontain",
2045
+ "doesnotbeginwith",
2046
+ "doesnotendwith"
2047
+ ].includes(operatorLC))) return;
2048
+ switch (operatorLC) {
2049
+ case "=":
2050
+ case "!=":
2051
+ case "<":
2052
+ case "<=":
2053
+ case ">":
2054
+ case ">=": {
2055
+ const sequelizeOperator = {
2056
+ "=": Op.eq,
2057
+ "!=": Op.ne,
2058
+ "<": Op.lt,
2059
+ "<=": Op.lte,
2060
+ ">": Op.gt,
2061
+ ">=": Op.gte
2062
+ }[operatorLC];
2063
+ return { [field]: valueIsField && operatorLC === "=" ? { [Op.col]: value } : { [sequelizeOperator]: valueIsField ? col(value) : shouldRenderAsNumber(value, parseNumbers) ? require_parseNumber.parseNumber(value, { parseNumbers: "strict" }) : value } };
2064
+ }
2065
+ case "contains": return { [field]: { [Op.substring]: valueIsField ? col(value) : `${value}` } };
2066
+ case "beginswith": return { [field]: { [Op.startsWith]: valueIsField ? col(value) : `${value}` } };
2067
+ case "endswith": return { [field]: { [Op.endsWith]: valueIsField ? col(value) : `${value}` } };
2068
+ case "doesnotcontain": return { [field]: { [Op.notLike]: valueIsField ? fn("CONCAT", "%", col(value), "%") : `%${value}%` } };
2069
+ case "doesnotbeginwith": return { [field]: { [Op.notLike]: valueIsField ? fn("CONCAT", col(value), "%") : `${value}%` } };
2070
+ case "doesnotendwith": return { [field]: { [Op.notLike]: valueIsField ? fn("CONCAT", "%", col(value)) : `%${value}` } };
2071
+ case "null": return { [field]: { [Op.is]: null } };
2072
+ case "notnull": return { [field]: { [Op.not]: null } };
2073
+ case "in":
2074
+ case "notin": {
2075
+ const valueAsArray = require_arrayUtils.toArray(value);
2076
+ return { [field]: { [operatorLC === "in" ? Op.in : Op.notIn]: valueAsArray.map((val) => valueIsField ? col(val) : shouldRenderAsNumber(val, parseNumbers) ? require_parseNumber.parseNumber(val, { parseNumbers: "strict" }) : val) } };
2077
+ }
2078
+ case "between":
2079
+ case "notbetween": {
2080
+ const valueAsArray = require_arrayUtils.toArray(value, { retainEmptyStrings: true });
2081
+ if (valueAsArray.length < 2 || !isValidValue(valueAsArray[0]) || !isValidValue(valueAsArray[1])) return;
2082
+ const [first, second] = valueAsArray;
2083
+ const firstNum = shouldRenderAsNumber(first, parseNumbers) ? require_parseNumber.parseNumber(first, { parseNumbers: "strict" }) : NaN;
2084
+ const secondNum = shouldRenderAsNumber(second, parseNumbers) ? require_parseNumber.parseNumber(second, { parseNumbers: "strict" }) : NaN;
2085
+ const firstValue = Number.isNaN(firstNum) ? first : firstNum;
2086
+ const secondValue = Number.isNaN(secondNum) ? second : secondNum;
2087
+ const valsOneAndTwoOnly = [firstValue, secondValue];
2088
+ if (!preserveValueOrder && firstValue === firstNum && secondValue === secondNum && secondNum < firstNum) {
2089
+ valsOneAndTwoOnly[0] = secondNum;
2090
+ valsOneAndTwoOnly[1] = firstNum;
2091
+ }
2092
+ return { [field]: { [operatorLC === "between" ? Op.between : Op.notBetween]: valueIsField ? valsOneAndTwoOnly.map((v) => col(v)) : valsOneAndTwoOnly.every((v) => shouldRenderAsNumber(v, parseNumbers)) ? valsOneAndTwoOnly.map((v) => require_parseNumber.parseNumber(v, { parseNumbers: "strict" })) : valsOneAndTwoOnly } };
2093
+ }
2094
+ }
2095
+ };
2096
+
2097
+ //#endregion
2098
+ //#region src/utils/formatQuery/formatQuery.ts
2099
+ /**
2100
+ * A collection of option presets for {@link formatQuery}, specifically for SQL-based formats.
2101
+ *
2102
+ * @group Export
2103
+ */
2104
+ const sqlDialectPresets = {
2105
+ ansi: {},
2106
+ sqlite: { paramsKeepPrefix: true },
2107
+ oracle: {},
2108
+ mssql: {
2109
+ concatOperator: "+",
2110
+ quoteFieldNamesWith: ["[", "]"],
2111
+ fieldIdentifierSeparator: ".",
2112
+ paramPrefix: "@"
2113
+ },
2114
+ mysql: { concatOperator: "CONCAT" },
2115
+ postgresql: {
2116
+ quoteFieldNamesWith: "\"",
2117
+ numberedParams: true,
2118
+ paramPrefix: "$"
2119
+ }
2120
+ };
2121
+ /**
2122
+ * A collection of option presets for {@link formatQuery}.
2123
+ *
2124
+ * @group Export
2125
+ */
2126
+ const formatQueryOptionPresets = { ...sqlDialectPresets };
2127
+ const defaultRuleProcessors = {
2128
+ cel: defaultRuleProcessorCEL,
2129
+ drizzle: defaultRuleProcessorDrizzle,
2130
+ elasticsearch: defaultRuleProcessorElasticSearch,
2131
+ json_without_ids: defaultRuleProcessorSQL,
2132
+ json: defaultRuleProcessorSQL,
2133
+ jsonata: defaultRuleProcessorJSONata,
2134
+ jsonlogic: defaultRuleProcessorJsonLogic,
2135
+ ldap: defaultRuleProcessorLDAP,
2136
+ mongodb_query: defaultRuleProcessorMongoDBQuery,
2137
+ mongodb: defaultRuleProcessorMongoDB,
2138
+ natural_language: defaultRuleProcessorNL,
2139
+ parameterized_named: defaultRuleProcessorParameterized,
2140
+ parameterized: defaultRuleProcessorParameterized,
2141
+ prisma: defaultRuleProcessorPrisma,
2142
+ sequelize: defaultRuleProcessorSequelize,
2143
+ spel: defaultRuleProcessorSpEL,
2144
+ sql: defaultRuleProcessorSQL
2145
+ };
2146
+ /* istanbul ignore next */
2147
+ const defaultOperatorProcessor = (r) => r.operator;
2148
+ const defaultOperatorProcessors = {
2149
+ cel: defaultOperatorProcessor,
2150
+ drizzle: defaultOperatorProcessor,
2151
+ elasticsearch: defaultOperatorProcessor,
2152
+ json_without_ids: defaultOperatorProcessor,
2153
+ json: defaultOperatorProcessor,
2154
+ jsonata: defaultOperatorProcessor,
2155
+ jsonlogic: defaultOperatorProcessor,
2156
+ ldap: defaultOperatorProcessor,
2157
+ mongodb_query: defaultOperatorProcessor,
2158
+ mongodb: defaultOperatorProcessor,
2159
+ natural_language: defaultOperatorProcessorNL,
2160
+ parameterized_named: defaultOperatorProcessorSQL,
2161
+ parameterized: defaultOperatorProcessorSQL,
2162
+ prisma: defaultOperatorProcessor,
2163
+ sequelize: defaultOperatorProcessor,
2164
+ spel: defaultOperatorProcessor,
2165
+ sql: defaultOperatorProcessorSQL
2166
+ };
2167
+ const defaultFallbackExpressions = {
2168
+ cel: "1 == 1",
2169
+ ldap: "",
2170
+ mongodb: "\"$and\":[{\"$expr\":true}]",
2171
+ natural_language: "1 is 1",
2172
+ spel: "1 == 1",
2173
+ sql: "(1 = 1)"
2174
+ };
2175
+ const defaultFormatQueryOptions = {
2176
+ format: "json",
2177
+ fields: [],
2178
+ quoteFieldNamesWith: ["", ""],
2179
+ fieldIdentifierSeparator: "",
2180
+ getOperators: () => [],
2181
+ paramPrefix: ":",
2182
+ paramsKeepPrefix: false,
2183
+ numberedParams: false,
2184
+ preserveValueOrder: false,
2185
+ placeholderFieldName: require_arrayUtils.defaultPlaceholderFieldName,
2186
+ placeholderOperatorName: require_arrayUtils.defaultPlaceholderOperatorName,
2187
+ quoteValuesWith: "'",
2188
+ concatOperator: "||",
2189
+ preset: "ansi",
2190
+ wordOrder: "SVO",
2191
+ translations: {},
2192
+ operatorMap: {}
2193
+ };
2194
+ const valueProcessorCanActAsRuleProcessor = new Set([
2195
+ "cel",
2196
+ "drizzle",
2197
+ "elasticsearch",
2198
+ "jsonata",
2199
+ "jsonlogic",
2200
+ "ldap",
2201
+ "mongodb_query",
2202
+ "mongodb",
2203
+ "prisma",
2204
+ "sequelize",
2205
+ "spel"
2206
+ ]);
2207
+ const sqlFormats = new Set([
2208
+ "sql",
2209
+ "parameterized",
2210
+ "parameterized_named",
2211
+ "drizzle",
2212
+ "prisma",
2213
+ "sequelize"
2214
+ ]);
2215
+ function formatQuery(ruleGroup, optionParam = {}) {
2216
+ const options = typeof optionParam === "string" ? { format: require_isRuleGroup.lc(optionParam) } : optionParam;
2217
+ const optObj = {
2218
+ ...defaultFormatQueryOptions,
2219
+ ...!options.format || sqlFormats.has(options.format) ? sqlDialectPresets[options.preset ?? "ansi"] ?? null : null,
2220
+ ...options,
2221
+ ...!options.format && (Object.keys(sqlDialectPresets).includes(options.preset ?? "") ? { format: "sql" } : null)
2222
+ };
2223
+ const format = require_isRuleGroup.lc(optObj.format);
2224
+ const { fallbackExpression: fallbackExpression_option, getOperators: getOperators_option, operatorProcessor: operatorProcessor_option, parseNumbers, quoteFieldNamesWith: quoteFieldNamesWith_option, ruleGroupProcessor: ruleGroupProcessor_option, ruleProcessor: ruleProcessor_option, validator, valueProcessor: valueProcessor_option, context } = optObj;
2225
+ const getParseNumberBoolean = (inputType) => {
2226
+ return typeof getParseNumberMethod({
2227
+ parseNumbers,
2228
+ inputType
2229
+ }) === "string" ? true : typeof parseNumbers === "boolean" ? parseNumbers : void 0;
2230
+ };
2231
+ const operatorProcessor = typeof operatorProcessor_option === "function" ? operatorProcessor_option : defaultOperatorProcessors[format] ?? defaultOperatorProcessor;
2232
+ const valueProcessor = typeof valueProcessor_option === "function" ? isValueProcessorLegacy(valueProcessor_option) ? (r) => valueProcessor_option(r.field, r.operator, r.value, r.valueSource) : valueProcessor_option : format === "natural_language" ? defaultValueProcessorNL : valueProcessorCanActAsRuleProcessor.has(format) ? ruleProcessor_option ?? defaultRuleProcessors[format] : defaultValueProcessorByRule;
2233
+ const ruleProcessor = (typeof ruleProcessor_option === "function" ? ruleProcessor_option : null) ?? (valueProcessorCanActAsRuleProcessor.has(format) && typeof ruleProcessor_option !== "function" && valueProcessor_option ? valueProcessor : null) ?? defaultRuleProcessors[format] ?? defaultRuleProcessorSQL;
2234
+ const quoteFieldNamesWith = getQuoteFieldNamesWithArray(quoteFieldNamesWith_option);
2235
+ const fields = require_optGroupUtils.toFullOptionList(optObj.fields);
2236
+ const getOperators = (f, m) => require_optGroupUtils.toFullOptionList(getOperators_option(f, m) ?? []);
2237
+ const fallbackExpression = fallbackExpression_option ?? defaultFallbackExpressions[format] ?? defaultFallbackExpressions.sql;
2238
+ let validationMap = {};
2239
+ // istanbul ignore else
2240
+ if (typeof validator === "function") {
2241
+ const validationResult = validator(ruleGroup);
2242
+ if (typeof validationResult === "boolean") {
2243
+ // istanbul ignore else
2244
+ if (!validationResult) return format === "parameterized" ? {
2245
+ sql: fallbackExpression,
2246
+ params: []
2247
+ } : format === "parameterized_named" ? {
2248
+ sql: fallbackExpression,
2249
+ params: {}
2250
+ } : format === "mongodb" ? `{${fallbackExpression}}` : format === "mongodb_query" ? mongoDbFallback : format === "prisma" ? prismaFallback : format === "jsonlogic" ? false : format === "elasticsearch" ? {} : format === "drizzle" || format === "sequelize" ? void 0 : fallbackExpression;
2251
+ } else validationMap = validationResult;
2252
+ }
2253
+ const validatorMap = {};
2254
+ const uniqueFields = require_optGroupUtils.toFlatOptionArray(fields);
2255
+ for (const f of uniqueFields)
2256
+ // istanbul ignore else
2257
+ if (typeof f.validator === "function") validatorMap[f.value ?? f.name] = f.validator;
2258
+ const validateRule = (rule) => {
2259
+ let validationResult;
2260
+ let fieldValidator;
2261
+ if (rule.id) validationResult = validationMap[rule.id];
2262
+ if (uniqueFields.length > 0) {
2263
+ const fieldArr = uniqueFields.filter((f) => f.name === rule.field);
2264
+ if (fieldArr.length > 0) {
2265
+ const field = fieldArr[0];
2266
+ // istanbul ignore else
2267
+ if (typeof field.validator === "function") fieldValidator = field.validator;
2268
+ }
2269
+ }
2270
+ return [validationResult, fieldValidator];
2271
+ };
2272
+ const finalOptions = {
2273
+ ...optObj,
2274
+ fallbackExpression,
2275
+ fields,
2276
+ format,
2277
+ getOperators,
2278
+ getParseNumberBoolean,
2279
+ quoteFieldNamesWith,
2280
+ operatorProcessor,
2281
+ ruleProcessor,
2282
+ valueProcessor,
2283
+ validateRule,
2284
+ validationMap,
2285
+ context
2286
+ };
2287
+ if (typeof ruleGroupProcessor_option === "function") return ruleGroupProcessor_option(ruleGroup, finalOptions);
2288
+ switch (format) {
2289
+ case "json":
2290
+ case "json_without_ids": {
2291
+ const rg = parseNumbers ? (0, immer.produce)(ruleGroup, (g) => numerifyValues(g, finalOptions)) : ruleGroup;
2292
+ if (format === "json_without_ids") return JSON.stringify(rg, (key, value) => key === "id" || key === "path" ? void 0 : bigIntJsonStringifyReplacer(key, value));
2293
+ return JSON.stringify(rg, bigIntJsonStringifyReplacer, 2);
2294
+ }
2295
+ case "sql": return defaultRuleGroupProcessorSQL(ruleGroup, finalOptions);
2296
+ case "parameterized":
2297
+ case "parameterized_named": return defaultRuleGroupProcessorParameterized(ruleGroup, finalOptions);
2298
+ case "mongodb": return defaultRuleGroupProcessorMongoDB(ruleGroup, finalOptions);
2299
+ case "mongodb_query": return defaultRuleGroupProcessorMongoDBQuery(ruleGroup, finalOptions);
2300
+ case "cel": return defaultRuleGroupProcessorCEL(ruleGroup, finalOptions);
2301
+ case "spel": return defaultRuleGroupProcessorSpEL(ruleGroup, finalOptions);
2302
+ case "jsonata": return defaultRuleGroupProcessorJSONata(ruleGroup, finalOptions);
2303
+ case "jsonlogic": return defaultRuleGroupProcessorJsonLogic(ruleGroup, finalOptions);
2304
+ case "elasticsearch": return defaultRuleGroupProcessorElasticSearch(ruleGroup, finalOptions);
2305
+ case "natural_language": return defaultRuleGroupProcessorNL(ruleGroup, finalOptions);
2306
+ case "ldap": return defaultRuleGroupProcessorLDAP(ruleGroup, finalOptions);
2307
+ case "prisma": return defaultRuleGroupProcessorPrisma(ruleGroup, finalOptions);
2308
+ case "drizzle": return defaultRuleGroupProcessorDrizzle(ruleGroup, finalOptions);
2309
+ case "sequelize": return defaultRuleGroupProcessorSequelize(ruleGroup, finalOptions);
2310
+ default: return "";
2311
+ }
2312
+ }
2313
+
2314
+ //#endregion
2315
+ //#region src/utils/formatQuery/index.ts
2316
+ const generateValueProcessor = (vpbr) => (field, operator, value, valueSource) => vpbr({
2317
+ field,
2318
+ operator,
2319
+ value,
2320
+ valueSource
2321
+ }, { parseNumbers: false });
2322
+ /**
2323
+ * Default value processor used by {@link formatQuery} for "sql" format.
2324
+ *
2325
+ * @group Export
2326
+ */
2327
+ const defaultValueProcessor = generateValueProcessor(defaultValueProcessorByRule);
2328
+ /**
2329
+ * @deprecated Prefer {@link defaultRuleProcessorMongoDB}.
2330
+ *
2331
+ * @group Export
2332
+ */
2333
+ const defaultMongoDBValueProcessor = generateValueProcessor(defaultRuleProcessorMongoDB);
2334
+ /**
2335
+ * @deprecated Prefer {@link defaultRuleProcessorCEL}.
2336
+ *
2337
+ * @group Export
2338
+ */
2339
+ const defaultCELValueProcessor = generateValueProcessor(defaultRuleProcessorCEL);
2340
+ /**
2341
+ * @deprecated Prefer {@link defaultRuleProcessorSpEL}.
2342
+ *
2343
+ * @group Export
2344
+ */
2345
+ const defaultSpELValueProcessor = generateValueProcessor(defaultRuleProcessorSpEL);
2346
+ /**
2347
+ * @deprecated Renamed to {@link defaultRuleProcessorCEL}.
2348
+ *
2349
+ * @group Export
2350
+ */
2351
+ const defaultValueProcessorCELByRule = defaultRuleProcessorCEL;
2352
+ /**
2353
+ * @deprecated Renamed to {@link defaultRuleProcessorMongoDB}.
2354
+ *
2355
+ * @group Export
2356
+ */
2357
+ const defaultValueProcessorMongoDBByRule = defaultRuleProcessorMongoDB;
2358
+ /**
2359
+ * @deprecated Renamed to {@link defaultRuleProcessorSpEL}.
2360
+ *
2361
+ * @group Export
2362
+ */
2363
+ const defaultValueProcessorSpELByRule = defaultRuleProcessorSpEL;
2364
+
2365
+ //#endregion
2366
+ exports.bigIntJsonParseReviver = bigIntJsonParseReviver;
2367
+ exports.bigIntJsonStringifyReplacer = bigIntJsonStringifyReplacer;
2368
+ exports.celCombinatorMap = celCombinatorMap;
2369
+ exports.defaultCELValueProcessor = defaultCELValueProcessor;
2370
+ exports.defaultExportOperatorMap = defaultExportOperatorMap;
2371
+ exports.defaultMongoDBValueProcessor = defaultMongoDBValueProcessor;
2372
+ exports.defaultNLTranslations = defaultNLTranslations;
2373
+ exports.defaultOperatorProcessorNL = defaultOperatorProcessorNL;
2374
+ exports.defaultOperatorProcessorSQL = defaultOperatorProcessorSQL;
2375
+ exports.defaultRuleGroupProcessorCEL = defaultRuleGroupProcessorCEL;
2376
+ exports.defaultRuleGroupProcessorDrizzle = defaultRuleGroupProcessorDrizzle;
2377
+ exports.defaultRuleGroupProcessorElasticSearch = defaultRuleGroupProcessorElasticSearch;
2378
+ exports.defaultRuleGroupProcessorJSONata = defaultRuleGroupProcessorJSONata;
2379
+ exports.defaultRuleGroupProcessorJsonLogic = defaultRuleGroupProcessorJsonLogic;
2380
+ exports.defaultRuleGroupProcessorLDAP = defaultRuleGroupProcessorLDAP;
2381
+ exports.defaultRuleGroupProcessorMongoDB = defaultRuleGroupProcessorMongoDB;
2382
+ exports.defaultRuleGroupProcessorMongoDBQuery = defaultRuleGroupProcessorMongoDBQuery;
2383
+ exports.defaultRuleGroupProcessorNL = defaultRuleGroupProcessorNL;
2384
+ exports.defaultRuleGroupProcessorParameterized = defaultRuleGroupProcessorParameterized;
2385
+ exports.defaultRuleGroupProcessorPrisma = defaultRuleGroupProcessorPrisma;
2386
+ exports.defaultRuleGroupProcessorSQL = defaultRuleGroupProcessorSQL;
2387
+ exports.defaultRuleGroupProcessorSequelize = defaultRuleGroupProcessorSequelize;
2388
+ exports.defaultRuleGroupProcessorSpEL = defaultRuleGroupProcessorSpEL;
2389
+ exports.defaultRuleProcessorCEL = defaultRuleProcessorCEL;
2390
+ exports.defaultRuleProcessorDrizzle = defaultRuleProcessorDrizzle;
2391
+ exports.defaultRuleProcessorElasticSearch = defaultRuleProcessorElasticSearch;
2392
+ exports.defaultRuleProcessorJSONata = defaultRuleProcessorJSONata;
2393
+ exports.defaultRuleProcessorJsonLogic = defaultRuleProcessorJsonLogic;
2394
+ exports.defaultRuleProcessorLDAP = defaultRuleProcessorLDAP;
2395
+ exports.defaultRuleProcessorMongoDB = defaultRuleProcessorMongoDB;
2396
+ exports.defaultRuleProcessorMongoDBQuery = defaultRuleProcessorMongoDBQuery;
2397
+ exports.defaultRuleProcessorNL = defaultRuleProcessorNL;
2398
+ exports.defaultRuleProcessorParameterized = defaultRuleProcessorParameterized;
2399
+ exports.defaultRuleProcessorPrisma = defaultRuleProcessorPrisma;
2400
+ exports.defaultRuleProcessorSQL = defaultRuleProcessorSQL;
2401
+ exports.defaultRuleProcessorSequelize = defaultRuleProcessorSequelize;
2402
+ exports.defaultRuleProcessorSpEL = defaultRuleProcessorSpEL;
2403
+ exports.defaultSpELValueProcessor = defaultSpELValueProcessor;
2404
+ exports.defaultValueProcessor = defaultValueProcessor;
2405
+ exports.defaultValueProcessorByRule = defaultValueProcessorByRule;
2406
+ exports.defaultValueProcessorCELByRule = defaultValueProcessorCELByRule;
2407
+ exports.defaultValueProcessorMongoDBByRule = defaultValueProcessorMongoDBByRule;
2408
+ exports.defaultValueProcessorNL = defaultValueProcessorNL;
2409
+ exports.defaultValueProcessorSpELByRule = defaultValueProcessorSpELByRule;
2410
+ exports.formatQuery = formatQuery;
2411
+ exports.formatQueryOptionPresets = formatQueryOptionPresets;
2412
+ exports.getNLTranslataion = getNLTranslataion;
2413
+ exports.getQuoteFieldNamesWithArray = getQuoteFieldNamesWithArray;
2414
+ exports.getQuotedFieldName = getQuotedFieldName;
2415
+ exports.isValidValue = isValidValue;
2416
+ exports.isValueProcessorLegacy = isValueProcessorLegacy;
2417
+ exports.jsonLogicAdditionalOperators = jsonLogicAdditionalOperators;
2418
+ exports.mapSQLOperator = mapSQLOperator;
2419
+ exports.mongoDbFallback = mongoDbFallback;
2420
+ exports.mongoOperators = mongoOperators;
2421
+ exports.normalizeConstituentWordOrder = normalizeConstituentWordOrder;
2422
+ exports.numerifyValues = numerifyValues;
2423
+ exports.prismaFallback = prismaFallback;
2424
+ exports.prismaOperators = prismaOperators;
2425
+ exports.processMatchMode = processMatchMode;
2426
+ exports.shouldRenderAsNumber = shouldRenderAsNumber;
2427
+ exports.sqlDialectPresets = sqlDialectPresets;
2428
+ //# sourceMappingURL=formatQuery.js.map