@astrale-os/kernel-server 0.4.17 → 0.5.0-beta.1
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/capture.d.ts +3 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +10 -0
- package/dist/capture.js.map +1 -0
- package/dist/cors/cors.d.ts +22 -0
- package/dist/cors/cors.d.ts.map +1 -0
- package/dist/cors/cors.js +136 -0
- package/dist/cors/cors.js.map +1 -0
- package/dist/cors/index.d.ts +3 -0
- package/dist/cors/index.d.ts.map +1 -0
- package/dist/cors/index.js +2 -0
- package/dist/cors/index.js.map +1 -0
- package/dist/cors/types.d.ts +12 -0
- package/dist/cors/types.d.ts.map +1 -0
- package/dist/cors/types.js +2 -0
- package/dist/cors/types.js.map +1 -0
- package/dist/errors/availability.d.ts +11 -0
- package/dist/errors/availability.d.ts.map +1 -0
- package/dist/errors/availability.js +15 -0
- package/dist/errors/availability.js.map +1 -0
- package/dist/errors/classify.d.ts +4 -0
- package/dist/errors/classify.d.ts.map +1 -0
- package/dist/errors/classify.js +254 -0
- package/dist/errors/classify.js.map +1 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +5 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/request-body.d.ts +8 -0
- package/dist/errors/request-body.d.ts.map +1 -0
- package/dist/errors/request-body.js +15 -0
- package/dist/errors/request-body.js.map +1 -0
- package/dist/errors/response-body.d.ts +5 -0
- package/dist/errors/response-body.d.ts.map +1 -0
- package/dist/errors/response-body.js +9 -0
- package/dist/errors/response-body.js.map +1 -0
- package/dist/index.d.ts +4 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -18
- package/dist/index.js.map +1 -1
- package/dist/installation/handler.d.ts +10 -0
- package/dist/installation/handler.d.ts.map +1 -0
- package/dist/installation/handler.js +126 -0
- package/dist/installation/handler.js.map +1 -0
- package/dist/installation/index.d.ts +3 -0
- package/dist/installation/index.d.ts.map +1 -0
- package/dist/installation/index.js +2 -0
- package/dist/installation/index.js.map +1 -0
- package/dist/installation/types.d.ts +12 -0
- package/dist/installation/types.d.ts.map +1 -0
- package/dist/installation/types.js +2 -0
- package/dist/installation/types.js.map +1 -0
- package/dist/invocation/context.d.ts +7 -0
- package/dist/invocation/context.d.ts.map +1 -0
- package/dist/invocation/context.js +62 -0
- package/dist/invocation/context.js.map +1 -0
- package/dist/invocation/index.d.ts +2 -2
- package/dist/invocation/index.d.ts.map +1 -1
- package/dist/invocation/index.js +1 -2
- package/dist/invocation/index.js.map +1 -1
- package/dist/invocation/types.d.ts +34 -0
- package/dist/invocation/types.d.ts.map +1 -0
- package/dist/invocation/types.js +2 -0
- package/dist/invocation/types.js.map +1 -0
- package/dist/issuer/index.d.ts +3 -0
- package/dist/issuer/index.d.ts.map +1 -0
- package/dist/issuer/index.js +2 -0
- package/dist/issuer/index.js.map +1 -0
- package/dist/issuer/routes.d.ts +13 -0
- package/dist/issuer/routes.d.ts.map +1 -0
- package/dist/issuer/routes.js +138 -0
- package/dist/issuer/routes.js.map +1 -0
- package/dist/issuer/types.d.ts +11 -0
- package/dist/issuer/types.d.ts.map +1 -0
- package/dist/issuer/types.js +2 -0
- package/dist/issuer/types.js.map +1 -0
- package/dist/lifecycle/active.d.ts +40 -0
- package/dist/lifecycle/active.d.ts.map +1 -0
- package/dist/lifecycle/active.js +200 -0
- package/dist/lifecycle/active.js.map +1 -0
- package/dist/lifecycle/index.d.ts +2 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/lifecycle/index.js +2 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/publication/index.d.ts +3 -0
- package/dist/publication/index.d.ts.map +1 -0
- package/dist/publication/index.js +2 -0
- package/dist/publication/index.js.map +1 -0
- package/dist/publication/snapshot.d.ts +14 -0
- package/dist/publication/snapshot.d.ts.map +1 -0
- package/dist/publication/snapshot.js +30 -0
- package/dist/publication/snapshot.js.map +1 -0
- package/dist/publication/types.d.ts +19 -0
- package/dist/publication/types.d.ts.map +1 -0
- package/dist/publication/types.js +2 -0
- package/dist/publication/types.js.map +1 -0
- package/dist/routes/index.d.ts +2 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +2 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/routes.d.ts +24 -0
- package/dist/routes/routes.d.ts.map +1 -0
- package/dist/routes/routes.js +438 -0
- package/dist/routes/routes.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +226 -0
- package/dist/server.js.map +1 -0
- package/dist/transport/body.d.ts +5 -0
- package/dist/transport/body.d.ts.map +1 -0
- package/dist/transport/body.js +51 -0
- package/dist/transport/body.js.map +1 -0
- package/dist/transport/codecs.d.ts +5 -0
- package/dist/transport/codecs.d.ts.map +1 -0
- package/dist/transport/codecs.js +6 -0
- package/dist/transport/codecs.js.map +1 -0
- package/dist/transport/credential.d.ts +11 -0
- package/dist/transport/credential.d.ts.map +1 -0
- package/dist/transport/credential.js +29 -0
- package/dist/transport/credential.js.map +1 -0
- package/dist/transport/http/handler.d.ts +16 -0
- package/dist/transport/http/handler.d.ts.map +1 -0
- package/dist/transport/http/handler.js +170 -0
- package/dist/transport/http/handler.js.map +1 -0
- package/dist/transport/http/index.d.ts +3 -0
- package/dist/transport/http/index.d.ts.map +1 -0
- package/dist/transport/http/index.js +3 -0
- package/dist/transport/http/index.js.map +1 -0
- package/dist/transport/http/render.d.ts +29 -0
- package/dist/transport/http/render.d.ts.map +1 -0
- package/dist/transport/http/render.js +277 -0
- package/dist/transport/http/render.js.map +1 -0
- package/dist/transport/index.d.ts +10 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +9 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/router.d.ts +5 -0
- package/dist/transport/router.d.ts.map +1 -0
- package/dist/transport/router.js +5 -0
- package/dist/transport/router.js.map +1 -0
- package/dist/transport/stream-error.d.ts +4 -0
- package/dist/transport/stream-error.d.ts.map +1 -0
- package/dist/transport/stream-error.js +14 -0
- package/dist/transport/stream-error.js.map +1 -0
- package/dist/transport/types.d.ts +29 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +2 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/transport/websocket/index.d.ts +3 -0
- package/dist/transport/websocket/index.d.ts.map +1 -0
- package/dist/transport/websocket/index.js +3 -0
- package/dist/transport/websocket/index.js.map +1 -0
- package/dist/transport/websocket/session.d.ts +19 -0
- package/dist/transport/websocket/session.d.ts.map +1 -0
- package/dist/transport/websocket/session.js +328 -0
- package/dist/transport/websocket/session.js.map +1 -0
- package/dist/transport/websocket/upgrade.d.ts +19 -0
- package/dist/transport/websocket/upgrade.d.ts.map +1 -0
- package/dist/transport/websocket/upgrade.js +46 -0
- package/dist/transport/websocket/upgrade.js.map +1 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +9 -11
- package/dist/app/create.d.ts +0 -48
- package/dist/app/create.d.ts.map +0 -1
- package/dist/app/create.js +0 -108
- package/dist/app/create.js.map +0 -1
- package/dist/app/index.d.ts +0 -4
- package/dist/app/index.d.ts.map +0 -1
- package/dist/app/index.js +0 -4
- package/dist/app/index.js.map +0 -1
- package/dist/app/multiplexed.d.ts +0 -53
- package/dist/app/multiplexed.d.ts.map +0 -1
- package/dist/app/multiplexed.js +0 -64
- package/dist/app/multiplexed.js.map +0 -1
- package/dist/app/ws-upgrade.d.ts +0 -34
- package/dist/app/ws-upgrade.d.ts.map +0 -1
- package/dist/app/ws-upgrade.js +0 -94
- package/dist/app/ws-upgrade.js.map +0 -1
- package/dist/capabilities/contract.d.ts +0 -8
- package/dist/capabilities/contract.d.ts.map +0 -1
- package/dist/capabilities/contract.js +0 -2
- package/dist/capabilities/contract.js.map +0 -1
- package/dist/capabilities/defer.d.ts +0 -4
- package/dist/capabilities/defer.d.ts.map +0 -1
- package/dist/capabilities/defer.js +0 -2
- package/dist/capabilities/defer.js.map +0 -1
- package/dist/capabilities/hono.d.ts +0 -8
- package/dist/capabilities/hono.d.ts.map +0 -1
- package/dist/capabilities/hono.js +0 -13
- package/dist/capabilities/hono.js.map +0 -1
- package/dist/capabilities/index.d.ts +0 -6
- package/dist/capabilities/index.d.ts.map +0 -1
- package/dist/capabilities/index.js +0 -3
- package/dist/capabilities/index.js.map +0 -1
- package/dist/capabilities/lifecycle.d.ts +0 -17
- package/dist/capabilities/lifecycle.d.ts.map +0 -1
- package/dist/capabilities/lifecycle.js +0 -37
- package/dist/capabilities/lifecycle.js.map +0 -1
- package/dist/capabilities/sleep.d.ts +0 -4
- package/dist/capabilities/sleep.d.ts.map +0 -1
- package/dist/capabilities/sleep.js +0 -8
- package/dist/capabilities/sleep.js.map +0 -1
- package/dist/cors.d.ts +0 -21
- package/dist/cors.d.ts.map +0 -1
- package/dist/cors.js +0 -17
- package/dist/cors.js.map +0 -1
- package/dist/envelope/batch.d.ts +0 -13
- package/dist/envelope/batch.d.ts.map +0 -1
- package/dist/envelope/batch.js +0 -96
- package/dist/envelope/batch.js.map +0 -1
- package/dist/envelope/codec.d.ts +0 -26
- package/dist/envelope/codec.d.ts.map +0 -1
- package/dist/envelope/codec.js +0 -52
- package/dist/envelope/codec.js.map +0 -1
- package/dist/envelope/credential.d.ts +0 -20
- package/dist/envelope/credential.d.ts.map +0 -1
- package/dist/envelope/credential.js +0 -32
- package/dist/envelope/credential.js.map +0 -1
- package/dist/envelope/http.d.ts +0 -31
- package/dist/envelope/http.d.ts.map +0 -1
- package/dist/envelope/http.js +0 -132
- package/dist/envelope/http.js.map +0 -1
- package/dist/envelope/sse.d.ts +0 -11
- package/dist/envelope/sse.d.ts.map +0 -1
- package/dist/envelope/sse.js +0 -73
- package/dist/envelope/sse.js.map +0 -1
- package/dist/envelope/ws.d.ts +0 -35
- package/dist/envelope/ws.d.ts.map +0 -1
- package/dist/envelope/ws.js +0 -142
- package/dist/envelope/ws.js.map +0 -1
- package/dist/invocation/dispatch.d.ts +0 -32
- package/dist/invocation/dispatch.d.ts.map +0 -1
- package/dist/invocation/dispatch.js +0 -68
- package/dist/invocation/dispatch.js.map +0 -1
- package/dist/invocation/dispatcher.d.ts +0 -19
- package/dist/invocation/dispatcher.d.ts.map +0 -1
- package/dist/invocation/dispatcher.js +0 -9
- package/dist/invocation/dispatcher.js.map +0 -1
- package/dist/jwks/discovery.d.ts +0 -40
- package/dist/jwks/discovery.d.ts.map +0 -1
- package/dist/jwks/discovery.js +0 -113
- package/dist/jwks/discovery.js.map +0 -1
- package/dist/jwks/index.d.ts +0 -3
- package/dist/jwks/index.d.ts.map +0 -1
- package/dist/jwks/index.js +0 -3
- package/dist/jwks/index.js.map +0 -1
- package/dist/jwks/issuers.d.ts +0 -47
- package/dist/jwks/issuers.d.ts.map +0 -1
- package/dist/jwks/issuers.js +0 -76
- package/dist/jwks/issuers.js.map +0 -1
- package/dist/jwks/keys.d.ts +0 -44
- package/dist/jwks/keys.d.ts.map +0 -1
- package/dist/jwks/keys.js +0 -56
- package/dist/jwks/keys.js.map +0 -1
- package/dist/plan/host-params.d.ts +0 -13
- package/dist/plan/host-params.d.ts.map +0 -1
- package/dist/plan/host-params.js +0 -23
- package/dist/plan/host-params.js.map +0 -1
- package/dist/plan/host.d.ts +0 -24
- package/dist/plan/host.d.ts.map +0 -1
- package/dist/plan/host.js +0 -24
- package/dist/plan/host.js.map +0 -1
- package/dist/plan/index.d.ts +0 -4
- package/dist/plan/index.d.ts.map +0 -1
- package/dist/plan/index.js +0 -4
- package/dist/plan/index.js.map +0 -1
- package/dist/plan/walk.d.ts +0 -51
- package/dist/plan/walk.d.ts.map +0 -1
- package/dist/plan/walk.js +0 -110
- package/dist/plan/walk.js.map +0 -1
- package/dist/render/binary.d.ts +0 -19
- package/dist/render/binary.d.ts.map +0 -1
- package/dist/render/binary.js +0 -33
- package/dist/render/binary.js.map +0 -1
- package/dist/render/body.d.ts +0 -10
- package/dist/render/body.d.ts.map +0 -1
- package/dist/render/body.js +0 -17
- package/dist/render/body.js.map +0 -1
- package/dist/render/index.d.ts +0 -3
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/index.js +0 -3
- package/dist/render/index.js.map +0 -1
- package/dist/routed/credential.d.ts +0 -10
- package/dist/routed/credential.d.ts.map +0 -1
- package/dist/routed/credential.js +0 -55
- package/dist/routed/credential.js.map +0 -1
- package/dist/routed/handler.d.ts +0 -38
- package/dist/routed/handler.d.ts.map +0 -1
- package/dist/routed/handler.js +0 -123
- package/dist/routed/handler.js.map +0 -1
- package/dist/routed/index.d.ts +0 -5
- package/dist/routed/index.d.ts.map +0 -1
- package/dist/routed/index.js +0 -5
- package/dist/routed/index.js.map +0 -1
- package/dist/routed/params.d.ts +0 -40
- package/dist/routed/params.d.ts.map +0 -1
- package/dist/routed/params.js +0 -146
- package/dist/routed/params.js.map +0 -1
- package/dist/routed/stream.d.ts +0 -21
- package/dist/routed/stream.d.ts.map +0 -1
- package/dist/routed/stream.js +0 -69
- package/dist/routed/stream.js.map +0 -1
package/dist/routed/handler.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route binding HTTP handler — native HTTP shape (REST-like).
|
|
3
|
-
*
|
|
4
|
-
* One handler per mounted route. Decodes params from the request, dispatches
|
|
5
|
-
* via the kernel API, encodes the response per output mode:
|
|
6
|
-
* - value → JSON body, HTTP status from error code table on error
|
|
7
|
-
* - stream → SSE with one event per yielded chunk (raw, NOT kernel envelope)
|
|
8
|
-
* - binary → raw bytes with BinaryResult contentType + status
|
|
9
|
-
*
|
|
10
|
-
* Errors use the kernel envelope's `{ error: { code, message, data? } }` shape
|
|
11
|
-
* for consistency with kernel HTTP. The HTTP status comes from the error code
|
|
12
|
-
* table (`kernelErrorHttpStatus`).
|
|
13
|
-
*/
|
|
14
|
-
import type { RouteBinding } from '@astrale-os/kernel-api';
|
|
15
|
-
import type { AuthPolicy } from '@astrale-os/kernel-api/routed';
|
|
16
|
-
import type { CapabilityHost } from '../capabilities/index.js';
|
|
17
|
-
import type { CorsConfig } from '../cors.js';
|
|
18
|
-
import type { Dispatcher } from '../invocation/index.js';
|
|
19
|
-
export type RouteHandlerConfig = {
|
|
20
|
-
/** The full kernel method name to dispatch (e.g. `Task.read`). */
|
|
21
|
-
method: string;
|
|
22
|
-
route: RouteBinding;
|
|
23
|
-
dispatcher: Dispatcher;
|
|
24
|
-
cors: CorsConfig;
|
|
25
|
-
/**
|
|
26
|
-
* Optional host placeholder extractor — returned values are merged into
|
|
27
|
-
* params at the lowest priority (host < path < query < header < body).
|
|
28
|
-
* Return null to reject the request with 404.
|
|
29
|
-
*/
|
|
30
|
-
hostParams?: (req: Request) => Record<string, string> | null;
|
|
31
|
-
/** Authentication policy from the method definition. Defaults to `'required'`. */
|
|
32
|
-
auth?: AuthPolicy;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Build a Hono-compatible handler for a single route binding.
|
|
36
|
-
*/
|
|
37
|
-
export declare function createRouteHandler(config: RouteHandlerConfig): (req: Request, pathParams: Record<string, string>, host?: CapabilityHost) => Promise<Response>;
|
|
38
|
-
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../routed/handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAiC,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACzF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAS/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AA2BxD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,YAAY,CAAA;IACnB,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,UAAU,CAAA;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;IAC5D,kFAAkF;IAClF,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,kBAAkB,GACzB,CAAC,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,QAAQ,CAAC,CAuGhG"}
|
package/dist/routed/handler.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route binding HTTP handler — native HTTP shape (REST-like).
|
|
3
|
-
*
|
|
4
|
-
* One handler per mounted route. Decodes params from the request, dispatches
|
|
5
|
-
* via the kernel API, encodes the response per output mode:
|
|
6
|
-
* - value → JSON body, HTTP status from error code table on error
|
|
7
|
-
* - stream → SSE with one event per yielded chunk (raw, NOT kernel envelope)
|
|
8
|
-
* - binary → raw bytes with BinaryResult contentType + status
|
|
9
|
-
*
|
|
10
|
-
* Errors use the kernel envelope's `{ error: { code, message, data? } }` shape
|
|
11
|
-
* for consistency with kernel HTTP. The HTTP status comes from the error code
|
|
12
|
-
* table (`kernelErrorHttpStatus`).
|
|
13
|
-
*/
|
|
14
|
-
import { KERNEL_ERROR_CODES, isBinaryResult, jsonCodec, kernelErrorHttpStatus, } from '@astrale-os/kernel-api';
|
|
15
|
-
import { buildCorsHeaders } from '../cors.js';
|
|
16
|
-
import { dispatchInvocation } from '../invocation/index.js';
|
|
17
|
-
import { buildBinaryResponse, toBody } from '../render/index.js';
|
|
18
|
-
import { readCredential } from './credential.js';
|
|
19
|
-
import { decodeRouteRequest } from './params.js';
|
|
20
|
-
import { buildRouteStreamResponse } from './stream.js';
|
|
21
|
-
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
22
|
-
function errorResponse(error, corsHeaders) {
|
|
23
|
-
const status = kernelErrorHttpStatus(error.code);
|
|
24
|
-
const body = jsonCodec.encode({
|
|
25
|
-
error: error.data === undefined
|
|
26
|
-
? { code: error.code, message: error.message }
|
|
27
|
-
: { code: error.code, message: error.message, data: error.data },
|
|
28
|
-
});
|
|
29
|
-
return new Response(toBody(body), {
|
|
30
|
-
status,
|
|
31
|
-
headers: { ...corsHeaders, 'content-type': 'application/json' },
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Build a Hono-compatible handler for a single route binding.
|
|
36
|
-
*/
|
|
37
|
-
export function createRouteHandler(config) {
|
|
38
|
-
const corsHeaders = buildCorsHeaders(config.cors);
|
|
39
|
-
const hostParamsFn = config.hostParams;
|
|
40
|
-
return async (req, pathParams, host) => {
|
|
41
|
-
if (req.method === 'OPTIONS') {
|
|
42
|
-
return new Response(null, { status: 204, headers: corsHeaders });
|
|
43
|
-
}
|
|
44
|
-
// 0. Host params (lowest priority).
|
|
45
|
-
let hostParams = {};
|
|
46
|
-
if (hostParamsFn) {
|
|
47
|
-
const extracted = hostParamsFn(req);
|
|
48
|
-
if (extracted === null) {
|
|
49
|
-
return new Response('Host not recognised', { status: 404, headers: corsHeaders });
|
|
50
|
-
}
|
|
51
|
-
hostParams = extracted;
|
|
52
|
-
}
|
|
53
|
-
// 1. Decode params + self
|
|
54
|
-
let decoded;
|
|
55
|
-
try {
|
|
56
|
-
decoded = await decodeRouteRequest({
|
|
57
|
-
route: config.route,
|
|
58
|
-
pathParams,
|
|
59
|
-
hostParams,
|
|
60
|
-
request: req,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
catch (err) {
|
|
64
|
-
return errorResponse({
|
|
65
|
-
code: KERNEL_ERROR_CODES.PARSE_ERROR,
|
|
66
|
-
message: err instanceof Error ? err.message : 'Parse error',
|
|
67
|
-
}, corsHeaders);
|
|
68
|
-
}
|
|
69
|
-
const params = decoded.params;
|
|
70
|
-
// 1b. Inject actual HTTP method for wildcard routes.
|
|
71
|
-
if (config.route.method === '*') {
|
|
72
|
-
params._method = req.method;
|
|
73
|
-
}
|
|
74
|
-
// 2. Resolve credential.
|
|
75
|
-
// Configurable via route.credential. Defaults to Authorization header.
|
|
76
|
-
const credSource = config.route.credential ?? { in: 'header', name: 'authorization' };
|
|
77
|
-
const credential = readCredential(req, credSource);
|
|
78
|
-
// 3. Dispatch
|
|
79
|
-
const requestId = crypto.randomUUID();
|
|
80
|
-
const result = await dispatchInvocation(config.dispatcher, {
|
|
81
|
-
path: config.method,
|
|
82
|
-
credential,
|
|
83
|
-
params,
|
|
84
|
-
...(decoded.self === undefined ? {} : { self: decoded.self }),
|
|
85
|
-
}, { id: requestId }, host);
|
|
86
|
-
// 4. Render
|
|
87
|
-
switch (result.kind) {
|
|
88
|
-
case 'ack':
|
|
89
|
-
return new Response(null, { status: 204, headers: corsHeaders });
|
|
90
|
-
case 'success': {
|
|
91
|
-
if (isBinaryResult(result.data)) {
|
|
92
|
-
return buildBinaryResponse(result.data, corsHeaders);
|
|
93
|
-
}
|
|
94
|
-
const body = jsonCodec.encode(result.data);
|
|
95
|
-
return new Response(toBody(body), {
|
|
96
|
-
status: 200,
|
|
97
|
-
headers: { ...corsHeaders, 'content-type': 'application/json' },
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
case 'error':
|
|
101
|
-
return errorResponse(result.error, corsHeaders);
|
|
102
|
-
case 'redirect': {
|
|
103
|
-
const body = jsonCodec.encode({ redirect: result.redirection });
|
|
104
|
-
return new Response(toBody(body), {
|
|
105
|
-
status: 307,
|
|
106
|
-
headers: {
|
|
107
|
-
...corsHeaders,
|
|
108
|
-
'content-type': 'application/json',
|
|
109
|
-
location: result.redirection.url,
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
case 'stream': {
|
|
114
|
-
const streamResult = await buildRouteStreamResponse(result.generator, corsHeaders);
|
|
115
|
-
if (streamResult.kind === 'error') {
|
|
116
|
-
return errorResponse(streamResult.error, corsHeaders);
|
|
117
|
-
}
|
|
118
|
-
return streamResult.response;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
//# sourceMappingURL=handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../routed/handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,qBAAqB,GACtB,MAAM,wBAAwB,CAAA;AAM/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAEtD,+EAA+E;AAE/E,SAAS,aAAa,CAAC,KAAyB,EAAE,WAAmC;IACnF,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAChD,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC;QAC5B,KAAK,EACH,KAAK,CAAC,IAAI,KAAK,SAAS;YACtB,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;YAC9C,CAAC,CAAC,EA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H,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
package/dist/routed/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { createRouteHandler, type RouteHandlerConfig } from './handler.js';
|
|
2
|
-
export { decodeRouteRequest, type DecodedRouteParams, type DecodeRouteInput } from './params.js';
|
|
3
|
-
export { readCredential } from './credential.js';
|
|
4
|
-
export { buildRouteStreamResponse, type StreamResponseResult } from './stream.js';
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../routed/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAC1E,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/routed/index.js
DELETED
package/dist/routed/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../routed/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAA;AAC1E,OAAO,EAAE,kBAAkB,EAAkD,MAAM,aAAa,CAAA;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,wBAAwB,EAA6B,MAAM,aAAa,CAAA"}
|
package/dist/routed/params.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route binding parameter decoder.
|
|
3
|
-
*
|
|
4
|
-
* Extracts params from all sources (host, path, query, header, body) per
|
|
5
|
-
* spec §3. Merge order: host < path < query < header < body — later wins.
|
|
6
|
-
* `route.self`, if set, is lifted to a separate top-level `self` channel
|
|
7
|
-
* AND removed from `params` — handlers read it via the `self` sibling in
|
|
8
|
-
* their execute context (`self.path.raw`), never from `params`. Leaving
|
|
9
|
-
* a copy in `params` would trip strict Zod validation of `inputSchema`
|
|
10
|
-
* (`route-self.ts` explicitly allows the placeholder to be absent from
|
|
11
|
-
* the schema, so the runtime must not smuggle it through anyway).
|
|
12
|
-
*
|
|
13
|
-
* Body modes:
|
|
14
|
-
* - `'*'` parse JSON body, merge top-level fields into params.
|
|
15
|
-
* - `'raw'` skip parsing; raw bytes at `params._body`.
|
|
16
|
-
* - `Record` parse JSON, pick mapped fields with wire-name remapping.
|
|
17
|
-
*/
|
|
18
|
-
import type { RouteBinding } from '@astrale-os/kernel-api';
|
|
19
|
-
export type DecodedRouteParams = Record<string, unknown>;
|
|
20
|
-
export type DecodedRoute = {
|
|
21
|
-
params: DecodedRouteParams;
|
|
22
|
-
/** Lifted from the placeholder declared by `route.self`. Sibling of params. */
|
|
23
|
-
self?: string;
|
|
24
|
-
};
|
|
25
|
-
export type DecodeRouteInput = {
|
|
26
|
-
route: RouteBinding;
|
|
27
|
-
/** Pre-extracted path params (from path matcher). */
|
|
28
|
-
pathParams: Record<string, string>;
|
|
29
|
-
/** Pre-extracted host params (from server-side host matcher). May be empty. */
|
|
30
|
-
hostParams?: Record<string, string>;
|
|
31
|
-
/** The raw request. */
|
|
32
|
-
request: Request;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Decode params from a route + request.
|
|
36
|
-
*
|
|
37
|
-
* Throws on body parse errors — the caller should map to PARSE_ERROR.
|
|
38
|
-
*/
|
|
39
|
-
export declare function decodeRouteRequest(input: DecodeRouteInput): Promise<DecodedRoute>;
|
|
40
|
-
//# sourceMappingURL=params.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../routed/params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAY,YAAY,EAAE,MAAM,wBAAwB,CAAA;AASpE,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAExD,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,kBAAkB,CAAA;IAC1B,+EAA+E;IAC/E,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,YAAY,CAAA;IACnB,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACnC,uBAAuB;IACvB,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAqGvF"}
|
package/dist/routed/params.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Route binding parameter decoder.
|
|
3
|
-
*
|
|
4
|
-
* Extracts params from all sources (host, path, query, header, body) per
|
|
5
|
-
* spec §3. Merge order: host < path < query < header < body — later wins.
|
|
6
|
-
* `route.self`, if set, is lifted to a separate top-level `self` channel
|
|
7
|
-
* AND removed from `params` — handlers read it via the `self` sibling in
|
|
8
|
-
* their execute context (`self.path.raw`), never from `params`. Leaving
|
|
9
|
-
* a copy in `params` would trip strict Zod validation of `inputSchema`
|
|
10
|
-
* (`route-self.ts` explicitly allows the placeholder to be absent from
|
|
11
|
-
* the schema, so the runtime must not smuggle it through anyway).
|
|
12
|
-
*
|
|
13
|
-
* Body modes:
|
|
14
|
-
* - `'*'` parse JSON body, merge top-level fields into params.
|
|
15
|
-
* - `'raw'` skip parsing; raw bytes at `params._body`.
|
|
16
|
-
* - `Record` parse JSON, pick mapped fields with wire-name remapping.
|
|
17
|
-
*/
|
|
18
|
-
import { jsonCodec } from '@astrale-os/kernel-api';
|
|
19
|
-
/** Check if a body pick is a whole-body read mode ({ as: 'text' } or { as: 'bytes' }). */
|
|
20
|
-
function isWholeBodyPick(pick) {
|
|
21
|
-
return typeof pick === 'object' && 'as' in pick;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Decode params from a route + request.
|
|
25
|
-
*
|
|
26
|
-
* Throws on body parse errors — the caller should map to PARSE_ERROR.
|
|
27
|
-
*/
|
|
28
|
-
export async function decodeRouteRequest(input) {
|
|
29
|
-
const { route, pathParams, hostParams = {}, request } = input;
|
|
30
|
-
const url = new URL(request.url);
|
|
31
|
-
const params = {};
|
|
32
|
-
// 1. Host placeholders (lowest priority)
|
|
33
|
-
for (const [k, v] of Object.entries(hostParams)) {
|
|
34
|
-
params[k] = v;
|
|
35
|
-
}
|
|
36
|
-
// 2. Path placeholders (implicit by name)
|
|
37
|
-
for (const [k, v] of Object.entries(pathParams)) {
|
|
38
|
-
params[k] = v;
|
|
39
|
-
}
|
|
40
|
-
// 3. Query parameters (explicit field → wire-name)
|
|
41
|
-
if (route.query) {
|
|
42
|
-
for (const [field, wireName] of Object.entries(route.query)) {
|
|
43
|
-
const value = url.searchParams.get(wireName);
|
|
44
|
-
if (value !== null) {
|
|
45
|
-
params[field] = decodeQueryValue(value);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// 4. Headers — per-entry: string = specific wire name, '*' = all headers
|
|
50
|
-
if (route.headers) {
|
|
51
|
-
for (const [field, pick] of Object.entries(route.headers)) {
|
|
52
|
-
if (pick === '*') {
|
|
53
|
-
const all = {};
|
|
54
|
-
request.headers.forEach((value, key) => {
|
|
55
|
-
all[key] = value;
|
|
56
|
-
});
|
|
57
|
-
params[field] = all;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
const value = request.headers.get(pick);
|
|
61
|
-
if (value !== null) {
|
|
62
|
-
params[field] = value;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// 5. Body — '*' = JSON spread, Record = per-field picks
|
|
68
|
-
if (route.body !== undefined) {
|
|
69
|
-
if (route.body === '*') {
|
|
70
|
-
// Parse JSON, merge all top-level fields
|
|
71
|
-
if (hasBody(request.method)) {
|
|
72
|
-
const decoded = await parseJsonBody(request);
|
|
73
|
-
if (decoded && typeof decoded === 'object') {
|
|
74
|
-
for (const [k, v] of Object.entries(decoded)) {
|
|
75
|
-
params[k] = v;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// Record<string, BodyPick> — inspect picks to determine read mode
|
|
82
|
-
const entries = Object.entries(route.body);
|
|
83
|
-
const wholeEntry = entries.find(([_, pick]) => isWholeBodyPick(pick));
|
|
84
|
-
if (wholeEntry) {
|
|
85
|
-
// Whole-body read: { as: 'text' } or { as: 'bytes' }
|
|
86
|
-
const [field, pick] = wholeEntry;
|
|
87
|
-
if (pick.as === 'text') {
|
|
88
|
-
params[field] = await request.text();
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
params[field] = new Uint8Array(await request.arrayBuffer());
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else if (hasBody(request.method)) {
|
|
95
|
-
// All string picks → JSON field picking
|
|
96
|
-
const decoded = await parseJsonBody(request);
|
|
97
|
-
if (decoded && typeof decoded === 'object') {
|
|
98
|
-
const obj = decoded;
|
|
99
|
-
for (const [field, wireName] of entries) {
|
|
100
|
-
if (wireName in obj) {
|
|
101
|
-
params[field] = obj[wireName];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
// 6. self lift: route.self placeholder → DecodedRoute.self (sibling of
|
|
109
|
-
// params, NOT a member). The source field is REMOVED from params —
|
|
110
|
-
// `self` is the canonical channel for "the node this method runs
|
|
111
|
-
// on" (matches envelope dispatch via `<path>::method`, which also
|
|
112
|
-
// keeps self out of the body). Leaving a copy in `params` would
|
|
113
|
-
// cause strict Zod validation of the inputSchema to reject the
|
|
114
|
-
// placeholder field, even though `validateRouteSelf` already says
|
|
115
|
-
// the schema doesn't have to declare it.
|
|
116
|
-
let self;
|
|
117
|
-
if (route.self !== undefined) {
|
|
118
|
-
const sourceValue = params[route.self];
|
|
119
|
-
if (typeof sourceValue === 'string') {
|
|
120
|
-
self = sourceValue;
|
|
121
|
-
delete params[route.self];
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return self !== undefined ? { params, self } : { params };
|
|
125
|
-
}
|
|
126
|
-
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
127
|
-
function hasBody(method) {
|
|
128
|
-
return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';
|
|
129
|
-
}
|
|
130
|
-
async function parseJsonBody(req) {
|
|
131
|
-
const bytes = new Uint8Array(await req.arrayBuffer());
|
|
132
|
-
if (bytes.length === 0)
|
|
133
|
-
return null;
|
|
134
|
-
return jsonCodec.decode(bytes);
|
|
135
|
-
}
|
|
136
|
-
/** Coerce a query string value to a sensible JS value (number/bool/string). */
|
|
137
|
-
function decodeQueryValue(raw) {
|
|
138
|
-
if (raw === 'true')
|
|
139
|
-
return true;
|
|
140
|
-
if (raw === 'false')
|
|
141
|
-
return false;
|
|
142
|
-
if (raw !== '' && !isNaN(Number(raw)))
|
|
143
|
-
return Number(raw);
|
|
144
|
-
return raw;
|
|
145
|
-
}
|
|
146
|
-
//# sourceMappingURL=params.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../routed/params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,wB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
4
|
-
* Distinct from `envelope/sse.ts`: route SSE emits each yielded value as its
|
|
5
|
-
* own JSON `data:` line, with `event: end` / `event: error` for terminal
|
|
6
|
-
* events. There is no kernel envelope wrapping; the route's `outputSchema`
|
|
7
|
-
* IS the chunk shape.
|
|
8
|
-
*
|
|
9
|
-
* Setup failures from the first iteration become a kernel error response so
|
|
10
|
-
* the caller can return them with the right HTTP status.
|
|
11
|
-
*/
|
|
12
|
-
import type { KernelErrorPayload } from '@astrale-os/kernel-api';
|
|
13
|
-
export type StreamResponseResult = {
|
|
14
|
-
kind: 'response';
|
|
15
|
-
response: Response;
|
|
16
|
-
} | {
|
|
17
|
-
kind: 'error';
|
|
18
|
-
error: KernelErrorPayload;
|
|
19
|
-
};
|
|
20
|
-
export declare function buildRouteStreamResponse(generator: AsyncGenerator<unknown>, corsHeaders: Record<string, string>): Promise<StreamResponseResult>;
|
|
21
|
-
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../routed/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAIhE,MAAM,MAAM,oBAAoB,GAC5B;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAA;AAEhD,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC,EAClC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,oBAAoB,CAAC,CAyD/B"}
|
package/dist/routed/stream.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SSE response with raw chunk framing — used by route bindings.
|
|
3
|
-
*
|
|
4
|
-
* Distinct from `envelope/sse.ts`: route SSE emits each yielded value as its
|
|
5
|
-
* own JSON `data:` line, with `event: end` / `event: error` for terminal
|
|
6
|
-
* events. There is no kernel envelope wrapping; the route's `outputSchema`
|
|
7
|
-
* IS the chunk shape.
|
|
8
|
-
*
|
|
9
|
-
* Setup failures from the first iteration become a kernel error response so
|
|
10
|
-
* the caller can return them with the right HTTP status.
|
|
11
|
-
*/
|
|
12
|
-
import { classifyError } from '@astrale-os/kernel-api';
|
|
13
|
-
export async function buildRouteStreamResponse(generator, corsHeaders) {
|
|
14
|
-
// Eagerly pull the first chunk so setup failures become a proper HTTP error.
|
|
15
|
-
let first;
|
|
16
|
-
try {
|
|
17
|
-
first = await generator.next();
|
|
18
|
-
}
|
|
19
|
-
catch (err) {
|
|
20
|
-
return { kind: 'error', error: classifyError(err) };
|
|
21
|
-
}
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
let cancelled = false;
|
|
24
|
-
const stream = new ReadableStream({
|
|
25
|
-
async start(controller) {
|
|
26
|
-
try {
|
|
27
|
-
if (!first.done) {
|
|
28
|
-
controller.enqueue(encoder.encode(`data: ${JSON.stringify(first.value)}\n\n`));
|
|
29
|
-
}
|
|
30
|
-
for await (const chunk of generator) {
|
|
31
|
-
if (cancelled)
|
|
32
|
-
break;
|
|
33
|
-
controller.enqueue(encoder.encode(`data: ${JSON.stringify(chunk)}\n\n`));
|
|
34
|
-
}
|
|
35
|
-
if (!cancelled) {
|
|
36
|
-
controller.enqueue(encoder.encode(`event: end\ndata: {}\n\n`));
|
|
37
|
-
}
|
|
38
|
-
controller.close();
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
try {
|
|
42
|
-
const error = classifyError(err);
|
|
43
|
-
controller.enqueue(encoder.encode(`event: error\ndata: ${JSON.stringify({ code: error.code, message: error.message })}\n\n`));
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
/* swallow */
|
|
47
|
-
}
|
|
48
|
-
controller.close();
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
cancel() {
|
|
52
|
-
cancelled = true;
|
|
53
|
-
generator.return(undefined).catch(() => { });
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
return {
|
|
57
|
-
kind: 'response',
|
|
58
|
-
response: new Response(stream, {
|
|
59
|
-
status: 200,
|
|
60
|
-
headers: {
|
|
61
|
-
...corsHeaders,
|
|
62
|
-
'content-type': 'text/event-stream',
|
|
63
|
-
'cache-control': 'no-cache',
|
|
64
|
-
connection: 'keep-alive',
|
|
65
|
-
},
|
|
66
|
-
}),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=stream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../routed/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAMtD,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,SAAkC,EAClC,WAAmC;IAEnC,6EAA6E;IAC7E,IAAI,KAA8B,CAAA;IAClC,IAAI,CAAC;QACH,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,CAAA;IAChC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,CAAA;IACrD,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;IACjC,IAAI,SAAS,GAAG,KAAK,CAAA;IACrB,MAAM,MAAM,GAAG,IAAI,cAAc,CAAC;QAChC,KAAK,CAAC,KAAK,CAAC,UAAU;YACpB,IAAI,CAAC;gBACH,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;oBAChB,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,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