@object-ui/core 0.3.1 → 0.5.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 (68) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/dist/actions/index.d.ts +1 -1
  3. package/dist/actions/index.js +1 -1
  4. package/dist/evaluator/ExpressionCache.d.ts +101 -0
  5. package/dist/evaluator/ExpressionCache.js +135 -0
  6. package/dist/evaluator/ExpressionEvaluator.d.ts +20 -2
  7. package/dist/evaluator/ExpressionEvaluator.js +34 -14
  8. package/dist/evaluator/index.d.ts +3 -2
  9. package/dist/evaluator/index.js +3 -2
  10. package/dist/index.d.ts +10 -7
  11. package/dist/index.js +9 -7
  12. package/dist/query/index.d.ts +6 -0
  13. package/dist/query/index.js +6 -0
  14. package/dist/query/query-ast.d.ts +32 -0
  15. package/dist/query/query-ast.js +268 -0
  16. package/dist/registry/PluginScopeImpl.d.ts +80 -0
  17. package/dist/registry/PluginScopeImpl.js +243 -0
  18. package/dist/registry/PluginSystem.d.ts +66 -0
  19. package/dist/registry/PluginSystem.js +142 -0
  20. package/dist/registry/Registry.d.ts +73 -4
  21. package/dist/registry/Registry.js +112 -7
  22. package/dist/validation/index.d.ts +9 -0
  23. package/dist/validation/index.js +9 -0
  24. package/dist/validation/validation-engine.d.ts +70 -0
  25. package/dist/validation/validation-engine.js +363 -0
  26. package/dist/validation/validators/index.d.ts +16 -0
  27. package/dist/validation/validators/index.js +16 -0
  28. package/dist/validation/validators/object-validation-engine.d.ts +118 -0
  29. package/dist/validation/validators/object-validation-engine.js +538 -0
  30. package/package.json +13 -5
  31. package/src/actions/index.ts +1 -1
  32. package/src/evaluator/ExpressionCache.ts +192 -0
  33. package/src/evaluator/ExpressionEvaluator.ts +33 -14
  34. package/src/evaluator/__tests__/ExpressionCache.test.ts +135 -0
  35. package/src/evaluator/index.ts +3 -2
  36. package/src/index.ts +10 -7
  37. package/src/query/__tests__/query-ast.test.ts +211 -0
  38. package/src/query/__tests__/window-functions.test.ts +275 -0
  39. package/src/query/index.ts +7 -0
  40. package/src/query/query-ast.ts +341 -0
  41. package/src/registry/PluginScopeImpl.ts +259 -0
  42. package/src/registry/PluginSystem.ts +161 -0
  43. package/src/registry/Registry.ts +125 -8
  44. package/src/registry/__tests__/PluginSystem.test.ts +226 -0
  45. package/src/registry/__tests__/Registry.test.ts +293 -0
  46. package/src/registry/__tests__/plugin-scope-integration.test.ts +283 -0
  47. package/src/validation/__tests__/object-validation-engine.test.ts +567 -0
  48. package/src/validation/__tests__/validation-engine.test.ts +102 -0
  49. package/src/validation/index.ts +10 -0
  50. package/src/validation/validation-engine.ts +461 -0
  51. package/src/validation/validators/index.ts +25 -0
  52. package/src/validation/validators/object-validation-engine.ts +722 -0
  53. package/tsconfig.tsbuildinfo +1 -1
  54. package/vitest.config.ts +2 -0
  55. package/src/adapters/index.d.ts +0 -8
  56. package/src/adapters/index.js +0 -10
  57. package/src/builder/schema-builder.d.ts +0 -294
  58. package/src/builder/schema-builder.js +0 -503
  59. package/src/index.d.ts +0 -13
  60. package/src/index.js +0 -16
  61. package/src/registry/Registry.d.ts +0 -56
  62. package/src/registry/Registry.js +0 -43
  63. package/src/types/index.d.ts +0 -19
  64. package/src/types/index.js +0 -8
  65. package/src/utils/filter-converter.d.ts +0 -57
  66. package/src/utils/filter-converter.js +0 -100
  67. package/src/validation/schema-validator.d.ts +0 -94
  68. package/src/validation/schema-validator.js +0 -278
@@ -0,0 +1,4 @@
1
+
2
+ > @object-ui/core@0.5.0 build /home/runner/work/objectui/objectui/packages/core
3
+ > tsc
4
+
@@ -5,4 +5,4 @@
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 './ActionRunner';
8
+ export * from './ActionRunner.js';
@@ -5,4 +5,4 @@
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 './ActionRunner';
8
+ export * from './ActionRunner.js';
@@ -0,0 +1,101 @@
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 - Expression Cache
10
+ *
11
+ * Caches compiled expressions to avoid re-parsing on every render.
12
+ * Provides significant performance improvement for frequently evaluated expressions.
13
+ *
14
+ * @module evaluator
15
+ * @packageDocumentation
16
+ */
17
+ /**
18
+ * A compiled expression function that can be executed with context values
19
+ */
20
+ export type CompiledExpression = (...args: any[]) => any;
21
+ /**
22
+ * Expression compilation metadata
23
+ */
24
+ export interface ExpressionMetadata {
25
+ /**
26
+ * The compiled function
27
+ */
28
+ fn: CompiledExpression;
29
+ /**
30
+ * Variable names used in the expression
31
+ */
32
+ varNames: string[];
33
+ /**
34
+ * Original expression string
35
+ */
36
+ expression: string;
37
+ /**
38
+ * Timestamp when the expression was compiled
39
+ */
40
+ compiledAt: number;
41
+ /**
42
+ * Number of times this expression has been used
43
+ */
44
+ hitCount: number;
45
+ }
46
+ /**
47
+ * Cache for compiled expressions
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const cache = new ExpressionCache();
52
+ * const compiled = cache.compile('data.amount > 1000', ['data']);
53
+ * const result = compiled.fn({ amount: 1500 }); // true
54
+ * ```
55
+ */
56
+ export declare class ExpressionCache {
57
+ private cache;
58
+ private maxSize;
59
+ /**
60
+ * Create a new expression cache
61
+ *
62
+ * @param maxSize Maximum number of expressions to cache (default: 1000)
63
+ */
64
+ constructor(maxSize?: number);
65
+ /**
66
+ * Compile an expression or retrieve from cache
67
+ *
68
+ * @param expr The expression to compile
69
+ * @param varNames Variable names available in the context
70
+ * @returns Compiled expression metadata
71
+ */
72
+ compile(expr: string, varNames: string[]): ExpressionMetadata;
73
+ /**
74
+ * Compile an expression into a function
75
+ */
76
+ private compileExpression;
77
+ /**
78
+ * Evict the least frequently used expression from cache
79
+ */
80
+ private evictLFU;
81
+ /**
82
+ * Check if an expression is cached
83
+ */
84
+ has(expr: string, varNames: string[]): boolean;
85
+ /**
86
+ * Clear the cache
87
+ */
88
+ clear(): void;
89
+ /**
90
+ * Get cache statistics
91
+ */
92
+ getStats(): {
93
+ size: number;
94
+ maxSize: number;
95
+ totalHits: number;
96
+ entries: Array<{
97
+ expression: string;
98
+ hitCount: number;
99
+ }>;
100
+ };
101
+ }
@@ -0,0 +1,135 @@
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
+ * Cache for compiled expressions
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const cache = new ExpressionCache();
14
+ * const compiled = cache.compile('data.amount > 1000', ['data']);
15
+ * const result = compiled.fn({ amount: 1500 }); // true
16
+ * ```
17
+ */
18
+ export class ExpressionCache {
19
+ /**
20
+ * Create a new expression cache
21
+ *
22
+ * @param maxSize Maximum number of expressions to cache (default: 1000)
23
+ */
24
+ constructor(maxSize = 1000) {
25
+ Object.defineProperty(this, "cache", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: new Map()
30
+ });
31
+ Object.defineProperty(this, "maxSize", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ this.maxSize = maxSize;
38
+ }
39
+ /**
40
+ * Compile an expression or retrieve from cache
41
+ *
42
+ * @param expr The expression to compile
43
+ * @param varNames Variable names available in the context
44
+ * @returns Compiled expression metadata
45
+ */
46
+ compile(expr, varNames) {
47
+ // Create a cache key that includes variable names to ensure correct scoping
48
+ const cacheKey = `${expr}::${varNames.join(',')}`;
49
+ if (this.cache.has(cacheKey)) {
50
+ const metadata = this.cache.get(cacheKey);
51
+ metadata.hitCount++;
52
+ return metadata;
53
+ }
54
+ // Evict least frequently used if cache is full
55
+ if (this.cache.size >= this.maxSize) {
56
+ this.evictLFU();
57
+ }
58
+ // Compile the expression
59
+ const fn = this.compileExpression(expr, varNames);
60
+ const metadata = {
61
+ fn,
62
+ varNames: [...varNames],
63
+ expression: expr,
64
+ compiledAt: Date.now(),
65
+ hitCount: 1,
66
+ };
67
+ this.cache.set(cacheKey, metadata);
68
+ return metadata;
69
+ }
70
+ /**
71
+ * Compile an expression into a function
72
+ */
73
+ compileExpression(expression, varNames) {
74
+ // SECURITY NOTE: Using Function constructor for expression evaluation.
75
+ // This is a controlled use case with:
76
+ // 1. Sanitization check (isDangerous) performed by caller
77
+ // 2. Strict mode enabled ("use strict")
78
+ // 3. Limited scope (only varNames variables available)
79
+ // 4. No access to global objects (process, window, etc.)
80
+ return new Function(...varNames, `"use strict"; return (${expression});`);
81
+ }
82
+ /**
83
+ * Evict the least frequently used expression from cache
84
+ */
85
+ evictLFU() {
86
+ let oldestKey = null;
87
+ let oldestTime = Infinity;
88
+ let lowestHits = Infinity;
89
+ // Find the entry with lowest hit count, or oldest if tied
90
+ for (const [key, metadata] of this.cache.entries()) {
91
+ if (metadata.hitCount < lowestHits ||
92
+ (metadata.hitCount === lowestHits && metadata.compiledAt < oldestTime)) {
93
+ oldestKey = key;
94
+ oldestTime = metadata.compiledAt;
95
+ lowestHits = metadata.hitCount;
96
+ }
97
+ }
98
+ if (oldestKey) {
99
+ this.cache.delete(oldestKey);
100
+ }
101
+ }
102
+ /**
103
+ * Check if an expression is cached
104
+ */
105
+ has(expr, varNames) {
106
+ const cacheKey = `${expr}::${varNames.join(',')}`;
107
+ return this.cache.has(cacheKey);
108
+ }
109
+ /**
110
+ * Clear the cache
111
+ */
112
+ clear() {
113
+ this.cache.clear();
114
+ }
115
+ /**
116
+ * Get cache statistics
117
+ */
118
+ getStats() {
119
+ let totalHits = 0;
120
+ const entries = [];
121
+ for (const metadata of this.cache.values()) {
122
+ totalHits += metadata.hitCount;
123
+ entries.push({
124
+ expression: metadata.expression,
125
+ hitCount: metadata.hitCount,
126
+ });
127
+ }
128
+ return {
129
+ size: this.cache.size,
130
+ maxSize: this.maxSize,
131
+ totalHits,
132
+ entries: entries.sort((a, b) => b.hitCount - a.hitCount),
133
+ };
134
+ }
135
+ }
@@ -14,7 +14,8 @@
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';
18
19
  /**
19
20
  * Options for expression evaluation
20
21
  */
@@ -39,7 +40,8 @@ export interface EvaluationOptions {
39
40
  */
40
41
  export declare class ExpressionEvaluator {
41
42
  private context;
42
- constructor(context?: ExpressionContext | Record<string, any>);
43
+ private cache;
44
+ constructor(context?: ExpressionContext | Record<string, any>, cache?: ExpressionCache);
43
45
  /**
44
46
  * Evaluate a string that may contain template expressions like ${...}
45
47
  *
@@ -88,6 +90,22 @@ export declare class ExpressionEvaluator {
88
90
  * Create a new evaluator with additional context data
89
91
  */
90
92
  withContext(data: Record<string, any>): ExpressionEvaluator;
93
+ /**
94
+ * Get cache statistics (useful for debugging and optimization)
95
+ */
96
+ getCacheStats(): {
97
+ size: number;
98
+ maxSize: number;
99
+ totalHits: number;
100
+ entries: Array<{
101
+ expression: string;
102
+ hitCount: number;
103
+ }>;
104
+ };
105
+ /**
106
+ * Clear the expression cache
107
+ */
108
+ clearCache(): void;
91
109
  }
92
110
  /**
93
111
  * Convenience function to quickly evaluate an expression
@@ -14,24 +14,33 @@
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';
18
19
  /**
19
20
  * Expression evaluator for dynamic UI expressions
20
21
  */
21
22
  export class ExpressionEvaluator {
22
- constructor(context) {
23
+ constructor(context, cache) {
23
24
  Object.defineProperty(this, "context", {
24
25
  enumerable: true,
25
26
  configurable: true,
26
27
  writable: true,
27
28
  value: void 0
28
29
  });
30
+ Object.defineProperty(this, "cache", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
29
36
  if (context instanceof ExpressionContext) {
30
37
  this.context = context;
31
38
  }
32
39
  else {
33
40
  this.context = new ExpressionContext(context || {});
34
41
  }
42
+ // Use provided cache or create a new one
43
+ this.cache = cache || new ExpressionCache();
35
44
  }
36
45
  /**
37
46
  * Evaluate a string that may contain template expressions like ${...}
@@ -108,16 +117,10 @@ export class ExpressionEvaluator {
108
117
  // Build safe function with context variables
109
118
  const varNames = Object.keys(contextObj);
110
119
  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});`);
120
+ // Use cached compilation
121
+ const compiled = this.cache.compile(expression, varNames);
119
122
  // Execute with context values
120
- return fn(...varValues);
123
+ return compiled.fn(...varValues);
121
124
  }
122
125
  catch (error) {
123
126
  throw new Error(`Failed to evaluate expression "${expression}": ${error.message}`);
@@ -181,20 +184,37 @@ export class ExpressionEvaluator {
181
184
  * Create a new evaluator with additional context data
182
185
  */
183
186
  withContext(data) {
184
- return new ExpressionEvaluator(this.context.createChild(data));
187
+ // Share the cache with the new evaluator for maximum efficiency
188
+ return new ExpressionEvaluator(this.context.createChild(data), this.cache);
189
+ }
190
+ /**
191
+ * Get cache statistics (useful for debugging and optimization)
192
+ */
193
+ getCacheStats() {
194
+ return this.cache.getStats();
195
+ }
196
+ /**
197
+ * Clear the expression cache
198
+ */
199
+ clearCache() {
200
+ this.cache.clear();
185
201
  }
186
202
  }
203
+ /**
204
+ * Shared global cache for convenience functions
205
+ */
206
+ const globalCache = new ExpressionCache();
187
207
  /**
188
208
  * Convenience function to quickly evaluate an expression
189
209
  */
190
210
  export function evaluateExpression(expression, context = {}, options = {}) {
191
- const evaluator = new ExpressionEvaluator(context);
211
+ const evaluator = new ExpressionEvaluator(context, globalCache);
192
212
  return evaluator.evaluate(expression, options);
193
213
  }
194
214
  /**
195
215
  * Convenience function to evaluate a condition
196
216
  */
197
217
  export function evaluateCondition(condition, context = {}) {
198
- const evaluator = new ExpressionEvaluator(context);
218
+ const evaluator = new ExpressionEvaluator(context, globalCache);
199
219
  return evaluator.evaluateCondition(condition);
200
220
  }
@@ -5,5 +5,6 @@
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';
@@ -5,5 +5,6 @@
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';
package/dist/index.d.ts CHANGED
@@ -5,10 +5,13 @@
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 './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';
package/dist/index.js CHANGED
@@ -5,12 +5,14 @@
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 * from './registry/Registry.js';
9
+ export * from './registry/PluginSystem.js';
10
+ export * from './registry/PluginScopeImpl.js';
11
+ export * from './validation/index.js';
12
+ export * from './builder/schema-builder.js';
13
+ export * from './utils/filter-converter.js';
14
+ export * from './evaluator/index.js';
15
+ export * from './actions/index.js';
16
+ export * from './query/index.js';
15
17
  // export * from './data-scope'; // TODO
16
18
  // export * from './validators'; // TODO
@@ -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';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * ObjectUI - Query AST Builder
3
+ * Phase 3.3: QuerySchema AST implementation
4
+ * ObjectStack Spec v0.7.1: Window functions support
5
+ */
6
+ import type { QueryAST, QuerySchema } from '@object-ui/types';
7
+ /**
8
+ * Query AST Builder - Converts QuerySchema to AST
9
+ */
10
+ export declare class QueryASTBuilder {
11
+ build(query: QuerySchema): QueryAST;
12
+ private buildSelect;
13
+ private buildFrom;
14
+ private buildWhere;
15
+ private buildFilterCondition;
16
+ private buildCondition;
17
+ private buildJoin;
18
+ private buildGroupBy;
19
+ private buildOrderBy;
20
+ private buildLimit;
21
+ private buildOffset;
22
+ private buildField;
23
+ private buildLiteral;
24
+ private buildAggregation;
25
+ /**
26
+ * Build window function node (ObjectStack Spec v0.7.1)
27
+ */
28
+ private buildWindow;
29
+ optimize(ast: QueryAST): QueryAST;
30
+ }
31
+ export declare const defaultQueryASTBuilder: QueryASTBuilder;
32
+ export declare function buildQueryAST(query: QuerySchema): QueryAST;