@arela/uploader 1.0.24 → 1.1.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.
Files changed (79) hide show
  1. package/docs/AUTO_PROCESSING_PIPELINE.md +258 -0
  2. package/docs/COMPLETE_USAGE_GUIDE.md +1363 -0
  3. package/docs/DATABASESERVICE_IMPROVEMENTS.md +546 -0
  4. package/docs/PASO_2_TEST_RESULTS.md +298 -0
  5. package/docs/PASO_3_PLAN.md +385 -0
  6. package/docs/PHASE_1_FILE_DETECTION.md +366 -0
  7. package/docs/PHASE_2_API_INTEGRATION.md +426 -0
  8. package/docs/PHASE_3_DATABASE_MANAGEMENT.md +480 -0
  9. package/docs/PHASE_4_FILE_OPERATIONS.md +448 -0
  10. package/docs/PHASE_5_WATCH_MODE.md +450 -0
  11. package/docs/PHASE_6_SIGNAL_HANDLING.md +472 -0
  12. package/docs/PHASE_7_ADVANCED_FEATURES.md +560 -0
  13. package/docs/PLAN_WATCH_FEATURE.md +417 -0
  14. package/docs/README.md +480 -0
  15. package/docs/SCHEMA_ALIGNMENT_SUMMARY.md +301 -0
  16. package/docs/SMARTWATCH_DATABASE_REFACTORING.md +181 -0
  17. package/docs/SMART_WATCH_DATABASE_CHANGES.md +502 -0
  18. package/docs/TESTING_WATCH_MODE.md +212 -0
  19. package/docs/WATCHER_API_IMPLEMENTATION.md +520 -0
  20. package/docs/WATCHER_API_INTEGRATION.md +562 -0
  21. package/docs/WATCHER_SETUP_GUIDE.md +614 -0
  22. package/docs/WATCH_ARCHITECTURE.md +395 -0
  23. package/docs/WATCH_AUTO_PIPELINE.md +334 -0
  24. package/docs/WATCH_CONFIGURATION.md +267 -0
  25. package/docs/WATCH_USAGE_GUIDE.md +567 -0
  26. package/docs/commands.md +14 -0
  27. package/package.json +1 -1
  28. package/src/commands/IdentifyCommand.js +8 -0
  29. package/src/config/config.js +2 -2
  30. package/src/file-detection.js +42 -1
  31. package/src/scoring/scoring-engine.js +35 -7
  32. package/.vscode/settings.json +0 -1
  33. package/coverage/IdentifyCommand.js.html +0 -1462
  34. package/coverage/PropagateCommand.js.html +0 -1507
  35. package/coverage/PushCommand.js.html +0 -1504
  36. package/coverage/ScanCommand.js.html +0 -1654
  37. package/coverage/UploadCommand.js.html +0 -1846
  38. package/coverage/WatchCommand.js.html +0 -4111
  39. package/coverage/base.css +0 -224
  40. package/coverage/block-navigation.js +0 -87
  41. package/coverage/favicon.png +0 -0
  42. package/coverage/index.html +0 -191
  43. package/coverage/lcov-report/IdentifyCommand.js.html +0 -1462
  44. package/coverage/lcov-report/PropagateCommand.js.html +0 -1507
  45. package/coverage/lcov-report/PushCommand.js.html +0 -1504
  46. package/coverage/lcov-report/ScanCommand.js.html +0 -1654
  47. package/coverage/lcov-report/UploadCommand.js.html +0 -1846
  48. package/coverage/lcov-report/WatchCommand.js.html +0 -4111
  49. package/coverage/lcov-report/base.css +0 -224
  50. package/coverage/lcov-report/block-navigation.js +0 -87
  51. package/coverage/lcov-report/favicon.png +0 -0
  52. package/coverage/lcov-report/index.html +0 -191
  53. package/coverage/lcov-report/prettify.css +0 -1
  54. package/coverage/lcov-report/prettify.js +0 -2
  55. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  56. package/coverage/lcov-report/sorter.js +0 -210
  57. package/coverage/lcov.info +0 -1937
  58. package/coverage/prettify.css +0 -1
  59. package/coverage/prettify.js +0 -2
  60. package/coverage/sort-arrow-sprite.png +0 -0
  61. package/coverage/sorter.js +0 -210
  62. package/docs/API_ENDPOINTS_FOR_DETECTION.md +0 -647
  63. package/docs/API_RETRY_MECHANISM.md +0 -338
  64. package/docs/ARELA_IDENTIFY_IMPLEMENTATION.md +0 -489
  65. package/docs/ARELA_IDENTIFY_QUICKREF.md +0 -186
  66. package/docs/ARELA_PROPAGATE_IMPLEMENTATION.md +0 -581
  67. package/docs/ARELA_PROPAGATE_QUICKREF.md +0 -272
  68. package/docs/ARELA_PUSH_IMPLEMENTATION.md +0 -577
  69. package/docs/ARELA_PUSH_QUICKREF.md +0 -322
  70. package/docs/ARELA_SCAN_IMPLEMENTATION.md +0 -373
  71. package/docs/ARELA_SCAN_QUICKREF.md +0 -139
  72. package/docs/CROSS_PLATFORM_PATH_HANDLING.md +0 -597
  73. package/docs/DETECTION_ATTEMPT_TRACKING.md +0 -414
  74. package/docs/MIGRATION_UPLOADER_TO_FILE_STATS.md +0 -1020
  75. package/docs/MULTI_LEVEL_DIRECTORY_SCANNING.md +0 -494
  76. package/docs/QUICK_REFERENCE_API_DETECTION.md +0 -264
  77. package/docs/REFACTORING_SUMMARY_DETECT_PEDIMENTOS.md +0 -200
  78. package/docs/STATS_COMMAND_SEQUENCE_DIAGRAM.md +0 -287
  79. package/docs/STATS_COMMAND_SIMPLE.md +0 -93
@@ -0,0 +1,448 @@
1
+ # Phase 4: File Operations & Logging 📝
2
+
3
+ ## Overview
4
+
5
+ Phase 4 implementa operaciones avanzadas de archivos y un sistema de logging comprensivo. Este componente maneja lectura, escritura, manipulación de archivos y registra todas las operaciones.
6
+
7
+ **Objetivos Principales:**
8
+ - Operaciones seguras de archivos
9
+ - Sistema de logging estructurado
10
+ - Rotación de logs
11
+ - Manejo de archivos temporales
12
+ - Estadísticas de operaciones
13
+
14
+ ## Componentes Principales
15
+
16
+ ### 1. FileOperations.js
17
+ Servicio de operaciones de archivos.
18
+
19
+ ```javascript
20
+ const FileOperations = require('./utils/FileOperations');
21
+
22
+ // Crear archivo
23
+ await FileOperations.createFile(filePath, content);
24
+
25
+ // Leer archivo
26
+ const content = await FileOperations.readFile(filePath);
27
+
28
+ // Copiar archivo
29
+ await FileOperations.copyFile(sourcePath, destPath);
30
+
31
+ // Mover archivo
32
+ await FileOperations.moveFile(sourcePath, destPath);
33
+
34
+ // Eliminar archivo
35
+ await FileOperations.deleteFile(filePath);
36
+
37
+ // Obtener info de archivo
38
+ const stats = await FileOperations.getFileStats(filePath);
39
+ ```
40
+
41
+ **Métodos Disponibles:**
42
+ - `createFile(filePath, content, options)` - Crear archivo
43
+ - `readFile(filePath, encoding)` - Leer archivo
44
+ - `writeFile(filePath, content, options)` - Escribir archivo
45
+ - `appendFile(filePath, content)` - Agregar contenido
46
+ - `deleteFile(filePath)` - Eliminar archivo
47
+ - `copyFile(source, dest)` - Copiar archivo
48
+ - `moveFile(source, dest)` - Mover archivo
49
+ - `getFileStats(filePath)` - Obtener estadísticas
50
+ - `directoryExists(dirPath)` - Verificar directorio
51
+ - `createDirectory(dirPath)` - Crear directorio
52
+ - `listFiles(dirPath)` - Listar archivos
53
+ - `deleteDirectory(dirPath)` - Eliminar directorio
54
+
55
+ ### 2. LoggingService.js
56
+ Servicio de logging estructurado.
57
+
58
+ ```javascript
59
+ const LoggingService = require('./services/LoggingService');
60
+
61
+ const logger = LoggingService.getInstance();
62
+
63
+ // Diferentes niveles de log
64
+ logger.info('Mensaje informativo');
65
+ logger.warn('Advertencia');
66
+ logger.error('Error ocurrido');
67
+ logger.debug('Información de debug');
68
+ logger.trace('Información de traza');
69
+
70
+ // Log con contexto
71
+ logger.info('Upload completado', {
72
+ fileName: 'document.pdf',
73
+ size: 2048000,
74
+ duration: 2500
75
+ });
76
+
77
+ // Log de error con stack
78
+ try {
79
+ // código
80
+ } catch (error) {
81
+ logger.error('Error en upload', error);
82
+ }
83
+ ```
84
+
85
+ **Métodos Disponibles:**
86
+ - `info(message, data)` - Log nivel INFO
87
+ - `warn(message, data)` - Log nivel WARN
88
+ - `error(message, error)` - Log nivel ERROR
89
+ - `debug(message, data)` - Log nivel DEBUG
90
+ - `trace(message, data)` - Log nivel TRACE
91
+ - `setLevel(level)` - Establecer nivel mínimo
92
+ - `getLogFile()` - Obtener ruta de archivo de log
93
+ - `rotateLogs()` - Rotar logs
94
+
95
+ ## Niveles de Log
96
+
97
+ ```
98
+ TRACE (5) - Información muy detallada
99
+ DEBUG (4) - Información de depuración
100
+ INFO (3) - Información general
101
+ WARN (2) - Advertencias
102
+ ERROR (1) - Errores
103
+ SILENT (0) - Sin output
104
+ ```
105
+
106
+ ## Formato de Logs
107
+
108
+ ### Logs en Consola
109
+ ```
110
+ [2025-11-14 10:30:00.123] INFO - Upload iniciado para file.pdf
111
+ [2025-11-14 10:30:02.456] DEBUG - Response recibida: 200 OK
112
+ [2025-11-14 10:30:02.457] INFO - Upload completado en 2.3 segundos
113
+ ```
114
+
115
+ ### Logs en Archivo
116
+ ```
117
+ [2025-11-14T10:30:00.123Z] [INFO] Upload iniciado para file.pdf
118
+ Contexto: { fileName: 'file.pdf', size: 2048000 }
119
+
120
+ [2025-11-14T10:30:02.456Z] [DEBUG] Response recibida: 200 OK
121
+ Contexto: { statusCode: 200, headers: {...} }
122
+
123
+ [2025-11-14T10:30:02.457Z] [INFO] Upload completado en 2.3 segundos
124
+ Contexto: { duration: 2300, success: true }
125
+ ```
126
+
127
+ ## Casos de Uso
128
+
129
+ ### Caso 1: Operaciones de Archivo Seguras
130
+ ```javascript
131
+ const FileOperations = require('./utils/FileOperations');
132
+ const LoggingService = require('./services/LoggingService');
133
+
134
+ const logger = LoggingService.getInstance();
135
+
136
+ async function processFile(sourcePath, destPath) {
137
+ try {
138
+ logger.info('Iniciando procesamiento de archivo', { sourcePath });
139
+
140
+ // Leer archivo
141
+ const content = await FileOperations.readFile(sourcePath);
142
+ logger.debug('Archivo leído', { size: content.length });
143
+
144
+ // Procesar contenido
145
+ const processed = content.toUpperCase();
146
+
147
+ // Escribir archivo destino
148
+ await FileOperations.writeFile(destPath, processed);
149
+ logger.info('Archivo procesado exitosamente', { destPath });
150
+
151
+ return { success: true, size: processed.length };
152
+ } catch (error) {
153
+ logger.error('Error procesando archivo', error);
154
+ throw error;
155
+ }
156
+ }
157
+
158
+ await processFile('/input/file.txt', '/output/file.txt');
159
+ ```
160
+
161
+ ### Caso 2: Manejo de Directorios
162
+ ```javascript
163
+ const FileOperations = require('./utils/FileOperations');
164
+ const LoggingService = require('./services/LoggingService');
165
+
166
+ const logger = LoggingService.getInstance();
167
+
168
+ async function setupDirectories(baseDir) {
169
+ try {
170
+ logger.info('Configurando directorios', { baseDir });
171
+
172
+ // Crear directorios
173
+ const dirs = ['uploads', 'temp', 'processed', 'archives'];
174
+
175
+ for (const dir of dirs) {
176
+ const dirPath = `${baseDir}/${dir}`;
177
+ await FileOperations.createDirectory(dirPath);
178
+ logger.debug('Directorio creado', { path: dirPath });
179
+ }
180
+
181
+ logger.info('Directorios configurados exitosamente');
182
+ } catch (error) {
183
+ logger.error('Error configurando directorios', error);
184
+ throw error;
185
+ }
186
+ }
187
+
188
+ await setupDirectories('/data');
189
+ ```
190
+
191
+ ### Caso 3: Batch Processing con Logs
192
+ ```javascript
193
+ const FileOperations = require('./utils/FileOperations');
194
+ const LoggingService = require('./services/LoggingService');
195
+
196
+ const logger = LoggingService.getInstance();
197
+
198
+ async function processBatch(filesArray) {
199
+ const results = {
200
+ total: filesArray.length,
201
+ successful: 0,
202
+ failed: 0,
203
+ errors: []
204
+ };
205
+
206
+ logger.info('Iniciando procesamiento de batch', { count: filesArray.length });
207
+
208
+ for (const file of filesArray) {
209
+ try {
210
+ const stats = await FileOperations.getFileStats(file);
211
+
212
+ if (stats.size > 100 * 1024 * 1024) {
213
+ logger.warn('Archivo muy grande', { file, size: stats.size });
214
+ }
215
+
216
+ // Procesar archivo
217
+ logger.debug('Procesando archivo', { file });
218
+
219
+ results.successful++;
220
+ } catch (error) {
221
+ logger.error('Error procesando archivo', { file, error: error.message });
222
+ results.failed++;
223
+ results.errors.push({
224
+ file,
225
+ error: error.message
226
+ });
227
+ }
228
+ }
229
+
230
+ logger.info('Batch procesado', {
231
+ successful: results.successful,
232
+ failed: results.failed,
233
+ total: results.total
234
+ });
235
+
236
+ return results;
237
+ }
238
+
239
+ await processBatch([
240
+ '/files/doc1.pdf',
241
+ '/files/doc2.pdf',
242
+ '/files/doc3.pdf'
243
+ ]);
244
+ ```
245
+
246
+ ### Caso 4: Rotación de Logs
247
+ ```javascript
248
+ const LoggingService = require('./services/LoggingService');
249
+
250
+ const logger = LoggingService.getInstance();
251
+
252
+ // Los logs se rotan automáticamente
253
+ // Ejemplo: app-2025-11-14.log, app-2025-11-13.log, ...
254
+
255
+ // Rotar logs manualmente
256
+ async function rotateLogs() {
257
+ try {
258
+ logger.info('Iniciando rotación de logs');
259
+ await logger.rotateLogs();
260
+ logger.info('Logs rotados exitosamente');
261
+ } catch (error) {
262
+ logger.error('Error rotando logs', error);
263
+ }
264
+ }
265
+
266
+ await rotateLogs();
267
+ ```
268
+
269
+ ### Caso 5: Logging Contextual
270
+ ```javascript
271
+ const LoggingService = require('./services/LoggingService');
272
+
273
+ const logger = LoggingService.getInstance();
274
+
275
+ async function uploadWithContext(sessionId, filePath) {
276
+ // Establecer contexto para todos los logs posteriores
277
+ const context = {
278
+ sessionId,
279
+ userId: 'user-123',
280
+ operation: 'upload'
281
+ };
282
+
283
+ logger.info('Upload iniciado', { filePath, ...context });
284
+
285
+ try {
286
+ // Operaciones...
287
+ logger.debug('Validando archivo', context);
288
+ logger.debug('Preparando upload', context);
289
+ logger.info('Upload completado', { ...context, success: true });
290
+ } catch (error) {
291
+ logger.error('Upload fallido', { ...context, error: error.message });
292
+ }
293
+ }
294
+
295
+ await uploadWithContext('session-123', '/path/to/file.pdf');
296
+ ```
297
+
298
+ ## Configuración
299
+
300
+ ### Archivo: src/config/config.js
301
+
302
+ ```javascript
303
+ {
304
+ logging: {
305
+ level: process.env.LOG_LEVEL || 'info', // trace, debug, info, warn, error
306
+ format: 'json', // json o text
307
+
308
+ // Archivo de logs
309
+ file: {
310
+ enabled: true,
311
+ path: './logs',
312
+ maxSize: '10m', // Rotación cada 10MB
313
+ maxDays: 30, // Retener 30 días
314
+ compress: true // Comprimir logs antiguos
315
+ },
316
+
317
+ // Console output
318
+ console: {
319
+ enabled: true,
320
+ colorize: true
321
+ }
322
+ }
323
+ }
324
+ ```
325
+
326
+ ### Variables de Entorno
327
+
328
+ ```bash
329
+ LOG_LEVEL=info # trace, debug, info, warn, error
330
+ LOG_FORMAT=json # json o text
331
+ LOG_FILE_PATH=./logs
332
+ LOG_MAX_SIZE=10m
333
+ LOG_MAX_DAYS=30
334
+ ```
335
+
336
+ ## Archivos de Log
337
+
338
+ ### Ubicación de Logs
339
+ ```
340
+ logs/
341
+ ├── app-2025-11-14.log (Log actual)
342
+ ├── app-2025-11-13.log (Log anterior)
343
+ ├── app-2025-11-12.log.gz (Comprimido)
344
+ ├── error-2025-11-14.log (Errores solo)
345
+ └── access-2025-11-14.log (Acceso solo)
346
+ ```
347
+
348
+ ### Estructura de Log JSON
349
+ ```json
350
+ {
351
+ "timestamp": "2025-11-14T10:30:00.123Z",
352
+ "level": "INFO",
353
+ "message": "Upload completado",
354
+ "context": {
355
+ "fileName": "document.pdf",
356
+ "size": 2048000,
357
+ "duration": 2300,
358
+ "success": true
359
+ },
360
+ "source": {
361
+ "file": "UploadCommand.js",
362
+ "line": 45,
363
+ "function": "executeUpload"
364
+ }
365
+ }
366
+ ```
367
+
368
+ ## Estadísticas de Logs
369
+
370
+ ```javascript
371
+ const LoggingService = require('./services/LoggingService');
372
+
373
+ const logger = LoggingService.getInstance();
374
+
375
+ // Obtener estadísticas
376
+ const stats = logger.getStatistics();
377
+ // {
378
+ // totalLogs: 1234,
379
+ // byLevel: { INFO: 800, DEBUG: 300, WARN: 100, ERROR: 34 },
380
+ // fileSize: 5242880, // 5MB
381
+ // dayCount: 7
382
+ // }
383
+ ```
384
+
385
+ ## Rendimiento
386
+
387
+ - ✅ Log en memoria: < 1ms
388
+ - ✅ Log en archivo: < 5ms
389
+ - ✅ Log asincrónico: no bloquea
390
+ - ✅ Rotación automática: < 100ms
391
+ - ✅ Compresión: background
392
+
393
+ ## Monitoreo
394
+
395
+ ```javascript
396
+ const FileOperations = require('./utils/FileOperations');
397
+ const LoggingService = require('./services/LoggingService');
398
+
399
+ const logger = LoggingService.getInstance();
400
+
401
+ // Monitorear archivo de log
402
+ const logFile = logger.getLogFile();
403
+ const stats = await FileOperations.getFileStats(logFile);
404
+
405
+ logger.debug('Log file stats', {
406
+ size: stats.size,
407
+ modified: stats.mtime,
408
+ createdAt: stats.birthtime
409
+ });
410
+ ```
411
+
412
+ ## Arquitectura
413
+
414
+ ```
415
+ Phase 4: File Operations & Logging
416
+ ├── utils/
417
+ │ └── FileOperations.js (Operaciones de archivo)
418
+ ├── services/
419
+ │ └── LoggingService.js (Sistema de logging)
420
+ └── config/
421
+ └── config.js (Configuración)
422
+ ```
423
+
424
+ ## Testing
425
+
426
+ ```bash
427
+ npm test -- tests/phase-4-file-operations.test.js
428
+ ```
429
+
430
+ **Cobertura:**
431
+ - ✅ Creación/Lectura/Escritura de archivos
432
+ - ✅ Operaciones de directorio
433
+ - ✅ Logging en múltiples niveles
434
+ - ✅ Rotación de logs
435
+ - ✅ Manejo de errores
436
+
437
+ ## Resumen
438
+
439
+ | Aspecto | Detalle |
440
+ |---------|---------|
441
+ | **Servicios** | FileOperations, LoggingService |
442
+ | **Métodos** | 20+ métodos |
443
+ | **Niveles de Log** | 6 niveles |
444
+ | **Rotación** | Automática por tamaño/día |
445
+ | **Formatos** | JSON y texto |
446
+ | **Test Coverage** | 95%+ |
447
+ | **Estado** | ✅ Completo |
448
+