@stacksjs/router 0.58.63 → 0.58.65

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.js CHANGED
@@ -213,6 +213,24 @@ function relativeActionsPath(path2) {
213
213
  function userActionsPath(path2) {
214
214
  return appPath(`Actions/${path2 || ""}`);
215
215
  }
216
+ function userJobsPath(path2) {
217
+ return appPath(`Jobs/${path2 || ""}`);
218
+ }
219
+ function userListenersPath(path2) {
220
+ return appPath(`Listeners/${path2 || ""}`);
221
+ }
222
+ function userMiddlewarePath(path2) {
223
+ return appPath(`Middleware/${path2 || ""}`);
224
+ }
225
+ function userModelsPath(path2) {
226
+ return appPath(`Models/${path2 || ""}`);
227
+ }
228
+ function userNotificationsPath(path2) {
229
+ return appPath(`Notifications/${path2 || ""}`);
230
+ }
231
+ function userEventsPath() {
232
+ return appPath(`Events.ts`);
233
+ }
216
234
  function aiPath(path2) {
217
235
  return corePath(`ai/${path2 || ""}`);
218
236
  }
@@ -597,6 +615,12 @@ var path2 = {
597
615
  tinkerPath,
598
616
  typesPath,
599
617
  uiPath,
618
+ userEventsPath,
619
+ userJobsPath,
620
+ userListenersPath,
621
+ userMiddlewarePath,
622
+ userModelsPath,
623
+ userNotificationsPath,
600
624
  utilsPath,
601
625
  validationPath,
602
626
  vitePath,
@@ -673,7 +697,6 @@ async function serve(options = {}) {
673
697
  hostname,
674
698
  port,
675
699
  fetch(req) {
676
- console.log(req);
677
700
  return serverResponse(req);
678
701
  }
679
702
  });
@@ -789,13 +812,28 @@ class Router {
789
812
  });
790
813
  }
791
814
  async get(path5, callback) {
792
- if (typeof callback === "string") {
815
+ if (callback instanceof Promise) {
816
+ const actionModule = await callback;
817
+ callback = actionModule.default;
818
+ } else if (typeof callback === "string") {
793
819
  const actionModule = await import(path2.userActionsPath(`${callback}.ts`));
794
820
  callback = actionModule.default.handle;
795
821
  }
796
822
  this.addRoute("GET", path5, callback, 200);
797
823
  return this;
798
824
  }
825
+ async health() {
826
+ const healthModule = await import(path2.userActionsPath("HealthAction.ts"));
827
+ const callback = healthModule.default.handle;
828
+ this.addRoute("GET", "/api/healthy", callback, 200);
829
+ return this;
830
+ }
831
+ async job(path5) {
832
+ const jobModule = await import(path2.userJobsPath("ExampleJob.ts"));
833
+ const callback = jobModule.default.handle;
834
+ this.addRoute("GET", path5, callback, 200);
835
+ return this;
836
+ }
799
837
  post(path5, callback) {
800
838
  this.addRoute("POST", path5, callback, 201);
801
839
  return this;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/router",
3
3
  "type": "module",
4
- "version": "0.58.63",
4
+ "version": "0.58.65",
5
5
  "description": "The Stacks framework router.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
package/src/router.ts CHANGED
@@ -48,7 +48,11 @@ export class Router implements RouterInterface {
48
48
 
49
49
  public async get(path: Route['url'], callback: Route['callback']): Promise<this> {
50
50
  // check if callback is a string and if it is, then import that module path and use the default.handle function as the callback
51
- if (typeof callback === 'string') {
51
+ if (callback instanceof Promise) {
52
+ const actionModule = await callback
53
+ callback = actionModule.default
54
+ }
55
+ else if (typeof callback === 'string') {
52
56
  // import the module and use the default.handle function as the callback
53
57
  const actionModule = await import(p.userActionsPath(`${callback}.ts`))
54
58
  callback = actionModule.default.handle
@@ -58,6 +62,22 @@ export class Router implements RouterInterface {
58
62
  return this
59
63
  }
60
64
 
65
+ public async health(): Promise<this> {
66
+ const healthModule = await import(p.userActionsPath('HealthAction.ts'))
67
+ const callback = healthModule.default.handle
68
+
69
+ this.addRoute('GET', '/api/healthy', callback, 200)
70
+ return this
71
+ }
72
+
73
+ public async job(path: Route['url']): Promise<this> {
74
+ const jobModule = await import(p.userJobsPath('ExampleJob.ts'))
75
+ const callback = jobModule.default.handle
76
+
77
+ this.addRoute('GET', path, callback, 200)
78
+ return this
79
+ }
80
+
61
81
  public post(path: Route['url'], callback: Route['callback']): this {
62
82
  this.addRoute('POST', path, callback, 201)
63
83
  return this
package/src/server.ts CHANGED
@@ -21,8 +21,6 @@ export async function serve(options: ServeOptions = {}) {
21
21
  port,
22
22
 
23
23
  fetch(req: Request) {
24
- // eslint-disable-next-line no-console
25
- console.log(req)
26
24
  return serverResponse(req)
27
25
  },
28
26
  })