@h3ravel/core 1.19.2 → 1.21.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_http.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
@@ -1,6 +1,7 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
2
  import { Bindings, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IServiceProvider, PathLoader, UseKey } from "@h3ravel/shared";
3
3
  import { H3, H3Event } from "h3";
4
+ import { HttpContext as HttpContext$1 } from "@h3ravel/http";
4
5
 
5
6
  //#region src/Contracts/ServiceProviderConstructor.d.ts
6
7
  type ServiceProviderConstructor = (new (app: Application) => ServiceProvider) & IServiceProvider;
@@ -108,6 +109,7 @@ declare abstract class ServiceProvider extends Inference {
108
109
  //#region src/Application.d.ts
109
110
  declare class Application extends Container implements IApplication {
110
111
  paths: PathLoader;
112
+ context?: (event: H3Event) => Promise<HttpContext>;
111
113
  private tries;
112
114
  private booted;
113
115
  private basePath;
@@ -316,7 +318,7 @@ config?: EntryConfig,
316
318
  /**
317
319
  * final middleware function to call once the server is fired up
318
320
  */
319
- middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
321
+ middleware?: (ctx: HttpContext$1) => Promise<unknown>) => Promise<Application>;
320
322
  //#endregion
321
323
  //#region src/Http/Kernel.d.ts
322
324
  /**
@@ -324,13 +326,13 @@ middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
324
326
  * It acts as the core middleware pipeline for HTTP requests.
325
327
  */
326
328
  declare class Kernel {
327
- protected context: (event: H3Event) => HttpContext;
329
+ protected context: (event: H3Event) => HttpContext | Promise<HttpContext>;
328
330
  protected middleware: IMiddleware[];
329
331
  /**
330
332
  * @param context - A factory function that converts an H3Event into an HttpContext.
331
333
  * @param middleware - An array of middleware classes that will be executed in sequence.
332
334
  */
333
- constructor(context: (event: H3Event) => HttpContext, middleware?: IMiddleware[]);
335
+ constructor(context: (event: H3Event) => HttpContext | Promise<HttpContext>, middleware?: IMiddleware[]);
334
336
  /**
335
337
  * Handles an incoming request and passes it through middleware before invoking the next handler.
336
338
  *
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
2
  import "reflect-metadata";
3
3
  import { Bindings, HttpContext, IApplication, IContainer, IController, IMiddleware, IPathName, IServiceProvider, PathLoader, UseKey } from "@h3ravel/shared";
4
+ import { HttpContext as HttpContext$1 } from "@h3ravel/http";
4
5
  import { H3, H3Event } from "h3";
5
6
 
6
7
  //#region src/Contracts/ServiceProviderConstructor.d.ts
@@ -109,6 +110,7 @@ declare abstract class ServiceProvider extends Inference {
109
110
  //#region src/Application.d.ts
110
111
  declare class Application extends Container implements IApplication {
111
112
  paths: PathLoader;
113
+ context?: (event: H3Event) => Promise<HttpContext>;
112
114
  private tries;
113
115
  private booted;
114
116
  private basePath;
@@ -317,7 +319,7 @@ config?: EntryConfig,
317
319
  /**
318
320
  * final middleware function to call once the server is fired up
319
321
  */
320
- middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
322
+ middleware?: (ctx: HttpContext$1) => Promise<unknown>) => Promise<Application>;
321
323
  //#endregion
322
324
  //#region src/Http/Kernel.d.ts
323
325
  /**
@@ -325,13 +327,13 @@ middleware?: (ctx: HttpContext) => Promise<unknown>) => Promise<Application>;
325
327
  * It acts as the core middleware pipeline for HTTP requests.
326
328
  */
327
329
  declare class Kernel {
328
- protected context: (event: H3Event) => HttpContext;
330
+ protected context: (event: H3Event) => HttpContext | Promise<HttpContext>;
329
331
  protected middleware: IMiddleware[];
330
332
  /**
331
333
  * @param context - A factory function that converts an H3Event into an HttpContext.
332
334
  * @param middleware - An array of middleware classes that will be executed in sequence.
333
335
  */
334
- constructor(context: (event: H3Event) => HttpContext, middleware?: IMiddleware[]);
336
+ constructor(context: (event: H3Event) => HttpContext | Promise<HttpContext>, middleware?: IMiddleware[]);
335
337
  /**
336
338
  * Handles an incoming request and passes it through middleware before invoking the next handler.
337
339
  *
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { FileSystem, HttpContext, Logger, PathLoader } from "@h3ravel/shared";
2
+ import { FileSystem, Logger, PathLoader } from "@h3ravel/shared";
3
3
  import { InvalidArgumentException, Str, dd, dump, str } from "@h3ravel/support";
4
4
  import fg from "fast-glob";
5
5
  import path from "node:path";
@@ -8,7 +8,7 @@ import dotenv from "dotenv";
8
8
  import dotenvExpand from "dotenv-expand";
9
9
  import { readFile } from "node:fs/promises";
10
10
  import semver from "semver";
11
- import { LogRequests, Request, Response } from "@h3ravel/http";
11
+ import { HttpContext as HttpContext$1, LogRequests, Request, Response } from "@h3ravel/http";
12
12
 
13
13
  //#region src/Container.ts
14
14
  var Container = class {
@@ -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$1.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.2",
3
+ "version": "1.21.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.24.0",
58
- "@h3ravel/support": "^0.14.3"
57
+ "@h3ravel/shared": "^0.27.0",
58
+ "@h3ravel/support": "^0.15.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/semver": "^7.7.1",