hightjs 0.1.1
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/.idea/HightJS.iml +9 -0
- package/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +13 -0
- package/.idea/libraries/test_package.xml +9 -0
- package/.idea/libraries/ts_commonjs_default_export.xml +9 -0
- package/.idea/misc.xml +7 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +13 -0
- package/README.md +508 -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 +122 -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 +203 -0
- package/dist/adapters/starters/express.d.ts +0 -0
- package/dist/adapters/starters/express.js +1 -0
- package/dist/adapters/starters/factory.d.ts +0 -0
- package/dist/adapters/starters/factory.js +1 -0
- package/dist/adapters/starters/fastify.d.ts +0 -0
- package/dist/adapters/starters/fastify.js +1 -0
- package/dist/adapters/starters/index.d.ts +0 -0
- package/dist/adapters/starters/index.js +1 -0
- package/dist/adapters/starters/native.d.ts +0 -0
- package/dist/adapters/starters/native.js +1 -0
- package/dist/api/console.d.ts +92 -0
- package/dist/api/console.js +276 -0
- package/dist/api/http.d.ts +180 -0
- package/dist/api/http.js +467 -0
- package/dist/auth/client.d.ts +14 -0
- package/dist/auth/client.js +68 -0
- package/dist/auth/components.d.ts +29 -0
- package/dist/auth/components.js +84 -0
- package/dist/auth/core.d.ts +38 -0
- package/dist/auth/core.js +124 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.js +27 -0
- package/dist/auth/jwt.d.ts +41 -0
- package/dist/auth/jwt.js +169 -0
- package/dist/auth/providers.d.ts +5 -0
- package/dist/auth/providers.js +14 -0
- package/dist/auth/react/index.d.ts +6 -0
- package/dist/auth/react/index.js +32 -0
- package/dist/auth/react.d.ts +22 -0
- package/dist/auth/react.js +175 -0
- package/dist/auth/routes.d.ts +16 -0
- package/dist/auth/routes.js +104 -0
- package/dist/auth/types.d.ts +62 -0
- package/dist/auth/types.js +2 -0
- package/dist/bin/hightjs.d.ts +2 -0
- package/dist/bin/hightjs.js +35 -0
- package/dist/builder.d.ts +32 -0
- package/dist/builder.js +341 -0
- package/dist/client/DefaultNotFound.d.ts +1 -0
- package/dist/client/DefaultNotFound.js +53 -0
- package/dist/client/ErrorBoundary.d.ts +16 -0
- package/dist/client/ErrorBoundary.js +181 -0
- package/dist/client/clientRouter.d.ts +58 -0
- package/dist/client/clientRouter.js +116 -0
- package/dist/client/entry.client.d.ts +1 -0
- package/dist/client/entry.client.js +271 -0
- package/dist/client/routerContext.d.ts +26 -0
- package/dist/client/routerContext.js +62 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.js +8 -0
- package/dist/components/Link.d.ts +7 -0
- package/dist/components/Link.js +13 -0
- package/dist/eslint/index.d.ts +32 -0
- package/dist/eslint/index.js +15 -0
- package/dist/eslint/use-client-rule.d.ts +19 -0
- package/dist/eslint/use-client-rule.js +99 -0
- package/dist/eslintSetup.d.ts +0 -0
- package/dist/eslintSetup.js +1 -0
- package/dist/example/src/web/routes/index.d.ts +3 -0
- package/dist/example/src/web/routes/index.js +15 -0
- package/dist/helpers.d.ts +18 -0
- package/dist/helpers.js +318 -0
- package/dist/hotReload.d.ts +23 -0
- package/dist/hotReload.js +292 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +480 -0
- package/dist/renderer.d.ts +14 -0
- package/dist/renderer.js +106 -0
- package/dist/router.d.ts +78 -0
- package/dist/router.js +359 -0
- package/dist/types/framework.d.ts +37 -0
- package/dist/types/framework.js +2 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.js +2 -0
- package/dist/typescript/use-client-plugin.d.ts +5 -0
- package/dist/typescript/use-client-plugin.js +113 -0
- package/dist/validation.d.ts +0 -0
- package/dist/validation.js +1 -0
- package/package.json +72 -0
- package/src/adapters/express.ts +70 -0
- package/src/adapters/factory.ts +96 -0
- package/src/adapters/fastify.ts +88 -0
- package/src/adapters/native.ts +223 -0
- package/src/api/console.ts +285 -0
- package/src/api/http.ts +515 -0
- package/src/auth/client.ts +74 -0
- package/src/auth/components.tsx +109 -0
- package/src/auth/core.ts +143 -0
- package/src/auth/index.ts +9 -0
- package/src/auth/jwt.ts +194 -0
- package/src/auth/providers.ts +13 -0
- package/src/auth/react/index.ts +9 -0
- package/src/auth/react.tsx +209 -0
- package/src/auth/routes.ts +133 -0
- package/src/auth/types.ts +73 -0
- package/src/bin/hightjs.js +40 -0
- package/src/builder.js +362 -0
- package/src/client/DefaultNotFound.tsx +68 -0
- package/src/client/clientRouter.ts +137 -0
- package/src/client/entry.client.tsx +302 -0
- package/src/client.ts +8 -0
- package/src/components/Link.tsx +22 -0
- package/src/helpers.ts +316 -0
- package/src/hotReload.ts +289 -0
- package/src/index.ts +514 -0
- package/src/renderer.tsx +122 -0
- package/src/router.ts +400 -0
- package/src/types/framework.ts +42 -0
- package/src/types.ts +54 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.HotReloadManager = void 0;
|
|
37
|
+
const ws_1 = require("ws");
|
|
38
|
+
const chokidar = __importStar(require("chokidar"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const router_1 = require("./router");
|
|
41
|
+
const console_1 = __importStar(require("./api/console"));
|
|
42
|
+
class HotReloadManager {
|
|
43
|
+
constructor(projectDir) {
|
|
44
|
+
this.wss = null;
|
|
45
|
+
this.watchers = [];
|
|
46
|
+
this.clients = new Set();
|
|
47
|
+
this.pingInterval = null;
|
|
48
|
+
this.backendApiChangeCallback = null;
|
|
49
|
+
this.frontendChangeCallback = null;
|
|
50
|
+
this.projectDir = projectDir;
|
|
51
|
+
}
|
|
52
|
+
async start() {
|
|
53
|
+
// Não cria servidor na porta separada - será integrado ao Express
|
|
54
|
+
this.setupWatchers();
|
|
55
|
+
}
|
|
56
|
+
// Novo método para integrar com Express
|
|
57
|
+
handleUpgrade(request, socket, head) {
|
|
58
|
+
if (!this.wss) {
|
|
59
|
+
this.wss = new ws_1.WebSocketServer({ noServer: true });
|
|
60
|
+
this.setupWebSocketServer();
|
|
61
|
+
}
|
|
62
|
+
this.wss.handleUpgrade(request, socket, head, (ws) => {
|
|
63
|
+
this.wss.emit('connection', ws, request);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
setupWebSocketServer() {
|
|
67
|
+
if (!this.wss)
|
|
68
|
+
return;
|
|
69
|
+
this.wss.on('connection', (ws) => {
|
|
70
|
+
this.clients.add(ws);
|
|
71
|
+
// Setup ping/pong para manter conexão viva
|
|
72
|
+
const ping = () => {
|
|
73
|
+
if (ws.readyState === ws_1.WebSocket.OPEN) {
|
|
74
|
+
ws.ping();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const pingTimer = setInterval(ping, 30000); // Ping a cada 30 segundos
|
|
78
|
+
ws.on('pong', () => {
|
|
79
|
+
// Cliente respondeu ao ping - conexão ainda ativa
|
|
80
|
+
});
|
|
81
|
+
ws.on('close', () => {
|
|
82
|
+
this.clients.delete(ws);
|
|
83
|
+
clearInterval(pingTimer);
|
|
84
|
+
});
|
|
85
|
+
ws.on('error', () => {
|
|
86
|
+
this.clients.delete(ws);
|
|
87
|
+
clearInterval(pingTimer);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
setupWatchers() {
|
|
92
|
+
// 1. Watcher para arquivos frontend (rotas, componentes) - EXCLUINDO backend
|
|
93
|
+
const frontendWatcher = chokidar.watch([
|
|
94
|
+
path.join(this.projectDir, 'src/web/**/*.{tsx,ts,jsx,js}'),
|
|
95
|
+
], {
|
|
96
|
+
ignored: [
|
|
97
|
+
/(^|[\/\\])\../, // arquivos ocultos
|
|
98
|
+
path.join(this.projectDir, 'src/web/backend/**/*') // exclui toda a pasta backend
|
|
99
|
+
],
|
|
100
|
+
persistent: true,
|
|
101
|
+
ignoreInitial: true
|
|
102
|
+
});
|
|
103
|
+
frontendWatcher.on('change', async (filePath) => {
|
|
104
|
+
console_1.default.logWithout(console_1.Levels.INFO, `🔄 Frontend alterado: ${filePath}`);
|
|
105
|
+
(0, router_1.clearFileCache)(filePath);
|
|
106
|
+
// Checa build do arquivo alterado
|
|
107
|
+
const result = await this.checkFrontendBuild(filePath);
|
|
108
|
+
if (result.error) {
|
|
109
|
+
this.notifyClients('frontend-error', { file: filePath, error: result.error });
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.frontendChangeCallback?.();
|
|
113
|
+
this.notifyClients('frontend-reload');
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
frontendWatcher.on('add', async (filePath) => {
|
|
117
|
+
console_1.default.info(`➕ Novo arquivo frontend: ${path.basename(filePath)}`);
|
|
118
|
+
const result = await this.checkFrontendBuild(filePath);
|
|
119
|
+
if (result.error) {
|
|
120
|
+
this.notifyClients('frontend-error', { file: filePath, error: result.error });
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.frontendChangeCallback?.();
|
|
124
|
+
this.notifyClients('frontend-reload');
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
frontendWatcher.on('unlink', (filePath) => {
|
|
128
|
+
console_1.default.info(`🗑️ Arquivo frontend removido: ${path.basename(filePath)}`);
|
|
129
|
+
(0, router_1.clearFileCache)(filePath);
|
|
130
|
+
this.frontendChangeCallback?.();
|
|
131
|
+
this.notifyClients('frontend-reload');
|
|
132
|
+
});
|
|
133
|
+
// 2. Watcher específico para rotas de API backend
|
|
134
|
+
const backendApiWatcher = chokidar.watch([
|
|
135
|
+
path.join(this.projectDir, 'src/web/backend/routes/**/*.{ts,tsx,js,jsx}'),
|
|
136
|
+
], {
|
|
137
|
+
ignored: /(^|[\/\\])\../,
|
|
138
|
+
persistent: true,
|
|
139
|
+
ignoreInitial: true
|
|
140
|
+
});
|
|
141
|
+
backendApiWatcher.on('change', (filePath) => {
|
|
142
|
+
console_1.default.info(`🔄 API backend alterada: ${path.basename(filePath)}`);
|
|
143
|
+
this.clearBackendCache(filePath);
|
|
144
|
+
this.notifyClients('backend-api-reload');
|
|
145
|
+
// Chama o callback, se definido
|
|
146
|
+
this.backendApiChangeCallback?.();
|
|
147
|
+
});
|
|
148
|
+
backendApiWatcher.on('add', (filePath) => {
|
|
149
|
+
console_1.default.info(`➕ Nova API backend: ${path.basename(filePath)}`);
|
|
150
|
+
this.notifyClients('backend-api-reload');
|
|
151
|
+
});
|
|
152
|
+
backendApiWatcher.on('unlink', (filePath) => {
|
|
153
|
+
console_1.default.info(`🗑️ API backend removida: ${path.basename(filePath)}`);
|
|
154
|
+
this.clearBackendCache(filePath);
|
|
155
|
+
this.notifyClients('backend-api-reload');
|
|
156
|
+
});
|
|
157
|
+
// 3. Watcher para arquivos backend (server.ts, configs)
|
|
158
|
+
const backendWatcher = chokidar.watch([
|
|
159
|
+
path.join(this.projectDir, 'src/server.ts'),
|
|
160
|
+
path.join(this.projectDir, 'src/**/*.ts'),
|
|
161
|
+
'!**/src/web/**', // exclui pasta web
|
|
162
|
+
], {
|
|
163
|
+
ignored: /(^|[\/\\])\../,
|
|
164
|
+
persistent: true,
|
|
165
|
+
ignoreInitial: true
|
|
166
|
+
});
|
|
167
|
+
backendWatcher.on('change', () => {
|
|
168
|
+
this.restartServer();
|
|
169
|
+
});
|
|
170
|
+
this.watchers.push(frontendWatcher, backendApiWatcher, backendWatcher);
|
|
171
|
+
}
|
|
172
|
+
notifyClients(type, data) {
|
|
173
|
+
const message = JSON.stringify({ type, data, timestamp: Date.now() });
|
|
174
|
+
this.clients.forEach((client) => {
|
|
175
|
+
if (client.readyState === ws_1.WebSocket.OPEN) {
|
|
176
|
+
client.send(message);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
restartServer() {
|
|
181
|
+
// Notifica clientes que o servidor está reiniciando
|
|
182
|
+
this.notifyClients('server-restart');
|
|
183
|
+
// Aguarda um pouco e tenta reconectar
|
|
184
|
+
setTimeout(() => {
|
|
185
|
+
this.notifyClients('server-ready');
|
|
186
|
+
}, 2000);
|
|
187
|
+
}
|
|
188
|
+
stop() {
|
|
189
|
+
// Para todos os watchers
|
|
190
|
+
this.watchers.forEach(watcher => watcher.close());
|
|
191
|
+
this.watchers = [];
|
|
192
|
+
// Para ping interval
|
|
193
|
+
if (this.pingInterval) {
|
|
194
|
+
clearInterval(this.pingInterval);
|
|
195
|
+
}
|
|
196
|
+
// Fecha WebSocket server
|
|
197
|
+
if (this.wss) {
|
|
198
|
+
this.wss.close();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Retorna o script do cliente para injetar no HTML
|
|
202
|
+
getClientScript() {
|
|
203
|
+
return `
|
|
204
|
+
<script>
|
|
205
|
+
(function() {
|
|
206
|
+
if (typeof window !== 'undefined') {
|
|
207
|
+
let ws;
|
|
208
|
+
let reconnectInterval;
|
|
209
|
+
|
|
210
|
+
function connect() {
|
|
211
|
+
ws = new WebSocket('ws://localhost:3000/hweb-hotreload/');
|
|
212
|
+
|
|
213
|
+
ws.onopen = function() {
|
|
214
|
+
clearInterval(reconnectInterval);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
ws.onmessage = function(event) {
|
|
218
|
+
const message = JSON.parse(event.data);
|
|
219
|
+
|
|
220
|
+
switch(message.type) {
|
|
221
|
+
case 'frontend-reload':
|
|
222
|
+
window.location.reload();
|
|
223
|
+
break;
|
|
224
|
+
case 'server-restart':
|
|
225
|
+
break;
|
|
226
|
+
case 'server-ready':
|
|
227
|
+
setTimeout(() => window.location.reload(), 500);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
ws.onclose = function() {
|
|
233
|
+
reconnectInterval = setInterval(() => {
|
|
234
|
+
connect();
|
|
235
|
+
}, 1000);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
ws.onerror = function() {
|
|
239
|
+
// Silencioso - sem logs
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
connect();
|
|
244
|
+
}
|
|
245
|
+
})();
|
|
246
|
+
</script>
|
|
247
|
+
`;
|
|
248
|
+
}
|
|
249
|
+
clearBackendCache(filePath) {
|
|
250
|
+
// Limpa o cache do require para forçar reload da rota de API
|
|
251
|
+
const absolutePath = path.resolve(filePath);
|
|
252
|
+
delete require.cache[absolutePath];
|
|
253
|
+
// Também limpa dependências relacionadas
|
|
254
|
+
Object.keys(require.cache).forEach(key => {
|
|
255
|
+
if (key.includes(path.dirname(absolutePath))) {
|
|
256
|
+
delete require.cache[key];
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
// Método para registrar callback de mudança de API backend
|
|
261
|
+
onBackendApiChange(callback) {
|
|
262
|
+
this.backendApiChangeCallback = callback;
|
|
263
|
+
}
|
|
264
|
+
// Método para registrar callback de mudança de frontend
|
|
265
|
+
onFrontendChange(callback) {
|
|
266
|
+
this.frontendChangeCallback = callback;
|
|
267
|
+
}
|
|
268
|
+
async checkFrontendBuild(filePath) {
|
|
269
|
+
// Usa ts-node para checar erros de compilação do arquivo alterado
|
|
270
|
+
const tsNodePath = require.resolve('ts-node');
|
|
271
|
+
const { spawn } = require('child_process');
|
|
272
|
+
return new Promise((resolve) => {
|
|
273
|
+
const proc = spawn(process.execPath, [tsNodePath, '--transpile-only', filePath], {
|
|
274
|
+
cwd: this.projectDir,
|
|
275
|
+
env: process.env,
|
|
276
|
+
});
|
|
277
|
+
let errorMsg = '';
|
|
278
|
+
proc.stderr.on('data', (data) => {
|
|
279
|
+
errorMsg += data.toString();
|
|
280
|
+
});
|
|
281
|
+
proc.on('close', (code) => {
|
|
282
|
+
if (code !== 0 && errorMsg) {
|
|
283
|
+
resolve({ error: errorMsg });
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
resolve({});
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
exports.HotReloadManager = HotReloadManager;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HightJSOptions, RequestHandler, BackendRouteConfig, BackendHandler } from './types';
|
|
2
|
+
import { HightJSRequest, HightJSResponse } from './api/http';
|
|
3
|
+
export { HightJSRequest, HightJSResponse };
|
|
4
|
+
export type { BackendRouteConfig, BackendHandler };
|
|
5
|
+
export { ExpressAdapter } from './adapters/express';
|
|
6
|
+
export { FastifyAdapter } from './adapters/fastify';
|
|
7
|
+
export { FrameworkAdapterFactory } from './adapters/factory';
|
|
8
|
+
export type { GenericRequest, GenericResponse, CookieOptions } from './types/framework';
|
|
9
|
+
export { app } from './helpers';
|
|
10
|
+
export default function hweb(options: HightJSOptions): {
|
|
11
|
+
prepare: () => Promise<void>;
|
|
12
|
+
executeInstrumentation: () => void;
|
|
13
|
+
getRequestHandler: () => RequestHandler;
|
|
14
|
+
setupWebSocket: (server: any) => void;
|
|
15
|
+
build: () => Promise<void>;
|
|
16
|
+
stop: () => void;
|
|
17
|
+
};
|