clear-router 2.8.2 → 2.8.4

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.
Files changed (68) hide show
  1. package/dist/ClearRequest.d.cts +1 -1
  2. package/dist/ClearRequest.d.mts +1 -1
  3. package/dist/Controller.d.cts +1 -1
  4. package/dist/Controller.d.mts +1 -1
  5. package/dist/ResourceRoutes.cjs +12 -0
  6. package/dist/ResourceRoutes.d.cts +13 -19
  7. package/dist/ResourceRoutes.d.mts +13 -19
  8. package/dist/ResourceRoutes.mjs +12 -0
  9. package/dist/{Request-Ci0UQ-Vl.d.mts → Route-tq-rge1g.d.mts} +46 -46
  10. package/dist/Route.d.cts +1 -1
  11. package/dist/Route.d.mts +1 -1
  12. package/dist/RouteGroup.cjs +150 -0
  13. package/dist/RouteGroup.d.cts +73 -0
  14. package/dist/RouteGroup.d.mts +73 -0
  15. package/dist/RouteGroup.mjs +150 -0
  16. package/dist/core/{router.cjs → CoreRouter.cjs} +13 -41
  17. package/dist/core/{router.d.cts → CoreRouter.d.cts} +6 -13
  18. package/dist/core/{router.d.mts → CoreRouter.d.mts} +6 -13
  19. package/dist/core/{router.mjs → CoreRouter.mjs} +13 -41
  20. package/dist/core/Request.d.cts +2 -2
  21. package/dist/core/Request.d.mts +2 -2
  22. package/dist/core/helpers.d.mts +1 -0
  23. package/dist/core/index.cjs +3 -2
  24. package/dist/core/index.d.cts +3 -2
  25. package/dist/core/index.d.mts +3 -2
  26. package/dist/core/index.mjs +3 -2
  27. package/dist/core/plugins.d.cts +1 -1
  28. package/dist/core/plugins.d.mts +1 -1
  29. package/dist/decorators/setup.cjs +2 -2
  30. package/dist/decorators/setup.mjs +1 -1
  31. package/dist/express/router.cjs +4 -4
  32. package/dist/express/router.d.cts +4 -3
  33. package/dist/express/router.d.mts +4 -3
  34. package/dist/express/router.mjs +3 -3
  35. package/dist/fastify/router.cjs +4 -4
  36. package/dist/fastify/router.d.cts +4 -3
  37. package/dist/fastify/router.d.mts +4 -3
  38. package/dist/fastify/router.mjs +3 -3
  39. package/dist/h3/router.cjs +4 -4
  40. package/dist/h3/router.d.cts +4 -3
  41. package/dist/h3/router.d.mts +4 -3
  42. package/dist/h3/router.mjs +3 -3
  43. package/dist/hono/router.cjs +4 -4
  44. package/dist/hono/router.d.cts +4 -3
  45. package/dist/hono/router.d.mts +4 -3
  46. package/dist/hono/router.mjs +3 -3
  47. package/dist/index.cjs +5 -3
  48. package/dist/index.d.cts +4 -3
  49. package/dist/index.d.mts +4 -3
  50. package/dist/index.mjs +4 -3
  51. package/dist/koa/router.cjs +4 -4
  52. package/dist/koa/router.d.cts +4 -3
  53. package/dist/koa/router.d.mts +4 -3
  54. package/dist/koa/router.mjs +3 -3
  55. package/dist/types/basic.d.cts +40 -3
  56. package/dist/types/basic.d.mts +40 -3
  57. package/dist/types/express.d.cts +1 -1
  58. package/dist/types/express.d.mts +1 -1
  59. package/dist/types/fastify.d.cts +1 -1
  60. package/dist/types/fastify.d.mts +1 -1
  61. package/dist/types/h3.d.cts +1 -1
  62. package/dist/types/h3.d.mts +1 -1
  63. package/dist/types/hono.d.cts +1 -1
  64. package/dist/types/hono.d.mts +1 -1
  65. package/dist/types/index.d.mts +1 -1
  66. package/dist/types/koa.d.cts +1 -1
  67. package/dist/types/koa.d.mts +1 -1
  68. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
- import { RequestData } from "./types/basic.cjs";
2
1
  import { Middleware } from "./types/express.cjs";
3
2
  import { Middleware as Middleware$1 } from "./types/fastify.cjs";
4
3
  import { Middleware as Middleware$2 } from "./types/h3.cjs";
5
4
  import { Middleware as Middleware$3 } from "./types/hono.cjs";
6
5
  import { Middleware as Middleware$4 } from "./types/koa.cjs";
7
6
  import { Route } from "./Route.cjs";
7
+ import { RequestData } from "./types/basic.cjs";
8
8
 
9
9
  //#region src/ClearRequest.d.ts
10
10
  declare class ClearRequest<X = any, M = Middleware$2 | Middleware | Middleware$1 | Middleware$3 | Middleware$4> {
@@ -1,10 +1,10 @@
1
- import { RequestData } from "./types/basic.mjs";
2
1
  import { Middleware } from "./types/express.mjs";
3
2
  import { Middleware as Middleware$1 } from "./types/fastify.mjs";
4
3
  import { Middleware as Middleware$2 } from "./types/h3.mjs";
5
4
  import { Middleware as Middleware$3 } from "./types/hono.mjs";
6
5
  import { Middleware as Middleware$4 } from "./types/koa.mjs";
7
6
  import { Route } from "./Route.mjs";
7
+ import { RequestData } from "./types/basic.mjs";
8
8
 
9
9
  //#region src/ClearRequest.d.ts
10
10
  declare class ClearRequest<X = any, M = Middleware$2 | Middleware | Middleware$1 | Middleware$3 | Middleware$4> {
@@ -1,5 +1,5 @@
1
- import { RequestData } from "./types/basic.cjs";
2
1
  import { ClearRequest } from "./ClearRequest.cjs";
2
+ import { RequestData } from "./types/basic.cjs";
3
3
 
4
4
  //#region src/Controller.d.ts
5
5
  declare abstract class Controller<X = any> {
@@ -1,5 +1,5 @@
1
- import { RequestData } from "./types/basic.mjs";
2
1
  import { ClearRequest } from "./ClearRequest.mjs";
2
+ import { RequestData } from "./types/basic.mjs";
3
3
 
4
4
  //#region src/Controller.d.ts
5
5
  declare abstract class Controller<X = any> {
@@ -64,6 +64,10 @@ var ResourceRoutes = class ResourceRoutes {
64
64
  }
65
65
  /**
66
66
  * Only register routes for the provided actions.
67
+ *
68
+ * @param action
69
+ * @param actions
70
+ * @returns
67
71
  */
68
72
  only(action, ...actions) {
69
73
  this.options.only = Array.from(new Set(require_helpers.wrap(action).concat(actions)));
@@ -71,6 +75,10 @@ var ResourceRoutes = class ResourceRoutes {
71
75
  }
72
76
  /**
73
77
  * Register all resource routes except the provided actions.
78
+ *
79
+ * @param action
80
+ * @param actions
81
+ * @returns
74
82
  */
75
83
  except(action, ...actions) {
76
84
  this.options.except = Array.from(new Set(require_helpers.wrap(action).concat(actions)));
@@ -78,6 +86,10 @@ var ResourceRoutes = class ResourceRoutes {
78
86
  }
79
87
  /**
80
88
  * Register one or more middleware that will be executed before the route.
89
+ *
90
+ * @param middlewares
91
+ * @param remember
92
+ * @returns
81
93
  */
82
94
  middleware(middlewares, remember = true) {
83
95
  if (remember) this.chainedMiddlewares.push(middlewares);
@@ -1,28 +1,10 @@
1
- import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "./types/basic.cjs";
2
1
  import { Middleware } from "./types/express.cjs";
3
2
  import { Middleware as Middleware$1 } from "./types/h3.cjs";
4
3
  import { Route } from "./Route.cjs";
4
+ import { ApiResourceMiddleware, HttpMethod, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions } from "./types/basic.cjs";
5
5
  import { ResourceRouteSelection } from "./ResourceRouteSelection.cjs";
6
6
 
7
7
  //#region src/ResourceRoutes.d.ts
8
- type ResourceRouteDefinition = {
9
- method: HttpMethod;
10
- path: string;
11
- };
12
- type ResourceRouteRegistrar<X, M, H> = (input: {
13
- action: ResourceAction;
14
- method: HttpMethod;
15
- path: string;
16
- handler: any;
17
- middlewares?: M[];
18
- name: string;
19
- }) => Route<X, M, H>;
20
- type ResourceRouteRemover<X, M, H> = (route: Route<X, M, H>) => void;
21
- type ResourceRoutesOptions<M = any> = {
22
- only?: ResourceAction[];
23
- except?: ResourceAction[];
24
- middlewares?: ApiResourceMiddleware<M>;
25
- };
26
8
  /**
27
9
  * @class clear-router ResourceRoutes
28
10
  * @description A ResourceRoutes creates a collection of resourceful routes in a single call
@@ -64,14 +46,26 @@ declare class ResourceRoutes<X = any, M = Middleware$1 | Middleware, H = any> {
64
46
  register(): this;
65
47
  /**
66
48
  * Only register routes for the provided actions.
49
+ *
50
+ * @param action
51
+ * @param actions
52
+ * @returns
67
53
  */
68
54
  only(action: ResourceAction | ResourceAction[], ...actions: ResourceAction[]): this;
69
55
  /**
70
56
  * Register all resource routes except the provided actions.
57
+ *
58
+ * @param action
59
+ * @param actions
60
+ * @returns
71
61
  */
72
62
  except(action: ResourceAction | ResourceAction[], ...actions: ResourceAction[]): this;
73
63
  /**
74
64
  * Register one or more middleware that will be executed before the route.
65
+ *
66
+ * @param middlewares
67
+ * @param remember
68
+ * @returns
75
69
  */
76
70
  middleware(middlewares: M[] | M, remember?: boolean): this;
77
71
  action(action: ResourceAction): Route<X, M, H> | undefined;
@@ -1,28 +1,10 @@
1
- import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "./types/basic.mjs";
2
1
  import { Middleware } from "./types/express.mjs";
3
2
  import { Middleware as Middleware$1 } from "./types/h3.mjs";
4
3
  import { Route } from "./Route.mjs";
4
+ import { ApiResourceMiddleware, HttpMethod, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions } from "./types/basic.mjs";
5
5
  import { ResourceRouteSelection } from "./ResourceRouteSelection.mjs";
6
6
 
7
7
  //#region src/ResourceRoutes.d.ts
8
- type ResourceRouteDefinition = {
9
- method: HttpMethod;
10
- path: string;
11
- };
12
- type ResourceRouteRegistrar<X, M, H> = (input: {
13
- action: ResourceAction;
14
- method: HttpMethod;
15
- path: string;
16
- handler: any;
17
- middlewares?: M[];
18
- name: string;
19
- }) => Route<X, M, H>;
20
- type ResourceRouteRemover<X, M, H> = (route: Route<X, M, H>) => void;
21
- type ResourceRoutesOptions<M = any> = {
22
- only?: ResourceAction[];
23
- except?: ResourceAction[];
24
- middlewares?: ApiResourceMiddleware<M>;
25
- };
26
8
  /**
27
9
  * @class clear-router ResourceRoutes
28
10
  * @description A ResourceRoutes creates a collection of resourceful routes in a single call
@@ -64,14 +46,26 @@ declare class ResourceRoutes<X = any, M = Middleware$1 | Middleware, H = any> {
64
46
  register(): this;
65
47
  /**
66
48
  * Only register routes for the provided actions.
49
+ *
50
+ * @param action
51
+ * @param actions
52
+ * @returns
67
53
  */
68
54
  only(action: ResourceAction | ResourceAction[], ...actions: ResourceAction[]): this;
69
55
  /**
70
56
  * Register all resource routes except the provided actions.
57
+ *
58
+ * @param action
59
+ * @param actions
60
+ * @returns
71
61
  */
72
62
  except(action: ResourceAction | ResourceAction[], ...actions: ResourceAction[]): this;
73
63
  /**
74
64
  * Register one or more middleware that will be executed before the route.
65
+ *
66
+ * @param middlewares
67
+ * @param remember
68
+ * @returns
75
69
  */
76
70
  middleware(middlewares: M[] | M, remember?: boolean): this;
77
71
  action(action: ResourceAction): Route<X, M, H> | undefined;
@@ -64,6 +64,10 @@ var ResourceRoutes = class ResourceRoutes {
64
64
  }
65
65
  /**
66
66
  * Only register routes for the provided actions.
67
+ *
68
+ * @param action
69
+ * @param actions
70
+ * @returns
67
71
  */
68
72
  only(action, ...actions) {
69
73
  this.options.only = Array.from(new Set(wrap(action).concat(actions)));
@@ -71,6 +75,10 @@ var ResourceRoutes = class ResourceRoutes {
71
75
  }
72
76
  /**
73
77
  * Register all resource routes except the provided actions.
78
+ *
79
+ * @param action
80
+ * @param actions
81
+ * @returns
74
82
  */
75
83
  except(action, ...actions) {
76
84
  this.options.except = Array.from(new Set(wrap(action).concat(actions)));
@@ -78,6 +86,10 @@ var ResourceRoutes = class ResourceRoutes {
78
86
  }
79
87
  /**
80
88
  * Register one or more middleware that will be executed before the route.
89
+ *
90
+ * @param middlewares
91
+ * @param remember
92
+ * @returns
81
93
  */
82
94
  middleware(middlewares, remember = true) {
83
95
  if (remember) this.chainedMiddlewares.push(middlewares);
@@ -1,9 +1,9 @@
1
+ import { Middleware } from "./types/express.mjs";
2
+ import { Middleware as Middleware$1 } from "./types/fastify.mjs";
3
+ import { Middleware as Middleware$2 } from "./types/h3.mjs";
4
+ import { Middleware as Middleware$3 } from "./types/hono.mjs";
5
+ import { Middleware as Middleware$4 } from "./types/koa.mjs";
1
6
  import { HttpMethod, RequestData } from "./types/basic.mjs";
2
- import { Middleware } from "./types/fastify.mjs";
3
- import { Middleware as Middleware$1 } from "./types/h3.mjs";
4
- import { Middleware as Middleware$2 } from "./types/hono.mjs";
5
- import { Middleware as Middleware$3 } from "./types/koa.mjs";
6
- import { Middleware as Middleware$4 } from "./types/express.mjs";
7
7
 
8
8
  //#region src/Contracts.d.ts
9
9
  /**
@@ -16,6 +16,26 @@ interface RouteParameter {
16
16
  optional: boolean;
17
17
  }
18
18
  //#endregion
19
+ //#region src/core/Request.d.ts
20
+ declare class Request<X = any, M = any> extends ClearRequest<X, M> {
21
+ original?: any;
22
+ method: string;
23
+ path: string;
24
+ url: string;
25
+ headers: Headers | Record<string, any>;
26
+ constructor(init?: Partial<Request<X, M>> & {
27
+ body?: RequestData;
28
+ query?: RequestData;
29
+ params?: RequestData;
30
+ route?: Route<X, M>;
31
+ });
32
+ getBody(): RequestData;
33
+ header(name: string): string;
34
+ param(name: string): any;
35
+ input(name: string): any;
36
+ is(method: HttpMethod | string): boolean;
37
+ }
38
+ //#endregion
19
39
  //#region src/core/Response.d.ts
20
40
  declare class Response {
21
41
  [key: string]: any;
@@ -39,6 +59,25 @@ declare class Response {
39
59
  noContent(): this;
40
60
  }
41
61
  //#endregion
62
+ //#region src/ClearRequest.d.ts
63
+ declare class ClearRequest<X = any, M = Middleware$2 | Middleware | Middleware$1 | Middleware$3 | Middleware$4> {
64
+ [key: string]: any;
65
+ /**
66
+ * @param body - Parsed request body
67
+ */
68
+ body: RequestData;
69
+ /**
70
+ * @param query - Parsed query parameters
71
+ */
72
+ query: RequestData;
73
+ /**
74
+ * @param params - Parsed route parameters
75
+ */
76
+ params: RequestData;
77
+ route: Route<X, M>;
78
+ constructor(init?: Partial<ClearRequest>);
79
+ }
80
+ //#endregion
42
81
  //#region src/Route.d.ts
43
82
  /**
44
83
  * @class clear-router Route
@@ -46,7 +85,7 @@ declare class Response {
46
85
  * @author 3m1n3nc3
47
86
  * @repository https://github.com/arkstack-tmp/clear-router
48
87
  */
49
- declare class Route<X = any, M = Middleware$1 | Middleware$4, H = any> {
88
+ declare class Route<X = any, M = Middleware$2 | Middleware, H = any> {
50
89
  ctx: X;
51
90
  body: RequestData;
52
91
  query: RequestData;
@@ -94,43 +133,4 @@ declare class Route<X = any, M = Middleware$1 | Middleware$4, H = any> {
94
133
  toPath(params?: RequestData): string;
95
134
  }
96
135
  //#endregion
97
- //#region src/ClearRequest.d.ts
98
- declare class ClearRequest<X = any, M = Middleware$1 | Middleware$4 | Middleware | Middleware$2 | Middleware$3> {
99
- [key: string]: any;
100
- /**
101
- * @param body - Parsed request body
102
- */
103
- body: RequestData;
104
- /**
105
- * @param query - Parsed query parameters
106
- */
107
- query: RequestData;
108
- /**
109
- * @param params - Parsed route parameters
110
- */
111
- params: RequestData;
112
- route: Route<X, M>;
113
- constructor(init?: Partial<ClearRequest>);
114
- }
115
- //#endregion
116
- //#region src/core/Request.d.ts
117
- declare class Request<X = any, M = any> extends ClearRequest<X, M> {
118
- original?: any;
119
- method: string;
120
- path: string;
121
- url: string;
122
- headers: Headers | Record<string, any>;
123
- constructor(init?: Partial<Request<X, M>> & {
124
- body?: RequestData;
125
- query?: RequestData;
126
- params?: RequestData;
127
- route?: Route<X, M>;
128
- });
129
- getBody(): RequestData;
130
- header(name: string): string;
131
- param(name: string): any;
132
- input(name: string): any;
133
- is(method: HttpMethod | string): boolean;
134
- }
135
- //#endregion
136
- export { Response as n, ClearHttpContext as r, Request as t };
136
+ export { ClearHttpContext as i, Response as n, Request as r, Route as t };
package/dist/Route.d.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { HttpMethod, RequestData } from "./types/basic.cjs";
2
1
  import { RouteParameter } from "./Contracts.cjs";
3
2
  import { Middleware } from "./types/express.cjs";
4
3
  import { Middleware as Middleware$1 } from "./types/h3.cjs";
5
4
  import { ClearRequest } from "./ClearRequest.cjs";
5
+ import { HttpMethod, RequestData } from "./types/basic.cjs";
6
6
 
7
7
  //#region src/Route.d.ts
8
8
  /**
package/dist/Route.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { HttpMethod, RequestData } from "./types/basic.mjs";
2
1
  import { RouteParameter } from "./Contracts.mjs";
3
2
  import { Middleware } from "./types/express.mjs";
4
3
  import { Middleware as Middleware$1 } from "./types/h3.mjs";
5
4
  import { ClearRequest } from "./ClearRequest.mjs";
5
+ import { HttpMethod, RequestData } from "./types/basic.mjs";
6
6
 
7
7
  //#region src/Route.d.ts
8
8
  /**
@@ -0,0 +1,150 @@
1
+ const require_helpers = require('./core/helpers.cjs');
2
+ let node_path = require("node:path");
3
+ let node_fs_promises = require("node:fs/promises");
4
+
5
+ //#region src/RouteGroup.ts
6
+ /**
7
+ * @class clear-router RouteGroup
8
+ * @description A route group describes a collection of routes on clear-router
9
+ * @author 3m1n3nc3
10
+ * @repository https://github.com/arkstack-tmp/clear-router
11
+ */
12
+ var RouteGroup = class {
13
+ checks = [];
14
+ conditions = [];
15
+ registration;
16
+ routes = /* @__PURE__ */ new Set();
17
+ unfilteredSources = /* @__PURE__ */ new Set();
18
+ constructor(options) {
19
+ this.options = options;
20
+ this.registration = this.register();
21
+ }
22
+ /**
23
+ * Returning a falsy value will stop route group registration
24
+ *
25
+ * @param condition
26
+ * @returns
27
+ */
28
+ when(condition) {
29
+ this.conditions.push(condition);
30
+ const unfilteredSources = Array.from(this.unfilteredSources);
31
+ if (unfilteredSources.length) this.checks.push(this.registration.then(async () => {
32
+ for (const source of unfilteredSources) if (!await condition(source)) {
33
+ this.rollback();
34
+ break;
35
+ }
36
+ }));
37
+ return this;
38
+ }
39
+ /**
40
+ * Register one or more middleware that will be executed before every route in the group.
41
+ *
42
+ * @param middlewares
43
+ * @returns
44
+ */
45
+ middleware(middlewares) {
46
+ this.checks.push(this.registration.then(() => {
47
+ for (const route of this.routes) route.middleware(middlewares);
48
+ }));
49
+ return this;
50
+ }
51
+ /**
52
+ * Attaches callbacks for the resolution and/or rejection of the RouteGroup.
53
+ *
54
+ * @param onfulfilled
55
+ * @param onrejected
56
+ * @returns
57
+ */
58
+ then(onfulfilled, onrejected) {
59
+ return Promise.all([this.registration, ...this.checks]).then(() => void 0).then(onfulfilled, onrejected);
60
+ }
61
+ /**
62
+ * Register the routes
63
+ */
64
+ async register() {
65
+ const current = this.options.context.getStore();
66
+ const previousPrefix = current?.prefix ?? this.options.defaultPrefix;
67
+ const previousMiddlewares = current?.groupMiddlewares ?? this.options.defaultMiddlewares;
68
+ const fullPrefix = [previousPrefix, this.options.prefix].filter(Boolean).join("/");
69
+ const nextContext = {
70
+ prefix: this.options.normalizePath(fullPrefix),
71
+ groupMiddlewares: [...previousMiddlewares, ...this.options.middlewares || []],
72
+ routeCollectors: [...current?.routeCollectors ?? [], this.routes]
73
+ };
74
+ await this.options.context.run(nextContext, async () => {
75
+ for (const entry of Array.isArray(this.options.source) ? this.options.source : [this.options.source]) {
76
+ if (typeof entry === "function") {
77
+ if (!this.conditions.length) this.unfilteredSources.add(entry);
78
+ else if (!await this.accepts(entry)) continue;
79
+ await Promise.resolve(entry());
80
+ continue;
81
+ }
82
+ const resolved = await this.resolveFiles(entry);
83
+ if (!resolved.directory && !await this.accepts(entry)) continue;
84
+ for (const file of resolved.files) {
85
+ if (resolved.directory && !await this.accepts(file)) continue;
86
+ await require_helpers.importFile(file);
87
+ }
88
+ }
89
+ });
90
+ }
91
+ /**
92
+ * Rollback the route registration
93
+ */
94
+ rollback() {
95
+ for (const route of this.routes) this.options.removeRoute(route);
96
+ }
97
+ /**
98
+ * Check whether a callback or path should be registered.
99
+ *
100
+ * @param source
101
+ * @returns
102
+ */
103
+ async accepts(source) {
104
+ for (const condition of this.conditions) if (!await condition(source)) return false;
105
+ return true;
106
+ }
107
+ /**
108
+ * Resolve files from the group path
109
+ *
110
+ * @param source
111
+ * @returns
112
+ */
113
+ async resolveFiles(source) {
114
+ const resolved = (0, node_path.isAbsolute)(source) ? source : (0, node_path.resolve)(process.cwd(), source);
115
+ let sourceStat;
116
+ try {
117
+ sourceStat = await (0, node_fs_promises.stat)(resolved);
118
+ } catch {
119
+ throw new Error(`Route group source not found: ${source}`);
120
+ }
121
+ if (sourceStat.isFile()) return {
122
+ directory: false,
123
+ files: [resolved]
124
+ };
125
+ if (!sourceStat.isDirectory()) throw new Error(`Route group source must be a file or directory: ${source}`);
126
+ return {
127
+ directory: true,
128
+ files: await this.readDirectory(resolved)
129
+ };
130
+ }
131
+ /**
132
+ * Read all the files in the configured directory
133
+ *
134
+ * @param directory
135
+ * @returns
136
+ */
137
+ async readDirectory(directory) {
138
+ const entries = await (0, node_fs_promises.readdir)(directory, { withFileTypes: true });
139
+ const files = [];
140
+ for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
141
+ const path = (0, node_path.join)(directory, entry.name);
142
+ if (entry.isDirectory()) files.push(...await this.readDirectory(path));
143
+ else if (entry.isFile() && /\.(?:[cm]?ts)$/.test(entry.name) && !entry.name.endsWith(".d.ts")) files.push(path);
144
+ }
145
+ return files;
146
+ }
147
+ };
148
+
149
+ //#endregion
150
+ exports.RouteGroup = RouteGroup;
@@ -0,0 +1,73 @@
1
+ import { Middleware } from "./types/express.cjs";
2
+ import { Middleware as Middleware$1 } from "./types/h3.cjs";
3
+ import { RouteGroupCondition, RouteGroupOptions } from "./types/basic.cjs";
4
+
5
+ //#region src/RouteGroup.d.ts
6
+ /**
7
+ * @class clear-router RouteGroup
8
+ * @description A route group describes a collection of routes on clear-router
9
+ * @author 3m1n3nc3
10
+ * @repository https://github.com/arkstack-tmp/clear-router
11
+ */
12
+ declare class RouteGroup<X = any, M = Middleware$1 | Middleware, H = any> implements PromiseLike<void> {
13
+ private readonly options;
14
+ private readonly checks;
15
+ private readonly conditions;
16
+ private readonly registration;
17
+ private readonly routes;
18
+ private readonly unfilteredSources;
19
+ constructor(options: RouteGroupOptions);
20
+ /**
21
+ * Returning a falsy value will stop route group registration
22
+ *
23
+ * @param condition
24
+ * @returns
25
+ */
26
+ when(condition: RouteGroupCondition): this;
27
+ /**
28
+ * Register one or more middleware that will be executed before every route in the group.
29
+ *
30
+ * @param middlewares
31
+ * @returns
32
+ */
33
+ middleware(middlewares: M[] | M): this;
34
+ /**
35
+ * Attaches callbacks for the resolution and/or rejection of the RouteGroup.
36
+ *
37
+ * @param onfulfilled
38
+ * @param onrejected
39
+ * @returns
40
+ */
41
+ then<TResult1 = void, TResult2 = never>(onfulfilled?: ((value: void) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
42
+ /**
43
+ * Register the routes
44
+ */
45
+ private register;
46
+ /**
47
+ * Rollback the route registration
48
+ */
49
+ private rollback;
50
+ /**
51
+ * Check whether a callback or path should be registered.
52
+ *
53
+ * @param source
54
+ * @returns
55
+ */
56
+ private accepts;
57
+ /**
58
+ * Resolve files from the group path
59
+ *
60
+ * @param source
61
+ * @returns
62
+ */
63
+ private resolveFiles;
64
+ /**
65
+ * Read all the files in the configured directory
66
+ *
67
+ * @param directory
68
+ * @returns
69
+ */
70
+ private readDirectory;
71
+ }
72
+ //#endregion
73
+ export { RouteGroup };
@@ -0,0 +1,73 @@
1
+ import { Middleware } from "./types/express.mjs";
2
+ import { Middleware as Middleware$1 } from "./types/h3.mjs";
3
+ import { RouteGroupCondition, RouteGroupOptions } from "./types/basic.mjs";
4
+
5
+ //#region src/RouteGroup.d.ts
6
+ /**
7
+ * @class clear-router RouteGroup
8
+ * @description A route group describes a collection of routes on clear-router
9
+ * @author 3m1n3nc3
10
+ * @repository https://github.com/arkstack-tmp/clear-router
11
+ */
12
+ declare class RouteGroup<X = any, M = Middleware$1 | Middleware, H = any> implements PromiseLike<void> {
13
+ private readonly options;
14
+ private readonly checks;
15
+ private readonly conditions;
16
+ private readonly registration;
17
+ private readonly routes;
18
+ private readonly unfilteredSources;
19
+ constructor(options: RouteGroupOptions);
20
+ /**
21
+ * Returning a falsy value will stop route group registration
22
+ *
23
+ * @param condition
24
+ * @returns
25
+ */
26
+ when(condition: RouteGroupCondition): this;
27
+ /**
28
+ * Register one or more middleware that will be executed before every route in the group.
29
+ *
30
+ * @param middlewares
31
+ * @returns
32
+ */
33
+ middleware(middlewares: M[] | M): this;
34
+ /**
35
+ * Attaches callbacks for the resolution and/or rejection of the RouteGroup.
36
+ *
37
+ * @param onfulfilled
38
+ * @param onrejected
39
+ * @returns
40
+ */
41
+ then<TResult1 = void, TResult2 = never>(onfulfilled?: ((value: void) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
42
+ /**
43
+ * Register the routes
44
+ */
45
+ private register;
46
+ /**
47
+ * Rollback the route registration
48
+ */
49
+ private rollback;
50
+ /**
51
+ * Check whether a callback or path should be registered.
52
+ *
53
+ * @param source
54
+ * @returns
55
+ */
56
+ private accepts;
57
+ /**
58
+ * Resolve files from the group path
59
+ *
60
+ * @param source
61
+ * @returns
62
+ */
63
+ private resolveFiles;
64
+ /**
65
+ * Read all the files in the configured directory
66
+ *
67
+ * @param directory
68
+ * @returns
69
+ */
70
+ private readDirectory;
71
+ }
72
+ //#endregion
73
+ export { RouteGroup };