hightjs 0.3.2 → 0.3.4

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 (42) hide show
  1. package/dist/adapters/factory.js +8 -8
  2. package/dist/adapters/native.js +3 -3
  3. package/dist/auth/client.js +5 -5
  4. package/dist/auth/components.js +2 -2
  5. package/dist/auth/core.js +2 -2
  6. package/dist/auth/react.js +4 -4
  7. package/dist/auth/routes.js +1 -1
  8. package/dist/bin/hightjs.js +29 -328
  9. package/dist/builder.js +47 -21
  10. package/dist/client/DefaultNotFound.js +1 -1
  11. package/dist/client/entry.client.js +3 -3
  12. package/dist/helpers.d.ts +1 -0
  13. package/dist/helpers.js +90 -28
  14. package/dist/hotReload.d.ts +3 -1
  15. package/dist/hotReload.js +43 -51
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +16 -30
  18. package/dist/router.js +133 -62
  19. package/dist/types.d.ts +42 -0
  20. package/docs/config.md +201 -0
  21. package/example/hightjs.config.ts +81 -0
  22. package/example/package-lock.json +633 -3054
  23. package/example/package.json +1 -1
  24. package/package.json +1 -1
  25. package/src/adapters/factory.ts +8 -8
  26. package/src/adapters/native.ts +3 -3
  27. package/src/auth/client.ts +5 -5
  28. package/src/auth/components.tsx +2 -2
  29. package/src/auth/core.ts +2 -2
  30. package/src/auth/react.tsx +4 -4
  31. package/src/auth/routes.ts +1 -1
  32. package/src/bin/hightjs.js +30 -391
  33. package/src/builder.js +47 -22
  34. package/src/client/DefaultNotFound.tsx +1 -1
  35. package/src/client/entry.client.tsx +3 -3
  36. package/src/helpers.ts +105 -29
  37. package/src/hotReload.ts +45 -55
  38. package/src/index.ts +20 -33
  39. package/src/router.ts +140 -63
  40. package/src/types.ts +52 -0
  41. package/example/.hweb/entry.client.js +0 -24
  42. package/example/hweb-dist/main-5KKAYNUU.js +0 -1137
package/docs/config.md ADDED
@@ -0,0 +1,201 @@
1
+ # HightJS Configuration (hightjs.config.ts)
2
+
3
+ O HightJS permite que você personalize as configurações do servidor através de um arquivo `hightjs.config.ts` (ou `.js`) na raiz do seu projeto.
4
+
5
+ ## 📝 Estrutura Básica
6
+
7
+ ### Opção 1: Função de Configuração (Recomendado)
8
+
9
+ ```typescript
10
+ import type { HightConfig, HightConfigFunction } from 'hightjs';
11
+
12
+ const hightConfig: HightConfigFunction = (phase, { defaultConfig }) => {
13
+ const config: HightConfig = {
14
+ maxHeadersCount: 100,
15
+ headersTimeout: 60000,
16
+ requestTimeout: 30000,
17
+ serverTimeout: 35000,
18
+ individualRequestTimeout: 30000,
19
+ maxUrlLength: 2048,
20
+ };
21
+
22
+ // Personalize baseado no ambiente
23
+ if (phase === 'development') {
24
+ config.requestTimeout = 60000;
25
+ config.individualRequestTimeout = 60000;
26
+ }
27
+
28
+ if (phase === 'production') {
29
+ config.maxHeadersCount = 50;
30
+ config.maxUrlLength = 1024;
31
+ }
32
+
33
+ return config;
34
+ };
35
+
36
+ export default hightConfig;
37
+ ```
38
+
39
+ ### Opção 2: Objeto Estático
40
+
41
+ ```typescript
42
+ import type { HightConfig } from 'hightjs';
43
+
44
+ const config: HightConfig = {
45
+ maxHeadersCount: 100,
46
+ headersTimeout: 60000,
47
+ requestTimeout: 30000,
48
+ serverTimeout: 35000,
49
+ individualRequestTimeout: 30000,
50
+ maxUrlLength: 2048,
51
+ };
52
+
53
+ export default config;
54
+ ```
55
+
56
+ ## ⚙️ Configurações Disponíveis
57
+
58
+ | Propriedade | Tipo | Padrão | Descrição |
59
+ |------------|------|--------|-----------|
60
+ | `maxHeadersCount` | `number` | `100` | Número máximo de headers HTTP permitidos por requisição |
61
+ | `headersTimeout` | `number` | `60000` | Timeout em ms para receber os headers HTTP |
62
+ | `requestTimeout` | `number` | `30000` | Timeout em ms para uma requisição completa |
63
+ | `serverTimeout` | `number` | `35000` | Timeout geral do servidor em ms |
64
+ | `individualRequestTimeout` | `number` | `30000` | Timeout por requisição individual em ms |
65
+ | `maxUrlLength` | `number` | `2048` | Tamanho máximo da URL em caracteres |
66
+
67
+ ## 🎯 Casos de Uso
68
+
69
+ ### Aumentar Timeouts para Debugging
70
+
71
+ ```typescript
72
+ const config: HightConfig = {
73
+ requestTimeout: 120000, // 2 minutos
74
+ individualRequestTimeout: 120000,
75
+ };
76
+ ```
77
+
78
+ ### Aumentar Limites para APIs com Muitos Headers
79
+
80
+ ```typescript
81
+ const config: HightConfig = {
82
+ maxHeadersCount: 200, // Dobro do padrão
83
+ };
84
+ ```
85
+
86
+ ### Configuração Rigorosa para Produção
87
+
88
+ ```typescript
89
+ const hightConfig: HightConfigFunction = (phase) => {
90
+ if (phase === 'production') {
91
+ return {
92
+ maxHeadersCount: 50,
93
+ maxUrlLength: 1024,
94
+ requestTimeout: 15000, // Mais restritivo
95
+ individualRequestTimeout: 15000,
96
+ };
97
+ }
98
+
99
+ // Valores padrão para desenvolvimento
100
+ return {};
101
+ };
102
+ ```
103
+
104
+ ### Suporte a URLs Muito Longas
105
+
106
+ ```typescript
107
+ const config: HightConfig = {
108
+ maxUrlLength: 4096, // Dobro do padrão
109
+ };
110
+ ```
111
+
112
+ ## 🔄 Hot Reload
113
+
114
+ Em modo de desenvolvimento (`dev: true`), o arquivo de configuração é recarregado automaticamente quando modificado, permitindo ajustes sem reiniciar o servidor.
115
+
116
+ ## 📦 TypeScript vs JavaScript
117
+
118
+ ### TypeScript (Recomendado)
119
+ - Arquivo: `hightjs.config.ts`
120
+ - Benefícios: Autocomplete, validação de tipos, detecção de erros
121
+
122
+ ### JavaScript
123
+ - Arquivo: `hightjs.config.js`
124
+ - Use JSDoc para ter intellisense:
125
+
126
+ ```javascript
127
+ /**
128
+ * @type {import('hightjs').HightConfigFunction}
129
+ */
130
+ const hightConfig = (phase, { defaultConfig }) => {
131
+ /** @type {import('hightjs').HightConfig} */
132
+ const config = {
133
+ maxHeadersCount: 100,
134
+ };
135
+
136
+ return config;
137
+ };
138
+
139
+ module.exports = hightConfig;
140
+ ```
141
+
142
+ ## 🚀 Exemplo Completo
143
+
144
+ ```typescript
145
+ import type { HightConfig, HightConfigFunction } from 'hightjs';
146
+
147
+ const hightConfig: HightConfigFunction = (phase, { defaultConfig }) => {
148
+ // Começa com valores padrão
149
+ const config: HightConfig = { ...defaultConfig };
150
+
151
+ // Configurações comuns
152
+ config.maxHeadersCount = 150;
153
+
154
+ // Ajustes por ambiente
155
+ if (phase === 'development') {
156
+ // Timeouts maiores para debugging
157
+ config.requestTimeout = 120000;
158
+ config.individualRequestTimeout = 120000;
159
+
160
+ // URLs longas para testes
161
+ config.maxUrlLength = 4096;
162
+ } else if (phase === 'production') {
163
+ // Mais restritivo em produção
164
+ config.maxHeadersCount = 50;
165
+ config.maxUrlLength = 1024;
166
+ config.requestTimeout = 20000;
167
+ config.individualRequestTimeout = 20000;
168
+
169
+ // Timeouts mais curtos para headers
170
+ config.headersTimeout = 30000;
171
+ config.serverTimeout = 25000;
172
+ }
173
+
174
+ return config;
175
+ };
176
+
177
+ export default hightConfig;
178
+ ```
179
+
180
+ ## 📍 Localização do Arquivo
181
+
182
+ O arquivo `hightjs.config.ts` (ou `.js`) deve estar na **raiz do seu projeto**, no mesmo nível do `package.json`.
183
+
184
+ ```
185
+ seu-projeto/
186
+ ├── hightjs.config.ts ← Aqui
187
+ ├── package.json
188
+ ├── tsconfig.json
189
+ └── src/
190
+ └── web/
191
+ └── ...
192
+ ```
193
+
194
+ ## ⚠️ Notas Importantes
195
+
196
+ 1. **Prioridade**: `.ts` tem prioridade sobre `.js` se ambos existirem
197
+ 2. **Fallback**: Se o arquivo não existir, valores padrão serão usados
198
+ 3. **Validação**: Valores inválidos serão ignorados e substituídos pelos padrões
199
+ 4. **Performance**: Use valores apropriados para evitar timeouts desnecessários ou aberturas de segurança
200
+ 5. **Segurança**: Não exponha valores muito altos em produção (ex: `maxUrlLength` muito grande pode facilitar ataques DoS)
201
+
@@ -0,0 +1,81 @@
1
+ import type { HightConfig, HightConfigFunction } from 'hightjs';
2
+
3
+ /**
4
+ * HightJS Configuration File
5
+ *
6
+ * This file allows you to customize server settings for your HightJS application.
7
+ * You can export either a static configuration object or a function that returns the configuration.
8
+ *
9
+ * In a real project, you would import from 'hightjs' instead:
10
+ * import type { HightConfig, HightConfigFunction } from 'hightjs';
11
+ */
12
+ const hightConfig: HightConfigFunction = (phase, { defaultConfig }) => {
13
+ const config: HightConfig = {
14
+ /**
15
+ * Maximum number of HTTP headers allowed per request
16
+ * Default: 100
17
+ * Increase this if you need to support requests with many headers
18
+ */
19
+ maxHeadersCount: 100,
20
+
21
+ /**
22
+ * Timeout in milliseconds for receiving HTTP headers
23
+ * Default: 60000 (60 seconds)
24
+ */
25
+ headersTimeout: 60000,
26
+
27
+ /**
28
+ * Timeout in milliseconds for a complete request
29
+ * Default: 30000 (30 seconds)
30
+ */
31
+ requestTimeout: 30000,
32
+
33
+ /**
34
+ * General server timeout in milliseconds
35
+ * Default: 35000 (35 seconds)
36
+ */
37
+ serverTimeout: 35000,
38
+
39
+ /**
40
+ * Timeout per individual request in milliseconds
41
+ * Default: 30000 (30 seconds)
42
+ */
43
+ individualRequestTimeout: 30000,
44
+
45
+ /**
46
+ * Maximum URL length in characters
47
+ * Default: 2048
48
+ */
49
+ maxUrlLength: 2048,
50
+ };
51
+
52
+ // You can customize settings based on the phase
53
+ if (phase === 'development') {
54
+ // In development, you might want longer timeouts for debugging
55
+ config.requestTimeout = 60000;
56
+ config.individualRequestTimeout = 60000;
57
+ }
58
+
59
+ if (phase === 'production') {
60
+ // In production, you might want stricter limits
61
+ config.maxHeadersCount = 50;
62
+ config.maxUrlLength = 1024;
63
+ }
64
+
65
+ return config;
66
+ };
67
+
68
+ export default hightConfig;
69
+
70
+ // You can also export a static object instead of a function:
71
+ // const staticConfig: HightConfig = {
72
+ // maxHeadersCount: 100,
73
+ // headersTimeout: 60000,
74
+ // requestTimeout: 30000,
75
+ // serverTimeout: 35000,
76
+ // individualRequestTimeout: 30000,
77
+ // maxUrlLength: 2048,
78
+ // };
79
+ //
80
+ // export default staticConfig;
81
+