@stacksjs/router 0.58.62 → 0.58.64

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
@@ -210,6 +210,27 @@ function actionsPath(path2) {
210
210
  function relativeActionsPath(path2) {
211
211
  return relative(projectPath(), actionsPath(path2));
212
212
  }
213
+ function userActionsPath(path2) {
214
+ return appPath(`Actions/${path2 || ""}`);
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
+ }
213
234
  function aiPath(path2) {
214
235
  return corePath(`ai/${path2 || ""}`);
215
236
  }
@@ -504,6 +525,7 @@ function xRayPath(path2) {
504
525
  }
505
526
  var path2 = {
506
527
  actionsPath,
528
+ userActionsPath,
507
529
  aiPath,
508
530
  assetsPath,
509
531
  relativeActionsPath,
@@ -593,6 +615,12 @@ var path2 = {
593
615
  tinkerPath,
594
616
  typesPath,
595
617
  uiPath,
618
+ userEventsPath,
619
+ userJobsPath,
620
+ userListenersPath,
621
+ userMiddlewarePath,
622
+ userModelsPath,
623
+ userNotificationsPath,
596
624
  utilsPath,
597
625
  validationPath,
598
626
  vitePath,
@@ -669,7 +697,6 @@ async function serve(options = {}) {
669
697
  hostname,
670
698
  port,
671
699
  fetch(req) {
672
- console.log(req);
673
700
  return serverResponse(req);
674
701
  }
675
702
  });
@@ -785,13 +812,28 @@ class Router {
785
812
  });
786
813
  }
787
814
  async get(path5, callback) {
788
- if (typeof callback === "string") {
789
- const actionModule = await import(path2.actionsPath(`${callback}.ts`));
815
+ if (callback instanceof Promise) {
816
+ const actionModule = await callback;
817
+ callback = actionModule.default;
818
+ } else if (typeof callback === "string") {
819
+ const actionModule = await import(path2.userActionsPath(`${callback}.ts`));
790
820
  callback = actionModule.default.handle;
791
821
  }
792
822
  this.addRoute("GET", path5, callback, 200);
793
823
  return this;
794
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
+ }
795
837
  post(path5, callback) {
796
838
  this.addRoute("POST", path5, callback, 201);
797
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.62",
4
+ "version": "0.58.64",
5
5
  "description": "The Stacks framework router.",
6
6
  "author": "Chris Breuer",
7
7
  "license": "MIT",
package/src/router.ts CHANGED
@@ -48,9 +48,13 @@ 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
- const actionModule = await import(p.actionsPath(`${callback}.ts`))
57
+ const actionModule = await import(p.userActionsPath(`${callback}.ts`))
54
58
  callback = actionModule.default.handle
55
59
  }
56
60
 
@@ -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
  })