@object-ui/core 3.3.0 → 3.3.2

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 (101) hide show
  1. package/CHANGELOG.md +12 -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/registry/Registry.d.ts +47 -0
  7. package/dist/registry/Registry.js +92 -0
  8. package/dist/utils/filter-converter.js +25 -5
  9. package/package.json +32 -8
  10. package/.turbo/turbo-build.log +0 -4
  11. package/src/__benchmarks__/core.bench.ts +0 -64
  12. package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
  13. package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
  14. package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
  15. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
  16. package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
  17. package/src/actions/ActionEngine.ts +0 -268
  18. package/src/actions/ActionRunner.ts +0 -717
  19. package/src/actions/TransactionManager.ts +0 -521
  20. package/src/actions/UndoManager.ts +0 -215
  21. package/src/actions/__tests__/ActionEngine.test.ts +0 -206
  22. package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
  23. package/src/actions/__tests__/ActionRunner.test.ts +0 -711
  24. package/src/actions/__tests__/TransactionManager.test.ts +0 -447
  25. package/src/actions/__tests__/UndoManager.test.ts +0 -320
  26. package/src/actions/index.ts +0 -12
  27. package/src/adapters/ApiDataSource.ts +0 -376
  28. package/src/adapters/README.md +0 -180
  29. package/src/adapters/ValueDataSource.ts +0 -459
  30. package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
  31. package/src/adapters/__tests__/ValueDataSource.test.ts +0 -571
  32. package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
  33. package/src/adapters/index.ts +0 -15
  34. package/src/adapters/resolveDataSource.ts +0 -79
  35. package/src/builder/__tests__/schema-builder.test.ts +0 -235
  36. package/src/builder/schema-builder.ts +0 -584
  37. package/src/data-scope/DataScopeManager.ts +0 -269
  38. package/src/data-scope/ViewDataProvider.ts +0 -282
  39. package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
  40. package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
  41. package/src/data-scope/index.ts +0 -24
  42. package/src/errors/__tests__/errors.test.ts +0 -292
  43. package/src/errors/index.ts +0 -269
  44. package/src/evaluator/ExpressionCache.ts +0 -206
  45. package/src/evaluator/ExpressionContext.ts +0 -118
  46. package/src/evaluator/ExpressionEvaluator.ts +0 -315
  47. package/src/evaluator/FormulaFunctions.ts +0 -398
  48. package/src/evaluator/SafeExpressionParser.ts +0 -893
  49. package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
  50. package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
  51. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -558
  52. package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
  53. package/src/evaluator/index.ts +0 -13
  54. package/src/index.ts +0 -38
  55. package/src/protocols/DndProtocol.ts +0 -168
  56. package/src/protocols/KeyboardProtocol.ts +0 -181
  57. package/src/protocols/NotificationProtocol.ts +0 -150
  58. package/src/protocols/ResponsiveProtocol.ts +0 -210
  59. package/src/protocols/SharingProtocol.ts +0 -185
  60. package/src/protocols/index.ts +0 -13
  61. package/src/query/__tests__/query-ast.test.ts +0 -211
  62. package/src/query/__tests__/window-functions.test.ts +0 -275
  63. package/src/query/index.ts +0 -7
  64. package/src/query/query-ast.ts +0 -341
  65. package/src/registry/PluginScopeImpl.ts +0 -259
  66. package/src/registry/PluginSystem.ts +0 -206
  67. package/src/registry/Registry.ts +0 -219
  68. package/src/registry/WidgetRegistry.ts +0 -316
  69. package/src/registry/__tests__/PluginSystem.test.ts +0 -309
  70. package/src/registry/__tests__/Registry.test.ts +0 -293
  71. package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
  72. package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
  73. package/src/theme/ThemeEngine.ts +0 -530
  74. package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
  75. package/src/theme/index.ts +0 -24
  76. package/src/types/index.ts +0 -21
  77. package/src/utils/__tests__/debug-collector.test.ts +0 -102
  78. package/src/utils/__tests__/debug.test.ts +0 -134
  79. package/src/utils/__tests__/expand-fields.test.ts +0 -120
  80. package/src/utils/__tests__/extract-records.test.ts +0 -50
  81. package/src/utils/__tests__/filter-converter.test.ts +0 -118
  82. package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
  83. package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
  84. package/src/utils/debug-collector.ts +0 -100
  85. package/src/utils/debug.ts +0 -148
  86. package/src/utils/expand-fields.ts +0 -76
  87. package/src/utils/extract-records.ts +0 -33
  88. package/src/utils/filter-converter.ts +0 -133
  89. package/src/utils/merge-views-into-objects.ts +0 -36
  90. package/src/utils/normalize-quick-filter.ts +0 -78
  91. package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
  92. package/src/validation/__tests__/schema-validator.test.ts +0 -118
  93. package/src/validation/__tests__/validation-engine.test.ts +0 -102
  94. package/src/validation/index.ts +0 -10
  95. package/src/validation/schema-validator.ts +0 -344
  96. package/src/validation/validation-engine.ts +0 -528
  97. package/src/validation/validators/index.ts +0 -25
  98. package/src/validation/validators/object-validation-engine.ts +0 -722
  99. package/tsconfig.json +0 -15
  100. package/tsconfig.tsbuildinfo +0 -1
  101. package/vitest.config.ts +0 -2
@@ -1,292 +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 } from 'vitest';
10
- import {
11
- ObjectUIError,
12
- SchemaError,
13
- RegistryError,
14
- ExpressionError,
15
- PluginError,
16
- FieldValidationError,
17
- ERROR_CODES,
18
- createError,
19
- formatErrorMessage,
20
- isObjectUIError,
21
- isErrorCode,
22
- } from '../index';
23
-
24
- // ---------------------------------------------------------------------------
25
- // ObjectUIError base class
26
- // ---------------------------------------------------------------------------
27
-
28
- describe('ObjectUIError', () => {
29
- it('should create an error with code and message', () => {
30
- const err = new ObjectUIError('something broke', 'OBJUI-001');
31
-
32
- expect(err).toBeInstanceOf(Error);
33
- expect(err).toBeInstanceOf(ObjectUIError);
34
- expect(err.name).toBe('ObjectUIError');
35
- expect(err.message).toBe('something broke');
36
- expect(err.code).toBe('OBJUI-001');
37
- expect(err.details).toBeUndefined();
38
- });
39
-
40
- it('should accept optional details', () => {
41
- const details = { type: 'fancy-button' };
42
- const err = new ObjectUIError('oops', 'OBJUI-001', details);
43
-
44
- expect(err.details).toEqual(details);
45
- });
46
-
47
- it('should serialize to JSON', () => {
48
- const err = new ObjectUIError('oops', 'OBJUI-001', { a: 1 });
49
- const json = err.toJSON();
50
-
51
- expect(json).toEqual(
52
- expect.objectContaining({
53
- name: 'ObjectUIError',
54
- message: 'oops',
55
- code: 'OBJUI-001',
56
- details: { a: 1 },
57
- }),
58
- );
59
- expect(json.stack).toBeDefined();
60
- });
61
-
62
- it('should have a proper stack trace', () => {
63
- const err = new ObjectUIError('trace me', 'OBJUI-001');
64
- expect(err.stack).toBeDefined();
65
- expect(err.stack).toContain('trace me');
66
- });
67
- });
68
-
69
- // ---------------------------------------------------------------------------
70
- // ERROR_CODES registry
71
- // ---------------------------------------------------------------------------
72
-
73
- describe('ERROR_CODES', () => {
74
- it('should contain all 10 defined error codes', () => {
75
- const expectedCodes = [
76
- 'OBJUI-001',
77
- 'OBJUI-002',
78
- 'OBJUI-003',
79
- 'OBJUI-004',
80
- 'OBJUI-005',
81
- 'OBJUI-006',
82
- 'OBJUI-007',
83
- 'OBJUI-008',
84
- 'OBJUI-009',
85
- 'OBJUI-010',
86
- ];
87
-
88
- for (const code of expectedCodes) {
89
- expect(ERROR_CODES[code]).toBeDefined();
90
- expect(ERROR_CODES[code].code).toBe(code);
91
- expect(ERROR_CODES[code].message).toBeTruthy();
92
- expect(ERROR_CODES[code].suggestion).toBeTruthy();
93
- expect(ERROR_CODES[code].docUrl).toContain(code);
94
- }
95
- });
96
- });
97
-
98
- // ---------------------------------------------------------------------------
99
- // isErrorCode type guard
100
- // ---------------------------------------------------------------------------
101
-
102
- describe('isErrorCode', () => {
103
- it('should return true for known codes', () => {
104
- expect(isErrorCode('OBJUI-001')).toBe(true);
105
- expect(isErrorCode('OBJUI-010')).toBe(true);
106
- });
107
-
108
- it('should return false for unknown codes', () => {
109
- expect(isErrorCode('OBJUI-999')).toBe(false);
110
- expect(isErrorCode(42)).toBe(false);
111
- expect(isErrorCode(null)).toBe(false);
112
- });
113
- });
114
-
115
- // ---------------------------------------------------------------------------
116
- // isObjectUIError type guard
117
- // ---------------------------------------------------------------------------
118
-
119
- describe('isObjectUIError', () => {
120
- it('should return true for ObjectUIError instances', () => {
121
- expect(isObjectUIError(new ObjectUIError('a', 'OBJUI-001'))).toBe(true);
122
- });
123
-
124
- it('should return true for subclass instances', () => {
125
- expect(isObjectUIError(new SchemaError('bad schema'))).toBe(true);
126
- expect(isObjectUIError(new ExpressionError('bad expr'))).toBe(true);
127
- });
128
-
129
- it('should return false for plain errors', () => {
130
- expect(isObjectUIError(new Error('plain'))).toBe(false);
131
- expect(isObjectUIError('string')).toBe(false);
132
- expect(isObjectUIError(null)).toBe(false);
133
- });
134
- });
135
-
136
- // ---------------------------------------------------------------------------
137
- // Specialized error classes
138
- // ---------------------------------------------------------------------------
139
-
140
- describe('SchemaError', () => {
141
- it('should default to OBJUI-002', () => {
142
- const err = new SchemaError('bad schema');
143
- expect(err.name).toBe('SchemaError');
144
- expect(err.code).toBe('OBJUI-002');
145
- expect(err).toBeInstanceOf(ObjectUIError);
146
- });
147
- });
148
-
149
- describe('RegistryError', () => {
150
- it('should accept a custom code', () => {
151
- const err = new RegistryError('not found', 'OBJUI-001');
152
- expect(err.name).toBe('RegistryError');
153
- expect(err.code).toBe('OBJUI-001');
154
- expect(err).toBeInstanceOf(ObjectUIError);
155
- });
156
- });
157
-
158
- describe('ExpressionError', () => {
159
- it('should default to OBJUI-003', () => {
160
- const err = new ExpressionError('eval failed');
161
- expect(err.name).toBe('ExpressionError');
162
- expect(err.code).toBe('OBJUI-003');
163
- });
164
- });
165
-
166
- describe('PluginError', () => {
167
- it('should accept a custom code', () => {
168
- const err = new PluginError('missing dep', 'OBJUI-004');
169
- expect(err.name).toBe('PluginError');
170
- expect(err.code).toBe('OBJUI-004');
171
- });
172
- });
173
-
174
- describe('FieldValidationError', () => {
175
- it('should default to OBJUI-009', () => {
176
- const err = new FieldValidationError('invalid field');
177
- expect(err.name).toBe('FieldValidationError');
178
- expect(err.code).toBe('OBJUI-009');
179
- });
180
- });
181
-
182
- // ---------------------------------------------------------------------------
183
- // createError factory
184
- // ---------------------------------------------------------------------------
185
-
186
- describe('createError', () => {
187
- it('should create a RegistryError for OBJUI-001', () => {
188
- const err = createError('OBJUI-001', { type: 'fancy-button' });
189
- expect(err).toBeInstanceOf(RegistryError);
190
- expect(err.message).toBe('Unknown component type: "fancy-button"');
191
- expect(err.code).toBe('OBJUI-001');
192
- });
193
-
194
- it('should create a SchemaError for OBJUI-002', () => {
195
- const err = createError('OBJUI-002', { reason: 'missing type' });
196
- expect(err).toBeInstanceOf(SchemaError);
197
- expect(err.message).toContain('missing type');
198
- });
199
-
200
- it('should create an ExpressionError for OBJUI-003', () => {
201
- const err = createError('OBJUI-003', { expression: '${bad}' });
202
- expect(err).toBeInstanceOf(ExpressionError);
203
- });
204
-
205
- it('should create a PluginError for OBJUI-004', () => {
206
- const err = createError('OBJUI-004', { dependency: 'chart-lib' });
207
- expect(err).toBeInstanceOf(PluginError);
208
- expect(err.message).toContain('chart-lib');
209
- });
210
-
211
- it('should create a PluginError for OBJUI-005', () => {
212
- const err = createError('OBJUI-005', { plugin: 'grid' });
213
- expect(err).toBeInstanceOf(PluginError);
214
- });
215
-
216
- it('should create a PluginError for OBJUI-006', () => {
217
- const err = createError('OBJUI-006', { plugin: 'kanban' });
218
- expect(err).toBeInstanceOf(PluginError);
219
- });
220
-
221
- it('should create a RegistryError for OBJUI-007', () => {
222
- const err = createError('OBJUI-007', { namespace: 'old-ns' });
223
- expect(err).toBeInstanceOf(RegistryError);
224
- });
225
-
226
- it('should create a FieldValidationError for OBJUI-009', () => {
227
- const err = createError('OBJUI-009', { field: 'email' });
228
- expect(err).toBeInstanceOf(FieldValidationError);
229
- });
230
-
231
- it('should create a base ObjectUIError for OBJUI-008', () => {
232
- const err = createError('OBJUI-008', { scope: 'readOnlyScope' });
233
- expect(err).toBeInstanceOf(ObjectUIError);
234
- expect(err.message).toContain('readOnlyScope');
235
- });
236
-
237
- it('should create a base ObjectUIError for OBJUI-010', () => {
238
- const err = createError('OBJUI-010', { action: 'save' });
239
- expect(err).toBeInstanceOf(ObjectUIError);
240
- expect(err.message).toContain('save');
241
- });
242
-
243
- it('should handle unknown error codes gracefully', () => {
244
- const err = createError('OBJUI-999');
245
- expect(err).toBeInstanceOf(ObjectUIError);
246
- expect(err.message).toContain('Unknown error code');
247
- });
248
-
249
- it('should pass through details', () => {
250
- const err = createError('OBJUI-001', { type: 'x' }, { extra: true });
251
- expect(err.details).toEqual({ extra: true });
252
- });
253
- });
254
-
255
- // ---------------------------------------------------------------------------
256
- // formatErrorMessage
257
- // ---------------------------------------------------------------------------
258
-
259
- describe('formatErrorMessage', () => {
260
- it('should include code and message', () => {
261
- const err = new ObjectUIError('something broke', 'OBJUI-001');
262
- const formatted = formatErrorMessage(err, false);
263
-
264
- expect(formatted).toBe('[OBJUI-001] something broke');
265
- });
266
-
267
- it('should include suggestion and docs in dev mode', () => {
268
- const err = createError('OBJUI-001', { type: 'magic-box' });
269
- const formatted = formatErrorMessage(err, true);
270
-
271
- expect(formatted).toContain('[OBJUI-001]');
272
- expect(formatted).toContain('šŸ’” Suggestion:');
273
- expect(formatted).toContain('šŸ“– Docs:');
274
- expect(formatted).toContain('https://objectui.dev/docs/errors/OBJUI-001');
275
- });
276
-
277
- it('should not include suggestion in production mode', () => {
278
- const err = createError('OBJUI-002', { reason: 'bad' });
279
- const formatted = formatErrorMessage(err, false);
280
-
281
- expect(formatted).not.toContain('šŸ’” Suggestion:');
282
- expect(formatted).not.toContain('šŸ“– Docs:');
283
- });
284
-
285
- it('should handle errors with unknown codes gracefully', () => {
286
- const err = new ObjectUIError('custom', 'CUSTOM-001');
287
- const formatted = formatErrorMessage(err, true);
288
-
289
- // No entry in ERROR_CODES so no suggestion appended
290
- expect(formatted).toBe('[CUSTOM-001] custom');
291
- });
292
- });
@@ -1,269 +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
- // ---------------------------------------------------------------------------
10
- // Error Code Registry
11
- // ---------------------------------------------------------------------------
12
-
13
- export interface ErrorCodeEntry {
14
- code: string;
15
- message: string;
16
- suggestion: string;
17
- docUrl: string;
18
- }
19
-
20
- const BASE_DOC_URL = 'https://objectui.dev/docs/errors';
21
-
22
- export const ERROR_CODES: Record<string, ErrorCodeEntry> = {
23
- 'OBJUI-001': {
24
- code: 'OBJUI-001',
25
- message: 'Unknown component type: "${type}"',
26
- suggestion:
27
- 'Ensure the component is registered via registry.register() before rendering. Check for typos in the component type name.',
28
- docUrl: `${BASE_DOC_URL}/OBJUI-001`,
29
- },
30
- 'OBJUI-002': {
31
- code: 'OBJUI-002',
32
- message: 'Schema validation failed: ${reason}',
33
- suggestion:
34
- 'Verify the schema against the ObjectUI JSON spec. Run the built-in schema validator for details.',
35
- docUrl: `${BASE_DOC_URL}/OBJUI-002`,
36
- },
37
- 'OBJUI-003': {
38
- code: 'OBJUI-003',
39
- message: 'Expression evaluation failed: ${expression}',
40
- suggestion:
41
- 'Check the expression syntax and ensure all referenced variables exist in the current data scope.',
42
- docUrl: `${BASE_DOC_URL}/OBJUI-003`,
43
- },
44
- 'OBJUI-004': {
45
- code: 'OBJUI-004',
46
- message: 'Plugin dependency missing: "${dependency}"',
47
- suggestion:
48
- 'Install the required dependency and register it before loading this plugin.',
49
- docUrl: `${BASE_DOC_URL}/OBJUI-004`,
50
- },
51
- 'OBJUI-005': {
52
- code: 'OBJUI-005',
53
- message: 'Plugin already loaded: "${plugin}"',
54
- suggestion:
55
- 'A plugin with the same name is already registered. Remove the duplicate or use a unique plugin name.',
56
- docUrl: `${BASE_DOC_URL}/OBJUI-005`,
57
- },
58
- 'OBJUI-006': {
59
- code: 'OBJUI-006',
60
- message: 'Plugin not found: "${plugin}"',
61
- suggestion:
62
- 'Verify the plugin name and ensure it has been registered before access.',
63
- docUrl: `${BASE_DOC_URL}/OBJUI-006`,
64
- },
65
- 'OBJUI-007': {
66
- code: 'OBJUI-007',
67
- message: 'Registry namespace deprecated: "${namespace}"',
68
- suggestion:
69
- 'Migrate to the new namespace format. See the migration guide for details.',
70
- docUrl: `${BASE_DOC_URL}/OBJUI-007`,
71
- },
72
- 'OBJUI-008': {
73
- code: 'OBJUI-008',
74
- message: 'Read-only scope violation: "${scope}"',
75
- suggestion:
76
- 'You are trying to mutate a read-only data scope. Use a writable scope or clone the data before modifying.',
77
- docUrl: `${BASE_DOC_URL}/OBJUI-008`,
78
- },
79
- 'OBJUI-009': {
80
- code: 'OBJUI-009',
81
- message: 'Invalid field configuration: "${field}"',
82
- suggestion:
83
- 'Check the field schema for required properties (type, name). Ensure the field widget is registered.',
84
- docUrl: `${BASE_DOC_URL}/OBJUI-009`,
85
- },
86
- 'OBJUI-010': {
87
- code: 'OBJUI-010',
88
- message: 'Action execution failed: "${action}"',
89
- suggestion:
90
- 'Verify the action handler is registered and that all required parameters are provided.',
91
- docUrl: `${BASE_DOC_URL}/OBJUI-010`,
92
- },
93
- } as const;
94
-
95
- // ---------------------------------------------------------------------------
96
- // Type Guards
97
- // ---------------------------------------------------------------------------
98
-
99
- /**
100
- * Check whether a string is a known ObjectUI error code.
101
- */
102
- export function isErrorCode(code: unknown): code is keyof typeof ERROR_CODES {
103
- return typeof code === 'string' && code in ERROR_CODES;
104
- }
105
-
106
- // ---------------------------------------------------------------------------
107
- // Base Error Class
108
- // ---------------------------------------------------------------------------
109
-
110
- /**
111
- * Base error class for all ObjectUI errors.
112
- */
113
- export class ObjectUIError extends Error {
114
- constructor(
115
- message: string,
116
- public code: string,
117
- public details?: Record<string, unknown>,
118
- ) {
119
- super(message);
120
- this.name = 'ObjectUIError';
121
-
122
- // Maintains proper stack trace for where error was thrown (only in V8)
123
- if ((Error as any).captureStackTrace) {
124
- (Error as any).captureStackTrace(this, this.constructor);
125
- }
126
- }
127
-
128
- /**
129
- * Convert error to JSON for logging / debugging.
130
- */
131
- toJSON() {
132
- return {
133
- name: this.name,
134
- message: this.message,
135
- code: this.code,
136
- details: this.details,
137
- stack: this.stack,
138
- };
139
- }
140
- }
141
-
142
- /**
143
- * Type guard to check if an error is an ObjectUIError.
144
- */
145
- export function isObjectUIError(error: unknown): error is ObjectUIError {
146
- return error instanceof ObjectUIError;
147
- }
148
-
149
- // ---------------------------------------------------------------------------
150
- // Specialized Error Classes
151
- // ---------------------------------------------------------------------------
152
-
153
- /** Thrown when a schema is invalid or fails validation. */
154
- export class SchemaError extends ObjectUIError {
155
- constructor(message: string, details?: Record<string, unknown>) {
156
- super(message, 'OBJUI-002', details);
157
- this.name = 'SchemaError';
158
- }
159
- }
160
-
161
- /** Thrown when a registry operation fails. */
162
- export class RegistryError extends ObjectUIError {
163
- constructor(message: string, code: string, details?: Record<string, unknown>) {
164
- super(message, code, details);
165
- this.name = 'RegistryError';
166
- }
167
- }
168
-
169
- /** Thrown when expression evaluation fails. */
170
- export class ExpressionError extends ObjectUIError {
171
- constructor(message: string, details?: Record<string, unknown>) {
172
- super(message, 'OBJUI-003', details);
173
- this.name = 'ExpressionError';
174
- }
175
- }
176
-
177
- /** Thrown when a plugin operation fails. */
178
- export class PluginError extends ObjectUIError {
179
- constructor(message: string, code: string, details?: Record<string, unknown>) {
180
- super(message, code, details);
181
- this.name = 'PluginError';
182
- }
183
- }
184
-
185
- /** Thrown when validation of user input / field config fails. */
186
- export class FieldValidationError extends ObjectUIError {
187
- constructor(message: string, details?: Record<string, unknown>) {
188
- super(message, 'OBJUI-009', details);
189
- this.name = 'FieldValidationError';
190
- }
191
- }
192
-
193
- // ---------------------------------------------------------------------------
194
- // Factory & Formatting Helpers
195
- // ---------------------------------------------------------------------------
196
-
197
- /**
198
- * Interpolate a template string with the given params.
199
- * Template variables use the `${key}` syntax.
200
- */
201
- function interpolate(
202
- template: string,
203
- params: Record<string, string>,
204
- ): string {
205
- return template.replace(/\$\{(\w+)\}/g, (_match, key: string) => {
206
- if (!(key in params) && (globalThis as any).process?.env?.NODE_ENV !== 'production') {
207
- console.warn(`[ObjectUI] Missing interpolation parameter "${key}" in error message template.`);
208
- }
209
- return params[key] ?? `\${${key}}`;
210
- });
211
- }
212
-
213
- /**
214
- * Create an `ObjectUIError` (or subclass) from a known error code.
215
- *
216
- * @param code - A registered error code (e.g. `"OBJUI-001"`).
217
- * @param params - Values to interpolate into the message template.
218
- * @param details - Optional extra details attached to the error.
219
- */
220
- export function createError(
221
- code: string,
222
- params: Record<string, string> = {},
223
- details?: Record<string, unknown>,
224
- ): ObjectUIError {
225
- const entry = ERROR_CODES[code];
226
- const message = entry
227
- ? interpolate(entry.message, params)
228
- : `Unknown error code: ${code}`;
229
-
230
- switch (code) {
231
- case 'OBJUI-002':
232
- return new SchemaError(message, details);
233
- case 'OBJUI-003':
234
- return new ExpressionError(message, details);
235
- case 'OBJUI-004':
236
- case 'OBJUI-005':
237
- case 'OBJUI-006':
238
- return new PluginError(message, code, details);
239
- case 'OBJUI-007':
240
- case 'OBJUI-001':
241
- return new RegistryError(message, code, details);
242
- case 'OBJUI-009':
243
- return new FieldValidationError(message, details);
244
- default:
245
- return new ObjectUIError(message, code, details);
246
- }
247
- }
248
-
249
- /**
250
- * Format an error message with actionable fix suggestions in development mode.
251
- *
252
- * @param error - The `ObjectUIError` to format.
253
- * @param isDev - When `true`, appends the suggestion and documentation link.
254
- */
255
- export function formatErrorMessage(
256
- error: ObjectUIError,
257
- isDev: boolean = (globalThis as any).process?.env?.NODE_ENV !== 'production',
258
- ): string {
259
- const entry = ERROR_CODES[error.code];
260
-
261
- let formatted = `[${error.code}] ${error.message}`;
262
-
263
- if (isDev && entry) {
264
- formatted += `\n\nšŸ’” Suggestion: ${entry.suggestion}`;
265
- formatted += `\nšŸ“– Docs: ${entry.docUrl}`;
266
- }
267
-
268
- return formatted;
269
- }