@daloyjs/core 1.0.0-beta.6 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/adapters/bun.d.ts +13 -1
- package/dist/adapters/bun.js +8 -1
- package/dist/adapters/cloudflare.d.ts +7 -1
- package/dist/adapters/cloudflare.js +6 -1
- package/dist/adapters/deno.d.ts +11 -1
- package/dist/adapters/deno.js +8 -1
- package/dist/adapters/fastly.d.ts +12 -2
- package/dist/adapters/fastly.js +12 -2
- package/dist/adapters/lambda.d.ts +37 -1
- package/dist/adapters/lambda.js +6 -1
- package/dist/adapters/node.d.ts +12 -1
- package/dist/adapters/node.js +223 -12
- package/dist/adapters/vercel.d.ts +13 -1
- package/dist/adapters/vercel.js +12 -1
- package/dist/app.d.ts +78 -17
- package/dist/app.js +444 -86
- package/dist/banner.d.ts +6 -0
- package/dist/banner.js +6 -0
- package/dist/cli.d.ts +35 -0
- package/dist/cli.js +23 -1
- package/dist/combine.d.ts +8 -0
- package/dist/combine.js +8 -0
- package/dist/compression.d.ts +3 -0
- package/dist/compression.js +3 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +4 -0
- package/dist/conn-info.d.ts +35 -2
- package/dist/conn-info.js +35 -2
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +2 -0
- package/dist/cookie.d.ts +12 -0
- package/dist/cookie.js +12 -0
- package/dist/dependency.d.ts +4 -0
- package/dist/dependency.js +3 -0
- package/dist/discriminator.d.ts +13 -0
- package/dist/discriminator.js +23 -1
- package/dist/docs.d.ts +78 -0
- package/dist/docs.js +21 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.js +14 -0
- package/dist/etag.d.ts +2 -0
- package/dist/etag.js +2 -0
- package/dist/fetch-guard.d.ts +7 -0
- package/dist/fetch-guard.js +7 -0
- package/dist/fetch-resilience.d.ts +4 -0
- package/dist/fetch-resilience.js +4 -0
- package/dist/http-signatures.d.ts +32 -0
- package/dist/http-signatures.js +30 -0
- package/dist/index.d.ts +1 -1
- package/dist/ip-restriction.d.ts +40 -3
- package/dist/ip-restriction.js +35 -3
- package/dist/jwk.d.ts +12 -1
- package/dist/jwk.js +6 -0
- package/dist/jwt.d.ts +14 -0
- package/dist/jwt.js +10 -0
- package/dist/load-shedding.d.ts +3 -0
- package/dist/load-shedding.js +3 -0
- package/dist/logger.d.ts +13 -0
- package/dist/logger.js +3 -0
- package/dist/mcp.d.ts +152 -10
- package/dist/mcp.js +223 -19
- package/dist/middleware.d.ts +68 -0
- package/dist/middleware.js +17 -0
- package/dist/mtls.d.ts +19 -2
- package/dist/mtls.js +12 -2
- package/dist/multipart.d.ts +42 -5
- package/dist/multipart.js +41 -5
- package/dist/openapi.d.ts +15 -9
- package/dist/openapi.js +6 -9
- package/dist/rate-limit-redis.d.ts +21 -2
- package/dist/rate-limit-redis.js +17 -2
- package/dist/safe-redirect.d.ts +6 -0
- package/dist/safe-redirect.js +6 -0
- package/dist/sbom.cdx.json +9 -9
- package/dist/sbom.spdx.json +5 -5
- package/dist/scheduler.d.ts +4 -0
- package/dist/schema.d.ts +25 -0
- package/dist/security-schemes.d.ts +50 -0
- package/dist/security-schemes.js +6 -0
- package/dist/security.d.ts +33 -0
- package/dist/security.js +28 -10
- package/dist/session.d.ts +34 -5
- package/dist/session.js +31 -5
- package/dist/streaming.d.ts +19 -0
- package/dist/streaming.js +16 -0
- package/dist/subdomains.d.ts +4 -0
- package/dist/subdomains.js +4 -0
- package/dist/time-claims.d.ts +22 -2
- package/dist/time-claims.js +6 -0
- package/dist/tracing.d.ts +12 -0
- package/dist/tracing.js +6 -0
- package/dist/types.d.ts +70 -1
- package/dist/waf.js +21 -1
- package/dist/webhook-delivery.d.ts +6 -0
- package/dist/webhook-delivery.js +5 -0
- package/dist/websocket.d.ts +137 -4
- package/dist/websocket.js +105 -4
- package/package.json +1 -1
package/dist/app.d.ts
CHANGED
|
@@ -51,7 +51,9 @@ export type SecurityPreset = "internal-service";
|
|
|
51
51
|
export interface AppOptions {
|
|
52
52
|
/** OpenAPI document metadata */
|
|
53
53
|
title?: string;
|
|
54
|
+
/** OpenAPI `info.version`. Falls back to the host package manifest version, then `"0.0.0"`. */
|
|
54
55
|
version?: string;
|
|
56
|
+
/** OpenAPI `info.description`. Falls back to the host package manifest description. */
|
|
55
57
|
description?: string;
|
|
56
58
|
/**
|
|
57
59
|
* Topology-aware security posture preset. See {@link SecurityPreset}.
|
|
@@ -350,9 +352,13 @@ export interface AppOptions {
|
|
|
350
352
|
* @since 0.3.0
|
|
351
353
|
*/
|
|
352
354
|
export interface AppOpenAPIOptions {
|
|
355
|
+
/** OpenAPI `info` object. `title`/`version` fall back to {@link AppOptions.title} / {@link AppOptions.version}, then the host package manifest. */
|
|
353
356
|
info?: Partial<OpenAPIInfo>;
|
|
357
|
+
/** `servers` array published in the generated document. */
|
|
354
358
|
servers?: OpenAPIOptions["servers"];
|
|
359
|
+
/** Security schemes stitched into `components.securitySchemes`. */
|
|
355
360
|
securitySchemes?: OpenAPIOptions["securitySchemes"];
|
|
361
|
+
/** OpenAPI 3.1 top-level `webhooks` operations, keyed by webhook name. */
|
|
356
362
|
webhooks?: OpenAPIOptions["webhooks"];
|
|
357
363
|
}
|
|
358
364
|
/**
|
|
@@ -684,18 +690,31 @@ export interface CspReportRouteOptions {
|
|
|
684
690
|
* @since 0.1.0
|
|
685
691
|
*/
|
|
686
692
|
export interface IntrospectedRoute {
|
|
693
|
+
/** HTTP method the route responds to (e.g. `"GET"`). */
|
|
687
694
|
method: HttpMethod;
|
|
695
|
+
/** Route path pattern as registered, including any group prefix (e.g. `/users/:id`). */
|
|
688
696
|
path: string;
|
|
697
|
+
/** OpenAPI operationId, when declared on the route. */
|
|
689
698
|
operationId?: string;
|
|
699
|
+
/** OpenAPI tags, when declared on the route or inherited from a group. */
|
|
690
700
|
tags?: string[];
|
|
701
|
+
/** One-line OpenAPI summary, when declared. */
|
|
691
702
|
summary?: string;
|
|
703
|
+
/** Longer OpenAPI description, when declared. */
|
|
692
704
|
description?: string;
|
|
705
|
+
/** `true` when the route is marked deprecated in OpenAPI. */
|
|
693
706
|
deprecated?: boolean;
|
|
707
|
+
/** Whether the route declares a request body schema. */
|
|
694
708
|
hasBody: boolean;
|
|
709
|
+
/** Whether the route declares a query-string schema. */
|
|
695
710
|
hasQuery: boolean;
|
|
711
|
+
/** Whether the route declares a path-params schema. */
|
|
696
712
|
hasParams: boolean;
|
|
713
|
+
/** Whether the route declares a request-headers schema. */
|
|
697
714
|
hasHeaders: boolean;
|
|
715
|
+
/** Declared response status codes (e.g. `[200, 404]`). */
|
|
698
716
|
responses: number[];
|
|
717
|
+
/** Security scheme name and required scopes, when the route declares `auth`. */
|
|
699
718
|
auth?: {
|
|
700
719
|
scheme: string;
|
|
701
720
|
scopes?: string[];
|
|
@@ -737,6 +756,17 @@ export declare const DALOY_REQUEST_RAW_BODY: unique symbol;
|
|
|
737
756
|
* opt in; userland code should not depend on it.
|
|
738
757
|
*/
|
|
739
758
|
export declare const DALOY_RAW_STREAM: unique symbol;
|
|
759
|
+
/**
|
|
760
|
+
* Internal Symbol an adapter sets (once, on its request shim's prototype) to
|
|
761
|
+
* declare: "the object that ultimately consumes this request's `Response`
|
|
762
|
+
* only reads `status` / `headers` / {@link DALOY_RAW_BODY} — it never needs a
|
|
763
|
+
* branded WHATWG `Response`". When present on the incoming request,
|
|
764
|
+
* {@link serializeResult} may return a {@link LightResponse} and skip the
|
|
765
|
+
* ~2µs undici `Response` construction per request. Requests without the
|
|
766
|
+
* marker (Bun / Deno / Workers adapters, tests, direct `app.fetch()` callers)
|
|
767
|
+
* always get a real `Response`, so the public contract is unchanged.
|
|
768
|
+
*/
|
|
769
|
+
export declare const DALOY_LIGHT_RESPONSE_OK: unique symbol;
|
|
740
770
|
/**
|
|
741
771
|
* Contract-first HTTP application.
|
|
742
772
|
*
|
|
@@ -799,10 +829,28 @@ export declare const DALOY_RAW_STREAM: unique symbol;
|
|
|
799
829
|
*/
|
|
800
830
|
type AppendRoute<Routes extends readonly RouteDefinition<any, any, any, any>[], R extends RouteDefinition<any, any, any, any>> = readonly RouteDefinition<any, any, any, any>[] extends Routes ? readonly [R] : readonly [...Routes, R];
|
|
801
831
|
/**
|
|
832
|
+
* The DaloyJS application: a contract-first router plus a web-standard
|
|
833
|
+
* `fetch(Request): Promise<Response>` handler that runs unchanged on Node,
|
|
834
|
+
* Bun, Deno, Cloudflare Workers, and Vercel via the adapters.
|
|
835
|
+
*
|
|
836
|
+
* Routes registered with {@link App.route} are validated against their
|
|
837
|
+
* declared schemas on the way in and out, accumulate in the typed
|
|
838
|
+
* {@link App.routes} tuple (powering OpenAPI generation and the typed
|
|
839
|
+
* client), and are served with secure defaults: body limits, request
|
|
840
|
+
* timeouts, security headers, and prod-mode error redaction.
|
|
841
|
+
*
|
|
842
|
+
* @typeParam Routes - Compile-time tuple of registered route definitions,
|
|
843
|
+
* grown by each {@link App.route} call.
|
|
802
844
|
* @since 0.1.0
|
|
803
845
|
*/
|
|
804
846
|
export declare class App<Routes extends readonly RouteDefinition<any, any, any, any>[] = readonly RouteDefinition<any, any, any, any>[]> {
|
|
847
|
+
/**
|
|
848
|
+
* Resolved constructor options. The security-relevant trio is always
|
|
849
|
+
* populated: `validateResponses` (default `true`), `bodyLimitBytes`
|
|
850
|
+
* (default 1 MiB), and `requestTimeoutMs` (default 30_000 ms).
|
|
851
|
+
*/
|
|
805
852
|
readonly options: Required<Pick<AppOptions, "validateResponses" | "bodyLimitBytes" | "requestTimeoutMs">> & AppOptions;
|
|
853
|
+
/** Structured logger for the app. Defaults to a JSON-lines console logger; override via `options.logger`. */
|
|
806
854
|
readonly log: Logger;
|
|
807
855
|
/**
|
|
808
856
|
* Public registry: enables OpenAPI gen, typed-client gen, dead-route detection.
|
|
@@ -1312,6 +1360,14 @@ export declare class App<Routes extends readonly RouteDefinition<any, any, any,
|
|
|
1312
1360
|
* @returns This `App` instance for chaining.
|
|
1313
1361
|
*/
|
|
1314
1362
|
use(hooks: Hooks): this;
|
|
1363
|
+
/**
|
|
1364
|
+
* Apply an ordered list of plugin extensions to the
|
|
1365
|
+
* group-level hook chain. Each extension's `handler` is wrapped into a
|
|
1366
|
+
* single-event {@link Hooks} bundle so subsequent route registrations
|
|
1367
|
+
* pick it up via the normal hook composition path.
|
|
1368
|
+
* @internal
|
|
1369
|
+
*/
|
|
1370
|
+
private applyExtensions;
|
|
1315
1371
|
/**
|
|
1316
1372
|
* Decorate `ctx.state` with a value available inside every handler and hook.
|
|
1317
1373
|
*
|
|
@@ -1334,16 +1390,10 @@ export declare class App<Routes extends readonly RouteDefinition<any, any, any,
|
|
|
1334
1390
|
*
|
|
1335
1391
|
* @param key - Property name on `ctx.state`.
|
|
1336
1392
|
* @param value - Value bound to that property on every request.
|
|
1393
|
+
* @param opts - Pass `{ override: true }` to replace an existing decoration (logged as a warning).
|
|
1337
1394
|
* @returns This `App` instance for chaining.
|
|
1395
|
+
* @throws Error if `key` is already decorated and `opts.override` is not `true`.
|
|
1338
1396
|
*/
|
|
1339
|
-
/**
|
|
1340
|
-
* Apply an ordered list of plugin extensions to the
|
|
1341
|
-
* group-level hook chain. Each extension's `handler` is wrapped into a
|
|
1342
|
-
* single-event {@link Hooks} bundle so subsequent route registrations
|
|
1343
|
-
* pick it up via the normal hook composition path.
|
|
1344
|
-
* @internal
|
|
1345
|
-
*/
|
|
1346
|
-
private applyExtensions;
|
|
1347
1397
|
decorate<K extends string, V>(key: K, value: V, opts?: {
|
|
1348
1398
|
override?: boolean;
|
|
1349
1399
|
}): this;
|
|
@@ -1474,13 +1524,6 @@ export declare class App<Routes extends readonly RouteDefinition<any, any, any,
|
|
|
1474
1524
|
* @returns Fulfills with the `Response` produced by the matching handler.
|
|
1475
1525
|
*/
|
|
1476
1526
|
request(input: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
1477
|
-
/**
|
|
1478
|
-
* Return a JSON-serializable summary of every registered route. Useful for
|
|
1479
|
-
* dead-route detection, dashboards, and tests that want to assert against
|
|
1480
|
-
* the route table without parsing the OpenAPI document.
|
|
1481
|
-
*
|
|
1482
|
-
* @returns Array of one {@link IntrospectedRoute} per registered route.
|
|
1483
|
-
*/
|
|
1484
1527
|
/**
|
|
1485
1528
|
* Emit a one-time development warning when any route declares a `2xx`
|
|
1486
1529
|
* response without a body schema, because response-field stripping
|
|
@@ -1490,6 +1533,13 @@ export declare class App<Routes extends readonly RouteDefinition<any, any, any,
|
|
|
1490
1533
|
* `secureDefaults: false`. See {@link findRoutesMissingResponseBodySchema}.
|
|
1491
1534
|
*/
|
|
1492
1535
|
private warnMissingResponseBodySchemas;
|
|
1536
|
+
/**
|
|
1537
|
+
* Return a JSON-serializable summary of every registered route. Useful for
|
|
1538
|
+
* dead-route detection, dashboards, and tests that want to assert against
|
|
1539
|
+
* the route table without parsing the OpenAPI document.
|
|
1540
|
+
*
|
|
1541
|
+
* @returns Array of one {@link IntrospectedRoute} per registered route.
|
|
1542
|
+
*/
|
|
1493
1543
|
introspect(): IntrospectedRoute[];
|
|
1494
1544
|
/**
|
|
1495
1545
|
* Begin graceful shutdown.
|
|
@@ -1532,6 +1582,12 @@ export declare class App<Routes extends readonly RouteDefinition<any, any, any,
|
|
|
1532
1582
|
/**
|
|
1533
1583
|
* Topological sort of plugin extensions. Refuses-at-call
|
|
1534
1584
|
* on cyclic ordering with a structured error naming the cycle.
|
|
1585
|
+
*
|
|
1586
|
+
* @param exts - Extensions to order by their `before` / `after` constraints (Kahn's algorithm).
|
|
1587
|
+
* @returns The extensions in a valid execution order.
|
|
1588
|
+
* @throws Error on duplicate extension names, on a `before`/`after` cycle
|
|
1589
|
+
* (naming the members), or when two extensions mutate the same response
|
|
1590
|
+
* header without declaring an ordering between each other.
|
|
1535
1591
|
* @internal
|
|
1536
1592
|
*/
|
|
1537
1593
|
export declare function topoSortExtensions(exts: ReadonlyArray<PluginExtension>): PluginExtension[];
|
|
@@ -1550,13 +1606,16 @@ export declare function topoSortExtensions(exts: ReadonlyArray<PluginExtension>)
|
|
|
1550
1606
|
* It powers both the `daloy doctor` `audit.response.bodySchema` finding and
|
|
1551
1607
|
* the development-mode boot warning emitted on the first request. The result
|
|
1552
1608
|
* is advisory — a route may legitimately return no body — so callers treat
|
|
1553
|
-
* it as a `warn`, never a hard error.
|
|
1609
|
+
* it as a `warn`, never a hard error. Routes that set
|
|
1610
|
+
* `acknowledgeNoResponseBodySchema: true` (including the framework-mounted
|
|
1611
|
+
* docs, AsyncAPI, health, and metrics routes, whose bodies DaloyJS itself
|
|
1612
|
+
* serializes) are skipped: the missing schema is declared intentional.
|
|
1554
1613
|
*
|
|
1555
1614
|
* @param routes - Route definitions to inspect (typically `app.routes`).
|
|
1556
1615
|
* @returns One entry per offending route with the affected `2xx` status codes.
|
|
1557
1616
|
* @since 0.40.0
|
|
1558
1617
|
*/
|
|
1559
|
-
export declare function findRoutesMissingResponseBodySchema(routes: readonly Pick<RouteDefinition<any, any, any, any>, "method" | "path" | "responses">[]): Array<{
|
|
1618
|
+
export declare function findRoutesMissingResponseBodySchema(routes: readonly Pick<RouteDefinition<any, any, any, any>, "method" | "path" | "responses" | "acknowledgeNoResponseBodySchema">[]): Array<{
|
|
1560
1619
|
method: string;
|
|
1561
1620
|
path: string;
|
|
1562
1621
|
statuses: number[];
|
|
@@ -1575,6 +1634,8 @@ export declare function findRoutesMissingResponseBodySchema(routes: readonly Pic
|
|
|
1575
1634
|
* for ergonomics and matches the factory pattern used by Express, Fastify,
|
|
1576
1635
|
* and Hono adapters.
|
|
1577
1636
|
*
|
|
1637
|
+
* @param options - Same {@link AppOptions} accepted by the `App` constructor. Default: `{}`.
|
|
1638
|
+
* @returns A new {@link App} instance.
|
|
1578
1639
|
* @since 0.3.0
|
|
1579
1640
|
*/
|
|
1580
1641
|
export declare function createApp(options?: AppOptions): App;
|