hightjs 0.5.0 → 0.5.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/README.md +0 -16
- package/dist/router.js +26 -12
- package/package.json +3 -2
- 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 +234 -0
- package/src/api/console.ts +305 -0
- package/src/api/http.ts +535 -0
- package/src/bin/hightjs.js +252 -0
- package/src/builder.js +631 -0
- package/src/client/DefaultNotFound.tsx +119 -0
- package/src/client/client.ts +25 -0
- package/src/client/clientRouter.ts +153 -0
- package/src/client/entry.client.tsx +526 -0
- package/src/components/Link.tsx +38 -0
- package/src/global/global.ts +171 -0
- package/src/helpers.ts +631 -0
- package/src/hotReload.ts +569 -0
- package/src/index.ts +557 -0
- package/src/loaders.js +53 -0
- package/src/renderer.tsx +421 -0
- package/src/router.ts +744 -0
- package/src/types/framework.ts +58 -0
- package/src/types.ts +258 -0
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
// Tipos genéricos para abstrair diferentes frameworks web
|
|
18
|
+
export interface GenericRequest {
|
|
19
|
+
method: string;
|
|
20
|
+
url: string;
|
|
21
|
+
headers: Record<string, string | string[]>;
|
|
22
|
+
body?: any;
|
|
23
|
+
query?: Record<string, any>;
|
|
24
|
+
params?: Record<string, string>;
|
|
25
|
+
cookies?: Record<string, string>;
|
|
26
|
+
raw?: any; // Requisição original do framework
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface GenericResponse {
|
|
30
|
+
status(code: number): GenericResponse;
|
|
31
|
+
header(name: string, value: string): GenericResponse;
|
|
32
|
+
cookie(name: string, value: string, options?: CookieOptions): GenericResponse;
|
|
33
|
+
clearCookie(name: string, options?: CookieOptions): GenericResponse;
|
|
34
|
+
json(data: any): void;
|
|
35
|
+
text(data: string): void;
|
|
36
|
+
send(data: any): void;
|
|
37
|
+
redirect(url: string): void;
|
|
38
|
+
raw?: any; // Resposta original do framework
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CookieOptions {
|
|
42
|
+
domain?: string;
|
|
43
|
+
expires?: Date;
|
|
44
|
+
httpOnly?: boolean;
|
|
45
|
+
maxAge?: number;
|
|
46
|
+
path?: string;
|
|
47
|
+
secure?: boolean;
|
|
48
|
+
signed?: boolean;
|
|
49
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type FrameworkType = 'express' | 'fastify' | 'native';
|
|
53
|
+
|
|
54
|
+
export interface FrameworkAdapter {
|
|
55
|
+
type: FrameworkType;
|
|
56
|
+
parseRequest(req: any): GenericRequest;
|
|
57
|
+
createResponse(res: any): GenericResponse;
|
|
58
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
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 type { ComponentType } from 'react';
|
|
18
|
+
import type { GenericRequest } from './types/framework';
|
|
19
|
+
import {HightJSRequest, HightJSResponse} from "./api/http";
|
|
20
|
+
import { WebSocket } from 'ws';
|
|
21
|
+
import { IncomingMessage } from 'http';
|
|
22
|
+
|
|
23
|
+
// Interface do contexto WebSocket simplificada
|
|
24
|
+
export interface WebSocketContext {
|
|
25
|
+
ws: WebSocket;
|
|
26
|
+
req: IncomingMessage;
|
|
27
|
+
hightReq: HightJSRequest;
|
|
28
|
+
url: URL;
|
|
29
|
+
params: Record<string, string>;
|
|
30
|
+
query: Record<string, string>;
|
|
31
|
+
send: (data: any) => void;
|
|
32
|
+
close: (code?: number, reason?: string) => void;
|
|
33
|
+
broadcast: (data: any, exclude?: WebSocket[]) => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// --- Tipos do Frontend (sem alteração) ---
|
|
37
|
+
export interface HightJSOptions {
|
|
38
|
+
dev?: boolean;
|
|
39
|
+
hostname?: string;
|
|
40
|
+
port?: number;
|
|
41
|
+
dir?: string;
|
|
42
|
+
framework?: 'express' | 'fastify' | 'native';
|
|
43
|
+
ssl?: {
|
|
44
|
+
redirectPort: number;
|
|
45
|
+
key: string;
|
|
46
|
+
cert: string;
|
|
47
|
+
ca?: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// --- Tipos de Configuração ---
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Interface para as configurações avançadas do servidor HightJS.
|
|
55
|
+
* Essas configurações podem ser definidas no arquivo hightjs.config.js
|
|
56
|
+
*/
|
|
57
|
+
export interface HightConfig {
|
|
58
|
+
/**
|
|
59
|
+
* Limita o número máximo de headers HTTP permitidos por requisição.
|
|
60
|
+
* Padrão: 100
|
|
61
|
+
*/
|
|
62
|
+
maxHeadersCount?: number;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Timeout em milissegundos para receber os headers HTTP.
|
|
66
|
+
* Padrão: 60000 (60 segundos)
|
|
67
|
+
*/
|
|
68
|
+
headersTimeout?: number;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Timeout em milissegundos para uma requisição completa.
|
|
72
|
+
* Padrão: 30000 (30 segundos)
|
|
73
|
+
*/
|
|
74
|
+
requestTimeout?: number;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Timeout geral do servidor em milissegundos.
|
|
78
|
+
* Padrão: 35000 (35 segundos)
|
|
79
|
+
*/
|
|
80
|
+
serverTimeout?: number;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Timeout por requisição individual em milissegundos.
|
|
84
|
+
* Padrão: 30000 (30 segundos)
|
|
85
|
+
*/
|
|
86
|
+
individualRequestTimeout?: number;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Tamanho máximo permitido para a URL em caracteres.
|
|
90
|
+
* Padrão: 2048
|
|
91
|
+
*/
|
|
92
|
+
maxUrlLength?: number;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Habilita o log de acesso HTTP (ex: GET /api/users 200 15ms).
|
|
96
|
+
* Padrão: false
|
|
97
|
+
*/
|
|
98
|
+
accessLogging?: boolean;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Configurações de CORS (Cross-Origin Resource Sharing).
|
|
102
|
+
* Define quais origens podem acessar seus recursos.
|
|
103
|
+
*/
|
|
104
|
+
cors?: {
|
|
105
|
+
/**
|
|
106
|
+
* Origens permitidas. Pode ser:
|
|
107
|
+
* - Uma string específica: 'https://exemplo.com'
|
|
108
|
+
* - Um array de strings: ['https://exemplo.com', 'https://outro.com']
|
|
109
|
+
* - Um wildcard: '*' (permite todas as origens - não recomendado em produção)
|
|
110
|
+
* - Uma função que retorna boolean: (origin) => origin.endsWith('.exemplo.com')
|
|
111
|
+
*/
|
|
112
|
+
origin?: string | string[] | ((origin: string) => boolean);
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Métodos HTTP permitidos.
|
|
116
|
+
* Padrão: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']
|
|
117
|
+
*/
|
|
118
|
+
methods?: string[];
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Headers permitidos nas requisições.
|
|
122
|
+
* Padrão: ['Content-Type', 'Authorization']
|
|
123
|
+
*/
|
|
124
|
+
allowedHeaders?: string[];
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Headers que serão expostos ao cliente.
|
|
128
|
+
* Padrão: []
|
|
129
|
+
*/
|
|
130
|
+
exposedHeaders?: string[];
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Permite o envio de credenciais (cookies, headers de autenticação).
|
|
134
|
+
* Padrão: false
|
|
135
|
+
*/
|
|
136
|
+
credentials?: boolean;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Tempo em segundos que o navegador deve cachear a resposta preflight.
|
|
140
|
+
* Padrão: 86400 (24 horas)
|
|
141
|
+
*/
|
|
142
|
+
maxAge?: number;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Habilita ou desabilita completamente o CORS.
|
|
146
|
+
* Padrão: false
|
|
147
|
+
*/
|
|
148
|
+
enabled?: boolean;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Tipo da função de configuração que pode ser exportada no hightjs.config.js
|
|
154
|
+
*/
|
|
155
|
+
export type HightConfigFunction = (
|
|
156
|
+
phase: string,
|
|
157
|
+
context: { defaultConfig: HightConfig }
|
|
158
|
+
) => HightConfig | Promise<HightConfig>;
|
|
159
|
+
|
|
160
|
+
export interface Metadata {
|
|
161
|
+
// Basic metadata
|
|
162
|
+
title?: string;
|
|
163
|
+
description?: string;
|
|
164
|
+
keywords?: string | string[];
|
|
165
|
+
author?: string;
|
|
166
|
+
favicon?: string;
|
|
167
|
+
|
|
168
|
+
// Viewport and mobile
|
|
169
|
+
viewport?: string;
|
|
170
|
+
themeColor?: string;
|
|
171
|
+
|
|
172
|
+
// SEO
|
|
173
|
+
canonical?: string;
|
|
174
|
+
robots?: string;
|
|
175
|
+
|
|
176
|
+
// Open Graph (Facebook, LinkedIn, etc.)
|
|
177
|
+
openGraph?: {
|
|
178
|
+
title?: string;
|
|
179
|
+
description?: string;
|
|
180
|
+
type?: string;
|
|
181
|
+
url?: string;
|
|
182
|
+
image?: string | {
|
|
183
|
+
url: string;
|
|
184
|
+
width?: number;
|
|
185
|
+
height?: number;
|
|
186
|
+
alt?: string;
|
|
187
|
+
};
|
|
188
|
+
siteName?: string;
|
|
189
|
+
locale?: string;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// Twitter Card
|
|
193
|
+
twitter?: {
|
|
194
|
+
card?: 'summary' | 'summary_large_image' | 'app' | 'player';
|
|
195
|
+
site?: string;
|
|
196
|
+
creator?: string;
|
|
197
|
+
title?: string;
|
|
198
|
+
description?: string;
|
|
199
|
+
image?: string;
|
|
200
|
+
imageAlt?: string;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// Additional metadata
|
|
204
|
+
language?: string;
|
|
205
|
+
charset?: string;
|
|
206
|
+
appleTouchIcon?: string;
|
|
207
|
+
manifest?: string;
|
|
208
|
+
|
|
209
|
+
// Custom meta tags
|
|
210
|
+
other?: Record<string, string>;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
export interface RouteConfig {
|
|
215
|
+
pattern: string;
|
|
216
|
+
component: ComponentType<any>;
|
|
217
|
+
generateMetadata?: (params: any, req: GenericRequest) => Promise<Metadata> | Metadata;
|
|
218
|
+
}
|
|
219
|
+
export type RequestHandler = (req: any, res: any) => Promise<void>;
|
|
220
|
+
|
|
221
|
+
// --- NOVO: Tipos do Backend ---
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Define o formato de uma função que manipula uma rota da API.
|
|
225
|
+
*/
|
|
226
|
+
export type BackendHandler = (
|
|
227
|
+
request: HightJSRequest, // HWebRequest será importado onde necessário
|
|
228
|
+
params: { [key: string]: string }
|
|
229
|
+
) => Promise<HightJSResponse> | HightJSResponse; // HWebResponse será importado onde necessário
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
export type HightMiddleware = (
|
|
234
|
+
request: HightJSRequest, // HWebRequest será importado onde necessário
|
|
235
|
+
params: { [key: string]: string },
|
|
236
|
+
next: () => Promise<HightJSResponse>
|
|
237
|
+
) => Promise<HightJSResponse> | HightJSResponse; // HWebResponse será importado onde necessário
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Define o formato de uma função que manipula uma rota WebSocket.
|
|
242
|
+
*/
|
|
243
|
+
export type WebSocketHandler = (
|
|
244
|
+
context: WebSocketContext
|
|
245
|
+
) => Promise<void> | void;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Define a estrutura de cada rota da API, com suporte para métodos HTTP e WebSocket.
|
|
249
|
+
*/
|
|
250
|
+
export interface BackendRouteConfig {
|
|
251
|
+
pattern: string;
|
|
252
|
+
GET?: BackendHandler;
|
|
253
|
+
POST?: BackendHandler;
|
|
254
|
+
PUT?: BackendHandler;
|
|
255
|
+
DELETE?: BackendHandler;
|
|
256
|
+
WS?: WebSocketHandler; // Suporte para WebSocket
|
|
257
|
+
middleware?: HightMiddleware[]; // Permite adicionar middlewares específicos à rota
|
|
258
|
+
}
|