@silasfmartins/testhub 1.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/.github/copilot-instructions.md +520 -0
- package/biome.json +37 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +169 -0
- package/dist/scripts/consumer-postinstall.d.ts +15 -0
- package/dist/scripts/consumer-postinstall.js +785 -0
- package/dist/scripts/generate-docs.d.ts +16 -0
- package/dist/scripts/generate-docs.js +1363 -0
- package/dist/scripts/generate-index.d.ts +2 -0
- package/dist/scripts/generate-index.js +314 -0
- package/dist/scripts/init-api.d.ts +2 -0
- package/dist/scripts/init-api.js +525 -0
- package/dist/scripts/init-banco.d.ts +2 -0
- package/dist/scripts/init-banco.js +347 -0
- package/dist/scripts/init-frontend.d.ts +2 -0
- package/dist/scripts/init-frontend.js +627 -0
- package/dist/scripts/init-mobile.d.ts +2 -0
- package/dist/scripts/init-mobile.js +481 -0
- package/dist/scripts/init-scenarios.d.ts +2 -0
- package/dist/scripts/init-scenarios.js +846 -0
- package/dist/scripts/init-ssh.d.ts +2 -0
- package/dist/scripts/init-ssh.js +639 -0
- package/dist/scripts/package-versions.d.ts +57 -0
- package/dist/scripts/package-versions.js +768 -0
- package/dist/scripts/postinstall.d.ts +1 -0
- package/dist/scripts/postinstall.js +527 -0
- package/dist/scripts/robust-build.d.ts +7 -0
- package/dist/scripts/robust-build.js +88 -0
- package/dist/scripts/setup-local-packages.d.ts +31 -0
- package/dist/scripts/setup-local-packages.js +237 -0
- package/dist/scripts/smart-override.d.ts +2 -0
- package/dist/scripts/smart-override.js +1360 -0
- package/dist/scripts/sync-configs.d.ts +27 -0
- package/dist/scripts/sync-configs.js +248 -0
- package/dist/scripts/test-biome-parse.d.ts +5 -0
- package/dist/scripts/test-biome-parse.js +84 -0
- package/dist/scripts/ultracite-setup.d.ts +4 -0
- package/dist/scripts/ultracite-setup.js +310 -0
- package/dist/scripts/update-all-init-scripts.d.ts +2 -0
- package/dist/scripts/update-all-init-scripts.js +52 -0
- package/dist/scripts/update-biome-schema.d.ts +15 -0
- package/dist/scripts/update-biome-schema.js +124 -0
- package/dist/src/AutoCoreFacade.d.ts +145 -0
- package/dist/src/AutoCoreFacade.js +217 -0
- package/dist/src/api/ApiActions.d.ts +297 -0
- package/dist/src/api/ApiActions.js +1905 -0
- package/dist/src/api/Certificate.d.ts +60 -0
- package/dist/src/api/Certificate.js +79 -0
- package/dist/src/api/JsonResponse.d.ts +116 -0
- package/dist/src/api/JsonResponse.js +206 -0
- package/dist/src/appium/DeviceFarmViewer.d.ts +79 -0
- package/dist/src/appium/DeviceFarmViewer.js +1083 -0
- package/dist/src/appium/MobileActions.d.ts +347 -0
- package/dist/src/appium/MobileActions.js +1632 -0
- package/dist/src/appium/MobileConnection.d.ts +160 -0
- package/dist/src/appium/MobileConnection.js +772 -0
- package/dist/src/config/envLoader.d.ts +123 -0
- package/dist/src/config/envLoader.js +361 -0
- package/dist/src/config/jest-safe-setup.d.ts +19 -0
- package/dist/src/config/jest-safe-setup.js +369 -0
- package/dist/src/config/timeouts.d.ts +32 -0
- package/dist/src/config/timeouts.js +38 -0
- package/dist/src/desktop/DesktopActions.d.ts +46 -0
- package/dist/src/desktop/DesktopActions.js +398 -0
- package/dist/src/desktop/DesktopConnection.d.ts +32 -0
- package/dist/src/desktop/DesktopConnection.js +84 -0
- package/dist/src/domain/entities/TestExecution.d.ts +117 -0
- package/dist/src/domain/entities/TestExecution.js +150 -0
- package/dist/src/domain/entities/TestReport.d.ts +114 -0
- package/dist/src/domain/entities/TestReport.js +179 -0
- package/dist/src/domain/repositories/ITestRepository.d.ts +196 -0
- package/dist/src/domain/repositories/ITestRepository.js +14 -0
- package/dist/src/domain/schemas/ValidationSchemas.d.ts +159 -0
- package/dist/src/domain/schemas/ValidationSchemas.js +181 -0
- package/dist/src/functions/errors/BaseError.d.ts +78 -0
- package/dist/src/functions/errors/BaseError.js +245 -0
- package/dist/src/functions/errors/ConfigurationError.d.ts +16 -0
- package/dist/src/functions/errors/ConfigurationError.js +48 -0
- package/dist/src/functions/errors/ErrorCatalog.d.ts +148 -0
- package/dist/src/functions/errors/ErrorCatalog.js +157 -0
- package/dist/src/functions/errors/GlobalErrorHandler.d.ts +101 -0
- package/dist/src/functions/errors/GlobalErrorHandler.js +281 -0
- package/dist/src/functions/errors/IntegrationError.d.ts +17 -0
- package/dist/src/functions/errors/IntegrationError.js +51 -0
- package/dist/src/functions/errors/SecurityError.d.ts +14 -0
- package/dist/src/functions/errors/SecurityError.js +42 -0
- package/dist/src/functions/errors/SystemError.d.ts +12 -0
- package/dist/src/functions/errors/SystemError.js +36 -0
- package/dist/src/functions/errors/ValidationError.d.ts +14 -0
- package/dist/src/functions/errors/ValidationError.js +61 -0
- package/dist/src/functions/errors/index.d.ts +12 -0
- package/dist/src/functions/errors/index.js +13 -0
- package/dist/src/global-setup.d.ts +1 -0
- package/dist/src/global-setup.js +1037 -0
- package/dist/src/helpers/BancoActions.d.ts +188 -0
- package/dist/src/helpers/BancoActions.js +581 -0
- package/dist/src/helpers/EnviromentHelper.d.ts +17 -0
- package/dist/src/helpers/EnviromentHelper.js +66 -0
- package/dist/src/helpers/ParallelExecutionHelper.d.ts +183 -0
- package/dist/src/helpers/ParallelExecutionHelper.js +375 -0
- package/dist/src/helpers/SyncSignal.d.ts +15 -0
- package/dist/src/helpers/SyncSignal.js +44 -0
- package/dist/src/hubdocs/CategoryDetector.d.ts +83 -0
- package/dist/src/hubdocs/CategoryDetector.js +401 -0
- package/dist/src/hubdocs/DirectStatementInterceptor.d.ts +54 -0
- package/dist/src/hubdocs/DirectStatementInterceptor.js +243 -0
- package/dist/src/hubdocs/ExecutionTracker.d.ts +107 -0
- package/dist/src/hubdocs/ExecutionTracker.js +702 -0
- package/dist/src/hubdocs/HubDocs.d.ts +395 -0
- package/dist/src/hubdocs/HubDocs.js +3586 -0
- package/dist/src/hubdocs/StatementMethodFilter.d.ts +71 -0
- package/dist/src/hubdocs/StatementMethodFilter.js +618 -0
- package/dist/src/hubdocs/StatementTracker.d.ts +417 -0
- package/dist/src/hubdocs/StatementTracker.js +2419 -0
- package/dist/src/hubdocs/SwaggerGenerator.d.ts +59 -0
- package/dist/src/hubdocs/SwaggerGenerator.js +405 -0
- package/dist/src/hubdocs/index.d.ts +9 -0
- package/dist/src/hubdocs/index.js +9 -0
- package/dist/src/hubdocs/types.d.ts +114 -0
- package/dist/src/hubdocs/types.js +5 -0
- package/dist/src/infrastructure/DependencyContainer.d.ts +142 -0
- package/dist/src/infrastructure/DependencyContainer.js +250 -0
- package/dist/src/infrastructure/adapters/AppiumAdapter.d.ts +168 -0
- package/dist/src/infrastructure/adapters/AppiumAdapter.js +468 -0
- package/dist/src/infrastructure/adapters/OracleAdapter.d.ts +150 -0
- package/dist/src/infrastructure/adapters/OracleAdapter.js +388 -0
- package/dist/src/infrastructure/adapters/PlaywrightAdapter.d.ts +192 -0
- package/dist/src/infrastructure/adapters/PlaywrightAdapter.js +382 -0
- package/dist/src/infrastructure/adapters/SSHAdapter.d.ts +141 -0
- package/dist/src/infrastructure/adapters/SSHAdapter.js +428 -0
- package/dist/src/interfaces.d.ts +501 -0
- package/dist/src/interfaces.js +25 -0
- package/dist/src/internal/fakes/__fake-actions__.d.ts +17 -0
- package/dist/src/internal/fakes/__fake-actions__.js +21 -0
- package/dist/src/internal/fakes/__forbidden__.d.ts +10 -0
- package/dist/src/internal/fakes/__forbidden__.js +18 -0
- package/dist/src/internal/fakes/__honeypot__.d.ts +15 -0
- package/dist/src/internal/fakes/__honeypot__.js +24 -0
- package/dist/src/octane/OctaneReporter.d.ts +13 -0
- package/dist/src/octane/OctaneReporter.js +61 -0
- package/dist/src/playwright/CryptoActions.d.ts +20 -0
- package/dist/src/playwright/CryptoActions.js +75 -0
- package/dist/src/playwright/EnhancedWebActions.d.ts +7 -0
- package/dist/src/playwright/EnhancedWebActions.js +65 -0
- package/dist/src/playwright/WebActions.d.ts +1599 -0
- package/dist/src/playwright/WebActions.js +11788 -0
- package/dist/src/playwright/actions/ActionTimeline.d.ts +36 -0
- package/dist/src/playwright/actions/ActionTimeline.js +101 -0
- package/dist/src/playwright/actions/RecoveryQueue.d.ts +82 -0
- package/dist/src/playwright/actions/RecoveryQueue.js +130 -0
- package/dist/src/playwright/actions/SelectorCache.d.ts +53 -0
- package/dist/src/playwright/actions/SelectorCache.js +96 -0
- package/dist/src/playwright/actions/index.d.ts +13 -0
- package/dist/src/playwright/actions/index.js +14 -0
- package/dist/src/playwright/actions/types.d.ts +147 -0
- package/dist/src/playwright/actions/types.js +5 -0
- package/dist/src/playwright/fixtures.d.ts +112 -0
- package/dist/src/playwright/fixtures.js +718 -0
- package/dist/src/playwright/network-logs-reporter.d.ts +7 -0
- package/dist/src/playwright/network-logs-reporter.js +66 -0
- package/dist/src/playwright/registerRecoveryWrappers.d.ts +1 -0
- package/dist/src/playwright/registerRecoveryWrappers.js +54 -0
- package/dist/src/security/BuildSecurity.d.ts +12 -0
- package/dist/src/security/BuildSecurity.js +138 -0
- package/dist/src/security/EulaProtection.d.ts +70 -0
- package/dist/src/security/EulaProtection.js +155 -0
- package/dist/src/security/HoneypotManager.d.ts +46 -0
- package/dist/src/security/HoneypotManager.js +234 -0
- package/dist/src/security/KeysManager.d.ts +36 -0
- package/dist/src/security/KeysManager.js +158 -0
- package/dist/src/security/ProofOfWorkIntegration.d.ts +64 -0
- package/dist/src/security/ProofOfWorkIntegration.js +206 -0
- package/dist/src/security/SecurityValidation.d.ts +21 -0
- package/dist/src/security/SecurityValidation.js +163 -0
- package/dist/src/security/SourceMapProtection.d.ts +55 -0
- package/dist/src/security/SourceMapProtection.js +220 -0
- package/dist/src/security/protector.d.ts +1 -0
- package/dist/src/security/protector.js +97 -0
- package/dist/src/ssh/SSHActions.d.ts +262 -0
- package/dist/src/ssh/SSHActions.js +790 -0
- package/dist/src/ssh/SSHClient.d.ts +99 -0
- package/dist/src/ssh/SSHClient.js +409 -0
- package/dist/src/statements/BaseStatement.d.ts +38 -0
- package/dist/src/statements/BaseStatement.js +78 -0
- package/dist/src/testContext/AuthStateManager.d.ts +93 -0
- package/dist/src/testContext/AuthStateManager.js +256 -0
- package/dist/src/testContext/CoverageManager.d.ts +198 -0
- package/dist/src/testContext/CoverageManager.js +917 -0
- package/dist/src/testContext/TestAnnotations.d.ts +476 -0
- package/dist/src/testContext/TestAnnotations.js +2647 -0
- package/dist/src/testContext/TestContext.d.ts +138 -0
- package/dist/src/testContext/TestContext.js +369 -0
- package/dist/src/testContext/UnifiedHtmlGenerator.d.ts +7 -0
- package/dist/src/testContext/UnifiedHtmlGenerator.js +264 -0
- package/dist/src/testContext/UnifiedReportManager.d.ts +211 -0
- package/dist/src/testContext/UnifiedReportManager.js +1206 -0
- package/dist/src/testhub/DynamicConfigManager.d.ts +121 -0
- package/dist/src/testhub/DynamicConfigManager.js +320 -0
- package/dist/src/testhub/SystemsManager.d.ts +119 -0
- package/dist/src/testhub/SystemsManager.js +365 -0
- package/dist/src/testhub/TestHubClient.d.ts +335 -0
- package/dist/src/testhub/TestHubClient.js +1215 -0
- package/dist/src/testhub/TestHubReporter.d.ts +62 -0
- package/dist/src/testhub/TestHubReporter.js +576 -0
- package/dist/src/testhub/TestHubVars.d.ts +116 -0
- package/dist/src/testhub/TestHubVars.js +273 -0
- package/dist/src/utils/ActionInterceptor.d.ts +59 -0
- package/dist/src/utils/ActionInterceptor.js +741 -0
- package/dist/src/utils/ArtifactsCompressor.d.ts +43 -0
- package/dist/src/utils/ArtifactsCompressor.js +181 -0
- package/dist/src/utils/AutoLogsFinal.d.ts +47 -0
- package/dist/src/utils/AutoLogsFinal.js +148 -0
- package/dist/src/utils/CodeGenSession.d.ts +114 -0
- package/dist/src/utils/CodeGenSession.js +264 -0
- package/dist/src/utils/ConfigLogger.d.ts +133 -0
- package/dist/src/utils/ConfigLogger.js +611 -0
- package/dist/src/utils/CustomReporter.d.ts +22 -0
- package/dist/src/utils/CustomReporter.js +352 -0
- package/dist/src/utils/DataStore.d.ts +171 -0
- package/dist/src/utils/DataStore.js +484 -0
- package/dist/src/utils/DatabaseInterceptor.d.ts +19 -0
- package/dist/src/utils/DatabaseInterceptor.js +295 -0
- package/dist/src/utils/DateHelper.d.ts +16 -0
- package/dist/src/utils/DateHelper.js +120 -0
- package/dist/src/utils/DateValidator.d.ts +4 -0
- package/dist/src/utils/DateValidator.js +51 -0
- package/dist/src/utils/DocumentGenerator.d.ts +35 -0
- package/dist/src/utils/DocumentGenerator.js +129 -0
- package/dist/src/utils/EvidenceCapture.d.ts +90 -0
- package/dist/src/utils/EvidenceCapture.js +600 -0
- package/dist/src/utils/EvidenceReportGenerator.d.ts +70 -0
- package/dist/src/utils/EvidenceReportGenerator.js +799 -0
- package/dist/src/utils/FrameManagementUtil.d.ts +42 -0
- package/dist/src/utils/FrameManagementUtil.js +75 -0
- package/dist/src/utils/GlobalStatementsInterceptor.d.ts +1 -0
- package/dist/src/utils/GlobalStatementsInterceptor.js +1 -0
- package/dist/src/utils/HTMLTemplate.d.ts +1 -0
- package/dist/src/utils/HTMLTemplate.js +1034 -0
- package/dist/src/utils/InterceptacaoMagica.d.ts +23 -0
- package/dist/src/utils/InterceptacaoMagica.js +365 -0
- package/dist/src/utils/LogSanitizer.d.ts +35 -0
- package/dist/src/utils/LogSanitizer.js +110 -0
- package/dist/src/utils/Logger.d.ts +65 -0
- package/dist/src/utils/Logger.js +284 -0
- package/dist/src/utils/McpLocalClient.d.ts +141 -0
- package/dist/src/utils/McpLocalClient.js +871 -0
- package/dist/src/utils/PDFEvidenceGenerator.d.ts +20 -0
- package/dist/src/utils/PDFEvidenceGenerator.js +156 -0
- package/dist/src/utils/SpecFileAnalyzer.d.ts +35 -0
- package/dist/src/utils/SpecFileAnalyzer.js +209 -0
- package/dist/src/utils/StatementInterceptor.d.ts +18 -0
- package/dist/src/utils/StatementInterceptor.js +87 -0
- package/dist/src/utils/StatementLogger.d.ts +33 -0
- package/dist/src/utils/StatementLogger.js +113 -0
- package/dist/src/utils/StatementsInterceptor.d.ts +1 -0
- package/dist/src/utils/StatementsInterceptor.js +1 -0
- package/dist/src/utils/TeamsFlushHook.d.ts +17 -0
- package/dist/src/utils/TeamsFlushHook.js +168 -0
- package/dist/src/utils/TerminalLogCapture.d.ts +158 -0
- package/dist/src/utils/TerminalLogCapture.js +531 -0
- package/dist/src/utils/TestMethodLogger.d.ts +70 -0
- package/dist/src/utils/TestMethodLogger.js +95 -0
- package/dist/src/utils/UnifiedTeardown.d.ts +4 -0
- package/dist/src/utils/UnifiedTeardown.js +400 -0
- package/dist/src/utils/XPathCatalog.d.ts +152 -0
- package/dist/src/utils/XPathCatalog.js +350 -0
- package/dist/src/utils/generators.d.ts +90 -0
- package/dist/src/utils/generators.js +167 -0
- package/dist/src/utils/testRecovery/ResilientPlaywright.d.ts +152 -0
- package/dist/src/utils/testRecovery/ResilientPlaywright.js +715 -0
- package/dist/src/utils/testRecovery/TestRecoveryClient.d.ts +801 -0
- package/dist/src/utils/testRecovery/TestRecoveryClient.js +1415 -0
- package/dist/src/utils/testRecovery/autoFixCode.d.ts +65 -0
- package/dist/src/utils/testRecovery/autoFixCode.js +32 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +59 -0
- package/dist/wdio.conf.d.ts +1 -0
- package/dist/wdio.conf.js +420 -0
- package/package.json +137 -0
- package/protect-loader.mjs +643 -0
- package/scripts/consumer-postinstall.ts +975 -0
- package/scripts/generate-index.ts +343 -0
- package/scripts/init-api.ts +613 -0
- package/scripts/init-banco.ts +437 -0
- package/scripts/init-frontend.ts +727 -0
- package/scripts/init-mobile.ts +558 -0
- package/scripts/init-scenarios.ts +925 -0
- package/scripts/init-ssh.ts +734 -0
- package/scripts/package-versions.ts +978 -0
- package/scripts/postinstall.ts +605 -0
- package/scripts/smart-override.ts +1675 -0
- package/scripts/sync-configs.ts +302 -0
- package/scripts/ultracite-setup.ts +370 -0
- package/src/types/globals.d.ts +48 -0
- package/tsconfig.json +29 -0
- package/types/autocore-sync-signal.d.ts +10 -0
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { Logger } from './Logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Store compartilhado para transferência de dados entre projetos e testes
|
|
6
|
+
*
|
|
7
|
+
* Funcionalidades:
|
|
8
|
+
* - Cache em memória para performance
|
|
9
|
+
* - Persistência em arquivo JSON
|
|
10
|
+
* - Métodos especializados para diferentes tipos de dados
|
|
11
|
+
* - Limpeza automática com TTL
|
|
12
|
+
* - Thread-safe operations
|
|
13
|
+
* - Type-safe getters para evitar erros de null
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // ✅ FORMA CORRETA - Armazenar dados
|
|
18
|
+
* DataStore.set('user_id', '12345')
|
|
19
|
+
* DataStore.set('URL_CLIENTE', 'https://example.com')
|
|
20
|
+
*
|
|
21
|
+
* // ✅ FORMA CORRETA - Recuperar com type safety
|
|
22
|
+
* const userId = DataStore.getString('user_id') // retorna string (nunca null)
|
|
23
|
+
* const url = DataStore.getString('URL_CLIENTE', 'https://default.com') // com fallback
|
|
24
|
+
* const count = DataStore.getNumber('attempts', 0) // retorna number
|
|
25
|
+
* const isActive = DataStore.getBoolean('active') // retorna boolean
|
|
26
|
+
*
|
|
27
|
+
* // ✅ FORMA CORRETA - Quando você TEM CERTEZA que o valor existe
|
|
28
|
+
* const token = DataStore.getOrThrow<string>('ACCESS_TOKEN') // lança erro se null
|
|
29
|
+
*
|
|
30
|
+
* // ❌ EVITE - Pode causar erro TypeScript "Type 'string | null' is not assignable to type 'string'"
|
|
31
|
+
* const url: string = DataStore.get('URL_CLIENTE') // ❌ ERRO!
|
|
32
|
+
* Logger.info(DataStore.get('URL_CLIENTE')) // ❌ ERRO!
|
|
33
|
+
*
|
|
34
|
+
* // ✅ CORRIJA USANDO - Operador de coalescência nula
|
|
35
|
+
* const url: string = DataStore.get('URL_CLIENTE') ?? 'default'
|
|
36
|
+
* Logger.info(DataStore.getString('URL_CLIENTE'))
|
|
37
|
+
*
|
|
38
|
+
* // Armazenar com TTL
|
|
39
|
+
* DataStore.setWithTTL('session_token', 'abc123', 3600) // expira em 1h
|
|
40
|
+
*
|
|
41
|
+
* // Armazenar resultado de query
|
|
42
|
+
* DataStore.storeQueryResult('user_details', userData)
|
|
43
|
+
*
|
|
44
|
+
* // Armazenar screenshot
|
|
45
|
+
* DataStore.storeScreenshot('login_page', screenshotBuffer)
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export class DataStore {
|
|
49
|
+
static dataFilePath = resolve(process.cwd(), '.test-data-store.json');
|
|
50
|
+
static persistEnabled = process.env.AUTOCORE_DATASTORE_PERSIST !== 'false';
|
|
51
|
+
static cache = {};
|
|
52
|
+
static initialized = false;
|
|
53
|
+
static lastSaveTime = 0;
|
|
54
|
+
static SAVE_THROTTLE_MS = 100; // Throttle saves to avoid excessive I/O
|
|
55
|
+
/**
|
|
56
|
+
* Inicializa o DataStore carregando dados existentes
|
|
57
|
+
*/
|
|
58
|
+
static initialize() {
|
|
59
|
+
if (DataStore.initialized)
|
|
60
|
+
return;
|
|
61
|
+
try {
|
|
62
|
+
if (DataStore.persistEnabled && existsSync(DataStore.dataFilePath)) {
|
|
63
|
+
const fileContent = readFileSync(DataStore.dataFilePath, 'utf8');
|
|
64
|
+
const rawData = JSON.parse(fileContent);
|
|
65
|
+
// Migrar dados antigos para novo formato
|
|
66
|
+
DataStore.cache = DataStore.migrateOldFormat(rawData);
|
|
67
|
+
// Limpar itens expirados
|
|
68
|
+
DataStore.cleanupExpiredItems();
|
|
69
|
+
Logger.info(`DataStore: Carregados ${Object.keys(DataStore.cache).length} valores`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
DataStore.cache = {};
|
|
73
|
+
if (DataStore.persistEnabled) {
|
|
74
|
+
DataStore.save();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
Logger.info('DataStore: Modo memória (persistência desabilitada)');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
DataStore.initialized = true;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
Logger.error('DataStore: Erro ao inicializar', error);
|
|
84
|
+
DataStore.cache = {};
|
|
85
|
+
DataStore.initialized = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Migra dados do formato antigo para o novo com metadados
|
|
90
|
+
*/
|
|
91
|
+
static migrateOldFormat(rawData) {
|
|
92
|
+
const migratedData = {};
|
|
93
|
+
for (const [key, value] of Object.entries(rawData)) {
|
|
94
|
+
// Se já está no novo formato
|
|
95
|
+
if (value &&
|
|
96
|
+
typeof value === 'object' &&
|
|
97
|
+
'value' in value &&
|
|
98
|
+
'timestamp' in value) {
|
|
99
|
+
migratedData[key] = value;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Migrar formato antigo
|
|
103
|
+
migratedData[key] = {
|
|
104
|
+
value,
|
|
105
|
+
timestamp: new Date().toISOString(),
|
|
106
|
+
type: DataStore.determineItemType(key, value),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return migratedData;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Determina o tipo do item baseado na chave e valor
|
|
114
|
+
*/
|
|
115
|
+
static determineItemType(key, value) {
|
|
116
|
+
if (key.startsWith('db_query_'))
|
|
117
|
+
return 'query';
|
|
118
|
+
if (key.startsWith('screenshot_'))
|
|
119
|
+
return 'screenshot';
|
|
120
|
+
if (key.startsWith('temp_'))
|
|
121
|
+
return 'temp';
|
|
122
|
+
if (key.includes('metadata') ||
|
|
123
|
+
key.includes('SYSTEM_') ||
|
|
124
|
+
key.includes('SETUP_'))
|
|
125
|
+
return 'metadata';
|
|
126
|
+
return 'simple';
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Remove itens expirados baseado no TTL
|
|
130
|
+
*/
|
|
131
|
+
static cleanupExpiredItems() {
|
|
132
|
+
const now = Date.now();
|
|
133
|
+
let cleanedCount = 0;
|
|
134
|
+
for (const [key, item] of Object.entries(DataStore.cache)) {
|
|
135
|
+
if (item.ttl) {
|
|
136
|
+
const itemTime = new Date(item.timestamp).getTime();
|
|
137
|
+
const expirationTime = itemTime + item.ttl * 1000;
|
|
138
|
+
if (now > expirationTime) {
|
|
139
|
+
delete DataStore.cache[key];
|
|
140
|
+
cleanedCount++;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (cleanedCount > 0) {
|
|
145
|
+
Logger.info(`DataStore: Removidos ${cleanedCount} itens expirados`);
|
|
146
|
+
DataStore.save();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Salva os dados no arquivo com throttling
|
|
151
|
+
*/
|
|
152
|
+
static save() {
|
|
153
|
+
if (!DataStore.persistEnabled) {
|
|
154
|
+
// Persistência desabilitada: apenas atualizar marcação de tempo
|
|
155
|
+
DataStore.lastSaveTime = Date.now();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const now = Date.now();
|
|
159
|
+
// Throttle saves para evitar I/O excessivo
|
|
160
|
+
if (now - DataStore.lastSaveTime < DataStore.SAVE_THROTTLE_MS) {
|
|
161
|
+
// Agenda save para depois se não houver um pendente
|
|
162
|
+
setTimeout(() => DataStore.save(), DataStore.SAVE_THROTTLE_MS);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
writeFileSync(DataStore.dataFilePath, JSON.stringify(DataStore.cache, null, 2), 'utf8');
|
|
167
|
+
DataStore.lastSaveTime = now;
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
Logger.error('DataStore: Erro ao salvar dados', error);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Armazena um valor com uma chave específica
|
|
175
|
+
*/
|
|
176
|
+
static set(key, value) {
|
|
177
|
+
DataStore.initialize();
|
|
178
|
+
DataStore.cache[key] = {
|
|
179
|
+
value,
|
|
180
|
+
timestamp: new Date().toISOString(),
|
|
181
|
+
type: DataStore.determineItemType(key, value),
|
|
182
|
+
};
|
|
183
|
+
DataStore.save();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Armazena um valor com TTL (Time To Live)
|
|
187
|
+
*/
|
|
188
|
+
static setWithTTL(key, value, ttlSeconds) {
|
|
189
|
+
DataStore.initialize();
|
|
190
|
+
DataStore.cache[key] = {
|
|
191
|
+
value,
|
|
192
|
+
timestamp: new Date().toISOString(),
|
|
193
|
+
ttl: ttlSeconds,
|
|
194
|
+
type: DataStore.determineItemType(key, value),
|
|
195
|
+
};
|
|
196
|
+
DataStore.save();
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Recupera um valor usando sua chave
|
|
200
|
+
*/
|
|
201
|
+
static get(key, defaultValue = null) {
|
|
202
|
+
DataStore.initialize();
|
|
203
|
+
const item = DataStore.cache[key];
|
|
204
|
+
if (!item) {
|
|
205
|
+
Logger.info(`DataStore: Chave '${key}' não encontrada`);
|
|
206
|
+
return defaultValue;
|
|
207
|
+
}
|
|
208
|
+
// Verificar se expirou
|
|
209
|
+
if (item.ttl) {
|
|
210
|
+
const now = Date.now();
|
|
211
|
+
const itemTime = new Date(item.timestamp).getTime();
|
|
212
|
+
const expirationTime = itemTime + item.ttl * 1000;
|
|
213
|
+
if (now > expirationTime) {
|
|
214
|
+
delete DataStore.cache[key];
|
|
215
|
+
DataStore.save();
|
|
216
|
+
Logger.info(`DataStore: Chave '${key}' expirada e removida`);
|
|
217
|
+
return defaultValue;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return item.value;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Recupera um valor ou lança erro se não existir
|
|
224
|
+
* Útil quando você tem certeza que o valor existe
|
|
225
|
+
*/
|
|
226
|
+
static getOrThrow(key) {
|
|
227
|
+
const value = DataStore.get(key);
|
|
228
|
+
if (value === null || value === undefined) {
|
|
229
|
+
throw new Error(`DataStore: Chave obrigatória '${key}' não encontrada`);
|
|
230
|
+
}
|
|
231
|
+
return value;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Recupera um valor string ou retorna string vazia
|
|
235
|
+
* Útil para evitar problemas com null
|
|
236
|
+
*/
|
|
237
|
+
static getString(key, defaultValue = '') {
|
|
238
|
+
const value = DataStore.get(key);
|
|
239
|
+
return value ?? defaultValue;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Recupera um valor number ou retorna 0
|
|
243
|
+
*/
|
|
244
|
+
static getNumber(key, defaultValue = 0) {
|
|
245
|
+
const value = DataStore.get(key);
|
|
246
|
+
return value ?? defaultValue;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Recupera um valor boolean ou retorna false
|
|
250
|
+
*/
|
|
251
|
+
static getBoolean(key, defaultValue = false) {
|
|
252
|
+
const value = DataStore.get(key);
|
|
253
|
+
return value ?? defaultValue;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Verifica se uma chave existe e não expirou
|
|
257
|
+
*/
|
|
258
|
+
static has(key) {
|
|
259
|
+
DataStore.initialize();
|
|
260
|
+
const item = DataStore.cache[key];
|
|
261
|
+
if (!item)
|
|
262
|
+
return false;
|
|
263
|
+
// Verificar TTL
|
|
264
|
+
if (item.ttl) {
|
|
265
|
+
const now = Date.now();
|
|
266
|
+
const itemTime = new Date(item.timestamp).getTime();
|
|
267
|
+
const expirationTime = itemTime + item.ttl * 1000;
|
|
268
|
+
if (now > expirationTime) {
|
|
269
|
+
delete DataStore.cache[key];
|
|
270
|
+
DataStore.save();
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Remove um valor específico
|
|
278
|
+
*/
|
|
279
|
+
static remove(key) {
|
|
280
|
+
DataStore.initialize();
|
|
281
|
+
if (key in DataStore.cache) {
|
|
282
|
+
delete DataStore.cache[key];
|
|
283
|
+
DataStore.save();
|
|
284
|
+
Logger.info(`DataStore: Removida chave '${key}'`);
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Limpa todos os valores armazenados
|
|
291
|
+
*/
|
|
292
|
+
static clear() {
|
|
293
|
+
DataStore.initialize();
|
|
294
|
+
DataStore.cache = {};
|
|
295
|
+
DataStore.save();
|
|
296
|
+
Logger.info('DataStore: Todos os valores foram limpos');
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Limpa apenas itens temporários
|
|
300
|
+
*/
|
|
301
|
+
static clearTempItems() {
|
|
302
|
+
DataStore.initialize();
|
|
303
|
+
let removedCount = 0;
|
|
304
|
+
for (const [key, item] of Object.entries(DataStore.cache)) {
|
|
305
|
+
if (item.type === 'temp' || key.startsWith('temp_')) {
|
|
306
|
+
delete DataStore.cache[key];
|
|
307
|
+
removedCount++;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (removedCount > 0) {
|
|
311
|
+
DataStore.save();
|
|
312
|
+
Logger.info(`DataStore: Removidos ${removedCount} itens temporários`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Retorna todos os dados armazenados com metadados
|
|
317
|
+
*/
|
|
318
|
+
static getAll() {
|
|
319
|
+
DataStore.initialize();
|
|
320
|
+
DataStore.cleanupExpiredItems();
|
|
321
|
+
const result = {};
|
|
322
|
+
for (const [key, item] of Object.entries(DataStore.cache)) {
|
|
323
|
+
result[key] = item.value;
|
|
324
|
+
}
|
|
325
|
+
return result;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Retorna estatísticas do DataStore
|
|
329
|
+
*/
|
|
330
|
+
static getStats() {
|
|
331
|
+
DataStore.initialize();
|
|
332
|
+
const stats = {
|
|
333
|
+
totalItems: Object.keys(DataStore.cache).length,
|
|
334
|
+
itemsByType: {},
|
|
335
|
+
expiredItems: 0,
|
|
336
|
+
totalSizeKB: 0,
|
|
337
|
+
};
|
|
338
|
+
const now = Date.now();
|
|
339
|
+
for (const item of Object.values(DataStore.cache)) {
|
|
340
|
+
// Contar por tipo
|
|
341
|
+
stats.itemsByType[item.type] = (stats.itemsByType[item.type] || 0) + 1;
|
|
342
|
+
// Contar expirados
|
|
343
|
+
if (item.ttl) {
|
|
344
|
+
const itemTime = new Date(item.timestamp).getTime();
|
|
345
|
+
const expirationTime = itemTime + item.ttl * 1000;
|
|
346
|
+
if (now > expirationTime) {
|
|
347
|
+
stats.expiredItems++;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// Calcular tamanho aproximado
|
|
352
|
+
try {
|
|
353
|
+
const jsonString = JSON.stringify(DataStore.cache);
|
|
354
|
+
stats.totalSizeKB = Math.round(Buffer.byteLength(jsonString, 'utf8') / 1024);
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
stats.totalSizeKB = 0;
|
|
358
|
+
}
|
|
359
|
+
return stats;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Armazena resultado de consulta de banco para uso posterior
|
|
363
|
+
*/
|
|
364
|
+
static storeQueryResult(queryName, data, ttlSeconds) {
|
|
365
|
+
const key = `db_query_${queryName}`;
|
|
366
|
+
const item = {
|
|
367
|
+
value: {
|
|
368
|
+
timestamp: new Date().toISOString(),
|
|
369
|
+
data,
|
|
370
|
+
queryName,
|
|
371
|
+
},
|
|
372
|
+
timestamp: new Date().toISOString(),
|
|
373
|
+
type: 'query',
|
|
374
|
+
...(ttlSeconds && { ttl: ttlSeconds }),
|
|
375
|
+
};
|
|
376
|
+
DataStore.initialize();
|
|
377
|
+
DataStore.cache[key] = item;
|
|
378
|
+
DataStore.save();
|
|
379
|
+
Logger.info(`DataStore: Resultado da query '${queryName}' armazenado`);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Recupera resultado de consulta de banco
|
|
383
|
+
*/
|
|
384
|
+
static getQueryResult(queryName) {
|
|
385
|
+
const result = DataStore.get(`db_query_${queryName}`);
|
|
386
|
+
return result ? result.data : null;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Armazena screenshot para evidências
|
|
390
|
+
*/
|
|
391
|
+
static storeScreenshot(name, screenshotData, metadata) {
|
|
392
|
+
const key = `screenshot_${name}`;
|
|
393
|
+
DataStore.initialize();
|
|
394
|
+
DataStore.cache[key] = {
|
|
395
|
+
value: {
|
|
396
|
+
data: screenshotData,
|
|
397
|
+
metadata: metadata || {},
|
|
398
|
+
timestamp: new Date().toISOString(),
|
|
399
|
+
},
|
|
400
|
+
timestamp: new Date().toISOString(),
|
|
401
|
+
type: 'screenshot',
|
|
402
|
+
};
|
|
403
|
+
DataStore.save();
|
|
404
|
+
Logger.info(`DataStore: Screenshot '${name}' armazenado`);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Recupera screenshot
|
|
408
|
+
*/
|
|
409
|
+
static getScreenshot(name) {
|
|
410
|
+
return DataStore.get(`screenshot_${name}`);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Armazena dados temporários com TTL curto
|
|
414
|
+
*/
|
|
415
|
+
static setTemp(key, value, ttlSeconds = 300) {
|
|
416
|
+
DataStore.setWithTTL(`temp_${key}`, value, ttlSeconds);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Recupera dados temporários
|
|
420
|
+
*/
|
|
421
|
+
static getTemp(key) {
|
|
422
|
+
return DataStore.get(`temp_${key}`);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Força limpeza completa e remove arquivo
|
|
426
|
+
*/
|
|
427
|
+
static cleanup() {
|
|
428
|
+
DataStore.cache = {};
|
|
429
|
+
DataStore.initialized = false;
|
|
430
|
+
if (DataStore.persistEnabled && existsSync(DataStore.dataFilePath)) {
|
|
431
|
+
try {
|
|
432
|
+
unlinkSync(DataStore.dataFilePath);
|
|
433
|
+
}
|
|
434
|
+
catch (error) {
|
|
435
|
+
Logger.error('Erro ao remover o arquivo .test-data-store.json', error);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Backup dos dados para outro arquivo
|
|
441
|
+
*/
|
|
442
|
+
static backup(backupPath) {
|
|
443
|
+
DataStore.initialize();
|
|
444
|
+
if (!DataStore.persistEnabled) {
|
|
445
|
+
Logger.warning('DataStore: Backup ignorado (persistência desabilitada)');
|
|
446
|
+
return '';
|
|
447
|
+
}
|
|
448
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
449
|
+
const finalBackupPath = backupPath || resolve(process.cwd(), `datastore-backup-${timestamp}.json`);
|
|
450
|
+
try {
|
|
451
|
+
writeFileSync(finalBackupPath, JSON.stringify(DataStore.cache, null, 2), 'utf8');
|
|
452
|
+
Logger.info(`DataStore: Backup criado em ${finalBackupPath}`);
|
|
453
|
+
return finalBackupPath;
|
|
454
|
+
}
|
|
455
|
+
catch (error) {
|
|
456
|
+
Logger.error('DataStore: Erro ao criar backup', error);
|
|
457
|
+
throw error;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Restaura dados de um backup
|
|
462
|
+
*/
|
|
463
|
+
static restore(backupPath) {
|
|
464
|
+
try {
|
|
465
|
+
if (!DataStore.persistEnabled) {
|
|
466
|
+
Logger.warning('DataStore: Restore ignorado (persistência desabilitada)');
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (!existsSync(backupPath)) {
|
|
470
|
+
throw new Error(`Arquivo de backup não encontrado: ${backupPath}`);
|
|
471
|
+
}
|
|
472
|
+
const backupContent = readFileSync(backupPath, 'utf8');
|
|
473
|
+
const backupData = JSON.parse(backupContent);
|
|
474
|
+
DataStore.cache = DataStore.migrateOldFormat(backupData);
|
|
475
|
+
DataStore.save();
|
|
476
|
+
DataStore.initialized = true;
|
|
477
|
+
Logger.info(`DataStore: Dados restaurados de ${backupPath}`);
|
|
478
|
+
}
|
|
479
|
+
catch (error) {
|
|
480
|
+
Logger.error('DataStore: Erro ao restaurar backup', error);
|
|
481
|
+
throw error;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚀 Instala interceptação automática em uma classe
|
|
3
|
+
*/
|
|
4
|
+
export declare function installDatabaseInterceptor(targetClass: unknown, className: string): void;
|
|
5
|
+
/**
|
|
6
|
+
* 🚀 Instala interceptação automática em múltiplas classes
|
|
7
|
+
*/
|
|
8
|
+
export declare function installDatabaseInterceptors(classes: {
|
|
9
|
+
class: unknown;
|
|
10
|
+
name: string;
|
|
11
|
+
}[]): void;
|
|
12
|
+
/**
|
|
13
|
+
* 📋 Lista interceptadores instalados
|
|
14
|
+
*/
|
|
15
|
+
export declare function getInstalledDatabaseInterceptors(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* 🧹 Remove todos os interceptadores
|
|
18
|
+
*/
|
|
19
|
+
export declare function clearDatabaseInterceptors(): void;
|