@h3ravel/http 11.5.2 → 11.6.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 +45 -7
- package/dist/index.d.cts +41 -9
- package/dist/index.d.ts +41 -9
- package/dist/index.js +45 -2
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -19032,6 +19032,44 @@ var FormRequest = class {
|
|
|
19032
19032
|
}
|
|
19033
19033
|
};
|
|
19034
19034
|
|
|
19035
|
+
//#endregion
|
|
19036
|
+
//#region src/HttpContext.ts
|
|
19037
|
+
/**
|
|
19038
|
+
* Represents the HTTP context for a single request lifecycle.
|
|
19039
|
+
* Encapsulates the application instance, request, and response objects.
|
|
19040
|
+
*/
|
|
19041
|
+
var HttpContext = class HttpContext {
|
|
19042
|
+
static contexts = /* @__PURE__ */ new WeakMap();
|
|
19043
|
+
constructor(app, request, response) {
|
|
19044
|
+
this.app = app;
|
|
19045
|
+
this.request = request;
|
|
19046
|
+
this.response = response;
|
|
19047
|
+
}
|
|
19048
|
+
/**
|
|
19049
|
+
* Factory method to create a new HttpContext instance from a context object.
|
|
19050
|
+
* @param ctx - Object containing app, request, and response
|
|
19051
|
+
* @returns A new HttpContext instance
|
|
19052
|
+
*/
|
|
19053
|
+
static init(ctx, event) {
|
|
19054
|
+
if (event && HttpContext.contexts.has(event)) return HttpContext.contexts.get(event);
|
|
19055
|
+
const instance = new HttpContext(ctx.app, ctx.request, ctx.response);
|
|
19056
|
+
if (event) HttpContext.contexts.set(event, instance);
|
|
19057
|
+
return instance;
|
|
19058
|
+
}
|
|
19059
|
+
/**
|
|
19060
|
+
* Retrieve an existing HttpContext instance for an event, if any.
|
|
19061
|
+
*/
|
|
19062
|
+
static get(event) {
|
|
19063
|
+
return HttpContext.contexts.get(event);
|
|
19064
|
+
}
|
|
19065
|
+
/**
|
|
19066
|
+
* Delete the cached context for a given event (optional cleanup).
|
|
19067
|
+
*/
|
|
19068
|
+
static forget(event) {
|
|
19069
|
+
HttpContext.contexts.delete(event);
|
|
19070
|
+
}
|
|
19071
|
+
};
|
|
19072
|
+
|
|
19035
19073
|
//#endregion
|
|
19036
19074
|
//#region src/Middleware.ts
|
|
19037
19075
|
var Middleware = class {};
|
|
@@ -19235,10 +19273,15 @@ var Request = class Request {
|
|
|
19235
19273
|
}
|
|
19236
19274
|
/**
|
|
19237
19275
|
* Retrieve a file from the request.
|
|
19276
|
+
*
|
|
19277
|
+
* By default a single `UploadedFile` instance will always be returned by
|
|
19278
|
+
* the method (first file in property when there are multiple), unless
|
|
19279
|
+
* the `expectArray` parameter is set to true, in which case, the method
|
|
19280
|
+
* returns an `UploadedFile[]` array.
|
|
19238
19281
|
*
|
|
19239
19282
|
* @param key
|
|
19240
19283
|
* @param defaultValue
|
|
19241
|
-
* @param expectArray
|
|
19284
|
+
* @param expectArray set to true to return an `UploadedFile[]` array.
|
|
19242
19285
|
* @returns
|
|
19243
19286
|
*/
|
|
19244
19287
|
file(key, defaultValue, expectArray) {
|
|
@@ -19890,12 +19933,7 @@ exports.FileBag = FileBag;
|
|
|
19890
19933
|
exports.FireCommand = FireCommand;
|
|
19891
19934
|
exports.FormRequest = FormRequest;
|
|
19892
19935
|
exports.HeaderBag = HeaderBag;
|
|
19893
|
-
|
|
19894
|
-
enumerable: true,
|
|
19895
|
-
get: function () {
|
|
19896
|
-
return __h3ravel_shared.HttpContext;
|
|
19897
|
-
}
|
|
19898
|
-
});
|
|
19936
|
+
exports.HttpContext = HttpContext;
|
|
19899
19937
|
exports.HttpServiceProvider = HttpServiceProvider;
|
|
19900
19938
|
exports.InputBag = InputBag;
|
|
19901
19939
|
exports.JsonResource = JsonResource;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
2
|
import { EventHandlerRequest, H3Event, HTTPResponse } from "h3";
|
|
3
|
-
import { DotNestedKeys, DotNestedValue, HttpContext
|
|
3
|
+
import { DotNestedKeys, DotNestedValue, HttpContext as HttpContext$1, IApplication, IMiddleware, IParamBag, IRequest, IResponse, RequestMethod, RequestObject } from "@h3ravel/shared";
|
|
4
4
|
import { Command } from "@h3ravel/musket";
|
|
5
5
|
import { Application } from "@h3ravel/core";
|
|
6
6
|
import { Url } from "@h3ravel/url";
|
|
7
7
|
|
|
8
|
-
//#region src/Contracts/HttpContract.d.ts
|
|
9
|
-
type RequestMethod = 'HEAD' | 'GET' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'PURGE' | 'POST' | 'CONNECT' | 'PATCH';
|
|
10
|
-
type RequestObject = Record<string, any>;
|
|
11
|
-
//#endregion
|
|
12
8
|
//#region src/Bags/ParamBag.d.ts
|
|
13
9
|
/**
|
|
14
10
|
* ParamBag is a container for key/value pairs
|
|
15
11
|
* for Node/H3 environments.
|
|
16
12
|
*/
|
|
17
|
-
declare class ParamBag implements
|
|
13
|
+
declare class ParamBag implements IParamBag {
|
|
18
14
|
protected parameters: RequestObject;
|
|
19
15
|
/**
|
|
20
16
|
* The current H3 H3Event instance
|
|
@@ -515,6 +511,37 @@ declare class FormRequest {
|
|
|
515
511
|
all(): Record<string, any>;
|
|
516
512
|
}
|
|
517
513
|
//#endregion
|
|
514
|
+
//#region src/HttpContext.d.ts
|
|
515
|
+
/**
|
|
516
|
+
* Represents the HTTP context for a single request lifecycle.
|
|
517
|
+
* Encapsulates the application instance, request, and response objects.
|
|
518
|
+
*/
|
|
519
|
+
declare class HttpContext implements HttpContext$1 {
|
|
520
|
+
app: IApplication;
|
|
521
|
+
request: IRequest;
|
|
522
|
+
response: IResponse;
|
|
523
|
+
private static contexts;
|
|
524
|
+
constructor(app: IApplication, request: IRequest, response: IResponse);
|
|
525
|
+
/**
|
|
526
|
+
* Factory method to create a new HttpContext instance from a context object.
|
|
527
|
+
* @param ctx - Object containing app, request, and response
|
|
528
|
+
* @returns A new HttpContext instance
|
|
529
|
+
*/
|
|
530
|
+
static init(ctx: {
|
|
531
|
+
app: IApplication;
|
|
532
|
+
request: IRequest;
|
|
533
|
+
response: IResponse;
|
|
534
|
+
}, event?: unknown): HttpContext;
|
|
535
|
+
/**
|
|
536
|
+
* Retrieve an existing HttpContext instance for an event, if any.
|
|
537
|
+
*/
|
|
538
|
+
static get(event: unknown): HttpContext | undefined;
|
|
539
|
+
/**
|
|
540
|
+
* Delete the cached context for a given event (optional cleanup).
|
|
541
|
+
*/
|
|
542
|
+
static forget(event: unknown): void;
|
|
543
|
+
}
|
|
544
|
+
//#endregion
|
|
518
545
|
//#region src/Middleware.d.ts
|
|
519
546
|
declare abstract class Middleware implements IMiddleware {
|
|
520
547
|
abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
@@ -524,7 +551,7 @@ declare abstract class Middleware implements IMiddleware {
|
|
|
524
551
|
declare class LogRequests extends Middleware {
|
|
525
552
|
handle({
|
|
526
553
|
request
|
|
527
|
-
}: HttpContext
|
|
554
|
+
}: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
528
555
|
}
|
|
529
556
|
//#endregion
|
|
530
557
|
//#region src/Providers/HttpServiceProvider.d.ts
|
|
@@ -662,9 +689,14 @@ declare class Request implements IRequest {
|
|
|
662
689
|
/**
|
|
663
690
|
* Retrieve a file from the request.
|
|
664
691
|
*
|
|
692
|
+
* By default a single `UploadedFile` instance will always be returned by
|
|
693
|
+
* the method (first file in property when there are multiple), unless
|
|
694
|
+
* the `expectArray` parameter is set to true, in which case, the method
|
|
695
|
+
* returns an `UploadedFile[]` array.
|
|
696
|
+
*
|
|
665
697
|
* @param key
|
|
666
698
|
* @param defaultValue
|
|
667
|
-
* @param expectArray
|
|
699
|
+
* @param expectArray set to true to return an `UploadedFile[]` array.
|
|
668
700
|
* @returns
|
|
669
701
|
*/
|
|
670
702
|
file<K extends string | undefined = undefined, E extends boolean | undefined = undefined>(key?: K, defaultValue?: any, expectArray?: E): K extends undefined ? Record<string, E extends true ? UploadedFile[] : UploadedFile> : E extends true ? UploadedFile[] : UploadedFile;
|
|
@@ -1049,4 +1081,4 @@ declare class Response implements IResponse {
|
|
|
1049
1081
|
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
1050
1082
|
}
|
|
1051
1083
|
//#endregion
|
|
1052
|
-
export { ApiResource, BadRequestException, FileBag, FireCommand, FormRequest, HeaderBag, HttpContext, HttpServiceProvider, InputBag, JsonResource, LogRequests, Middleware, ParamBag, Request,
|
|
1084
|
+
export { ApiResource, BadRequestException, FileBag, FireCommand, FormRequest, HeaderBag, HttpContext, HttpServiceProvider, InputBag, JsonResource, LogRequests, Middleware, ParamBag, Request, Resource, Response, ServerBag, SuspiciousOperationException, UnexpectedValueException, UploadedFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
2
|
import { Command } from "@h3ravel/musket";
|
|
3
|
-
import { DotNestedKeys, DotNestedValue, HttpContext
|
|
3
|
+
import { DotNestedKeys, DotNestedValue, HttpContext as HttpContext$1, IApplication, IMiddleware, IParamBag, IRequest, IResponse, RequestMethod, RequestObject } from "@h3ravel/shared";
|
|
4
4
|
import { EventHandlerRequest, H3Event, HTTPResponse } from "h3";
|
|
5
5
|
import { Application } from "@h3ravel/core";
|
|
6
6
|
import { Url } from "@h3ravel/url";
|
|
7
7
|
|
|
8
|
-
//#region src/Contracts/HttpContract.d.ts
|
|
9
|
-
type RequestMethod = 'HEAD' | 'GET' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'PURGE' | 'POST' | 'CONNECT' | 'PATCH';
|
|
10
|
-
type RequestObject = Record<string, any>;
|
|
11
|
-
//#endregion
|
|
12
8
|
//#region src/Bags/ParamBag.d.ts
|
|
13
9
|
/**
|
|
14
10
|
* ParamBag is a container for key/value pairs
|
|
15
11
|
* for Node/H3 environments.
|
|
16
12
|
*/
|
|
17
|
-
declare class ParamBag implements
|
|
13
|
+
declare class ParamBag implements IParamBag {
|
|
18
14
|
protected parameters: RequestObject;
|
|
19
15
|
/**
|
|
20
16
|
* The current H3 H3Event instance
|
|
@@ -515,6 +511,37 @@ declare class FormRequest {
|
|
|
515
511
|
all(): Record<string, any>;
|
|
516
512
|
}
|
|
517
513
|
//#endregion
|
|
514
|
+
//#region src/HttpContext.d.ts
|
|
515
|
+
/**
|
|
516
|
+
* Represents the HTTP context for a single request lifecycle.
|
|
517
|
+
* Encapsulates the application instance, request, and response objects.
|
|
518
|
+
*/
|
|
519
|
+
declare class HttpContext implements HttpContext$1 {
|
|
520
|
+
app: IApplication;
|
|
521
|
+
request: IRequest;
|
|
522
|
+
response: IResponse;
|
|
523
|
+
private static contexts;
|
|
524
|
+
constructor(app: IApplication, request: IRequest, response: IResponse);
|
|
525
|
+
/**
|
|
526
|
+
* Factory method to create a new HttpContext instance from a context object.
|
|
527
|
+
* @param ctx - Object containing app, request, and response
|
|
528
|
+
* @returns A new HttpContext instance
|
|
529
|
+
*/
|
|
530
|
+
static init(ctx: {
|
|
531
|
+
app: IApplication;
|
|
532
|
+
request: IRequest;
|
|
533
|
+
response: IResponse;
|
|
534
|
+
}, event?: unknown): HttpContext;
|
|
535
|
+
/**
|
|
536
|
+
* Retrieve an existing HttpContext instance for an event, if any.
|
|
537
|
+
*/
|
|
538
|
+
static get(event: unknown): HttpContext | undefined;
|
|
539
|
+
/**
|
|
540
|
+
* Delete the cached context for a given event (optional cleanup).
|
|
541
|
+
*/
|
|
542
|
+
static forget(event: unknown): void;
|
|
543
|
+
}
|
|
544
|
+
//#endregion
|
|
518
545
|
//#region src/Middleware.d.ts
|
|
519
546
|
declare abstract class Middleware implements IMiddleware {
|
|
520
547
|
abstract handle(context: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
@@ -524,7 +551,7 @@ declare abstract class Middleware implements IMiddleware {
|
|
|
524
551
|
declare class LogRequests extends Middleware {
|
|
525
552
|
handle({
|
|
526
553
|
request
|
|
527
|
-
}: HttpContext
|
|
554
|
+
}: HttpContext, next: () => Promise<unknown>): Promise<unknown>;
|
|
528
555
|
}
|
|
529
556
|
//#endregion
|
|
530
557
|
//#region src/Providers/HttpServiceProvider.d.ts
|
|
@@ -662,9 +689,14 @@ declare class Request implements IRequest {
|
|
|
662
689
|
/**
|
|
663
690
|
* Retrieve a file from the request.
|
|
664
691
|
*
|
|
692
|
+
* By default a single `UploadedFile` instance will always be returned by
|
|
693
|
+
* the method (first file in property when there are multiple), unless
|
|
694
|
+
* the `expectArray` parameter is set to true, in which case, the method
|
|
695
|
+
* returns an `UploadedFile[]` array.
|
|
696
|
+
*
|
|
665
697
|
* @param key
|
|
666
698
|
* @param defaultValue
|
|
667
|
-
* @param expectArray
|
|
699
|
+
* @param expectArray set to true to return an `UploadedFile[]` array.
|
|
668
700
|
* @returns
|
|
669
701
|
*/
|
|
670
702
|
file<K extends string | undefined = undefined, E extends boolean | undefined = undefined>(key?: K, defaultValue?: any, expectArray?: E): K extends undefined ? Record<string, E extends true ? UploadedFile[] : UploadedFile> : E extends true ? UploadedFile[] : UploadedFile;
|
|
@@ -1049,4 +1081,4 @@ declare class Response implements IResponse {
|
|
|
1049
1081
|
getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
|
|
1050
1082
|
}
|
|
1051
1083
|
//#endregion
|
|
1052
|
-
export { ApiResource, BadRequestException, FileBag, FireCommand, FormRequest, HeaderBag, HttpContext, HttpServiceProvider, InputBag, JsonResource, LogRequests, Middleware, ParamBag, Request,
|
|
1084
|
+
export { ApiResource, BadRequestException, FileBag, FireCommand, FormRequest, HeaderBag, HttpContext, HttpServiceProvider, InputBag, JsonResource, LogRequests, Middleware, ParamBag, Request, Resource, Response, ServerBag, SuspiciousOperationException, UnexpectedValueException, UploadedFile };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { i as __toESM, r as __require, t as __commonJS } from "./chunk-BLWcukCW.
|
|
|
2
2
|
import { writeFile } from "fs/promises";
|
|
3
3
|
import { Arr, Obj, Str, data_get, data_set, safeDot } from "@h3ravel/support";
|
|
4
4
|
import { Command } from "@h3ravel/musket";
|
|
5
|
-
import {
|
|
5
|
+
import { Logger } from "@h3ravel/shared";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
|
|
8
8
|
import { StringDecoder } from "node:string_decoder";
|
|
@@ -19012,6 +19012,44 @@ var FormRequest = class {
|
|
|
19012
19012
|
}
|
|
19013
19013
|
};
|
|
19014
19014
|
|
|
19015
|
+
//#endregion
|
|
19016
|
+
//#region src/HttpContext.ts
|
|
19017
|
+
/**
|
|
19018
|
+
* Represents the HTTP context for a single request lifecycle.
|
|
19019
|
+
* Encapsulates the application instance, request, and response objects.
|
|
19020
|
+
*/
|
|
19021
|
+
var HttpContext = class HttpContext {
|
|
19022
|
+
static contexts = /* @__PURE__ */ new WeakMap();
|
|
19023
|
+
constructor(app, request, response) {
|
|
19024
|
+
this.app = app;
|
|
19025
|
+
this.request = request;
|
|
19026
|
+
this.response = response;
|
|
19027
|
+
}
|
|
19028
|
+
/**
|
|
19029
|
+
* Factory method to create a new HttpContext instance from a context object.
|
|
19030
|
+
* @param ctx - Object containing app, request, and response
|
|
19031
|
+
* @returns A new HttpContext instance
|
|
19032
|
+
*/
|
|
19033
|
+
static init(ctx, event) {
|
|
19034
|
+
if (event && HttpContext.contexts.has(event)) return HttpContext.contexts.get(event);
|
|
19035
|
+
const instance = new HttpContext(ctx.app, ctx.request, ctx.response);
|
|
19036
|
+
if (event) HttpContext.contexts.set(event, instance);
|
|
19037
|
+
return instance;
|
|
19038
|
+
}
|
|
19039
|
+
/**
|
|
19040
|
+
* Retrieve an existing HttpContext instance for an event, if any.
|
|
19041
|
+
*/
|
|
19042
|
+
static get(event) {
|
|
19043
|
+
return HttpContext.contexts.get(event);
|
|
19044
|
+
}
|
|
19045
|
+
/**
|
|
19046
|
+
* Delete the cached context for a given event (optional cleanup).
|
|
19047
|
+
*/
|
|
19048
|
+
static forget(event) {
|
|
19049
|
+
HttpContext.contexts.delete(event);
|
|
19050
|
+
}
|
|
19051
|
+
};
|
|
19052
|
+
|
|
19015
19053
|
//#endregion
|
|
19016
19054
|
//#region src/Middleware.ts
|
|
19017
19055
|
var Middleware = class {};
|
|
@@ -19215,10 +19253,15 @@ var Request = class Request {
|
|
|
19215
19253
|
}
|
|
19216
19254
|
/**
|
|
19217
19255
|
* Retrieve a file from the request.
|
|
19256
|
+
*
|
|
19257
|
+
* By default a single `UploadedFile` instance will always be returned by
|
|
19258
|
+
* the method (first file in property when there are multiple), unless
|
|
19259
|
+
* the `expectArray` parameter is set to true, in which case, the method
|
|
19260
|
+
* returns an `UploadedFile[]` array.
|
|
19218
19261
|
*
|
|
19219
19262
|
* @param key
|
|
19220
19263
|
* @param defaultValue
|
|
19221
|
-
* @param expectArray
|
|
19264
|
+
* @param expectArray set to true to return an `UploadedFile[]` array.
|
|
19222
19265
|
* @returns
|
|
19223
19266
|
*/
|
|
19224
19267
|
file(key, defaultValue, expectArray) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/http",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.6.0",
|
|
4
4
|
"description": "HTTP kernel, middleware pipeline, request/response classes for H3ravel.",
|
|
5
5
|
"h3ravel": {
|
|
6
6
|
"providers": [
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"h3": "2.0.1-rc.5",
|
|
46
46
|
"srvx": "^0.8.2",
|
|
47
47
|
"@h3ravel/support": "^0.14.4",
|
|
48
|
-
"@h3ravel/
|
|
49
|
-
"@h3ravel/
|
|
48
|
+
"@h3ravel/shared": "^0.26.0",
|
|
49
|
+
"@h3ravel/url": "^1.0.8"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@h3ravel/core": "^1.20.0"
|