@coherent.js/core 1.0.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +130 -0
- package/dist/coherent.d.ts +472 -0
- package/dist/coherent.d.ts.map +1 -0
- package/dist/coherent.js +590 -0
- package/dist/coherent.js.map +1 -0
- package/dist/components/component-system.d.ts +1138 -0
- package/dist/components/component-system.d.ts.map +1 -0
- package/dist/components/component-system.js +2220 -0
- package/dist/components/component-system.js.map +1 -0
- package/dist/components/lifecycle.d.ts +212 -0
- package/dist/components/lifecycle.d.ts.map +1 -0
- package/dist/components/lifecycle.js +525 -0
- package/dist/components/lifecycle.js.map +1 -0
- package/dist/core/html-utils.d.ts +14 -0
- package/dist/core/html-utils.d.ts.map +1 -0
- package/dist/core/html-utils.js +166 -0
- package/dist/core/html-utils.js.map +1 -0
- package/dist/core/object-factory.d.ts +38 -0
- package/dist/core/object-factory.d.ts.map +1 -0
- package/dist/core/object-factory.js +63 -0
- package/dist/core/object-factory.js.map +1 -0
- package/dist/core/object-utils.d.ts +77 -0
- package/dist/core/object-utils.d.ts.map +1 -0
- package/dist/core/object-utils.js +502 -0
- package/dist/core/object-utils.js.map +1 -0
- package/dist/dev/dev-tools.d.ts +194 -0
- package/dist/dev/dev-tools.d.ts.map +1 -0
- package/dist/dev/dev-tools.js +846 -0
- package/dist/dev/dev-tools.js.map +1 -0
- package/dist/forms/validation.d.ts +271 -0
- package/dist/forms/validation.d.ts.map +1 -0
- package/dist/forms/validation.js +573 -0
- package/dist/forms/validation.js.map +1 -0
- package/dist/index.cjs +5281 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +5204 -0
- package/dist/index.js.map +7 -0
- package/dist/performance/bundle-optimizer.d.ts +95 -0
- package/dist/performance/bundle-optimizer.d.ts.map +1 -0
- package/dist/performance/bundle-optimizer.js +192 -0
- package/dist/performance/bundle-optimizer.js.map +1 -0
- package/dist/performance/cache-manager.d.ts +107 -0
- package/dist/performance/cache-manager.d.ts.map +1 -0
- package/dist/performance/cache-manager.js +314 -0
- package/dist/performance/cache-manager.js.map +1 -0
- package/dist/performance/component-cache.d.ts +120 -0
- package/dist/performance/component-cache.d.ts.map +1 -0
- package/dist/performance/component-cache.js +364 -0
- package/dist/performance/component-cache.js.map +1 -0
- package/dist/performance/monitor.d.ts +189 -0
- package/dist/performance/monitor.d.ts.map +1 -0
- package/dist/performance/monitor.js +347 -0
- package/dist/performance/monitor.js.map +1 -0
- package/dist/rendering/base-renderer.d.ts +140 -0
- package/dist/rendering/base-renderer.d.ts.map +1 -0
- package/dist/rendering/base-renderer.js +409 -0
- package/dist/rendering/base-renderer.js.map +1 -0
- package/dist/rendering/css-manager.d.ts +73 -0
- package/dist/rendering/css-manager.d.ts.map +1 -0
- package/dist/rendering/css-manager.js +176 -0
- package/dist/rendering/css-manager.js.map +1 -0
- package/dist/rendering/dom-renderer.d.ts +62 -0
- package/dist/rendering/dom-renderer.d.ts.map +1 -0
- package/dist/rendering/dom-renderer.js +252 -0
- package/dist/rendering/dom-renderer.js.map +1 -0
- package/dist/rendering/html-renderer.d.ts +67 -0
- package/dist/rendering/html-renderer.d.ts.map +1 -0
- package/dist/rendering/html-renderer.js +444 -0
- package/dist/rendering/html-renderer.js.map +1 -0
- package/dist/rendering/renderer-config.d.ts +282 -0
- package/dist/rendering/renderer-config.d.ts.map +1 -0
- package/dist/rendering/renderer-config.js +144 -0
- package/dist/rendering/renderer-config.js.map +1 -0
- package/dist/rendering/streaming-renderer.d.ts +117 -0
- package/dist/rendering/streaming-renderer.d.ts.map +1 -0
- package/dist/rendering/streaming-renderer.js +326 -0
- package/dist/rendering/streaming-renderer.js.map +1 -0
- package/dist/rendering/vdom-diff.d.ts +47 -0
- package/dist/rendering/vdom-diff.d.ts.map +1 -0
- package/dist/rendering/vdom-diff.js +416 -0
- package/dist/rendering/vdom-diff.js.map +1 -0
- package/dist/routing/router.d.ts +241 -0
- package/dist/routing/router.d.ts.map +1 -0
- package/dist/routing/router.js +648 -0
- package/dist/routing/router.js.map +1 -0
- package/dist/state/reactive-state.d.ts +166 -0
- package/dist/state/reactive-state.d.ts.map +1 -0
- package/dist/state/reactive-state.js +546 -0
- package/dist/state/reactive-state.js.map +1 -0
- package/dist/state/state-manager.d.ts +45 -0
- package/dist/state/state-manager.d.ts.map +1 -0
- package/dist/state/state-manager.js +151 -0
- package/dist/state/state-manager.js.map +1 -0
- package/dist/types/constants.d.ts +8 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/constants.js +36 -0
- package/dist/types/constants.js.map +1 -0
- package/dist/utils/dependency-utils.d.ts +43 -0
- package/dist/utils/dependency-utils.d.ts.map +1 -0
- package/dist/utils/dependency-utils.js +105 -0
- package/dist/utils/dependency-utils.js.map +1 -0
- package/dist/utils/error-handler.d.ts +148 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +468 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/normalization.d.ts +3 -0
- package/dist/utils/normalization.d.ts.map +1 -0
- package/dist/utils/normalization.js +24 -0
- package/dist/utils/normalization.js.map +1 -0
- package/dist/utils/validation.d.ts +10 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +32 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +44 -0
- package/types/index.d.ts +734 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Error Handling System for Coherent.js
|
|
3
|
+
* Provides detailed error messages and debugging context
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Custom error types for better debugging
|
|
7
|
+
*/
|
|
8
|
+
export class CoherentError extends Error {
|
|
9
|
+
constructor(message, options = {}) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'CoherentError';
|
|
12
|
+
this.type = options.type || 'generic';
|
|
13
|
+
this.component = options.component;
|
|
14
|
+
this.context = options.context;
|
|
15
|
+
this.suggestions = options.suggestions || [];
|
|
16
|
+
this.timestamp = Date.now();
|
|
17
|
+
if (Error.captureStackTrace) {
|
|
18
|
+
Error.captureStackTrace(this, CoherentError);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
return {
|
|
23
|
+
name: this.name,
|
|
24
|
+
message: this.message,
|
|
25
|
+
type: this.type,
|
|
26
|
+
component: this.component,
|
|
27
|
+
context: this.context,
|
|
28
|
+
suggestions: this.suggestions,
|
|
29
|
+
timestamp: this.timestamp,
|
|
30
|
+
stack: this.stack
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class ComponentValidationError extends CoherentError {
|
|
35
|
+
constructor(message, component, suggestions = []) {
|
|
36
|
+
super(message, {
|
|
37
|
+
type: 'validation',
|
|
38
|
+
component,
|
|
39
|
+
suggestions: [
|
|
40
|
+
'Check component structure and syntax',
|
|
41
|
+
'Ensure all required properties are present',
|
|
42
|
+
'Validate prop types and values',
|
|
43
|
+
...suggestions
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
this.name = 'ComponentValidationError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export class RenderingError extends CoherentError {
|
|
50
|
+
constructor(message, component, context, suggestions = []) {
|
|
51
|
+
super(message, {
|
|
52
|
+
type: 'rendering',
|
|
53
|
+
component,
|
|
54
|
+
context,
|
|
55
|
+
suggestions: [
|
|
56
|
+
'Check for circular references',
|
|
57
|
+
'Validate component depth',
|
|
58
|
+
'Ensure all functions return valid components',
|
|
59
|
+
...suggestions
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
this.name = 'RenderingError';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export class PerformanceError extends CoherentError {
|
|
66
|
+
constructor(message, metrics, suggestions = []) {
|
|
67
|
+
super(message, {
|
|
68
|
+
type: 'performance',
|
|
69
|
+
context: metrics,
|
|
70
|
+
suggestions: [
|
|
71
|
+
'Consider component memoization',
|
|
72
|
+
'Reduce component complexity',
|
|
73
|
+
'Enable caching',
|
|
74
|
+
...suggestions
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
this.name = 'PerformanceError';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export class StateError extends CoherentError {
|
|
81
|
+
constructor(message, state, suggestions = []) {
|
|
82
|
+
super(message, {
|
|
83
|
+
type: 'state',
|
|
84
|
+
context: state,
|
|
85
|
+
suggestions: [
|
|
86
|
+
'Check state mutations',
|
|
87
|
+
'Ensure proper state initialization',
|
|
88
|
+
'Validate state transitions',
|
|
89
|
+
...suggestions
|
|
90
|
+
]
|
|
91
|
+
});
|
|
92
|
+
this.name = 'StateError';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Error handler with context-aware reporting
|
|
97
|
+
*/
|
|
98
|
+
export class ErrorHandler {
|
|
99
|
+
constructor(options = {}) {
|
|
100
|
+
this.options = {
|
|
101
|
+
enableStackTrace: options.enableStackTrace !== false,
|
|
102
|
+
enableSuggestions: options.enableSuggestions !== false,
|
|
103
|
+
enableLogging: options.enableLogging !== false,
|
|
104
|
+
logLevel: options.logLevel || 'error',
|
|
105
|
+
maxErrorHistory: options.maxErrorHistory || 100,
|
|
106
|
+
...options
|
|
107
|
+
};
|
|
108
|
+
this.errorHistory = [];
|
|
109
|
+
this.errorCounts = new Map();
|
|
110
|
+
this.suppressedErrors = new Set();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Handle and report errors with detailed context
|
|
114
|
+
*/
|
|
115
|
+
handle(error, context = {}) {
|
|
116
|
+
// Create enhanced error if it's not already a CoherentError
|
|
117
|
+
const enhancedError = this.enhanceError(error, _context);
|
|
118
|
+
// Add to history
|
|
119
|
+
this.addToHistory(enhancedError);
|
|
120
|
+
// Log if enabled
|
|
121
|
+
if (this.options.enableLogging) {
|
|
122
|
+
this.logError(enhancedError);
|
|
123
|
+
}
|
|
124
|
+
// Return enhanced error for potential re-throwing
|
|
125
|
+
return enhancedError;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Enhance existing errors with more context
|
|
129
|
+
*/
|
|
130
|
+
enhanceError(error, context = {}) {
|
|
131
|
+
if (error instanceof CoherentError) {
|
|
132
|
+
return error;
|
|
133
|
+
}
|
|
134
|
+
// Determine error type from context
|
|
135
|
+
const errorType = this.classifyError(error, _context);
|
|
136
|
+
// Create appropriate error type
|
|
137
|
+
switch (errorType) {
|
|
138
|
+
case 'validation':
|
|
139
|
+
return new ComponentValidationError(error.message, context.component, this.generateSuggestions(error, _context));
|
|
140
|
+
case 'rendering':
|
|
141
|
+
return new RenderingError(error.message, context.component, context.renderContext, this.generateSuggestions(error, _context));
|
|
142
|
+
case 'performance':
|
|
143
|
+
return new PerformanceError(error.message, context.metrics, this.generateSuggestions(error, _context));
|
|
144
|
+
case 'state':
|
|
145
|
+
return new StateError(error.message, context.state, this.generateSuggestions(error, _context));
|
|
146
|
+
default:
|
|
147
|
+
return new CoherentError(error.message, {
|
|
148
|
+
type: errorType,
|
|
149
|
+
component: context.component,
|
|
150
|
+
context: context.context,
|
|
151
|
+
suggestions: this.generateSuggestions(error, _context)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Classify error type based on message and context
|
|
157
|
+
*/
|
|
158
|
+
classifyError(error, _context) {
|
|
159
|
+
const message = error.message.toLowerCase();
|
|
160
|
+
// Validation errors
|
|
161
|
+
if (message.includes('invalid') || message.includes('validation') ||
|
|
162
|
+
message.includes('required') || message.includes('type')) {
|
|
163
|
+
return 'validation';
|
|
164
|
+
}
|
|
165
|
+
// Rendering errors
|
|
166
|
+
if (message.includes('render') || message.includes('circular') ||
|
|
167
|
+
message.includes('depth') || message.includes('cannot render')) {
|
|
168
|
+
return 'rendering';
|
|
169
|
+
}
|
|
170
|
+
// Performance errors
|
|
171
|
+
if (message.includes('slow') || message.includes('memory') ||
|
|
172
|
+
message.includes('performance') || message.includes('timeout')) {
|
|
173
|
+
return 'performance';
|
|
174
|
+
}
|
|
175
|
+
// State errors
|
|
176
|
+
if (message.includes('state') || message.includes('mutation') ||
|
|
177
|
+
message.includes('store') || context.state) {
|
|
178
|
+
return 'state';
|
|
179
|
+
}
|
|
180
|
+
// Check context for type hints
|
|
181
|
+
if (context.component)
|
|
182
|
+
return 'validation';
|
|
183
|
+
if (context.renderContext)
|
|
184
|
+
return 'rendering';
|
|
185
|
+
if (context.metrics)
|
|
186
|
+
return 'performance';
|
|
187
|
+
return 'generic';
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Generate helpful suggestions based on error
|
|
191
|
+
*/
|
|
192
|
+
generateSuggestions(error, context = {}) {
|
|
193
|
+
const suggestions = [];
|
|
194
|
+
const message = error.message.toLowerCase();
|
|
195
|
+
// Common patterns and suggestions
|
|
196
|
+
const patterns = [
|
|
197
|
+
{
|
|
198
|
+
pattern: /cannot render|render.*failed/,
|
|
199
|
+
suggestions: [
|
|
200
|
+
'Check if component returns a valid object structure',
|
|
201
|
+
'Ensure all properties are properly defined',
|
|
202
|
+
'Look for undefined variables or null references'
|
|
203
|
+
]
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
pattern: /circular.*reference/,
|
|
207
|
+
suggestions: [
|
|
208
|
+
'Remove circular references between components',
|
|
209
|
+
'Use lazy loading or memoization to break cycles',
|
|
210
|
+
'Check for self-referencing components'
|
|
211
|
+
]
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
pattern: /maximum.*depth/,
|
|
215
|
+
suggestions: [
|
|
216
|
+
'Reduce component nesting depth',
|
|
217
|
+
'Break complex components into smaller parts',
|
|
218
|
+
'Check for infinite recursion in component functions'
|
|
219
|
+
]
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
pattern: /invalid.*component/,
|
|
223
|
+
suggestions: [
|
|
224
|
+
'Ensure component follows the expected object structure',
|
|
225
|
+
'Check property names and values for typos',
|
|
226
|
+
'Verify component is not null or undefined'
|
|
227
|
+
]
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
pattern: /performance|slow|timeout/,
|
|
231
|
+
suggestions: [
|
|
232
|
+
'Enable component caching',
|
|
233
|
+
'Use memoization for expensive operations',
|
|
234
|
+
'Reduce component complexity',
|
|
235
|
+
'Consider lazy loading for large components'
|
|
236
|
+
]
|
|
237
|
+
}
|
|
238
|
+
];
|
|
239
|
+
// Match patterns and add suggestions
|
|
240
|
+
patterns.forEach(({ pattern, suggestions: patternSuggestions }) => {
|
|
241
|
+
if (pattern.test(message)) {
|
|
242
|
+
suggestions.push(...patternSuggestions);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
// Context-specific suggestions
|
|
246
|
+
if (context.component) {
|
|
247
|
+
const componentType = typeof context.component;
|
|
248
|
+
if (componentType === 'function') {
|
|
249
|
+
suggestions.push('Check function component return value');
|
|
250
|
+
}
|
|
251
|
+
else if (componentType === 'object' && context.component === null) {
|
|
252
|
+
suggestions.push('Component is null - ensure proper initialization');
|
|
253
|
+
}
|
|
254
|
+
else if (Array.isArray(context.component)) {
|
|
255
|
+
suggestions.push('Arrays should contain valid component objects');
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// Add debugging tips
|
|
259
|
+
if (suggestions.length === 0) {
|
|
260
|
+
suggestions.push('Enable development tools for more detailed debugging', 'Check browser console for additional error details', 'Use component validation tools to identify issues');
|
|
261
|
+
}
|
|
262
|
+
return [...new Set(suggestions)]; // Remove duplicates
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Add error to history with deduplication
|
|
266
|
+
*/
|
|
267
|
+
addToHistory(error) {
|
|
268
|
+
const errorKey = `${error.name}:${error.message}`;
|
|
269
|
+
// Update count
|
|
270
|
+
this.errorCounts.set(errorKey, (this.errorCounts.get(errorKey) || 0) + 1);
|
|
271
|
+
// Add to history
|
|
272
|
+
const historyEntry = {
|
|
273
|
+
...error.toJSON(),
|
|
274
|
+
count: this.errorCounts.get(errorKey),
|
|
275
|
+
firstSeen: this.errorHistory.find(e => e.key === errorKey)?.firstSeen || error.timestamp,
|
|
276
|
+
key: errorKey
|
|
277
|
+
};
|
|
278
|
+
// Remove old entry if exists
|
|
279
|
+
this.errorHistory = this.errorHistory.filter(e => e.key !== errorKey);
|
|
280
|
+
// Add new entry
|
|
281
|
+
this.errorHistory.unshift(historyEntry);
|
|
282
|
+
// Limit history size
|
|
283
|
+
if (this.errorHistory.length > this.options.maxErrorHistory) {
|
|
284
|
+
this.errorHistory = this.errorHistory.slice(0, this.options.maxErrorHistory);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Log error with enhanced formatting
|
|
289
|
+
*/
|
|
290
|
+
logError(error) {
|
|
291
|
+
if (this.suppressedErrors.has(`${error.name}:${error.message}`)) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const isRepeated = this.errorCounts.get(`${error.name}:${error.message}`) > 1;
|
|
295
|
+
// Format error for console
|
|
296
|
+
const errorGroup = `🚨 ${error.name}${isRepeated ? ` (×${this.errorCounts.get(`${error.name}:${error.message}`)})` : ''}`;
|
|
297
|
+
console.group(errorGroup);
|
|
298
|
+
// Main error message
|
|
299
|
+
console.error(`❌ ${error.message}`);
|
|
300
|
+
// Component context if available
|
|
301
|
+
if (error.component) {
|
|
302
|
+
console.log('🔍 Component:', this.formatComponent(error.component));
|
|
303
|
+
}
|
|
304
|
+
// Additional context
|
|
305
|
+
if (error._context) {
|
|
306
|
+
console.log('📋 Context:', error._context);
|
|
307
|
+
}
|
|
308
|
+
// Suggestions
|
|
309
|
+
if (this.options.enableSuggestions && error.suggestions.length > 0) {
|
|
310
|
+
console.group('💡 Suggestions:');
|
|
311
|
+
error.suggestions.forEach((suggestion, index) => {
|
|
312
|
+
console.log(`${index + 1}. ${suggestion}`);
|
|
313
|
+
});
|
|
314
|
+
console.groupEnd();
|
|
315
|
+
}
|
|
316
|
+
// Stack trace
|
|
317
|
+
if (this.options.enableStackTrace && error.stack) {
|
|
318
|
+
console.log('📚 Stack trace:', error.stack);
|
|
319
|
+
}
|
|
320
|
+
console.groupEnd();
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Format component for logging
|
|
324
|
+
*/
|
|
325
|
+
formatComponent(component, maxDepth = 2, currentDepth = 0) {
|
|
326
|
+
if (currentDepth > maxDepth) {
|
|
327
|
+
return '[...deep]';
|
|
328
|
+
}
|
|
329
|
+
if (typeof component === 'function') {
|
|
330
|
+
return `[Function: ${component.name || 'anonymous'}]`;
|
|
331
|
+
}
|
|
332
|
+
if (Array.isArray(component)) {
|
|
333
|
+
return component.slice(0, 3).map(item => this.formatComponent(item, maxDepth, currentDepth + 1));
|
|
334
|
+
}
|
|
335
|
+
if (component && typeof component === 'object') {
|
|
336
|
+
const formatted = {};
|
|
337
|
+
const keys = Object.keys(component).slice(0, 5);
|
|
338
|
+
for (const key of keys) {
|
|
339
|
+
if (key === 'children' && component[key]) {
|
|
340
|
+
formatted[key] = this.formatComponent(component[key], maxDepth, currentDepth + 1);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
formatted[key] = component[key];
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (Object.keys(component).length > 5) {
|
|
347
|
+
formatted['...'] = `(${Object.keys(component).length - 5} more)`;
|
|
348
|
+
}
|
|
349
|
+
return formatted;
|
|
350
|
+
}
|
|
351
|
+
return component;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Suppress specific error types
|
|
355
|
+
*/
|
|
356
|
+
suppress(errorPattern) {
|
|
357
|
+
this.suppressedErrors.add(errorPattern);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Clear error history
|
|
361
|
+
*/
|
|
362
|
+
clearHistory() {
|
|
363
|
+
this.errorHistory = [];
|
|
364
|
+
this.errorCounts.clear();
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Get error statistics
|
|
368
|
+
*/
|
|
369
|
+
getStats() {
|
|
370
|
+
const errorsByType = {};
|
|
371
|
+
const errorsByTime = {};
|
|
372
|
+
this.errorHistory.forEach(error => {
|
|
373
|
+
// Count by type
|
|
374
|
+
errorsByType[error.type] = (errorsByType[error.type] || 0) + error.count;
|
|
375
|
+
// Count by hour
|
|
376
|
+
const hour = new Date(error.timestamp).toISOString().slice(0, 13);
|
|
377
|
+
errorsByTime[hour] = (errorsByTime[hour] || 0) + error.count;
|
|
378
|
+
});
|
|
379
|
+
return {
|
|
380
|
+
totalErrors: this.errorHistory.reduce((sum, e) => sum + e.count, 0),
|
|
381
|
+
uniqueErrors: this.errorHistory.length,
|
|
382
|
+
errorsByType,
|
|
383
|
+
errorsByTime,
|
|
384
|
+
mostCommonErrors: this.getMostCommonErrors(5),
|
|
385
|
+
recentErrors: this.errorHistory.slice(0, 10)
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Get most common errors
|
|
390
|
+
*/
|
|
391
|
+
getMostCommonErrors(limit = 10) {
|
|
392
|
+
return this.errorHistory
|
|
393
|
+
.sort((a, b) => b.count - a.count)
|
|
394
|
+
.slice(0, limit)
|
|
395
|
+
.map(({ name, message, count, type }) => ({
|
|
396
|
+
name,
|
|
397
|
+
message,
|
|
398
|
+
count,
|
|
399
|
+
type
|
|
400
|
+
}));
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Global error handler instance
|
|
405
|
+
*/
|
|
406
|
+
export const globalErrorHandler = new ErrorHandler();
|
|
407
|
+
/**
|
|
408
|
+
* Convenience functions for common error types
|
|
409
|
+
*/
|
|
410
|
+
export function throwValidationError(message, component, suggestions = []) {
|
|
411
|
+
throw new ComponentValidationError(message, component, suggestions);
|
|
412
|
+
}
|
|
413
|
+
export function throwRenderingError(message, component, context, suggestions = []) {
|
|
414
|
+
throw new RenderingError(message, component, context, suggestions);
|
|
415
|
+
}
|
|
416
|
+
export function throwPerformanceError(message, metrics, suggestions = []) {
|
|
417
|
+
throw new PerformanceError(message, metrics, suggestions);
|
|
418
|
+
}
|
|
419
|
+
export function throwStateError(message, state, suggestions = []) {
|
|
420
|
+
throw new StateError(message, state, suggestions);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Try-catch wrapper with enhanced error handling
|
|
424
|
+
*/
|
|
425
|
+
export function safeExecute(fn, context = {}, fallback = null) {
|
|
426
|
+
try {
|
|
427
|
+
return fn();
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
const enhancedError = globalErrorHandler.handle(error, _context);
|
|
431
|
+
if (fallback !== null) {
|
|
432
|
+
return typeof fallback === 'function' ? fallback(enhancedError) : fallback;
|
|
433
|
+
}
|
|
434
|
+
throw enhancedError;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Async try-catch wrapper
|
|
439
|
+
*/
|
|
440
|
+
export async function safeExecuteAsync(fn, context = {}, fallback = null) {
|
|
441
|
+
try {
|
|
442
|
+
return await fn();
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
const enhancedError = globalErrorHandler.handle(error, _context);
|
|
446
|
+
if (fallback !== null) {
|
|
447
|
+
return typeof fallback === 'function' ? fallback(enhancedError) : fallback;
|
|
448
|
+
}
|
|
449
|
+
throw enhancedError;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Factory function to create an ErrorHandler instance
|
|
454
|
+
*
|
|
455
|
+
* @param {Object} options - ErrorHandler configuration
|
|
456
|
+
* @returns {ErrorHandler} ErrorHandler instance
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* const errorHandler = createErrorHandler({
|
|
460
|
+
* enableTracing: true,
|
|
461
|
+
* enableSuggestions: true
|
|
462
|
+
* });
|
|
463
|
+
*/
|
|
464
|
+
export function createErrorHandler(options = {}) {
|
|
465
|
+
return new ErrorHandler(options);
|
|
466
|
+
}
|
|
467
|
+
export default ErrorHandler;
|
|
468
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../../src/utils/error-handler.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACpC,YAAY,OAAO,EAAE,OAAO,GAAG,EAAE;QAC7B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE5B,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC1B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;IAED,MAAM;QACF,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK;SACpB,CAAC;IACN,CAAC;CACJ;AAED,MAAM,OAAO,wBAAyB,SAAQ,aAAa;IACvD,YAAY,OAAO,EAAE,SAAS,EAAE,WAAW,GA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C,KAAK,UAAU,gBAAgB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,IAAI;IACpE,IAAI,CAAC;QACD,OAAO,MAAM,EAAE,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,aAAa,GAAG,kBAAkB,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEhE,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC/E,CAAC;QAED,MAAM,aAAa,CAAC;IACxB,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAO,GAAG,EAAE;IAC3C,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalization.d.ts","sourceRoot":"","sources":["../../../../src/utils/normalization.js"],"names":[],"mappings":"AACA,gDAWC;AAED,oDAYC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/utils/normalization.js
|
|
2
|
+
export function normalizeProps(_props) {
|
|
3
|
+
if (!props || typeof props !== 'object') {
|
|
4
|
+
return {};
|
|
5
|
+
}
|
|
6
|
+
// Filter out key and ref from props (they're handled separately)
|
|
7
|
+
const normalizedProps = { ...props };
|
|
8
|
+
delete normalizedProps.key;
|
|
9
|
+
delete normalizedProps.ref;
|
|
10
|
+
return normalizedProps;
|
|
11
|
+
}
|
|
12
|
+
export function flattenChildren(children) {
|
|
13
|
+
const flattened = [];
|
|
14
|
+
for (const child of children) {
|
|
15
|
+
if (Array.isArray(child)) {
|
|
16
|
+
flattened.push(...flattenChildren(child));
|
|
17
|
+
}
|
|
18
|
+
else if (child !== null && child !== undefined && child !== false) {
|
|
19
|
+
flattened.push(child);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return flattened;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=normalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalization.js","sourceRoot":"","sources":["../../../../src/utils/normalization.js"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,MAAM,UAAU,cAAc,CAAC,KAAK;IAChC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,EAAE,CAAC;IACd,CAAC;IAED,iEAAiE;IACjE,MAAM,eAAe,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IACrC,OAAO,eAAe,CAAC,GAAG,CAAC;IAC3B,OAAO,eAAe,CAAC,GAAG,CAAC;IAE3B,OAAO,eAAe,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAQ;IACpC,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,SAAS,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9C,CAAC;aAAM,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YAClE,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export namespace Validation {
|
|
2
|
+
export { validateCoherentObject };
|
|
3
|
+
export { validateComponent };
|
|
4
|
+
export { validateProps };
|
|
5
|
+
}
|
|
6
|
+
declare function validateCoherentObject(obj: any, context?: string): boolean;
|
|
7
|
+
declare function validateComponent(componentFunction: any): boolean;
|
|
8
|
+
declare function validateProps(props: any): boolean;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../../src/utils/validation.js"],"names":[],"mappings":";;;;;AASA,6EAcC;AAED,oEAMC;AAED,oDAMC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/utils/validation.js
|
|
2
|
+
import { CoherentTypes, COHERENT_MARKER } from '../types/constants.js';
|
|
3
|
+
export const Validation = {
|
|
4
|
+
validateCoherentObject,
|
|
5
|
+
validateComponent,
|
|
6
|
+
validateProps
|
|
7
|
+
};
|
|
8
|
+
function validateCoherentObject(obj, context = 'render') {
|
|
9
|
+
if (!obj || typeof obj !== 'object') {
|
|
10
|
+
throw new Error(`${context}: Expected object, received ${typeof obj}`);
|
|
11
|
+
}
|
|
12
|
+
if (!obj[COHERENT_MARKER]) {
|
|
13
|
+
throw new Error(`${context}: Object is not a valid Coherent object`);
|
|
14
|
+
}
|
|
15
|
+
if (!Object.values(CoherentTypes).includes(obj.type)) {
|
|
16
|
+
throw new Error(`${context}: Invalid Coherent object type: ${obj.type}`);
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
function validateComponent(componentFunction) {
|
|
21
|
+
if (typeof componentFunction !== 'function') {
|
|
22
|
+
throw new Error('Component must be a function');
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
function validateProps(_props) {
|
|
27
|
+
if (props && typeof props !== 'object') {
|
|
28
|
+
throw new Error('Props must be an object');
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../../src/utils/validation.js"],"names":[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
+
"version": "1.0.0-beta.2",
|
|
4
|
+
"description": "Core runtime for Coherent.js (SSR framework).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"development": "./src/index.js",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/",
|
|
18
|
+
"types/",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20.0.0"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/Tomdrouv1/coherent.js.git"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "node build.mjs",
|
|
36
|
+
"clean": "rm -rf dist/",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:watch": "vitest",
|
|
39
|
+
"test:coverage": "vitest run --coverage",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test:vitest": "vitest run",
|
|
42
|
+
"test:node": "node --test test/*.test.js"
|
|
43
|
+
}
|
|
44
|
+
}
|