@h3ravel/router 1.29.0-alpha.16 → 2.0.0-alpha.16

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.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
- import { ActionInput, CallableConstructor, ClassConstructor, ConcreteConstructor, GenericObject, IAbstractRouteCollection, IApplication, ICallableDispatcher, IContainer, IController, IControllerDispatcher, IDispatcher, IHttpContext, IMiddleware, IRequest, IResponse, IRoute, IRouteCollection, IRouteUrlGenerator, IRouter, IUrlGenerator, MiddlewareIdentifier, MiddlewareList, ResourceMethod, ResourceOptions, ResponsableType, RouteActions, RouteMethod, RouteParams, UrlRoutable } from "@h3ravel/contracts";
3
- import { Middleware, Request, Response } from "@h3ravel/http";
4
- import { H3, Middleware as Middleware$1, MiddlewareOptions } from "h3";
5
2
  import { Collection, ServiceProvider } from "@h3ravel/support";
3
+ import { ActionInput, CallableConstructor, ClassConstructor, ConcreteConstructor, GenericObject, IAbstractRouteCollection, IApplication, ICallableDispatcher, IContainer, IController, IControllerDispatcher, IDispatcher, IHttpContext, IMiddleware, IRequest, IResponse, IRoute, IRouteCollection, IRouteUrlGenerator, IRouter, IUrlGenerator, MiddlewareIdentifier, MiddlewareList, ResourceMethod, ResourceOptions, ResponsableType, RouteActions, RouteMethod, RouteParams, UrlRoutable } from "@h3ravel/contracts";
6
4
  import { Magic } from "@h3ravel/shared";
7
5
  import { Command } from "@h3ravel/musket";
6
+ import { Middleware, Request, Response } from "@h3ravel/http";
7
+ import { H3, Middleware as Middleware$1, MiddlewareOptions } from "h3";
8
8
  import { Model } from "@h3ravel/database";
9
9
 
10
10
  //#region src/RouteParameter.d.ts
@@ -121,7 +121,7 @@ declare class RouteDependencyResolver {
121
121
  }
122
122
  //#endregion
123
123
  //#region src/ControllerDispatcher.d.ts
124
- declare const ControllerDispatcher_base: typeof RouteDependencyResolver & typeof IControllerDispatcher & typeof FiltersControllerMiddleware & (new (...args: any[]) => RouteDependencyResolver & IControllerDispatcher & FiltersControllerMiddleware);
124
+ declare const ControllerDispatcher_base: typeof IControllerDispatcher & typeof RouteDependencyResolver & typeof FiltersControllerMiddleware & (new (...args: any[]) => IControllerDispatcher & RouteDependencyResolver & FiltersControllerMiddleware);
125
125
  declare class ControllerDispatcher extends ControllerDispatcher_base {
126
126
  protected container: IApplication;
127
127
  /**
@@ -896,6 +896,7 @@ declare class Router extends Router_base {
896
896
  * The route group attribute stack.
897
897
  */
898
898
  protected groupStack: GenericObject<any>[];
899
+ protected routeLoading: Promise<void>;
899
900
  /**
900
901
  * The event dispatcher instance.
901
902
  */
@@ -1220,6 +1221,10 @@ declare class Router extends Router_base {
1220
1221
  * @param routes
1221
1222
  */
1222
1223
  group<C extends ((_e: this) => void) | string>(attributes: RouteActions, routes: C | C[]): this;
1224
+ /**
1225
+ * Wait for route files queued by route groups to finish loading.
1226
+ */
1227
+ routesLoaded(): Promise<void>;
1223
1228
  /**
1224
1229
  * Update the group stack with the given attributes.
1225
1230
  *
@@ -1681,7 +1686,7 @@ declare class Route extends IRoute {
1681
1686
  *
1682
1687
  * @return array
1683
1688
  */
1684
- static getValidators(): IRouteValidator[] | (UriValidator | HostValidator | MethodValidator | SchemeValidator)[];
1689
+ static getValidators(): IRouteValidator[] | (MethodValidator | UriValidator | HostValidator | SchemeValidator)[];
1685
1690
  /**
1686
1691
  * Run the route action and return the response.
1687
1692
  *
@@ -1766,7 +1771,7 @@ declare abstract class AbstractRouteCollection implements IAbstractRouteCollecti
1766
1771
  }
1767
1772
  //#endregion
1768
1773
  //#region src/CallableDispatcher.d.ts
1769
- declare const CallableDispatcher_base: typeof ICallableDispatcher & typeof RouteDependencyResolver & (new (...args: any[]) => ICallableDispatcher & RouteDependencyResolver);
1774
+ declare const CallableDispatcher_base: typeof RouteDependencyResolver & typeof ICallableDispatcher & (new (...args: any[]) => RouteDependencyResolver & ICallableDispatcher);
1770
1775
  declare class CallableDispatcher extends CallableDispatcher_base {
1771
1776
  protected container: IApplication;
1772
1777
  /**
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import { Arr, Collection, Macroable, MacroableClass, Obj, RuntimeException, Serv
2
2
  import { Injectable, LogicException, ModelNotFoundException, NotFoundHttpException, RouteNotFoundException, UrlGenerationException } from "@h3ravel/foundation";
3
3
  import { IApplication, ICallableDispatcher, IControllerDispatcher, IResponsable, IResponse, IRoute, IRouteUrlGenerator, IRouter, IUrlGenerator, UrlRoutable } from "@h3ravel/contracts";
4
4
  import "reflect-metadata";
5
- import { Finalizable, Logger, Magic, UseMagic, internal, mix, trait, use } from "@h3ravel/shared";
5
+ import { Finalizable, Logger, Magic, UseMagic, importFile, internal, mix, trait, use } from "@h3ravel/shared";
6
6
  import { Command } from "@h3ravel/musket";
7
7
  import { JsonResponse, Middleware, Request, Response, UnexpectedValueException } from "@h3ravel/http";
8
- import { createRequire } from "module";
8
+ import * as facadeModule from "@h3ravel/support/facades";
9
9
  import { existsSync } from "node:fs";
10
10
  import crypto from "crypto";
11
11
  //#region src/AbstractRouteCollection.ts
@@ -3047,6 +3047,7 @@ var Router = class Router extends mix(IRouter, MacroableClass, Magic) {
3047
3047
  * The route group attribute stack.
3048
3048
  */
3049
3049
  groupStack = [];
3050
+ routeLoading = Promise.resolve();
3050
3051
  /**
3051
3052
  * The event dispatcher instance.
3052
3053
  */
@@ -3537,13 +3538,33 @@ var Router = class Router extends mix(IRouter, MacroableClass, Magic) {
3537
3538
  */
3538
3539
  group(attributes, routes) {
3539
3540
  for (const groupRoutes of Arr.wrap(routes)) {
3540
- this.updateGroupStack(attributes);
3541
- this.loadRoutes(groupRoutes);
3542
- this.groupStack.pop();
3541
+ if (typeof groupRoutes === "function") {
3542
+ this.updateGroupStack(attributes);
3543
+ this.loadRoutes(groupRoutes);
3544
+ this.groupStack.pop();
3545
+ continue;
3546
+ }
3547
+ const parentStack = [...this.groupStack];
3548
+ this.routeLoading = this.routeLoading.then(async () => {
3549
+ const previousStack = this.groupStack;
3550
+ this.groupStack = [...parentStack];
3551
+ this.updateGroupStack(attributes);
3552
+ try {
3553
+ await this.loadRoutes(groupRoutes);
3554
+ } finally {
3555
+ this.groupStack = previousStack;
3556
+ }
3557
+ });
3543
3558
  }
3544
3559
  return this;
3545
3560
  }
3546
3561
  /**
3562
+ * Wait for route files queued by route groups to finish loading.
3563
+ */
3564
+ async routesLoaded() {
3565
+ await this.routeLoading;
3566
+ }
3567
+ /**
3547
3568
  * Update the group stack with the given attributes.
3548
3569
  *
3549
3570
  * @param attributes
@@ -3567,9 +3588,12 @@ var Router = class Router extends mix(IRouter, MacroableClass, Magic) {
3567
3588
  * @param routes
3568
3589
  */
3569
3590
  async loadRoutes(routes) {
3570
- const require = createRequire(import.meta.url);
3571
- if (typeof routes === "function") routes(this);
3572
- else if (existsSync(this.app.paths.distPath(routes))) require(this.app.paths.distPath(routes));
3591
+ if (typeof routes === "function") {
3592
+ routes(this);
3593
+ return;
3594
+ }
3595
+ const sourcePath = this.app.paths.distPath(routes);
3596
+ if (existsSync(sourcePath)) await importFile(sourcePath, { virtualModules: { "@h3ravel/support/facades": facadeModule } });
3573
3597
  }
3574
3598
  /**
3575
3599
  * Get the prefix from the last group on the stack.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/router",
3
- "version": "1.29.0-alpha.16",
3
+ "version": "2.0.0-alpha.16",
4
4
  "description": "Route facade, decorators and controller system for H3ravel.",
5
5
  "h3ravel": {
6
6
  "providers": [
@@ -8,9 +8,7 @@
8
8
  ]
9
9
  },
10
10
  "type": "module",
11
- "main": "./dist/index.cjs",
12
11
  "types": "./dist/index.d.ts",
13
- "module": "./dist/index.js",
14
12
  "exports": {
15
13
  ".": {
16
14
  "import": "./dist/index.js",
@@ -41,22 +39,22 @@
41
39
  "laravel"
42
40
  ],
43
41
  "peerDependencies": {
44
- "@h3ravel/database": "^11.15.0-alpha.16"
42
+ "@h3ravel/database": "^11.17.0-alpha.16"
45
43
  },
46
44
  "dependencies": {
47
45
  "h3": "2.0.1-rc.5",
48
- "@h3ravel/contracts": "^1.29.0-alpha.16",
49
- "@h3ravel/events": "^1.29.0-alpha.16",
46
+ "@h3ravel/contracts": "^2.0.0-alpha.16",
47
+ "@h3ravel/events": "^2.0.0-alpha.16",
50
48
  "@h3ravel/musket": "^1.29.0-alpha.15",
51
- "@h3ravel/http": "^11.15.0-alpha.16",
52
- "@h3ravel/shared": "^1.29.0-alpha.16",
53
- "@h3ravel/support": "^1.29.0-alpha.16",
54
- "@h3ravel/foundation": "^1.29.0-alpha.16",
49
+ "@h3ravel/http": "^11.17.0-alpha.16",
50
+ "@h3ravel/shared": "^2.0.0-alpha.16",
51
+ "@h3ravel/support": "^2.0.0-alpha.16",
52
+ "@h3ravel/foundation": "^2.0.0-alpha.16",
55
53
  "reflect-metadata": "^0.2.2"
56
54
  },
57
55
  "scripts": {
58
56
  "build": "tsdown --config-loader unrun",
59
- "dev": "tsx watch src/index.ts",
57
+ "dev": "tsdown --watch --config-loader unrun",
60
58
  "start": "node dist/index.js",
61
59
  "lint": "eslint . --ext .ts",
62
60
  "test": "jest --passWithNoTests",