@react-querybuilder/core 8.9.1 → 8.9.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 (59) hide show
  1. package/dist/arrayUtils-BF1P8iHS.mjs +122 -0
  2. package/dist/arrayUtils-BF1P8iHS.mjs.map +1 -0
  3. package/dist/basic-BfD-7CN3.d.mts +1235 -0
  4. package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +21 -10
  5. package/dist/cjs/react-querybuilder_core.cjs.development.js +22 -19
  6. package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
  7. package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +21 -10
  8. package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
  9. package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
  10. package/dist/convertQuery-H7RhQiIc.mjs +75 -0
  11. package/dist/convertQuery-H7RhQiIc.mjs.map +1 -0
  12. package/dist/export-r-V7bU31.d.mts +452 -0
  13. package/dist/formatQuery.d.mts +667 -0
  14. package/dist/formatQuery.mjs +2366 -0
  15. package/dist/formatQuery.mjs.map +1 -0
  16. package/dist/import-BwbbP4oU.d.mts +28 -0
  17. package/dist/isRuleGroup-CnhYpLOM.mjs +40 -0
  18. package/dist/isRuleGroup-CnhYpLOM.mjs.map +1 -0
  19. package/dist/isRuleGroup-DqAs2x4E.js.map +1 -1
  20. package/dist/objectUtils-BtWdcZVG.mjs +11 -0
  21. package/dist/objectUtils-BtWdcZVG.mjs.map +1 -0
  22. package/dist/optGroupUtils-Duv-M8rf.mjs +102 -0
  23. package/dist/optGroupUtils-Duv-M8rf.mjs.map +1 -0
  24. package/dist/parseCEL.d.mts +34 -0
  25. package/dist/parseCEL.mjs +2593 -0
  26. package/dist/parseCEL.mjs.map +1 -0
  27. package/dist/parseJSONata.d.mts +36 -0
  28. package/dist/parseJSONata.mjs +268 -0
  29. package/dist/parseJSONata.mjs.map +1 -0
  30. package/dist/parseJsonLogic.d.mts +36 -0
  31. package/dist/parseJsonLogic.mjs +191 -0
  32. package/dist/parseJsonLogic.mjs.map +1 -0
  33. package/dist/parseMongoDB.d.mts +79 -0
  34. package/dist/parseMongoDB.mjs +267 -0
  35. package/dist/parseMongoDB.mjs.map +1 -0
  36. package/dist/parseNumber-BtGKa58z.mjs +24 -0
  37. package/dist/parseNumber-BtGKa58z.mjs.map +1 -0
  38. package/dist/parseSQL.d.mts +37 -0
  39. package/dist/parseSQL.mjs +6626 -0
  40. package/dist/parseSQL.mjs.map +1 -0
  41. package/dist/parseSpEL.d.mts +34 -0
  42. package/dist/parseSpEL.mjs +273 -0
  43. package/dist/parseSpEL.mjs.map +1 -0
  44. package/dist/prepareQueryObjects-CS6Wmhmf.mjs +154 -0
  45. package/dist/prepareQueryObjects-CS6Wmhmf.mjs.map +1 -0
  46. package/dist/react-querybuilder_core.d.mts +21 -10
  47. package/dist/react-querybuilder_core.legacy-esm.d.ts +21 -10
  48. package/dist/react-querybuilder_core.legacy-esm.js +19 -18
  49. package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
  50. package/dist/react-querybuilder_core.mjs +22 -20
  51. package/dist/react-querybuilder_core.mjs.map +1 -1
  52. package/dist/react-querybuilder_core.production.d.mts +21 -10
  53. package/dist/react-querybuilder_core.production.mjs +1 -1
  54. package/dist/react-querybuilder_core.production.mjs.map +1 -1
  55. package/dist/transformQuery-DdMvmrCh.mjs +41 -0
  56. package/dist/transformQuery-DdMvmrCh.mjs.map +1 -0
  57. package/dist/transformQuery.d.mts +118 -0
  58. package/dist/transformQuery.mjs +4 -0
  59. package/package.json +66 -18
@@ -0,0 +1,28 @@
1
+ import { FullField, OptionList, ValueSources } from "./basic-BfD-7CN3.mjs";
2
+
3
+ //#region src/types/import.d.ts
4
+
5
+ /**
6
+ * Options common to all parsers.
7
+ */
8
+ interface ParserCommonOptions {
9
+ fields?: OptionList<FullField> | Record<string, FullField>;
10
+ getValueSources?: (field: string, operator: string) => ValueSources;
11
+ listsAsArrays?: boolean;
12
+ /**
13
+ * When true, the generated query will use independent combinators ({@link RuleGroupTypeIC}).
14
+ */
15
+ independentCombinators?: boolean;
16
+ /**
17
+ * When true, a unique `id` will be generated for each rule and group in the query.
18
+ */
19
+ generateIDs?: boolean;
20
+ /**
21
+ * Generates a `bigint` value if the string represents a valid integer
22
+ * outside the safe boundaries of the `number` type.
23
+ */
24
+ bigIntOnOverflow?: boolean;
25
+ }
26
+ //#endregion
27
+ export { ParserCommonOptions };
28
+ //# sourceMappingURL=import-BwbbP4oU.d.mts.map
@@ -0,0 +1,40 @@
1
+ import { numericRegex } from "numeric-quantity";
2
+
3
+ //#region src/utils/misc.ts
4
+ /**
5
+ * Converts a value to lowercase if it's a string, otherwise returns the value as is.
6
+ */
7
+ // istanbul ignore next
8
+ const lc = (v) => typeof v === "string" ? v.toLowerCase() : v;
9
+ /**
10
+ * Regex matching numeric strings. Passes for positive/negative integers, decimals,
11
+ * and E notation, with optional surrounding whitespace.
12
+ */
13
+ const numericRegex$1 = new RegExp(numericRegex.source.replace(/^\^/, String.raw`^\s*`).replace(/\$$/, String.raw`\s*$`));
14
+ /**
15
+ * Determines if a variable is a plain old JavaScript object, aka POJO.
16
+ */
17
+ const isPojo = (obj) => obj === null || typeof obj !== "object" ? false : Object.getPrototypeOf(obj) === Object.prototype;
18
+ /**
19
+ * Simple helper to determine whether a value is null, undefined, or an empty string.
20
+ */
21
+ const nullOrUndefinedOrEmpty = (value) => value === null || value === void 0 || value === "";
22
+
23
+ //#endregion
24
+ //#region src/utils/isRuleGroup.ts
25
+ /**
26
+ * Determines if an object is a {@link RuleGroupType} or {@link RuleGroupTypeIC}.
27
+ */
28
+ const isRuleGroup = (rg) => isPojo(rg) && Array.isArray(rg.rules);
29
+ /**
30
+ * Determines if an object is a {@link RuleGroupType}.
31
+ */
32
+ const isRuleGroupType = (rg) => isRuleGroup(rg) && typeof rg.combinator === "string";
33
+ /**
34
+ * Determines if an object is a {@link RuleGroupTypeIC}.
35
+ */
36
+ const isRuleGroupTypeIC = (rg) => isRuleGroup(rg) && rg.combinator === void 0;
37
+
38
+ //#endregion
39
+ export { isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, lc, nullOrUndefinedOrEmpty, numericRegex$1 as numericRegex };
40
+ //# sourceMappingURL=isRuleGroup-CnhYpLOM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isRuleGroup-CnhYpLOM.mjs","names":["numericRegex: RegExp","numericQuantityRegex"],"sources":["../src/utils/misc.ts","../src/utils/isRuleGroup.ts"],"sourcesContent":["import { numericRegex as numericQuantityRegex } from 'numeric-quantity';\n\n/**\n * Converts a value to lowercase if it's a string, otherwise returns the value as is.\n */\n// istanbul ignore next\nexport const lc = <T>(v: T): T => (typeof v === 'string' ? (v.toLowerCase() as T) : v);\n\n/**\n * Regex matching numeric strings. Passes for positive/negative integers, decimals,\n * and E notation, with optional surrounding whitespace.\n */\nexport const numericRegex: RegExp = new RegExp(\n numericQuantityRegex.source.replace(/^\\^/, String.raw`^\\s*`).replace(/\\$$/, String.raw`\\s*$`)\n);\n\n/**\n * Determines if a variable is a plain old JavaScript object, aka POJO.\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isPojo = (obj: any): obj is Record<string, any> =>\n obj === null || typeof obj !== 'object' ? false : Object.getPrototypeOf(obj) === Object.prototype;\n\n/**\n * Simple helper to determine whether a value is null, undefined, or an empty string.\n */\nexport const nullOrUndefinedOrEmpty = (value: unknown): value is null | undefined | '' =>\n value === null || value === undefined || value === '';\n","import type { RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleType } from '../types';\nimport { isPojo } from './misc';\n\n/**\n * Determines if an object is a {@link RuleType} (only checks for a `field` property).\n */\nexport const isRuleType = (s: unknown): s is RuleType =>\n isPojo(s) && 'field' in s && typeof s.field === 'string';\n\n/**\n * Determines if an object is a {@link RuleGroupType} or {@link RuleGroupTypeIC}.\n */\nexport const isRuleGroup = (rg: unknown): rg is RuleGroupTypeAny =>\n isPojo(rg) && Array.isArray(rg.rules);\n\n/**\n * Determines if an object is a {@link RuleGroupType}.\n */\nexport const isRuleGroupType = (rg: unknown): rg is RuleGroupType =>\n isRuleGroup(rg) && typeof rg.combinator === 'string';\n\n/**\n * Determines if an object is a {@link RuleGroupTypeIC}.\n */\nexport const isRuleGroupTypeIC = (rg: unknown): rg is RuleGroupTypeIC =>\n isRuleGroup(rg) && rg.combinator === undefined;\n"],"mappings":";;;;;;;AAMA,MAAa,MAAS,MAAa,OAAO,MAAM,WAAY,EAAE,aAAa,GAAS;;;;;AAMpF,MAAaA,iBAAuB,IAAI,OACtCC,aAAqB,OAAO,QAAQ,OAAO,OAAO,GAAG,OAAO,CAAC,QAAQ,OAAO,OAAO,GAAG,OAAO,CAC9F;;;;AAMD,MAAa,UAAU,QACrB,QAAQ,QAAQ,OAAO,QAAQ,WAAW,QAAQ,OAAO,eAAe,IAAI,KAAK,OAAO;;;;AAK1F,MAAa,0BAA0B,UACrC,UAAU,QAAQ,UAAU,UAAa,UAAU;;;;;;;ACfrD,MAAa,eAAe,OAC1B,OAAO,GAAG,IAAI,MAAM,QAAQ,GAAG,MAAM;;;;AAKvC,MAAa,mBAAmB,OAC9B,YAAY,GAAG,IAAI,OAAO,GAAG,eAAe;;;;AAK9C,MAAa,qBAAqB,OAChC,YAAY,GAAG,IAAI,GAAG,eAAe"}
@@ -1 +1 @@
1
- {"version":3,"file":"isRuleGroup-DqAs2x4E.js","names":["numericRegex: RegExp","numericQuantityRegex"],"sources":["../src/utils/misc.ts","../src/utils/isRuleGroup.ts"],"sourcesContent":["import { numericRegex as numericQuantityRegex } from 'numeric-quantity';\n\n/**\n * Converts a value to lowercase if it's a string, otherwise returns the value as is.\n */\n// istanbul ignore next\nexport const lc = <T>(v: T): T => (typeof v === 'string' ? (v.toLowerCase() as T) : v);\n\n/**\n * Regex matching numeric strings. Passes for positive/negative integers, decimals,\n * and E notation, with optional surrounding whitespace.\n */\nexport const numericRegex: RegExp = new RegExp(\n numericQuantityRegex.source.replace(/^\\^/, String.raw`^\\s*`).replace(/\\$$/, String.raw`\\s*$`)\n);\n\n/**\n * Determines if a variable is a plain old JavaScript object, aka POJO.\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isPojo = (obj: any): obj is Record<string, any> =>\n obj === null || typeof obj !== 'object' ? false : Object.getPrototypeOf(obj) === Object.prototype;\n\n/**\n * Simple helper to determine whether a value is null, undefined, or an empty string.\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const nullOrUndefinedOrEmpty = (value: any): value is null | undefined | '' =>\n value === null || value === undefined || value === '';\n","import type { RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC } from '../types';\nimport { isPojo } from './misc';\n\n/**\n * Determines if an object is a {@link RuleGroupType} or {@link RuleGroupTypeIC}.\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isRuleGroup = (rg: any): rg is RuleGroupTypeAny =>\n isPojo(rg) && Array.isArray(rg.rules);\n\n/**\n * Determines if an object is a {@link RuleGroupType}.\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isRuleGroupType = (rg: any): rg is RuleGroupType =>\n isRuleGroup(rg) && typeof rg.combinator === 'string';\n\n/**\n * Determines if an object is a {@link RuleGroupTypeIC}.\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isRuleGroupTypeIC = (rg: any): rg is RuleGroupTypeIC =>\n isRuleGroup(rg) && rg.combinator === undefined;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAa,MAAS,MAAa,OAAO,MAAM,WAAY,EAAE,aAAa,GAAS;;;;;AAMpF,MAAaA,eAAuB,IAAI,OACtCC,8BAAqB,OAAO,QAAQ,OAAO,OAAO,GAAG,OAAO,CAAC,QAAQ,OAAO,OAAO,GAAG,OAAO,CAC9F;;;;AAMD,MAAa,UAAU,QACrB,QAAQ,QAAQ,OAAO,QAAQ,WAAW,QAAQ,OAAO,eAAe,IAAI,KAAK,OAAO;;;;AAM1F,MAAa,0BAA0B,UACrC,UAAU,QAAQ,UAAU,UAAa,UAAU;;;;;;;ACrBrD,MAAa,eAAe,OAC1B,OAAO,GAAG,IAAI,MAAM,QAAQ,GAAG,MAAM;;;;AAMvC,MAAa,mBAAmB,OAC9B,YAAY,GAAG,IAAI,OAAO,GAAG,eAAe;;;;AAM9C,MAAa,qBAAqB,OAChC,YAAY,GAAG,IAAI,GAAG,eAAe"}
1
+ {"version":3,"file":"isRuleGroup-DqAs2x4E.js","names":["numericRegex: RegExp","numericQuantityRegex"],"sources":["../src/utils/misc.ts","../src/utils/isRuleGroup.ts"],"sourcesContent":["import { numericRegex as numericQuantityRegex } from 'numeric-quantity';\n\n/**\n * Converts a value to lowercase if it's a string, otherwise returns the value as is.\n */\n// istanbul ignore next\nexport const lc = <T>(v: T): T => (typeof v === 'string' ? (v.toLowerCase() as T) : v);\n\n/**\n * Regex matching numeric strings. Passes for positive/negative integers, decimals,\n * and E notation, with optional surrounding whitespace.\n */\nexport const numericRegex: RegExp = new RegExp(\n numericQuantityRegex.source.replace(/^\\^/, String.raw`^\\s*`).replace(/\\$$/, String.raw`\\s*$`)\n);\n\n/**\n * Determines if a variable is a plain old JavaScript object, aka POJO.\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isPojo = (obj: any): obj is Record<string, any> =>\n obj === null || typeof obj !== 'object' ? false : Object.getPrototypeOf(obj) === Object.prototype;\n\n/**\n * Simple helper to determine whether a value is null, undefined, or an empty string.\n */\nexport const nullOrUndefinedOrEmpty = (value: unknown): value is null | undefined | '' =>\n value === null || value === undefined || value === '';\n","import type { RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleType } from '../types';\nimport { isPojo } from './misc';\n\n/**\n * Determines if an object is a {@link RuleType} (only checks for a `field` property).\n */\nexport const isRuleType = (s: unknown): s is RuleType =>\n isPojo(s) && 'field' in s && typeof s.field === 'string';\n\n/**\n * Determines if an object is a {@link RuleGroupType} or {@link RuleGroupTypeIC}.\n */\nexport const isRuleGroup = (rg: unknown): rg is RuleGroupTypeAny =>\n isPojo(rg) && Array.isArray(rg.rules);\n\n/**\n * Determines if an object is a {@link RuleGroupType}.\n */\nexport const isRuleGroupType = (rg: unknown): rg is RuleGroupType =>\n isRuleGroup(rg) && typeof rg.combinator === 'string';\n\n/**\n * Determines if an object is a {@link RuleGroupTypeIC}.\n */\nexport const isRuleGroupTypeIC = (rg: unknown): rg is RuleGroupTypeIC =>\n isRuleGroup(rg) && rg.combinator === undefined;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAa,MAAS,MAAa,OAAO,MAAM,WAAY,EAAE,aAAa,GAAS;;;;;AAMpF,MAAaA,eAAuB,IAAI,OACtCC,8BAAqB,OAAO,QAAQ,OAAO,OAAO,GAAG,OAAO,CAAC,QAAQ,OAAO,OAAO,GAAG,OAAO,CAC9F;;;;AAMD,MAAa,UAAU,QACrB,QAAQ,QAAQ,OAAO,QAAQ,WAAW,QAAQ,OAAO,eAAe,IAAI,KAAK,OAAO;;;;AAK1F,MAAa,0BAA0B,UACrC,UAAU,QAAQ,UAAU,UAAa,UAAU;;;;;;;ACfrD,MAAa,eAAe,OAC1B,OAAO,GAAG,IAAI,MAAM,QAAQ,GAAG,MAAM;;;;AAKvC,MAAa,mBAAmB,OAC9B,YAAY,GAAG,IAAI,OAAO,GAAG,eAAe;;;;AAK9C,MAAa,qBAAqB,OAChC,YAAY,GAAG,IAAI,GAAG,eAAe"}
@@ -0,0 +1,11 @@
1
+ //#region src/utils/objectUtils.ts
2
+ /**
3
+ * A strongly-typed version of `Object.keys()`.
4
+ *
5
+ * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-keys.ts)
6
+ */
7
+ const objectKeys = Object.keys;
8
+
9
+ //#endregion
10
+ export { objectKeys };
11
+ //# sourceMappingURL=objectUtils-BtWdcZVG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectUtils-BtWdcZVG.mjs","names":[],"sources":["../src/utils/objectUtils.ts"],"sourcesContent":["// All code in this file is adapted from:\n// npm: https://www.npmjs.com/package/ts-extras\n// src: https://github.com/sindresorhus/ts-extras\n\n/**\n * Original looked like this (not sure why template string is used):\n * ```\n * type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;\n * ```\n */\ntype ObjectKeys<T extends object> = Exclude<keyof T, symbol>;\n\n/**\n * A strongly-typed version of `Object.keys()`.\n *\n * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-keys.ts)\n */\nexport const objectKeys = Object.keys as <Type extends object>(\n value: Type\n) => Array<ObjectKeys<Type>>;\n\n/**\n * A strongly-typed version of `Object.entries()`.\n *\n * [Original source](https://github.com/sindresorhus/ts-extras/blob/44f57392c5f027268330771996c4fdf9260b22d6/source/object-entries.ts)\n */\nexport const objectEntries = Object.entries as <Type extends Record<PropertyKey, unknown>>(\n value: Type\n) => Array<[ObjectKeys<Type>, Type[ObjectKeys<Type>]]>;\n"],"mappings":";;;;;;AAiBA,MAAa,aAAa,OAAO"}
@@ -0,0 +1,102 @@
1
+ import { isPojo } from "./isRuleGroup-CnhYpLOM.mjs";
2
+ import { produce } from "immer";
3
+
4
+ //#region src/utils/optGroupUtils.ts
5
+ const isOptionWithName = (opt) => isPojo(opt) && "name" in opt && typeof opt.name === "string";
6
+ const isOptionWithValue = (opt) => isPojo(opt) && "value" in opt && typeof opt.value === "string";
7
+ /**
8
+ * Converts an {@link Option} or {@link ValueOption} (i.e., {@link BaseOption})
9
+ * into a {@link FullOption}. Full options are left unchanged.
10
+ *
11
+ * @group Option Lists
12
+ */
13
+ function toFullOption(opt, baseProperties, labelMap) {
14
+ return produce((draft) => {
15
+ const idObj = {};
16
+ let needsUpdating = !!baseProperties;
17
+ if (typeof draft === "string") return {
18
+ ...baseProperties,
19
+ name: draft,
20
+ value: draft,
21
+ label: labelMap?.[draft] ?? draft
22
+ };
23
+ if (isOptionWithName(draft) && !isOptionWithValue(draft)) {
24
+ idObj.value = draft.name;
25
+ needsUpdating = true;
26
+ } else if (!isOptionWithName(draft) && isOptionWithValue(draft)) {
27
+ idObj.name = draft.value;
28
+ needsUpdating = true;
29
+ }
30
+ if (needsUpdating) return Object.assign({}, baseProperties, draft, idObj);
31
+ })(opt);
32
+ }
33
+ /**
34
+ * Converts an {@link OptionList} or {@link FlexibleOptionList} into a {@link FullOptionList}.
35
+ * Lists of full options are left unchanged.
36
+ *
37
+ * @group Option Lists
38
+ */
39
+ function toFullOptionList(optList, baseProperties, labelMap) {
40
+ if (!Array.isArray(optList)) return [];
41
+ return produce((draft) => {
42
+ if (isFlexibleOptionGroupArray(draft)) for (const optGroup of draft) for (const [idx, opt] of optGroup.options.entries()) optGroup.options[idx] = toFullOption(opt, baseProperties, labelMap);
43
+ else for (const [idx, opt] of draft.entries()) draft[idx] = toFullOption(opt, baseProperties, labelMap);
44
+ })(optList);
45
+ }
46
+ /**
47
+ * Generates a new array of objects with duplicates removed based
48
+ * on the identifying property (`value` or `name`)
49
+ *
50
+ * @group Option Lists
51
+ */
52
+ const uniqByIdentifier = (originalArray) => {
53
+ const names = /* @__PURE__ */ new Set();
54
+ const newArray = [];
55
+ for (const el of originalArray) if (!names.has(el.value ?? el.name)) {
56
+ names.add(el.value ?? el.name);
57
+ newArray.push(el);
58
+ }
59
+ return originalArray.length === newArray.length ? originalArray : newArray;
60
+ };
61
+ /**
62
+ * Determines if an {@link OptionList} is an {@link OptionGroup} array.
63
+ *
64
+ * @group Option Lists
65
+ */
66
+ const isOptionGroupArray = (arr) => Array.isArray(arr) && arr.length > 0 && isPojo(arr[0]) && "options" in arr[0] && Array.isArray(arr[0].options);
67
+ /**
68
+ * Determines if an array is a flat array of {@link FlexibleOption}.
69
+ *
70
+ * @group Option Lists
71
+ */
72
+ const isFlexibleOptionArray = (arr) => {
73
+ let isFOA = false;
74
+ if (Array.isArray(arr)) for (const o of arr) if (isOptionWithName(o) || isOptionWithValue(o)) isFOA = true;
75
+ else return false;
76
+ return isFOA;
77
+ };
78
+ /**
79
+ * Determines if a {@link FlexibleOptionList} is a {@link FlexibleOptionGroup} array.
80
+ *
81
+ * @group Option Lists
82
+ */
83
+ const isFlexibleOptionGroupArray = (arr, { allowEmpty = false } = {}) => {
84
+ let isFOGA = false;
85
+ if (Array.isArray(arr)) for (const og of arr) if (isPojo(og) && "options" in og && (isFlexibleOptionArray(og.options) || allowEmpty && Array.isArray(og.options) && og.options.length === 0)) isFOGA = true;
86
+ else return false;
87
+ return isFOGA;
88
+ };
89
+ function getOption(arr, name) {
90
+ return (isFlexibleOptionGroupArray(arr, { allowEmpty: true }) ? arr.flatMap((og) => og.options) : arr).find((op) => op.value === name || op.name === name);
91
+ }
92
+ /**
93
+ * Flattens {@link FlexibleOptionGroup} arrays into {@link BaseOption} arrays.
94
+ * If the array is already flat, it is returned as is.
95
+ *
96
+ * @group Option Lists
97
+ */
98
+ const toFlatOptionArray = (arr) => uniqByIdentifier(isOptionGroupArray(arr) ? arr.flatMap((og) => og.options) : arr);
99
+
100
+ //#endregion
101
+ export { getOption, isFlexibleOptionArray, isFlexibleOptionGroupArray, toFlatOptionArray, toFullOption, toFullOptionList };
102
+ //# sourceMappingURL=optGroupUtils-Duv-M8rf.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optGroupUtils-Duv-M8rf.mjs","names":["idObj: { name?: string; value?: string }","newArray: T[]"],"sources":["../src/utils/optGroupUtils.ts"],"sourcesContent":["import type { Draft } from 'immer';\nimport { produce } from 'immer';\nimport type {\n BaseOption,\n BaseOptionMap,\n FlexibleOption,\n FlexibleOptionGroup,\n FlexibleOptionList,\n FullOption,\n FullOptionList,\n GetOptionIdentifierType,\n Option,\n OptionGroup,\n RequireAtLeastOne,\n ToFullOption,\n ValueOption,\n WithUnknownIndex,\n} from '../types';\nimport { isPojo } from './misc';\n\nconst isOptionWithName = (opt: BaseOption): opt is Option =>\n isPojo(opt) && 'name' in opt && typeof opt.name === 'string';\nconst isOptionWithValue = (opt: BaseOption): opt is ValueOption =>\n isPojo(opt) && 'value' in opt && typeof opt.value === 'string';\n\n/**\n * Converts an {@link Option} or {@link ValueOption} (i.e., {@link BaseOption})\n * into a {@link FullOption}. Full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOption<Opt extends BaseOption>(\n opt: Opt | string,\n baseProperties?: Record<string, unknown>,\n labelMap?: Record<string, unknown>\n): ToFullOption<Opt> {\n const recipe: (o: Opt | string) => ToFullOption<Opt> = produce(draft => {\n const idObj: { name?: string; value?: string } = {};\n let needsUpdating = !!baseProperties;\n\n if (typeof draft === 'string') {\n return {\n ...baseProperties,\n name: draft,\n value: draft,\n label: labelMap?.[draft] ?? draft,\n } as Draft<Opt>;\n }\n\n if (isOptionWithName(draft) && !isOptionWithValue(draft)) {\n idObj.value = draft.name;\n needsUpdating = true;\n } else if (!isOptionWithName(draft) && isOptionWithValue(draft)) {\n idObj.name = draft.value;\n needsUpdating = true;\n }\n\n if (needsUpdating) {\n return Object.assign({}, baseProperties, draft, idObj);\n }\n });\n return recipe(opt);\n}\n\n/**\n * Converts an {@link OptionList} or {@link FlexibleOptionList} into a {@link FullOptionList}.\n * Lists of full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOptionList<Opt extends BaseOption>(\n optList: unknown[],\n baseProperties?: Record<string, unknown>,\n labelMap?: Record<string, unknown>\n): FullOptionList<Opt> {\n if (!Array.isArray(optList)) {\n return [] as unknown as FullOptionList<Opt>;\n }\n\n const recipe: (ol: FlexibleOptionList<Opt>) => FullOptionList<Opt> = produce(draft => {\n if (isFlexibleOptionGroupArray(draft)) {\n for (const optGroup of draft) {\n for (const [idx, opt] of optGroup.options.entries())\n optGroup.options[idx] = toFullOption(opt, baseProperties, labelMap);\n }\n } else {\n for (const [idx, opt] of (draft as Opt[]).entries())\n draft[idx] = toFullOption(opt, baseProperties, labelMap);\n }\n });\n\n return recipe(optList as FlexibleOptionList<Opt>);\n}\n\n/**\n * Converts a {@link FlexibleOptionList} into a {@link FullOptionList}.\n * Lists of full options are left unchanged.\n *\n * @group Option Lists\n */\nexport function toFullOptionMap<OptMap extends BaseOptionMap>(\n optMap: OptMap,\n baseProperties?: Record<string, unknown>\n): OptMap extends BaseOptionMap<infer V, infer K> ? Partial<Record<K, ToFullOption<V>>> : never {\n type FullOptMapType =\n OptMap extends BaseOptionMap<infer VT, infer KT>\n ? Partial<Record<KT, ToFullOption<VT>>>\n : never;\n\n return Object.fromEntries(\n (Object.entries(optMap) as [string, FlexibleOption][]).map(([k, v]) => [\n k,\n toFullOption(v, baseProperties),\n ])\n ) as FullOptMapType;\n}\n\n/**\n * @deprecated Renamed to {@link uniqByIdentifier}.\n *\n * @group Option Lists\n */\nexport const uniqByName = <\n T extends { name: string; value?: string } | { name?: string; value: string },\n>(\n originalArray: T[]\n): T[] => uniqByIdentifier(originalArray);\n\n/**\n * Generates a new array of objects with duplicates removed based\n * on the identifying property (`value` or `name`)\n *\n * @group Option Lists\n */\nexport const uniqByIdentifier = <\n T extends RequireAtLeastOne<{ name: string; value: string }, 'name' | 'value'>,\n>(\n originalArray: T[]\n): T[] => {\n const names = new Set<string>();\n const newArray: T[] = [];\n for (const el of originalArray) {\n if (!names.has((el.value ?? el.name)!)) {\n names.add((el.value ?? el.name)!);\n newArray.push(el);\n }\n }\n return originalArray.length === newArray.length ? originalArray : newArray;\n};\n\n/**\n * Determines if an {@link OptionList} is an {@link OptionGroup} array.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isOptionGroupArray = (arr: any): arr is OptionGroup<BaseOption>[] =>\n Array.isArray(arr) &&\n arr.length > 0 &&\n isPojo(arr[0]) &&\n 'options' in arr[0] &&\n Array.isArray(arr[0].options);\n\n/**\n * Determines if an array is a flat array of {@link FlexibleOption}.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isFlexibleOptionArray = (arr: any): arr is FlexibleOption[] => {\n let isFOA = false;\n if (Array.isArray(arr)) {\n for (const o of arr) {\n if (isOptionWithName(o) || isOptionWithValue(o)) {\n isFOA = true;\n } else {\n return false;\n }\n }\n }\n return isFOA;\n};\n\n/**\n * Determines if an array is a flat array of {@link FullOption}.\n *\n * @group Option Lists\n */\n// oxlint-disable-next-line typescript/no-explicit-any\nexport const isFullOptionArray = (arr: any): arr is FullOption[] => {\n let isFOA = false;\n if (Array.isArray(arr)) {\n for (const o of arr) {\n if (isOptionWithName(o) && isOptionWithValue(o)) {\n isFOA = true;\n } else {\n return false;\n }\n }\n }\n return isFOA;\n};\n\n/**\n * Determines if a {@link FlexibleOptionList} is a {@link FlexibleOptionGroup} array.\n *\n * @group Option Lists\n */\nexport const isFlexibleOptionGroupArray = (\n // oxlint-disable-next-line typescript/no-explicit-any\n arr: any,\n { allowEmpty = false }: { allowEmpty?: boolean } = {}\n): arr is FlexibleOptionGroup[] => {\n let isFOGA = false;\n if (Array.isArray(arr)) {\n for (const og of arr) {\n if (\n isPojo(og) &&\n 'options' in og &&\n (isFlexibleOptionArray(og.options) ||\n (allowEmpty && Array.isArray(og.options) && og.options.length === 0))\n ) {\n isFOGA = true;\n } else {\n return false;\n }\n }\n }\n return isFOGA;\n};\n\n/**\n * Determines if a {@link FlexibleOptionList} is a {@link OptionGroup} array of {@link FullOption}.\n *\n * @group Option Lists\n */\nexport const isFullOptionGroupArray = (\n // oxlint-disable-next-line typescript/no-explicit-any\n arr: any,\n { allowEmpty = false }: { allowEmpty?: boolean } = {}\n): arr is OptionGroup<FullOption>[] => {\n let isFOGA = false;\n if (Array.isArray(arr)) {\n for (const og of arr) {\n if (\n isPojo(og) &&\n 'options' in og &&\n (isFullOptionArray(og.options) ||\n (allowEmpty && Array.isArray(og.options) && og.options.length === 0))\n ) {\n isFOGA = true;\n } else {\n return false;\n }\n }\n }\n return isFOGA;\n};\n\n/**\n * Gets the option from an {@link OptionList} with the given `name`. Handles\n * {@link Option} arrays as well as {@link OptionGroup} arrays.\n *\n * @group Option Lists\n */\nexport function getOption<OptType extends FullOption>(\n arr: FullOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends ValueOption>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends Option>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined;\nexport function getOption<OptType extends BaseOption>(\n arr: FlexibleOptionList<OptType>,\n name: string\n): OptType | undefined {\n const options = isFlexibleOptionGroupArray(arr, { allowEmpty: true })\n ? arr.flatMap(og => og.options)\n : arr;\n return options.find(op => op.value === name || op.name === name) as OptType | undefined;\n}\n\n/**\n * Gets the first option from an {@link OptionList}.\n *\n * @group Option Lists\n */\nexport function getFirstOption<Opt extends FullOption>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends ValueOption>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends Option>(\n arr?: OptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null;\nexport function getFirstOption<Opt extends BaseOption>(\n arr?: FlexibleOptionGroup<Opt>[] | Opt[]\n): GetOptionIdentifierType<Opt> | null {\n if (!Array.isArray(arr) || arr.length === 0) {\n return null;\n } else if (isFlexibleOptionGroupArray(arr, { allowEmpty: true })) {\n for (const og of arr) {\n if (og.options.length > 0) {\n return (og.options[0].value ?? og.options[0].name) as GetOptionIdentifierType<Opt>;\n }\n }\n // istanbul ignore next\n return null;\n }\n\n return (arr[0].value ?? arr[0].name) as GetOptionIdentifierType<Opt>;\n}\n\n/**\n * Flattens {@link FlexibleOptionGroup} arrays into {@link BaseOption} arrays.\n * If the array is already flat, it is returned as is.\n *\n * @group Option Lists\n */\nexport const toFlatOptionArray = <T extends FullOption, OL extends FullOptionList<T>>(arr: OL) =>\n uniqByIdentifier(isOptionGroupArray(arr) ? arr.flatMap(og => og.options) : arr) as T[];\n\n/**\n * Generates a new {@link OptionGroup} array with duplicates\n * removed based on the identifying property (`value` or `name`).\n *\n * @group Option Lists\n */\nexport const uniqOptGroups = <T extends BaseOption>(\n originalArray: FlexibleOptionGroup<T>[]\n): OptionGroup<ToFullOption<T>>[] => {\n type K = T extends BaseOption<infer KT> ? KT : never;\n const labels = new Set<string>();\n const names = new Set<K>();\n const newArray: OptionGroup<ToFullOption<T>>[] = [];\n for (const el of originalArray) {\n if (!labels.has(el.label)) {\n labels.add(el.label);\n const optionsForThisGroup: WithUnknownIndex<ToFullOption<T>>[] = [];\n for (const opt of el.options) {\n if (!names.has((opt.value ?? opt.name) as K)) {\n names.add((opt.value ?? opt.name) as K);\n optionsForThisGroup.push(toFullOption(opt) as WithUnknownIndex<ToFullOption<T>>);\n }\n }\n newArray.push({ ...el, options: optionsForThisGroup });\n }\n }\n return newArray;\n};\n\n/**\n * Generates a new {@link Option} or {@link OptionGroup} array with duplicates\n * removed based on the identifier property (`value` or `name`).\n *\n * @group Option Lists\n */\nexport const uniqOptList = <T extends BaseOption>(\n originalArray: FlexibleOptionList<T>\n): WithUnknownIndex<BaseOption & FullOption>[] | OptionGroup<ToFullOption<T>>[] => {\n if (isFlexibleOptionGroupArray(originalArray)) {\n return uniqOptGroups(originalArray) as OptionGroup<ToFullOption<T>>[];\n }\n return uniqByIdentifier((originalArray as BaseOption[]).map(o => toFullOption(o)));\n};\n"],"mappings":";;;;AAoBA,MAAM,oBAAoB,QACxB,OAAO,IAAI,IAAI,UAAU,OAAO,OAAO,IAAI,SAAS;AACtD,MAAM,qBAAqB,QACzB,OAAO,IAAI,IAAI,WAAW,OAAO,OAAO,IAAI,UAAU;;;;;;;AAQxD,SAAgB,aACd,KACA,gBACA,UACmB;AA0BnB,QAzBuD,SAAQ,UAAS;EACtE,MAAMA,QAA2C,EAAE;EACnD,IAAI,gBAAgB,CAAC,CAAC;AAEtB,MAAI,OAAO,UAAU,SACnB,QAAO;GACL,GAAG;GACH,MAAM;GACN,OAAO;GACP,OAAO,WAAW,UAAU;GAC7B;AAGH,MAAI,iBAAiB,MAAM,IAAI,CAAC,kBAAkB,MAAM,EAAE;AACxD,SAAM,QAAQ,MAAM;AACpB,mBAAgB;aACP,CAAC,iBAAiB,MAAM,IAAI,kBAAkB,MAAM,EAAE;AAC/D,SAAM,OAAO,MAAM;AACnB,mBAAgB;;AAGlB,MAAI,cACF,QAAO,OAAO,OAAO,EAAE,EAAE,gBAAgB,OAAO,MAAM;GAExD,CACY,IAAI;;;;;;;;AASpB,SAAgB,iBACd,SACA,gBACA,UACqB;AACrB,KAAI,CAAC,MAAM,QAAQ,QAAQ,CACzB,QAAO,EAAE;AAeX,QAZqE,SAAQ,UAAS;AACpF,MAAI,2BAA2B,MAAM,CACnC,MAAK,MAAM,YAAY,MACrB,MAAK,MAAM,CAAC,KAAK,QAAQ,SAAS,QAAQ,SAAS,CACjD,UAAS,QAAQ,OAAO,aAAa,KAAK,gBAAgB,SAAS;MAGvE,MAAK,MAAM,CAAC,KAAK,QAAS,MAAgB,SAAS,CACjD,OAAM,OAAO,aAAa,KAAK,gBAAgB,SAAS;GAE5D,CAEY,QAAmC;;;;;;;;AA2CnD,MAAa,oBAGX,kBACQ;CACR,MAAM,wBAAQ,IAAI,KAAa;CAC/B,MAAMC,WAAgB,EAAE;AACxB,MAAK,MAAM,MAAM,cACf,KAAI,CAAC,MAAM,IAAK,GAAG,SAAS,GAAG,KAAO,EAAE;AACtC,QAAM,IAAK,GAAG,SAAS,GAAG,KAAO;AACjC,WAAS,KAAK,GAAG;;AAGrB,QAAO,cAAc,WAAW,SAAS,SAAS,gBAAgB;;;;;;;AASpE,MAAa,sBAAsB,QACjC,MAAM,QAAQ,IAAI,IAClB,IAAI,SAAS,KACb,OAAO,IAAI,GAAG,IACd,aAAa,IAAI,MACjB,MAAM,QAAQ,IAAI,GAAG,QAAQ;;;;;;AAQ/B,MAAa,yBAAyB,QAAsC;CAC1E,IAAI,QAAQ;AACZ,KAAI,MAAM,QAAQ,IAAI,CACpB,MAAK,MAAM,KAAK,IACd,KAAI,iBAAiB,EAAE,IAAI,kBAAkB,EAAE,CAC7C,SAAQ;KAER,QAAO;AAIb,QAAO;;;;;;;AA4BT,MAAa,8BAEX,KACA,EAAE,aAAa,UAAoC,EAAE,KACpB;CACjC,IAAI,SAAS;AACb,KAAI,MAAM,QAAQ,IAAI,CACpB,MAAK,MAAM,MAAM,IACf,KACE,OAAO,GAAG,IACV,aAAa,OACZ,sBAAsB,GAAG,QAAQ,IAC/B,cAAc,MAAM,QAAQ,GAAG,QAAQ,IAAI,GAAG,QAAQ,WAAW,GAEpE,UAAS;KAET,QAAO;AAIb,QAAO;;AAiDT,SAAgB,UACd,KACA,MACqB;AAIrB,SAHgB,2BAA2B,KAAK,EAAE,YAAY,MAAM,CAAC,GACjE,IAAI,SAAQ,OAAM,GAAG,QAAQ,GAC7B,KACW,MAAK,OAAM,GAAG,UAAU,QAAQ,GAAG,SAAS,KAAK;;;;;;;;AAyClE,MAAa,qBAAyE,QACpF,iBAAiB,mBAAmB,IAAI,GAAG,IAAI,SAAQ,OAAM,GAAG,QAAQ,GAAG,IAAI"}
@@ -0,0 +1,34 @@
1
+ import { DefaultRuleGroupType, DefaultRuleGroupTypeIC, Except } from "./basic-BfD-7CN3.mjs";
2
+ import { ParserCommonOptions } from "./import-BwbbP4oU.mjs";
3
+
4
+ //#region src/utils/parseCEL/parseCEL.d.ts
5
+
6
+ /**
7
+ * Options object for {@link parseCEL}.
8
+ */
9
+ interface ParseCELOptions extends ParserCommonOptions {}
10
+ /**
11
+ * Converts a CEL string expression into a query suitable for the
12
+ * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
13
+ * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).
14
+ */
15
+ declare function parseCEL(cel: string): DefaultRuleGroupType;
16
+ /**
17
+ * Converts a CEL string expression into a query suitable for the
18
+ * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
19
+ * ({@link index!DefaultRuleGroupType DefaultRuleGroupType}).
20
+ */
21
+ declare function parseCEL(cel: string, options: Except<ParseCELOptions, "independentCombinators"> & {
22
+ independentCombinators?: false;
23
+ }): DefaultRuleGroupType;
24
+ /**
25
+ * Converts a CEL string expression into a query suitable for the
26
+ * {@link index!QueryBuilder QueryBuilder} component's `query` or `defaultQuery` props
27
+ * ({@link index!DefaultRuleGroupTypeIC DefaultRuleGroupTypeIC}).
28
+ */
29
+ declare function parseCEL(cel: string, options: Except<ParseCELOptions, "independentCombinators"> & {
30
+ independentCombinators: true;
31
+ }): DefaultRuleGroupTypeIC;
32
+ //#endregion
33
+ export { ParseCELOptions, parseCEL };
34
+ //# sourceMappingURL=parseCEL.d.mts.map