@h3ravel/http 11.4.3 → 11.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,10 +1,460 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
- import { Command } from "@h3ravel/musket";
2
+ import { EventHandlerRequest, H3Event, HTTPResponse } from "h3";
3
3
  import { DotNestedKeys, DotNestedValue, HttpContext, HttpContext as HttpContext$1, IMiddleware, IRequest, IResponse } from "@h3ravel/shared";
4
- import { EventHandlerRequest, H3Event } from "h3";
5
- import { ResponseHeaderMap, TypedHeaders } from "fetchdts";
4
+ import { Command } from "@h3ravel/musket";
6
5
  import { Application } from "@h3ravel/core";
6
+ import { Url } from "@h3ravel/url";
7
7
 
8
+ //#region src/Contracts/HttpContract.d.ts
9
+ type RequestMethod = 'HEAD' | 'GET' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'PURGE' | 'POST' | 'CONNECT' | 'PATCH';
10
+ type RequestObject = Record<string, any>;
11
+ //#endregion
12
+ //#region src/Bags/ParamBag.d.ts
13
+ /**
14
+ * ParamBag is a container for key/value pairs
15
+ * for Node/H3 environments.
16
+ */
17
+ declare class ParamBag implements Iterable<[string, any]> {
18
+ protected parameters: RequestObject;
19
+ /**
20
+ * The current H3 H3Event instance
21
+ */
22
+ readonly event: H3Event;
23
+ constructor(parameters: RequestObject | undefined,
24
+ /**
25
+ * The current H3 H3Event instance
26
+ */
27
+ event: H3Event);
28
+ /**
29
+ * Returns the parameters.
30
+ * @
31
+ * @param key The name of the parameter to return or null to get them all
32
+ *
33
+ * @throws BadRequestException if the value is not an array
34
+ */
35
+ all(key?: string): any;
36
+ get(key: string, defaultValue?: any): any;
37
+ set(key: string, value: any): void;
38
+ /**
39
+ * Returns true if the parameter is defined.
40
+ *
41
+ * @param key
42
+ */
43
+ has(key: string): boolean;
44
+ /**
45
+ * Removes a parameter.
46
+ *
47
+ * @param key
48
+ */
49
+ remove(key: string): void;
50
+ /**
51
+ *
52
+ * Returns the parameter as string.
53
+ *
54
+ * @param key
55
+ * @param defaultValue
56
+ * @throws UnexpectedValueException if the value cannot be converted to string
57
+ * @returns
58
+ */
59
+ getString(key: string, defaultValue?: string): string;
60
+ /**
61
+ * Returns the parameter value converted to integer.
62
+ *
63
+ * @param key
64
+ * @param defaultValue
65
+ * @throws UnexpectedValueException if the value cannot be converted to integer
66
+ */
67
+ getInt(key: string, defaultValue?: number): number;
68
+ /**
69
+ * Returns the parameter value converted to boolean.
70
+ *
71
+ * @param key
72
+ * @param defaultValue
73
+ * @throws UnexpectedValueException if the value cannot be converted to a boolean
74
+ */
75
+ getBoolean(key: string, defaultValue?: boolean): boolean;
76
+ /**
77
+ * Returns the alphabetic characters of the parameter value.
78
+ *
79
+ * @param key
80
+ * @param defaultValue
81
+ * @throws UnexpectedValueException if the value cannot be converted to string
82
+ */
83
+ getAlpha(key: string, defaultValue?: string): string;
84
+ /**
85
+ * Returns the alphabetic characters and digits of the parameter value.
86
+ *
87
+ * @param key
88
+ * @param defaultValue
89
+ * @throws UnexpectedValueException if the value cannot be converted to string
90
+ */
91
+ getAlnum(key: string, defaultValue?: string): string;
92
+ /**
93
+ * Returns the digits of the parameter value.
94
+ *
95
+ * @param key
96
+ * @param defaultValue
97
+ * @throws UnexpectedValueException if the value cannot be converted to string
98
+ * @returns
99
+ **/
100
+ getDigits(key: string, defaultValue?: string): string;
101
+ /**
102
+ * Returns the parameter keys.
103
+ */
104
+ keys(): string[];
105
+ /**
106
+ * Replaces the current parameters by a new set.
107
+ */
108
+ replace(parameters?: RequestObject): void;
109
+ /**
110
+ * Adds parameters.
111
+ */
112
+ add(parameters?: RequestObject): void;
113
+ /**
114
+ * Returns the number of parameters.
115
+ */
116
+ count(): number;
117
+ /**
118
+ * Returns an iterator for parameters.
119
+ *
120
+ * @returns
121
+ */
122
+ [Symbol.iterator](): ArrayIterator<[string, any]>;
123
+ }
124
+ //#endregion
125
+ //#region src/UploadedFile.d.ts
126
+ declare class UploadedFile {
127
+ originalName: string;
128
+ mimeType: string;
129
+ size: number;
130
+ content: File;
131
+ constructor(originalName: string, mimeType: string, size: number, content: File);
132
+ static createFromBase(file: File): UploadedFile;
133
+ /**
134
+ * Save to disk (Node environment only)
135
+ */
136
+ moveTo(destination: string): Promise<void>;
137
+ }
138
+ //#endregion
139
+ //#region src/Bags/FileBag.d.ts
140
+ type FileInput = UploadedFile | File | null | undefined;
141
+ /**
142
+ * FileBag is a container for uploaded files
143
+ * for Node/H3 environments.
144
+ */
145
+ declare class FileBag extends ParamBag {
146
+ protected parameters: Record<string, UploadedFile | UploadedFile[] | null>;
147
+ constructor(parameters: Record<string, FileInput | FileInput[]> | undefined,
148
+ /**
149
+ * The current H3 H3Event instance
150
+ */
151
+ event: H3Event);
152
+ /**
153
+ * Replace all stored files.
154
+ */
155
+ replace(files?: Record<string, FileInput | FileInput[]>): void;
156
+ /**
157
+ * Set a file or array of files.
158
+ */
159
+ set(key: string, value: FileInput | FileInput[]): void;
160
+ /**
161
+ * Add multiple files.
162
+ */
163
+ add(files?: Record<string, FileInput | FileInput[]>): void;
164
+ /**
165
+ * Get all stored files.
166
+ */
167
+ all(): Record<string, UploadedFile | UploadedFile[] | null>;
168
+ /**
169
+ * Normalize file input into UploadedFile instances.
170
+ */
171
+ protected convertFileInformation(file: FileInput): UploadedFile | null;
172
+ }
173
+ //#endregion
174
+ //#region src/Bags/HeaderBag.d.ts
175
+ /**
176
+ * HeaderBag — A container for HTTP headers
177
+ * for Node/H3 environments.
178
+ */
179
+ declare class HeaderBag implements Iterable<[string, (string | null)[]]> {
180
+ protected static readonly UPPER = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ";
181
+ protected static readonly LOWER = "-abcdefghijklmnopqrstuvwxyz";
182
+ protected headers: Record<string, (string | null)[]>;
183
+ protected cacheControl: Record<string, string | boolean>;
184
+ constructor(headers?: Record<string, string | string[] | null>);
185
+ /**
186
+ * Returns all headers as string (for debugging / toString)
187
+ *
188
+ * @returns
189
+ */
190
+ toString(): string;
191
+ /**
192
+ * Returns all headers or specific header list
193
+ *
194
+ * @param key
195
+ * @returns
196
+ */
197
+ all(key?: string): Record<string, (string | null)[]> | (string | null)[];
198
+ /**
199
+ * Returns header keys
200
+ *
201
+ * @returns
202
+ */
203
+ keys(): string[];
204
+ /**
205
+ * Replace all headers with new set
206
+ *
207
+ * @param headers
208
+ */
209
+ replace(headers?: Record<string, string | string[] | null>): void;
210
+ /**
211
+ * Add multiple headers
212
+ *
213
+ * @param headers
214
+ */
215
+ add(headers: Record<string, string | string[] | null>): void;
216
+ /**
217
+ * Returns first header value by name or default
218
+ *
219
+ * @param key
220
+ * @param defaultValue
221
+ * @returns
222
+ */
223
+ get<R = undefined>(key: string, defaultValue?: string | null): R extends undefined ? string | null : R;
224
+ /**
225
+ * Sets a header by name.
226
+ *
227
+ * @param replace Whether to replace existing values (default true)
228
+ */
229
+ set(key: string, values: string | string[] | null, replace?: boolean): void;
230
+ /**
231
+ * Returns true if header exists
232
+ *
233
+ * @param key
234
+ * @returns
235
+ */
236
+ has(key: string): boolean;
237
+ /**
238
+ * Returns true if header contains value
239
+ *
240
+ * @param key
241
+ * @param value
242
+ * @returns
243
+ */
244
+ contains(key: string, value: string): boolean;
245
+ /**
246
+ * Removes a header
247
+ *
248
+ * @param key
249
+ */
250
+ remove(key: string): void;
251
+ /**
252
+ * Returns parsed date from header
253
+ *
254
+ * @param key
255
+ * @param defaultValue
256
+ * @returns
257
+ */
258
+ getDate(key: string, defaultValue?: Date | null): Date | null;
259
+ /**
260
+ * Adds a Cache-Control directive
261
+ *
262
+ * @param key
263
+ * @param value
264
+ */
265
+ addCacheControlDirective(key: string, value?: string | boolean): void;
266
+ /**
267
+ * Returns true if Cache-Control directive is defined
268
+ *
269
+ * @param key
270
+ * @returns
271
+ */
272
+ hasCacheControlDirective(key: string): boolean;
273
+ /**
274
+ * Returns a Cache-Control directive value by name
275
+ *
276
+ * @param key
277
+ * @returns
278
+ */
279
+ getCacheControlDirective(key: string): string | boolean | null;
280
+ /**
281
+ * Removes a Cache-Control directive
282
+ *
283
+ * @param key
284
+ * @returns
285
+ */
286
+ removeCacheControlDirective(key: string): void;
287
+ /**
288
+ * Number of headers
289
+ *
290
+ * @param key
291
+ * @returns
292
+ */
293
+ count(): number;
294
+ /**
295
+ * Normalize header name to lowercase with hyphens
296
+ *
297
+ * @param key
298
+ * @returns
299
+ */
300
+ protected normalizeKey(key: string): string;
301
+ /**
302
+ * Generates Cache-Control header string
303
+ *
304
+ * @param header
305
+ * @returns
306
+ */
307
+ protected getCacheControlHeader(): string;
308
+ /**
309
+ * Parses Cache-Control header
310
+ *
311
+ * @param header
312
+ * @returns
313
+ */
314
+ protected parseCacheControl(header: string): Record<string, string | boolean>;
315
+ /**
316
+ * Iterator support
317
+ * @returns
318
+ */
319
+ [Symbol.iterator](): Iterator<[string, (string | null)[]]>;
320
+ }
321
+ //#endregion
322
+ //#region src/Bags/InputBag.d.ts
323
+ /**
324
+ * InputBag is a container for user input values
325
+ * (e.g., query params, body, cookies)
326
+ * for Node/H3 environments.
327
+ */
328
+ declare class InputBag extends ParamBag {
329
+ constructor(inputs: RequestObject | undefined,
330
+ /**
331
+ * The current H3 H3Event instance
332
+ */
333
+ event: H3Event);
334
+ /**
335
+ * Returns a scalar input value by name.
336
+ *
337
+ * @param key
338
+ * @param defaultValue
339
+ * @throws BadRequestException if the input contains a non-scalar value
340
+ * @returns
341
+ */
342
+ get<T extends string | number | boolean | null>(key: string, defaultValue?: T | null): T | string | number | boolean | null;
343
+ /**
344
+ * Replaces all current input values.
345
+ *
346
+ * @param inputs
347
+ * @returns
348
+ */
349
+ replace(inputs?: RequestObject): void;
350
+ /**
351
+ * Adds multiple input values.
352
+ *
353
+ * @param inputs
354
+ * @returns
355
+ */
356
+ add(inputs?: RequestObject): void;
357
+ /**
358
+ * Sets an input by name.
359
+ *
360
+ * @param key
361
+ * @param value
362
+ * @throws TypeError if value is not scalar or array
363
+ * @returns
364
+ */
365
+ set(key: string, value: any): void;
366
+ /**
367
+ * Returns true if a key exists.
368
+ *
369
+ * @param key
370
+ * @returns
371
+ */
372
+ has(key: string): boolean;
373
+ /**
374
+ * Returns all parameters.
375
+ *
376
+ * @returns
377
+ */
378
+ all(): RequestObject;
379
+ /**
380
+ * Converts a parameter value to string.
381
+ *
382
+ * @param key
383
+ * @param defaultValue
384
+ * @throws BadRequestException if input contains a non-scalar value
385
+ * @returns
386
+ */
387
+ getString(key: string, defaultValue?: string): string;
388
+ /**
389
+ * Filters input value with a predicate.
390
+ * Mimics PHP’s filter_var() in spirit, but simpler.
391
+ *
392
+ * @param key
393
+ * @param defaultValue
394
+ * @param filterFn
395
+ * @throws BadRequestException if validation fails
396
+ * @returns
397
+ */
398
+ filter<T = any>(key: string, defaultValue?: T | null, filterFn?: (value: any) => boolean): T | null;
399
+ /**
400
+ * Returns an enum value by key.
401
+ *
402
+ * @param key
403
+ * @param EnumClass
404
+ * @param defaultValue
405
+ * @throws BadRequestException if conversion fails
406
+ * @returns
407
+ */
408
+ getEnum<T extends Record<string, string | number>>(key: string, EnumClass: T, defaultValue?: T[keyof T] | null): T[keyof T] | null;
409
+ /**
410
+ * Removes a key.
411
+ *
412
+ * @param key
413
+ */
414
+ remove(key: string): void;
415
+ /**
416
+ * Returns all keys.
417
+ *
418
+ * @returns
419
+ */
420
+ keys(): string[];
421
+ /**
422
+ * Returns number of parameters.
423
+ *
424
+ * @returns
425
+ */
426
+ count(): number;
427
+ }
428
+ //#endregion
429
+ //#region src/Bags/ServerBag.d.ts
430
+ /**
431
+ * ServerBag — a simplified version of Symfony's ServerBag
432
+ * for Node/H3 environments.
433
+ *
434
+ * Responsible for extracting and normalizing HTTP headers
435
+ * from the incoming request.
436
+ */
437
+ declare class ServerBag extends ParamBag {
438
+ constructor(parameters: Record<string, string | undefined> | undefined,
439
+ /**
440
+ * The current H3 H3Event instance
441
+ */
442
+ event: H3Event);
443
+ /**
444
+ * Returns all request headers, normalized to uppercase with underscores.
445
+ * Example: content-type → CONTENT_TYPE
446
+ */
447
+ getHeaders(): Record<string, string>;
448
+ /**
449
+ * Returns a specific header by name, case-insensitive.
450
+ */
451
+ get(name: string): string | undefined;
452
+ /**
453
+ * Returns true if a header exists.
454
+ */
455
+ has(name: string): boolean;
456
+ }
457
+ //#endregion
8
458
  //#region src/Commands/FireCommand.d.ts
9
459
  declare class FireCommand extends Command {
10
460
  /**
@@ -23,6 +473,48 @@ declare class FireCommand extends Command {
23
473
  protected fire(): Promise<void>;
24
474
  }
25
475
  //#endregion
476
+ //#region src/Exceptions/BadRequestException.d.ts
477
+ declare class BadRequestException extends Error {
478
+ constructor(message: string);
479
+ }
480
+ //#endregion
481
+ //#region src/Exceptions/SuspiciousOperationException.d.ts
482
+ declare class SuspiciousOperationException extends Error {
483
+ constructor(message: string);
484
+ }
485
+ //#endregion
486
+ //#region src/Exceptions/UnexpectedValueException.d.ts
487
+ declare class UnexpectedValueException extends Error {
488
+ constructor(message: string);
489
+ }
490
+ //#endregion
491
+ //#region src/FormRequest.d.ts
492
+ declare class FormRequest {
493
+ protected dataset: {
494
+ files: Record<string, File | UploadedFile | (File | UploadedFile)[]>;
495
+ input: Record<string, any>;
496
+ };
497
+ constructor(data: FormData);
498
+ /**
499
+ * Initialize the data
500
+ * @param data
501
+ */
502
+ initialize(data: FormData): void;
503
+ /**
504
+ * Get all uploaded files
505
+ */
506
+ files(): Record<string, File | UploadedFile | (File | UploadedFile)[]>;
507
+ /**
508
+ * Get all input fields
509
+ */
510
+ input(): Record<string, any>;
511
+ /**
512
+ * Get combined input and files
513
+ * File entries take precedence if names overlap.
514
+ */
515
+ all(): Record<string, any>;
516
+ }
517
+ //#endregion
26
518
  //#region src/Middleware.d.ts
27
519
  declare abstract class Middleware implements IMiddleware {
28
520
  abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
@@ -56,42 +548,355 @@ declare class HttpServiceProvider {
56
548
  //#endregion
57
549
  //#region src/Request.d.ts
58
550
  declare class Request implements IRequest {
551
+ #private;
552
+ /**
553
+ * The current H3 H3Event instance
554
+ */
555
+ private readonly event;
59
556
  /**
60
557
  * The current app instance
61
558
  */
62
559
  app: Application;
560
+ /**
561
+ * Parsed request body
562
+ */
563
+ body: unknown;
63
564
  /**
64
565
  * Gets route parameters.
65
566
  * @returns An object containing route parameters.
66
567
  */
67
- readonly params: NonNullable<H3Event['context']['params']>;
568
+ params: NonNullable<H3Event['context']['params']>;
68
569
  /**
69
- * Gets query parameters.
70
- * @returns An object containing query parameters.
570
+ * All of the converted files for the request.
71
571
  */
72
- readonly query: Record<string, string>;
572
+ protected convertedFiles?: Record<string, UploadedFile | UploadedFile[]>;
573
+ /**
574
+ * Form data from incoming request.
575
+ * @returns The FormRequest object.
576
+ */
577
+ protected formData: FormRequest;
578
+ /**
579
+ * Request body parameters (POST).
580
+ *
581
+ * @see getPayload() for portability between content types
582
+ */
583
+ protected request: InputBag;
584
+ /**
585
+ * Query string parameters (GET).
586
+ */
587
+ query: InputBag;
588
+ /**
589
+ * Uploaded files (FILES).
590
+ */
591
+ files: FileBag;
592
+ /**
593
+ * Server and execution environment parameters
594
+ */
595
+ server: ServerBag;
596
+ /**
597
+ * Cookies
598
+ */
599
+ cookies: InputBag;
600
+ /**
601
+ * The request attributes (parameters parsed from the PATH_INFO, ...).
602
+ */
603
+ attributes: ParamBag;
73
604
  /**
74
605
  * Gets the request headers.
75
606
  * @returns An object containing request headers.
76
607
  */
77
- readonly headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
608
+ headers: HeaderBag;
609
+ protected content?: ReadableStream | string | false | null;
610
+ protected static formats?: Record<string, string[]> | undefined | null;
611
+ protected static httpMethodParameterOverride: boolean;
612
+ /**
613
+ * List of Acceptable Content Types
614
+ */
615
+ private acceptableContentTypes;
616
+ constructor(
78
617
  /**
79
618
  * The current H3 H3Event instance
80
619
  */
81
- private readonly event;
82
- constructor(event: H3Event,
620
+ event: H3Event,
83
621
  /**
84
622
  * The current app instance
85
623
  */
86
624
  app: Application);
87
625
  /**
88
- * Get all input data (query + body).
626
+ * Factory method to create a Request instance from an H3Event.
627
+ */
628
+ static create(
629
+ /**
630
+ * The current H3 H3Event instance
631
+ */
632
+ event: H3Event,
633
+ /**
634
+ * The current app instance
89
635
  */
90
- all<T = Record<string, unknown>>(): Promise<T>;
636
+ app: Application): Promise<Request>;
91
637
  /**
92
- * Get a single input field from query or body.
638
+ * Sets the parameters for this request.
639
+ *
640
+ * This method also re-initializes all properties.
641
+ *
642
+ * @param attributes
643
+ * @param cookies The COOKIE parameters
644
+ * @param files The FILES parameters
645
+ * @param server The SERVER parameters
646
+ * @param content The raw body data
647
+ */
648
+ initialize(): Promise<void>;
649
+ private setBody;
650
+ /**
651
+ * Retrieve all data from the instance (query + body).
652
+ */
653
+ all<T = Record<string, any>>(keys?: string | string[]): T;
654
+ /**
655
+ * Retrieve an input item from the request.
656
+ *
657
+ * @param key
658
+ * @param defaultValue
659
+ * @returns
660
+ */
661
+ input<K extends string | undefined>(key?: K, defaultValue?: any): K extends undefined ? RequestObject : any;
662
+ /**
663
+ * Retrieve a file from the request.
664
+ *
665
+ * @param key
666
+ * @param defaultValue
667
+ * @returns
668
+ */
669
+ file<K extends string | undefined = undefined>(key?: K, defaultValue?: any): K extends undefined ? Record<string, UploadedFile | UploadedFile[]> : UploadedFile | UploadedFile[];
670
+ /**
671
+ * Get an array of all of the files on the request.
672
+ */
673
+ allFiles(): Record<string, UploadedFile | UploadedFile[]>;
674
+ /**
675
+ * Extract and convert uploaded files from FormData.
676
+ */
677
+ convertUploadedFiles(files: Record<string, UploadedFile | UploadedFile[]>): Record<string, UploadedFile | UploadedFile[]>;
678
+ /**
679
+ * Determine if the data contains a given key.
680
+ *
681
+ * @param keys
682
+ * @returns
683
+ */
684
+ has(keys: string[] | string): boolean;
685
+ /**
686
+ * Determine if the instance is missing a given key.
687
+ */
688
+ missing(key: string | string[]): boolean;
689
+ /**
690
+ * Get a subset containing the provided keys with values from the instance data.
691
+ *
692
+ * @param keys
693
+ * @returns
694
+ */
695
+ only<T = Record<string, any>>(keys: string[]): T;
696
+ /**
697
+ * Get all of the data except for a specified array of items.
698
+ *
699
+ * @param keys
700
+ * @returns
701
+ */
702
+ except<T = Record<string, any>>(keys: string[]): T;
703
+ /**
704
+ * Merges new input data into the current request's input source.
705
+ *
706
+ * @param input - An object containing key-value pairs to merge.
707
+ * @returns this - For fluent chaining.
708
+ */
709
+ merge(input: Record<string, any>): this;
710
+ /**
711
+ * Merge new input into the request's input, but only when that key is missing from the request.
712
+ *
713
+ * @param input
714
+ */
715
+ mergeIfMissing(input: Record<string, any>): this;
716
+ /**
717
+ * Get the keys for all of the input and files.
718
+ */
719
+ keys(): string[];
720
+ /**
721
+ * Determine if the request is sending JSON.
722
+ *
723
+ * @return bool
724
+ */
725
+ isJson(): boolean;
726
+ /**
727
+ * Determine if the current request probably expects a JSON response.
728
+ *
729
+ * @returns
730
+ */
731
+ expectsJson(): boolean;
732
+ /**
733
+ * Determine if the current request is asking for JSON.
734
+ *
735
+ * @returns
736
+ */
737
+ wantsJson(): boolean;
738
+ /**
739
+ * Gets a list of content types acceptable by the client browser in preferable order.
740
+ * @returns {string[]}
741
+ */
742
+ getAcceptableContentTypes(): string[];
743
+ /**
744
+ * Determine if the request is the result of a PJAX call.
745
+ *
746
+ * @return bool
747
+ */
748
+ pjax(): boolean;
749
+ /**
750
+ * Returns true if the request is an XMLHttpRequest (AJAX).
751
+ *
752
+ * @alias isXmlHttpRequest()
753
+ * @returns {boolean}
754
+ */
755
+ ajax(): boolean;
756
+ /**
757
+ * Returns true if the request is an XMLHttpRequest (AJAX).
758
+ */
759
+ isXmlHttpRequest(): boolean;
760
+ /**
761
+ * Returns the value of the requested header.
762
+ */
763
+ getHeader(name: string): string | undefined | null;
764
+ /**
765
+ * Checks if the request method is of specified type.
766
+ *
767
+ * @param method Uppercase request method (GET, POST etc)
768
+ */
769
+ isMethod(method: string): boolean;
770
+ /**
771
+ * Checks whether or not the method is safe.
772
+ *
773
+ * @see https://tools.ietf.org/html/rfc7231#section-4.2.1
774
+ */
775
+ isMethodSafe(): boolean;
776
+ /**
777
+ * Checks whether or not the method is idempotent.
778
+ */
779
+ isMethodIdempotent(): boolean;
780
+ /**
781
+ * Checks whether the method is cacheable or not.
782
+ *
783
+ * @see https://tools.ietf.org/html/rfc7231#section-4.2.3
784
+ */
785
+ isMethodCacheable(): boolean;
786
+ /**
787
+ * Initializes HTTP request formats.
788
+ */
789
+ protected static initializeFormats(): void;
790
+ /**
791
+ * Gets the request "intended" method.
792
+ *
793
+ * If the X-HTTP-Method-Override header is set, and if the method is a POST,
794
+ * then it is used to determine the "real" intended HTTP method.
795
+ *
796
+ * The _method request parameter can also be used to determine the HTTP method,
797
+ * but only if enableHttpMethodParameterOverride() has been called.
798
+ *
799
+ * The method is always an uppercased string.
800
+ *
801
+ * @see getRealMethod()
802
+ */
803
+ getMethod(): RequestMethod;
804
+ /**
805
+ * Gets the "real" request method.
806
+ *
807
+ * @see getMethod()
808
+ */
809
+ getRealMethod(): RequestMethod;
810
+ /**
811
+ * Get the client IP address.
812
+ */
813
+ ip(): string | undefined;
814
+ /**
815
+ * Get a URI instance for the request.
816
+ */
817
+ uri(): Url;
818
+ /**
819
+ * Get the full URL for the request.
820
+ */
821
+ fullUrl(): string;
822
+ /**
823
+ * Return the Request instance.
824
+ */
825
+ instance(): this;
826
+ /**
827
+ * Get the request method.
828
+ */
829
+ method(): RequestMethod;
830
+ /**
831
+ * Get the JSON payload for the request.
832
+ *
833
+ * @param key
834
+ * @param defaultValue
835
+ * @return {InputBag}
836
+ */
837
+ json<K extends string | undefined = undefined>(key?: string, defaultValue?: any): K extends undefined ? InputBag : any;
838
+ /**
839
+ * Get the input source for the request.
840
+ *
841
+ * @return {InputBag}
842
+ */
843
+ protected getInputSource(): InputBag;
844
+ /**
845
+ * Returns the request body content.
846
+ *
847
+ * @param asStream If true, returns a ReadableStream instead of the parsed string
848
+ * @return {string | ReadableStream | Promise<string | ReadableStream>}
849
+ */
850
+ getContent(asStream?: boolean): string | ReadableStream;
851
+ /**
852
+ * Determine if the uploaded data contains a file.
853
+ *
854
+ * @param key
855
+ * @return boolean
856
+ */
857
+ hasFile(key: string): boolean;
858
+ /**
859
+ * Check that the given file is a valid file instance.
860
+ *
861
+ * @param file
862
+ * @return boolean
863
+ */
864
+ protected isValidFile(file: UploadedFile): boolean;
865
+ /**
866
+ * Gets a "parameter" value from any bag.
867
+ *
868
+ * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
869
+ * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
870
+ * public property instead (attributes, query, request).
871
+ *
872
+ * Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
873
+ *
874
+ * @internal use explicit input sources instead
875
+ */
876
+ get(key: string, defaultValue?: any): any;
877
+ /**
878
+ * Enables support for the _method request parameter to determine the intended HTTP method.
879
+ *
880
+ * Be warned that enabling this feature might lead to CSRF issues in your code.
881
+ * Check that you are using CSRF tokens when required.
882
+ * If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
883
+ * and used to send a "PUT" or "DELETE" request via the _method request parameter.
884
+ * If these methods are not protected against CSRF, this presents a possible vulnerability.
885
+ *
886
+ * The HTTP method can only be overridden when the real HTTP method is POST.
887
+ */
888
+ static enableHttpMethodParameterOverride(): void;
889
+ /**
890
+ * Checks whether support for the _method request parameter is enabled.
891
+ */
892
+ static getHttpMethodParameterOverride(): boolean;
893
+ /**
894
+ * Dump the items.
895
+ *
896
+ * @param keys
897
+ * @return this
93
898
  */
94
- input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
899
+ dump(...keys: any[]): this;
95
900
  /**
96
901
  * Get the base event
97
902
  */
@@ -118,7 +923,7 @@ type BodyResource = Resource & {
118
923
  /**
119
924
  * Class to render API resource
120
925
  */
121
- declare class JsonResource<R extends Resource = any> {
926
+ declare class JsonResource<R$1 extends Resource = any> {
122
927
  #private;
123
928
  protected event: H3Event;
124
929
  /**
@@ -132,7 +937,7 @@ declare class JsonResource<R extends Resource = any> {
132
937
  /**
133
938
  * The data to send to the client
134
939
  */
135
- resource: R;
940
+ resource: R$1;
136
941
  /**
137
942
  * The final response data object
138
943
  */
@@ -154,7 +959,7 @@ declare class JsonResource<R extends Resource = any> {
154
959
  * @param res The response instance
155
960
  * @param rsc The data to send to the client
156
961
  */
157
- constructor(event: H3Event, rsc: R);
962
+ constructor(event: H3Event, rsc: R$1);
158
963
  /**
159
964
  * Return the data in the expected format
160
965
  *
@@ -219,7 +1024,7 @@ declare class Response implements IResponse {
219
1024
  * Set a header.
220
1025
  */
221
1026
  setHeader(name: string, value: string): this;
222
- html(content: string): string;
1027
+ html(content: string): HTTPResponse;
223
1028
  /**
224
1029
  * Send a JSON response.
225
1030
  */
@@ -231,7 +1036,7 @@ declare class Response implements IResponse {
231
1036
  /**
232
1037
  * Redirect to another URL.
233
1038
  */
234
- redirect(url: string, status?: number): string;
1039
+ redirect(location: string, status?: number, statusText?: string | undefined): HTTPResponse;
235
1040
  /**
236
1041
  * Apply headers before sending response.
237
1042
  */
@@ -243,4 +1048,4 @@ declare class Response implements IResponse {
243
1048
  getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
244
1049
  }
245
1050
  //#endregion
246
- export { ApiResource, FireCommand, HttpContext, HttpServiceProvider, JsonResource, LogRequests, Middleware, Request, Resource, Response };
1051
+ export { ApiResource, BadRequestException, FileBag, FireCommand, FormRequest, HeaderBag, HttpContext, HttpServiceProvider, InputBag, JsonResource, LogRequests, Middleware, ParamBag, Request, RequestMethod, RequestObject, Resource, Response, ServerBag, SuspiciousOperationException, UnexpectedValueException, UploadedFile };