@object-ui/core 0.3.0 → 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 (90) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +8 -0
  3. package/dist/actions/ActionRunner.d.ts +40 -0
  4. package/dist/actions/ActionRunner.js +160 -0
  5. package/dist/actions/index.d.ts +8 -0
  6. package/dist/actions/index.js +8 -0
  7. package/dist/adapters/index.d.ts +7 -0
  8. package/dist/adapters/index.js +10 -0
  9. package/dist/builder/schema-builder.d.ts +7 -0
  10. package/dist/builder/schema-builder.js +4 -6
  11. package/dist/evaluator/ExpressionCache.d.ts +101 -0
  12. package/dist/evaluator/ExpressionCache.js +135 -0
  13. package/dist/evaluator/ExpressionContext.d.ts +51 -0
  14. package/dist/evaluator/ExpressionContext.js +110 -0
  15. package/dist/evaluator/ExpressionEvaluator.d.ts +117 -0
  16. package/dist/evaluator/ExpressionEvaluator.js +220 -0
  17. package/dist/evaluator/index.d.ts +10 -0
  18. package/dist/evaluator/index.js +10 -0
  19. package/dist/index.d.ts +17 -4
  20. package/dist/index.js +16 -5
  21. package/dist/query/index.d.ts +6 -0
  22. package/dist/query/index.js +6 -0
  23. package/dist/query/query-ast.d.ts +32 -0
  24. package/dist/query/query-ast.js +268 -0
  25. package/dist/registry/PluginScopeImpl.d.ts +80 -0
  26. package/dist/registry/PluginScopeImpl.js +243 -0
  27. package/dist/registry/PluginSystem.d.ts +66 -0
  28. package/dist/registry/PluginSystem.js +142 -0
  29. package/dist/registry/Registry.d.ts +80 -4
  30. package/dist/registry/Registry.js +119 -7
  31. package/dist/types/index.d.ts +7 -0
  32. package/dist/types/index.js +7 -0
  33. package/dist/utils/filter-converter.d.ts +57 -0
  34. package/dist/utils/filter-converter.js +100 -0
  35. package/dist/validation/index.d.ts +9 -0
  36. package/dist/validation/index.js +9 -0
  37. package/dist/validation/schema-validator.d.ts +7 -0
  38. package/dist/validation/schema-validator.js +4 -6
  39. package/dist/validation/validation-engine.d.ts +70 -0
  40. package/dist/validation/validation-engine.js +363 -0
  41. package/dist/validation/validators/index.d.ts +16 -0
  42. package/dist/validation/validators/index.js +16 -0
  43. package/dist/validation/validators/object-validation-engine.d.ts +118 -0
  44. package/dist/validation/validators/object-validation-engine.js +538 -0
  45. package/package.json +26 -7
  46. package/src/actions/ActionRunner.ts +195 -0
  47. package/src/actions/index.ts +9 -0
  48. package/src/adapters/README.md +180 -0
  49. package/src/adapters/index.ts +10 -0
  50. package/src/builder/schema-builder.ts +8 -0
  51. package/src/evaluator/ExpressionCache.ts +192 -0
  52. package/src/evaluator/ExpressionContext.ts +118 -0
  53. package/src/evaluator/ExpressionEvaluator.ts +267 -0
  54. package/src/evaluator/__tests__/ExpressionCache.test.ts +135 -0
  55. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +101 -0
  56. package/src/evaluator/index.ts +11 -0
  57. package/src/index.test.ts +8 -0
  58. package/src/index.ts +18 -5
  59. package/src/query/__tests__/query-ast.test.ts +211 -0
  60. package/src/query/__tests__/window-functions.test.ts +275 -0
  61. package/src/query/index.ts +7 -0
  62. package/src/query/query-ast.ts +341 -0
  63. package/src/registry/PluginScopeImpl.ts +259 -0
  64. package/src/registry/PluginSystem.ts +161 -0
  65. package/src/registry/Registry.ts +133 -8
  66. package/src/registry/__tests__/PluginSystem.test.ts +226 -0
  67. package/src/registry/__tests__/Registry.test.ts +293 -0
  68. package/src/registry/__tests__/plugin-scope-integration.test.ts +283 -0
  69. package/src/types/index.ts +8 -0
  70. package/src/utils/__tests__/filter-converter.test.ts +118 -0
  71. package/src/utils/filter-converter.ts +133 -0
  72. package/src/validation/__tests__/object-validation-engine.test.ts +567 -0
  73. package/src/validation/__tests__/validation-engine.test.ts +102 -0
  74. package/src/validation/index.ts +10 -0
  75. package/src/validation/schema-validator.ts +8 -0
  76. package/src/validation/validation-engine.ts +461 -0
  77. package/src/validation/validators/index.ts +25 -0
  78. package/src/validation/validators/object-validation-engine.ts +722 -0
  79. package/tsconfig.tsbuildinfo +1 -1
  80. package/vitest.config.ts +2 -0
  81. package/src/builder/schema-builder.d.ts +0 -287
  82. package/src/builder/schema-builder.js +0 -505
  83. package/src/index.d.ts +0 -4
  84. package/src/index.js +0 -7
  85. package/src/registry/Registry.d.ts +0 -49
  86. package/src/registry/Registry.js +0 -36
  87. package/src/types/index.d.ts +0 -12
  88. package/src/types/index.js +0 -1
  89. package/src/validation/schema-validator.d.ts +0 -87
  90. package/src/validation/schema-validator.js +0 -280
@@ -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
+ });
@@ -0,0 +1,283 @@
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
+ /**
10
+ * Plugin Scope Integration Tests
11
+ * Section 3.3: Test scoped plugin system to ensure isolation
12
+ */
13
+
14
+ import { describe, it, expect, beforeEach } from 'vitest';
15
+ import { Registry } from '../Registry';
16
+ import { PluginSystem } from '../PluginSystem';
17
+ import type { PluginScope } from '@object-ui/types';
18
+
19
+ describe('Plugin Scope Integration', () => {
20
+ let registry: Registry;
21
+ let pluginSystem: PluginSystem;
22
+
23
+ beforeEach(() => {
24
+ registry = new Registry();
25
+ pluginSystem = new PluginSystem();
26
+ });
27
+
28
+ describe('Component Registration Isolation', () => {
29
+ it('should isolate component registrations between plugins', async () => {
30
+ const MockTableA = () => 'Table A';
31
+ const MockTableB = () => 'Table B';
32
+
33
+ const pluginA = {
34
+ name: 'plugin-a',
35
+ version: '1.0.0',
36
+ register: (scope: PluginScope) => {
37
+ scope.registerComponent('table', MockTableA);
38
+ },
39
+ };
40
+
41
+ const pluginB = {
42
+ name: 'plugin-b',
43
+ version: '1.0.0',
44
+ register: (scope: PluginScope) => {
45
+ scope.registerComponent('table', MockTableB);
46
+ },
47
+ };
48
+
49
+ await pluginSystem.loadPlugin(pluginA, registry, true);
50
+ await pluginSystem.loadPlugin(pluginB, registry, true);
51
+
52
+ // Both plugins should have their own namespaced component
53
+ const tableA = registry.getConfig('plugin-a:table');
54
+ const tableB = registry.getConfig('plugin-b:table');
55
+
56
+ expect(tableA).toBeDefined();
57
+ expect(tableB).toBeDefined();
58
+ expect(tableA?.component).toBe(MockTableA);
59
+ expect(tableB?.component).toBe(MockTableB);
60
+ });
61
+
62
+ it('should allow scoped component to access global components', async () => {
63
+ const GlobalButton = () => 'Global Button';
64
+ const MockGrid = () => 'Grid';
65
+
66
+ // Register a global component
67
+ registry.register('button', GlobalButton);
68
+
69
+ const plugin = {
70
+ name: 'plugin-grid',
71
+ version: '1.0.0',
72
+ register: (scope: PluginScope) => {
73
+ scope.registerComponent('grid', MockGrid);
74
+
75
+ // Plugin should be able to access global components
76
+ const button = scope.getComponent('button');
77
+ expect(button).toBe(GlobalButton);
78
+ },
79
+ };
80
+
81
+ await pluginSystem.loadPlugin(plugin, registry, true);
82
+ });
83
+ });
84
+
85
+ describe('State Management Isolation', () => {
86
+ it('should isolate state between plugins', async () => {
87
+ let stateA: any;
88
+ let stateB: any;
89
+
90
+ const pluginA = {
91
+ name: 'plugin-a',
92
+ version: '1.0.0',
93
+ register: (scope: PluginScope) => {
94
+ const [config, setConfig] = scope.useState('config', { theme: 'dark' });
95
+ stateA = config;
96
+ setConfig({ theme: 'light' });
97
+ },
98
+ };
99
+
100
+ const pluginB = {
101
+ name: 'plugin-b',
102
+ version: '1.0.0',
103
+ register: (scope: PluginScope) => {
104
+ const [config, setConfig] = scope.useState('config', { theme: 'auto' });
105
+ stateB = config;
106
+ },
107
+ };
108
+
109
+ await pluginSystem.loadPlugin(pluginA, registry, true);
110
+ await pluginSystem.loadPlugin(pluginB, registry, true);
111
+
112
+ // State should be isolated
113
+ const scopeA = pluginSystem.getScope('plugin-a');
114
+ const scopeB = pluginSystem.getScope('plugin-b');
115
+
116
+ expect(scopeA?.getState('config')).toEqual({ theme: 'light' });
117
+ expect(scopeB?.getState('config')).toEqual({ theme: 'auto' });
118
+ });
119
+
120
+ it('should enforce state size limits', async () => {
121
+ const plugin = {
122
+ name: 'plugin-heavy',
123
+ version: '1.0.0',
124
+ scopeConfig: {
125
+ maxStateSize: 100, // Very small limit for testing
126
+ },
127
+ register: (scope: PluginScope) => {
128
+ // This should throw due to size limit
129
+ expect(() => {
130
+ scope.setState('largeData', {
131
+ data: 'x'.repeat(1000), // Much larger than 100 bytes
132
+ });
133
+ }).toThrow(/exceeded maximum state size/);
134
+ },
135
+ };
136
+
137
+ await pluginSystem.loadPlugin(plugin, registry, true);
138
+ });
139
+ });
140
+
141
+ describe('Event Bus Isolation', () => {
142
+ it('should isolate events between plugins', async () => {
143
+ const eventsA: any[] = [];
144
+ const eventsB: any[] = [];
145
+
146
+ const pluginA = {
147
+ name: 'plugin-a',
148
+ version: '1.0.0',
149
+ register: (scope: PluginScope) => {
150
+ scope.on('data-updated', (data) => {
151
+ eventsA.push(data);
152
+ });
153
+
154
+ scope.emit('data-updated', { source: 'A' });
155
+ },
156
+ };
157
+
158
+ const pluginB = {
159
+ name: 'plugin-b',
160
+ version: '1.0.0',
161
+ register: (scope: PluginScope) => {
162
+ scope.on('data-updated', (data) => {
163
+ eventsB.push(data);
164
+ });
165
+
166
+ scope.emit('data-updated', { source: 'B' });
167
+ },
168
+ };
169
+
170
+ await pluginSystem.loadPlugin(pluginA, registry, true);
171
+ await pluginSystem.loadPlugin(pluginB, registry, true);
172
+
173
+ // Events should be isolated - plugin A should only see its own events
174
+ expect(eventsA).toHaveLength(1);
175
+ expect(eventsA[0]).toEqual({ source: 'A' });
176
+
177
+ expect(eventsB).toHaveLength(1);
178
+ expect(eventsB[0]).toEqual({ source: 'B' });
179
+ });
180
+
181
+ it('should support global events for cross-plugin communication', async () => {
182
+ const globalEvents: any[] = [];
183
+
184
+ const pluginA = {
185
+ name: 'plugin-a',
186
+ version: '1.0.0',
187
+ register: (scope: PluginScope) => {
188
+ scope.onGlobal('app-ready', (data) => {
189
+ globalEvents.push({ plugin: 'A', data });
190
+ });
191
+ },
192
+ };
193
+
194
+ const pluginB = {
195
+ name: 'plugin-b',
196
+ version: '1.0.0',
197
+ register: (scope: PluginScope) => {
198
+ scope.onGlobal('app-ready', (data) => {
199
+ globalEvents.push({ plugin: 'B', data });
200
+ });
201
+
202
+ // Emit global event
203
+ scope.emitGlobal('app-ready', { status: 'ready' });
204
+ },
205
+ };
206
+
207
+ await pluginSystem.loadPlugin(pluginA, registry, true);
208
+ await pluginSystem.loadPlugin(pluginB, registry, true);
209
+
210
+ // Both plugins should receive the global event
211
+ expect(globalEvents).toHaveLength(2);
212
+ expect(globalEvents[0]).toEqual({ plugin: 'A', data: { status: 'ready' } });
213
+ expect(globalEvents[1]).toEqual({ plugin: 'B', data: { status: 'ready' } });
214
+ });
215
+ });
216
+
217
+ describe('Plugin Lifecycle', () => {
218
+ it('should cleanup plugin resources on unload', async () => {
219
+ const plugin = {
220
+ name: 'plugin-temp',
221
+ version: '1.0.0',
222
+ register: (scope: PluginScope) => {
223
+ scope.setState('data', { value: 123 });
224
+ scope.registerComponent('temp', () => 'Temp');
225
+ },
226
+ };
227
+
228
+ await pluginSystem.loadPlugin(plugin, registry, true);
229
+
230
+ const scope = pluginSystem.getScope('plugin-temp');
231
+ expect(scope?.getState('data')).toEqual({ value: 123 });
232
+
233
+ await pluginSystem.unloadPlugin('plugin-temp');
234
+
235
+ // Scope should be cleaned up
236
+ expect(pluginSystem.getScope('plugin-temp')).toBeUndefined();
237
+ });
238
+
239
+ it('should call lifecycle hooks', async () => {
240
+ let loadCalled = false;
241
+ let unloadCalled = false;
242
+
243
+ const plugin = {
244
+ name: 'plugin-lifecycle',
245
+ version: '1.0.0',
246
+ register: () => {},
247
+ onLoad: async () => {
248
+ loadCalled = true;
249
+ },
250
+ onUnload: async () => {
251
+ unloadCalled = true;
252
+ },
253
+ };
254
+
255
+ await pluginSystem.loadPlugin(plugin, registry, true);
256
+ expect(loadCalled).toBe(true);
257
+
258
+ await pluginSystem.unloadPlugin('plugin-lifecycle');
259
+ expect(unloadCalled).toBe(true);
260
+ });
261
+ });
262
+
263
+ describe('Legacy Compatibility', () => {
264
+ it('should support legacy plugins without scopes', async () => {
265
+ const MockComponent = () => 'Legacy';
266
+
267
+ const legacyPlugin = {
268
+ name: 'legacy-plugin',
269
+ version: '1.0.0',
270
+ register: (reg: Registry) => {
271
+ reg.register('legacy', MockComponent);
272
+ },
273
+ };
274
+
275
+ // Load without scope
276
+ await pluginSystem.loadPlugin(legacyPlugin, registry, false);
277
+
278
+ // Component should be registered directly
279
+ const component = registry.getConfig('legacy');
280
+ expect(component?.component).toBe(MockComponent);
281
+ });
282
+ });
283
+ });
@@ -1,3 +1,11 @@
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
+
1
9
  export interface SchemaNode {
2
10
  type: string;
3
11
  id?: string;