@semacode/cli 1.3.5 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cpp-symbols.d.ts +10 -0
- package/dist/cpp-symbols.js.map +1 -0
- package/dist/dotnet-http.d.ts +23 -0
- package/dist/dotnet-http.js.map +1 -0
- package/dist/drift.d.ts +118 -0
- package/dist/drift.js.map +1 -0
- package/dist/go-http.d.ts +23 -0
- package/dist/go-http.js.map +1 -0
- package/dist/importador.d.ts +29 -0
- package/dist/importador.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js.map +1 -0
- package/dist/java-http.d.ts +23 -0
- package/dist/java-http.js.map +1 -0
- package/dist/lua-symbols.d.ts +8 -0
- package/dist/lua-symbols.js.map +1 -0
- package/dist/projeto.d.ts +48 -0
- package/dist/projeto.js.map +1 -0
- package/dist/python-http.d.ts +23 -0
- package/dist/python-http.js.map +1 -0
- package/dist/rust-http.d.ts +23 -0
- package/dist/rust-http.js.map +1 -0
- package/dist/tipos.d.ts +3 -0
- package/dist/tipos.js.map +1 -0
- package/dist/typescript-http.d.ts +35 -0
- package/dist/typescript-http.js.map +1 -0
- package/node_modules/@sema/gerador-css/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-css/dist/index.js +592 -0
- package/node_modules/@sema/gerador-css/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-css/package.json +14 -0
- package/node_modules/@sema/gerador-css/src/index.ts +605 -0
- package/node_modules/@sema/gerador-css/tsconfig.json +13 -0
- package/node_modules/@sema/gerador-css/tsconfig.tsbuildinfo +1 -0
- package/node_modules/@sema/gerador-dart/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-dart/dist/index.js +44 -0
- package/node_modules/@sema/gerador-dart/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-dart/package.json +14 -0
- package/node_modules/@sema/gerador-dart/src/index.ts +52 -0
- package/node_modules/@sema/gerador-dart/tsconfig.json +13 -0
- package/node_modules/@sema/gerador-dart/tsconfig.tsbuildinfo +1 -0
- package/node_modules/@sema/gerador-html/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-html/dist/index.js +163 -0
- package/node_modules/@sema/gerador-html/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-html/package.json +14 -0
- package/node_modules/@sema/gerador-html/src/index.ts +185 -0
- package/node_modules/@sema/gerador-html/tsconfig.json +13 -0
- package/node_modules/@sema/gerador-html/tsconfig.tsbuildinfo +1 -0
- package/node_modules/@sema/gerador-javascript/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-javascript/dist/index.js +421 -0
- package/node_modules/@sema/gerador-javascript/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-javascript/package.json +14 -0
- package/node_modules/@sema/gerador-javascript/src/index.ts +461 -0
- package/node_modules/@sema/gerador-javascript/tsconfig.json +13 -0
- package/node_modules/@sema/gerador-javascript/tsconfig.tsbuildinfo +1 -0
- package/node_modules/@sema/gerador-lua/dist/index.d.ts +3 -0
- package/node_modules/@sema/gerador-lua/dist/index.js +328 -0
- package/node_modules/@sema/gerador-lua/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-lua/package.json +14 -0
- package/node_modules/@sema/gerador-lua/src/index.d.ts +3 -0
- package/node_modules/@sema/gerador-lua/src/index.js.map +1 -0
- package/node_modules/@sema/gerador-lua/src/index.ts +359 -0
- package/node_modules/@sema/gerador-lua/tsconfig.json +13 -0
- package/node_modules/@sema/gerador-lua/tsconfig.tsbuildinfo +1 -0
- package/node_modules/@sema/gerador-python/dist/index.d.ts +6 -0
- package/node_modules/@sema/gerador-python/dist/index.js +628 -0
- package/node_modules/@sema/gerador-python/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-python/package.json +14 -0
- package/node_modules/@sema/gerador-python/src/index.ts +706 -0
- package/node_modules/@sema/gerador-python/tsconfig.json +13 -0
- package/node_modules/@sema/gerador-python/tsconfig.tsbuildinfo +1 -0
- package/node_modules/@sema/gerador-typescript/dist/index.d.ts +6 -0
- package/node_modules/@sema/gerador-typescript/dist/index.js +656 -0
- package/node_modules/@sema/gerador-typescript/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-typescript/package.json +14 -0
- package/node_modules/@sema/gerador-typescript/src/index.ts +728 -0
- package/node_modules/@sema/gerador-typescript/tsconfig.json +13 -0
- package/node_modules/@sema/gerador-typescript/tsconfig.tsbuildinfo +1 -0
- package/node_modules/@sema/nucleo/dist/ast/tipos.d.ts +122 -0
- package/node_modules/@sema/nucleo/dist/ast/tipos.js +2 -0
- package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.d.ts +21 -0
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js +12 -0
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/formatador/index.d.ts +9 -0
- package/node_modules/@sema/nucleo/dist/formatador/index.js +445 -0
- package/node_modules/@sema/nucleo/dist/formatador/index.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/index.d.ts +34 -0
- package/node_modules/@sema/nucleo/dist/index.js +95 -0
- package/node_modules/@sema/nucleo/dist/index.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/ir/conversor.d.ts +5 -0
- package/node_modules/@sema/nucleo/dist/ir/conversor.js +781 -0
- package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/ir/modelos.d.ts +285 -0
- package/node_modules/@sema/nucleo/dist/ir/modelos.js +2 -0
- package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/lexer/lexer.d.ts +7 -0
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js +122 -0
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/lexer/tokens.d.ts +8 -0
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js +46 -0
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/parser/parser.d.ts +9 -0
- package/node_modules/@sema/nucleo/dist/parser/parser.js +656 -0
- package/node_modules/@sema/nucleo/dist/parser/parser.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +57 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js +1497 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.d.ts +104 -0
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js +445 -0
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.d.ts +91 -0
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js +258 -0
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/util/arquivos.d.ts +2 -0
- package/node_modules/@sema/nucleo/dist/util/arquivos.js +25 -0
- package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +1 -0
- package/node_modules/@sema/nucleo/package.json +10 -0
- package/node_modules/@sema/nucleo/src/ast/tipos.ts +191 -0
- package/node_modules/@sema/nucleo/src/diagnosticos/index.ts +43 -0
- package/node_modules/@sema/nucleo/src/formatador/index.ts +507 -0
- package/node_modules/@sema/nucleo/src/index.ts +133 -0
- package/node_modules/@sema/nucleo/src/ir/conversor.ts +912 -0
- package/node_modules/@sema/nucleo/src/ir/modelos.ts +331 -0
- package/node_modules/@sema/nucleo/src/lexer/lexer.ts +166 -0
- package/node_modules/@sema/nucleo/src/lexer/tokens.ts +64 -0
- package/node_modules/@sema/nucleo/src/parser/gramatica.ebnf +39 -0
- package/node_modules/@sema/nucleo/src/parser/parser.ts +790 -0
- package/node_modules/@sema/nucleo/src/semantico/analisador.ts +2692 -0
- package/node_modules/@sema/nucleo/src/semantico/estruturas.ts +632 -0
- package/node_modules/@sema/nucleo/src/semantico/seguranca.ts +362 -0
- package/node_modules/@sema/nucleo/src/util/arquivos.ts +28 -0
- package/node_modules/@sema/nucleo/tsconfig.json +9 -0
- package/node_modules/@sema/nucleo/tsconfig.tsbuildinfo +1 -0
- package/node_modules/@sema/padroes/dist/index.d.ts +23 -0
- package/node_modules/@sema/padroes/dist/index.js +210 -0
- package/node_modules/@sema/padroes/dist/index.js.map +1 -0
- package/node_modules/@sema/padroes/package.json +10 -0
- package/node_modules/@sema/padroes/src/index.ts +251 -0
- package/node_modules/@sema/padroes/tsconfig.json +9 -0
- package/node_modules/@sema/padroes/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
- package/README.md +0 -73
- package/logo.png +0 -0
- package/semacode-cli-1.3.1.tgz +0 -0
- package/src/cpp-symbols.ts +0 -82
- package/src/dotnet-http.ts +0 -355
- package/src/drift.ts +0 -2455
- package/src/go-http.ts +0 -118
- package/src/importador.ts +0 -3448
- package/src/index.ts +0 -4476
- package/src/java-http.ts +0 -247
- package/src/projeto.ts +0 -810
- package/src/python-http.ts +0 -258
- package/src/rust-http.ts +0 -125
- package/src/tipos.ts +0 -22
- package/src/typescript-http.ts +0 -1076
- package/tsconfig.json +0 -20
package/README.md
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
# Sema CLI
|
|
2
|
-
|
|
3
|
-
Sema e um Protocolo de Governanca de Intencao para IA e backend vivo.
|
|
4
|
-
|
|
5
|
-
Ela nao foi desenhada para ergonomia humana como prioridade. O alvo principal e IA operando contrato, drift e contexto de sistema vivo com menos chute.
|
|
6
|
-
|
|
7
|
-
Este pacote entrega a CLI oficial para:
|
|
8
|
-
|
|
9
|
-
- validar contratos `.sema`
|
|
10
|
-
- inspecionar projeto
|
|
11
|
-
- medir `drift` entre contrato e codigo vivo
|
|
12
|
-
- importar legado
|
|
13
|
-
- gerar resumo compacto por capacidade de IA
|
|
14
|
-
- preparar contexto para IA
|
|
15
|
-
|
|
16
|
-
Quando a CLI roda em projeto, a trilha IA-first recomendada fica assim:
|
|
17
|
-
|
|
18
|
-
- raiz do repo: `llms.txt`, `SEMA_BRIEF.*`, `SEMA_INDEX.json`, `AGENTS.md`, `README.md`
|
|
19
|
-
- modulo alvo: `resumo.micro.txt`, `briefing.min.json`, `prompt-curto.txt`, `drift.json`, `briefing.json`
|
|
20
|
-
|
|
21
|
-
Isto nao existe para agradar humano. Existe para a IA achar o contexto certo sem entupir a janela com lixo.
|
|
22
|
-
|
|
23
|
-
Para regenerar os entrypoints IA-first da raiz:
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
sema sync-ai-entrypoints --json
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Instalacao pelo npm registry
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
npm install -g @semacode/cli
|
|
33
|
-
sema --help
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Instalacao via tarball da release
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
npm install -g ./{{TGZ_ARQUIVO}}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Ou direto da GitHub Release:
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
npm install -g https://github.com/gerlanss/Sema/releases/latest/download/sema-cli-latest.tgz
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Instalacao local ao projeto
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
npm install @semacode/cli
|
|
52
|
-
npx sema --help
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Ou, se voce estiver testando um tarball local:
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
npm install ./{{TGZ_ARQUIVO}}
|
|
59
|
-
npx sema --help
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Primeiro teste
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
mkdir sema-demo
|
|
66
|
-
cd sema-demo
|
|
67
|
-
sema iniciar
|
|
68
|
-
sema validar contratos/pedidos.sema --json
|
|
69
|
-
sema starter-ia
|
|
70
|
-
sema resumo contratos/pedidos.sema --micro --para onboarding
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
Repositorio: https://github.com/gerlanss/Sema
|
package/logo.png
DELETED
|
Binary file
|
package/semacode-cli-1.3.1.tgz
DELETED
|
Binary file
|
package/src/cpp-symbols.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export interface SimboloCppExtraido {
|
|
2
|
-
simbolo: string;
|
|
3
|
-
retorno?: string;
|
|
4
|
-
parametros: Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function extrairParametrosCpp(assinatura: string): Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }> {
|
|
8
|
-
return assinatura.split(",").map((parametroBruto) => {
|
|
9
|
-
const parametro = parametroBruto.trim();
|
|
10
|
-
if (!parametro || parametro === "void") {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
const semPadrao = parametro.split("=")[0]?.trim() ?? parametro;
|
|
14
|
-
const partes = semPadrao.split(/\s+/).filter(Boolean);
|
|
15
|
-
if (partes.length < 2) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
const nome = partes.at(-1)!.replace(/[&*]+$/, "");
|
|
19
|
-
const tipoTexto = partes.slice(0, -1).join(" ");
|
|
20
|
-
return {
|
|
21
|
-
nome,
|
|
22
|
-
tipoTexto,
|
|
23
|
-
obrigatorio: !parametro.includes("="),
|
|
24
|
-
};
|
|
25
|
-
}).filter((item): item is NonNullable<typeof item> => Boolean(item));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function extrairSimbolosCpp(codigo: string): SimboloCppExtraido[] {
|
|
29
|
-
const simbolos = new Map<string, SimboloCppExtraido>();
|
|
30
|
-
|
|
31
|
-
for (const match of codigo.matchAll(/(?:^|\n)\s*(?:inline\s+|static\s+|virtual\s+|constexpr\s+|friend\s+|extern\s+|template\s*<[^>]+>\s*)*(?:[\w:<>~*&]+\s+)+([A-Za-z_]\w*)::([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?:const)?\s*(?:\{|;)/g)) {
|
|
32
|
-
const simbolo = `${match[1]!}.${match[2]!}`;
|
|
33
|
-
simbolos.set(simbolo, {
|
|
34
|
-
simbolo,
|
|
35
|
-
parametros: extrairParametrosCpp(match[3] ?? ""),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (const match of codigo.matchAll(/(?:^|\n)\s*(?:inline\s+|static\s+|virtual\s+|constexpr\s+|friend\s+|extern\s+)*(?:[\w:<>~*&]+\s+)+([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?:const)?\s*(?:\{|;)/g)) {
|
|
40
|
-
const nome = match[1]!;
|
|
41
|
-
if (["if", "for", "while", "switch", "return"].includes(nome)) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (!simbolos.has(nome)) {
|
|
45
|
-
simbolos.set(nome, {
|
|
46
|
-
simbolo: nome,
|
|
47
|
-
parametros: extrairParametrosCpp(match[2] ?? ""),
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const pilhaClasses: string[] = [];
|
|
53
|
-
for (const linha of codigo.split(/\r?\n/)) {
|
|
54
|
-
const trim = linha.trim();
|
|
55
|
-
const classe = trim.match(/^(?:class|struct)\s+([A-Za-z_]\w*)/);
|
|
56
|
-
if (classe) {
|
|
57
|
-
pilhaClasses.push(classe[1]!);
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
if (trim.startsWith("};") || trim === "}" || trim === "};") {
|
|
61
|
-
pilhaClasses.pop();
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const metodoClasse = trim.match(/^(?:inline\s+|static\s+|virtual\s+|constexpr\s+)*(?:[\w:<>~*&]+\s+)+([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?:const)?\s*\{/);
|
|
66
|
-
if (metodoClasse && pilhaClasses.length > 0) {
|
|
67
|
-
const nomeClasse = pilhaClasses[pilhaClasses.length - 1]!;
|
|
68
|
-
const nomeMetodo = metodoClasse[1]!;
|
|
69
|
-
if (!["if", "for", "while", "switch"].includes(nomeMetodo)) {
|
|
70
|
-
const simbolo = `${nomeClasse}.${nomeMetodo}`;
|
|
71
|
-
if (!simbolos.has(simbolo)) {
|
|
72
|
-
simbolos.set(simbolo, {
|
|
73
|
-
simbolo,
|
|
74
|
-
parametros: extrairParametrosCpp(metodoClasse[2] ?? ""),
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return [...simbolos.values()];
|
|
82
|
-
}
|
package/src/dotnet-http.ts
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
export interface ParametroRotaBackend {
|
|
2
|
-
nome: string;
|
|
3
|
-
tipoSema: "Texto" | "Inteiro" | "Decimal" | "Id";
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface SimboloDotnetExtraido {
|
|
7
|
-
simbolo: string;
|
|
8
|
-
retorno?: string;
|
|
9
|
-
parametros: Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface RotaDotnetExtraida {
|
|
13
|
-
origem: "dotnet";
|
|
14
|
-
metodo: string;
|
|
15
|
-
caminho: string;
|
|
16
|
-
simbolo: string;
|
|
17
|
-
parametros: ParametroRotaBackend[];
|
|
18
|
-
retorno?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const METODOS_HTTP = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
22
|
-
|
|
23
|
-
function normalizarCaminhoBase(caminho?: string): string | undefined {
|
|
24
|
-
if (!caminho) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
return caminho.replace(/^\/+|\/+$/g, "");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function juntarCaminho(base: string | undefined, sufixo: string | undefined): string {
|
|
31
|
-
const partes = [base, sufixo]
|
|
32
|
-
.map((parte) => normalizarCaminhoBase(parte))
|
|
33
|
-
.filter((parte): parte is string => Boolean(parte));
|
|
34
|
-
return `/${partes.join("/")}`.replace(/\/+/g, "/");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function normalizarCaminhoAspNet(caminho: string, classe?: string, metodo?: string): string {
|
|
38
|
-
const controller = (classe ?? "").replace(/Controller$/i, "");
|
|
39
|
-
const action = metodo ?? "";
|
|
40
|
-
return caminho
|
|
41
|
-
.replace(/\[controller\]/gi, controller ? controller.toLowerCase() : "controller")
|
|
42
|
-
.replace(/\[action\]/gi, action ? action.toLowerCase() : "action")
|
|
43
|
-
.replace(/\{([^}:]+):[^}]+\}/g, "{$1}")
|
|
44
|
-
.replace(/\/+/g, "/");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function mapearTipoRotaDotnet(tipo?: string): ParametroRotaBackend["tipoSema"] {
|
|
48
|
-
const normalizado = (tipo ?? "").toLowerCase();
|
|
49
|
-
if (/(^|\.)(int|int32|int64|long|short)$/.test(normalizado)) {
|
|
50
|
-
return "Inteiro";
|
|
51
|
-
}
|
|
52
|
-
if (/(^|\.)(float|double|decimal)$/.test(normalizado)) {
|
|
53
|
-
return "Decimal";
|
|
54
|
-
}
|
|
55
|
-
if (/guid|uuid|id$/i.test(normalizado)) {
|
|
56
|
-
return "Id";
|
|
57
|
-
}
|
|
58
|
-
return "Texto";
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function extrairParametrosRota(caminho: string, assinatura: string): ParametroRotaBackend[] {
|
|
62
|
-
const tiposAssinatura = new Map<string, string>();
|
|
63
|
-
for (const parametroBruto of assinatura.split(",")) {
|
|
64
|
-
const parametro = parametroBruto.trim();
|
|
65
|
-
if (!parametro) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
const semPadrao = parametro.split("=")[0]?.trim() ?? parametro;
|
|
69
|
-
const partes = semPadrao.split(/\s+/).filter(Boolean);
|
|
70
|
-
if (partes.length < 2) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
const nome = partes.at(-1)!;
|
|
74
|
-
const tipo = partes.slice(0, -1).join(" ");
|
|
75
|
-
tiposAssinatura.set(nome, tipo);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return [...caminho.matchAll(/\{([^}:]+)(?::[^}]+)?\}/g)].map((match) => {
|
|
79
|
-
const nome = match[1]!;
|
|
80
|
-
return {
|
|
81
|
-
nome,
|
|
82
|
-
tipoSema: mapearTipoRotaDotnet(tiposAssinatura.get(nome)),
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function extrairTextoAtributo(atributo: string): string | undefined {
|
|
88
|
-
return atributo.match(/"([^"]+)"/)?.[1];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function extrairMetodosAtributo(atributo: string): string[] {
|
|
92
|
-
const direto = atributo.match(/\[\s*Http(Get|Post|Put|Patch|Delete)\b/i)?.[1]?.toUpperCase();
|
|
93
|
-
if (direto && METODOS_HTTP.has(direto)) {
|
|
94
|
-
return [direto];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const bloco = atributo.match(/\bHttpMethods\.(Get|Post|Put|Patch|Delete)\b/gi)
|
|
98
|
-
?.map((item) => item.split(".").pop()?.toUpperCase() ?? "")
|
|
99
|
-
.filter((item) => METODOS_HTTP.has(item));
|
|
100
|
-
if (bloco && bloco.length > 0) {
|
|
101
|
-
return [...new Set(bloco)];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const requestMapping = atributo.match(/\[\s*AcceptVerbs\(([^)]*)\)\s*\]/i)?.[1];
|
|
105
|
-
if (requestMapping) {
|
|
106
|
-
const encontrados = [...requestMapping.matchAll(/"([A-Za-z]+)"/g)]
|
|
107
|
-
.map((match) => match[1]!.toUpperCase())
|
|
108
|
-
.filter((item) => METODOS_HTTP.has(item));
|
|
109
|
-
if (encontrados.length > 0) {
|
|
110
|
-
return [...new Set(encontrados)];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return [];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function contarChar(texto: string, alvo: string): number {
|
|
118
|
-
return [...texto].filter((char) => char === alvo).length;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function atualizarPilhaClasses<T extends { profundidade: number }>(pilha: T[], profundidade: number): void {
|
|
122
|
-
while (pilha.length > 0 && profundidade < pilha[pilha.length - 1]!.profundidade) {
|
|
123
|
-
pilha.pop();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function extrairAtributos(linhas: string[], inicio: number): { atributos: string[]; proximoIndice: number } {
|
|
128
|
-
const atributos: string[] = [];
|
|
129
|
-
let indice = inicio;
|
|
130
|
-
|
|
131
|
-
while (indice < linhas.length) {
|
|
132
|
-
const linha = linhas[indice]!.trim();
|
|
133
|
-
if (!linha.startsWith("[")) {
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
let atual = linha;
|
|
137
|
-
let saldo = contarChar(linha, "[") - contarChar(linha, "]");
|
|
138
|
-
while (saldo > 0 && indice + 1 < linhas.length) {
|
|
139
|
-
indice += 1;
|
|
140
|
-
const complemento = linhas[indice]!.trim();
|
|
141
|
-
atual += ` ${complemento}`;
|
|
142
|
-
saldo += contarChar(complemento, "[") - contarChar(complemento, "]");
|
|
143
|
-
}
|
|
144
|
-
atributos.push(atual);
|
|
145
|
-
indice += 1;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return { atributos, proximoIndice: indice };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function extrairSimbolosDotnet(codigo: string): SimboloDotnetExtraido[] {
|
|
152
|
-
const simbolos = new Map<string, SimboloDotnetExtraido>();
|
|
153
|
-
const linhas = codigo.split(/\r?\n/);
|
|
154
|
-
const pilhaClasses: Array<{ nome: string; profundidade: number }> = [];
|
|
155
|
-
let classePendente: { nome: string; profundidade: number } | undefined;
|
|
156
|
-
let profundidade = 0;
|
|
157
|
-
|
|
158
|
-
for (let indice = 0; indice < linhas.length; indice += 1) {
|
|
159
|
-
const linhaOriginal = linhas[indice]!;
|
|
160
|
-
const linha = linhaOriginal.trim();
|
|
161
|
-
if (classePendente && linha.startsWith("{")) {
|
|
162
|
-
pilhaClasses.push(classePendente);
|
|
163
|
-
classePendente = undefined;
|
|
164
|
-
}
|
|
165
|
-
if (!linha || linha.startsWith("//")) {
|
|
166
|
-
profundidade += contarChar(linhaOriginal, "{") - contarChar(linhaOriginal, "}");
|
|
167
|
-
atualizarPilhaClasses(pilhaClasses, profundidade);
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const { atributos, proximoIndice } = extrairAtributos(linhas, indice);
|
|
172
|
-
if (atributos.length > 0) {
|
|
173
|
-
indice = proximoIndice;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const linhaEfetiva = (linhas[indice] ?? "").trim();
|
|
177
|
-
const classe = linhaEfetiva.match(/\bclass\s+([A-Za-z_]\w*)/);
|
|
178
|
-
if (classe) {
|
|
179
|
-
const entrada = { nome: classe[1]!, profundidade: profundidade + 1 };
|
|
180
|
-
if (linhaEfetiva.includes("{")) {
|
|
181
|
-
pilhaClasses.push(entrada);
|
|
182
|
-
} else {
|
|
183
|
-
classePendente = entrada;
|
|
184
|
-
}
|
|
185
|
-
profundidade += contarChar(linhaEfetiva, "{") - contarChar(linhaEfetiva, "}");
|
|
186
|
-
atualizarPilhaClasses(pilhaClasses, profundidade);
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const metodo = linhaEfetiva.match(/\b(?:public|internal|protected|private)\s+(?:static\s+|async\s+|virtual\s+|override\s+|sealed\s+|partial\s+)*([A-Za-z0-9_<>,.?[\]\s]+)\s+([A-Za-z_]\w*)\s*\(([^)]*)\)/);
|
|
191
|
-
if (metodo) {
|
|
192
|
-
const classeAtual = pilhaClasses[pilhaClasses.length - 1];
|
|
193
|
-
const simbolo = classeAtual ? `${classeAtual.nome}.${metodo[2]!}` : metodo[2]!;
|
|
194
|
-
simbolos.set(simbolo, {
|
|
195
|
-
simbolo,
|
|
196
|
-
retorno: metodo[1]!.trim(),
|
|
197
|
-
parametros: metodo[3]!.split(",").flatMap((parametroBruto) => {
|
|
198
|
-
const parametro = parametroBruto.trim();
|
|
199
|
-
if (!parametro) {
|
|
200
|
-
return [];
|
|
201
|
-
}
|
|
202
|
-
const semPadrao = parametro.split("=")[0]?.trim() ?? parametro;
|
|
203
|
-
const partes = semPadrao.split(/\s+/).filter(Boolean);
|
|
204
|
-
if (partes.length < 2) {
|
|
205
|
-
return [];
|
|
206
|
-
}
|
|
207
|
-
return [{
|
|
208
|
-
nome: partes.at(-1)!,
|
|
209
|
-
tipoTexto: partes.slice(0, -1).join(" "),
|
|
210
|
-
obrigatorio: !parametro.includes("="),
|
|
211
|
-
}];
|
|
212
|
-
}),
|
|
213
|
-
});
|
|
214
|
-
profundidade += contarChar(linhaEfetiva, "{") - contarChar(linhaEfetiva, "}");
|
|
215
|
-
atualizarPilhaClasses(pilhaClasses, profundidade);
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const funcaoLocal = linhaEfetiva.match(/\b([A-Za-z0-9_<>,.?[\]\s]+)\s+([A-Za-z_]\w*)\s*\(([^)]*)\)\s*=>/);
|
|
220
|
-
if (funcaoLocal && atributos.length === 0 && pilhaClasses.length === 0) {
|
|
221
|
-
const simbolo = funcaoLocal[2]!;
|
|
222
|
-
simbolos.set(simbolo, {
|
|
223
|
-
simbolo,
|
|
224
|
-
retorno: funcaoLocal[1]!.trim(),
|
|
225
|
-
parametros: [],
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const funcaoTopo = linhaEfetiva.match(/\b(?:static\s+)?([A-Za-z0-9_<>,.?[\]\s]+)\s+([A-Za-z_]\w*)\s*\(([^)]*)\)\s*(?:\{|$)/);
|
|
230
|
-
if (funcaoTopo && atributos.length === 0 && pilhaClasses.length === 0 && !["if", "for", "while", "switch"].includes(funcaoTopo[2]!)) {
|
|
231
|
-
const simbolo = funcaoTopo[2]!;
|
|
232
|
-
if (!simbolos.has(simbolo)) {
|
|
233
|
-
simbolos.set(simbolo, {
|
|
234
|
-
simbolo,
|
|
235
|
-
retorno: funcaoTopo[1]!.trim(),
|
|
236
|
-
parametros: funcaoTopo[3]!.split(",").flatMap((parametroBruto) => {
|
|
237
|
-
const parametro = parametroBruto.trim();
|
|
238
|
-
if (!parametro) {
|
|
239
|
-
return [];
|
|
240
|
-
}
|
|
241
|
-
const semPadrao = parametro.split("=")[0]?.trim() ?? parametro;
|
|
242
|
-
const partes = semPadrao.split(/\s+/).filter(Boolean);
|
|
243
|
-
if (partes.length < 2) {
|
|
244
|
-
return [];
|
|
245
|
-
}
|
|
246
|
-
return [{
|
|
247
|
-
nome: partes.at(-1)!,
|
|
248
|
-
tipoTexto: partes.slice(0, -1).join(" "),
|
|
249
|
-
obrigatorio: !parametro.includes("="),
|
|
250
|
-
}];
|
|
251
|
-
}),
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
profundidade += contarChar(linhaEfetiva, "{") - contarChar(linhaEfetiva, "}");
|
|
257
|
-
atualizarPilhaClasses(pilhaClasses, profundidade);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return [...simbolos.values()];
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export function extrairRotasDotnet(codigo: string): RotaDotnetExtraida[] {
|
|
264
|
-
const rotas = new Map<string, RotaDotnetExtraida>();
|
|
265
|
-
const linhas = codigo.split(/\r?\n/);
|
|
266
|
-
const pilhaClasses: Array<{ nome: string; profundidade: number; rotaBase?: string; apiController: boolean }> = [];
|
|
267
|
-
let classePendente: { nome: string; profundidade: number; rotaBase?: string; apiController: boolean } | undefined;
|
|
268
|
-
let profundidade = 0;
|
|
269
|
-
|
|
270
|
-
for (let indice = 0; indice < linhas.length; indice += 1) {
|
|
271
|
-
const linhaOriginal = linhas[indice]!;
|
|
272
|
-
const linha = linhaOriginal.trim();
|
|
273
|
-
if (classePendente && linha.startsWith("{")) {
|
|
274
|
-
pilhaClasses.push(classePendente);
|
|
275
|
-
classePendente = undefined;
|
|
276
|
-
}
|
|
277
|
-
if (!linha || linha.startsWith("//")) {
|
|
278
|
-
profundidade += contarChar(linhaOriginal, "{") - contarChar(linhaOriginal, "}");
|
|
279
|
-
atualizarPilhaClasses(pilhaClasses, profundidade);
|
|
280
|
-
continue;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
const { atributos, proximoIndice } = extrairAtributos(linhas, indice);
|
|
284
|
-
if (atributos.length > 0) {
|
|
285
|
-
indice = proximoIndice;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const linhaEfetiva = (linhas[indice] ?? "").trim();
|
|
289
|
-
const classe = linhaEfetiva.match(/\bclass\s+([A-Za-z_]\w*)/);
|
|
290
|
-
if (classe) {
|
|
291
|
-
const rotaBase = atributos
|
|
292
|
-
.map((atributo) => extrairTextoAtributo(atributo))
|
|
293
|
-
.find(Boolean);
|
|
294
|
-
const entrada = {
|
|
295
|
-
nome: classe[1]!,
|
|
296
|
-
profundidade: profundidade + 1,
|
|
297
|
-
rotaBase,
|
|
298
|
-
apiController: atributos.some((atributo) => /\[\s*ApiController\s*\]/i.test(atributo)),
|
|
299
|
-
};
|
|
300
|
-
if (linhaEfetiva.includes("{")) {
|
|
301
|
-
pilhaClasses.push(entrada);
|
|
302
|
-
} else {
|
|
303
|
-
classePendente = entrada;
|
|
304
|
-
}
|
|
305
|
-
profundidade += contarChar(linhaEfetiva, "{") - contarChar(linhaEfetiva, "}");
|
|
306
|
-
atualizarPilhaClasses(pilhaClasses, profundidade);
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
const classeAtual = pilhaClasses[pilhaClasses.length - 1];
|
|
311
|
-
const metodo = linhaEfetiva.match(/\b(?:public|internal|protected)\s+(?:async\s+|virtual\s+|override\s+|static\s+)*([A-Za-z0-9_<>,.?[\]\s]+)\s+([A-Za-z_]\w*)\s*\(([^)]*)\)/);
|
|
312
|
-
if (metodo && classeAtual) {
|
|
313
|
-
const atributosMetodo = atributos.filter((atributo) => /\[\s*(?:Http|AcceptVerbs)/i.test(atributo));
|
|
314
|
-
for (const atributo of atributosMetodo) {
|
|
315
|
-
const metodos = extrairMetodosAtributo(atributo);
|
|
316
|
-
const rotaMetodo = extrairTextoAtributo(atributo);
|
|
317
|
-
for (const httpMetodo of metodos) {
|
|
318
|
-
const caminho = normalizarCaminhoAspNet(
|
|
319
|
-
juntarCaminho(classeAtual.rotaBase, rotaMetodo),
|
|
320
|
-
classeAtual.nome,
|
|
321
|
-
metodo[2]!,
|
|
322
|
-
);
|
|
323
|
-
const registro: RotaDotnetExtraida = {
|
|
324
|
-
origem: "dotnet",
|
|
325
|
-
metodo: httpMetodo,
|
|
326
|
-
caminho,
|
|
327
|
-
simbolo: `${classeAtual.nome}.${metodo[2]!}`,
|
|
328
|
-
parametros: extrairParametrosRota(caminho, metodo[3] ?? ""),
|
|
329
|
-
retorno: metodo[1]!.trim(),
|
|
330
|
-
};
|
|
331
|
-
rotas.set(`${registro.metodo}:${registro.caminho}:${registro.simbolo}`, registro);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
for (const match of linhaEfetiva.matchAll(/\b\w+\.Map(Get|Post|Put|Patch|Delete)\(\s*"([^"]+)"\s*,\s*([A-Za-z_][\w.]*)/g)) {
|
|
337
|
-
const httpMetodo = match[1]!.toUpperCase();
|
|
338
|
-
const caminho = normalizarCaminhoAspNet(match[2]!);
|
|
339
|
-
const simbolo = match[3]!;
|
|
340
|
-
const registro: RotaDotnetExtraida = {
|
|
341
|
-
origem: "dotnet",
|
|
342
|
-
metodo: httpMetodo,
|
|
343
|
-
caminho,
|
|
344
|
-
simbolo,
|
|
345
|
-
parametros: extrairParametrosRota(caminho, ""),
|
|
346
|
-
};
|
|
347
|
-
rotas.set(`${registro.metodo}:${registro.caminho}:${registro.simbolo}`, registro);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
profundidade += contarChar(linhaEfetiva, "{") - contarChar(linhaEfetiva, "}");
|
|
351
|
-
atualizarPilhaClasses(pilhaClasses, profundidade);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
return [...rotas.values()];
|
|
355
|
-
}
|