@semacode/cli 2.3.0 → 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/LICENSE +39 -39
- package/README.md +112 -41
- package/dist/agentContextPack.js +14 -10
- package/dist/agentEntryPoints.d.ts +5 -0
- package/dist/agentEntryPoints.js +102 -91
- package/dist/angular-consumer-standalone.d.ts +3 -1
- package/dist/angular-consumer-standalone.js +12 -8
- package/dist/bin.d.ts +6 -0
- package/dist/bin.js +130 -0
- package/dist/cliArgs.js +4 -4
- package/dist/cliControlError.d.ts +12 -0
- package/dist/cliControlError.js +47 -0
- package/dist/cliGrammar.d.ts +11 -0
- package/dist/cliGrammar.js +551 -0
- package/dist/cliHelp.d.ts +13 -0
- package/dist/cliHelp.js +19 -0
- package/dist/cliHelpTexto.d.ts +3 -0
- package/dist/cliHelpTexto.js +168 -0
- package/dist/cliRuntime.d.ts +2 -0
- package/dist/cliRuntime.js +31 -0
- package/dist/comandos.js +9 -22
- package/dist/contexto.js +5 -5
- package/dist/dev/index.d.ts +1 -0
- package/dist/dev/index.js +51 -9
- package/dist/discovery/catalog.js +3 -3
- package/dist/distribuicao/filesystemGlobal.d.ts +63 -0
- package/dist/distribuicao/filesystemGlobal.js +701 -0
- package/dist/distribuicao/index.d.ts +7 -0
- package/dist/distribuicao/index.js +227 -0
- package/dist/distribuicao/launcherGlobal.d.ts +53 -0
- package/dist/distribuicao/launcherGlobal.js +643 -0
- package/dist/distribuicao/launcherWindows.d.ts +28 -0
- package/dist/distribuicao/launcherWindows.js +326 -0
- package/dist/distribuicao/lockContextGlobal.d.ts +10 -0
- package/dist/distribuicao/lockContextGlobal.js +17 -0
- package/dist/distribuicao/lockGlobal.d.ts +6 -0
- package/dist/distribuicao/lockGlobal.js +520 -0
- package/dist/distribuicao/skillGlobal.d.ts +48 -0
- package/dist/distribuicao/skillGlobal.js +652 -0
- package/dist/distribuicao/skillIntentPolicy.d.ts +21 -0
- package/dist/distribuicao/skillIntentPolicy.js +115 -0
- package/dist/distribuicao/tipos.d.ts +50 -0
- package/dist/distribuicao/tipos.js +10 -0
- package/dist/distribuicao/versaoSemantica.d.ts +3 -0
- package/dist/distribuicao/versaoSemantica.js +62 -0
- package/dist/drift.part01.d.ts +34 -2
- package/dist/drift.part01.js +3 -0
- package/dist/drift.part04.d.ts +12 -2
- package/dist/drift.part04.js +89 -15
- package/dist/drift.part05.d.ts +2 -1
- package/dist/drift.part05.js +9 -6
- package/dist/drift.part06.d.ts +2 -1
- package/dist/drift.part06.js +115 -24
- package/dist/drift.part07.d.ts +11 -10
- package/dist/drift.part07.js +261 -255
- package/dist/drift.part08.d.ts +2 -1
- package/dist/drift.part08.js +35 -25
- package/dist/drift.part11.js +279 -32
- package/dist/drift.part12.d.ts +1 -1
- package/dist/drift.part12.js +196 -11
- package/dist/drift.part13.d.ts +18 -2
- package/dist/drift.part13.js +654 -76
- package/dist/drift.part14.js +21 -7
- package/dist/driftCacheCas.d.ts +43 -0
- package/dist/driftCacheCas.js +351 -0
- package/dist/driftCacheFilesystem.d.ts +64 -0
- package/dist/driftCacheFilesystem.js +313 -0
- package/dist/driftCacheModes.d.ts +38 -0
- package/dist/driftCacheModes.js +147 -0
- package/dist/driftCacheStore.d.ts +80 -0
- package/dist/driftCacheStore.js +603 -0
- package/dist/driftCatalogo.d.ts +65 -0
- package/dist/driftCatalogo.js +516 -0
- package/dist/driftEscopo.d.ts +21 -0
- package/dist/driftEscopo.js +647 -0
- package/dist/driftEscopoReferencias.d.ts +8 -0
- package/dist/driftEscopoReferencias.js +612 -0
- package/dist/driftOrcamento.d.ts +6 -0
- package/dist/driftOrcamento.js +20 -3
- package/dist/geracaoCore.js +4 -6
- package/dist/iaPrompts.d.ts +3 -3
- package/dist/iaPrompts.js +13 -14
- package/dist/index.d.ts +4 -1
- package/dist/index.js +6 -25
- package/dist/index.part01.d.ts +21 -14
- package/dist/index.part01.js +20 -165
- package/dist/index.part02.js +57 -43
- package/dist/index.part03.d.ts +23 -1
- package/dist/index.part03.js +83 -8
- package/dist/index.part04.d.ts +10 -2
- package/dist/index.part04.js +48 -14
- package/dist/index.part05.d.ts +1 -1
- package/dist/index.part05.js +109 -30
- package/dist/index.part06.js +34 -16
- package/dist/index.part07.js +31 -27
- package/dist/index.part08.d.ts +1 -1
- package/dist/index.part08.js +23 -28
- package/dist/init/templates.part01.js +393 -393
- package/dist/init/templates.part02.js +189 -189
- package/dist/initCommand.js +5 -1
- package/dist/initTemplatesBackend.js +73 -73
- package/dist/initTemplatesBase.js +7 -5
- package/dist/initTemplatesFlutter.js +137 -137
- package/dist/initTemplatesRuntime.js +350 -350
- package/dist/initTemplatesWeb.js +309 -309
- package/dist/pipelineConteudo/command.d.ts +1 -0
- package/dist/pipelineConteudo/command.js +4 -32
- package/dist/pipelineConteudo/help.d.ts +2 -0
- package/dist/pipelineConteudo/help.js +33 -0
- package/dist/profileAuthorCommand.js +3 -7
- package/dist/profileCommand.js +3 -7
- package/dist/projeto.d.ts +1 -1
- package/dist/projetoCarregar.d.ts +2 -2
- package/dist/projetoCarregar.js +69 -28
- package/dist/projetoCatalogo.d.ts +8 -0
- package/dist/projetoCatalogo.js +164 -0
- package/dist/projetoOrigens.d.ts +2 -0
- package/dist/projetoOrigens.js +65 -9
- package/dist/projetoTipos.d.ts +15 -5
- package/dist/resultadoCli.d.ts +20 -0
- package/dist/resultadoCli.js +57 -0
- package/dist/saidaCli.d.ts +35 -0
- package/dist/saidaCli.js +118 -0
- package/dist/sistemasInterativos/acceptanceEvidence.d.ts +22 -0
- package/dist/sistemasInterativos/acceptanceEvidence.js +345 -0
- package/dist/sistemasInterativos/engineObservation.d.ts +12 -0
- package/dist/sistemasInterativos/engineObservation.js +438 -0
- package/dist/sistemasInterativos/jobOrchestration.d.ts +2 -0
- package/dist/sistemasInterativos/jobOrchestration.js +204 -0
- package/dist/sistemasInterativos/operationPrimitives.d.ts +21 -0
- package/dist/sistemasInterativos/operationPrimitives.js +194 -0
- package/dist/sistemasInterativos/operations.d.ts +4 -39
- package/dist/sistemasInterativos/operations.js +5 -1164
- package/dist/skillCommand.d.ts +5 -0
- package/dist/skillCommand.js +88 -0
- package/dist/sync/index.js +35 -35
- package/docs/README.md +11 -7
- package/docs/ai-integration.md +18 -11
- package/docs/ai-onboarding.md +81 -62
- package/docs/ai-workflow.md +10 -4
- package/docs/auth.md +26 -26
- package/docs/cli.md +197 -79
- package/docs/commands.md +30 -6
- package/docs/database.md +15 -15
- package/docs/deploy.md +54 -41
- package/docs/documentation.md +11 -10
- package/docs/drift-cache.md +108 -0
- package/docs/env.md +16 -16
- package/docs/frontend.md +41 -41
- package/docs/getting-started.md +82 -57
- package/docs/i18n.md +15 -15
- package/docs/repositories.md +60 -43
- package/docs/rollback.md +38 -31
- package/docs/security.md +54 -32
- package/docs/sistemas-interativos.md +27 -27
- package/docs/support.md +8 -8
- package/docs/testing.md +123 -17
- package/docs/vocabulary.md +29 -29
- package/exemplos/agendamento.sema +1 -1
- package/exemplos/assinatura.sema +1 -1
- package/exemplos/auditoria.sema +1 -1
- package/exemplos/autenticacao.sema +1 -1
- package/exemplos/author_obra_comum.sema +1 -1
- package/exemplos/author_tema_sensivel.sema +1 -1
- package/exemplos/automacao.sema +1 -1
- package/exemplos/cadastro_usuario.sema +1 -1
- package/exemplos/calculadora.sema +1 -1
- package/exemplos/crud_simples.sema +1 -1
- package/exemplos/estoque.sema +1 -1
- package/exemplos/exportacao.sema +1 -1
- package/exemplos/fila.sema +1 -1
- package/exemplos/integracao_externa.sema +1 -1
- package/exemplos/multi_tenant.sema +1 -1
- package/exemplos/notificacao.sema +1 -1
- package/exemplos/operacao_estrategia.sema +132 -132
- package/exemplos/operacao_estrategia_discovery.sema +220 -220
- package/exemplos/operacao_estrategia_fluxo.sema +114 -114
- package/exemplos/operacao_estrategia_gates.sema +106 -106
- package/exemplos/operacao_estrategia_quarentena.sema +133 -133
- package/exemplos/operacao_estrategia_rollout.sema +124 -124
- package/exemplos/pagamento.sema +1 -1
- package/exemplos/pagamento_dominio.sema +1 -1
- package/exemplos/pedido.sema +1 -1
- package/exemplos/permissao.sema +1 -1
- package/exemplos/persistencia_vendor_first.sema +1 -1
- package/exemplos/profile_conversas.sema +165 -165
- package/exemplos/profile_game.sema +1 -1
- package/exemplos/profile_legal.sema +1 -1
- package/exemplos/profile_ops.sema +1 -1
- package/exemplos/profile_research.sema +1 -1
- package/exemplos/profile_software.sema +1 -1
- package/exemplos/profile_workflow_n8n.sema +1 -1
- package/exemplos/relatorio.sema +1 -1
- package/exemplos/replica_analitica_erp.sema +1 -1
- package/exemplos/testes_embutidos.sema +1 -1
- package/exemplos/tratamento_erro.sema +1 -1
- package/exemplos/upload_arquivo.sema +1 -1
- package/exemplos/webhook.sema +1 -1
- package/node_modules/@sema/gerador-cpp/dist/index.js +176 -176
- package/node_modules/@sema/gerador-css/dist/index.part01.js +10 -10
- package/node_modules/@sema/gerador-css/dist/index.part02.js +460 -460
- package/node_modules/@sema/gerador-dotnet/dist/index.js +169 -169
- package/node_modules/@sema/gerador-html/dist/index.js +17 -17
- package/node_modules/@sema/gerador-python/dist/index.part02.js +3 -3
- package/node_modules/@sema/gerador-typescript/dist/index.part02.js +11 -11
- package/node_modules/@sema/nucleo/dist/diagnosticos/melhorador.js +42 -42
- package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js +1 -0
- package/package.json +7 -2
- package/scripts/postinstall.mjs +148 -0
- package/skills/sema/SKILL.md +199 -0
- package/skills/sema/agents/openai.yaml +4 -0
- package/node_modules/@sema/gerador-cpp/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-css/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-css/dist/index.part01.js.map +0 -1
- package/node_modules/@sema/gerador-css/dist/index.part02.js.map +0 -1
- package/node_modules/@sema/gerador-dart/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-dotnet/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-html/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-javascript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-lua/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-php/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-python/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-python/dist/index.part01.js.map +0 -1
- package/node_modules/@sema/gerador-python/dist/index.part02.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/dist/index.part01.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/dist/index.part02.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/dist/index.part03.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/melhorador.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/snippets.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.part03.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.declaracoes.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.modulo.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.part03.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part03.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part04.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part05.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part06.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part07.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.part08.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.part01.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.part02.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/orcamentoSemantico.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +0 -1
- package/node_modules/@sema/padroes/dist/index.js.map +0 -1
package/dist/drift.part13.js
CHANGED
|
@@ -1,91 +1,669 @@
|
|
|
1
|
-
// SEMA-GOVERNED: sema.
|
|
2
|
-
//
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
// SEMA-GOVERNED: sema.produto.governanca_ia.drift, sema.produto.governanca_ia.drift.cache.store
|
|
2
|
+
// Descrição: planeja o escopo físico, cataloga uma vez e reutiliza extrações validadas sem escrever no workspace.
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import pacoteCli from "../package.json" with { type: "json" };
|
|
6
|
+
import { resolverDiretoriosIgnoradosAtivos, } from "./drift.part01.js";
|
|
7
|
+
import { EXTENSOES_ARQUIVOS_RASTREAVEIS_DRIFT, chaveCaminhoCanonicoDrift, } from "./drift.part04.js";
|
|
5
8
|
import { indexarTypeScript } from "./drift.part06.js";
|
|
6
|
-
import { indexarCpp, indexarDart, indexarDotnet, indexarGo, indexarJava, indexarLua, indexarPersistenciaDeclarativa, indexarPhp, indexarPython, indexarRust } from "./drift.part07.js";
|
|
9
|
+
import { indexarCpp, indexarDart, indexarDotnet, indexarGo, indexarJava, indexarLua, indexarPersistenciaDeclarativa, indexarPhp, indexarPython, indexarRust, } from "./drift.part07.js";
|
|
7
10
|
import { indexarPersistenciaDetalhada } from "./drift.part08.js";
|
|
8
|
-
import { construirMapaRecursos } from "./drift.part10.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
11
|
+
import { coletarVinculosIr, construirMapaRecursos } from "./drift.part10.js";
|
|
12
|
+
import { criarCatalogoDrift, } from "./driftCatalogo.js";
|
|
13
|
+
import { expandirDependenciasPlanoDrift, planejarEscopoDrift, } from "./driftEscopo.js";
|
|
14
|
+
import { criarStoreCacheDrift, digestJsonCanonicoCacheDrift, } from "./driftCacheStore.js";
|
|
15
|
+
const SCHEMA_PAYLOAD_INDICES_CACHE_DRIFT = "sema.drift-index-payload/v4";
|
|
16
|
+
const SCHEMA_IDENTIDADE_INDICES_CACHE_DRIFT = "sema.drift-index-identity/v3";
|
|
17
|
+
const SCHEMA_ESTADO_CACHE_DRIFT = "sema.drift-cache/v3";
|
|
18
|
+
const EXTRATOR_INDICES_CACHE_DRIFT = "drift-index-v4-2026-08-16";
|
|
19
|
+
const CHAVES_INDICES_CACHE_DRIFT = [
|
|
20
|
+
"indexTs", "indexPy", "indexDart", "indexDotnet", "indexJava", "indexGo",
|
|
21
|
+
"indexRust", "indexLua", "indexCpp", "indexPhp", "indexPersistencia",
|
|
22
|
+
];
|
|
23
|
+
const ORIGENS_SIMBOLO_POR_INDICE = {
|
|
24
|
+
indexTs: ["ts", "js"],
|
|
25
|
+
indexPy: ["py"],
|
|
26
|
+
indexDart: ["dart"],
|
|
27
|
+
indexDotnet: ["cs"],
|
|
28
|
+
indexJava: ["java"],
|
|
29
|
+
indexGo: ["go"],
|
|
30
|
+
indexRust: ["rust"],
|
|
31
|
+
indexLua: ["lua"],
|
|
32
|
+
indexCpp: ["cpp"],
|
|
33
|
+
indexPhp: ["php"],
|
|
34
|
+
indexPersistencia: ["sql"],
|
|
35
|
+
};
|
|
36
|
+
const EXTENSOES_POR_INDICE = {
|
|
37
|
+
indexTs: [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"],
|
|
38
|
+
indexPy: [".py"],
|
|
39
|
+
indexDart: [".dart"],
|
|
40
|
+
indexDotnet: [".cs"],
|
|
41
|
+
indexJava: [".java"],
|
|
42
|
+
indexGo: [".go"],
|
|
43
|
+
indexRust: [".rs"],
|
|
44
|
+
indexLua: [".lua"],
|
|
45
|
+
indexCpp: [".cpp", ".cc", ".cxx", ".hpp", ".h"],
|
|
46
|
+
indexPhp: [".php"],
|
|
47
|
+
indexPersistencia: [
|
|
48
|
+
".sql", ".psql", ".ddl", ".prisma", ".ts", ".tsx", ".js", ".jsx",
|
|
49
|
+
".mjs", ".cjs", ".py", ".dart", ".lua", ".cs", ".java", ".go",
|
|
50
|
+
".rs", ".cpp", ".cc", ".cxx", ".hpp", ".h", ".php",
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
const METRICAS_CATALOGO_VAZIO = {
|
|
54
|
+
diretoriosVisitados: 0,
|
|
55
|
+
arquivosCatalogados: 0,
|
|
56
|
+
leiturasConteudo: 0,
|
|
57
|
+
bytesLidos: 0,
|
|
58
|
+
acertosMemoriaConteudo: 0,
|
|
59
|
+
origem: "plano_explicito",
|
|
60
|
+
};
|
|
61
|
+
const LEITOR_VAZIO = {
|
|
62
|
+
contem: () => false,
|
|
63
|
+
lerTexto: async (caminho) => {
|
|
64
|
+
throw new Error(`Arquivo fora do plano explicito do drift: ${caminho}`);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
function estadoCacheInicial(modo, origem, avisos) {
|
|
68
|
+
return {
|
|
69
|
+
modo,
|
|
70
|
+
origem,
|
|
71
|
+
schema: SCHEMA_ESTADO_CACHE_DRIFT,
|
|
72
|
+
metricas: {
|
|
73
|
+
hits: 0,
|
|
74
|
+
misses: 0,
|
|
75
|
+
corruptos: 0,
|
|
76
|
+
gravacoes: 0,
|
|
77
|
+
errosGravacao: 0,
|
|
78
|
+
},
|
|
79
|
+
avisos,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function indicesVazios(planoEscopo, modoCache, avisosModoCache) {
|
|
83
|
+
return {
|
|
84
|
+
detalhesPersistencia: { colunas: [], repositorios: [] },
|
|
85
|
+
indexDart: { simbolos: [], rotas: [], recursos: [], consumerSurfaces: [] },
|
|
86
|
+
indexTs: { simbolos: [], rotas: [], recursos: [], consumerSurfaces: [] },
|
|
87
|
+
mapaImpl: new Map(),
|
|
88
|
+
mapaRecursos: new Map(),
|
|
89
|
+
todasRotasIndexadas: [],
|
|
90
|
+
todosArquivosConhecidos: [],
|
|
91
|
+
todosRecursos: [],
|
|
92
|
+
todosSimbolos: [],
|
|
93
|
+
planoEscopo,
|
|
94
|
+
cache: estadoCacheInicial(modoCache, "nao_aplicavel", avisosModoCache),
|
|
95
|
+
catalogo: { ...METRICAS_CATALOGO_VAZIO },
|
|
96
|
+
leitorArquivosPlanejados: LEITOR_VAZIO,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function coletarArquivosFisicosDeclarados(contexto) {
|
|
100
|
+
const arquivos = new Set();
|
|
101
|
+
for (const modulo of contexto.modulosSelecionados) {
|
|
102
|
+
const ir = modulo.resultado.ir;
|
|
103
|
+
if (!ir) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
for (const { vinculo } of coletarVinculosIr(ir)) {
|
|
107
|
+
const arquivo = vinculo.arquivo ?? (vinculo.tipo === "arquivo" ? vinculo.valor : undefined);
|
|
108
|
+
if (arquivo) {
|
|
109
|
+
arquivos.add(arquivo);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return [...arquivos].sort((a, b) => a.localeCompare(b, "pt-BR"));
|
|
114
|
+
}
|
|
115
|
+
function caminhoContidoCache(baseProjeto, arquivo) {
|
|
116
|
+
const relativo = path.relative(path.resolve(baseProjeto), path.resolve(arquivo));
|
|
117
|
+
return relativo === "" || (relativo !== ".."
|
|
118
|
+
&& !relativo.startsWith(`..${path.sep}`)
|
|
119
|
+
&& !path.isAbsolute(relativo));
|
|
120
|
+
}
|
|
121
|
+
function resolverArquivoCache(baseProjeto, arquivo) {
|
|
122
|
+
if (!path.isAbsolute(arquivo) && arquivo.includes(":")) {
|
|
123
|
+
throw new Error("cache_indice_arquivo_fora_workspace");
|
|
124
|
+
}
|
|
125
|
+
const absoluto = path.isAbsolute(arquivo)
|
|
126
|
+
? path.resolve(arquivo)
|
|
127
|
+
: path.resolve(baseProjeto, arquivo);
|
|
128
|
+
if (!caminhoContidoCache(baseProjeto, absoluto)) {
|
|
129
|
+
throw new Error("cache_indice_arquivo_fora_workspace");
|
|
130
|
+
}
|
|
131
|
+
return absoluto;
|
|
132
|
+
}
|
|
133
|
+
function caminhoRelativoSeguroCache(baseProjeto, arquivo) {
|
|
134
|
+
const relativo = path.relative(path.resolve(baseProjeto), resolverArquivoCache(baseProjeto, arquivo)).replace(/\\/g, "/");
|
|
135
|
+
if (!caminhoRelativoValidoCache(relativo)) {
|
|
136
|
+
throw new Error("cache_indice_arquivo_fora_workspace");
|
|
137
|
+
}
|
|
138
|
+
return relativo;
|
|
139
|
+
}
|
|
140
|
+
function caminhoRelativoValidoCache(valor) {
|
|
141
|
+
return typeof valor === "string"
|
|
142
|
+
&& valor.length > 0
|
|
143
|
+
&& valor !== "."
|
|
144
|
+
&& valor !== ".."
|
|
145
|
+
&& !valor.startsWith("../")
|
|
146
|
+
&& !valor.includes("\\")
|
|
147
|
+
&& !valor.includes(":")
|
|
148
|
+
&& !valor.includes("\0")
|
|
149
|
+
&& !path.posix.isAbsolute(valor)
|
|
150
|
+
&& valor.split("/").every((segmento) => segmento.length > 0 && segmento !== "." && segmento !== "..");
|
|
151
|
+
}
|
|
152
|
+
function resolverCaminhoRelativoCache(baseProjeto, relativo) {
|
|
153
|
+
if (!caminhoRelativoValidoCache(relativo)) {
|
|
154
|
+
throw new Error("cache_indice_arquivo_fora_workspace");
|
|
155
|
+
}
|
|
156
|
+
const absoluto = path.resolve(baseProjeto, ...relativo.split("/"));
|
|
157
|
+
if (!caminhoContidoCache(baseProjeto, absoluto)) {
|
|
158
|
+
throw new Error("cache_indice_arquivo_fora_workspace");
|
|
159
|
+
}
|
|
160
|
+
return absoluto;
|
|
161
|
+
}
|
|
162
|
+
function registroJson(valor) {
|
|
163
|
+
return typeof valor === "object" && valor !== null && !Array.isArray(valor);
|
|
164
|
+
}
|
|
165
|
+
function textoNaoVazio(valor) {
|
|
166
|
+
return typeof valor === "string" && valor.length > 0;
|
|
167
|
+
}
|
|
168
|
+
function normalizarJsonCache(valor) {
|
|
169
|
+
return JSON.parse(JSON.stringify(valor));
|
|
170
|
+
}
|
|
171
|
+
function serializarSimboloCache(baseProjeto, registro) {
|
|
172
|
+
return {
|
|
173
|
+
origem: registro.origem,
|
|
174
|
+
caminho: registro.caminho,
|
|
175
|
+
arquivo: caminhoRelativoSeguroCache(baseProjeto, registro.arquivo),
|
|
176
|
+
simbolo: registro.simbolo,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function serializarRotaCache(baseProjeto, registro) {
|
|
180
|
+
return {
|
|
181
|
+
origem: registro.origem,
|
|
182
|
+
metodo: registro.metodo,
|
|
183
|
+
caminho: registro.caminho,
|
|
184
|
+
arquivo: caminhoRelativoSeguroCache(baseProjeto, registro.arquivo),
|
|
185
|
+
simbolo: registro.simbolo,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function serializarRecursoCache(baseProjeto, registro) {
|
|
189
|
+
const serializado = {
|
|
190
|
+
origem: registro.origem,
|
|
191
|
+
nome: registro.nome,
|
|
192
|
+
arquivo: caminhoRelativoSeguroCache(baseProjeto, registro.arquivo),
|
|
193
|
+
tipo: registro.tipo,
|
|
194
|
+
};
|
|
195
|
+
if (registro.simbolo !== undefined) {
|
|
196
|
+
serializado.simbolo = registro.simbolo;
|
|
197
|
+
}
|
|
198
|
+
return serializado;
|
|
199
|
+
}
|
|
200
|
+
function serializarConsumerSurfaceCache(baseProjeto, registro) {
|
|
201
|
+
return {
|
|
202
|
+
rota: registro.rota,
|
|
203
|
+
arquivo: caminhoRelativoSeguroCache(baseProjeto, registro.arquivo),
|
|
204
|
+
tipoArquivo: registro.tipoArquivo,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function serializarColunaPersistenciaCache(baseProjeto, registro) {
|
|
208
|
+
return {
|
|
209
|
+
origem: registro.origem,
|
|
210
|
+
categoriaPersistencia: registro.categoriaPersistencia,
|
|
211
|
+
recurso: registro.recurso,
|
|
212
|
+
coluna: registro.coluna,
|
|
213
|
+
arquivo: caminhoRelativoSeguroCache(baseProjeto, registro.arquivo),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function serializarRepositorioPersistenciaCache(baseProjeto, registro) {
|
|
217
|
+
return {
|
|
218
|
+
origem: registro.origem,
|
|
219
|
+
categoriaPersistencia: registro.categoriaPersistencia,
|
|
220
|
+
recurso: registro.recurso,
|
|
221
|
+
arquivo: caminhoRelativoSeguroCache(baseProjeto, registro.arquivo),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function serializarIndiceCache(baseProjeto, indice) {
|
|
225
|
+
return {
|
|
226
|
+
simbolos: indice.simbolos.map((item) => serializarSimboloCache(baseProjeto, item)),
|
|
227
|
+
rotas: indice.rotas.map((item) => serializarRotaCache(baseProjeto, item)),
|
|
228
|
+
recursos: indice.recursos.map((item) => serializarRecursoCache(baseProjeto, item)),
|
|
229
|
+
consumerSurfaces: indice.consumerSurfaces
|
|
230
|
+
.map((item) => serializarConsumerSurfaceCache(baseProjeto, item)),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function derivarIntegridadePayloadCache(indices, detalhesPersistencia) {
|
|
234
|
+
const agregar = (campo) => CHAVES_INDICES_CACHE_DRIFT
|
|
235
|
+
.flatMap((chave) => {
|
|
236
|
+
const indice = indices[chave];
|
|
237
|
+
return indice[campo];
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
simbolosDigest: digestJsonCanonicoCacheDrift(agregar("simbolos")),
|
|
241
|
+
rotasDigest: digestJsonCanonicoCacheDrift(agregar("rotas")),
|
|
242
|
+
recursosDigest: digestJsonCanonicoCacheDrift(agregar("recursos")),
|
|
243
|
+
consumerSurfacesDigest: digestJsonCanonicoCacheDrift(agregar("consumerSurfaces")),
|
|
244
|
+
persistenciaDigest: digestJsonCanonicoCacheDrift(detalhesPersistencia),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function serializarIndicesCache(baseProjeto, extracoes) {
|
|
248
|
+
const indices = Object.fromEntries(CHAVES_INDICES_CACHE_DRIFT.map((chave) => [
|
|
249
|
+
chave,
|
|
250
|
+
serializarIndiceCache(baseProjeto, extracoes.indices[chave]),
|
|
251
|
+
]));
|
|
252
|
+
const detalhesPersistencia = {
|
|
253
|
+
colunas: extracoes.detalhesPersistencia.colunas
|
|
254
|
+
.map((item) => serializarColunaPersistenciaCache(baseProjeto, item)),
|
|
255
|
+
repositorios: extracoes.detalhesPersistencia.repositorios
|
|
256
|
+
.map((item) => serializarRepositorioPersistenciaCache(baseProjeto, item)),
|
|
257
|
+
};
|
|
258
|
+
return normalizarJsonCache({
|
|
259
|
+
schema: SCHEMA_PAYLOAD_INDICES_CACHE_DRIFT,
|
|
260
|
+
detalhesPersistencia,
|
|
261
|
+
indices,
|
|
262
|
+
integridadeDerivada: derivarIntegridadePayloadCache(indices, detalhesPersistencia),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function possuiCamposExatos(valor, obrigatorios, opcionais = []) {
|
|
266
|
+
const permitidos = new Set([...obrigatorios, ...opcionais]);
|
|
267
|
+
return obrigatorios.every((campo) => Object.prototype.hasOwnProperty.call(valor, campo))
|
|
268
|
+
&& Object.keys(valor).every((campo) => permitidos.has(campo));
|
|
269
|
+
}
|
|
270
|
+
function validarRegistroArquivoCache(valor, camposTexto, camposOpcionais = []) {
|
|
271
|
+
return registroJson(valor)
|
|
272
|
+
&& possuiCamposExatos(valor, ["arquivo", ...camposTexto], camposOpcionais)
|
|
273
|
+
&& caminhoRelativoValidoCache(valor.arquivo)
|
|
274
|
+
&& camposTexto.every((campo) => textoNaoVazio(valor[campo]))
|
|
275
|
+
&& camposOpcionais.every((campo) => valor[campo] === undefined || textoNaoVazio(valor[campo]));
|
|
276
|
+
}
|
|
277
|
+
function validarListaRegistrosCache(valor, camposTexto, camposOpcionais = []) {
|
|
278
|
+
return Array.isArray(valor)
|
|
279
|
+
&& valor.every((item) => validarRegistroArquivoCache(item, camposTexto, camposOpcionais));
|
|
280
|
+
}
|
|
281
|
+
function arquivoCompativelComIndiceCache(chave, arquivo) {
|
|
282
|
+
const extensao = path.posix.extname(arquivo).toLowerCase();
|
|
283
|
+
return EXTENSOES_POR_INDICE[chave].includes(extensao);
|
|
284
|
+
}
|
|
285
|
+
function validarIndiceLinguagemCache(valor, chave) {
|
|
286
|
+
if (!(registroJson(valor)
|
|
287
|
+
&& possuiCamposExatos(valor, ["simbolos", "rotas", "recursos", "consumerSurfaces"])
|
|
288
|
+
&& validarListaRegistrosCache(valor.simbolos, ["origem", "caminho", "simbolo"])
|
|
289
|
+
&& validarListaRegistrosCache(valor.rotas, ["origem", "metodo", "caminho", "simbolo"])
|
|
290
|
+
&& validarListaRegistrosCache(valor.recursos, ["origem", "nome", "tipo"], ["simbolo"])
|
|
291
|
+
&& validarListaRegistrosCache(valor.consumerSurfaces, ["rota", "tipoArquivo"]))) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
const registros = [valor.simbolos, valor.rotas, valor.recursos, valor.consumerSurfaces]
|
|
295
|
+
.flat();
|
|
296
|
+
if (!registros.every((item) => arquivoCompativelComIndiceCache(chave, item.arquivo)))
|
|
297
|
+
return false;
|
|
298
|
+
if (!valor.simbolos
|
|
299
|
+
.every((item) => ORIGENS_SIMBOLO_POR_INDICE[chave].includes(item.origem)))
|
|
300
|
+
return false;
|
|
301
|
+
if (["indexLua", "indexCpp", "indexPersistencia"].includes(chave)
|
|
302
|
+
&& (valor.rotas.length > 0 || valor.consumerSurfaces.length > 0))
|
|
303
|
+
return false;
|
|
304
|
+
if (!["indexTs", "indexDart"].includes(chave) && valor.consumerSurfaces.length > 0)
|
|
305
|
+
return false;
|
|
306
|
+
const caminhosRotas = new Set(valor.rotas
|
|
307
|
+
.map((rota) => rota.caminho));
|
|
308
|
+
return valor.consumerSurfaces
|
|
309
|
+
.every((surface) => caminhosRotas.has(surface.rota));
|
|
310
|
+
}
|
|
311
|
+
function validarPayloadIndicesCache(valor) {
|
|
312
|
+
if (!registroJson(valor)
|
|
313
|
+
|| !possuiCamposExatos(valor, [
|
|
314
|
+
"schema",
|
|
315
|
+
"detalhesPersistencia",
|
|
316
|
+
"indices",
|
|
317
|
+
"integridadeDerivada",
|
|
318
|
+
])
|
|
319
|
+
|| valor.schema !== SCHEMA_PAYLOAD_INDICES_CACHE_DRIFT
|
|
320
|
+
|| !registroJson(valor.detalhesPersistencia)
|
|
321
|
+
|| !possuiCamposExatos(valor.detalhesPersistencia, ["colunas", "repositorios"])
|
|
322
|
+
|| !registroJson(valor.indices)
|
|
323
|
+
|| !possuiCamposExatos(valor.indices, CHAVES_INDICES_CACHE_DRIFT)
|
|
324
|
+
|| !CHAVES_INDICES_CACHE_DRIFT.every((chave) => validarIndiceLinguagemCache(valor.indices[chave], chave))
|
|
325
|
+
|| !registroJson(valor.integridadeDerivada)
|
|
326
|
+
|| !possuiCamposExatos(valor.integridadeDerivada, [
|
|
327
|
+
"simbolosDigest",
|
|
328
|
+
"rotasDigest",
|
|
329
|
+
"recursosDigest",
|
|
330
|
+
"consumerSurfacesDigest",
|
|
331
|
+
"persistenciaDigest",
|
|
332
|
+
])) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
const estruturaValida = validarListaRegistrosCache(valor.detalhesPersistencia.colunas, ["origem", "categoriaPersistencia", "recurso", "coluna"]) && validarListaRegistrosCache(valor.detalhesPersistencia.repositorios, ["origem", "categoriaPersistencia", "recurso"]);
|
|
336
|
+
if (!estruturaValida)
|
|
337
|
+
return false;
|
|
338
|
+
const integridadeEsperada = derivarIntegridadePayloadCache(valor.indices, valor.detalhesPersistencia);
|
|
339
|
+
return Object.entries(integridadeEsperada).every(([campo, esperado]) => (valor.integridadeDerivada[campo] === esperado));
|
|
340
|
+
}
|
|
341
|
+
function restaurarRegistroArquivoCache(baseProjeto, catalogo, registro) {
|
|
342
|
+
const arquivo = resolverCaminhoRelativoCache(baseProjeto, registro.arquivo);
|
|
343
|
+
if (!catalogo.contem(arquivo)) {
|
|
344
|
+
throw new Error("cache_indice_arquivo_fora_catalogo");
|
|
345
|
+
}
|
|
346
|
+
return { ...registro, arquivo };
|
|
347
|
+
}
|
|
348
|
+
function restaurarIndicesCache(baseProjeto, catalogo, payload) {
|
|
349
|
+
if (!validarPayloadIndicesCache(payload))
|
|
350
|
+
return null;
|
|
351
|
+
const restaurar = (valor) => valor.map((item) => restaurarRegistroArquivoCache(baseProjeto, catalogo, item));
|
|
352
|
+
try {
|
|
353
|
+
const detalhes = payload.detalhesPersistencia;
|
|
354
|
+
const indicesPayload = payload.indices;
|
|
355
|
+
const indices = Object.fromEntries(CHAVES_INDICES_CACHE_DRIFT.map((chave) => {
|
|
356
|
+
const indice = indicesPayload[chave];
|
|
357
|
+
return [chave, {
|
|
358
|
+
simbolos: restaurar(indice.simbolos),
|
|
359
|
+
rotas: restaurar(indice.rotas),
|
|
360
|
+
recursos: restaurar(indice.recursos),
|
|
361
|
+
consumerSurfaces: restaurar(indice.consumerSurfaces),
|
|
362
|
+
}];
|
|
363
|
+
}));
|
|
364
|
+
return derivarIndicesExtraidos({
|
|
365
|
+
detalhesPersistencia: {
|
|
366
|
+
colunas: restaurar(detalhes.colunas),
|
|
367
|
+
repositorios: restaurar(detalhes.repositorios),
|
|
368
|
+
},
|
|
369
|
+
indices,
|
|
370
|
+
}, catalogo);
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function criarMapaImplDrift(todosSimbolos, arquivosPrioritarios) {
|
|
377
|
+
const prioritarios = new Set(arquivosPrioritarios.map(chaveCaminhoCanonicoDrift));
|
|
378
|
+
const mapaImpl = new Map();
|
|
379
|
+
for (const simbolo of todosSimbolos.filter((item) => item.origem !== "sql")) {
|
|
380
|
+
const existente = mapaImpl.get(simbolo.caminho);
|
|
381
|
+
if (!existente) {
|
|
382
|
+
mapaImpl.set(simbolo.caminho, simbolo);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
const prioridadeExistente = prioritarios.has(chaveCaminhoCanonicoDrift(existente.arquivo));
|
|
386
|
+
const prioridadeNova = prioritarios.has(chaveCaminhoCanonicoDrift(simbolo.arquivo));
|
|
387
|
+
if ((prioridadeNova && !prioridadeExistente)
|
|
388
|
+
|| (prioridadeNova === prioridadeExistente
|
|
389
|
+
&& simbolo.arquivo.localeCompare(existente.arquivo, "pt-BR") < 0)) {
|
|
390
|
+
mapaImpl.set(simbolo.caminho, simbolo);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return mapaImpl;
|
|
394
|
+
}
|
|
395
|
+
function montarIndicesPreparados(extraidos, arquivosPrioritarios, planoEscopo, cache, catalogo) {
|
|
396
|
+
return {
|
|
397
|
+
...extraidos,
|
|
398
|
+
mapaImpl: criarMapaImplDrift(extraidos.todosSimbolos, arquivosPrioritarios),
|
|
399
|
+
mapaRecursos: construirMapaRecursos(extraidos.todosRecursos),
|
|
400
|
+
planoEscopo,
|
|
401
|
+
cache,
|
|
402
|
+
catalogo: catalogo.metricas(),
|
|
403
|
+
leitorArquivosPlanejados: catalogo,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function derivarIndicesExtraidos(extracoes, catalogo) {
|
|
407
|
+
const agregar = (campo) => CHAVES_INDICES_CACHE_DRIFT
|
|
408
|
+
.flatMap((chave) => extracoes.indices[chave][campo]);
|
|
409
|
+
const todosSimbolos = agregar("simbolos");
|
|
410
|
+
const todasRotasIndexadas = agregar("rotas");
|
|
411
|
+
const todosRecursos = agregar("recursos");
|
|
73
412
|
const todosArquivosConhecidos = [...new Set([
|
|
74
|
-
...
|
|
413
|
+
...catalogo.arquivosCatalogados(),
|
|
75
414
|
...todosSimbolos.map((item) => item.arquivo),
|
|
76
415
|
...todasRotasIndexadas.map((item) => item.arquivo),
|
|
77
416
|
...todosRecursos.map((item) => item.arquivo),
|
|
78
417
|
])].sort((a, b) => a.localeCompare(b, "pt-BR"));
|
|
79
418
|
return {
|
|
80
|
-
detalhesPersistencia,
|
|
81
|
-
indexDart,
|
|
82
|
-
indexTs,
|
|
83
|
-
mapaImpl,
|
|
84
|
-
mapaRecursos,
|
|
419
|
+
detalhesPersistencia: extracoes.detalhesPersistencia,
|
|
420
|
+
indexDart: extracoes.indices.indexDart,
|
|
421
|
+
indexTs: extracoes.indices.indexTs,
|
|
85
422
|
todasRotasIndexadas,
|
|
86
423
|
todosArquivosConhecidos,
|
|
87
424
|
todosRecursos,
|
|
88
425
|
todosSimbolos,
|
|
89
426
|
};
|
|
90
427
|
}
|
|
428
|
+
async function calcularIndices(diretorios, catalogo) {
|
|
429
|
+
const [indexTs, indexPy, indexDart, indexDotnet, indexJava, indexGo, indexRust, indexLua, indexPhp, indexPersistencia, detalhesPersistencia, indexCpp,] = await Promise.all([
|
|
430
|
+
indexarTypeScript(diretorios, catalogo),
|
|
431
|
+
indexarPython(diretorios, catalogo),
|
|
432
|
+
indexarDart(diretorios, catalogo),
|
|
433
|
+
indexarDotnet(diretorios, catalogo),
|
|
434
|
+
indexarJava(diretorios, catalogo),
|
|
435
|
+
indexarGo(diretorios, catalogo),
|
|
436
|
+
indexarRust(diretorios, catalogo),
|
|
437
|
+
indexarLua(diretorios, catalogo),
|
|
438
|
+
indexarPhp(diretorios, catalogo),
|
|
439
|
+
indexarPersistenciaDeclarativa(diretorios, catalogo),
|
|
440
|
+
indexarPersistenciaDetalhada(diretorios, catalogo),
|
|
441
|
+
indexarCpp(diretorios, catalogo),
|
|
442
|
+
]);
|
|
443
|
+
const extracoes = {
|
|
444
|
+
detalhesPersistencia,
|
|
445
|
+
indices: {
|
|
446
|
+
indexTs,
|
|
447
|
+
indexPy: { ...indexPy, consumerSurfaces: [] },
|
|
448
|
+
indexDart,
|
|
449
|
+
indexDotnet: { ...indexDotnet, consumerSurfaces: [] },
|
|
450
|
+
indexJava: { ...indexJava, consumerSurfaces: [] },
|
|
451
|
+
indexGo: { ...indexGo, consumerSurfaces: [] },
|
|
452
|
+
indexRust: { ...indexRust, consumerSurfaces: [] },
|
|
453
|
+
indexLua: { ...indexLua, rotas: [], consumerSurfaces: [] },
|
|
454
|
+
indexCpp: { ...indexCpp, rotas: [], consumerSurfaces: [] },
|
|
455
|
+
indexPhp: { ...indexPhp, consumerSurfaces: [] },
|
|
456
|
+
indexPersistencia: { ...indexPersistencia, rotas: [], consumerSurfaces: [] },
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
return [extracoes, derivarIndicesExtraidos(extracoes, catalogo)];
|
|
460
|
+
}
|
|
461
|
+
function relativoIdentidade(baseProjeto, alvo) {
|
|
462
|
+
const absoluto = resolverArquivoCache(baseProjeto, alvo);
|
|
463
|
+
const relativo = path.relative(path.resolve(baseProjeto), absoluto).replace(/\\/g, "/");
|
|
464
|
+
if (relativo === "")
|
|
465
|
+
return ".";
|
|
466
|
+
if (relativo === ".."
|
|
467
|
+
|| relativo.startsWith("../")
|
|
468
|
+
|| relativo.includes(":")
|
|
469
|
+
|| relativo.includes("\0")
|
|
470
|
+
|| path.posix.isAbsolute(relativo)) {
|
|
471
|
+
throw new Error("cache_identidade_fora_workspace");
|
|
472
|
+
}
|
|
473
|
+
return relativo;
|
|
474
|
+
}
|
|
475
|
+
function digestValorCache(valor) {
|
|
476
|
+
return digestJsonCanonicoCacheDrift(normalizarJsonCache(valor));
|
|
477
|
+
}
|
|
478
|
+
function representarPlanoCache(contexto, configuracao, plano) {
|
|
479
|
+
const relativo = (alvo) => relativoIdentidade(contexto.baseProjeto, alvo);
|
|
480
|
+
const ordenar = (itens) => [...new Set(itens.map(relativo))]
|
|
481
|
+
.sort((a, b) => a.localeCompare(b, "pt-BR"));
|
|
482
|
+
const dependencias = Object.entries(plano.dependencias)
|
|
483
|
+
.map(([arquivo, destinos]) => [
|
|
484
|
+
relativo(arquivo),
|
|
485
|
+
ordenar(destinos),
|
|
486
|
+
])
|
|
487
|
+
.sort(([a], [b]) => a.localeCompare(b, "pt-BR"));
|
|
488
|
+
return normalizarJsonCache({
|
|
489
|
+
escopo: configuracao.escopo,
|
|
490
|
+
estrategia: plano.estrategia,
|
|
491
|
+
cobertura: plano.cobertura,
|
|
492
|
+
termos: [...configuracao.termosEscopo].sort((a, b) => a.localeCompare(b, "pt-BR")),
|
|
493
|
+
modulos: [...plano.modulos].sort((a, b) => a.localeCompare(b, "pt-BR")),
|
|
494
|
+
arquivos: ordenar(plano.arquivos),
|
|
495
|
+
arquivosDeclarados: ordenar(plano.arquivosDeclarados),
|
|
496
|
+
arquivosInferidos: ordenar(plano.arquivosInferidos),
|
|
497
|
+
arquivosAusentes: ordenar(plano.arquivosAusentes),
|
|
498
|
+
diretorios: ordenar(plano.diretorios),
|
|
499
|
+
diretoriosCodigo: ordenar(contexto.diretoriosCodigo),
|
|
500
|
+
ignorarWorktrees: configuracao.ignorarWorktrees,
|
|
501
|
+
ignorarConsumidoresLaterais: configuracao.ignorarConsumidoresLaterais,
|
|
502
|
+
dependencias,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
async function criarChaveIndicesCache(contexto, configuracao, plano, catalogo, store, arquivosExplicitos) {
|
|
506
|
+
const candidatos = new Map();
|
|
507
|
+
const adicionarCandidato = (arquivo) => {
|
|
508
|
+
const absoluto = resolverArquivoCache(contexto.baseProjeto, arquivo);
|
|
509
|
+
candidatos.set(chaveCaminhoCanonicoDrift(absoluto), absoluto);
|
|
510
|
+
};
|
|
511
|
+
for (const entrada of catalogo.listarEntradas().filter((item) => configuracao.escopo === "projeto" || item.explicito)) {
|
|
512
|
+
adicionarCandidato(entrada.caminho);
|
|
513
|
+
}
|
|
514
|
+
for (const arquivo of [
|
|
515
|
+
...arquivosExplicitos,
|
|
516
|
+
...plano.arquivos,
|
|
517
|
+
...plano.arquivosDeclarados,
|
|
518
|
+
...plano.arquivosInferidos,
|
|
519
|
+
...plano.arquivosAusentes,
|
|
520
|
+
]) {
|
|
521
|
+
adicionarCandidato(arquivo);
|
|
522
|
+
}
|
|
523
|
+
const membros = await Promise.all([...candidatos.values()].map(async (arquivo) => {
|
|
524
|
+
const relativo = caminhoRelativoSeguroCache(contexto.baseProjeto, arquivo);
|
|
525
|
+
if (!catalogo.contem(arquivo)) {
|
|
526
|
+
return { arquivo: relativo, estado: "ausente" };
|
|
527
|
+
}
|
|
528
|
+
return {
|
|
529
|
+
arquivo: relativo,
|
|
530
|
+
estado: "presente",
|
|
531
|
+
digest: await catalogo.digest(arquivo),
|
|
532
|
+
};
|
|
533
|
+
}));
|
|
534
|
+
membros.sort((a, b) => a.arquivo.localeCompare(b.arquivo, "pt-BR"));
|
|
535
|
+
const contratos = contexto.modulosSelecionados
|
|
536
|
+
.map((modulo) => ({
|
|
537
|
+
arquivo: caminhoRelativoSeguroCache(contexto.baseProjeto, modulo.caminho),
|
|
538
|
+
modulo: modulo.resultado.ir ?? null,
|
|
539
|
+
diagnosticos: modulo.resultado.diagnosticos,
|
|
540
|
+
}))
|
|
541
|
+
.sort((a, b) => a.arquivo.localeCompare(b.arquivo, "pt-BR"));
|
|
542
|
+
return digestJsonCanonicoCacheDrift({
|
|
543
|
+
schema: SCHEMA_IDENTIDADE_INDICES_CACHE_DRIFT,
|
|
544
|
+
cliVersion: pacoteCli.version,
|
|
545
|
+
typescriptVersion: ts.version,
|
|
546
|
+
extrator: EXTRATOR_INDICES_CACHE_DRIFT,
|
|
547
|
+
workspaceId: store.workspaceId,
|
|
548
|
+
gitHead: store.gitHead,
|
|
549
|
+
planoDigest: digestValorCache(representarPlanoCache(contexto, configuracao, plano)),
|
|
550
|
+
contratosDigest: digestValorCache(contratos),
|
|
551
|
+
configuracaoDigest: digestValorCache(contexto.configCarregada?.config ?? null),
|
|
552
|
+
membros,
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
function adaptarEventoStoreCache(observador) {
|
|
556
|
+
if (!observador)
|
|
557
|
+
return undefined;
|
|
558
|
+
return (evento) => {
|
|
559
|
+
const tipo = evento.tipo === "cache.read.hit"
|
|
560
|
+
? "cache.hit"
|
|
561
|
+
: evento.tipo === "cache.read.miss"
|
|
562
|
+
? "cache.miss"
|
|
563
|
+
: evento.tipo === "cache.read.corrupt"
|
|
564
|
+
? "cache.corrupt"
|
|
565
|
+
: evento.tipo === "cache.write.published" || evento.tipo === "cache.write.reused"
|
|
566
|
+
? "cache.write"
|
|
567
|
+
: evento.tipo === "cache.store.unavailable" || evento.tipo === "cache.write.error"
|
|
568
|
+
? "cache.unavailable"
|
|
569
|
+
: null;
|
|
570
|
+
if (!tipo)
|
|
571
|
+
return;
|
|
572
|
+
try {
|
|
573
|
+
observador({
|
|
574
|
+
tipo,
|
|
575
|
+
...(evento.caminhoVirtual ? { caminho: evento.caminhoVirtual } : {}),
|
|
576
|
+
...(evento.chave ? { chave: evento.chave } : {}),
|
|
577
|
+
...(evento.codigo ? { motivo: evento.codigo } : {}),
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
catch {
|
|
581
|
+
// Observabilidade não altera o resultado funcional do drift.
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
function estadoCacheDoStore(modo, origem, avisos, store) {
|
|
586
|
+
const metricas = store.metricas();
|
|
587
|
+
return {
|
|
588
|
+
modo,
|
|
589
|
+
origem,
|
|
590
|
+
schema: SCHEMA_ESTADO_CACHE_DRIFT,
|
|
591
|
+
...(store.workspaceId ? { workspaceId: store.workspaceId } : {}),
|
|
592
|
+
metricas: {
|
|
593
|
+
hits: metricas.hits,
|
|
594
|
+
misses: metricas.misses,
|
|
595
|
+
corruptos: metricas.corruptos,
|
|
596
|
+
gravacoes: metricas.publicacoes,
|
|
597
|
+
errosGravacao: metricas.erros,
|
|
598
|
+
},
|
|
599
|
+
avisos,
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
async function resolverIndicesComCache(contexto, configuracaoEscopo, planoEscopo, catalogo, arquivosPrioritarios, arquivosExplicitos, modoCache, avisosModoCache, observador) {
|
|
603
|
+
const store = await criarStoreCacheDrift({
|
|
604
|
+
baseProjeto: contexto.baseProjeto,
|
|
605
|
+
observador: adaptarEventoStoreCache(observador),
|
|
606
|
+
});
|
|
607
|
+
if (!store.disponivel) {
|
|
608
|
+
const [, extraidos] = await calcularIndices(planoEscopo.diretorios, catalogo);
|
|
609
|
+
return montarIndicesPreparados(extraidos, arquivosPrioritarios, planoEscopo, estadoCacheDoStore(modoCache, "indisponivel", avisosModoCache, store), catalogo);
|
|
610
|
+
}
|
|
611
|
+
let chave;
|
|
612
|
+
try {
|
|
613
|
+
chave = await criarChaveIndicesCache(contexto, configuracaoEscopo, planoEscopo, catalogo, store, arquivosExplicitos);
|
|
614
|
+
}
|
|
615
|
+
catch {
|
|
616
|
+
const [, extraidos] = await calcularIndices(planoEscopo.diretorios, catalogo);
|
|
617
|
+
return montarIndicesPreparados(extraidos, arquivosPrioritarios, planoEscopo, estadoCacheDoStore(modoCache, "indisponivel", avisosModoCache, store), catalogo);
|
|
618
|
+
}
|
|
619
|
+
const validarPayloadAplicavel = (valor) => {
|
|
620
|
+
if (!validarPayloadIndicesCache(valor))
|
|
621
|
+
return false;
|
|
622
|
+
return restaurarIndicesCache(contexto.baseProjeto, catalogo, valor) !== null;
|
|
623
|
+
};
|
|
624
|
+
if (modoCache === "cache") {
|
|
625
|
+
const leitura = await store.ler(chave, validarPayloadAplicavel);
|
|
626
|
+
if (leitura.estado === "hit") {
|
|
627
|
+
const restaurados = restaurarIndicesCache(contexto.baseProjeto, catalogo, leitura.valor);
|
|
628
|
+
if (restaurados) {
|
|
629
|
+
return montarIndicesPreparados(restaurados, arquivosPrioritarios, planoEscopo, estadoCacheDoStore(modoCache, "cache", avisosModoCache, store), catalogo);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
const [extracoes, extraidos] = await calcularIndices(planoEscopo.diretorios, catalogo);
|
|
634
|
+
try {
|
|
635
|
+
const payload = serializarIndicesCache(contexto.baseProjeto, extracoes);
|
|
636
|
+
await store.publicar(chave, payload, validarPayloadAplicavel);
|
|
637
|
+
}
|
|
638
|
+
catch {
|
|
639
|
+
// Cache é aceleração descartável; a extração recém-calculada continua autoritativa.
|
|
640
|
+
}
|
|
641
|
+
return montarIndicesPreparados(extraidos, arquivosPrioritarios, planoEscopo, estadoCacheDoStore(modoCache, "calculado", avisosModoCache, store), catalogo);
|
|
642
|
+
}
|
|
643
|
+
export async function prepararIndicesDrift(contexto, configuracaoEscopo, opcoes = {}) {
|
|
644
|
+
const modoCache = opcoes.modoCache ?? "none";
|
|
645
|
+
const avisosModoCache = opcoes.avisosModoCache ?? [];
|
|
646
|
+
let planoEscopo = await planejarEscopoDrift(contexto, configuracaoEscopo);
|
|
647
|
+
if (planoEscopo.bloqueios.length > 0) {
|
|
648
|
+
return indicesVazios(planoEscopo, modoCache, avisosModoCache);
|
|
649
|
+
}
|
|
650
|
+
const arquivosExplicitos = planoEscopo.estrategia === "arquivos_vinculados"
|
|
651
|
+
? planoEscopo.arquivos
|
|
652
|
+
: coletarArquivosFisicosDeclarados(contexto);
|
|
653
|
+
const catalogo = await criarCatalogoDrift({
|
|
654
|
+
baseDiretorio: contexto.baseProjeto,
|
|
655
|
+
arquivos: arquivosExplicitos,
|
|
656
|
+
raizes: planoEscopo.estrategia === "projeto" ? planoEscopo.diretorios : [],
|
|
657
|
+
extensoes: EXTENSOES_ARQUIVOS_RASTREAVEIS_DRIFT,
|
|
658
|
+
diretoriosIgnorados: resolverDiretoriosIgnoradosAtivos(configuracaoEscopo),
|
|
659
|
+
observador: opcoes.observador,
|
|
660
|
+
});
|
|
661
|
+
const arquivosPrioritarios = [...planoEscopo.arquivos];
|
|
662
|
+
planoEscopo = await expandirDependenciasPlanoDrift(contexto, planoEscopo, catalogo);
|
|
663
|
+
if (modoCache === "none") {
|
|
664
|
+
const [, extraidos] = await calcularIndices(planoEscopo.diretorios, catalogo);
|
|
665
|
+
return montarIndicesPreparados(extraidos, arquivosPrioritarios, planoEscopo, estadoCacheInicial(modoCache, "calculado", avisosModoCache), catalogo);
|
|
666
|
+
}
|
|
667
|
+
return resolverIndicesComCache(contexto, configuracaoEscopo, planoEscopo, catalogo, arquivosPrioritarios, arquivosExplicitos, modoCache, avisosModoCache, opcoes.observador);
|
|
668
|
+
}
|
|
91
669
|
//# sourceMappingURL=drift.part13.js.map
|