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