@decohere/http 0.0.1-dev.126 → 0.0.1-dev.5
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 +2 -2
- package/package.json +4 -13
- package/src/app/app.ts +147 -0
- package/src/app/module.ts +19 -0
- package/src/auth/ability.ts +56 -0
- package/src/auth/auth.config.ts +34 -0
- package/src/auth/auth.extensions.ts +115 -0
- package/src/auth/auth.types.ts +124 -0
- package/src/auth/casl-authorization.service.ts +62 -0
- package/{types/src/auth/principal-provider.d.ts → src/auth/principal-provider.ts} +13 -5
- package/src/auth/safe-outbound-url.ts +117 -0
- package/src/auth/token-service.ts +192 -0
- package/src/builder/builder.ts +118 -0
- package/{es6/src/const.js → src/const.ts} +25 -17
- package/src/health/health.controller.ts +34 -0
- package/src/health/health.extensions.ts +53 -0
- package/src/health/readiness.service.ts +33 -0
- package/{types/src/health/readiness.types.d.ts → src/health/readiness.types.ts} +4 -8
- package/src/hosting/hosted-service-host.ts +102 -0
- package/src/hosting/hosted-service.ts +31 -0
- package/src/http/http.compression.ts +38 -0
- package/src/http/http.extensions.ts +244 -0
- package/{types/src/http/http.options.store.d.ts → src/http/http.options.store.ts} +11 -1
- package/src/http/http.options.ts +41 -0
- package/{types/src/http/http.security.d.ts → src/http/http.security.ts} +16 -10
- package/src/http/http.static.ts +359 -0
- package/{es6/src/index.js → src/index.ts} +1 -0
- package/src/openapi/index.ts +22 -0
- package/src/openapi/openapi.generator.ts +78 -0
- package/src/openapi/openapi.types.ts +60 -0
- package/src/openapi/request-schema.ts +155 -0
- package/src/openapi/request-validator.ts +95 -0
- package/src/providers/fastify.provider.ts +454 -0
- package/src/routing/anvil.types.ts +150 -0
- package/src/routing/decorators/argument.decorator.ts +33 -0
- package/src/routing/decorators/auth.decorator.ts +79 -0
- package/src/routing/decorators/controller.decorator.ts +9 -0
- package/src/routing/decorators/field.decorator.ts +15 -0
- package/src/routing/decorators/request.decorator.ts +34 -0
- package/src/routing/decorators/response.decorator.ts +18 -0
- package/src/routing/decorators/route.decorator.ts +52 -0
- package/src/routing/filters/exception-filter-host.ts +90 -0
- package/src/routing/filters/exception-filter.ts +29 -0
- package/src/routing/middleware/http-access-log.middleware.ts +36 -0
- package/src/routing/middleware/middleware.ts +26 -0
- package/src/routing/middleware/request-id.ts +18 -0
- package/src/routing/path.util.ts +38 -0
- package/src/routing/pipes/pipes.ts +132 -0
- package/src/routing/services/route-argument-resolver.ts +92 -0
- package/src/routing/services/route-registry.ts +229 -0
- package/src/routing/services/router.ts +166 -0
- package/src/sse/sse.decorator.ts +41 -0
- package/src/sse/sse.encoder.ts +86 -0
- package/src/sse/sse.types.ts +47 -0
- package/src/sse/sse.wire.ts +34 -0
- package/src/testing/boot-module.ts +63 -0
- package/src/testing/sse-reader.ts +120 -0
- package/tests/app.hosted-services.spec.ts +292 -0
- package/tests/app.shutdown.integration.spec.ts +160 -0
- package/tests/app.spec.ts +132 -0
- package/tests/auth.ability.spec.ts +48 -0
- package/tests/auth.decorators.spec.ts +20 -0
- package/tests/auth.fail-closed.pentest.spec.ts +77 -0
- package/tests/auth.integration.spec.ts +234 -0
- package/tests/auth.jwks-cache.spec.ts +52 -0
- package/tests/auth.missing-auth.pentest.spec.ts +56 -0
- package/tests/auth.oidc-ssrf.pentest.spec.ts +72 -0
- package/tests/auth.oidc.integration.spec.ts +161 -0
- package/tests/auth.token-service.spec.ts +251 -0
- package/tests/builder.spec.ts +12 -0
- package/tests/health.integration.spec.ts +111 -0
- package/tests/helpers/listen-ephemeral.ts +13 -0
- package/tests/helpers/local-oidc-server.ts +100 -0
- package/tests/http.access-log.integration.spec.ts +111 -0
- package/tests/http.boolean-query.integration.spec.ts +59 -0
- package/tests/http.compression.integration.spec.ts +604 -0
- package/tests/http.date-query.integration.spec.ts +71 -0
- package/tests/http.global-prefix.integration.spec.ts +284 -0
- package/tests/http.number-query.integration.spec.ts +65 -0
- package/tests/http.pino-roll-hmr.integration.spec.ts +79 -0
- package/tests/http.pipeline-order.integration.spec.ts +95 -0
- package/tests/http.request-cleanup.integration.spec.ts +57 -0
- package/tests/http.request-id-scope.pentest.spec.ts +50 -0
- package/tests/http.security.integration.spec.ts +106 -0
- package/tests/http.static.integration.spec.ts +847 -0
- package/tests/http.static.spec.ts +111 -0
- package/tests/http.surface.integration.spec.ts +167 -0
- package/tests/openapi.integration.spec.ts +193 -0
- package/tests/openapi.validator-cache.integration.spec.ts +55 -0
- package/tests/routing.decorators.spec.ts +15 -0
- package/tests/routing.registry.spec.ts +44 -0
- package/tests/routing.resolver.spec.ts +92 -0
- package/tests/sse.integration.spec.ts +421 -0
- package/tests/sse.wire.spec.ts +33 -0
- package/LICENSE +0 -15
- package/commonjs/src/app/app.js +0 -166
- package/commonjs/src/app/index.js +0 -19
- package/commonjs/src/app/module.js +0 -17
- package/commonjs/src/auth/ability.js +0 -54
- package/commonjs/src/auth/auth.config.js +0 -23
- package/commonjs/src/auth/auth.extensions.js +0 -106
- package/commonjs/src/auth/auth.types.js +0 -65
- package/commonjs/src/auth/casl-authorization.service.js +0 -36
- package/commonjs/src/auth/index.js +0 -23
- package/commonjs/src/auth/principal-provider.js +0 -19
- package/commonjs/src/auth/safe-outbound-url.js +0 -102
- package/commonjs/src/auth/token-service.js +0 -151
- package/commonjs/src/builder/builder.js +0 -95
- package/commonjs/src/builder/index.js +0 -18
- package/commonjs/src/const.js +0 -87
- package/commonjs/src/health/health.controller.js +0 -75
- package/commonjs/src/health/health.extensions.js +0 -50
- package/commonjs/src/health/index.js +0 -21
- package/commonjs/src/health/readiness.service.js +0 -67
- package/commonjs/src/health/readiness.types.js +0 -7
- package/commonjs/src/hosting/hosted-service-host.js +0 -88
- package/commonjs/src/hosting/hosted-service.js +0 -11
- package/commonjs/src/hosting/index.js +0 -19
- package/commonjs/src/http/http.compression.js +0 -27
- package/commonjs/src/http/http.extensions.js +0 -269
- package/commonjs/src/http/http.options.js +0 -26
- package/commonjs/src/http/http.options.store.js +0 -20
- package/commonjs/src/http/http.security.js +0 -27
- package/commonjs/src/http/http.static.js +0 -248
- package/commonjs/src/http/index.js +0 -22
- package/commonjs/src/index.js +0 -27
- package/commonjs/src/openapi/index.js +0 -45
- package/commonjs/src/openapi/openapi.generator.js +0 -103
- package/commonjs/src/openapi/openapi.types.js +0 -4
- package/commonjs/src/openapi/request-schema.js +0 -187
- package/commonjs/src/openapi/request-validator.js +0 -85
- package/commonjs/src/providers/fastify.provider.js +0 -391
- package/commonjs/src/providers/index.js +0 -18
- package/commonjs/src/routing/anvil.types.js +0 -99
- package/commonjs/src/routing/decorators/argument.decorator.js +0 -49
- package/commonjs/src/routing/decorators/auth.decorator.js +0 -70
- package/commonjs/src/routing/decorators/controller.decorator.js +0 -16
- package/commonjs/src/routing/decorators/field.decorator.js +0 -25
- package/commonjs/src/routing/decorators/index.js +0 -24
- package/commonjs/src/routing/decorators/request.decorator.js +0 -30
- package/commonjs/src/routing/decorators/response.decorator.js +0 -34
- package/commonjs/src/routing/decorators/route.decorator.js +0 -67
- package/commonjs/src/routing/filters/exception-filter-host.js +0 -145
- package/commonjs/src/routing/filters/exception-filter.js +0 -28
- package/commonjs/src/routing/index.js +0 -25
- package/commonjs/src/routing/middleware/http-access-log.middleware.js +0 -47
- package/commonjs/src/routing/middleware/middleware.js +0 -20
- package/commonjs/src/routing/middleware/request-id.js +0 -30
- package/commonjs/src/routing/path.util.js +0 -51
- package/commonjs/src/routing/pipes/index.js +0 -18
- package/commonjs/src/routing/pipes/pipes.js +0 -145
- package/commonjs/src/routing/services/index.js +0 -18
- package/commonjs/src/routing/services/route-argument-resolver.js +0 -77
- package/commonjs/src/routing/services/route-registry.js +0 -194
- package/commonjs/src/routing/services/router.js +0 -158
- package/commonjs/src/sse/index.js +0 -26
- package/commonjs/src/sse/sse.decorator.js +0 -42
- package/commonjs/src/sse/sse.encoder.js +0 -73
- package/commonjs/src/sse/sse.types.js +0 -36
- package/commonjs/src/sse/sse.wire.js +0 -40
- package/commonjs/src/testing/boot-module.js +0 -38
- package/commonjs/src/testing/index.js +0 -20
- package/commonjs/src/testing/sse-reader.js +0 -98
- package/es6/src/app/app.js +0 -148
- package/es6/src/app/index.js +0 -2
- package/es6/src/app/module.js +0 -7
- package/es6/src/auth/ability.js +0 -45
- package/es6/src/auth/auth.config.js +0 -19
- package/es6/src/auth/auth.extensions.js +0 -83
- package/es6/src/auth/auth.types.js +0 -35
- package/es6/src/auth/casl-authorization.service.js +0 -40
- package/es6/src/auth/index.js +0 -6
- package/es6/src/auth/principal-provider.js +0 -14
- package/es6/src/auth/safe-outbound-url.js +0 -99
- package/es6/src/auth/token-service.js +0 -141
- package/es6/src/builder/builder.js +0 -85
- package/es6/src/builder/index.js +0 -1
- package/es6/src/health/health.controller.js +0 -65
- package/es6/src/health/health.extensions.js +0 -40
- package/es6/src/health/index.js +0 -4
- package/es6/src/health/readiness.service.js +0 -57
- package/es6/src/health/readiness.types.js +0 -4
- package/es6/src/hosting/hosted-service-host.js +0 -81
- package/es6/src/hosting/hosted-service.js +0 -8
- package/es6/src/hosting/index.js +0 -2
- package/es6/src/http/http.compression.js +0 -9
- package/es6/src/http/http.extensions.js +0 -259
- package/es6/src/http/http.options.js +0 -16
- package/es6/src/http/http.options.store.js +0 -13
- package/es6/src/http/http.security.js +0 -9
- package/es6/src/http/http.static.js +0 -224
- package/es6/src/http/index.js +0 -5
- package/es6/src/openapi/index.js +0 -3
- package/es6/src/openapi/openapi.generator.js +0 -82
- package/es6/src/openapi/openapi.types.js +0 -1
- package/es6/src/openapi/request-schema.js +0 -160
- package/es6/src/openapi/request-validator.js +0 -71
- package/es6/src/providers/fastify.provider.js +0 -376
- package/es6/src/providers/index.js +0 -1
- package/es6/src/routing/anvil.types.js +0 -57
- package/es6/src/routing/decorators/argument.decorator.js +0 -28
- package/es6/src/routing/decorators/auth.decorator.js +0 -58
- package/es6/src/routing/decorators/controller.decorator.js +0 -6
- package/es6/src/routing/decorators/field.decorator.js +0 -15
- package/es6/src/routing/decorators/index.js +0 -7
- package/es6/src/routing/decorators/request.decorator.js +0 -24
- package/es6/src/routing/decorators/response.decorator.js +0 -16
- package/es6/src/routing/decorators/route.decorator.js +0 -37
- package/es6/src/routing/filters/exception-filter-host.js +0 -127
- package/es6/src/routing/filters/exception-filter.js +0 -10
- package/es6/src/routing/index.js +0 -8
- package/es6/src/routing/middleware/http-access-log.middleware.js +0 -37
- package/es6/src/routing/middleware/middleware.js +0 -10
- package/es6/src/routing/middleware/request-id.js +0 -14
- package/es6/src/routing/path.util.js +0 -33
- package/es6/src/routing/pipes/index.js +0 -1
- package/es6/src/routing/pipes/pipes.js +0 -118
- package/es6/src/routing/services/index.js +0 -1
- package/es6/src/routing/services/route-argument-resolver.js +0 -67
- package/es6/src/routing/services/route-registry.js +0 -184
- package/es6/src/routing/services/router.js +0 -148
- package/es6/src/sse/index.js +0 -2
- package/es6/src/sse/sse.decorator.js +0 -31
- package/es6/src/sse/sse.encoder.js +0 -67
- package/es6/src/sse/sse.types.js +0 -22
- package/es6/src/sse/sse.wire.js +0 -30
- package/es6/src/testing/boot-module.js +0 -35
- package/es6/src/testing/index.js +0 -2
- package/es6/src/testing/sse-reader.js +0 -91
- package/types/src/app/app.d.ts +0 -41
- package/types/src/app/module.d.ts +0 -15
- package/types/src/auth/ability.d.ts +0 -19
- package/types/src/auth/auth.config.d.ts +0 -28
- package/types/src/auth/auth.extensions.d.ts +0 -53
- package/types/src/auth/auth.types.d.ts +0 -73
- package/types/src/auth/casl-authorization.service.d.ts +0 -28
- package/types/src/auth/safe-outbound-url.d.ts +0 -9
- package/types/src/auth/token-service.d.ts +0 -31
- package/types/src/builder/builder.d.ts +0 -36
- package/types/src/const.d.ts +0 -32
- package/types/src/health/health.controller.d.ts +0 -16
- package/types/src/health/health.extensions.d.ts +0 -31
- package/types/src/health/readiness.service.d.ts +0 -9
- package/types/src/hosting/hosted-service-host.d.ts +0 -37
- package/types/src/hosting/hosted-service.d.ts +0 -31
- package/types/src/http/http.compression.d.ts +0 -32
- package/types/src/http/http.extensions.d.ts +0 -79
- package/types/src/http/http.options.d.ts +0 -39
- package/types/src/http/http.static.d.ts +0 -160
- package/types/src/index.d.ts +0 -10
- package/types/src/openapi/index.d.ts +0 -6
- package/types/src/openapi/openapi.generator.d.ts +0 -6
- package/types/src/openapi/openapi.types.d.ts +0 -58
- package/types/src/openapi/request-schema.d.ts +0 -21
- package/types/src/openapi/request-validator.d.ts +0 -9
- package/types/src/providers/fastify.provider.d.ts +0 -56
- package/types/src/routing/anvil.types.d.ts +0 -119
- package/types/src/routing/decorators/argument.decorator.d.ts +0 -11
- package/types/src/routing/decorators/auth.decorator.d.ts +0 -30
- package/types/src/routing/decorators/controller.decorator.d.ts +0 -3
- package/types/src/routing/decorators/field.decorator.d.ts +0 -2
- package/types/src/routing/decorators/request.decorator.d.ts +0 -8
- package/types/src/routing/decorators/response.decorator.d.ts +0 -4
- package/types/src/routing/decorators/route.decorator.d.ts +0 -7
- package/types/src/routing/filters/exception-filter-host.d.ts +0 -19
- package/types/src/routing/filters/exception-filter.d.ts +0 -16
- package/types/src/routing/middleware/http-access-log.middleware.d.ts +0 -8
- package/types/src/routing/middleware/middleware.d.ts +0 -10
- package/types/src/routing/middleware/request-id.d.ts +0 -6
- package/types/src/routing/path.util.d.ts +0 -9
- package/types/src/routing/pipes/pipes.d.ts +0 -21
- package/types/src/routing/services/route-argument-resolver.d.ts +0 -10
- package/types/src/routing/services/route-registry.d.ts +0 -20
- package/types/src/routing/services/router.d.ts +0 -22
- package/types/src/sse/sse.decorator.d.ts +0 -17
- package/types/src/sse/sse.encoder.d.ts +0 -16
- package/types/src/sse/sse.types.d.ts +0 -37
- package/types/src/sse/sse.wire.d.ts +0 -9
- package/types/src/testing/boot-module.d.ts +0 -34
- package/types/src/testing/sse-reader.d.ts +0 -29
- /package/{types/src/app/index.d.ts → src/app/index.ts} +0 -0
- /package/{types/src/auth/index.d.ts → src/auth/index.ts} +0 -0
- /package/{types/src/builder/index.d.ts → src/builder/index.ts} +0 -0
- /package/{types/src/health/index.d.ts → src/health/index.ts} +0 -0
- /package/{types/src/hosting/index.d.ts → src/hosting/index.ts} +0 -0
- /package/{types/src/http/index.d.ts → src/http/index.ts} +0 -0
- /package/{types/src/providers/index.d.ts → src/providers/index.ts} +0 -0
- /package/{types/src/routing/decorators/index.d.ts → src/routing/decorators/index.ts} +0 -0
- /package/{types/src/routing/index.d.ts → src/routing/index.ts} +0 -0
- /package/{types/src/routing/pipes/index.d.ts → src/routing/pipes/index.ts} +0 -0
- /package/{types/src/routing/services/index.d.ts → src/routing/services/index.ts} +0 -0
- /package/{types/src/sse/index.d.ts → src/sse/index.ts} +0 -0
- /package/{types/src/testing/index.d.ts → src/testing/index.ts} +0 -0
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Constructable } from "@decohere/core/reflection";
|
|
2
|
-
import type { HttpOptions } from "../../http/http.options.js";
|
|
3
|
-
import type { MappedRoute } from "../anvil.types.js";
|
|
4
|
-
export declare class RouteRegistry {
|
|
5
|
-
private readonly routeMap;
|
|
6
|
-
private readonly httpOptions?;
|
|
7
|
-
constructor(httpOptions?: HttpOptions);
|
|
8
|
-
addController(controller: Constructable): void;
|
|
9
|
-
get routes(): MapIterator<MappedRoute>;
|
|
10
|
-
getRoute(key: string): MappedRoute;
|
|
11
|
-
private addControllerRoute;
|
|
12
|
-
/** `@Controller({ globalPrefix: false })` opts out, unless the app put it back under. */
|
|
13
|
-
private takesGlobalPrefix;
|
|
14
|
-
private getControllerPrefix;
|
|
15
|
-
private getRouteArguments;
|
|
16
|
-
private getRouteArgument;
|
|
17
|
-
private getFields;
|
|
18
|
-
private enrichField;
|
|
19
|
-
private getDefaultPipes;
|
|
20
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type LifetimeScope } from "@decohere/crucible";
|
|
2
|
-
import type { IAuthorizationService } from "../../auth/auth.types.js";
|
|
3
|
-
import type { HttpOptions } from "../../http/http.options.js";
|
|
4
|
-
import type { HttpRequest } from "../anvil.types.js";
|
|
5
|
-
import { RouteRegistry } from "./route-registry.js";
|
|
6
|
-
export declare class Router {
|
|
7
|
-
private readonly argResolver;
|
|
8
|
-
private readonly lifetimeScope;
|
|
9
|
-
private readonly routeRegistry;
|
|
10
|
-
private readonly authService?;
|
|
11
|
-
private readonly httpOptions?;
|
|
12
|
-
private readonly logger;
|
|
13
|
-
constructor(routeRegistry: RouteRegistry, lifetimeScope: LifetimeScope, authService?: IAuthorizationService, httpOptions?: HttpOptions);
|
|
14
|
-
/**
|
|
15
|
-
* Without an authorization service nothing checks tokens, so a route marked @Authorize
|
|
16
|
-
* would be served to anyone. Refuse to start instead of failing open.
|
|
17
|
-
*/
|
|
18
|
-
private assertAuthConfiguredForProtectedRoutes;
|
|
19
|
-
route(routeKey: string, httpRequest: HttpRequest): Promise<any>;
|
|
20
|
-
private resolveMiddlewares;
|
|
21
|
-
private authorize;
|
|
22
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { SseOptions } from "./sse.types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Mark a route as a server-sent event stream. The method returns an `AsyncIterable` of
|
|
4
|
-
* {@link SseMessage}s (an `async *` method is the usual shape) and the HTTP package writes it as
|
|
5
|
-
* `text/event-stream`. Auth, validation and middleware run first, exactly as on any route,
|
|
6
|
-
* so an unauthorised caller gets a normal 401/403 and no event is ever sent.
|
|
7
|
-
*
|
|
8
|
-
* Combine with `@Get()` (EventSource only issues GET).
|
|
9
|
-
*/
|
|
10
|
-
export declare function Sse(options?: SseOptions): (_target: object, _methodName: string, descriptor: PropertyDescriptor) => void;
|
|
11
|
-
/**
|
|
12
|
-
* Inject an `AbortSignal` that aborts when the client disconnects or the app stops. Pass it to
|
|
13
|
-
* whatever the producer waits on (timers, subscriptions, queries) so it stops promptly.
|
|
14
|
-
*/
|
|
15
|
-
export declare const Signal: () => (target: object, propertyKey: string, parameterIndex: number) => void;
|
|
16
|
-
/** Inject the `Last-Event-ID` header the browser sends when it reconnects, or `undefined`. */
|
|
17
|
-
export declare const LastEventId: () => (target: object, propertyKey: string, parameterIndex: number) => void;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type SseEncodeOptions = {
|
|
2
|
-
/** Aborted when the client disconnects or the app stops. */
|
|
3
|
-
signal: AbortSignal;
|
|
4
|
-
heartbeatMs: number;
|
|
5
|
-
/**
|
|
6
|
-
* Called once, as the stream ends, with a promise that settles when the producer has
|
|
7
|
-
* actually stopped (its `finally` blocks have run).
|
|
8
|
-
*/
|
|
9
|
-
onProducerStopped: (stopped: Promise<void>) => void;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Turn the handler's events into SSE text. Writes an opening comment so the browser sees the
|
|
13
|
-
* response headers at once, a heartbeat whenever the producer is quiet, and stops as soon as the
|
|
14
|
-
* signal aborts, without waiting for a producer that is stuck.
|
|
15
|
-
*/
|
|
16
|
-
export declare function encodeSse(source: AsyncIterable<unknown>, options: SseEncodeOptions): AsyncGenerator<string>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One server-sent event. A bare `string` yielded by a handler is shorthand for `{ data }`.
|
|
3
|
-
*
|
|
4
|
-
* `data` is written as-is when it is a string and as JSON otherwise.
|
|
5
|
-
*/
|
|
6
|
-
export type SseMessage<T = unknown> = {
|
|
7
|
-
data: T;
|
|
8
|
-
/** Becomes the `event:` field; the browser dispatches it to `addEventListener(event, ...)`. */
|
|
9
|
-
event?: string;
|
|
10
|
-
/** Becomes the `id:` field; the browser sends the last one back as `Last-Event-ID` on reconnect. */
|
|
11
|
-
id?: string;
|
|
12
|
-
/** Tells the browser how many milliseconds to wait before reconnecting. */
|
|
13
|
-
retry?: number;
|
|
14
|
-
};
|
|
15
|
-
/** What a `@Sse()` handler returns: any async iterable of messages (an `async *` method is the usual shape). */
|
|
16
|
-
export type SseStream<T = unknown> = AsyncIterable<SseMessage<T> | string>;
|
|
17
|
-
export type SseOptions = {
|
|
18
|
-
/**
|
|
19
|
-
* Milliseconds of silence before the HTTP package writes a `: heartbeat` comment, which keeps proxies
|
|
20
|
-
* and load balancers from closing an idle connection. Default 15000. `0` turns heartbeats off.
|
|
21
|
-
*/
|
|
22
|
-
heartbeatMs?: number;
|
|
23
|
-
};
|
|
24
|
-
export declare const DEFAULT_SSE_HEARTBEAT_MS = 15000;
|
|
25
|
-
/**
|
|
26
|
-
* What the router hands the HTTP provider for an `@Sse()` route. The request-scoped services the
|
|
27
|
-
* handler uses must stay alive for as long as the stream runs, so the provider calls `release()`
|
|
28
|
-
* once the stream is over, instead of the router disposing them as soon as the handler returns.
|
|
29
|
-
*/
|
|
30
|
-
export declare class SseResponse {
|
|
31
|
-
readonly events: AsyncIterable<unknown>;
|
|
32
|
-
private readonly onRelease;
|
|
33
|
-
private released;
|
|
34
|
-
constructor(events: AsyncIterable<unknown>, onRelease: () => Promise<void>);
|
|
35
|
-
/** Safe to call more than once. */
|
|
36
|
-
release(): Promise<void>;
|
|
37
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** Encode one event as the text a browser's `EventSource` parses. */
|
|
2
|
-
declare function formatMessage(item: unknown): string;
|
|
3
|
-
/** A comment line: ignored by `EventSource`, but it is traffic on the wire. */
|
|
4
|
-
declare function formatComment(text: string): string;
|
|
5
|
-
export declare const sseWire: {
|
|
6
|
-
formatMessage: typeof formatMessage;
|
|
7
|
-
formatComment: typeof formatComment;
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ContainerBuilder } from "@decohere/crucible";
|
|
2
|
-
import type { Constructable } from "@decohere/core/reflection";
|
|
3
|
-
import type { App } from "../app/app.js";
|
|
4
|
-
import { Builder } from "../builder/builder.js";
|
|
5
|
-
import "../http/http.extensions.js";
|
|
6
|
-
import type { HttpProvider } from "../routing/anvil.types.js";
|
|
7
|
-
import { type EventStreamRead, type ReadEventsOptions } from "./sse-reader.js";
|
|
8
|
-
export type BootModuleOptions = {
|
|
9
|
-
controllers: Constructable[];
|
|
10
|
-
/** Register services the controllers need. */
|
|
11
|
-
services?: (containerBuilder: ContainerBuilder) => void;
|
|
12
|
-
/** Add anything else to the builder (`withAuth()`, `withOpenApi()`, ...) before the app is built. */
|
|
13
|
-
configure?: (builder: Builder) => unknown;
|
|
14
|
-
/** Defaults to the Fastify provider. */
|
|
15
|
-
provider?: Constructable<HttpProvider>;
|
|
16
|
-
};
|
|
17
|
-
export type BootedModule = AsyncDisposable & {
|
|
18
|
-
app: App;
|
|
19
|
-
/** Origin of the listening app, e.g. `http://127.0.0.1:41233`. */
|
|
20
|
-
baseUrl: string;
|
|
21
|
-
/** `GET path` as an `EventSource` would, and collect the first `count` events. */
|
|
22
|
-
readEvents(path: string, options?: ReadEventsOptions): Promise<EventStreamRead>;
|
|
23
|
-
/** Stop the app (closing any open streams). Same as `await using`. */
|
|
24
|
-
stop(): Promise<void>;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Boot the given controllers as a real app on a free loopback port, so a test can call it over
|
|
28
|
-
* HTTP. The app runs the full pipeline: routing, auth, middleware, and the real provider.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* await using api = await bootModule({ controllers: [PriceController] });
|
|
32
|
-
* const { events } = await api.readEvents("/prices/stream", { count: 3 });
|
|
33
|
-
*/
|
|
34
|
-
export declare function bootModule(options: BootModuleOptions): Promise<BootedModule>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type ReceivedEvent = {
|
|
2
|
-
/** The `data:` lines joined with `\n`, as `EventSource` would give them. */
|
|
3
|
-
data: string;
|
|
4
|
-
event?: string;
|
|
5
|
-
id?: string;
|
|
6
|
-
retry?: number;
|
|
7
|
-
};
|
|
8
|
-
export type EventStreamRead = {
|
|
9
|
-
status: number;
|
|
10
|
-
headers: Headers;
|
|
11
|
-
/** The events received, at most the requested count. */
|
|
12
|
-
events: ReceivedEvent[];
|
|
13
|
-
/** Comment lines (`: heartbeat` and the like) seen before the read ended. */
|
|
14
|
-
comments: string[];
|
|
15
|
-
/** True when the server ended the stream (as opposed to the reader stopping at the count). */
|
|
16
|
-
ended: boolean;
|
|
17
|
-
};
|
|
18
|
-
export type ReadEventsOptions = {
|
|
19
|
-
/** Stop and close the connection after this many events. Default 1. `Infinity` reads until the server ends the stream. */
|
|
20
|
-
count?: number;
|
|
21
|
-
headers?: Record<string, string>;
|
|
22
|
-
/** Give up (and fail) if the read has not finished after this many milliseconds. Default 5000. */
|
|
23
|
-
timeoutMs?: number;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* GET `url` as an `EventSource` would and collect events until `count` have arrived or the
|
|
27
|
-
* server ends the stream. A non-200 answer (401, 403, ...) returns at once with no events.
|
|
28
|
-
*/
|
|
29
|
-
export declare function readEventStream(url: string, options?: ReadEventsOptions): Promise<EventStreamRead>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|