@h3ravel/http 11.5.3 → 11.6.1

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 DELETED
@@ -1,1057 +0,0 @@
1
- /// <reference path="./app.globals.d.ts" />
2
- import { EventHandlerRequest, H3Event, HTTPResponse } from "h3";
3
- import { DotNestedKeys, DotNestedValue, HttpContext, HttpContext as HttpContext$1, IMiddleware, IRequest, IResponse } from "@h3ravel/shared";
4
- import { Command } from "@h3ravel/musket";
5
- import { Application } from "@h3ravel/core";
6
- import { Url } from "@h3ravel/url";
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
458
- //#region src/Commands/FireCommand.d.ts
459
- declare class FireCommand extends Command {
460
- /**
461
- * The name and signature of the console command.
462
- *
463
- * @var string
464
- */
465
- protected signature: string;
466
- /**
467
- * The console command description.
468
- *
469
- * @var string
470
- */
471
- protected description: string;
472
- handle(): Promise<void>;
473
- protected fire(): Promise<void>;
474
- }
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
518
- //#region src/Middleware.d.ts
519
- declare abstract class Middleware implements IMiddleware {
520
- abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
521
- }
522
- //#endregion
523
- //#region src/Middleware/LogRequests.d.ts
524
- declare class LogRequests extends Middleware {
525
- handle({
526
- request
527
- }: HttpContext$1, next: () => Promise<unknown>): Promise<unknown>;
528
- }
529
- //#endregion
530
- //#region src/Providers/HttpServiceProvider.d.ts
531
- /**
532
- * Sets up HTTP kernel and request lifecycle.
533
- *
534
- * Register Request, Response, and Middleware classes.
535
- * Configure global middleware stack.
536
- * Boot HTTP kernel.
537
- *
538
- * Auto-Registered
539
- */
540
- declare class HttpServiceProvider {
541
- private app;
542
- static priority: number;
543
- registeredCommands?: (new (app: any, kernel: any) => any)[];
544
- constructor(app: any);
545
- register(): void;
546
- boot(): void;
547
- }
548
- //#endregion
549
- //#region src/Request.d.ts
550
- declare class Request implements IRequest {
551
- #private;
552
- /**
553
- * The current H3 H3Event instance
554
- */
555
- private readonly event;
556
- /**
557
- * The current app instance
558
- */
559
- app: Application;
560
- /**
561
- * Parsed request body
562
- */
563
- body: unknown;
564
- /**
565
- * Gets route parameters.
566
- * @returns An object containing route parameters.
567
- */
568
- params: NonNullable<H3Event['context']['params']>;
569
- /**
570
- * All of the converted files for the request.
571
- */
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
- * Uploaded files (FILES).
586
- */
587
- files: FileBag;
588
- /**
589
- * Query string parameters (GET).
590
- */
591
- query: InputBag;
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;
604
- /**
605
- * Gets the request headers.
606
- * @returns An object containing request headers.
607
- */
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(
617
- /**
618
- * The current H3 H3Event instance
619
- */
620
- event: H3Event,
621
- /**
622
- * The current app instance
623
- */
624
- app: Application);
625
- /**
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
635
- */
636
- app: Application): Promise<Request>;
637
- /**
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
- * By default a single `UploadedFile` instance will always be returned by
666
- * the method (first file in property when there are multiple), unless
667
- * the `expectArray` parameter is set to true, in which case, the method
668
- * returns an `UploadedFile[]` array.
669
- *
670
- * @param key
671
- * @param defaultValue
672
- * @param expectArray set to true to return an `UploadedFile[]` array.
673
- * @returns
674
- */
675
- file<K extends string | undefined = undefined, E extends boolean | undefined = undefined>(key?: K, defaultValue?: any, expectArray?: E): K extends undefined ? Record<string, E extends true ? UploadedFile[] : UploadedFile> : E extends true ? UploadedFile[] : UploadedFile;
676
- /**
677
- * Determine if the uploaded data contains a file.
678
- *
679
- * @param key
680
- * @return boolean
681
- */
682
- hasFile(key: string): boolean;
683
- /**
684
- * Check that the given file is a valid file instance.
685
- *
686
- * @param file
687
- * @return boolean
688
- */
689
- protected isValidFile(file: UploadedFile): boolean;
690
- /**
691
- * Get an object with all the files on the request.
692
- */
693
- allFiles(): Record<string, UploadedFile | UploadedFile[]>;
694
- /**
695
- * Extract and convert uploaded files from FormData.
696
- */
697
- convertUploadedFiles(files: Record<string, UploadedFile | UploadedFile[]>): Record<string, UploadedFile | UploadedFile[]>;
698
- /**
699
- * Determine if the data contains a given key.
700
- *
701
- * @param keys
702
- * @returns
703
- */
704
- has(keys: string[] | string): boolean;
705
- /**
706
- * Determine if the instance is missing a given key.
707
- */
708
- missing(key: string | string[]): boolean;
709
- /**
710
- * Get a subset containing the provided keys with values from the instance data.
711
- *
712
- * @param keys
713
- * @returns
714
- */
715
- only<T = Record<string, any>>(keys: string[]): T;
716
- /**
717
- * Get all of the data except for a specified array of items.
718
- *
719
- * @param keys
720
- * @returns
721
- */
722
- except<T = Record<string, any>>(keys: string[]): T;
723
- /**
724
- * Merges new input data into the current request's input source.
725
- *
726
- * @param input - An object containing key-value pairs to merge.
727
- * @returns this - For fluent chaining.
728
- */
729
- merge(input: Record<string, any>): this;
730
- /**
731
- * Merge new input into the request's input, but only when that key is missing from the request.
732
- *
733
- * @param input
734
- */
735
- mergeIfMissing(input: Record<string, any>): this;
736
- /**
737
- * Get the keys for all of the input and files.
738
- */
739
- keys(): string[];
740
- /**
741
- * Determine if the request is sending JSON.
742
- *
743
- * @return bool
744
- */
745
- isJson(): boolean;
746
- /**
747
- * Determine if the current request probably expects a JSON response.
748
- *
749
- * @returns
750
- */
751
- expectsJson(): boolean;
752
- /**
753
- * Determine if the current request is asking for JSON.
754
- *
755
- * @returns
756
- */
757
- wantsJson(): boolean;
758
- /**
759
- * Gets a list of content types acceptable by the client browser in preferable order.
760
- * @returns {string[]}
761
- */
762
- getAcceptableContentTypes(): string[];
763
- /**
764
- * Determine if the request is the result of a PJAX call.
765
- *
766
- * @return bool
767
- */
768
- pjax(): boolean;
769
- /**
770
- * Returns true if the request is an XMLHttpRequest (AJAX).
771
- *
772
- * @alias isXmlHttpRequest()
773
- * @returns {boolean}
774
- */
775
- ajax(): boolean;
776
- /**
777
- * Returns true if the request is an XMLHttpRequest (AJAX).
778
- */
779
- isXmlHttpRequest(): boolean;
780
- /**
781
- * Returns the value of the requested header.
782
- */
783
- getHeader(name: string): string | undefined | null;
784
- /**
785
- * Checks if the request method is of specified type.
786
- *
787
- * @param method Uppercase request method (GET, POST etc)
788
- */
789
- isMethod(method: string): boolean;
790
- /**
791
- * Checks whether or not the method is safe.
792
- *
793
- * @see https://tools.ietf.org/html/rfc7231#section-4.2.1
794
- */
795
- isMethodSafe(): boolean;
796
- /**
797
- * Checks whether or not the method is idempotent.
798
- */
799
- isMethodIdempotent(): boolean;
800
- /**
801
- * Checks whether the method is cacheable or not.
802
- *
803
- * @see https://tools.ietf.org/html/rfc7231#section-4.2.3
804
- */
805
- isMethodCacheable(): boolean;
806
- /**
807
- * Initializes HTTP request formats.
808
- */
809
- protected static initializeFormats(): void;
810
- /**
811
- * Gets the request "intended" method.
812
- *
813
- * If the X-HTTP-Method-Override header is set, and if the method is a POST,
814
- * then it is used to determine the "real" intended HTTP method.
815
- *
816
- * The _method request parameter can also be used to determine the HTTP method,
817
- * but only if enableHttpMethodParameterOverride() has been called.
818
- *
819
- * The method is always an uppercased string.
820
- *
821
- * @see getRealMethod()
822
- */
823
- getMethod(): RequestMethod;
824
- /**
825
- * Gets the "real" request method.
826
- *
827
- * @see getMethod()
828
- */
829
- getRealMethod(): RequestMethod;
830
- /**
831
- * Get the client IP address.
832
- */
833
- ip(): string | undefined;
834
- /**
835
- * Get a URI instance for the request.
836
- */
837
- uri(): Url;
838
- /**
839
- * Get the full URL for the request.
840
- */
841
- fullUrl(): string;
842
- /**
843
- * Return the Request instance.
844
- */
845
- instance(): this;
846
- /**
847
- * Get the request method.
848
- */
849
- method(): RequestMethod;
850
- /**
851
- * Get the JSON payload for the request.
852
- *
853
- * @param key
854
- * @param defaultValue
855
- * @return {InputBag}
856
- */
857
- json<K extends string | undefined = undefined>(key?: string, defaultValue?: any): K extends undefined ? InputBag : any;
858
- /**
859
- * Get the input source for the request.
860
- *
861
- * @return {InputBag}
862
- */
863
- protected getInputSource(): InputBag;
864
- /**
865
- * Returns the request body content.
866
- *
867
- * @param asStream If true, returns a ReadableStream instead of the parsed string
868
- * @return {string | ReadableStream | Promise<string | ReadableStream>}
869
- */
870
- getContent(asStream?: boolean): string | ReadableStream;
871
- /**
872
- * Gets a "parameter" value from any bag.
873
- *
874
- * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
875
- * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
876
- * public property instead (attributes, query, request).
877
- *
878
- * Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
879
- *
880
- * @internal use explicit input sources instead
881
- */
882
- get(key: string, defaultValue?: any): any;
883
- /**
884
- * Enables support for the _method request parameter to determine the intended HTTP method.
885
- *
886
- * Be warned that enabling this feature might lead to CSRF issues in your code.
887
- * Check that you are using CSRF tokens when required.
888
- * If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
889
- * and used to send a "PUT" or "DELETE" request via the _method request parameter.
890
- * If these methods are not protected against CSRF, this presents a possible vulnerability.
891
- *
892
- * The HTTP method can only be overridden when the real HTTP method is POST.
893
- */
894
- static enableHttpMethodParameterOverride(): void;
895
- /**
896
- * Checks whether support for the _method request parameter is enabled.
897
- */
898
- static getHttpMethodParameterOverride(): boolean;
899
- /**
900
- * Dump the items.
901
- *
902
- * @param keys
903
- * @return this
904
- */
905
- dump(...keys: any[]): this;
906
- /**
907
- * Get the base event
908
- */
909
- getEvent(): H3Event;
910
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
911
- }
912
- //#endregion
913
- //#region src/Resources/JsonResource.d.ts
914
- interface Resource {
915
- [key: string]: any;
916
- pagination?: {
917
- from?: number | undefined;
918
- to?: number | undefined;
919
- perPage?: number | undefined;
920
- total?: number | undefined;
921
- } | undefined;
922
- }
923
- type BodyResource = Resource & {
924
- data: Omit<Resource, 'pagination'>;
925
- meta?: {
926
- pagination?: Resource['pagination'];
927
- } | undefined;
928
- };
929
- /**
930
- * Class to render API resource
931
- */
932
- declare class JsonResource<R$1 extends Resource = any> {
933
- #private;
934
- protected event: H3Event;
935
- /**
936
- * The request instance
937
- */
938
- request: H3Event<EventHandlerRequest>['req'];
939
- /**
940
- * The response instance
941
- */
942
- response: H3Event['res'];
943
- /**
944
- * The data to send to the client
945
- */
946
- resource: R$1;
947
- /**
948
- * The final response data object
949
- */
950
- body: BodyResource;
951
- /**
952
- * Flag to track if response should be sent automatically
953
- */
954
- private shouldSend;
955
- /**
956
- * Flag to track if response has been sent
957
- */
958
- private responseSent;
959
- /**
960
- * Declare that this includes R's properties
961
- */
962
- [key: string]: any;
963
- /**
964
- * @param req The request instance
965
- * @param res The response instance
966
- * @param rsc The data to send to the client
967
- */
968
- constructor(event: H3Event, rsc: R$1);
969
- /**
970
- * Return the data in the expected format
971
- *
972
- * @returns
973
- */
974
- data(): Resource;
975
- /**
976
- * Build the response object
977
- * @returns this
978
- */
979
- json(): this;
980
- /**
981
- * Add context data to the response object
982
- * @param data Context data
983
- * @returns this
984
- */
985
- additional<X extends {
986
- [key: string]: any;
987
- }>(data: X): this;
988
- /**
989
- * Send the output to the client
990
- * @returns this
991
- */
992
- send(): this;
993
- /**
994
- * Set the status code for this response
995
- * @param code Status code
996
- * @returns this
997
- */
998
- status(code: number): this;
999
- /**
1000
- * Check if send should be triggered automatically
1001
- */
1002
- private checkSend;
1003
- }
1004
- //#endregion
1005
- //#region src/Resources/ApiResource.d.ts
1006
- declare function ApiResource(instance: JsonResource): JsonResource<any>;
1007
- //#endregion
1008
- //#region src/Response.d.ts
1009
- declare class Response implements IResponse {
1010
- /**
1011
- * The current app instance
1012
- */
1013
- app: Application;
1014
- /**
1015
- * The current H3 H3Event instance
1016
- */
1017
- private readonly event;
1018
- private statusCode;
1019
- private headers;
1020
- constructor(event: H3Event,
1021
- /**
1022
- * The current app instance
1023
- */
1024
- app: Application);
1025
- /**
1026
- * Set HTTP status code.
1027
- */
1028
- setStatusCode(code: number): this;
1029
- /**
1030
- * Set a header.
1031
- */
1032
- setHeader(name: string, value: string): this;
1033
- html(content: string): HTTPResponse;
1034
- /**
1035
- * Send a JSON response.
1036
- */
1037
- json<T = unknown>(data: T): T;
1038
- /**
1039
- * Send plain text.
1040
- */
1041
- text(data: string): string;
1042
- /**
1043
- * Redirect to another URL.
1044
- */
1045
- redirect(location: string, status?: number, statusText?: string | undefined): HTTPResponse;
1046
- /**
1047
- * Apply headers before sending response.
1048
- */
1049
- private applyHeaders;
1050
- /**
1051
- * Get the base event
1052
- */
1053
- getEvent(): H3Event;
1054
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
1055
- }
1056
- //#endregion
1057
- export { ApiResource, BadRequestException, FileBag, FireCommand, FormRequest, HeaderBag, HttpContext, HttpServiceProvider, InputBag, JsonResource, LogRequests, Middleware, ParamBag, Request, RequestMethod, RequestObject, Resource, Response, ServerBag, SuspiciousOperationException, UnexpectedValueException, UploadedFile };