@lithia-js/core 1.0.0-canary.2 → 1.0.0-canary.21

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 (102) hide show
  1. package/README.md +26 -43
  2. package/dist/_index.d.ts +245 -0
  3. package/dist/_index.mjs +2106 -0
  4. package/dist/_index.mjs.map +1 -0
  5. package/dist/index.d.ts +824 -0
  6. package/dist/index.mjs +856 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/protocol-DBwVPJYN.d.ts +332 -0
  9. package/dist/tasks-X-3clDS8.d.ts +31 -0
  10. package/dist/workers/app-worker.d.ts +2 -0
  11. package/dist/workers/app-worker.mjs +1907 -0
  12. package/dist/workers/app-worker.mjs.map +1 -0
  13. package/dist/workers/task-worker.d.ts +45 -0
  14. package/dist/workers/task-worker.mjs +146 -0
  15. package/dist/workers/task-worker.mjs.map +1 -0
  16. package/package.json +47 -23
  17. package/CHANGELOG.md +0 -31
  18. package/dist/config.d.ts +0 -101
  19. package/dist/config.js +0 -113
  20. package/dist/config.js.map +0 -1
  21. package/dist/context/event-context.d.ts +0 -53
  22. package/dist/context/event-context.js +0 -42
  23. package/dist/context/event-context.js.map +0 -1
  24. package/dist/context/index.d.ts +0 -16
  25. package/dist/context/index.js +0 -29
  26. package/dist/context/index.js.map +0 -1
  27. package/dist/context/lithia-context.d.ts +0 -47
  28. package/dist/context/lithia-context.js +0 -43
  29. package/dist/context/lithia-context.js.map +0 -1
  30. package/dist/context/route-context.d.ts +0 -74
  31. package/dist/context/route-context.js +0 -42
  32. package/dist/context/route-context.js.map +0 -1
  33. package/dist/env.d.ts +0 -1
  34. package/dist/env.js +0 -32
  35. package/dist/env.js.map +0 -1
  36. package/dist/errors.d.ts +0 -51
  37. package/dist/errors.js +0 -80
  38. package/dist/errors.js.map +0 -1
  39. package/dist/hooks/dependency-hooks.d.ts +0 -105
  40. package/dist/hooks/dependency-hooks.js +0 -96
  41. package/dist/hooks/dependency-hooks.js.map +0 -1
  42. package/dist/hooks/event-hooks.d.ts +0 -61
  43. package/dist/hooks/event-hooks.js +0 -70
  44. package/dist/hooks/event-hooks.js.map +0 -1
  45. package/dist/hooks/index.d.ts +0 -41
  46. package/dist/hooks/index.js +0 -59
  47. package/dist/hooks/index.js.map +0 -1
  48. package/dist/hooks/route-hooks.d.ts +0 -154
  49. package/dist/hooks/route-hooks.js +0 -174
  50. package/dist/hooks/route-hooks.js.map +0 -1
  51. package/dist/lib.d.ts +0 -10
  52. package/dist/lib.js +0 -30
  53. package/dist/lib.js.map +0 -1
  54. package/dist/lithia.d.ts +0 -447
  55. package/dist/lithia.js +0 -649
  56. package/dist/lithia.js.map +0 -1
  57. package/dist/logger.d.ts +0 -11
  58. package/dist/logger.js +0 -55
  59. package/dist/logger.js.map +0 -1
  60. package/dist/module-loader.d.ts +0 -12
  61. package/dist/module-loader.js +0 -78
  62. package/dist/module-loader.js.map +0 -1
  63. package/dist/server/event-processor.d.ts +0 -195
  64. package/dist/server/event-processor.js +0 -253
  65. package/dist/server/event-processor.js.map +0 -1
  66. package/dist/server/http-server.d.ts +0 -196
  67. package/dist/server/http-server.js +0 -295
  68. package/dist/server/http-server.js.map +0 -1
  69. package/dist/server/middlewares/validation.d.ts +0 -12
  70. package/dist/server/middlewares/validation.js +0 -34
  71. package/dist/server/middlewares/validation.js.map +0 -1
  72. package/dist/server/request-processor.d.ts +0 -400
  73. package/dist/server/request-processor.js +0 -652
  74. package/dist/server/request-processor.js.map +0 -1
  75. package/dist/server/request.d.ts +0 -73
  76. package/dist/server/request.js +0 -207
  77. package/dist/server/request.js.map +0 -1
  78. package/dist/server/response.d.ts +0 -69
  79. package/dist/server/response.js +0 -173
  80. package/dist/server/response.js.map +0 -1
  81. package/src/config.ts +0 -212
  82. package/src/context/event-context.ts +0 -66
  83. package/src/context/index.ts +0 -32
  84. package/src/context/lithia-context.ts +0 -59
  85. package/src/context/route-context.ts +0 -89
  86. package/src/env.ts +0 -31
  87. package/src/errors.ts +0 -96
  88. package/src/hooks/dependency-hooks.ts +0 -122
  89. package/src/hooks/event-hooks.ts +0 -69
  90. package/src/hooks/index.ts +0 -58
  91. package/src/hooks/route-hooks.ts +0 -177
  92. package/src/lib.ts +0 -27
  93. package/src/lithia.ts +0 -777
  94. package/src/logger.ts +0 -66
  95. package/src/module-loader.ts +0 -45
  96. package/src/server/event-processor.ts +0 -344
  97. package/src/server/http-server.ts +0 -371
  98. package/src/server/middlewares/validation.ts +0 -46
  99. package/src/server/request-processor.ts +0 -860
  100. package/src/server/request.ts +0 -247
  101. package/src/server/response.ts +0 -204
  102. package/tsconfig.json +0 -8
@@ -0,0 +1,824 @@
1
+ import { c as LithiaClientError, E as Event, T as TaskInvocationSource, R as Route } from './protocol-DBwVPJYN.js';
2
+ export { B as BadRequestError, d as ConflictError, F as ForbiddenError, e as LithiaConfig, L as LithiaError, f as LithiaEventError, N as NotFoundError, b as RouteNotFoundError, U as UnauthorizedError, g as defineConfig } from './protocol-DBwVPJYN.js';
3
+ import { Socket, Server } from 'socket.io';
4
+ import { IncomingHttpHeaders, IncomingMessage, ServerResponse, OutgoingHttpHeaders } from 'node:http';
5
+ import { FileInfo } from 'busboy';
6
+ import { Cookies } from 'cookie';
7
+ import { ZodType } from 'zod';
8
+ import '@lithia-js/utils';
9
+ import 'c12';
10
+
11
+ /**
12
+ * Indicates that the server hit an unexpected internal failure.
13
+ */
14
+ declare class InternalServerError extends LithiaClientError {
15
+ constructor(m: string, d?: any);
16
+ }
17
+ /**
18
+ * Indicates that the service is temporarily unavailable.
19
+ */
20
+ declare class ServiceUnavailableError extends LithiaClientError {
21
+ constructor(m: string, d?: any);
22
+ }
23
+ /**
24
+ * Indicates that an upstream operation timed out.
25
+ */
26
+ declare class GatewayTimeoutError extends LithiaClientError {
27
+ constructor(m: string, d?: any);
28
+ }
29
+
30
+ /**
31
+ * Returns the payload received by the current event handler.
32
+ *
33
+ * Use this inside helpers called from event handlers when passing the event
34
+ * payload explicitly would add unnecessary plumbing. Event hook semantics are
35
+ * described in [Event Handlers](https://lithiajs.org/docs/latest/events).
36
+ *
37
+ * @returns {T} Payload currently bound to the active event context.
38
+ * @throws {NotInEventContextError} Throws when called outside a managed socket
39
+ * event handler.
40
+ */
41
+ declare function useData<T = any>(): T;
42
+ /**
43
+ * Returns the active Socket.IO connection for the current event handler.
44
+ *
45
+ * This hook exposes the socket boundary owned by the current event file, so
46
+ * helper code can emit messages or inspect socket metadata without threading
47
+ * the socket through every call.
48
+ *
49
+ * @returns {Socket} Socket.IO connection bound to the active event context.
50
+ * @throws {NotInEventContextError} Throws when called outside a managed socket
51
+ * event handler.
52
+ */
53
+ declare function useSocket(): Socket;
54
+ /**
55
+ * Returns the current event manifest entry being handled.
56
+ *
57
+ * The returned metadata includes the resolved event name and compiled module
58
+ * path discovered from `src/app/events`.
59
+ *
60
+ * @returns {Event} Event manifest entry bound to the active event context.
61
+ * @throws {NotInEventContextError} Throws when called outside a managed socket
62
+ * event handler.
63
+ */
64
+ declare function useEvent(): Event;
65
+
66
+ /**
67
+ * Route params object populated by the route matcher.
68
+ *
69
+ * Keys correspond to dynamic segments extracted from the matched route pattern.
70
+ * The values are assigned by the HTTP transport before the handler runs and
71
+ * remain mutable for the lifetime of the current request context.
72
+ */
73
+ type Params = Record<string, any>;
74
+ /**
75
+ * Query object parsed from the incoming request URL.
76
+ *
77
+ * Each value is currently stored as the last string value observed for a given
78
+ * query key during URL parsing.
79
+ */
80
+ type Query = Record<string, any>;
81
+ /**
82
+ * Uploaded multipart file returned by `req.files()`.
83
+ *
84
+ * Each file entry contains the metadata reported by Busboy plus the fully
85
+ * buffered file contents collected while the multipart stream is parsed.
86
+ */
87
+ interface UploadedFile extends FileInfo {
88
+ fieldname: string;
89
+ buffer: Buffer;
90
+ }
91
+ /**
92
+ * Lithia wrapper around Node's `IncomingMessage`.
93
+ *
94
+ * Provides helpers for reading params, query, body, cookies, and multipart
95
+ * uploads from route handlers and middleware.
96
+ *
97
+ * The wrapper parses URL-derived data eagerly in the constructor and reads the
98
+ * request stream lazily only when `body()` or `files()` is called. Parsed
99
+ * payloads are cached so route handlers and middleware can safely reuse the
100
+ * same request wrapper without reparsing the stream.
101
+ *
102
+ * Related docs:
103
+ * - https://lithiajs.org/docs/latest/routes
104
+ * - https://lithiajs.org/docs/latest/project-structure
105
+ */
106
+ declare class LithiaRequest {
107
+ private readonly req;
108
+ private readonly opts;
109
+ readonly headers: Readonly<IncomingHttpHeaders>;
110
+ readonly method: Readonly<string>;
111
+ readonly pathname: Readonly<string>;
112
+ query: Query;
113
+ params: Params;
114
+ private readonly storage;
115
+ private _bodyCache;
116
+ private _filesCache;
117
+ private _cookies;
118
+ /**
119
+ * Creates a request wrapper for the current HTTP transaction.
120
+ *
121
+ * The constructor captures headers, reconstructs a best-effort absolute URL,
122
+ * normalizes the HTTP method to uppercase, and initializes parsed query and
123
+ * route-param containers for later middleware and handler use.
124
+ *
125
+ * @param {IncomingMessage} req - Raw Node.js request object received by the
126
+ * HTTP server.
127
+ * @param {{ maxBodySize?: number }} opts - Per-request parsing options used
128
+ * when consuming the request body stream.
129
+ */
130
+ constructor(req: IncomingMessage, opts: {
131
+ maxBodySize?: number;
132
+ });
133
+ /**
134
+ * Returns the best-effort client IP address for the current request.
135
+ *
136
+ * The lookup prefers proxy-forwarded headers before falling back to the raw
137
+ * socket address, which makes the result suitable for deployments behind
138
+ * reverse proxies that preserve `x-forwarded-for` or `x-real-ip`.
139
+ *
140
+ * @returns {string} The resolved client IP address, or `"unknown"` when no
141
+ * address can be derived.
142
+ */
143
+ ip(): string;
144
+ /**
145
+ * Returns the current request user-agent string.
146
+ *
147
+ * @returns {string} The raw `user-agent` header value, or an empty string
148
+ * when the header is missing.
149
+ */
150
+ userAgent(): string;
151
+ /**
152
+ * Returns whether the current request is using HTTPS.
153
+ *
154
+ * The check prefers `x-forwarded-proto` for proxy-aware deployments and then
155
+ * falls back to the encrypted state of the underlying socket.
156
+ *
157
+ * @returns {boolean} `true` when the request should be treated as HTTPS.
158
+ */
159
+ isSecure(): boolean;
160
+ /**
161
+ * Returns the request host header.
162
+ *
163
+ * @returns {string} The current host header value, or `"unknown"` when it is
164
+ * not available.
165
+ */
166
+ host(): string;
167
+ /**
168
+ * Returns the absolute request URL reconstructed from the current request.
169
+ *
170
+ * This helper rebuilds the URL from the current security state, host header,
171
+ * and parsed pathname. It does not append the original query string.
172
+ *
173
+ * @returns {string} Absolute URL for the current request pathname.
174
+ */
175
+ url(): string;
176
+ /**
177
+ * Parses and returns the request body.
178
+ *
179
+ * JSON and plain text bodies are supported automatically. Multipart requests
180
+ * populate both `body()` and `files()` through a shared parsing pass. The
181
+ * parsed value is cached after the first read so later consumers do not touch
182
+ * the underlying stream again.
183
+ *
184
+ * Requests whose method is not one of `POST`, `PUT`, `PATCH`, or `DELETE`
185
+ * resolve to an empty object without reading the stream.
186
+ *
187
+ * @returns {Promise<T>} Parsed request body, multipart field map, raw text, or
188
+ * an empty object for methods that do not consume a body by default.
189
+ * @throws {BadRequestError} Thrown when the declared or streamed body size
190
+ * exceeds `maxBodySize`, or when JSON parsing fails.
191
+ */
192
+ body<T>(): Promise<T>;
193
+ /**
194
+ * Returns uploaded files for multipart/form-data requests.
195
+ *
196
+ * `files()` shares the same multipart parsing pass used by `body()`. The
197
+ * first call buffers every uploaded file into memory and caches both the
198
+ * parsed field object and file array for later access.
199
+ *
200
+ * @returns {Promise<UploadedFile[]>} Buffered multipart files, or an empty
201
+ * array when the request is not multipart.
202
+ */
203
+ files(): Promise<UploadedFile[]>;
204
+ /**
205
+ * Overrides the cached body value for the current request context.
206
+ *
207
+ * This mutates only the wrapper cache and the internal storage map. It does
208
+ * not modify the underlying Node.js request stream.
209
+ *
210
+ * @param {unknown} value - Replacement body value to expose through `body()`
211
+ * and internal request storage.
212
+ */
213
+ setBody(value: unknown): void;
214
+ /**
215
+ * Returns all parsed cookies from the request.
216
+ *
217
+ * Cookies are parsed lazily on first access and cached for the remainder of
218
+ * the request lifecycle.
219
+ *
220
+ * @returns {Cookies} Parsed cookie map for the current request.
221
+ */
222
+ cookies(): Cookies;
223
+ /**
224
+ * Returns a single cookie value by name.
225
+ *
226
+ * @param {string} name - Cookie name to read from the parsed cookie map.
227
+ * @returns {string | undefined} The cookie value when present.
228
+ */
229
+ cookie(name: string): string | undefined;
230
+ /**
231
+ * Returns a value stored in the per-request internal storage map.
232
+ *
233
+ * This storage is local to the current request wrapper and can be used by
234
+ * middleware and handlers to exchange derived values without mutating the
235
+ * typed request surface.
236
+ *
237
+ * @param {string} key - Storage key associated with the requested value.
238
+ * @returns {T | undefined} Stored value for the key, if one exists.
239
+ */
240
+ get<T>(key: string): T | undefined;
241
+ /**
242
+ * Stores a value in the per-request internal storage map.
243
+ *
244
+ * @param {string} key - Storage key to create or overwrite.
245
+ * @param {unknown} value - Arbitrary value to retain for the lifetime of the
246
+ * current request wrapper.
247
+ */
248
+ set(key: string, value: unknown): void;
249
+ /**
250
+ * Parses a multipart/form-data request into cached fields and file buffers.
251
+ *
252
+ * The request stream is piped into Busboy exactly once. Field values are
253
+ * collected into a plain object, file contents are buffered fully in memory,
254
+ * and both results are stored in the request cache and internal storage map.
255
+ *
256
+ * @returns {Promise<void>} Resolves after Busboy finishes consuming the
257
+ * multipart stream and caches the parsed payload.
258
+ */
259
+ private parseMultipart;
260
+ }
261
+
262
+ /**
263
+ * Cookie attributes accepted by `LithiaResponse.cookie()`.
264
+ *
265
+ * These options are forwarded to the cookie serializer when pending cookies
266
+ * are flushed into the `Set-Cookie` header.
267
+ */
268
+ interface CookieOptions {
269
+ domain?: string;
270
+ expires?: Date;
271
+ httpOnly?: boolean;
272
+ maxAge?: number;
273
+ path?: string;
274
+ sameSite?: boolean | "lax" | "strict" | "none";
275
+ secure?: boolean;
276
+ }
277
+ /**
278
+ * Lithia wrapper around Node's `ServerResponse`.
279
+ *
280
+ * Provides helpers for status management, JSON/text responses, redirects,
281
+ * cookies, and file responses.
282
+ *
283
+ * The wrapper keeps response mutations centralized until one of the terminal
284
+ * methods sends or streams the response. After that point, further mutations
285
+ * are rejected to preserve a single-write HTTP lifecycle.
286
+ *
287
+ * Related docs:
288
+ * - https://lithiajs.org/docs/latest/routes
289
+ * - https://lithiajs.org/docs/latest/project-structure
290
+ */
291
+ declare class LithiaResponse {
292
+ private readonly res;
293
+ _ended: boolean;
294
+ private _cookies;
295
+ on: (event: string, listener: (chunk: unknown) => void) => void;
296
+ /**
297
+ * Creates a response wrapper for the current HTTP transaction.
298
+ *
299
+ * The wrapper binds a pass-through `on()` helper to the underlying Node.js
300
+ * response object so route-adjacent code can subscribe to response events
301
+ * without holding the raw `ServerResponse`.
302
+ *
303
+ * @param {ServerResponse} res - Raw Node.js response object associated with
304
+ * the current request.
305
+ */
306
+ constructor(res: ServerResponse);
307
+ /**
308
+ * Returns the current HTTP status code.
309
+ *
310
+ * @returns {number} Status code currently assigned to the underlying
311
+ * response.
312
+ */
313
+ get statusCode(): number;
314
+ /**
315
+ * Sets the HTTP status code for the response.
316
+ *
317
+ * This mutates the underlying response only while it is still active.
318
+ *
319
+ * @param {number} status - HTTP status code to assign before the response is
320
+ * sent.
321
+ * @returns {this} The current response wrapper for fluent chaining.
322
+ * @throws {Error} Thrown when the response has already ended or when the
323
+ * supplied status code falls outside the valid HTTP range.
324
+ */
325
+ status(status: number): this;
326
+ /**
327
+ * Returns the currently assigned response headers.
328
+ *
329
+ * @returns {Readonly<OutgoingHttpHeaders>} Snapshot of the headers currently
330
+ * stored on the underlying response.
331
+ */
332
+ headers(): Readonly<OutgoingHttpHeaders>;
333
+ /**
334
+ * Sets multiple response headers at once.
335
+ *
336
+ * @param {OutgoingHttpHeaders} headers - Header entries to assign to the
337
+ * response before it is sent.
338
+ * @returns {this} The current response wrapper for fluent chaining.
339
+ * @throws {Error} Thrown when the response has already ended.
340
+ */
341
+ setHeaders(headers: OutgoingHttpHeaders): this;
342
+ /**
343
+ * Sets a single response header.
344
+ *
345
+ * @param {string} name - Header name to create or overwrite.
346
+ * @param {string | number | string[]} value - Header value written to the
347
+ * underlying response.
348
+ * @returns {this} The current response wrapper for fluent chaining.
349
+ * @throws {Error} Thrown when the response has already ended.
350
+ */
351
+ setHeader(name: string, value: string | number | string[]): this;
352
+ /**
353
+ * Removes a response header.
354
+ *
355
+ * @param {string} name - Header name to remove.
356
+ * @returns {this} The current response wrapper for fluent chaining.
357
+ * @throws {Error} Thrown when the response has already ended.
358
+ */
359
+ removeHeader(name: string): this;
360
+ /**
361
+ * Queues a cookie to be written when the response is sent.
362
+ *
363
+ * Cookies are accumulated in memory and serialized only when a terminal
364
+ * response method flushes headers.
365
+ *
366
+ * @param {string} name - Cookie name.
367
+ * @param {string} value - Cookie value.
368
+ * @param {CookieOptions} [options={}] - Cookie serialization options.
369
+ * @returns {this} The current response wrapper for fluent chaining.
370
+ * @throws {Error} Thrown when the response has already ended.
371
+ */
372
+ cookie(name: string, value: string, options?: CookieOptions): this;
373
+ /**
374
+ * Clears a cookie by expiring it immediately.
375
+ *
376
+ * @param {string} name - Cookie name to expire.
377
+ * @param {CookieOptions} [options={}] - Additional cookie attributes that
378
+ * must match the original cookie scope.
379
+ * @returns {this} The current response wrapper for fluent chaining.
380
+ */
381
+ clearCookie(name: string, options?: CookieOptions): this;
382
+ /**
383
+ * Sends a response body using a best-effort content type.
384
+ *
385
+ * The method flushes pending cookies before writing, chooses a default
386
+ * content type when none is set, and treats plain objects as JSON by
387
+ * delegating to `json()`. Calling `send()` is a terminal operation for the
388
+ * response lifecycle.
389
+ *
390
+ * @param {unknown} [data] - Response payload to send.
391
+ * @throws {Error} Thrown when the response has already ended.
392
+ */
393
+ send(data?: unknown): void;
394
+ /**
395
+ * Sends a JSON response.
396
+ *
397
+ * Pending cookies are flushed before serialization. If JSON serialization
398
+ * throws, the method logs the failure and falls back to a `500 Internal
399
+ * Server Error` response body.
400
+ *
401
+ * @param {object} obj - Plain object to serialize as JSON.
402
+ */
403
+ json(obj: object): void;
404
+ /**
405
+ * Sends a redirect response.
406
+ *
407
+ * This sets the status code, writes the `Location` header, and then ends the
408
+ * response.
409
+ *
410
+ * @param {string} url - Redirect target written to the `Location` header.
411
+ * @param {number} [status=302] - Redirect status code.
412
+ */
413
+ redirect(url: string, status?: number): void;
414
+ /**
415
+ * Ends the response without sending additional data.
416
+ *
417
+ * Pending cookies are flushed before the underlying response is closed.
418
+ *
419
+ * @throws {Error} Thrown when the response has already ended.
420
+ */
421
+ end(): void;
422
+ /**
423
+ * Streams a file to the client.
424
+ *
425
+ * The method resolves the final path, verifies that it points to a regular
426
+ * file, sets `Content-Length`, flushes pending cookies, and pipes the file
427
+ * stream into the underlying response. Missing files and stream failures fall
428
+ * back to a `404` JSON error payload.
429
+ *
430
+ * @param {string} filePath - File path to stream. When `opts.root` is set, it
431
+ * is resolved relative to that root.
432
+ * @param {{ root?: string }} [opts={}] - Optional root directory used to
433
+ * resolve relative file paths.
434
+ */
435
+ sendFile(filePath: string, opts?: {
436
+ root?: string;
437
+ }): void;
438
+ /**
439
+ * Serializes queued cookies into the response headers and clears the queue.
440
+ *
441
+ * Existing `Set-Cookie` headers are preserved and extended so multiple
442
+ * middleware and handler calls can contribute cookies before the response is
443
+ * finalized.
444
+ */
445
+ private applyPendingCookies;
446
+ /**
447
+ * Ensures the response has not already been finalized.
448
+ *
449
+ * @throws {Error} Thrown when a terminal response method has already sent or
450
+ * ended the response.
451
+ */
452
+ private ensureActive;
453
+ }
454
+
455
+ /**
456
+ * Declares an OpenAPI security requirement object for a route operation.
457
+ *
458
+ * Each key references a named security scheme and its value lists the scopes
459
+ * required for the operation when that scheme supports scoped authorization.
460
+ */
461
+ type OpenAPISecurityRequirement = Record<string, string[]>;
462
+ /**
463
+ * Describes a response exposed in the generated OpenAPI document.
464
+ *
465
+ * This metadata is attached to a single status code entry inside
466
+ * `metadata.openapi.responses`.
467
+ */
468
+ interface OpenAPIResponseMetadata {
469
+ /**
470
+ * Human-readable description shown in the generated spec.
471
+ */
472
+ description: string;
473
+ /**
474
+ * Optional Zod schema used to describe the response body.
475
+ */
476
+ schema?: ZodType;
477
+ /**
478
+ * Response media type. Defaults to `application/json`.
479
+ */
480
+ contentType?: string;
481
+ }
482
+ /**
483
+ * Explicit OpenAPI metadata attached to an HTTP route module.
484
+ *
485
+ * Export this inside `export const metadata = { openapi: ... }` to enrich the
486
+ * generated OpenAPI document for a route.
487
+ *
488
+ * The route file remains the source of truth for the HTTP contract. This type
489
+ * provides the structured metadata surface used by Lithia's OpenAPI generation
490
+ * pipeline and Scalar docs integration.
491
+ *
492
+ * Related docs:
493
+ * - https://lithiajs.org/docs/latest/openapi
494
+ * - https://lithiajs.org/docs/latest/routes
495
+ */
496
+ interface OpenAPIRouteMetadata {
497
+ /**
498
+ * Short operation summary.
499
+ */
500
+ summary?: string;
501
+ /**
502
+ * Longer operation description.
503
+ */
504
+ description?: string;
505
+ /**
506
+ * Tags used to group operations in the generated docs.
507
+ */
508
+ tags?: string[];
509
+ /**
510
+ * Zod schema describing path params.
511
+ */
512
+ params?: ZodType;
513
+ /**
514
+ * Zod schema describing querystring params.
515
+ */
516
+ query?: ZodType;
517
+ /**
518
+ * Zod schema describing the JSON request body.
519
+ */
520
+ body?: ZodType;
521
+ /**
522
+ * Explicit response definitions keyed by status code.
523
+ */
524
+ responses?: Record<number | `${number}`, OpenAPIResponseMetadata>;
525
+ /**
526
+ * Optional security requirements for the operation.
527
+ */
528
+ security?: OpenAPISecurityRequirement[];
529
+ }
530
+ /**
531
+ * Route module metadata exported from a route file as `export const metadata`.
532
+ *
533
+ * This is the top-level metadata envelope recognized by the HTTP route loader.
534
+ */
535
+ interface RouteMetadata {
536
+ openapi?: OpenAPIRouteMetadata;
537
+ }
538
+
539
+ /**
540
+ * Continuation used by route middleware to hand control to the next step in
541
+ * the pipeline.
542
+ *
543
+ * Calling `next()` transfers control to the next middleware or, once the stack
544
+ * is exhausted, to the route handler itself.
545
+ */
546
+ type NextRoute = () => Promise<void> | void;
547
+ /**
548
+ * Middleware executed before a route handler.
549
+ *
550
+ * Route middleware can inspect or mutate the request/response and may stop the
551
+ * pipeline by not calling `next()`.
552
+ *
553
+ * @param {LithiaRequest} req - Current request wrapper shared across the route
554
+ * pipeline.
555
+ * @param {LithiaResponse} res - Current response wrapper shared across the
556
+ * route pipeline.
557
+ * @param {NextRoute} next - Continuation that advances execution to the next
558
+ * middleware or the final route handler.
559
+ * @returns {Promise<void>} Resolves after the middleware finishes its work.
560
+ */
561
+ type RouteMiddleware = (req: LithiaRequest, res: LithiaResponse, next: NextRoute) => Promise<void>;
562
+ /**
563
+ * Route module default export signature.
564
+ *
565
+ * Route handlers are the terminal HTTP boundary for a matched route module and
566
+ * receive the current request and response wrappers.
567
+ *
568
+ * @param {LithiaRequest} req - Current request wrapper.
569
+ * @param {LithiaResponse} res - Current response wrapper.
570
+ * @returns {Promise<void>} Resolves after the handler finishes shaping the HTTP
571
+ * response.
572
+ */
573
+ type RouteHandler = (req: LithiaRequest, res: LithiaResponse) => Promise<void>;
574
+
575
+ /**
576
+ * Continuation used by event middleware to hand control to the next step in
577
+ * the event pipeline.
578
+ *
579
+ * Calling `next()` transfers control to the next middleware or, once the stack
580
+ * is exhausted, to the final event handler.
581
+ */
582
+ type NextEvent = () => Promise<void> | void;
583
+ /**
584
+ * Middleware executed before a socket event handler.
585
+ *
586
+ * @param {Socket} socket - Active socket associated with the event execution.
587
+ * @param {NextEvent} next - Continuation that advances to the next middleware
588
+ * or event handler.
589
+ * @returns {Promise<void>} Resolves after the middleware completes.
590
+ */
591
+ type EventMiddleware = (socket: Socket, next: NextEvent) => Promise<void>;
592
+ /**
593
+ * Event module default export signature.
594
+ *
595
+ * @param {Socket} socket - Active socket for the current event.
596
+ * @param {any} [data] - Event payload forwarded from Socket.IO.
597
+ * @returns {Promise<void>} Resolves after the event handler completes.
598
+ */
599
+ type EventHandler = (socket: Socket, data?: any) => Promise<void>;
600
+
601
+ /**
602
+ * Token used to register or resolve a dependency from the app container.
603
+ */
604
+ type InjectionKey<T> = symbol | string | {
605
+ new (...args: any[]): T;
606
+ };
607
+
608
+ declare module "../hooks/lithia-hooks" {
609
+ interface LithiaTasks {
610
+ }
611
+ }
612
+ type TaskInvocationKey = keyof LithiaTasks | (string & {});
613
+ /**
614
+ * Stores a value in the current app dependency container.
615
+ *
616
+ * Values registered with `provide()` can later be retrieved with
617
+ * `useDependency()` or `useOptionalDependency()` from routes, events, tasks,
618
+ * and `app/server.ts`.
619
+ *
620
+ * The value is written into the container bound to the current Lithia
621
+ * execution context. When called during mutable bootstrap, the registration
622
+ * becomes available to later route, event, and task executions.
623
+ *
624
+ * @param {InjectionKey<T>} key - Token used to register the dependency.
625
+ * @param {T} value - Dependency instance stored under `key`.
626
+ * @throws {NotInLithiaContextError} Throws when called outside a managed
627
+ * Lithia execution context.
628
+ */
629
+ declare function provide<T>(key: InjectionKey<T>, value: T): void;
630
+ /**
631
+ * Resolves a dependency from the current Lithia context.
632
+ *
633
+ * Throws when the dependency has not been registered for the current app
634
+ * lifecycle.
635
+ *
636
+ * @param {InjectionKey<T>} key - Token used to resolve the dependency.
637
+ * @returns {T} Registered dependency instance for `key`.
638
+ * @throws {NotInLithiaContextError} Throws when called outside a managed
639
+ * Lithia execution context.
640
+ * @throws {DependencyNotInitializedError} Throws when `key` has not been
641
+ * registered in the current container.
642
+ */
643
+ declare function useDependency<T>(key: InjectionKey<T>): T;
644
+ /**
645
+ * Resolves a dependency from the current Lithia context when available.
646
+ *
647
+ * Returns `undefined` instead of throwing when the dependency has not been
648
+ * registered.
649
+ *
650
+ * @param {InjectionKey<T>} key - Token used to resolve the dependency.
651
+ * @returns {T | undefined} Registered dependency instance, or `undefined` when
652
+ * the dependency is absent.
653
+ * @throws {NotInLithiaContextError} Throws when called outside a managed
654
+ * Lithia execution context.
655
+ */
656
+ declare function useOptionalDependency<T>(key: InjectionKey<T>): T | undefined;
657
+ type KnownTaskPayload<T> = T extends (...args: infer P) => any ? P : never;
658
+ type KnownTaskReturn<T> = T extends (...args: any[]) => Promise<infer R> ? R : T extends (...args: any[]) => infer R ? R : any;
659
+ type TaskPayload<K extends TaskInvocationKey> = K extends keyof LithiaTasks ? KnownTaskPayload<LithiaTasks[K]> : any[];
660
+ type TaskReturn<K extends TaskInvocationKey> = K extends keyof LithiaTasks ? KnownTaskReturn<LithiaTasks[K]> : unknown;
661
+ /**
662
+ * Returned by `dispatchTask()` to identify an async task execution.
663
+ */
664
+ type TaskExecutionHandle<K extends string = string> = {
665
+ taskId: K;
666
+ executionId: string;
667
+ source: TaskInvocationSource;
668
+ };
669
+ /**
670
+ * Executes an async task and waits for its result.
671
+ *
672
+ * This path uses Lithia's warm task workers to reduce latency for request-time
673
+ * task execution while still keeping the work outside the app worker.
674
+ *
675
+ * Task semantics are described in
676
+ * [Async Tasks](https://lithiajs.org/docs/latest/async-tasks).
677
+ *
678
+ * @param {K} taskId - Task identifier to execute.
679
+ * @param {...TaskPayload<K>} args - Arguments forwarded to the task worker.
680
+ * @returns {Promise<Awaited<TaskReturn<K>>>} Resolves with the task result
681
+ * returned by the worker.
682
+ * @throws {Error} Throws when called outside a Lithia-managed worker, when the
683
+ * worker closes before replying, when arguments cannot be cloned, or when the
684
+ * task worker reports a failure.
685
+ */
686
+ declare function executeTask<K extends TaskInvocationKey>(taskId: K, ...args: TaskPayload<K>): Promise<Awaited<TaskReturn<K>>>;
687
+ /**
688
+ * Dispatches an async task without awaiting its result.
689
+ *
690
+ * This path is fire-and-forget and returns a handle that can be logged or
691
+ * correlated later.
692
+ *
693
+ * @param {K} taskId - Task identifier to dispatch.
694
+ * @param {...TaskPayload<K>} args - Arguments forwarded to the task worker.
695
+ * @returns {TaskExecutionHandle<Extract<K, string>>} Handle that identifies
696
+ * the dispatched task execution.
697
+ * @throws {Error} Throws when called outside a Lithia-managed worker or when
698
+ * arguments cannot be cloned for worker dispatch.
699
+ */
700
+ declare function dispatchTask<K extends TaskInvocationKey>(taskId: K, ...args: TaskPayload<K>): TaskExecutionHandle<Extract<K, string>>;
701
+ /**
702
+ * Legacy alias for `executeTask()`.
703
+ *
704
+ * Prefer `executeTask()` in new code.
705
+ *
706
+ * @param {K} taskId - Task identifier to execute.
707
+ * @param {...TaskPayload<K>} args - Arguments forwarded to the task worker.
708
+ * @returns {Promise<Awaited<TaskReturn<K>>>} Resolves with the task result.
709
+ */
710
+ declare function runTask<K extends TaskInvocationKey>(taskId: K, ...args: TaskPayload<K>): Promise<Awaited<TaskReturn<K>>>;
711
+ /**
712
+ * Legacy alias for `dispatchTask()`.
713
+ *
714
+ * Prefer `dispatchTask()` in new code.
715
+ *
716
+ * @param {K} taskId - Task identifier to dispatch.
717
+ * @param {...TaskPayload<K>} args - Arguments forwarded to the task worker.
718
+ * @returns {TaskExecutionHandle<Extract<K, string>>} Handle that identifies
719
+ * the dispatched task execution.
720
+ */
721
+ declare function runTaskAsync<K extends TaskInvocationKey>(taskId: K, ...args: TaskPayload<K>): TaskExecutionHandle<Extract<K, string>>;
722
+
723
+ /**
724
+ * Returns the current Lithia request object.
725
+ *
726
+ * This hook is only available while handling an HTTP route.
727
+ * Route hook semantics are described in
728
+ * [Route Handlers](https://lithiajs.org/docs/latest/routes).
729
+ *
730
+ * @returns {LithiaRequest} Request wrapper bound to the active route context.
731
+ * @throws {NotInRequestContextError} Throws when called outside a managed HTTP
732
+ * route handler.
733
+ */
734
+ declare function useRequest(): LithiaRequest;
735
+ /**
736
+ * Returns the current Lithia response object.
737
+ *
738
+ * This hook is only available while handling an HTTP route.
739
+ *
740
+ * @returns {LithiaResponse} Response wrapper bound to the active route
741
+ * context.
742
+ * @throws {NotInRequestContextError} Throws when called outside a managed HTTP
743
+ * route handler.
744
+ */
745
+ declare function useResponse(): LithiaResponse;
746
+ /**
747
+ * Returns the matched route manifest entry for the current request.
748
+ *
749
+ * The route may be `undefined` when the current request context was created
750
+ * without a resolved route manifest entry.
751
+ *
752
+ * @returns {Route | undefined} Matched route metadata for the current request.
753
+ * @throws {NotInRequestContextError} Throws when called outside a managed HTTP
754
+ * route handler.
755
+ */
756
+ declare function useRoute(): Route | undefined;
757
+ /**
758
+ * Returns the pathname for the current request.
759
+ *
760
+ * @returns {string} URL pathname of the active request.
761
+ * @throws {NotInRequestContextError} Throws when called outside a managed HTTP
762
+ * route handler.
763
+ */
764
+ declare function usePathname(): string;
765
+ /**
766
+ * Returns the typed route params for the current request.
767
+ *
768
+ * This is a typed view over the params already parsed and attached to the
769
+ * current request object.
770
+ *
771
+ * @returns {T} Route params bound to the active request.
772
+ * @throws {NotInRequestContextError} Throws when called outside a managed HTTP
773
+ * route handler.
774
+ */
775
+ declare function useParams<T extends Params = Params>(): T;
776
+ /**
777
+ * Returns the typed query object for the current request.
778
+ *
779
+ * @returns {T} Query object parsed from the active request URL.
780
+ * @throws {NotInRequestContextError} Throws when called outside a managed HTTP
781
+ * route handler.
782
+ */
783
+ declare function useQuery<T extends Query = Query>(): T;
784
+ /**
785
+ * Returns the raw incoming HTTP headers for the current request.
786
+ *
787
+ * @returns {IncomingHttpHeaders} Raw request headers for the active HTTP
788
+ * request.
789
+ * @throws {NotInRequestContextError} Throws when called outside a managed HTTP
790
+ * route handler.
791
+ */
792
+ declare function useHeaders(): IncomingHttpHeaders;
793
+ /**
794
+ * Returns the shared Socket.IO server instance.
795
+ *
796
+ * Use this from HTTP routes when you need to emit socket events from the
797
+ * request side of the app.
798
+ *
799
+ * @returns {SocketServer} Socket.IO server shared by the current application
800
+ * runtime.
801
+ * @throws {NotInRequestContextError} Throws when called outside a managed HTTP
802
+ * route handler.
803
+ */
804
+ declare function useSocketServer(): Server;
805
+
806
+ /**
807
+ * Optional cleanup returned by `app/server.ts`.
808
+ *
809
+ * The cleanup callback runs during controlled shutdown after the startup
810
+ * bootstrap has completed successfully.
811
+ */
812
+ type LithiaServerCleanup = void | (() => void | Promise<void>);
813
+ /**
814
+ * Bootstrap contract for `src/app/server.ts`.
815
+ *
816
+ * The function runs before the app starts accepting traffic and may return an
817
+ * optional cleanup callback that runs during shutdown and reload. Startup
818
+ * lifecycle details are described in
819
+ * [Project Structure](https://lithiajs.org/docs/latest/project-structure) and
820
+ * [Deploying](https://lithiajs.org/docs/latest/deploying).
821
+ */
822
+ type LithiaServerBootstrap = () => Promise<LithiaServerCleanup>;
823
+
824
+ export { type CookieOptions, type EventHandler, type EventMiddleware, GatewayTimeoutError, InternalServerError, LithiaClientError, LithiaRequest, LithiaResponse, type LithiaServerBootstrap, type LithiaServerCleanup, type NextEvent, type NextRoute, type OpenAPIResponseMetadata, type OpenAPIRouteMetadata, type OpenAPISecurityRequirement, type Params, type Query, type RouteHandler, type RouteMetadata, type RouteMiddleware, ServiceUnavailableError, type UploadedFile, dispatchTask, executeTask, provide, runTask, runTaskAsync, useData, useDependency, useEvent, useHeaders, useOptionalDependency, useParams, usePathname, useQuery, useRequest, useResponse, useRoute, useSocket, useSocketServer };