@h3ravel/shared 0.25.0 → 0.26.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.ts CHANGED
@@ -1,32 +1,32 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
- import { ChalkInstance } from "chalk";
3
- import { ChoiceOrSeparatorArray, ChoiceOrSeparatorArray as ChoiceOrSeparatorArray$1 } from "inquirer-autocomplete-standalone";
4
- import { Separator } from "@inquirer/prompts";
5
2
  import { H3, H3Event, HTTPResponse, Middleware, MiddlewareOptions, serve } from "h3";
6
3
  import { Edge } from "edge.js";
7
4
  import { DotNestedKeys as DotNestedKeys$1, DotNestedValue as DotNestedValue$1 } from "@h3ravel/shared";
5
+ import { Separator } from "@inquirer/prompts";
6
+ import { ChoiceOrSeparatorArray, ChoiceOrSeparatorArray as ChoiceOrSeparatorArray$1 } from "inquirer-autocomplete-standalone";
7
+ import { ChalkInstance } from "chalk";
8
8
 
9
9
  //#region src/Contracts/ObjContract.d.ts
10
10
  /**
11
11
  * Adds a dot prefix to nested keys
12
12
  */
13
- type DotPrefix<T$1 extends string, U extends string> = T$1 extends '' ? U : `${T$1}.${U}`;
13
+ type DotPrefix<T extends string, U extends string> = T extends '' ? U : `${T}.${U}`;
14
14
  /**
15
15
  * Converts a union of objects into a single merged object
16
16
  */
17
- type MergeUnion<T$1> = (T$1 extends any ? (k: T$1) => void : never) extends ((k: infer I) => void) ? { [K in keyof I]: I[K] } : never;
17
+ type MergeUnion<T> = (T extends any ? (k: T) => void : never) extends ((k: infer I) => void) ? { [K in keyof I]: I[K] } : never;
18
18
  /**
19
19
  * Flattens nested objects into dotted keys
20
20
  */
21
- type DotFlatten<T$1, Prefix extends string = ''> = MergeUnion<{ [K in keyof T$1 & string]: T$1[K] extends Record<string, any> ? DotFlatten<T$1[K], DotPrefix<Prefix, K>> : { [P in DotPrefix<Prefix, K>]: T$1[K] } }[keyof T$1 & string]>;
21
+ type DotFlatten<T, Prefix extends string = ''> = MergeUnion<{ [K in keyof T & string]: T[K] extends Record<string, any> ? DotFlatten<T[K], DotPrefix<Prefix, K>> : { [P in DotPrefix<Prefix, K>]: T[K] } }[keyof T & string]>;
22
22
  /**
23
23
  * Builds "nested.key" paths for autocompletion
24
24
  */
25
- type DotNestedKeys<T$1> = { [K in keyof T$1 & string]: T$1[K] extends object ? `${K}` | `${K}.${DotNestedKeys<T$1[K]>}` : `${K}` }[keyof T$1 & string];
25
+ type DotNestedKeys<T> = { [K in keyof T & string]: T[K] extends object ? `${K}` | `${K}.${DotNestedKeys<T[K]>}` : `${K}` }[keyof T & string];
26
26
  /**
27
27
  * Retrieves type at a given dot-path
28
28
  */
29
- type DotNestedValue<T$1, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T$1 ? DotNestedValue<T$1[Key], Rest> : never : Path extends keyof T$1 ? T$1[Path] : never;
29
+ type DotNestedValue<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? DotNestedValue<T[Key], Rest> : never : Path extends keyof T ? T[Path] : never;
30
30
  /**
31
31
  * A generic object type that supports nullable string values
32
32
  */
@@ -151,109 +151,351 @@ interface IApplication extends IContainer {
151
151
  getVersion(key: string): string | undefined;
152
152
  }
153
153
  //#endregion
154
- //#region src/Contracts/IRequest.d.ts
154
+ //#region src/Contracts/IHttpResponse.d.ts
155
155
  /**
156
- * Interface for the Request contract, defining methods for handling HTTP request data.
156
+ * Interface for the Response contract, defining methods for handling HTTP responses.
157
157
  */
158
- interface IRequest {
158
+ interface IHttpResponse {
159
159
  /**
160
- * The current app instance
160
+ * Set HTTP status code.
161
161
  */
162
- app: IApplication;
162
+ setStatusCode(code: number, text?: string): this;
163
163
  /**
164
- * Gets route parameters.
165
- * @returns An object containing route parameters.
164
+ * Retrieves the status code for the current web response.
166
165
  */
167
- params: NonNullable<H3Event['context']['params']>;
166
+ getStatusCode(): number;
168
167
  /**
169
- * Gets query parameters.
170
- * @returns An object containing query parameters.
168
+ * Sets the response charset.
171
169
  */
172
- query: Record<string, any>;
170
+ setCharset(charset: string): this;
173
171
  /**
174
- * Gets all input data (query parameters, route parameters, and body).
175
- * @returns A promise resolving to an object containing all input data.
172
+ * Retrieves the response charset.
176
173
  */
177
- all<T = Record<string, unknown>>(): Promise<T>;
174
+ getCharset(): string | undefined;
178
175
  /**
179
- * Gets a single input field from query or body.
180
- * @param key - The key of the input field.
181
- * @param defaultValue - Optional default value if the key is not found.
182
- * @returns A promise resolving to the value of the input field or the default value.
176
+ * Returns true if the response may safely be kept in a shared (surrogate) cache.
177
+ *
178
+ * Responses marked "private" with an explicit Cache-Control directive are
179
+ * considered uncacheable.
180
+ *
181
+ * Responses with neither a freshness lifetime (Expires, max-age) nor cache
182
+ * validator (Last-Modified, ETag) are considered uncacheable because there is
183
+ * no way to tell when or how to remove them from the cache.
184
+ *
185
+ * Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
186
+ * for example "status codes that are defined as cacheable by default [...]
187
+ * can be reused by a cache with heuristic expiration unless otherwise indicated"
188
+ * (https://tools.ietf.org/html/rfc7231#section-6.1)
189
+ *
190
+ * @final
183
191
  */
184
- input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
192
+ isCacheable(): boolean;
185
193
  /**
186
- * Gets the underlying event object or a specific property of it.
187
- * @param key - Optional key to access a nested property of the event.
188
- * @returns The entire event object or the value of the specified property.
194
+ * Returns true if the response is "fresh".
195
+ *
196
+ * Fresh responses may be served from cache without any interaction with the
197
+ * origin. A response is considered fresh when it includes a Cache-Control/max-age
198
+ * indicator or Expires header and the calculated age is less than the freshness lifetime.
189
199
  */
190
- getEvent(): H3Event;
191
- getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
200
+ isFresh(): boolean;
201
+ /**
202
+ * Returns true if the response includes headers that can be used to validate
203
+ * the response with the origin server using a conditional GET request.
204
+ */
205
+ isValidateable(): boolean;
206
+ /**
207
+ * Sets the response content.
208
+ */
209
+ setContent(content?: any): this;
210
+ /**
211
+ * Gets the current response content.
212
+ */
213
+ getContent(): any;
214
+ /**
215
+ * Set a header.
216
+ */
217
+ setHeader(name: string, value: string): this;
218
+ /**
219
+ * Sets the HTTP protocol version (1.0 or 1.1).
220
+ */
221
+ setProtocolVersion(version: string): this;
222
+ /**
223
+ * Gets the HTTP protocol version.
224
+ */
225
+ getProtocolVersion(): string;
226
+ /**
227
+ * Marks the response as "private".
228
+ *
229
+ * It makes the response ineligible for serving other clients.
230
+ */
231
+ setPrivate(): this;
232
+ /**
233
+ * Marks the response as "public".
234
+ *
235
+ * It makes the response eligible for serving other clients.
236
+ */
237
+ setPublic(): this;
238
+ /**
239
+ * Returns the Date header as a DateTime instance.
240
+ * @throws {RuntimeException} When the header is not parseable
241
+ */
242
+ getDate(): any;
243
+ /**
244
+ * Returns the age of the response in seconds.
245
+ *
246
+ * @final
247
+ */
248
+ getAge(): number;
249
+ /**
250
+ * Marks the response stale by setting the Age header to be equal to the maximum age of the response.
251
+ */
252
+ expire(): this;
253
+ /**
254
+ * Returns the value of the Expires header as a DateTime instance.
255
+ *
256
+ * @final
257
+ */
258
+ getExpires(): any;
259
+ /**
260
+ * Returns the number of seconds after the time specified in the response's Date
261
+ * header when the response should no longer be considered fresh.
262
+ *
263
+ * First, it checks for a s-maxage directive, then a max-age directive, and then it falls
264
+ * back on an expires header. It returns null when no maximum age can be established.
265
+ */
266
+ getMaxAge(): number | undefined;
267
+ /**
268
+ * Sets the number of seconds after which the response should no longer be considered fresh.
269
+ *
270
+ * This method sets the Cache-Control max-age directive.
271
+ */
272
+ setMaxAge(value: number): this;
273
+ /**
274
+ * Sets the number of seconds after which the response should no longer be returned by shared caches when backend is down.
275
+ *
276
+ * This method sets the Cache-Control stale-if-error directive.
277
+ */
278
+ setStaleIfError(value: number): this;
279
+ /**
280
+ * Sets the number of seconds after which the response should no longer return stale content by shared caches.
281
+ *
282
+ * This method sets the Cache-Control stale-while-revalidate directive.
283
+ */
284
+ setStaleWhileRevalidate(value: number): this;
285
+ /**
286
+ * Returns the response's time-to-live in seconds.
287
+ *
288
+ * It returns null when no freshness information is present in the response.
289
+ *
290
+ * When the response's TTL is 0, the response may not be served from cache without first
291
+ * revalidating with the origin.
292
+ *
293
+ * @final
294
+ */
295
+ getTtl(): number | undefined;
296
+ /**
297
+ * Sets the response's time-to-live for shared caches in seconds.
298
+ *
299
+ * This method adjusts the Cache-Control/s-maxage directive.
300
+ */
301
+ setTtl(seconds: number): this;
302
+ /**
303
+ * Sets the response's time-to-live for private/client caches in seconds.
304
+ *
305
+ * This method adjusts the Cache-Control/max-age directive.
306
+ */
307
+ setClientTtl(seconds: number): this;
308
+ /**
309
+ * Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
310
+ *
311
+ * This method sets the Cache-Control s-maxage directive.
312
+ */
313
+ setSharedMaxAge(value: number): this;
314
+ /**
315
+ * Returns the Last-Modified HTTP header as a DateTime instance.
316
+ *
317
+ * @throws \RuntimeException When the HTTP header is not parseable
318
+ *
319
+ * @final
320
+ */
321
+ getLastModified(): any;
322
+ /**
323
+ * Sets the Last-Modified HTTP header with a DateTime instance.
324
+ *
325
+ * Passing null as value will remove the header.
326
+ *
327
+ * @return $this
328
+ *
329
+ * @final
330
+ */
331
+ setLastModified(date?: any): this;
332
+ /**
333
+ * Returns the literal value of the ETag HTTP header.
334
+ */
335
+ getEtag(): string | null;
336
+ /**
337
+ * Sets the ETag value.
338
+ *
339
+ * @param etag The ETag unique identifier or null to remove the header
340
+ * @param weak Whether you want a weak ETag or not
341
+ */
342
+ setEtag(etag?: string, weak?: boolean): this;
343
+ /**
344
+ * Sets the response's cache headers (validation and/or expiration).
345
+ *
346
+ * Available options are: must_revalidate, no_cache, no_store, no_transform, public, private, proxy_revalidate, max_age, s_maxage, immutable, last_modified and etag.
347
+ *
348
+ * @throws {InvalidArgumentException}
349
+ */
350
+ setCache(options: any): this;
351
+ /**
352
+ * Modifies the response so that it conforms to the rules defined for a 304 status code.
353
+ *
354
+ * This sets the status, removes the body, and discards any headers
355
+ * that MUST NOT be included in 304 responses.
356
+ * @see https://tools.ietf.org/html/rfc2616#section-10.3.5
357
+ */
358
+ setNotModified(): this;
359
+ /**
360
+ * Add an array of headers to the response.
361
+ *
362
+ */
363
+ withHeaders(headers: any): this;
364
+ /**
365
+ * Set the exception to attach to the response.
366
+ */
367
+ withException(e: Error): this;
368
+ /**
369
+ * Throws the response in a HttpResponseException instance.
370
+ *
371
+ * @throws {HttpResponseException}
372
+ */
373
+ throwResponse(): void;
374
+ /**
375
+ * Is response invalid?
376
+ *
377
+ * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
378
+ */
379
+ isInvalid(): boolean;
380
+ /**
381
+ * Is response informative?
382
+ */
383
+ isInformational(): boolean;
384
+ /**
385
+ * Is response successful?
386
+ */
387
+ isSuccessful(): boolean;
388
+ /**
389
+ * Is the response a redirect?
390
+ */
391
+ isRedirection(): boolean;
392
+ /**
393
+ * Is there a client error?
394
+ */
395
+ isClientError(): boolean;
396
+ /**
397
+ * Was there a server side error?
398
+ */
399
+ isServerError(): boolean;
400
+ /**
401
+ * Is the response OK?
402
+ */
403
+ isOk(): boolean;
404
+ /**
405
+ * Is the response forbidden?
406
+ */
407
+ isForbidden(): boolean;
408
+ /**
409
+ * Is the response a not found error?
410
+ */
411
+ isNotFound(): boolean;
412
+ /**
413
+ * Is the response a redirect of some form?
414
+ */
415
+ isRedirect(location?: string | null): boolean;
416
+ /**
417
+ * Is the response empty?
418
+ */
419
+ isEmpty(): boolean;
420
+ /**
421
+ * Apply headers before sending response.
422
+ */
423
+ sendHeaders(statusCode?: number): this;
424
+ /**
425
+ * Prepares the Response before it is sent to the client.
426
+ *
427
+ * This method tweaks the Response to ensure that it is
428
+ * compliant with RFC 2616. Most of the changes are based on
429
+ * the Request that is "associated" with this Response.
430
+ **/
431
+ prepare(request: IRequest): this;
192
432
  }
193
433
  //#endregion
194
434
  //#region src/Contracts/IResponse.d.ts
195
435
  /**
196
436
  * Interface for the Response contract, defining methods for handling HTTP responses.
197
437
  */
198
- interface IResponse {
438
+ interface IResponse extends IHttpResponse {
199
439
  /**
200
440
  * The current app instance
201
441
  */
202
442
  app: IApplication;
203
443
  /**
204
- * Sets the HTTP status code for the response.
205
- * @param code - The HTTP status code.
206
- * @returns The instance for method chaining.
444
+ * Sends content for the current web response.
207
445
  */
208
- setStatusCode(code: number): this;
446
+ sendContent(type?: 'html' | 'json' | 'text' | 'xml', parse?: boolean): unknown;
209
447
  /**
210
- * Sets a response header.
211
- * @param name - The header name.
212
- * @param value - The header value.
213
- * @returns The instance for method chaining.
448
+ * Sends content for the current web response.
214
449
  */
215
- setHeader(name: string, value: string): this;
450
+ send(type?: 'html' | 'json' | 'text' | 'xml'): unknown;
216
451
  /**
217
- * Sends an HTML response.
218
- * @param content - The HTML content to send.
219
- * @returns The HTML content.
452
+ *
453
+ * @param content The content to serve
454
+ * @param send if set to true, the content will be returned, instead of the Response instance
455
+ * @returns
220
456
  */
221
- html(content: string): HTTPResponse;
457
+ html(content?: string): this;
458
+ html(content: string, parse: boolean): HTTPResponse;
222
459
  /**
223
- * Sends a JSON response.
224
- * @param data - The data to send as JSON.
225
- * @returns The input data.
460
+ * Send a JSON response.
226
461
  */
227
- json<T = unknown>(data: T): T;
462
+ json<T = unknown>(data?: T): this;
463
+ json<T = unknown>(data: T, parse: boolean): T;
228
464
  /**
229
- * Sends a plain text response.
230
- * @param data - The text content to send.
231
- * @returns The text content.
465
+ * Send plain text.
232
466
  */
233
- text(data: string): string;
467
+ text(content?: string): this;
468
+ text(content: string, parse: boolean): HTTPResponse;
234
469
  /**
235
- * Redirects to another URL.
236
- * @param url - The URL to redirect to.
237
- * @param status - The HTTP status code for the redirect (default: 302).
238
- * @returns The redirect URL.
470
+ * Send plain xml.
239
471
  */
240
- redirect(url: string, status?: number): HTTPResponse;
472
+ xml(data?: string): this;
473
+ xml(data: string, parse: boolean): HTTPResponse;
241
474
  /**
242
- * Gets the underlying event object or a specific property of it.
243
- * @param key - Optional key to access a nested property of the event.
244
- * @returns The entire event object or the value of the specified property.
475
+ * Redirect to another URL.
476
+ */
477
+ redirect(location: string, status?: number, statusText?: string | undefined): HTTPResponse;
478
+ /**
479
+ * Dump the response.
480
+ */
481
+ dump(): this;
482
+ /**
483
+ * Get the base event
245
484
  */
246
485
  getEvent(): H3Event;
247
- getEvent<K extends DotNestedKeys$1<H3Event>>(key: K): DotNestedValue$1<H3Event, K>;
486
+ getEvent<K$1 extends DotNestedKeys$1<H3Event>>(key: K$1): DotNestedValue$1<H3Event, K$1>;
248
487
  }
249
488
  //#endregion
250
489
  //#region src/Contracts/IHttp.d.ts
251
490
  type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';
252
- type ExtractControllerMethods<T$1> = { [K in keyof T$1]: T$1[K] extends ((...args: any[]) => any) ? K : never }[keyof T$1];
491
+ type RequestMethod = 'HEAD' | 'GET' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'PURGE' | 'POST' | 'CONNECT' | 'PATCH';
492
+ type RequestObject = Record<string, any>;
493
+ type ResponseObject = Record<string, any>;
494
+ type ExtractControllerMethods<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? K : never }[keyof T];
253
495
  /**
254
496
  * Interface for the Router contract, defining methods for HTTP routing.
255
497
  */
256
- interface IRouter {
498
+ declare class IRouter {
257
499
  /**
258
500
  * Registers a GET route.
259
501
  * @param path - The route path.
@@ -373,7 +615,7 @@ type RouteEventHandler = (...args: any[]) => any;
373
615
  * Defines the contract for all controllers.
374
616
  * Any controller implementing this must define these methods.
375
617
  */
376
- interface IController {
618
+ declare class IController {
377
619
  show?(...ctx: any[]): any;
378
620
  index?(...ctx: any[]): any;
379
621
  store?(...ctx: any[]): any;
@@ -384,10 +626,433 @@ interface IController {
384
626
  * Defines the contract for all middlewares.
385
627
  * Any middleware implementing this must define these methods.
386
628
  */
387
- interface IMiddleware {
629
+ declare class IMiddleware {
388
630
  handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
389
631
  }
390
632
  //#endregion
633
+ //#region src/Contracts/IParamBag.d.ts
634
+ declare class IParamBag implements Iterable<[string, any]> {
635
+ /**
636
+ * The current H3 H3Event instance
637
+ */
638
+ readonly event: H3Event;
639
+ constructor(parameters: RequestObject | undefined,
640
+ /**
641
+ * The current H3 H3Event instance
642
+ */
643
+ event: H3Event);
644
+ /**
645
+ * Returns the parameters.
646
+ * @
647
+ * @param key The name of the parameter to return or null to get them all
648
+ *
649
+ * @throws BadRequestException if the value is not an array
650
+ */
651
+ all(key?: string): any;
652
+ get(key: string, defaultValue?: any): any;
653
+ set(key: string, value: any): void;
654
+ /**
655
+ * Returns true if the parameter is defined.
656
+ *
657
+ * @param key
658
+ */
659
+ has(key: string): boolean;
660
+ /**
661
+ * Removes a parameter.
662
+ *
663
+ * @param key
664
+ */
665
+ remove(key: string): void;
666
+ /**
667
+ *
668
+ * Returns the parameter as string.
669
+ *
670
+ * @param key
671
+ * @param defaultValue
672
+ * @throws UnexpectedValueException if the value cannot be converted to string
673
+ * @returns
674
+ */
675
+ getString(key: string, defaultValue?: string): string;
676
+ /**
677
+ * Returns the parameter value converted to integer.
678
+ *
679
+ * @param key
680
+ * @param defaultValue
681
+ * @throws UnexpectedValueException if the value cannot be converted to integer
682
+ */
683
+ getInt(key: string, defaultValue?: number): number;
684
+ /**
685
+ * Returns the parameter value converted to boolean.
686
+ *
687
+ * @param key
688
+ * @param defaultValue
689
+ * @throws UnexpectedValueException if the value cannot be converted to a boolean
690
+ */
691
+ getBoolean(key: string, defaultValue?: boolean): boolean;
692
+ /**
693
+ * Returns the alphabetic characters of the parameter value.
694
+ *
695
+ * @param key
696
+ * @param defaultValue
697
+ * @throws UnexpectedValueException if the value cannot be converted to string
698
+ */
699
+ getAlpha(key: string, defaultValue?: string): string;
700
+ /**
701
+ * Returns the alphabetic characters and digits of the parameter value.
702
+ *
703
+ * @param key
704
+ * @param defaultValue
705
+ * @throws UnexpectedValueException if the value cannot be converted to string
706
+ */
707
+ getAlnum(key: string, defaultValue?: string): string;
708
+ /**
709
+ * Returns the digits of the parameter value.
710
+ *
711
+ * @param key
712
+ * @param defaultValue
713
+ * @throws UnexpectedValueException if the value cannot be converted to string
714
+ * @returns
715
+ **/
716
+ getDigits(key: string, defaultValue?: string): string;
717
+ /**
718
+ * Returns the parameter keys.
719
+ */
720
+ keys(): string[];
721
+ /**
722
+ * Replaces the current parameters by a new set.
723
+ */
724
+ replace(parameters?: RequestObject): void;
725
+ /**
726
+ * Adds parameters.
727
+ */
728
+ add(parameters?: RequestObject): void;
729
+ /**
730
+ * Returns the number of parameters.
731
+ */
732
+ count(): number;
733
+ /**
734
+ * Returns an iterator for parameters.
735
+ *
736
+ * @returns
737
+ */
738
+ [Symbol.iterator](): ArrayIterator<[string, any]>;
739
+ }
740
+ //#endregion
741
+ //#region src/Contracts/IUploadedFile.d.ts
742
+ declare class IUploadedFile {
743
+ originalName: string;
744
+ mimeType: string;
745
+ size: number;
746
+ content: File;
747
+ constructor(originalName: string, mimeType: string, size: number, content: File);
748
+ static createFromBase(file: File): IUploadedFile;
749
+ /**
750
+ * Save to disk (Node environment only)
751
+ */
752
+ moveTo(destination: string): Promise<void>;
753
+ }
754
+ //#endregion
755
+ //#region src/Contracts/IRequest.d.ts
756
+ type RequestObject$1 = Record<string, any>;
757
+ /**
758
+ * Interface for the Request contract, defining methods for handling HTTP request data.
759
+ */
760
+ declare class IRequest {
761
+ /**
762
+ * The current app instance
763
+ */
764
+ app: IApplication;
765
+ /**
766
+ * Parsed request body
767
+ */
768
+ body: unknown;
769
+ /**
770
+ * Gets route parameters.
771
+ * @returns An object containing route parameters.
772
+ */
773
+ params: NonNullable<H3Event['context']['params']>;
774
+ /**
775
+ * Uploaded files (FILES).
776
+ */
777
+ constructor(
778
+ /**
779
+ * The current H3 H3Event instance
780
+ */
781
+ event: H3Event,
782
+ /**
783
+ * The current app instance
784
+ */
785
+ app: IApplication);
786
+ /**
787
+ * Factory method to create a Request instance from an H3Event.
788
+ */
789
+ static create(
790
+ /**
791
+ * The current H3 H3Event instance
792
+ */
793
+ event: H3Event,
794
+ /**
795
+ * The current app instance
796
+ */
797
+ app: IApplication): Promise<Request>;
798
+ /**
799
+ * Sets the parameters for this request.
800
+ *
801
+ * This method also re-initializes all properties.
802
+ *
803
+ * @param attributes
804
+ * @param cookies The COOKIE parameters
805
+ * @param files The FILES parameters
806
+ * @param server The SERVER parameters
807
+ * @param content The raw body data
808
+ */
809
+ initialize(): Promise<void>;
810
+ /**
811
+ * Retrieve all data from the instance (query + body).
812
+ */
813
+ all<T = Record<string, any>>(keys?: string | string[]): T;
814
+ /**
815
+ * Retrieve an input item from the request.
816
+ *
817
+ * @param key
818
+ * @param defaultValue
819
+ * @returns
820
+ */
821
+ input<K$1 extends string | undefined>(key?: K$1, defaultValue?: any): K$1 extends undefined ? RequestObject$1 : any;
822
+ /**
823
+ * Retrieve a file from the request.
824
+ *
825
+ * By default a single `UploadedFile` instance will always be returned by
826
+ * the method (first file in property when there are multiple), unless
827
+ * the `expectArray` parameter is set to true, in which case, the method
828
+ * returns an `UploadedFile[]` array.
829
+ *
830
+ * @param key
831
+ * @param defaultValue
832
+ * @param expectArray set to true to return an `UploadedFile[]` array.
833
+ * @returns
834
+ */
835
+ file<K$1 extends string | undefined = undefined, E extends boolean | undefined = undefined>(key?: K$1, defaultValue?: any, expectArray?: E): K$1 extends undefined ? Record<string, E extends true ? IUploadedFile[] : IUploadedFile> : E extends true ? IUploadedFile[] : IUploadedFile;
836
+ /**
837
+ * Determine if the uploaded data contains a file.
838
+ *
839
+ * @param key
840
+ * @return boolean
841
+ */
842
+ hasFile(key: string): boolean;
843
+ /**
844
+ * Get an object with all the files on the request.
845
+ */
846
+ allFiles(): Record<string, IUploadedFile | IUploadedFile[]>;
847
+ /**
848
+ * Extract and convert uploaded files from FormData.
849
+ */
850
+ convertUploadedFiles(files: Record<string, IUploadedFile | IUploadedFile[]>): Record<string, IUploadedFile | IUploadedFile[]>;
851
+ /**
852
+ * Determine if the data contains a given key.
853
+ *
854
+ * @param keys
855
+ * @returns
856
+ */
857
+ has(keys: string[] | string): boolean;
858
+ /**
859
+ * Determine if the instance is missing a given key.
860
+ */
861
+ missing(key: string | string[]): boolean;
862
+ /**
863
+ * Get a subset containing the provided keys with values from the instance data.
864
+ *
865
+ * @param keys
866
+ * @returns
867
+ */
868
+ only<T = Record<string, any>>(keys: string[]): T;
869
+ /**
870
+ * Get all of the data except for a specified array of items.
871
+ *
872
+ * @param keys
873
+ * @returns
874
+ */
875
+ except<T = Record<string, any>>(keys: string[]): T;
876
+ /**
877
+ * Merges new input data into the current request's input source.
878
+ *
879
+ * @param input - An object containing key-value pairs to merge.
880
+ * @returns this - For fluent chaining.
881
+ */
882
+ merge(input: Record<string, any>): this;
883
+ /**
884
+ * Merge new input into the request's input, but only when that key is missing from the request.
885
+ *
886
+ * @param input
887
+ */
888
+ mergeIfMissing(input: Record<string, any>): this;
889
+ /**
890
+ * Get the keys for all of the input and files.
891
+ */
892
+ keys(): string[];
893
+ /**
894
+ * Determine if the request is sending JSON.
895
+ *
896
+ * @return bool
897
+ */
898
+ isJson(): boolean;
899
+ /**
900
+ * Determine if the current request probably expects a JSON response.
901
+ *
902
+ * @returns
903
+ */
904
+ expectsJson(): boolean;
905
+ /**
906
+ * Determine if the current request is asking for JSON.
907
+ *
908
+ * @returns
909
+ */
910
+ wantsJson(): boolean;
911
+ /**
912
+ * Gets a list of content types acceptable by the client browser in preferable order.
913
+ * @returns {string[]}
914
+ */
915
+ getAcceptableContentTypes(): string[];
916
+ /**
917
+ * Determine if the request is the result of a PJAX call.
918
+ *
919
+ * @return bool
920
+ */
921
+ pjax(): boolean;
922
+ /**
923
+ * Returns true if the request is an XMLHttpRequest (AJAX).
924
+ *
925
+ * @alias isXmlHttpRequest()
926
+ * @returns {boolean}
927
+ */
928
+ ajax(): boolean;
929
+ /**
930
+ * Returns true if the request is an XMLHttpRequest (AJAX).
931
+ */
932
+ isXmlHttpRequest(): boolean;
933
+ /**
934
+ * Returns the value of the requested header.
935
+ */
936
+ getHeader(name: string): string | undefined | null;
937
+ /**
938
+ * Checks if the request method is of specified type.
939
+ *
940
+ * @param method Uppercase request method (GET, POST etc)
941
+ */
942
+ isMethod(method: string): boolean;
943
+ /**
944
+ * Checks whether or not the method is safe.
945
+ *
946
+ * @see https://tools.ietf.org/html/rfc7231#section-4.2.1
947
+ */
948
+ isMethodSafe(): boolean;
949
+ /**
950
+ * Checks whether or not the method is idempotent.
951
+ */
952
+ isMethodIdempotent(): boolean;
953
+ /**
954
+ * Checks whether the method is cacheable or not.
955
+ *
956
+ * @see https://tools.ietf.org/html/rfc7231#section-4.2.3
957
+ */
958
+ isMethodCacheable(): boolean;
959
+ /**
960
+ * Gets the request "intended" method.
961
+ *
962
+ * If the X-HTTP-Method-Override header is set, and if the method is a POST,
963
+ * then it is used to determine the "real" intended HTTP method.
964
+ *
965
+ * The _method request parameter can also be used to determine the HTTP method,
966
+ * but only if enableHttpMethodParameterOverride() has been called.
967
+ *
968
+ * The method is always an uppercased string.
969
+ *
970
+ * @see getRealMethod()
971
+ */
972
+ getMethod(): RequestMethod;
973
+ /**
974
+ * Gets the "real" request method.
975
+ *
976
+ * @see getMethod()
977
+ */
978
+ getRealMethod(): RequestMethod;
979
+ /**
980
+ * Get the client IP address.
981
+ */
982
+ ip(): string | undefined;
983
+ /**
984
+ * Get a URI instance for the request.
985
+ */
986
+ uri(): unknown;
987
+ /**
988
+ * Get the full URL for the request.
989
+ */
990
+ fullUrl(): string;
991
+ /**
992
+ * Return the Request instance.
993
+ */
994
+ instance(): this;
995
+ /**
996
+ * Get the request method.
997
+ */
998
+ method(): RequestMethod;
999
+ /**
1000
+ * Get the JSON payload for the request.
1001
+ *
1002
+ * @param key
1003
+ * @param defaultValue
1004
+ * @return {InputBag}
1005
+ */
1006
+ json<K$1 extends string | undefined = undefined>(key?: string, defaultValue?: any): K$1 extends undefined ? IParamBag : any;
1007
+ /**
1008
+ * Returns the request body content.
1009
+ *
1010
+ * @param asStream If true, returns a ReadableStream instead of the parsed string
1011
+ * @return {string | ReadableStream | Promise<string | ReadableStream>}
1012
+ */
1013
+ getContent(asStream?: boolean): string | ReadableStream;
1014
+ /**
1015
+ * Gets a "parameter" value from any bag.
1016
+ *
1017
+ * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
1018
+ * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
1019
+ * public property instead (attributes, query, request).
1020
+ *
1021
+ * Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
1022
+ *
1023
+ * @internal use explicit input sources instead
1024
+ */
1025
+ get(key: string, defaultValue?: any): any;
1026
+ /**
1027
+ * Enables support for the _method request parameter to determine the intended HTTP method.
1028
+ *
1029
+ * Be warned that enabling this feature might lead to CSRF issues in your code.
1030
+ * Check that you are using CSRF tokens when required.
1031
+ * If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
1032
+ * and used to send a "PUT" or "DELETE" request via the _method request parameter.
1033
+ * If these methods are not protected against CSRF, this presents a possible vulnerability.
1034
+ *
1035
+ * The HTTP method can only be overridden when the real HTTP method is POST.
1036
+ */
1037
+ static enableHttpMethodParameterOverride(): void;
1038
+ /**
1039
+ * Checks whether support for the _method request parameter is enabled.
1040
+ */
1041
+ static getHttpMethodParameterOverride(): boolean;
1042
+ /**
1043
+ * Dump the items.
1044
+ *
1045
+ * @param keys
1046
+ * @return this
1047
+ */
1048
+ dump(...keys: any[]): this;
1049
+ /**
1050
+ * Get the base event
1051
+ */
1052
+ getEvent(): H3Event;
1053
+ getEvent<K$1 extends DotNestedKeys<H3Event>>(key: K$1): DotNestedValue<H3Event, K$1>;
1054
+ }
1055
+ //#endregion
391
1056
  //#region src/Utils/PathLoader.d.ts
392
1057
  declare class PathLoader {
393
1058
  private paths;
@@ -411,7 +1076,7 @@ declare class PathLoader {
411
1076
  }
412
1077
  //#endregion
413
1078
  //#region src/Contracts/BindingsContract.d.ts
414
- type RemoveIndexSignature<T$1> = { [K in keyof T$1 as string extends K ? never : number extends K ? never : K]: T$1[K] };
1079
+ type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
415
1080
  type Bindings = {
416
1081
  [key: string]: any;
417
1082
  [key: `app.${string}`]: any;
@@ -724,6 +1389,13 @@ declare class Resolver {
724
1389
  * @returns
725
1390
  */
726
1391
  static hashObjectOrFunction(provider: object | ((..._: any[]) => any)): string;
1392
+ /**
1393
+ * Checks if a function is asyncronous
1394
+ *
1395
+ * @param func
1396
+ * @returns
1397
+ */
1398
+ static isAsyncFunction(func: any): boolean;
727
1399
  }
728
1400
  //#endregion
729
1401
  //#region src/Utils/scripts.d.ts
@@ -773,4 +1445,4 @@ declare class TaskManager {
773
1445
  static advancedTaskRunner<R = any>(info: [[string, string], [string, string]] | [[string, string]], task: (() => Promise<R>) | (() => R)): Promise<R | undefined>;
774
1446
  }
775
1447
  //#endregion
776
- export { Bindings, Choice, type ChoiceOrSeparatorArray, Choices, DotFlatten, DotNestedKeys, DotNestedValue, EnvParser, EventHandler, ExtractControllerMethods, FileSystem, GenericWithNullableStringValues, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IRequest, IResponse, IRouter, ISeparator, IServiceProvider, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, PathLoader, Prompts, Resolver, RouteDefinition, RouteEventHandler, RouteMethod, RouterEnd, TaskManager, UseKey, baseTsconfig, mainTsconfig, packageJsonScript };
1448
+ export { Bindings, Choice, type ChoiceOrSeparatorArray, Choices, DotFlatten, DotNestedKeys, DotNestedValue, EnvParser, EventHandler, ExtractControllerMethods, FileSystem, GenericWithNullableStringValues, HttpContext, IApplication, IContainer, IController, IHttpResponse, IMiddleware, IParamBag, IPathName, IRequest, IResponse, IRouter, ISeparator, IServiceProvider, IUploadedFile, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, PathLoader, Prompts, RequestMethod, RequestObject, Resolver, ResponseObject, RouteDefinition, RouteEventHandler, RouteMethod, RouterEnd, TaskManager, UseKey, baseTsconfig, mainTsconfig, packageJsonScript };