@react-querybuilder/core 8.11.0 → 8.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/basic-BeKPP0_1.d.ts +1257 -0
  2. package/dist/basic-CLG_Bmom.d.mts +1257 -0
  3. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +14 -2
  4. package/dist/cjs/react-querybuilder_core.cjs.development.js +23 -11
  5. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  6. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +14 -2
  7. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  8. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  9. package/dist/{convertQuery-DAqoID3O.js → convertQuery-C7NvB0XA.js} +1 -1
  10. package/dist/{convertQuery-DAqoID3O.js.map → convertQuery-C7NvB0XA.js.map} +1 -1
  11. package/dist/{convertQuery-CqX3rPvj.mjs → convertQuery-Cj4t-LT4.mjs} +2 -2
  12. package/dist/{convertQuery-CqX3rPvj.mjs.map → convertQuery-Cj4t-LT4.mjs.map} +1 -1
  13. package/dist/{export-Dy4FckB-.d.ts → export-B2Yw5gak.d.mts} +2 -3
  14. package/dist/{export-t1V2N8pz.d.mts → export-CQB0nuvW.d.ts} +2 -3
  15. package/dist/formatQuery.d.mts +15 -4
  16. package/dist/formatQuery.d.ts +15 -4
  17. package/dist/formatQuery.js +170 -423
  18. package/dist/formatQuery.js.map +1 -1
  19. package/dist/formatQuery.mjs +4 -257
  20. package/dist/formatQuery.mjs.map +1 -1
  21. package/dist/{import-Cz8canKo.d.mts → import-BtpySRSy.d.mts} +2 -2
  22. package/dist/{import-DtS9Ocx5.d.ts → import-Dvayhrgj.d.ts} +2 -2
  23. package/dist/{isRuleGroup-CYcfPgbg.mjs → isRuleGroup-BcfwGaIN.mjs} +1 -1
  24. package/dist/{isRuleGroup-CYcfPgbg.mjs.map → isRuleGroup-BcfwGaIN.mjs.map} +1 -1
  25. package/dist/parseCEL.d.mts +32 -8
  26. package/dist/parseCEL.d.ts +32 -8
  27. package/dist/parseCEL.js +175 -15
  28. package/dist/parseCEL.js.map +1 -1
  29. package/dist/parseCEL.mjs +163 -8
  30. package/dist/parseCEL.mjs.map +1 -1
  31. package/dist/parseJSONata.d.mts +2 -3
  32. package/dist/parseJSONata.d.ts +2 -3
  33. package/dist/parseJSONata.js +2 -2
  34. package/dist/parseJSONata.mjs +3 -3
  35. package/dist/parseJsonLogic.d.mts +4 -4
  36. package/dist/parseJsonLogic.d.ts +4 -4
  37. package/dist/parseJsonLogic.js +9 -10
  38. package/dist/parseJsonLogic.js.map +1 -1
  39. package/dist/parseJsonLogic.mjs +4 -5
  40. package/dist/parseJsonLogic.mjs.map +1 -1
  41. package/dist/parseMongoDB.d.mts +2 -3
  42. package/dist/parseMongoDB.d.ts +2 -3
  43. package/dist/parseMongoDB.js +19 -20
  44. package/dist/parseMongoDB.js.map +1 -1
  45. package/dist/parseMongoDB.mjs +4 -5
  46. package/dist/parseMongoDB.mjs.map +1 -1
  47. package/dist/parseSQL.d.mts +2 -3
  48. package/dist/parseSQL.d.ts +2 -3
  49. package/dist/parseSQL.js +15 -16
  50. package/dist/parseSQL.js.map +1 -1
  51. package/dist/parseSQL.mjs +3 -5
  52. package/dist/parseSQL.mjs.map +1 -1
  53. package/dist/parseSpEL.d.mts +2 -3
  54. package/dist/parseSpEL.d.ts +2 -3
  55. package/dist/parseSpEL.js +3 -4
  56. package/dist/parseSpEL.js.map +1 -1
  57. package/dist/parseSpEL.mjs +3 -4
  58. package/dist/parseSpEL.mjs.map +1 -1
  59. package/dist/{prepareQueryObjects-DPCC-iHp.mjs → prepareQueryObjects-BfnyRV5t.mjs} +4 -3
  60. package/dist/{prepareQueryObjects-DPCC-iHp.mjs.map → prepareQueryObjects-BfnyRV5t.mjs.map} +1 -1
  61. package/dist/{prepareQueryObjects-BOUWfel5.js → prepareQueryObjects-Cz_28zYz.js} +12 -11
  62. package/dist/prepareQueryObjects-Cz_28zYz.js.map +1 -0
  63. package/dist/react-querybuilder_core.d.mts +14 -2
  64. package/dist/react-querybuilder_core.legacy-esm.d.ts +14 -2
  65. package/dist/react-querybuilder_core.legacy-esm.js +23 -11
  66. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  67. package/dist/react-querybuilder_core.mjs +23 -11
  68. package/dist/react-querybuilder_core.mjs.map +1 -1
  69. package/dist/react-querybuilder_core.production.d.mts +14 -2
  70. package/dist/react-querybuilder_core.production.mjs +1 -1
  71. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  72. package/dist/{transformQuery-CWDPogO5.js → transformQuery-B4SaTTO-.js} +1 -1
  73. package/dist/{transformQuery-CWDPogO5.js.map → transformQuery-B4SaTTO-.js.map} +1 -1
  74. package/dist/{transformQuery-DCCpjtyq.mjs → transformQuery-C85j__7e.mjs} +2 -2
  75. package/dist/{transformQuery-DCCpjtyq.mjs.map → transformQuery-C85j__7e.mjs.map} +1 -1
  76. package/dist/transformQuery.d.mts +1 -1
  77. package/dist/transformQuery.d.ts +1 -1
  78. package/dist/transformQuery.js +1 -1
  79. package/dist/transformQuery.mjs +2 -2
  80. package/dist/utils-Dkz3Xn2D.js +707 -0
  81. package/dist/utils-Dkz3Xn2D.js.map +1 -0
  82. package/dist/utils-DxH23QtE.mjs +514 -0
  83. package/dist/utils-DxH23QtE.mjs.map +1 -0
  84. package/package.json +10 -8
  85. package/dist/arrayUtils-A_OXU9W1.mjs +0 -50
  86. package/dist/arrayUtils-A_OXU9W1.mjs.map +0 -1
  87. package/dist/arrayUtils-QxZOZTf6.js +0 -73
  88. package/dist/arrayUtils-QxZOZTf6.js.map +0 -1
  89. package/dist/basic-DEc65Kng.d.mts +0 -363
  90. package/dist/basic-Dd_M2f3M.d.ts +0 -363
  91. package/dist/lexer-C53tqS2p.js +0 -406
  92. package/dist/lexer-C53tqS2p.js.map +0 -1
  93. package/dist/optGroupUtils-B0hTpodo.js +0 -251
  94. package/dist/optGroupUtils-B0hTpodo.js.map +0 -1
  95. package/dist/optGroupUtils-VeZ3k7-1.mjs +0 -185
  96. package/dist/optGroupUtils-VeZ3k7-1.mjs.map +0 -1
  97. package/dist/parseNumber-CXdMVNFx.mjs +0 -24
  98. package/dist/parseNumber-CXdMVNFx.mjs.map +0 -1
  99. package/dist/parseNumber-D4iQDxK-.js +0 -31
  100. package/dist/parseNumber-D4iQDxK-.js.map +0 -1
  101. package/dist/prepareQueryObjects-BOUWfel5.js.map +0 -1
@@ -0,0 +1,707 @@
1
+ const require_isRuleGroup = require('./isRuleGroup-DqAs2x4E.js');
2
+ let numeric_quantity = require("numeric-quantity");
3
+ numeric_quantity = require_isRuleGroup.__toESM(numeric_quantity);
4
+ let immer = require("immer");
5
+ immer = require_isRuleGroup.__toESM(immer);
6
+
7
+ //#region src/defaults.ts
8
+ /**
9
+ * @group Defaults
10
+ */
11
+ const defaultPlaceholderName = "~";
12
+ /**
13
+ * Default `name` for placeholder option in the `fields` array.
14
+ *
15
+ * @group Defaults
16
+ */
17
+ const defaultPlaceholderFieldName = defaultPlaceholderName;
18
+ /**
19
+ * Default `name` for placeholder option in the `operators` array.
20
+ *
21
+ * @group Defaults
22
+ */
23
+ const defaultPlaceholderOperatorName = defaultPlaceholderName;
24
+ /**
25
+ * Default character used to `.join` and `.split` arrays.
26
+ *
27
+ * @group Defaults
28
+ */
29
+ const defaultJoinChar = ",";
30
+ /**
31
+ * Map of default operators to their respective opposite/negating operators.
32
+ *
33
+ * @group Defaults
34
+ */
35
+ const defaultOperatorNegationMap = {
36
+ "=": "!=",
37
+ "!=": "=",
38
+ "<": ">=",
39
+ "<=": ">",
40
+ ">": "<=",
41
+ ">=": "<",
42
+ beginsWith: "doesNotBeginWith",
43
+ doesNotBeginWith: "beginsWith",
44
+ endsWith: "doesNotEndWith",
45
+ doesNotEndWith: "endsWith",
46
+ contains: "doesNotContain",
47
+ doesNotContain: "contains",
48
+ between: "notBetween",
49
+ notBetween: "between",
50
+ in: "notIn",
51
+ notIn: "in",
52
+ notNull: "null",
53
+ null: "notNull"
54
+ };
55
+ /**
56
+ * Default combinator list.
57
+ *
58
+ * @group Defaults
59
+ */
60
+ const defaultCombinators = [{
61
+ name: "and",
62
+ value: "and",
63
+ label: "AND"
64
+ }, {
65
+ name: "or",
66
+ value: "or",
67
+ label: "OR"
68
+ }];
69
+ /**
70
+ * Default combinator list, with `XOR` added.
71
+ *
72
+ * @group Defaults
73
+ */
74
+ const defaultCombinatorsExtended = [...defaultCombinators, {
75
+ name: "xor",
76
+ value: "xor",
77
+ label: "XOR"
78
+ }];
79
+
80
+ //#endregion
81
+ //#region src/utils/arrayUtils.ts
82
+ /**
83
+ * Splits a string by a given character (see {@link defaultJoinChar}). Escaped characters
84
+ * (characters preceded by a backslash) will not apply to the split, and the backslash will
85
+ * be removed in the array element. Inverse of {@link joinWith}.
86
+ *
87
+ * @example
88
+ * splitBy('this\\,\\,that,,the other,,,\\,')
89
+ * // or
90
+ * splitBy('this\\,\\,that,,the other,,,\\,', ',')
91
+ * // would return
92
+ * ['this,,that', '', 'the other', '', '', ',']
93
+ */
94
+ const splitBy = (str, splitChar = defaultJoinChar) => typeof str === "string" ? str.split(`\\${splitChar}`).map((c) => c.split(splitChar)).reduce((prev, curr, idx) => {
95
+ if (idx === 0) return curr;
96
+ return [
97
+ ...prev.slice(0, -1),
98
+ `${prev.at(-1)}${splitChar}${curr[0]}`,
99
+ ...curr.slice(1)
100
+ ];
101
+ }, []) : [];
102
+ /**
103
+ * Joins an array of strings using the given character (see {@link defaultJoinChar}). When
104
+ * the given character appears in an array element, a backslash will be added just before it
105
+ * to distinguish it from the join character. Effectively the inverse of {@link splitBy}.
106
+ *
107
+ * TIP: The join character can actually be a string of any length. Only the first character
108
+ * will be searched for in the array elements and preceded by a backslash.
109
+ *
110
+ * @example
111
+ * joinWith(['this,,that', '', 'the other', '', '', ','], ', ')
112
+ * // would return
113
+ * 'this\\,\\,that, , the other, , , \\,'
114
+ */
115
+ const joinWith = (strArr, joinChar = defaultJoinChar) => strArr.map((str) => `${str ?? ""}`.replaceAll(joinChar[0], `\\${joinChar[0]}`)).join(joinChar);
116
+ /**
117
+ * Trims the value if it is a string. Otherwise returns the value as is.
118
+ */
119
+ const trimIfString = (val) => typeof val === "string" ? val.trim() : val;
120
+ /**
121
+ * Splits a string by comma then trims each element. Arrays are returned as is except
122
+ * any string elements are trimmed.
123
+ */
124
+ const toArray = (v, { retainEmptyStrings } = {}) => Array.isArray(v) ? v.map((v$1) => trimIfString(v$1)) : typeof v === "string" ? splitBy(v, defaultJoinChar).filter(retainEmptyStrings ? () => true : (s) => !/^\s*$/.test(s)).map((s) => s.trim()) : typeof v === "number" ? [v] : [];
125
+
126
+ //#endregion
127
+ //#region src/utils/parseNumber.ts
128
+ /**
129
+ * Converts a string to a number. Uses native `parseFloat` if `parseNumbers` is "native",
130
+ * otherwise uses [`numeric-quantity`](https://jakeboone02.github.io/numeric-quantity/).
131
+ * If that returns `NaN`, the string is returned unchanged. Numeric values are returned
132
+ * as-is regardless of the `parseNumbers` option.
133
+ */
134
+ const parseNumber = (val, { parseNumbers, bigIntOnOverflow } = {}) => {
135
+ if (!parseNumbers || typeof val === "bigint" || typeof val === "number") return val;
136
+ if (parseNumbers === "native") return Number.parseFloat(val);
137
+ const valAsNum = (0, numeric_quantity.numericQuantity)(val, {
138
+ allowTrailingInvalid: parseNumbers === "enhanced",
139
+ bigIntOnOverflow,
140
+ romanNumerals: false,
141
+ round: false
142
+ });
143
+ return typeof valAsNum === "bigint" || !Number.isNaN(valAsNum) ? valAsNum : val;
144
+ };
145
+
146
+ //#endregion
147
+ //#region src/utils/objectUtils.ts
148
+ /**
149
+ * A strongly-typed version of `Object.keys()`.
150
+ *
151
+ * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-keys.ts)
152
+ */
153
+ const objectKeys = Object.keys;
154
+
155
+ //#endregion
156
+ //#region src/utils/optGroupUtils.ts
157
+ const isOptionWithName = (opt) => require_isRuleGroup.isPojo(opt) && "name" in opt && typeof opt.name === "string";
158
+ const isOptionWithValue = (opt) => require_isRuleGroup.isPojo(opt) && "value" in opt && typeof opt.value === "string";
159
+ /**
160
+ * Converts an {@link Option} or {@link ValueOption} (i.e., {@link BaseOption})
161
+ * into a {@link FullOption}. Full options are left unchanged.
162
+ *
163
+ * @group Option Lists
164
+ */
165
+ function toFullOption(opt, baseProperties, labelMap) {
166
+ return (0, immer.produce)((draft) => {
167
+ const idObj = {};
168
+ let needsUpdating = !!baseProperties;
169
+ if (typeof draft === "string") return {
170
+ ...baseProperties,
171
+ name: draft,
172
+ value: draft,
173
+ label: labelMap?.[draft] ?? draft
174
+ };
175
+ if (isOptionWithName(draft) && !isOptionWithValue(draft)) {
176
+ idObj.value = draft.name;
177
+ needsUpdating = true;
178
+ } else if (!isOptionWithName(draft) && isOptionWithValue(draft)) {
179
+ idObj.name = draft.value;
180
+ needsUpdating = true;
181
+ }
182
+ if (needsUpdating) return Object.assign({}, baseProperties, draft, idObj);
183
+ })(opt);
184
+ }
185
+ /**
186
+ * Converts an {@link OptionList} or {@link FlexibleOptionList} into a {@link FullOptionList}.
187
+ * Lists of full options are left unchanged.
188
+ *
189
+ * @group Option Lists
190
+ */
191
+ function toFullOptionList(optList, baseProperties, labelMap) {
192
+ if (!Array.isArray(optList)) return [];
193
+ return (0, immer.produce)((draft) => {
194
+ if (isFlexibleOptionGroupArray(draft)) for (const optGroup of draft) for (const [idx, opt] of optGroup.options.entries()) optGroup.options[idx] = toFullOption(opt, baseProperties, labelMap);
195
+ else for (const [idx, opt] of draft.entries()) draft[idx] = toFullOption(opt, baseProperties, labelMap);
196
+ })(optList);
197
+ }
198
+ /**
199
+ * Generates a new array of objects with duplicates removed based
200
+ * on the identifying property (`value` or `name`)
201
+ *
202
+ * @group Option Lists
203
+ */
204
+ const uniqByIdentifier = (originalArray) => {
205
+ const names = /* @__PURE__ */ new Set();
206
+ const newArray = [];
207
+ for (const el of originalArray) if (!names.has(el.value ?? el.name)) {
208
+ names.add(el.value ?? el.name);
209
+ newArray.push(el);
210
+ }
211
+ return originalArray.length === newArray.length ? originalArray : newArray;
212
+ };
213
+ /**
214
+ * Determines if an {@link OptionList} is an {@link OptionGroup} array.
215
+ *
216
+ * @group Option Lists
217
+ */
218
+ const isOptionGroupArray = (arr) => Array.isArray(arr) && arr.length > 0 && require_isRuleGroup.isPojo(arr[0]) && "options" in arr[0] && Array.isArray(arr[0].options);
219
+ /**
220
+ * Determines if an array is a flat array of {@link FlexibleOption}.
221
+ *
222
+ * @group Option Lists
223
+ */
224
+ const isFlexibleOptionArray = (arr) => {
225
+ let isFOA = false;
226
+ if (Array.isArray(arr)) for (const o of arr) if (isOptionWithName(o) || isOptionWithValue(o)) isFOA = true;
227
+ else return false;
228
+ return isFOA;
229
+ };
230
+ /**
231
+ * Determines if a {@link FlexibleOptionList} is a {@link FlexibleOptionGroup} array.
232
+ *
233
+ * @group Option Lists
234
+ */
235
+ const isFlexibleOptionGroupArray = (arr, { allowEmpty = false } = {}) => {
236
+ let isFOGA = false;
237
+ if (Array.isArray(arr)) for (const og of arr) if (require_isRuleGroup.isPojo(og) && "options" in og && (isFlexibleOptionArray(og.options) || allowEmpty && Array.isArray(og.options) && og.options.length === 0)) isFOGA = true;
238
+ else return false;
239
+ return isFOGA;
240
+ };
241
+ function getOption(arr, name) {
242
+ return (isFlexibleOptionGroupArray(arr, { allowEmpty: true }) ? arr.flatMap((og) => og.options) : arr).find((op) => op.value === name || op.name === name);
243
+ }
244
+ /**
245
+ * Flattens {@link FlexibleOptionGroup} arrays into {@link BaseOption} arrays.
246
+ * If the array is already flat, it is returned as is.
247
+ *
248
+ * @group Option Lists
249
+ */
250
+ const toFlatOptionArray = (arr) => uniqByIdentifier(isOptionGroupArray(arr) ? arr.flatMap((og) => og.options) : arr);
251
+
252
+ //#endregion
253
+ //#region src/utils/getParseNumberMethod.ts
254
+ const getParseNumberMethod = ({ parseNumbers, inputType }) => {
255
+ if (typeof parseNumbers === "string") {
256
+ const [method, level] = parseNumbers.split("-");
257
+ if (level === "limited") return inputType === "number" ? method : false;
258
+ return method;
259
+ }
260
+ return parseNumbers ? "strict" : false;
261
+ };
262
+
263
+ //#endregion
264
+ //#region src/utils/formatQuery/utils.ts
265
+ /**
266
+ * Maps a {@link DefaultOperatorName} to a SQL operator.
267
+ *
268
+ * @group Export
269
+ */
270
+ const mapSQLOperator = (rqbOperator) => {
271
+ switch (require_isRuleGroup.lc(rqbOperator)) {
272
+ case "null": return "is null";
273
+ case "notnull": return "is not null";
274
+ case "notin": return "not in";
275
+ case "notbetween": return "not between";
276
+ case "contains":
277
+ case "beginswith":
278
+ case "endswith": return "like";
279
+ case "doesnotcontain":
280
+ case "doesnotbeginwith":
281
+ case "doesnotendwith": return "not like";
282
+ default: return rqbOperator;
283
+ }
284
+ };
285
+ /**
286
+ * Maps a (lowercase) {@link DefaultOperatorName} to a MongoDB operator.
287
+ *
288
+ * @group Export
289
+ */
290
+ const mongoOperators = {
291
+ "=": "$eq",
292
+ "!=": "$ne",
293
+ "<": "$lt",
294
+ "<=": "$lte",
295
+ ">": "$gt",
296
+ ">=": "$gte",
297
+ in: "$in",
298
+ notin: "$nin",
299
+ notIn: "$nin"
300
+ };
301
+ /**
302
+ * Maps a (lowercase) {@link DefaultOperatorName} to a Prisma ORM operator.
303
+ *
304
+ * @group Export
305
+ */
306
+ const prismaOperators = {
307
+ "=": "equals",
308
+ "!=": "not",
309
+ "<": "lt",
310
+ "<=": "lte",
311
+ ">": "gt",
312
+ ">=": "gte",
313
+ in: "in",
314
+ notin: "notIn"
315
+ };
316
+ /**
317
+ * Maps a {@link DefaultCombinatorName} to a CEL combinator.
318
+ *
319
+ * @group Export
320
+ */
321
+ const celCombinatorMap = {
322
+ and: "&&",
323
+ or: "||"
324
+ };
325
+ /**
326
+ * Register these operators with `jsonLogic` before applying the result
327
+ * of `formatQuery(query, 'jsonlogic')`.
328
+ *
329
+ * @example
330
+ * ```
331
+ * for (const [op, func] of Object.entries(jsonLogicAdditionalOperators)) {
332
+ * jsonLogic.add_operation(op, func);
333
+ * }
334
+ * jsonLogic.apply({ "startsWith": [{ "var": "firstName" }, "Stev"] }, data);
335
+ * ```
336
+ *
337
+ * @group Export
338
+ */
339
+ const jsonLogicAdditionalOperators = {
340
+ startsWith: (a, b) => typeof a === "string" && a.startsWith(b),
341
+ endsWith: (a, b) => typeof a === "string" && a.endsWith(b)
342
+ };
343
+ /**
344
+ * Converts all `string`-type `value` properties of a query object into `number` where appropriate.
345
+ *
346
+ * Used by {@link formatQuery} for the `json*` formats when `parseNumbers` is `true`.
347
+ *
348
+ * @group Export
349
+ */
350
+ const numerifyValues = (rg, options) => ({
351
+ ...rg,
352
+ rules: rg.rules.map((r) => {
353
+ if (typeof r === "string") return r;
354
+ if (require_isRuleGroup.isRuleGroup(r)) return numerifyValues(r, options);
355
+ const fieldData = getOption(options.fields, r.field);
356
+ const parseNumbers = getParseNumberMethod({
357
+ parseNumbers: options.parseNumbers,
358
+ inputType: fieldData?.inputType
359
+ });
360
+ if (Array.isArray(r.value)) return {
361
+ ...r,
362
+ value: r.value.map((v) => parseNumber(v, { parseNumbers }))
363
+ };
364
+ const valAsArray = toArray(r.value, { retainEmptyStrings: true }).map((v) => parseNumber(v, { parseNumbers }));
365
+ if (valAsArray.every((v) => typeof v === "number")) {
366
+ // istanbul ignore else
367
+ if (valAsArray.length > 1) return {
368
+ ...r,
369
+ value: valAsArray
370
+ };
371
+ else if (valAsArray.length === 1) return {
372
+ ...r,
373
+ value: valAsArray[0]
374
+ };
375
+ }
376
+ return r;
377
+ })
378
+ });
379
+ /**
380
+ * Determines whether a value is _anything_ except an empty `string` or `NaN`.
381
+ *
382
+ * @group Export
383
+ */
384
+ const isValidValue = (value) => typeof value === "string" && value.length > 0 || typeof value === "number" && !Number.isNaN(value) || typeof value !== "string" && typeof value !== "number";
385
+ /**
386
+ * Determines whether {@link formatQuery} should render the given value as a number.
387
+ * As long as `parseNumbers` is `true`, `number` and `bigint` values will return `true` and
388
+ * `string` values will return `true` if they test positive against {@link numericRegex}.
389
+ *
390
+ * @group Export
391
+ */
392
+ const shouldRenderAsNumber = (value, parseNumbers) => !!parseNumbers && (typeof value === "number" || typeof value === "bigint" || typeof value === "string" && require_isRuleGroup.numericRegex.test(value));
393
+ /**
394
+ * Used by {@link formatQuery} to determine whether the given value processor is a
395
+ * "legacy" value processor by counting the number of arguments. Legacy value
396
+ * processors take 3 arguments (not counting any arguments with default values), while
397
+ * rule-based value processors take no more than 2 arguments.
398
+ *
399
+ * @group Export
400
+ */
401
+ const isValueProcessorLegacy = (valueProcessor) => valueProcessor.length >= 3;
402
+ /**
403
+ * Converts the `quoteFieldNamesWith` option into an array of two strings.
404
+ * If the option is a string, the array elements are both that string.
405
+ *
406
+ * @default
407
+ * ['', '']
408
+ *
409
+ * @group Export
410
+ */
411
+ const getQuoteFieldNamesWithArray = (quoteFieldNamesWith = ["", ""]) => Array.isArray(quoteFieldNamesWith) ? quoteFieldNamesWith : typeof quoteFieldNamesWith === "string" ? [quoteFieldNamesWith, quoteFieldNamesWith] : quoteFieldNamesWith ?? ["", ""];
412
+ /**
413
+ * Given a field name and relevant {@link ValueProcessorOptions}, returns the field name
414
+ * wrapped in the configured quote character(s).
415
+ *
416
+ * @group Export
417
+ */
418
+ const getQuotedFieldName = (fieldName, { quoteFieldNamesWith, fieldIdentifierSeparator }) => {
419
+ const [qPre, qPost] = getQuoteFieldNamesWithArray(quoteFieldNamesWith);
420
+ return typeof fieldIdentifierSeparator === "string" && fieldIdentifierSeparator.length > 0 ? joinWith(splitBy(fieldName, fieldIdentifierSeparator).map((part) => `${qPre}${part}${qPost}`), fieldIdentifierSeparator) : `${qPre}${fieldName}${qPost}`;
421
+ };
422
+ const defaultWordOrder = [
423
+ "S",
424
+ "V",
425
+ "O"
426
+ ];
427
+ /**
428
+ * Given a [Constituent word order](https://en.wikipedia.org/wiki/Word_order#Constituent_word_orders)
429
+ * like "svo" or "sov", returns a permutation of `["S", "V", "O"]` based on the first occurrence of
430
+ * each letter in the input string (case insensitive). This widens the valid input from abbreviations
431
+ * like "svo" to more expressive strings like "subject-verb-object" or "sub ver obj". Any missing
432
+ * letters are appended in the default order "SVO" (e.g., "object" would yield `["O", "S", "V"]`).
433
+ *
434
+ * @group Export
435
+ */
436
+ const normalizeConstituentWordOrder = (input) => {
437
+ const result = [];
438
+ const letterSet = new Set(defaultWordOrder);
439
+ for (const char of input.toUpperCase()) if (letterSet.has(char)) {
440
+ result.push(char);
441
+ letterSet.delete(char);
442
+ if (letterSet.size === 0) break;
443
+ }
444
+ for (const letter of defaultWordOrder) if (letterSet.has(letter)) result.push(letter);
445
+ return result;
446
+ };
447
+ /**
448
+ * Default translations used by {@link formatQuery} for "natural_language" format.
449
+ *
450
+ * @group Export
451
+ */
452
+ const defaultNLTranslations = {
453
+ groupPrefix: "",
454
+ groupPrefix_not_xor: "either zero or more than one of",
455
+ groupPrefix_xor: "exactly one of",
456
+ groupSuffix: "is true",
457
+ groupSuffix_not: "is not true"
458
+ };
459
+ /**
460
+ * Note: This function assumes `conditions.length > 0`
461
+ */
462
+ const translationMatchFilter = (key, keyToTest, conditions) => keyToTest.startsWith(key) && conditions.every((c) => keyToTest.includes(`_${c}`) && keyToTest.match(/_/g)?.length === conditions.length);
463
+ /**
464
+ * Used by {@link formatQuery} to get a translation based on certain conditions
465
+ * for the "natural_language" format.
466
+ *
467
+ * @group Export
468
+ */
469
+ 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] ?? "";
470
+ /**
471
+ * Transforms
472
+ * - `match: { mode: "atLeast", threshold: 1 }` to `match: { mode: "some" }`
473
+ * - `match: { mode: "atMost", threshold: 0 }` to `match: { mode: "none" }`.
474
+ *
475
+ * Returns:
476
+ * - Processed `{ mode, threshold }` object for valid subqueries
477
+ * - `null` if match mode is not applicable for the rule
478
+ * - `false` if match mode is valid, but either
479
+ * 1. `threshold` is required and invalid, or
480
+ * 2. `value` is not a valid rule group.
481
+ */
482
+ const processMatchMode = (rule) => {
483
+ const { mode, threshold } = rule.match ?? {};
484
+ if (!mode) return null;
485
+ if (!require_isRuleGroup.isRuleGroup(rule.value)) return false;
486
+ const matchModeLC = require_isRuleGroup.lc(mode);
487
+ const matchModeCoerced = matchModeLC === "atleast" && threshold === 1 ? "some" : matchModeLC === "atmost" && threshold === 0 ? "none" : matchModeLC;
488
+ if ((matchModeCoerced === "atleast" || matchModeCoerced === "atmost" || matchModeCoerced === "exactly") && (typeof threshold !== "number" || threshold < 0)) return false;
489
+ return {
490
+ mode: matchModeCoerced,
491
+ threshold
492
+ };
493
+ };
494
+ /**
495
+ * "Replacer" method for JSON.stringify's second argument. Converts `bigint` values to
496
+ * objects with a `$bigint` property having a value of a string representation of
497
+ * the actual `bigint`-type value.
498
+ *
499
+ * Inverse of {@link bigIntJsonParseReviver}.
500
+ *
501
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
502
+ */
503
+ const bigIntJsonStringifyReplacer = (_key, value) => typeof value === "bigint" ? { $bigint: value.toString() } : value;
504
+ /**
505
+ * "Reviver" method for JSON.parse's second argument. Converts objects having a single
506
+ * `$bigint: string` property to an actual `bigint` value.
507
+ *
508
+ * Inverse of {@link bigIntJsonStringifyReplacer}.
509
+ *
510
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
511
+ */
512
+ const bigIntJsonParseReviver = (_key, value) => require_isRuleGroup.isPojo(value) && Object.keys(value).length === 1 && typeof value.$bigint === "string" ? BigInt(value.$bigint) : value;
513
+
514
+ //#endregion
515
+ Object.defineProperty(exports, 'bigIntJsonParseReviver', {
516
+ enumerable: true,
517
+ get: function () {
518
+ return bigIntJsonParseReviver;
519
+ }
520
+ });
521
+ Object.defineProperty(exports, 'bigIntJsonStringifyReplacer', {
522
+ enumerable: true,
523
+ get: function () {
524
+ return bigIntJsonStringifyReplacer;
525
+ }
526
+ });
527
+ Object.defineProperty(exports, 'celCombinatorMap', {
528
+ enumerable: true,
529
+ get: function () {
530
+ return celCombinatorMap;
531
+ }
532
+ });
533
+ Object.defineProperty(exports, 'defaultNLTranslations', {
534
+ enumerable: true,
535
+ get: function () {
536
+ return defaultNLTranslations;
537
+ }
538
+ });
539
+ Object.defineProperty(exports, 'defaultOperatorNegationMap', {
540
+ enumerable: true,
541
+ get: function () {
542
+ return defaultOperatorNegationMap;
543
+ }
544
+ });
545
+ Object.defineProperty(exports, 'defaultPlaceholderFieldName', {
546
+ enumerable: true,
547
+ get: function () {
548
+ return defaultPlaceholderFieldName;
549
+ }
550
+ });
551
+ Object.defineProperty(exports, 'defaultPlaceholderOperatorName', {
552
+ enumerable: true,
553
+ get: function () {
554
+ return defaultPlaceholderOperatorName;
555
+ }
556
+ });
557
+ Object.defineProperty(exports, 'getNLTranslataion', {
558
+ enumerable: true,
559
+ get: function () {
560
+ return getNLTranslataion;
561
+ }
562
+ });
563
+ Object.defineProperty(exports, 'getOption', {
564
+ enumerable: true,
565
+ get: function () {
566
+ return getOption;
567
+ }
568
+ });
569
+ Object.defineProperty(exports, 'getParseNumberMethod', {
570
+ enumerable: true,
571
+ get: function () {
572
+ return getParseNumberMethod;
573
+ }
574
+ });
575
+ Object.defineProperty(exports, 'getQuoteFieldNamesWithArray', {
576
+ enumerable: true,
577
+ get: function () {
578
+ return getQuoteFieldNamesWithArray;
579
+ }
580
+ });
581
+ Object.defineProperty(exports, 'getQuotedFieldName', {
582
+ enumerable: true,
583
+ get: function () {
584
+ return getQuotedFieldName;
585
+ }
586
+ });
587
+ Object.defineProperty(exports, 'isFlexibleOptionArray', {
588
+ enumerable: true,
589
+ get: function () {
590
+ return isFlexibleOptionArray;
591
+ }
592
+ });
593
+ Object.defineProperty(exports, 'isFlexibleOptionGroupArray', {
594
+ enumerable: true,
595
+ get: function () {
596
+ return isFlexibleOptionGroupArray;
597
+ }
598
+ });
599
+ Object.defineProperty(exports, 'isValidValue', {
600
+ enumerable: true,
601
+ get: function () {
602
+ return isValidValue;
603
+ }
604
+ });
605
+ Object.defineProperty(exports, 'isValueProcessorLegacy', {
606
+ enumerable: true,
607
+ get: function () {
608
+ return isValueProcessorLegacy;
609
+ }
610
+ });
611
+ Object.defineProperty(exports, 'joinWith', {
612
+ enumerable: true,
613
+ get: function () {
614
+ return joinWith;
615
+ }
616
+ });
617
+ Object.defineProperty(exports, 'jsonLogicAdditionalOperators', {
618
+ enumerable: true,
619
+ get: function () {
620
+ return jsonLogicAdditionalOperators;
621
+ }
622
+ });
623
+ Object.defineProperty(exports, 'mapSQLOperator', {
624
+ enumerable: true,
625
+ get: function () {
626
+ return mapSQLOperator;
627
+ }
628
+ });
629
+ Object.defineProperty(exports, 'mongoOperators', {
630
+ enumerable: true,
631
+ get: function () {
632
+ return mongoOperators;
633
+ }
634
+ });
635
+ Object.defineProperty(exports, 'normalizeConstituentWordOrder', {
636
+ enumerable: true,
637
+ get: function () {
638
+ return normalizeConstituentWordOrder;
639
+ }
640
+ });
641
+ Object.defineProperty(exports, 'numerifyValues', {
642
+ enumerable: true,
643
+ get: function () {
644
+ return numerifyValues;
645
+ }
646
+ });
647
+ Object.defineProperty(exports, 'objectKeys', {
648
+ enumerable: true,
649
+ get: function () {
650
+ return objectKeys;
651
+ }
652
+ });
653
+ Object.defineProperty(exports, 'parseNumber', {
654
+ enumerable: true,
655
+ get: function () {
656
+ return parseNumber;
657
+ }
658
+ });
659
+ Object.defineProperty(exports, 'prismaOperators', {
660
+ enumerable: true,
661
+ get: function () {
662
+ return prismaOperators;
663
+ }
664
+ });
665
+ Object.defineProperty(exports, 'processMatchMode', {
666
+ enumerable: true,
667
+ get: function () {
668
+ return processMatchMode;
669
+ }
670
+ });
671
+ Object.defineProperty(exports, 'shouldRenderAsNumber', {
672
+ enumerable: true,
673
+ get: function () {
674
+ return shouldRenderAsNumber;
675
+ }
676
+ });
677
+ Object.defineProperty(exports, 'toArray', {
678
+ enumerable: true,
679
+ get: function () {
680
+ return toArray;
681
+ }
682
+ });
683
+ Object.defineProperty(exports, 'toFlatOptionArray', {
684
+ enumerable: true,
685
+ get: function () {
686
+ return toFlatOptionArray;
687
+ }
688
+ });
689
+ Object.defineProperty(exports, 'toFullOption', {
690
+ enumerable: true,
691
+ get: function () {
692
+ return toFullOption;
693
+ }
694
+ });
695
+ Object.defineProperty(exports, 'toFullOptionList', {
696
+ enumerable: true,
697
+ get: function () {
698
+ return toFullOptionList;
699
+ }
700
+ });
701
+ Object.defineProperty(exports, 'trimIfString', {
702
+ enumerable: true,
703
+ get: function () {
704
+ return trimIfString;
705
+ }
706
+ });
707
+ //# sourceMappingURL=utils-Dkz3Xn2D.js.map