@h3ravel/core 1.19.1 → 1.20.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.
@@ -1,3 +1,5 @@
1
+ import { HTTPResponse } from 'h3'
2
+
1
3
  export { }
2
4
 
3
5
  declare global {
@@ -35,7 +37,7 @@ declare global {
35
37
  * @param viewPath
36
38
  * @param params
37
39
  */
38
- function view (viewPath: string, params?: Record<string, any> | undefined): Promise<string>
40
+ function view (viewPath: string, params?: Record<string, any> | undefined): Promise<HTTPResponse>
39
41
 
40
42
  /**
41
43
  * Get static asset
package/dist/index.cjs CHANGED
@@ -378,6 +378,7 @@ var Registerer = class Registerer {
378
378
  //#region src/Application.ts
379
379
  var Application = class Application extends Container {
380
380
  paths = new __h3ravel_shared.PathLoader();
381
+ context;
381
382
  tries = 0;
382
383
  booted = false;
383
384
  basePath;
@@ -690,11 +691,18 @@ const h3ravel = async (providers = [], basePath = process.cwd(), config = {
690
691
  await app.quickStartup(providers, config.filteredProviders, config.autoload);
691
692
  try {
692
693
  h3App = app.make("http.app");
693
- const kernel = new Kernel((event) => __h3ravel_shared.HttpContext.init({
694
- app,
695
- request: new __h3ravel_http.Request(event, app),
696
- response: new __h3ravel_http.Response(event, app)
697
- }), [new __h3ravel_http.LogRequests()]);
694
+ app.context = async (event) => {
695
+ if (event._h3ravelContext) return event._h3ravelContext;
696
+ __h3ravel_http.Request.enableHttpMethodParameterOverride();
697
+ const ctx = __h3ravel_shared.HttpContext.init({
698
+ app,
699
+ request: await __h3ravel_http.Request.create(event, app),
700
+ response: new __h3ravel_http.Response(event, app)
701
+ });
702
+ event._h3ravelContext = ctx;
703
+ return ctx;
704
+ };
705
+ const kernel = new Kernel(async (event) => app.context(event), [new __h3ravel_http.LogRequests()]);
698
706
  h3App.use((event) => kernel.handle(event, middleware));
699
707
  } catch {
700
708
  if (!h3App && config.h3) h3App = config.h3;
@@ -734,7 +742,7 @@ var Kernel = class {
734
742
  /**
735
743
  * Convert the raw event into a standardized HttpContext
736
744
  */
737
- const ctx = this.context(event);
745
+ const ctx = await this.context(event);
738
746
  const { app } = ctx.request;
739
747
  /**
740
748
  * Bind HTTP Response instance to the service container
package/dist/index.d.cts CHANGED
@@ -108,6 +108,7 @@ declare abstract class ServiceProvider extends Inference {
108
108
  //#region src/Application.d.ts
109
109
  declare class Application extends Container implements IApplication {
110
110
  paths: PathLoader;
111
+ context?: (event: H3Event) => Promise<HttpContext>;
111
112
  private tries;
112
113
  private booted;
113
114
  private basePath;
@@ -324,13 +325,13 @@ middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
324
325
  * It acts as the core middleware pipeline for HTTP requests.
325
326
  */
326
327
  declare class Kernel {
327
- protected context: (event: H3Event) => HttpContext;
328
+ protected context: (event: H3Event) => HttpContext | Promise<HttpContext>;
328
329
  protected middleware: IMiddleware[];
329
330
  /**
330
331
  * @param context - A factory function that converts an H3Event into an HttpContext.
331
332
  * @param middleware - An array of middleware classes that will be executed in sequence.
332
333
  */
333
- constructor(context: (event: H3Event) => HttpContext, middleware?: IMiddleware[]);
334
+ constructor(context: (event: H3Event) => HttpContext | Promise<HttpContext>, middleware?: IMiddleware[]);
334
335
  /**
335
336
  * Handles an incoming request and passes it through middleware before invoking the next handler.
336
337
  *
package/dist/index.d.ts CHANGED
@@ -109,6 +109,7 @@ declare abstract class ServiceProvider extends Inference {
109
109
  //#region src/Application.d.ts
110
110
  declare class Application extends Container implements IApplication {
111
111
  paths: PathLoader;
112
+ context?: (event: H3Event) => Promise<HttpContext>;
112
113
  private tries;
113
114
  private booted;
114
115
  private basePath;
@@ -325,13 +326,13 @@ middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
325
326
  * It acts as the core middleware pipeline for HTTP requests.
326
327
  */
327
328
  declare class Kernel {
328
- protected context: (event: H3Event) => HttpContext;
329
+ protected context: (event: H3Event) => HttpContext | Promise<HttpContext>;
329
330
  protected middleware: IMiddleware[];
330
331
  /**
331
332
  * @param context - A factory function that converts an H3Event into an HttpContext.
332
333
  * @param middleware - An array of middleware classes that will be executed in sequence.
333
334
  */
334
- constructor(context: (event: H3Event) => HttpContext, middleware?: IMiddleware[]);
335
+ constructor(context: (event: H3Event) => HttpContext | Promise<HttpContext>, middleware?: IMiddleware[]);
335
336
  /**
336
337
  * Handles an incoming request and passes it through middleware before invoking the next handler.
337
338
  *
package/dist/index.js CHANGED
@@ -345,6 +345,7 @@ var Registerer = class Registerer {
345
345
  //#region src/Application.ts
346
346
  var Application = class Application extends Container {
347
347
  paths = new PathLoader();
348
+ context;
348
349
  tries = 0;
349
350
  booted = false;
350
351
  basePath;
@@ -657,11 +658,18 @@ const h3ravel = async (providers = [], basePath = process.cwd(), config = {
657
658
  await app.quickStartup(providers, config.filteredProviders, config.autoload);
658
659
  try {
659
660
  h3App = app.make("http.app");
660
- const kernel = new Kernel((event) => HttpContext.init({
661
- app,
662
- request: new Request(event, app),
663
- response: new Response(event, app)
664
- }), [new LogRequests()]);
661
+ app.context = async (event) => {
662
+ if (event._h3ravelContext) return event._h3ravelContext;
663
+ Request.enableHttpMethodParameterOverride();
664
+ const ctx = HttpContext.init({
665
+ app,
666
+ request: await Request.create(event, app),
667
+ response: new Response(event, app)
668
+ });
669
+ event._h3ravelContext = ctx;
670
+ return ctx;
671
+ };
672
+ const kernel = new Kernel(async (event) => app.context(event), [new LogRequests()]);
665
673
  h3App.use((event) => kernel.handle(event, middleware));
666
674
  } catch {
667
675
  if (!h3App && config.h3) h3App = config.h3;
@@ -701,7 +709,7 @@ var Kernel = class {
701
709
  /**
702
710
  * Convert the raw event into a standardized HttpContext
703
711
  */
704
- const ctx = this.context(event);
712
+ const ctx = await this.context(event);
705
713
  const { app } = ctx.request;
706
714
  /**
707
715
  * Bind HTTP Response instance to the service container
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/core",
3
- "version": "1.19.1",
3
+ "version": "1.20.0",
4
4
  "description": "Core application container, lifecycle management and service providers for H3ravel.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -46,16 +46,16 @@
46
46
  "chalk": "^5.6.2",
47
47
  "commander": "^14.0.1",
48
48
  "detect-port": "^2.1.0",
49
- "dotenv": "^17.2.2",
49
+ "dotenv": "^17.2.3",
50
50
  "dotenv-expand": "^12.0.3",
51
51
  "fast-glob": "^3.3.3",
52
- "h3": "2.0.0-beta.4",
52
+ "h3": "2.0.1-rc.5",
53
53
  "reflect-metadata": "^0.2.2",
54
54
  "semver": "^7.7.2",
55
55
  "srvx": "^0.8.7",
56
56
  "tslib": "^2.8.1",
57
- "@h3ravel/shared": "^0.22.3",
58
- "@h3ravel/support": "^0.14.2"
57
+ "@h3ravel/support": "^0.14.4",
58
+ "@h3ravel/shared": "^0.25.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/semver": "^7.7.1",