@h3ravel/http 11.7.3 → 11.7.5

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.mts DELETED
@@ -1,1897 +0,0 @@
1
- /// <reference path="./app.globals.d.ts" />
2
- import { Command } from "@h3ravel/musket";
3
- import { DotNestedKeys, DotNestedValue, HttpContext as HttpContext$1, IApplication, IMiddleware, IParamBag, IRequest, IResponse, RequestMethod, RequestObject, ResponseObject } from "@h3ravel/shared";
4
- import { EventHandlerRequest, H3Event, HTTPResponse } from "h3";
5
- import { DateTime } from "@h3ravel/support";
6
- import { Application } from "@h3ravel/core";
7
- import { Url } from "@h3ravel/url";
8
-
9
- //#region src/Commands/FireCommand.d.ts
10
- declare class FireCommand extends Command {
11
- /**
12
- * The name and signature of the console command.
13
- *
14
- * @var string
15
- */
16
- protected signature: string;
17
- /**
18
- * The console command description.
19
- *
20
- * @var string
21
- */
22
- protected description: string;
23
- handle(): Promise<void>;
24
- protected fire(): Promise<void>;
25
- }
26
- //#endregion
27
- //#region src/Contracts/HttpContract.d.ts
28
- type CacheOptions = Partial<{
29
- must_revalidate: boolean;
30
- no_cache: boolean;
31
- no_store: boolean;
32
- no_transform: boolean;
33
- public: boolean;
34
- private: boolean;
35
- proxy_revalidate: boolean;
36
- max_age: number;
37
- s_maxage: number;
38
- immutable: boolean;
39
- stale_while_revalidate: number;
40
- stale_if_error: number;
41
- last_modified: string | Date;
42
- etag: string;
43
- }>;
44
- //#endregion
45
- //#region src/Exceptions/BadRequestException.d.ts
46
- declare class BadRequestException extends Error {
47
- constructor(message: string);
48
- }
49
- //#endregion
50
- //#region src/Exceptions/ConflictingHeadersException.d.ts
51
- declare class ConflictingHeadersException extends Error {
52
- constructor(message: string);
53
- }
54
- //#endregion
55
- //#region src/Utilities/HeaderBag.d.ts
56
- /**
57
- * HeaderBag — A container for HTTP headers
58
- * for Node/H3 environments.
59
- */
60
- declare class HeaderBag implements Iterable<[string, (string | null)[]]> {
61
- protected static readonly UPPER = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ";
62
- protected static readonly LOWER = "-abcdefghijklmnopqrstuvwxyz";
63
- protected headers: Record<string, (string | null)[]>;
64
- protected headerNames: Record<string, string>;
65
- protected cacheControl: Record<string, string | boolean>;
66
- constructor(headers?: Record<string, string | string[] | null>);
67
- /**
68
- * Returns all headers as string (for debugging / toString)
69
- *
70
- * @returns
71
- */
72
- toString(): string;
73
- /**
74
- * Returns all headers or specific header list
75
- *
76
- * @param key
77
- * @returns
78
- */
79
- all<K extends string | undefined>(key?: K): K extends string ? (string | null)[] : Record<string, (string | null)[]>;
80
- /**
81
- * Returns header keys
82
- *
83
- * @returns
84
- */
85
- keys(): string[];
86
- /**
87
- * Replace all headers with new set
88
- *
89
- * @param headers
90
- */
91
- replace(headers?: Record<string, string | string[] | null>): void;
92
- /**
93
- * Add multiple headers
94
- *
95
- * @param headers
96
- */
97
- add(headers: Record<string, string | string[] | null>): void;
98
- /**
99
- * Returns first header value by name or default
100
- *
101
- * @param key
102
- * @param defaultValue
103
- * @returns
104
- */
105
- get<R = undefined>(key: string, defaultValue?: string | null): R extends undefined ? string | null : R;
106
- /**
107
- * Sets a header by name.
108
- *
109
- * @param replace Whether to replace existing values (default true)
110
- */
111
- set(key: string, values: string | string[] | null, replace?: boolean): void;
112
- /**
113
- * Returns true if header exists
114
- *
115
- * @param key
116
- * @returns
117
- */
118
- has(key: string): boolean;
119
- /**
120
- * Returns true if header contains value
121
- *
122
- * @param key
123
- * @param value
124
- * @returns
125
- */
126
- contains(key: string, value: string): boolean;
127
- /**
128
- * Removes a header
129
- *
130
- * @param key
131
- */
132
- remove(key: string): void;
133
- /**
134
- * Returns parsed date from header
135
- *
136
- * @param key
137
- * @param defaultValue
138
- * @returns
139
- */
140
- getDate(key: string, defaultValue?: Date | null): DateTime | undefined;
141
- /**
142
- * Adds a Cache-Control directive
143
- *
144
- * @param key
145
- * @param value
146
- */
147
- addCacheControlDirective(key: string, value?: string | boolean): void;
148
- /**
149
- * Returns true if Cache-Control directive is defined
150
- *
151
- * @param key
152
- * @returns
153
- */
154
- hasCacheControlDirective(key: string): boolean;
155
- /**
156
- * Returns a Cache-Control directive value by name
157
- *
158
- * @param key
159
- * @returns
160
- */
161
- getCacheControlDirective(key: string): string | boolean | null;
162
- /**
163
- * Removes a Cache-Control directive
164
- *
165
- * @param key
166
- * @returns
167
- */
168
- removeCacheControlDirective(key: string): void;
169
- /**
170
- * Number of headers
171
- *
172
- * @param key
173
- * @returns
174
- */
175
- count(): number;
176
- /**
177
- * Normalize header name to lowercase with hyphens
178
- *
179
- * @param key
180
- * @returns
181
- */
182
- protected normalizeKey(key: string): string;
183
- /**
184
- * Generates Cache-Control header string
185
- *
186
- * @param header
187
- * @returns
188
- */
189
- protected getCacheControlHeader(): string;
190
- /**
191
- * Parses Cache-Control header
192
- *
193
- * @param header
194
- * @returns
195
- */
196
- protected parseCacheControl(header: string): Record<string, string | boolean>;
197
- /**
198
- * Iterator support
199
- * @returns
200
- */
201
- [Symbol.iterator](): Iterator<[string, (string | null)[]]>;
202
- }
203
- //#endregion
204
- //#region src/Utilities/Cookie.d.ts
205
- /**
206
- * Represents a Cookie
207
- */
208
- declare class Cookie {
209
- private name;
210
- private value?;
211
- private domain?;
212
- private secure?;
213
- private httpOnly;
214
- static readonly SAMESITE_NONE = "none";
215
- static readonly SAMESITE_LAX = "lax";
216
- static readonly SAMESITE_STRICT = "strict";
217
- private expire;
218
- private path;
219
- private sameSite?;
220
- private raw;
221
- private partitioned;
222
- private secureDefault;
223
- private static readonly RESERVED_CHARS_LIST;
224
- private static readonly RESERVED_CHARS_FROM;
225
- private static readonly RESERVED_CHARS_TO;
226
- constructor(name: string, value?: string | null | undefined, expire?: number | string | Date, path?: string, domain?: string | null | undefined, secure?: boolean | null | undefined, httpOnly?: boolean, raw?: boolean, sameSite?: string | null, partitioned?: boolean);
227
- /**
228
- * Create a Cookie instance from a Set-Cookie header string.
229
- */
230
- static fromString(cookie: string, decode?: boolean): Cookie;
231
- /**
232
- * Convert various expiration formats into a timestamp (seconds)
233
- */
234
- private static expiresTimestamp;
235
- private clone;
236
- withValue(value: string | null): Cookie;
237
- withDomain(domain: string | null): Cookie;
238
- withPath(path: string | null): Cookie;
239
- withSecure(secure?: boolean): Cookie;
240
- withHttpOnly(httpOnly?: boolean): Cookie;
241
- withRaw(raw?: boolean): Cookie;
242
- withSameSite(sameSite?: string | null): Cookie;
243
- withPartitioned(partitioned?: boolean): Cookie;
244
- withExpires(expire: number | string | Date): Cookie;
245
- getName(): string;
246
- getValue(): string | undefined | null;
247
- getDomain(): string | undefined | null;
248
- getPath(): string;
249
- getExpiresTime(): number;
250
- getMaxAge(): number;
251
- /**
252
- * Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client.
253
- */
254
- isSecure(): boolean;
255
- isHttpOnly(): boolean;
256
- isRaw(): boolean;
257
- getSameSite(): string | undefined | null;
258
- isPartitioned(): boolean;
259
- /**
260
- * Whether this cookie is about to be cleared.
261
- */
262
- isCleared(): boolean;
263
- /**
264
- * Convert the cookie to a Set-Cookie header string.
265
- */
266
- toString(): string;
267
- /**
268
- * @param bool $default The default value of the "secure" flag when it is set to null
269
- */
270
- setSecureDefault(defaultValue: boolean): void;
271
- }
272
- //#endregion
273
- //#region src/Utilities/ResponseHeaderBag.d.ts
274
- /**
275
- * ResponseHeaderBag is a container for Response HTTP headers.
276
- * for Node/H3 environments.
277
- */
278
- declare class ResponseHeaderBag extends HeaderBag {
279
- static readonly COOKIES_FLAT = "flat";
280
- static readonly COOKIES_ARRAY = "array";
281
- static readonly DISPOSITION_ATTACHMENT = "attachment";
282
- static readonly DISPOSITION_INLINE = "inline";
283
- protected computedCacheControl: Record<string, string | boolean>;
284
- protected cookies: Record<string, Record<string, Record<string, Cookie>>>;
285
- protected headerNames: Record<string, string>;
286
- constructor(
287
- /**
288
- * The current H3 H3Event instance
289
- */
290
- event: H3Event);
291
- /**
292
- * Returns the headers with original capitalizations.
293
- */
294
- allPreserveCase(): Record<string, string[]>;
295
- allPreserveCaseWithoutCookies(): Record<string, string[]>;
296
- replace(headers?: Record<string, string | string[]>): void;
297
- all<K extends string | undefined>(key?: K): K extends string ? (string | null)[] : Record<string, (string | null)[]>;
298
- set(key: string, values: string | string[] | null, replace?: boolean): void;
299
- remove(key: string): void;
300
- hasCacheControlDirective(key: string): boolean;
301
- getCacheControlDirective(key: string): boolean | string | null;
302
- setCookie(cookie: Cookie): void;
303
- removeCookie(name: string, path?: string, domain?: string | null): void;
304
- /**
305
- * @throws {Error} if format is invalid
306
- */
307
- getCookies(format?: string): Cookie[] | Record<string, any>;
308
- clearCookie(name: string, path?: string, domain?: string | null, secure?: boolean, httpOnly?: boolean, sameSite?: string | null, partitioned?: boolean): void;
309
- makeDisposition(disposition: string, filename: string, fallback?: string): string;
310
- protected computeCacheControlValue(): string;
311
- private initDate;
312
- }
313
- //#endregion
314
- //#region src/Utilities/HttpResponse.d.ts
315
- declare class HttpResponse {
316
- /**
317
- * The current H3 H3Event instance
318
- */
319
- protected readonly event: H3Event;
320
- protected statusCode: number;
321
- protected headers: ResponseHeaderBag;
322
- protected content: any;
323
- protected version: string;
324
- protected statusText: string;
325
- protected charset?: string;
326
- /**
327
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
328
- */
329
- private HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES;
330
- /**
331
- * The exception that triggered the error response (if applicable).
332
- */
333
- exception?: Error;
334
- /**
335
- * Tracks headers already sent in informational responses.
336
- */
337
- private sentHeaders;
338
- /**
339
- * Status codes translation table.
340
- *
341
- * The list of codes is complete according to the
342
- * @link https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml Hypertext Transfer Protocol (HTTP) Status Code Registry
343
- * (last updated 2021-10-01).
344
- *
345
- * Unless otherwise noted, the status code is defined in RFC2616.
346
- */
347
- static statusTexts: {
348
- [key: number]: string;
349
- };
350
- constructor(
351
- /**
352
- * The current H3 H3Event instance
353
- */
354
- event: H3Event);
355
- /**
356
- * Set HTTP status code.
357
- */
358
- setStatusCode(code: number, text?: string): this;
359
- /**
360
- * Retrieves the status code for the current web response.
361
- */
362
- getStatusCode(): number;
363
- /**
364
- * Sets the response charset.
365
- */
366
- setCharset(charset: string): this;
367
- /**
368
- * Retrieves the response charset.
369
- */
370
- getCharset(): string | undefined;
371
- /**
372
- * Returns true if the response may safely be kept in a shared (surrogate) cache.
373
- *
374
- * Responses marked "private" with an explicit Cache-Control directive are
375
- * considered uncacheable.
376
- *
377
- * Responses with neither a freshness lifetime (Expires, max-age) nor cache
378
- * validator (Last-Modified, ETag) are considered uncacheable because there is
379
- * no way to tell when or how to remove them from the cache.
380
- *
381
- * Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
382
- * for example "status codes that are defined as cacheable by default [...]
383
- * can be reused by a cache with heuristic expiration unless otherwise indicated"
384
- * (https://tools.ietf.org/html/rfc7231#section-6.1)
385
- *
386
- * @final
387
- */
388
- isCacheable(): boolean;
389
- /**
390
- * Returns true if the response is "fresh".
391
- *
392
- * Fresh responses may be served from cache without any interaction with the
393
- * origin. A response is considered fresh when it includes a Cache-Control/max-age
394
- * indicator or Expires header and the calculated age is less than the freshness lifetime.
395
- */
396
- isFresh(): boolean;
397
- /**
398
- * Returns true if the response includes headers that can be used to validate
399
- * the response with the origin server using a conditional GET request.
400
- */
401
- isValidateable(): boolean;
402
- /**
403
- * Sets the response content.
404
- */
405
- setContent(content?: any): this;
406
- /**
407
- * Gets the current response content.
408
- */
409
- getContent(): any;
410
- /**
411
- * Set a header.
412
- */
413
- setHeader(name: string, value: string): this;
414
- /**
415
- * Sets the HTTP protocol version (1.0 or 1.1).
416
- */
417
- setProtocolVersion(version: string): this;
418
- /**
419
- * Gets the HTTP protocol version.
420
- */
421
- getProtocolVersion(): string;
422
- /**
423
- * Marks the response as "private".
424
- *
425
- * It makes the response ineligible for serving other clients.
426
- */
427
- setPrivate(): this;
428
- /**
429
- * Marks the response as "public".
430
- *
431
- * It makes the response eligible for serving other clients.
432
- */
433
- setPublic(): this;
434
- /**
435
- * Returns the Date header as a DateTime instance.
436
- * @throws {RuntimeException} When the header is not parseable
437
- */
438
- getDate(): DateTime | undefined;
439
- /**
440
- * Returns the age of the response in seconds.
441
- *
442
- * @final
443
- */
444
- getAge(): number;
445
- /**
446
- * Marks the response stale by setting the Age header to be equal to the maximum age of the response.
447
- */
448
- expire(): this;
449
- /**
450
- * Returns the value of the Expires header as a DateTime instance.
451
- *
452
- * @final
453
- */
454
- getExpires(): DateTime | undefined;
455
- /**
456
- * Returns the number of seconds after the time specified in the response's Date
457
- * header when the response should no longer be considered fresh.
458
- *
459
- * First, it checks for a s-maxage directive, then a max-age directive, and then it falls
460
- * back on an expires header. It returns null when no maximum age can be established.
461
- */
462
- getMaxAge(): number | undefined;
463
- /**
464
- * Sets the number of seconds after which the response should no longer be considered fresh.
465
- *
466
- * This method sets the Cache-Control max-age directive.
467
- */
468
- setMaxAge(value: number): this;
469
- /**
470
- * Sets the number of seconds after which the response should no longer be returned by shared caches when backend is down.
471
- *
472
- * This method sets the Cache-Control stale-if-error directive.
473
- */
474
- setStaleIfError(value: number): this;
475
- /**
476
- * Sets the number of seconds after which the response should no longer return stale content by shared caches.
477
- *
478
- * This method sets the Cache-Control stale-while-revalidate directive.
479
- */
480
- setStaleWhileRevalidate(value: number): this;
481
- /**
482
- * Returns the response's time-to-live in seconds.
483
- *
484
- * It returns null when no freshness information is present in the response.
485
- *
486
- * When the response's TTL is 0, the response may not be served from cache without first
487
- * revalidating with the origin.
488
- *
489
- * @final
490
- */
491
- getTtl(): number | undefined;
492
- /**
493
- * Sets the response's time-to-live for shared caches in seconds.
494
- *
495
- * This method adjusts the Cache-Control/s-maxage directive.
496
- */
497
- setTtl(seconds: number): this;
498
- /**
499
- * Sets the response's time-to-live for private/client caches in seconds.
500
- *
501
- * This method adjusts the Cache-Control/max-age directive.
502
- */
503
- setClientTtl(seconds: number): this;
504
- /**
505
- * Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
506
- *
507
- * This method sets the Cache-Control s-maxage directive.
508
- */
509
- setSharedMaxAge(value: number): this;
510
- /**
511
- * Returns the Last-Modified HTTP header as a DateTime instance.
512
- *
513
- * @throws \RuntimeException When the HTTP header is not parseable
514
- *
515
- * @final
516
- */
517
- getLastModified(): DateTime | undefined;
518
- /**
519
- * Sets the Last-Modified HTTP header with a DateTime instance.
520
- *
521
- * Passing null as value will remove the header.
522
- *
523
- * @return $this
524
- *
525
- * @final
526
- */
527
- setLastModified(date?: DateTime | Date | string): this;
528
- /**
529
- * Returns the literal value of the ETag HTTP header.
530
- */
531
- getEtag(): string | null;
532
- /**
533
- * Sets the ETag value.
534
- *
535
- * @param etag The ETag unique identifier or null to remove the header
536
- * @param weak Whether you want a weak ETag or not
537
- */
538
- setEtag(etag?: string, weak?: boolean): this;
539
- /**
540
- * Sets the response's cache headers (validation and/or expiration).
541
- *
542
- * Available options are: must_revalidate, no_cache, no_store, no_transform, public, private, proxy_revalidate, max_age, s_maxage, immutable, last_modified and etag.
543
- *
544
- * @throws {InvalidArgumentException}
545
- */
546
- setCache(options: CacheOptions): this;
547
- /**
548
- * Modifies the response so that it conforms to the rules defined for a 304 status code.
549
- *
550
- * This sets the status, removes the body, and discards any headers
551
- * that MUST NOT be included in 304 responses.
552
- * @see https://tools.ietf.org/html/rfc2616#section-10.3.5
553
- */
554
- setNotModified(): this;
555
- /**
556
- * Add an array of headers to the response.
557
- *
558
- */
559
- withHeaders(headers: HeaderBag | ResponseObject): this;
560
- /**
561
- * Set the exception to attach to the response.
562
- */
563
- withException(e: Error): this;
564
- /**
565
- * Throws the response in a HttpResponseException instance.
566
- *
567
- * @throws {HttpResponseException}
568
- */
569
- throwResponse(): void;
570
- /**
571
- * Is response invalid?
572
- *
573
- * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
574
- */
575
- isInvalid(): boolean;
576
- /**
577
- * Is response informative?
578
- */
579
- isInformational(): boolean;
580
- /**
581
- * Is response successful?
582
- */
583
- isSuccessful(): boolean;
584
- /**
585
- * Is the response a redirect?
586
- */
587
- isRedirection(): boolean;
588
- /**
589
- * Is there a client error?
590
- */
591
- isClientError(): boolean;
592
- /**
593
- * Was there a server side error?
594
- */
595
- isServerError(): boolean;
596
- /**
597
- * Is the response OK?
598
- */
599
- isOk(): boolean;
600
- /**
601
- * Is the response forbidden?
602
- */
603
- isForbidden(): boolean;
604
- /**
605
- * Is the response a not found error?
606
- */
607
- isNotFound(): boolean;
608
- /**
609
- * Is the response a redirect of some form?
610
- */
611
- isRedirect(location?: string | null): boolean;
612
- /**
613
- * Is the response empty?
614
- */
615
- isEmpty(): boolean;
616
- /**
617
- * Apply headers before sending response.
618
- */
619
- sendHeaders(statusCode?: number): this;
620
- /**
621
- * Prepares the Response before it is sent to the client.
622
- *
623
- * This method tweaks the Response to ensure that it is
624
- * compliant with RFC 2616. Most of the changes are based on
625
- * the Request that is "associated" with this Response.
626
- **/
627
- prepare(request: Request): this;
628
- /**
629
- * Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.
630
- *
631
- * @see http://support.microsoft.com/kb/323308
632
- */
633
- protected ensureIEOverSSLCompatibility(request: Request): void;
634
- }
635
- //#endregion
636
- //#region src/Exceptions/HttpResponseException.d.ts
637
- declare class HttpResponseException extends Error {
638
- /**
639
- * The underlying response instance.
640
- */
641
- protected response: HttpResponse;
642
- /**
643
- * Create a new HTTP response exception instance.
644
- *
645
- * @param response
646
- * @param previous
647
- */
648
- constructor(response: HttpResponse, previous?: Error);
649
- /**
650
- * Get the underlying response instance.
651
- */
652
- getResponse(): HttpResponse;
653
- }
654
- //#endregion
655
- //#region src/Exceptions/SuspiciousOperationException.d.ts
656
- declare class SuspiciousOperationException extends Error {
657
- constructor(message: string);
658
- }
659
- //#endregion
660
- //#region src/Exceptions/UnexpectedValueException.d.ts
661
- declare class UnexpectedValueException extends Error {
662
- constructor(message: string);
663
- }
664
- //#endregion
665
- //#region src/UploadedFile.d.ts
666
- declare class UploadedFile {
667
- originalName: string;
668
- mimeType: string;
669
- size: number;
670
- content: File;
671
- constructor(originalName: string, mimeType: string, size: number, content: File);
672
- static createFromBase(file: File): UploadedFile;
673
- /**
674
- * Save to disk (Node environment only)
675
- */
676
- moveTo(destination: string): Promise<void>;
677
- }
678
- //#endregion
679
- //#region src/FormRequest.d.ts
680
- declare class FormRequest {
681
- protected dataset: {
682
- files: Record<string, File | UploadedFile | (File | UploadedFile)[]>;
683
- input: Record<string, any>;
684
- };
685
- constructor(data: FormData);
686
- /**
687
- * Initialize the data
688
- * @param data
689
- */
690
- initialize(data: FormData): void;
691
- /**
692
- * Get all uploaded files
693
- */
694
- files(): Record<string, File | UploadedFile | (File | UploadedFile)[]>;
695
- /**
696
- * Get all input fields
697
- */
698
- input(): Record<string, any>;
699
- /**
700
- * Get combined input and files
701
- * File entries take precedence if names overlap.
702
- */
703
- all(): Record<string, any>;
704
- }
705
- //#endregion
706
- //#region src/HttpContext.d.ts
707
- /**
708
- * Represents the HTTP context for a single request lifecycle.
709
- * Encapsulates the application instance, request, and response objects.
710
- */
711
- declare class HttpContext implements HttpContext$1 {
712
- app: IApplication;
713
- request: IRequest;
714
- response: IResponse;
715
- private static contexts;
716
- constructor(app: IApplication, request: IRequest, response: IResponse);
717
- /**
718
- * Factory method to create a new HttpContext instance from a context object.
719
- * @param ctx - Object containing app, request, and response
720
- * @returns A new HttpContext instance
721
- */
722
- static init(ctx: {
723
- app: IApplication;
724
- request: IRequest;
725
- response: IResponse;
726
- }, event?: unknown): HttpContext;
727
- /**
728
- * Retrieve an existing HttpContext instance for an event, if any.
729
- */
730
- static get(event: unknown): HttpContext | undefined;
731
- /**
732
- * Delete the cached context for a given event (optional cleanup).
733
- */
734
- static forget(event: unknown): void;
735
- }
736
- //#endregion
737
- //#region src/Middleware.d.ts
738
- declare abstract class Middleware implements IMiddleware {
739
- abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
740
- }
741
- //#endregion
742
- //#region src/Middleware/LogRequests.d.ts
743
- declare class LogRequests extends Middleware {
744
- handle({
745
- request
746
- }: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
747
- }
748
- //#endregion
749
- //#region src/Providers/HttpServiceProvider.d.ts
750
- /**
751
- * Sets up HTTP kernel and request lifecycle.
752
- *
753
- * Register Request, Response, and Middleware classes.
754
- * Configure global middleware stack.
755
- * Boot HTTP kernel.
756
- *
757
- * Auto-Registered
758
- */
759
- declare class HttpServiceProvider {
760
- private app;
761
- static priority: number;
762
- registeredCommands?: (new (app: any, kernel: any) => any)[];
763
- constructor(app: any);
764
- register(): void;
765
- boot(): void;
766
- }
767
- //#endregion
768
- //#region src/Utilities/ParamBag.d.ts
769
- /**
770
- * ParamBag is a container for key/value pairs
771
- * for Node/H3 environments.
772
- */
773
- declare class ParamBag implements IParamBag {
774
- protected parameters: RequestObject;
775
- /**
776
- * The current H3 H3Event instance
777
- */
778
- readonly event: H3Event;
779
- constructor(parameters: RequestObject | undefined,
780
- /**
781
- * The current H3 H3Event instance
782
- */
783
- event: H3Event);
784
- /**
785
- * Returns the parameters.
786
- * @
787
- * @param key The name of the parameter to return or null to get them all
788
- *
789
- * @throws BadRequestException if the value is not an array
790
- */
791
- all(key?: string): any;
792
- get(key: string, defaultValue?: any): any;
793
- set(key: string, value: any): void;
794
- /**
795
- * Returns true if the parameter is defined.
796
- *
797
- * @param key
798
- */
799
- has(key: string): boolean;
800
- /**
801
- * Removes a parameter.
802
- *
803
- * @param key
804
- */
805
- remove(key: string): void;
806
- /**
807
- *
808
- * Returns the parameter as string.
809
- *
810
- * @param key
811
- * @param defaultValue
812
- * @throws UnexpectedValueException if the value cannot be converted to string
813
- * @returns
814
- */
815
- getString(key: string, defaultValue?: string): string;
816
- /**
817
- * Returns the parameter value converted to integer.
818
- *
819
- * @param key
820
- * @param defaultValue
821
- * @throws UnexpectedValueException if the value cannot be converted to integer
822
- */
823
- getInt(key: string, defaultValue?: number): number;
824
- /**
825
- * Returns the parameter value converted to boolean.
826
- *
827
- * @param key
828
- * @param defaultValue
829
- * @throws UnexpectedValueException if the value cannot be converted to a boolean
830
- */
831
- getBoolean(key: string, defaultValue?: boolean): boolean;
832
- /**
833
- * Returns the alphabetic characters of the parameter value.
834
- *
835
- * @param key
836
- * @param defaultValue
837
- * @throws UnexpectedValueException if the value cannot be converted to string
838
- */
839
- getAlpha(key: string, defaultValue?: string): string;
840
- /**
841
- * Returns the alphabetic characters and digits of the parameter value.
842
- *
843
- * @param key
844
- * @param defaultValue
845
- * @throws UnexpectedValueException if the value cannot be converted to string
846
- */
847
- getAlnum(key: string, defaultValue?: string): string;
848
- /**
849
- * Returns the digits of the parameter value.
850
- *
851
- * @param key
852
- * @param defaultValue
853
- * @throws UnexpectedValueException if the value cannot be converted to string
854
- * @returns
855
- **/
856
- getDigits(key: string, defaultValue?: string): string;
857
- /**
858
- * Returns the parameter keys.
859
- */
860
- keys(): string[];
861
- /**
862
- * Replaces the current parameters by a new set.
863
- */
864
- replace(parameters?: RequestObject): void;
865
- /**
866
- * Adds parameters.
867
- */
868
- add(parameters?: RequestObject): void;
869
- /**
870
- * Returns the number of parameters.
871
- */
872
- count(): number;
873
- /**
874
- * Returns an iterator for parameters.
875
- *
876
- * @returns
877
- */
878
- [Symbol.iterator](): ArrayIterator<[string, any]>;
879
- }
880
- //#endregion
881
- //#region src/Utilities/InputBag.d.ts
882
- /**
883
- * InputBag is a container for user input values
884
- * (e.g., query params, body, cookies)
885
- * for Node/H3 environments.
886
- */
887
- declare class InputBag extends ParamBag {
888
- constructor(inputs: RequestObject | undefined,
889
- /**
890
- * The current H3 H3Event instance
891
- */
892
- event: H3Event);
893
- /**
894
- * Returns a scalar input value by name.
895
- *
896
- * @param key
897
- * @param defaultValue
898
- * @throws BadRequestException if the input contains a non-scalar value
899
- * @returns
900
- */
901
- get<T extends string | number | boolean | null>(key: string, defaultValue?: T | null): T | string | number | boolean | null;
902
- /**
903
- * Replaces all current input values.
904
- *
905
- * @param inputs
906
- * @returns
907
- */
908
- replace(inputs?: RequestObject): void;
909
- /**
910
- * Adds multiple input values.
911
- *
912
- * @param inputs
913
- * @returns
914
- */
915
- add(inputs?: RequestObject): void;
916
- /**
917
- * Sets an input by name.
918
- *
919
- * @param key
920
- * @param value
921
- * @throws TypeError if value is not scalar or array
922
- * @returns
923
- */
924
- set(key: string, value: any): void;
925
- /**
926
- * Returns true if a key exists.
927
- *
928
- * @param key
929
- * @returns
930
- */
931
- has(key: string): boolean;
932
- /**
933
- * Returns all parameters.
934
- *
935
- * @returns
936
- */
937
- all(): RequestObject;
938
- /**
939
- * Converts a parameter value to string.
940
- *
941
- * @param key
942
- * @param defaultValue
943
- * @throws BadRequestException if input contains a non-scalar value
944
- * @returns
945
- */
946
- getString(key: string, defaultValue?: string): string;
947
- /**
948
- * Filters input value with a predicate.
949
- * Mimics PHP’s filter_var() in spirit, but simpler.
950
- *
951
- * @param key
952
- * @param defaultValue
953
- * @param filterFn
954
- * @throws BadRequestException if validation fails
955
- * @returns
956
- */
957
- filter<T = any>(key: string, defaultValue?: T | null, filterFn?: (value: any) => boolean): T | null;
958
- /**
959
- * Returns an enum value by key.
960
- *
961
- * @param key
962
- * @param EnumClass
963
- * @param defaultValue
964
- * @throws BadRequestException if conversion fails
965
- * @returns
966
- */
967
- getEnum<T extends Record<string, string | number>>(key: string, EnumClass: T, defaultValue?: T[keyof T] | null): T[keyof T] | null;
968
- /**
969
- * Removes a key.
970
- *
971
- * @param key
972
- */
973
- remove(key: string): void;
974
- /**
975
- * Returns all keys.
976
- *
977
- * @returns
978
- */
979
- keys(): string[];
980
- /**
981
- * Returns number of parameters.
982
- *
983
- * @returns
984
- */
985
- count(): number;
986
- }
987
- //#endregion
988
- //#region src/Utilities/FileBag.d.ts
989
- type FileInput = UploadedFile | File | null | undefined;
990
- /**
991
- * FileBag is a container for uploaded files
992
- * for Node/H3 environments.
993
- */
994
- declare class FileBag extends ParamBag {
995
- protected parameters: Record<string, UploadedFile | UploadedFile[] | null>;
996
- constructor(parameters: Record<string, FileInput | FileInput[]> | undefined,
997
- /**
998
- * The current H3 H3Event instance
999
- */
1000
- event: H3Event);
1001
- /**
1002
- * Replace all stored files.
1003
- */
1004
- replace(files?: Record<string, FileInput | FileInput[]>): void;
1005
- /**
1006
- * Set a file or array of files.
1007
- */
1008
- set(key: string, value: FileInput | FileInput[]): void;
1009
- /**
1010
- * Add multiple files.
1011
- */
1012
- add(files?: Record<string, FileInput | FileInput[]>): void;
1013
- /**
1014
- * Get all stored files.
1015
- */
1016
- all(): Record<string, UploadedFile | UploadedFile[] | null>;
1017
- /**
1018
- * Normalize file input into UploadedFile instances.
1019
- */
1020
- protected convertFileInformation(file: FileInput): UploadedFile | null;
1021
- }
1022
- //#endregion
1023
- //#region src/Utilities/ServerBag.d.ts
1024
- /**
1025
- * ServerBag — a simplified version of Symfony's ServerBag
1026
- * for Node/H3 environments.
1027
- *
1028
- * Responsible for extracting and normalizing HTTP headers
1029
- * from the incoming request.
1030
- */
1031
- declare class ServerBag extends ParamBag {
1032
- constructor(parameters: Record<string, string | undefined> | undefined,
1033
- /**
1034
- * The current H3 H3Event instance
1035
- */
1036
- event: H3Event);
1037
- /**
1038
- * Returns all request headers, normalized to uppercase with underscores.
1039
- * Example: content-type → CONTENT_TYPE
1040
- */
1041
- getHeaders(): Record<string, string>;
1042
- /**
1043
- * Returns a specific header by name, case-insensitive.
1044
- */
1045
- get(name: string): string | undefined;
1046
- /**
1047
- * Returns true if a header exists.
1048
- */
1049
- has(name: string): boolean;
1050
- }
1051
- //#endregion
1052
- //#region src/Utilities/HttpRequest.d.ts
1053
- declare class HttpRequest {
1054
- #private;
1055
- /**
1056
- * The current H3 H3Event instance
1057
- */
1058
- protected readonly event: H3Event;
1059
- /**
1060
- * The current app instance
1061
- */
1062
- app: Application;
1063
- HEADER_FORWARDED: number;
1064
- HEADER_X_FORWARDED_FOR: number;
1065
- HEADER_X_FORWARDED_HOST: number;
1066
- HEADER_X_FORWARDED_PROTO: number;
1067
- HEADER_X_FORWARDED_PORT: number;
1068
- HEADER_X_FORWARDED_PREFIX: number;
1069
- HEADER_X_FORWARDED_AWS_ELB: number;
1070
- HEADER_X_FORWARDED_TRAEFIK: number;
1071
- METHOD_HEAD: string;
1072
- METHOD_GET: string;
1073
- METHOD_POST: string;
1074
- METHOD_PUT: string;
1075
- METHOD_PATCH: string;
1076
- METHOD_DELETE: string;
1077
- METHOD_PURGE: string;
1078
- METHOD_OPTIONS: string;
1079
- METHOD_TRACE: string;
1080
- METHOD_CONNECT: string;
1081
- /**
1082
- * Names for headers that can be trusted when
1083
- * using trusted proxies.
1084
- *
1085
- * The FORWARDED header is the standard as of rfc7239.
1086
- *
1087
- * The other headers are non-standard, but widely used
1088
- * by popular reverse proxies (like Apache mod_proxy or Amazon EC2).
1089
- */
1090
- private TRUSTED_HEADERS;
1091
- private FORWARDED_PARAMS;
1092
- /**
1093
- * Parsed request body
1094
- */
1095
- body: unknown;
1096
- protected format?: string;
1097
- protected formData: FormRequest;
1098
- private preferredFormat?;
1099
- private isForwardedValid;
1100
- private static trustedHeaderSet;
1101
- /**
1102
- * Gets route parameters.
1103
- * @returns An object containing route parameters.
1104
- */
1105
- params: NonNullable<H3Event['context']['params']>;
1106
- /**
1107
- * Request body parameters (POST).
1108
- *
1109
- * @see getPayload() for portability between content types
1110
- */
1111
- protected request: InputBag;
1112
- /**
1113
- * Uploaded files (FILES).
1114
- */
1115
- files: FileBag;
1116
- /**
1117
- * Query string parameters (GET).
1118
- */
1119
- query: InputBag;
1120
- /**
1121
- * Server and execution environment parameters
1122
- */
1123
- server: ServerBag;
1124
- /**
1125
- * Cookies
1126
- */
1127
- cookies: InputBag;
1128
- /**
1129
- * The request attributes (parameters parsed from the PATH_INFO, ...).
1130
- */
1131
- attributes: ParamBag;
1132
- /**
1133
- * Gets the request headers.
1134
- * @returns An object containing request headers.
1135
- */
1136
- headers: HeaderBag;
1137
- protected content?: ReadableStream | string | false | null;
1138
- protected static formats?: Record<string, string[]> | undefined | null;
1139
- protected static trustedProxies: string[];
1140
- protected static httpMethodParameterOverride: boolean;
1141
- /**
1142
- * List of Acceptable Content Types
1143
- */
1144
- private acceptableContentTypes;
1145
- private trustedValuesCache;
1146
- constructor(
1147
- /**
1148
- * The current H3 H3Event instance
1149
- */
1150
- event: H3Event,
1151
- /**
1152
- * The current app instance
1153
- */
1154
- app: Application);
1155
- /**
1156
- * Sets the parameters for this request.
1157
- *
1158
- * This method also re-initializes all properties.
1159
- *
1160
- * @param attributes
1161
- * @param cookies The COOKIE parameters
1162
- * @param files The FILES parameters
1163
- * @param server The SERVER parameters
1164
- * @param content The raw body data
1165
- */
1166
- initialize(): Promise<void>;
1167
- /**
1168
- * Gets a list of content types acceptable by the client browser in preferable order.
1169
- * @returns {string[]}
1170
- */
1171
- getAcceptableContentTypes(): string[];
1172
- /**
1173
- * Get a URI instance for the request.
1174
- */
1175
- getUriInstance(): Url;
1176
- /**
1177
- * Checks whether the request is secure or not.
1178
- *
1179
- * This method can read the client protocol from the "X-Forwarded-Proto" header
1180
- * when trusted proxies were set via "setTrustedProxies()".
1181
- *
1182
- * The "X-Forwarded-Proto" header must contain the protocol: "https" or "http".
1183
- */
1184
- isSecure(): boolean;
1185
- /**
1186
- * Returns the value of the requested header.
1187
- */
1188
- getHeader(name: string): string | undefined | null;
1189
- /**
1190
- * Checks if the request method is of specified type.
1191
- *
1192
- * @param method Uppercase request method (GET, POST etc)
1193
- */
1194
- isMethod(method: string): boolean;
1195
- /**
1196
- * Checks whether or not the method is safe.
1197
- *
1198
- * @see https://tools.ietf.org/html/rfc7231#section-4.2.1
1199
- */
1200
- isMethodSafe(): boolean;
1201
- /**
1202
- * Checks whether or not the method is idempotent.
1203
- */
1204
- isMethodIdempotent(): boolean;
1205
- /**
1206
- * Checks whether the method is cacheable or not.
1207
- *
1208
- * @see https://tools.ietf.org/html/rfc7231#section-4.2.3
1209
- */
1210
- isMethodCacheable(): boolean;
1211
- /**
1212
- * Returns true if the request is an XMLHttpRequest (AJAX).
1213
- */
1214
- isXmlHttpRequest(): boolean;
1215
- /**
1216
- * Initializes HTTP request formats.
1217
- */
1218
- protected static initializeFormats(): void;
1219
- /**
1220
- * Gets the request "intended" method.
1221
- *
1222
- * If the X-HTTP-Method-Override header is set, and if the method is a POST,
1223
- * then it is used to determine the "real" intended HTTP method.
1224
- *
1225
- * The _method request parameter can also be used to determine the HTTP method,
1226
- * but only if enableHttpMethodParameterOverride() has been called.
1227
- *
1228
- * The method is always an uppercased string.
1229
- *
1230
- * @see getRealMethod()
1231
- */
1232
- getMethod(): RequestMethod;
1233
- /**
1234
- * Gets the preferred format for the response by inspecting, in the following order:
1235
- * * the request format set using setRequestFormat;
1236
- * * the values of the Accept HTTP header.
1237
- *
1238
- * Note that if you use this method, you should send the "Vary: Accept" header
1239
- * in the response to prevent any issues with intermediary HTTP caches.
1240
- */
1241
- getPreferredFormat(defaultValue?: string): string | undefined;
1242
- /**
1243
- * Gets the format associated with the mime type.
1244
- */
1245
- getFormat(mimeType: string): string | undefined;
1246
- /**
1247
- * Gets the request format.
1248
- *
1249
- * Here is the process to determine the format:
1250
- *
1251
- * * format defined by the user (with setRequestFormat())
1252
- * * _format request attribute
1253
- * * $default
1254
- *
1255
- * @see getPreferredFormat
1256
- */
1257
- getRequestFormat(defaultValue?: string): string | undefined;
1258
- /**
1259
- * Sets the request format.
1260
- */
1261
- setRequestFormat(format: string): void;
1262
- /**
1263
- * Gets the "real" request method.
1264
- *
1265
- * @see getMethod()
1266
- */
1267
- getRealMethod(): RequestMethod;
1268
- /**
1269
- * Gets the mime type associated with the format.
1270
- */
1271
- getMimeType(format: string): string | undefined;
1272
- /**
1273
- * Gets the mime types associated with the format.
1274
- */
1275
- static getMimeTypes(format: string): string[];
1276
- /**
1277
- * Gets the list of trusted proxies.
1278
- */
1279
- static getTrustedProxies(): string[];
1280
- /**
1281
- * Returns the request body content.
1282
- *
1283
- * @param asStream If true, returns a ReadableStream instead of the parsed string
1284
- * @return {string | ReadableStream | Promise<string | ReadableStream>}
1285
- */
1286
- getContent(asStream?: boolean): string | ReadableStream;
1287
- /**
1288
- * Gets a "parameter" value from any bag.
1289
- *
1290
- * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
1291
- * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
1292
- * public property instead (attributes, query, request).
1293
- *
1294
- * Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
1295
- *
1296
- * @internal use explicit input sources instead
1297
- */
1298
- get(key: string, defaultValue?: any): any;
1299
- /**
1300
- * Indicates whether this request originated from a trusted proxy.
1301
- *
1302
- * This can be useful to determine whether or not to trust the
1303
- * contents of a proxy-specific header.
1304
- */
1305
- isFromTrustedProxy(): boolean;
1306
- /**
1307
- * This method is rather heavy because it splits and merges headers, and it's called by many other methods such as
1308
- * getPort(), isSecure(), getHost(), getClientIps(), getBaseUrl() etc. Thus, we try to cache the results for
1309
- * best performance.
1310
- */
1311
- private getTrustedValues;
1312
- private normalizeAndFilterClientIps;
1313
- /**
1314
- * Enables support for the _method request parameter to determine the intended HTTP method.
1315
- *
1316
- * Be warned that enabling this feature might lead to CSRF issues in your code.
1317
- * Check that you are using CSRF tokens when required.
1318
- * If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
1319
- * and used to send a "PUT" or "DELETE" request via the _method request parameter.
1320
- * If these methods are not protected against CSRF, this presents a possible vulnerability.
1321
- *
1322
- * The HTTP method can only be overridden when the real HTTP method is POST.
1323
- */
1324
- static enableHttpMethodParameterOverride(): void;
1325
- /**
1326
- * Checks whether support for the _method request parameter is enabled.
1327
- */
1328
- static getHttpMethodParameterOverride(): boolean;
1329
- }
1330
- //#endregion
1331
- //#region src/Request.d.ts
1332
- declare class Request extends HttpRequest implements IRequest {
1333
- #private;
1334
- /**
1335
- * All of the converted files for the request.
1336
- */
1337
- protected convertedFiles?: Record<string, UploadedFile | UploadedFile[]>;
1338
- constructor(
1339
- /**
1340
- * The current H3 H3Event instance
1341
- */
1342
- event: H3Event,
1343
- /**
1344
- * The current app instance
1345
- */
1346
- app: Application);
1347
- /**
1348
- * Factory method to create a Request instance from an H3Event.
1349
- */
1350
- static create(
1351
- /**
1352
- * The current H3 H3Event instance
1353
- */
1354
- event: H3Event,
1355
- /**
1356
- * The current app instance
1357
- */
1358
- app: Application): Promise<Request>;
1359
- private setBody;
1360
- /**
1361
- * Retrieve all data from the instance (query + body).
1362
- */
1363
- all<T = Record<string, any>>(keys?: string | string[]): T;
1364
- /**
1365
- * Retrieve an input item from the request.
1366
- *
1367
- * @param key
1368
- * @param defaultValue
1369
- * @returns
1370
- */
1371
- input<K extends string | undefined>(key?: K, defaultValue?: any): K extends undefined ? RequestObject : any;
1372
- /**
1373
- * Retrieve a file from the request.
1374
- *
1375
- * By default a single `UploadedFile` instance will always be returned by
1376
- * the method (first file in property when there are multiple), unless
1377
- * the `expectArray` parameter is set to true, in which case, the method
1378
- * returns an `UploadedFile[]` array.
1379
- *
1380
- * @param key
1381
- * @param defaultValue
1382
- * @param expectArray set to true to return an `UploadedFile[]` array.
1383
- * @returns
1384
- */
1385
- 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;
1386
- /**
1387
- * Determine if the uploaded data contains a file.
1388
- *
1389
- * @param key
1390
- * @return boolean
1391
- */
1392
- hasFile(key: string): boolean;
1393
- /**
1394
- * Check that the given file is a valid file instance.
1395
- *
1396
- * @param file
1397
- * @return boolean
1398
- */
1399
- protected isValidFile(file: UploadedFile): boolean;
1400
- /**
1401
- * Get an object with all the files on the request.
1402
- */
1403
- allFiles(): Record<string, UploadedFile | UploadedFile[]>;
1404
- /**
1405
- * Extract and convert uploaded files from FormData.
1406
- */
1407
- convertUploadedFiles(files: Record<string, UploadedFile | UploadedFile[]>): Record<string, UploadedFile | UploadedFile[]>;
1408
- /**
1409
- * Determine if the data contains a given key.
1410
- *
1411
- * @param keys
1412
- * @returns
1413
- */
1414
- has(keys: string[] | string): boolean;
1415
- /**
1416
- * Determine if the instance is missing a given key.
1417
- */
1418
- missing(key: string | string[]): boolean;
1419
- /**
1420
- * Get a subset containing the provided keys with values from the instance data.
1421
- *
1422
- * @param keys
1423
- * @returns
1424
- */
1425
- only<T = Record<string, any>>(keys: string[]): T;
1426
- /**
1427
- * Get all of the data except for a specified array of items.
1428
- *
1429
- * @param keys
1430
- * @returns
1431
- */
1432
- except<T = Record<string, any>>(keys: string[]): T;
1433
- /**
1434
- * Merges new input data into the current request's input source.
1435
- *
1436
- * @param input - An object containing key-value pairs to merge.
1437
- * @returns this - For fluent chaining.
1438
- */
1439
- merge(input: Record<string, any>): this;
1440
- /**
1441
- * Merge new input into the request's input, but only when that key is missing from the request.
1442
- *
1443
- * @param input
1444
- */
1445
- mergeIfMissing(input: Record<string, any>): this;
1446
- /**
1447
- * Get the keys for all of the input and files.
1448
- */
1449
- keys(): string[];
1450
- /**
1451
- * Determine if the request is sending JSON.
1452
- *
1453
- * @return bool
1454
- */
1455
- isJson(): boolean;
1456
- /**
1457
- * Determine if the current request probably expects a JSON response.
1458
- *
1459
- * @returns
1460
- */
1461
- expectsJson(): boolean;
1462
- /**
1463
- * Determine if the current request is asking for JSON.
1464
- *
1465
- * @returns
1466
- */
1467
- wantsJson(): boolean;
1468
- /**
1469
- * Determine if the request is the result of a PJAX call.
1470
- *
1471
- * @return bool
1472
- */
1473
- pjax(): boolean;
1474
- /**
1475
- * Returns true if the request is an XMLHttpRequest (AJAX).
1476
- *
1477
- * @alias isXmlHttpRequest()
1478
- * @returns {boolean}
1479
- */
1480
- ajax(): boolean;
1481
- /**
1482
- * Get the client IP address.
1483
- */
1484
- ip(): string | undefined;
1485
- /**
1486
- * Get a URI instance for the request.
1487
- */
1488
- uri(): Url;
1489
- /**
1490
- * Get the full URL for the request.
1491
- */
1492
- fullUrl(): string;
1493
- /**
1494
- * Return the Request instance.
1495
- */
1496
- instance(): this;
1497
- /**
1498
- * Get the request method.
1499
- */
1500
- method(): RequestMethod;
1501
- /**
1502
- * Get the JSON payload for the request.
1503
- *
1504
- * @param key
1505
- * @param defaultValue
1506
- * @return {InputBag}
1507
- */
1508
- json<K extends string | undefined = undefined>(key?: string, defaultValue?: any): K extends undefined ? InputBag : any;
1509
- /**
1510
- * Get the input source for the request.
1511
- *
1512
- * @return {InputBag}
1513
- */
1514
- protected getInputSource(): InputBag;
1515
- /**
1516
- * Dump the items.
1517
- *
1518
- * @param keys
1519
- */
1520
- dump(...keys: any[]): this;
1521
- /**
1522
- * Get the base event
1523
- */
1524
- getEvent(): H3Event;
1525
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
1526
- }
1527
- //#endregion
1528
- //#region src/Resources/JsonResource.d.ts
1529
- interface Resource {
1530
- [key: string]: any;
1531
- pagination?: {
1532
- from?: number | undefined;
1533
- to?: number | undefined;
1534
- perPage?: number | undefined;
1535
- total?: number | undefined;
1536
- } | undefined;
1537
- }
1538
- type BodyResource = Resource & {
1539
- data: Omit<Resource, 'pagination'>;
1540
- meta?: {
1541
- pagination?: Resource['pagination'];
1542
- } | undefined;
1543
- };
1544
- /**
1545
- * Class to render API resource
1546
- */
1547
- declare class JsonResource<R extends Resource = any> {
1548
- #private;
1549
- protected event: H3Event;
1550
- /**
1551
- * The request instance
1552
- */
1553
- request: H3Event<EventHandlerRequest>['req'];
1554
- /**
1555
- * The response instance
1556
- */
1557
- response: H3Event['res'];
1558
- /**
1559
- * The data to send to the client
1560
- */
1561
- resource: R;
1562
- /**
1563
- * The final response data object
1564
- */
1565
- body: BodyResource;
1566
- /**
1567
- * Flag to track if response should be sent automatically
1568
- */
1569
- private shouldSend;
1570
- /**
1571
- * Flag to track if response has been sent
1572
- */
1573
- private responseSent;
1574
- /**
1575
- * Declare that this includes R's properties
1576
- */
1577
- [key: string]: any;
1578
- /**
1579
- * @param req The request instance
1580
- * @param res The response instance
1581
- * @param rsc The data to send to the client
1582
- */
1583
- constructor(event: H3Event, rsc: R);
1584
- /**
1585
- * Return the data in the expected format
1586
- *
1587
- * @returns
1588
- */
1589
- data(): Resource;
1590
- /**
1591
- * Build the response object
1592
- * @returns this
1593
- */
1594
- json(): this;
1595
- /**
1596
- * Add context data to the response object
1597
- * @param data Context data
1598
- * @returns this
1599
- */
1600
- additional<X extends {
1601
- [key: string]: any;
1602
- }>(data: X): this;
1603
- /**
1604
- * Send the output to the client
1605
- * @returns this
1606
- */
1607
- send(): this;
1608
- /**
1609
- * Set the status code for this response
1610
- * @param code Status code
1611
- * @returns this
1612
- */
1613
- status(code: number): this;
1614
- /**
1615
- * Check if send should be triggered automatically
1616
- */
1617
- private checkSend;
1618
- }
1619
- //#endregion
1620
- //#region src/Resources/ApiResource.d.ts
1621
- declare function ApiResource(instance: JsonResource): JsonResource<any>;
1622
- //#endregion
1623
- //#region src/Response.d.ts
1624
- declare class Response extends HttpResponse implements IResponse {
1625
- /**
1626
- * The current app instance
1627
- */
1628
- app: Application;
1629
- constructor(
1630
- /**
1631
- * The current H3 H3Event instance
1632
- */
1633
- event: H3Event,
1634
- /**
1635
- * The current app instance
1636
- */
1637
- app: Application);
1638
- /**
1639
- * Sends content for the current web response.
1640
- */
1641
- sendContent(type?: 'html' | 'json' | 'text' | 'xml', parse?: boolean): unknown;
1642
- /**
1643
- * Sends content for the current web response.
1644
- */
1645
- send(type?: 'html' | 'json' | 'text' | 'xml'): unknown;
1646
- /**
1647
- *
1648
- * @param content The content to serve
1649
- * @param send if set to true, the content will be returned, instead of the Response instance
1650
- * @returns
1651
- */
1652
- html(content?: string): this;
1653
- html(content: string, parse: boolean): HTTPResponse;
1654
- /**
1655
- * Send a JSON response.
1656
- */
1657
- json<T = unknown>(data?: T): this;
1658
- json<T = unknown>(data: T, parse: boolean): T;
1659
- /**
1660
- * Send plain text.
1661
- */
1662
- text(content?: string): this;
1663
- text(content: string, parse: boolean): HTTPResponse;
1664
- /**
1665
- * Send plain xml.
1666
- */
1667
- xml(data?: string): this;
1668
- xml(data: string, parse: boolean): HTTPResponse;
1669
- /**
1670
- * Build the HTTP Response
1671
- *
1672
- * @param contentType
1673
- * @param data
1674
- */
1675
- private httpResponse;
1676
- /**
1677
- * Redirect to another URL.
1678
- */
1679
- redirect(location: string, status?: number, statusText?: string | undefined): HTTPResponse;
1680
- /**
1681
- * Dump the response.
1682
- */
1683
- dump(): this;
1684
- /**
1685
- * Get the base event
1686
- */
1687
- getEvent(): H3Event;
1688
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
1689
- }
1690
- //#endregion
1691
- //#region src/Utilities/HeaderUtility.d.ts
1692
- /**
1693
- * HTTP header utility functions .
1694
- */
1695
- declare class HeaderUtility {
1696
- static readonly DISPOSITION_ATTACHMENT = "attachment";
1697
- static readonly DISPOSITION_INLINE = "inline";
1698
- private constructor();
1699
- /**
1700
- * Splits an HTTP header by one or more separators.
1701
- *
1702
- * Example:
1703
- * HeaderUtility.split('da, en-gb;q=0.8', ',;')
1704
- * // returns [['da'], ['en-gb', 'q=0.8']]
1705
- */
1706
- static split(header: string, separators: string): string[][];
1707
- /**
1708
- * Combines an array of arrays into one associative object.
1709
- * [['foo', 'abc'], ['bar']] => { foo: 'abc', bar: true }
1710
- */
1711
- static combine(parts: (string | true)[][]): Record<string, string | boolean>;
1712
- /**
1713
- * Joins an associative object into a string for use in an HTTP header.
1714
- * { foo: 'abc', bar: true, baz: 'a b c' } => 'foo=abc, bar, baz="a b c"'
1715
- */
1716
- static toString(assoc: Record<string, string | boolean>, separator: string): string;
1717
- /**
1718
- * Encodes a string as a quoted string, if necessary.
1719
- */
1720
- static quote(s: string): string;
1721
- /**
1722
- * Decodes a quoted string.
1723
- */
1724
- static unquote(s: string): string;
1725
- /**
1726
- * Generates an HTTP Content-Disposition field-value.
1727
- *
1728
- * @see RFC 6266
1729
- */
1730
- static makeDisposition(disposition: string, filename: string, filenameFallback?: string): string;
1731
- /**
1732
- * Like parse_str(), but preserves dots in variable names.
1733
- */
1734
- static parseQuery(query: string, ignoreBrackets?: boolean, separator?: string): Record<string, any>;
1735
- private static groupParts;
1736
- }
1737
- //#endregion
1738
- //#region src/Utilities/IpUtils.d.ts
1739
- /**
1740
- * Http utility functions for IP handling.
1741
- */
1742
- declare class IpUtils {
1743
- static readonly PRIVATE_SUBNETS: string[];
1744
- private static checkedIps;
1745
- private constructor();
1746
- /**
1747
- * Checks if an IPv4 or IPv6 address is contained in the list of given IPs or subnets.
1748
- *
1749
- * @param requestIp
1750
- * @param ips List of IPs or subnets (can be a string if only a single one)
1751
- */
1752
- static checkIp(requestIp?: string, ips?: string | string[]): boolean;
1753
- /**
1754
- * Compares two IPv4 addresses or checks if one belongs to a CIDR subnet.
1755
- *
1756
- * @param requestIp
1757
- * @param ip IPv4 address or subnet in CIDR notation
1758
- *
1759
- * @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet
1760
- */
1761
- static checkIp4(requestIp: string, ip: string): boolean;
1762
- /**
1763
- * Compares two IPv6 addresses or checks if one belongs to a CIDR subnet.
1764
- *
1765
- * @see https://github.com/dsp/v6tools
1766
- *
1767
- * @param requestIp
1768
- * @param ip IPv6 address or subnet in CIDR notation
1769
- *
1770
- * @throws {RuntimeException} When IPV6 support is not enabled
1771
- */
1772
- static checkIp6(requestIp: string, ip: string): boolean;
1773
- /**
1774
- * Anonymizes an IPv4/IPv6 by zeroing out trailing bytes.
1775
- *
1776
- * @param ip
1777
- * @param v4Bytes
1778
- * @param v6Bytes
1779
- */
1780
- static anonymize(ip: string, v4Bytes?: number, v6Bytes?: number): string;
1781
- /**
1782
- * Checks if IP is within private subnets.
1783
- */
1784
- static isPrivateIp(requestIp: string): boolean;
1785
- private static isIPv4;
1786
- private static isIPv6;
1787
- private static ipv4ToLong;
1788
- private static inetPton;
1789
- private static inetPton4;
1790
- private static inetPton6;
1791
- private static inetNtop;
1792
- private static getCacheResult;
1793
- private static setCacheResult;
1794
- }
1795
- //#endregion
1796
- //#region src/Utilities/ResponseUtilities.d.ts
1797
- declare enum ResponseCodes {
1798
- HTTP_CONTINUE = 100,
1799
- HTTP_SWITCHING_PROTOCOLS = 101,
1800
- HTTP_PROCESSING = 102,
1801
- // RFC2518
1802
- HTTP_EARLY_HINTS = 103,
1803
- // RFC8297
1804
- HTTP_OK = 200,
1805
- HTTP_CREATED = 201,
1806
- HTTP_ACCEPTED = 202,
1807
- HTTP_NON_AUTHORITATIVE_INFORMATION = 203,
1808
- HTTP_NO_CONTENT = 204,
1809
- HTTP_RESET_CONTENT = 205,
1810
- HTTP_PARTIAL_CONTENT = 206,
1811
- HTTP_MULTI_STATUS = 207,
1812
- // RFC4918
1813
- HTTP_ALREADY_REPORTED = 208,
1814
- // RFC5842
1815
- HTTP_IM_USED = 226,
1816
- // RFC3229
1817
- HTTP_MULTIPLE_CHOICES = 300,
1818
- HTTP_MOVED_PERMANENTLY = 301,
1819
- HTTP_FOUND = 302,
1820
- HTTP_SEE_OTHER = 303,
1821
- HTTP_NOT_MODIFIED = 304,
1822
- HTTP_USE_PROXY = 305,
1823
- HTTP_RESERVED = 306,
1824
- HTTP_TEMPORARY_REDIRECT = 307,
1825
- HTTP_PERMANENTLY_REDIRECT = 308,
1826
- // RFC7238
1827
- HTTP_BAD_REQUEST = 400,
1828
- HTTP_UNAUTHORIZED = 401,
1829
- HTTP_PAYMENT_REQUIRED = 402,
1830
- HTTP_FORBIDDEN = 403,
1831
- HTTP_NOT_FOUND = 404,
1832
- HTTP_METHOD_NOT_ALLOWED = 405,
1833
- HTTP_NOT_ACCEPTABLE = 406,
1834
- HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
1835
- HTTP_REQUEST_TIMEOUT = 408,
1836
- HTTP_CONFLICT = 409,
1837
- HTTP_GONE = 410,
1838
- HTTP_LENGTH_REQUIRED = 411,
1839
- HTTP_PRECONDITION_FAILED = 412,
1840
- HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
1841
- HTTP_REQUEST_URI_TOO_LONG = 414,
1842
- HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
1843
- HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
1844
- HTTP_EXPECTATION_FAILED = 417,
1845
- HTTP_I_AM_A_TEAPOT = 418,
1846
- // RFC2324
1847
- HTTP_MISDIRECTED_REQUEST = 421,
1848
- // RFC7540
1849
- HTTP_UNPROCESSABLE_ENTITY = 422,
1850
- // RFC4918
1851
- HTTP_LOCKED = 423,
1852
- // RFC4918
1853
- HTTP_FAILED_DEPENDENCY = 424,
1854
- // RFC4918
1855
- HTTP_TOO_EARLY = 425,
1856
- // RFC-ietf-httpbis-replay-04
1857
- HTTP_UPGRADE_REQUIRED = 426,
1858
- // RFC2817
1859
- HTTP_PRECONDITION_REQUIRED = 428,
1860
- // RFC6585
1861
- HTTP_TOO_MANY_REQUESTS = 429,
1862
- // RFC6585
1863
- HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
1864
- // RFC6585
1865
- HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
1866
- // RFC7725
1867
- HTTP_INTERNAL_SERVER_ERROR = 500,
1868
- HTTP_NOT_IMPLEMENTED = 501,
1869
- HTTP_BAD_GATEWAY = 502,
1870
- HTTP_SERVICE_UNAVAILABLE = 503,
1871
- HTTP_GATEWAY_TIMEOUT = 504,
1872
- HTTP_VERSION_NOT_SUPPORTED = 505,
1873
- HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506,
1874
- // RFC2295
1875
- HTTP_INSUFFICIENT_STORAGE = 507,
1876
- // RFC4918
1877
- HTTP_LOOP_DETECTED = 508,
1878
- // RFC5842
1879
- HTTP_NOT_EXTENDED = 510,
1880
- // RFC2774
1881
- HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511,
1882
- }
1883
- declare const HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES: CacheOptions;
1884
- /**
1885
- * Status codes translation table.
1886
- *
1887
- * The list of codes is complete according to the
1888
- * @link https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml Hypertext Transfer Protocol (HTTP) Status Code Registry
1889
- * (last updated 2021-10-01).
1890
- *
1891
- * Unless otherwise noted, the status code is defined in RFC2616.
1892
- */
1893
- declare const statusTexts: {
1894
- [key: number]: string;
1895
- };
1896
- //#endregion
1897
- export { ApiResource, BadRequestException, CacheOptions, ConflictingHeadersException, Cookie, FileBag, FireCommand, FormRequest, HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES, HeaderBag, HeaderUtility, HttpContext, HttpRequest, HttpResponse, HttpResponseException, HttpServiceProvider, InputBag, IpUtils, JsonResource, LogRequests, Middleware, ParamBag, Request, Resource, Response, ResponseCodes, ResponseHeaderBag, ServerBag, SuspiciousOperationException, UnexpectedValueException, UploadedFile, statusTexts };