@h3ravel/shared 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +0 -26
- package/dist/index.d.cts +443 -55
- package/dist/index.d.ts +443 -55
- package/dist/index.js +1 -26
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -38,31 +38,6 @@ crypto = __toESM(crypto);
|
|
|
38
38
|
let preferred_pm = require("preferred-pm");
|
|
39
39
|
preferred_pm = __toESM(preferred_pm);
|
|
40
40
|
|
|
41
|
-
//#region src/Contracts/IHttp.ts
|
|
42
|
-
/**
|
|
43
|
-
* Represents the HTTP context for a single request lifecycle.
|
|
44
|
-
* Encapsulates the application instance, request, and response objects.
|
|
45
|
-
*/
|
|
46
|
-
var HttpContext = class HttpContext {
|
|
47
|
-
constructor(app, request, response) {
|
|
48
|
-
this.app = app;
|
|
49
|
-
this.request = request;
|
|
50
|
-
this.response = response;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Factory method to create a new HttpContext instance from a context object.
|
|
54
|
-
* @param ctx - Object containing app, request, and response
|
|
55
|
-
* @returns A new HttpContext instance
|
|
56
|
-
*/
|
|
57
|
-
static init(ctx) {
|
|
58
|
-
/**
|
|
59
|
-
* Return a new instance
|
|
60
|
-
*/
|
|
61
|
-
return new HttpContext(ctx.app, ctx.request, ctx.response);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
41
|
//#region src/Utils/EnvParser.ts
|
|
67
42
|
var EnvParser = class {
|
|
68
43
|
static parse(initial) {
|
|
@@ -544,7 +519,6 @@ var TaskManager = class {
|
|
|
544
519
|
//#endregion
|
|
545
520
|
exports.EnvParser = EnvParser;
|
|
546
521
|
exports.FileSystem = FileSystem;
|
|
547
|
-
exports.HttpContext = HttpContext;
|
|
548
522
|
exports.Logger = Logger;
|
|
549
523
|
exports.PathLoader = PathLoader;
|
|
550
524
|
exports.Prompts = Prompts;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
|
-
import { H3, H3Event, Middleware, MiddlewareOptions, serve } from "h3";
|
|
2
|
+
import { H3, H3Event, HTTPResponse, Middleware, MiddlewareOptions, serve } from "h3";
|
|
3
3
|
import { Edge } from "edge.js";
|
|
4
|
-
import { ResponseHeaderMap, TypedHeaders } from "fetchdts";
|
|
5
4
|
import { DotNestedKeys as DotNestedKeys$1, DotNestedValue as DotNestedValue$1 } from "@h3ravel/shared";
|
|
6
5
|
import { Separator } from "@inquirer/prompts";
|
|
7
6
|
import { ChoiceOrSeparatorArray, ChoiceOrSeparatorArray as ChoiceOrSeparatorArray$1 } from "inquirer-autocomplete-standalone";
|
|
@@ -152,51 +151,6 @@ interface IApplication extends IContainer {
|
|
|
152
151
|
getVersion(key: string): string | undefined;
|
|
153
152
|
}
|
|
154
153
|
//#endregion
|
|
155
|
-
//#region src/Contracts/IRequest.d.ts
|
|
156
|
-
/**
|
|
157
|
-
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
158
|
-
*/
|
|
159
|
-
interface IRequest {
|
|
160
|
-
/**
|
|
161
|
-
* The current app instance
|
|
162
|
-
*/
|
|
163
|
-
app: IApplication;
|
|
164
|
-
/**
|
|
165
|
-
* Gets route parameters.
|
|
166
|
-
* @returns An object containing route parameters.
|
|
167
|
-
*/
|
|
168
|
-
params: NonNullable<H3Event['context']['params']>;
|
|
169
|
-
/**
|
|
170
|
-
* Gets query parameters.
|
|
171
|
-
* @returns An object containing query parameters.
|
|
172
|
-
*/
|
|
173
|
-
query: Record<string, any>;
|
|
174
|
-
/**
|
|
175
|
-
* Gets the request headers.
|
|
176
|
-
* @returns An object containing request headers.
|
|
177
|
-
*/
|
|
178
|
-
headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
|
|
179
|
-
/**
|
|
180
|
-
* Gets all input data (query parameters, route parameters, and body).
|
|
181
|
-
* @returns A promise resolving to an object containing all input data.
|
|
182
|
-
*/
|
|
183
|
-
all<T = Record<string, unknown>>(): Promise<T>;
|
|
184
|
-
/**
|
|
185
|
-
* Gets a single input field from query or body.
|
|
186
|
-
* @param key - The key of the input field.
|
|
187
|
-
* @param defaultValue - Optional default value if the key is not found.
|
|
188
|
-
* @returns A promise resolving to the value of the input field or the default value.
|
|
189
|
-
*/
|
|
190
|
-
input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
|
|
191
|
-
/**
|
|
192
|
-
* Gets the underlying event object or a specific property of it.
|
|
193
|
-
* @param key - Optional key to access a nested property of the event.
|
|
194
|
-
* @returns The entire event object or the value of the specified property.
|
|
195
|
-
*/
|
|
196
|
-
getEvent(): H3Event;
|
|
197
|
-
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
198
|
-
}
|
|
199
|
-
//#endregion
|
|
200
154
|
//#region src/Contracts/IResponse.d.ts
|
|
201
155
|
/**
|
|
202
156
|
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
@@ -224,7 +178,7 @@ interface IResponse {
|
|
|
224
178
|
* @param content - The HTML content to send.
|
|
225
179
|
* @returns The HTML content.
|
|
226
180
|
*/
|
|
227
|
-
html(content: string):
|
|
181
|
+
html(content: string): HTTPResponse;
|
|
228
182
|
/**
|
|
229
183
|
* Sends a JSON response.
|
|
230
184
|
* @param data - The data to send as JSON.
|
|
@@ -243,7 +197,7 @@ interface IResponse {
|
|
|
243
197
|
* @param status - The HTTP status code for the redirect (default: 302).
|
|
244
198
|
* @returns The redirect URL.
|
|
245
199
|
*/
|
|
246
|
-
redirect(url: string, status?: number):
|
|
200
|
+
redirect(url: string, status?: number): HTTPResponse;
|
|
247
201
|
/**
|
|
248
202
|
* Gets the underlying event object or a specific property of it.
|
|
249
203
|
* @param key - Optional key to access a nested property of the event.
|
|
@@ -255,11 +209,13 @@ interface IResponse {
|
|
|
255
209
|
//#endregion
|
|
256
210
|
//#region src/Contracts/IHttp.d.ts
|
|
257
211
|
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';
|
|
212
|
+
type RequestMethod = 'HEAD' | 'GET' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'PURGE' | 'POST' | 'CONNECT' | 'PATCH';
|
|
213
|
+
type RequestObject = Record<string, any>;
|
|
258
214
|
type ExtractControllerMethods<T$1> = { [K in keyof T$1]: T$1[K] extends ((...args: any[]) => any) ? K : never }[keyof T$1];
|
|
259
215
|
/**
|
|
260
216
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
261
217
|
*/
|
|
262
|
-
|
|
218
|
+
declare class IRouter {
|
|
263
219
|
/**
|
|
264
220
|
* Registers a GET route.
|
|
265
221
|
* @param path - The route path.
|
|
@@ -349,6 +305,7 @@ declare class HttpContext {
|
|
|
349
305
|
app: IApplication;
|
|
350
306
|
request: IRequest;
|
|
351
307
|
response: IResponse;
|
|
308
|
+
private static contexts;
|
|
352
309
|
constructor(app: IApplication, request: IRequest, response: IResponse);
|
|
353
310
|
/**
|
|
354
311
|
* Factory method to create a new HttpContext instance from a context object.
|
|
@@ -359,7 +316,15 @@ declare class HttpContext {
|
|
|
359
316
|
app: IApplication;
|
|
360
317
|
request: IRequest;
|
|
361
318
|
response: IResponse;
|
|
362
|
-
}): HttpContext;
|
|
319
|
+
}, event?: unknown): HttpContext;
|
|
320
|
+
/**
|
|
321
|
+
* Retrieve an existing HttpContext instance for an event, if any.
|
|
322
|
+
*/
|
|
323
|
+
static get(event: unknown): HttpContext | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* Delete the cached context for a given event (optional cleanup).
|
|
326
|
+
*/
|
|
327
|
+
static forget(event: unknown): void;
|
|
363
328
|
}
|
|
364
329
|
/**
|
|
365
330
|
* Type for EventHandler, representing a function that handles an H3 event.
|
|
@@ -370,7 +335,7 @@ type RouteEventHandler = (...args: any[]) => any;
|
|
|
370
335
|
* Defines the contract for all controllers.
|
|
371
336
|
* Any controller implementing this must define these methods.
|
|
372
337
|
*/
|
|
373
|
-
|
|
338
|
+
declare class IController {
|
|
374
339
|
show?(...ctx: any[]): any;
|
|
375
340
|
index?(...ctx: any[]): any;
|
|
376
341
|
store?(...ctx: any[]): any;
|
|
@@ -381,10 +346,433 @@ interface IController {
|
|
|
381
346
|
* Defines the contract for all middlewares.
|
|
382
347
|
* Any middleware implementing this must define these methods.
|
|
383
348
|
*/
|
|
384
|
-
|
|
349
|
+
declare class IMiddleware {
|
|
385
350
|
handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
|
|
386
351
|
}
|
|
387
352
|
//#endregion
|
|
353
|
+
//#region src/Contracts/IParamBag.d.ts
|
|
354
|
+
declare class IParamBag implements Iterable<[string, any]> {
|
|
355
|
+
/**
|
|
356
|
+
* The current H3 H3Event instance
|
|
357
|
+
*/
|
|
358
|
+
readonly event: H3Event;
|
|
359
|
+
constructor(parameters: RequestObject | undefined,
|
|
360
|
+
/**
|
|
361
|
+
* The current H3 H3Event instance
|
|
362
|
+
*/
|
|
363
|
+
event: H3Event);
|
|
364
|
+
/**
|
|
365
|
+
* Returns the parameters.
|
|
366
|
+
* @
|
|
367
|
+
* @param key The name of the parameter to return or null to get them all
|
|
368
|
+
*
|
|
369
|
+
* @throws BadRequestException if the value is not an array
|
|
370
|
+
*/
|
|
371
|
+
all(key?: string): any;
|
|
372
|
+
get(key: string, defaultValue?: any): any;
|
|
373
|
+
set(key: string, value: any): void;
|
|
374
|
+
/**
|
|
375
|
+
* Returns true if the parameter is defined.
|
|
376
|
+
*
|
|
377
|
+
* @param key
|
|
378
|
+
*/
|
|
379
|
+
has(key: string): boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Removes a parameter.
|
|
382
|
+
*
|
|
383
|
+
* @param key
|
|
384
|
+
*/
|
|
385
|
+
remove(key: string): void;
|
|
386
|
+
/**
|
|
387
|
+
*
|
|
388
|
+
* Returns the parameter as string.
|
|
389
|
+
*
|
|
390
|
+
* @param key
|
|
391
|
+
* @param defaultValue
|
|
392
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
393
|
+
* @returns
|
|
394
|
+
*/
|
|
395
|
+
getString(key: string, defaultValue?: string): string;
|
|
396
|
+
/**
|
|
397
|
+
* Returns the parameter value converted to integer.
|
|
398
|
+
*
|
|
399
|
+
* @param key
|
|
400
|
+
* @param defaultValue
|
|
401
|
+
* @throws UnexpectedValueException if the value cannot be converted to integer
|
|
402
|
+
*/
|
|
403
|
+
getInt(key: string, defaultValue?: number): number;
|
|
404
|
+
/**
|
|
405
|
+
* Returns the parameter value converted to boolean.
|
|
406
|
+
*
|
|
407
|
+
* @param key
|
|
408
|
+
* @param defaultValue
|
|
409
|
+
* @throws UnexpectedValueException if the value cannot be converted to a boolean
|
|
410
|
+
*/
|
|
411
|
+
getBoolean(key: string, defaultValue?: boolean): boolean;
|
|
412
|
+
/**
|
|
413
|
+
* Returns the alphabetic characters of the parameter value.
|
|
414
|
+
*
|
|
415
|
+
* @param key
|
|
416
|
+
* @param defaultValue
|
|
417
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
418
|
+
*/
|
|
419
|
+
getAlpha(key: string, defaultValue?: string): string;
|
|
420
|
+
/**
|
|
421
|
+
* Returns the alphabetic characters and digits of the parameter value.
|
|
422
|
+
*
|
|
423
|
+
* @param key
|
|
424
|
+
* @param defaultValue
|
|
425
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
426
|
+
*/
|
|
427
|
+
getAlnum(key: string, defaultValue?: string): string;
|
|
428
|
+
/**
|
|
429
|
+
* Returns the digits of the parameter value.
|
|
430
|
+
*
|
|
431
|
+
* @param key
|
|
432
|
+
* @param defaultValue
|
|
433
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
434
|
+
* @returns
|
|
435
|
+
**/
|
|
436
|
+
getDigits(key: string, defaultValue?: string): string;
|
|
437
|
+
/**
|
|
438
|
+
* Returns the parameter keys.
|
|
439
|
+
*/
|
|
440
|
+
keys(): string[];
|
|
441
|
+
/**
|
|
442
|
+
* Replaces the current parameters by a new set.
|
|
443
|
+
*/
|
|
444
|
+
replace(parameters?: RequestObject): void;
|
|
445
|
+
/**
|
|
446
|
+
* Adds parameters.
|
|
447
|
+
*/
|
|
448
|
+
add(parameters?: RequestObject): void;
|
|
449
|
+
/**
|
|
450
|
+
* Returns the number of parameters.
|
|
451
|
+
*/
|
|
452
|
+
count(): number;
|
|
453
|
+
/**
|
|
454
|
+
* Returns an iterator for parameters.
|
|
455
|
+
*
|
|
456
|
+
* @returns
|
|
457
|
+
*/
|
|
458
|
+
[Symbol.iterator](): ArrayIterator<[string, any]>;
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region src/Contracts/IUploadedFile.d.ts
|
|
462
|
+
declare class IUploadedFile {
|
|
463
|
+
originalName: string;
|
|
464
|
+
mimeType: string;
|
|
465
|
+
size: number;
|
|
466
|
+
content: File;
|
|
467
|
+
constructor(originalName: string, mimeType: string, size: number, content: File);
|
|
468
|
+
static createFromBase(file: File): IUploadedFile;
|
|
469
|
+
/**
|
|
470
|
+
* Save to disk (Node environment only)
|
|
471
|
+
*/
|
|
472
|
+
moveTo(destination: string): Promise<void>;
|
|
473
|
+
}
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/Contracts/IRequest.d.ts
|
|
476
|
+
type RequestObject$1 = Record<string, any>;
|
|
477
|
+
/**
|
|
478
|
+
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
479
|
+
*/
|
|
480
|
+
declare class IRequest {
|
|
481
|
+
/**
|
|
482
|
+
* The current app instance
|
|
483
|
+
*/
|
|
484
|
+
app: IApplication;
|
|
485
|
+
/**
|
|
486
|
+
* Parsed request body
|
|
487
|
+
*/
|
|
488
|
+
body: unknown;
|
|
489
|
+
/**
|
|
490
|
+
* Gets route parameters.
|
|
491
|
+
* @returns An object containing route parameters.
|
|
492
|
+
*/
|
|
493
|
+
params: NonNullable<H3Event['context']['params']>;
|
|
494
|
+
/**
|
|
495
|
+
* Uploaded files (FILES).
|
|
496
|
+
*/
|
|
497
|
+
constructor(
|
|
498
|
+
/**
|
|
499
|
+
* The current H3 H3Event instance
|
|
500
|
+
*/
|
|
501
|
+
event: H3Event,
|
|
502
|
+
/**
|
|
503
|
+
* The current app instance
|
|
504
|
+
*/
|
|
505
|
+
app: IApplication);
|
|
506
|
+
/**
|
|
507
|
+
* Factory method to create a Request instance from an H3Event.
|
|
508
|
+
*/
|
|
509
|
+
static create(
|
|
510
|
+
/**
|
|
511
|
+
* The current H3 H3Event instance
|
|
512
|
+
*/
|
|
513
|
+
event: H3Event,
|
|
514
|
+
/**
|
|
515
|
+
* The current app instance
|
|
516
|
+
*/
|
|
517
|
+
app: IApplication): Promise<Request>;
|
|
518
|
+
/**
|
|
519
|
+
* Sets the parameters for this request.
|
|
520
|
+
*
|
|
521
|
+
* This method also re-initializes all properties.
|
|
522
|
+
*
|
|
523
|
+
* @param attributes
|
|
524
|
+
* @param cookies The COOKIE parameters
|
|
525
|
+
* @param files The FILES parameters
|
|
526
|
+
* @param server The SERVER parameters
|
|
527
|
+
* @param content The raw body data
|
|
528
|
+
*/
|
|
529
|
+
initialize(): Promise<void>;
|
|
530
|
+
/**
|
|
531
|
+
* Retrieve all data from the instance (query + body).
|
|
532
|
+
*/
|
|
533
|
+
all<T = Record<string, any>>(keys?: string | string[]): T;
|
|
534
|
+
/**
|
|
535
|
+
* Retrieve an input item from the request.
|
|
536
|
+
*
|
|
537
|
+
* @param key
|
|
538
|
+
* @param defaultValue
|
|
539
|
+
* @returns
|
|
540
|
+
*/
|
|
541
|
+
input<K extends string | undefined>(key?: K, defaultValue?: any): K extends undefined ? RequestObject$1 : any;
|
|
542
|
+
/**
|
|
543
|
+
* Retrieve a file from the request.
|
|
544
|
+
*
|
|
545
|
+
* By default a single `UploadedFile` instance will always be returned by
|
|
546
|
+
* the method (first file in property when there are multiple), unless
|
|
547
|
+
* the `expectArray` parameter is set to true, in which case, the method
|
|
548
|
+
* returns an `UploadedFile[]` array.
|
|
549
|
+
*
|
|
550
|
+
* @param key
|
|
551
|
+
* @param defaultValue
|
|
552
|
+
* @param expectArray set to true to return an `UploadedFile[]` array.
|
|
553
|
+
* @returns
|
|
554
|
+
*/
|
|
555
|
+
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 ? IUploadedFile[] : IUploadedFile> : E extends true ? IUploadedFile[] : IUploadedFile;
|
|
556
|
+
/**
|
|
557
|
+
* Determine if the uploaded data contains a file.
|
|
558
|
+
*
|
|
559
|
+
* @param key
|
|
560
|
+
* @return boolean
|
|
561
|
+
*/
|
|
562
|
+
hasFile(key: string): boolean;
|
|
563
|
+
/**
|
|
564
|
+
* Get an object with all the files on the request.
|
|
565
|
+
*/
|
|
566
|
+
allFiles(): Record<string, IUploadedFile | IUploadedFile[]>;
|
|
567
|
+
/**
|
|
568
|
+
* Extract and convert uploaded files from FormData.
|
|
569
|
+
*/
|
|
570
|
+
convertUploadedFiles(files: Record<string, IUploadedFile | IUploadedFile[]>): Record<string, IUploadedFile | IUploadedFile[]>;
|
|
571
|
+
/**
|
|
572
|
+
* Determine if the data contains a given key.
|
|
573
|
+
*
|
|
574
|
+
* @param keys
|
|
575
|
+
* @returns
|
|
576
|
+
*/
|
|
577
|
+
has(keys: string[] | string): boolean;
|
|
578
|
+
/**
|
|
579
|
+
* Determine if the instance is missing a given key.
|
|
580
|
+
*/
|
|
581
|
+
missing(key: string | string[]): boolean;
|
|
582
|
+
/**
|
|
583
|
+
* Get a subset containing the provided keys with values from the instance data.
|
|
584
|
+
*
|
|
585
|
+
* @param keys
|
|
586
|
+
* @returns
|
|
587
|
+
*/
|
|
588
|
+
only<T = Record<string, any>>(keys: string[]): T;
|
|
589
|
+
/**
|
|
590
|
+
* Get all of the data except for a specified array of items.
|
|
591
|
+
*
|
|
592
|
+
* @param keys
|
|
593
|
+
* @returns
|
|
594
|
+
*/
|
|
595
|
+
except<T = Record<string, any>>(keys: string[]): T;
|
|
596
|
+
/**
|
|
597
|
+
* Merges new input data into the current request's input source.
|
|
598
|
+
*
|
|
599
|
+
* @param input - An object containing key-value pairs to merge.
|
|
600
|
+
* @returns this - For fluent chaining.
|
|
601
|
+
*/
|
|
602
|
+
merge(input: Record<string, any>): this;
|
|
603
|
+
/**
|
|
604
|
+
* Merge new input into the request's input, but only when that key is missing from the request.
|
|
605
|
+
*
|
|
606
|
+
* @param input
|
|
607
|
+
*/
|
|
608
|
+
mergeIfMissing(input: Record<string, any>): this;
|
|
609
|
+
/**
|
|
610
|
+
* Get the keys for all of the input and files.
|
|
611
|
+
*/
|
|
612
|
+
keys(): string[];
|
|
613
|
+
/**
|
|
614
|
+
* Determine if the request is sending JSON.
|
|
615
|
+
*
|
|
616
|
+
* @return bool
|
|
617
|
+
*/
|
|
618
|
+
isJson(): boolean;
|
|
619
|
+
/**
|
|
620
|
+
* Determine if the current request probably expects a JSON response.
|
|
621
|
+
*
|
|
622
|
+
* @returns
|
|
623
|
+
*/
|
|
624
|
+
expectsJson(): boolean;
|
|
625
|
+
/**
|
|
626
|
+
* Determine if the current request is asking for JSON.
|
|
627
|
+
*
|
|
628
|
+
* @returns
|
|
629
|
+
*/
|
|
630
|
+
wantsJson(): boolean;
|
|
631
|
+
/**
|
|
632
|
+
* Gets a list of content types acceptable by the client browser in preferable order.
|
|
633
|
+
* @returns {string[]}
|
|
634
|
+
*/
|
|
635
|
+
getAcceptableContentTypes(): string[];
|
|
636
|
+
/**
|
|
637
|
+
* Determine if the request is the result of a PJAX call.
|
|
638
|
+
*
|
|
639
|
+
* @return bool
|
|
640
|
+
*/
|
|
641
|
+
pjax(): boolean;
|
|
642
|
+
/**
|
|
643
|
+
* Returns true if the request is an XMLHttpRequest (AJAX).
|
|
644
|
+
*
|
|
645
|
+
* @alias isXmlHttpRequest()
|
|
646
|
+
* @returns {boolean}
|
|
647
|
+
*/
|
|
648
|
+
ajax(): boolean;
|
|
649
|
+
/**
|
|
650
|
+
* Returns true if the request is an XMLHttpRequest (AJAX).
|
|
651
|
+
*/
|
|
652
|
+
isXmlHttpRequest(): boolean;
|
|
653
|
+
/**
|
|
654
|
+
* Returns the value of the requested header.
|
|
655
|
+
*/
|
|
656
|
+
getHeader(name: string): string | undefined | null;
|
|
657
|
+
/**
|
|
658
|
+
* Checks if the request method is of specified type.
|
|
659
|
+
*
|
|
660
|
+
* @param method Uppercase request method (GET, POST etc)
|
|
661
|
+
*/
|
|
662
|
+
isMethod(method: string): boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Checks whether or not the method is safe.
|
|
665
|
+
*
|
|
666
|
+
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1
|
|
667
|
+
*/
|
|
668
|
+
isMethodSafe(): boolean;
|
|
669
|
+
/**
|
|
670
|
+
* Checks whether or not the method is idempotent.
|
|
671
|
+
*/
|
|
672
|
+
isMethodIdempotent(): boolean;
|
|
673
|
+
/**
|
|
674
|
+
* Checks whether the method is cacheable or not.
|
|
675
|
+
*
|
|
676
|
+
* @see https://tools.ietf.org/html/rfc7231#section-4.2.3
|
|
677
|
+
*/
|
|
678
|
+
isMethodCacheable(): boolean;
|
|
679
|
+
/**
|
|
680
|
+
* Gets the request "intended" method.
|
|
681
|
+
*
|
|
682
|
+
* If the X-HTTP-Method-Override header is set, and if the method is a POST,
|
|
683
|
+
* then it is used to determine the "real" intended HTTP method.
|
|
684
|
+
*
|
|
685
|
+
* The _method request parameter can also be used to determine the HTTP method,
|
|
686
|
+
* but only if enableHttpMethodParameterOverride() has been called.
|
|
687
|
+
*
|
|
688
|
+
* The method is always an uppercased string.
|
|
689
|
+
*
|
|
690
|
+
* @see getRealMethod()
|
|
691
|
+
*/
|
|
692
|
+
getMethod(): RequestMethod;
|
|
693
|
+
/**
|
|
694
|
+
* Gets the "real" request method.
|
|
695
|
+
*
|
|
696
|
+
* @see getMethod()
|
|
697
|
+
*/
|
|
698
|
+
getRealMethod(): RequestMethod;
|
|
699
|
+
/**
|
|
700
|
+
* Get the client IP address.
|
|
701
|
+
*/
|
|
702
|
+
ip(): string | undefined;
|
|
703
|
+
/**
|
|
704
|
+
* Get a URI instance for the request.
|
|
705
|
+
*/
|
|
706
|
+
uri(): unknown;
|
|
707
|
+
/**
|
|
708
|
+
* Get the full URL for the request.
|
|
709
|
+
*/
|
|
710
|
+
fullUrl(): string;
|
|
711
|
+
/**
|
|
712
|
+
* Return the Request instance.
|
|
713
|
+
*/
|
|
714
|
+
instance(): this;
|
|
715
|
+
/**
|
|
716
|
+
* Get the request method.
|
|
717
|
+
*/
|
|
718
|
+
method(): RequestMethod;
|
|
719
|
+
/**
|
|
720
|
+
* Get the JSON payload for the request.
|
|
721
|
+
*
|
|
722
|
+
* @param key
|
|
723
|
+
* @param defaultValue
|
|
724
|
+
* @return {InputBag}
|
|
725
|
+
*/
|
|
726
|
+
json<K extends string | undefined = undefined>(key?: string, defaultValue?: any): K extends undefined ? IParamBag : any;
|
|
727
|
+
/**
|
|
728
|
+
* Returns the request body content.
|
|
729
|
+
*
|
|
730
|
+
* @param asStream If true, returns a ReadableStream instead of the parsed string
|
|
731
|
+
* @return {string | ReadableStream | Promise<string | ReadableStream>}
|
|
732
|
+
*/
|
|
733
|
+
getContent(asStream?: boolean): string | ReadableStream;
|
|
734
|
+
/**
|
|
735
|
+
* Gets a "parameter" value from any bag.
|
|
736
|
+
*
|
|
737
|
+
* This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
|
|
738
|
+
* flexibility in controllers, it is better to explicitly get request parameters from the appropriate
|
|
739
|
+
* public property instead (attributes, query, request).
|
|
740
|
+
*
|
|
741
|
+
* Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
|
|
742
|
+
*
|
|
743
|
+
* @internal use explicit input sources instead
|
|
744
|
+
*/
|
|
745
|
+
get(key: string, defaultValue?: any): any;
|
|
746
|
+
/**
|
|
747
|
+
* Enables support for the _method request parameter to determine the intended HTTP method.
|
|
748
|
+
*
|
|
749
|
+
* Be warned that enabling this feature might lead to CSRF issues in your code.
|
|
750
|
+
* Check that you are using CSRF tokens when required.
|
|
751
|
+
* If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
|
|
752
|
+
* and used to send a "PUT" or "DELETE" request via the _method request parameter.
|
|
753
|
+
* If these methods are not protected against CSRF, this presents a possible vulnerability.
|
|
754
|
+
*
|
|
755
|
+
* The HTTP method can only be overridden when the real HTTP method is POST.
|
|
756
|
+
*/
|
|
757
|
+
static enableHttpMethodParameterOverride(): void;
|
|
758
|
+
/**
|
|
759
|
+
* Checks whether support for the _method request parameter is enabled.
|
|
760
|
+
*/
|
|
761
|
+
static getHttpMethodParameterOverride(): boolean;
|
|
762
|
+
/**
|
|
763
|
+
* Dump the items.
|
|
764
|
+
*
|
|
765
|
+
* @param keys
|
|
766
|
+
* @return this
|
|
767
|
+
*/
|
|
768
|
+
dump(...keys: any[]): this;
|
|
769
|
+
/**
|
|
770
|
+
* Get the base event
|
|
771
|
+
*/
|
|
772
|
+
getEvent(): H3Event;
|
|
773
|
+
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
774
|
+
}
|
|
775
|
+
//#endregion
|
|
388
776
|
//#region src/Utils/PathLoader.d.ts
|
|
389
777
|
declare class PathLoader {
|
|
390
778
|
private paths;
|
|
@@ -414,7 +802,7 @@ type Bindings = {
|
|
|
414
802
|
[key: `app.${string}`]: any;
|
|
415
803
|
env(): NodeJS.ProcessEnv;
|
|
416
804
|
env<T extends string>(key: T, def?: any): any;
|
|
417
|
-
view(viewPath: string, params?: Record<string, any>): Promise<
|
|
805
|
+
view(viewPath: string, params?: Record<string, any>): Promise<HTTPResponse>;
|
|
418
806
|
edge: Edge;
|
|
419
807
|
asset(key: string, def?: string): string;
|
|
420
808
|
router: IRouter;
|
|
@@ -770,4 +1158,4 @@ declare class TaskManager {
|
|
|
770
1158
|
static advancedTaskRunner<R = any>(info: [[string, string], [string, string]] | [[string, string]], task: (() => Promise<R>) | (() => R)): Promise<R | undefined>;
|
|
771
1159
|
}
|
|
772
1160
|
//#endregion
|
|
773
|
-
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 };
|
|
1161
|
+
export { Bindings, Choice, type ChoiceOrSeparatorArray, Choices, DotFlatten, DotNestedKeys, DotNestedValue, EnvParser, EventHandler, ExtractControllerMethods, FileSystem, GenericWithNullableStringValues, HttpContext, IApplication, IContainer, IController, IMiddleware, IParamBag, IPathName, IRequest, IResponse, IRouter, ISeparator, IServiceProvider, IUploadedFile, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, PathLoader, Prompts, RequestMethod, RequestObject, Resolver, RouteDefinition, RouteEventHandler, RouteMethod, RouterEnd, TaskManager, UseKey, baseTsconfig, mainTsconfig, packageJsonScript };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
import { ChalkInstance } from "chalk";
|
|
3
3
|
import { ChoiceOrSeparatorArray, ChoiceOrSeparatorArray as ChoiceOrSeparatorArray$1 } from "inquirer-autocomplete-standalone";
|
|
4
4
|
import { Separator } from "@inquirer/prompts";
|
|
5
|
-
import { H3, H3Event, Middleware, MiddlewareOptions, serve } from "h3";
|
|
5
|
+
import { H3, H3Event, HTTPResponse, Middleware, MiddlewareOptions, serve } from "h3";
|
|
6
6
|
import { Edge } from "edge.js";
|
|
7
|
-
import { ResponseHeaderMap, TypedHeaders } from "fetchdts";
|
|
8
7
|
import { DotNestedKeys as DotNestedKeys$1, DotNestedValue as DotNestedValue$1 } from "@h3ravel/shared";
|
|
9
8
|
|
|
10
9
|
//#region src/Contracts/ObjContract.d.ts
|
|
@@ -152,51 +151,6 @@ interface IApplication extends IContainer {
|
|
|
152
151
|
getVersion(key: string): string | undefined;
|
|
153
152
|
}
|
|
154
153
|
//#endregion
|
|
155
|
-
//#region src/Contracts/IRequest.d.ts
|
|
156
|
-
/**
|
|
157
|
-
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
158
|
-
*/
|
|
159
|
-
interface IRequest {
|
|
160
|
-
/**
|
|
161
|
-
* The current app instance
|
|
162
|
-
*/
|
|
163
|
-
app: IApplication;
|
|
164
|
-
/**
|
|
165
|
-
* Gets route parameters.
|
|
166
|
-
* @returns An object containing route parameters.
|
|
167
|
-
*/
|
|
168
|
-
params: NonNullable<H3Event['context']['params']>;
|
|
169
|
-
/**
|
|
170
|
-
* Gets query parameters.
|
|
171
|
-
* @returns An object containing query parameters.
|
|
172
|
-
*/
|
|
173
|
-
query: Record<string, any>;
|
|
174
|
-
/**
|
|
175
|
-
* Gets the request headers.
|
|
176
|
-
* @returns An object containing request headers.
|
|
177
|
-
*/
|
|
178
|
-
headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
|
|
179
|
-
/**
|
|
180
|
-
* Gets all input data (query parameters, route parameters, and body).
|
|
181
|
-
* @returns A promise resolving to an object containing all input data.
|
|
182
|
-
*/
|
|
183
|
-
all<T = Record<string, unknown>>(): Promise<T>;
|
|
184
|
-
/**
|
|
185
|
-
* Gets a single input field from query or body.
|
|
186
|
-
* @param key - The key of the input field.
|
|
187
|
-
* @param defaultValue - Optional default value if the key is not found.
|
|
188
|
-
* @returns A promise resolving to the value of the input field or the default value.
|
|
189
|
-
*/
|
|
190
|
-
input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
|
|
191
|
-
/**
|
|
192
|
-
* Gets the underlying event object or a specific property of it.
|
|
193
|
-
* @param key - Optional key to access a nested property of the event.
|
|
194
|
-
* @returns The entire event object or the value of the specified property.
|
|
195
|
-
*/
|
|
196
|
-
getEvent(): H3Event;
|
|
197
|
-
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
198
|
-
}
|
|
199
|
-
//#endregion
|
|
200
154
|
//#region src/Contracts/IResponse.d.ts
|
|
201
155
|
/**
|
|
202
156
|
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
@@ -224,7 +178,7 @@ interface IResponse {
|
|
|
224
178
|
* @param content - The HTML content to send.
|
|
225
179
|
* @returns The HTML content.
|
|
226
180
|
*/
|
|
227
|
-
html(content: string):
|
|
181
|
+
html(content: string): HTTPResponse;
|
|
228
182
|
/**
|
|
229
183
|
* Sends a JSON response.
|
|
230
184
|
* @param data - The data to send as JSON.
|
|
@@ -243,7 +197,7 @@ interface IResponse {
|
|
|
243
197
|
* @param status - The HTTP status code for the redirect (default: 302).
|
|
244
198
|
* @returns The redirect URL.
|
|
245
199
|
*/
|
|
246
|
-
redirect(url: string, status?: number):
|
|
200
|
+
redirect(url: string, status?: number): HTTPResponse;
|
|
247
201
|
/**
|
|
248
202
|
* Gets the underlying event object or a specific property of it.
|
|
249
203
|
* @param key - Optional key to access a nested property of the event.
|
|
@@ -255,11 +209,13 @@ interface IResponse {
|
|
|
255
209
|
//#endregion
|
|
256
210
|
//#region src/Contracts/IHttp.d.ts
|
|
257
211
|
type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'patch' | 'apiResource' | 'group' | 'route';
|
|
212
|
+
type RequestMethod = 'HEAD' | 'GET' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'PURGE' | 'POST' | 'CONNECT' | 'PATCH';
|
|
213
|
+
type RequestObject = Record<string, any>;
|
|
258
214
|
type ExtractControllerMethods<T$1> = { [K in keyof T$1]: T$1[K] extends ((...args: any[]) => any) ? K : never }[keyof T$1];
|
|
259
215
|
/**
|
|
260
216
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
261
217
|
*/
|
|
262
|
-
|
|
218
|
+
declare class IRouter {
|
|
263
219
|
/**
|
|
264
220
|
* Registers a GET route.
|
|
265
221
|
* @param path - The route path.
|
|
@@ -349,6 +305,7 @@ declare class HttpContext {
|
|
|
349
305
|
app: IApplication;
|
|
350
306
|
request: IRequest;
|
|
351
307
|
response: IResponse;
|
|
308
|
+
private static contexts;
|
|
352
309
|
constructor(app: IApplication, request: IRequest, response: IResponse);
|
|
353
310
|
/**
|
|
354
311
|
* Factory method to create a new HttpContext instance from a context object.
|
|
@@ -359,7 +316,15 @@ declare class HttpContext {
|
|
|
359
316
|
app: IApplication;
|
|
360
317
|
request: IRequest;
|
|
361
318
|
response: IResponse;
|
|
362
|
-
}): HttpContext;
|
|
319
|
+
}, event?: unknown): HttpContext;
|
|
320
|
+
/**
|
|
321
|
+
* Retrieve an existing HttpContext instance for an event, if any.
|
|
322
|
+
*/
|
|
323
|
+
static get(event: unknown): HttpContext | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* Delete the cached context for a given event (optional cleanup).
|
|
326
|
+
*/
|
|
327
|
+
static forget(event: unknown): void;
|
|
363
328
|
}
|
|
364
329
|
/**
|
|
365
330
|
* Type for EventHandler, representing a function that handles an H3 event.
|
|
@@ -370,7 +335,7 @@ type RouteEventHandler = (...args: any[]) => any;
|
|
|
370
335
|
* Defines the contract for all controllers.
|
|
371
336
|
* Any controller implementing this must define these methods.
|
|
372
337
|
*/
|
|
373
|
-
|
|
338
|
+
declare class IController {
|
|
374
339
|
show?(...ctx: any[]): any;
|
|
375
340
|
index?(...ctx: any[]): any;
|
|
376
341
|
store?(...ctx: any[]): any;
|
|
@@ -381,10 +346,433 @@ interface IController {
|
|
|
381
346
|
* Defines the contract for all middlewares.
|
|
382
347
|
* Any middleware implementing this must define these methods.
|
|
383
348
|
*/
|
|
384
|
-
|
|
349
|
+
declare class IMiddleware {
|
|
385
350
|
handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
|
|
386
351
|
}
|
|
387
352
|
//#endregion
|
|
353
|
+
//#region src/Contracts/IParamBag.d.ts
|
|
354
|
+
declare class IParamBag implements Iterable<[string, any]> {
|
|
355
|
+
/**
|
|
356
|
+
* The current H3 H3Event instance
|
|
357
|
+
*/
|
|
358
|
+
readonly event: H3Event;
|
|
359
|
+
constructor(parameters: RequestObject | undefined,
|
|
360
|
+
/**
|
|
361
|
+
* The current H3 H3Event instance
|
|
362
|
+
*/
|
|
363
|
+
event: H3Event);
|
|
364
|
+
/**
|
|
365
|
+
* Returns the parameters.
|
|
366
|
+
* @
|
|
367
|
+
* @param key The name of the parameter to return or null to get them all
|
|
368
|
+
*
|
|
369
|
+
* @throws BadRequestException if the value is not an array
|
|
370
|
+
*/
|
|
371
|
+
all(key?: string): any;
|
|
372
|
+
get(key: string, defaultValue?: any): any;
|
|
373
|
+
set(key: string, value: any): void;
|
|
374
|
+
/**
|
|
375
|
+
* Returns true if the parameter is defined.
|
|
376
|
+
*
|
|
377
|
+
* @param key
|
|
378
|
+
*/
|
|
379
|
+
has(key: string): boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Removes a parameter.
|
|
382
|
+
*
|
|
383
|
+
* @param key
|
|
384
|
+
*/
|
|
385
|
+
remove(key: string): void;
|
|
386
|
+
/**
|
|
387
|
+
*
|
|
388
|
+
* Returns the parameter as string.
|
|
389
|
+
*
|
|
390
|
+
* @param key
|
|
391
|
+
* @param defaultValue
|
|
392
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
393
|
+
* @returns
|
|
394
|
+
*/
|
|
395
|
+
getString(key: string, defaultValue?: string): string;
|
|
396
|
+
/**
|
|
397
|
+
* Returns the parameter value converted to integer.
|
|
398
|
+
*
|
|
399
|
+
* @param key
|
|
400
|
+
* @param defaultValue
|
|
401
|
+
* @throws UnexpectedValueException if the value cannot be converted to integer
|
|
402
|
+
*/
|
|
403
|
+
getInt(key: string, defaultValue?: number): number;
|
|
404
|
+
/**
|
|
405
|
+
* Returns the parameter value converted to boolean.
|
|
406
|
+
*
|
|
407
|
+
* @param key
|
|
408
|
+
* @param defaultValue
|
|
409
|
+
* @throws UnexpectedValueException if the value cannot be converted to a boolean
|
|
410
|
+
*/
|
|
411
|
+
getBoolean(key: string, defaultValue?: boolean): boolean;
|
|
412
|
+
/**
|
|
413
|
+
* Returns the alphabetic characters of the parameter value.
|
|
414
|
+
*
|
|
415
|
+
* @param key
|
|
416
|
+
* @param defaultValue
|
|
417
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
418
|
+
*/
|
|
419
|
+
getAlpha(key: string, defaultValue?: string): string;
|
|
420
|
+
/**
|
|
421
|
+
* Returns the alphabetic characters and digits of the parameter value.
|
|
422
|
+
*
|
|
423
|
+
* @param key
|
|
424
|
+
* @param defaultValue
|
|
425
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
426
|
+
*/
|
|
427
|
+
getAlnum(key: string, defaultValue?: string): string;
|
|
428
|
+
/**
|
|
429
|
+
* Returns the digits of the parameter value.
|
|
430
|
+
*
|
|
431
|
+
* @param key
|
|
432
|
+
* @param defaultValue
|
|
433
|
+
* @throws UnexpectedValueException if the value cannot be converted to string
|
|
434
|
+
* @returns
|
|
435
|
+
**/
|
|
436
|
+
getDigits(key: string, defaultValue?: string): string;
|
|
437
|
+
/**
|
|
438
|
+
* Returns the parameter keys.
|
|
439
|
+
*/
|
|
440
|
+
keys(): string[];
|
|
441
|
+
/**
|
|
442
|
+
* Replaces the current parameters by a new set.
|
|
443
|
+
*/
|
|
444
|
+
replace(parameters?: RequestObject): void;
|
|
445
|
+
/**
|
|
446
|
+
* Adds parameters.
|
|
447
|
+
*/
|
|
448
|
+
add(parameters?: RequestObject): void;
|
|
449
|
+
/**
|
|
450
|
+
* Returns the number of parameters.
|
|
451
|
+
*/
|
|
452
|
+
count(): number;
|
|
453
|
+
/**
|
|
454
|
+
* Returns an iterator for parameters.
|
|
455
|
+
*
|
|
456
|
+
* @returns
|
|
457
|
+
*/
|
|
458
|
+
[Symbol.iterator](): ArrayIterator<[string, any]>;
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region src/Contracts/IUploadedFile.d.ts
|
|
462
|
+
declare class IUploadedFile {
|
|
463
|
+
originalName: string;
|
|
464
|
+
mimeType: string;
|
|
465
|
+
size: number;
|
|
466
|
+
content: File;
|
|
467
|
+
constructor(originalName: string, mimeType: string, size: number, content: File);
|
|
468
|
+
static createFromBase(file: File): IUploadedFile;
|
|
469
|
+
/**
|
|
470
|
+
* Save to disk (Node environment only)
|
|
471
|
+
*/
|
|
472
|
+
moveTo(destination: string): Promise<void>;
|
|
473
|
+
}
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/Contracts/IRequest.d.ts
|
|
476
|
+
type RequestObject$1 = Record<string, any>;
|
|
477
|
+
/**
|
|
478
|
+
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
479
|
+
*/
|
|
480
|
+
declare class IRequest {
|
|
481
|
+
/**
|
|
482
|
+
* The current app instance
|
|
483
|
+
*/
|
|
484
|
+
app: IApplication;
|
|
485
|
+
/**
|
|
486
|
+
* Parsed request body
|
|
487
|
+
*/
|
|
488
|
+
body: unknown;
|
|
489
|
+
/**
|
|
490
|
+
* Gets route parameters.
|
|
491
|
+
* @returns An object containing route parameters.
|
|
492
|
+
*/
|
|
493
|
+
params: NonNullable<H3Event['context']['params']>;
|
|
494
|
+
/**
|
|
495
|
+
* Uploaded files (FILES).
|
|
496
|
+
*/
|
|
497
|
+
constructor(
|
|
498
|
+
/**
|
|
499
|
+
* The current H3 H3Event instance
|
|
500
|
+
*/
|
|
501
|
+
event: H3Event,
|
|
502
|
+
/**
|
|
503
|
+
* The current app instance
|
|
504
|
+
*/
|
|
505
|
+
app: IApplication);
|
|
506
|
+
/**
|
|
507
|
+
* Factory method to create a Request instance from an H3Event.
|
|
508
|
+
*/
|
|
509
|
+
static create(
|
|
510
|
+
/**
|
|
511
|
+
* The current H3 H3Event instance
|
|
512
|
+
*/
|
|
513
|
+
event: H3Event,
|
|
514
|
+
/**
|
|
515
|
+
* The current app instance
|
|
516
|
+
*/
|
|
517
|
+
app: IApplication): Promise<Request>;
|
|
518
|
+
/**
|
|
519
|
+
* Sets the parameters for this request.
|
|
520
|
+
*
|
|
521
|
+
* This method also re-initializes all properties.
|
|
522
|
+
*
|
|
523
|
+
* @param attributes
|
|
524
|
+
* @param cookies The COOKIE parameters
|
|
525
|
+
* @param files The FILES parameters
|
|
526
|
+
* @param server The SERVER parameters
|
|
527
|
+
* @param content The raw body data
|
|
528
|
+
*/
|
|
529
|
+
initialize(): Promise<void>;
|
|
530
|
+
/**
|
|
531
|
+
* Retrieve all data from the instance (query + body).
|
|
532
|
+
*/
|
|
533
|
+
all<T = Record<string, any>>(keys?: string | string[]): T;
|
|
534
|
+
/**
|
|
535
|
+
* Retrieve an input item from the request.
|
|
536
|
+
*
|
|
537
|
+
* @param key
|
|
538
|
+
* @param defaultValue
|
|
539
|
+
* @returns
|
|
540
|
+
*/
|
|
541
|
+
input<K extends string | undefined>(key?: K, defaultValue?: any): K extends undefined ? RequestObject$1 : any;
|
|
542
|
+
/**
|
|
543
|
+
* Retrieve a file from the request.
|
|
544
|
+
*
|
|
545
|
+
* By default a single `UploadedFile` instance will always be returned by
|
|
546
|
+
* the method (first file in property when there are multiple), unless
|
|
547
|
+
* the `expectArray` parameter is set to true, in which case, the method
|
|
548
|
+
* returns an `UploadedFile[]` array.
|
|
549
|
+
*
|
|
550
|
+
* @param key
|
|
551
|
+
* @param defaultValue
|
|
552
|
+
* @param expectArray set to true to return an `UploadedFile[]` array.
|
|
553
|
+
* @returns
|
|
554
|
+
*/
|
|
555
|
+
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 ? IUploadedFile[] : IUploadedFile> : E extends true ? IUploadedFile[] : IUploadedFile;
|
|
556
|
+
/**
|
|
557
|
+
* Determine if the uploaded data contains a file.
|
|
558
|
+
*
|
|
559
|
+
* @param key
|
|
560
|
+
* @return boolean
|
|
561
|
+
*/
|
|
562
|
+
hasFile(key: string): boolean;
|
|
563
|
+
/**
|
|
564
|
+
* Get an object with all the files on the request.
|
|
565
|
+
*/
|
|
566
|
+
allFiles(): Record<string, IUploadedFile | IUploadedFile[]>;
|
|
567
|
+
/**
|
|
568
|
+
* Extract and convert uploaded files from FormData.
|
|
569
|
+
*/
|
|
570
|
+
convertUploadedFiles(files: Record<string, IUploadedFile | IUploadedFile[]>): Record<string, IUploadedFile | IUploadedFile[]>;
|
|
571
|
+
/**
|
|
572
|
+
* Determine if the data contains a given key.
|
|
573
|
+
*
|
|
574
|
+
* @param keys
|
|
575
|
+
* @returns
|
|
576
|
+
*/
|
|
577
|
+
has(keys: string[] | string): boolean;
|
|
578
|
+
/**
|
|
579
|
+
* Determine if the instance is missing a given key.
|
|
580
|
+
*/
|
|
581
|
+
missing(key: string | string[]): boolean;
|
|
582
|
+
/**
|
|
583
|
+
* Get a subset containing the provided keys with values from the instance data.
|
|
584
|
+
*
|
|
585
|
+
* @param keys
|
|
586
|
+
* @returns
|
|
587
|
+
*/
|
|
588
|
+
only<T = Record<string, any>>(keys: string[]): T;
|
|
589
|
+
/**
|
|
590
|
+
* Get all of the data except for a specified array of items.
|
|
591
|
+
*
|
|
592
|
+
* @param keys
|
|
593
|
+
* @returns
|
|
594
|
+
*/
|
|
595
|
+
except<T = Record<string, any>>(keys: string[]): T;
|
|
596
|
+
/**
|
|
597
|
+
* Merges new input data into the current request's input source.
|
|
598
|
+
*
|
|
599
|
+
* @param input - An object containing key-value pairs to merge.
|
|
600
|
+
* @returns this - For fluent chaining.
|
|
601
|
+
*/
|
|
602
|
+
merge(input: Record<string, any>): this;
|
|
603
|
+
/**
|
|
604
|
+
* Merge new input into the request's input, but only when that key is missing from the request.
|
|
605
|
+
*
|
|
606
|
+
* @param input
|
|
607
|
+
*/
|
|
608
|
+
mergeIfMissing(input: Record<string, any>): this;
|
|
609
|
+
/**
|
|
610
|
+
* Get the keys for all of the input and files.
|
|
611
|
+
*/
|
|
612
|
+
keys(): string[];
|
|
613
|
+
/**
|
|
614
|
+
* Determine if the request is sending JSON.
|
|
615
|
+
*
|
|
616
|
+
* @return bool
|
|
617
|
+
*/
|
|
618
|
+
isJson(): boolean;
|
|
619
|
+
/**
|
|
620
|
+
* Determine if the current request probably expects a JSON response.
|
|
621
|
+
*
|
|
622
|
+
* @returns
|
|
623
|
+
*/
|
|
624
|
+
expectsJson(): boolean;
|
|
625
|
+
/**
|
|
626
|
+
* Determine if the current request is asking for JSON.
|
|
627
|
+
*
|
|
628
|
+
* @returns
|
|
629
|
+
*/
|
|
630
|
+
wantsJson(): boolean;
|
|
631
|
+
/**
|
|
632
|
+
* Gets a list of content types acceptable by the client browser in preferable order.
|
|
633
|
+
* @returns {string[]}
|
|
634
|
+
*/
|
|
635
|
+
getAcceptableContentTypes(): string[];
|
|
636
|
+
/**
|
|
637
|
+
* Determine if the request is the result of a PJAX call.
|
|
638
|
+
*
|
|
639
|
+
* @return bool
|
|
640
|
+
*/
|
|
641
|
+
pjax(): boolean;
|
|
642
|
+
/**
|
|
643
|
+
* Returns true if the request is an XMLHttpRequest (AJAX).
|
|
644
|
+
*
|
|
645
|
+
* @alias isXmlHttpRequest()
|
|
646
|
+
* @returns {boolean}
|
|
647
|
+
*/
|
|
648
|
+
ajax(): boolean;
|
|
649
|
+
/**
|
|
650
|
+
* Returns true if the request is an XMLHttpRequest (AJAX).
|
|
651
|
+
*/
|
|
652
|
+
isXmlHttpRequest(): boolean;
|
|
653
|
+
/**
|
|
654
|
+
* Returns the value of the requested header.
|
|
655
|
+
*/
|
|
656
|
+
getHeader(name: string): string | undefined | null;
|
|
657
|
+
/**
|
|
658
|
+
* Checks if the request method is of specified type.
|
|
659
|
+
*
|
|
660
|
+
* @param method Uppercase request method (GET, POST etc)
|
|
661
|
+
*/
|
|
662
|
+
isMethod(method: string): boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Checks whether or not the method is safe.
|
|
665
|
+
*
|
|
666
|
+
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1
|
|
667
|
+
*/
|
|
668
|
+
isMethodSafe(): boolean;
|
|
669
|
+
/**
|
|
670
|
+
* Checks whether or not the method is idempotent.
|
|
671
|
+
*/
|
|
672
|
+
isMethodIdempotent(): boolean;
|
|
673
|
+
/**
|
|
674
|
+
* Checks whether the method is cacheable or not.
|
|
675
|
+
*
|
|
676
|
+
* @see https://tools.ietf.org/html/rfc7231#section-4.2.3
|
|
677
|
+
*/
|
|
678
|
+
isMethodCacheable(): boolean;
|
|
679
|
+
/**
|
|
680
|
+
* Gets the request "intended" method.
|
|
681
|
+
*
|
|
682
|
+
* If the X-HTTP-Method-Override header is set, and if the method is a POST,
|
|
683
|
+
* then it is used to determine the "real" intended HTTP method.
|
|
684
|
+
*
|
|
685
|
+
* The _method request parameter can also be used to determine the HTTP method,
|
|
686
|
+
* but only if enableHttpMethodParameterOverride() has been called.
|
|
687
|
+
*
|
|
688
|
+
* The method is always an uppercased string.
|
|
689
|
+
*
|
|
690
|
+
* @see getRealMethod()
|
|
691
|
+
*/
|
|
692
|
+
getMethod(): RequestMethod;
|
|
693
|
+
/**
|
|
694
|
+
* Gets the "real" request method.
|
|
695
|
+
*
|
|
696
|
+
* @see getMethod()
|
|
697
|
+
*/
|
|
698
|
+
getRealMethod(): RequestMethod;
|
|
699
|
+
/**
|
|
700
|
+
* Get the client IP address.
|
|
701
|
+
*/
|
|
702
|
+
ip(): string | undefined;
|
|
703
|
+
/**
|
|
704
|
+
* Get a URI instance for the request.
|
|
705
|
+
*/
|
|
706
|
+
uri(): unknown;
|
|
707
|
+
/**
|
|
708
|
+
* Get the full URL for the request.
|
|
709
|
+
*/
|
|
710
|
+
fullUrl(): string;
|
|
711
|
+
/**
|
|
712
|
+
* Return the Request instance.
|
|
713
|
+
*/
|
|
714
|
+
instance(): this;
|
|
715
|
+
/**
|
|
716
|
+
* Get the request method.
|
|
717
|
+
*/
|
|
718
|
+
method(): RequestMethod;
|
|
719
|
+
/**
|
|
720
|
+
* Get the JSON payload for the request.
|
|
721
|
+
*
|
|
722
|
+
* @param key
|
|
723
|
+
* @param defaultValue
|
|
724
|
+
* @return {InputBag}
|
|
725
|
+
*/
|
|
726
|
+
json<K extends string | undefined = undefined>(key?: string, defaultValue?: any): K extends undefined ? IParamBag : any;
|
|
727
|
+
/**
|
|
728
|
+
* Returns the request body content.
|
|
729
|
+
*
|
|
730
|
+
* @param asStream If true, returns a ReadableStream instead of the parsed string
|
|
731
|
+
* @return {string | ReadableStream | Promise<string | ReadableStream>}
|
|
732
|
+
*/
|
|
733
|
+
getContent(asStream?: boolean): string | ReadableStream;
|
|
734
|
+
/**
|
|
735
|
+
* Gets a "parameter" value from any bag.
|
|
736
|
+
*
|
|
737
|
+
* This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
|
|
738
|
+
* flexibility in controllers, it is better to explicitly get request parameters from the appropriate
|
|
739
|
+
* public property instead (attributes, query, request).
|
|
740
|
+
*
|
|
741
|
+
* Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
|
|
742
|
+
*
|
|
743
|
+
* @internal use explicit input sources instead
|
|
744
|
+
*/
|
|
745
|
+
get(key: string, defaultValue?: any): any;
|
|
746
|
+
/**
|
|
747
|
+
* Enables support for the _method request parameter to determine the intended HTTP method.
|
|
748
|
+
*
|
|
749
|
+
* Be warned that enabling this feature might lead to CSRF issues in your code.
|
|
750
|
+
* Check that you are using CSRF tokens when required.
|
|
751
|
+
* If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
|
|
752
|
+
* and used to send a "PUT" or "DELETE" request via the _method request parameter.
|
|
753
|
+
* If these methods are not protected against CSRF, this presents a possible vulnerability.
|
|
754
|
+
*
|
|
755
|
+
* The HTTP method can only be overridden when the real HTTP method is POST.
|
|
756
|
+
*/
|
|
757
|
+
static enableHttpMethodParameterOverride(): void;
|
|
758
|
+
/**
|
|
759
|
+
* Checks whether support for the _method request parameter is enabled.
|
|
760
|
+
*/
|
|
761
|
+
static getHttpMethodParameterOverride(): boolean;
|
|
762
|
+
/**
|
|
763
|
+
* Dump the items.
|
|
764
|
+
*
|
|
765
|
+
* @param keys
|
|
766
|
+
* @return this
|
|
767
|
+
*/
|
|
768
|
+
dump(...keys: any[]): this;
|
|
769
|
+
/**
|
|
770
|
+
* Get the base event
|
|
771
|
+
*/
|
|
772
|
+
getEvent(): H3Event;
|
|
773
|
+
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
774
|
+
}
|
|
775
|
+
//#endregion
|
|
388
776
|
//#region src/Utils/PathLoader.d.ts
|
|
389
777
|
declare class PathLoader {
|
|
390
778
|
private paths;
|
|
@@ -414,7 +802,7 @@ type Bindings = {
|
|
|
414
802
|
[key: `app.${string}`]: any;
|
|
415
803
|
env(): NodeJS.ProcessEnv;
|
|
416
804
|
env<T extends string>(key: T, def?: any): any;
|
|
417
|
-
view(viewPath: string, params?: Record<string, any>): Promise<
|
|
805
|
+
view(viewPath: string, params?: Record<string, any>): Promise<HTTPResponse>;
|
|
418
806
|
edge: Edge;
|
|
419
807
|
asset(key: string, def?: string): string;
|
|
420
808
|
router: IRouter;
|
|
@@ -770,4 +1158,4 @@ declare class TaskManager {
|
|
|
770
1158
|
static advancedTaskRunner<R = any>(info: [[string, string], [string, string]] | [[string, string]], task: (() => Promise<R>) | (() => R)): Promise<R | undefined>;
|
|
771
1159
|
}
|
|
772
1160
|
//#endregion
|
|
773
|
-
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 };
|
|
1161
|
+
export { Bindings, Choice, type ChoiceOrSeparatorArray, Choices, DotFlatten, DotNestedKeys, DotNestedValue, EnvParser, EventHandler, ExtractControllerMethods, FileSystem, GenericWithNullableStringValues, HttpContext, IApplication, IContainer, IController, IMiddleware, IParamBag, IPathName, IRequest, IResponse, IRouter, ISeparator, IServiceProvider, IUploadedFile, Logger, LoggerChalk, LoggerLog, LoggerParseSignature, PathLoader, Prompts, RequestMethod, RequestObject, Resolver, RouteDefinition, RouteEventHandler, RouteMethod, RouterEnd, TaskManager, UseKey, baseTsconfig, mainTsconfig, packageJsonScript };
|
package/dist/index.js
CHANGED
|
@@ -7,31 +7,6 @@ import { confirm, input, password, select } from "@inquirer/prompts";
|
|
|
7
7
|
import crypto from "crypto";
|
|
8
8
|
import preferredPM from "preferred-pm";
|
|
9
9
|
|
|
10
|
-
//#region src/Contracts/IHttp.ts
|
|
11
|
-
/**
|
|
12
|
-
* Represents the HTTP context for a single request lifecycle.
|
|
13
|
-
* Encapsulates the application instance, request, and response objects.
|
|
14
|
-
*/
|
|
15
|
-
var HttpContext = class HttpContext {
|
|
16
|
-
constructor(app, request, response) {
|
|
17
|
-
this.app = app;
|
|
18
|
-
this.request = request;
|
|
19
|
-
this.response = response;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Factory method to create a new HttpContext instance from a context object.
|
|
23
|
-
* @param ctx - Object containing app, request, and response
|
|
24
|
-
* @returns A new HttpContext instance
|
|
25
|
-
*/
|
|
26
|
-
static init(ctx) {
|
|
27
|
-
/**
|
|
28
|
-
* Return a new instance
|
|
29
|
-
*/
|
|
30
|
-
return new HttpContext(ctx.app, ctx.request, ctx.response);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
10
|
//#region src/Utils/EnvParser.ts
|
|
36
11
|
var EnvParser = class {
|
|
37
12
|
static parse(initial) {
|
|
@@ -511,4 +486,4 @@ var TaskManager = class {
|
|
|
511
486
|
};
|
|
512
487
|
|
|
513
488
|
//#endregion
|
|
514
|
-
export { EnvParser, FileSystem,
|
|
489
|
+
export { EnvParser, FileSystem, Logger, PathLoader, Prompts, Resolver, TaskManager, baseTsconfig, mainTsconfig, packageJsonScript };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Shared Utilities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"chalk": "^5.6.0",
|
|
49
49
|
"edge.js": "^6.3.0",
|
|
50
50
|
"escalade": "^3.2.0",
|
|
51
|
-
"h3": "
|
|
51
|
+
"h3": "2.0.1-rc.5",
|
|
52
52
|
"inquirer-autocomplete-standalone": "^0.8.1",
|
|
53
53
|
"preferred-pm": "^4.1.1"
|
|
54
54
|
},
|