vatts 1.0.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/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 hweb(options: VattsOptions): {
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 = hweb;
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.__HWEB_LAYOUT__ = LayoutComponent.default || LayoutComponent;`
165
- : `window.__HWEB_LAYOUT__ = null;`;
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.__HWEB_NOT_FOUND__ = NotFoundComponent.default || NotFoundComponent;`
169
- : `window.__HWEB_NOT_FOUND__ = null;`;
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 hweb
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.__HWEB_COMPONENTS__ = {
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
- // Registra o DefaultNotFound do hweb
197
- window.__HWEB_DEFAULT_NOT_FOUND__ = DefaultNotFound;
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 hweb(options) {
215
+ function vatts(options) {
216
216
  const { dev = true, dir = process.cwd(), port = 3000 } = options;
217
217
  // @ts-ignore
218
218
  process.vatts = options;
@@ -256,9 +256,18 @@ function hweb(options) {
256
256
  // Função para regenerar o entry file
257
257
  const regenerateEntryFile = () => {
258
258
  // Recarrega todas as rotas e componentes
259
- frontendRoutes = (0, router_1.loadRoutes)(userWebRoutesDir);
260
- (0, router_1.loadLayout)(userWebDir);
261
- (0, router_1.loadNotFound)(userWebDir);
259
+ const newFrontendRoutes = (0, router_1.loadRoutes)(userWebRoutesDir);
260
+ const newLayout = (0, router_1.loadLayout)(userWebDir);
261
+ const newNotFound = (0, router_1.loadNotFound)(userWebDir);
262
+ // Se nada mudou, não reescreve o entry file (evita disparar rebuild extra)
263
+ const oldKey = frontendRoutes.map(r => `${r.pattern ?? ''}:${r.componentPath}`).join('|');
264
+ const newKey = newFrontendRoutes.map(r => `${r.pattern ?? ''}:${r.componentPath}`).join('|');
265
+ if (oldKey === newKey) {
266
+ // Ainda atualiza refs internas de layout/notFound, mas evita re-gerar o entry.
267
+ frontendRoutes = newFrontendRoutes;
268
+ return;
269
+ }
270
+ frontendRoutes = newFrontendRoutes;
262
271
  // Regenera o entry file
263
272
  entryPoint = createEntryFile(dir, frontendRoutes);
264
273
  };
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 || 'App hweb'}</title>
178
+ <title>${metadata.title || 'Vatts.js'}</title>
179
179
  </head>
180
180
  <body>
181
181
  <div id="root"></div>
package/dist/router.d.ts CHANGED
@@ -1,101 +1,50 @@
1
1
  import { RouteConfig, BackendRouteConfig, VattsMiddleware, WebSocketHandler } from './types';
2
- /**
3
- * Limpa todo o cache de rotas carregadas
4
- */
5
2
  export declare function clearAllRouteCache(): void;
6
- /**
7
- * Limpa o cache de um arquivo específico e recarrega as rotas se necessário
8
- * @param changedFilePath Caminho do arquivo que foi alterado
9
- */
10
3
  export declare function clearFileCache(changedFilePath: string): void;
11
- /**
12
- * Carrega o layout.tsx se existir no diretório web
13
- * @param webDir O diretório web onde procurar o layout
14
- * @returns O layout carregado ou null se não existir
15
- */
16
4
  export declare function loadLayout(webDir: string): {
17
5
  componentPath: string;
18
6
  metadata?: any;
19
7
  } | null;
20
- /**
21
- * Retorna o layout atual se carregado
22
- */
23
8
  export declare function getLayout(): {
24
9
  componentPath: string;
25
10
  metadata?: any;
26
11
  } | null;
27
- /**
28
- * Carrega dinamicamente todas as rotas de frontend do diretório do usuário.
29
- * @param routesDir O diretório onde as rotas de página estão localizadas.
30
- * @returns A lista de rotas de página que foram carregadas.
31
- */
32
12
  export declare function loadRoutes(routesDir: string): (RouteConfig & {
33
13
  componentPath: string;
34
14
  })[];
35
- /**
36
- * Encontra a rota de página correspondente para uma URL.
37
- * @param pathname O caminho da URL (ex: "/users/123").
38
- * @returns Um objeto com a rota e os parâmetros, ou null se não encontrar.
39
- */
40
15
  export declare function findMatchingRoute(pathname: string): {
41
- route: RouteConfig & {
16
+ route: {
42
17
  componentPath: string;
18
+ pattern: string;
19
+ component: import("react").ComponentType<any>;
20
+ generateMetadata?: (params: any, req: import(".").GenericRequest) => Promise<import("./types").Metadata> | import("./types").Metadata;
43
21
  };
44
22
  params: {
45
23
  [key: string]: string;
46
24
  };
47
25
  } | null;
48
- /**
49
- * Carrega dinamicamente todas as rotas de API do diretório de backend.
50
- * @param backendRoutesDir O diretório onde as rotas de API estão localizadas.
51
- */
52
26
  export declare function loadBackendRoutes(backendRoutesDir: string): void;
53
- /**
54
- * Encontra a rota de API correspondente para uma URL e método HTTP.
55
- * @param pathname O caminho da URL (ex: "/api/users/123").
56
- * @param method O método HTTP da requisição (GET, POST, etc.).
57
- * @returns Um objeto com a rota e os parâmetros, ou null se não encontrar.
58
- */
59
27
  export declare function findMatchingBackendRoute(pathname: string, method: string): {
60
28
  route: BackendRouteConfig;
61
29
  params: {
62
30
  [key: string]: string;
63
31
  };
64
32
  } | null;
65
- /**
66
- * Carrega o notFound.tsx se existir no diretório web
67
- * @param webDir O diretório web onde procurar o notFound
68
- * @returns O notFound carregado ou null se não existir
69
- */
70
33
  export declare function loadNotFound(webDir: string): {
71
34
  componentPath: string;
72
35
  } | null;
73
- /**
74
- * Retorna o componente 404 atual se carregado
75
- */
76
36
  export declare function getNotFound(): {
77
37
  componentPath: string;
78
38
  } | null;
79
- /**
80
- * Processa e registra rotas WebSocket encontradas nas rotas backend
81
- */
82
39
  export declare function processWebSocketRoutes(): void;
83
- /**
84
- * Encontra a rota WebSocket correspondente para uma URL
85
- */
86
40
  export declare function findMatchingWebSocketRoute(pathname: string): {
87
41
  route: {
88
42
  pattern: string;
89
43
  handler: WebSocketHandler;
90
- middleware?: VattsMiddleware[];
44
+ middleware: VattsMiddleware[] | undefined;
91
45
  };
92
46
  params: {
93
47
  [key: string]: string;
94
48
  };
95
49
  } | null;
96
- /**
97
- * Configura WebSocket upgrade no servidor HTTP existente
98
- * @param server Servidor HTTP (Express, Fastify ou Native)
99
- * @param hotReloadManager Instância do gerenciador de hot-reload para coordenação
100
- */
101
50
  export declare function setupWebSocketUpgrade(server: any, hotReloadManager?: any): void;