@semacode/cli 1.5.16 → 1.5.17
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/AGENTS.md +272 -0
- package/LICENSE +22 -0
- package/SEMA_BRIEF.curto.txt +9 -0
- package/SEMA_BRIEF.md +70 -0
- package/SEMA_BRIEF.micro.txt +7 -0
- package/SEMA_INDEX.json +921 -0
- package/dist/angular-consumer-standalone.d.ts +6 -0
- package/dist/angular-consumer-standalone.js.map +1 -0
- package/dist/cpp-symbols.d.ts +10 -0
- package/dist/cpp-symbols.js.map +1 -0
- package/dist/docs.d.ts +56 -0
- package/dist/docs.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 +225 -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 +31 -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 +10 -0
- package/dist/lua-symbols.js.map +1 -0
- package/dist/php-symbols.d.ts +24 -0
- package/dist/php-symbols.js.map +1 -0
- package/dist/projeto.d.ts +53 -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/docs/AGENT_STARTER.md +102 -0
- package/docs/cli.md +119 -0
- package/docs/como-ensinar-a-sema-para-ia.md +149 -0
- package/docs/deploy.md +70 -0
- package/docs/documentacao.md +63 -0
- package/docs/env.md +56 -0
- package/docs/extensao-vscode.md +45 -0
- package/docs/fluxo-pratico-ia-sema.md +177 -0
- package/docs/instalacao-e-primeiro-uso.md +112 -0
- package/docs/integracao-com-ia.md +101 -0
- package/docs/mcp.md +53 -0
- package/docs/pagamento-ponta-a-ponta.md +155 -0
- package/docs/persistencia-vendor-first.md +145 -0
- package/docs/prompt-base-ia-sema.md +104 -0
- package/docs/rollback.md +47 -0
- package/docs/sintaxe.md +410 -0
- package/exemplos/agendamento.sema +106 -0
- package/exemplos/assinatura.sema +136 -0
- package/exemplos/auditoria.sema +88 -0
- package/exemplos/autenticacao.sema +125 -0
- package/exemplos/automacao.sema +107 -0
- package/exemplos/cadastro_usuario.sema +54 -0
- package/exemplos/calculadora.sema +78 -0
- package/exemplos/crud_simples.sema +89 -0
- package/exemplos/estoque.sema +126 -0
- package/exemplos/exportacao.sema +94 -0
- package/exemplos/fila.sema +131 -0
- package/exemplos/integracao_externa.sema +94 -0
- package/exemplos/multi_tenant.sema +140 -0
- package/exemplos/notificacao.sema +98 -0
- package/exemplos/operacao_estrategia.sema +402 -0
- package/exemplos/pagamento.sema +222 -0
- package/exemplos/pagamento_dominio.sema +35 -0
- package/exemplos/pedido.sema +119 -0
- package/exemplos/permissao.sema +121 -0
- package/exemplos/persistencia_vendor_first.sema +86 -0
- package/exemplos/relatorio.sema +93 -0
- package/exemplos/testes_embutidos.sema +45 -0
- package/exemplos/tratamento_erro.sema +157 -0
- package/exemplos/upload_arquivo.sema +93 -0
- package/exemplos/webhook.sema +96 -0
- package/llms-full.txt +34 -0
- package/llms.txt +17 -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 +7 -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 +7 -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 +7 -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 +7 -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 +7 -0
- package/node_modules/@sema/gerador-python/dist/index.d.ts +6 -0
- package/node_modules/@sema/gerador-python/dist/index.js +729 -0
- package/node_modules/@sema/gerador-python/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-python/package.json +7 -0
- package/node_modules/@sema/gerador-typescript/dist/index.d.ts +6 -0
- package/node_modules/@sema/gerador-typescript/dist/index.js +793 -0
- package/node_modules/@sema/gerador-typescript/dist/index.js.map +1 -0
- package/node_modules/@sema/gerador-typescript/package.json +7 -0
- package/node_modules/@sema/nucleo/dist/ast/tipos.d.ts +125 -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 +488 -0
- package/node_modules/@sema/nucleo/dist/formatador/index.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/index.d.ts +35 -0
- package/node_modules/@sema/nucleo/dist/index.js +96 -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 +1072 -0
- package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/ir/modelos.d.ts +377 -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 +82 -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 +807 -0
- package/node_modules/@sema/nucleo/dist/parser/parser.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.d.ts +39 -0
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js +294 -0
- package/node_modules/@sema/nucleo/dist/persistencia/contratos.js.map +1 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +58 -0
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js +1912 -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 +7 -0
- package/node_modules/@sema/padroes/dist/index.d.ts +25 -0
- package/node_modules/@sema/padroes/dist/index.js +316 -0
- package/node_modules/@sema/padroes/dist/index.js.map +1 -0
- package/node_modules/@sema/padroes/package.json +7 -0
- package/package.json +35 -26
- package/semacode-cli-1.3.1.tgz +0 -0
- package/src/angular-consumer-standalone.ts +0 -312
- package/src/cpp-symbols.ts +0 -82
- package/src/docs.ts +0 -535
- package/src/dotnet-http.ts +0 -355
- package/src/drift.ts +0 -4933
- package/src/go-http.ts +0 -118
- package/src/importador.ts +0 -3891
- package/src/index.ts +0 -5641
- package/src/java-http.ts +0 -247
- package/src/lua-symbols.ts +0 -114
- package/src/php-symbols.ts +0 -462
- package/src/projeto.ts +0 -862
- package/src/python-http.ts +0 -258
- package/src/rust-http.ts +0 -125
- package/src/tipos.ts +0 -24
- package/src/typescript-http.ts +0 -1076
- package/tsconfig.json +0 -20
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
|
-
}
|