@coherent.js/devtools 1.0.0-beta.3 → 1.0.0-beta.6

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/package.json CHANGED
@@ -1,15 +1,52 @@
1
1
  {
2
2
  "name": "@coherent.js/devtools",
3
- "version": "1.0.0-beta.3",
4
- "description": "Developer tools for Coherent.js applications",
3
+ "version": "1.0.0-beta.6",
4
+ "description": "Developer tools for Coherent.js applications - tree-shakable modular exports",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./types/index.d.ts",
8
8
  "exports": {
9
- ".": "./dist/index.js",
10
- "./inspector": "./dist/inspector.js",
11
- "./profiler": "./dist/profiler.js",
12
- "./logger": "./dist/logger.js"
9
+ ".": {
10
+ "development": "./src/index.js",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./visualizer": {
15
+ "development": "./src/component-visualizer.js",
16
+ "import": "./dist/component-visualizer.js",
17
+ "require": "./dist/component-visualizer.cjs"
18
+ },
19
+ "./performance": {
20
+ "development": "./src/performance-dashboard.js",
21
+ "import": "./dist/performance-dashboard.js",
22
+ "require": "./dist/performance-dashboard.cjs"
23
+ },
24
+ "./errors": {
25
+ "development": "./src/enhanced-errors.js",
26
+ "import": "./dist/enhanced-errors.js",
27
+ "require": "./dist/enhanced-errors.cjs"
28
+ },
29
+ "./hybrid": {
30
+ "development": "./src/hybrid-integration-tools.js",
31
+ "import": "./dist/hybrid-integration-tools.js",
32
+ "require": "./dist/hybrid-integration-tools.cjs"
33
+ },
34
+ "./inspector": {
35
+ "development": "./src/inspector.js",
36
+ "import": "./dist/inspector.js",
37
+ "require": "./dist/inspector.cjs"
38
+ },
39
+ "./profiler": {
40
+ "development": "./src/profiler.js",
41
+ "import": "./dist/profiler.js",
42
+ "require": "./dist/profiler.cjs"
43
+ },
44
+ "./logger": {
45
+ "development": "./src/logger.js",
46
+ "import": "./dist/logger.js",
47
+ "require": "./dist/logger.cjs"
48
+ },
49
+ "./package.json": "./package.json"
13
50
  },
14
51
  "files": [
15
52
  "dist/",
@@ -22,12 +59,13 @@
22
59
  "devtools",
23
60
  "debugging",
24
61
  "profiling",
25
- "inspector"
62
+ "inspector",
63
+ "tree-shakable"
26
64
  ],
27
65
  "author": "Coherent.js Team",
28
66
  "license": "MIT",
29
67
  "peerDependencies": {
30
- "@coherent.js/core": "1.0.0-beta.3"
68
+ "@coherent.js/core": "1.0.0-beta.6"
31
69
  },
32
70
  "repository": {
33
71
  "type": "git",
@@ -36,6 +74,7 @@
36
74
  "publishConfig": {
37
75
  "access": "public"
38
76
  },
77
+ "sideEffects": false,
39
78
  "scripts": {
40
79
  "build": "node build.mjs",
41
80
  "clean": "rm -rf dist"
package/types/index.d.ts CHANGED
@@ -3,8 +3,15 @@
3
3
  * @module @coherent.js/devtools
4
4
  */
5
5
 
6
- // ===== Logger Types =====
6
+ import type { CoherentNode, ComponentInstance, ComponentProps } from '@coherent.js/core';
7
7
 
8
+ // ============================================================================
9
+ // Logger Types
10
+ // ============================================================================
11
+
12
+ /**
13
+ * Log level enumeration
14
+ */
8
15
  export enum LogLevel {
9
16
  TRACE = 0,
10
17
  DEBUG = 1,
@@ -14,175 +21,521 @@ export enum LogLevel {
14
21
  FATAL = 5
15
22
  }
16
23
 
24
+ /**
25
+ * Logger configuration options
26
+ */
17
27
  export interface LoggerOptions {
28
+ /** Minimum log level to output */
18
29
  level?: LogLevel;
30
+ /** Prefix for all log messages */
19
31
  prefix?: string;
32
+ /** Include timestamp in output */
20
33
  timestamp?: boolean;
34
+ /** Use colored output */
21
35
  colors?: boolean;
36
+ /** Maximum logs to keep in memory */
22
37
  maxLogs?: number;
38
+ /** Maximum buffer size */
23
39
  maxBufferSize?: number;
40
+ /** Enable log grouping */
24
41
  grouping?: boolean;
42
+ /** Buffer logs before output */
25
43
  buffer?: boolean;
44
+ /** Sample rate (0-1) for high-volume logging */
26
45
  sampleRate?: number;
46
+ /** Suppress all output */
27
47
  silent?: boolean;
48
+ /** Custom output handler */
28
49
  output?: ((log: LogEntry) => void) | null;
50
+ /** Filter by categories */
29
51
  categories?: string[] | null;
52
+ /** Custom filter function */
30
53
  filter?: ((log: LogEntry) => boolean) | null;
31
54
  }
32
55
 
56
+ /**
57
+ * Log entry structure
58
+ */
33
59
  export interface LogEntry {
60
+ /** Log level */
34
61
  level: LogLevel;
62
+ /** Log message */
35
63
  message: string;
64
+ /** Timestamp (ms since epoch) */
36
65
  timestamp: number;
37
- data?: any[];
66
+ /** Additional data */
67
+ data?: unknown[];
68
+ /** Log category */
38
69
  category?: string;
39
- context?: Record<string, any>;
70
+ /** Additional context */
71
+ context?: Record<string, unknown>;
40
72
  }
41
73
 
74
+ /**
75
+ * Development logger class
76
+ */
42
77
  export class DevLogger {
43
78
  constructor(options?: LoggerOptions);
44
- trace(message: string, ...data: any[]): void;
45
- debug(message: string, ...data: any[]): void;
46
- info(message: string, ...data: any[]): void;
47
- warn(message: string, ...data: any[]): void;
48
- error(message: string, ...data: any[]): void;
49
- fatal(message: string, ...data: any[]): void;
50
- log(level: LogLevel, message: string, ...data: any[]): void;
79
+
80
+ /** Log at TRACE level */
81
+ trace(message: string, ...data: unknown[]): void;
82
+
83
+ /** Log at DEBUG level */
84
+ debug(message: string, ...data: unknown[]): void;
85
+
86
+ /** Log at INFO level */
87
+ info(message: string, ...data: unknown[]): void;
88
+
89
+ /** Log at WARN level */
90
+ warn(message: string, ...data: unknown[]): void;
91
+
92
+ /** Log at ERROR level */
93
+ error(message: string, ...data: unknown[]): void;
94
+
95
+ /** Log at FATAL level */
96
+ fatal(message: string, ...data: unknown[]): void;
97
+
98
+ /** Log at specific level */
99
+ log(level: LogLevel, message: string, ...data: unknown[]): void;
100
+
101
+ /** Start a log group */
51
102
  group(label: string): void;
103
+
104
+ /** End current log group */
52
105
  groupEnd(): void;
106
+
107
+ /** Clear all logs */
53
108
  clear(): void;
109
+
110
+ /** Get all stored logs */
54
111
  getLogs(): LogEntry[];
112
+
113
+ /** Set minimum log level */
55
114
  setLevel(level: LogLevel): void;
115
+
116
+ /** Add a log filter */
56
117
  addFilter(filter: (log: LogEntry) => boolean): void;
118
+
119
+ /** Remove a log filter */
57
120
  removeFilter(filter: (log: LogEntry) => boolean): void;
58
121
  }
59
122
 
123
+ /**
124
+ * Create a logger instance
125
+ */
60
126
  export function createLogger(options?: LoggerOptions): DevLogger;
127
+
128
+ /**
129
+ * Create a logger for a specific component
130
+ */
61
131
  export function createComponentLogger(componentName: string, options?: LoggerOptions): DevLogger;
132
+
133
+ /**
134
+ * Create a logger that outputs to console
135
+ */
62
136
  export function createConsoleLogger(): DevLogger;
63
137
 
64
- // ===== Inspector Types =====
138
+ // ============================================================================
139
+ // Inspector Types
140
+ // ============================================================================
65
141
 
142
+ /**
143
+ * Inspector configuration options
144
+ */
66
145
  export interface InspectorOptions {
146
+ /** Track inspection history */
67
147
  trackHistory?: boolean;
148
+ /** Maximum history entries */
68
149
  maxHistory?: number;
150
+ /** Verbose output */
69
151
  verbose?: boolean;
70
152
  }
71
153
 
154
+ /**
155
+ * Component analysis result
156
+ */
72
157
  export interface ComponentAnalysis {
158
+ /** Component type */
73
159
  type: string;
160
+ /** Whether component is valid */
74
161
  valid: boolean;
162
+ /** Validation issues */
75
163
  issues: string[];
164
+ /** Warnings */
76
165
  warnings: string[];
77
166
  }
78
167
 
79
- export interface ComponentTree {
168
+ /**
169
+ * Component tree node
170
+ */
171
+ export interface ComponentTreeNode {
172
+ /** Component type/name */
80
173
  type: string;
174
+ /** Tag name (if element) */
81
175
  tagName?: string;
82
- children: ComponentTree[];
176
+ /** Child nodes */
177
+ children: ComponentTreeNode[];
178
+ /** Tree depth */
83
179
  depth: number;
180
+ /** Component name */
181
+ name?: string;
182
+ /** Component ID */
183
+ id?: string;
184
+ /** Props */
185
+ props?: Record<string, unknown>;
186
+ /** State */
187
+ state?: Record<string, unknown>;
188
+ /** Render count */
189
+ renderCount?: number;
84
190
  }
85
191
 
192
+ /**
193
+ * Component statistics
194
+ */
86
195
  export interface ComponentStats {
196
+ /** Maximum depth */
87
197
  depth: number;
198
+ /** Total element count */
88
199
  elementCount: number;
200
+ /** Complexity score */
89
201
  complexity: number;
202
+ /** Total node count */
90
203
  nodeCount: number;
91
204
  }
92
205
 
206
+ /**
207
+ * Inspector data for a component
208
+ */
209
+ export interface InspectorData {
210
+ /** Component instance */
211
+ component: ComponentInstance;
212
+ /** Component props */
213
+ props: Record<string, unknown>;
214
+ /** Component state */
215
+ state: Record<string, unknown>;
216
+ /** Rendered output */
217
+ rendered: CoherentNode;
218
+ /** Render time (ms) */
219
+ renderTime: number;
220
+ /** Update count */
221
+ updateCount: number;
222
+ }
223
+
224
+ /**
225
+ * Full inspection result
226
+ */
93
227
  export interface InspectionResult {
228
+ /** Unique inspection ID */
94
229
  id: string;
230
+ /** Inspection timestamp */
95
231
  timestamp: number;
232
+ /** Time taken to inspect */
96
233
  inspectionTime: number;
97
- component: any;
98
- metadata: Record<string, any>;
234
+ /** Inspected component */
235
+ component: unknown;
236
+ /** Additional metadata */
237
+ metadata: Record<string, unknown>;
238
+ /** Component type */
99
239
  type: string;
100
- structure: any;
101
- props: Record<string, any>;
240
+ /** Component structure */
241
+ structure: unknown;
242
+ /** Component props */
243
+ props: Record<string, unknown>;
244
+ /** Tree depth */
102
245
  depth: number;
246
+ /** Direct child count */
103
247
  childCount: number;
248
+ /** Complexity score */
104
249
  complexity: number;
250
+ /** Total node count */
105
251
  nodeCount: number;
252
+ /** Analysis result */
106
253
  analysis: ComponentAnalysis;
107
- tree: ComponentTree;
254
+ /** Component tree */
255
+ tree: ComponentTreeNode;
256
+ /** Statistics */
108
257
  stats: ComponentStats;
258
+ /** Whether component is valid */
109
259
  valid: boolean;
260
+ /** Validation issues */
110
261
  issues: string[];
262
+ /** Errors found */
111
263
  errors: string[];
264
+ /** Warnings found */
112
265
  warnings: string[];
113
266
  }
114
267
 
268
+ /**
269
+ * Component inspector class
270
+ */
115
271
  export class ComponentInspector {
116
272
  constructor(options?: InspectorOptions);
117
- inspect(component: any, metadata?: Record<string, any>): InspectionResult;
273
+
274
+ /** Inspect a component */
275
+ inspect(component: unknown, metadata?: Record<string, unknown>): InspectionResult;
276
+
277
+ /** Get inspection history */
118
278
  getHistory(): InspectionResult[];
279
+
280
+ /** Get a specific inspection by ID */
119
281
  getComponent(id: string): InspectionResult | undefined;
282
+
283
+ /** Clear inspection history */
120
284
  clear(): void;
121
285
  }
122
286
 
287
+ /**
288
+ * Create an inspector instance
289
+ */
123
290
  export function createInspector(options?: InspectorOptions): ComponentInspector;
124
- export function inspect(component: any, metadata?: Record<string, any>): InspectionResult;
125
- export function validateComponent(component: any): { valid: boolean; issues: string[] };
126
291
 
127
- // ===== Profiler Types =====
292
+ /**
293
+ * Inspect a component
294
+ */
295
+ export function inspect(component: unknown, metadata?: Record<string, unknown>): InspectionResult;
128
296
 
297
+ /**
298
+ * Validate a component structure
299
+ */
300
+ export function validateComponent(component: unknown): { valid: boolean; issues: string[] };
301
+
302
+ // ============================================================================
303
+ // Profiler Types
304
+ // ============================================================================
305
+
306
+ /**
307
+ * Profiler configuration options
308
+ */
129
309
  export interface ProfilerOptions {
310
+ /** Sample rate (0-1) */
130
311
  sampleRate?: number;
312
+ /** Maximum samples to keep */
131
313
  maxSamples?: number;
314
+ /** Auto-start profiling */
132
315
  autoStart?: boolean;
133
316
  }
134
317
 
318
+ /**
319
+ * Performance measurement
320
+ */
135
321
  export interface PerformanceMeasurement {
322
+ /** Measurement name */
136
323
  name: string;
324
+ /** Duration in ms */
137
325
  duration: number;
326
+ /** Start time */
138
327
  startTime: number;
328
+ /** End time */
139
329
  endTime: number;
140
- metadata?: Record<string, any>;
330
+ /** Additional metadata */
331
+ metadata?: Record<string, unknown>;
141
332
  }
142
333
 
334
+ /**
335
+ * Profiler result for a component render
336
+ */
337
+ export interface ProfilerResult {
338
+ /** Component name */
339
+ componentName: string;
340
+ /** Total duration */
341
+ duration: number;
342
+ /** Render phase */
343
+ phase: 'mount' | 'update';
344
+ /** Actual duration (excluding suspended time) */
345
+ actualDuration: number;
346
+ /** Base duration (without memoization) */
347
+ baseDuration: number;
348
+ /** Start time */
349
+ startTime: number;
350
+ /** Commit time */
351
+ commitTime: number;
352
+ }
353
+
354
+ /**
355
+ * Profile report for a measurement
356
+ */
143
357
  export interface ProfileReport {
358
+ /** All measurements */
144
359
  measurements: PerformanceMeasurement[];
360
+ /** Total time */
145
361
  totalTime: number;
362
+ /** Average time */
146
363
  averageTime: number;
364
+ /** Minimum time */
147
365
  minTime: number;
366
+ /** Maximum time */
148
367
  maxTime: number;
368
+ /** Sample count */
149
369
  count: number;
150
370
  }
151
371
 
372
+ /**
373
+ * Performance profiler class
374
+ */
152
375
  export class PerformanceProfiler {
153
376
  constructor(options?: ProfilerOptions);
377
+
378
+ /** Start a measurement */
154
379
  start(name: string): void;
380
+
381
+ /** End a measurement */
155
382
  end(name: string): PerformanceMeasurement | null;
156
- measure(name: string, fn: () => any): any;
157
- measureAsync(name: string, fn: () => Promise<any>): Promise<any>;
383
+
384
+ /** Measure a synchronous function */
385
+ measure<T>(name: string, fn: () => T): T;
386
+
387
+ /** Measure an async function */
388
+ measureAsync<T>(name: string, fn: () => Promise<T>): Promise<T>;
389
+
390
+ /** Get profile report */
158
391
  getReport(name?: string): ProfileReport | Map<string, ProfileReport>;
392
+
393
+ /** Clear all measurements */
159
394
  clear(): void;
395
+
396
+ /** Reset profiler state */
160
397
  reset(): void;
161
398
  }
162
399
 
400
+ /**
401
+ * Create a profiler instance
402
+ */
163
403
  export function createProfiler(options?: ProfilerOptions): PerformanceProfiler;
404
+
405
+ /**
406
+ * Measure a synchronous function
407
+ */
164
408
  export function measure<T>(name: string, fn: () => T): T;
409
+
410
+ /**
411
+ * Profile a function and return result with duration
412
+ */
165
413
  export function profile<T>(fn: () => T): { result: T; duration: number };
166
414
 
167
- // ===== DevTools Types =====
415
+ /**
416
+ * Create a profiler that tracks render performance
417
+ */
418
+ export function createRenderProfiler(config?: ProfilerOptions): {
419
+ start(label: string): void;
420
+ end(label: string): number;
421
+ measure<T>(label: string, fn: () => T): T;
422
+ measureAsync<T>(label: string, fn: () => Promise<T>): Promise<T>;
423
+ getMetrics(): ProfileReport;
424
+ reset(): void;
425
+ onRender(callback: (result: ProfilerResult) => void): () => void;
426
+ };
168
427
 
428
+ /**
429
+ * HOC to add profiling to a component
430
+ */
431
+ export function withProfiling<P extends ComponentProps>(
432
+ component: (props: P) => CoherentNode,
433
+ name?: string
434
+ ): (props: P) => CoherentNode;
435
+
436
+ // ============================================================================
437
+ // DevTools Configuration
438
+ // ============================================================================
439
+
440
+ /**
441
+ * DevTools configuration options
442
+ */
443
+ export interface DevToolsConfig {
444
+ /** Enable devtools */
445
+ enabled?: boolean;
446
+ /** Log level */
447
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
448
+ /** Trace renders */
449
+ traceRenders?: boolean;
450
+ /** Trace state changes */
451
+ traceState?: boolean;
452
+ /** Show panel UI */
453
+ panel?: boolean;
454
+ }
455
+
456
+ /**
457
+ * DevTools instance interface
458
+ */
459
+ export interface DevToolsInstance {
460
+ /** Inspect a component */
461
+ inspect(component: ComponentInstance): InspectorData;
462
+
463
+ /** Log a message */
464
+ log(level: string, message: string, data?: unknown): void;
465
+
466
+ /** Trace an event */
467
+ trace(event: string, data?: unknown): void;
468
+
469
+ /** Get the component tree */
470
+ getComponentTree(): ComponentTreeNode[];
471
+
472
+ /** Enable devtools */
473
+ enable(): void;
474
+
475
+ /** Disable devtools */
476
+ disable(): void;
477
+
478
+ /** Check if enabled */
479
+ isEnabled(): boolean;
480
+ }
481
+
482
+ /**
483
+ * Create a devtools instance
484
+ */
485
+ export function createDevtools(config?: DevToolsConfig): DevToolsInstance;
486
+
487
+ /**
488
+ * HOC to add devtools tracking to a component
489
+ */
490
+ export function withDevtools<T extends (...args: unknown[]) => CoherentNode>(
491
+ component: T,
492
+ name?: string
493
+ ): T;
494
+
495
+ // ============================================================================
496
+ // DevTools Class
497
+ // ============================================================================
498
+
499
+ /**
500
+ * Combined DevTools options
501
+ */
169
502
  export interface DevToolsOptions {
503
+ /** Logger options */
170
504
  logger?: LoggerOptions;
505
+ /** Inspector options */
171
506
  inspector?: InspectorOptions;
507
+ /** Profiler options */
172
508
  profiler?: ProfilerOptions;
509
+ /** Enable all tools */
173
510
  enabled?: boolean;
174
511
  }
175
512
 
513
+ /**
514
+ * Combined DevTools class
515
+ */
176
516
  export class DevTools {
517
+ /** Logger instance */
177
518
  logger: DevLogger;
519
+ /** Inspector instance */
178
520
  inspector: ComponentInspector;
521
+ /** Profiler instance */
179
522
  profiler: PerformanceProfiler;
180
523
 
181
524
  constructor(options?: DevToolsOptions);
525
+
526
+ /** Enable all tools */
182
527
  enable(): void;
528
+
529
+ /** Disable all tools */
183
530
  disable(): void;
531
+
532
+ /** Check if enabled */
184
533
  isEnabled(): boolean;
534
+
535
+ /** Clear all data */
185
536
  clear(): void;
537
+
538
+ /** Get combined report */
186
539
  getReport(): {
187
540
  logs: LogEntry[];
188
541
  inspections: InspectionResult[];
@@ -190,9 +543,18 @@ export class DevTools {
190
543
  };
191
544
  }
192
545
 
546
+ /**
547
+ * Create a DevTools instance
548
+ */
193
549
  export function createDevTools(options?: DevToolsOptions): DevTools;
194
550
 
195
- // Default export
551
+ // ============================================================================
552
+ // Default Export
553
+ // ============================================================================
554
+
555
+ /**
556
+ * Default devtools export
557
+ */
196
558
  declare const devtools: {
197
559
  ComponentInspector: typeof ComponentInspector;
198
560
  createInspector: typeof createInspector;