@adonisjs/http-server 8.0.0-next.5 → 8.0.0-next.7

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 (56) hide show
  1. package/build/{chunk-BFGF3A5X.js → chunk-3XEJZ4S4.js} +1105 -566
  2. package/build/{chunk-ASX56VAK.js → chunk-NQNHMINZ.js} +59 -0
  3. package/build/factories/http_context.d.ts +2 -1
  4. package/build/factories/http_server.d.ts +7 -0
  5. package/build/factories/main.js +31 -5
  6. package/build/factories/qs_parser_factory.d.ts +3 -2
  7. package/build/factories/request.d.ts +1 -0
  8. package/build/factories/response.d.ts +1 -0
  9. package/build/factories/router.d.ts +1 -0
  10. package/build/factories/server_factory.d.ts +1 -0
  11. package/build/factories/url_builder_factory.d.ts +1 -0
  12. package/build/index.d.ts +3 -1
  13. package/build/index.js +87 -37
  14. package/build/src/cookies/client.d.ts +35 -0
  15. package/build/src/cookies/drivers/encrypted.d.ts +13 -0
  16. package/build/src/cookies/drivers/plain.d.ts +9 -0
  17. package/build/src/cookies/drivers/signed.d.ts +13 -0
  18. package/build/src/cookies/parser.d.ts +18 -0
  19. package/build/src/cookies/serializer.d.ts +21 -2
  20. package/build/src/define_config.d.ts +1 -3
  21. package/build/src/define_middleware.d.ts +1 -1
  22. package/build/src/exception_handler.d.ts +72 -31
  23. package/build/src/helpers.d.ts +50 -0
  24. package/build/src/helpers.js +5 -1
  25. package/build/src/http_context/local_storage.d.ts +17 -0
  26. package/build/src/http_context/main.d.ts +8 -0
  27. package/build/src/qs.d.ts +14 -0
  28. package/build/src/redirect.d.ts +62 -9
  29. package/build/src/request.d.ts +109 -10
  30. package/build/src/response.d.ts +416 -203
  31. package/build/src/router/brisk.d.ts +13 -0
  32. package/build/src/router/executor.d.ts +4 -0
  33. package/build/src/router/factories/use_return_value.d.ts +5 -0
  34. package/build/src/router/group.d.ts +18 -1
  35. package/build/src/router/legacy/url_builder.d.ts +14 -14
  36. package/build/src/router/main.d.ts +73 -4
  37. package/build/src/router/matchers.d.ts +3 -0
  38. package/build/src/router/resource.d.ts +34 -1
  39. package/build/src/router/route.d.ts +9 -1
  40. package/build/src/router/signed_url_builder.d.ts +4 -8
  41. package/build/src/router/store.d.ts +9 -0
  42. package/build/src/router/url_builder.d.ts +4 -9
  43. package/build/src/server/factories/middleware_handler.d.ts +10 -1
  44. package/build/src/server/factories/route_finder.d.ts +13 -3
  45. package/build/src/server/factories/write_response.d.ts +9 -2
  46. package/build/src/server/main.d.ts +77 -23
  47. package/build/src/tracing_channels.d.ts +4 -4
  48. package/build/src/types/middleware.d.ts +34 -9
  49. package/build/src/types/qs.d.ts +5 -0
  50. package/build/src/types/request.d.ts +1 -1
  51. package/build/src/types/response.d.ts +14 -6
  52. package/build/src/types/route.d.ts +40 -19
  53. package/build/src/types/server.d.ts +26 -11
  54. package/build/src/types/tracing_channels.d.ts +21 -3
  55. package/build/src/types/url_builder.d.ts +24 -11
  56. package/package.json +17 -15
@@ -15,25 +15,42 @@ import type { HttpContext } from './http_context/main.ts';
15
15
  */
16
16
  export declare class Request extends Macroable {
17
17
  #private;
18
+ /** Native Node.js incoming message instance */
18
19
  request: IncomingMessage;
20
+ /** Native Node.js server response instance */
19
21
  response: ServerResponse;
20
22
  /**
21
- * Parsed URL with query string stored as a string.
23
+ * Parsed URL with query string stored as a string and decode flag
22
24
  */
23
25
  parsedUrl: {
26
+ /** The pathname portion of the URL */
24
27
  pathname: string;
28
+ /** The query string portion of the URL */
25
29
  query: string;
30
+ /** Flag indicating whether parameters should be decoded */
26
31
  shouldDecodeParam: boolean;
27
32
  };
28
33
  /**
29
- * The ctx will be set by the context itself. It creates a circular
30
- * reference
34
+ * HTTP context reference - creates a circular reference when set by the context
31
35
  */
32
36
  ctx?: HttpContext;
33
- constructor(request: IncomingMessage, response: ServerResponse, encryption: Encryption, config: RequestConfig, qsParser: Qs);
37
+ /**
38
+ * Creates a new Request instance wrapping the native Node.js HTTP request
39
+ * @param request - Native Node.js incoming message instance
40
+ * @param response - Native Node.js server response instance
41
+ * @param encryption - Encryption module for cookie and URL signing
42
+ * @param config - Request configuration options
43
+ * @param qsParser - Query string parser instance
44
+ */
45
+ constructor(
46
+ /** Native Node.js incoming message instance */
47
+ request: IncomingMessage,
48
+ /** Native Node.js server response instance */
49
+ response: ServerResponse, encryption: Encryption, config: RequestConfig, qsParser: Qs);
34
50
  /**
35
51
  * Returns the request id from the `x-request-id` header. The
36
52
  * header is untouched, if it already exists.
53
+ * @returns The request ID or undefined if not found/generated
37
54
  */
38
55
  id(): string | undefined;
39
56
  /**
@@ -43,44 +60,57 @@ export declare class Request extends Macroable {
43
60
  *
44
61
  * This method is supposed to be invoked by the body parser and must be called only
45
62
  * once. For further mutations make use of `updateBody` method.
63
+ * @param body - Parsed request body data
64
+ * @returns {void}
46
65
  */
47
66
  setInitialBody(body: Record<string, any>): void;
48
67
  /**
49
68
  * Update the request body with new data object. The `all` property
50
69
  * will be re-computed by merging the query string and request
51
70
  * body.
71
+ * @param body - New request body data to set
72
+ * @returns {void}
52
73
  */
53
74
  updateBody(body: Record<string, any>): void;
54
75
  /**
55
76
  * Update the request raw body. Bodyparser sets this when unable to parse
56
77
  * the request body or when request is multipart/form-data.
78
+ * @param rawBody - Raw request body as string
79
+ * @returns {void}
57
80
  */
58
81
  updateRawBody(rawBody: string): void;
59
82
  /**
60
83
  * Update the query string with the new data object. The `all` property
61
84
  * will be re-computed by merging the query and the request body.
85
+ * @param data - New query string data to set
86
+ * @returns {void}
62
87
  */
63
88
  updateQs(data: Record<string, any>): void;
64
89
  /**
65
90
  * Returns route params
91
+ * @returns {Record<string, any>} Object containing route parameters
66
92
  */
67
93
  params(): Record<string, any>;
68
94
  /**
69
95
  * Returns the query string object by reference
96
+ * @returns {Record<string, any>} Object containing parsed query string parameters
70
97
  */
71
98
  qs(): Record<string, any>;
72
99
  /**
73
100
  * Returns reference to the request body
101
+ * @returns {Record<string, any>} Object containing parsed request body
74
102
  */
75
103
  body(): Record<string, any>;
76
104
  /**
77
105
  * Returns reference to the merged copy of request body
78
106
  * and query string
107
+ * @returns {Record<string, any>} Object containing merged request body and query parameters
79
108
  */
80
109
  all(): Record<string, any>;
81
110
  /**
82
111
  * Returns reference to the merged copy of original request
83
112
  * query string and body
113
+ * @returns {Record<string, any>} Object containing original merged request data
84
114
  */
85
115
  original(): Record<string, any>;
86
116
  /**
@@ -88,6 +118,7 @@ export declare class Request extends Macroable {
88
118
  *
89
119
  * Ideally you must be dealing with the parsed body accessed using [[input]], [[all]] or
90
120
  * [[post]] methods. The `raw` body is always a string.
121
+ * @returns {string | null} Raw request body as string or null if not set
91
122
  */
92
123
  raw(): string | null;
93
124
  /**
@@ -101,6 +132,9 @@ export declare class Request extends Macroable {
101
132
  * // with default value
102
133
  * request.input('username', 'virk')
103
134
  * ```
135
+ * @param key - Key to lookup in request data
136
+ * @param defaultValue - Default value when key is not found
137
+ * @returns Value from request data or default value
104
138
  */
105
139
  input(key: string, defaultValue?: any): any;
106
140
  /**
@@ -113,6 +147,9 @@ export declare class Request extends Macroable {
113
147
  * // with default value
114
148
  * request.param('id', 1)
115
149
  * ```
150
+ * @param key - Parameter key to lookup
151
+ * @param defaultValue - Default value when parameter is not found
152
+ * @returns Value from route parameters or default value
116
153
  */
117
154
  param(key: string, defaultValue?: any): any;
118
155
  /**
@@ -122,6 +159,8 @@ export declare class Request extends Macroable {
122
159
  * ```js
123
160
  * request.except(['_csrf'])
124
161
  * ```
162
+ * @param keys - Array of keys to exclude from the result
163
+ * @returns {Record<string, any>} Object with all request data except specified keys
125
164
  */
126
165
  except(keys: string[]): Record<string, any>;
127
166
  /**
@@ -131,6 +170,8 @@ export declare class Request extends Macroable {
131
170
  * ```js
132
171
  * request.only(['username', 'age'])
133
172
  * ```
173
+ * @param keys - Array of keys to include in the result
174
+ * @returns {{ [K in T]: any }} Object with only the specified keys from request data
134
175
  */
135
176
  only<T extends string>(keys: T[]): {
136
177
  [K in T]: any;
@@ -144,6 +185,7 @@ export declare class Request extends Macroable {
144
185
  * ```js
145
186
  * request.intended()
146
187
  * ```
188
+ * @returns {string} Original HTTP method from the request
147
189
  */
148
190
  intended(): string;
149
191
  /**
@@ -159,15 +201,20 @@ export declare class Request extends Macroable {
159
201
  * ```js
160
202
  * request.method()
161
203
  * ```
204
+ * @returns {string} HTTP method (potentially spoofed)
162
205
  */
163
206
  method(): string;
164
207
  /**
165
208
  * Returns a copy of headers as an object
209
+ * @returns {IncomingHttpHeaders} Object containing all HTTP headers
166
210
  */
167
211
  headers(): IncomingHttpHeaders;
168
212
  /**
169
213
  * Returns value for a given header key. The default value is
170
214
  * used when original value is `undefined`.
215
+ * @param key - Header name to lookup
216
+ * @param defaultValue - Default value when header is not found
217
+ * @returns {string | undefined} Header value or default value if not found
171
218
  */
172
219
  header(key: string, defaultValue?: any): string | undefined;
173
220
  /**
@@ -200,6 +247,7 @@ export declare class Request extends Macroable {
200
247
  * ```
201
248
  *
202
249
  * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
250
+ * @returns {string} Client IP address
203
251
  */
204
252
  ip(): string;
205
253
  /**
@@ -219,6 +267,7 @@ export declare class Request extends Macroable {
219
267
  * ```
220
268
  *
221
269
  * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
270
+ * @returns {string[]} Array of IP addresses from most to least trusted
222
271
  */
223
272
  ips(): string[];
224
273
  /**
@@ -240,12 +289,14 @@ export declare class Request extends Macroable {
240
289
  * ```
241
290
  *
242
291
  * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
292
+ * @returns {string} Request protocol ('http' or 'https')
243
293
  */
244
294
  protocol(): string;
245
295
  /**
246
296
  * Returns a boolean telling if request is served over `https`
247
297
  * or not. Check [[protocol]] method to know how protocol is
248
298
  * fetched.
299
+ * @returns {boolean} True if request is served over HTTPS
249
300
  */
250
301
  secure(): boolean;
251
302
  /**
@@ -264,6 +315,7 @@ export declare class Request extends Macroable {
264
315
  * ```
265
316
  *
266
317
  * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
318
+ * @returns {string | null} Request host or null if not found
267
319
  */
268
320
  host(): string | null;
269
321
  /**
@@ -282,6 +334,7 @@ export declare class Request extends Macroable {
282
334
  * ```
283
335
  *
284
336
  * The value of trustProxy is passed directly to [proxy-addr](https://www.npmjs.com/package/proxy-addr)
337
+ * @returns {string | null} Request hostname (without port) or null if not found
285
338
  */
286
339
  hostname(): string | null;
287
340
  /**
@@ -289,16 +342,19 @@ export declare class Request extends Macroable {
289
342
  * returned if [[hostname]] is `null` or is an IP address.
290
343
  *
291
344
  * Also `www` is not considered as a subdomain
345
+ * @returns {string[]} Array of subdomains (excluding www)
292
346
  */
293
347
  subdomains(): string[];
294
348
  /**
295
349
  * Returns a boolean telling, if request `X-Requested-With === 'xmlhttprequest'`
296
350
  * or not.
351
+ * @returns {boolean} True if request is an AJAX request
297
352
  */
298
353
  ajax(): boolean;
299
354
  /**
300
355
  * Returns a boolean telling, if request has `X-Pjax` header
301
356
  * set or not
357
+ * @returns {boolean} True if request is a PJAX request
302
358
  */
303
359
  pjax(): boolean;
304
360
  /**
@@ -311,6 +367,8 @@ export declare class Request extends Macroable {
311
367
  * // include query string
312
368
  * request.url(true)
313
369
  * ```
370
+ * @param includeQueryString - Whether to include query string in the URL
371
+ * @returns {string} Request pathname, optionally with query string
314
372
  */
315
373
  url(includeQueryString?: boolean): string;
316
374
  /**
@@ -324,10 +382,14 @@ export declare class Request extends Macroable {
324
382
  * // include query string
325
383
  * request.completeUrl(true)
326
384
  * ```
385
+ * @param includeQueryString - Whether to include query string in the URL
386
+ * @returns {string} Complete URL including protocol and host
327
387
  */
328
388
  completeUrl(includeQueryString?: boolean): string;
329
389
  /**
330
390
  * Find if the current HTTP request is for the given route or the routes
391
+ * @param routeIdentifier - Route name, pattern, or handler reference to match
392
+ * @returns {boolean} True if the request matches any of the given route identifiers
331
393
  */
332
394
  matchesRoute(routeIdentifier: string | string[]): boolean;
333
395
  /**
@@ -357,6 +419,8 @@ export declare class Request extends Macroable {
357
419
  * // process XML
358
420
  * }
359
421
  * ```
422
+ * @param types - Array of content types to match against
423
+ * @returns {string | null} Best matching content type or null if no match
360
424
  */
361
425
  is(types: string[]): string | null;
362
426
  /**
@@ -379,6 +443,8 @@ export declare class Request extends Macroable {
379
443
  * // decide yourself
380
444
  * }
381
445
  * ```
446
+ * @param types - Array of types to match against Accept header
447
+ * @returns {T | null} Best matching accept type or null if no match
382
448
  */
383
449
  accepts<T extends string>(types: T[]): T | null;
384
450
  /**
@@ -387,6 +453,7 @@ export declare class Request extends Macroable {
387
453
  *
388
454
  * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
389
455
  * docs too.
456
+ * @returns {string[]} Array of accepted types in preference order
390
457
  */
391
458
  types(): string[];
392
459
  /**
@@ -409,6 +476,8 @@ export declare class Request extends Macroable {
409
476
  * return view.render('about', { lang: 'en' })
410
477
  * }
411
478
  * ```
479
+ * @param languages - Array of languages to match against Accept-Language header
480
+ * @returns {T | null} Best matching language or null if no match
412
481
  */
413
482
  language<T extends string>(languages: T[]): T | null;
414
483
  /**
@@ -417,6 +486,7 @@ export declare class Request extends Macroable {
417
486
  *
418
487
  * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
419
488
  * docs too.
489
+ * @returns {string[]} Array of accepted languages in preference order
420
490
  */
421
491
  languages(): string[];
422
492
  /**
@@ -437,6 +507,8 @@ export declare class Request extends Macroable {
437
507
  * // make ISO-8859-1 friendly response
438
508
  * }
439
509
  * ```
510
+ * @param charsets - Array of charsets to match against Accept-Charset header
511
+ * @returns {T | null} Best matching charset or null if no match
440
512
  */
441
513
  charset<T extends string>(charsets: T[]): T | null;
442
514
  /**
@@ -445,6 +517,7 @@ export declare class Request extends Macroable {
445
517
  *
446
518
  * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
447
519
  * docs too.
520
+ * @returns {string[]} Array of accepted charsets in preference order
448
521
  */
449
522
  charsets(): string[];
450
523
  /**
@@ -455,18 +528,22 @@ export declare class Request extends Macroable {
455
528
  *
456
529
  * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
457
530
  * docs too.
531
+ * @param encodings - Array of encodings to match against Accept-Encoding header
532
+ * @returns {T | null} Best matching encoding or null if no match
458
533
  */
459
534
  encoding<T extends string>(encodings: T[]): T | null;
460
535
  /**
461
- * Return the charsets that the request accepts, in the order of the
536
+ * Return the encodings that the request accepts, in the order of the
462
537
  * client's preference (most preferred first).
463
538
  *
464
539
  * Make sure to check [accepts](https://www.npmjs.com/package/accepts) package
465
540
  * docs too.
541
+ * @returns {string[]} Array of accepted encodings in preference order
466
542
  */
467
543
  encodings(): string[];
468
544
  /**
469
545
  * Returns a boolean telling if request has body
546
+ * @returns {boolean} True if request contains a body
470
547
  */
471
548
  hasBody(): boolean;
472
549
  /**
@@ -492,30 +569,44 @@ export declare class Request extends Macroable {
492
569
  * response.send(responseBody)
493
570
  * }
494
571
  * ```
572
+ * @returns {boolean} True if client cache is fresh (should return 304)
495
573
  */
496
574
  fresh(): boolean;
497
575
  /**
498
576
  * Opposite of [[fresh]]
577
+ * @returns {boolean} True if client cache is stale (should send new response)
499
578
  */
500
579
  stale(): boolean;
501
580
  /**
502
581
  * Returns all parsed and signed cookies. Signed cookies ensures
503
582
  * that their value isn't tampered.
583
+ * @returns {{ [key: string]: any }} Object containing all parsed cookies
504
584
  */
505
- cookiesList(): Record<string, any>;
585
+ cookiesList(): {
586
+ [key: string]: any;
587
+ };
506
588
  /**
507
589
  * Returns value for a given key from signed cookies. Optional
508
590
  * defaultValue is returned when actual value is undefined.
591
+ * @param key - Cookie name to lookup
592
+ * @param defaultValue - Default value when cookie is not found
593
+ * @returns Cookie value or default value if not found
509
594
  */
510
595
  cookie(key: string, defaultValue?: string): any;
511
596
  /**
512
- * Returns value for a given key from signed cookies. Optional
597
+ * Returns value for a given key from encrypted cookies. Optional
513
598
  * defaultValue is returned when actual value is undefined.
599
+ * @param key - Cookie name to lookup
600
+ * @param defaultValue - Default value when cookie is not found
601
+ * @returns Decrypted cookie value or default value if not found
514
602
  */
515
603
  encryptedCookie(key: string, defaultValue?: string): any;
516
604
  /**
517
605
  * Returns value for a given key from unsigned cookies. Optional
518
606
  * defaultValue is returned when actual value is undefined.
607
+ * @param key - Cookie name to lookup
608
+ * @param options - Options object with defaultValue and encoded flag
609
+ * @returns Plain cookie value or default value if not found
519
610
  */
520
611
  plainCookie(key: string, options?: {
521
612
  defaultValue?: string;
@@ -523,12 +614,15 @@ export declare class Request extends Macroable {
523
614
  }): any;
524
615
  plainCookie(key: string, defaultValue?: string, encoded?: boolean): any;
525
616
  /**
526
- * Returns a boolean telling if a signed url as a valid signature
617
+ * Returns a boolean telling if a signed url has a valid signature
527
618
  * or not.
619
+ * @param purpose - Optional purpose for signature verification
620
+ * @returns {boolean} True if the signed URL has a valid signature
528
621
  */
529
622
  hasValidSignature(purpose?: string): boolean;
530
623
  /**
531
624
  * Serializes request to JSON format
625
+ * @returns Object representation of the request
532
626
  */
533
627
  serialize(): {
534
628
  id: string | undefined;
@@ -539,13 +633,16 @@ export declare class Request extends Macroable {
539
633
  headers: IncomingHttpHeaders;
540
634
  method: string;
541
635
  protocol: string;
542
- cookies: Record<string, any>;
636
+ cookies: {
637
+ [key: string]: any;
638
+ };
543
639
  hostname: string | null;
544
640
  ip: string;
545
641
  subdomains: Record<string, any>;
546
642
  };
547
643
  /**
548
644
  * toJSON copy of the request
645
+ * @returns JSON representation of the request
549
646
  */
550
647
  toJSON(): {
551
648
  id: string | undefined;
@@ -556,7 +653,9 @@ export declare class Request extends Macroable {
556
653
  headers: IncomingHttpHeaders;
557
654
  method: string;
558
655
  protocol: string;
559
- cookies: Record<string, any>;
656
+ cookies: {
657
+ [key: string]: any;
658
+ };
560
659
  hostname: string | null;
561
660
  ip: string;
562
661
  subdomains: Record<string, any>;