@coherent.js/core 1.0.0-beta.2 → 1.0.0-beta.5
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/dist/coherent.d.ts +10 -150
- package/dist/coherent.d.ts.map +1 -1
- package/dist/coherent.js +33 -166
- package/dist/coherent.js.map +1 -1
- package/dist/components/component-system.js +109 -109
- package/dist/core/html-utils.js +5 -5
- package/dist/core/object-factory.js +21 -21
- package/dist/core/object-utils.js +2 -2
- package/dist/database/adapters/mongodb.d.ts +15 -0
- package/dist/database/adapters/mongodb.d.ts.map +1 -0
- package/dist/database/adapters/mongodb.js +216 -0
- package/dist/database/adapters/mongodb.js.map +1 -0
- package/dist/database/adapters/mysql.d.ts +12 -0
- package/dist/database/adapters/mysql.d.ts.map +1 -0
- package/dist/database/adapters/mysql.js +171 -0
- package/dist/database/adapters/mysql.js.map +1 -0
- package/dist/database/adapters/postgresql.d.ts +12 -0
- package/dist/database/adapters/postgresql.d.ts.map +1 -0
- package/dist/database/adapters/postgresql.js +177 -0
- package/dist/database/adapters/postgresql.js.map +1 -0
- package/dist/database/adapters/sqlite.d.ts +15 -0
- package/dist/database/adapters/sqlite.d.ts.map +1 -0
- package/dist/database/adapters/sqlite.js +241 -0
- package/dist/database/adapters/sqlite.js.map +1 -0
- package/dist/database/connection-manager.d.ts +135 -0
- package/dist/database/connection-manager.d.ts.map +1 -0
- package/dist/database/connection-manager.js +362 -0
- package/dist/database/connection-manager.js.map +1 -0
- package/dist/database/index.d.ts +38 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +60 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/middleware.d.ts +122 -0
- package/dist/database/middleware.d.ts.map +1 -0
- package/dist/database/middleware.js +390 -0
- package/dist/database/middleware.js.map +1 -0
- package/dist/database/migration.d.ts +62 -0
- package/dist/database/migration.d.ts.map +1 -0
- package/dist/database/migration.js +423 -0
- package/dist/database/migration.js.map +1 -0
- package/dist/database/model.d.ts +8 -0
- package/dist/database/model.d.ts.map +1 -0
- package/dist/database/model.js +167 -0
- package/dist/database/model.js.map +1 -0
- package/dist/database/query-builder.d.ts +111 -0
- package/dist/database/query-builder.d.ts.map +1 -0
- package/dist/database/query-builder.js +187 -0
- package/dist/database/query-builder.js.map +1 -0
- package/dist/database/utils.d.ts +196 -0
- package/dist/database/utils.d.ts.map +1 -0
- package/dist/database/utils.js +372 -0
- package/dist/database/utils.js.map +1 -0
- package/dist/dev/dev-tools.d.ts +1 -1
- package/dist/dev/dev-tools.js +28 -28
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +2 -2
- package/dist/performance/bundle-optimizer.js +11 -11
- package/dist/performance/cache-manager.js +6 -6
- package/dist/performance/monitor.js +10 -10
- package/dist/performance/monitor.js.map +1 -1
- package/dist/rendering/base-renderer.js +13 -13
- package/dist/rendering/dom-renderer.d.ts +0 -23
- package/dist/rendering/dom-renderer.d.ts.map +1 -1
- package/dist/rendering/dom-renderer.js +9 -77
- package/dist/rendering/dom-renderer.js.map +1 -1
- package/dist/rendering/html-renderer.d.ts +0 -15
- package/dist/rendering/html-renderer.d.ts.map +1 -1
- package/dist/rendering/html-renderer.js +4 -85
- package/dist/rendering/html-renderer.js.map +1 -1
- package/dist/rendering/streaming-renderer.js +12 -12
- package/dist/utils/dependency-utils.js +2 -2
- package/dist/utils/normalization.js +1 -1
- package/dist/utils/validation.js +1 -1
- package/package.json +22 -1
- package/dist/components/lifecycle.d.ts +0 -212
- package/dist/components/lifecycle.d.ts.map +0 -1
- package/dist/components/lifecycle.js +0 -525
- package/dist/components/lifecycle.js.map +0 -1
- package/dist/forms/validation.d.ts +0 -271
- package/dist/forms/validation.d.ts.map +0 -1
- package/dist/forms/validation.js +0 -573
- package/dist/forms/validation.js.map +0 -1
- package/dist/performance/component-cache.d.ts +0 -120
- package/dist/performance/component-cache.d.ts.map +0 -1
- package/dist/performance/component-cache.js +0 -364
- package/dist/performance/component-cache.js.map +0 -1
- package/dist/rendering/css-manager.d.ts +0 -73
- package/dist/rendering/css-manager.d.ts.map +0 -1
- package/dist/rendering/css-manager.js +0 -176
- package/dist/rendering/css-manager.js.map +0 -1
- package/dist/rendering/vdom-diff.d.ts +0 -47
- package/dist/rendering/vdom-diff.d.ts.map +0 -1
- package/dist/rendering/vdom-diff.js +0 -416
- package/dist/rendering/vdom-diff.js.map +0 -1
- package/dist/routing/router.d.ts +0 -241
- package/dist/routing/router.d.ts.map +0 -1
- package/dist/routing/router.js +0 -648
- package/dist/routing/router.js.map +0 -1
- package/dist/state/reactive-state.d.ts +0 -166
- package/dist/state/reactive-state.d.ts.map +0 -1
- package/dist/state/reactive-state.js +0 -546
- package/dist/state/reactive-state.js.map +0 -1
- package/dist/utils/error-handler.d.ts +0 -148
- package/dist/utils/error-handler.d.ts.map +0 -1
- package/dist/utils/error-handler.js +0 -468
- package/dist/utils/error-handler.js.map +0 -1
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database Utilities for Coherent.js
|
|
3
|
+
*
|
|
4
|
+
* @fileoverview Utility functions for database operations, model registration, and migrations.
|
|
5
|
+
*/
|
|
6
|
+
import { DatabaseManager } from './connection-manager.js';
|
|
7
|
+
// Migration utilities are handled by the createMigration factory function
|
|
8
|
+
/**
|
|
9
|
+
* Model registry for managing model classes
|
|
10
|
+
*/
|
|
11
|
+
const modelRegistry = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* Create database connection with configuration
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} config - Database configuration
|
|
16
|
+
* @returns {Promise<DatabaseManager>} Database manager instance
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const db = await createConnection({
|
|
20
|
+
* type: 'postgresql',
|
|
21
|
+
* host: 'localhost',
|
|
22
|
+
* database: 'myapp',
|
|
23
|
+
* username: 'user',
|
|
24
|
+
* password: 'pass'
|
|
25
|
+
* });
|
|
26
|
+
*/
|
|
27
|
+
export async function createConnection(config) {
|
|
28
|
+
const db = new DatabaseManager(config);
|
|
29
|
+
await db.connect();
|
|
30
|
+
return db;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
|
|
34
|
+
// Add custom methods if provided
|
|
35
|
+
if (definition.methods) {
|
|
36
|
+
Object.entries(definition.methods).forEach(([methodName, method]) => {
|
|
37
|
+
DynamicModel.prototype[methodName] = method;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Add custom static methods if provided
|
|
42
|
+
if (definition.staticMethods) {
|
|
43
|
+
Object.entries(definition.staticMethods).forEach(([methodName, method]) => {
|
|
44
|
+
DynamicModel[methodName] = method;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Register the model
|
|
49
|
+
registerModel(name, DynamicModel);
|
|
50
|
+
|
|
51
|
+
return DynamicModel;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Register a model class
|
|
56
|
+
*
|
|
57
|
+
* @param {string} name - Model name
|
|
58
|
+
* @param {Function} ModelClass - Model class
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* registerModel('User', UserModel);
|
|
62
|
+
*/
|
|
63
|
+
export function registerModel(name, ModelClass) {
|
|
64
|
+
modelRegistry.set(name, ModelClass);
|
|
65
|
+
// Make model globally available for relationships
|
|
66
|
+
if (typeof global !== 'undefined') {
|
|
67
|
+
global[name] = ModelClass;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get registered model by name
|
|
72
|
+
*
|
|
73
|
+
* @param {string} name - Model name
|
|
74
|
+
* @returns {Function|null} Model class or null if not found
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* const User = getModel('User');
|
|
78
|
+
*/
|
|
79
|
+
export function getModel(name) {
|
|
80
|
+
return modelRegistry.get(name) || null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get all registered models
|
|
84
|
+
*
|
|
85
|
+
* @returns {Map<string, Function>} Map of model names to classes
|
|
86
|
+
*/
|
|
87
|
+
export function getAllModels() {
|
|
88
|
+
return new Map(modelRegistry);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Run database migrations
|
|
92
|
+
*
|
|
93
|
+
* @param {DatabaseManager} db - Database manager instance
|
|
94
|
+
* @param {Object} [config={}] - Migration configuration
|
|
95
|
+
* @returns {Promise<Array<string>>} Applied migration names
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const applied = await runMigrations(db, {
|
|
99
|
+
* directory: './migrations'
|
|
100
|
+
* });
|
|
101
|
+
*/
|
|
102
|
+
export async function runMigrations(db, config = {}) {
|
|
103
|
+
const { createMigration } = await import('./migration.js');
|
|
104
|
+
const migration = createMigration(db, config);
|
|
105
|
+
return await migration.run();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Rollback database migrations
|
|
109
|
+
*
|
|
110
|
+
* @param {DatabaseManager} db - Database manager instance
|
|
111
|
+
* @param {number} [steps=1] - Number of batches to rollback
|
|
112
|
+
* @param {Object} [config={}] - Migration configuration
|
|
113
|
+
* @returns {Promise<Array<string>>} Rolled back migration names
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* const rolledBack = await rollbackMigrations(db, 2);
|
|
117
|
+
*/
|
|
118
|
+
export async function rollbackMigrations(db, steps = 1, config = {}) {
|
|
119
|
+
const { createMigration } = await import('./migration.js');
|
|
120
|
+
const migration = createMigration(db, config);
|
|
121
|
+
return await migration.rollback(steps);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create a new migration file
|
|
125
|
+
*
|
|
126
|
+
* @param {string} name - Migration name
|
|
127
|
+
* @param {Object} [config={}] - Migration configuration
|
|
128
|
+
* @returns {Promise<string>} Created file path
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* const filePath = await createMigration('create_users_table');
|
|
132
|
+
*/
|
|
133
|
+
export async function createMigrationFile(name, config = {}) {
|
|
134
|
+
const { createMigration } = await import('./migration.js');
|
|
135
|
+
const migration = createMigration(null, config);
|
|
136
|
+
return await migration.create(name);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Seed database with initial data
|
|
140
|
+
*
|
|
141
|
+
* @param {DatabaseManager} db - Database manager instance
|
|
142
|
+
* @param {Function|Array<Function>} seeders - Seeder functions
|
|
143
|
+
* @returns {Promise<void>}
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* await seedDatabase(db, [
|
|
147
|
+
* async (db) => {
|
|
148
|
+
* await User.create({ name: 'Admin', email: 'admin@example.com' });
|
|
149
|
+
* }
|
|
150
|
+
* ]);
|
|
151
|
+
*/
|
|
152
|
+
export async function seedDatabase(db, seeders) {
|
|
153
|
+
const seederArray = Array.isArray(seeders) ? seeders : [seeders];
|
|
154
|
+
for (const seeder of seederArray) {
|
|
155
|
+
if (typeof seeder === 'function') {
|
|
156
|
+
await seeder(db);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Validate database configuration
|
|
162
|
+
*
|
|
163
|
+
* @param {Object} config - Database configuration
|
|
164
|
+
* @returns {Object} Validation result
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* const validation = validateConfig(config);
|
|
168
|
+
* if (!validation.valid) {
|
|
169
|
+
* console._error('Config errors:', validation.errors);
|
|
170
|
+
* }
|
|
171
|
+
*/
|
|
172
|
+
export function validateConfig(config) {
|
|
173
|
+
const errors = [];
|
|
174
|
+
if (!config || typeof config !== 'object') {
|
|
175
|
+
errors.push('Configuration must be an object');
|
|
176
|
+
return { valid: false, errors };
|
|
177
|
+
}
|
|
178
|
+
if (!config.type) {
|
|
179
|
+
errors.push('Database type is required');
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const supportedTypes = ['postgresql', 'mysql', 'sqlite', 'mongodb'];
|
|
183
|
+
if (!supportedTypes.includes(config.type)) {
|
|
184
|
+
errors.push(`Unsupported database type: ${config.type}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!config.database) {
|
|
188
|
+
errors.push('Database name is required');
|
|
189
|
+
}
|
|
190
|
+
if (config.type !== 'sqlite') {
|
|
191
|
+
if (!config.host) {
|
|
192
|
+
errors.push('Host is required for non-SQLite databases');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (config.pool) {
|
|
196
|
+
if (config.pool.min && config.pool.max && config.pool.min > config.pool.max) {
|
|
197
|
+
errors.push('Pool min size cannot be greater than max size');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
valid: errors.length === 0,
|
|
202
|
+
errors
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Create database backup
|
|
207
|
+
*
|
|
208
|
+
* @param {DatabaseManager} db - Database manager instance
|
|
209
|
+
* @param {Object} [options={}] - Backup options
|
|
210
|
+
* @returns {Promise<string>} Backup file path or data
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* const backupPath = await createBackup(db, {
|
|
214
|
+
* format: 'sql',
|
|
215
|
+
* outputPath: './backups'
|
|
216
|
+
* });
|
|
217
|
+
*/
|
|
218
|
+
export async function createBackup(db, options = {}) {
|
|
219
|
+
const backupConfig = {
|
|
220
|
+
format: 'sql',
|
|
221
|
+
outputPath: './backups',
|
|
222
|
+
timestamp: true,
|
|
223
|
+
...options
|
|
224
|
+
};
|
|
225
|
+
const timestamp = backupConfig.timestamp ? new Date().toISOString().replace(/[:.]/g, '-') : '';
|
|
226
|
+
const fileName = `backup${timestamp ? '_' + timestamp : ''}.${backupConfig.format}`;
|
|
227
|
+
const filePath = `${backupConfig.outputPath}/${fileName}`;
|
|
228
|
+
// This would be adapter-specific implementation
|
|
229
|
+
// For now, return a placeholder
|
|
230
|
+
console.log(`Backup would be created at: ${filePath}`);
|
|
231
|
+
return filePath;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Restore database from backup
|
|
235
|
+
*
|
|
236
|
+
* @param {DatabaseManager} db - Database manager instance
|
|
237
|
+
* @param {string} backupPath - Path to backup file
|
|
238
|
+
* @param {Object} [options={}] - Restore options
|
|
239
|
+
* @returns {Promise<void>}
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* await restoreBackup(db, './backups/backup_2023-12-01.sql');
|
|
243
|
+
*/
|
|
244
|
+
export async function restoreBackup(db, backupPath) {
|
|
245
|
+
// This would be adapter-specific implementation
|
|
246
|
+
console.log(`Restore would be performed from: ${backupPath}`);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Generate database schema documentation
|
|
250
|
+
*
|
|
251
|
+
* @param {DatabaseManager} db - Database manager instance
|
|
252
|
+
* @param {Object} [options={}] - Documentation options
|
|
253
|
+
* @returns {Promise<Object>} Schema documentation
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* const docs = await generateSchemaDocs(db, {
|
|
257
|
+
* includeIndexes: true,
|
|
258
|
+
* includeRelationships: true
|
|
259
|
+
* });
|
|
260
|
+
*/
|
|
261
|
+
export async function generateSchemaDocs(db) {
|
|
262
|
+
const schema = {
|
|
263
|
+
database: db.config.database,
|
|
264
|
+
type: db.config.type,
|
|
265
|
+
tables: [],
|
|
266
|
+
models: []
|
|
267
|
+
};
|
|
268
|
+
// Add registered models to documentation
|
|
269
|
+
for (const [name, ModelClass] of modelRegistry) {
|
|
270
|
+
schema.models.push({
|
|
271
|
+
name,
|
|
272
|
+
tableName: ModelClass.tableName,
|
|
273
|
+
primaryKey: ModelClass.primaryKey,
|
|
274
|
+
fillable: ModelClass.fillable,
|
|
275
|
+
relationships: ModelClass.relationships,
|
|
276
|
+
validationRules: ModelClass.validationRules
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
return schema;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Database health check utility
|
|
283
|
+
*
|
|
284
|
+
* @param {DatabaseManager} db - Database manager instance
|
|
285
|
+
* @returns {Promise<Object>} Health check result
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* const health = await checkDatabaseHealth(db);
|
|
289
|
+
* console.log(`Database is ${health.status}`);
|
|
290
|
+
*/
|
|
291
|
+
export async function checkDatabaseHealth(db) {
|
|
292
|
+
const startTime = Date.now();
|
|
293
|
+
try {
|
|
294
|
+
await db.query('SELECT 1');
|
|
295
|
+
const responseTime = Date.now() - startTime;
|
|
296
|
+
const stats = db.getStats();
|
|
297
|
+
return {
|
|
298
|
+
status: 'healthy',
|
|
299
|
+
responseTime,
|
|
300
|
+
connected: db.isConnected,
|
|
301
|
+
stats
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
catch (_error) {
|
|
305
|
+
return {
|
|
306
|
+
status: 'unhealthy',
|
|
307
|
+
_error: _error.message,
|
|
308
|
+
connected: db.isConnected,
|
|
309
|
+
responseTime: Date.now() - startTime
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Batch operation utility
|
|
315
|
+
*
|
|
316
|
+
* @param {DatabaseManager} db - Database manager instance
|
|
317
|
+
* @param {Array} operations - Array of operations to execute
|
|
318
|
+
* @param {Object} [options={}] - Batch options
|
|
319
|
+
* @returns {Promise<Array>} Results array
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* const results = await batchOperations(db, [
|
|
323
|
+
* { sql: 'INSERT INTO users (name) VALUES (?)', params: ['John'] },
|
|
324
|
+
* { sql: 'INSERT INTO users (name) VALUES (?)', params: ['Jane'] }
|
|
325
|
+
* ]);
|
|
326
|
+
*/
|
|
327
|
+
export async function batchOperations(db, operations, options = {}) {
|
|
328
|
+
const config = {
|
|
329
|
+
useTransaction: true,
|
|
330
|
+
continueOnError: false,
|
|
331
|
+
...options
|
|
332
|
+
};
|
|
333
|
+
const results = [];
|
|
334
|
+
if (config.useTransaction) {
|
|
335
|
+
const tx = await db.transaction();
|
|
336
|
+
try {
|
|
337
|
+
for (const operation of operations) {
|
|
338
|
+
try {
|
|
339
|
+
const result = await tx.query(operation.sql, operation.params);
|
|
340
|
+
results.push({ success: true, result });
|
|
341
|
+
}
|
|
342
|
+
catch (_error) {
|
|
343
|
+
results.push({ success: false, _error: _error.message });
|
|
344
|
+
if (!config.continueOnError) {
|
|
345
|
+
throw _error;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
await tx.commit();
|
|
350
|
+
}
|
|
351
|
+
catch (_error) {
|
|
352
|
+
await tx.rollback();
|
|
353
|
+
throw _error;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
for (const operation of operations) {
|
|
358
|
+
try {
|
|
359
|
+
const result = await db.query(operation.sql, operation.params);
|
|
360
|
+
results.push({ success: true, result });
|
|
361
|
+
}
|
|
362
|
+
catch (_error) {
|
|
363
|
+
results.push({ success: false, _error: _error.message });
|
|
364
|
+
if (!config.continueOnError) {
|
|
365
|
+
throw _error;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return results;
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/database/utils.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,0EAA0E;AAE1E;;GAEG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;AAEhC;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAM;IAC3C,MAAM,EAAE,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM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AAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;oBAEvD,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;wBAC5B,MAAM,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;YACH,CAAC;YAED,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC;QAEpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;YACpB,MAAM,KAAK,CAAC;QACd,CAAC;IAEH,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC/D,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAC1C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBAEvD,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;oBAC5B,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/dev/dev-tools.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ export class DevTools {
|
|
|
77
77
|
/**
|
|
78
78
|
* Get component type
|
|
79
79
|
*/
|
|
80
|
-
getComponentType(component: any): "
|
|
80
|
+
getComponentType(component: any): "function" | "text" | "array" | "element" | "unknown";
|
|
81
81
|
/**
|
|
82
82
|
* Visualize component structure
|
|
83
83
|
*/
|
package/dist/dev/dev-tools.js
CHANGED
|
@@ -107,9 +107,9 @@ export class DevTools {
|
|
|
107
107
|
this.postRenderAnalysis(component, result, renderTime, renderId);
|
|
108
108
|
return result;
|
|
109
109
|
}
|
|
110
|
-
catch (
|
|
111
|
-
this.handleRenderError(
|
|
112
|
-
throw
|
|
110
|
+
catch (_error) {
|
|
111
|
+
this.handleRenderError(_error, component, context, renderId);
|
|
112
|
+
throw _error;
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
115
|
}
|
|
@@ -187,10 +187,10 @@ export class DevTools {
|
|
|
187
187
|
try {
|
|
188
188
|
validateComponent(component);
|
|
189
189
|
}
|
|
190
|
-
catch (
|
|
190
|
+
catch (_error) {
|
|
191
191
|
return {
|
|
192
192
|
isValid: false,
|
|
193
|
-
message: `Invalid component at ${path}: ${
|
|
193
|
+
message: `Invalid component at ${path}: ${_error.message}`
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
// Recursive validation for objects and arrays
|
|
@@ -247,7 +247,7 @@ export class DevTools {
|
|
|
247
247
|
*/
|
|
248
248
|
analyzeContext(context, renderId) {
|
|
249
249
|
// Large context warning
|
|
250
|
-
const contextSize = JSON.stringify(
|
|
250
|
+
const contextSize = JSON.stringify(context).length;
|
|
251
251
|
if (contextSize > 10000) {
|
|
252
252
|
this.warnings.push({
|
|
253
253
|
type: 'context',
|
|
@@ -258,10 +258,10 @@ export class DevTools {
|
|
|
258
258
|
}
|
|
259
259
|
// Circular reference check
|
|
260
260
|
try {
|
|
261
|
-
JSON.stringify(
|
|
261
|
+
JSON.stringify(context);
|
|
262
262
|
}
|
|
263
|
-
catch (
|
|
264
|
-
if (
|
|
263
|
+
catch (_error) {
|
|
264
|
+
if (_error.message.includes('circular')) {
|
|
265
265
|
this.warnings.push({
|
|
266
266
|
type: 'context',
|
|
267
267
|
message: 'Circular reference detected in context',
|
|
@@ -383,12 +383,12 @@ export class DevTools {
|
|
|
383
383
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
384
384
|
}
|
|
385
385
|
/**
|
|
386
|
-
* Setup
|
|
386
|
+
* Setup _error handling
|
|
387
387
|
*/
|
|
388
388
|
setupErrorHandling() {
|
|
389
|
-
// Global
|
|
390
|
-
const originalConsoleError = console.
|
|
391
|
-
console.
|
|
389
|
+
// Global _error handler
|
|
390
|
+
const originalConsoleError = console._error;
|
|
391
|
+
console._error = (...args) => {
|
|
392
392
|
// Log to dev tools
|
|
393
393
|
this.errors.push({
|
|
394
394
|
type: 'console',
|
|
@@ -410,11 +410,11 @@ export class DevTools {
|
|
|
410
410
|
});
|
|
411
411
|
});
|
|
412
412
|
}
|
|
413
|
-
// Browser
|
|
413
|
+
// Browser _error handler
|
|
414
414
|
if (typeof window !== 'undefined') {
|
|
415
|
-
window.addEventListener('
|
|
415
|
+
window.addEventListener('_error', (event) => {
|
|
416
416
|
this.errors.push({
|
|
417
|
-
type: 'browser-
|
|
417
|
+
type: 'browser-_error',
|
|
418
418
|
message: event.message,
|
|
419
419
|
filename: event.filename,
|
|
420
420
|
lineno: event.lineno,
|
|
@@ -427,18 +427,18 @@ export class DevTools {
|
|
|
427
427
|
/**
|
|
428
428
|
* Handle render errors specifically
|
|
429
429
|
*/
|
|
430
|
-
handleRenderError(
|
|
430
|
+
handleRenderError(_error, component, context, renderId) {
|
|
431
431
|
this.errors.push({
|
|
432
|
-
type: 'render-
|
|
433
|
-
message:
|
|
434
|
-
stack:
|
|
432
|
+
type: 'render-_error',
|
|
433
|
+
message: _error.message,
|
|
434
|
+
stack: _error.stack,
|
|
435
435
|
component: this.serializeComponent(component),
|
|
436
|
-
context: Object.keys(
|
|
436
|
+
context: Object.keys(context),
|
|
437
437
|
renderId,
|
|
438
438
|
timestamp: Date.now()
|
|
439
439
|
});
|
|
440
|
-
console.
|
|
441
|
-
console.
|
|
440
|
+
console._error(`🚨 Render Error in ${renderId}:`, _error.message);
|
|
441
|
+
console._error('Component:', this.serializeComponent(component));
|
|
442
442
|
}
|
|
443
443
|
/**
|
|
444
444
|
* Setup hot reload capability
|
|
@@ -736,8 +736,8 @@ export class DevTools {
|
|
|
736
736
|
}
|
|
737
737
|
return component;
|
|
738
738
|
}
|
|
739
|
-
catch (
|
|
740
|
-
return `[Serialization Error: ${
|
|
739
|
+
catch (_error) {
|
|
740
|
+
return `[Serialization Error: ${_error.message}]`;
|
|
741
741
|
}
|
|
742
742
|
}
|
|
743
743
|
clearDevData() {
|
|
@@ -812,7 +812,7 @@ export const devUtils = {
|
|
|
812
812
|
for (const tag of tags) {
|
|
813
813
|
const props = component[tag];
|
|
814
814
|
if (props && typeof props === 'object') {
|
|
815
|
-
console.log(`${tag} props:`, Object.keys(
|
|
815
|
+
console.log(`${tag} props:`, Object.keys(props));
|
|
816
816
|
}
|
|
817
817
|
}
|
|
818
818
|
}
|
|
@@ -826,8 +826,8 @@ export const devUtils = {
|
|
|
826
826
|
console.log('✅ Component is valid');
|
|
827
827
|
return true;
|
|
828
828
|
}
|
|
829
|
-
catch (
|
|
830
|
-
console.
|
|
829
|
+
catch (_error) {
|
|
830
|
+
console._error('❌ Component validation failed:', _error.message);
|
|
831
831
|
return false;
|
|
832
832
|
}
|
|
833
833
|
},
|
package/dist/index.cjs
CHANGED
|
@@ -106,6 +106,7 @@ function createPerformanceMonitor(options = {}) {
|
|
|
106
106
|
},
|
|
107
107
|
alerts: {
|
|
108
108
|
enabled: true,
|
|
109
|
+
debounceMs: 5e3,
|
|
109
110
|
rules: []
|
|
110
111
|
},
|
|
111
112
|
resources: {
|
|
@@ -267,7 +268,7 @@ function createPerformanceMonitor(options = {}) {
|
|
|
267
268
|
const alertKey = `${rule.metric}-${rule.condition}-${rule.threshold}`;
|
|
268
269
|
const lastTriggered = alertState.triggered.get(alertKey);
|
|
269
270
|
const now = Date.now();
|
|
270
|
-
if (!lastTriggered || now - lastTriggered >
|
|
271
|
+
if (!lastTriggered || now - lastTriggered > opts.alerts.debounceMs) {
|
|
271
272
|
alertState.triggered.set(alertKey, now);
|
|
272
273
|
alertState.history.push({
|
|
273
274
|
rule,
|