hightjs 0.4.0 → 0.5.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.
Files changed (125) hide show
  1. package/README.md +48 -116
  2. package/dist/bin/hightjs.js +51 -23
  3. package/dist/builder.js +139 -4
  4. package/dist/client/DefaultNotFound.d.ts +1 -1
  5. package/dist/client/DefaultNotFound.js +72 -46
  6. package/dist/client/client.d.ts +3 -0
  7. package/dist/{client.js → client/client.js} +4 -4
  8. package/dist/client/entry.client.js +39 -29
  9. package/dist/global/global.d.ts +117 -0
  10. package/dist/{auth/types.js → global/global.js} +0 -1
  11. package/dist/helpers.js +80 -2
  12. package/dist/hotReload.js +2 -2
  13. package/dist/index.js +16 -16
  14. package/dist/loaders.d.ts +1 -0
  15. package/dist/loaders.js +46 -0
  16. package/dist/renderer.js +158 -4
  17. package/dist/types.d.ts +44 -0
  18. package/package.json +36 -31
  19. package/.idea/HightJS.iml +0 -9
  20. package/.idea/copilot.data.migration.agent.xml +0 -6
  21. package/.idea/copilot.data.migration.ask.xml +0 -6
  22. package/.idea/copilot.data.migration.ask2agent.xml +0 -6
  23. package/.idea/copilot.data.migration.edit.xml +0 -6
  24. package/.idea/copilotDiffState.xml +0 -67
  25. package/.idea/inspectionProfiles/Project_Default.xml +0 -13
  26. package/.idea/libraries/test_package.xml +0 -9
  27. package/.idea/libraries/ts_commonjs_default_export.xml +0 -9
  28. package/.idea/misc.xml +0 -7
  29. package/.idea/modules.xml +0 -8
  30. package/.idea/vcs.xml +0 -6
  31. package/dist/auth/client.d.ts +0 -24
  32. package/dist/auth/client.js +0 -146
  33. package/dist/auth/components.d.ts +0 -29
  34. package/dist/auth/components.js +0 -100
  35. package/dist/auth/core.d.ts +0 -55
  36. package/dist/auth/core.js +0 -189
  37. package/dist/auth/index.d.ts +0 -7
  38. package/dist/auth/index.js +0 -45
  39. package/dist/auth/jwt.d.ts +0 -41
  40. package/dist/auth/jwt.js +0 -185
  41. package/dist/auth/providers/credentials.d.ts +0 -60
  42. package/dist/auth/providers/credentials.js +0 -97
  43. package/dist/auth/providers/discord.d.ts +0 -63
  44. package/dist/auth/providers/discord.js +0 -190
  45. package/dist/auth/providers/google.d.ts +0 -63
  46. package/dist/auth/providers/google.js +0 -186
  47. package/dist/auth/providers/index.d.ts +0 -2
  48. package/dist/auth/providers/index.js +0 -35
  49. package/dist/auth/providers.d.ts +0 -3
  50. package/dist/auth/providers.js +0 -26
  51. package/dist/auth/react/index.d.ts +0 -6
  52. package/dist/auth/react/index.js +0 -48
  53. package/dist/auth/react.d.ts +0 -22
  54. package/dist/auth/react.js +0 -199
  55. package/dist/auth/routes.d.ts +0 -16
  56. package/dist/auth/routes.js +0 -152
  57. package/dist/auth/types.d.ts +0 -76
  58. package/dist/client.d.ts +0 -3
  59. package/docs/README.md +0 -58
  60. package/docs/arquivos-especiais.md +0 -10
  61. package/docs/autenticacao.md +0 -212
  62. package/docs/checklist.md +0 -9
  63. package/docs/cli.md +0 -72
  64. package/docs/config.md +0 -216
  65. package/docs/estrutura.md +0 -20
  66. package/docs/faq.md +0 -10
  67. package/docs/hot-reload.md +0 -5
  68. package/docs/integracoes.md +0 -240
  69. package/docs/middlewares.md +0 -73
  70. package/docs/rotas-backend.md +0 -45
  71. package/docs/rotas-frontend.md +0 -66
  72. package/docs/seguranca.md +0 -8
  73. package/docs/websocket.md +0 -45
  74. package/example/certs/cert.pem +0 -20
  75. package/example/certs/key.pem +0 -27
  76. package/example/hightjs.config.ts +0 -87
  77. package/example/package-lock.json +0 -1174
  78. package/example/package.json +0 -26
  79. package/example/postcss.config.js +0 -8
  80. package/example/src/backend/auth.ts +0 -42
  81. package/example/src/backend/routes/auth.ts +0 -3
  82. package/example/src/backend/routes/version.ts +0 -13
  83. package/example/src/web/components/Home.tsx +0 -140
  84. package/example/src/web/components/LoginPage.tsx +0 -149
  85. package/example/src/web/globals.css +0 -5
  86. package/example/src/web/layout.tsx +0 -100
  87. package/example/src/web/routes/index.tsx +0 -13
  88. package/example/src/web/routes/login.tsx +0 -30
  89. package/example/tailwind.config.js +0 -12
  90. package/example/tsconfig.json +0 -15
  91. package/src/adapters/express.ts +0 -87
  92. package/src/adapters/factory.ts +0 -112
  93. package/src/adapters/fastify.ts +0 -104
  94. package/src/adapters/native.ts +0 -234
  95. package/src/api/console.ts +0 -305
  96. package/src/api/http.ts +0 -535
  97. package/src/auth/client.ts +0 -171
  98. package/src/auth/components.tsx +0 -125
  99. package/src/auth/core.ts +0 -215
  100. package/src/auth/index.ts +0 -25
  101. package/src/auth/jwt.ts +0 -210
  102. package/src/auth/providers/credentials.ts +0 -139
  103. package/src/auth/providers/discord.ts +0 -239
  104. package/src/auth/providers/google.ts +0 -234
  105. package/src/auth/providers/index.ts +0 -20
  106. package/src/auth/providers.ts +0 -20
  107. package/src/auth/react/index.ts +0 -25
  108. package/src/auth/react.tsx +0 -234
  109. package/src/auth/routes.ts +0 -183
  110. package/src/auth/types.ts +0 -108
  111. package/src/bin/hightjs.js +0 -222
  112. package/src/builder.js +0 -472
  113. package/src/client/DefaultNotFound.tsx +0 -84
  114. package/src/client/clientRouter.ts +0 -153
  115. package/src/client/entry.client.tsx +0 -511
  116. package/src/client.ts +0 -24
  117. package/src/components/Link.tsx +0 -38
  118. package/src/helpers.ts +0 -542
  119. package/src/hotReload.ts +0 -569
  120. package/src/index.ts +0 -555
  121. package/src/renderer.tsx +0 -263
  122. package/src/router.ts +0 -730
  123. package/src/types/framework.ts +0 -58
  124. package/src/types.ts +0 -207
  125. package/tsconfig.json +0 -17
@@ -1,305 +0,0 @@
1
- /*
2
- * This file is part of the HightJS Project.
3
- * Copyright (c) 2025 itsmuzin
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- import boxen, { Options as BoxenOptions } from 'boxen';
18
- import readline from 'node:readline';
19
-
20
- /**
21
- * Um "handle" para uma linha dinâmica. As instâncias desta classe
22
- * são retornadas por `Console.dynamicLine()` e usadas para controlar
23
- * o conteúdo da linha.
24
- */
25
- export class DynamicLine {
26
- // A ID é usada internamente pela classe Console para rastrear esta linha.
27
- private readonly _id = Symbol();
28
-
29
- constructor(initialContent: string) {
30
- // Registra esta nova linha na classe Console para que ela seja renderizada.
31
- Console['registerDynamicLine'](this._id, initialContent);
32
- }
33
-
34
- /**
35
- * Atualiza o conteúdo da linha no console.
36
- * @param newContent O novo texto a ser exibido.
37
- */
38
- update(newContent: string): void {
39
- Console['updateDynamicLine'](this._id, newContent);
40
- }
41
-
42
- /**
43
- * Finaliza a linha, opcionalmente com um texto final, e a torna estática.
44
- * @param finalContent O texto final a ser exibido.
45
- */
46
- end(finalContent: string): void {
47
- Console['endDynamicLine'](this._id, finalContent);
48
- }
49
- }
50
-
51
- export enum Colors {
52
- Reset = "\x1b[0m",
53
- Bright = "\x1b[1m",
54
- Dim = "\x1b[2m",
55
- Underscore = "\x1b[4m",
56
- Blink = "\x1b[5m",
57
- Reverse = "\x1b[7m",
58
- Hidden = "\x1b[8m",
59
-
60
- FgBlack = "\x1b[30m",
61
- FgRed = "\x1b[31m",
62
- FgGreen = "\x1b[32m",
63
- FgYellow = "\x1b[33m",
64
- FgBlue = "\x1b[34m",
65
- FgMagenta = "\x1b[35m",
66
- FgCyan = "\x1b[36m",
67
- FgWhite = "\x1b[37m",
68
- FgGray = "\x1b[90m", // ← adicionado
69
-
70
- BgBlack = "\x1b[40m",
71
- BgRed = "\x1b[41m",
72
- BgGreen = "\x1b[42m",
73
- BgYellow = "\x1b[43m",
74
- BgBlue = "\x1b[44m",
75
- BgMagenta = "\x1b[45m",
76
- BgCyan = "\x1b[46m",
77
- BgWhite = "\x1b[47m",
78
- BgGray = "\x1b[100m", // ← adicionado
79
- }
80
-
81
-
82
- export enum Levels {
83
- ERROR = "ERROR",
84
- WARN = "WARN",
85
- INFO = "INFO",
86
- DEBUG = "DEBUG",
87
- SUCCESS = "SUCCESS"
88
- }
89
-
90
- export default class Console {
91
- // Armazena o estado de todas as linhas dinâmicas ativas
92
- private static activeLines: { id: symbol; content: string }[] = [];
93
-
94
- // Quantas linhas foram efetivamente renderizadas na última operação.
95
- // Usamos esse contador para evitar off-by-one ao mover o cursor para
96
- // redesenhar o bloco dinâmico.
97
- private static lastRenderedLines = 0;
98
-
99
- // --- MÉTODOS PRIVADOS PARA GERENCIAR A RENDERIZAÇÃO ---
100
-
101
- /**
102
- * Limpa todas as linhas dinâmicas da tela e as redesenha com o conteúdo atualizado.
103
- * Observação: usamos lastRenderedLines para saber quantas linhas mover
104
- * o cursor para cima (isso evita mover para cima demais quando uma nova
105
- * linha foi registrada).
106
- */
107
- private static redrawDynamicLines(): void {
108
- const stream = process.stdout;
109
-
110
- // Se anteriormente renderizamos N linhas, movemos o cursor para cima N
111
- // para chegar ao topo do bloco dinâmico. Se N for 0, não movemos.
112
- if (this.lastRenderedLines > 0) {
113
- try {
114
- readline.moveCursor(stream, 0, -this.lastRenderedLines);
115
- } catch (_e) {
116
- // Em terminais estranhos a movimentação pode falhar — ignoramos.
117
- }
118
- }
119
-
120
- // Posiciona no início da linha e limpa tudo abaixo (removendo o bloco antigo).
121
- readline.cursorTo(stream, 0);
122
- readline.clearScreenDown(stream);
123
-
124
- // Reescreve as linhas com o conteúdo atualizado
125
- if (this.activeLines.length > 0) {
126
- stream.write(this.activeLines.map(l => l.content).join('\n') + '\n');
127
- }
128
-
129
- // Atualiza o contador de linhas que agora estão renderizadas.
130
- this.lastRenderedLines = this.activeLines.length;
131
- }
132
-
133
- /**
134
- * Envolve a escrita de texto estático (logs normais) para não interferir
135
- * com as linhas dinâmicas.
136
- */
137
- private static writeStatic(content: string): void {
138
- const stream = process.stdout;
139
-
140
- // Se há um bloco dinâmico na tela, removemos (limpamos) ele antes de
141
- // escrever o conteúdo estático — assim evitamos misturar a saída.
142
- if (this.lastRenderedLines > 0) {
143
- try {
144
- readline.moveCursor(stream, 0, -this.lastRenderedLines);
145
- } catch (_e) {}
146
- readline.cursorTo(stream, 0);
147
- readline.clearScreenDown(stream);
148
- }
149
-
150
- // Garante que o conteúdo termine com quebra de linha.
151
- if (!content.endsWith('\n')) content += '\n';
152
- stream.write(content);
153
-
154
- // Depois de escrever o log estático, redesenhamos o bloco dinâmico abaixo dele.
155
- if (this.activeLines.length > 0) {
156
- stream.write(this.activeLines.map(l => l.content).join('\n') + '\n');
157
- this.lastRenderedLines = this.activeLines.length;
158
- } else {
159
- this.lastRenderedLines = 0;
160
- }
161
- }
162
-
163
- // --- MÉTODOS CHAMADOS PELA CLASSE DynamicLine ---
164
- private static registerDynamicLine(id: symbol, content: string): void {
165
- // Adiciona a nova linha à lista de linhas ativas
166
- this.activeLines.push({ id, content });
167
- // Redesenha todo o bloco (usa lastRenderedLines internamente)
168
- this.redrawDynamicLines();
169
- }
170
-
171
- private static updateDynamicLine(id: symbol, newContent: string): void {
172
- const line = this.activeLines.find(l => l.id === id);
173
- if (line) {
174
- line.content = newContent;
175
- this.redrawDynamicLines();
176
- }
177
- }
178
-
179
- private static endDynamicLine(id: symbol, finalContent: string): void {
180
- const lineIndex = this.activeLines.findIndex(l => l.id === id);
181
- if (lineIndex > -1) {
182
- // Remove a linha da lista de ativas.
183
- this.activeLines.splice(lineIndex, 1);
184
-
185
- // Escreve o conteúdo final como uma linha estática.
186
- // writeStatic cuidará de limpar e redesenhar as linhas dinâmicas
187
- // restantes no lugar certo.
188
- this.writeStatic(finalContent + '\n');
189
- }
190
- }
191
-
192
- // --- MÉTODOS DE LOG PÚBLICOS (MODIFICADOS) ---
193
- static error(...args: any[]): void { this.log(Levels.ERROR, ...args); }
194
- static warn(...args: any[]): void { this.log(Levels.WARN, ...args); }
195
- static info(...args: any[]): void { this.log(Levels.INFO, ...args); }
196
- static success(...args: any[]): void { this.log(Levels.SUCCESS, ...args); }
197
- static debug(...args: any[]): void { this.log(Levels.DEBUG, ...args); }
198
-
199
- static logCustomLevel(levelName: string, without: boolean = true, color?: Colors, ...args: any[]): void {
200
- if (without) { this.logWithout(levelName as Levels, color, ...args); }
201
- else { this.log(levelName as Levels, color, ...args); }
202
- }
203
-
204
- static logWithout(level: Levels, colors?:Colors, ...args: any[]): void {
205
-
206
- const color = colors ? colors : level === Levels.ERROR ? Colors.BgRed : level === Levels.WARN ? Colors.BgYellow : level === Levels.INFO ? Colors.BgMagenta : level === Levels.SUCCESS ? Colors.BgGreen : Colors.BgCyan;
207
-
208
- let output = "";
209
- for (const arg of args) {
210
- let msg = (arg instanceof Error) ? arg.stack : (typeof arg === 'string') ? arg : JSON.stringify(arg, null, 2);
211
- if (msg) output += ` ${color} ${level} ${Colors.Reset} ${msg}\n`;
212
- }
213
- this.writeStatic(output);
214
- }
215
-
216
- static log(level: Levels, colors?: Colors, ...args: any[]): void {
217
- const color = colors || level === Levels.ERROR ? Colors.BgRed : level === Levels.WARN ? Colors.BgYellow : level === Levels.INFO ? Colors.BgMagenta : level === Levels.SUCCESS ? Colors.BgGreen : Colors.BgCyan;
218
- let output = "\n";
219
- for (const arg of args) {
220
- let msg = (arg instanceof Error) ? arg.stack : (typeof arg === 'string') ? arg : JSON.stringify(arg, null, 2);
221
- if (msg) output += ` ${color} ${level} ${Colors.Reset} ${msg}\n`;
222
- }
223
- this.writeStatic(output);
224
- }
225
-
226
- // --- OUTROS MÉTODOS ---
227
- static async ask(question: string, defaultValue?: string): Promise<string> {
228
- // Garantimos que o bloco dinâmico atual seja temporariamente removido
229
- // (redesenhado depois) para não poluir o prompt.
230
- const stream = process.stdout;
231
- if (this.lastRenderedLines > 0) {
232
- try { readline.moveCursor(stream, 0, -this.lastRenderedLines); } catch (_e) {}
233
- readline.cursorTo(stream, 0);
234
- readline.clearScreenDown(stream);
235
- }
236
-
237
- const readlineInterface = readline.createInterface({ input: process.stdin, output: process.stdout });
238
- const coloredQuestion = ` ${Colors.FgMagenta}${question}${Colors.Reset}`;
239
- const defaultValuePart = defaultValue ? ` [${Colors.Reset}${Colors.FgCyan}${defaultValue}${Colors.Reset}]` : '';
240
- const fullPrompt = `${coloredQuestion}${defaultValuePart}:\n > `;
241
-
242
- return new Promise(resolve => {
243
- readlineInterface.question(fullPrompt, ans => {
244
- readlineInterface.close();
245
- const value = ans.trim();
246
- // Redesenha as linhas dinâmicas após o prompt
247
- this.redrawDynamicLines();
248
- resolve(value === '' && defaultValue !== undefined ? defaultValue : value);
249
- });
250
- });
251
- }
252
-
253
- static async confirm(message: string, defaultYes = false): Promise<boolean> {
254
- const suffix = defaultYes ? 'yes' : 'no';
255
- while (true) {
256
- const ans = (await this.ask(message + " (yes/no)", suffix)).toLowerCase();
257
- if (!ans) return defaultYes;
258
- if (['y','yes'].includes(ans)) return true;
259
- if (['n','no'].includes(ans)) return false;
260
- this.warn('Resposta inválida, digite y ou n.');
261
- }
262
- }
263
-
264
- static table(data: Record<string, any> | Array<{ Field: string, Value: any }>): void {
265
- let rows: Array<{ Field: string, Value: any }>;
266
- if (Array.isArray(data)) {
267
- rows = data.map(row => ({ Field: String(row.Field), Value: String(row.Value) }));
268
- } else {
269
- rows = Object.entries(data).map(([Field, Value]) => ({ Field, Value: String(Value) }));
270
- }
271
- const fieldLen = Math.max(...rows.map(r => r.Field.length), 'Field'.length);
272
- const valueLen = Math.max(...rows.map(r => r.Value.length), 'Value'.length);
273
- const sep = `+${'-'.repeat(fieldLen+2)}+${'-'.repeat(valueLen+2)}+`;
274
- let output = sep + '\n';
275
- output += `| ${Colors.FgGreen}${'Field'.padEnd(fieldLen)}${Colors.Reset} | ${Colors.FgGreen}${'Value'.padEnd(valueLen)}${Colors.Reset} |\n`;
276
- output += sep + '\n';
277
- for (const row of rows) {
278
- output += `| ${row.Field.padEnd(fieldLen)} | ${row.Value.padEnd(valueLen)} |\n`;
279
- }
280
- output += sep + '\n';
281
- this.writeStatic(output);
282
- }
283
-
284
- static box(content: string, options?: BoxenOptions): void {
285
- const defaultOptions: BoxenOptions = {
286
- padding: 1,
287
- margin: 1,
288
- borderStyle: 'round',
289
- borderColor: 'whiteBright',
290
- titleAlignment: 'left',
291
- };
292
- const finalOptions = { ...defaultOptions, ...options };
293
- const boxedContent = boxen(content, finalOptions);
294
- this.writeStatic(boxedContent + '\n');
295
- }
296
-
297
- /**
298
- * Cria e retorna um controlador para uma linha dinâmica no console.
299
- * @param initialContent O conteúdo inicial a ser exibido.
300
- * @returns Uma instância de DynamicLine para controlar a linha.
301
- */
302
- static dynamicLine(initialContent: string): DynamicLine {
303
- return new DynamicLine(initialContent);
304
- }
305
- }