nyte 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +59 -0
- package/dist/adapters/express.d.ts +7 -0
- package/dist/adapters/express.js +63 -0
- package/dist/adapters/factory.d.ts +23 -0
- package/dist/adapters/factory.js +121 -0
- package/dist/adapters/fastify.d.ts +25 -0
- package/dist/adapters/fastify.js +61 -0
- package/dist/adapters/native.d.ts +8 -0
- package/dist/adapters/native.js +200 -0
- package/dist/api/console.d.ts +81 -0
- package/dist/api/console.js +318 -0
- package/dist/api/http.d.ts +180 -0
- package/dist/api/http.js +469 -0
- package/dist/bin/nytejs.d.ts +2 -0
- package/dist/bin/nytejs.js +277 -0
- package/dist/builder.d.ts +32 -0
- package/dist/builder.js +634 -0
- package/dist/client/DefaultNotFound.d.ts +1 -0
- package/dist/client/DefaultNotFound.js +79 -0
- package/dist/client/client.d.ts +4 -0
- package/dist/client/client.js +27 -0
- package/dist/client/clientRouter.d.ts +58 -0
- package/dist/client/clientRouter.js +132 -0
- package/dist/client/entry.client.d.ts +1 -0
- package/dist/client/entry.client.js +455 -0
- package/dist/client/rpc.d.ts +8 -0
- package/dist/client/rpc.js +97 -0
- package/dist/components/Link.d.ts +7 -0
- package/dist/components/Link.js +13 -0
- package/dist/global/global.d.ts +117 -0
- package/dist/global/global.js +17 -0
- package/dist/helpers.d.ts +20 -0
- package/dist/helpers.js +604 -0
- package/dist/hotReload.d.ts +32 -0
- package/dist/hotReload.js +545 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +515 -0
- package/dist/loaders.d.ts +1 -0
- package/dist/loaders.js +138 -0
- package/dist/renderer.d.ts +14 -0
- package/dist/renderer.js +380 -0
- package/dist/router.d.ts +101 -0
- package/dist/router.js +659 -0
- package/dist/rpc/server.d.ts +11 -0
- package/dist/rpc/server.js +166 -0
- package/dist/rpc/types.d.ts +22 -0
- package/dist/rpc/types.js +20 -0
- package/dist/types/framework.d.ts +37 -0
- package/dist/types/framework.js +2 -0
- package/dist/types.d.ts +218 -0
- package/dist/types.js +2 -0
- package/package.json +87 -0
- package/src/adapters/express.ts +87 -0
- package/src/adapters/factory.ts +112 -0
- package/src/adapters/fastify.ts +104 -0
- package/src/adapters/native.ts +245 -0
- package/src/api/console.ts +348 -0
- package/src/api/http.ts +535 -0
- package/src/bin/nytejs.js +331 -0
- package/src/builder.js +690 -0
- package/src/client/DefaultNotFound.tsx +119 -0
- package/src/client/client.ts +24 -0
- package/src/client/clientRouter.ts +153 -0
- package/src/client/entry.client.tsx +529 -0
- package/src/client/rpc.ts +101 -0
- package/src/components/Link.tsx +38 -0
- package/src/global/global.ts +171 -0
- package/src/helpers.ts +657 -0
- package/src/hotReload.ts +566 -0
- package/src/index.ts +582 -0
- package/src/loaders.js +160 -0
- package/src/renderer.tsx +421 -0
- package/src/router.ts +732 -0
- package/src/rpc/server.ts +190 -0
- package/src/rpc/types.ts +45 -0
- package/src/types/framework.ts +58 -0
- package/src/types.ts +288 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Levels = exports.Colors = exports.DynamicLine = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* This file is part of the Nyte.js Project.
|
|
9
|
+
* Copyright (c) 2026 itsmuzin
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
const boxen_1 = __importDefault(require("boxen"));
|
|
24
|
+
const node_readline_1 = __importDefault(require("node:readline"));
|
|
25
|
+
/**
|
|
26
|
+
* Um "handle" para uma linha dinâmica. As instâncias desta classe
|
|
27
|
+
* são retornadas por `Console.dynamicLine()` e usadas para controlar
|
|
28
|
+
* o conteúdo da linha.
|
|
29
|
+
*/
|
|
30
|
+
class DynamicLine {
|
|
31
|
+
constructor(initialContent) {
|
|
32
|
+
// A ID é usada internamente pela classe Console para rastrear esta linha.
|
|
33
|
+
this._id = Symbol();
|
|
34
|
+
// Registra esta nova linha na classe Console para que ela seja renderizada.
|
|
35
|
+
Console['registerDynamicLine'](this._id, initialContent);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Atualiza o conteúdo da linha no console.
|
|
39
|
+
* @param newContent O novo texto a ser exibido.
|
|
40
|
+
*/
|
|
41
|
+
update(newContent) {
|
|
42
|
+
Console['updateDynamicLine'](this._id, newContent);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Finaliza a linha, opcionalmente com um texto final, e a torna estática.
|
|
46
|
+
* @param finalContent O texto final a ser exibido.
|
|
47
|
+
*/
|
|
48
|
+
end(finalContent) {
|
|
49
|
+
Console['endDynamicLine'](this._id, finalContent);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.DynamicLine = DynamicLine;
|
|
53
|
+
var Colors;
|
|
54
|
+
(function (Colors) {
|
|
55
|
+
Colors["Reset"] = "\u001B[0m";
|
|
56
|
+
Colors["Bright"] = "\u001B[1m";
|
|
57
|
+
Colors["Dim"] = "\u001B[2m";
|
|
58
|
+
Colors["Underscore"] = "\u001B[4m";
|
|
59
|
+
Colors["Blink"] = "\u001B[5m";
|
|
60
|
+
Colors["Reverse"] = "\u001B[7m";
|
|
61
|
+
Colors["Hidden"] = "\u001B[8m";
|
|
62
|
+
Colors["FgBlack"] = "\u001B[30m";
|
|
63
|
+
Colors["FgRed"] = "\u001B[31m";
|
|
64
|
+
Colors["FgGreen"] = "\u001B[32m";
|
|
65
|
+
Colors["FgYellow"] = "\u001B[33m";
|
|
66
|
+
Colors["FgBlue"] = "\u001B[34m";
|
|
67
|
+
Colors["FgMagenta"] = "\u001B[35m";
|
|
68
|
+
Colors["FgCyan"] = "\u001B[36m";
|
|
69
|
+
Colors["FgWhite"] = "\u001B[37m";
|
|
70
|
+
Colors["FgGray"] = "\u001B[90m";
|
|
71
|
+
Colors["FgAlmostWhite"] = "\u001B[38;2;220;220;220m";
|
|
72
|
+
Colors["BgBlack"] = "\u001B[40m";
|
|
73
|
+
Colors["BgRed"] = "\u001B[41m";
|
|
74
|
+
Colors["BgGreen"] = "\u001B[42m";
|
|
75
|
+
Colors["BgYellow"] = "\u001B[43m";
|
|
76
|
+
Colors["BgBlue"] = "\u001B[44m";
|
|
77
|
+
Colors["BgMagenta"] = "\u001B[45m";
|
|
78
|
+
Colors["BgCyan"] = "\u001B[46m";
|
|
79
|
+
Colors["BgWhite"] = "\u001B[47m";
|
|
80
|
+
Colors["BgGray"] = "\u001B[100m";
|
|
81
|
+
})(Colors || (exports.Colors = Colors = {}));
|
|
82
|
+
var Levels;
|
|
83
|
+
(function (Levels) {
|
|
84
|
+
Levels["ERROR"] = "ERROR";
|
|
85
|
+
Levels["WARN"] = "WARN";
|
|
86
|
+
Levels["INFO"] = "INFO";
|
|
87
|
+
Levels["DEBUG"] = "DEBUG";
|
|
88
|
+
Levels["SUCCESS"] = "SUCCESS";
|
|
89
|
+
})(Levels || (exports.Levels = Levels = {}));
|
|
90
|
+
class Console {
|
|
91
|
+
// --- MÉTODOS PRIVADOS PARA GERENCIAR A RENDERIZAÇÃO ---
|
|
92
|
+
static redrawDynamicLines() {
|
|
93
|
+
const stream = process.stdout;
|
|
94
|
+
if (this.lastRenderedLines > 0) {
|
|
95
|
+
try {
|
|
96
|
+
node_readline_1.default.moveCursor(stream, 0, -this.lastRenderedLines);
|
|
97
|
+
}
|
|
98
|
+
catch (_e) {
|
|
99
|
+
// Em terminais estranhos a movimentação pode falhar — ignoramos.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
node_readline_1.default.cursorTo(stream, 0);
|
|
103
|
+
node_readline_1.default.clearScreenDown(stream);
|
|
104
|
+
if (this.activeLines.length > 0) {
|
|
105
|
+
// ATUALIZADO: Aplica o formato de log (Timestamp + Style) nas linhas dinâmicas
|
|
106
|
+
// Usamos um nível pseudo 'WAIT' para indicar processo em andamento
|
|
107
|
+
stream.write(this.activeLines.map(l => this.formatLog('WAIT', l.content, Colors.FgCyan)).join('\n') + '\n');
|
|
108
|
+
}
|
|
109
|
+
this.lastRenderedLines = this.activeLines.length;
|
|
110
|
+
}
|
|
111
|
+
static writeStatic(content) {
|
|
112
|
+
const stream = process.stdout;
|
|
113
|
+
if (this.lastRenderedLines > 0) {
|
|
114
|
+
try {
|
|
115
|
+
node_readline_1.default.moveCursor(stream, 0, -this.lastRenderedLines);
|
|
116
|
+
}
|
|
117
|
+
catch (_e) { }
|
|
118
|
+
node_readline_1.default.cursorTo(stream, 0);
|
|
119
|
+
node_readline_1.default.clearScreenDown(stream);
|
|
120
|
+
}
|
|
121
|
+
if (!content.endsWith('\n'))
|
|
122
|
+
content += '\n';
|
|
123
|
+
stream.write(content);
|
|
124
|
+
if (this.activeLines.length > 0) {
|
|
125
|
+
// ATUALIZADO: Garante que ao redesenhar após um log estático, o formato se mantém
|
|
126
|
+
stream.write(this.activeLines.map(l => this.formatLog('WAIT', l.content, Colors.FgCyan)).join('\n') + '\n');
|
|
127
|
+
this.lastRenderedLines = this.activeLines.length;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this.lastRenderedLines = 0;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// --- HELPER DE FORMATAÇÃO CENTRALIZADO ---
|
|
134
|
+
static formatLog(level, message, color) {
|
|
135
|
+
let icon = '•';
|
|
136
|
+
let baseColor = Colors.FgWhite;
|
|
137
|
+
switch (level) {
|
|
138
|
+
// ✕ : Multiplication X (Matemático, sempre texto)
|
|
139
|
+
case Levels.ERROR:
|
|
140
|
+
icon = '✕';
|
|
141
|
+
baseColor = Colors.FgRed;
|
|
142
|
+
break;
|
|
143
|
+
// ⚠ : Muitas vezes vira emoji. O triângulo ▲ é mais seguro e fica bonito colorido
|
|
144
|
+
// Alternativa: '‼'
|
|
145
|
+
case Levels.WARN:
|
|
146
|
+
icon = '▲';
|
|
147
|
+
baseColor = Colors.FgYellow;
|
|
148
|
+
break;
|
|
149
|
+
// ℹ : Vira emoji. O '𝐢' é um "i" matemático em negrito (Math Bold Small I)
|
|
150
|
+
// Ele mantém a cor que você definir e parece muito um ícone.
|
|
151
|
+
case Levels.INFO:
|
|
152
|
+
icon = '𝐢';
|
|
153
|
+
baseColor = Colors.FgCyan;
|
|
154
|
+
break;
|
|
155
|
+
// ✔ : Às vezes vira emoji verde. O '✓' simples costuma obedecer a cor.
|
|
156
|
+
// Se der erro, use '√' (raiz quadrada)
|
|
157
|
+
case Levels.SUCCESS:
|
|
158
|
+
icon = '✓';
|
|
159
|
+
baseColor = Colors.FgGreen;
|
|
160
|
+
break;
|
|
161
|
+
// ⚙ : Vira emoji cinza. Use '›' ou '»' ou '⌗' para debug
|
|
162
|
+
case Levels.DEBUG:
|
|
163
|
+
icon = '›';
|
|
164
|
+
baseColor = Colors.FgMagenta;
|
|
165
|
+
break;
|
|
166
|
+
// ⟳ : Esse costuma funcionar, mas se virar emoji, use '∞' ou '…'
|
|
167
|
+
case 'WAIT':
|
|
168
|
+
icon = '∞';
|
|
169
|
+
baseColor = Colors.FgCyan;
|
|
170
|
+
break;
|
|
171
|
+
default:
|
|
172
|
+
icon = '•';
|
|
173
|
+
baseColor = color || Colors.FgWhite;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (color) {
|
|
177
|
+
baseColor = color;
|
|
178
|
+
}
|
|
179
|
+
const gray = Colors.FgGray;
|
|
180
|
+
const bold = Colors.Bright;
|
|
181
|
+
const reset = Colors.Reset;
|
|
182
|
+
const now = new Date();
|
|
183
|
+
const time = now.toLocaleTimeString('pt-BR', { hour12: false });
|
|
184
|
+
// Retorna a string formatada SEM quebra de linha (quem chama decide onde por)
|
|
185
|
+
return ` ${gray}${time}${reset} ${Colors.Bright + baseColor}${icon} ${bold}${level}${reset} ${message}`;
|
|
186
|
+
}
|
|
187
|
+
// --- MÉTODOS CHAMADOS PELA CLASSE DynamicLine ---
|
|
188
|
+
static registerDynamicLine(id, content) {
|
|
189
|
+
this.activeLines.push({ id, content });
|
|
190
|
+
this.redrawDynamicLines();
|
|
191
|
+
}
|
|
192
|
+
static updateDynamicLine(id, newContent) {
|
|
193
|
+
const line = this.activeLines.find(l => l.id === id);
|
|
194
|
+
if (line) {
|
|
195
|
+
line.content = newContent;
|
|
196
|
+
this.redrawDynamicLines();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
static endDynamicLine(id, finalContent) {
|
|
200
|
+
const lineIndex = this.activeLines.findIndex(l => l.id === id);
|
|
201
|
+
if (lineIndex > -1) {
|
|
202
|
+
this.activeLines.splice(lineIndex, 1);
|
|
203
|
+
// ATUALIZADO: Formata a mensagem final como INFO (ou SUCCESS implícito)
|
|
204
|
+
// para manter consistência visual com o resto dos logs.
|
|
205
|
+
this.writeStatic(this.formatLog(Levels.INFO, finalContent) + '\n');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// --- MÉTODOS DE LOG PÚBLICOS ---
|
|
209
|
+
static error(...args) { this.log(Levels.ERROR, null, ...args); }
|
|
210
|
+
static warn(...args) { this.log(Levels.WARN, null, ...args); }
|
|
211
|
+
static info(...args) { this.log(Levels.INFO, null, ...args); }
|
|
212
|
+
static success(...args) { this.log(Levels.SUCCESS, null, ...args); }
|
|
213
|
+
static debug(...args) { this.log(Levels.DEBUG, null, ...args); }
|
|
214
|
+
static logCustomLevel(levelName, without = true, color, ...args) {
|
|
215
|
+
if (without) {
|
|
216
|
+
this.logWithout(levelName, color, ...args);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
this.log(levelName, color, ...args);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
static logWithout(level, colors, ...args) {
|
|
223
|
+
this.log(level, colors, ...args);
|
|
224
|
+
}
|
|
225
|
+
static log(level, colors, ...args) {
|
|
226
|
+
let output = "";
|
|
227
|
+
for (const arg of args) {
|
|
228
|
+
let msg = (arg instanceof Error) ? arg.stack : (typeof arg === 'string') ? arg : JSON.stringify(arg, null, 2);
|
|
229
|
+
if (msg) {
|
|
230
|
+
// ATUALIZADO: Usa o helper formatLog
|
|
231
|
+
output += this.formatLog(level, msg, colors) + '\n';
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Remove a última quebra de linha porque writeStatic já garante uma
|
|
235
|
+
this.writeStatic(output.replace(/\n$/, ''));
|
|
236
|
+
}
|
|
237
|
+
// --- OUTROS MÉTODOS ---
|
|
238
|
+
static async ask(question, defaultValue) {
|
|
239
|
+
const stream = process.stdout;
|
|
240
|
+
if (this.lastRenderedLines > 0) {
|
|
241
|
+
try {
|
|
242
|
+
node_readline_1.default.moveCursor(stream, 0, -this.lastRenderedLines);
|
|
243
|
+
}
|
|
244
|
+
catch (_e) { }
|
|
245
|
+
node_readline_1.default.cursorTo(stream, 0);
|
|
246
|
+
node_readline_1.default.clearScreenDown(stream);
|
|
247
|
+
}
|
|
248
|
+
const readlineInterface = node_readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
249
|
+
const defaultPart = defaultValue ? ` (${defaultValue})` : '';
|
|
250
|
+
const prompt = ` ${Colors.FgCyan}?${Colors.Reset} ${question}${Colors.FgGray}${defaultPart}${Colors.Reset} \n ${Colors.FgCyan}➜${Colors.Reset} `;
|
|
251
|
+
return new Promise(resolve => {
|
|
252
|
+
readlineInterface.question(prompt, ans => {
|
|
253
|
+
readlineInterface.close();
|
|
254
|
+
const value = ans.trim();
|
|
255
|
+
this.redrawDynamicLines();
|
|
256
|
+
resolve(value === '' && defaultValue !== undefined ? defaultValue : value);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
static async confirm(message, defaultYes = false) {
|
|
261
|
+
const suffix = defaultYes ? 'Y/n' : 'y/N';
|
|
262
|
+
while (true) {
|
|
263
|
+
const ans = (await this.ask(`${message} ${Colors.FgGray}[${suffix}]${Colors.Reset}`)).toLowerCase();
|
|
264
|
+
if (ans === '')
|
|
265
|
+
return defaultYes;
|
|
266
|
+
if (['y', 'yes', 's', 'sim'].includes(ans))
|
|
267
|
+
return true;
|
|
268
|
+
if (['n', 'no', 'nao', 'não'].includes(ans))
|
|
269
|
+
return false;
|
|
270
|
+
// ATUALIZADO: Formato consistente
|
|
271
|
+
this.writeStatic(` ${Colors.FgRed}✖ Opção inválida.${Colors.Reset}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
static table(data) {
|
|
275
|
+
let rows;
|
|
276
|
+
if (Array.isArray(data)) {
|
|
277
|
+
rows = data.map(row => ({ Field: String(row.Field), Value: String(row.Value) }));
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
rows = Object.entries(data).map(([Field, Value]) => ({ Field, Value: String(Value) }));
|
|
281
|
+
}
|
|
282
|
+
const fieldLen = Math.max(...rows.map(r => r.Field.length), 'Field'.length);
|
|
283
|
+
const valueLen = Math.max(...rows.map(r => r.Value.length), 'Value'.length);
|
|
284
|
+
const h_line = '─'.repeat(fieldLen + 2);
|
|
285
|
+
const v_line = '─'.repeat(valueLen + 2);
|
|
286
|
+
const top = `┌${h_line}┬${v_line}┐`;
|
|
287
|
+
const mid = `├${h_line}┼${v_line}┤`;
|
|
288
|
+
const bottom = `└${h_line}┴${v_line}┘`;
|
|
289
|
+
let output = top + '\n';
|
|
290
|
+
output += `│ ${Colors.Bright}${Colors.FgGreen}${'Field'.padEnd(fieldLen)}${Colors.Reset} │ ${Colors.Bright}${Colors.FgGreen}${'Value'.padEnd(valueLen)}${Colors.Reset} │\n`;
|
|
291
|
+
output += mid + '\n';
|
|
292
|
+
for (const row of rows) {
|
|
293
|
+
output += `│ ${row.Field.padEnd(fieldLen)} │ ${row.Value.padEnd(valueLen)} │\n`;
|
|
294
|
+
}
|
|
295
|
+
output += bottom + '\n';
|
|
296
|
+
this.writeStatic(output);
|
|
297
|
+
}
|
|
298
|
+
static box(content, options) {
|
|
299
|
+
const defaultOptions = {
|
|
300
|
+
padding: 1,
|
|
301
|
+
margin: 1,
|
|
302
|
+
borderStyle: 'round',
|
|
303
|
+
borderColor: 'cyan',
|
|
304
|
+
titleAlignment: 'left',
|
|
305
|
+
};
|
|
306
|
+
const finalOptions = { ...defaultOptions, ...options };
|
|
307
|
+
const boxedContent = (0, boxen_1.default)(content, finalOptions);
|
|
308
|
+
this.writeStatic(boxedContent + '\n');
|
|
309
|
+
}
|
|
310
|
+
static dynamicLine(initialContent) {
|
|
311
|
+
return new DynamicLine(initialContent);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Armazena o estado de todas as linhas dinâmicas ativas
|
|
315
|
+
Console.activeLines = [];
|
|
316
|
+
// Quantas linhas foram efetivamente renderizadas na última operação.
|
|
317
|
+
Console.lastRenderedLines = 0;
|
|
318
|
+
exports.default = Console;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { GenericRequest, GenericResponse, CookieOptions } from '../types/framework';
|
|
2
|
+
/**
|
|
3
|
+
* Abstração sobre a requisição HTTP de entrada.
|
|
4
|
+
* Funciona com qualquer framework web (Express, Fastify, etc.)
|
|
5
|
+
*/
|
|
6
|
+
export declare class NyteRequest {
|
|
7
|
+
/** A requisição genérica parseada pelo adapter */
|
|
8
|
+
private readonly _req;
|
|
9
|
+
constructor(req: GenericRequest);
|
|
10
|
+
private validateAndSanitizeRequest;
|
|
11
|
+
/**
|
|
12
|
+
* Retorna o método HTTP da requisição (GET, POST, etc.)
|
|
13
|
+
*/
|
|
14
|
+
get method(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Retorna a URL completa da requisição
|
|
17
|
+
*/
|
|
18
|
+
get url(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Retorna todos os headers da requisição
|
|
21
|
+
*/
|
|
22
|
+
get headers(): Record<string, string | string[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Retorna um header específico com validação
|
|
25
|
+
*/
|
|
26
|
+
header(name: string): string | string[] | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Retorna todos os query parameters
|
|
29
|
+
*/
|
|
30
|
+
get query(): Record<string, any>;
|
|
31
|
+
/**
|
|
32
|
+
* Retorna todos os parâmetros de rota
|
|
33
|
+
*/
|
|
34
|
+
get params(): Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Retorna todos os cookies
|
|
37
|
+
*/
|
|
38
|
+
get cookies(): Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* Retorna um cookie específico com validação
|
|
41
|
+
*/
|
|
42
|
+
cookie(name: string): string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Retorna o corpo (body) da requisição, já parseado como JSON com validação
|
|
45
|
+
*/
|
|
46
|
+
json<T = any>(): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Retorna o corpo da requisição como texto
|
|
49
|
+
*/
|
|
50
|
+
text(): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Retorna o corpo da requisição como FormData (para uploads)
|
|
53
|
+
*/
|
|
54
|
+
formData(): Promise<any>;
|
|
55
|
+
/**
|
|
56
|
+
* Retorna a requisição original do framework
|
|
57
|
+
*/
|
|
58
|
+
get raw(): any;
|
|
59
|
+
/**
|
|
60
|
+
* Verifica se a requisição tem um content-type específico
|
|
61
|
+
*/
|
|
62
|
+
is(type: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Verifica se a requisição é AJAX/XHR
|
|
65
|
+
*/
|
|
66
|
+
get isAjax(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Retorna o IP do cliente com validação melhorada
|
|
69
|
+
*/
|
|
70
|
+
get ip(): string;
|
|
71
|
+
private isValidIP;
|
|
72
|
+
/**
|
|
73
|
+
* Retorna o User-Agent
|
|
74
|
+
*/
|
|
75
|
+
get userAgent(): string | undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Abstração para construir a resposta HTTP.
|
|
79
|
+
* Funciona com qualquer framework web (Express, Fastify, etc.)
|
|
80
|
+
*/
|
|
81
|
+
export declare class NyteResponse {
|
|
82
|
+
private _status;
|
|
83
|
+
private _headers;
|
|
84
|
+
private _cookies;
|
|
85
|
+
private _body;
|
|
86
|
+
private _sent;
|
|
87
|
+
/**
|
|
88
|
+
* Define o status HTTP da resposta
|
|
89
|
+
*/
|
|
90
|
+
status(code: number): NyteResponse;
|
|
91
|
+
/**
|
|
92
|
+
* Define um header da resposta
|
|
93
|
+
*/
|
|
94
|
+
header(name: string, value: string): NyteResponse;
|
|
95
|
+
/**
|
|
96
|
+
* Define múltiplos headers
|
|
97
|
+
*/
|
|
98
|
+
headers(headers: Record<string, string>): NyteResponse;
|
|
99
|
+
/**
|
|
100
|
+
* Define um cookie
|
|
101
|
+
*/
|
|
102
|
+
cookie(name: string, value: string, options?: CookieOptions): NyteResponse;
|
|
103
|
+
/**
|
|
104
|
+
* Remove um cookie
|
|
105
|
+
*/
|
|
106
|
+
clearCookie(name: string, options?: CookieOptions): NyteResponse;
|
|
107
|
+
/**
|
|
108
|
+
* Envia resposta JSON
|
|
109
|
+
*/
|
|
110
|
+
json(data: any): NyteResponse;
|
|
111
|
+
/**
|
|
112
|
+
* Envia resposta de texto
|
|
113
|
+
*/
|
|
114
|
+
text(data: string): NyteResponse;
|
|
115
|
+
/**
|
|
116
|
+
* Envia resposta HTML
|
|
117
|
+
*/
|
|
118
|
+
html(data: string): NyteResponse;
|
|
119
|
+
/**
|
|
120
|
+
* Envia qualquer tipo de dados
|
|
121
|
+
*/
|
|
122
|
+
send(data: any): NyteResponse;
|
|
123
|
+
/**
|
|
124
|
+
* Redireciona para uma URL
|
|
125
|
+
*/
|
|
126
|
+
redirect(url: string, status?: number): NyteResponse;
|
|
127
|
+
/**
|
|
128
|
+
* Método interno para aplicar a resposta ao objeto de resposta do framework
|
|
129
|
+
*/
|
|
130
|
+
_applyTo(res: GenericResponse): void;
|
|
131
|
+
/**
|
|
132
|
+
* Método de compatibilidade com versão anterior (Express)
|
|
133
|
+
*/
|
|
134
|
+
_send(res: any): void;
|
|
135
|
+
/**
|
|
136
|
+
* Cria uma resposta JSON
|
|
137
|
+
*/
|
|
138
|
+
static json(data: any, options?: {
|
|
139
|
+
status?: number;
|
|
140
|
+
headers?: Record<string, string>;
|
|
141
|
+
}): NyteResponse;
|
|
142
|
+
/**
|
|
143
|
+
* Cria uma resposta de texto
|
|
144
|
+
*/
|
|
145
|
+
static text(data: string, options?: {
|
|
146
|
+
status?: number;
|
|
147
|
+
headers?: Record<string, string>;
|
|
148
|
+
}): NyteResponse;
|
|
149
|
+
/**
|
|
150
|
+
* Cria uma resposta HTML
|
|
151
|
+
*/
|
|
152
|
+
static html(data: string, options?: {
|
|
153
|
+
status?: number;
|
|
154
|
+
headers?: Record<string, string>;
|
|
155
|
+
}): NyteResponse;
|
|
156
|
+
/**
|
|
157
|
+
* Cria um redirecionamento
|
|
158
|
+
*/
|
|
159
|
+
static redirect(url: string, status?: number): NyteResponse;
|
|
160
|
+
/**
|
|
161
|
+
* Cria uma resposta 404
|
|
162
|
+
*/
|
|
163
|
+
static notFound(message?: string): NyteResponse;
|
|
164
|
+
/**
|
|
165
|
+
* Cria uma resposta 500
|
|
166
|
+
*/
|
|
167
|
+
static error(message?: string): NyteResponse;
|
|
168
|
+
/**
|
|
169
|
+
* Cria uma resposta 400
|
|
170
|
+
*/
|
|
171
|
+
static badRequest(message?: string): NyteResponse;
|
|
172
|
+
/**
|
|
173
|
+
* Cria uma resposta 401
|
|
174
|
+
*/
|
|
175
|
+
static unauthorized(message?: string): NyteResponse;
|
|
176
|
+
/**
|
|
177
|
+
* Cria uma resposta 403
|
|
178
|
+
*/
|
|
179
|
+
static forbidden(message?: string): NyteResponse;
|
|
180
|
+
}
|