@theokit/http 0.4.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 (38) hide show
  1. package/README.md +172 -0
  2. package/dist/app.d.ts +67 -0
  3. package/dist/app.js +11 -0
  4. package/dist/app.js.map +1 -0
  5. package/dist/chunk-34KOKJ5M.js +71 -0
  6. package/dist/chunk-34KOKJ5M.js.map +1 -0
  7. package/dist/chunk-3PGQVQWG.js +276 -0
  8. package/dist/chunk-3PGQVQWG.js.map +1 -0
  9. package/dist/chunk-7QVYU63E.js +7 -0
  10. package/dist/chunk-7QVYU63E.js.map +1 -0
  11. package/dist/chunk-HLW7YKZE.js +99 -0
  12. package/dist/chunk-HLW7YKZE.js.map +1 -0
  13. package/dist/chunk-LKNI6QEP.js +20 -0
  14. package/dist/chunk-LKNI6QEP.js.map +1 -0
  15. package/dist/chunk-LWCNTZN6.js +87 -0
  16. package/dist/chunk-LWCNTZN6.js.map +1 -0
  17. package/dist/chunk-SMWUPP2C.js +125 -0
  18. package/dist/chunk-SMWUPP2C.js.map +1 -0
  19. package/dist/chunk-TBMGRXH5.js +477 -0
  20. package/dist/chunk-TBMGRXH5.js.map +1 -0
  21. package/dist/chunk-U46H4CGF.js +34 -0
  22. package/dist/chunk-U46H4CGF.js.map +1 -0
  23. package/dist/exception-filter-chain-BCSQ3MZ2.js +10 -0
  24. package/dist/exception-filter-chain-BCSQ3MZ2.js.map +1 -0
  25. package/dist/index.d.ts +1047 -0
  26. package/dist/index.js +761 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/interceptor-chain-6S3PUV7J.js +9 -0
  29. package/dist/interceptor-chain-6S3PUV7J.js.map +1 -0
  30. package/dist/middleware-consumer-ljxK1fU_.d.ts +58 -0
  31. package/dist/runtime-node.d.ts +21 -0
  32. package/dist/runtime-node.js +12 -0
  33. package/dist/runtime-node.js.map +1 -0
  34. package/dist/theokit-plugin.d.ts +65 -0
  35. package/dist/theokit-plugin.js +432 -0
  36. package/dist/theokit-plugin.js.map +1 -0
  37. package/dist/types-CGthbcon.d.ts +19 -0
  38. package/package.json +58 -0
@@ -0,0 +1,1047 @@
1
+ import { ZodTypeAny, z } from 'zod';
2
+ import { D as DiContainer, M as MiddlewareConsumerImpl } from './middleware-consumer-ljxK1fU_.js';
3
+ export { a as MiddlewareConfigProxy, b as MiddlewareFn, N as NestMiddleware, R as ResolvedMiddleware, m as middlewareMatchesPath, r as resolveOrNew, c as runMiddleware } from './middleware-consumer-ljxK1fU_.js';
4
+ import { S as ServerHandle } from './types-CGthbcon.js';
5
+ export { ReadinessCheck, TheoApp, TheoAppOptions } from './app.js';
6
+
7
+ interface ControllerOptions {
8
+ host?: string;
9
+ }
10
+ interface ControllerMeta {
11
+ prefix: string;
12
+ host?: string;
13
+ }
14
+ /**
15
+ * Class decorator that declares a route-prefix scope.
16
+ * Equivalent to NestJS's @Controller('prefix').
17
+ */
18
+ declare function Controller(prefix?: string, opts?: ControllerOptions): ClassDecorator;
19
+
20
+ type HttpVerb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'ALL';
21
+ interface RouteMethodEntry {
22
+ verb: HttpVerb;
23
+ path: string;
24
+ propertyKey: string | symbol;
25
+ }
26
+ declare const Get: (path?: string) => MethodDecorator;
27
+ declare const Post: (path?: string) => MethodDecorator;
28
+ declare const Put: (path?: string) => MethodDecorator;
29
+ declare const Patch: (path?: string) => MethodDecorator;
30
+ declare const Delete: (path?: string) => MethodDecorator;
31
+ declare const Options: (path?: string) => MethodDecorator;
32
+ declare const Head: (path?: string) => MethodDecorator;
33
+ declare const All: (path?: string) => MethodDecorator;
34
+
35
+ type ParamSource = 'req' | 'res' | 'body' | 'param' | 'query' | 'headers' | 'session' | 'ip' | 'host';
36
+ interface ParamEntry {
37
+ source: ParamSource;
38
+ key?: string;
39
+ index: number;
40
+ passthrough?: boolean;
41
+ /** Explicit Zod schema — when set, bypasses design:paramtypes + DTO resolution.
42
+ * Preferred path: `@Body(zMySchema)` works without emitDecoratorMetadata. */
43
+ schema?: ZodTypeAny;
44
+ }
45
+ declare const Req: (keyOrSchema?: string | ZodTypeAny) => ParameterDecorator;
46
+ declare const Body: (keyOrSchema?: string | ZodTypeAny) => ParameterDecorator;
47
+ declare const Param: (keyOrSchema?: string | ZodTypeAny) => ParameterDecorator;
48
+ declare const Query: (keyOrSchema?: string | ZodTypeAny) => ParameterDecorator;
49
+ declare const Headers: (keyOrSchema?: string | ZodTypeAny) => ParameterDecorator;
50
+ declare const Session: (keyOrSchema?: string | ZodTypeAny) => ParameterDecorator;
51
+ declare const Ip: (keyOrSchema?: string | ZodTypeAny) => ParameterDecorator;
52
+ declare const HostParam: (keyOrSchema?: string | ZodTypeAny) => ParameterDecorator;
53
+ declare function Res(opts?: {
54
+ passthrough?: boolean;
55
+ }): ParameterDecorator;
56
+
57
+ declare function HttpCode(status: number): MethodDecorator;
58
+ declare function Header(name: string, value: string): MethodDecorator;
59
+ interface RedirectMeta {
60
+ url: string;
61
+ status: number;
62
+ }
63
+ declare function Redirect(url: string, status?: number): MethodDecorator;
64
+
65
+ declare function UseGuards(...guards: Function[]): ClassDecorator & MethodDecorator;
66
+ declare function UseInterceptors(...interceptors: Function[]): ClassDecorator & MethodDecorator;
67
+ declare function UseFilters(...filters: Function[]): ClassDecorator & MethodDecorator;
68
+ /** @Catch(ExceptionType, ...) — marks which exception types an ExceptionFilter handles.
69
+ * Empty args = catch-all filter. */
70
+ declare function Catch(...exceptions: Function[]): ClassDecorator;
71
+
72
+ /**
73
+ * @SetMetadata + Reflector — NestJS-style custom metadata for guards.
74
+ *
75
+ * Enables role-based auth pattern:
76
+ * const Roles = createDecorator<string[]>()
77
+ * @Roles(['admin']) → guard reads via reflector.get(Roles, handler)
78
+ */
79
+
80
+ /** Unique key type for type-safe metadata decorators. */
81
+ type MetadataKey<T> = symbol & {
82
+ __type?: T;
83
+ };
84
+ declare function createDecorator<T>(): (value: T) => MethodDecorator & ClassDecorator;
85
+ /**
86
+ * Low-level @SetMetadata decorator — attaches arbitrary metadata.
87
+ * NestJS equivalent: `@SetMetadata(key, value)`.
88
+ *
89
+ * Prefer `createDecorator<T>()` for type-safe metadata.
90
+ */
91
+ declare function SetMetadata<T>(metaKey: string | symbol, value: T): MethodDecorator & ClassDecorator;
92
+ /**
93
+ * Reflector — reads metadata set by createDecorator or @SetMetadata.
94
+ * NestJS-compatible Reflector with getAllAndOverride/getAllAndMerge.
95
+ * HTTP-only per ADR D1.
96
+ */
97
+ declare class Reflector {
98
+ /**
99
+ * Read metadata set by a typed decorator created via createDecorator<T>().
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const Roles = createDecorator<string[]>()
104
+ * const reflector = new Reflector()
105
+ * const roles = reflector.get(Roles, handlerFn) // string[] | undefined
106
+ * ```
107
+ */
108
+ get<T>(decorator: (value: T) => MethodDecorator & ClassDecorator, target: Function, propertyKey?: string | symbol): T | undefined;
109
+ /**
110
+ * Read metadata set by @SetMetadata(key, value).
111
+ */
112
+ getByKey<T>(key: string | symbol, target: Function, propertyKey?: string | symbol): T | undefined;
113
+ /**
114
+ * Read metadata checking method-level first, then class-level.
115
+ * Returns the first non-undefined value found.
116
+ *
117
+ * NestJS equivalent: `reflector.getAllAndOverride(ROLES_KEY, [context.getHandler(), context.getClass()])`
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * const Roles = createDecorator<string[]>()
122
+ * // In a guard:
123
+ * const roles = reflector.getAllAndOverride(Roles, context.getClass(), context.getMethodName())
124
+ * // Checks method-level @Roles first, falls back to class-level @Roles
125
+ * ```
126
+ */
127
+ getAllAndOverride<T>(decorator: (value: T) => MethodDecorator & ClassDecorator, target: Function, propertyKey?: string | symbol): T | undefined;
128
+ /**
129
+ * Read metadata checking method-level first, then class-level, by raw key.
130
+ * Returns the first non-undefined value found.
131
+ */
132
+ getAllAndOverrideByKey<T>(key: string | symbol, target: Function, propertyKey?: string | symbol): T | undefined;
133
+ /**
134
+ * Read metadata from both method-level and class-level, merging arrays.
135
+ * Returns all found values as a flat array.
136
+ *
137
+ * NestJS equivalent: `reflector.getAllAndMerge(ROLES_KEY, [context.getHandler(), context.getClass()])`
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const Tags = createDecorator<string[]>()
142
+ *
143
+ * @Tags(['api'])
144
+ * @Controller('cats')
145
+ * class CatsCtrl {
146
+ * @Tags(['read'])
147
+ * @Get()
148
+ * findAll() {}
149
+ * }
150
+ *
151
+ * reflector.getAllAndMerge(Tags, CatsCtrl, 'findAll')
152
+ * // → ['read', 'api'] (method + class merged)
153
+ * ```
154
+ */
155
+ getAllAndMerge<T>(decorator: (value: T) => MethodDecorator & ClassDecorator, target: Function, propertyKey?: string | symbol): T extends (infer U)[] ? U[] : T[];
156
+ }
157
+
158
+ interface ThrottleOptions {
159
+ /** Maximum requests within the TTL window. */
160
+ limit: number;
161
+ /** Time-to-live in milliseconds. */
162
+ ttl: number;
163
+ /** Optional throttle set name (for multiple throttler definitions). */
164
+ name?: string;
165
+ }
166
+ /**
167
+ * Override the global rate limit for a controller or specific route.
168
+ * NestJS equivalent: `@Throttle({ default: { limit, ttl } })`.
169
+ */
170
+ declare function Throttle(options: ThrottleOptions): ClassDecorator & MethodDecorator;
171
+ /**
172
+ * Skip rate limiting for a controller or specific route.
173
+ * NestJS equivalent: `@SkipThrottle()`.
174
+ *
175
+ * @param skip — defaults to `true`. Pass `false` to re-enable on a
176
+ * specific route inside a skipped controller.
177
+ */
178
+ declare function SkipThrottle(skip?: boolean): ClassDecorator & MethodDecorator;
179
+ /**
180
+ * Read throttle metadata for a given class or method.
181
+ * Used by the rate-limit plugin to resolve per-route overrides.
182
+ */
183
+ declare function getThrottleOptions(target: Function, propertyKey?: string | symbol): ThrottleOptions | undefined;
184
+ /**
185
+ * Check if throttling is skipped for a given class or method.
186
+ */
187
+ declare function isThrottleSkipped(target: Function, propertyKey?: string | symbol): boolean;
188
+
189
+ /**
190
+ * Global Symbol-keyed metadata namespace constants for @theokit/http.
191
+ *
192
+ * Uses Symbol.for() (global Symbol registry) instead of Symbol() (local) because
193
+ * the SWC loader imports controller files as separate module instances. With local
194
+ * Symbols, the decorator-set metadata keys would be different Symbol instances from
195
+ * the keys used by walkControllerMetadata — making metadata lookup silently fail.
196
+ *
197
+ * Symbol.for() ensures the SAME Symbol instance across module boundaries, which is
198
+ * exactly how reflect-metadata keys should work in a multi-module decorator system.
199
+ */
200
+ declare const CONTROLLER_PREFIX: unique symbol;
201
+ declare const ROUTE_METHODS: unique symbol;
202
+ declare const ROUTE_PARAMS: unique symbol;
203
+ declare const ROUTE_STATUS: unique symbol;
204
+ declare const ROUTE_HEADERS: unique symbol;
205
+ declare const ROUTE_REDIRECT: unique symbol;
206
+ declare const USE_GUARDS: unique symbol;
207
+ declare const USE_INTERCEPTORS: unique symbol;
208
+ declare const USE_FILTERS: unique symbol;
209
+ declare const CATCH_EXCEPTIONS: unique symbol;
210
+
211
+ /**
212
+ * Typed facade over Reflect.defineMetadata / Reflect.getMetadata.
213
+ * Centralizes all reflect-metadata calls so decorators + bridge
214
+ * never call Reflect.* directly (single import point for the polyfill).
215
+ */
216
+ declare function setMeta<T>(key: symbol, target: object, value: T, propertyKey?: string | symbol): void;
217
+ declare function getMeta<T>(key: symbol, target: object, propertyKey?: string | symbol): T | undefined;
218
+
219
+ /**
220
+ * ExecutionContext — Web Standard Request-based context passed to guards.
221
+ *
222
+ * Per ADR D460: the pipeline operates on Web Standard Request/Response.
223
+ * node:http types live ONLY in the runtime adapter (runtime/node.ts).
224
+ *
225
+ * Guards access request headers via request.headers.get('x-role'),
226
+ * NOT via req.headers['x-role'].
227
+ */
228
+ /**
229
+ * Execution context available in guards during request processing.
230
+ * Uses Web Standard Request (works on Node, Bun, Deno, CF Workers).
231
+ */
232
+ interface ExecutionContext {
233
+ /** The Web Standard Request object. */
234
+ getRequest(): Request;
235
+ /** Parsed URL (convenience — avoids re-parsing). */
236
+ getUrl(): URL;
237
+ /** The controller class constructor. */
238
+ getClass(): Function;
239
+ /** The handler method name (property key on the controller). */
240
+ getMethodName(): string | symbol;
241
+ }
242
+ /**
243
+ * Interface for guard classes (bound via @UseGuards).
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * class RolesGuard implements CanActivate {
248
+ * canActivate(context: ExecutionContext): boolean {
249
+ * const request = context.getRequest()
250
+ * const role = request.headers.get('x-role')
251
+ * return role === 'admin'
252
+ * }
253
+ * }
254
+ * ```
255
+ */
256
+ interface CanActivate {
257
+ canActivate(context: ExecutionContext): boolean | Promise<boolean>;
258
+ }
259
+ /** Create an ExecutionContext from a Web Standard Request. */
260
+ declare function createExecutionContext(request: Request, controllerClass: Function, methodName: string | symbol): ExecutionContext;
261
+
262
+ /** Interface for exception filter classes (bound via @UseFilters). */
263
+ interface ExceptionFilter {
264
+ catch(exception: unknown, host: ArgumentsHost): Response | Promise<Response>;
265
+ }
266
+ /** ArgumentsHost — Web Standard. */
267
+ interface ArgumentsHost {
268
+ getRequest(): Request;
269
+ }
270
+ /**
271
+ * Run exception filters and return an error Response.
272
+ * Returns the filter's Response or a built-in fallback.
273
+ */
274
+ declare function runExceptionFilters(exception: unknown, filters: Function[], request: Request, container?: DiContainer): Promise<Response>;
275
+
276
+ /**
277
+ * Resolves a Zod schema from a DTO class via the `static schema` convention (Pattern D2).
278
+ * Returns undefined when the class doesn't carry a compatible schema.
279
+ */
280
+ declare function resolveDtoSchema(dtoClass: unknown): ZodTypeAny | undefined;
281
+
282
+ /**
283
+ * Configuration error thrown by the bridge when decorator setup is incomplete.
284
+ * Carries actionable messages pointing consumers to the migration guide.
285
+ */
286
+ declare class HttpDecoratorsConfigError extends Error {
287
+ readonly name = "HttpDecoratorsConfigError";
288
+ constructor(message: string);
289
+ }
290
+
291
+ /**
292
+ * Interceptor execution engine — onion-model chain runner.
293
+ *
294
+ * Per Pattern D3: "@UseInterceptors both translate to defineMiddleware wraps".
295
+ * Interceptors wrap the handler call (NOT body parsing — EC-1) and can
296
+ * transform the response or short-circuit by not calling next().
297
+ *
298
+ * Execution order follows NestJS convention:
299
+ * middleware → guards → interceptors → handler
300
+ * Interceptor composition: class-level FIRST, then method-level (EC-9).
301
+ */
302
+
303
+ /**
304
+ * Interceptor interface — Web Standard Request.
305
+ * `next()` wraps ONLY the handler call — body parsing happens before.
306
+ */
307
+ interface Interceptor {
308
+ intercept(request: Request, next: () => Promise<unknown>): Promise<unknown>;
309
+ }
310
+ /**
311
+ * Run the interceptor chain using the onion model.
312
+ * Outermost interceptor (first in array) wraps all inner ones.
313
+ */
314
+ declare function runInterceptors(interceptors: Function[], handler: () => Promise<unknown>, request: Request, container?: DiContainer): Promise<unknown>;
315
+
316
+ interface WalkResult {
317
+ verb: HttpVerb;
318
+ fullPath: string;
319
+ propertyKey: string | symbol;
320
+ bodySchema?: ZodTypeAny;
321
+ querySchema?: ZodTypeAny;
322
+ paramsSchema?: ZodTypeAny;
323
+ paramEntries: ParamEntry[];
324
+ status?: number;
325
+ headers: [string, string][];
326
+ redirect?: RedirectMeta;
327
+ guards: Function[];
328
+ interceptors: Function[];
329
+ filters: Function[];
330
+ }
331
+ /**
332
+ * Normalize a joined path: strip doubles, trim trailing, ensure leading.
333
+ * (EC-3)
334
+ */
335
+ declare function joinPath(prefix: string, path: string): string;
336
+ /**
337
+ * Walk all decorator metadata on a controller class and produce
338
+ * a structured list of route descriptors. Memoized per class via WeakMap.
339
+ */
340
+ declare function walkControllerMetadata(ControllerClass: Function): WalkResult[];
341
+
342
+ interface RouteRegistration {
343
+ verb: HttpVerb;
344
+ fullPath: string;
345
+ walkResult: WalkResult;
346
+ }
347
+ /**
348
+ * Low-level API: walks decorator metadata per controller class and returns
349
+ * structured route descriptors. Used internally by the Vite plugin (ADR D7)
350
+ * and available to advanced consumers who don't use Vite.
351
+ *
352
+ * EC-5: deduplicates by class reference; warns on duplicates.
353
+ */
354
+ declare function registerControllers(controllers: Function[]): RouteRegistration[];
355
+
356
+ /**
357
+ * Creates a real HTTP server from decorated controller classes.
358
+ * Uses Web Standard Request/Response internally; Node adapter at the boundary.
359
+ */
360
+ interface CreateDecoratorServerOptions {
361
+ controllers: Function[];
362
+ container?: DiContainer;
363
+ configure?: (consumer: MiddlewareConsumerImpl) => void;
364
+ }
365
+ declare function createDecoratorServer(controllersOrOpts: Function[] | CreateDecoratorServerOptions): ServerHandle;
366
+
367
+ /**
368
+ * HttpException hierarchy for @theokit/http.
369
+ *
370
+ * Per ADR D2: response shape {error: {code, message, statusCode}} matches
371
+ * existing guard (401) and validation (422) format.
372
+ */
373
+ interface HttpExceptionOptions {
374
+ cause?: Error;
375
+ description?: string;
376
+ }
377
+ declare class HttpException extends Error {
378
+ readonly statusCode: number;
379
+ readonly code: string;
380
+ readonly description?: string;
381
+ constructor(message: string, statusCode: number, options?: HttpExceptionOptions);
382
+ toJSON(): {
383
+ error: {
384
+ description?: string | undefined;
385
+ code: string;
386
+ message: string;
387
+ statusCode: number;
388
+ };
389
+ };
390
+ }
391
+ declare const BadRequestException_base: {
392
+ new (message?: string, options?: HttpExceptionOptions): {
393
+ readonly statusCode: number;
394
+ readonly code: string;
395
+ readonly description?: string;
396
+ toJSON(): {
397
+ error: {
398
+ description?: string | undefined;
399
+ code: string;
400
+ message: string;
401
+ statusCode: number;
402
+ };
403
+ };
404
+ name: string;
405
+ message: string;
406
+ stack?: string;
407
+ cause?: unknown;
408
+ };
409
+ isError(error: unknown): error is Error;
410
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
411
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
412
+ stackTraceLimit: number;
413
+ };
414
+ declare class BadRequestException extends BadRequestException_base {
415
+ }
416
+ declare const UnauthorizedException_base: {
417
+ new (message?: string, options?: HttpExceptionOptions): {
418
+ readonly statusCode: number;
419
+ readonly code: string;
420
+ readonly description?: string;
421
+ toJSON(): {
422
+ error: {
423
+ description?: string | undefined;
424
+ code: string;
425
+ message: string;
426
+ statusCode: number;
427
+ };
428
+ };
429
+ name: string;
430
+ message: string;
431
+ stack?: string;
432
+ cause?: unknown;
433
+ };
434
+ isError(error: unknown): error is Error;
435
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
436
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
437
+ stackTraceLimit: number;
438
+ };
439
+ declare class UnauthorizedException extends UnauthorizedException_base {
440
+ }
441
+ declare const ForbiddenException_base: {
442
+ new (message?: string, options?: HttpExceptionOptions): {
443
+ readonly statusCode: number;
444
+ readonly code: string;
445
+ readonly description?: string;
446
+ toJSON(): {
447
+ error: {
448
+ description?: string | undefined;
449
+ code: string;
450
+ message: string;
451
+ statusCode: number;
452
+ };
453
+ };
454
+ name: string;
455
+ message: string;
456
+ stack?: string;
457
+ cause?: unknown;
458
+ };
459
+ isError(error: unknown): error is Error;
460
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
461
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
462
+ stackTraceLimit: number;
463
+ };
464
+ declare class ForbiddenException extends ForbiddenException_base {
465
+ }
466
+ declare const NotFoundException_base: {
467
+ new (message?: string, options?: HttpExceptionOptions): {
468
+ readonly statusCode: number;
469
+ readonly code: string;
470
+ readonly description?: string;
471
+ toJSON(): {
472
+ error: {
473
+ description?: string | undefined;
474
+ code: string;
475
+ message: string;
476
+ statusCode: number;
477
+ };
478
+ };
479
+ name: string;
480
+ message: string;
481
+ stack?: string;
482
+ cause?: unknown;
483
+ };
484
+ isError(error: unknown): error is Error;
485
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
486
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
487
+ stackTraceLimit: number;
488
+ };
489
+ declare class NotFoundException extends NotFoundException_base {
490
+ }
491
+ declare const MethodNotAllowedException_base: {
492
+ new (message?: string, options?: HttpExceptionOptions): {
493
+ readonly statusCode: number;
494
+ readonly code: string;
495
+ readonly description?: string;
496
+ toJSON(): {
497
+ error: {
498
+ description?: string | undefined;
499
+ code: string;
500
+ message: string;
501
+ statusCode: number;
502
+ };
503
+ };
504
+ name: string;
505
+ message: string;
506
+ stack?: string;
507
+ cause?: unknown;
508
+ };
509
+ isError(error: unknown): error is Error;
510
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
511
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
512
+ stackTraceLimit: number;
513
+ };
514
+ declare class MethodNotAllowedException extends MethodNotAllowedException_base {
515
+ }
516
+ declare const NotAcceptableException_base: {
517
+ new (message?: string, options?: HttpExceptionOptions): {
518
+ readonly statusCode: number;
519
+ readonly code: string;
520
+ readonly description?: string;
521
+ toJSON(): {
522
+ error: {
523
+ description?: string | undefined;
524
+ code: string;
525
+ message: string;
526
+ statusCode: number;
527
+ };
528
+ };
529
+ name: string;
530
+ message: string;
531
+ stack?: string;
532
+ cause?: unknown;
533
+ };
534
+ isError(error: unknown): error is Error;
535
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
536
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
537
+ stackTraceLimit: number;
538
+ };
539
+ declare class NotAcceptableException extends NotAcceptableException_base {
540
+ }
541
+ declare const RequestTimeoutException_base: {
542
+ new (message?: string, options?: HttpExceptionOptions): {
543
+ readonly statusCode: number;
544
+ readonly code: string;
545
+ readonly description?: string;
546
+ toJSON(): {
547
+ error: {
548
+ description?: string | undefined;
549
+ code: string;
550
+ message: string;
551
+ statusCode: number;
552
+ };
553
+ };
554
+ name: string;
555
+ message: string;
556
+ stack?: string;
557
+ cause?: unknown;
558
+ };
559
+ isError(error: unknown): error is Error;
560
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
561
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
562
+ stackTraceLimit: number;
563
+ };
564
+ declare class RequestTimeoutException extends RequestTimeoutException_base {
565
+ }
566
+ declare const ConflictException_base: {
567
+ new (message?: string, options?: HttpExceptionOptions): {
568
+ readonly statusCode: number;
569
+ readonly code: string;
570
+ readonly description?: string;
571
+ toJSON(): {
572
+ error: {
573
+ description?: string | undefined;
574
+ code: string;
575
+ message: string;
576
+ statusCode: number;
577
+ };
578
+ };
579
+ name: string;
580
+ message: string;
581
+ stack?: string;
582
+ cause?: unknown;
583
+ };
584
+ isError(error: unknown): error is Error;
585
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
586
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
587
+ stackTraceLimit: number;
588
+ };
589
+ declare class ConflictException extends ConflictException_base {
590
+ }
591
+ declare const GoneException_base: {
592
+ new (message?: string, options?: HttpExceptionOptions): {
593
+ readonly statusCode: number;
594
+ readonly code: string;
595
+ readonly description?: string;
596
+ toJSON(): {
597
+ error: {
598
+ description?: string | undefined;
599
+ code: string;
600
+ message: string;
601
+ statusCode: number;
602
+ };
603
+ };
604
+ name: string;
605
+ message: string;
606
+ stack?: string;
607
+ cause?: unknown;
608
+ };
609
+ isError(error: unknown): error is Error;
610
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
611
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
612
+ stackTraceLimit: number;
613
+ };
614
+ declare class GoneException extends GoneException_base {
615
+ }
616
+ declare const PreconditionFailedException_base: {
617
+ new (message?: string, options?: HttpExceptionOptions): {
618
+ readonly statusCode: number;
619
+ readonly code: string;
620
+ readonly description?: string;
621
+ toJSON(): {
622
+ error: {
623
+ description?: string | undefined;
624
+ code: string;
625
+ message: string;
626
+ statusCode: number;
627
+ };
628
+ };
629
+ name: string;
630
+ message: string;
631
+ stack?: string;
632
+ cause?: unknown;
633
+ };
634
+ isError(error: unknown): error is Error;
635
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
636
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
637
+ stackTraceLimit: number;
638
+ };
639
+ declare class PreconditionFailedException extends PreconditionFailedException_base {
640
+ }
641
+ declare const PayloadTooLargeException_base: {
642
+ new (message?: string, options?: HttpExceptionOptions): {
643
+ readonly statusCode: number;
644
+ readonly code: string;
645
+ readonly description?: string;
646
+ toJSON(): {
647
+ error: {
648
+ description?: string | undefined;
649
+ code: string;
650
+ message: string;
651
+ statusCode: number;
652
+ };
653
+ };
654
+ name: string;
655
+ message: string;
656
+ stack?: string;
657
+ cause?: unknown;
658
+ };
659
+ isError(error: unknown): error is Error;
660
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
661
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
662
+ stackTraceLimit: number;
663
+ };
664
+ declare class PayloadTooLargeException extends PayloadTooLargeException_base {
665
+ }
666
+ declare const UnsupportedMediaTypeException_base: {
667
+ new (message?: string, options?: HttpExceptionOptions): {
668
+ readonly statusCode: number;
669
+ readonly code: string;
670
+ readonly description?: string;
671
+ toJSON(): {
672
+ error: {
673
+ description?: string | undefined;
674
+ code: string;
675
+ message: string;
676
+ statusCode: number;
677
+ };
678
+ };
679
+ name: string;
680
+ message: string;
681
+ stack?: string;
682
+ cause?: unknown;
683
+ };
684
+ isError(error: unknown): error is Error;
685
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
686
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
687
+ stackTraceLimit: number;
688
+ };
689
+ declare class UnsupportedMediaTypeException extends UnsupportedMediaTypeException_base {
690
+ }
691
+ declare const ImATeapotException_base: {
692
+ new (message?: string, options?: HttpExceptionOptions): {
693
+ readonly statusCode: number;
694
+ readonly code: string;
695
+ readonly description?: string;
696
+ toJSON(): {
697
+ error: {
698
+ description?: string | undefined;
699
+ code: string;
700
+ message: string;
701
+ statusCode: number;
702
+ };
703
+ };
704
+ name: string;
705
+ message: string;
706
+ stack?: string;
707
+ cause?: unknown;
708
+ };
709
+ isError(error: unknown): error is Error;
710
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
711
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
712
+ stackTraceLimit: number;
713
+ };
714
+ declare class ImATeapotException extends ImATeapotException_base {
715
+ }
716
+ declare const UnprocessableEntityException_base: {
717
+ new (message?: string, options?: HttpExceptionOptions): {
718
+ readonly statusCode: number;
719
+ readonly code: string;
720
+ readonly description?: string;
721
+ toJSON(): {
722
+ error: {
723
+ description?: string | undefined;
724
+ code: string;
725
+ message: string;
726
+ statusCode: number;
727
+ };
728
+ };
729
+ name: string;
730
+ message: string;
731
+ stack?: string;
732
+ cause?: unknown;
733
+ };
734
+ isError(error: unknown): error is Error;
735
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
736
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
737
+ stackTraceLimit: number;
738
+ };
739
+ declare class UnprocessableEntityException extends UnprocessableEntityException_base {
740
+ }
741
+ declare const InternalServerErrorException_base: {
742
+ new (message?: string, options?: HttpExceptionOptions): {
743
+ readonly statusCode: number;
744
+ readonly code: string;
745
+ readonly description?: string;
746
+ toJSON(): {
747
+ error: {
748
+ description?: string | undefined;
749
+ code: string;
750
+ message: string;
751
+ statusCode: number;
752
+ };
753
+ };
754
+ name: string;
755
+ message: string;
756
+ stack?: string;
757
+ cause?: unknown;
758
+ };
759
+ isError(error: unknown): error is Error;
760
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
761
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
762
+ stackTraceLimit: number;
763
+ };
764
+ declare class InternalServerErrorException extends InternalServerErrorException_base {
765
+ }
766
+ declare const NotImplementedException_base: {
767
+ new (message?: string, options?: HttpExceptionOptions): {
768
+ readonly statusCode: number;
769
+ readonly code: string;
770
+ readonly description?: string;
771
+ toJSON(): {
772
+ error: {
773
+ description?: string | undefined;
774
+ code: string;
775
+ message: string;
776
+ statusCode: number;
777
+ };
778
+ };
779
+ name: string;
780
+ message: string;
781
+ stack?: string;
782
+ cause?: unknown;
783
+ };
784
+ isError(error: unknown): error is Error;
785
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
786
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
787
+ stackTraceLimit: number;
788
+ };
789
+ declare class NotImplementedException extends NotImplementedException_base {
790
+ }
791
+ declare const BadGatewayException_base: {
792
+ new (message?: string, options?: HttpExceptionOptions): {
793
+ readonly statusCode: number;
794
+ readonly code: string;
795
+ readonly description?: string;
796
+ toJSON(): {
797
+ error: {
798
+ description?: string | undefined;
799
+ code: string;
800
+ message: string;
801
+ statusCode: number;
802
+ };
803
+ };
804
+ name: string;
805
+ message: string;
806
+ stack?: string;
807
+ cause?: unknown;
808
+ };
809
+ isError(error: unknown): error is Error;
810
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
811
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
812
+ stackTraceLimit: number;
813
+ };
814
+ declare class BadGatewayException extends BadGatewayException_base {
815
+ }
816
+ declare const ServiceUnavailableException_base: {
817
+ new (message?: string, options?: HttpExceptionOptions): {
818
+ readonly statusCode: number;
819
+ readonly code: string;
820
+ readonly description?: string;
821
+ toJSON(): {
822
+ error: {
823
+ description?: string | undefined;
824
+ code: string;
825
+ message: string;
826
+ statusCode: number;
827
+ };
828
+ };
829
+ name: string;
830
+ message: string;
831
+ stack?: string;
832
+ cause?: unknown;
833
+ };
834
+ isError(error: unknown): error is Error;
835
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
836
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
837
+ stackTraceLimit: number;
838
+ };
839
+ declare class ServiceUnavailableException extends ServiceUnavailableException_base {
840
+ }
841
+ declare const GatewayTimeoutException_base: {
842
+ new (message?: string, options?: HttpExceptionOptions): {
843
+ readonly statusCode: number;
844
+ readonly code: string;
845
+ readonly description?: string;
846
+ toJSON(): {
847
+ error: {
848
+ description?: string | undefined;
849
+ code: string;
850
+ message: string;
851
+ statusCode: number;
852
+ };
853
+ };
854
+ name: string;
855
+ message: string;
856
+ stack?: string;
857
+ cause?: unknown;
858
+ };
859
+ isError(error: unknown): error is Error;
860
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
861
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
862
+ stackTraceLimit: number;
863
+ };
864
+ declare class GatewayTimeoutException extends GatewayTimeoutException_base {
865
+ }
866
+ declare const HttpVersionNotSupportedException_base: {
867
+ new (message?: string, options?: HttpExceptionOptions): {
868
+ readonly statusCode: number;
869
+ readonly code: string;
870
+ readonly description?: string;
871
+ toJSON(): {
872
+ error: {
873
+ description?: string | undefined;
874
+ code: string;
875
+ message: string;
876
+ statusCode: number;
877
+ };
878
+ };
879
+ name: string;
880
+ message: string;
881
+ stack?: string;
882
+ cause?: unknown;
883
+ };
884
+ isError(error: unknown): error is Error;
885
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
886
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
887
+ stackTraceLimit: number;
888
+ };
889
+ declare class HttpVersionNotSupportedException extends HttpVersionNotSupportedException_base {
890
+ }
891
+ declare const TooManyRequestsException_base: {
892
+ new (message?: string, options?: HttpExceptionOptions): {
893
+ readonly statusCode: number;
894
+ readonly code: string;
895
+ readonly description?: string;
896
+ toJSON(): {
897
+ error: {
898
+ description?: string | undefined;
899
+ code: string;
900
+ message: string;
901
+ statusCode: number;
902
+ };
903
+ };
904
+ name: string;
905
+ message: string;
906
+ stack?: string;
907
+ cause?: unknown;
908
+ };
909
+ isError(error: unknown): error is Error;
910
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
911
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
912
+ stackTraceLimit: number;
913
+ };
914
+ declare class TooManyRequestsException extends TooManyRequestsException_base {
915
+ }
916
+ /**
917
+ * HttpStatus enum — all standard HTTP status codes as named constants.
918
+ *
919
+ * @example
920
+ * ```ts
921
+ * import { HttpStatus } from '@theokit/http'
922
+ *
923
+ * @HttpCode(HttpStatus.CREATED)
924
+ * @Post()
925
+ * create() { ... }
926
+ *
927
+ * if (res.status === HttpStatus.NOT_FOUND) { ... }
928
+ * ```
929
+ */
930
+ declare const HttpStatus: {
931
+ readonly OK: 200;
932
+ readonly CREATED: 201;
933
+ readonly ACCEPTED: 202;
934
+ readonly NO_CONTENT: 204;
935
+ readonly MOVED_PERMANENTLY: 301;
936
+ readonly FOUND: 302;
937
+ readonly NOT_MODIFIED: 304;
938
+ readonly TEMPORARY_REDIRECT: 307;
939
+ readonly PERMANENT_REDIRECT: 308;
940
+ readonly BAD_REQUEST: 400;
941
+ readonly UNAUTHORIZED: 401;
942
+ readonly PAYMENT_REQUIRED: 402;
943
+ readonly FORBIDDEN: 403;
944
+ readonly NOT_FOUND: 404;
945
+ readonly METHOD_NOT_ALLOWED: 405;
946
+ readonly NOT_ACCEPTABLE: 406;
947
+ readonly REQUEST_TIMEOUT: 408;
948
+ readonly CONFLICT: 409;
949
+ readonly GONE: 410;
950
+ readonly PRECONDITION_FAILED: 412;
951
+ readonly PAYLOAD_TOO_LARGE: 413;
952
+ readonly UNSUPPORTED_MEDIA_TYPE: 415;
953
+ readonly IM_A_TEAPOT: 418;
954
+ readonly UNPROCESSABLE_ENTITY: 422;
955
+ readonly TOO_MANY_REQUESTS: 429;
956
+ readonly INTERNAL_SERVER_ERROR: 500;
957
+ readonly NOT_IMPLEMENTED: 501;
958
+ readonly BAD_GATEWAY: 502;
959
+ readonly SERVICE_UNAVAILABLE: 503;
960
+ readonly GATEWAY_TIMEOUT: 504;
961
+ };
962
+ type HttpStatusCode = (typeof HttpStatus)[keyof typeof HttpStatus];
963
+
964
+ /**
965
+ * Typed Client — end-to-end type inference from route contracts.
966
+ *
967
+ * Zero codegen, zero runtime overhead on types. The developer defines
968
+ * a route map using `contract()`, and `createTypedClient<T>()` infers
969
+ * request body + response types automatically.
970
+ */
971
+
972
+ interface RouteDefinition {
973
+ body?: z.ZodType;
974
+ params?: Record<string, 'string' | 'number'>;
975
+ query?: Record<string, 'string' | 'number' | 'boolean'>;
976
+ response: unknown;
977
+ }
978
+ type RouteMap = Record<string, RouteDefinition>;
979
+ type InferBody<D> = D extends {
980
+ body: z.ZodType;
981
+ } ? z.infer<D['body']> : never;
982
+ type InferResponse<D> = D extends {
983
+ response: infer R;
984
+ } ? R : unknown;
985
+ interface TypedClient<M extends RouteMap> {
986
+ get<P extends string & keyof M>(path: P, opts?: {
987
+ query?: Record<string, string>;
988
+ headers?: Record<string, string>;
989
+ }): Promise<InferResponse<M[`GET ${P}`] extends never ? M[P] : M[`GET ${P}`]>>;
990
+ post<P extends string>(path: P, body?: InferBody<M[`POST ${P}`]>, opts?: {
991
+ headers?: Record<string, string>;
992
+ }): Promise<InferResponse<M[`POST ${P}`]>>;
993
+ put<P extends string>(path: P, body?: InferBody<M[`PUT ${P}`]>, opts?: {
994
+ headers?: Record<string, string>;
995
+ }): Promise<InferResponse<M[`PUT ${P}`]>>;
996
+ delete<P extends string>(path: P, opts?: {
997
+ headers?: Record<string, string>;
998
+ }): Promise<InferResponse<M[`DELETE ${P}`]>>;
999
+ }
1000
+ declare function createTypedClient<M extends RouteMap>(baseUrl: string, defaultHeaders?: Record<string, string>): TypedClient<M>;
1001
+ declare class TypedClientError extends Error {
1002
+ readonly status: number;
1003
+ readonly body: Record<string, unknown>;
1004
+ constructor(status: number, body: Record<string, unknown>);
1005
+ }
1006
+
1007
+ /**
1008
+ * Route Contract — type-level bridge between @Controller and TypedClient.
1009
+ *
1010
+ * The developer defines a contract object mapping routes to their types.
1011
+ * This object is the single source of truth for both server validation
1012
+ * and client type inference.
1013
+ *
1014
+ * @example
1015
+ * ```ts
1016
+ * // server/contracts.ts — shared between server and client
1017
+ * import { z } from 'zod'
1018
+ * import { contract } from '@theokit/http'
1019
+ *
1020
+ * export const zCreateTask = z.object({
1021
+ * title: z.string().min(3),
1022
+ * priority: z.enum(['low', 'medium', 'high']).default('medium'),
1023
+ * })
1024
+ *
1025
+ * export interface Task { id: number; title: string; priority: string; done: boolean }
1026
+ *
1027
+ * export const routes = contract({
1028
+ * 'GET /api/tasks': { response: [] as Task[] },
1029
+ * 'GET /api/tasks/:id': { response: {} as Task },
1030
+ * 'POST /api/tasks': { body: zCreateTask, response: {} as Task },
1031
+ * 'PUT /api/tasks/:id': { body: z.object({ done: z.boolean() }), response: {} as Task },
1032
+ * 'DELETE /api/tasks/:id': { response: undefined as void },
1033
+ * })
1034
+ * export type AppRoutes = typeof routes
1035
+ * ```
1036
+ *
1037
+ * The `contract()` function is identity at runtime (zero overhead) but
1038
+ * enforces the RouteMap type at the type level, enabling full inference.
1039
+ */
1040
+
1041
+ /**
1042
+ * Identity function that enforces RouteMap type constraint.
1043
+ * Zero runtime overhead — exists only for type inference.
1044
+ */
1045
+ declare function contract<T extends RouteMap>(routes: T): T;
1046
+
1047
+ export { All, type ArgumentsHost, BadGatewayException, BadRequestException, Body, CATCH_EXCEPTIONS, CONTROLLER_PREFIX, type CanActivate, Catch, ConflictException, Controller, type ControllerMeta, type ControllerOptions, Delete, DiContainer, type ExceptionFilter, type ExecutionContext, ForbiddenException, GatewayTimeoutException, Get, GoneException, Head, Header, Headers, HostParam, HttpCode, HttpDecoratorsConfigError, HttpException, type HttpExceptionOptions, HttpStatus, type HttpStatusCode, type HttpVerb, HttpVersionNotSupportedException, ImATeapotException, type Interceptor, InternalServerErrorException, Ip, type MetadataKey, MethodNotAllowedException, MiddlewareConsumerImpl, NotAcceptableException, NotFoundException, NotImplementedException, Options, Param, type ParamEntry, type ParamSource, Patch, PayloadTooLargeException, Post, PreconditionFailedException, Put, Query, ROUTE_HEADERS, ROUTE_METHODS, ROUTE_PARAMS, ROUTE_REDIRECT, ROUTE_STATUS, Redirect, type RedirectMeta, Reflector, Req, RequestTimeoutException, Res, type RouteDefinition, type RouteMap, type RouteMethodEntry, type RouteRegistration, ServiceUnavailableException, Session, SetMetadata, SkipThrottle, Throttle, type ThrottleOptions, TooManyRequestsException, type TypedClient, TypedClientError, USE_FILTERS, USE_GUARDS, USE_INTERCEPTORS, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, UseFilters, UseGuards, UseInterceptors, type WalkResult, contract, createDecorator, createDecoratorServer, createExecutionContext, createTypedClient, getMeta, getThrottleOptions, isThrottleSkipped, joinPath, registerControllers, resolveDtoSchema, runExceptionFilters, runInterceptors, setMeta, walkControllerMetadata };