@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 +45 -3
- package/package.json +1 -1
- package/src/router.ts +22 -2
- package/src/server.ts +0 -2
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 (
|
|
789
|
-
const actionModule = await
|
|
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
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 (
|
|
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.
|
|
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
|