@object-ui/core 0.3.1 → 2.0.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 (118) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +11 -0
  3. package/dist/actions/ActionRunner.d.ts +228 -4
  4. package/dist/actions/ActionRunner.js +397 -45
  5. package/dist/actions/TransactionManager.d.ts +193 -0
  6. package/dist/actions/TransactionManager.js +410 -0
  7. package/dist/actions/index.d.ts +2 -1
  8. package/dist/actions/index.js +2 -1
  9. package/dist/adapters/ApiDataSource.d.ts +69 -0
  10. package/dist/adapters/ApiDataSource.js +293 -0
  11. package/dist/adapters/ValueDataSource.d.ts +55 -0
  12. package/dist/adapters/ValueDataSource.js +287 -0
  13. package/dist/adapters/index.d.ts +3 -0
  14. package/dist/adapters/index.js +5 -2
  15. package/dist/adapters/resolveDataSource.d.ts +40 -0
  16. package/dist/adapters/resolveDataSource.js +59 -0
  17. package/dist/data-scope/DataScopeManager.d.ts +127 -0
  18. package/dist/data-scope/DataScopeManager.js +229 -0
  19. package/dist/data-scope/index.d.ts +10 -0
  20. package/dist/data-scope/index.js +10 -0
  21. package/dist/evaluator/ExpressionCache.d.ts +101 -0
  22. package/dist/evaluator/ExpressionCache.js +135 -0
  23. package/dist/evaluator/ExpressionEvaluator.d.ts +30 -2
  24. package/dist/evaluator/ExpressionEvaluator.js +60 -16
  25. package/dist/evaluator/FormulaFunctions.d.ts +58 -0
  26. package/dist/evaluator/FormulaFunctions.js +350 -0
  27. package/dist/evaluator/index.d.ts +4 -2
  28. package/dist/evaluator/index.js +4 -2
  29. package/dist/index.d.ts +14 -7
  30. package/dist/index.js +13 -9
  31. package/dist/query/index.d.ts +6 -0
  32. package/dist/query/index.js +6 -0
  33. package/dist/query/query-ast.d.ts +32 -0
  34. package/dist/query/query-ast.js +268 -0
  35. package/dist/registry/PluginScopeImpl.d.ts +80 -0
  36. package/dist/registry/PluginScopeImpl.js +243 -0
  37. package/dist/registry/PluginSystem.d.ts +66 -0
  38. package/dist/registry/PluginSystem.js +142 -0
  39. package/dist/registry/Registry.d.ts +83 -4
  40. package/dist/registry/Registry.js +113 -7
  41. package/dist/registry/WidgetRegistry.d.ts +120 -0
  42. package/dist/registry/WidgetRegistry.js +275 -0
  43. package/dist/theme/ThemeEngine.d.ts +82 -0
  44. package/dist/theme/ThemeEngine.js +400 -0
  45. package/dist/theme/index.d.ts +8 -0
  46. package/dist/theme/index.js +8 -0
  47. package/dist/validation/index.d.ts +9 -0
  48. package/dist/validation/index.js +9 -0
  49. package/dist/validation/validation-engine.d.ts +88 -0
  50. package/dist/validation/validation-engine.js +428 -0
  51. package/dist/validation/validators/index.d.ts +16 -0
  52. package/dist/validation/validators/index.js +16 -0
  53. package/dist/validation/validators/object-validation-engine.d.ts +118 -0
  54. package/dist/validation/validators/object-validation-engine.js +538 -0
  55. package/package.json +14 -5
  56. package/src/actions/ActionRunner.ts +577 -55
  57. package/src/actions/TransactionManager.ts +521 -0
  58. package/src/actions/__tests__/ActionRunner.params.test.ts +134 -0
  59. package/src/actions/__tests__/ActionRunner.test.ts +711 -0
  60. package/src/actions/__tests__/TransactionManager.test.ts +447 -0
  61. package/src/actions/index.ts +2 -1
  62. package/src/adapters/ApiDataSource.ts +349 -0
  63. package/src/adapters/ValueDataSource.ts +332 -0
  64. package/src/adapters/__tests__/ApiDataSource.test.ts +418 -0
  65. package/src/adapters/__tests__/ValueDataSource.test.ts +325 -0
  66. package/src/adapters/__tests__/resolveDataSource.test.ts +144 -0
  67. package/src/adapters/index.ts +6 -1
  68. package/src/adapters/resolveDataSource.ts +79 -0
  69. package/src/builder/__tests__/schema-builder.test.ts +235 -0
  70. package/src/data-scope/DataScopeManager.ts +269 -0
  71. package/src/data-scope/__tests__/DataScopeManager.test.ts +211 -0
  72. package/src/data-scope/index.ts +16 -0
  73. package/src/evaluator/ExpressionCache.ts +192 -0
  74. package/src/evaluator/ExpressionEvaluator.ts +61 -16
  75. package/src/evaluator/FormulaFunctions.ts +398 -0
  76. package/src/evaluator/__tests__/ExpressionCache.test.ts +135 -0
  77. package/src/evaluator/__tests__/ExpressionContext.test.ts +110 -0
  78. package/src/evaluator/__tests__/FormulaFunctions.test.ts +447 -0
  79. package/src/evaluator/index.ts +4 -2
  80. package/src/index.ts +14 -10
  81. package/src/query/__tests__/query-ast.test.ts +211 -0
  82. package/src/query/__tests__/window-functions.test.ts +275 -0
  83. package/src/query/index.ts +7 -0
  84. package/src/query/query-ast.ts +341 -0
  85. package/src/registry/PluginScopeImpl.ts +259 -0
  86. package/src/registry/PluginSystem.ts +161 -0
  87. package/src/registry/Registry.ts +136 -8
  88. package/src/registry/WidgetRegistry.ts +316 -0
  89. package/src/registry/__tests__/PluginSystem.test.ts +226 -0
  90. package/src/registry/__tests__/Registry.test.ts +293 -0
  91. package/src/registry/__tests__/WidgetRegistry.test.ts +321 -0
  92. package/src/registry/__tests__/plugin-scope-integration.test.ts +283 -0
  93. package/src/theme/ThemeEngine.ts +452 -0
  94. package/src/theme/__tests__/ThemeEngine.test.ts +606 -0
  95. package/src/theme/index.ts +22 -0
  96. package/src/validation/__tests__/object-validation-engine.test.ts +567 -0
  97. package/src/validation/__tests__/schema-validator.test.ts +118 -0
  98. package/src/validation/__tests__/validation-engine.test.ts +102 -0
  99. package/src/validation/index.ts +10 -0
  100. package/src/validation/validation-engine.ts +520 -0
  101. package/src/validation/validators/index.ts +25 -0
  102. package/src/validation/validators/object-validation-engine.ts +722 -0
  103. package/tsconfig.tsbuildinfo +1 -1
  104. package/vitest.config.ts +2 -0
  105. package/src/adapters/index.d.ts +0 -8
  106. package/src/adapters/index.js +0 -10
  107. package/src/builder/schema-builder.d.ts +0 -294
  108. package/src/builder/schema-builder.js +0 -503
  109. package/src/index.d.ts +0 -13
  110. package/src/index.js +0 -16
  111. package/src/registry/Registry.d.ts +0 -56
  112. package/src/registry/Registry.js +0 -43
  113. package/src/types/index.d.ts +0 -19
  114. package/src/types/index.js +0 -8
  115. package/src/utils/filter-converter.d.ts +0 -57
  116. package/src/utils/filter-converter.js +0 -100
  117. package/src/validation/schema-validator.d.ts +0 -94
  118. package/src/validation/schema-validator.js +0 -278
@@ -14,7 +14,9 @@
14
14
  * @module evaluator
15
15
  * @packageDocumentation
16
16
  */
17
- import { ExpressionContext } from './ExpressionContext';
17
+ import { ExpressionContext } from './ExpressionContext.js';
18
+ import { ExpressionCache } from './ExpressionCache.js';
19
+ import { FormulaFunctions } from './FormulaFunctions.js';
18
20
  /**
19
21
  * Options for expression evaluation
20
22
  */
@@ -39,7 +41,9 @@ export interface EvaluationOptions {
39
41
  */
40
42
  export declare class ExpressionEvaluator {
41
43
  private context;
42
- constructor(context?: ExpressionContext | Record<string, any>);
44
+ private cache;
45
+ private formulas;
46
+ constructor(context?: ExpressionContext | Record<string, any>, cache?: ExpressionCache, formulas?: FormulaFunctions);
43
47
  /**
44
48
  * Evaluate a string that may contain template expressions like ${...}
45
49
  *
@@ -88,6 +92,30 @@ export declare class ExpressionEvaluator {
88
92
  * Create a new evaluator with additional context data
89
93
  */
90
94
  withContext(data: Record<string, any>): ExpressionEvaluator;
95
+ /**
96
+ * Get cache statistics (useful for debugging and optimization)
97
+ */
98
+ getCacheStats(): {
99
+ size: number;
100
+ maxSize: number;
101
+ totalHits: number;
102
+ entries: Array<{
103
+ expression: string;
104
+ hitCount: number;
105
+ }>;
106
+ };
107
+ /**
108
+ * Clear the expression cache
109
+ */
110
+ clearCache(): void;
111
+ /**
112
+ * Get the formula functions registry
113
+ */
114
+ getFormulas(): FormulaFunctions;
115
+ /**
116
+ * Register a custom formula function
117
+ */
118
+ registerFunction(name: string, fn: (...args: any[]) => any): void;
91
119
  }
92
120
  /**
93
121
  * Convenience function to quickly evaluate an expression
@@ -14,24 +14,41 @@
14
14
  * @module evaluator
15
15
  * @packageDocumentation
16
16
  */
17
- import { ExpressionContext } from './ExpressionContext';
17
+ import { ExpressionContext } from './ExpressionContext.js';
18
+ import { ExpressionCache } from './ExpressionCache.js';
19
+ import { FormulaFunctions } from './FormulaFunctions.js';
18
20
  /**
19
21
  * Expression evaluator for dynamic UI expressions
20
22
  */
21
23
  export class ExpressionEvaluator {
22
- constructor(context) {
24
+ constructor(context, cache, formulas) {
23
25
  Object.defineProperty(this, "context", {
24
26
  enumerable: true,
25
27
  configurable: true,
26
28
  writable: true,
27
29
  value: void 0
28
30
  });
31
+ Object.defineProperty(this, "cache", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ Object.defineProperty(this, "formulas", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: void 0
42
+ });
29
43
  if (context instanceof ExpressionContext) {
30
44
  this.context = context;
31
45
  }
32
46
  else {
33
47
  this.context = new ExpressionContext(context || {});
34
48
  }
49
+ // Use provided cache or create a new one
50
+ this.cache = cache || new ExpressionCache();
51
+ this.formulas = formulas || new FormulaFunctions();
35
52
  }
36
53
  /**
37
54
  * Evaluate a string that may contain template expressions like ${...}
@@ -105,19 +122,16 @@ export class ExpressionEvaluator {
105
122
  try {
106
123
  // Create a safe evaluation function
107
124
  const contextObj = this.context.toObject();
125
+ // Inject formula functions into the evaluation context
126
+ const formulaObj = this.formulas.toObject();
127
+ const mergedContext = { ...formulaObj, ...contextObj };
108
128
  // Build safe function with context variables
109
- const varNames = Object.keys(contextObj);
110
- const varValues = Object.values(contextObj);
111
- // SECURITY NOTE: Using Function constructor for expression evaluation.
112
- // This is a controlled use case with:
113
- // 1. Sanitization check (isDangerous) blocks dangerous patterns
114
- // 2. Strict mode enabled ("use strict")
115
- // 3. Limited scope (only contextObj variables available)
116
- // 4. No access to global objects (process, window, etc.)
117
- // For production use, consider: expr-eval, safe-eval, or a custom parser
118
- const fn = new Function(...varNames, `"use strict"; return (${expression});`);
129
+ const varNames = Object.keys(mergedContext);
130
+ const varValues = Object.values(mergedContext);
131
+ // Use cached compilation
132
+ const compiled = this.cache.compile(expression, varNames);
119
133
  // Execute with context values
120
- return fn(...varValues);
134
+ return compiled.fn(...varValues);
121
135
  }
122
136
  catch (error) {
123
137
  throw new Error(`Failed to evaluate expression "${expression}": ${error.message}`);
@@ -181,20 +195,50 @@ export class ExpressionEvaluator {
181
195
  * Create a new evaluator with additional context data
182
196
  */
183
197
  withContext(data) {
184
- return new ExpressionEvaluator(this.context.createChild(data));
198
+ // Share the cache and formulas with the new evaluator for maximum efficiency
199
+ return new ExpressionEvaluator(this.context.createChild(data), this.cache, this.formulas);
200
+ }
201
+ /**
202
+ * Get cache statistics (useful for debugging and optimization)
203
+ */
204
+ getCacheStats() {
205
+ return this.cache.getStats();
206
+ }
207
+ /**
208
+ * Clear the expression cache
209
+ */
210
+ clearCache() {
211
+ this.cache.clear();
212
+ }
213
+ /**
214
+ * Get the formula functions registry
215
+ */
216
+ getFormulas() {
217
+ return this.formulas;
218
+ }
219
+ /**
220
+ * Register a custom formula function
221
+ */
222
+ registerFunction(name, fn) {
223
+ this.formulas.register(name, fn);
185
224
  }
186
225
  }
226
+ /**
227
+ * Shared global cache and formulas for convenience functions
228
+ */
229
+ const globalCache = new ExpressionCache();
230
+ const globalFormulas = new FormulaFunctions();
187
231
  /**
188
232
  * Convenience function to quickly evaluate an expression
189
233
  */
190
234
  export function evaluateExpression(expression, context = {}, options = {}) {
191
- const evaluator = new ExpressionEvaluator(context);
235
+ const evaluator = new ExpressionEvaluator(context, globalCache, globalFormulas);
192
236
  return evaluator.evaluate(expression, options);
193
237
  }
194
238
  /**
195
239
  * Convenience function to evaluate a condition
196
240
  */
197
241
  export function evaluateCondition(condition, context = {}) {
198
- const evaluator = new ExpressionEvaluator(context);
242
+ const evaluator = new ExpressionEvaluator(context, globalCache, globalFormulas);
199
243
  return evaluator.evaluateCondition(condition);
200
244
  }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * @object-ui/core - Formula Functions
10
+ *
11
+ * Built-in formula functions for the expression engine.
12
+ * Provides aggregation, date, logic, and string functions
13
+ * compatible with low-code platform expression evaluation.
14
+ *
15
+ * @module evaluator
16
+ * @packageDocumentation
17
+ */
18
+ /**
19
+ * A formula function that can be registered with the expression evaluator
20
+ */
21
+ export type FormulaFunction = (...args: any[]) => any;
22
+ /**
23
+ * Registry of built-in formula functions
24
+ */
25
+ export declare class FormulaFunctions {
26
+ private functions;
27
+ constructor();
28
+ /**
29
+ * Register a custom formula function
30
+ */
31
+ register(name: string, fn: FormulaFunction): void;
32
+ /**
33
+ * Get a formula function by name
34
+ */
35
+ get(name: string): FormulaFunction | undefined;
36
+ /**
37
+ * Check if a function is registered
38
+ */
39
+ has(name: string): boolean;
40
+ /**
41
+ * Get all registered function names
42
+ */
43
+ getNames(): string[];
44
+ /**
45
+ * Get all functions as a plain object (for injection into expression context)
46
+ */
47
+ toObject(): Record<string, FormulaFunction>;
48
+ /**
49
+ * Register all default built-in functions
50
+ */
51
+ private registerDefaults;
52
+ private registerAggregationFunctions;
53
+ private registerDateFunctions;
54
+ private registerLogicFunctions;
55
+ private registerStringFunctions;
56
+ private registerStringSearchFunctions;
57
+ private registerStatisticalFunctions;
58
+ }
@@ -0,0 +1,350 @@
1
+ /**
2
+ * ObjectUI
3
+ * Copyright (c) 2024-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * Registry of built-in formula functions
10
+ */
11
+ export class FormulaFunctions {
12
+ constructor() {
13
+ Object.defineProperty(this, "functions", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: new Map()
18
+ });
19
+ this.registerDefaults();
20
+ }
21
+ /**
22
+ * Register a custom formula function
23
+ */
24
+ register(name, fn) {
25
+ this.functions.set(name.toUpperCase(), fn);
26
+ }
27
+ /**
28
+ * Get a formula function by name
29
+ */
30
+ get(name) {
31
+ return this.functions.get(name.toUpperCase());
32
+ }
33
+ /**
34
+ * Check if a function is registered
35
+ */
36
+ has(name) {
37
+ return this.functions.has(name.toUpperCase());
38
+ }
39
+ /**
40
+ * Get all registered function names
41
+ */
42
+ getNames() {
43
+ return Array.from(this.functions.keys());
44
+ }
45
+ /**
46
+ * Get all functions as a plain object (for injection into expression context)
47
+ */
48
+ toObject() {
49
+ const result = {};
50
+ for (const [name, fn] of this.functions) {
51
+ result[name] = fn;
52
+ }
53
+ return result;
54
+ }
55
+ /**
56
+ * Register all default built-in functions
57
+ */
58
+ registerDefaults() {
59
+ this.registerAggregationFunctions();
60
+ this.registerDateFunctions();
61
+ this.registerLogicFunctions();
62
+ this.registerStringFunctions();
63
+ this.registerStringSearchFunctions();
64
+ this.registerStatisticalFunctions();
65
+ }
66
+ // ==========================================================================
67
+ // Aggregation Functions
68
+ // ==========================================================================
69
+ registerAggregationFunctions() {
70
+ this.register('SUM', (...args) => {
71
+ const values = flattenNumericArgs(args);
72
+ return values.reduce((sum, v) => sum + v, 0);
73
+ });
74
+ this.register('AVG', (...args) => {
75
+ const values = flattenNumericArgs(args);
76
+ if (values.length === 0)
77
+ return 0;
78
+ return values.reduce((sum, v) => sum + v, 0) / values.length;
79
+ });
80
+ this.register('COUNT', (...args) => {
81
+ const values = flattenArgs(args);
82
+ return values.filter(v => v != null).length;
83
+ });
84
+ this.register('MIN', (...args) => {
85
+ const values = flattenNumericArgs(args);
86
+ if (values.length === 0)
87
+ return 0;
88
+ return Math.min(...values);
89
+ });
90
+ this.register('MAX', (...args) => {
91
+ const values = flattenNumericArgs(args);
92
+ if (values.length === 0)
93
+ return 0;
94
+ return Math.max(...values);
95
+ });
96
+ }
97
+ // ==========================================================================
98
+ // Date Functions
99
+ // ==========================================================================
100
+ registerDateFunctions() {
101
+ this.register('TODAY', () => {
102
+ const now = new Date();
103
+ return now.toISOString().split('T')[0];
104
+ });
105
+ this.register('NOW', () => {
106
+ return new Date().toISOString();
107
+ });
108
+ this.register('DATEADD', (dateStr, amount, unit) => {
109
+ const date = new Date(dateStr);
110
+ if (isNaN(date.getTime())) {
111
+ throw new Error(`DATEADD: Invalid date "${dateStr}"`);
112
+ }
113
+ const normalizedUnit = String(unit).toLowerCase();
114
+ switch (normalizedUnit) {
115
+ case 'day':
116
+ case 'days':
117
+ date.setDate(date.getDate() + amount);
118
+ break;
119
+ case 'month':
120
+ case 'months':
121
+ date.setMonth(date.getMonth() + amount);
122
+ break;
123
+ case 'year':
124
+ case 'years':
125
+ date.setFullYear(date.getFullYear() + amount);
126
+ break;
127
+ case 'hour':
128
+ case 'hours':
129
+ date.setHours(date.getHours() + amount);
130
+ break;
131
+ case 'minute':
132
+ case 'minutes':
133
+ date.setMinutes(date.getMinutes() + amount);
134
+ break;
135
+ default:
136
+ throw new Error(`DATEADD: Unsupported unit "${unit}"`);
137
+ }
138
+ return date.toISOString();
139
+ });
140
+ this.register('DATEDIFF', (dateStr1, dateStr2, unit) => {
141
+ const date1 = new Date(dateStr1);
142
+ const date2 = new Date(dateStr2);
143
+ if (isNaN(date1.getTime())) {
144
+ throw new Error(`DATEDIFF: Invalid date "${dateStr1}"`);
145
+ }
146
+ if (isNaN(date2.getTime())) {
147
+ throw new Error(`DATEDIFF: Invalid date "${dateStr2}"`);
148
+ }
149
+ const diffMs = date2.getTime() - date1.getTime();
150
+ const normalizedUnit = String(unit).toLowerCase();
151
+ switch (normalizedUnit) {
152
+ case 'day':
153
+ case 'days':
154
+ return Math.floor(diffMs / (1000 * 60 * 60 * 24));
155
+ case 'month':
156
+ case 'months':
157
+ return (date2.getFullYear() - date1.getFullYear()) * 12 + (date2.getMonth() - date1.getMonth());
158
+ case 'year':
159
+ case 'years':
160
+ return date2.getFullYear() - date1.getFullYear();
161
+ case 'hour':
162
+ case 'hours':
163
+ return Math.floor(diffMs / (1000 * 60 * 60));
164
+ case 'minute':
165
+ case 'minutes':
166
+ return Math.floor(diffMs / (1000 * 60));
167
+ default:
168
+ throw new Error(`DATEDIFF: Unsupported unit "${unit}"`);
169
+ }
170
+ });
171
+ this.register('DATEFORMAT', (dateStr, format) => {
172
+ const date = new Date(dateStr);
173
+ if (isNaN(date.getTime())) {
174
+ throw new Error(`DATEFORMAT: Invalid date "${dateStr}"`);
175
+ }
176
+ const pad = (n, len = 2) => String(n).padStart(len, '0');
177
+ return format
178
+ .replace('YYYY', String(date.getFullYear()))
179
+ .replace('YY', String(date.getFullYear()).slice(-2))
180
+ .replace('MM', pad(date.getMonth() + 1))
181
+ .replace('DD', pad(date.getDate()))
182
+ .replace('HH', pad(date.getHours()))
183
+ .replace('mm', pad(date.getMinutes()))
184
+ .replace('ss', pad(date.getSeconds()));
185
+ });
186
+ }
187
+ // ==========================================================================
188
+ // Logic Functions
189
+ // ==========================================================================
190
+ registerLogicFunctions() {
191
+ this.register('IF', (condition, trueValue, falseValue) => {
192
+ return condition ? trueValue : falseValue;
193
+ });
194
+ this.register('AND', (...args) => {
195
+ return args.every(Boolean);
196
+ });
197
+ this.register('OR', (...args) => {
198
+ return args.some(Boolean);
199
+ });
200
+ this.register('NOT', (value) => {
201
+ return !value;
202
+ });
203
+ this.register('SWITCH', (expr, ...cases) => {
204
+ // SWITCH(expr, val1, result1, val2, result2, ..., defaultResult)
205
+ for (let i = 0; i < cases.length - 1; i += 2) {
206
+ if (expr === cases[i]) {
207
+ return cases[i + 1];
208
+ }
209
+ }
210
+ // Return default value if odd number of case args
211
+ if (cases.length % 2 === 1) {
212
+ return cases[cases.length - 1];
213
+ }
214
+ return undefined;
215
+ });
216
+ }
217
+ // ==========================================================================
218
+ // String Functions
219
+ // ==========================================================================
220
+ registerStringFunctions() {
221
+ this.register('CONCAT', (...args) => {
222
+ return args.map(a => String(a ?? '')).join('');
223
+ });
224
+ this.register('LEFT', (text, count) => {
225
+ return String(text ?? '').substring(0, count);
226
+ });
227
+ this.register('RIGHT', (text, count) => {
228
+ const str = String(text ?? '');
229
+ return str.substring(Math.max(0, str.length - count));
230
+ });
231
+ this.register('TRIM', (text) => {
232
+ return String(text ?? '').trim();
233
+ });
234
+ this.register('UPPER', (text) => {
235
+ return String(text ?? '').toUpperCase();
236
+ });
237
+ this.register('LOWER', (text) => {
238
+ return String(text ?? '').toLowerCase();
239
+ });
240
+ }
241
+ // ==========================================================================
242
+ // String Search Functions
243
+ // ==========================================================================
244
+ registerStringSearchFunctions() {
245
+ this.register('FIND', (search, text, startPos) => {
246
+ const str = String(text ?? '');
247
+ const idx = str.indexOf(String(search ?? ''), startPos ?? 0);
248
+ return idx;
249
+ });
250
+ this.register('REPLACE', (text, search, replacement) => {
251
+ const str = String(text ?? '');
252
+ return str.split(String(search ?? '')).join(String(replacement ?? ''));
253
+ });
254
+ this.register('SUBSTRING', (text, start, length) => {
255
+ const str = String(text ?? '');
256
+ if (length !== undefined) {
257
+ return str.substring(start, start + length);
258
+ }
259
+ return str.substring(start);
260
+ });
261
+ this.register('REGEX', (text, pattern, flags) => {
262
+ const str = String(text ?? '');
263
+ const regex = new RegExp(pattern, flags);
264
+ return regex.test(str);
265
+ });
266
+ this.register('LEN', (text) => {
267
+ return String(text ?? '').length;
268
+ });
269
+ }
270
+ // ==========================================================================
271
+ // Statistical Functions
272
+ // ==========================================================================
273
+ registerStatisticalFunctions() {
274
+ this.register('MEDIAN', (...args) => {
275
+ const values = flattenNumericArgs(args).sort((a, b) => a - b);
276
+ if (values.length === 0)
277
+ return 0;
278
+ const mid = Math.floor(values.length / 2);
279
+ return values.length % 2 !== 0
280
+ ? values[mid]
281
+ : (values[mid - 1] + values[mid]) / 2;
282
+ });
283
+ this.register('STDEV', (...args) => {
284
+ const values = flattenNumericArgs(args);
285
+ if (values.length < 2)
286
+ return 0;
287
+ const mean = values.reduce((sum, v) => sum + v, 0) / values.length;
288
+ const squaredDiffs = values.map(v => (v - mean) ** 2);
289
+ const variance = squaredDiffs.reduce((sum, v) => sum + v, 0) / (values.length - 1);
290
+ return Math.sqrt(variance);
291
+ });
292
+ this.register('VARIANCE', (...args) => {
293
+ const values = flattenNumericArgs(args);
294
+ if (values.length < 2)
295
+ return 0;
296
+ const mean = values.reduce((sum, v) => sum + v, 0) / values.length;
297
+ const squaredDiffs = values.map(v => (v - mean) ** 2);
298
+ return squaredDiffs.reduce((sum, v) => sum + v, 0) / (values.length - 1);
299
+ });
300
+ this.register('PERCENTILE', (percentile, ...args) => {
301
+ const values = flattenNumericArgs(args).sort((a, b) => a - b);
302
+ if (values.length === 0)
303
+ return 0;
304
+ const p = Math.max(0, Math.min(100, percentile)) / 100;
305
+ const index = p * (values.length - 1);
306
+ const lower = Math.floor(index);
307
+ const upper = Math.ceil(index);
308
+ if (lower === upper)
309
+ return values[lower];
310
+ const fraction = index - lower;
311
+ return values[lower] + fraction * (values[upper] - values[lower]);
312
+ });
313
+ }
314
+ }
315
+ // ==========================================================================
316
+ // Helpers
317
+ // ==========================================================================
318
+ /**
319
+ * Flatten nested arrays and extract numeric values
320
+ */
321
+ function flattenNumericArgs(args) {
322
+ const result = [];
323
+ for (const arg of args) {
324
+ if (Array.isArray(arg)) {
325
+ result.push(...flattenNumericArgs(arg));
326
+ }
327
+ else {
328
+ const num = Number(arg);
329
+ if (!isNaN(num)) {
330
+ result.push(num);
331
+ }
332
+ }
333
+ }
334
+ return result;
335
+ }
336
+ /**
337
+ * Flatten nested arrays
338
+ */
339
+ function flattenArgs(args) {
340
+ const result = [];
341
+ for (const arg of args) {
342
+ if (Array.isArray(arg)) {
343
+ result.push(...flattenArgs(arg));
344
+ }
345
+ else {
346
+ result.push(arg);
347
+ }
348
+ }
349
+ return result;
350
+ }
@@ -5,5 +5,7 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- export * from './ExpressionContext';
9
- export * from './ExpressionEvaluator';
8
+ export * from './ExpressionContext.js';
9
+ export * from './ExpressionEvaluator.js';
10
+ export * from './ExpressionCache.js';
11
+ export * from './FormulaFunctions.js';
@@ -5,5 +5,7 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- export * from './ExpressionContext';
9
- export * from './ExpressionEvaluator';
8
+ export * from './ExpressionContext.js';
9
+ export * from './ExpressionEvaluator.js';
10
+ export * from './ExpressionCache.js';
11
+ export * from './FormulaFunctions.js';
package/dist/index.d.ts CHANGED
@@ -5,10 +5,17 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- export * from './types';
9
- export * from './registry/Registry';
10
- export * from './validation/schema-validator';
11
- export * from './builder/schema-builder';
12
- export * from './utils/filter-converter';
13
- export * from './evaluator';
14
- export * from './actions';
8
+ export type { SchemaNode, ComponentRendererProps } from './types/index.js';
9
+ export * from './registry/Registry.js';
10
+ export * from './registry/PluginSystem.js';
11
+ export * from './registry/PluginScopeImpl.js';
12
+ export * from './registry/WidgetRegistry.js';
13
+ export * from './validation/index.js';
14
+ export * from './builder/schema-builder.js';
15
+ export * from './utils/filter-converter.js';
16
+ export * from './evaluator/index.js';
17
+ export * from './actions/index.js';
18
+ export * from './query/index.js';
19
+ export * from './adapters/index.js';
20
+ export * from './theme/index.js';
21
+ export * from './data-scope/index.js';
package/dist/index.js CHANGED
@@ -5,12 +5,16 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- export * from './types';
9
- export * from './registry/Registry';
10
- export * from './validation/schema-validator';
11
- export * from './builder/schema-builder';
12
- export * from './utils/filter-converter';
13
- export * from './evaluator';
14
- export * from './actions';
15
- // export * from './data-scope'; // TODO
16
- // export * from './validators'; // TODO
8
+ export * from './registry/Registry.js';
9
+ export * from './registry/PluginSystem.js';
10
+ export * from './registry/PluginScopeImpl.js';
11
+ export * from './registry/WidgetRegistry.js';
12
+ export * from './validation/index.js';
13
+ export * from './builder/schema-builder.js';
14
+ export * from './utils/filter-converter.js';
15
+ export * from './evaluator/index.js';
16
+ export * from './actions/index.js';
17
+ export * from './query/index.js';
18
+ export * from './adapters/index.js';
19
+ export * from './theme/index.js';
20
+ export * from './data-scope/index.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @object-ui/core - Query Module
3
+ *
4
+ * Phase 3.3: Query AST builder and utilities
5
+ */
6
+ export * from './query-ast.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @object-ui/core - Query Module
3
+ *
4
+ * Phase 3.3: Query AST builder and utilities
5
+ */
6
+ export * from './query-ast.js';