@daloyjs/core 0.2.0 → 0.3.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/README.md +6 -4
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/openapi.d.ts +31 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +32 -11
- package/dist/openapi.js.map +1 -1
- package/dist/security-schemes.d.ts +98 -0
- package/dist/security-schemes.d.ts.map +1 -0
- package/dist/security-schemes.js +72 -0
- package/dist/security-schemes.js.map +1 -0
- package/dist/streaming.d.ts +85 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +261 -0
- package/dist/streaming.js.map +1 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ DaloyJS exists to be the framework you'd build if you took the best ideas from e
|
|
|
27
27
|
| **Supply-chain-hardened installs and publishing** | [pnpm](https://pnpm.io/motivation) + hardened CI/CD | `ignore-scripts`, release-age cooldown, explicit build allowlist, SHA-pinned actions, isolated OIDC publish with provenance. |
|
|
28
28
|
|
|
29
29
|
```
|
|
30
|
-
|
|
30
|
+
159/159 framework tests passing · 100% line + function coverage · clean strict TypeScript 6
|
|
31
31
|
runs on Node, Bun, Deno, Cloudflare, Vercel
|
|
32
32
|
~12.3M static-route ops/sec · ~1.5M dynamic-route ops/sec on M-class CPU
|
|
33
33
|
```
|
|
@@ -177,7 +177,7 @@ import { swaggerUiHtml, htmlResponse } from "@daloyjs/core/docs";
|
|
|
177
177
|
```
|
|
178
178
|
|
|
179
179
|
Mount at `/docs` and the UI is always contract-accurate — never stale.
|
|
180
|
-
`create-daloy@0.1.
|
|
180
|
+
`create-daloy@0.1.11` mounts Swagger UI at `/docs` and the live spec at `/openapi.json` by default.
|
|
181
181
|
|
|
182
182
|
---
|
|
183
183
|
|
|
@@ -310,11 +310,13 @@ Full, versioned plan: [ROADMAP.md](./ROADMAP.md).
|
|
|
310
310
|
- [x] `SECURITY.md` and vulnerability disclosure process
|
|
311
311
|
- [x] `pnpm create daloy` project scaffolder (Node + Vercel Edge + Cloudflare templates)
|
|
312
312
|
- [x] Docs site discoverability pass: page metadata, sitemap, robots, OpenGraph image, ORM guides
|
|
313
|
+
- [x] Streaming response helpers: SSE + NDJSON with backpressure-safe writers (`sseStream` / `sseResponse` / `ndjsonStream` / `ndjsonResponse`)
|
|
314
|
+
- [x] OpenAPI extras: `securitySchemes` builders (`httpBearerScheme` / `httpBasicScheme` / `apiKeyScheme` / `oauth2Scheme` / `openIdConnectScheme`) and top-level `webhooks` support
|
|
313
315
|
- [ ] Branch coverage push to `>= 98%`
|
|
314
316
|
- [ ] Release checklist and publishing docs cleanup
|
|
315
317
|
|
|
316
|
-
**On deck (`0.3.
|
|
317
|
-
multipart/form-data ergonomics, CSRF helper,
|
|
318
|
+
**On deck (`0.3.x` and beyond):** OpenTelemetry,
|
|
319
|
+
multipart/form-data ergonomics, CSRF helper, Redis rate-limit store,
|
|
318
320
|
CLI route and schema inspector, WebSockets, and HTTP/2 + HTTP/3 adapters.
|
|
319
321
|
|
|
320
322
|
## License
|
package/dist/index.d.ts
CHANGED
|
@@ -10,4 +10,8 @@ export { requestId, secureHeaders, cors, rateLimit, timing, bearerAuth, } from "
|
|
|
10
10
|
export type { RequestIdOptions, SecureHeadersOptions, CorsOptions, RateLimitOptions, RateLimitStore, } from "./middleware.js";
|
|
11
11
|
export { createLogger, noopLogger } from "./logger.js";
|
|
12
12
|
export type { Logger, LogLevel, ConsoleLoggerOptions } from "./logger.js";
|
|
13
|
+
export { sseStream, sseResponse, ndjsonStream, ndjsonResponse, } from "./streaming.js";
|
|
14
|
+
export type { SSEMessage, StreamOptions, SSEStreamOptions, SSEResponseOptions, NDJSONResponseOptions, } from "./streaming.js";
|
|
15
|
+
export { httpBearerScheme, httpBasicScheme, apiKeyScheme, oauth2Scheme, openIdConnectScheme, } from "./security-schemes.js";
|
|
16
|
+
export type { ApiKeyLocation, ApiKeyScheme, ApiKeySchemeOptions, HttpBasicScheme, HttpBasicSchemeOptions, HttpBearerScheme, HttpBearerSchemeOptions, OAuth2AuthorizationCodeFlow, OAuth2ClientCredentialsFlow, OAuth2Flows, OAuth2ImplicitFlow, OAuth2PasswordFlow, OAuth2Scheme, OAuth2SchemeOptions, OpenIdConnectScheme, OpenIdConnectSchemeOptions, SecurityScheme, } from "./security-schemes.js";
|
|
13
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE9D,YAAY,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,WAAW,EACX,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,SAAS,EACT,eAAe,EACf,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EACL,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,QAAQ,GACT,MAAM,eAAe,CAAC;A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,EACb,IAAI,EACJ,SAAS,EACT,MAAM,EACN,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,gBAAgB,EAChB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,EACL,SAAS,EACT,WAAW,EACX,YAAY,EACZ,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,GACf,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,6 @@ export { validate, isStandardSchema } from "./schema.js";
|
|
|
4
4
|
export { readBodyLimited, safeJsonParse, sanitizeHeaderName, sanitizeHeaderValue, timingSafeEqual, randomId, } from "./security.js";
|
|
5
5
|
export { requestId, secureHeaders, cors, rateLimit, timing, bearerAuth, } from "./middleware.js";
|
|
6
6
|
export { createLogger, noopLogger } from "./logger.js";
|
|
7
|
+
export { sseStream, sseResponse, ndjsonStream, ndjsonResponse, } from "./streaming.js";
|
|
8
|
+
export { httpBearerScheme, httpBasicScheme, apiKeyScheme, oauth2Scheme, openIdConnectScheme, } from "./security-schemes.js";
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAoB/B,OAAO,EACL,SAAS,EACT,eAAe,EACf,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,GACd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EACL,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,QAAQ,GACT,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,SAAS,EACT,aAAa,EACb,IAAI,EACJ,SAAS,EACT,MAAM,EACN,UAAU,GACX,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAoB/B,OAAO,EACL,SAAS,EACT,eAAe,EACf,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,GACd,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EACL,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,QAAQ,GACT,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,SAAS,EACT,aAAa,EACb,IAAI,EACJ,SAAS,EACT,MAAM,EACN,UAAU,GACX,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGvD,OAAO,EACL,SAAS,EACT,WAAW,EACX,YAAY,EACZ,cAAc,GACf,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,mBAAmB,GACpB,MAAM,uBAAuB,CAAC"}
|
package/dist/openapi.d.ts
CHANGED
|
@@ -8,13 +8,38 @@
|
|
|
8
8
|
* fail — codegen and docs still work, just with looser types for that field.
|
|
9
9
|
*/
|
|
10
10
|
import type { App } from "./app.js";
|
|
11
|
+
import type { AuthSpec, HttpMethod, RequestSchemas, ResponsesMap } from "./types.js";
|
|
12
|
+
import type { SecurityScheme } from "./security-schemes.js";
|
|
13
|
+
export { httpBearerScheme, httpBasicScheme, apiKeyScheme, oauth2Scheme, openIdConnectScheme, } from "./security-schemes.js";
|
|
14
|
+
export type { ApiKeyLocation, ApiKeyScheme, ApiKeySchemeOptions, HttpBasicScheme, HttpBasicSchemeOptions, HttpBearerScheme, HttpBearerSchemeOptions, OAuth2AuthorizationCodeFlow, OAuth2ClientCredentialsFlow, OAuth2Flows, OAuth2ImplicitFlow, OAuth2PasswordFlow, OAuth2Scheme, OAuth2SchemeOptions, OpenIdConnectScheme, OpenIdConnectSchemeOptions, SecurityScheme, } from "./security-schemes.js";
|
|
11
15
|
export interface OpenAPIInfo {
|
|
12
16
|
title: string;
|
|
13
17
|
version: string;
|
|
14
18
|
description?: string;
|
|
15
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Map of named OpenAPI Security Scheme objects. Builders from
|
|
22
|
+
* `./security-schemes.ts` (`httpBearerScheme`, `apiKeyScheme`, ...) return
|
|
23
|
+
* values that fit here.
|
|
24
|
+
*/
|
|
16
25
|
export interface SecuritySchemeMap {
|
|
17
|
-
[name: string]: Record<string, unknown>;
|
|
26
|
+
[name: string]: SecurityScheme | Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Webhook definition for OpenAPI 3.1 top-level `webhooks`. Mirrors a
|
|
30
|
+
* `RouteDefinition` minus `path` (consumers control the URL) and `handler`
|
|
31
|
+
* (no execution path on the producer side).
|
|
32
|
+
*/
|
|
33
|
+
export interface WebhookDefinition {
|
|
34
|
+
method: HttpMethod;
|
|
35
|
+
operationId?: string;
|
|
36
|
+
summary?: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
tags?: string[];
|
|
39
|
+
deprecated?: boolean;
|
|
40
|
+
request?: RequestSchemas;
|
|
41
|
+
responses: ResponsesMap;
|
|
42
|
+
auth?: AuthSpec;
|
|
18
43
|
}
|
|
19
44
|
export interface OpenAPIOptions {
|
|
20
45
|
info: OpenAPIInfo;
|
|
@@ -23,6 +48,11 @@ export interface OpenAPIOptions {
|
|
|
23
48
|
description?: string;
|
|
24
49
|
}>;
|
|
25
50
|
securitySchemes?: SecuritySchemeMap;
|
|
51
|
+
/**
|
|
52
|
+
* Optional OpenAPI 3.1 webhooks. Each key is a webhook name; the value is
|
|
53
|
+
* one or more webhook operations (one per HTTP method).
|
|
54
|
+
*/
|
|
55
|
+
webhooks?: Record<string, WebhookDefinition | WebhookDefinition[]>;
|
|
26
56
|
}
|
|
27
57
|
export declare function generateOpenAPI(app: App, options: OpenAPIOptions): Record<string, unknown>;
|
|
28
58
|
//# sourceMappingURL=openapi.d.ts.map
|
package/dist/openapi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources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AQ,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvD,eAAe,CAAC,EAAE,iBAAiB,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,CAAC,CAAC;CACpE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA4C1F"}
|
package/dist/openapi.js
CHANGED
|
@@ -7,18 +7,21 @@
|
|
|
7
7
|
* we use it. Otherwise we emit a permissive `{}` placeholder rather than
|
|
8
8
|
* fail — codegen and docs still work, just with looser types for that field.
|
|
9
9
|
*/
|
|
10
|
+
export { httpBearerScheme, httpBasicScheme, apiKeyScheme, oauth2Scheme, openIdConnectScheme, } from "./security-schemes.js";
|
|
10
11
|
export function generateOpenAPI(app, options) {
|
|
11
12
|
const paths = {};
|
|
12
13
|
for (const route of app.routes) {
|
|
13
14
|
const oasPath = route.path.replace(/:([A-Za-z0-9_]+)/g, "{$1}");
|
|
14
15
|
paths[oasPath] ??= {};
|
|
15
|
-
paths[oasPath][route.method.toLowerCase()] = buildOperation(route);
|
|
16
|
+
paths[oasPath][route.method.toLowerCase()] = buildOperation(route, route.path);
|
|
16
17
|
}
|
|
18
|
+
const webhooks = buildWebhooks(options.webhooks);
|
|
17
19
|
return {
|
|
18
20
|
openapi: "3.1.0",
|
|
19
21
|
info: options.info,
|
|
20
22
|
...(options.servers ? { servers: options.servers } : {}),
|
|
21
23
|
paths,
|
|
24
|
+
...(webhooks ? { webhooks } : {}),
|
|
22
25
|
components: {
|
|
23
26
|
...(options.securitySchemes ? { securitySchemes: options.securitySchemes } : {}),
|
|
24
27
|
schemas: {
|
|
@@ -47,7 +50,7 @@ export function generateOpenAPI(app, options) {
|
|
|
47
50
|
},
|
|
48
51
|
};
|
|
49
52
|
}
|
|
50
|
-
function buildOperation(route) {
|
|
53
|
+
function buildOperation(route, path) {
|
|
51
54
|
const op = {
|
|
52
55
|
...(route.operationId ? { operationId: route.operationId } : {}),
|
|
53
56
|
...(route.summary ? { summary: route.summary } : {}),
|
|
@@ -56,15 +59,17 @@ function buildOperation(route) {
|
|
|
56
59
|
...(route.deprecated ? { deprecated: true } : {}),
|
|
57
60
|
};
|
|
58
61
|
const parameters = [];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
if (path) {
|
|
63
|
+
// Path params: emit one entry per :name in the path.
|
|
64
|
+
const paramNames = [...path.matchAll(/:([A-Za-z0-9_]+)/g)].map((m) => m[1]);
|
|
65
|
+
for (const name of paramNames) {
|
|
66
|
+
parameters.push({
|
|
67
|
+
name,
|
|
68
|
+
in: "path",
|
|
69
|
+
required: true,
|
|
70
|
+
schema: extractPropertySchema(route.request?.params, name) ?? { type: "string" },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
68
73
|
}
|
|
69
74
|
if (route.request?.query) {
|
|
70
75
|
const schema = toJsonSchema(route.request.query) ?? { type: "object" };
|
|
@@ -114,6 +119,22 @@ function buildOperation(route) {
|
|
|
114
119
|
}
|
|
115
120
|
return op;
|
|
116
121
|
}
|
|
122
|
+
function buildWebhooks(webhooks) {
|
|
123
|
+
if (!webhooks)
|
|
124
|
+
return undefined;
|
|
125
|
+
const out = {};
|
|
126
|
+
for (const [name, defOrDefs] of Object.entries(webhooks)) {
|
|
127
|
+
const defs = Array.isArray(defOrDefs) ? defOrDefs : [defOrDefs];
|
|
128
|
+
if (defs.length === 0)
|
|
129
|
+
continue;
|
|
130
|
+
const pathItem = {};
|
|
131
|
+
for (const def of defs) {
|
|
132
|
+
pathItem[def.method.toLowerCase()] = buildOperation(def);
|
|
133
|
+
}
|
|
134
|
+
out[name] = pathItem;
|
|
135
|
+
}
|
|
136
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
137
|
+
}
|
|
117
138
|
function toJsonSchema(schema) {
|
|
118
139
|
if (!schema)
|
|
119
140
|
return undefined;
|
package/dist/openapi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../src/openapi.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAgE/B,MAAM,UAAU,eAAe,CAAC,GAAQ,EAAE,OAAuB;IAC/D,MAAM,KAAK,GAA4C,EAAE,CAAC;IAE1D,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;QAChE,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACtB,KAAK,CAAC,OAAO,CAAE,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEjD,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,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C,CAAC,IAAI,CAAC,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;YACjF,MAAM,UAAU,GAA4B,EAAE,CAAC;YAC/C,MAAM,QAAQ,GAAa,EAAE,CAAC;YAC9B,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAM,KAAK,CAAC,EAAE,CAAC;gBAChD,UAAU,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;gBAC/B,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,EAAE;oBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;QAClD,CAAC;QACD,KAAK,UAAU,CAAC;QAChB,KAAK,OAAO;YACV,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9E,KAAK,aAAa,CAAC;QACnB,KAAK,UAAU,CAAC;QAChB,KAAK,aAAa,CAAC;QACnB,KAAK,UAAU;YACb,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvC;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ergonomic builders for OpenAPI 3.1 Security Scheme objects.
|
|
3
|
+
*
|
|
4
|
+
* These return plain JSON objects shaped exactly like the spec expects, so the
|
|
5
|
+
* output of any builder can be dropped straight into
|
|
6
|
+
* `generateOpenAPI(app, { securitySchemes: { ... } })`.
|
|
7
|
+
*
|
|
8
|
+
* Spec reference:
|
|
9
|
+
* https://spec.openapis.org/oas/v3.1.0#security-scheme-object
|
|
10
|
+
*/
|
|
11
|
+
export type ApiKeyLocation = "header" | "query" | "cookie";
|
|
12
|
+
export interface HttpBearerSchemeOptions {
|
|
13
|
+
/** Hint about the bearer token format (e.g. "JWT"). */
|
|
14
|
+
bearerFormat?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface HttpBasicSchemeOptions {
|
|
18
|
+
description?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ApiKeySchemeOptions {
|
|
21
|
+
in: ApiKeyLocation;
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface OAuth2ImplicitFlow {
|
|
26
|
+
authorizationUrl: string;
|
|
27
|
+
refreshUrl?: string;
|
|
28
|
+
scopes: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
export interface OAuth2PasswordFlow {
|
|
31
|
+
tokenUrl: string;
|
|
32
|
+
refreshUrl?: string;
|
|
33
|
+
scopes: Record<string, string>;
|
|
34
|
+
}
|
|
35
|
+
export interface OAuth2ClientCredentialsFlow {
|
|
36
|
+
tokenUrl: string;
|
|
37
|
+
refreshUrl?: string;
|
|
38
|
+
scopes: Record<string, string>;
|
|
39
|
+
}
|
|
40
|
+
export interface OAuth2AuthorizationCodeFlow {
|
|
41
|
+
authorizationUrl: string;
|
|
42
|
+
tokenUrl: string;
|
|
43
|
+
refreshUrl?: string;
|
|
44
|
+
scopes: Record<string, string>;
|
|
45
|
+
}
|
|
46
|
+
export interface OAuth2Flows {
|
|
47
|
+
implicit?: OAuth2ImplicitFlow;
|
|
48
|
+
password?: OAuth2PasswordFlow;
|
|
49
|
+
clientCredentials?: OAuth2ClientCredentialsFlow;
|
|
50
|
+
authorizationCode?: OAuth2AuthorizationCodeFlow;
|
|
51
|
+
}
|
|
52
|
+
export interface OAuth2SchemeOptions {
|
|
53
|
+
flows: OAuth2Flows;
|
|
54
|
+
description?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface OpenIdConnectSchemeOptions {
|
|
57
|
+
openIdConnectUrl: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface HttpBearerScheme {
|
|
61
|
+
type: "http";
|
|
62
|
+
scheme: "bearer";
|
|
63
|
+
bearerFormat?: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface HttpBasicScheme {
|
|
67
|
+
type: "http";
|
|
68
|
+
scheme: "basic";
|
|
69
|
+
description?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface ApiKeyScheme {
|
|
72
|
+
type: "apiKey";
|
|
73
|
+
in: ApiKeyLocation;
|
|
74
|
+
name: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
}
|
|
77
|
+
export interface OAuth2Scheme {
|
|
78
|
+
type: "oauth2";
|
|
79
|
+
flows: OAuth2Flows;
|
|
80
|
+
description?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface OpenIdConnectScheme {
|
|
83
|
+
type: "openIdConnect";
|
|
84
|
+
openIdConnectUrl: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
}
|
|
87
|
+
export type SecurityScheme = HttpBearerScheme | HttpBasicScheme | ApiKeyScheme | OAuth2Scheme | OpenIdConnectScheme;
|
|
88
|
+
/** HTTP Bearer token scheme (e.g. `Authorization: Bearer <token>`). */
|
|
89
|
+
export declare function httpBearerScheme(options?: HttpBearerSchemeOptions): HttpBearerScheme;
|
|
90
|
+
/** HTTP Basic auth scheme (`Authorization: Basic <base64>`). */
|
|
91
|
+
export declare function httpBasicScheme(options?: HttpBasicSchemeOptions): HttpBasicScheme;
|
|
92
|
+
/** API key scheme delivered in a header, query parameter, or cookie. */
|
|
93
|
+
export declare function apiKeyScheme(options: ApiKeySchemeOptions): ApiKeyScheme;
|
|
94
|
+
/** OAuth 2.0 scheme. At least one flow is required. */
|
|
95
|
+
export declare function oauth2Scheme(options: OAuth2SchemeOptions): OAuth2Scheme;
|
|
96
|
+
/** OpenID Connect Discovery scheme. */
|
|
97
|
+
export declare function openIdConnectScheme(options: OpenIdConnectSchemeOptions): OpenIdConnectScheme;
|
|
98
|
+
//# sourceMappingURL=security-schemes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-schemes.d.ts","sourceRoot":"","sources":["../src/security-schemes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE3D,MAAM,WAAW,uBAAuB;IACtC,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,cAAc,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,2BAA2B;IAC1C,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MA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,gBAAgB,GAChB,eAAe,GACf,YAAY,GACZ,YAAY,GACZ,mBAAmB,CAAC;AAExB,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAKxF;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,CAIrF;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAgBvE;AAED,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAavE;AAED,uCAAuC;AACvC,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,0BAA0B,GAClC,mBAAmB,CAYrB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ergonomic builders for OpenAPI 3.1 Security Scheme objects.
|
|
3
|
+
*
|
|
4
|
+
* These return plain JSON objects shaped exactly like the spec expects, so the
|
|
5
|
+
* output of any builder can be dropped straight into
|
|
6
|
+
* `generateOpenAPI(app, { securitySchemes: { ... } })`.
|
|
7
|
+
*
|
|
8
|
+
* Spec reference:
|
|
9
|
+
* https://spec.openapis.org/oas/v3.1.0#security-scheme-object
|
|
10
|
+
*/
|
|
11
|
+
/** HTTP Bearer token scheme (e.g. `Authorization: Bearer <token>`). */
|
|
12
|
+
export function httpBearerScheme(options = {}) {
|
|
13
|
+
const scheme = { type: "http", scheme: "bearer" };
|
|
14
|
+
if (options.bearerFormat !== undefined)
|
|
15
|
+
scheme.bearerFormat = options.bearerFormat;
|
|
16
|
+
if (options.description !== undefined)
|
|
17
|
+
scheme.description = options.description;
|
|
18
|
+
return scheme;
|
|
19
|
+
}
|
|
20
|
+
/** HTTP Basic auth scheme (`Authorization: Basic <base64>`). */
|
|
21
|
+
export function httpBasicScheme(options = {}) {
|
|
22
|
+
const scheme = { type: "http", scheme: "basic" };
|
|
23
|
+
if (options.description !== undefined)
|
|
24
|
+
scheme.description = options.description;
|
|
25
|
+
return scheme;
|
|
26
|
+
}
|
|
27
|
+
/** API key scheme delivered in a header, query parameter, or cookie. */
|
|
28
|
+
export function apiKeyScheme(options) {
|
|
29
|
+
if (options.in !== "header" && options.in !== "query" && options.in !== "cookie") {
|
|
30
|
+
throw new TypeError(`apiKeyScheme: "in" must be one of "header" | "query" | "cookie", got "${String(options.in)}"`);
|
|
31
|
+
}
|
|
32
|
+
if (typeof options.name !== "string" || options.name.length === 0) {
|
|
33
|
+
throw new TypeError(`apiKeyScheme: "name" must be a non-empty string`);
|
|
34
|
+
}
|
|
35
|
+
const scheme = {
|
|
36
|
+
type: "apiKey",
|
|
37
|
+
in: options.in,
|
|
38
|
+
name: options.name,
|
|
39
|
+
};
|
|
40
|
+
if (options.description !== undefined)
|
|
41
|
+
scheme.description = options.description;
|
|
42
|
+
return scheme;
|
|
43
|
+
}
|
|
44
|
+
/** OAuth 2.0 scheme. At least one flow is required. */
|
|
45
|
+
export function oauth2Scheme(options) {
|
|
46
|
+
const flows = options.flows ?? {};
|
|
47
|
+
const hasFlow = flows.implicit !== undefined ||
|
|
48
|
+
flows.password !== undefined ||
|
|
49
|
+
flows.clientCredentials !== undefined ||
|
|
50
|
+
flows.authorizationCode !== undefined;
|
|
51
|
+
if (!hasFlow) {
|
|
52
|
+
throw new TypeError(`oauth2Scheme: at least one OAuth2 flow is required`);
|
|
53
|
+
}
|
|
54
|
+
const scheme = { type: "oauth2", flows };
|
|
55
|
+
if (options.description !== undefined)
|
|
56
|
+
scheme.description = options.description;
|
|
57
|
+
return scheme;
|
|
58
|
+
}
|
|
59
|
+
/** OpenID Connect Discovery scheme. */
|
|
60
|
+
export function openIdConnectScheme(options) {
|
|
61
|
+
if (typeof options.openIdConnectUrl !== "string" || options.openIdConnectUrl.length === 0) {
|
|
62
|
+
throw new TypeError(`openIdConnectScheme: "openIdConnectUrl" must be a non-empty string`);
|
|
63
|
+
}
|
|
64
|
+
const scheme = {
|
|
65
|
+
type: "openIdConnect",
|
|
66
|
+
openIdConnectUrl: options.openIdConnectUrl,
|
|
67
|
+
};
|
|
68
|
+
if (options.description !== undefined)
|
|
69
|
+
scheme.description = options.description;
|
|
70
|
+
return scheme;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=security-schemes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-schemes.js","sourceRoot":"","sources":["../src/security-schemes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAqGH,uEAAuE;AACvE,MAAM,UAAU,gBAAgB,CAAC,UAAmC,EAAE;IACpE,MAAM,MAAM,GAAqB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IACpE,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS;QAAE,MAAM,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IACnF,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS;QAAE,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAChF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,eAAe,CAAC,UAAkC,EAAE;IAClE,MAAM,MAAM,GAAoB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAClE,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS;QAAE,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAChF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,OAA4B;IACvD,IAAI,OAAO,CAAC,EAAE,KAAK,QAAQ,IAAI,OAAO,CAAC,EAAE,KAAK,OAAO,IAAI,OAAO,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACjF,MAAM,IAAI,SAAS,CACjB,yEAAyE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,C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IAAI,SAAS,CACjB,oEAAoE,CACrE,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAwB;QAClC,IAAI,EAAE,eAAe;QACrB,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;KAC3C,CAAC;IACF,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS;QAAE,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAChF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming response helpers — Server-Sent Events (SSE) and NDJSON.
|
|
3
|
+
*
|
|
4
|
+
* Both helpers return a `ReadableStream<Uint8Array>` (or, in the `*Response`
|
|
5
|
+
* forms, a `Response`) that is **backpressure-safe**: data is only pulled
|
|
6
|
+
* from the underlying `AsyncIterable`/generator when the consumer asks for
|
|
7
|
+
* the next chunk. They also honor an optional `AbortSignal` and call
|
|
8
|
+
* `iterator.return()` so caller-owned resources (DB cursors, fetches, queues)
|
|
9
|
+
* are released when the client disconnects.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { sseStream } from "@daloyjs/core";
|
|
13
|
+
*
|
|
14
|
+
* app.route({
|
|
15
|
+
* method: "GET",
|
|
16
|
+
* path: "/events",
|
|
17
|
+
* operationId: "events",
|
|
18
|
+
* responses: { 200: { description: "SSE stream" } },
|
|
19
|
+
* handler: ({ request }) => ({
|
|
20
|
+
* status: 200,
|
|
21
|
+
* headers: { "content-type": "text/event-stream" },
|
|
22
|
+
* body: sseStream(async function* () {
|
|
23
|
+
* yield { event: "ping", data: { now: Date.now() } };
|
|
24
|
+
* }, { signal: request.signal }),
|
|
25
|
+
* }),
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* For NDJSON, each yielded value is JSON-encoded and terminated with `\n`.
|
|
30
|
+
*/
|
|
31
|
+
/** A single SSE event. `data` may be a string or any JSON-serializable value. */
|
|
32
|
+
export interface SSEMessage {
|
|
33
|
+
data: unknown;
|
|
34
|
+
event?: string;
|
|
35
|
+
id?: string;
|
|
36
|
+
/** Reconnection delay in milliseconds. */
|
|
37
|
+
retry?: number;
|
|
38
|
+
/** Comment line (sent as `: <comment>`). Useful for keep-alive pings. */
|
|
39
|
+
comment?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface StreamOptions {
|
|
42
|
+
/** Abort the stream when this signal fires. */
|
|
43
|
+
signal?: AbortSignal;
|
|
44
|
+
}
|
|
45
|
+
export interface SSEStreamOptions extends StreamOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Send a comment (`:keep-alive`) every N milliseconds to keep the
|
|
48
|
+
* connection open through proxies. Set to `0`/`undefined` to disable.
|
|
49
|
+
*/
|
|
50
|
+
keepAliveMs?: number;
|
|
51
|
+
}
|
|
52
|
+
export interface SSEResponseOptions extends SSEStreamOptions {
|
|
53
|
+
status?: number;
|
|
54
|
+
headers?: HeadersInit;
|
|
55
|
+
}
|
|
56
|
+
export interface NDJSONResponseOptions extends StreamOptions {
|
|
57
|
+
status?: number;
|
|
58
|
+
headers?: HeadersInit;
|
|
59
|
+
}
|
|
60
|
+
type IterableSource<T> = AsyncIterable<T> | Iterable<T> | (() => AsyncIterable<T> | Iterable<T>);
|
|
61
|
+
/**
|
|
62
|
+
* Build a backpressure-safe `ReadableStream` from an async iterable of SSE
|
|
63
|
+
* messages. The iterator is only advanced when the consumer pulls the next
|
|
64
|
+
* chunk, so a slow client cannot cause unbounded buffering.
|
|
65
|
+
*/
|
|
66
|
+
export declare function sseStream(source: IterableSource<SSEMessage | string>, opts?: SSEStreamOptions): ReadableStream<Uint8Array>;
|
|
67
|
+
/**
|
|
68
|
+
* Wrap `sseStream` in a `Response` with the proper SSE headers
|
|
69
|
+
* (`text/event-stream`, no caching, keep-alive). Caller-supplied headers win.
|
|
70
|
+
*/
|
|
71
|
+
export declare function sseResponse(source: IterableSource<SSEMessage | string>, opts?: SSEResponseOptions): Response;
|
|
72
|
+
/**
|
|
73
|
+
* Build a backpressure-safe `ReadableStream` of NDJSON (newline-delimited
|
|
74
|
+
* JSON) records from an async iterable. Each yielded value is encoded with
|
|
75
|
+
* `JSON.stringify` and terminated with `\n`. Values that stringify to
|
|
76
|
+
* `undefined` throw because they cannot be represented as valid NDJSON.
|
|
77
|
+
*/
|
|
78
|
+
export declare function ndjsonStream<T>(source: IterableSource<T>, opts?: StreamOptions): ReadableStream<Uint8Array>;
|
|
79
|
+
/**
|
|
80
|
+
* Wrap `ndjsonStream` in a `Response` with `application/x-ndjson` and
|
|
81
|
+
* cache-busting headers. Caller-supplied headers win.
|
|
82
|
+
*/
|
|
83
|
+
export declare function ndjsonResponse<T>(source: IterableSource<T>, opts?: NDJSONResponseOptions): Response;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,iFAAiF;AACjF,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,KAAK,cAAc,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AA2DjG;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,cAAc,CAAC,UAAU,GAAG,MAAM,CAAC,EAC3C,IAAI,GAAE,gBAAqB,GAC1B,cAAc,CAAC,UAAU,CAAC,CAuE5B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,cAAc,CAAC,UAAU,GAAG,MAAM,CAAC,EAC3C,IAAI,GAAE,kBAAuB,GAC5B,QAAQ,CASV;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EACzB,IAAI,GAAE,aAAkB,GACvB,cAAc,CAAC,UAAU,CAAC,CAuD5B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,EACzB,IAAI,GAAE,qBAA0B,GAC/B,QAAQ,CAOV"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming response helpers — Server-Sent Events (SSE) and NDJSON.
|
|
3
|
+
*
|
|
4
|
+
* Both helpers return a `ReadableStream<Uint8Array>` (or, in the `*Response`
|
|
5
|
+
* forms, a `Response`) that is **backpressure-safe**: data is only pulled
|
|
6
|
+
* from the underlying `AsyncIterable`/generator when the consumer asks for
|
|
7
|
+
* the next chunk. They also honor an optional `AbortSignal` and call
|
|
8
|
+
* `iterator.return()` so caller-owned resources (DB cursors, fetches, queues)
|
|
9
|
+
* are released when the client disconnects.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { sseStream } from "@daloyjs/core";
|
|
13
|
+
*
|
|
14
|
+
* app.route({
|
|
15
|
+
* method: "GET",
|
|
16
|
+
* path: "/events",
|
|
17
|
+
* operationId: "events",
|
|
18
|
+
* responses: { 200: { description: "SSE stream" } },
|
|
19
|
+
* handler: ({ request }) => ({
|
|
20
|
+
* status: 200,
|
|
21
|
+
* headers: { "content-type": "text/event-stream" },
|
|
22
|
+
* body: sseStream(async function* () {
|
|
23
|
+
* yield { event: "ping", data: { now: Date.now() } };
|
|
24
|
+
* }, { signal: request.signal }),
|
|
25
|
+
* }),
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* For NDJSON, each yielded value is JSON-encoded and terminated with `\n`.
|
|
30
|
+
*/
|
|
31
|
+
const TEXT_ENCODER = new TextEncoder();
|
|
32
|
+
function getAsyncIterator(src) {
|
|
33
|
+
const it = typeof src === "function" ? src() : src;
|
|
34
|
+
if (it == null) {
|
|
35
|
+
throw new TypeError("Streaming source is null/undefined");
|
|
36
|
+
}
|
|
37
|
+
if (typeof it[Symbol.asyncIterator] === "function") {
|
|
38
|
+
return it[Symbol.asyncIterator]();
|
|
39
|
+
}
|
|
40
|
+
if (typeof it[Symbol.iterator] === "function") {
|
|
41
|
+
const sync = it[Symbol.iterator]();
|
|
42
|
+
const wrapped = {
|
|
43
|
+
next: async () => sync.next(),
|
|
44
|
+
};
|
|
45
|
+
if (sync.return) {
|
|
46
|
+
wrapped.return = async (value) => sync.return(value);
|
|
47
|
+
}
|
|
48
|
+
return wrapped;
|
|
49
|
+
}
|
|
50
|
+
throw new TypeError("Streaming source is not iterable");
|
|
51
|
+
}
|
|
52
|
+
function encodeSSE(msg) {
|
|
53
|
+
const message = typeof msg === "string" ? { data: msg } : msg;
|
|
54
|
+
let out = "";
|
|
55
|
+
if (message.comment) {
|
|
56
|
+
for (const line of String(message.comment).split(/\r?\n/)) {
|
|
57
|
+
out += `: ${line}\n`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (message.event !== undefined) {
|
|
61
|
+
// Event names cannot contain newlines per the spec.
|
|
62
|
+
out += `event: ${String(message.event).replace(/[\r\n]+/g, " ")}\n`;
|
|
63
|
+
}
|
|
64
|
+
if (message.id !== undefined) {
|
|
65
|
+
out += `id: ${String(message.id).replace(/[\r\n]+/g, " ")}\n`;
|
|
66
|
+
}
|
|
67
|
+
if (message.retry !== undefined && Number.isFinite(message.retry)) {
|
|
68
|
+
out += `retry: ${Math.max(0, Math.floor(message.retry))}\n`;
|
|
69
|
+
}
|
|
70
|
+
if (message.data !== undefined) {
|
|
71
|
+
const raw = typeof message.data === "string" ? message.data : JSON.stringify(message.data);
|
|
72
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
73
|
+
out += `data: ${line}\n`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
out += "\n";
|
|
77
|
+
return TEXT_ENCODER.encode(out);
|
|
78
|
+
}
|
|
79
|
+
function encodeNDJSON(value) {
|
|
80
|
+
const line = JSON.stringify(value);
|
|
81
|
+
if (line === undefined) {
|
|
82
|
+
throw new TypeError("NDJSON values must be JSON-serializable");
|
|
83
|
+
}
|
|
84
|
+
return TEXT_ENCODER.encode(line + "\n");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Build a backpressure-safe `ReadableStream` from an async iterable of SSE
|
|
88
|
+
* messages. The iterator is only advanced when the consumer pulls the next
|
|
89
|
+
* chunk, so a slow client cannot cause unbounded buffering.
|
|
90
|
+
*/
|
|
91
|
+
export function sseStream(source, opts = {}) {
|
|
92
|
+
const iterator = getAsyncIterator(source);
|
|
93
|
+
let keepAliveTimer;
|
|
94
|
+
let abortHandler;
|
|
95
|
+
const cleanup = async (cancelValue) => {
|
|
96
|
+
if (keepAliveTimer !== undefined) {
|
|
97
|
+
clearInterval(keepAliveTimer);
|
|
98
|
+
keepAliveTimer = undefined;
|
|
99
|
+
}
|
|
100
|
+
if (opts.signal && abortHandler) {
|
|
101
|
+
opts.signal.removeEventListener("abort", abortHandler);
|
|
102
|
+
abortHandler = undefined;
|
|
103
|
+
}
|
|
104
|
+
if (typeof iterator.return === "function") {
|
|
105
|
+
try {
|
|
106
|
+
await iterator.return(cancelValue);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
/* swallow — the consumer is already gone */
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return new ReadableStream({
|
|
114
|
+
start(controller) {
|
|
115
|
+
if (opts.signal?.aborted) {
|
|
116
|
+
controller.close();
|
|
117
|
+
void cleanup();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (opts.signal) {
|
|
121
|
+
abortHandler = () => {
|
|
122
|
+
try {
|
|
123
|
+
controller.close();
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
/* already closed */
|
|
127
|
+
}
|
|
128
|
+
void cleanup();
|
|
129
|
+
};
|
|
130
|
+
opts.signal.addEventListener("abort", abortHandler, { once: true });
|
|
131
|
+
}
|
|
132
|
+
if (opts.keepAliveMs && opts.keepAliveMs > 0) {
|
|
133
|
+
keepAliveTimer = setInterval(() => {
|
|
134
|
+
try {
|
|
135
|
+
if ((controller.desiredSize ?? 0) > 0) {
|
|
136
|
+
controller.enqueue(TEXT_ENCODER.encode(": keep-alive\n\n"));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
/* stream closed — interval will be cleared on cancel */
|
|
141
|
+
}
|
|
142
|
+
}, opts.keepAliveMs);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
async pull(controller) {
|
|
146
|
+
try {
|
|
147
|
+
const { value, done } = await iterator.next();
|
|
148
|
+
if (done) {
|
|
149
|
+
controller.close();
|
|
150
|
+
await cleanup();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
controller.enqueue(encodeSSE(value));
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
controller.error(err);
|
|
157
|
+
await cleanup(err);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
async cancel(reason) {
|
|
161
|
+
await cleanup(reason);
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Wrap `sseStream` in a `Response` with the proper SSE headers
|
|
167
|
+
* (`text/event-stream`, no caching, keep-alive). Caller-supplied headers win.
|
|
168
|
+
*/
|
|
169
|
+
export function sseResponse(source, opts = {}) {
|
|
170
|
+
const stream = sseStream(source, opts);
|
|
171
|
+
const headers = new Headers(opts.headers);
|
|
172
|
+
if (!headers.has("content-type"))
|
|
173
|
+
headers.set("content-type", "text/event-stream; charset=utf-8");
|
|
174
|
+
if (!headers.has("cache-control"))
|
|
175
|
+
headers.set("cache-control", "no-cache, no-transform");
|
|
176
|
+
if (!headers.has("connection"))
|
|
177
|
+
headers.set("connection", "keep-alive");
|
|
178
|
+
// Disable proxy buffering (nginx).
|
|
179
|
+
if (!headers.has("x-accel-buffering"))
|
|
180
|
+
headers.set("x-accel-buffering", "no");
|
|
181
|
+
return new Response(stream, { status: opts.status ?? 200, headers });
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Build a backpressure-safe `ReadableStream` of NDJSON (newline-delimited
|
|
185
|
+
* JSON) records from an async iterable. Each yielded value is encoded with
|
|
186
|
+
* `JSON.stringify` and terminated with `\n`. Values that stringify to
|
|
187
|
+
* `undefined` throw because they cannot be represented as valid NDJSON.
|
|
188
|
+
*/
|
|
189
|
+
export function ndjsonStream(source, opts = {}) {
|
|
190
|
+
const iterator = getAsyncIterator(source);
|
|
191
|
+
let abortHandler;
|
|
192
|
+
const cleanup = async (cancelValue) => {
|
|
193
|
+
if (opts.signal && abortHandler) {
|
|
194
|
+
opts.signal.removeEventListener("abort", abortHandler);
|
|
195
|
+
abortHandler = undefined;
|
|
196
|
+
}
|
|
197
|
+
if (typeof iterator.return === "function") {
|
|
198
|
+
try {
|
|
199
|
+
await iterator.return(cancelValue);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
/* swallow */
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
return new ReadableStream({
|
|
207
|
+
start(controller) {
|
|
208
|
+
if (opts.signal?.aborted) {
|
|
209
|
+
controller.close();
|
|
210
|
+
void cleanup();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (opts.signal) {
|
|
214
|
+
abortHandler = () => {
|
|
215
|
+
try {
|
|
216
|
+
controller.close();
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
/* already closed */
|
|
220
|
+
}
|
|
221
|
+
void cleanup();
|
|
222
|
+
};
|
|
223
|
+
opts.signal.addEventListener("abort", abortHandler, { once: true });
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
async pull(controller) {
|
|
227
|
+
try {
|
|
228
|
+
const { value, done } = await iterator.next();
|
|
229
|
+
if (done) {
|
|
230
|
+
controller.close();
|
|
231
|
+
await cleanup();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
controller.enqueue(encodeNDJSON(value));
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
controller.error(err);
|
|
238
|
+
await cleanup(err);
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
async cancel(reason) {
|
|
242
|
+
await cleanup(reason);
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Wrap `ndjsonStream` in a `Response` with `application/x-ndjson` and
|
|
248
|
+
* cache-busting headers. Caller-supplied headers win.
|
|
249
|
+
*/
|
|
250
|
+
export function ndjsonResponse(source, opts = {}) {
|
|
251
|
+
const stream = ndjsonStream(source, opts);
|
|
252
|
+
const headers = new Headers(opts.headers);
|
|
253
|
+
if (!headers.has("content-type"))
|
|
254
|
+
headers.set("content-type", "application/x-ndjson; charset=utf-8");
|
|
255
|
+
if (!headers.has("cache-control"))
|
|
256
|
+
headers.set("cache-control", "no-cache, no-transform");
|
|
257
|
+
if (!headers.has("x-accel-buffering"))
|
|
258
|
+
headers.set("x-accel-buffering", "no");
|
|
259
|
+
return new Response(stream, { status: opts.status ?? 200, headers });
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=streaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC;AAsCvC,SAAS,gBAAgB,CAAI,GAAsB;IACjD,MAAM,EAAE,GAAG,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IACnD,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACf,MAAM,IAAI,SAAS,CAAC,oCAAoC,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,OAAQ,EAAuB,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,UAAU,EAAE,CAAC;QACzE,OAAQ,EAAuB,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IAC1D,CAAC;IACD,IAAI,OAAQ,EAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,UAAU,EAAE,CAAC;QAC/D,MAAM,IAAI,GAAI,EAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,MAAM,OAAO,GAAqB;YAChC,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE;SAC9B,CAAC;QACF,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,KAAe,EAAE,EAAE,CAAC,IAAI,CAAC,MAAO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AC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;IAC9E,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AACvE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daloyjs/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "DaloyJS is a runtime-portable, contract-first TypeScript web framework with built-in OpenAPI (Hey API), typed client generation, large-scale maintainability, and security-first defaults. Hono-grade portability, Elysia-grade DX, FastAPI-grade docs, Fastify-grade ops — distributed via pnpm.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -61,6 +61,10 @@
|
|
|
61
61
|
"./contract": {
|
|
62
62
|
"types": "./dist/contract.d.ts",
|
|
63
63
|
"import": "./dist/contract.js"
|
|
64
|
+
},
|
|
65
|
+
"./streaming": {
|
|
66
|
+
"types": "./dist/streaming.d.ts",
|
|
67
|
+
"import": "./dist/streaming.js"
|
|
64
68
|
}
|
|
65
69
|
},
|
|
66
70
|
"files": [
|