@react-querybuilder/core 8.22.5 → 8.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +16 -13
  76. package/dist/parseSpEL.js.map +1 -1
  77. package/dist/parseSpEL.mjs +12 -9
  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,5 +1,5 @@
1
- const require_utils = require("./utils-C79dxwZb.js");
2
- const require_isRuleGroup = require("./isRuleGroup-0JNiQgLg.js");
1
+ const require_utils = require("./utils-e-7KHkjV.js");
2
+ const require_objectUtils = require("./objectUtils-DfnEmDSV.js");
3
3
  //#region src/utils/filterFieldsByComparator.ts
4
4
  const filterByComparator = (field, operator, fieldToCompare) => {
5
5
  const fullField = require_utils.toFullOption(field);
@@ -37,64 +37,10 @@ const filterFieldsByComparator = (field, fields, operator) => {
37
37
  return fields.filter((f) => filterByComparator(field, operator, f));
38
38
  };
39
39
  //#endregion
40
- //#region src/utils/getValueSourcesUtil.ts
41
- const defaultValueSourcesArray = [{
42
- name: "value",
43
- value: "value",
44
- label: "value"
45
- }];
46
- const dummyFD = {
47
- name: "name",
48
- value: "name",
49
- valueSources: null,
50
- label: "label"
51
- };
52
- /**
53
- * Utility function to get the value sources array for the given
54
- * field and operator. If the field definition does not define a
55
- * `valueSources` property, the `getValueSources` prop is used.
56
- * Returns `[FullOption<"value">]` by default.
57
- */
58
- const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
59
- const fd = fieldData ? require_utils.toFullOption(fieldData) : dummyFD;
60
- let valueSourcesNEW = fd.valueSources ?? false;
61
- if (typeof valueSourcesNEW === "function") valueSourcesNEW = valueSourcesNEW(operator);
62
- if (!valueSourcesNEW && getValueSources) valueSourcesNEW = getValueSources(fd.value, operator, { fieldData: fd });
63
- if (!valueSourcesNEW) return defaultValueSourcesArray;
64
- if (require_utils.isFlexibleOptionArray(valueSourcesNEW)) return require_utils.toFullOptionList(valueSourcesNEW);
65
- return valueSourcesNEW.map((vs) => defaultValueSourcesArray.find((dmm) => dmm.value === require_isRuleGroup.lc(vs)) ?? {
66
- name: vs,
67
- value: vs,
68
- label: vs
69
- });
70
- };
71
- //#endregion
72
- //#region src/utils/parserUtils.ts
73
- const getFieldsArray = (fields) => {
74
- const fieldsArray = fields ? Array.isArray(fields) ? fields : Object.keys(fields).map((fld) => Object.assign({}, fields[fld], { name: fld })).sort((a, b) => a.label.localeCompare(b.label)) : [];
75
- return require_utils.toFlatOptionArray(fieldsArray);
76
- };
77
- function fieldIsValidUtil(params) {
78
- const { fieldsFlat, fieldName, operator, subordinateFieldName, getValueSources } = params;
79
- const vsIncludes = (vs) => {
80
- const vss = getValueSourcesUtil(primaryField, operator, getValueSources);
81
- return require_utils.isFlexibleOptionArray(vss) && vss.some((vso) => vso.value === vs || vso.name === vs);
82
- };
83
- if (fieldsFlat.length === 0) return true;
84
- let valid = false;
85
- const primaryField = require_utils.toFullOption(fieldsFlat.find((ff) => ff.name === fieldName));
86
- if (primaryField) {
87
- valid = !(!subordinateFieldName && operator !== "notNull" && operator !== "null" && !vsIncludes("value"));
88
- if (valid && !!subordinateFieldName) if (vsIncludes("field") && fieldName !== subordinateFieldName) {
89
- if (!filterFieldsByComparator(primaryField, fieldsFlat, operator).some((vsf) => vsf.name === subordinateFieldName)) valid = false;
90
- } else valid = false;
91
- }
92
- return valid;
93
- }
94
- //#endregion
95
40
  //#region src/utils/generateID.ts
96
41
  /* v8 ignore file -- this is fine */
97
42
  const cryptoModule = globalThis.crypto;
43
+ const uuidV4regex = /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
98
44
  /**
99
45
  * Default `id` generator. Generates a valid v4 UUID. Uses `crypto.randomUUID()`
100
46
  * when available, otherwise uses an alternate method based on `getRandomValues`.
@@ -127,6 +73,38 @@ if (cryptoModule) {
127
73
  }
128
74
  }
129
75
  //#endregion
76
+ //#region src/utils/getValueSourcesUtil.ts
77
+ const defaultValueSourcesArray = [{
78
+ name: "value",
79
+ value: "value",
80
+ label: "value"
81
+ }];
82
+ const dummyFD = {
83
+ name: "name",
84
+ value: "name",
85
+ valueSources: null,
86
+ label: "label"
87
+ };
88
+ /**
89
+ * Utility function to get the value sources array for the given
90
+ * field and operator. If the field definition does not define a
91
+ * `valueSources` property, the `getValueSources` prop is used.
92
+ * Returns `[FullOption<"value">]` by default.
93
+ */
94
+ const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
95
+ const fd = fieldData ? require_utils.toFullOption(fieldData) : dummyFD;
96
+ let valueSourcesNEW = fd.valueSources ?? false;
97
+ if (typeof valueSourcesNEW === "function") valueSourcesNEW = valueSourcesNEW(operator);
98
+ if (!valueSourcesNEW && getValueSources) valueSourcesNEW = getValueSources(fd.value, operator, { fieldData: fd });
99
+ if (!valueSourcesNEW) return defaultValueSourcesArray;
100
+ if (require_utils.isFlexibleOptionArray(valueSourcesNEW)) return require_utils.toFullOptionList(valueSourcesNEW);
101
+ return valueSourcesNEW.map((vs) => defaultValueSourcesArray.find((dmm) => dmm.value === require_objectUtils.lc(vs)) ?? {
102
+ name: vs,
103
+ value: vs,
104
+ label: vs
105
+ });
106
+ };
107
+ //#endregion
130
108
  //#region src/utils/prepareQueryObjects.ts
131
109
  /**
132
110
  * Ensures that a rule is valid by adding an `id` property if it does not already exist.
@@ -153,7 +131,7 @@ const prepareRuleGroup = (queryObject, { idGenerator = generateID } = {}) => {
153
131
  const r = queryObject.rules[i];
154
132
  if (typeof r === "string") newRules.push(r);
155
133
  else {
156
- const prepared = require_isRuleGroup.isRuleGroup(r) ? prepareRuleGroup(r, { idGenerator }) : prepareRule(r, { idGenerator });
134
+ const prepared = require_objectUtils.isRuleGroup(r) ? prepareRuleGroup(r, { idGenerator }) : prepareRule(r, { idGenerator });
157
135
  newRules.push(prepared);
158
136
  if (prepared !== r) rulesChanged = true;
159
137
  }
@@ -165,17 +143,48 @@ const prepareRuleGroup = (queryObject, { idGenerator = generateID } = {}) => {
165
143
  rules: newRules
166
144
  };
167
145
  };
146
+ /**
147
+ * Ensures that a rule or group is valid. See {@link prepareRule} and {@link prepareRuleGroup}.
148
+ */
149
+ const prepareRuleOrGroup = (rg, { idGenerator = generateID } = {}) => require_objectUtils.isRuleGroup(rg) ? prepareRuleGroup(rg, { idGenerator }) : prepareRule(rg, { idGenerator });
150
+ /**
151
+ * Resolves the query a query builder should render from the available sources, in precedence
152
+ * order: the controlled `query`, then whatever is already in the store, then the uncontrolled
153
+ * `defaultQuery`, then a freshly created empty group.
154
+ *
155
+ * The result is prepared with {@link prepareRuleGroup} unless it already has an `id`, which is
156
+ * taken to mean it has been prepared before—most often because the caller is passing back the
157
+ * object it received from `onQueryChange`.
158
+ *
159
+ * @group Query Tools
160
+ */
161
+ const resolveCandidateQuery = (sources, options) => {
162
+ const candidateQuery = sources.query ?? sources.storeQuery ?? sources.defaultQuery ?? sources.fallbackQuery;
163
+ return candidateQuery.id ? candidateQuery : prepareRuleGroup(candidateQuery, options);
164
+ };
168
165
  //#endregion
169
- Object.defineProperty(exports, "fieldIsValidUtil", {
166
+ Object.defineProperty(exports, "filterFieldsByComparator", {
167
+ enumerable: true,
168
+ get: function() {
169
+ return filterFieldsByComparator;
170
+ }
171
+ });
172
+ Object.defineProperty(exports, "generateID", {
173
+ enumerable: true,
174
+ get: function() {
175
+ return generateID;
176
+ }
177
+ });
178
+ Object.defineProperty(exports, "getValueSourcesUtil", {
170
179
  enumerable: true,
171
180
  get: function() {
172
- return fieldIsValidUtil;
181
+ return getValueSourcesUtil;
173
182
  }
174
183
  });
175
- Object.defineProperty(exports, "getFieldsArray", {
184
+ Object.defineProperty(exports, "prepareRule", {
176
185
  enumerable: true,
177
186
  get: function() {
178
- return getFieldsArray;
187
+ return prepareRule;
179
188
  }
180
189
  });
181
190
  Object.defineProperty(exports, "prepareRuleGroup", {
@@ -184,5 +193,23 @@ Object.defineProperty(exports, "prepareRuleGroup", {
184
193
  return prepareRuleGroup;
185
194
  }
186
195
  });
196
+ Object.defineProperty(exports, "prepareRuleOrGroup", {
197
+ enumerable: true,
198
+ get: function() {
199
+ return prepareRuleOrGroup;
200
+ }
201
+ });
202
+ Object.defineProperty(exports, "resolveCandidateQuery", {
203
+ enumerable: true,
204
+ get: function() {
205
+ return resolveCandidateQuery;
206
+ }
207
+ });
208
+ Object.defineProperty(exports, "uuidV4regex", {
209
+ enumerable: true,
210
+ get: function() {
211
+ return uuidV4regex;
212
+ }
213
+ });
187
214
 
188
- //# sourceMappingURL=prepareQueryObjects-BnGL91Tt.js.map
215
+ //# sourceMappingURL=prepareQueryObjects-Dj9cTl9D.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareQueryObjects-Dj9cTl9D.js","names":["toFullOption","isFlexibleOptionGroupArray","toFullOption","isFlexibleOptionArray","toFullOptionList","lc","processMatchMode","isRuleGroup"],"sources":["../src/utils/filterFieldsByComparator.ts","../src/utils/generateID.ts","../src/utils/getValueSourcesUtil.ts","../src/utils/prepareQueryObjects.ts"],"sourcesContent":["import type { FullField, OptionList, WithUnknownIndex } from '../types';\nimport { isFlexibleOptionGroupArray, toFullOption } from './optGroupUtils';\n\nconst filterByComparator = (field: FullField, operator: string, fieldToCompare: FullField) => {\n const fullField = toFullOption(field);\n const fullFieldToCompare = toFullOption(fieldToCompare);\n if (fullField.value === fullFieldToCompare.value) {\n return false;\n }\n if (typeof fullField.comparator === 'string') {\n return fullField[fullField.comparator] === fullFieldToCompare[fullField.comparator];\n }\n return (\n fullField.comparator?.(fullFieldToCompare, operator) ??\n /* v8 ignore start -- @preserve */ false /* v8 ignore stop -- @preserve */\n );\n};\n\n/**\n * For a given {@link FullField}, returns the `fields` list filtered for\n * other fields that match by `comparator`. Only fields *other than the\n * one in question* will ever be included, even if `comparator` is `null`\n * or `undefined`. If `comparator` is a string, fields with the same value\n * for that property will be included. If `comparator` is a function, each\n * field will be passed to the function along with the `operator` and fields\n * for which the function returns `true` will be included.\n *\n * @group Option Lists\n */\nexport const filterFieldsByComparator = (\n /** The field in question. */\n field: FullField,\n /** The full {@link FullField} list to be filtered. */\n fields: OptionList<FullField>,\n operator: string\n):\n | FullField[]\n | {\n options: WithUnknownIndex<FullField>[];\n label: string;\n }[] => {\n if (!field.comparator) {\n const filterOutSameField = (f: FullField) =>\n (f.value ?? /* v8 ignore start -- @preserve */ f.name) /* v8 ignore stop -- @preserve */ !==\n (field.value ??\n /* v8 ignore start -- @preserve */ field.name); /* v8 ignore stop -- @preserve */\n if (isFlexibleOptionGroupArray(fields)) {\n return fields.map(og => ({\n ...og,\n options: og.options.filter(v => filterOutSameField(v)),\n }));\n }\n return fields.filter(v => filterOutSameField(v));\n }\n\n if (isFlexibleOptionGroupArray(fields)) {\n return fields\n .map(og => ({\n ...og,\n options: og.options.filter(f => filterByComparator(field, operator, f)),\n }))\n .filter(og => og.options.length > 0);\n }\n\n return fields.filter(f => filterByComparator(field, operator, f));\n};\n","/* v8 ignore file -- this is fine */\n\ntype UUID = `${string}-${string}-${string}-${string}-${string}`;\n\nconst cryptoModule = globalThis.crypto;\n\nexport const uuidV4regex: RegExp =\n /^[\\da-f]{8}-[\\da-f]{4}-4[\\da-f]{3}-[89ab][\\da-f]{3}-[\\da-f]{12}$/i;\n\n/**\n * Default `id` generator. Generates a valid v4 UUID. Uses `crypto.randomUUID()`\n * when available, otherwise uses an alternate method based on `getRandomValues`.\n * The returned string is guaranteed to match this regex:\n * ```\n * /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i\n * ```\n * @returns Valid v4 UUID\n */\n// Default implementation adapted from https://stackoverflow.com/a/68141099/217579\n// v8 ignore next\nexport let generateID = (): UUID =>\n '00-0-4-2-000'.replaceAll(/[^-]/g, s =>\n (((Math.random() + Math.trunc(s as unknown as number)) * 0x1_00_00) >> Number.parseInt(s))\n .toString(16)\n .padStart(4, '0')\n ) as UUID;\n\n// Improve on the default implementation by using the crypto package if it's available\n// v8 ignore else\nif (cryptoModule) {\n // v8 ignore else\n if (typeof cryptoModule.randomUUID === 'function') {\n generateID = () => cryptoModule.randomUUID();\n } else if (typeof cryptoModule.getRandomValues === 'function') {\n // `randomUUID` is much simpler and faster, but it's only guaranteed to be\n // available in secure contexts (server-side, https, etc.). `generateID`\n // doesn't really need to be cryptographically secure, it only needs a\n // fairly low chance of collisions. We fall back to the always-available\n // `getRandomValues` here (while still generating a valid v4 UUID) when\n // `randomUUID` is not available.\n const position19vals = '89ab';\n const container = new Uint32Array(32);\n\n generateID = () => {\n cryptoModule.getRandomValues(container);\n let id = (container[0] % 16).toString(16);\n for (let i = 1; i < 32; i++) {\n if (i === 12) {\n id = `${id}${'4'}`;\n } else if (i === 16) {\n id = `${id}${position19vals[container[17] % 4]}`;\n } else {\n id = `${id}${(container[i] % 16).toString(16)}`;\n }\n\n if (i === 7 || i === 11 || i === 15 || i === 19) {\n id = `${id}${'-'}`;\n }\n }\n return id as UUID;\n };\n }\n}\n","import type {\n FullField,\n GetOptionIdentifierType,\n ValueSourceFlexibleOptions,\n ValueSourceFullOptions,\n ValueSources,\n} from '../types';\nimport { lc } from './misc';\nimport { isFlexibleOptionArray, toFullOption, toFullOptionList } from './optGroupUtils';\n\nconst defaultValueSourcesArray: ValueSourceFullOptions = [\n { name: 'value', value: 'value', label: 'value' },\n];\n\nconst dummyFD = {\n name: 'name',\n value: 'name',\n valueSources: null,\n label: 'label',\n};\n\n/**\n * Utility function to get the value sources array for the given\n * field and operator. If the field definition does not define a\n * `valueSources` property, the `getValueSources` prop is used.\n * Returns `[FullOption<\"value\">]` by default.\n */\n// oxlint-disable-next-line typescript/no-unnecessary-type-parameters\nexport const getValueSourcesUtil = <F extends FullField, O extends string>(\n fieldData: F,\n operator: string,\n getValueSources?: (\n field: GetOptionIdentifierType<F>,\n operator: O,\n misc: { fieldData: F }\n ) => ValueSources | ValueSourceFlexibleOptions\n): ValueSourceFullOptions => {\n // TypeScript doesn't allow it directly, but in practice\n // `fieldData` can end up being undefined or null. The nullish\n // coalescing assignment below avoids errors like\n // \"TypeError: Cannot read properties of undefined (reading 'name')\"\n const fd = fieldData ? toFullOption(fieldData) : dummyFD;\n\n let valueSourcesNEW:\n | false\n | ValueSources\n | ValueSourceFlexibleOptions\n | ((operator: string) => ValueSources | ValueSourceFlexibleOptions) = fd.valueSources ?? false;\n\n if (typeof valueSourcesNEW === 'function') {\n valueSourcesNEW = valueSourcesNEW(operator);\n }\n\n if (!valueSourcesNEW && getValueSources) {\n valueSourcesNEW = getValueSources(fd.value as GetOptionIdentifierType<F>, operator as O, {\n fieldData: fd as F,\n });\n }\n\n if (!valueSourcesNEW) {\n return defaultValueSourcesArray;\n }\n\n if (isFlexibleOptionArray(valueSourcesNEW)) {\n return toFullOptionList(valueSourcesNEW as ValueSourceFullOptions) as ValueSourceFullOptions;\n }\n\n return valueSourcesNEW.map(\n vs =>\n defaultValueSourcesArray.find(dmm => dmm.value === lc(vs)) ?? {\n name: vs,\n value: vs,\n label: vs,\n }\n ) as ValueSourceFullOptions;\n};\n","import type {\n RuleGroupArray,\n RuleGroupICArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\n} from '../types';\nimport { processMatchMode } from './formatQuery/utils';\nimport { generateID } from './generateID';\nimport { isRuleGroup } from './isRuleGroup';\n\n/**\n * Options for {@link prepareRule}/{@link prepareRuleGroup}.\n */\nexport interface PreparerOptions {\n idGenerator?: () => string;\n}\n\n/**\n * Ensures that a rule is valid by adding an `id` property if it does not already exist.\n */\nexport const prepareRule = (\n rule: RuleType,\n { idGenerator = generateID }: PreparerOptions = {}\n): RuleType => {\n const needsId = !rule.id;\n const hasMatchMode = processMatchMode(rule);\n\n if (!needsId && !hasMatchMode) {\n return rule;\n }\n\n return {\n ...rule,\n ...(needsId && { id: idGenerator() }),\n ...(hasMatchMode && { value: prepareRuleGroup(rule.value, { idGenerator }) }),\n };\n};\n\n/**\n * Ensures that a rule group is valid by recursively adding an `id` property to the group itself\n * and all its rules and subgroups where one does not already exist.\n */\nexport const prepareRuleGroup = <RG extends RuleGroupTypeAny>(\n queryObject: RG,\n { idGenerator = generateID }: PreparerOptions = {}\n): RG => {\n const needsId = !queryObject.id;\n let rulesChanged = false;\n const newRules: (RuleGroupTypeAny | RuleType | string)[] = [];\n\n for (let i = 0; i < queryObject.rules.length; i++) {\n const r = queryObject.rules[i];\n if (typeof r === 'string') {\n newRules.push(r);\n } else {\n const prepared = isRuleGroup(r)\n ? prepareRuleGroup(r, { idGenerator })\n : prepareRule(r, { idGenerator });\n newRules.push(prepared);\n if (prepared !== r) {\n rulesChanged = true;\n }\n }\n }\n\n if (!needsId && !rulesChanged) {\n return queryObject;\n }\n\n return {\n ...queryObject,\n ...(needsId && { id: idGenerator() }),\n rules: newRules as RuleGroupArray | RuleGroupICArray,\n };\n};\n\n/**\n * Ensures that a rule or group is valid. See {@link prepareRule} and {@link prepareRuleGroup}.\n */\nexport const prepareRuleOrGroup = (\n rg: RuleGroupTypeAny | RuleType,\n { idGenerator = generateID }: PreparerOptions = {}\n): RuleGroupType | RuleGroupTypeIC | RuleType =>\n isRuleGroup(rg) ? prepareRuleGroup(rg, { idGenerator }) : prepareRule(rg, { idGenerator });\n\n/**\n * Resolves the query a query builder should render from the available sources, in precedence\n * order: the controlled `query`, then whatever is already in the store, then the uncontrolled\n * `defaultQuery`, then a freshly created empty group.\n *\n * The result is prepared with {@link prepareRuleGroup} unless it already has an `id`, which is\n * taken to mean it has been prepared before—most often because the caller is passing back the\n * object it received from `onQueryChange`.\n *\n * @group Query Tools\n */\nexport const resolveCandidateQuery = <RG extends RuleGroupTypeAny>(\n sources: {\n query?: RG;\n storeQuery?: RG;\n defaultQuery?: RG;\n fallbackQuery: RG;\n },\n options?: { idGenerator?: () => string }\n): RG => {\n const candidateQuery =\n sources.query ?? sources.storeQuery ?? sources.defaultQuery ?? sources.fallbackQuery;\n\n return candidateQuery.id ? candidateQuery : prepareRuleGroup(candidateQuery, options);\n};\n"],"mappings":";;;AAGA,MAAM,sBAAsB,OAAkB,UAAkB,mBAA8B;CAC5F,MAAM,YAAYA,cAAAA,aAAa,KAAK;CACpC,MAAM,qBAAqBA,cAAAA,aAAa,cAAc;CACtD,IAAI,UAAU,UAAU,mBAAmB,OACzC,OAAO;CAET,IAAI,OAAO,UAAU,eAAe,UAClC,OAAO,UAAU,UAAU,gBAAgB,mBAAmB,UAAU;CAE1E,OACE,UAAU,aAAa,oBAAoB,QAAQ;oCAChB;AAEvC;;;;;;;;;;;;AAaA,MAAa,4BAEX,OAEA,QACA,aAMS;CACT,IAAI,CAAC,MAAM,YAAY;EACrB,MAAM,sBAAsB,OACzB,EAAE,4CAA4C,EAAE,WAChD,MAAM;qCAC8B,MAAM;EAC7C,IAAIC,cAAAA,2BAA2B,MAAM,GACnC,OAAO,OAAO,KAAI,QAAO;GACvB,GAAG;GACH,SAAS,GAAG,QAAQ,QAAO,MAAK,mBAAmB,CAAC,CAAC;EACvD,EAAE;EAEJ,OAAO,OAAO,QAAO,MAAK,mBAAmB,CAAC,CAAC;CACjD;CAE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AY,GAAG,EAAE,YAAY,CAAC;GAClC,SAAS,KAAK,QAAQ;GACtB,IAAI,aAAa,GACf,eAAe;EAEnB;CACF;CAEA,IAAI,CAAC,WAAW,CAAC,cACf,OAAO;CAGT,OAAO;EACL,GAAG;EACH,GAAI,WAAW,EAAE,IAAI,YAAY,EAAE;EACnC,OAAO;CACT;AACF;;;;AAKA,MAAa,sBACX,IACA,EAAE,cAAc,eAAgC,CAAC,MAEjDA,oBAAAA,YAAY,EAAE,IAAI,iBAAiB,IAAI,EAAE,YAAY,CAAC,IAAI,YAAY,IAAI,EAAE,YAAY,CAAC;;;;;;;;;;;;AAa3F,MAAa,yBACX,SAMA,YACO;CACP,MAAM,iBACJ,QAAQ,SAAS,QAAQ,cAAc,QAAQ,gBAAgB,QAAQ;CAEzE,OAAO,eAAe,KAAK,iBAAiB,iBAAiB,gBAAgB,OAAO;AACtF"}
@@ -1,5 +1,5 @@
1
- import { A as toFullOption, D as isFlexibleOptionArray, O as isFlexibleOptionGroupArray, j as toFullOptionList, k as toFlatOptionArray, y as processMatchMode } from "./utils-4k-j5FBa.mjs";
2
- import { a as lc, t as isRuleGroup } from "./isRuleGroup-CqLThsbu.mjs";
1
+ import { A as isFlexibleOptionGroupArray, I as toFullOption, L as toFullOptionList, k as isFlexibleOptionArray, y as processMatchMode } from "./utils-CP5Jqy1P.mjs";
2
+ import { i as isRuleGroup, l as lc } from "./objectUtils-DDZ-KhV5.mjs";
3
3
  //#region src/utils/filterFieldsByComparator.ts
4
4
  const filterByComparator = (field, operator, fieldToCompare) => {
5
5
  const fullField = toFullOption(field);
@@ -37,64 +37,10 @@ const filterFieldsByComparator = (field, fields, operator) => {
37
37
  return fields.filter((f) => filterByComparator(field, operator, f));
38
38
  };
39
39
  //#endregion
40
- //#region src/utils/getValueSourcesUtil.ts
41
- const defaultValueSourcesArray = [{
42
- name: "value",
43
- value: "value",
44
- label: "value"
45
- }];
46
- const dummyFD = {
47
- name: "name",
48
- value: "name",
49
- valueSources: null,
50
- label: "label"
51
- };
52
- /**
53
- * Utility function to get the value sources array for the given
54
- * field and operator. If the field definition does not define a
55
- * `valueSources` property, the `getValueSources` prop is used.
56
- * Returns `[FullOption<"value">]` by default.
57
- */
58
- const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
59
- const fd = fieldData ? toFullOption(fieldData) : dummyFD;
60
- let valueSourcesNEW = fd.valueSources ?? false;
61
- if (typeof valueSourcesNEW === "function") valueSourcesNEW = valueSourcesNEW(operator);
62
- if (!valueSourcesNEW && getValueSources) valueSourcesNEW = getValueSources(fd.value, operator, { fieldData: fd });
63
- if (!valueSourcesNEW) return defaultValueSourcesArray;
64
- if (isFlexibleOptionArray(valueSourcesNEW)) return toFullOptionList(valueSourcesNEW);
65
- return valueSourcesNEW.map((vs) => defaultValueSourcesArray.find((dmm) => dmm.value === lc(vs)) ?? {
66
- name: vs,
67
- value: vs,
68
- label: vs
69
- });
70
- };
71
- //#endregion
72
- //#region src/utils/parserUtils.ts
73
- const getFieldsArray = (fields) => {
74
- const fieldsArray = fields ? Array.isArray(fields) ? fields : Object.keys(fields).map((fld) => Object.assign({}, fields[fld], { name: fld })).sort((a, b) => a.label.localeCompare(b.label)) : [];
75
- return toFlatOptionArray(fieldsArray);
76
- };
77
- function fieldIsValidUtil(params) {
78
- const { fieldsFlat, fieldName, operator, subordinateFieldName, getValueSources } = params;
79
- const vsIncludes = (vs) => {
80
- const vss = getValueSourcesUtil(primaryField, operator, getValueSources);
81
- return isFlexibleOptionArray(vss) && vss.some((vso) => vso.value === vs || vso.name === vs);
82
- };
83
- if (fieldsFlat.length === 0) return true;
84
- let valid = false;
85
- const primaryField = toFullOption(fieldsFlat.find((ff) => ff.name === fieldName));
86
- if (primaryField) {
87
- valid = !(!subordinateFieldName && operator !== "notNull" && operator !== "null" && !vsIncludes("value"));
88
- if (valid && !!subordinateFieldName) if (vsIncludes("field") && fieldName !== subordinateFieldName) {
89
- if (!filterFieldsByComparator(primaryField, fieldsFlat, operator).some((vsf) => vsf.name === subordinateFieldName)) valid = false;
90
- } else valid = false;
91
- }
92
- return valid;
93
- }
94
- //#endregion
95
40
  //#region src/utils/generateID.ts
96
41
  /* v8 ignore file -- this is fine */
97
42
  const cryptoModule = globalThis.crypto;
43
+ const uuidV4regex = /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
98
44
  /**
99
45
  * Default `id` generator. Generates a valid v4 UUID. Uses `crypto.randomUUID()`
100
46
  * when available, otherwise uses an alternate method based on `getRandomValues`.
@@ -127,6 +73,38 @@ if (cryptoModule) {
127
73
  }
128
74
  }
129
75
  //#endregion
76
+ //#region src/utils/getValueSourcesUtil.ts
77
+ const defaultValueSourcesArray = [{
78
+ name: "value",
79
+ value: "value",
80
+ label: "value"
81
+ }];
82
+ const dummyFD = {
83
+ name: "name",
84
+ value: "name",
85
+ valueSources: null,
86
+ label: "label"
87
+ };
88
+ /**
89
+ * Utility function to get the value sources array for the given
90
+ * field and operator. If the field definition does not define a
91
+ * `valueSources` property, the `getValueSources` prop is used.
92
+ * Returns `[FullOption<"value">]` by default.
93
+ */
94
+ const getValueSourcesUtil = (fieldData, operator, getValueSources) => {
95
+ const fd = fieldData ? toFullOption(fieldData) : dummyFD;
96
+ let valueSourcesNEW = fd.valueSources ?? false;
97
+ if (typeof valueSourcesNEW === "function") valueSourcesNEW = valueSourcesNEW(operator);
98
+ if (!valueSourcesNEW && getValueSources) valueSourcesNEW = getValueSources(fd.value, operator, { fieldData: fd });
99
+ if (!valueSourcesNEW) return defaultValueSourcesArray;
100
+ if (isFlexibleOptionArray(valueSourcesNEW)) return toFullOptionList(valueSourcesNEW);
101
+ return valueSourcesNEW.map((vs) => defaultValueSourcesArray.find((dmm) => dmm.value === lc(vs)) ?? {
102
+ name: vs,
103
+ value: vs,
104
+ label: vs
105
+ });
106
+ };
107
+ //#endregion
130
108
  //#region src/utils/prepareQueryObjects.ts
131
109
  /**
132
110
  * Ensures that a rule is valid by adding an `id` property if it does not already exist.
@@ -165,7 +143,26 @@ const prepareRuleGroup = (queryObject, { idGenerator = generateID } = {}) => {
165
143
  rules: newRules
166
144
  };
167
145
  };
146
+ /**
147
+ * Ensures that a rule or group is valid. See {@link prepareRule} and {@link prepareRuleGroup}.
148
+ */
149
+ const prepareRuleOrGroup = (rg, { idGenerator = generateID } = {}) => isRuleGroup(rg) ? prepareRuleGroup(rg, { idGenerator }) : prepareRule(rg, { idGenerator });
150
+ /**
151
+ * Resolves the query a query builder should render from the available sources, in precedence
152
+ * order: the controlled `query`, then whatever is already in the store, then the uncontrolled
153
+ * `defaultQuery`, then a freshly created empty group.
154
+ *
155
+ * The result is prepared with {@link prepareRuleGroup} unless it already has an `id`, which is
156
+ * taken to mean it has been prepared before—most often because the caller is passing back the
157
+ * object it received from `onQueryChange`.
158
+ *
159
+ * @group Query Tools
160
+ */
161
+ const resolveCandidateQuery = (sources, options) => {
162
+ const candidateQuery = sources.query ?? sources.storeQuery ?? sources.defaultQuery ?? sources.fallbackQuery;
163
+ return candidateQuery.id ? candidateQuery : prepareRuleGroup(candidateQuery, options);
164
+ };
168
165
  //#endregion
169
- export { fieldIsValidUtil as n, getFieldsArray as r, prepareRuleGroup as t };
166
+ export { getValueSourcesUtil as a, filterFieldsByComparator as c, resolveCandidateQuery as i, prepareRuleGroup as n, generateID as o, prepareRuleOrGroup as r, uuidV4regex as s, prepareRule as t };
170
167
 
171
- //# sourceMappingURL=prepareQueryObjects-ChINDIap.mjs.map
168
+ //# sourceMappingURL=prepareQueryObjects-Dmyf3Wi_.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareQueryObjects-Dmyf3Wi_.mjs","names":[],"sources":["../src/utils/filterFieldsByComparator.ts","../src/utils/generateID.ts","../src/utils/getValueSourcesUtil.ts","../src/utils/prepareQueryObjects.ts"],"sourcesContent":["import type { FullField, OptionList, WithUnknownIndex } from '../types';\nimport { isFlexibleOptionGroupArray, toFullOption } from './optGroupUtils';\n\nconst filterByComparator = (field: FullField, operator: string, fieldToCompare: FullField) => {\n const fullField = toFullOption(field);\n const fullFieldToCompare = toFullOption(fieldToCompare);\n if (fullField.value === fullFieldToCompare.value) {\n return false;\n }\n if (typeof fullField.comparator === 'string') {\n return fullField[fullField.comparator] === fullFieldToCompare[fullField.comparator];\n }\n return (\n fullField.comparator?.(fullFieldToCompare, operator) ??\n /* v8 ignore start -- @preserve */ false /* v8 ignore stop -- @preserve */\n );\n};\n\n/**\n * For a given {@link FullField}, returns the `fields` list filtered for\n * other fields that match by `comparator`. Only fields *other than the\n * one in question* will ever be included, even if `comparator` is `null`\n * or `undefined`. If `comparator` is a string, fields with the same value\n * for that property will be included. If `comparator` is a function, each\n * field will be passed to the function along with the `operator` and fields\n * for which the function returns `true` will be included.\n *\n * @group Option Lists\n */\nexport const filterFieldsByComparator = (\n /** The field in question. */\n field: FullField,\n /** The full {@link FullField} list to be filtered. */\n fields: OptionList<FullField>,\n operator: string\n):\n | FullField[]\n | {\n options: WithUnknownIndex<FullField>[];\n label: string;\n }[] => {\n if (!field.comparator) {\n const filterOutSameField = (f: FullField) =>\n (f.value ?? /* v8 ignore start -- @preserve */ f.name) /* v8 ignore stop -- @preserve */ !==\n (field.value ??\n /* v8 ignore start -- @preserve */ field.name); /* v8 ignore stop -- @preserve */\n if (isFlexibleOptionGroupArray(fields)) {\n return fields.map(og => ({\n ...og,\n options: og.options.filter(v => filterOutSameField(v)),\n }));\n }\n return fields.filter(v => filterOutSameField(v));\n }\n\n if (isFlexibleOptionGroupArray(fields)) {\n return fields\n .map(og => ({\n ...og,\n options: og.options.filter(f => filterByComparator(field, operator, f)),\n }))\n .filter(og => og.options.length > 0);\n }\n\n return fields.filter(f => filterByComparator(field, operator, f));\n};\n","/* v8 ignore file -- this is fine */\n\ntype UUID = `${string}-${string}-${string}-${string}-${string}`;\n\nconst cryptoModule = globalThis.crypto;\n\nexport const uuidV4regex: RegExp =\n /^[\\da-f]{8}-[\\da-f]{4}-4[\\da-f]{3}-[89ab][\\da-f]{3}-[\\da-f]{12}$/i;\n\n/**\n * Default `id` generator. Generates a valid v4 UUID. Uses `crypto.randomUUID()`\n * when available, otherwise uses an alternate method based on `getRandomValues`.\n * The returned string is guaranteed to match this regex:\n * ```\n * /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i\n * ```\n * @returns Valid v4 UUID\n */\n// Default implementation adapted from https://stackoverflow.com/a/68141099/217579\n// v8 ignore next\nexport let generateID = (): UUID =>\n '00-0-4-2-000'.replaceAll(/[^-]/g, s =>\n (((Math.random() + Math.trunc(s as unknown as number)) * 0x1_00_00) >> Number.parseInt(s))\n .toString(16)\n .padStart(4, '0')\n ) as UUID;\n\n// Improve on the default implementation by using the crypto package if it's available\n// v8 ignore else\nif (cryptoModule) {\n // v8 ignore else\n if (typeof cryptoModule.randomUUID === 'function') {\n generateID = () => cryptoModule.randomUUID();\n } else if (typeof cryptoModule.getRandomValues === 'function') {\n // `randomUUID` is much simpler and faster, but it's only guaranteed to be\n // available in secure contexts (server-side, https, etc.). `generateID`\n // doesn't really need to be cryptographically secure, it only needs a\n // fairly low chance of collisions. We fall back to the always-available\n // `getRandomValues` here (while still generating a valid v4 UUID) when\n // `randomUUID` is not available.\n const position19vals = '89ab';\n const container = new Uint32Array(32);\n\n generateID = () => {\n cryptoModule.getRandomValues(container);\n let id = (container[0] % 16).toString(16);\n for (let i = 1; i < 32; i++) {\n if (i === 12) {\n id = `${id}${'4'}`;\n } else if (i === 16) {\n id = `${id}${position19vals[container[17] % 4]}`;\n } else {\n id = `${id}${(container[i] % 16).toString(16)}`;\n }\n\n if (i === 7 || i === 11 || i === 15 || i === 19) {\n id = `${id}${'-'}`;\n }\n }\n return id as UUID;\n };\n }\n}\n","import type {\n FullField,\n GetOptionIdentifierType,\n ValueSourceFlexibleOptions,\n ValueSourceFullOptions,\n ValueSources,\n} from '../types';\nimport { lc } from './misc';\nimport { isFlexibleOptionArray, toFullOption, toFullOptionList } from './optGroupUtils';\n\nconst defaultValueSourcesArray: ValueSourceFullOptions = [\n { name: 'value', value: 'value', label: 'value' },\n];\n\nconst dummyFD = {\n name: 'name',\n value: 'name',\n valueSources: null,\n label: 'label',\n};\n\n/**\n * Utility function to get the value sources array for the given\n * field and operator. If the field definition does not define a\n * `valueSources` property, the `getValueSources` prop is used.\n * Returns `[FullOption<\"value\">]` by default.\n */\n// oxlint-disable-next-line typescript/no-unnecessary-type-parameters\nexport const getValueSourcesUtil = <F extends FullField, O extends string>(\n fieldData: F,\n operator: string,\n getValueSources?: (\n field: GetOptionIdentifierType<F>,\n operator: O,\n misc: { fieldData: F }\n ) => ValueSources | ValueSourceFlexibleOptions\n): ValueSourceFullOptions => {\n // TypeScript doesn't allow it directly, but in practice\n // `fieldData` can end up being undefined or null. The nullish\n // coalescing assignment below avoids errors like\n // \"TypeError: Cannot read properties of undefined (reading 'name')\"\n const fd = fieldData ? toFullOption(fieldData) : dummyFD;\n\n let valueSourcesNEW:\n | false\n | ValueSources\n | ValueSourceFlexibleOptions\n | ((operator: string) => ValueSources | ValueSourceFlexibleOptions) = fd.valueSources ?? false;\n\n if (typeof valueSourcesNEW === 'function') {\n valueSourcesNEW = valueSourcesNEW(operator);\n }\n\n if (!valueSourcesNEW && getValueSources) {\n valueSourcesNEW = getValueSources(fd.value as GetOptionIdentifierType<F>, operator as O, {\n fieldData: fd as F,\n });\n }\n\n if (!valueSourcesNEW) {\n return defaultValueSourcesArray;\n }\n\n if (isFlexibleOptionArray(valueSourcesNEW)) {\n return toFullOptionList(valueSourcesNEW as ValueSourceFullOptions) as ValueSourceFullOptions;\n }\n\n return valueSourcesNEW.map(\n vs =>\n defaultValueSourcesArray.find(dmm => dmm.value === lc(vs)) ?? {\n name: vs,\n value: vs,\n label: vs,\n }\n ) as ValueSourceFullOptions;\n};\n","import type {\n RuleGroupArray,\n RuleGroupICArray,\n RuleGroupType,\n RuleGroupTypeAny,\n RuleGroupTypeIC,\n RuleType,\n} from '../types';\nimport { processMatchMode } from './formatQuery/utils';\nimport { generateID } from './generateID';\nimport { isRuleGroup } from './isRuleGroup';\n\n/**\n * Options for {@link prepareRule}/{@link prepareRuleGroup}.\n */\nexport interface PreparerOptions {\n idGenerator?: () => string;\n}\n\n/**\n * Ensures that a rule is valid by adding an `id` property if it does not already exist.\n */\nexport const prepareRule = (\n rule: RuleType,\n { idGenerator = generateID }: PreparerOptions = {}\n): RuleType => {\n const needsId = !rule.id;\n const hasMatchMode = processMatchMode(rule);\n\n if (!needsId && !hasMatchMode) {\n return rule;\n }\n\n return {\n ...rule,\n ...(needsId && { id: idGenerator() }),\n ...(hasMatchMode && { value: prepareRuleGroup(rule.value, { idGenerator }) }),\n };\n};\n\n/**\n * Ensures that a rule group is valid by recursively adding an `id` property to the group itself\n * and all its rules and subgroups where one does not already exist.\n */\nexport const prepareRuleGroup = <RG extends RuleGroupTypeAny>(\n queryObject: RG,\n { idGenerator = generateID }: PreparerOptions = {}\n): RG => {\n const needsId = !queryObject.id;\n let rulesChanged = false;\n const newRules: (RuleGroupTypeAny | RuleType | string)[] = [];\n\n for (let i = 0; i < queryObject.rules.length; i++) {\n const r = queryObject.rules[i];\n if (typeof r === 'string') {\n newRules.push(r);\n } else {\n const prepared = isRuleGroup(r)\n ? prepareRuleGroup(r, { idGenerator })\n : prepareRule(r, { idGenerator });\n newRules.push(prepared);\n if (prepared !== r) {\n rulesChanged = true;\n }\n }\n }\n\n if (!needsId && !rulesChanged) {\n return queryObject;\n }\n\n return {\n ...queryObject,\n ...(needsId && { id: idGenerator() }),\n rules: newRules as RuleGroupArray | RuleGroupICArray,\n };\n};\n\n/**\n * Ensures that a rule or group is valid. See {@link prepareRule} and {@link prepareRuleGroup}.\n */\nexport const prepareRuleOrGroup = (\n rg: RuleGroupTypeAny | RuleType,\n { idGenerator = generateID }: PreparerOptions = {}\n): RuleGroupType | RuleGroupTypeIC | RuleType =>\n isRuleGroup(rg) ? prepareRuleGroup(rg, { idGenerator }) : prepareRule(rg, { idGenerator });\n\n/**\n * Resolves the query a query builder should render from the available sources, in precedence\n * order: the controlled `query`, then whatever is already in the store, then the uncontrolled\n * `defaultQuery`, then a freshly created empty group.\n *\n * The result is prepared with {@link prepareRuleGroup} unless it already has an `id`, which is\n * taken to mean it has been prepared before—most often because the caller is passing back the\n * object it received from `onQueryChange`.\n *\n * @group Query Tools\n */\nexport const resolveCandidateQuery = <RG extends RuleGroupTypeAny>(\n sources: {\n query?: RG;\n storeQuery?: RG;\n defaultQuery?: RG;\n fallbackQuery: RG;\n },\n options?: { idGenerator?: () => string }\n): RG => {\n const candidateQuery =\n sources.query ?? sources.storeQuery ?? sources.defaultQuery ?? sources.fallbackQuery;\n\n return candidateQuery.id ? candidateQuery : prepareRuleGroup(candidateQuery, options);\n};\n"],"mappings":";;;AAGA,MAAM,sBAAsB,OAAkB,UAAkB,mBAA8B;CAC5F,MAAM,YAAY,aAAa,KAAK;CACpC,MAAM,qBAAqB,aAAa,cAAc;CACtD,IAAI,UAAU,UAAU,mBAAmB,OACzC,OAAO;CAET,IAAI,OAAO,UAAU,eAAe,UAClC,OAAO,UAAU,UAAU,gBAAgB,mBAAmB,UAAU;CAE1E,OACE,UAAU,aAAa,oBAAoB,QAAQ;oCAChB;AAEvC;;;;;;;;;;;;AAaA,MAAa,4BAEX,OAEA,QACA,aAMS;CACT,IAAI,CAAC,MAAM,YAAY;EACrB,MAAM,sBAAsB,OACzB,EAAE,4CAA4C,EAAE,WAChD,MAAM;qCAC8B,MAAM;EAC7C,IAAI,2BAA2B,MAAM,GACnC,OAAO,OAAO,KAAI,QAAO;GACvB,GAAG;GACH,SAAS,GAAG,QAAQ,QAAO,MAAK,mBAAmB,CAAC,CAAC;EACvD,EAAE;EAEJ,OAAO,OAAO,QAAO,MAAK,mBAAmB,CAAC,CAAC;CACjD;CAEA,IAAI,2BAA2B,MAAM,GACnC,OAAO,OACJ,KAAI,QAAO;EACV,GAAG;EACH,SAAS,GAAG,QAA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