flowingts 0.0.0 → 0.19.0
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/LICENSE +15 -0
- package/README.md +74 -3
- package/dist/core/abort.d.ts +23 -0
- package/dist/core/abort.d.ts.map +1 -0
- package/dist/core/abort.js +23 -0
- package/dist/core/abort.js.map +1 -0
- package/dist/core/app/core.d.ts +35 -0
- package/dist/core/app/core.d.ts.map +1 -0
- package/dist/core/app/core.js +2 -0
- package/dist/core/app/core.js.map +1 -0
- package/dist/core/app/options.d.ts +178 -0
- package/dist/core/app/options.d.ts.map +1 -0
- package/dist/core/app/options.js +2 -0
- package/dist/core/app/options.js.map +1 -0
- package/dist/core/app.d.ts +143 -0
- package/dist/core/app.d.ts.map +1 -0
- package/dist/core/app.js +283 -0
- package/dist/core/app.js.map +1 -0
- package/dist/core/body-parser.d.ts +14 -0
- package/dist/core/body-parser.d.ts.map +1 -0
- package/dist/core/body-parser.js +76 -0
- package/dist/core/body-parser.js.map +1 -0
- package/dist/core/compiler.d.ts +104 -0
- package/dist/core/compiler.d.ts.map +1 -0
- package/dist/core/compiler.js +151 -0
- package/dist/core/compiler.js.map +1 -0
- package/dist/core/compose.d.ts +16 -0
- package/dist/core/compose.d.ts.map +1 -0
- package/dist/core/compose.js +41 -0
- package/dist/core/compose.js.map +1 -0
- package/dist/core/context.d.ts +290 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +460 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/contracts.d.ts +76 -0
- package/dist/core/contracts.d.ts.map +1 -0
- package/dist/core/contracts.js +87 -0
- package/dist/core/contracts.js.map +1 -0
- package/dist/core/errors.d.ts +50 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +25 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/guard.d.ts +10 -0
- package/dist/core/guard.d.ts.map +1 -0
- package/dist/core/guard.js +14 -0
- package/dist/core/guard.js.map +1 -0
- package/dist/core/health.d.ts +37 -0
- package/dist/core/health.d.ts.map +1 -0
- package/dist/core/health.js +68 -0
- package/dist/core/health.js.map +1 -0
- package/dist/core/hooks.d.ts +34 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +27 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/index.d.ts +30 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/infer.d.ts +68 -0
- package/dist/core/infer.d.ts.map +1 -0
- package/dist/core/infer.js +2 -0
- package/dist/core/infer.js.map +1 -0
- package/dist/core/inject.d.ts +27 -0
- package/dist/core/inject.d.ts.map +1 -0
- package/dist/core/inject.js +85 -0
- package/dist/core/inject.js.map +1 -0
- package/dist/core/logger.d.ts +57 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +134 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/metadata.d.ts +83 -0
- package/dist/core/metadata.d.ts.map +1 -0
- package/dist/core/metadata.js +91 -0
- package/dist/core/metadata.js.map +1 -0
- package/dist/core/mounted-group.d.ts +77 -0
- package/dist/core/mounted-group.d.ts.map +1 -0
- package/dist/core/mounted-group.js +131 -0
- package/dist/core/mounted-group.js.map +1 -0
- package/dist/core/registry/framework-routes.d.ts +28 -0
- package/dist/core/registry/framework-routes.d.ts.map +1 -0
- package/dist/core/registry/framework-routes.js +83 -0
- package/dist/core/registry/framework-routes.js.map +1 -0
- package/dist/core/registry/registry.d.ts +58 -0
- package/dist/core/registry/registry.d.ts.map +1 -0
- package/dist/core/registry/registry.js +208 -0
- package/dist/core/registry/registry.js.map +1 -0
- package/dist/core/registry/route-program.d.ts +16 -0
- package/dist/core/registry/route-program.d.ts.map +1 -0
- package/dist/core/registry/route-program.js +62 -0
- package/dist/core/registry/route-program.js.map +1 -0
- package/dist/core/request-validation.d.ts +15 -0
- package/dist/core/request-validation.d.ts.map +1 -0
- package/dist/core/request-validation.js +67 -0
- package/dist/core/request-validation.js.map +1 -0
- package/dist/core/response/pipeline.d.ts +51 -0
- package/dist/core/response/pipeline.d.ts.map +1 -0
- package/dist/core/response/pipeline.js +169 -0
- package/dist/core/response/pipeline.js.map +1 -0
- package/dist/core/route-table.d.ts +58 -0
- package/dist/core/route-table.d.ts.map +1 -0
- package/dist/core/route-table.js +108 -0
- package/dist/core/route-table.js.map +1 -0
- package/dist/core/runtime/observer.d.ts +47 -0
- package/dist/core/runtime/observer.d.ts.map +1 -0
- package/dist/core/runtime/observer.js +125 -0
- package/dist/core/runtime/observer.js.map +1 -0
- package/dist/core/runtime/request-handler.d.ts +62 -0
- package/dist/core/runtime/request-handler.d.ts.map +1 -0
- package/dist/core/runtime/request-handler.js +256 -0
- package/dist/core/runtime/request-handler.js.map +1 -0
- package/dist/core/runtime/server.d.ts +59 -0
- package/dist/core/runtime/server.d.ts.map +1 -0
- package/dist/core/runtime/server.js +180 -0
- package/dist/core/runtime/server.js.map +1 -0
- package/dist/core/shutdown.d.ts +41 -0
- package/dist/core/shutdown.d.ts.map +1 -0
- package/dist/core/shutdown.js +53 -0
- package/dist/core/shutdown.js.map +1 -0
- package/dist/core/streaming/sse.d.ts +35 -0
- package/dist/core/streaming/sse.d.ts.map +1 -0
- package/dist/core/streaming/sse.js +121 -0
- package/dist/core/streaming/sse.js.map +1 -0
- package/dist/core/symbols.d.ts +28 -0
- package/dist/core/symbols.d.ts.map +1 -0
- package/dist/core/symbols.js +28 -0
- package/dist/core/symbols.js.map +1 -0
- package/dist/core/telemetry.d.ts +83 -0
- package/dist/core/telemetry.d.ts.map +1 -0
- package/dist/core/telemetry.js +96 -0
- package/dist/core/telemetry.js.map +1 -0
- package/dist/core/uploads/receive.d.ts +63 -0
- package/dist/core/uploads/receive.d.ts.map +1 -0
- package/dist/core/uploads/receive.js +342 -0
- package/dist/core/uploads/receive.js.map +1 -0
- package/dist/core/uploads/types.d.ts +79 -0
- package/dist/core/uploads/types.d.ts.map +1 -0
- package/dist/core/uploads/types.js +2 -0
- package/dist/core/uploads/types.js.map +1 -0
- package/dist/decorators/hooks.d.ts +25 -0
- package/dist/decorators/hooks.d.ts.map +1 -0
- package/dist/decorators/hooks.js +36 -0
- package/dist/decorators/hooks.js.map +1 -0
- package/dist/decorators/http.d.ts +21 -0
- package/dist/decorators/http.d.ts.map +1 -0
- package/dist/decorators/http.js +21 -0
- package/dist/decorators/http.js.map +1 -0
- package/dist/decorators/index.d.ts +7 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +7 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/log.d.ts +10 -0
- package/dist/decorators/log.d.ts.map +1 -0
- package/dist/decorators/log.js +32 -0
- package/dist/decorators/log.js.map +1 -0
- package/dist/decorators/middlewares.d.ts +28 -0
- package/dist/decorators/middlewares.d.ts.map +1 -0
- package/dist/decorators/middlewares.js +40 -0
- package/dist/decorators/middlewares.js.map +1 -0
- package/dist/decorators/router.d.ts +12 -0
- package/dist/decorators/router.d.ts.map +1 -0
- package/dist/decorators/router.js +20 -0
- package/dist/decorators/router.js.map +1 -0
- package/dist/decorators/schema.d.ts +8 -0
- package/dist/decorators/schema.d.ts.map +1 -0
- package/dist/decorators/schema.js +14 -0
- package/dist/decorators/schema.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/auth.d.ts +41 -0
- package/dist/middlewares/auth.d.ts.map +1 -0
- package/dist/middlewares/auth.js +74 -0
- package/dist/middlewares/auth.js.map +1 -0
- package/dist/middlewares/cors.d.ts +30 -0
- package/dist/middlewares/cors.d.ts.map +1 -0
- package/dist/middlewares/cors.js +69 -0
- package/dist/middlewares/cors.js.map +1 -0
- package/dist/middlewares/csrf.d.ts +42 -0
- package/dist/middlewares/csrf.d.ts.map +1 -0
- package/dist/middlewares/csrf.js +70 -0
- package/dist/middlewares/csrf.js.map +1 -0
- package/dist/middlewares/index.d.ts +6 -0
- package/dist/middlewares/index.d.ts.map +1 -0
- package/dist/middlewares/index.js +6 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/rate-limit.d.ts +35 -0
- package/dist/middlewares/rate-limit.d.ts.map +1 -0
- package/dist/middlewares/rate-limit.js +45 -0
- package/dist/middlewares/rate-limit.js.map +1 -0
- package/dist/middlewares/security-headers.d.ts +28 -0
- package/dist/middlewares/security-headers.d.ts.map +1 -0
- package/dist/middlewares/security-headers.js +42 -0
- package/dist/middlewares/security-headers.js.map +1 -0
- package/dist/openapi/generate.d.ts +51 -0
- package/dist/openapi/generate.d.ts.map +1 -0
- package/dist/openapi/generate.js +175 -0
- package/dist/openapi/generate.js.map +1 -0
- package/dist/schema/serialization.d.ts +2 -0
- package/dist/schema/serialization.d.ts.map +1 -0
- package/dist/schema/serialization.js +11 -0
- package/dist/schema/serialization.js.map +1 -0
- package/dist/schema/validation.d.ts +22 -0
- package/dist/schema/validation.d.ts.map +1 -0
- package/dist/schema/validation.js +68 -0
- package/dist/schema/validation.js.map +1 -0
- package/dist/server/static.d.ts +45 -0
- package/dist/server/static.d.ts.map +1 -0
- package/dist/server/static.js +204 -0
- package/dist/server/static.js.map +1 -0
- package/dist/server/tls.d.ts +48 -0
- package/dist/server/tls.d.ts.map +1 -0
- package/dist/server/tls.js +60 -0
- package/dist/server/tls.js.map +1 -0
- package/dist/shims/symbol-metadata.d.ts +2 -0
- package/dist/shims/symbol-metadata.d.ts.map +1 -0
- package/dist/shims/symbol-metadata.js +8 -0
- package/dist/shims/symbol-metadata.js.map +1 -0
- package/dist/utils/content-type.d.ts +13 -0
- package/dist/utils/content-type.d.ts.map +1 -0
- package/dist/utils/content-type.js +75 -0
- package/dist/utils/content-type.js.map +1 -0
- package/dist/utils/cookie.d.ts +34 -0
- package/dist/utils/cookie.d.ts.map +1 -0
- package/dist/utils/cookie.js +94 -0
- package/dist/utils/cookie.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +52 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/origin-match.d.ts +58 -0
- package/dist/utils/origin-match.d.ts.map +1 -0
- package/dist/utils/origin-match.js +194 -0
- package/dist/utils/origin-match.js.map +1 -0
- package/dist/utils/path.d.ts +10 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +60 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/query.d.ts +28 -0
- package/dist/utils/query.d.ts.map +1 -0
- package/dist/utils/query.js +67 -0
- package/dist/utils/query.js.map +1 -0
- package/dist/utils/request-target.d.ts +31 -0
- package/dist/utils/request-target.d.ts.map +1 -0
- package/dist/utils/request-target.js +80 -0
- package/dist/utils/request-target.js.map +1 -0
- package/dist/utils/safe-json.d.ts +24 -0
- package/dist/utils/safe-json.d.ts.map +1 -0
- package/dist/utils/safe-json.js +83 -0
- package/dist/utils/safe-json.js.map +1 -0
- package/dist/utils/trace-context.d.ts +17 -0
- package/dist/utils/trace-context.d.ts.map +1 -0
- package/dist/utils/trace-context.js +30 -0
- package/dist/utils/trace-context.js.map +1 -0
- package/package.json +85 -6
package/dist/core/app.js
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { uploadSettings } from './uploads/receive.js';
|
|
2
|
+
import '../shims/symbol-metadata.js';
|
|
3
|
+
import { childScope, joinPrefix, compileAutoRoutes, compileManualRoute, createGroup, ROOT_SCOPE, } from './compiler.js';
|
|
4
|
+
import { MountedGroup, RouteGroupScope } from './mounted-group.js';
|
|
5
|
+
import { staticHandler } from '../server/static.js';
|
|
6
|
+
import { canonicalPath, joinPaths } from '../utils/path.js';
|
|
7
|
+
import { generateOpenAPI } from '../openapi/generate.js';
|
|
8
|
+
import { compileHealth } from './health.js';
|
|
9
|
+
import { mediaType } from '../utils/content-type.js';
|
|
10
|
+
import { compileHostMatcher } from '../utils/origin-match.js';
|
|
11
|
+
import { inject } from './inject.js';
|
|
12
|
+
import { guardsMiddleware } from './guard.js';
|
|
13
|
+
import { consoleLogger, silentLogger } from './logger.js';
|
|
14
|
+
import { createTelemetry } from './telemetry.js';
|
|
15
|
+
import { buildSecurityHeaders } from '../middlewares/security-headers.js';
|
|
16
|
+
import { FrameworkRoutes } from './registry/framework-routes.js';
|
|
17
|
+
import { RouteRegistry } from './registry/registry.js';
|
|
18
|
+
import { RequestHandler } from './runtime/request-handler.js';
|
|
19
|
+
import { RequestObserver } from './runtime/observer.js';
|
|
20
|
+
import { ServerLifecycle } from './runtime/server.js';
|
|
21
|
+
import { routeHooks } from './hooks.js';
|
|
22
|
+
import { NATIVE_CONTRACTS } from './contracts.js';
|
|
23
|
+
function assertOpen(scope) {
|
|
24
|
+
if (scope.token && !scope.token.open) {
|
|
25
|
+
throw new Error('[flowing] app.group(): this group has already finished; register its routes inside the callback, synchronously.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const isThenable = (v) => (typeof v === 'object' || typeof v === 'function') && v !== null && typeof v.then === 'function';
|
|
29
|
+
/**
|
|
30
|
+
* O app. É uma fachada (Facade) sobre o registro de rotas, as rotas do próprio framework (health, OpenAPI),
|
|
31
|
+
* o servidor e o pipeline da requisição: a API pública fica aqui, e o trabalho fica nesses componentes.
|
|
32
|
+
*/
|
|
33
|
+
export class FlowingApp {
|
|
34
|
+
log;
|
|
35
|
+
core;
|
|
36
|
+
registry;
|
|
37
|
+
framework;
|
|
38
|
+
runtime;
|
|
39
|
+
requests;
|
|
40
|
+
constructor(opts = {}) {
|
|
41
|
+
this.log = opts.logger === false ? silentLogger : (opts.logger ?? consoleLogger());
|
|
42
|
+
this.core = {
|
|
43
|
+
opts,
|
|
44
|
+
log: this.log,
|
|
45
|
+
middlewares: [],
|
|
46
|
+
errorHandlers: [],
|
|
47
|
+
onSendHooks: [],
|
|
48
|
+
onRequestHooks: [],
|
|
49
|
+
contracts: opts.contracts ?? NATIVE_CONTRACTS,
|
|
50
|
+
telemetry: opts.telemetry ? createTelemetry(opts.telemetry) : undefined,
|
|
51
|
+
onResponseHooks: [],
|
|
52
|
+
scopedOnResponse: 0,
|
|
53
|
+
onCloseHooks: [],
|
|
54
|
+
// Compilados na criação: uma regra inválida falha aqui, e não na primeira requisição.
|
|
55
|
+
allowedHosts: opts.allowedHosts ? compileHostMatcher(opts.allowedHosts) : undefined,
|
|
56
|
+
serializers: new Map(Object.entries(opts.serializers ?? {}).map(([type, fn]) => [mediaType(type), fn])),
|
|
57
|
+
uploads: uploadSettings(opts.uploads),
|
|
58
|
+
applySecurityHeaders: opts.securityHeaders !== false ? buildSecurityHeaders(opts.securityHeaders) : undefined,
|
|
59
|
+
};
|
|
60
|
+
this.registry = new RouteRegistry(this.core, () => this.framework.reservedPaths(), () => this.framework.openapi?.cache.clear());
|
|
61
|
+
this.framework = new FrameworkRoutes(this.core, this.registry);
|
|
62
|
+
const observer = new RequestObserver(this.core);
|
|
63
|
+
this.runtime = new ServerLifecycle(this.core, () => this.callback(), observer);
|
|
64
|
+
this.requests = new RequestHandler(this.core, this.registry, this.framework, this.runtime, observer);
|
|
65
|
+
}
|
|
66
|
+
use(mw) {
|
|
67
|
+
this.core.middlewares.push(mw);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
onError(h) {
|
|
71
|
+
this.core.errorHandlers.push(h);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Roda imediatamente antes de escrever uma resposta com corpo (exceto streams), inclusive em erros
|
|
76
|
+
* e 404. É síncrono: pode alterar headers (ETag, assinatura) ou devolver `{ body, contentType }`
|
|
77
|
+
* novos. Se lançar, o erro é logado e a resposta original é enviada (F-04).
|
|
78
|
+
*/
|
|
79
|
+
onSend(hook) {
|
|
80
|
+
this.core.onSendHooks.push(hook);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Roda no início de cada requisição, antes da validação do `Host` e dos middlewares: abrir um span, contar
|
|
85
|
+
* requisições ativas. Toda requisição que passa por aqui também passa pelo `onResponse`. É síncrono; erros
|
|
86
|
+
* são só logados (F-38).
|
|
87
|
+
*/
|
|
88
|
+
onRequest(hook) {
|
|
89
|
+
this.core.onRequestHooks.push(hook);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Roda exatamente uma vez quando a requisição termina, com status, duração, `outcome` (`completed`,
|
|
94
|
+
* `aborted`, `error`), motivo do cancelamento, tempo até os headers, rota e se foi stream: métricas,
|
|
95
|
+
* tracing, auditoria. Pode ser assíncrono; erros são só logados (F-04, F-38).
|
|
96
|
+
*/
|
|
97
|
+
onResponse(hook) {
|
|
98
|
+
this.core.onResponseHooks.push(hook);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Roda no `close()`, depois que o servidor fecha, qualquer que seja a origem (sinal, teste, código),
|
|
103
|
+
* e antes do `shutdown.onShutdown`. Erros são logados e fazem o `close()` rejeitar ao final (F-04).
|
|
104
|
+
*/
|
|
105
|
+
onClose(hook) {
|
|
106
|
+
this.core.onCloseHooks.push(hook);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
mount(ref, options = {}) {
|
|
110
|
+
return this.mountIn(ROOT_SCOPE, ref, options);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Agrupa `mount()`s sob um prefixo, middlewares e guards comuns. Não é um container: é só composição,
|
|
114
|
+
* com a mesma semântica do `mount()`. Grupos podem ser aninhados.
|
|
115
|
+
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* app.group({ prefix: '/v2', middlewares: [authenticate], guards: [isAdmin] }, (g) =>
|
|
118
|
+
* g.mount(UserRoutes).mount(new OrderRoutes(db)),
|
|
119
|
+
* );
|
|
120
|
+
* ```
|
|
121
|
+
* Ordem de execução: middlewares dos grupos (de fora para dentro) → do `mount()` → da classe → do método.
|
|
122
|
+
*/
|
|
123
|
+
group(options, define) {
|
|
124
|
+
this.groupIn(ROOT_SCOPE, options, define);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/** @internal */
|
|
128
|
+
groupIn(parent, options, define) {
|
|
129
|
+
assertOpen(parent);
|
|
130
|
+
const scope = childScope(parent, options);
|
|
131
|
+
// Registro em duas fases: o que o callback registrar fica pendente e só é efetivado se ele terminar
|
|
132
|
+
// de forma síncrona e sem erro. Grupos aninhados entram no lote do grupo mais externo; se um aninhado
|
|
133
|
+
// falhar (mesmo com o erro capturado pelo externo), só a parte dele é descartada.
|
|
134
|
+
const outermost = this.registry.pending === undefined;
|
|
135
|
+
if (outermost)
|
|
136
|
+
this.registry.pending = [];
|
|
137
|
+
const mark = this.registry.pending.length;
|
|
138
|
+
try {
|
|
139
|
+
const result = define(new RouteGroupScope(this, scope));
|
|
140
|
+
if (isThenable(result)) {
|
|
141
|
+
// O callback continua rodando depois do `await`; o escopo fechado abaixo rejeita registros
|
|
142
|
+
// tardios, e este handler evita um unhandledRejection.
|
|
143
|
+
result.then(undefined, (err) => this.log.error({ err }, 'async app.group() callback failed after the group was rejected'));
|
|
144
|
+
throw new Error('[flowing] app.group(): the callback must be synchronous; do async work before registering routes.');
|
|
145
|
+
}
|
|
146
|
+
if (outermost)
|
|
147
|
+
this.registry.commit(this.registry.pending);
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
this.registry.pending.length = mark;
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
scope.token.open = false;
|
|
155
|
+
if (outermost)
|
|
156
|
+
this.registry.pending = undefined;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Serve os arquivos de `root` em `GET prefix/*` (F-13). É uma rota como as outras: vale `group()`
|
|
161
|
+
* (host, guards, middlewares), 404/405 e a checagem de conflitos. Não entra no OpenAPI.
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* app.static('/assets', './public', { maxAge: '7d', immutable: true });
|
|
165
|
+
* app.static('/', './dist', { fallback: 'index.html' }); // SPA
|
|
166
|
+
* ```
|
|
167
|
+
* Caminhos que saem da raiz (`..`, symlinks), arquivos ocultos e diretórios sem índice respondem 404.
|
|
168
|
+
*/
|
|
169
|
+
static(prefix, root, opts = {}) {
|
|
170
|
+
this.staticIn(ROOT_SCOPE, prefix, root, opts);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
/** @internal */
|
|
174
|
+
staticIn(scope, prefix, root, opts) {
|
|
175
|
+
assertOpen(scope);
|
|
176
|
+
const handler = staticHandler(root, opts);
|
|
177
|
+
const base = joinPrefix(scope.prefix, prefix) || '/';
|
|
178
|
+
const route = (path) => ({
|
|
179
|
+
method: 'GET',
|
|
180
|
+
path,
|
|
181
|
+
handler: (ctx) => handler(ctx),
|
|
182
|
+
schemas: {},
|
|
183
|
+
middlewares: [...scope.middlewares],
|
|
184
|
+
guards: [...scope.guards],
|
|
185
|
+
hooks: routeHooks(scope.hooks),
|
|
186
|
+
owner: 'static',
|
|
187
|
+
handlerName: `static('${prefix}')`,
|
|
188
|
+
hosts: scope.hosts,
|
|
189
|
+
internal: true,
|
|
190
|
+
});
|
|
191
|
+
// `prefix/*` cobre os arquivos; o próprio prefixo (`/assets`, `/assets/`) serve o índice.
|
|
192
|
+
const routes = [route(joinPaths(base, '*'))];
|
|
193
|
+
if (base !== '/')
|
|
194
|
+
routes.push(route(base));
|
|
195
|
+
this.registry.stage(`static('${prefix}')`, routes);
|
|
196
|
+
}
|
|
197
|
+
/** @internal */
|
|
198
|
+
mountIn(scope, ref, options = {}) {
|
|
199
|
+
assertOpen(scope);
|
|
200
|
+
const group = createGroup(ref, options, scope);
|
|
201
|
+
this.registry.stage(group.name, compileAutoRoutes(group));
|
|
202
|
+
return new MountedGroup(this, group, (g, method, path, select, opts) => {
|
|
203
|
+
assertOpen(scope);
|
|
204
|
+
this.registry.stage(g.name, [compileManualRoute(g, method, path, select, opts)]);
|
|
205
|
+
}, scope);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Serve o documento OpenAPI 3.1 gerado das rotas (`/openapi.json`) e, com `docs`, o Swagger UI (F-16).
|
|
209
|
+
* As duas rotas passam pelos middlewares globais e pelos `middlewares`/`guards` informados aqui:
|
|
210
|
+
* `app.openapi({ guards: [isAdmin] })`. O documento é gerado na primeira requisição, depois dos `mount()`.
|
|
211
|
+
*/
|
|
212
|
+
openapi(opts = {}) {
|
|
213
|
+
const path = opts.path ?? '/openapi.json';
|
|
214
|
+
const docs = opts.docs === true ? '/docs' : opts.docs || false;
|
|
215
|
+
if (docs && canonicalPath(docs) === canonicalPath(path))
|
|
216
|
+
throw new Error(`[flowing] openapi(): "docs" and "path" cannot both be "${path}".`);
|
|
217
|
+
this.framework.assertFreePaths('app.openapi()', docs ? [canonicalPath(path), canonicalPath(docs)] : [canonicalPath(path)], 'openapi');
|
|
218
|
+
const pipeline = [...(opts.middlewares ?? [])];
|
|
219
|
+
if (opts.guards?.length)
|
|
220
|
+
pipeline.push(guardsMiddleware(opts.guards));
|
|
221
|
+
this.framework.openapi = { opts, path, docs, pipeline, cache: new Map() };
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Healthchecks para load balancers e orquestradores (Kubernetes, ECS…).
|
|
226
|
+
* - `GET /livez`: o processo está de pé (200 sempre).
|
|
227
|
+
* - `GET /readyz`: pronto para receber tráfego. Roda os `checks` (banco, fila…) e responde 503 se algum
|
|
228
|
+
* falhar ou estourar o tempo, e também durante o encerramento.
|
|
229
|
+
*
|
|
230
|
+
* As rotas são servidas **antes** dos middlewares globais (sondas não têm credenciais nem devem
|
|
231
|
+
* consumir rate limit); use `guards`/`middlewares` aqui para restringir.
|
|
232
|
+
*/
|
|
233
|
+
health(opts = {}) {
|
|
234
|
+
const config = compileHealth(opts, this.log);
|
|
235
|
+
this.framework.assertFreePaths('app.health()', config.paths, 'health');
|
|
236
|
+
this.framework.health = config;
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Documento OpenAPI 3.1 das rotas registradas até agora, para gravar em arquivo ou testar (F-16).
|
|
241
|
+
* Com virtual hosts, é por host (F-35): `{ host: 'api.exemplo.com' }` traz as rotas desse host e as sem
|
|
242
|
+
* host; sem `host`, só as sem host. Domínios diferentes nunca se misturam num mesmo documento.
|
|
243
|
+
*/
|
|
244
|
+
openapiDocument(opts = this.framework.openapi?.opts ?? {}) {
|
|
245
|
+
return generateOpenAPI(this.registry.routesFor(opts.host?.toLowerCase()), opts, !this.core.opts.formatError, (s) => this.core.contracts.toJsonSchema(s));
|
|
246
|
+
}
|
|
247
|
+
/** Executa o pipeline completo para um contexto já criado. */
|
|
248
|
+
handle(ctx) {
|
|
249
|
+
return this.requests.handle(ctx);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Listener `(req, res)` do app, para usar com qualquer servidor do Node:
|
|
253
|
+
* `https.createServer(opts, app.callback())`, `http2` em modo compat, testes etc. (F-09).
|
|
254
|
+
*/
|
|
255
|
+
callback() {
|
|
256
|
+
return this.requests.callback();
|
|
257
|
+
}
|
|
258
|
+
listen(options = {}) {
|
|
259
|
+
return this.runtime.listen(options);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Troca os certificados sem reiniciar nem derrubar conexões (renovação, ACME externo). Conexões novas
|
|
263
|
+
* usam os novos; as abertas seguem com os antigos. Um certificado inválido lança erro e mantém os atuais.
|
|
264
|
+
*/
|
|
265
|
+
reloadTLS(tls) {
|
|
266
|
+
this.runtime.reloadTLS(tls);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Para de aceitar conexões, encerra as ociosas e espera as requisições em andamento terminarem.
|
|
270
|
+
* Depois de `graceMs`, força o fechamento das restantes.
|
|
271
|
+
*/
|
|
272
|
+
close(graceMs = 10_000) {
|
|
273
|
+
return this.runtime.close(graceMs);
|
|
274
|
+
}
|
|
275
|
+
/** Executa uma requisição em memória, sem rede. Ideal para testes (F-09). */
|
|
276
|
+
inject(opts) {
|
|
277
|
+
return inject(this.callback(), typeof opts === 'string' ? { url: opts } : opts);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
export function createApp(opts) {
|
|
281
|
+
return new FlowingApp(opts);
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/core/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,6BAA6B,CAAC;AAErC,OAAO,EACL,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,UAAU,GAMX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGnE,OAAO,EAAE,aAAa,EAAsB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAuB,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAsB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAA2C,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAe,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAA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} from './context.ts';
|
|
2
|
+
import { type ProtoPoisoning } from '../utils/safe-json.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Parser de body para um tipo de mídia (F-12): recebe o corpo cru, já limitado pelo `bodyLimit`, e devolve o valor
|
|
5
|
+
* de `ctx.body`. Pode ser assíncrono. O resultado passa pela proteção contra prototype pollution (S-08) e é validado
|
|
6
|
+
* pelo contrato da rota, como o JSON.
|
|
7
|
+
*/
|
|
8
|
+
export type BodyParser = (raw: Buffer, ctx: Context) => unknown;
|
|
9
|
+
/**
|
|
10
|
+
* Lê e parseia o body: JSON nativo e os `parsers` do app (F-12), respeitando `limit` em bytes. O app chama antes dos
|
|
11
|
+
* middlewares globais, que recebem o body já lido; é uma etapa direta, sem camada de middleware (F-39).
|
|
12
|
+
*/
|
|
13
|
+
export declare function bodyReader(limit: number, protoPoisoning?: ProtoPoisoning, parsers?: ReadonlyMap<string, BodyParser>): (ctx: Context) => Promise<void> | undefined;
|
|
14
|
+
//# sourceMappingURL=body-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-parser.d.ts","sourceRoot":"","sources":["../../src/core/body-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAkC,KAAK,cAAc,EAAe,MAAM,uBAAuB,CAAC;AAEzG;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;AAEhE;;;GAGG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,cAAc,GAAE,cAAwB,EACxC,OAAO,GAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAa,GACnD,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CA8D7C"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { isJsonContentType, mediaType } from '../utils/content-type.js';
|
|
2
|
+
import { parseJson, ProtoPoisoningError, scrubParsed } from '../utils/safe-json.js';
|
|
3
|
+
/**
|
|
4
|
+
* Lê e parseia o body: JSON nativo e os `parsers` do app (F-12), respeitando `limit` em bytes. O app chama antes dos
|
|
5
|
+
* middlewares globais, que recebem o body já lido; é uma etapa direta, sem camada de middleware (F-39).
|
|
6
|
+
*/
|
|
7
|
+
export function bodyReader(limit, protoPoisoning = 'error', parsers = new Map()) {
|
|
8
|
+
// Síncrono quando não há body a ler (GET, HEAD, outro Content-Type): sem Promise por requisição (F-41).
|
|
9
|
+
return (ctx) => {
|
|
10
|
+
if (ctx.method === 'GET' || ctx.method === 'HEAD')
|
|
11
|
+
return undefined;
|
|
12
|
+
const contentType = ctx.req.headers['content-type'];
|
|
13
|
+
if (isJsonContentType(contentType))
|
|
14
|
+
return readJson(ctx);
|
|
15
|
+
// Sem parsers configurados, nem o tipo de mídia é calculado.
|
|
16
|
+
if (parsers.size === 0)
|
|
17
|
+
return undefined;
|
|
18
|
+
const parser = parsers.get(mediaType(contentType));
|
|
19
|
+
return parser ? readWith(ctx, parser) : undefined;
|
|
20
|
+
};
|
|
21
|
+
async function readRaw(ctx) {
|
|
22
|
+
// B-12: rejeita cedo pelo Content-Length e fecha a conexão ao exceder,
|
|
23
|
+
// para o cliente não continuar enviando um corpo que será descartado.
|
|
24
|
+
const tooLarge = () => {
|
|
25
|
+
ctx.res.setHeader('Connection', 'close');
|
|
26
|
+
return ctx.throw(413, 'Payload too large', 'PAYLOAD_TOO_LARGE');
|
|
27
|
+
};
|
|
28
|
+
const declared = Number(ctx.req.headers['content-length']);
|
|
29
|
+
if (Number.isFinite(declared) && declared > limit)
|
|
30
|
+
tooLarge();
|
|
31
|
+
const chunks = [];
|
|
32
|
+
let size = 0;
|
|
33
|
+
for await (const chunk of ctx.req) {
|
|
34
|
+
size += chunk.length;
|
|
35
|
+
if (size > limit)
|
|
36
|
+
tooLarge();
|
|
37
|
+
chunks.push(chunk);
|
|
38
|
+
}
|
|
39
|
+
return Buffer.concat(chunks);
|
|
40
|
+
}
|
|
41
|
+
async function readJson(ctx) {
|
|
42
|
+
const raw = (await readRaw(ctx)).toString('utf8');
|
|
43
|
+
if (raw) {
|
|
44
|
+
try {
|
|
45
|
+
ctx.body = parseJson(raw, protoPoisoning);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
// S-08: `__proto__` e `constructor.prototype` no body são recusados (ou removidos, se configurado).
|
|
49
|
+
if (err instanceof ProtoPoisoningError)
|
|
50
|
+
ctx.throw(400, err.message, 'PROTO_POISONING');
|
|
51
|
+
ctx.throw(400, 'Invalid JSON', 'INVALID_JSON');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function readWith(ctx, parser) {
|
|
56
|
+
const raw = await readRaw(ctx);
|
|
57
|
+
if (raw.length === 0)
|
|
58
|
+
return;
|
|
59
|
+
let value;
|
|
60
|
+
try {
|
|
61
|
+
value = await parser(raw, ctx);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// A mensagem do parser pode expor detalhes internos: o cliente recebe só o motivo genérico.
|
|
65
|
+
ctx.throw(400, 'Invalid body', 'INVALID_BODY');
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
scrubParsed(value, protoPoisoning);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
ctx.throw(400, err.message, 'PROTO_POISONING');
|
|
72
|
+
}
|
|
73
|
+
ctx.body = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=body-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-parser.js","sourceRoot":"","sources":["../../src/core/body-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAA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,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,CAAC;YACH,WAAW,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,KAAK,CAAC,GAAG,EAAG,GAAa,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QAC5D,CAAC;QACD,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Guard } from './guard.ts';
|
|
2
|
+
import type { Middleware } from './compose.ts';
|
|
3
|
+
import { type RouterMetadata } from './metadata.ts';
|
|
4
|
+
import type { RouteDefinition } from './route-table.ts';
|
|
5
|
+
import { type MatchRule, type RouteHostRule } from '../utils/origin-match.ts';
|
|
6
|
+
import { type HookOptions, type RouteHooks, type ScopedHooks } from './hooks.ts';
|
|
7
|
+
export interface CompiledRoute extends RouteDefinition {
|
|
8
|
+
method: string;
|
|
9
|
+
path: string;
|
|
10
|
+
/** Classe e método de origem, para mensagens e para o OpenAPI (F-16). */
|
|
11
|
+
owner: string;
|
|
12
|
+
handlerName: string;
|
|
13
|
+
/** Virtual hosts da rota (F-35); vazio = qualquer host. */
|
|
14
|
+
hosts: readonly RouteHostRule[];
|
|
15
|
+
/** Rota criada pelo framework (`static()`): fica fora do OpenAPI. */
|
|
16
|
+
internal?: boolean;
|
|
17
|
+
/** Hooks com escopo da rota (F-43), já em ordem de execução; ausente se não há nenhum. */
|
|
18
|
+
hooks?: RouteHooks | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Um host, ou uma lista: `'api.exemplo.com'`, `'*.exemplo.dev'`, `/^tenant-\d+\.exemplo\.com$/`. */
|
|
21
|
+
export type HostOption = MatchRule | readonly MatchRule[];
|
|
22
|
+
export declare function compileHostOption(host: HostOption | undefined): RouteHostRule[];
|
|
23
|
+
/** Classe com construtor sem argumentos **ou** instância já construída (B-10). */
|
|
24
|
+
export type RouterRef = (new () => object) | object;
|
|
25
|
+
type AnyMethod = (...args: never[]) => unknown;
|
|
26
|
+
/** Seleciona um método da instância montada: `(r) => r.getUser` (F-30). */
|
|
27
|
+
export type MethodSelector<T> = (routes: T) => AnyMethod;
|
|
28
|
+
/** Seleciona vários métodos: `(r) => [r.list, r.getUser]` (F-30). */
|
|
29
|
+
export type MethodsSelector<T> = (routes: T) => readonly AnyMethod[];
|
|
30
|
+
/** Opções de `app.mount()`, aplicadas no ponto de composição (F-28, F-30). */
|
|
31
|
+
export interface MountOptions<T = object> {
|
|
32
|
+
/** Substitui o prefixo definido no `@Router`. */
|
|
33
|
+
prefix?: string;
|
|
34
|
+
/** Registra só estes métodos de rota. Não pode ser usado junto com `except`. */
|
|
35
|
+
only?: MethodsSelector<T>;
|
|
36
|
+
/** Registra todos os métodos de rota, exceto estes. */
|
|
37
|
+
except?: MethodsSelector<T>;
|
|
38
|
+
/** Registra as rotas declaradas na classe. Padrão: `true`. Use `false` para só mapear manualmente. */
|
|
39
|
+
auto?: boolean;
|
|
40
|
+
/** Middlewares para todas as rotas do grupo; rodam antes dos `@Middlewares` da classe. */
|
|
41
|
+
middlewares?: readonly Middleware[];
|
|
42
|
+
/** Guards para todas as rotas do grupo; rodam antes dos `@Guards` da classe. */
|
|
43
|
+
guards?: readonly Guard[];
|
|
44
|
+
/** Hooks `onSend`, `onResponse` e `onError` só para estas rotas (F-43); rodam antes dos hooks da classe. */
|
|
45
|
+
hooks?: HookOptions;
|
|
46
|
+
/** Virtual host (F-35): as rotas só respondem nesses hosts. Sem `host`, valem para qualquer um. */
|
|
47
|
+
host?: HostOption;
|
|
48
|
+
}
|
|
49
|
+
/** Opções de uma rota mapeada manualmente: `.get(path, sel, { middlewares, guards })` (F-30). */
|
|
50
|
+
export interface ManualRouteOptions {
|
|
51
|
+
/** Rodam depois dos `@Middlewares` do método (são as mais específicas). */
|
|
52
|
+
middlewares?: readonly Middleware[];
|
|
53
|
+
/** Rodam depois dos `@Guards` do método. */
|
|
54
|
+
guards?: readonly Guard[];
|
|
55
|
+
/** Hooks só desta rota (F-43): os mais específicos. */
|
|
56
|
+
hooks?: HookOptions;
|
|
57
|
+
}
|
|
58
|
+
/** Opções de `app.group()`: valem para todos os `mount()` do grupo, inclusive de grupos aninhados. */
|
|
59
|
+
export interface GroupOptions {
|
|
60
|
+
/** Somado antes do prefixo de cada classe: `group({ prefix: '/v2' })` + `@Router('/users')` → `/v2/users`. */
|
|
61
|
+
prefix?: string;
|
|
62
|
+
/** Rodam antes dos middlewares do `mount()`. */
|
|
63
|
+
middlewares?: readonly Middleware[];
|
|
64
|
+
/** Rodam antes dos guards do `mount()`. */
|
|
65
|
+
guards?: readonly Guard[];
|
|
66
|
+
/** Hooks para todas as rotas do grupo (F-43); rodam antes dos hooks do `mount()`. */
|
|
67
|
+
hooks?: HookOptions;
|
|
68
|
+
/** Virtual host (F-35) para todos os `mount()` do grupo, inclusive os aninhados. */
|
|
69
|
+
host?: HostOption;
|
|
70
|
+
}
|
|
71
|
+
/** Escopo acumulado dos grupos em volta de um `mount()`. */
|
|
72
|
+
export interface RouteScope {
|
|
73
|
+
/** Validade do grupo: depois que o callback do `group()` termina, registrar nele é erro. */
|
|
74
|
+
readonly token?: {
|
|
75
|
+
open: boolean;
|
|
76
|
+
};
|
|
77
|
+
prefix: string;
|
|
78
|
+
middlewares: readonly Middleware[];
|
|
79
|
+
guards: readonly Guard[];
|
|
80
|
+
hooks: ScopedHooks;
|
|
81
|
+
hosts: readonly RouteHostRule[];
|
|
82
|
+
}
|
|
83
|
+
export declare const ROOT_SCOPE: RouteScope;
|
|
84
|
+
/** Prefixo de um grupo dentro de outro, sem barras duplicadas; vazio não altera nada. */
|
|
85
|
+
export declare function joinPrefix(outer: string, inner: string): string;
|
|
86
|
+
/** Escopo de um grupo aninhado em `parent`. */
|
|
87
|
+
export declare function childScope(parent: RouteScope, opts: GroupOptions): RouteScope;
|
|
88
|
+
/** Um grupo montado: a instância, sua metadata e as opções do `mount`. */
|
|
89
|
+
export interface RouteGroup {
|
|
90
|
+
name: string;
|
|
91
|
+
instance: object;
|
|
92
|
+
meta: RouterMetadata;
|
|
93
|
+
prefix: string;
|
|
94
|
+
options: MountOptions;
|
|
95
|
+
scope: RouteScope;
|
|
96
|
+
hosts: readonly RouteHostRule[];
|
|
97
|
+
}
|
|
98
|
+
export declare function createGroup(ref: RouterRef, options?: MountOptions, scope?: RouteScope): RouteGroup;
|
|
99
|
+
/** Rotas declaradas na classe (`@Get`, `@Post`…), filtradas por `only`/`except` e `auto`. */
|
|
100
|
+
export declare function compileAutoRoutes(group: RouteGroup): CompiledRoute[];
|
|
101
|
+
/** Rota mapeada no app: `.get('/legacy/:id', (r) => r.getUser, opts)` (F-30). */
|
|
102
|
+
export declare function compileManualRoute(group: RouteGroup, httpMethod: string, path: string, selector: MethodSelector<object>, options?: ManualRouteOptions): CompiledRoute;
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/core/compiler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAwC,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAC1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAoB,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAChG,OAAO,EAA2B,KAAK,WAAW,EAAe,KAAK,UAAU,EAAc,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAEnI,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,MAAM,EAAE,MAAM,CAAC;I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