@semacode/cli 1.2.17 → 1.3.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/README.md +2 -2
- package/dist/index.js +58 -10
- package/dist/projeto.js +4 -1
- package/package.json +17 -34
- package/src/cpp-symbols.ts +82 -0
- package/src/dotnet-http.ts +355 -0
- package/src/drift.ts +2455 -0
- package/src/go-http.ts +118 -0
- package/src/importador.ts +3448 -0
- package/src/index.ts +4470 -0
- package/src/java-http.ts +247 -0
- package/src/projeto.ts +810 -0
- package/src/python-http.ts +258 -0
- package/src/rust-http.ts +125 -0
- package/src/tipos.ts +22 -0
- package/src/typescript-http.ts +1076 -0
- package/tsconfig.json +20 -0
- package/AGENTS.md +0 -50
- package/LICENSE +0 -22
- package/SEMA_BRIEF.curto.txt +0 -9
- package/SEMA_BRIEF.md +0 -49
- package/SEMA_BRIEF.micro.txt +0 -7
- package/SEMA_INDEX.json +0 -546
- package/dist/cpp-symbols.d.ts +0 -10
- package/dist/cpp-symbols.js.map +0 -1
- package/dist/dotnet-http.d.ts +0 -23
- package/dist/dotnet-http.js.map +0 -1
- package/dist/drift.d.ts +0 -118
- package/dist/drift.js.map +0 -1
- package/dist/go-http.d.ts +0 -23
- package/dist/go-http.js.map +0 -1
- package/dist/importador.d.ts +0 -29
- package/dist/importador.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js.map +0 -1
- package/dist/java-http.d.ts +0 -23
- package/dist/java-http.js.map +0 -1
- package/dist/lua-symbols.d.ts +0 -8
- package/dist/lua-symbols.js.map +0 -1
- package/dist/projeto.d.ts +0 -48
- package/dist/projeto.js.map +0 -1
- package/dist/python-http.d.ts +0 -23
- package/dist/python-http.js.map +0 -1
- package/dist/rust-http.d.ts +0 -23
- package/dist/rust-http.js.map +0 -1
- package/dist/tipos.d.ts +0 -3
- package/dist/tipos.js.map +0 -1
- package/dist/typescript-http.d.ts +0 -35
- package/dist/typescript-http.js.map +0 -1
- package/docs/AGENT_STARTER.md +0 -102
- package/docs/como-ensinar-a-sema-para-ia.md +0 -149
- package/docs/fluxo-pratico-ia-sema.md +0 -177
- package/docs/instalacao-e-primeiro-uso.md +0 -196
- package/docs/integracao-com-ia.md +0 -228
- package/docs/pagamento-ponta-a-ponta.md +0 -155
- package/docs/prompt-base-ia-sema.md +0 -104
- package/docs/sintaxe.md +0 -361
- package/exemplos/automacao.sema +0 -107
- package/exemplos/cadastro_usuario.sema +0 -54
- package/exemplos/calculadora.sema +0 -78
- package/exemplos/crud_simples.sema +0 -89
- package/exemplos/operacao_estrategia.sema +0 -402
- package/exemplos/pagamento.sema +0 -222
- package/exemplos/pagamento_dominio.sema +0 -35
- package/exemplos/testes_embutidos.sema +0 -45
- package/exemplos/tratamento_erro.sema +0 -157
- package/llms-full.txt +0 -34
- package/llms.txt +0 -17
- package/node_modules/@sema/gerador-dart/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-dart/dist/index.js +0 -44
- package/node_modules/@sema/gerador-dart/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-dart/package.json +0 -7
- package/node_modules/@sema/gerador-lua/dist/index.d.ts +0 -3
- package/node_modules/@sema/gerador-lua/dist/index.js +0 -328
- package/node_modules/@sema/gerador-lua/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-lua/package.json +0 -7
- package/node_modules/@sema/gerador-python/dist/index.d.ts +0 -6
- package/node_modules/@sema/gerador-python/dist/index.js +0 -628
- package/node_modules/@sema/gerador-python/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-python/package.json +0 -7
- package/node_modules/@sema/gerador-typescript/dist/index.d.ts +0 -6
- package/node_modules/@sema/gerador-typescript/dist/index.js +0 -656
- package/node_modules/@sema/gerador-typescript/dist/index.js.map +0 -1
- package/node_modules/@sema/gerador-typescript/package.json +0 -7
- package/node_modules/@sema/nucleo/dist/ast/tipos.d.ts +0 -122
- package/node_modules/@sema/nucleo/dist/ast/tipos.js +0 -2
- package/node_modules/@sema/nucleo/dist/ast/tipos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.d.ts +0 -21
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js +0 -12
- package/node_modules/@sema/nucleo/dist/diagnosticos/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/formatador/index.d.ts +0 -9
- package/node_modules/@sema/nucleo/dist/formatador/index.js +0 -445
- package/node_modules/@sema/nucleo/dist/formatador/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/index.d.ts +0 -34
- package/node_modules/@sema/nucleo/dist/index.js +0 -95
- package/node_modules/@sema/nucleo/dist/index.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/conversor.d.ts +0 -5
- package/node_modules/@sema/nucleo/dist/ir/conversor.js +0 -781
- package/node_modules/@sema/nucleo/dist/ir/conversor.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/ir/modelos.d.ts +0 -285
- package/node_modules/@sema/nucleo/dist/ir/modelos.js +0 -2
- package/node_modules/@sema/nucleo/dist/ir/modelos.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/lexer.d.ts +0 -7
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js +0 -122
- package/node_modules/@sema/nucleo/dist/lexer/lexer.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/lexer/tokens.d.ts +0 -8
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js +0 -46
- package/node_modules/@sema/nucleo/dist/lexer/tokens.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/parser/parser.d.ts +0 -9
- package/node_modules/@sema/nucleo/dist/parser/parser.js +0 -656
- package/node_modules/@sema/nucleo/dist/parser/parser.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/analisador.d.ts +0 -57
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js +0 -1497
- package/node_modules/@sema/nucleo/dist/semantico/analisador.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.d.ts +0 -104
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js +0 -445
- package/node_modules/@sema/nucleo/dist/semantico/estruturas.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.d.ts +0 -91
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js +0 -258
- package/node_modules/@sema/nucleo/dist/semantico/seguranca.js.map +0 -1
- package/node_modules/@sema/nucleo/dist/util/arquivos.d.ts +0 -2
- package/node_modules/@sema/nucleo/dist/util/arquivos.js +0 -25
- package/node_modules/@sema/nucleo/dist/util/arquivos.js.map +0 -1
- package/node_modules/@sema/nucleo/package.json +0 -7
- package/node_modules/@sema/padroes/dist/index.d.ts +0 -21
- package/node_modules/@sema/padroes/dist/index.js +0 -159
- package/node_modules/@sema/padroes/dist/index.js.map +0 -1
- package/node_modules/@sema/padroes/package.json +0 -7
package/src/java-http.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
export interface ParametroRotaJava {
|
|
2
|
+
nome: string;
|
|
3
|
+
tipoSema: "Texto" | "Inteiro" | "Decimal" | "Id";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface SimboloJavaExtraido {
|
|
7
|
+
simbolo: string;
|
|
8
|
+
retorno?: string;
|
|
9
|
+
parametros: Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RotaJavaExtraida {
|
|
13
|
+
origem: "java";
|
|
14
|
+
metodo: string;
|
|
15
|
+
caminho: string;
|
|
16
|
+
simbolo: string;
|
|
17
|
+
parametros: ParametroRotaJava[];
|
|
18
|
+
retorno?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const METODOS_HTTP = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
22
|
+
|
|
23
|
+
function contarChar(texto: string, alvo: string): number {
|
|
24
|
+
return [...texto].filter((char) => char === alvo).length;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function juntarCaminho(base: string | undefined, sufixo: string | undefined): string {
|
|
28
|
+
const partes = [base, sufixo]
|
|
29
|
+
.map((parte) => (parte ?? "").trim())
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((parte) => parte.replace(/^\/+|\/+$/g, ""));
|
|
32
|
+
return `/${partes.join("/")}`.replace(/\/+/g, "/");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function extrairParametrosAssinaturaJava(assinatura: string): Array<{ nome: string; tipoTexto?: string; obrigatorio: boolean }> {
|
|
36
|
+
return assinatura.split(",").map((parametroBruto) => {
|
|
37
|
+
const parametro = parametroBruto.trim();
|
|
38
|
+
if (!parametro) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const limpo = parametro.replace(/^@\w+(?:\([^)]*\))?\s*/g, "").trim();
|
|
42
|
+
const partes = limpo.split(/\s+/).filter(Boolean);
|
|
43
|
+
if (partes.length < 2) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
nome: partes.at(-1)!,
|
|
48
|
+
tipoTexto: partes.slice(0, -1).join(" "),
|
|
49
|
+
obrigatorio: true,
|
|
50
|
+
};
|
|
51
|
+
}).filter((item): item is NonNullable<typeof item> => Boolean(item));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function mapearTipoJava(tipo?: string): ParametroRotaJava["tipoSema"] {
|
|
55
|
+
const normalizado = (tipo ?? "").toLowerCase();
|
|
56
|
+
if (/(^|\.)(int|integer|long|short)$/.test(normalizado)) {
|
|
57
|
+
return "Inteiro";
|
|
58
|
+
}
|
|
59
|
+
if (/(^|\.)(float|double|bigdecimal|decimal)$/.test(normalizado)) {
|
|
60
|
+
return "Decimal";
|
|
61
|
+
}
|
|
62
|
+
if (/uuid|id$/i.test(normalizado)) {
|
|
63
|
+
return "Id";
|
|
64
|
+
}
|
|
65
|
+
return "Texto";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function extrairAtributosJava(linhas: string[], inicio: number): { atributos: string[]; proximoIndice: number } {
|
|
69
|
+
const atributos: string[] = [];
|
|
70
|
+
let indice = inicio;
|
|
71
|
+
|
|
72
|
+
while (indice < linhas.length) {
|
|
73
|
+
const linha = linhas[indice]!.trim();
|
|
74
|
+
if (!linha.startsWith("@")) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
let atual = linha;
|
|
78
|
+
let saldo = contarChar(linha, "(") - contarChar(linha, ")");
|
|
79
|
+
while (saldo > 0 && indice + 1 < linhas.length) {
|
|
80
|
+
indice += 1;
|
|
81
|
+
const complemento = linhas[indice]!.trim();
|
|
82
|
+
atual += ` ${complemento}`;
|
|
83
|
+
saldo += contarChar(complemento, "(") - contarChar(complemento, ")");
|
|
84
|
+
}
|
|
85
|
+
atributos.push(atual);
|
|
86
|
+
indice += 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { atributos, proximoIndice: indice };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function extrairCaminhoJava(atributo: string): string | undefined {
|
|
93
|
+
return atributo.match(/"([^"]+)"/)?.[1];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function extrairMetodosJava(atributo: string): string[] {
|
|
97
|
+
const direto = atributo.match(/@(Get|Post|Put|Patch|Delete)Mapping/i)?.[1]?.toUpperCase();
|
|
98
|
+
if (direto && METODOS_HTTP.has(direto)) {
|
|
99
|
+
return [direto];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const requestMethod = [...atributo.matchAll(/RequestMethod\.(GET|POST|PUT|PATCH|DELETE)/gi)]
|
|
103
|
+
.map((match) => match[1]!.toUpperCase())
|
|
104
|
+
.filter((metodo) => METODOS_HTTP.has(metodo));
|
|
105
|
+
if (requestMethod.length > 0) {
|
|
106
|
+
return [...new Set(requestMethod)];
|
|
107
|
+
}
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function normalizarCaminhoJava(caminho: string): string {
|
|
112
|
+
return caminho.replace(/\{([^}:]+):[^}]+\}/g, "{$1}").replace(/\/+/g, "/");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function extrairParametrosRotaJava(caminho: string, assinatura: string): ParametroRotaJava[] {
|
|
116
|
+
const assinaturaMap = new Map<string, string>();
|
|
117
|
+
for (const parametro of extrairParametrosAssinaturaJava(assinatura)) {
|
|
118
|
+
assinaturaMap.set(parametro.nome, parametro.tipoTexto ?? "");
|
|
119
|
+
}
|
|
120
|
+
return [...caminho.matchAll(/\{([^}:]+)(?::[^}]+)?\}/g)].map((match) => {
|
|
121
|
+
const nome = match[1]!;
|
|
122
|
+
return {
|
|
123
|
+
nome,
|
|
124
|
+
tipoSema: mapearTipoJava(assinaturaMap.get(nome)),
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function extrairSimbolosJava(codigo: string): SimboloJavaExtraido[] {
|
|
130
|
+
const simbolos = new Map<string, SimboloJavaExtraido>();
|
|
131
|
+
const linhas = codigo.split(/\r?\n/);
|
|
132
|
+
const pilhaClasses: Array<{ nome: string; profundidade: number }> = [];
|
|
133
|
+
let profundidade = 0;
|
|
134
|
+
|
|
135
|
+
for (let indice = 0; indice < linhas.length; indice += 1) {
|
|
136
|
+
const linhaOriginal = linhas[indice]!;
|
|
137
|
+
const { atributos, proximoIndice } = extrairAtributosJava(linhas, indice);
|
|
138
|
+
if (atributos.length > 0) {
|
|
139
|
+
indice = proximoIndice;
|
|
140
|
+
}
|
|
141
|
+
const linha = (linhas[indice] ?? linhaOriginal).trim();
|
|
142
|
+
if (!linha || linha.startsWith("//")) {
|
|
143
|
+
profundidade += contarChar(linhaOriginal, "{") - contarChar(linhaOriginal, "}");
|
|
144
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
145
|
+
pilhaClasses.pop();
|
|
146
|
+
}
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const classe = linha.match(/\bclass\s+([A-Za-z_]\w*)/);
|
|
151
|
+
if (classe) {
|
|
152
|
+
pilhaClasses.push({ nome: classe[1]!, profundidade: profundidade + 1 });
|
|
153
|
+
profundidade += contarChar(linha, "{") - contarChar(linha, "}");
|
|
154
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
155
|
+
pilhaClasses.pop();
|
|
156
|
+
}
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const metodo = linha.match(/\b(?:public|protected|private)\s+(?:static\s+|final\s+|synchronized\s+)*([A-Za-z0-9_<>,.?[\]\s]+)\s+([A-Za-z_]\w*)\s*\(([^)]*)\)/);
|
|
161
|
+
if (metodo) {
|
|
162
|
+
const classeAtual = pilhaClasses[pilhaClasses.length - 1];
|
|
163
|
+
const simbolo = classeAtual ? `${classeAtual.nome}.${metodo[2]!}` : metodo[2]!;
|
|
164
|
+
simbolos.set(simbolo, {
|
|
165
|
+
simbolo,
|
|
166
|
+
retorno: metodo[1]!.trim(),
|
|
167
|
+
parametros: extrairParametrosAssinaturaJava(metodo[3]!),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
profundidade += contarChar(linha, "{") - contarChar(linha, "}");
|
|
172
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
173
|
+
pilhaClasses.pop();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return [...simbolos.values()];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function extrairRotasJava(codigo: string): RotaJavaExtraida[] {
|
|
181
|
+
const rotas = new Map<string, RotaJavaExtraida>();
|
|
182
|
+
const linhas = codigo.split(/\r?\n/);
|
|
183
|
+
const pilhaClasses: Array<{ nome: string; profundidade: number; rotaBase?: string; rest: boolean }> = [];
|
|
184
|
+
let profundidade = 0;
|
|
185
|
+
|
|
186
|
+
for (let indice = 0; indice < linhas.length; indice += 1) {
|
|
187
|
+
const linhaOriginal = linhas[indice]!;
|
|
188
|
+
const { atributos, proximoIndice } = extrairAtributosJava(linhas, indice);
|
|
189
|
+
if (atributos.length > 0) {
|
|
190
|
+
indice = proximoIndice;
|
|
191
|
+
}
|
|
192
|
+
const linha = (linhas[indice] ?? linhaOriginal).trim();
|
|
193
|
+
if (!linha || linha.startsWith("//")) {
|
|
194
|
+
profundidade += contarChar(linhaOriginal, "{") - contarChar(linhaOriginal, "}");
|
|
195
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
196
|
+
pilhaClasses.pop();
|
|
197
|
+
}
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const classe = linha.match(/\bclass\s+([A-Za-z_]\w*)/);
|
|
202
|
+
if (classe) {
|
|
203
|
+
const rotaBase = atributos
|
|
204
|
+
.filter((atributo) => /@RequestMapping/i.test(atributo))
|
|
205
|
+
.map((atributo) => extrairCaminhoJava(atributo))
|
|
206
|
+
.find(Boolean);
|
|
207
|
+
pilhaClasses.push({
|
|
208
|
+
nome: classe[1]!,
|
|
209
|
+
profundidade: profundidade + 1,
|
|
210
|
+
rotaBase,
|
|
211
|
+
rest: atributos.some((atributo) => /@RestController/i.test(atributo)),
|
|
212
|
+
});
|
|
213
|
+
profundidade += contarChar(linha, "{") - contarChar(linha, "}");
|
|
214
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
215
|
+
pilhaClasses.pop();
|
|
216
|
+
}
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const classeAtual = pilhaClasses[pilhaClasses.length - 1];
|
|
221
|
+
const metodo = linha.match(/\b(?:public|protected)\s+(?:static\s+|final\s+)*([A-Za-z0-9_<>,.?[\]\s]+)\s+([A-Za-z_]\w*)\s*\(([^)]*)\)/);
|
|
222
|
+
if (classeAtual && metodo) {
|
|
223
|
+
for (const atributo of atributos.filter((item) => /@(Get|Post|Put|Patch|Delete)Mapping|@RequestMapping/i.test(item))) {
|
|
224
|
+
const metodos = extrairMetodosJava(atributo);
|
|
225
|
+
const caminho = normalizarCaminhoJava(juntarCaminho(classeAtual.rotaBase, extrairCaminhoJava(atributo)));
|
|
226
|
+
for (const httpMetodo of metodos) {
|
|
227
|
+
const registro: RotaJavaExtraida = {
|
|
228
|
+
origem: "java",
|
|
229
|
+
metodo: httpMetodo,
|
|
230
|
+
caminho,
|
|
231
|
+
simbolo: `${classeAtual.nome}.${metodo[2]!}`,
|
|
232
|
+
parametros: extrairParametrosRotaJava(caminho, metodo[3] ?? ""),
|
|
233
|
+
retorno: metodo[1]!.trim(),
|
|
234
|
+
};
|
|
235
|
+
rotas.set(`${registro.metodo}:${registro.caminho}:${registro.simbolo}`, registro);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
profundidade += contarChar(linha, "{") - contarChar(linha, "}");
|
|
241
|
+
while (pilhaClasses.length > 0 && profundidade < pilhaClasses[pilhaClasses.length - 1]!.profundidade) {
|
|
242
|
+
pilhaClasses.pop();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return [...rotas.values()];
|
|
247
|
+
}
|