create-nexwire 4.0.0 → 4.1.1
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/README.md +5 -4
- package/express/README.md +13 -7
- package/express/package.json +2 -2
- package/express/src/config/session.ts +1 -1
- package/express/src/database/migrations/sqlite/meta/0000_snapshot.json +1 -1
- package/express/src/database/migrations/sqlite/meta/_journal.json +1 -1
- package/express/src/database/schema.ts +3 -3
- package/express/src/framework/cache/cache.ts +82 -81
- package/express/src/framework/database/seed.ts +1 -1
- package/express/src/framework/facade.ts +1 -24
- package/express/src/framework/http/app.ts +5 -5
- package/express/src/framework/http/openapi.ts +1 -1
- package/express/src/framework/http/router.ts +3 -18
- package/express/src/framework/http/types.ts +19 -0
- package/express/src/framework/http/validation.ts +18 -18
- package/express/src/framework/maker-cli/middleware/core.mjs +41 -47
- package/express/src/framework/maker-cli/module/core.mjs +920 -684
- package/express/src/framework/maker-cli/module/index.mjs +202 -140
- package/express/src/framework/maker-cli/runtime/core.mjs +1 -2
- package/express/src/framework/maker-cli/stubs/controller/openapi.ts.stub +40 -14
- package/express/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +40 -15
- package/express/src/framework/maker-cli/stubs/controller/plain.ts.stub +42 -16
- package/express/src/framework/maker-cli/stubs/controller/standalone.ts.stub +47 -0
- package/express/src/framework/maker-cli/stubs/facade/name.ts.stub +12 -0
- package/express/src/framework/maker-cli/stubs/helper/name.ts.stub +14 -0
- package/express/src/framework/maker-cli/stubs/middleware/name.local.ts.stub +15 -0
- package/express/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -8
- package/express/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -8
- package/express/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -8
- package/express/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -50
- package/express/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +11 -11
- package/express/src/framework/maker-cli/stubs/route/api.ts.stub +93 -79
- package/express/src/framework/maker-cli/stubs/route/plain.ts.stub +23 -10
- package/express/src/framework/maker-cli/stubs/route/standalone.api.ts.stub +113 -0
- package/express/src/framework/maker-cli/stubs/route/standalone.plain.ts.stub +37 -0
- package/express/src/framework/maker-cli/stubs/{controller/schema.plain.ts.stub → schema/name.plain.ts.stub} +13 -13
- package/express/src/framework/maker-cli/stubs/{controller/schema.ts.stub → schema/name.ts.stub} +32 -32
- package/express/src/framework/maker-cli/stubs/service/name.plain.ts.stub +67 -0
- package/express/src/framework/maker-cli/stubs/service/name.ts.stub +65 -0
- package/express/src/framework/maker-cli/stubs/type/name.ts.stub +22 -0
- package/express/src/framework/maker-cli/utils/naming.mjs +56 -13
- package/express/src/framework/modules/discover.ts +57 -54
- package/express/src/framework/notification/index.ts +1 -1
- package/express/src/framework/realtime/broadcast.ts +46 -46
- package/express/src/framework/server.ts +2 -1
- package/express/src/framework/session/session.ts +102 -98
- package/express/src/framework/support/mail.ts +48 -48
- package/express/src/framework/support/status-codes.ts +75 -0
- package/express/src/middlewares/auth-middleware.ts +1 -1
- package/express/src/modules/auth/__tests__/forgetpass.test.ts +200 -0
- package/express/src/modules/auth/__tests__/login.test.ts +171 -0
- package/express/src/modules/auth/__tests__/logout.test.ts +60 -0
- package/express/src/modules/auth/__tests__/logoutalldevices.test.ts +49 -0
- package/express/src/modules/auth/__tests__/me.test.ts +91 -0
- package/express/src/modules/auth/__tests__/refreshtoken.test.ts +305 -0
- package/express/src/modules/auth/__tests__/register.test.ts +291 -0
- package/express/src/modules/auth/__tests__/resetpass.test.ts +206 -0
- package/express/src/modules/auth/__tests__/verifyemail.test.ts +183 -0
- package/express/src/modules/auth/controllers/auth.ts +254 -0
- package/express/src/modules/auth/controllers/{role.controller.ts → role.ts} +25 -15
- package/{hono/src/modules/auth/database/models/notifications.ts → express/src/modules/auth/database/models/notification.ts} +1 -1
- package/express/src/modules/auth/database/models/role.ts +1 -1
- package/express/src/modules/auth/database/models/user.ts +1 -1
- package/express/src/modules/auth/facade.ts +12 -0
- package/express/src/modules/auth/{controllers/auth.helpers.ts → helpers/auth.ts} +3 -4
- package/express/src/modules/auth/jobs/registeruser.ts +23 -23
- package/express/src/modules/auth/routes/{api.ts → index.ts} +150 -150
- package/express/src/modules/auth/routes/role.ts +33 -33
- package/{hono/src/modules/auth/controllers/auth.schema.ts → express/src/modules/auth/schemas/auth.ts} +102 -102
- package/express/src/modules/auth/services/forgetpassword.ts +66 -0
- package/express/src/modules/auth/services/login.ts +63 -0
- package/express/src/modules/auth/services/logout.ts +25 -0
- package/express/src/modules/auth/services/logoutalldevices.ts +19 -0
- package/express/src/modules/auth/services/me.ts +31 -0
- package/express/src/modules/auth/services/refreshtoken.ts +110 -0
- package/express/src/modules/auth/services/register.ts +141 -0
- package/express/src/modules/auth/services/resetpassword.ts +69 -0
- package/express/src/modules/auth/services/verifyemail.ts +77 -0
- package/express/src/modules/auth/types/auth.ts +31 -0
- package/express/src/resources/src/assets/images/logo.png +0 -0
- package/express/src/resources/src/pages/auth/forgetPassword.vue +1 -0
- package/express/src/resources/src/pages/auth/login.vue +1 -1
- package/express/src/storage/database/nexwire.sqlite +0 -0
- package/hono/README.md +13 -7
- package/hono/package.json +1 -1
- package/hono/src/config/session.ts +1 -1
- package/hono/src/database/migrations/sqlite/meta/0000_snapshot.json +1 -1
- package/hono/src/database/migrations/sqlite/meta/_journal.json +1 -1
- package/hono/src/database/schema.ts +3 -3
- package/hono/src/framework/cache/cache.ts +82 -81
- package/hono/src/framework/database/seed.ts +1 -1
- package/hono/src/framework/http/app.ts +5 -5
- package/hono/src/framework/http/validation.ts +21 -21
- package/hono/src/framework/maker-cli/middleware/core.mjs +40 -46
- package/hono/src/framework/maker-cli/module/core.mjs +401 -168
- package/hono/src/framework/maker-cli/module/index.mjs +73 -11
- package/hono/src/framework/maker-cli/stubs/controller/openapi.ts.stub +28 -16
- package/hono/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +28 -17
- package/hono/src/framework/maker-cli/stubs/controller/plain.ts.stub +28 -16
- package/hono/src/framework/maker-cli/stubs/controller/standalone.ts.stub +56 -0
- package/hono/src/framework/maker-cli/stubs/facade/name.ts.stub +12 -0
- package/hono/src/framework/maker-cli/stubs/helper/name.ts.stub +14 -0
- package/hono/src/framework/maker-cli/stubs/middleware/name.local.ts.stub +15 -0
- package/hono/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -8
- package/hono/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -8
- package/hono/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -8
- package/hono/src/framework/maker-cli/stubs/notification/route.api.ts.stub +49 -49
- package/hono/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +11 -11
- package/hono/src/framework/maker-cli/stubs/route/api.ts.stub +93 -79
- package/hono/src/framework/maker-cli/stubs/route/plain.ts.stub +23 -10
- package/hono/src/framework/maker-cli/stubs/route/standalone.api.ts.stub +112 -0
- package/hono/src/framework/maker-cli/stubs/route/standalone.plain.ts.stub +37 -0
- package/hono/src/framework/maker-cli/stubs/{controller/schema.plain.ts.stub → schema/name.plain.ts.stub} +13 -13
- package/hono/src/framework/maker-cli/stubs/{controller/schema.ts.stub → schema/name.ts.stub} +32 -32
- package/hono/src/framework/maker-cli/stubs/service/name.plain.ts.stub +67 -0
- package/hono/src/framework/maker-cli/stubs/service/name.ts.stub +65 -0
- package/hono/src/framework/maker-cli/stubs/type/name.ts.stub +22 -0
- package/hono/src/framework/maker-cli/utils/naming.mjs +56 -13
- package/hono/src/framework/modules/discover.ts +57 -54
- package/hono/src/framework/notification/index.ts +1 -1
- package/hono/src/framework/realtime/broadcast.ts +46 -46
- package/hono/src/framework/server.ts +1 -1
- package/hono/src/framework/session/session.ts +121 -116
- package/hono/src/middlewares/auth-middleware.ts +1 -1
- package/hono/src/modules/auth/__tests__/forgetpass.test.ts +170 -0
- package/hono/src/modules/auth/__tests__/login.test.ts +154 -0
- package/hono/src/modules/auth/__tests__/logout.test.ts +53 -0
- package/hono/src/modules/auth/__tests__/logoutalldevices.test.ts +34 -0
- package/hono/src/modules/auth/__tests__/me.test.ts +87 -0
- package/hono/src/modules/auth/__tests__/refreshtoken.test.ts +305 -0
- package/hono/src/modules/auth/__tests__/register.test.ts +258 -0
- package/hono/src/modules/auth/__tests__/resetpass.test.ts +214 -0
- package/hono/src/modules/auth/__tests__/verifyemail.test.ts +189 -0
- package/hono/src/modules/auth/controllers/auth.ts +238 -0
- package/hono/src/modules/auth/controllers/{role.controller.ts → role.ts} +25 -25
- package/{express/src/modules/auth/database/models/notifications.ts → hono/src/modules/auth/database/models/notification.ts} +1 -1
- package/hono/src/modules/auth/database/models/role.ts +1 -1
- package/hono/src/modules/auth/database/models/user.ts +1 -1
- package/hono/src/modules/auth/facade.ts +12 -0
- package/hono/src/modules/auth/{controllers/auth.helpers.ts → helpers/auth.ts} +5 -6
- package/hono/src/modules/auth/jobs/registeruser.ts +23 -23
- package/hono/src/modules/auth/routes/{api.ts → index.ts} +150 -150
- package/hono/src/modules/auth/routes/role.ts +33 -33
- package/{express/src/modules/auth/controllers/auth.schema.ts → hono/src/modules/auth/schemas/auth.ts} +102 -102
- package/hono/src/modules/auth/services/forgetpassword.ts +58 -0
- package/hono/src/modules/auth/services/login.ts +61 -0
- package/hono/src/modules/auth/services/logout.ts +24 -0
- package/hono/src/modules/auth/services/logoutalldevices.ts +19 -0
- package/hono/src/modules/auth/services/me.ts +31 -0
- package/hono/src/modules/auth/services/refreshtoken.ts +110 -0
- package/hono/src/modules/auth/services/register.ts +132 -0
- package/hono/src/modules/auth/services/resetpassword.ts +69 -0
- package/hono/src/modules/auth/services/verifyemail.ts +77 -0
- package/hono/src/modules/auth/types/auth.ts +31 -0
- package/hono/src/resources/src/assets/images/logo.png +0 -0
- package/hono/src/storage/database/nexwire.sqlite +0 -0
- package/package.json +1 -1
- package/express/src/framework/maker-cli/stubs/example/console.ts.stub +0 -34
- package/express/src/framework/maker-cli/stubs/example/controller.ts.stub +0 -418
- package/express/src/framework/maker-cli/stubs/example/job.ts.stub +0 -75
- package/express/src/framework/maker-cli/stubs/example/route.api.ts.stub +0 -207
- package/express/src/framework/maker-cli/stubs/example/route.plain.ts.stub +0 -18
- package/express/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +0 -42
- package/express/src/framework/maker-cli/stubs/example/schema.ts.stub +0 -42
- package/express/src/modules/auth/controllers/auth.controller.ts +0 -358
- package/hono/src/framework/maker-cli/stubs/example/console.ts.stub +0 -34
- package/hono/src/framework/maker-cli/stubs/example/controller.ts.stub +0 -505
- package/hono/src/framework/maker-cli/stubs/example/job.ts.stub +0 -75
- package/hono/src/framework/maker-cli/stubs/example/route.api.ts.stub +0 -207
- package/hono/src/framework/maker-cli/stubs/example/route.plain.ts.stub +0 -18
- package/hono/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +0 -42
- package/hono/src/framework/maker-cli/stubs/example/schema.ts.stub +0 -42
- package/hono/src/modules/auth/controllers/auth.controller.ts +0 -413
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { createRoute, createRouter, HttpStatusCodes, jsonContent, z } from "@/framework/facade.js";
|
|
2
|
-
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
-
import { list,
|
|
4
|
-
import { PaginatedNotificationsSchema, UnreadCountSchema } from "../
|
|
5
|
-
|
|
6
|
-
const listRoute = createRoute({
|
|
7
|
-
path: "/",
|
|
8
|
-
method: "get",
|
|
9
|
-
tags: ["Notifications"],
|
|
10
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(PaginatedNotificationsSchema, "Paginated notifications") },
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const unreadCountRoute = createRoute({
|
|
14
|
-
path: "/unread-count",
|
|
15
|
-
method: "get",
|
|
16
|
-
tags: ["Notifications"],
|
|
17
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(UnreadCountSchema, "Unread count") },
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const markReadRoute = createRoute({
|
|
21
|
-
path: "/{id}/read",
|
|
22
|
-
method: "patch",
|
|
23
|
-
tags: ["Notifications"],
|
|
24
|
-
request: { params: z.object({ id: z.coerce.number() }) },
|
|
25
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "Marked as read") },
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const markAllReadRoute = createRoute({
|
|
29
|
-
path: "/read-all",
|
|
30
|
-
method: "patch",
|
|
31
|
-
tags: ["Notifications"],
|
|
32
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "All marked as read") },
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const deleteRoute = createRoute({
|
|
36
|
-
path: "/{id}",
|
|
37
|
-
method: "delete",
|
|
38
|
-
tags: ["Notifications"],
|
|
39
|
-
request: { params: z.object({ id: z.coerce.number() }) },
|
|
40
|
-
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "Deleted") },
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
export default createRouter()
|
|
44
|
-
.group(authMiddleware)
|
|
45
|
-
.api(listRoute, list)
|
|
46
|
-
.api(unreadCountRoute, unreadCount)
|
|
47
|
-
.api(markReadRoute, markRead)
|
|
48
|
-
.api(markAllReadRoute, markAllRead)
|
|
49
|
-
.api(deleteRoute, remove);
|
|
1
|
+
import { createRoute, createRouter, HttpStatusCodes, jsonContent, z } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { list, markAllRead, markRead, remove, unreadCount } from "../controllers/{{module}}.js";
|
|
4
|
+
import { PaginatedNotificationsSchema, UnreadCountSchema } from "../schemas/{{module}}.js";
|
|
5
|
+
|
|
6
|
+
const listRoute = createRoute({
|
|
7
|
+
path: "/",
|
|
8
|
+
method: "get",
|
|
9
|
+
tags: ["Notifications"],
|
|
10
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(PaginatedNotificationsSchema, "Paginated notifications") },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const unreadCountRoute = createRoute({
|
|
14
|
+
path: "/unread-count",
|
|
15
|
+
method: "get",
|
|
16
|
+
tags: ["Notifications"],
|
|
17
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(UnreadCountSchema, "Unread count") },
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const markReadRoute = createRoute({
|
|
21
|
+
path: "/{id}/read",
|
|
22
|
+
method: "patch",
|
|
23
|
+
tags: ["Notifications"],
|
|
24
|
+
request: { params: z.object({ id: z.coerce.number() }) },
|
|
25
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "Marked as read") },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const markAllReadRoute = createRoute({
|
|
29
|
+
path: "/read-all",
|
|
30
|
+
method: "patch",
|
|
31
|
+
tags: ["Notifications"],
|
|
32
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "All marked as read") },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const deleteRoute = createRoute({
|
|
36
|
+
path: "/{id}",
|
|
37
|
+
method: "delete",
|
|
38
|
+
tags: ["Notifications"],
|
|
39
|
+
request: { params: z.object({ id: z.coerce.number() }) },
|
|
40
|
+
responses: { [HttpStatusCodes.OK]: jsonContent(z.object({ ok: z.boolean() }), "Deleted") },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export default createRouter()
|
|
44
|
+
.group(authMiddleware)
|
|
45
|
+
.api(listRoute, list)
|
|
46
|
+
.api(unreadCountRoute, unreadCount)
|
|
47
|
+
.api(markReadRoute, markRead)
|
|
48
|
+
.api(markAllReadRoute, markAllRead)
|
|
49
|
+
.api(deleteRoute, remove);
|
|
50
50
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { group } from "@/framework/facade.js";
|
|
2
|
-
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
-
import { list, unreadCount, markRead, markAllRead, remove } from "../controllers/{{module}}.
|
|
4
|
-
|
|
5
|
-
export default group()
|
|
6
|
-
.use(authMiddleware)
|
|
7
|
-
.get("/", list)
|
|
8
|
-
.get("/unread-count", unreadCount)
|
|
9
|
-
.patch("/:id/read", markRead)
|
|
10
|
-
.patch("/read-all", markAllRead)
|
|
11
|
-
.delete("/:id", remove);
|
|
1
|
+
import { group } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { list, unreadCount, markRead, markAllRead, remove } from "../controllers/{{module}}.js";
|
|
4
|
+
|
|
5
|
+
export default group()
|
|
6
|
+
.use(authMiddleware)
|
|
7
|
+
.get("/", list)
|
|
8
|
+
.get("/unread-count", unreadCount)
|
|
9
|
+
.patch("/:id/read", markRead)
|
|
10
|
+
.patch("/read-all", markAllRead)
|
|
11
|
+
.delete("/:id", remove);
|
|
12
12
|
|
|
@@ -1,80 +1,94 @@
|
|
|
1
|
-
import { createRoute, group, HttpStatusCodes, jsonContent } from "@/framework/facade.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
{{ClassName}}
|
|
7
|
-
{{ClassName}}
|
|
8
|
-
{{ClassName}}
|
|
9
|
-
{{ClassName}}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[HttpStatusCodes.
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
[HttpStatusCodes.
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
[HttpStatusCodes.
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.api(
|
|
77
|
-
.api(
|
|
78
|
-
.api(
|
|
79
|
-
.api(
|
|
1
|
+
import { createRoute, group, HttpStatusCodes, jsonContent } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { requireRole } from "@/middlewares/role-middleware.js";
|
|
4
|
+
import { destroy, index, show, store, update } from "@/modules/{{module}}/controllers/{{controller}}.js";
|
|
5
|
+
import {
|
|
6
|
+
Create{{ClassName}}Schema,
|
|
7
|
+
{{ClassName}}IdParamsSchema,
|
|
8
|
+
{{ClassName}}ListResponseSchema,
|
|
9
|
+
{{ClassName}}MessageSchema,
|
|
10
|
+
{{ClassName}}ResponseSchema,
|
|
11
|
+
Update{{ClassName}}Schema
|
|
12
|
+
} from "@/modules/{{module}}/schemas/{{controller}}.js";
|
|
13
|
+
|
|
14
|
+
const indexRoute = createRoute({
|
|
15
|
+
path: "/",
|
|
16
|
+
method: "get",
|
|
17
|
+
tags: ["{{ModuleClass}}"],
|
|
18
|
+
responses: {
|
|
19
|
+
[HttpStatusCodes.OK]: jsonContent({{ClassName}}ListResponseSchema, "{{module}} list")
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const showRoute = createRoute({
|
|
24
|
+
path: "/{id}",
|
|
25
|
+
method: "get",
|
|
26
|
+
tags: ["{{ModuleClass}}"],
|
|
27
|
+
request: {
|
|
28
|
+
params: {{ClassName}}IdParamsSchema
|
|
29
|
+
},
|
|
30
|
+
responses: {
|
|
31
|
+
[HttpStatusCodes.OK]: jsonContent({{ClassName}}ResponseSchema, "{{module}} item"),
|
|
32
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const storeRoute = createRoute({
|
|
37
|
+
path: "/",
|
|
38
|
+
method: "post",
|
|
39
|
+
tags: ["{{ModuleClass}}"],
|
|
40
|
+
request: {
|
|
41
|
+
body: jsonContent(Create{{ClassName}}Schema, "Create {{module}} payload")
|
|
42
|
+
},
|
|
43
|
+
responses: {
|
|
44
|
+
[HttpStatusCodes.CREATED]: jsonContent({{ClassName}}MessageSchema, "Created")
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const updateRoute = createRoute({
|
|
49
|
+
path: "/{id}",
|
|
50
|
+
method: "put",
|
|
51
|
+
tags: ["{{ModuleClass}}"],
|
|
52
|
+
request: {
|
|
53
|
+
params: {{ClassName}}IdParamsSchema,
|
|
54
|
+
body: jsonContent(Update{{ClassName}}Schema, "Update {{module}} payload")
|
|
55
|
+
},
|
|
56
|
+
responses: {
|
|
57
|
+
[HttpStatusCodes.OK]: jsonContent({{ClassName}}MessageSchema, "Updated"),
|
|
58
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const destroyRoute = createRoute({
|
|
63
|
+
path: "/{id}",
|
|
64
|
+
method: "delete",
|
|
65
|
+
tags: ["{{ModuleClass}}"],
|
|
66
|
+
request: {
|
|
67
|
+
params: {{ClassName}}IdParamsSchema
|
|
68
|
+
},
|
|
69
|
+
responses: {
|
|
70
|
+
[HttpStatusCodes.OK]: jsonContent({{ClassName}}MessageSchema, "Deleted"),
|
|
71
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export default group()
|
|
76
|
+
.api(indexRoute, index)
|
|
77
|
+
.api(showRoute, show)
|
|
78
|
+
.api(storeRoute, store)
|
|
79
|
+
.api(updateRoute, update)
|
|
80
|
+
.api(destroyRoute, destroy);
|
|
81
|
+
|
|
82
|
+
// Gate the whole group (authMiddleware resolves the session once for every route):
|
|
83
|
+
// export default group(authMiddleware).api(indexRoute, index) ...
|
|
84
|
+
//
|
|
85
|
+
// Or gate a single route by role. requireRole reads the role authMiddleware set,
|
|
86
|
+
// so authMiddleware must run first:
|
|
87
|
+
// group().api(destroyRoute, [authMiddleware, requireRole("admin")], destroy)
|
|
88
|
+
//
|
|
89
|
+
// Or group all authMiddleware and set single requireRole middleware
|
|
90
|
+
// so authMiddleware must run on all chain and requireRole single on per route:
|
|
91
|
+
// group(authMiddleware).api(destroyRoute, [requireRole("admin")], destroy)
|
|
92
|
+
//
|
|
93
|
+
// Delete the imports above when you do not need them.
|
|
80
94
|
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import { group } from "@/framework/facade.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export default group()
|
|
6
|
-
.get("/", index)
|
|
7
|
-
.get("/:id", show)
|
|
8
|
-
.post("/", store)
|
|
9
|
-
.put("/:id", update)
|
|
10
|
-
.delete("/:id", destroy);
|
|
1
|
+
import { group } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { requireRole } from "@/middlewares/role-middleware.js";
|
|
4
|
+
import { index, show, store, update, destroy } from "@/modules/{{module}}/controllers/{{controller}}.js";
|
|
11
5
|
|
|
6
|
+
export default group()
|
|
7
|
+
.get("/", index)
|
|
8
|
+
.get("/:id", show)
|
|
9
|
+
.post("/", store)
|
|
10
|
+
.put("/:id", update)
|
|
11
|
+
.delete("/:id", destroy);
|
|
12
|
+
|
|
13
|
+
// Gate the whole group (authMiddleware resolves the session once for every route):
|
|
14
|
+
// export default group(authMiddleware).api(indexRoute, index) ...
|
|
15
|
+
//
|
|
16
|
+
// Or gate a single route by role. requireRole reads the role authMiddleware set,
|
|
17
|
+
// so authMiddleware must run first:
|
|
18
|
+
// group().api(destroyRoute, [authMiddleware, requireRole("admin")], destroy)
|
|
19
|
+
//
|
|
20
|
+
// Or group all authMiddleware and set single requireRole middleware
|
|
21
|
+
// so authMiddleware must run on all chain and requireRole single on per route:
|
|
22
|
+
// group(authMiddleware).api(destroyRoute, [requireRole("admin")], destroy)
|
|
23
|
+
//
|
|
24
|
+
// Delete the imports above when you do not need them.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createRoute, group, HttpStatusCodes, jsonContent, z } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { requireRole } from "@/middlewares/role-middleware.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* {{module}} routes for {{controller}}.
|
|
7
|
+
*
|
|
8
|
+
* Wire each route to a handler:
|
|
9
|
+
* import { index, show, store, update, destroy } from "@/modules/{{module}}/controllers/{{controller}}.js";
|
|
10
|
+
* export default group().api(indexRoute, index).api(showRoute, show) ...
|
|
11
|
+
*
|
|
12
|
+
* Wire each route to its validation schema:
|
|
13
|
+
* import {
|
|
14
|
+
* Create{{ClassName}}Schema,
|
|
15
|
+
* {{ClassName}}IdParamsSchema,
|
|
16
|
+
* {{ClassName}}ListResponseSchema,
|
|
17
|
+
* {{ClassName}}MessageSchema,
|
|
18
|
+
* {{ClassName}}ResponseSchema,
|
|
19
|
+
* Update{{ClassName}}Schema
|
|
20
|
+
* } from "@/modules/{{module}}/schemas/{{controller}}.js";
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const indexRoute = createRoute({
|
|
24
|
+
path: "/",
|
|
25
|
+
method: "get",
|
|
26
|
+
tags: ["{{ModuleClass}}"],
|
|
27
|
+
// request: {
|
|
28
|
+
// query: {{ClassName}}ListQuerySchema
|
|
29
|
+
// },
|
|
30
|
+
responses: {
|
|
31
|
+
[HttpStatusCodes.OK]: jsonContent(
|
|
32
|
+
z.object({ message: z.string(), data: z.array(z.object({ id: z.number(), name: z.string() })) }),
|
|
33
|
+
"{{module}} list"
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const showRoute = createRoute({
|
|
39
|
+
path: "/{id}",
|
|
40
|
+
method: "get",
|
|
41
|
+
tags: ["{{ModuleClass}}"],
|
|
42
|
+
// request: {
|
|
43
|
+
// params: {{ClassName}}IdParamsSchema
|
|
44
|
+
// },
|
|
45
|
+
responses: {
|
|
46
|
+
[HttpStatusCodes.OK]: jsonContent(
|
|
47
|
+
z.object({ message: z.string(), data: z.object({ id: z.number(), name: z.string() }) }),
|
|
48
|
+
"{{module}} item"
|
|
49
|
+
),
|
|
50
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent(z.object({ message: z.string() }), "Not found")
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const storeRoute = createRoute({
|
|
55
|
+
path: "/",
|
|
56
|
+
method: "post",
|
|
57
|
+
tags: ["{{ModuleClass}}"],
|
|
58
|
+
// request: {
|
|
59
|
+
// body: jsonContent(Create{{ClassName}}Schema, "Create {{module}} payload")
|
|
60
|
+
// },
|
|
61
|
+
responses: {
|
|
62
|
+
[HttpStatusCodes.CREATED]: jsonContent(z.object({ message: z.string() }), "Created")
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const updateRoute = createRoute({
|
|
67
|
+
path: "/{id}",
|
|
68
|
+
method: "put",
|
|
69
|
+
tags: ["{{ModuleClass}}"],
|
|
70
|
+
// request: {
|
|
71
|
+
// params: {{ClassName}}IdParamsSchema,
|
|
72
|
+
// body: jsonContent(Update{{ClassName}}Schema, "Update {{module}} payload")
|
|
73
|
+
// },
|
|
74
|
+
responses: {
|
|
75
|
+
[HttpStatusCodes.OK]: jsonContent(z.object({ message: z.string() }), "Updated"),
|
|
76
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent(z.object({ message: z.string() }), "Not found")
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const destroyRoute = createRoute({
|
|
81
|
+
path: "/{id}",
|
|
82
|
+
method: "delete",
|
|
83
|
+
tags: ["{{ModuleClass}}"],
|
|
84
|
+
// request: {
|
|
85
|
+
// params: {{ClassName}}IdParamsSchema
|
|
86
|
+
// },
|
|
87
|
+
responses: {
|
|
88
|
+
[HttpStatusCodes.OK]: jsonContent(z.object({ message: z.string() }), "Deleted"),
|
|
89
|
+
[HttpStatusCodes.NOT_FOUND]: jsonContent(z.object({ message: z.string() }), "Not found")
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export default group()
|
|
94
|
+
.api(indexRoute, (c: any) => c.json({ message: "{{module}} list not implemented", data: [] }))
|
|
95
|
+
.api(showRoute, (c: any) => c.json({ message: "{{module}} item not implemented", data: { id: 0, name: "" } }))
|
|
96
|
+
.api(storeRoute, (c: any) => c.json({ message: "{{module}} create not implemented" }, 201))
|
|
97
|
+
.api(updateRoute, (c: any) => c.json({ message: "{{module}} update not implemented" }))
|
|
98
|
+
.api(destroyRoute, (c: any) => c.json({ message: "{{module}} delete not implemented" }));
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
// Gate the whole group (authMiddleware resolves the session once for every route):
|
|
102
|
+
// export default group(authMiddleware).api(indexRoute, index) ...
|
|
103
|
+
//
|
|
104
|
+
// Or gate a single route by role. requireRole reads the role authMiddleware set,
|
|
105
|
+
// so authMiddleware must run first:
|
|
106
|
+
// group().api(destroyRoute, [authMiddleware, requireRole("admin")], destroy)
|
|
107
|
+
//
|
|
108
|
+
// Or group all authMiddleware and set single requireRole middleware
|
|
109
|
+
// so authMiddleware must run on all chain and requireRole single on per route:
|
|
110
|
+
// group(authMiddleware).api(destroyRoute, [requireRole("admin")], destroy)
|
|
111
|
+
//
|
|
112
|
+
// Delete the imports above when you do not need them.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { group } from "@/framework/facade.js";
|
|
2
|
+
import { authMiddleware } from "@/middlewares/auth-middleware.js";
|
|
3
|
+
import { requireRole } from "@/middlewares/role-middleware.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* {{module}} routes for {{controller}}.
|
|
7
|
+
*
|
|
8
|
+
* Wire each handler to a controller:
|
|
9
|
+
* import { index, show, store, update, destroy } from "@/modules/{{module}}/controllers/{{controller}}.js";
|
|
10
|
+
* export default group().get("/", index).get("/:id", show) ...
|
|
11
|
+
*
|
|
12
|
+
* Add validation with the validate() helper:
|
|
13
|
+
* import { validate } from "@/framework/facade.js";
|
|
14
|
+
* import { {{ClassName}}IdParamsSchema } from "@/modules/{{module}}/schemas/{{controller}}.js";
|
|
15
|
+
* const params = await validate({{ClassName}}IdParamsSchema, c.req.param());
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export default group()
|
|
19
|
+
.get("/", (c: any) => c.json({ message: "{{module}} list not implemented", data: [] }))
|
|
20
|
+
.get("/:id", (c: any) => c.json({ message: "{{module}} item not implemented", data: { id: 0, name: "" } }))
|
|
21
|
+
.post("/", (c: any) => c.json({ message: "{{module}} create not implemented" }, 201))
|
|
22
|
+
.put("/:id", (c: any) => c.json({ message: "{{module}} update not implemented" }))
|
|
23
|
+
.delete("/:id", (c: any) => c.json({ message: "{{module}} delete not implemented" }));
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// Gate the whole group (authMiddleware resolves the session once for every route):
|
|
27
|
+
// export default group(authMiddleware).api(indexRoute, index) ...
|
|
28
|
+
//
|
|
29
|
+
// Or gate a single route by role. requireRole reads the role authMiddleware set,
|
|
30
|
+
// so authMiddleware must run first:
|
|
31
|
+
// group().api(destroyRoute, [authMiddleware, requireRole("admin")], destroy)
|
|
32
|
+
//
|
|
33
|
+
// Or group all authMiddleware and set single requireRole middleware
|
|
34
|
+
// so authMiddleware must run on all chain and requireRole single on per route:
|
|
35
|
+
// group(authMiddleware).api(destroyRoute, [requireRole("admin")], destroy)
|
|
36
|
+
//
|
|
37
|
+
// Delete the imports above when you do not need them.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { z } from "@/framework/facade.js";
|
|
2
|
-
|
|
3
|
-
export const Create{{ClassName}}Schema = z.object({
|
|
4
|
-
name: z.string().min(1)
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
export const Update{{ClassName}}Schema = z.object({
|
|
8
|
-
name: z.string().min(1)
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
export const {{ClassName}}IdParamsSchema = z.object({
|
|
12
|
-
id: z.coerce.number().int().positive()
|
|
13
|
-
});
|
|
1
|
+
import { z } from "@/framework/facade.js";
|
|
2
|
+
|
|
3
|
+
export const Create{{ClassName}}Schema = z.object({
|
|
4
|
+
name: z.string().min(1)
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
export const Update{{ClassName}}Schema = z.object({
|
|
8
|
+
name: z.string().min(1)
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const {{ClassName}}IdParamsSchema = z.object({
|
|
12
|
+
id: z.coerce.number().int().positive()
|
|
13
|
+
});
|
|
14
14
|
|
package/hono/src/framework/maker-cli/stubs/{controller/schema.ts.stub → schema/name.ts.stub}
RENAMED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { z } from "@/framework/facade.js";
|
|
2
|
-
|
|
3
|
-
export const {{ClassName}}ItemSchema = z.object({
|
|
4
|
-
id: z.number(),
|
|
5
|
-
name: z.string()
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export const Create{{ClassName}}Schema = z.object({
|
|
9
|
-
name: z.string().min(1)
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export const Update{{ClassName}}Schema = z.object({
|
|
13
|
-
name: z.string().min(1)
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const {{ClassName}}IdParamsSchema = z.object({
|
|
17
|
-
id: z.coerce.number().int().positive()
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export const {{ClassName}}ListResponseSchema = z.object({
|
|
21
|
-
message: z.string(),
|
|
22
|
-
data: z.array({{ClassName}}ItemSchema)
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const {{ClassName}}ResponseSchema = z.object({
|
|
26
|
-
message: z.string(),
|
|
27
|
-
data: {{ClassName}}ItemSchema
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export const {{ClassName}}MessageSchema = z.object({
|
|
31
|
-
message: z.string()
|
|
32
|
-
});
|
|
1
|
+
import { z } from "@/framework/facade.js";
|
|
2
|
+
|
|
3
|
+
export const {{ClassName}}ItemSchema = z.object({
|
|
4
|
+
id: z.number(),
|
|
5
|
+
name: z.string()
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const Create{{ClassName}}Schema = z.object({
|
|
9
|
+
name: z.string().min(1)
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const Update{{ClassName}}Schema = z.object({
|
|
13
|
+
name: z.string().min(1)
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const {{ClassName}}IdParamsSchema = z.object({
|
|
17
|
+
id: z.coerce.number().int().positive()
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const {{ClassName}}ListResponseSchema = z.object({
|
|
21
|
+
message: z.string(),
|
|
22
|
+
data: z.array({{ClassName}}ItemSchema)
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const {{ClassName}}ResponseSchema = z.object({
|
|
26
|
+
message: z.string(),
|
|
27
|
+
data: {{ClassName}}ItemSchema
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const {{ClassName}}MessageSchema = z.object({
|
|
31
|
+
message: z.string()
|
|
32
|
+
});
|
|
33
33
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { eq } from "drizzle-orm";
|
|
2
|
+
import { db } from "@/framework/facade.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Why: Returns every {{controller}} row for list screens.
|
|
6
|
+
* When: Called by the controller's index() handler.
|
|
7
|
+
* Where: GET /{{controller}} route.
|
|
8
|
+
*
|
|
9
|
+
* TODO: import your model and query it, for example:
|
|
10
|
+
* import { {{tableVariable}} } from "@/modules/{{module}}/database/models/{{controller}}.js";
|
|
11
|
+
* return db.select().from({{tableVariable}});
|
|
12
|
+
*/
|
|
13
|
+
export const {{controller}}Service = {
|
|
14
|
+
/**
|
|
15
|
+
* Why: CRUD service for {{controller}}.
|
|
16
|
+
* When: Consumed directly by the controller as `{{controller}}Service.list()`, etc.
|
|
17
|
+
* Where: Wired into the module's controller handlers.
|
|
18
|
+
*/
|
|
19
|
+
list: async () => {
|
|
20
|
+
void db;
|
|
21
|
+
return [];
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Why: Returns one {{controller}} row by primary key.
|
|
26
|
+
* When: Called by the controller's show/update/destroy handlers.
|
|
27
|
+
* Where: Reused across GET/PUT/DELETE /{{controller}}/{id} routes.
|
|
28
|
+
*
|
|
29
|
+
* TODO: query the model by id and return the row, or null when missing.
|
|
30
|
+
*/
|
|
31
|
+
findOne: async (_id: number) => {
|
|
32
|
+
return null;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Why: Persists a new {{controller}} row.
|
|
37
|
+
* When: Called by the controller's store() handler.
|
|
38
|
+
* Where: POST /{{controller}} route.
|
|
39
|
+
*
|
|
40
|
+
* TODO: insert the validated payload and return the created row.
|
|
41
|
+
*/
|
|
42
|
+
create: async (_data: Record<string, unknown>) => {
|
|
43
|
+
return null;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Why: Applies a partial change to one {{controller}} row.
|
|
48
|
+
* When: Called by the controller's update() handler.
|
|
49
|
+
* Where: PUT/PATCH /{{controller}}/{id} route.
|
|
50
|
+
*
|
|
51
|
+
* TODO: update by id, refresh updatedAt, and return the row, or null when missing.
|
|
52
|
+
*/
|
|
53
|
+
update: async (_id: number, _data: Record<string, unknown>) => {
|
|
54
|
+
return null;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Why: Removes one {{controller}} row.
|
|
59
|
+
* When: Called by the controller's destroy() handler.
|
|
60
|
+
* Where: DELETE /{{controller}}/{id} route.
|
|
61
|
+
*
|
|
62
|
+
* TODO: delete by id and return the removed row, or null when missing.
|
|
63
|
+
*/
|
|
64
|
+
remove: async (_id: number) => {
|
|
65
|
+
return null;
|
|
66
|
+
},
|
|
67
|
+
};
|