@react-querybuilder/core 8.22.5 → 8.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/derivations/package.json +4 -0
  2. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +2078 -1665
  3. package/dist/cjs/react-querybuilder_core.cjs.development.js +1293 -422
  4. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  5. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +2078 -1665
  6. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  7. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  8. package/dist/{convertQuery-Cw76XFIn.js → convertQuery-BLT0GIhM.js} +17 -8
  9. package/dist/{convertQuery-Cw76XFIn.js.map → convertQuery-BLT0GIhM.js.map} +1 -1
  10. package/dist/{convertQuery-D_4J7E-Z.mjs → convertQuery-DaXv3h7S.mjs} +6 -3
  11. package/dist/{convertQuery-D_4J7E-Z.mjs.map → convertQuery-DaXv3h7S.mjs.map} +1 -1
  12. package/dist/derivations.d.mts +2902 -0
  13. package/dist/derivations.d.ts +2902 -0
  14. package/dist/derivations.js +2845 -0
  15. package/dist/derivations.js.map +1 -0
  16. package/dist/derivations.mjs +2678 -0
  17. package/dist/derivations.mjs.map +1 -0
  18. package/dist/formatQuery.d.mts +2 -895
  19. package/dist/formatQuery.d.ts +2 -895
  20. package/dist/formatQuery.js +120 -140
  21. package/dist/formatQuery.js.map +1 -1
  22. package/dist/formatQuery.mjs +8 -28
  23. package/dist/formatQuery.mjs.map +1 -1
  24. package/dist/{import-DVWI7Fdh.d.mts → import-BdKPtLzo.d.mts} +2 -2
  25. package/dist/{import-6ExjhifL.d.ts → import-BfZTwhp2.d.ts} +2 -2
  26. package/dist/{index-CX9mehdL.d.mts → index-DOIE2pwx.d.mts} +274 -3
  27. package/dist/{index-CX9mehdL.d.ts → index-DOIE2pwx.d.ts} +274 -3
  28. package/dist/index-OF2Q1gTp.d.mts +895 -0
  29. package/dist/index-XueTy_XQ.d.ts +895 -0
  30. package/dist/isRuleOrGroupValid-CIMZNkt4.mjs +27 -0
  31. package/dist/isRuleOrGroupValid-CIMZNkt4.mjs.map +1 -0
  32. package/dist/isRuleOrGroupValid-CtUf4_4x.js +38 -0
  33. package/dist/isRuleOrGroupValid-CtUf4_4x.js.map +1 -0
  34. package/dist/{isRuleGroup-CqLThsbu.mjs → objectUtils-DDZ-KhV5.mjs} +25 -2
  35. package/dist/objectUtils-DDZ-KhV5.mjs.map +1 -0
  36. package/dist/{isRuleGroup-0JNiQgLg.js → objectUtils-DfnEmDSV.js} +48 -1
  37. package/dist/objectUtils-DfnEmDSV.js.map +1 -0
  38. package/dist/parseCEL.d.mts +2 -2
  39. package/dist/parseCEL.d.ts +2 -2
  40. package/dist/parseCEL.js +19 -16
  41. package/dist/parseCEL.js.map +1 -1
  42. package/dist/parseCEL.mjs +12 -9
  43. package/dist/parseCEL.mjs.map +1 -1
  44. package/dist/parseCypher.d.mts +1 -1
  45. package/dist/parseCypher.d.ts +1 -1
  46. package/dist/parseGremlin.d.mts +1 -1
  47. package/dist/parseGremlin.d.ts +1 -1
  48. package/dist/parseJSONata.d.mts +2 -2
  49. package/dist/parseJSONata.d.ts +2 -2
  50. package/dist/parseJSONata.js +17 -14
  51. package/dist/parseJSONata.js.map +1 -1
  52. package/dist/parseJSONata.mjs +11 -8
  53. package/dist/parseJSONata.mjs.map +1 -1
  54. package/dist/parseJsonLogic.d.mts +2 -2
  55. package/dist/parseJsonLogic.d.ts +2 -2
  56. package/dist/parseJsonLogic.js +38 -38
  57. package/dist/parseJsonLogic.js.map +1 -1
  58. package/dist/parseJsonLogic.mjs +5 -5
  59. package/dist/parseMongoDB.d.mts +2 -2
  60. package/dist/parseMongoDB.d.ts +2 -2
  61. package/dist/parseMongoDB.js +50 -47
  62. package/dist/parseMongoDB.js.map +1 -1
  63. package/dist/parseMongoDB.mjs +35 -32
  64. package/dist/parseMongoDB.mjs.map +1 -1
  65. package/dist/parseSPARQL.d.mts +1 -1
  66. package/dist/parseSPARQL.d.ts +1 -1
  67. package/dist/parseSQL.d.mts +2 -2
  68. package/dist/parseSQL.d.ts +2 -2
  69. package/dist/parseSQL.js +27 -23
  70. package/dist/parseSQL.js.map +1 -1
  71. package/dist/parseSQL.mjs +21 -17
  72. package/dist/parseSQL.mjs.map +1 -1
  73. package/dist/parseSpEL.d.mts +2 -2
  74. package/dist/parseSpEL.d.ts +2 -2
  75. package/dist/parseSpEL.js +17 -14
  76. package/dist/parseSpEL.js.map +1 -1
  77. package/dist/parseSpEL.mjs +13 -10
  78. package/dist/parseSpEL.mjs.map +1 -1
  79. package/dist/parserUtils-BKPstAaO.mjs +30 -0
  80. package/dist/parserUtils-BKPstAaO.mjs.map +1 -0
  81. package/dist/parserUtils-DbBXyAht.js +41 -0
  82. package/dist/parserUtils-DbBXyAht.js.map +1 -0
  83. package/dist/{prepareQueryObjects-BnGL91Tt.js → prepareQueryObjects-Dj9cTl9D.js} +90 -63
  84. package/dist/prepareQueryObjects-Dj9cTl9D.js.map +1 -0
  85. package/dist/{prepareQueryObjects-ChINDIap.mjs → prepareQueryObjects-Dmyf3Wi_.mjs} +56 -59
  86. package/dist/prepareQueryObjects-Dmyf3Wi_.mjs.map +1 -0
  87. package/dist/react-querybuilder_core.d.mts +2078 -1665
  88. package/dist/react-querybuilder_core.legacy-esm.d.ts +2078 -1665
  89. package/dist/react-querybuilder_core.legacy-esm.js +1445 -635
  90. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  91. package/dist/react-querybuilder_core.mjs +1288 -424
  92. package/dist/react-querybuilder_core.mjs.map +1 -1
  93. package/dist/react-querybuilder_core.production.d.mts +2078 -1665
  94. package/dist/react-querybuilder_core.production.mjs +1 -1
  95. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  96. package/dist/transformQuery-B7d9AWUf.d.mts +116 -0
  97. package/dist/transformQuery-BXDiUBGB.d.ts +116 -0
  98. package/dist/transformQuery.d.mts +2 -116
  99. package/dist/transformQuery.d.ts +2 -116
  100. package/dist/transformQuery.js +3 -4
  101. package/dist/transformQuery.js.map +1 -1
  102. package/dist/transformQuery.mjs +1 -2
  103. package/dist/transformQuery.mjs.map +1 -1
  104. package/dist/utils-CP5Jqy1P.mjs +1294 -0
  105. package/dist/utils-CP5Jqy1P.mjs.map +1 -0
  106. package/dist/utils-e-7KHkjV.js +1779 -0
  107. package/dist/utils-e-7KHkjV.js.map +1 -0
  108. package/package.json +33 -22
  109. package/dist/isRuleGroup-0JNiQgLg.js.map +0 -1
  110. package/dist/isRuleGroup-CqLThsbu.mjs.map +0 -1
  111. package/dist/objectUtils-Cr02aGxb.js +0 -27
  112. package/dist/objectUtils-Cr02aGxb.js.map +0 -1
  113. package/dist/objectUtils-DBlmJgBf.mjs +0 -16
  114. package/dist/objectUtils-DBlmJgBf.mjs.map +0 -1
  115. package/dist/prepareQueryObjects-BnGL91Tt.js.map +0 -1
  116. package/dist/prepareQueryObjects-ChINDIap.mjs.map +0 -1
  117. package/dist/utils-4k-j5FBa.mjs +0 -537
  118. package/dist/utils-4k-j5FBa.mjs.map +0 -1
  119. package/dist/utils-C79dxwZb.js +0 -752
  120. package/dist/utils-C79dxwZb.js.map +0 -1
@@ -1,537 +0,0 @@
1
- import { a as lc, i as isPojo, s as numericRegex$1, t as isRuleGroup } from "./isRuleGroup-CqLThsbu.mjs";
2
- import { numericQuantity } from "numeric-quantity";
3
- //#region src/defaults.ts
4
- /**
5
- * Map of default operators to their respective opposite/negating operators.
6
- *
7
- * @group Defaults
8
- */
9
- const defaultOperatorNegationMap = {
10
- "=": "!=",
11
- "!=": "=",
12
- "<": ">=",
13
- "<=": ">",
14
- ">": "<=",
15
- ">=": "<",
16
- beginsWith: "doesNotBeginWith",
17
- doesNotBeginWith: "beginsWith",
18
- endsWith: "doesNotEndWith",
19
- doesNotEndWith: "endsWith",
20
- contains: "doesNotContain",
21
- doesNotContain: "contains",
22
- between: "notBetween",
23
- notBetween: "between",
24
- in: "notIn",
25
- notIn: "in",
26
- notNull: "null",
27
- null: "notNull"
28
- };
29
- //#endregion
30
- //#region src/utils/arrayUtils.ts
31
- /**
32
- * Splits a string by a given character (see {@link defaultJoinChar}). Escaped characters
33
- * (characters preceded by a backslash) will not apply to the split, and the backslash will
34
- * be removed in the array element. Inverse of {@link joinWith}.
35
- *
36
- * @example
37
- * splitBy('this\\,\\,that,,the other,,,\\,')
38
- * // or
39
- * splitBy('this\\,\\,that,,the other,,,\\,', ',')
40
- * // would return
41
- * ['this,,that', '', 'the other', '', '', ',']
42
- */
43
- const splitBy = (str, splitChar = ",") => typeof str === "string" ? str.split(`\\${splitChar}`).map((c) => c.split(splitChar)).reduce((prev, curr, idx) => {
44
- if (idx === 0) return curr;
45
- return [
46
- ...prev.slice(0, -1),
47
- `${prev.at(-1)}${splitChar}${curr[0]}`,
48
- ...curr.slice(1)
49
- ];
50
- }, []) : [];
51
- /**
52
- * Joins an array of strings using the given character (see {@link defaultJoinChar}). When
53
- * the given character appears in an array element, a backslash will be added just before it
54
- * to distinguish it from the join character. Effectively the inverse of {@link splitBy}.
55
- *
56
- * TIP: The join character can actually be a string of any length. Only the first character
57
- * will be searched for in the array elements and preceded by a backslash.
58
- *
59
- * @example
60
- * joinWith(['this,,that', '', 'the other', '', '', ','], ', ')
61
- * // would return
62
- * 'this\\,\\,that, , the other, , , \\,'
63
- */
64
- const joinWith = (strArr, joinChar = ",") => strArr.map((str) => `${str ?? ""}`.replaceAll(joinChar[0], `\\${joinChar[0]}`)).join(joinChar);
65
- /**
66
- * Trims the value if it is a string. Otherwise returns the value as is.
67
- */
68
- const trimIfString = (val) => typeof val === "string" ? val.trim() : val;
69
- /**
70
- * Splits a string by comma then trims each element. Arrays are returned as is except
71
- * any string elements are trimmed.
72
- */
73
- const toArray = (a, { retainEmptyStrings } = {}) => Array.isArray(a) ? a.map(trimIfString) : typeof a === "string" ? splitBy(a, ",").filter(retainEmptyStrings ? () => true : (s) => !/^\s*$/.test(s)).map((s) => s.trim()) : typeof a === "number" ? [a] : [];
74
- //#endregion
75
- //#region src/utils/parseNumber.ts
76
- /**
77
- * Converts a string to a number. Uses native `parseFloat` if `parseNumbers` is "native",
78
- * otherwise uses [`numeric-quantity`](https://jakeboone02.github.io/numeric-quantity/).
79
- * If that returns `NaN`, the string is returned unchanged. Numeric values are returned
80
- * as-is regardless of the `parseNumbers` option.
81
- */
82
- const parseNumber = (val, { parseNumbers, bigIntOnOverflow } = {}) => {
83
- if (!parseNumbers || typeof val === "bigint" || typeof val === "number") return val;
84
- if (parseNumbers === "native") return Number.parseFloat(val);
85
- const valAsNum = numericQuantity(val, {
86
- allowTrailingInvalid: parseNumbers === "enhanced",
87
- bigIntOnOverflow,
88
- romanNumerals: false,
89
- round: false
90
- });
91
- return typeof valAsNum === "bigint" || !Number.isNaN(valAsNum) ? valAsNum : val;
92
- };
93
- //#endregion
94
- //#region src/utils/optGroupUtils.ts
95
- const isOptionWithName = (opt) => isPojo(opt) && "name" in opt && typeof opt.name === "string";
96
- const isOptionWithValue = (opt) => isPojo(opt) && "value" in opt && typeof opt.value === "string";
97
- /**
98
- * Converts an {@link Option} or {@link ValueOption} (i.e., {@link BaseOption})
99
- * into a {@link FullOption}. Full options are left unchanged.
100
- *
101
- * @group Option Lists
102
- */
103
- function toFullOption(opt, baseProperties, labelMap) {
104
- if (typeof opt === "string") return {
105
- ...baseProperties,
106
- name: opt,
107
- value: opt,
108
- label: labelMap?.[opt] ?? opt
109
- };
110
- const idObj = {};
111
- let needsUpdating = !!baseProperties;
112
- if (isOptionWithName(opt) && !isOptionWithValue(opt)) {
113
- idObj.value = opt.name;
114
- needsUpdating = true;
115
- } else if (!isOptionWithName(opt) && isOptionWithValue(opt)) {
116
- idObj.name = opt.value;
117
- needsUpdating = true;
118
- }
119
- if (needsUpdating) return Object.assign({}, baseProperties, opt, idObj);
120
- return opt;
121
- }
122
- /**
123
- * Converts an {@link OptionList} or {@link FlexibleOptionList} into a {@link FullOptionList}.
124
- * Lists of full options are left unchanged.
125
- *
126
- * @group Option Lists
127
- */
128
- function toFullOptionList(optList, baseProperties, labelMap) {
129
- if (!Array.isArray(optList)) return [];
130
- const list = optList;
131
- if (isFlexibleOptionGroupArray(list)) return list.map((optGroup) => ({
132
- ...optGroup,
133
- options: optGroup.options.map((opt) => toFullOption(opt, baseProperties, labelMap))
134
- }));
135
- return list.map((opt) => toFullOption(opt, baseProperties, labelMap));
136
- }
137
- /**
138
- * Generates a new array of objects with duplicates removed based
139
- * on the identifying property (`value` or `name`)
140
- *
141
- * @group Option Lists
142
- */
143
- const uniqByIdentifier = (originalArray) => {
144
- const names = /* @__PURE__ */ new Set();
145
- const newArray = [];
146
- for (const el of originalArray) if (!names.has(el.value ?? el.name)) {
147
- names.add(el.value ?? el.name);
148
- newArray.push(el);
149
- }
150
- return originalArray.length === newArray.length ? originalArray : newArray;
151
- };
152
- /**
153
- * Determines if an {@link OptionList} is an {@link OptionGroup} array.
154
- *
155
- * @group Option Lists
156
- */
157
- const isOptionGroupArray = (arr) => Array.isArray(arr) && arr.length > 0 && isPojo(arr[0]) && "options" in arr[0] && Array.isArray(arr[0].options);
158
- /**
159
- * Determines if an array is a flat array of {@link FlexibleOption}.
160
- *
161
- * @group Option Lists
162
- */
163
- const isFlexibleOptionArray = (arr) => {
164
- let isFOA = false;
165
- if (Array.isArray(arr)) for (const o of arr) if (isOptionWithName(o) || isOptionWithValue(o)) isFOA = true;
166
- else return false;
167
- return isFOA;
168
- };
169
- /**
170
- * Determines if a {@link FlexibleOptionList} is a {@link FlexibleOptionGroup} array.
171
- *
172
- * @group Option Lists
173
- */
174
- const isFlexibleOptionGroupArray = (arr, { allowEmpty = false } = {}) => {
175
- let isFOGA = false;
176
- if (Array.isArray(arr)) for (const og of arr) if (isPojo(og) && "options" in og && (isFlexibleOptionArray(og.options) || allowEmpty && Array.isArray(og.options) && og.options.length === 0)) isFOGA = true;
177
- else return false;
178
- return isFOGA;
179
- };
180
- function getOption(arr, name) {
181
- return (isFlexibleOptionGroupArray(arr, { allowEmpty: true }) ? arr.flatMap((og) => og.options) : arr).find((op) => op.value === name || op.name === name);
182
- }
183
- /**
184
- * Flattens {@link FlexibleOptionGroup} arrays into {@link BaseOption} arrays.
185
- * If the array is already flat, it is returned as is.
186
- *
187
- * @group Option Lists
188
- */
189
- const toFlatOptionArray = (arr) => uniqByIdentifier(isOptionGroupArray(arr) ? arr.flatMap((og) => og.options) : arr);
190
- //#endregion
191
- //#region src/utils/getParseNumberMethod.ts
192
- const getParseNumberMethod = ({ parseNumbers, inputType }) => {
193
- if (typeof parseNumbers === "string") {
194
- const [method, level] = parseNumbers.split("-");
195
- if (level === "limited") return inputType === "number" ? method : false;
196
- return method;
197
- }
198
- return parseNumbers ? "strict" : false;
199
- };
200
- //#endregion
201
- //#region src/utils/formatQuery/utils.ts
202
- /**
203
- * Maps a {@link DefaultOperatorName} to a SQL operator.
204
- *
205
- * @group Export
206
- */
207
- const mapSQLOperator = (rqbOperator) => {
208
- switch (lc(rqbOperator)) {
209
- case "null": return "is null";
210
- case "notnull": return "is not null";
211
- case "notin": return "not in";
212
- case "notbetween": return "not between";
213
- case "contains":
214
- case "beginswith":
215
- case "endswith": return "like";
216
- case "doesnotcontain":
217
- case "doesnotbeginwith":
218
- case "doesnotendwith": return "not like";
219
- default: return rqbOperator;
220
- }
221
- };
222
- /**
223
- * Returns a preset-aware SQL string-concatenation function. Emits `CONCAT(a, b, ...)` when
224
- * `concatOperator` is `"CONCAT"` (case-insensitive), otherwise joins with the infix operator
225
- * (e.g. `a || b`, `a + b`).
226
- *
227
- * @group Export
228
- */
229
- const getSQLConcat = (concatOperator = "||") => (...values) => concatOperator.toUpperCase() === "CONCAT" ? `CONCAT(${values.join(", ")})` : values.join(` ${concatOperator} `);
230
- /**
231
- * Returns the `[prefix, suffix]` `LIKE` wildcards for a string-match operator (e.g. `contains`
232
- * → `['%', '%']`, `beginsWith` → `['', '%']`, `endsWith` → `['%', '']`). Unknown operators
233
- * yield `['', '']`.
234
- *
235
- * @group Export
236
- */
237
- const getLikeWildcards = (operatorLC) => {
238
- switch (operatorLC) {
239
- case "contains":
240
- case "doesnotcontain": return ["%", "%"];
241
- case "beginswith":
242
- case "doesnotbeginwith": return ["", "%"];
243
- case "endswith":
244
- case "doesnotendwith": return ["%", ""];
245
- default: return ["", ""];
246
- }
247
- };
248
- /**
249
- * Wraps an already-serialized SQL fragment (a quoted field name or an expression) with the
250
- * `LIKE` wildcards for the given (lowercase) string-match operator, concatenating the literal
251
- * `%` markers via the preset-aware {@link getSQLConcat}. Returns the fragment untouched for
252
- * operators without wildcards.
253
- *
254
- * @group Export
255
- */
256
- const wrapLikeFragment = (fragment, operatorLC, { concatOperator = "||", quoteValuesWith, wrapValueWith = ["", ""] } = {}) => {
257
- const [pre, post] = getLikeWildcards(operatorLC);
258
- const quoteChar = quoteValuesWith || `'`;
259
- const quote = (p) => `${wrapValueWith[0]}${quoteChar}${p}${quoteChar}${wrapValueWith[1]}`;
260
- const parts = [
261
- pre && quote(pre),
262
- fragment,
263
- post && quote(post)
264
- ].filter(Boolean);
265
- return parts.length > 1 ? getSQLConcat(concatOperator)(...parts) : fragment;
266
- };
267
- /**
268
- * Maps a (lowercase) {@link DefaultOperatorName} to a MongoDB operator.
269
- *
270
- * @group Export
271
- */
272
- const mongoOperators = {
273
- "=": "$eq",
274
- "!=": "$ne",
275
- "<": "$lt",
276
- "<=": "$lte",
277
- ">": "$gt",
278
- ">=": "$gte",
279
- in: "$in",
280
- notin: "$nin",
281
- notIn: "$nin"
282
- };
283
- /**
284
- * Maps a (lowercase) {@link DefaultOperatorName} to a Prisma ORM operator.
285
- *
286
- * @group Export
287
- */
288
- const prismaOperators = {
289
- "=": "equals",
290
- "!=": "not",
291
- "<": "lt",
292
- "<=": "lte",
293
- ">": "gt",
294
- ">=": "gte",
295
- in: "in",
296
- notin: "notIn"
297
- };
298
- /**
299
- * Maps a {@link DefaultCombinatorName} to a CEL combinator.
300
- *
301
- * @group Export
302
- */
303
- const celCombinatorMap = {
304
- and: "&&",
305
- or: "||"
306
- };
307
- /**
308
- * Register these operators with `jsonLogic` before applying the result
309
- * of `formatQuery(query, 'jsonlogic')`.
310
- *
311
- * @example
312
- * ```
313
- * for (const [op, func] of Object.entries(jsonLogicAdditionalOperators)) {
314
- * jsonLogic.add_operation(op, func);
315
- * }
316
- * jsonLogic.apply({ "startsWith": [{ "var": "firstName" }, "Stev"] }, data);
317
- * ```
318
- *
319
- * @group Export
320
- */
321
- const jsonLogicAdditionalOperators = {
322
- startsWith: (a, b) => typeof a === "string" && a.startsWith(b),
323
- endsWith: (a, b) => typeof a === "string" && a.endsWith(b)
324
- };
325
- /**
326
- * Returns a new query object with all `string`-type `value` properties converted
327
- * to `number` where appropriate.
328
- *
329
- * Used by {@link formatQuery} for the `json*` formats when `parseNumbers` is `true`.
330
- *
331
- * @group Export
332
- */
333
- const numerifyValues = (rg, options) => ({
334
- ...rg,
335
- rules: rg.rules.map((r) => {
336
- if (typeof r === "string") return r;
337
- if (isRuleGroup(r)) return numerifyValues(r, options);
338
- const fieldData = getOption(options.fields, r.field);
339
- const parseNumbers = getParseNumberMethod({
340
- parseNumbers: options.parseNumbers,
341
- inputType: fieldData?.inputType
342
- });
343
- if (Array.isArray(r.value)) return {
344
- ...r,
345
- value: r.value.map((v) => parseNumber(v, { parseNumbers }))
346
- };
347
- const valAsArray = toArray(r.value, { retainEmptyStrings: true }).map((v) => parseNumber(v, { parseNumbers }));
348
- if (valAsArray.every((v) => typeof v === "number")) {
349
- // v8 ignore else
350
- if (valAsArray.length > 1) return {
351
- ...r,
352
- value: valAsArray
353
- };
354
- else if (valAsArray.length === 1) return {
355
- ...r,
356
- value: valAsArray[0]
357
- };
358
- }
359
- return r;
360
- })
361
- });
362
- /**
363
- * Determines whether a value is _anything_ except an empty `string` or `NaN`.
364
- *
365
- * @group Export
366
- */
367
- const isValidValue = (value) => typeof value === "string" && value.length > 0 || typeof value === "number" && !Number.isNaN(value) || typeof value !== "string" && typeof value !== "number";
368
- /**
369
- * Determines whether {@link formatQuery} should render the given value as a number.
370
- * As long as `parseNumbers` is `true`, `number` and `bigint` values will return `true` and
371
- * `string` values will return `true` if they test positive against {@link numericRegex}.
372
- *
373
- * @group Export
374
- */
375
- const shouldRenderAsNumber = (value, parseNumbers) => !!parseNumbers && (typeof value === "number" || typeof value === "bigint" || typeof value === "string" && numericRegex$1.test(value));
376
- /**
377
- * Used by {@link formatQuery} to determine whether the given value processor is a
378
- * "legacy" value processor by counting the number of arguments. Legacy value
379
- * processors take 3 arguments (not counting any arguments with default values), while
380
- * rule-based value processors take no more than 2 arguments.
381
- *
382
- * @group Export
383
- */
384
- const isValueProcessorLegacy = (valueProcessor) => valueProcessor.length >= 3;
385
- /**
386
- * Converts the `quoteFieldNamesWith` option into an array of two strings.
387
- * If the option is a string, the array elements are both that string.
388
- *
389
- * @default
390
- * ['', '']
391
- *
392
- * @group Export
393
- */
394
- const getQuoteFieldNamesWithArray = (quoteFieldNamesWith = ["", ""]) => Array.isArray(quoteFieldNamesWith) ? quoteFieldNamesWith : typeof quoteFieldNamesWith === "string" ? [quoteFieldNamesWith, quoteFieldNamesWith] : quoteFieldNamesWith ?? ["", ""];
395
- /**
396
- * Given a field name and relevant {@link ValueProcessorOptions}, returns the field name
397
- * wrapped in the configured quote character(s).
398
- *
399
- * @group Export
400
- */
401
- const getQuotedFieldName = (fieldName, { quoteFieldNamesWith, fieldIdentifierSeparator }) => {
402
- const [qPre, qPost] = getQuoteFieldNamesWithArray(quoteFieldNamesWith);
403
- return typeof fieldIdentifierSeparator === "string" && fieldIdentifierSeparator.length > 0 ? joinWith(splitBy(fieldName, fieldIdentifierSeparator).map((part) => `${qPre}${part}${qPost}`), fieldIdentifierSeparator) : `${qPre}${fieldName}${qPost}`;
404
- };
405
- const defaultWordOrder = [
406
- "S",
407
- "V",
408
- "O"
409
- ];
410
- /**
411
- * Given a [Constituent word order](https://en.wikipedia.org/wiki/Word_order#Constituent_word_orders)
412
- * like "svo" or "sov", returns a permutation of `["S", "V", "O"]` based on the first occurrence of
413
- * each letter in the input string (case insensitive). This widens the valid input from abbreviations
414
- * like "svo" to more expressive strings like "subject-verb-object" or "sub ver obj". Any missing
415
- * letters are appended in the default order "SVO" (e.g., "object" would yield `["O", "S", "V"]`).
416
- *
417
- * @group Export
418
- */
419
- const normalizeConstituentWordOrder = (input) => {
420
- const result = [];
421
- const letterSet = new Set(defaultWordOrder);
422
- for (const char of input.toUpperCase()) if (letterSet.has(char)) {
423
- result.push(char);
424
- letterSet.delete(char);
425
- if (letterSet.size === 0) break;
426
- }
427
- for (const letter of defaultWordOrder) if (letterSet.has(letter)) result.push(letter);
428
- return result;
429
- };
430
- /**
431
- * Prefixes a named-parameter value with the given `paramPrefix` unless the value already
432
- * begins with it. Used by {@link formatQuery} to render rules whose `valueSource` is
433
- * `"parameter"` (e.g. `"p1"` with prefix `":"` → `":p1"`; `":p1"` → `":p1"`).
434
- *
435
- * @group Export
436
- */
437
- const withParamPrefix = (value, paramPrefix = ":") => {
438
- const v = `${value ?? ""}`;
439
- return paramPrefix && v.startsWith(paramPrefix) ? v : `${paramPrefix}${v}`;
440
- };
441
- /**
442
- * Strips a leading `paramPrefix` from a named-parameter value if present. Inverse of
443
- * {@link withParamPrefix}; used to normalize parameter names for validation/lookup.
444
- *
445
- * @group Export
446
- */
447
- const stripParamPrefix = (value, paramPrefix = ":") => {
448
- const v = `${value ?? ""}`;
449
- return paramPrefix && v.startsWith(paramPrefix) ? v.slice(paramPrefix.length) : v;
450
- };
451
- /**
452
- * Default translations used by {@link formatQuery} for "natural_language" format.
453
- *
454
- * @group Export
455
- */
456
- const defaultNLTranslations = {
457
- groupPrefix: "",
458
- groupPrefix_not_xor: "either zero or more than one of",
459
- groupPrefix_xor: "exactly one of",
460
- groupSuffix: "is true",
461
- groupSuffix_not: "is not true"
462
- };
463
- /**
464
- * Note: This function assumes `conditions.length > 0`
465
- */
466
- const translationMatchFilter = (key, keyToTest, conditions) => keyToTest.startsWith(key) && conditions.every((c) => keyToTest.includes(`_${c}`) && keyToTest.match(/_/g)?.length === conditions.length);
467
- /**
468
- * Used by {@link formatQuery} to get a translation based on certain conditions
469
- * for the "natural_language" format.
470
- *
471
- * @group Export
472
- */
473
- const getNLTranslataion = (key, translations, conditions = []) => conditions.length === 0 ? translations[key] ?? defaultNLTranslations[key] ??
474
- /* v8 ignore start -- @preserve */ "" : Object.entries(translations).find(([keyToTest]) => translationMatchFilter(key, keyToTest, conditions))?.[1] ?? Object.entries(defaultNLTranslations).find(([keyToTest]) => translationMatchFilter(key, keyToTest, conditions))?.[1] ?? defaultNLTranslations[key] ??
475
- /* v8 ignore next -- @preserve */ "";
476
- /**
477
- * Transforms
478
- * - `match: { mode: "atLeast", threshold: 1 }` to `match: { mode: "some" }`
479
- * - `match: { mode: "atMost", threshold: 0 }` to `match: { mode: "none" }`.
480
- *
481
- * Returns:
482
- * - Processed `{ mode, threshold }` object for valid subqueries
483
- * - `null` if match mode is not applicable for the rule
484
- * - `false` if match mode is valid, but either
485
- * 1. `threshold` is required and invalid, or
486
- * 2. `value` is not a valid rule group.
487
- */
488
- const processMatchMode = (rule) => {
489
- const { mode, threshold } = rule.match ?? {};
490
- if (!mode) return null;
491
- if (!isRuleGroup(rule.value)) return false;
492
- const matchModeLC = lc(mode);
493
- const matchModeCoerced = matchModeLC === "atleast" && threshold === 1 ? "some" : matchModeLC === "atmost" && threshold === 0 ? "none" : matchModeLC;
494
- if ((matchModeCoerced === "atleast" || matchModeCoerced === "atmost" || matchModeCoerced === "exactly") && (typeof threshold !== "number" || threshold < 0)) return false;
495
- return {
496
- mode: matchModeCoerced,
497
- threshold
498
- };
499
- };
500
- /**
501
- * Base alias assigned to the element binding of a subquery generated for a rule's
502
- * {@link MatchMode `match` mode} (e.g. `unnest(field) as elem_alias`).
503
- */
504
- const subqueryElementAliasBase = "elem_alias";
505
- /**
506
- * Returns the element alias for a subquery at the given nesting depth. Depth 0 (the common,
507
- * non-nested case) uses {@link subqueryElementAliasBase} unchanged; deeper levels are suffixed
508
- * with the depth, so a subquery nested within a subquery cannot shadow its parent's binding.
509
- *
510
- * Deterministic by depth rather than randomized, so output remains stable and snapshot-friendly.
511
- *
512
- * @group Export
513
- */
514
- const getSubqueryElementAlias = (subqueryDepth = 0) => subqueryDepth > 0 ? `${subqueryElementAliasBase}_${subqueryDepth}` : subqueryElementAliasBase;
515
- /**
516
- * "Replacer" method for JSON.stringify's second argument. Converts `bigint` values to
517
- * objects with a `$bigint` property having a value of a string representation of
518
- * the actual `bigint`-type value.
519
- *
520
- * Inverse of {@link bigIntJsonParseReviver}.
521
- *
522
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
523
- */
524
- const bigIntJsonStringifyReplacer = (_key, value) => typeof value === "bigint" ? { $bigint: value.toString() } : value;
525
- /**
526
- * "Reviver" method for JSON.parse's second argument. Converts objects having a single
527
- * `$bigint: string` property to an actual `bigint` value.
528
- *
529
- * Inverse of {@link bigIntJsonStringifyReplacer}.
530
- *
531
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
532
- */
533
- const bigIntJsonParseReviver = (_key, value) => isPojo(value) && Object.keys(value).length === 1 && typeof value.$bigint === "string" ? BigInt(value.$bigint) : value;
534
- //#endregion
535
- export { toFullOption as A, withParamPrefix as C, isFlexibleOptionArray as D, getOption as E, trimIfString as F, defaultOperatorNegationMap as I, parseNumber as M, joinWith as N, isFlexibleOptionGroupArray as O, toArray as P, subqueryElementAliasBase as S, getParseNumberMethod as T, numerifyValues as _, getLikeWildcards as a, shouldRenderAsNumber as b, getQuotedFieldName as c, isValidValue as d, isValueProcessorLegacy as f, normalizeConstituentWordOrder as g, mongoOperators as h, defaultNLTranslations as i, toFullOptionList as j, toFlatOptionArray as k, getSQLConcat as l, mapSQLOperator as m, bigIntJsonStringifyReplacer as n, getNLTranslataion as o, jsonLogicAdditionalOperators as p, celCombinatorMap as r, getQuoteFieldNamesWithArray as s, bigIntJsonParseReviver as t, getSubqueryElementAlias as u, prismaOperators as v, wrapLikeFragment as w, stripParamPrefix as x, processMatchMode as y };
536
-
537
- //# sourceMappingURL=utils-4k-j5FBa.mjs.map