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.
Files changed (173) hide show
  1. package/README.md +5 -4
  2. package/express/README.md +13 -7
  3. package/express/package.json +2 -2
  4. package/express/src/config/session.ts +1 -1
  5. package/express/src/database/migrations/sqlite/meta/0000_snapshot.json +1 -1
  6. package/express/src/database/migrations/sqlite/meta/_journal.json +1 -1
  7. package/express/src/database/schema.ts +3 -3
  8. package/express/src/framework/cache/cache.ts +82 -81
  9. package/express/src/framework/database/seed.ts +1 -1
  10. package/express/src/framework/facade.ts +1 -24
  11. package/express/src/framework/http/app.ts +5 -5
  12. package/express/src/framework/http/openapi.ts +1 -1
  13. package/express/src/framework/http/router.ts +3 -18
  14. package/express/src/framework/http/types.ts +19 -0
  15. package/express/src/framework/http/validation.ts +18 -18
  16. package/express/src/framework/maker-cli/middleware/core.mjs +41 -47
  17. package/express/src/framework/maker-cli/module/core.mjs +920 -684
  18. package/express/src/framework/maker-cli/module/index.mjs +202 -140
  19. package/express/src/framework/maker-cli/runtime/core.mjs +1 -2
  20. package/express/src/framework/maker-cli/stubs/controller/openapi.ts.stub +40 -14
  21. package/express/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +40 -15
  22. package/express/src/framework/maker-cli/stubs/controller/plain.ts.stub +42 -16
  23. package/express/src/framework/maker-cli/stubs/controller/standalone.ts.stub +47 -0
  24. package/express/src/framework/maker-cli/stubs/facade/name.ts.stub +12 -0
  25. package/express/src/framework/maker-cli/stubs/helper/name.ts.stub +14 -0
  26. package/express/src/framework/maker-cli/stubs/middleware/name.local.ts.stub +15 -0
  27. package/express/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -8
  28. package/express/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -8
  29. package/express/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -8
  30. package/express/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -50
  31. package/express/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +11 -11
  32. package/express/src/framework/maker-cli/stubs/route/api.ts.stub +93 -79
  33. package/express/src/framework/maker-cli/stubs/route/plain.ts.stub +23 -10
  34. package/express/src/framework/maker-cli/stubs/route/standalone.api.ts.stub +113 -0
  35. package/express/src/framework/maker-cli/stubs/route/standalone.plain.ts.stub +37 -0
  36. package/express/src/framework/maker-cli/stubs/{controller/schema.plain.ts.stub → schema/name.plain.ts.stub} +13 -13
  37. package/express/src/framework/maker-cli/stubs/{controller/schema.ts.stub → schema/name.ts.stub} +32 -32
  38. package/express/src/framework/maker-cli/stubs/service/name.plain.ts.stub +67 -0
  39. package/express/src/framework/maker-cli/stubs/service/name.ts.stub +65 -0
  40. package/express/src/framework/maker-cli/stubs/type/name.ts.stub +22 -0
  41. package/express/src/framework/maker-cli/utils/naming.mjs +56 -13
  42. package/express/src/framework/modules/discover.ts +57 -54
  43. package/express/src/framework/notification/index.ts +1 -1
  44. package/express/src/framework/realtime/broadcast.ts +46 -46
  45. package/express/src/framework/server.ts +2 -1
  46. package/express/src/framework/session/session.ts +102 -98
  47. package/express/src/framework/support/mail.ts +48 -48
  48. package/express/src/framework/support/status-codes.ts +75 -0
  49. package/express/src/middlewares/auth-middleware.ts +1 -1
  50. package/express/src/modules/auth/__tests__/forgetpass.test.ts +200 -0
  51. package/express/src/modules/auth/__tests__/login.test.ts +171 -0
  52. package/express/src/modules/auth/__tests__/logout.test.ts +60 -0
  53. package/express/src/modules/auth/__tests__/logoutalldevices.test.ts +49 -0
  54. package/express/src/modules/auth/__tests__/me.test.ts +91 -0
  55. package/express/src/modules/auth/__tests__/refreshtoken.test.ts +305 -0
  56. package/express/src/modules/auth/__tests__/register.test.ts +291 -0
  57. package/express/src/modules/auth/__tests__/resetpass.test.ts +206 -0
  58. package/express/src/modules/auth/__tests__/verifyemail.test.ts +183 -0
  59. package/express/src/modules/auth/controllers/auth.ts +254 -0
  60. package/express/src/modules/auth/controllers/{role.controller.ts → role.ts} +25 -15
  61. package/{hono/src/modules/auth/database/models/notifications.ts → express/src/modules/auth/database/models/notification.ts} +1 -1
  62. package/express/src/modules/auth/database/models/role.ts +1 -1
  63. package/express/src/modules/auth/database/models/user.ts +1 -1
  64. package/express/src/modules/auth/facade.ts +12 -0
  65. package/express/src/modules/auth/{controllers/auth.helpers.ts → helpers/auth.ts} +3 -4
  66. package/express/src/modules/auth/jobs/registeruser.ts +23 -23
  67. package/express/src/modules/auth/routes/{api.ts → index.ts} +150 -150
  68. package/express/src/modules/auth/routes/role.ts +33 -33
  69. package/{hono/src/modules/auth/controllers/auth.schema.ts → express/src/modules/auth/schemas/auth.ts} +102 -102
  70. package/express/src/modules/auth/services/forgetpassword.ts +66 -0
  71. package/express/src/modules/auth/services/login.ts +63 -0
  72. package/express/src/modules/auth/services/logout.ts +25 -0
  73. package/express/src/modules/auth/services/logoutalldevices.ts +19 -0
  74. package/express/src/modules/auth/services/me.ts +31 -0
  75. package/express/src/modules/auth/services/refreshtoken.ts +110 -0
  76. package/express/src/modules/auth/services/register.ts +141 -0
  77. package/express/src/modules/auth/services/resetpassword.ts +69 -0
  78. package/express/src/modules/auth/services/verifyemail.ts +77 -0
  79. package/express/src/modules/auth/types/auth.ts +31 -0
  80. package/express/src/resources/src/assets/images/logo.png +0 -0
  81. package/express/src/resources/src/pages/auth/forgetPassword.vue +1 -0
  82. package/express/src/resources/src/pages/auth/login.vue +1 -1
  83. package/express/src/storage/database/nexwire.sqlite +0 -0
  84. package/hono/README.md +13 -7
  85. package/hono/package.json +1 -1
  86. package/hono/src/config/session.ts +1 -1
  87. package/hono/src/database/migrations/sqlite/meta/0000_snapshot.json +1 -1
  88. package/hono/src/database/migrations/sqlite/meta/_journal.json +1 -1
  89. package/hono/src/database/schema.ts +3 -3
  90. package/hono/src/framework/cache/cache.ts +82 -81
  91. package/hono/src/framework/database/seed.ts +1 -1
  92. package/hono/src/framework/http/app.ts +5 -5
  93. package/hono/src/framework/http/validation.ts +21 -21
  94. package/hono/src/framework/maker-cli/middleware/core.mjs +40 -46
  95. package/hono/src/framework/maker-cli/module/core.mjs +401 -168
  96. package/hono/src/framework/maker-cli/module/index.mjs +73 -11
  97. package/hono/src/framework/maker-cli/stubs/controller/openapi.ts.stub +28 -16
  98. package/hono/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +28 -17
  99. package/hono/src/framework/maker-cli/stubs/controller/plain.ts.stub +28 -16
  100. package/hono/src/framework/maker-cli/stubs/controller/standalone.ts.stub +56 -0
  101. package/hono/src/framework/maker-cli/stubs/facade/name.ts.stub +12 -0
  102. package/hono/src/framework/maker-cli/stubs/helper/name.ts.stub +14 -0
  103. package/hono/src/framework/maker-cli/stubs/middleware/name.local.ts.stub +15 -0
  104. package/hono/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -8
  105. package/hono/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -8
  106. package/hono/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -8
  107. package/hono/src/framework/maker-cli/stubs/notification/route.api.ts.stub +49 -49
  108. package/hono/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +11 -11
  109. package/hono/src/framework/maker-cli/stubs/route/api.ts.stub +93 -79
  110. package/hono/src/framework/maker-cli/stubs/route/plain.ts.stub +23 -10
  111. package/hono/src/framework/maker-cli/stubs/route/standalone.api.ts.stub +112 -0
  112. package/hono/src/framework/maker-cli/stubs/route/standalone.plain.ts.stub +37 -0
  113. package/hono/src/framework/maker-cli/stubs/{controller/schema.plain.ts.stub → schema/name.plain.ts.stub} +13 -13
  114. package/hono/src/framework/maker-cli/stubs/{controller/schema.ts.stub → schema/name.ts.stub} +32 -32
  115. package/hono/src/framework/maker-cli/stubs/service/name.plain.ts.stub +67 -0
  116. package/hono/src/framework/maker-cli/stubs/service/name.ts.stub +65 -0
  117. package/hono/src/framework/maker-cli/stubs/type/name.ts.stub +22 -0
  118. package/hono/src/framework/maker-cli/utils/naming.mjs +56 -13
  119. package/hono/src/framework/modules/discover.ts +57 -54
  120. package/hono/src/framework/notification/index.ts +1 -1
  121. package/hono/src/framework/realtime/broadcast.ts +46 -46
  122. package/hono/src/framework/server.ts +1 -1
  123. package/hono/src/framework/session/session.ts +121 -116
  124. package/hono/src/middlewares/auth-middleware.ts +1 -1
  125. package/hono/src/modules/auth/__tests__/forgetpass.test.ts +170 -0
  126. package/hono/src/modules/auth/__tests__/login.test.ts +154 -0
  127. package/hono/src/modules/auth/__tests__/logout.test.ts +53 -0
  128. package/hono/src/modules/auth/__tests__/logoutalldevices.test.ts +34 -0
  129. package/hono/src/modules/auth/__tests__/me.test.ts +87 -0
  130. package/hono/src/modules/auth/__tests__/refreshtoken.test.ts +305 -0
  131. package/hono/src/modules/auth/__tests__/register.test.ts +258 -0
  132. package/hono/src/modules/auth/__tests__/resetpass.test.ts +214 -0
  133. package/hono/src/modules/auth/__tests__/verifyemail.test.ts +189 -0
  134. package/hono/src/modules/auth/controllers/auth.ts +238 -0
  135. package/hono/src/modules/auth/controllers/{role.controller.ts → role.ts} +25 -25
  136. package/{express/src/modules/auth/database/models/notifications.ts → hono/src/modules/auth/database/models/notification.ts} +1 -1
  137. package/hono/src/modules/auth/database/models/role.ts +1 -1
  138. package/hono/src/modules/auth/database/models/user.ts +1 -1
  139. package/hono/src/modules/auth/facade.ts +12 -0
  140. package/hono/src/modules/auth/{controllers/auth.helpers.ts → helpers/auth.ts} +5 -6
  141. package/hono/src/modules/auth/jobs/registeruser.ts +23 -23
  142. package/hono/src/modules/auth/routes/{api.ts → index.ts} +150 -150
  143. package/hono/src/modules/auth/routes/role.ts +33 -33
  144. package/{express/src/modules/auth/controllers/auth.schema.ts → hono/src/modules/auth/schemas/auth.ts} +102 -102
  145. package/hono/src/modules/auth/services/forgetpassword.ts +58 -0
  146. package/hono/src/modules/auth/services/login.ts +61 -0
  147. package/hono/src/modules/auth/services/logout.ts +24 -0
  148. package/hono/src/modules/auth/services/logoutalldevices.ts +19 -0
  149. package/hono/src/modules/auth/services/me.ts +31 -0
  150. package/hono/src/modules/auth/services/refreshtoken.ts +110 -0
  151. package/hono/src/modules/auth/services/register.ts +132 -0
  152. package/hono/src/modules/auth/services/resetpassword.ts +69 -0
  153. package/hono/src/modules/auth/services/verifyemail.ts +77 -0
  154. package/hono/src/modules/auth/types/auth.ts +31 -0
  155. package/hono/src/resources/src/assets/images/logo.png +0 -0
  156. package/hono/src/storage/database/nexwire.sqlite +0 -0
  157. package/package.json +1 -1
  158. package/express/src/framework/maker-cli/stubs/example/console.ts.stub +0 -34
  159. package/express/src/framework/maker-cli/stubs/example/controller.ts.stub +0 -418
  160. package/express/src/framework/maker-cli/stubs/example/job.ts.stub +0 -75
  161. package/express/src/framework/maker-cli/stubs/example/route.api.ts.stub +0 -207
  162. package/express/src/framework/maker-cli/stubs/example/route.plain.ts.stub +0 -18
  163. package/express/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +0 -42
  164. package/express/src/framework/maker-cli/stubs/example/schema.ts.stub +0 -42
  165. package/express/src/modules/auth/controllers/auth.controller.ts +0 -358
  166. package/hono/src/framework/maker-cli/stubs/example/console.ts.stub +0 -34
  167. package/hono/src/framework/maker-cli/stubs/example/controller.ts.stub +0 -505
  168. package/hono/src/framework/maker-cli/stubs/example/job.ts.stub +0 -75
  169. package/hono/src/framework/maker-cli/stubs/example/route.api.ts.stub +0 -207
  170. package/hono/src/framework/maker-cli/stubs/example/route.plain.ts.stub +0 -18
  171. package/hono/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +0 -42
  172. package/hono/src/framework/maker-cli/stubs/example/schema.ts.stub +0 -42
  173. package/hono/src/modules/auth/controllers/auth.controller.ts +0 -413
@@ -1,54 +1,80 @@
1
1
  import type { Request, Response } from "express";
2
2
  import { HttpStatusCodes } from "@/framework/facade.js";
3
3
  import { validate } from "@/framework/facade.js";
4
- import { Create{{ClassName}}Schema, Update{{ClassName}}Schema, {{ClassName}}IdParamsSchema } from "@/modules/{{module}}/controllers/{{controller}}.schema.js";
4
+ import { Create{{ClassName}}Schema, Update{{ClassName}}Schema, {{ClassName}}IdParamsSchema } from "@/modules/{{module}}/schemas/{{controller}}.js";
5
+ import { {{controller}}Service } from "@/modules/{{module}}/services/{{controller}}.js";
5
6
 
6
7
  /**
7
- * Why: Returns collection response shape for list pages.
8
+ * Why: Returns every {{controller}} row for list screens.
8
9
  * When: Used by GET list endpoint.
9
10
  * Where: GET /{{controller}} route.
10
11
  */
11
12
  export const index = async (_req: Request, res: Response) => {
12
- res.json({ message: "{{controller}} list fetched successfully", data: [] });
13
+ const data = await {{controller}}Service.list();
14
+
15
+ res.json({ message: "{{controller}} list fetched successfully", data });
13
16
  };
14
17
 
15
18
  /**
16
- * Why: Returns one resource by validated route id.
19
+ * Why: Returns one {{controller}} row by validated route id.
17
20
  * When: Used by detail screens or fetch-by-id calls.
18
21
  * Where: GET /{{controller}}/{id} route.
19
22
  */
20
23
  export const show = async (req: Request, res: Response) => {
21
24
  const params = await validate({{ClassName}}IdParamsSchema, req.params);
22
- res.json({ message: "{{controller}} fetched successfully", data: { id: params.id, name: "" } });
25
+ const data = await {{controller}}Service.findOne(params.id);
26
+
27
+ if (!data) {
28
+ res.status(HttpStatusCodes.NOT_FOUND).json({ message: "{{controller}} not found" });
29
+ return;
30
+ }
31
+
32
+ res.json({ message: "{{controller}} fetched successfully", data });
23
33
  };
24
34
 
25
35
  /**
26
- * Why: Creates a new resource from validated request body.
36
+ * Why: Creates a new {{controller}} row from a validated request body.
27
37
  * When: Used by create form submissions.
28
38
  * Where: POST /{{controller}} route.
29
39
  */
30
40
  export const store = async (req: Request, res: Response) => {
31
- await validate(Create{{ClassName}}Schema, req.body);
32
- res.status(HttpStatusCodes.CREATED).json({ message: "{{controller}} created successfully" });
41
+ const body = await validate(Create{{ClassName}}Schema, req.body);
42
+ const data = await {{controller}}Service.create(body);
43
+
44
+ res.status(HttpStatusCodes.CREATED).json({ message: "{{controller}} created successfully", data });
33
45
  };
34
46
 
35
47
  /**
36
- * Why: Updates an existing resource using id + body validation.
48
+ * Why: Updates an existing {{controller}} row using id + body validation.
37
49
  * When: Used by edit/update form submissions.
38
50
  * Where: PUT/PATCH /{{controller}}/{id} route.
39
51
  */
40
52
  export const update = async (req: Request, res: Response) => {
41
- await validate({{ClassName}}IdParamsSchema, req.params);
42
- await validate(Update{{ClassName}}Schema, req.body);
43
- res.json({ message: "{{controller}} updated successfully" });
53
+ const params = await validate({{ClassName}}IdParamsSchema, req.params);
54
+ const body = await validate(Update{{ClassName}}Schema, req.body);
55
+ const data = await {{controller}}Service.update(params.id, body);
56
+
57
+ if (!data) {
58
+ res.status(HttpStatusCodes.NOT_FOUND).json({ message: "{{controller}} not found" });
59
+ return;
60
+ }
61
+
62
+ res.json({ message: "{{controller}} updated successfully", data });
44
63
  };
45
64
 
46
65
  /**
47
- * Why: Deletes one resource by validated route id.
66
+ * Why: Deletes one {{controller}} row by validated route id.
48
67
  * When: Used by delete actions.
49
68
  * Where: DELETE /{{controller}}/{id} route.
50
69
  */
51
70
  export const destroy = async (req: Request, res: Response) => {
52
- await validate({{ClassName}}IdParamsSchema, req.params);
53
- res.json({ message: "{{controller}} deleted successfully" });
54
- };
71
+ const params = await validate({{ClassName}}IdParamsSchema, req.params);
72
+ const data = await {{controller}}Service.remove(params.id);
73
+
74
+ if (!data) {
75
+ res.status(HttpStatusCodes.NOT_FOUND).json({ message: "{{controller}} not found" });
76
+ return;
77
+ }
78
+
79
+ res.json({ message: "{{controller}} deleted successfully", data });
80
+ };
@@ -0,0 +1,47 @@
1
+ import type { Request, Response } from "express";
2
+ import { HttpStatusCodes } from "@/framework/facade.js";
3
+
4
+ /**
5
+ * Why: Returns collection response shape for list pages.
6
+ * When: Used by GET list endpoint.
7
+ * Where: GET /{{controller}} route.
8
+ */
9
+ export const index = async (_req: Request, res: Response) => {
10
+ res.json({ message: "{{controller}} list fetched successfully", data: [] });
11
+ };
12
+
13
+ /**
14
+ * Why: Returns one resource by validated route id.
15
+ * When: Used by detail screens or fetch-by-id calls.
16
+ * Where: GET /{{controller}}/{id} route.
17
+ */
18
+ export const show = async (req: Request, res: Response) => {
19
+ res.json({ message: "{{controller}} fetched successfully", data: { id: req.params.id, name: "" } });
20
+ };
21
+
22
+ /**
23
+ * Why: Creates a new resource from validated request body.
24
+ * When: Used by create form submissions.
25
+ * Where: POST /{{controller}} route.
26
+ */
27
+ export const store = async (_req: Request, res: Response) => {
28
+ res.status(HttpStatusCodes.CREATED).json({ message: "{{controller}} created successfully" });
29
+ };
30
+
31
+ /**
32
+ * Why: Updates an existing resource using id + body validation.
33
+ * When: Used by edit/update form submissions.
34
+ * Where: PUT/PATCH /{{controller}}/{id} route.
35
+ */
36
+ export const update = async (_req: Request, res: Response) => {
37
+ res.json({ message: "{{controller}} updated successfully" });
38
+ };
39
+
40
+ /**
41
+ * Why: Deletes one resource by validated route id.
42
+ * When: Used by delete actions.
43
+ * Where: DELETE /{{controller}}/{id} route.
44
+ */
45
+ export const destroy = async (_req: Request, res: Response) => {
46
+ res.json({ message: "{{controller}} deleted successfully" });
47
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Public API for the {{module}} module.
3
+ *
4
+ * Other modules import from this file, never from controllers/ or services/ directly.
5
+ * Re-export the pieces they are allowed to depend on:
6
+ *
7
+ * export { list, findOne } from "./services/{{controller}}.js";
8
+ *
9
+ * Rule: a facade must never import another module's facade.
10
+ */
11
+
12
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Why: Reusable {{name}} logic that does not belong to a controller or service.
3
+ * When: Called by controllers, services, jobs, or other helpers.
4
+ * Where: src/modules/{{module}}/helpers/{{name}}.ts
5
+ */
6
+
7
+ /**
8
+ * Why: Placeholder shared helper.
9
+ * When: Replace this with real logic and rename it.
10
+ * Where: Anywhere inside the {{module}} module.
11
+ */
12
+ export function {{name}}Helper<T>(value: T): T {
13
+ return value;
14
+ }
@@ -0,0 +1,15 @@
1
+ import type { NextFunction, Request, Response } from "express";
2
+
3
+ /**
4
+ * Why: Route-scoped middleware for the {{module}} module.
5
+ * When: Attach to a route or route group inside routes/*.ts.
6
+ * Where: src/modules/{{module}}/middlewares/{{name}}.ts
7
+ *
8
+ * Register it in a route file:
9
+ * import { {{camel}}Middleware } from "@/modules/{{module}}/middlewares/{{name}}.js";
10
+ * router.get("/path", {{camel}}Middleware, handler);
11
+ */
12
+ export function {{camel}}Middleware(_req: Request, _res: Response, next: NextFunction) {
13
+ // Guard the route here, then continue the chain.
14
+ return next();
15
+ }
@@ -1,9 +1,10 @@
1
- import { relations } from "drizzle-orm";
2
- import { int, mysqlTable, timestamp } from "drizzle-orm/mysql-core";
3
-
4
- export const {{tableVariable}} = mysqlTable("{{tableName}}", {
5
- id: int("id").autoincrement().primaryKey(),
6
- createdAt: timestamp("created_at").defaultNow().notNull(),
7
- updatedAt: timestamp("updated_at").defaultNow().notNull()
8
- });
1
+ import { relations } from "drizzle-orm";
2
+ import { int, mysqlTable, timestamp, varchar } from "drizzle-orm/mysql-core";
3
+
4
+ export const {{tableVariable}} = mysqlTable("{{tableName}}", {
5
+ id: int("id").autoincrement().primaryKey(),
6
+ name: varchar("name", { length: 255 }).notNull(),
7
+ createdAt: timestamp("created_at").defaultNow().notNull(),
8
+ updatedAt: timestamp("updated_at").defaultNow().notNull()
9
+ });
9
10
 
@@ -1,9 +1,10 @@
1
- import { relations } from "drizzle-orm";
2
- import { pgTable, serial, timestamp } from "drizzle-orm/pg-core";
3
-
4
- export const {{tableVariable}} = pgTable("{{tableName}}", {
5
- id: serial("id").primaryKey(),
6
- createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
7
- updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull()
8
- });
1
+ import { relations } from "drizzle-orm";
2
+ import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
3
+
4
+ export const {{tableVariable}} = pgTable("{{tableName}}", {
5
+ id: serial("id").primaryKey(),
6
+ name: text("name").notNull(),
7
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
8
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull()
9
+ });
9
10
 
@@ -1,9 +1,10 @@
1
- import { relations } from "drizzle-orm";
2
- import { integer, sqliteTable } from "drizzle-orm/sqlite-core";
3
-
4
- export const {{tableVariable}} = sqliteTable("{{tableName}}", {
5
- id: integer("id").primaryKey({ autoIncrement: true }),
6
- createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()).notNull(),
7
- updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()).notNull()
8
- });
1
+ import { relations } from "drizzle-orm";
2
+ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
3
+
4
+ export const {{tableVariable}} = sqliteTable("{{tableName}}", {
5
+ id: integer("id").primaryKey({ autoIncrement: true }),
6
+ name: text("name").notNull(),
7
+ createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(() => new Date()).notNull(),
8
+ updatedAt: integer("updated_at", { mode: "timestamp" }).$defaultFn(() => new Date()).notNull()
9
+ });
9
10
 
@@ -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, markAllRead, markRead, remove, unreadCount } from "../controllers/{{module}}.controller.js";
4
- import { PaginatedNotificationsSchema, UnreadCountSchema } from "../controllers/{{module}}.schema.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
-
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
+
@@ -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}}.controller.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);
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 { requireRole } from "@/middlewares/role-middleware.js";
3
- import { destroy, index, show, store, update } from "@/modules/{{module}}/controllers/{{controller}}.controller.js";
4
- import {
5
- Create{{ClassName}}Schema,
6
- {{ClassName}}IdParamsSchema,
7
- {{ClassName}}ListResponseSchema,
8
- {{ClassName}}MessageSchema,
9
- {{ClassName}}ResponseSchema,
10
- Update{{ClassName}}Schema
11
- } from "@/modules/{{module}}/controllers/{{controller}}.schema.js";
12
-
13
- const indexRoute = createRoute({
14
- path: "/",
15
- method: "get",
16
- tags: ["{{ModuleClass}}"],
17
- responses: {
18
- [HttpStatusCodes.OK]: jsonContent({{ClassName}}ListResponseSchema, "{{module}} list")
19
- }
20
- });
21
-
22
- const showRoute = createRoute({
23
- path: "/{id}",
24
- method: "get",
25
- tags: ["{{ModuleClass}}"],
26
- request: {
27
- params: {{ClassName}}IdParamsSchema
28
- },
29
- responses: {
30
- [HttpStatusCodes.OK]: jsonContent({{ClassName}}ResponseSchema, "{{module}} item"),
31
- [HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
32
- }
33
- });
34
-
35
- const storeRoute = createRoute({
36
- path: "/",
37
- method: "post",
38
- tags: ["{{ModuleClass}}"],
39
- request: {
40
- body: jsonContent(Create{{ClassName}}Schema, "Create {{module}} payload")
41
- },
42
- responses: {
43
- [HttpStatusCodes.CREATED]: jsonContent({{ClassName}}MessageSchema, "Created")
44
- }
45
- });
46
-
47
- const updateRoute = createRoute({
48
- path: "/{id}",
49
- method: "put",
50
- tags: ["{{ModuleClass}}"],
51
- request: {
52
- params: {{ClassName}}IdParamsSchema,
53
- body: jsonContent(Update{{ClassName}}Schema, "Update {{module}} payload")
54
- },
55
- responses: {
56
- [HttpStatusCodes.OK]: jsonContent({{ClassName}}MessageSchema, "Updated"),
57
- [HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
58
- }
59
- });
60
-
61
- const destroyRoute = createRoute({
62
- path: "/{id}",
63
- method: "delete",
64
- tags: ["{{ModuleClass}}"],
65
- request: {
66
- params: {{ClassName}}IdParamsSchema
67
- },
68
- responses: {
69
- [HttpStatusCodes.OK]: jsonContent({{ClassName}}MessageSchema, "Deleted"),
70
- [HttpStatusCodes.NOT_FOUND]: jsonContent({{ClassName}}MessageSchema, "Not found")
71
- }
72
- });
73
-
74
- export default group()
75
- .api(indexRoute, index)
76
- .api(showRoute, show)
77
- .api(storeRoute, store)
78
- .api(updateRoute, update)
79
- .api(destroyRoute, destroy);
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 { requireRole } from "@/middlewares/role-middleware.js";
3
- import { index, show, store, update, destroy } from "@/modules/{{module}}/controllers/{{controller}}.controller.js";
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.