@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.
Files changed (99) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/bun.d.ts +13 -1
  3. package/dist/adapters/bun.js +8 -1
  4. package/dist/adapters/cloudflare.d.ts +7 -1
  5. package/dist/adapters/cloudflare.js +6 -1
  6. package/dist/adapters/deno.d.ts +11 -1
  7. package/dist/adapters/deno.js +8 -1
  8. package/dist/adapters/fastly.d.ts +12 -2
  9. package/dist/adapters/fastly.js +12 -2
  10. package/dist/adapters/lambda.d.ts +37 -1
  11. package/dist/adapters/lambda.js +6 -1
  12. package/dist/adapters/node.d.ts +12 -1
  13. package/dist/adapters/node.js +223 -12
  14. package/dist/adapters/vercel.d.ts +13 -1
  15. package/dist/adapters/vercel.js +12 -1
  16. package/dist/app.d.ts +78 -17
  17. package/dist/app.js +444 -86
  18. package/dist/banner.d.ts +6 -0
  19. package/dist/banner.js +6 -0
  20. package/dist/cli.d.ts +35 -0
  21. package/dist/cli.js +23 -1
  22. package/dist/combine.d.ts +8 -0
  23. package/dist/combine.js +8 -0
  24. package/dist/compression.d.ts +3 -0
  25. package/dist/compression.js +3 -0
  26. package/dist/config.d.ts +4 -0
  27. package/dist/config.js +4 -0
  28. package/dist/conn-info.d.ts +35 -2
  29. package/dist/conn-info.js +35 -2
  30. package/dist/contract.d.ts +2 -0
  31. package/dist/contract.js +2 -0
  32. package/dist/cookie.d.ts +12 -0
  33. package/dist/cookie.js +12 -0
  34. package/dist/dependency.d.ts +4 -0
  35. package/dist/dependency.js +3 -0
  36. package/dist/discriminator.d.ts +13 -0
  37. package/dist/discriminator.js +23 -1
  38. package/dist/docs.d.ts +78 -0
  39. package/dist/docs.js +21 -0
  40. package/dist/errors.d.ts +16 -0
  41. package/dist/errors.js +14 -0
  42. package/dist/etag.d.ts +2 -0
  43. package/dist/etag.js +2 -0
  44. package/dist/fetch-guard.d.ts +7 -0
  45. package/dist/fetch-guard.js +7 -0
  46. package/dist/fetch-resilience.d.ts +4 -0
  47. package/dist/fetch-resilience.js +4 -0
  48. package/dist/http-signatures.d.ts +32 -0
  49. package/dist/http-signatures.js +30 -0
  50. package/dist/index.d.ts +1 -1
  51. package/dist/ip-restriction.d.ts +40 -3
  52. package/dist/ip-restriction.js +35 -3
  53. package/dist/jwk.d.ts +12 -1
  54. package/dist/jwk.js +6 -0
  55. package/dist/jwt.d.ts +14 -0
  56. package/dist/jwt.js +10 -0
  57. package/dist/load-shedding.d.ts +3 -0
  58. package/dist/load-shedding.js +3 -0
  59. package/dist/logger.d.ts +13 -0
  60. package/dist/logger.js +3 -0
  61. package/dist/mcp.d.ts +152 -10
  62. package/dist/mcp.js +223 -19
  63. package/dist/middleware.d.ts +68 -0
  64. package/dist/middleware.js +17 -0
  65. package/dist/mtls.d.ts +19 -2
  66. package/dist/mtls.js +12 -2
  67. package/dist/multipart.d.ts +42 -5
  68. package/dist/multipart.js +41 -5
  69. package/dist/openapi.d.ts +15 -9
  70. package/dist/openapi.js +6 -9
  71. package/dist/rate-limit-redis.d.ts +21 -2
  72. package/dist/rate-limit-redis.js +17 -2
  73. package/dist/safe-redirect.d.ts +6 -0
  74. package/dist/safe-redirect.js +6 -0
  75. package/dist/sbom.cdx.json +9 -9
  76. package/dist/sbom.spdx.json +5 -5
  77. package/dist/scheduler.d.ts +4 -0
  78. package/dist/schema.d.ts +25 -0
  79. package/dist/security-schemes.d.ts +50 -0
  80. package/dist/security-schemes.js +6 -0
  81. package/dist/security.d.ts +33 -0
  82. package/dist/security.js +28 -10
  83. package/dist/session.d.ts +34 -5
  84. package/dist/session.js +31 -5
  85. package/dist/streaming.d.ts +19 -0
  86. package/dist/streaming.js +16 -0
  87. package/dist/subdomains.d.ts +4 -0
  88. package/dist/subdomains.js +4 -0
  89. package/dist/time-claims.d.ts +22 -2
  90. package/dist/time-claims.js +6 -0
  91. package/dist/tracing.d.ts +12 -0
  92. package/dist/tracing.js +6 -0
  93. package/dist/types.d.ts +70 -1
  94. package/dist/waf.js +21 -1
  95. package/dist/webhook-delivery.d.ts +6 -0
  96. package/dist/webhook-delivery.js +5 -0
  97. package/dist/websocket.d.ts +137 -4
  98. package/dist/websocket.js +105 -4
  99. package/package.json +1 -1
package/dist/banner.d.ts CHANGED
@@ -30,10 +30,16 @@ export interface StartupBannerOptions {
30
30
  /**
31
31
  * Build the multi-line startup banner string without printing it. Useful for
32
32
  * tests, custom loggers, or wrapping the output in additional context.
33
+ *
34
+ * @param options Banner content and rendering flags ({@link StartupBannerOptions}).
35
+ * @returns The framed banner as a single string with `\n` line separators.
33
36
  */
34
37
  export declare function formatStartupBanner(options: StartupBannerOptions): string;
35
38
  /**
36
39
  * Print {@link formatStartupBanner} to stdout (or a custom writer). Designed to
37
40
  * replace ad-hoc `console.log("listening on …")` calls in starter templates.
41
+ *
42
+ * @param options Banner content and rendering flags ({@link StartupBannerOptions}).
43
+ * @param write Output sink for the banner text. Defaults to `process.stdout.write`.
38
44
  */
39
45
  export declare function printStartupBanner(options: StartupBannerOptions, write?: (s: string) => void): void;
package/dist/banner.js CHANGED
@@ -86,6 +86,9 @@ function visibleWidth(s) {
86
86
  /**
87
87
  * Build the multi-line startup banner string without printing it. Useful for
88
88
  * tests, custom loggers, or wrapping the output in additional context.
89
+ *
90
+ * @param options Banner content and rendering flags ({@link StartupBannerOptions}).
91
+ * @returns The framed banner as a single string with `\n` line separators.
89
92
  */
90
93
  export function formatStartupBanner(options) {
91
94
  const useColor = options.color ?? detectColor();
@@ -126,6 +129,9 @@ export function formatStartupBanner(options) {
126
129
  /**
127
130
  * Print {@link formatStartupBanner} to stdout (or a custom writer). Designed to
128
131
  * replace ad-hoc `console.log("listening on …")` calls in starter templates.
132
+ *
133
+ * @param options Banner content and rendering flags ({@link StartupBannerOptions}).
134
+ * @param write Output sink for the banner text. Defaults to `process.stdout.write`.
129
135
  */
130
136
  export function printStartupBanner(options, write = (s) => process.stdout.write(s)) {
131
137
  write(`\n${formatStartupBanner(options)}\n\n`);
package/dist/cli.d.ts CHANGED
@@ -12,7 +12,9 @@
12
12
  import type { App } from "./app.js";
13
13
  /** I/O hooks used by {@link runCli} to read modules, write output, and spawn child processes. */
14
14
  export interface CliIO {
15
+ /** Write a chunk to standard output (tables, JSON/YAML dumps). */
15
16
  stdout: (chunk: string) => void;
17
+ /** Write a chunk to standard error (usage errors, diagnostics). */
16
18
  stderr: (chunk: string) => void;
17
19
  /** Resolve a user-provided entry specifier to a module to import. */
18
20
  importEntry: (specifier: string) => Promise<unknown>;
@@ -37,15 +39,22 @@ export interface CliIO {
37
39
  }
38
40
  /** Return value of {@link runCli}. The caller wires `exitCode` into `process.exit(...)`. */
39
41
  export interface CliResult {
42
+ /** Process exit code: `0` on success, `1` on load failures or failed checks, `2` on usage errors. */
40
43
  exitCode: number;
41
44
  }
42
45
  /** Parsed CLI flags accepted by {@link runCli}. See {@link parseArgs}. */
43
46
  export interface CliOptions {
47
+ /** `--json`: print machine-readable JSON instead of a table. */
44
48
  json: boolean;
49
+ /** `--check`: run the contract test suite; exit 1 on errors. */
45
50
  check: boolean;
51
+ /** `--schemas`: include per-route schema presence (body/query/params/headers). */
46
52
  schemas: boolean;
53
+ /** `--openapi`: print the App's OpenAPI 3.1 document. */
47
54
  openapi: boolean;
55
+ /** `--asyncapi`: print the AsyncAPI 3.0 document for the App's WebSocket surfaces. */
48
56
  asyncapi: boolean;
57
+ /** `--ai`: print the AI/codegen-friendly route-catalog dump ({@link buildAiDump}). */
49
58
  ai: boolean;
50
59
  /**
51
60
  * Output format for `--ai` and `--openapi`. Defaults to `"json"`.
@@ -56,10 +65,15 @@ export interface CliOptions {
56
65
  * @since 0.14.2
57
66
  */
58
67
  format?: "json" | "yaml";
68
+ /** `--tag <tag>`: only show routes that declare this tag. */
59
69
  tag?: string;
70
+ /** `--method <method>`: only show routes for this HTTP method (uppercased by {@link parseArgs}). */
60
71
  method?: string;
72
+ /** Entry file to load the App from (last positional argument). */
61
73
  entry?: string;
74
+ /** `-h` / `--help`: print usage and exit 0. */
62
75
  help: boolean;
76
+ /** `-v` / `--version`: print the CLI version and exit 0. */
63
77
  version: boolean;
64
78
  /** Override runtime detection for `daloy dev`. */
65
79
  runtime?: DevRuntime;
@@ -76,6 +90,7 @@ export type DevRuntime = "node" | "bun" | "deno";
76
90
  * Detect which JS runtime is hosting the CLI. Inspects
77
91
  * `globalThis.process.versions` for Bun/Deno markers; falls back to Node.
78
92
  *
93
+ * @returns `"bun"`, `"deno"`, or `"node"` (the default when no marker is found).
79
94
  * @since 0.3.0
80
95
  */
81
96
  export declare function detectRuntime(): DevRuntime;
@@ -92,6 +107,9 @@ export declare function detectRuntime(): DevRuntime;
92
107
  * `runCli()` callers and tests so the invariant holds regardless of how the
93
108
  * entry value was produced.
94
109
  *
110
+ * @param entry - Entry path to validate.
111
+ * @param context - Label prefixed to error messages (e.g. `"daloy dev"`).
112
+ * @throws Error when the path is empty, contains NUL/CR/LF, or starts with `-`.
95
113
  * @internal
96
114
  */
97
115
  export declare function assertSafeEntryPath(entry: string, context: string): void;
@@ -102,6 +120,8 @@ export declare function assertSafeEntryPath(entry: string, context: string): voi
102
120
  * paths like `src/server.ts` are rewritten to `./src/server.ts`. This is
103
121
  * the second half of the {@link assertSafeEntryPath} defense.
104
122
  *
123
+ * @param entry - Entry path to anchor.
124
+ * @returns The path unchanged if already absolute or `./`/`../`-anchored (Windows drive paths included); otherwise `./` + path.
105
125
  * @internal
106
126
  */
107
127
  export declare function normalizeEntryArg(entry: string): string;
@@ -124,6 +144,10 @@ export declare function normalizeEntryArg(entry: string): string;
124
144
  * `SECURITY.md` § "CLI threat model" for the full rationale (and why we
125
145
  * are not vulnerable to the class of bug Snyk reported as CVE-2022-22984).
126
146
  *
147
+ * @param runtime - Host runtime to build the command for.
148
+ * @param entry - Entry file to run; validated and `./`-anchored before use.
149
+ * @returns The executable name and argv array to pass to `spawn({ shell: false })`.
150
+ * @throws Error via {@link assertSafeEntryPath} when the entry path is unsafe.
127
151
  * @since 0.3.0
128
152
  */
129
153
  export declare function buildDevCommand(runtime: DevRuntime, entry: string): {
@@ -133,6 +157,10 @@ export declare function buildDevCommand(runtime: DevRuntime, entry: string): {
133
157
  /**
134
158
  * Parse a process-style argv (without the `node`/`daloy` prefix) into a
135
159
  * `{ command, opts }` pair. Throws on unknown flags or invalid enum values.
160
+ *
161
+ * @param argv - Arguments after the binary name, e.g. `["inspect", "--json", "./src/server.ts"]`.
162
+ * @returns The resolved command (default `"inspect"`) and parsed {@link CliOptions}.
163
+ * @throws Error on unknown `-`-prefixed flags, missing flag values, or invalid `--format`/`--runtime` values.
136
164
  */
137
165
  export declare function parseArgs(argv: readonly string[]): {
138
166
  command: string;
@@ -142,6 +170,10 @@ export declare function parseArgs(argv: readonly string[]): {
142
170
  * Execute the CLI against the supplied argv and {@link CliIO}. Does not read
143
171
  * `process.argv`, write to process stdio, or call `process.exit()` directly,
144
172
  * so tests can drive `inspect`/`dev`/`doctor` with in-memory stdio.
173
+ *
174
+ * @param argv - Process-style arguments (without the `node`/`daloy` prefix); see {@link parseArgs}.
175
+ * @param io - I/O hooks for stdout/stderr, module import, spawning, and file reads.
176
+ * @returns A {@link CliResult} whose `exitCode` the caller feeds to `process.exit()`.
145
177
  */
146
178
  export declare function runCli(argv: readonly string[], io: CliIO): Promise<CliResult>;
147
179
  /**
@@ -151,6 +183,9 @@ export declare function runCli(argv: readonly string[], io: CliIO): Promise<CliR
151
183
  * stable and self-describing so LLMs and SDK builders can consume it
152
184
  * without round-tripping through OpenAPI.
153
185
  *
186
+ * @param app - Loaded App whose route registry is dumped.
187
+ * @param opts - Parsed CLI options; `--tag` / `--method` filter the catalog.
188
+ * @returns JSON-serializable dump with `daloy.ai` version marker, `generatedAt`, and the `routes` array.
154
189
  * @since 0.14.0
155
190
  */
156
191
  export declare function buildAiDump(app: App, opts: CliOptions): Record<string, unknown>;
package/dist/cli.js CHANGED
@@ -118,6 +118,7 @@ const DEFAULT_DEV_ENTRIES = [
118
118
  * Detect which JS runtime is hosting the CLI. Inspects
119
119
  * `globalThis.process.versions` for Bun/Deno markers; falls back to Node.
120
120
  *
121
+ * @returns `"bun"`, `"deno"`, or `"node"` (the default when no marker is found).
121
122
  * @since 0.3.0
122
123
  */
123
124
  export function detectRuntime() {
@@ -142,6 +143,9 @@ export function detectRuntime() {
142
143
  * `runCli()` callers and tests so the invariant holds regardless of how the
143
144
  * entry value was produced.
144
145
  *
146
+ * @param entry - Entry path to validate.
147
+ * @param context - Label prefixed to error messages (e.g. `"daloy dev"`).
148
+ * @throws Error when the path is empty, contains NUL/CR/LF, or starts with `-`.
145
149
  * @internal
146
150
  */
147
151
  export function assertSafeEntryPath(entry, context) {
@@ -163,6 +167,8 @@ export function assertSafeEntryPath(entry, context) {
163
167
  * paths like `src/server.ts` are rewritten to `./src/server.ts`. This is
164
168
  * the second half of the {@link assertSafeEntryPath} defense.
165
169
  *
170
+ * @param entry - Entry path to anchor.
171
+ * @returns The path unchanged if already absolute or `./`/`../`-anchored (Windows drive paths included); otherwise `./` + path.
166
172
  * @internal
167
173
  */
168
174
  export function normalizeEntryArg(entry) {
@@ -194,6 +200,10 @@ export function normalizeEntryArg(entry) {
194
200
  * `SECURITY.md` § "CLI threat model" for the full rationale (and why we
195
201
  * are not vulnerable to the class of bug Snyk reported as CVE-2022-22984).
196
202
  *
203
+ * @param runtime - Host runtime to build the command for.
204
+ * @param entry - Entry file to run; validated and `./`-anchored before use.
205
+ * @returns The executable name and argv array to pass to `spawn({ shell: false })`.
206
+ * @throws Error via {@link assertSafeEntryPath} when the entry path is unsafe.
197
207
  * @since 0.3.0
198
208
  */
199
209
  export function buildDevCommand(runtime, entry) {
@@ -242,6 +252,10 @@ async function resolveDevEntry(entry) {
242
252
  /**
243
253
  * Parse a process-style argv (without the `node`/`daloy` prefix) into a
244
254
  * `{ command, opts }` pair. Throws on unknown flags or invalid enum values.
255
+ *
256
+ * @param argv - Arguments after the binary name, e.g. `["inspect", "--json", "./src/server.ts"]`.
257
+ * @returns The resolved command (default `"inspect"`) and parsed {@link CliOptions}.
258
+ * @throws Error on unknown `-`-prefixed flags, missing flag values, or invalid `--format`/`--runtime` values.
245
259
  */
246
260
  export function parseArgs(argv) {
247
261
  const opts = {
@@ -343,6 +357,10 @@ function readFlagValue(argv, index, flag) {
343
357
  * Execute the CLI against the supplied argv and {@link CliIO}. Does not read
344
358
  * `process.argv`, write to process stdio, or call `process.exit()` directly,
345
359
  * so tests can drive `inspect`/`dev`/`doctor` with in-memory stdio.
360
+ *
361
+ * @param argv - Process-style arguments (without the `node`/`daloy` prefix); see {@link parseArgs}.
362
+ * @param io - I/O hooks for stdout/stderr, module import, spawning, and file reads.
363
+ * @returns A {@link CliResult} whose `exitCode` the caller feeds to `process.exit()`.
346
364
  */
347
365
  export async function runCli(argv, io) {
348
366
  let parsed;
@@ -750,7 +768,8 @@ async function runDoctor(opts, io) {
750
768
  message: `${missingBody.length} route(s) declare a 2xx response with no body schema, so ` +
751
769
  `response field-level stripping (OWASP API3) is not applied: ${sample}` +
752
770
  `${missingBody.length > 5 ? ", …" : ""}. Declare a response body schema so undeclared ` +
753
- "handler fields cannot leak, or ignore if the route intentionally returns no body.",
771
+ "handler fields cannot leak, or set `acknowledgeNoResponseBodySchema: true` on routes " +
772
+ "that intentionally return an opaque or body-less response.",
754
773
  });
755
774
  }
756
775
  }
@@ -826,6 +845,9 @@ async function runDev(opts, io) {
826
845
  * stable and self-describing so LLMs and SDK builders can consume it
827
846
  * without round-tripping through OpenAPI.
828
847
  *
848
+ * @param app - Loaded App whose route registry is dumped.
849
+ * @param opts - Parsed CLI options; `--tag` / `--method` filter the catalog.
850
+ * @returns JSON-serializable dump with `daloy.ai` version marker, `generatedAt`, and the `routes` array.
829
851
  * @since 0.14.0
830
852
  */
831
853
  export function buildAiDump(app, opts) {
package/dist/combine.d.ts CHANGED
@@ -29,6 +29,8 @@ import type { Hooks, BaseContext } from "./types.js";
29
29
  * app.use(adminStack);
30
30
  * ```
31
31
  *
32
+ * @param layers Hook bundles to compose, executed in the order given.
33
+ * @returns A single merged {@link Hooks} bundle preserving all lifecycle phases.
32
34
  * @since 0.19.0
33
35
  */
34
36
  export declare function every(...layers: Hooks[]): Hooks;
@@ -61,6 +63,8 @@ export declare function every(...layers: Hooks[]): Hooks;
61
63
  * ));
62
64
  * ```
63
65
  *
66
+ * @param layers Candidate hook bundles; the first `beforeHandle` that passes wins.
67
+ * @returns A merged {@link Hooks} bundle with the OR-style `beforeHandle` strategy.
64
68
  * @since 0.19.0
65
69
  */
66
70
  export declare function some(...layers: Hooks[]): Hooks;
@@ -91,6 +95,10 @@ export type ExceptPredicate = string | string[] | ((ctx: BaseContext<any, any>)
91
95
  * exempted. Wrap each bundle with {@link except} individually when you
92
96
  * need to gate other phases.
93
97
  *
98
+ * @param when Paths or predicate ({@link ExceptPredicate}) that exempt a request.
99
+ * @param hooks The hook bundle whose `beforeHandle` is skipped on a match.
100
+ * @returns A {@link Hooks} bundle whose `beforeHandle` is gated by `when`.
101
+ * @throws Error at composition time if a string pattern does not start with `/`.
94
102
  * @since 0.19.0
95
103
  */
96
104
  export declare function except(when: ExceptPredicate, hooks: Hooks): Hooks;
package/dist/combine.js CHANGED
@@ -28,6 +28,8 @@
28
28
  * app.use(adminStack);
29
29
  * ```
30
30
  *
31
+ * @param layers Hook bundles to compose, executed in the order given.
32
+ * @returns A single merged {@link Hooks} bundle preserving all lifecycle phases.
31
33
  * @since 0.19.0
32
34
  */
33
35
  export function every(...layers) {
@@ -62,6 +64,8 @@ export function every(...layers) {
62
64
  * ));
63
65
  * ```
64
66
  *
67
+ * @param layers Candidate hook bundles; the first `beforeHandle` that passes wins.
68
+ * @returns A merged {@link Hooks} bundle with the OR-style `beforeHandle` strategy.
65
69
  * @since 0.19.0
66
70
  */
67
71
  export function some(...layers) {
@@ -119,6 +123,10 @@ export function some(...layers) {
119
123
  * exempted. Wrap each bundle with {@link except} individually when you
120
124
  * need to gate other phases.
121
125
  *
126
+ * @param when Paths or predicate ({@link ExceptPredicate}) that exempt a request.
127
+ * @param hooks The hook bundle whose `beforeHandle` is skipped on a match.
128
+ * @returns A {@link Hooks} bundle whose `beforeHandle` is gated by `when`.
129
+ * @throws Error at composition time if a string pattern does not start with `/`.
122
130
  * @since 0.19.0
123
131
  */
124
132
  export function except(when, hooks) {
@@ -121,6 +121,9 @@ export declare function _resetCompressionRuntimeProbeForTests(): void;
121
121
  * app.use(compression());
122
122
  * ```
123
123
  *
124
+ * @param opts Compression tuning ({@link CompressionOptions}); `minimumSize` defaults to `1024` bytes.
125
+ * @returns A {@link Hooks} bundle whose `onSend` compresses eligible response bodies.
126
+ * @throws TypeError if `compressLevel` is passed or `minimumSize` is not a finite non-negative integer.
124
127
  * @since 0.25.0
125
128
  */
126
129
  export declare function compression(opts?: CompressionOptions): Hooks;
@@ -281,6 +281,9 @@ async function compressBytes(bytes, encoding) {
281
281
  * app.use(compression());
282
282
  * ```
283
283
  *
284
+ * @param opts Compression tuning ({@link CompressionOptions}); `minimumSize` defaults to `1024` bytes.
285
+ * @returns A {@link Hooks} bundle whose `onSend` compresses eligible response bodies.
286
+ * @throws TypeError if `compressLevel` is passed or `minimumSize` is not a finite non-negative integer.
284
287
  * @since 0.25.0
285
288
  */
286
289
  export function compression(opts = {}) {
package/dist/config.d.ts CHANGED
@@ -21,6 +21,7 @@ import { type StandardSchemaV1 } from "./schema.js";
21
21
  * dashboard, a startup probe, or a custom error renderer.
22
22
  */
23
23
  export declare class ConfigValidationError extends Error {
24
+ /** Every validation issue, as `{ key, message }` pairs (`key` is the dotted path, `"<root>"`/`"<source>"` for top-level failures). */
24
25
  readonly issues: ReadonlyArray<{
25
26
  key: string;
26
27
  message: string;
@@ -92,6 +93,9 @@ export interface DefineConfigOptions<S extends StandardSchemaV1> {
92
93
  * export const config = await defineConfig({ schema: Config });
93
94
  * ```
94
95
  *
96
+ * @param opts - Schema, source (default `"env"`), optional `transform`, and the stderr sink.
97
+ * @returns The validated, typed configuration object.
98
+ * @throws {ConfigValidationError} When the source cannot be read or the schema reports issues.
95
99
  * @since 0.20.0
96
100
  */
97
101
  export declare function defineConfig<S extends StandardSchemaV1>(opts: DefineConfigOptions<S>): Promise<StandardSchemaV1.InferOutput<S>>;
package/dist/config.js CHANGED
@@ -21,6 +21,7 @@ import { validate } from "./schema.js";
21
21
  * dashboard, a startup probe, or a custom error renderer.
22
22
  */
23
23
  export class ConfigValidationError extends Error {
24
+ /** Every validation issue, as `{ key, message }` pairs (`key` is the dotted path, `"<root>"`/`"<source>"` for top-level failures). */
24
25
  issues;
25
26
  constructor(issues) {
26
27
  const summary = issues
@@ -90,6 +91,9 @@ function pathToKey(path) {
90
91
  * export const config = await defineConfig({ schema: Config });
91
92
  * ```
92
93
  *
94
+ * @param opts - Schema, source (default `"env"`), optional `transform`, and the stderr sink.
95
+ * @returns The validated, typed configuration object.
96
+ * @throws {ConfigValidationError} When the source cannot be read or the schema reports issues.
93
97
  * @since 0.20.0
94
98
  */
95
99
  export async function defineConfig(opts) {
@@ -69,6 +69,9 @@ interface MutableConnInfo {
69
69
  * @internal Adapter helper — attach {@link ConnInfo} to a `Request`. Called
70
70
  * by the Node / Bun / Deno / Cloudflare / Vercel / Lambda adapters before
71
71
  * `app.fetch(request)`.
72
+ *
73
+ * @param request - Incoming request to tag (stored under a private symbol).
74
+ * @param info - Connection metadata gathered by the adapter.
72
75
  */
73
76
  export declare function setConnInfo(request: Request, info: ConnInfo): void;
74
77
  /**
@@ -76,6 +79,8 @@ export declare function setConnInfo(request: Request, info: ConnInfo): void;
76
79
  * `undefined` when the adapter does not expose connection metadata (e.g.
77
80
  * Cloudflare Workers without `cf` enabled).
78
81
  *
82
+ * @param request - Request previously tagged by {@link setConnInfo}.
83
+ * @returns The attached {@link ConnInfo}, or `undefined` when absent.
79
84
  * @since 0.24.0
80
85
  */
81
86
  export declare function getConnInfo(request: Request): ConnInfo | undefined;
@@ -83,6 +88,9 @@ export declare function getConnInfo(request: Request): ConnInfo | undefined;
83
88
  * Refuses-at-construction on malformed {@link BehindProxyConfig}. Called once
84
89
  * during `new App({ behindProxy })`.
85
90
  *
91
+ * @param cfg - Proxy posture to validate; `undefined` is accepted as "unset".
92
+ * @throws Error when `hops` is not an integer in [0, 64], when `cidrs` is
93
+ * empty or contains non-string entries, or when the shape is unrecognized.
86
94
  * @since 0.24.0
87
95
  */
88
96
  export declare function assertBehindProxy(cfg: BehindProxyConfig | undefined): void;
@@ -93,6 +101,10 @@ export declare function assertBehindProxy(cfg: BehindProxyConfig | undefined): v
93
101
  * `undefined` when the header is shorter than the configured hop count
94
102
  * (caller falls back to the immediate peer).
95
103
  *
104
+ * @param header - Raw `X-Forwarded-For` header value, or `null` when absent.
105
+ * @param hops - Declared number of trusted proxy hops (must be >= 1).
106
+ * @returns The client IP at the declared hop, or `undefined` when the chain
107
+ * is too short or `hops < 1`.
96
108
  * @internal
97
109
  */
98
110
  export declare function pickForwardedForByHops(header: string | null, hops: number): string | undefined;
@@ -102,6 +114,10 @@ export declare function pickForwardedForByHops(header: string | null, hops: numb
102
114
  * available (the caller — rate-limit, ipRestriction, audit-log — must fail
103
115
  * closed rather than guess).
104
116
  *
117
+ * @param request - Incoming request whose client IP should be resolved.
118
+ * @param cfg - The app's `behindProxy` posture; `undefined` behaves as `"none"`.
119
+ * @returns The trusted client IP, or `undefined` when neither the peer
120
+ * address nor a trusted `X-Forwarded-For` slot is available.
105
121
  * @since 0.24.0
106
122
  */
107
123
  export declare function resolveClientIp(request: Request, cfg: BehindProxyConfig | undefined): string | undefined;
@@ -110,11 +126,28 @@ export declare function resolveClientIp(request: Request, cfg: BehindProxyConfig
110
126
  * `undefined` rather than allocating a plain object so the IP cannot be
111
127
  * serialized into logs by accident.
112
128
  *
129
+ * @param ctx - Request context whose adapter-attached {@link ConnInfo} is read.
130
+ * @returns The immediate peer address, or `undefined` when the adapter did
131
+ * not attach connection metadata.
113
132
  * @since 0.24.0
114
133
  */
115
134
  export declare function readRemoteAddress(ctx: BaseContext<any, any>): string | undefined;
116
- /** @since 0.24.0 */
135
+ /**
136
+ * Lazy accessor for `ctx.remotePort` (the immediate peer's TCP port).
137
+ *
138
+ * @param ctx - Request context whose adapter-attached {@link ConnInfo} is read.
139
+ * @returns The immediate peer port, or `undefined` when the adapter did not
140
+ * attach connection metadata.
141
+ * @since 0.24.0
142
+ */
117
143
  export declare function readRemotePort(ctx: BaseContext<any, any>): number | undefined;
118
- /** @internal Test-only helper. */
144
+ /**
145
+ * Test-only helper that shallow-copies a {@link ConnInfo} into a mutable shape
146
+ * so tests can tweak fields without casting away `readonly`.
147
+ *
148
+ * @param info - Connection metadata to copy.
149
+ * @returns A mutable shallow copy of `info`.
150
+ * @internal
151
+ */
119
152
  export declare function _makeConnInfoForTests(info: ConnInfo): MutableConnInfo;
120
153
  export {};
package/dist/conn-info.js CHANGED
@@ -23,6 +23,9 @@ const CONN_INFO_SYMBOL = Symbol.for("daloyjs.connInfo");
23
23
  * @internal Adapter helper — attach {@link ConnInfo} to a `Request`. Called
24
24
  * by the Node / Bun / Deno / Cloudflare / Vercel / Lambda adapters before
25
25
  * `app.fetch(request)`.
26
+ *
27
+ * @param request - Incoming request to tag (stored under a private symbol).
28
+ * @param info - Connection metadata gathered by the adapter.
26
29
  */
27
30
  export function setConnInfo(request, info) {
28
31
  request[CONN_INFO_SYMBOL] = info;
@@ -32,6 +35,8 @@ export function setConnInfo(request, info) {
32
35
  * `undefined` when the adapter does not expose connection metadata (e.g.
33
36
  * Cloudflare Workers without `cf` enabled).
34
37
  *
38
+ * @param request - Request previously tagged by {@link setConnInfo}.
39
+ * @returns The attached {@link ConnInfo}, or `undefined` when absent.
35
40
  * @since 0.24.0
36
41
  */
37
42
  export function getConnInfo(request) {
@@ -41,6 +46,9 @@ export function getConnInfo(request) {
41
46
  * Refuses-at-construction on malformed {@link BehindProxyConfig}. Called once
42
47
  * during `new App({ behindProxy })`.
43
48
  *
49
+ * @param cfg - Proxy posture to validate; `undefined` is accepted as "unset".
50
+ * @throws Error when `hops` is not an integer in [0, 64], when `cidrs` is
51
+ * empty or contains non-string entries, or when the shape is unrecognized.
44
52
  * @since 0.24.0
45
53
  */
46
54
  export function assertBehindProxy(cfg) {
@@ -76,6 +84,10 @@ export function assertBehindProxy(cfg) {
76
84
  * `undefined` when the header is shorter than the configured hop count
77
85
  * (caller falls back to the immediate peer).
78
86
  *
87
+ * @param header - Raw `X-Forwarded-For` header value, or `null` when absent.
88
+ * @param hops - Declared number of trusted proxy hops (must be >= 1).
89
+ * @returns The client IP at the declared hop, or `undefined` when the chain
90
+ * is too short or `hops < 1`.
79
91
  * @internal
80
92
  */
81
93
  export function pickForwardedForByHops(header, hops) {
@@ -97,6 +109,10 @@ export function pickForwardedForByHops(header, hops) {
97
109
  * available (the caller — rate-limit, ipRestriction, audit-log — must fail
98
110
  * closed rather than guess).
99
111
  *
112
+ * @param request - Incoming request whose client IP should be resolved.
113
+ * @param cfg - The app's `behindProxy` posture; `undefined` behaves as `"none"`.
114
+ * @returns The trusted client IP, or `undefined` when neither the peer
115
+ * address nor a trusted `X-Forwarded-For` slot is available.
100
116
  * @since 0.24.0
101
117
  */
102
118
  export function resolveClientIp(request, cfg) {
@@ -129,16 +145,33 @@ export function resolveClientIp(request, cfg) {
129
145
  * `undefined` rather than allocating a plain object so the IP cannot be
130
146
  * serialized into logs by accident.
131
147
  *
148
+ * @param ctx - Request context whose adapter-attached {@link ConnInfo} is read.
149
+ * @returns The immediate peer address, or `undefined` when the adapter did
150
+ * not attach connection metadata.
132
151
  * @since 0.24.0
133
152
  */
134
153
  export function readRemoteAddress(ctx) {
135
154
  return getConnInfo(ctx.request)?.remoteAddress;
136
155
  }
137
- /** @since 0.24.0 */
156
+ /**
157
+ * Lazy accessor for `ctx.remotePort` (the immediate peer's TCP port).
158
+ *
159
+ * @param ctx - Request context whose adapter-attached {@link ConnInfo} is read.
160
+ * @returns The immediate peer port, or `undefined` when the adapter did not
161
+ * attach connection metadata.
162
+ * @since 0.24.0
163
+ */
138
164
  export function readRemotePort(ctx) {
139
165
  return getConnInfo(ctx.request)?.remotePort;
140
166
  }
141
- /** @internal Test-only helper. */
167
+ /**
168
+ * Test-only helper that shallow-copies a {@link ConnInfo} into a mutable shape
169
+ * so tests can tweak fields without casting away `readonly`.
170
+ *
171
+ * @param info - Connection metadata to copy.
172
+ * @returns A mutable shallow copy of `info`.
173
+ * @internal
174
+ */
142
175
  export function _makeConnInfoForTests(info) {
143
176
  return { ...info };
144
177
  }
@@ -44,6 +44,8 @@ export interface ContractTestOptions {
44
44
  * routes don't carry body schemas by accident, and that `meta.examples`
45
45
  * reference declared response statuses.
46
46
  *
47
+ * @param app The {@link App} whose registered routes are inspected.
48
+ * @param opts Check toggles ({@link ContractTestOptions}); `requireOperationId` defaults to `true`.
47
49
  * @returns A {@link ContractReport}. In CI, exit non-zero when `report.ok` is `false`.
48
50
  */
49
51
  export declare function runContractTests(app: App, opts?: ContractTestOptions): Promise<ContractReport>;
package/dist/contract.js CHANGED
@@ -19,6 +19,8 @@ import { validate } from "./schema.js";
19
19
  * routes don't carry body schemas by accident, and that `meta.examples`
20
20
  * reference declared response statuses.
21
21
  *
22
+ * @param app The {@link App} whose registered routes are inspected.
23
+ * @param opts Check toggles ({@link ContractTestOptions}); `requireOperationId` defaults to `true`.
22
24
  * @returns A {@link ContractReport}. In CI, exit non-zero when `report.ok` is `false`.
23
25
  */
24
26
  export async function runContractTests(app, opts = {}) {
package/dist/cookie.d.ts CHANGED
@@ -84,6 +84,11 @@ export declare function assertCookieAttributes(input: {
84
84
  * The value is URI-encoded so binary signature bytes and base64 padding
85
85
  * round-trip safely.
86
86
  *
87
+ * @param name Cookie name; `__Host-`/`__Secure-` prefixes are enforced by validation.
88
+ * @param value Cookie value; URI-encoded before serialization.
89
+ * @param attributes Cookie attributes. Defaults: `SameSite=Strict`, `Secure`, `HttpOnly`, `Path=/`.
90
+ * @returns A single `Set-Cookie` header value.
91
+ * @throws Error if the name or attributes fail {@link assertCookieAttributes} validation.
87
92
  * @since 0.27.0
88
93
  */
89
94
  export declare function serializeCookie(name: string, value: string, attributes?: CookieAttributes): string;
@@ -92,6 +97,10 @@ export declare function serializeCookie(name: string, value: string, attributes?
92
97
  * `Max-Age=0` per RFC 6265 §5.2.2 and preserves the original attributes so
93
98
  * intermediaries match the original cookie when deciding what to delete.
94
99
  *
100
+ * @param name Name of the cookie to clear.
101
+ * @param attributes Attributes of the original cookie; must match for deletion to apply.
102
+ * @returns A `Set-Cookie` header value with an empty value and `Max-Age=0`.
103
+ * @throws Error if the name or attributes fail {@link assertCookieAttributes} validation.
95
104
  * @since 0.27.0
96
105
  */
97
106
  export declare function serializeClearCookie(name: string, attributes?: CookieAttributes): string;
@@ -118,6 +127,9 @@ export declare function serializeClearCookie(name: string, attributes?: CookieAt
118
127
  * parser-level guard is defense-in-depth for developers who customize the
119
128
  * cookie name or read other cookies through this helper.
120
129
  *
130
+ * @param header The raw `Cookie` request header, or `null`/`undefined` when absent.
131
+ * @param name Exact cookie name to read (case-sensitive).
132
+ * @returns The decoded cookie value, or `null` when absent or duplicated.
121
133
  * @since 0.27.0
122
134
  */
123
135
  export declare function readRequestCookie(header: string | null | undefined, name: string): string | null;
package/dist/cookie.js CHANGED
@@ -96,6 +96,11 @@ export function assertCookieAttributes(input) {
96
96
  * The value is URI-encoded so binary signature bytes and base64 padding
97
97
  * round-trip safely.
98
98
  *
99
+ * @param name Cookie name; `__Host-`/`__Secure-` prefixes are enforced by validation.
100
+ * @param value Cookie value; URI-encoded before serialization.
101
+ * @param attributes Cookie attributes. Defaults: `SameSite=Strict`, `Secure`, `HttpOnly`, `Path=/`.
102
+ * @returns A single `Set-Cookie` header value.
103
+ * @throws Error if the name or attributes fail {@link assertCookieAttributes} validation.
99
104
  * @since 0.27.0
100
105
  */
101
106
  export function serializeCookie(name, value, attributes = {}) {
@@ -125,6 +130,10 @@ export function serializeCookie(name, value, attributes = {}) {
125
130
  * `Max-Age=0` per RFC 6265 §5.2.2 and preserves the original attributes so
126
131
  * intermediaries match the original cookie when deciding what to delete.
127
132
  *
133
+ * @param name Name of the cookie to clear.
134
+ * @param attributes Attributes of the original cookie; must match for deletion to apply.
135
+ * @returns A `Set-Cookie` header value with an empty value and `Max-Age=0`.
136
+ * @throws Error if the name or attributes fail {@link assertCookieAttributes} validation.
128
137
  * @since 0.27.0
129
138
  */
130
139
  export function serializeClearCookie(name, attributes = {}) {
@@ -170,6 +179,9 @@ export function serializeClearCookie(name, attributes = {}) {
170
179
  * parser-level guard is defense-in-depth for developers who customize the
171
180
  * cookie name or read other cookies through this helper.
172
181
  *
182
+ * @param header The raw `Cookie` request header, or `null`/`undefined` when absent.
183
+ * @param name Exact cookie name to read (case-sensitive).
184
+ * @returns The decoded cookie value, or `null` when absent or duplicated.
173
185
  * @since 0.27.0
174
186
  */
175
187
  export function readRequestCookie(header, name) {
@@ -31,6 +31,7 @@ export interface DependencyOptions<TName extends string, TValue, TStateKey exten
31
31
  }
32
32
  /** Hooks bundle returned by {@link defineDependency} (carries metadata). */
33
33
  export interface DependencyHooks extends Hooks {
34
+ /** Non-enumerable dependency metadata (`name` + `dependsOn`) used for dedup and cycle checks. */
34
35
  readonly [DEPENDENCY_MARKER]: {
35
36
  readonly name: string;
36
37
  readonly dependsOn: readonly string[];
@@ -42,6 +43,9 @@ export interface DependencyHooks extends Hooks {
42
43
  * `ctx.state[stateKey]` (default `name`). Composing the same dependency
43
44
  * twice in one chain runs `resolve()` exactly once.
44
45
  *
46
+ * @param opts - Dependency `name`, optional `dependsOn` / `stateKey`, and the `resolve` function.
47
+ * @returns A {@link DependencyHooks} bundle to compose via `app.use()` / route hooks.
48
+ * @throws {Error} When `name` is empty or the dependency declares itself in `dependsOn` (cycle).
45
49
  * @since 0.24.0
46
50
  */
47
51
  export declare function defineDependency<TName extends string, TValue, TStateKey extends string = TName>(opts: DependencyOptions<TName, TValue, TStateKey>): DependencyHooks;
@@ -21,6 +21,9 @@ const RESULTS_KEY = Symbol.for("daloyjs.dependency.results");
21
21
  * `ctx.state[stateKey]` (default `name`). Composing the same dependency
22
22
  * twice in one chain runs `resolve()` exactly once.
23
23
  *
24
+ * @param opts - Dependency `name`, optional `dependsOn` / `stateKey`, and the `resolve` function.
25
+ * @returns A {@link DependencyHooks} bundle to compose via `app.use()` / route hooks.
26
+ * @throws {Error} When `name` is empty or the dependency declares itself in `dependsOn` (cycle).
24
27
  * @since 0.24.0
25
28
  */
26
29
  export function defineDependency(opts) {
@@ -27,6 +27,11 @@ export interface DiscriminatorObject {
27
27
  * Build an OpenAPI 3.1 Discriminator Object. Throws on an empty
28
28
  * `propertyName` so misconfigurations fail at boot rather than producing a
29
29
  * silently invalid spec.
30
+ *
31
+ * @param propertyName Name of the property that selects the variant schema.
32
+ * @param mapping Optional explicit discriminator-value-to-$ref map.
33
+ * @returns A {@link DiscriminatorObject} ready to embed in an OpenAPI schema.
34
+ * @throws TypeError if `propertyName` is not a non-empty string.
30
35
  */
31
36
  export declare function discriminator(propertyName: string, mapping?: Record<string, string>): DiscriminatorObject;
32
37
  /** Options for {@link discriminatedUnion}. */
@@ -68,6 +73,14 @@ export type DiscriminatedUnion<V extends Record<string, StandardSchemaV1>> = Sta
68
73
  * const Cat = z.object({ kind: z.literal("cat"), meow: z.boolean() });
69
74
  * const Dog = z.object({ kind: z.literal("dog"), bark: z.boolean() });
70
75
  * const Animal = discriminatedUnion("kind", { cat: Cat, dog: Dog });
76
+ *
77
+ * @param propertyName Discriminator property read off the incoming value.
78
+ * @param variants Map from discriminator value to variant schema. Only own
79
+ * properties are consulted, so prototype names like `constructor` cannot
80
+ * be abused to bypass variant lookup.
81
+ * @param opts Optional {@link DiscriminatedUnionOptions} (explicit `mapping`, `vendor`).
82
+ * @returns A {@link DiscriminatedUnion} usable as validator and OpenAPI emitter.
83
+ * @throws TypeError if `propertyName` is empty or `variants` has no entries.
71
84
  */
72
85
  export declare function discriminatedUnion<P extends string, V extends Record<string, StandardSchemaV1>>(propertyName: P, variants: V, opts?: DiscriminatedUnionOptions): DiscriminatedUnion<V>;
73
86
  export {};