@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,226 @@
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
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
10
+ import { PluginSystem, type PluginDefinition } from '../PluginSystem';
11
+ import { Registry } from '../Registry';
12
+
13
+ describe('PluginSystem', () => {
14
+ let pluginSystem: PluginSystem;
15
+ let registry: Registry;
16
+
17
+ beforeEach(() => {
18
+ pluginSystem = new PluginSystem();
19
+ registry = new Registry();
20
+ });
21
+
22
+ it('should load a simple plugin', async () => {
23
+ const plugin: PluginDefinition = {
24
+ name: 'test-plugin',
25
+ version: '1.0.0',
26
+ register: (reg) => {
27
+ reg.register('test', () => 'test');
28
+ }
29
+ };
30
+
31
+ // Use legacy mode (useScope: false) to test direct registry access
32
+ await pluginSystem.loadPlugin(plugin, registry, false);
33
+
34
+ expect(pluginSystem.isLoaded('test-plugin')).toBe(true);
35
+ expect(pluginSystem.getLoadedPlugins()).toContain('test-plugin');
36
+ expect(registry.has('test')).toBe(true);
37
+ });
38
+
39
+ it('should execute onLoad lifecycle hook', async () => {
40
+ const onLoad = vi.fn();
41
+ const plugin: PluginDefinition = {
42
+ name: 'test-plugin',
43
+ version: '1.0.0',
44
+ register: () => {},
45
+ onLoad
46
+ };
47
+
48
+ await pluginSystem.loadPlugin(plugin, registry);
49
+
50
+ expect(onLoad).toHaveBeenCalledTimes(1);
51
+ });
52
+
53
+ it('should execute async onLoad lifecycle hook', async () => {
54
+ const onLoad = vi.fn().mockResolvedValue(undefined);
55
+ const plugin: PluginDefinition = {
56
+ name: 'test-plugin',
57
+ version: '1.0.0',
58
+ register: () => {},
59
+ onLoad
60
+ };
61
+
62
+ await pluginSystem.loadPlugin(plugin, registry);
63
+
64
+ expect(onLoad).toHaveBeenCalledTimes(1);
65
+ });
66
+
67
+ it('should not load plugin twice', async () => {
68
+ const onLoad = vi.fn();
69
+ const plugin: PluginDefinition = {
70
+ name: 'test-plugin',
71
+ version: '1.0.0',
72
+ register: () => {},
73
+ onLoad
74
+ };
75
+
76
+ await pluginSystem.loadPlugin(plugin, registry);
77
+ await pluginSystem.loadPlugin(plugin, registry);
78
+
79
+ expect(onLoad).toHaveBeenCalledTimes(1);
80
+ });
81
+
82
+ it('should check dependencies before loading', async () => {
83
+ const plugin: PluginDefinition = {
84
+ name: 'dependent-plugin',
85
+ version: '1.0.0',
86
+ dependencies: ['base-plugin'],
87
+ register: () => {}
88
+ };
89
+
90
+ await expect(pluginSystem.loadPlugin(plugin, registry)).rejects.toThrow(
91
+ 'Missing dependency: base-plugin required by dependent-plugin'
92
+ );
93
+ });
94
+
95
+ it('should load plugins with dependencies in correct order', async () => {
96
+ const basePlugin: PluginDefinition = {
97
+ name: 'base-plugin',
98
+ version: '1.0.0',
99
+ register: () => {}
100
+ };
101
+
102
+ const dependentPlugin: PluginDefinition = {
103
+ name: 'dependent-plugin',
104
+ version: '1.0.0',
105
+ dependencies: ['base-plugin'],
106
+ register: () => {}
107
+ };
108
+
109
+ await pluginSystem.loadPlugin(basePlugin, registry);
110
+ await pluginSystem.loadPlugin(dependentPlugin, registry);
111
+
112
+ expect(pluginSystem.isLoaded('base-plugin')).toBe(true);
113
+ expect(pluginSystem.isLoaded('dependent-plugin')).toBe(true);
114
+ });
115
+
116
+ it('should unload a plugin', async () => {
117
+ const onUnload = vi.fn();
118
+ const plugin: PluginDefinition = {
119
+ name: 'test-plugin',
120
+ version: '1.0.0',
121
+ register: () => {},
122
+ onUnload
123
+ };
124
+
125
+ await pluginSystem.loadPlugin(plugin, registry);
126
+ expect(pluginSystem.isLoaded('test-plugin')).toBe(true);
127
+
128
+ await pluginSystem.unloadPlugin('test-plugin');
129
+
130
+ expect(pluginSystem.isLoaded('test-plugin')).toBe(false);
131
+ expect(onUnload).toHaveBeenCalledTimes(1);
132
+ });
133
+
134
+ it('should prevent unloading plugin with dependents', async () => {
135
+ const basePlugin: PluginDefinition = {
136
+ name: 'base-plugin',
137
+ version: '1.0.0',
138
+ register: () => {}
139
+ };
140
+
141
+ const dependentPlugin: PluginDefinition = {
142
+ name: 'dependent-plugin',
143
+ version: '1.0.0',
144
+ dependencies: ['base-plugin'],
145
+ register: () => {}
146
+ };
147
+
148
+ await pluginSystem.loadPlugin(basePlugin, registry);
149
+ await pluginSystem.loadPlugin(dependentPlugin, registry);
150
+
151
+ await expect(pluginSystem.unloadPlugin('base-plugin')).rejects.toThrow(
152
+ 'Cannot unload plugin "base-plugin" - plugin "dependent-plugin" depends on it'
153
+ );
154
+ });
155
+
156
+ it('should throw error when unloading non-existent plugin', async () => {
157
+ await expect(pluginSystem.unloadPlugin('non-existent')).rejects.toThrow(
158
+ 'Plugin "non-existent" is not loaded'
159
+ );
160
+ });
161
+
162
+ it('should get plugin definition', async () => {
163
+ const plugin: PluginDefinition = {
164
+ name: 'test-plugin',
165
+ version: '1.0.0',
166
+ register: () => {}
167
+ };
168
+
169
+ await pluginSystem.loadPlugin(plugin, registry);
170
+
171
+ const retrieved = pluginSystem.getPlugin('test-plugin');
172
+ expect(retrieved).toBe(plugin);
173
+ });
174
+
175
+ it('should get all plugins', async () => {
176
+ const plugin1: PluginDefinition = {
177
+ name: 'plugin-1',
178
+ version: '1.0.0',
179
+ register: () => {}
180
+ };
181
+
182
+ const plugin2: PluginDefinition = {
183
+ name: 'plugin-2',
184
+ version: '1.0.0',
185
+ register: () => {}
186
+ };
187
+
188
+ await pluginSystem.loadPlugin(plugin1, registry);
189
+ await pluginSystem.loadPlugin(plugin2, registry);
190
+
191
+ const allPlugins = pluginSystem.getAllPlugins();
192
+ expect(allPlugins).toHaveLength(2);
193
+ expect(allPlugins).toContain(plugin1);
194
+ expect(allPlugins).toContain(plugin2);
195
+ });
196
+
197
+ it('should call register function with registry', async () => {
198
+ const registerFn = vi.fn();
199
+ const plugin: PluginDefinition = {
200
+ name: 'test-plugin',
201
+ version: '1.0.0',
202
+ register: registerFn
203
+ };
204
+
205
+ // Use legacy mode (useScope: false) to verify the raw Registry is passed
206
+ await pluginSystem.loadPlugin(plugin, registry, false);
207
+
208
+ expect(registerFn).toHaveBeenCalledWith(registry);
209
+ expect(registerFn).toHaveBeenCalledTimes(1);
210
+ });
211
+
212
+ it('should cleanup on registration failure', async () => {
213
+ const plugin: PluginDefinition = {
214
+ name: 'failing-plugin',
215
+ version: '1.0.0',
216
+ register: () => {
217
+ throw new Error('Registration failed');
218
+ }
219
+ };
220
+
221
+ await expect(pluginSystem.loadPlugin(plugin, registry)).rejects.toThrow('Registration failed');
222
+
223
+ expect(pluginSystem.isLoaded('failing-plugin')).toBe(false);
224
+ expect(pluginSystem.getPlugin('failing-plugin')).toBeUndefined();
225
+ });
226
+ });
@@ -0,0 +1,293 @@
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
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
10
+ import { Registry } from '../Registry';
11
+
12
+ describe('Registry', () => {
13
+ let registry: Registry;
14
+ let consoleWarnSpy: any;
15
+
16
+ beforeEach(() => {
17
+ registry = new Registry();
18
+ consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
19
+ });
20
+
21
+ afterEach(() => {
22
+ consoleWarnSpy.mockRestore();
23
+ });
24
+
25
+ describe('Basic Registration', () => {
26
+ it('should register a component without namespace', () => {
27
+ const component = () => 'test';
28
+ registry.register('button', component);
29
+
30
+ expect(registry.has('button')).toBe(true);
31
+ expect(registry.get('button')).toBe(component);
32
+ });
33
+
34
+ it('should warn when registering without namespace', () => {
35
+ const component = () => 'test';
36
+ registry.register('button', component);
37
+
38
+ expect(consoleWarnSpy).toHaveBeenCalledWith(
39
+ expect.stringContaining('Registering component "button" without a namespace is deprecated')
40
+ );
41
+ });
42
+
43
+ it('should register a component with namespace', () => {
44
+ const component = () => 'test';
45
+ registry.register('button', component, { namespace: 'ui' });
46
+
47
+ expect(registry.has('button', 'ui')).toBe(true);
48
+ expect(registry.get('button', 'ui')).toBe(component);
49
+ });
50
+
51
+ it('should not warn when registering with namespace', () => {
52
+ const component = () => 'test';
53
+ registry.register('button', component, { namespace: 'ui' });
54
+
55
+ expect(consoleWarnSpy).not.toHaveBeenCalled();
56
+ });
57
+ });
58
+
59
+ describe('Namespaced Registration', () => {
60
+ it('should register components with the same name in different namespaces', () => {
61
+ const gridComponent1 = () => 'grid1';
62
+ const gridComponent2 = () => 'grid2';
63
+
64
+ registry.register('grid', gridComponent1, { namespace: 'plugin-grid' });
65
+ registry.register('grid', gridComponent2, { namespace: 'plugin-aggrid' });
66
+
67
+ expect(registry.get('grid', 'plugin-grid')).toBe(gridComponent1);
68
+ expect(registry.get('grid', 'plugin-aggrid')).toBe(gridComponent2);
69
+ });
70
+
71
+ it('should store full type as namespace:type', () => {
72
+ const component = () => 'test';
73
+ registry.register('button', component, { namespace: 'ui' });
74
+
75
+ const config = registry.getConfig('button', 'ui');
76
+ expect(config?.type).toBe('ui:button');
77
+ });
78
+
79
+ it('should preserve namespace in component config', () => {
80
+ const component = () => 'test';
81
+ registry.register('button', component, {
82
+ namespace: 'ui',
83
+ label: 'Button',
84
+ category: 'form'
85
+ });
86
+
87
+ const config = registry.getConfig('button', 'ui');
88
+ expect(config?.namespace).toBe('ui');
89
+ expect(config?.label).toBe('Button');
90
+ expect(config?.category).toBe('form');
91
+ });
92
+ });
93
+
94
+ describe('Namespace Lookup with Fallback', () => {
95
+ it('should not fallback when namespace is explicitly specified', () => {
96
+ const component = () => 'test';
97
+ registry.register('button', component);
98
+
99
+ // When no namespace is specified, should find it
100
+ expect(registry.get('button')).toBe(component);
101
+
102
+ // When namespace is specified but component isn't in that namespace, should return undefined
103
+ expect(registry.get('button', 'ui')).toBeUndefined();
104
+ });
105
+
106
+ it('should prefer namespaced component over non-namespaced', () => {
107
+ const component1 = () => 'non-namespaced';
108
+ const component2 = () => 'namespaced';
109
+
110
+ registry.register('button', component1);
111
+ registry.register('button', component2, { namespace: 'ui' });
112
+
113
+ // When searching with namespace, should get namespaced version
114
+ expect(registry.get('button', 'ui')).toBe(component2);
115
+
116
+ // When searching without namespace, should get the latest registered (namespaced one due to backward compatibility)
117
+ expect(registry.get('button')).toBe(component2);
118
+ });
119
+
120
+ it('should return undefined when component not found in any namespace', () => {
121
+ expect(registry.get('nonexistent', 'ui')).toBeUndefined();
122
+ expect(registry.get('nonexistent')).toBeUndefined();
123
+ });
124
+ });
125
+
126
+ describe('has() method', () => {
127
+ it('should check existence with namespace', () => {
128
+ const component = () => 'test';
129
+ registry.register('button', component, { namespace: 'ui' });
130
+
131
+ expect(registry.has('button', 'ui')).toBe(true);
132
+ // Due to backward compatibility, non-namespaced lookup also works
133
+ expect(registry.has('button')).toBe(true);
134
+ // Other namespaces should return false
135
+ expect(registry.has('button', 'other')).toBe(false);
136
+ });
137
+
138
+ it('should fallback to non-namespaced check only when no namespace provided', () => {
139
+ const component = () => 'test';
140
+ registry.register('button', component);
141
+
142
+ expect(registry.has('button')).toBe(true);
143
+ // When namespace is explicitly requested, should not find non-namespaced component
144
+ expect(registry.has('button', 'ui')).toBe(false);
145
+ });
146
+ });
147
+
148
+ describe('getConfig() method', () => {
149
+ it('should get config with namespace', () => {
150
+ const component = () => 'test';
151
+ registry.register('button', component, {
152
+ namespace: 'ui',
153
+ label: 'Button'
154
+ });
155
+
156
+ const config = registry.getConfig('button', 'ui');
157
+ expect(config).toBeDefined();
158
+ expect(config?.component).toBe(component);
159
+ expect(config?.label).toBe('Button');
160
+ });
161
+
162
+ it('should not fallback when namespace is explicitly provided', () => {
163
+ const component = () => 'test';
164
+ registry.register('button', component, { label: 'Button' });
165
+
166
+ // When no namespace is provided, should find it
167
+ const config1 = registry.getConfig('button');
168
+ expect(config1).toBeDefined();
169
+
170
+ // When namespace is provided but component isn't in that namespace, should return undefined
171
+ const config2 = registry.getConfig('button', 'ui');
172
+ expect(config2).toBeUndefined();
173
+ });
174
+ });
175
+
176
+ describe('getAllTypes() and getAllConfigs()', () => {
177
+ it('should return all registered types including namespaced ones', () => {
178
+ registry.register('button', () => 'b1');
179
+ registry.register('input', () => 'i1', { namespace: 'ui' });
180
+ registry.register('grid', () => 'g1', { namespace: 'plugin-grid' });
181
+
182
+ const types = registry.getAllTypes();
183
+ // Due to backward compatibility, namespaced components are stored under both keys
184
+ expect(types).toContain('button');
185
+ expect(types).toContain('ui:input');
186
+ expect(types).toContain('input'); // backward compat
187
+ expect(types).toContain('plugin-grid:grid');
188
+ expect(types).toContain('grid'); // backward compat
189
+ });
190
+
191
+ it('should return all configs', () => {
192
+ registry.register('button', () => 'b1', { label: 'Button' });
193
+ registry.register('input', () => 'i1', {
194
+ namespace: 'ui',
195
+ label: 'Input'
196
+ });
197
+
198
+ const configs = registry.getAllConfigs();
199
+ // Due to backward compatibility, namespaced components are stored twice
200
+ expect(configs.length).toBeGreaterThanOrEqual(2);
201
+ expect(configs.map(c => c.type)).toContain('button');
202
+ expect(configs.map(c => c.type)).toContain('ui:input');
203
+ });
204
+ });
205
+
206
+ describe('Conflict Prevention', () => {
207
+ it('should allow same type name in different namespaces', () => {
208
+ const grid1 = () => 'grid-plugin-1';
209
+ const grid2 = () => 'grid-plugin-2';
210
+ const grid3 = () => 'aggrid-plugin';
211
+
212
+ registry.register('grid', grid1, { namespace: 'plugin-grid' });
213
+ registry.register('grid', grid2, { namespace: 'plugin-view' });
214
+ registry.register('grid', grid3, { namespace: 'plugin-aggrid' });
215
+
216
+ expect(registry.get('grid', 'plugin-grid')).toBe(grid1);
217
+ expect(registry.get('grid', 'plugin-view')).toBe(grid2);
218
+ expect(registry.get('grid', 'plugin-aggrid')).toBe(grid3);
219
+ });
220
+
221
+ it('should handle complex namespace names', () => {
222
+ const component = () => 'test';
223
+ registry.register('table', component, { namespace: 'plugin-advanced-grid' });
224
+
225
+ expect(registry.get('table', 'plugin-advanced-grid')).toBe(component);
226
+ expect(registry.getConfig('table', 'plugin-advanced-grid')?.type).toBe('plugin-advanced-grid:table');
227
+ });
228
+ });
229
+
230
+ describe('Backward Compatibility', () => {
231
+ it('should maintain compatibility with existing non-namespaced code', () => {
232
+ const component = () => 'test';
233
+
234
+ // Old-style registration
235
+ registry.register('button', component);
236
+
237
+ // Old-style retrieval should still work
238
+ expect(registry.get('button')).toBe(component);
239
+ expect(registry.has('button')).toBe(true);
240
+ expect(registry.getConfig('button')).toBeDefined();
241
+ });
242
+
243
+ it('should support mixed namespaced and non-namespaced registrations', () => {
244
+ const oldButton = () => 'old';
245
+ const newButton = () => 'new';
246
+
247
+ registry.register('button-old', oldButton);
248
+ registry.register('button-new', newButton, { namespace: 'ui' });
249
+
250
+ expect(registry.get('button-old')).toBe(oldButton);
251
+ expect(registry.get('button-new', 'ui')).toBe(newButton);
252
+ });
253
+
254
+ it('should allow non-namespaced lookup of namespaced components', () => {
255
+ const component = () => 'test';
256
+
257
+ // Register with namespace
258
+ registry.register('button', component, { namespace: 'ui' });
259
+
260
+ // Should be findable both ways for backward compatibility
261
+ expect(registry.get('button')).toBe(component);
262
+ expect(registry.get('button', 'ui')).toBe(component);
263
+
264
+ // The full type should be namespaced
265
+ const config = registry.getConfig('button');
266
+ expect(config?.type).toBe('ui:button');
267
+ });
268
+ });
269
+
270
+ describe('Edge Cases', () => {
271
+ it('should handle empty namespace string', () => {
272
+ const component = () => 'test';
273
+ registry.register('button', component, { namespace: '' });
274
+
275
+ // Empty namespace should be treated as no namespace
276
+ expect(registry.get('button')).toBe(component);
277
+ });
278
+
279
+ it('should handle namespace with special characters', () => {
280
+ const component = () => 'test';
281
+ registry.register('button', component, { namespace: 'plugin-my-custom' });
282
+
283
+ expect(registry.get('button', 'plugin-my-custom')).toBe(component);
284
+ });
285
+
286
+ it('should handle undefined meta', () => {
287
+ const component = () => 'test';
288
+ registry.register('button', component, undefined);
289
+
290
+ expect(registry.get('button')).toBe(component);
291
+ });
292
+ });
293
+ });