@genesislcap/expression-builder 14.248.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 (114) hide show
  1. package/FUTURE.md +164 -0
  2. package/README.md +3 -0
  3. package/custom-elements-manifest.config.js +14 -0
  4. package/dist/custom-elements.json +1971 -0
  5. package/dist/dts/config/combinators.d.ts +6 -0
  6. package/dist/dts/config/combinators.d.ts.map +1 -0
  7. package/dist/dts/config/index.d.ts +3 -0
  8. package/dist/dts/config/index.d.ts.map +1 -0
  9. package/dist/dts/config/operators.d.ts +4 -0
  10. package/dist/dts/config/operators.d.ts.map +1 -0
  11. package/dist/dts/index.d.ts +6 -0
  12. package/dist/dts/index.d.ts.map +1 -0
  13. package/dist/dts/main/events.d.ts +50 -0
  14. package/dist/dts/main/events.d.ts.map +1 -0
  15. package/dist/dts/main/expression-builder.d.ts +44 -0
  16. package/dist/dts/main/expression-builder.d.ts.map +1 -0
  17. package/dist/dts/main/expression-builder.helpers.d.ts +19 -0
  18. package/dist/dts/main/expression-builder.helpers.d.ts.map +1 -0
  19. package/dist/dts/main/expression-builder.styles.d.ts +3 -0
  20. package/dist/dts/main/expression-builder.styles.d.ts.map +1 -0
  21. package/dist/dts/main/expression-builder.template.d.ts +4 -0
  22. package/dist/dts/main/expression-builder.template.d.ts.map +1 -0
  23. package/dist/dts/main/expression-group/expression-group.d.ts +18 -0
  24. package/dist/dts/main/expression-group/expression-group.d.ts.map +1 -0
  25. package/dist/dts/main/expression-group/expression-group.styles.d.ts +2 -0
  26. package/dist/dts/main/expression-group/expression-group.styles.d.ts.map +1 -0
  27. package/dist/dts/main/expression-group/expression-group.template.d.ts +3 -0
  28. package/dist/dts/main/expression-group/expression-group.template.d.ts.map +1 -0
  29. package/dist/dts/main/expression-rule/expression-rule.d.ts +27 -0
  30. package/dist/dts/main/expression-rule/expression-rule.d.ts.map +1 -0
  31. package/dist/dts/main/expression-rule/expression-rule.helpers.d.ts +4 -0
  32. package/dist/dts/main/expression-rule/expression-rule.helpers.d.ts.map +1 -0
  33. package/dist/dts/main/expression-rule/expression-rule.styles.d.ts +2 -0
  34. package/dist/dts/main/expression-rule/expression-rule.styles.d.ts.map +1 -0
  35. package/dist/dts/main/expression-rule/expression-rule.template.d.ts +3 -0
  36. package/dist/dts/main/expression-rule/expression-rule.template.d.ts.map +1 -0
  37. package/dist/dts/main/index.d.ts +4 -0
  38. package/dist/dts/main/index.d.ts.map +1 -0
  39. package/dist/dts/main/rule-field/rule-field.d.ts +15 -0
  40. package/dist/dts/main/rule-field/rule-field.d.ts.map +1 -0
  41. package/dist/dts/main/rule-field/rule-field.template.d.ts +3 -0
  42. package/dist/dts/main/rule-field/rule-field.template.d.ts.map +1 -0
  43. package/dist/dts/main/rule-operator/rule-operator.d.ts +17 -0
  44. package/dist/dts/main/rule-operator/rule-operator.d.ts.map +1 -0
  45. package/dist/dts/main/rule-operator/rule-operator.template.d.ts +3 -0
  46. package/dist/dts/main/rule-operator/rule-operator.template.d.ts.map +1 -0
  47. package/dist/dts/main/rule-value/rule-value.d.ts +17 -0
  48. package/dist/dts/main/rule-value/rule-value.d.ts.map +1 -0
  49. package/dist/dts/main/rule-value/rule-value.helpers.d.ts +6 -0
  50. package/dist/dts/main/rule-value/rule-value.helpers.d.ts.map +1 -0
  51. package/dist/dts/main/rule-value/rule-value.styles.d.ts +2 -0
  52. package/dist/dts/main/rule-value/rule-value.styles.d.ts.map +1 -0
  53. package/dist/dts/main/rule-value/rule-value.template.d.ts +3 -0
  54. package/dist/dts/main/rule-value/rule-value.template.d.ts.map +1 -0
  55. package/dist/dts/types/index.d.ts +3 -0
  56. package/dist/dts/types/index.d.ts.map +1 -0
  57. package/dist/dts/types/private.types.d.ts +21 -0
  58. package/dist/dts/types/private.types.d.ts.map +1 -0
  59. package/dist/dts/types/public.types.d.ts +160 -0
  60. package/dist/dts/types/public.types.d.ts.map +1 -0
  61. package/dist/dts/utils/data-model.d.ts +27 -0
  62. package/dist/dts/utils/data-model.d.ts.map +1 -0
  63. package/dist/dts/utils/formatting.d.ts +13 -0
  64. package/dist/dts/utils/formatting.d.ts.map +1 -0
  65. package/dist/dts/utils/index.d.ts +4 -0
  66. package/dist/dts/utils/index.d.ts.map +1 -0
  67. package/dist/dts/utils/misc.d.ts +14 -0
  68. package/dist/dts/utils/misc.d.ts.map +1 -0
  69. package/dist/esm/config/combinators.js +31 -0
  70. package/dist/esm/config/index.js +2 -0
  71. package/dist/esm/config/operators.js +91 -0
  72. package/dist/esm/index.js +5 -0
  73. package/dist/esm/main/events.js +13 -0
  74. package/dist/esm/main/expression-builder.helpers.js +129 -0
  75. package/dist/esm/main/expression-builder.js +157 -0
  76. package/dist/esm/main/expression-builder.styles.js +177 -0
  77. package/dist/esm/main/expression-builder.template.js +13 -0
  78. package/dist/esm/main/expression-group/expression-group.js +121 -0
  79. package/dist/esm/main/expression-group/expression-group.styles.js +45 -0
  80. package/dist/esm/main/expression-group/expression-group.template.js +102 -0
  81. package/dist/esm/main/expression-rule/expression-rule.helpers.js +25 -0
  82. package/dist/esm/main/expression-rule/expression-rule.js +203 -0
  83. package/dist/esm/main/expression-rule/expression-rule.styles.js +57 -0
  84. package/dist/esm/main/expression-rule/expression-rule.template.js +65 -0
  85. package/dist/esm/main/index.js +3 -0
  86. package/dist/esm/main/rule-field/rule-field.js +48 -0
  87. package/dist/esm/main/rule-field/rule-field.template.js +46 -0
  88. package/dist/esm/main/rule-operator/rule-operator.js +60 -0
  89. package/dist/esm/main/rule-operator/rule-operator.template.js +46 -0
  90. package/dist/esm/main/rule-value/rule-value.helpers.js +17 -0
  91. package/dist/esm/main/rule-value/rule-value.js +115 -0
  92. package/dist/esm/main/rule-value/rule-value.styles.js +11 -0
  93. package/dist/esm/main/rule-value/rule-value.template.js +106 -0
  94. package/dist/esm/types/index.js +2 -0
  95. package/dist/esm/types/private.types.js +1 -0
  96. package/dist/esm/types/public.types.js +1 -0
  97. package/dist/esm/utils/data-model.js +51 -0
  98. package/dist/esm/utils/formatting.js +23 -0
  99. package/dist/esm/utils/index.js +3 -0
  100. package/dist/esm/utils/misc.js +62 -0
  101. package/dist/expression-builder.api.json +212 -0
  102. package/dist/expression-builder.d.ts +322 -0
  103. package/dist/tsdoc-metadata.json +11 -0
  104. package/docs/.gitattributes +2 -0
  105. package/docs/api/expression-builder.config.md +6 -0
  106. package/docs/api/expression-builder.md +13 -0
  107. package/docs/api/expression-builder.types.md +6 -0
  108. package/docs/api/index.md +12 -0
  109. package/docs/api-report.md +260 -0
  110. package/license.txt +46 -0
  111. package/package.json +66 -0
  112. package/playwright.config.ts +5 -0
  113. package/test/unit/test.ts +1 -0
  114. package/tsdoc.json +4 -0
package/FUTURE.md ADDED
@@ -0,0 +1,164 @@
1
+ I discussed with an AI about how we can improve the implementation to be more efficient in future
2
+
3
+ =======user 3========
4
+
5
+ Great, I will build this implementaiton. This should suit me for now. However I have a question about a future improvement, just to see whether this solution can be improved in future or whether it would block it off. Is there a way to assign IDs in a cleverer way to make searching for parts of the state to update quicker to be more efficient? This probably isn't necessary unless the user creates a huge nested expression, but it's still good for me to know about this
6
+
7
+ =======response========
8
+ Okay, that's a great question. While the simple incremental ID approach works well, there are strategies for potentially optimizing the state update process, especially for very large, deeply nested query builders. These strategies involve creating more structured or hierarchical IDs that make searching more efficient. However, keep in mind that the added complexity may not be worth it unless you actually encounter performance issues with large expressions.
9
+
10
+ Here are a few ideas:
11
+
12
+ **1. Hierarchical IDs (Path-Based IDs)**
13
+
14
+ * **Concept:** Embed the path from the root to the node within the ID itself. This allows you to quickly locate the node without traversing the entire tree.
15
+
16
+ * **Implementation:**
17
+
18
+ * When creating a new group or rule, construct its ID by concatenating the IDs of its ancestors, separated by a delimiter (e.g., "/").
19
+
20
+ ```typescript
21
+ // Example (assuming Group and Rule now have a parentId property)
22
+
23
+ generateRuleId(parentId: string | null): string {
24
+ return `${parentId ? parentId + '/' : ''}rule-${this.nextRuleId++}`;
25
+ }
26
+
27
+ generateGroupId(parentId: string | null): string {
28
+ return `${parentId ? parentId + '/' : ''}group-${this.nextGroupId++}`;
29
+ }
30
+ ```
31
+
32
+ * To update a node, you can split the hierarchical ID to traverse down the tree:
33
+
34
+ ```typescript
35
+ function updateValue(model: Group, path: string, newValue: any) {
36
+ const ids = path.split('/');
37
+ let current: any = model;
38
+
39
+ for (let i = 0; i < ids.length - 1; i++) {
40
+ const id = ids[i];
41
+ current = current.rules.find(r => ('groupId' in r && r.groupId === id) || ('ruleId' in r && r.ruleId === id)); //Union type issues
42
+ if (!current) return; // Path doesn't exist
43
+ }
44
+
45
+ const lastId = ids[ids.length - 1];
46
+ const target = current.rules.find(r => ('groupId' in r && r.groupId === lastId) || ('ruleId' in r && r.ruleId === lastId));
47
+
48
+ if (target) {
49
+ target.value = newValue; // Or, make an immutable update here
50
+ }
51
+ }
52
+ ```
53
+
54
+ * **Benefits:**
55
+
56
+ * **Faster Lookups:** You can traverse directly to the node instead of searching the entire tree.
57
+ * **Clear Node Context:** The ID provides immediate information about the node's position in the hierarchy.
58
+
59
+ * **Cons:**
60
+
61
+ * **Longer IDs:** Hierarchical IDs can become quite long in deeply nested expressions.
62
+ * **More Complex ID Parsing:** Extracting information from the ID requires parsing the path.
63
+ * **Immutability Challenges:** Path based mutations can be tricky as the ID is essential for finding the target object
64
+
65
+ * **Use Cases:** This approach is most beneficial when you perform frequent updates to specific nodes and when the depth of nesting can be significant.
66
+
67
+ **2. Indexes and Maps**
68
+
69
+ * **Concept:** Maintain separate data structures (maps/dictionaries) that index nodes by their IDs. This provides O(1) lookup by ID.
70
+
71
+ * **Implementation:**
72
+
73
+ 1. **Node Map:**
74
+
75
+ ```typescript
76
+ // expression-builder.ts
77
+ @observable nodeMap: {[id:string]: Rule | Group} = {}; // Or Map<string, Rule | Group>
78
+ ```
79
+
80
+ 2. **Update Node Map:** When creating or deleting a node, update the `nodeMap`.
81
+
82
+ ```typescript
83
+ // When creating a rule:
84
+ const ruleId = this.generateRuleId();
85
+ const newRule: Rule = {
86
+ config: this.config,
87
+ ruleId: ruleId
88
+ };
89
+ this.nodeMap = {...this.nodeMap, [ruleId]: newRule}
90
+
91
+ //When deleting a rule
92
+ delete this.nodeMap[ruleId];
93
+ this.nodeMap = {...this.nodeMap}
94
+ ```
95
+
96
+ 3. **Lookup:** To update a node, simply access it directly via its ID:
97
+
98
+ ```typescript
99
+ const rule = this.nodeMap[ruleId];
100
+ if (rule) {
101
+ // Update the rule
102
+ }
103
+ ```
104
+
105
+ * **Benefits:**
106
+
107
+ * **Extremely Fast Lookups:** O(1) time complexity for finding nodes by ID.
108
+
109
+ * **Cons:**
110
+
111
+ * **Memory Overhead:** Maintaining the index adds memory overhead.
112
+ * **Synchronization:** You need to ensure the index is kept perfectly synchronized with the main data structure. Every time the tree changes, the index must be updated.
113
+ * **Additional Maintenance:** Requires careful management to avoid inconsistencies.
114
+
115
+ * **Use Cases:** This approach is valuable when you need the absolute fastest lookup times and are willing to trade off memory and added complexity.
116
+
117
+ **3. Structural Sharing and Immutability Helpers**
118
+
119
+ * **Concept:** Tools like Immer and Mori.js can help you perform immutable updates to deeply nested data structures more efficiently. They use structural sharing to minimize copying, so only the parts of the data structure that are actually modified are recreated.
120
+
121
+ * **Implementation:** Use Immer's `produce` function to create immutable updates:
122
+
123
+ ```typescript
124
+ import { produce } from 'immer';
125
+
126
+ handleFilterSelected(event: CustomEvent) {
127
+ const { ruleId, filterId } = event.detail;
128
+
129
+ this.model = produce(this.model, draft => {
130
+ //locate your object here
131
+ //draft is the mutable copy you can directly manipulate
132
+ });
133
+ }
134
+ ```
135
+
136
+ * **Benefits:**
137
+
138
+ * **Simplified Immutable Updates:** Immer handles the complexities of immutable updates, making your code cleaner.
139
+ * **Performance Optimizations:** Structural sharing reduces copying, improving performance, especially for large data structures.
140
+
141
+ * **Cons:**
142
+
143
+ * **Library Dependency:** Introduces an external dependency.
144
+ * **Learning Curve:** Requires understanding how Immer works.
145
+
146
+ * **Use Cases:** This is a good general-purpose optimization technique for any application with immutable state management.
147
+
148
+ **Which Approach to Choose?**
149
+
150
+ 1. **Start Simple:** Implement the basic incremental ID approach.
151
+ 2. **Profile:** If you notice performance issues with large expressions, use your browser's developer tools to profile the update process and identify bottlenecks.
152
+ 3. **Optimize Strategically:**
153
+ * If lookups are slow, consider a `nodeMap` (remembering to carefully manage synchronization).
154
+ * Use Immer to simplify immutable updates and potentially improve performance through structural sharing.
155
+ * Hierarchical IDs are more complex and should only be considered if the other techniques aren't sufficient.
156
+
157
+ **Important Considerations**
158
+
159
+ * **Premature Optimization:** Don't over-optimize prematurely. Focus on creating a working solution first, and then address performance issues if and when they arise.
160
+ * **Test Thoroughly:** Any time you introduce optimizations, test your code thoroughly to ensure that the optimizations don't introduce bugs.
161
+ * **Trade-offs:** Be aware of the trade-offs between performance, memory usage, and code complexity.
162
+
163
+ By following this iterative approach, you can build a query builder that is both functional and performant.
164
+
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Genesis Foundation Expressions
2
+
3
+ TODO
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ /** Globs to analyze */
3
+ globs: ['src/**/*.ts'],
4
+ /** Directory to output CEM to */
5
+ outdir: './dist',
6
+ /** Run in dev mode, provides extra logging */
7
+ dev: false,
8
+ /** Enable special handling for FastElement */
9
+ fast: true,
10
+ /** Include third party custom elements manifests */
11
+ dependencies: true,
12
+ /** Output CEM path to `package.json`, defaults to true */
13
+ packagejson: true,
14
+ };