@h3ravel/shared 0.25.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 -39
- package/dist/index.d.cts +429 -44
- package/dist/index.d.ts +429 -44
- package/dist/index.js +1 -39
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -38,44 +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
|
-
static contexts = /* @__PURE__ */ new WeakMap();
|
|
48
|
-
constructor(app, request, response) {
|
|
49
|
-
this.app = app;
|
|
50
|
-
this.request = request;
|
|
51
|
-
this.response = response;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Factory method to create a new HttpContext instance from a context object.
|
|
55
|
-
* @param ctx - Object containing app, request, and response
|
|
56
|
-
* @returns A new HttpContext instance
|
|
57
|
-
*/
|
|
58
|
-
static init(ctx, event) {
|
|
59
|
-
if (event && HttpContext.contexts.has(event)) return HttpContext.contexts.get(event);
|
|
60
|
-
const instance = new HttpContext(ctx.app, ctx.request, ctx.response);
|
|
61
|
-
if (event) HttpContext.contexts.set(event, instance);
|
|
62
|
-
return instance;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Retrieve an existing HttpContext instance for an event, if any.
|
|
66
|
-
*/
|
|
67
|
-
static get(event) {
|
|
68
|
-
return HttpContext.contexts.get(event);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Delete the cached context for a given event (optional cleanup).
|
|
72
|
-
*/
|
|
73
|
-
static forget(event) {
|
|
74
|
-
HttpContext.contexts.delete(event);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
//#endregion
|
|
79
41
|
//#region src/Utils/EnvParser.ts
|
|
80
42
|
var EnvParser = class {
|
|
81
43
|
static parse(initial) {
|
|
@@ -557,7 +519,6 @@ var TaskManager = class {
|
|
|
557
519
|
//#endregion
|
|
558
520
|
exports.EnvParser = EnvParser;
|
|
559
521
|
exports.FileSystem = FileSystem;
|
|
560
|
-
exports.HttpContext = HttpContext;
|
|
561
522
|
exports.Logger = Logger;
|
|
562
523
|
exports.PathLoader = PathLoader;
|
|
563
524
|
exports.Prompts = Prompts;
|
package/dist/index.d.cts
CHANGED
|
@@ -151,46 +151,6 @@ interface IApplication extends IContainer {
|
|
|
151
151
|
getVersion(key: string): string | undefined;
|
|
152
152
|
}
|
|
153
153
|
//#endregion
|
|
154
|
-
//#region src/Contracts/IRequest.d.ts
|
|
155
|
-
/**
|
|
156
|
-
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
157
|
-
*/
|
|
158
|
-
interface IRequest {
|
|
159
|
-
/**
|
|
160
|
-
* The current app instance
|
|
161
|
-
*/
|
|
162
|
-
app: IApplication;
|
|
163
|
-
/**
|
|
164
|
-
* Gets route parameters.
|
|
165
|
-
* @returns An object containing route parameters.
|
|
166
|
-
*/
|
|
167
|
-
params: NonNullable<H3Event['context']['params']>;
|
|
168
|
-
/**
|
|
169
|
-
* Gets query parameters.
|
|
170
|
-
* @returns An object containing query parameters.
|
|
171
|
-
*/
|
|
172
|
-
query: Record<string, any>;
|
|
173
|
-
/**
|
|
174
|
-
* Gets all input data (query parameters, route parameters, and body).
|
|
175
|
-
* @returns A promise resolving to an object containing all input data.
|
|
176
|
-
*/
|
|
177
|
-
all<T = Record<string, unknown>>(): Promise<T>;
|
|
178
|
-
/**
|
|
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.
|
|
183
|
-
*/
|
|
184
|
-
input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
|
|
185
|
-
/**
|
|
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.
|
|
189
|
-
*/
|
|
190
|
-
getEvent(): H3Event;
|
|
191
|
-
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
192
|
-
}
|
|
193
|
-
//#endregion
|
|
194
154
|
//#region src/Contracts/IResponse.d.ts
|
|
195
155
|
/**
|
|
196
156
|
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
@@ -249,11 +209,13 @@ interface IResponse {
|
|
|
249
209
|
//#endregion
|
|
250
210
|
//#region src/Contracts/IHttp.d.ts
|
|
251
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>;
|
|
252
214
|
type ExtractControllerMethods<T$1> = { [K in keyof T$1]: T$1[K] extends ((...args: any[]) => any) ? K : never }[keyof T$1];
|
|
253
215
|
/**
|
|
254
216
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
255
217
|
*/
|
|
256
|
-
|
|
218
|
+
declare class IRouter {
|
|
257
219
|
/**
|
|
258
220
|
* Registers a GET route.
|
|
259
221
|
* @param path - The route path.
|
|
@@ -373,7 +335,7 @@ type RouteEventHandler = (...args: any[]) => any;
|
|
|
373
335
|
* Defines the contract for all controllers.
|
|
374
336
|
* Any controller implementing this must define these methods.
|
|
375
337
|
*/
|
|
376
|
-
|
|
338
|
+
declare class IController {
|
|
377
339
|
show?(...ctx: any[]): any;
|
|
378
340
|
index?(...ctx: any[]): any;
|
|
379
341
|
store?(...ctx: any[]): any;
|
|
@@ -384,10 +346,433 @@ interface IController {
|
|
|
384
346
|
* Defines the contract for all middlewares.
|
|
385
347
|
* Any middleware implementing this must define these methods.
|
|
386
348
|
*/
|
|
387
|
-
|
|
349
|
+
declare class IMiddleware {
|
|
388
350
|
handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
|
|
389
351
|
}
|
|
390
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
|
|
391
776
|
//#region src/Utils/PathLoader.d.ts
|
|
392
777
|
declare class PathLoader {
|
|
393
778
|
private paths;
|
|
@@ -773,4 +1158,4 @@ declare class TaskManager {
|
|
|
773
1158
|
static advancedTaskRunner<R = any>(info: [[string, string], [string, string]] | [[string, string]], task: (() => Promise<R>) | (() => R)): Promise<R | undefined>;
|
|
774
1159
|
}
|
|
775
1160
|
//#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 };
|
|
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
|
@@ -151,46 +151,6 @@ interface IApplication extends IContainer {
|
|
|
151
151
|
getVersion(key: string): string | undefined;
|
|
152
152
|
}
|
|
153
153
|
//#endregion
|
|
154
|
-
//#region src/Contracts/IRequest.d.ts
|
|
155
|
-
/**
|
|
156
|
-
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
157
|
-
*/
|
|
158
|
-
interface IRequest {
|
|
159
|
-
/**
|
|
160
|
-
* The current app instance
|
|
161
|
-
*/
|
|
162
|
-
app: IApplication;
|
|
163
|
-
/**
|
|
164
|
-
* Gets route parameters.
|
|
165
|
-
* @returns An object containing route parameters.
|
|
166
|
-
*/
|
|
167
|
-
params: NonNullable<H3Event['context']['params']>;
|
|
168
|
-
/**
|
|
169
|
-
* Gets query parameters.
|
|
170
|
-
* @returns An object containing query parameters.
|
|
171
|
-
*/
|
|
172
|
-
query: Record<string, any>;
|
|
173
|
-
/**
|
|
174
|
-
* Gets all input data (query parameters, route parameters, and body).
|
|
175
|
-
* @returns A promise resolving to an object containing all input data.
|
|
176
|
-
*/
|
|
177
|
-
all<T = Record<string, unknown>>(): Promise<T>;
|
|
178
|
-
/**
|
|
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.
|
|
183
|
-
*/
|
|
184
|
-
input<T = unknown>(key: string, defaultValue?: T): Promise<T>;
|
|
185
|
-
/**
|
|
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.
|
|
189
|
-
*/
|
|
190
|
-
getEvent(): H3Event;
|
|
191
|
-
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
192
|
-
}
|
|
193
|
-
//#endregion
|
|
194
154
|
//#region src/Contracts/IResponse.d.ts
|
|
195
155
|
/**
|
|
196
156
|
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
@@ -249,11 +209,13 @@ interface IResponse {
|
|
|
249
209
|
//#endregion
|
|
250
210
|
//#region src/Contracts/IHttp.d.ts
|
|
251
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>;
|
|
252
214
|
type ExtractControllerMethods<T$1> = { [K in keyof T$1]: T$1[K] extends ((...args: any[]) => any) ? K : never }[keyof T$1];
|
|
253
215
|
/**
|
|
254
216
|
* Interface for the Router contract, defining methods for HTTP routing.
|
|
255
217
|
*/
|
|
256
|
-
|
|
218
|
+
declare class IRouter {
|
|
257
219
|
/**
|
|
258
220
|
* Registers a GET route.
|
|
259
221
|
* @param path - The route path.
|
|
@@ -373,7 +335,7 @@ type RouteEventHandler = (...args: any[]) => any;
|
|
|
373
335
|
* Defines the contract for all controllers.
|
|
374
336
|
* Any controller implementing this must define these methods.
|
|
375
337
|
*/
|
|
376
|
-
|
|
338
|
+
declare class IController {
|
|
377
339
|
show?(...ctx: any[]): any;
|
|
378
340
|
index?(...ctx: any[]): any;
|
|
379
341
|
store?(...ctx: any[]): any;
|
|
@@ -384,10 +346,433 @@ interface IController {
|
|
|
384
346
|
* Defines the contract for all middlewares.
|
|
385
347
|
* Any middleware implementing this must define these methods.
|
|
386
348
|
*/
|
|
387
|
-
|
|
349
|
+
declare class IMiddleware {
|
|
388
350
|
handle(context: HttpContext, next: () => Promise<any>): Promise<any>;
|
|
389
351
|
}
|
|
390
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
|
|
391
776
|
//#region src/Utils/PathLoader.d.ts
|
|
392
777
|
declare class PathLoader {
|
|
393
778
|
private paths;
|
|
@@ -773,4 +1158,4 @@ declare class TaskManager {
|
|
|
773
1158
|
static advancedTaskRunner<R = any>(info: [[string, string], [string, string]] | [[string, string]], task: (() => Promise<R>) | (() => R)): Promise<R | undefined>;
|
|
774
1159
|
}
|
|
775
1160
|
//#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 };
|
|
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,44 +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
|
-
static contexts = /* @__PURE__ */ new WeakMap();
|
|
17
|
-
constructor(app, request, response) {
|
|
18
|
-
this.app = app;
|
|
19
|
-
this.request = request;
|
|
20
|
-
this.response = response;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Factory method to create a new HttpContext instance from a context object.
|
|
24
|
-
* @param ctx - Object containing app, request, and response
|
|
25
|
-
* @returns A new HttpContext instance
|
|
26
|
-
*/
|
|
27
|
-
static init(ctx, event) {
|
|
28
|
-
if (event && HttpContext.contexts.has(event)) return HttpContext.contexts.get(event);
|
|
29
|
-
const instance = new HttpContext(ctx.app, ctx.request, ctx.response);
|
|
30
|
-
if (event) HttpContext.contexts.set(event, instance);
|
|
31
|
-
return instance;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Retrieve an existing HttpContext instance for an event, if any.
|
|
35
|
-
*/
|
|
36
|
-
static get(event) {
|
|
37
|
-
return HttpContext.contexts.get(event);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Delete the cached context for a given event (optional cleanup).
|
|
41
|
-
*/
|
|
42
|
-
static forget(event) {
|
|
43
|
-
HttpContext.contexts.delete(event);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
10
|
//#region src/Utils/EnvParser.ts
|
|
49
11
|
var EnvParser = class {
|
|
50
12
|
static parse(initial) {
|
|
@@ -524,4 +486,4 @@ var TaskManager = class {
|
|
|
524
486
|
};
|
|
525
487
|
|
|
526
488
|
//#endregion
|
|
527
|
-
export { EnvParser, FileSystem,
|
|
489
|
+
export { EnvParser, FileSystem, Logger, PathLoader, Prompts, Resolver, TaskManager, baseTsconfig, mainTsconfig, packageJsonScript };
|