@archbase/tools 3.0.0

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/README.md ADDED
@@ -0,0 +1,423 @@
1
+ # @archbase/tools
2
+
3
+ Developer tools and utilities for debugging, performance monitoring, and development workflows.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @archbase/tools
9
+ # or
10
+ yarn add @archbase/tools
11
+ # or
12
+ pnpm add @archbase/tools
13
+ ```
14
+
15
+ ## Features
16
+
17
+ ### 🐛 Debug Utilities
18
+
19
+ #### ArchbaseConsoleLogger
20
+ Enhanced console logger with colors, grouping, and structured output.
21
+
22
+ ```typescript
23
+ import { logger } from '@archbase/tools';
24
+
25
+ // Basic logging
26
+ logger.info('User logged in', { userId: 123 });
27
+ logger.warn('Deprecated API usage');
28
+ logger.error('Authentication failed');
29
+
30
+ // Grouped logging
31
+ logger.group('API Request');
32
+ logger.info('Sending request to /api/users');
33
+ logger.success('Request completed');
34
+ logger.groupEnd();
35
+
36
+ // Performance timing
37
+ logger.time('data-fetch');
38
+ // ... some async operation
39
+ logger.timeEnd('data-fetch');
40
+ ```
41
+
42
+ #### ArchbaseDebugPanel
43
+ Real-time debug panel for monitoring application events.
44
+
45
+ ```typescript
46
+ import { ArchbaseDebugPanel, emitDebugInfo } from '@archbase/tools';
47
+
48
+ // Add to your app
49
+ function App() {
50
+ return (
51
+ <div>
52
+ <YourAppContent />
53
+ <ArchbaseDebugPanel
54
+ enabled={process.env.NODE_ENV === 'development'}
55
+ position="bottom-right"
56
+ maxEntries={100}
57
+ />
58
+ </div>
59
+ );
60
+ }
61
+
62
+ // Emit debug events
63
+ emitDebugInfo({
64
+ type: 'api',
65
+ message: 'User data fetched',
66
+ data: userData
67
+ });
68
+ ```
69
+
70
+ ### ⚡ Performance Utilities
71
+
72
+ #### ArchbasePerformanceMonitor
73
+ Track and analyze performance metrics with statistics.
74
+
75
+ ```typescript
76
+ import { performanceMonitor } from '@archbase/tools';
77
+
78
+ // Start/end measurements
79
+ performanceMonitor.start('api-call');
80
+ await fetchUserData();
81
+ const duration = performanceMonitor.end('api-call');
82
+
83
+ // Get statistics
84
+ const stats = performanceMonitor.getStats('api-call');
85
+ console.log(stats); // { count, total, average, min, max, median }
86
+
87
+ // Generate report
88
+ performanceMonitor.report();
89
+ ```
90
+
91
+ #### useArchbaseRenderTracker
92
+ React hook to track component render performance.
93
+
94
+ ```typescript
95
+ import { useArchbaseRenderTracker } from '@archbase/tools';
96
+
97
+ function MyComponent(props) {
98
+ const renderInfo = useArchbaseRenderTracker('MyComponent', props);
99
+
100
+ // renderInfo contains:
101
+ // - componentName
102
+ // - renderCount
103
+ // - lastRenderTime
104
+ // - averageRenderTime
105
+
106
+ return <div>Component content</div>;
107
+ }
108
+ ```
109
+
110
+ #### useArchbaseWhyDidYouRender
111
+ Debug hook to track why components re-render.
112
+
113
+ ```typescript
114
+ import { useArchbaseWhyDidYouRender } from '@archbase/tools';
115
+
116
+ function MyComponent(props) {
117
+ useArchbaseWhyDidYouRender('MyComponent', props);
118
+
119
+ // Will log to debug panel when props change
120
+ return <div>Component content</div>;
121
+ }
122
+ ```
123
+
124
+ ### 🛠️ Development Utilities
125
+
126
+ #### ArchbaseLocalStorageViewer
127
+ Component to view and manage localStorage in development.
128
+
129
+ ```typescript
130
+ import { ArchbaseLocalStorageViewer } from '@archbase/tools';
131
+
132
+ function DevTools() {
133
+ return (
134
+ <div style={{ height: '400px' }}>
135
+ <ArchbaseLocalStorageViewer
136
+ prefix="myapp_" // Filter by prefix
137
+ showSize={true}
138
+ onItemClick={(key, value) => console.log(key, value)}
139
+ />
140
+ </div>
141
+ );
142
+ }
143
+ ```
144
+
145
+ #### ArchbaseNetworkMonitor
146
+ Monitor and debug network requests.
147
+
148
+ ```typescript
149
+ import { ArchbaseNetworkMonitor } from '@archbase/tools';
150
+
151
+ function DevTools() {
152
+ return (
153
+ <div style={{ height: '500px' }}>
154
+ <ArchbaseNetworkMonitor
155
+ filterUrls={['/api/']} // Only monitor API calls
156
+ excludeUrls={['/analytics']} // Exclude analytics
157
+ maxRequests={50}
158
+ />
159
+ </div>
160
+ );
161
+ }
162
+ ```
163
+
164
+ #### ArchbaseStateInspector
165
+ Inspect and compare application state over time.
166
+
167
+ ```typescript
168
+ import { ArchbaseStateInspector } from '@archbase/tools';
169
+
170
+ // Define your stores
171
+ const stores = [
172
+ {
173
+ name: 'User Store',
174
+ type: 'zustand' as const,
175
+ getState: () => userStore.getState(),
176
+ subscribe: (listener) => userStore.subscribe(listener)
177
+ },
178
+ {
179
+ name: 'App Store',
180
+ type: 'redux' as const,
181
+ getState: () => store.getState(),
182
+ subscribe: (listener) => store.subscribe(listener)
183
+ }
184
+ ];
185
+
186
+ function DevTools() {
187
+ return (
188
+ <div style={{ height: '600px' }}>
189
+ <ArchbaseStateInspector
190
+ stores={stores}
191
+ maxSnapshots={50}
192
+ />
193
+ </div>
194
+ );
195
+ }
196
+ ```
197
+
198
+ #### ArchbaseErrorBoundary
199
+ Enhanced error boundary with debugging features.
200
+
201
+ ```typescript
202
+ import { ArchbaseErrorBoundary } from '@archbase/tools';
203
+
204
+ function App() {
205
+ return (
206
+ <ArchbaseErrorBoundary
207
+ showStack={process.env.NODE_ENV === 'development'}
208
+ logToConsole={true}
209
+ onError={(error, errorInfo) => {
210
+ // Custom error handling
211
+ console.error('App error:', error);
212
+ }}
213
+ fallback={(error, errorInfo) => (
214
+ <div>Custom error UI</div>
215
+ )}
216
+ >
217
+ <YourAppContent />
218
+ </ArchbaseErrorBoundary>
219
+ );
220
+ }
221
+ ```
222
+
223
+ #### ArchbaseMemoryLeakDetector
224
+ Detect potential memory leaks during development.
225
+
226
+ #### ArchbaseDataSourceInspector
227
+ Advanced DataSource inspector with real-time monitoring, inspired by ArchbasePanelTemplate debug functionality.
228
+
229
+ ```typescript
230
+ import { ArchbaseDataSourceInspector, useArchbaseDataSourceDebug } from '@archbase/tools';
231
+
232
+ // Define your DataSources to monitor
233
+ const dataSources = [
234
+ {
235
+ name: 'Users DataSource',
236
+ dataSource: userDataSource
237
+ },
238
+ {
239
+ name: 'Products DataSource',
240
+ dataSource: productDataSource
241
+ }
242
+ ];
243
+
244
+ function DevTools() {
245
+ return (
246
+ <ArchbaseDataSourceInspector
247
+ dataSources={dataSources}
248
+ autoDiscover={true} // Auto-discover DataSources in development
249
+ hotkey="ctrl+shift+D"
250
+ visible={false}
251
+ position="top-right"
252
+ maxOperations={100}
253
+ />
254
+ );
255
+ }
256
+
257
+ // Or use the debug hook for individual DataSources
258
+ function MyComponent() {
259
+ const userDataSource = useArchbaseDataSource(/*...*/);
260
+
261
+ // Enable debug monitoring
262
+ const debugInfo = useArchbaseDataSourceDebug(
263
+ userDataSource,
264
+ 'UserDataSource',
265
+ {
266
+ logOperations: true,
267
+ monitorState: true,
268
+ trackPerformance: true,
269
+ maxHistory: 50
270
+ }
271
+ );
272
+
273
+ // Access debug information
274
+ console.log('Current state:', debugInfo.currentState);
275
+ console.log('Operations:', debugInfo.operations);
276
+ console.log('Performance:', debugInfo.performanceStats);
277
+
278
+ return <div>Your component</div>;
279
+ }
280
+ ```
281
+
282
+ #### useArchbaseDataSourceDebug Hook
283
+ Monitor individual DataSource instances with detailed debugging.
284
+
285
+ ```typescript
286
+ import { useArchbaseDataSourceDebug } from '@archbase/tools';
287
+
288
+ const debugInfo = useArchbaseDataSourceDebug(dataSource, 'MyDataSource', {
289
+ logOperations: true, // Log all operations
290
+ monitorState: true, // Monitor state changes
291
+ trackPerformance: true, // Track operation performance
292
+ maxHistory: 100 // Keep last 100 operations
293
+ });
294
+
295
+ // Available debug information:
296
+ // - debugInfo.operations: Array of all operations
297
+ // - debugInfo.currentState: Current DataSource state
298
+ // - debugInfo.performanceStats: Performance statistics
299
+ // - debugInfo.getOperationHistory(methodName): Filter operations
300
+ // - debugInfo.clearHistory(): Clear operation history
301
+ // - debugInfo.exportDebugData(): Export all debug data
302
+ ```
303
+
304
+ ```typescript
305
+ import { memoryLeakDetector } from '@archbase/tools';
306
+
307
+ // Start monitoring
308
+ memoryLeakDetector.startMonitoring(5000); // Check every 5 seconds
309
+
310
+ // Get statistics
311
+ const stats = memoryLeakDetector.getMemoryStats();
312
+ console.log('Memory usage:', stats.current);
313
+ console.log('Peak usage:', stats.peak);
314
+ console.log('Growth:', stats.growth + '%');
315
+ console.log('Suspicions:', stats.suspicions);
316
+
317
+ // Force garbage collection (Chrome DevTools only)
318
+ memoryLeakDetector.forceGarbageCollection();
319
+
320
+ // Export data for analysis
321
+ const data = memoryLeakDetector.exportData();
322
+ console.log(data);
323
+
324
+ // Stop monitoring
325
+ memoryLeakDetector.stopMonitoring();
326
+ ```
327
+
328
+ ## Complete Development Setup
329
+
330
+ Here's a complete example of setting up all development tools:
331
+
332
+ ```typescript
333
+ import React from 'react';
334
+ import {
335
+ ArchbaseDebugPanel,
336
+ ArchbaseErrorBoundary,
337
+ ArchbaseLocalStorageViewer,
338
+ ArchbaseNetworkMonitor,
339
+ ArchbaseStateInspector,
340
+ ArchbaseDataSourceInspector,
341
+ memoryLeakDetector,
342
+ logger
343
+ } from '@archbase/tools';
344
+
345
+ // Start memory monitoring in development
346
+ if (process.env.NODE_ENV === 'development') {
347
+ memoryLeakDetector.startMonitoring(10000);
348
+ }
349
+
350
+ function DevToolsPanel() {
351
+ const [activeTab, setActiveTab] = React.useState('localStorage');
352
+
353
+ return (
354
+ <div style={{
355
+ position: 'fixed',
356
+ bottom: 0,
357
+ left: 0,
358
+ right: 0,
359
+ height: '300px',
360
+ zIndex: 9999
361
+ }}>
362
+ <div style={{ display: 'flex', borderBottom: '1px solid #ccc' }}>
363
+ <button onClick={() => setActiveTab('localStorage')}>LocalStorage</button>
364
+ <button onClick={() => setActiveTab('network')}>Network</button>
365
+ <button onClick={() => setActiveTab('state')}>State</button>
366
+ <button onClick={() => setActiveTab('datasource')}>DataSource</button>
367
+ </div>
368
+
369
+ <div style={{ height: 'calc(100% - 40px)' }}>
370
+ {activeTab === 'localStorage' && <ArchbaseLocalStorageViewer />}
371
+ {activeTab === 'network' && <ArchbaseNetworkMonitor />}
372
+ {activeTab === 'state' && <ArchbaseStateInspector stores={yourStores} />}
373
+ {activeTab === 'datasource' && <ArchbaseDataSourceInspector autoDiscover={true} />}
374
+ </div>
375
+ </div>
376
+ );
377
+ }
378
+
379
+ export function App() {
380
+ return (
381
+ <ArchbaseErrorBoundary>
382
+ <div>
383
+ <YourAppContent />
384
+
385
+ {/* Debug panel */}
386
+ <ArchbaseDebugPanel />
387
+
388
+ {/* Development tools panel */}
389
+ {process.env.NODE_ENV === 'development' && <DevToolsPanel />}
390
+ </div>
391
+ </ArchbaseErrorBoundary>
392
+ );
393
+ }
394
+ ```
395
+
396
+ ## TypeScript Support
397
+
398
+ All tools are written in TypeScript and include full type definitions.
399
+
400
+ ## Browser Compatibility
401
+
402
+ - Chrome/Edge: Full support
403
+ - Firefox: Full support (except memory monitoring)
404
+ - Safari: Full support (except memory monitoring)
405
+
406
+ ## Performance Impact
407
+
408
+ These tools are designed for development use only. They should be disabled in production:
409
+
410
+ ```typescript
411
+ const isDev = process.env.NODE_ENV === 'development';
412
+
413
+ // Only include dev tools in development builds
414
+ {isDev && <ArchbaseDebugPanel />}
415
+ ```
416
+
417
+ ## Contributing
418
+
419
+ This package is part of the Archbase React ecosystem. See the main repository for contribution guidelines.
420
+
421
+ ## License
422
+
423
+ MIT License
Binary file