vatts 1.0.2-alpha.1 → 1.0.2-alpha.2
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/dist/builder.js +1 -1
- package/dist/client/clientRouter.js +0 -1
- package/dist/client/entry.client.js +7 -7
- package/dist/helpers.js +18 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -10
- package/dist/renderer.js +1 -1
- package/dist/types.d.ts +2 -4
- package/package.json +1 -1
package/dist/builder.js
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
// Sistema de roteamento do lado do cliente para hweb-sdk
|
|
19
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
19
|
exports.router = void 0;
|
|
21
20
|
class Router {
|
|
@@ -201,7 +201,7 @@ function App({ componentMap, routes, initialComponentPath, initialParams, layout
|
|
|
201
201
|
// para garantir que o ErrorModal apareça em qualquer estado.
|
|
202
202
|
let resolvedContent;
|
|
203
203
|
if (!CurrentPageComponent || initialComponentPath === '__404__') {
|
|
204
|
-
const NotFoundComponent = window.
|
|
204
|
+
const NotFoundComponent = window.__VATTS_NOT_FOUND__;
|
|
205
205
|
if (NotFoundComponent) {
|
|
206
206
|
const NotFoundContent = (0, jsx_runtime_1.jsx)(NotFoundComponent, {});
|
|
207
207
|
resolvedContent = layoutComponent
|
|
@@ -209,7 +209,7 @@ function App({ componentMap, routes, initialComponentPath, initialParams, layout
|
|
|
209
209
|
: NotFoundContent;
|
|
210
210
|
}
|
|
211
211
|
else {
|
|
212
|
-
const DefaultNotFound = window.
|
|
212
|
+
const DefaultNotFound = window.__VATTS_DEFAULT_NOT_FOUND__;
|
|
213
213
|
const NotFoundContent = (0, jsx_runtime_1.jsx)(DefaultNotFound, {});
|
|
214
214
|
resolvedContent = layoutComponent
|
|
215
215
|
? react_1.default.createElement(layoutComponent, { children: NotFoundContent })
|
|
@@ -261,11 +261,11 @@ function initializeClient() {
|
|
|
261
261
|
// Cria o mapa de componentes dinamicamente a partir dos módulos carregados
|
|
262
262
|
const componentMap = {};
|
|
263
263
|
// Registra todos os componentes que foram importados
|
|
264
|
-
if (window.
|
|
265
|
-
Object.assign(componentMap, window.
|
|
264
|
+
if (window.__VATTS_COMPONENTS__) {
|
|
265
|
+
Object.assign(componentMap, window.__VATTS_COMPONENTS__);
|
|
266
266
|
}
|
|
267
267
|
else {
|
|
268
|
-
console.warn('[Vatts] No components found in window.
|
|
268
|
+
console.warn('[Vatts] No components found in window.__VATTS_COMPONENTS__');
|
|
269
269
|
}
|
|
270
270
|
const container = document.getElementById('root');
|
|
271
271
|
if (!container) {
|
|
@@ -292,7 +292,7 @@ function initializeClient() {
|
|
|
292
292
|
const root = (0, client_1.createRoot)(container);
|
|
293
293
|
// Salva a referência globalmente
|
|
294
294
|
window.__VATTS_ROOT__ = root;
|
|
295
|
-
root.render((0, jsx_runtime_1.jsx)(App, { componentMap: componentMap, routes: initialData.routes, initialComponentPath: initialData.initialComponentPath, initialParams: initialData.initialParams, layoutComponent: window.
|
|
295
|
+
root.render((0, jsx_runtime_1.jsx)(App, { componentMap: componentMap, routes: initialData.routes, initialComponentPath: initialData.initialComponentPath, initialParams: initialData.initialParams, layoutComponent: window.__VATTS_LAYOUT__ }));
|
|
296
296
|
}
|
|
297
297
|
catch (error) {
|
|
298
298
|
console.error('[Watts] Critical Error rendering application:', error);
|
|
@@ -316,7 +316,7 @@ if (document.readyState === 'loading') {
|
|
|
316
316
|
else {
|
|
317
317
|
// ESM Hoisting Fix:
|
|
318
318
|
// Como este arquivo é importado pelo arquivo gerado automaticamente, ele executa
|
|
319
|
-
// ANTES do corpo do arquivo gerado (onde window.
|
|
319
|
+
// ANTES do corpo do arquivo gerado (onde window.__VATTS_COMPONENTS__ é definido).
|
|
320
320
|
// Usamos setTimeout para garantir que a inicialização ocorra após as atribuições globais.
|
|
321
321
|
setTimeout(initializeClient, 0);
|
|
322
322
|
}
|
package/dist/helpers.js
CHANGED
|
@@ -315,13 +315,13 @@ const parseBody = (req) => {
|
|
|
315
315
|
/**
|
|
316
316
|
* Inicializa servidor nativo do Vatts.js usando HTTP ou HTTPS
|
|
317
317
|
*/
|
|
318
|
-
async function initNativeServer(
|
|
318
|
+
async function initNativeServer(vattsApp, options, port, hostname) {
|
|
319
319
|
const time = Date.now();
|
|
320
|
-
await
|
|
320
|
+
await vattsApp.prepare();
|
|
321
321
|
const projectDir = options.dir || process.cwd();
|
|
322
322
|
const phase = options.dev ? 'development' : 'production';
|
|
323
323
|
const vattsConfig = await loadVattsConfig(projectDir, phase);
|
|
324
|
-
const handler =
|
|
324
|
+
const handler = vattsApp.getRequestHandler();
|
|
325
325
|
const msg = console_1.default.dynamicLine(`${console_1.Colors.Bright}Starting Vatts.js on port ${options.port}${console_1.Colors.Reset}`);
|
|
326
326
|
// --- LÓGICA DO LISTENER (REUTILIZÁVEL) ---
|
|
327
327
|
// Extraímos a lógica principal para uma variável
|
|
@@ -461,7 +461,7 @@ async function initNativeServer(hwebApp, options, port, hostname) {
|
|
|
461
461
|
ca: options.ssl.ca ? fs_1.default.readFileSync(options.ssl.ca) : undefined
|
|
462
462
|
};
|
|
463
463
|
// 1. Cria o servidor HTTPS principal
|
|
464
|
-
server = https_1.default.createServer(sslOptions, requestListener);
|
|
464
|
+
server = https_1.default.createServer(sslOptions, requestListener);
|
|
465
465
|
// 2. Cria o servidor de REDIRECIONAMENTO (HTTP -> HTTPS)
|
|
466
466
|
const httpRedirectPort = options.ssl.redirectPort;
|
|
467
467
|
http_1.default.createServer((req, res) => {
|
|
@@ -490,7 +490,7 @@ async function initNativeServer(hwebApp, options, port, hostname) {
|
|
|
490
490
|
else {
|
|
491
491
|
// --- MODO HTTP (Original) ---
|
|
492
492
|
// Cria o servidor HTTP nativo
|
|
493
|
-
server = http_1.default.createServer(requestListener);
|
|
493
|
+
server = http_1.default.createServer(requestListener);
|
|
494
494
|
}
|
|
495
495
|
// Configurações de segurança do servidor (usa configuração personalizada)
|
|
496
496
|
server.setTimeout(vattsConfig.serverTimeout || 35000); // Timeout geral do servidor
|
|
@@ -502,26 +502,26 @@ async function initNativeServer(hwebApp, options, port, hostname) {
|
|
|
502
502
|
msg.end(`${console_1.Colors.Bright}Ready on port ${console_1.Colors.BgGreen} ${options.port} ${console_1.Colors.Reset}${console_1.Colors.Bright} in ${Date.now() - time}ms${console_1.Colors.Reset}\n`);
|
|
503
503
|
});
|
|
504
504
|
// Configura WebSocket para hot reload (Comum a ambos)
|
|
505
|
-
|
|
506
|
-
|
|
505
|
+
vattsApp.setupWebSocket(server);
|
|
506
|
+
vattsApp.executeInstrumentation();
|
|
507
507
|
return server;
|
|
508
508
|
}
|
|
509
509
|
// --- Função Principal ---
|
|
510
510
|
function app(options = {}) {
|
|
511
511
|
const framework = options.framework || 'native';
|
|
512
512
|
index_1.FrameworkAdapterFactory.setFramework(framework);
|
|
513
|
-
// Tipando a app principal do
|
|
514
|
-
const
|
|
513
|
+
// Tipando a app principal do vatts
|
|
514
|
+
const vattsApp = (0, index_1.default)(options);
|
|
515
515
|
return {
|
|
516
|
-
...
|
|
516
|
+
...vattsApp,
|
|
517
517
|
/**
|
|
518
518
|
* Integra com uma aplicação de qualquer framework (Express, Fastify, etc)
|
|
519
519
|
* O 'serverApp: any' é mantido para flexibilidade, já que pode ser de tipos diferentes.
|
|
520
520
|
*/
|
|
521
521
|
integrate: async (serverApp) => {
|
|
522
|
-
await
|
|
523
|
-
const handler =
|
|
524
|
-
// O framework é setado nas opções do
|
|
522
|
+
await vattsApp.prepare();
|
|
523
|
+
const handler = vattsApp.getRequestHandler();
|
|
524
|
+
// O framework é setado nas opções do vatts, que deve
|
|
525
525
|
// retornar o handler correto em getRequestHandler()
|
|
526
526
|
// A lógica de integração original parece correta.
|
|
527
527
|
if (framework === 'express') {
|
|
@@ -536,7 +536,7 @@ function app(options = {}) {
|
|
|
536
536
|
serverApp.use(express.json());
|
|
537
537
|
serverApp.use(express.urlencoded({ extended: true }));
|
|
538
538
|
serverApp.use(handler);
|
|
539
|
-
|
|
539
|
+
vattsApp.setupWebSocket(serverApp);
|
|
540
540
|
}
|
|
541
541
|
else if (framework === 'fastify') {
|
|
542
542
|
try {
|
|
@@ -554,14 +554,14 @@ function app(options = {}) {
|
|
|
554
554
|
await serverApp.register(async (fastify) => {
|
|
555
555
|
fastify.all('*', handler);
|
|
556
556
|
});
|
|
557
|
-
|
|
557
|
+
vattsApp.setupWebSocket(serverApp);
|
|
558
558
|
}
|
|
559
559
|
else {
|
|
560
560
|
// Generic integration (assume Express-like)
|
|
561
561
|
serverApp.use(handler);
|
|
562
|
-
|
|
562
|
+
vattsApp.setupWebSocket(serverApp);
|
|
563
563
|
}
|
|
564
|
-
|
|
564
|
+
vattsApp.executeInstrumentation();
|
|
565
565
|
return serverApp;
|
|
566
566
|
},
|
|
567
567
|
/**
|
|
@@ -602,7 +602,7 @@ ${console_1.Colors.Bright + console_1.Colors.FgRed} \\/ /~~\\ | | .__/
|
|
|
602
602
|
if (framework !== 'native') {
|
|
603
603
|
console_1.default.warn(`The "${framework}" framework was selected, but the init() method only works with the "native" framework. Starting native server...`);
|
|
604
604
|
}
|
|
605
|
-
return await initNativeServer(
|
|
605
|
+
return await initNativeServer(vattsApp, options, actualPort, actualHostname);
|
|
606
606
|
}
|
|
607
607
|
};
|
|
608
608
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type { GenericRequest, GenericResponse, CookieOptions } from './types/fra
|
|
|
9
9
|
export { app } from './helpers';
|
|
10
10
|
export type { WebSocketContext, WebSocketHandler } from './types';
|
|
11
11
|
export type { VattsConfig, VattsConfigFunction } from './types';
|
|
12
|
-
export default function
|
|
12
|
+
export default function vatts(options: VattsOptions): {
|
|
13
13
|
prepare: () => Promise<void>;
|
|
14
14
|
executeInstrumentation: () => void;
|
|
15
15
|
getRequestHandler: () => RequestHandler;
|
package/dist/index.js
CHANGED
|
@@ -53,7 +53,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
53
53
|
};
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
55
|
exports.app = exports.FrameworkAdapterFactory = exports.FastifyAdapter = exports.ExpressAdapter = exports.VattsResponse = exports.VattsRequest = void 0;
|
|
56
|
-
exports.default =
|
|
56
|
+
exports.default = vatts;
|
|
57
57
|
const path_1 = __importDefault(require("path"));
|
|
58
58
|
const fs_1 = __importDefault(require("fs"));
|
|
59
59
|
const express_1 = require("./adapters/express");
|
|
@@ -161,12 +161,12 @@ function createEntryFile(projectDir, routes) {
|
|
|
161
161
|
.join('\n');
|
|
162
162
|
// Registra o layout se existir
|
|
163
163
|
const layoutRegistration = layout
|
|
164
|
-
? `window.
|
|
165
|
-
: `window.
|
|
164
|
+
? `window.__VATTS_LAYOUT__ = LayoutComponent.default || LayoutComponent;`
|
|
165
|
+
: `window.__VATTS_LAYOUT__ = null;`;
|
|
166
166
|
// Registra o notFound se existir
|
|
167
167
|
const notFoundRegistration = notFound
|
|
168
|
-
? `window.
|
|
169
|
-
: `window.
|
|
168
|
+
? `window.__VATTS_NOT_FOUND__ = NotFoundComponent.default || NotFoundComponent;`
|
|
169
|
+
: `window.__VATTS_NOT_FOUND__ = null;`;
|
|
170
170
|
// Caminho correto para o entry.client
|
|
171
171
|
// IMPORTANT: quando o pacote é instalado via npm, bundlers (Rollup/Vite/etc.) não transpilam TSX em node_modules.
|
|
172
172
|
// Por isso, aqui a gente sempre aponta para os artefatos compilados em dist/.
|
|
@@ -176,14 +176,14 @@ function createEntryFile(projectDir, routes) {
|
|
|
176
176
|
// Import do DefaultNotFound do SDK (compilado)
|
|
177
177
|
const defaultNotFoundPath = path_1.default.join(sdkDir, 'dist', 'client', 'DefaultNotFound.js');
|
|
178
178
|
const relativeDefaultNotFoundPath = path_1.default.relative(tempDir, defaultNotFoundPath).replace(/\\/g, '/');
|
|
179
|
-
const entryContent = `// Arquivo gerado automaticamente pelo
|
|
179
|
+
const entryContent = `// Arquivo gerado automaticamente pelo vatts
|
|
180
180
|
${imports}
|
|
181
181
|
${layoutImport}
|
|
182
182
|
${notFoundImport}
|
|
183
183
|
import DefaultNotFound from '${relativeDefaultNotFoundPath}';
|
|
184
184
|
|
|
185
185
|
// Registra os componentes para o cliente
|
|
186
|
-
window.
|
|
186
|
+
window.__VATTS_COMPONENTS__ = {
|
|
187
187
|
${componentRegistration}
|
|
188
188
|
};
|
|
189
189
|
|
|
@@ -193,8 +193,8 @@ ${layoutRegistration}
|
|
|
193
193
|
// Registra o notFound se existir
|
|
194
194
|
${notFoundRegistration}
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
window.
|
|
196
|
+
|
|
197
|
+
window.__VATTS_DEFAULT_NOT_FOUND__ = DefaultNotFound;
|
|
198
198
|
|
|
199
199
|
// Importa e executa o entry.client.tsx
|
|
200
200
|
import '${relativeEntryPath}';
|
|
@@ -212,7 +212,7 @@ import '${relativeEntryPath}';
|
|
|
212
212
|
throw e;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function vatts(options) {
|
|
216
216
|
const { dev = true, dir = process.cwd(), port = 3000 } = options;
|
|
217
217
|
// @ts-ignore
|
|
218
218
|
process.vatts = options;
|
package/dist/renderer.js
CHANGED
|
@@ -175,7 +175,7 @@ async function render({ req, route, params, allRoutes }) {
|
|
|
175
175
|
<html lang="${htmlLang}">
|
|
176
176
|
<head>
|
|
177
177
|
${metaTags}
|
|
178
|
-
<title>${metadata.title || '
|
|
178
|
+
<title>${metadata.title || 'Vatts.js'}</title>
|
|
179
179
|
</head>
|
|
180
180
|
<body>
|
|
181
181
|
<div id="root"></div>
|
package/dist/types.d.ts
CHANGED
|
@@ -192,12 +192,10 @@ export type RequestHandler = (req: any, res: any) => Promise<void>;
|
|
|
192
192
|
/**
|
|
193
193
|
* Define o formato de uma função que manipula uma rota da API.
|
|
194
194
|
*/
|
|
195
|
-
export type BackendHandler = (request: VattsRequest,
|
|
196
|
-
params: {
|
|
195
|
+
export type BackendHandler = (request: VattsRequest, params: {
|
|
197
196
|
[key: string]: string;
|
|
198
197
|
}) => Promise<VattsResponse> | VattsResponse;
|
|
199
|
-
export type VattsMiddleware = (request: VattsRequest,
|
|
200
|
-
params: {
|
|
198
|
+
export type VattsMiddleware = (request: VattsRequest, params: {
|
|
201
199
|
[key: string]: string;
|
|
202
200
|
}, next: () => Promise<VattsResponse>) => Promise<VattsResponse> | VattsResponse;
|
|
203
201
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vatts",
|
|
3
|
-
"version": "1.0.2-alpha.
|
|
3
|
+
"version": "1.0.2-alpha.2",
|
|
4
4
|
"description": "Vatts.js is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "itsmuzin",
|