@object-ui/core 3.3.0 → 3.3.1

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 (99) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +20 -1
  3. package/dist/actions/ActionRunner.d.ts +9 -0
  4. package/dist/actions/ActionRunner.js +41 -4
  5. package/dist/adapters/ValueDataSource.js +3 -1
  6. package/dist/utils/filter-converter.js +25 -5
  7. package/package.json +32 -8
  8. package/.turbo/turbo-build.log +0 -4
  9. package/src/__benchmarks__/core.bench.ts +0 -64
  10. package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
  11. package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
  12. package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
  13. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
  14. package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
  15. package/src/actions/ActionEngine.ts +0 -268
  16. package/src/actions/ActionRunner.ts +0 -717
  17. package/src/actions/TransactionManager.ts +0 -521
  18. package/src/actions/UndoManager.ts +0 -215
  19. package/src/actions/__tests__/ActionEngine.test.ts +0 -206
  20. package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
  21. package/src/actions/__tests__/ActionRunner.test.ts +0 -711
  22. package/src/actions/__tests__/TransactionManager.test.ts +0 -447
  23. package/src/actions/__tests__/UndoManager.test.ts +0 -320
  24. package/src/actions/index.ts +0 -12
  25. package/src/adapters/ApiDataSource.ts +0 -376
  26. package/src/adapters/README.md +0 -180
  27. package/src/adapters/ValueDataSource.ts +0 -459
  28. package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
  29. package/src/adapters/__tests__/ValueDataSource.test.ts +0 -571
  30. package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
  31. package/src/adapters/index.ts +0 -15
  32. package/src/adapters/resolveDataSource.ts +0 -79
  33. package/src/builder/__tests__/schema-builder.test.ts +0 -235
  34. package/src/builder/schema-builder.ts +0 -584
  35. package/src/data-scope/DataScopeManager.ts +0 -269
  36. package/src/data-scope/ViewDataProvider.ts +0 -282
  37. package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
  38. package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
  39. package/src/data-scope/index.ts +0 -24
  40. package/src/errors/__tests__/errors.test.ts +0 -292
  41. package/src/errors/index.ts +0 -269
  42. package/src/evaluator/ExpressionCache.ts +0 -206
  43. package/src/evaluator/ExpressionContext.ts +0 -118
  44. package/src/evaluator/ExpressionEvaluator.ts +0 -315
  45. package/src/evaluator/FormulaFunctions.ts +0 -398
  46. package/src/evaluator/SafeExpressionParser.ts +0 -893
  47. package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
  48. package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
  49. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -558
  50. package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
  51. package/src/evaluator/index.ts +0 -13
  52. package/src/index.ts +0 -38
  53. package/src/protocols/DndProtocol.ts +0 -168
  54. package/src/protocols/KeyboardProtocol.ts +0 -181
  55. package/src/protocols/NotificationProtocol.ts +0 -150
  56. package/src/protocols/ResponsiveProtocol.ts +0 -210
  57. package/src/protocols/SharingProtocol.ts +0 -185
  58. package/src/protocols/index.ts +0 -13
  59. package/src/query/__tests__/query-ast.test.ts +0 -211
  60. package/src/query/__tests__/window-functions.test.ts +0 -275
  61. package/src/query/index.ts +0 -7
  62. package/src/query/query-ast.ts +0 -341
  63. package/src/registry/PluginScopeImpl.ts +0 -259
  64. package/src/registry/PluginSystem.ts +0 -206
  65. package/src/registry/Registry.ts +0 -219
  66. package/src/registry/WidgetRegistry.ts +0 -316
  67. package/src/registry/__tests__/PluginSystem.test.ts +0 -309
  68. package/src/registry/__tests__/Registry.test.ts +0 -293
  69. package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
  70. package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
  71. package/src/theme/ThemeEngine.ts +0 -530
  72. package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
  73. package/src/theme/index.ts +0 -24
  74. package/src/types/index.ts +0 -21
  75. package/src/utils/__tests__/debug-collector.test.ts +0 -102
  76. package/src/utils/__tests__/debug.test.ts +0 -134
  77. package/src/utils/__tests__/expand-fields.test.ts +0 -120
  78. package/src/utils/__tests__/extract-records.test.ts +0 -50
  79. package/src/utils/__tests__/filter-converter.test.ts +0 -118
  80. package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
  81. package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
  82. package/src/utils/debug-collector.ts +0 -100
  83. package/src/utils/debug.ts +0 -148
  84. package/src/utils/expand-fields.ts +0 -76
  85. package/src/utils/extract-records.ts +0 -33
  86. package/src/utils/filter-converter.ts +0 -133
  87. package/src/utils/merge-views-into-objects.ts +0 -36
  88. package/src/utils/normalize-quick-filter.ts +0 -78
  89. package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
  90. package/src/validation/__tests__/schema-validator.test.ts +0 -118
  91. package/src/validation/__tests__/validation-engine.test.ts +0 -102
  92. package/src/validation/index.ts +0 -10
  93. package/src/validation/schema-validator.ts +0 -344
  94. package/src/validation/validation-engine.ts +0 -528
  95. package/src/validation/validators/index.ts +0 -25
  96. package/src/validation/validators/object-validation-engine.ts +0 -722
  97. package/tsconfig.json +0 -15
  98. package/tsconfig.tsbuildinfo +0 -1
  99. package/vitest.config.ts +0 -2
@@ -1,293 +0,0 @@
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
- });
@@ -1,321 +0,0 @@
1
- /**
2
- * Tests for WidgetRegistry
3
- */
4
-
5
- import { describe, it, expect, vi, beforeEach } from 'vitest';
6
- import { WidgetRegistry } from '../WidgetRegistry';
7
- import { Registry } from '../Registry';
8
- import type { WidgetManifest, WidgetRegistryEvent } from '@object-ui/types';
9
-
10
- function createManifest(overrides: Partial<WidgetManifest> = {}): WidgetManifest {
11
- return {
12
- name: 'test-widget',
13
- version: '1.0.0',
14
- type: 'test',
15
- label: 'Test Widget',
16
- source: { type: 'inline', component: () => null },
17
- ...overrides,
18
- };
19
- }
20
-
21
- describe('WidgetRegistry', () => {
22
- let widgetRegistry: WidgetRegistry;
23
-
24
- beforeEach(() => {
25
- widgetRegistry = new WidgetRegistry();
26
- });
27
-
28
- describe('register / unregister', () => {
29
- it('registers a widget manifest', () => {
30
- const manifest = createManifest();
31
- widgetRegistry.register(manifest);
32
- expect(widgetRegistry.has('test-widget')).toBe(true);
33
- expect(widgetRegistry.getManifest('test-widget')).toBe(manifest);
34
- });
35
-
36
- it('registers multiple manifests at once', () => {
37
- widgetRegistry.registerAll([
38
- createManifest({ name: 'a', type: 'a' }),
39
- createManifest({ name: 'b', type: 'b' }),
40
- ]);
41
- expect(widgetRegistry.has('a')).toBe(true);
42
- expect(widgetRegistry.has('b')).toBe(true);
43
- });
44
-
45
- it('unregisters a widget', () => {
46
- widgetRegistry.register(createManifest());
47
- expect(widgetRegistry.unregister('test-widget')).toBe(true);
48
- expect(widgetRegistry.has('test-widget')).toBe(false);
49
- });
50
-
51
- it('returns false when unregistering a non-existent widget', () => {
52
- expect(widgetRegistry.unregister('nope')).toBe(false);
53
- });
54
- });
55
-
56
- describe('getAllManifests / getByCategory', () => {
57
- it('returns all manifests', () => {
58
- widgetRegistry.registerAll([
59
- createManifest({ name: 'a', type: 'a' }),
60
- createManifest({ name: 'b', type: 'b' }),
61
- ]);
62
- expect(widgetRegistry.getAllManifests()).toHaveLength(2);
63
- });
64
-
65
- it('filters by category', () => {
66
- widgetRegistry.registerAll([
67
- createManifest({ name: 'chart-1', type: 'c1', category: 'charts' }),
68
- createManifest({ name: 'form-1', type: 'f1', category: 'forms' }),
69
- createManifest({ name: 'chart-2', type: 'c2', category: 'charts' }),
70
- ]);
71
- expect(widgetRegistry.getByCategory('charts')).toHaveLength(2);
72
- expect(widgetRegistry.getByCategory('forms')).toHaveLength(1);
73
- expect(widgetRegistry.getByCategory('unknown')).toHaveLength(0);
74
- });
75
- });
76
-
77
- describe('load', () => {
78
- it('loads an inline widget', async () => {
79
- const component = () => null;
80
- widgetRegistry.register(
81
- createManifest({ source: { type: 'inline', component } }),
82
- );
83
-
84
- const resolved = await widgetRegistry.load('test-widget');
85
- expect(resolved.component).toBe(component);
86
- expect(resolved.manifest.name).toBe('test-widget');
87
- expect(resolved.loadedAt).toBeGreaterThan(0);
88
- expect(widgetRegistry.isLoaded('test-widget')).toBe(true);
89
- });
90
-
91
- it('returns cached resolved widget on subsequent loads', async () => {
92
- widgetRegistry.register(createManifest());
93
- const first = await widgetRegistry.load('test-widget');
94
- const second = await widgetRegistry.load('test-widget');
95
- expect(first).toBe(second);
96
- });
97
-
98
- it('throws when loading an unregistered widget', async () => {
99
- await expect(widgetRegistry.load('nope')).rejects.toThrow(
100
- 'Widget "nope" is not registered',
101
- );
102
- });
103
-
104
- it('loads a widget from the component registry', async () => {
105
- const componentRegistry = new Registry();
106
- const component = () => null;
107
- componentRegistry.register('existing-type', component);
108
-
109
- const reg = new WidgetRegistry({ componentRegistry });
110
- reg.register(
111
- createManifest({
112
- source: { type: 'registry', registryKey: 'existing-type' },
113
- }),
114
- );
115
-
116
- const resolved = await reg.load('test-widget');
117
- expect(resolved.component).toBe(component);
118
- });
119
-
120
- it('throws when registry key is not found', async () => {
121
- const componentRegistry = new Registry();
122
- const reg = new WidgetRegistry({ componentRegistry });
123
- reg.register(
124
- createManifest({
125
- source: { type: 'registry', registryKey: 'missing-key' },
126
- }),
127
- );
128
-
129
- await expect(reg.load('test-widget')).rejects.toThrow(
130
- 'references registry key "missing-key"',
131
- );
132
- });
133
-
134
- it('throws when no component registry is configured for registry source', async () => {
135
- widgetRegistry.register(
136
- createManifest({
137
- source: { type: 'registry', registryKey: 'something' },
138
- }),
139
- );
140
-
141
- await expect(widgetRegistry.load('test-widget')).rejects.toThrow(
142
- 'no component registry is configured',
143
- );
144
- });
145
-
146
- it('resolves dependencies before loading', async () => {
147
- const loadOrder: string[] = [];
148
-
149
- widgetRegistry.register(
150
- createManifest({
151
- name: 'dep-a',
152
- type: 'dep-a',
153
- source: {
154
- type: 'inline',
155
- component: () => {
156
- loadOrder.push('dep-a');
157
- return null;
158
- },
159
- },
160
- }),
161
- );
162
-
163
- widgetRegistry.register(
164
- createManifest({
165
- name: 'main',
166
- type: 'main',
167
- dependencies: ['dep-a'],
168
- source: {
169
- type: 'inline',
170
- component: () => {
171
- loadOrder.push('main');
172
- return null;
173
- },
174
- },
175
- }),
176
- );
177
-
178
- await widgetRegistry.load('main');
179
- expect(widgetRegistry.isLoaded('dep-a')).toBe(true);
180
- expect(widgetRegistry.isLoaded('main')).toBe(true);
181
- });
182
-
183
- it('syncs loaded widget to component registry', async () => {
184
- const componentRegistry = new Registry();
185
- const reg = new WidgetRegistry({ componentRegistry });
186
- const component = () => null;
187
-
188
- reg.register(
189
- createManifest({
190
- name: 'sync-test',
191
- type: 'custom-type',
192
- label: 'Sync Test',
193
- category: 'testing',
194
- source: { type: 'inline', component },
195
- }),
196
- );
197
-
198
- await reg.load('sync-test');
199
-
200
- const synced = componentRegistry.get('custom-type');
201
- expect(synced).toBe(component);
202
- });
203
- });
204
-
205
- describe('loadAll', () => {
206
- it('loads all registered widgets', async () => {
207
- widgetRegistry.registerAll([
208
- createManifest({ name: 'a', type: 'a' }),
209
- createManifest({ name: 'b', type: 'b' }),
210
- ]);
211
-
212
- const results = await widgetRegistry.loadAll();
213
- expect(results).toHaveLength(2);
214
- expect(results.every((r) => !(r.result instanceof Error))).toBe(true);
215
- });
216
-
217
- it('captures errors for failed widgets', async () => {
218
- widgetRegistry.register(createManifest({ name: 'good', type: 'good' }));
219
- widgetRegistry.register(
220
- createManifest({
221
- name: 'bad',
222
- type: 'bad',
223
- source: { type: 'registry', registryKey: 'missing' },
224
- }),
225
- );
226
-
227
- const results = await widgetRegistry.loadAll();
228
- const bad = results.find((r) => r.name === 'bad');
229
- expect(bad?.result).toBeInstanceOf(Error);
230
- });
231
- });
232
-
233
- describe('events', () => {
234
- it('emits widget:registered event', () => {
235
- const events: WidgetRegistryEvent[] = [];
236
- widgetRegistry.on((e) => events.push(e));
237
-
238
- widgetRegistry.register(createManifest());
239
-
240
- expect(events).toHaveLength(1);
241
- expect(events[0].type).toBe('widget:registered');
242
- });
243
-
244
- it('emits widget:unregistered event', () => {
245
- widgetRegistry.register(createManifest());
246
-
247
- const events: WidgetRegistryEvent[] = [];
248
- widgetRegistry.on((e) => events.push(e));
249
-
250
- widgetRegistry.unregister('test-widget');
251
-
252
- expect(events).toHaveLength(1);
253
- expect(events[0].type).toBe('widget:unregistered');
254
- });
255
-
256
- it('emits widget:loaded event', async () => {
257
- widgetRegistry.register(createManifest());
258
-
259
- const events: WidgetRegistryEvent[] = [];
260
- widgetRegistry.on((e) => events.push(e));
261
-
262
- await widgetRegistry.load('test-widget');
263
-
264
- expect(events.some((e) => e.type === 'widget:loaded')).toBe(true);
265
- });
266
-
267
- it('emits widget:error event on load failure', async () => {
268
- widgetRegistry.register(
269
- createManifest({
270
- source: { type: 'registry', registryKey: 'missing' },
271
- }),
272
- );
273
-
274
- const events: WidgetRegistryEvent[] = [];
275
- widgetRegistry.on((e) => events.push(e));
276
-
277
- await widgetRegistry.load('test-widget').catch(() => {});
278
-
279
- expect(events.some((e) => e.type === 'widget:error')).toBe(true);
280
- });
281
-
282
- it('supports unsubscribing from events', () => {
283
- const handler = vi.fn();
284
- const unsub = widgetRegistry.on(handler);
285
-
286
- widgetRegistry.register(createManifest({ name: 'a', type: 'a' }));
287
- expect(handler).toHaveBeenCalledTimes(1);
288
-
289
- unsub();
290
- widgetRegistry.register(createManifest({ name: 'b', type: 'b' }));
291
- expect(handler).toHaveBeenCalledTimes(1); // No new calls
292
- });
293
- });
294
-
295
- describe('clear / getStats', () => {
296
- it('clears all widgets', async () => {
297
- widgetRegistry.register(createManifest());
298
- await widgetRegistry.load('test-widget');
299
-
300
- widgetRegistry.clear();
301
-
302
- expect(widgetRegistry.has('test-widget')).toBe(false);
303
- expect(widgetRegistry.isLoaded('test-widget')).toBe(false);
304
- });
305
-
306
- it('returns correct stats', () => {
307
- widgetRegistry.registerAll([
308
- createManifest({ name: 'a', type: 'a', category: 'charts' }),
309
- createManifest({ name: 'b', type: 'b', category: 'forms' }),
310
- createManifest({ name: 'c', type: 'c', category: 'charts' }),
311
- ]);
312
-
313
- const stats = widgetRegistry.getStats();
314
- expect(stats.registered).toBe(3);
315
- expect(stats.loaded).toBe(0);
316
- expect(stats.categories).toContain('charts');
317
- expect(stats.categories).toContain('forms');
318
- expect(stats.categories).toHaveLength(2);
319
- });
320
- });
321
- });