deploy-bbc 1.2.0 → 1.2.2

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 (242) hide show
  1. package/README.md +345 -0
  2. package/dist/index.js +16870 -0
  3. package/dist/templates/base/package.json +20 -0
  4. package/dist/templates/base/src/routes/index.ts +12 -0
  5. package/dist/templates/base/src/types/index.ts +2 -0
  6. package/dist/templates/base-bun-native/package.json +19 -0
  7. package/dist/templates/base-bun-native/src/index.ts +50 -0
  8. package/dist/templates/base-bun-native/src/routes/index.ts +21 -0
  9. package/dist/templates/base-bun-native/src/types/index.ts +2 -0
  10. package/dist/templates/base-express/package.json +21 -0
  11. package/dist/templates/base-express/src/routes/index.ts +12 -0
  12. package/dist/templates/base-express/src/types/index.ts +2 -0
  13. package/dist/templates/templates/base/.env.example +3 -0
  14. package/dist/templates/templates/base/README.md +31 -0
  15. package/dist/templates/templates/base/src/config/index.ts +8 -0
  16. package/dist/templates/templates/base/src/index.ts +26 -0
  17. package/dist/templates/templates/base/src/middleware/error.ts +13 -0
  18. package/dist/templates/templates/base/src/middleware/logger.ts +8 -0
  19. package/dist/templates/templates/base/src/utils/env.ts +5 -0
  20. package/dist/templates/templates/base/tsconfig.json +20 -0
  21. package/dist/templates/templates/base-bun-native/.env.example +3 -0
  22. package/dist/templates/templates/base-bun-native/README.md +31 -0
  23. package/dist/templates/templates/base-bun-native/src/config/index.ts +8 -0
  24. package/dist/templates/templates/base-bun-native/src/middleware/error.ts +20 -0
  25. package/dist/templates/templates/base-bun-native/src/middleware/logger.ts +6 -0
  26. package/dist/templates/templates/base-bun-native/src/utils/env.ts +5 -0
  27. package/dist/templates/templates/base-bun-native/tsconfig.json +20 -0
  28. package/dist/templates/templates/base-express/.env.example +3 -0
  29. package/dist/templates/templates/base-express/README.md +31 -0
  30. package/dist/templates/templates/base-express/src/config/index.ts +8 -0
  31. package/dist/templates/templates/base-express/src/index.ts +27 -0
  32. package/dist/templates/templates/base-express/src/middleware/error.ts +15 -0
  33. package/dist/templates/templates/base-express/src/middleware/logger.ts +12 -0
  34. package/dist/templates/templates/base-express/src/utils/env.ts +5 -0
  35. package/dist/templates/templates/base-express/tsconfig.json +20 -0
  36. package/dist/templates/templates/extras/ai/anthropic/src/services/ai/anthropic.ts +0 -0
  37. package/dist/templates/templates/extras/ai/gemini/src/services/ai/gemini.ts +0 -0
  38. package/dist/templates/templates/extras/ai/openai/src/routes/ai/chat.ts +0 -0
  39. package/dist/templates/templates/extras/ai/openai/src/services/ai/openai.ts +0 -0
  40. package/dist/templates/templates/extras/ai/vercel-ai/src/routes/ai/generate.ts +0 -0
  41. package/dist/templates/templates/extras/ai/vercel-ai/src/routes/ai/stream.ts +0 -0
  42. package/dist/templates/templates/extras/ai/vercel-ai/src/services/ai/index.ts +0 -0
  43. package/dist/templates/templates/extras/auth/jwt/src/middleware/auth.ts +0 -0
  44. package/dist/templates/templates/extras/auth/jwt/src/routes/auth.ts +0 -0
  45. package/dist/templates/templates/extras/auth/jwt/src/utils/jwt.ts +0 -0
  46. package/dist/templates/templates/extras/auth/oauth/src/config/oauth.ts +0 -0
  47. package/dist/templates/templates/extras/auth/oauth/src/routes/auth.ts +0 -0
  48. package/dist/templates/templates/extras/auth/session/src/config/session.ts +0 -0
  49. package/dist/templates/templates/extras/auth/session/src/middleware/session.ts +0 -0
  50. package/dist/templates/templates/extras/cloud/aws/src/services/aws/s3.ts +0 -0
  51. package/dist/templates/templates/extras/cloud/aws/src/services/aws/ses.ts +0 -0
  52. package/dist/templates/templates/extras/cloud/azure/src/services/azure/blob.ts +0 -0
  53. package/dist/templates/templates/extras/cloud/cloudflare-r2/src/services/cloudflare/r2.ts +0 -0
  54. package/dist/templates/templates/extras/cloud/gcp/src/services/gcp/storage.ts +0 -0
  55. package/dist/templates/templates/extras/database/mongodb/src/db/index.ts +0 -0
  56. package/dist/templates/templates/extras/database/mongodb/src/db/models/user.model.ts +0 -0
  57. package/dist/templates/templates/extras/database/mysql/drizzle.config.ts +0 -0
  58. package/dist/templates/templates/extras/database/postgres/src/db/index.ts +0 -0
  59. package/dist/templates/templates/extras/database/redis/src/db/redis.ts +0 -0
  60. package/dist/templates/templates/extras/docs/scalar/src/openapi/index.ts +0 -0
  61. package/dist/templates/templates/extras/docs/scalar/src/routes/docs.ts +0 -0
  62. package/dist/templates/templates/extras/docs/swagger/src/openapi/index.ts +0 -0
  63. package/dist/templates/templates/extras/docs/swagger/src/routes/docs.ts +0 -0
  64. package/dist/templates/templates/extras/email/nodemailer/src/services/email/nodemailer.ts +0 -0
  65. package/dist/templates/templates/extras/email/resend/src/services/email/resend.ts +0 -0
  66. package/dist/templates/templates/extras/email/resend/src/templates/email/welcome.ts +0 -0
  67. package/dist/templates/templates/extras/email/sendgrid/src/services/email/sendgrid.ts +0 -0
  68. package/dist/templates/templates/extras/observability/logtail/src/config/logger.ts +0 -0
  69. package/dist/templates/templates/extras/observability/sentry/src/config/sentry.ts +0 -0
  70. package/dist/templates/templates/extras/observability/sentry/src/middleware/sentry.ts +0 -0
  71. package/dist/templates/templates/extras/queue/bullmq/src/queue/index.ts +0 -0
  72. package/dist/templates/templates/extras/queue/bullmq/src/queue/jobs/email.job.ts +0 -0
  73. package/dist/templates/templates/extras/queue/bullmq/src/queue/processors/email.processor.ts +0 -0
  74. package/dist/templates/templates/extras/queue/bullmq/src/routes/queue.ts +0 -0
  75. package/dist/templates/templates/extras/queue/inngest/src/inngest/client.ts +0 -0
  76. package/dist/templates/templates/extras/queue/inngest/src/inngest/functions/email.ts +0 -0
  77. package/dist/templates/templates/extras/queue/inngest/src/routes/inngest.ts +0 -0
  78. package/dist/templates/templates/extras/realtime/socketio/src/socket/handlers.ts +0 -0
  79. package/dist/templates/templates/extras/realtime/socketio/src/socket/index.ts +0 -0
  80. package/dist/templates/templates/extras/realtime/sse/src/routes/sse.ts +0 -0
  81. package/dist/templates/templates/extras/testing/vitest/src/__tests__/example.test.ts +0 -0
  82. package/dist/templates/templates/extras/testing/vitest/src/__tests__/setup.ts +0 -0
  83. package/dist/templates/templates/extras/testing/vitest/vitest.config.ts +0 -0
  84. package/dist/templates/templates/extras/validation/yup/src/middleware/index.ts +1 -0
  85. package/dist/templates/templates/extras/validation/yup/src/middleware/validate.ts +83 -0
  86. package/dist/templates/templates/extras/validation/yup/src/routes/users.ts +132 -0
  87. package/dist/templates/templates/extras/validation/zod/src/middleware/index.ts +1 -0
  88. package/dist/templates/templates/extras/validation/zod/src/middleware/validate.ts +80 -0
  89. package/dist/templates/templates/extras/validation/zod/src/routes/users.ts +128 -0
  90. package/package.json +43 -9
  91. package/CLAUDE.md +0 -403
  92. package/cli/README.md +0 -345
  93. package/cli/package.json +0 -54
  94. package/cli/src/cli/index.ts +0 -454
  95. package/cli/src/helpers/create-project.ts +0 -66
  96. package/cli/src/helpers/generate-docker-compose.ts +0 -133
  97. package/cli/src/helpers/generate-dockerfile.ts +0 -45
  98. package/cli/src/helpers/init-git.ts +0 -33
  99. package/cli/src/helpers/install-dependencies.ts +0 -28
  100. package/cli/src/helpers/log-next-steps.ts +0 -87
  101. package/cli/src/helpers/scaffold-project.ts +0 -88
  102. package/cli/src/index.ts +0 -18
  103. package/cli/src/installers/ai.ts +0 -123
  104. package/cli/src/installers/auth.ts +0 -132
  105. package/cli/src/installers/base.ts +0 -16
  106. package/cli/src/installers/cloud.ts +0 -127
  107. package/cli/src/installers/database.ts +0 -212
  108. package/cli/src/installers/docs.ts +0 -93
  109. package/cli/src/installers/email.ts +0 -119
  110. package/cli/src/installers/env-variables.ts +0 -27
  111. package/cli/src/installers/index.ts +0 -145
  112. package/cli/src/installers/observability.ts +0 -103
  113. package/cli/src/installers/queue.ts +0 -103
  114. package/cli/src/installers/ratelimit.ts +0 -98
  115. package/cli/src/installers/realtime.ts +0 -79
  116. package/cli/src/installers/testing.ts +0 -88
  117. package/cli/src/installers/validation.ts +0 -85
  118. package/cli/src/types/index.ts +0 -126
  119. package/cli/src/utils/add-package-dependency.ts +0 -56
  120. package/cli/src/utils/dependency-version-map.ts +0 -85
  121. package/cli/src/utils/logger.ts +0 -19
  122. package/cli/src/utils/parse-name-and-path.ts +0 -71
  123. package/cli/src/utils/render-title.ts +0 -11
  124. package/cli/tsconfig.json +0 -35
  125. package/test-cli.sh +0 -56
  126. package/tsconfig.json +0 -15
  127. /package/{cli/src → dist}/templates/base/.env.example +0 -0
  128. /package/{cli/src → dist}/templates/base/README.md +0 -0
  129. /package/{cli/src → dist}/templates/base/src/config/index.ts +0 -0
  130. /package/{cli/src → dist}/templates/base/src/index.ts +0 -0
  131. /package/{cli/src → dist}/templates/base/src/middleware/error.ts +0 -0
  132. /package/{cli/src → dist}/templates/base/src/middleware/logger.ts +0 -0
  133. /package/{cli/src → dist}/templates/base/src/utils/env.ts +0 -0
  134. /package/{cli/src → dist}/templates/base/tsconfig.json +0 -0
  135. /package/{cli/src → dist}/templates/base-bun-native/.env.example +0 -0
  136. /package/{cli/src → dist}/templates/base-bun-native/README.md +0 -0
  137. /package/{cli/src → dist}/templates/base-bun-native/src/config/index.ts +0 -0
  138. /package/{cli/src → dist}/templates/base-bun-native/src/middleware/error.ts +0 -0
  139. /package/{cli/src → dist}/templates/base-bun-native/src/middleware/logger.ts +0 -0
  140. /package/{cli/src → dist}/templates/base-bun-native/src/utils/env.ts +0 -0
  141. /package/{cli/src → dist}/templates/base-bun-native/tsconfig.json +0 -0
  142. /package/{cli/src → dist}/templates/base-express/.env.example +0 -0
  143. /package/{cli/src → dist}/templates/base-express/README.md +0 -0
  144. /package/{cli/src → dist}/templates/base-express/src/config/index.ts +0 -0
  145. /package/{cli/src → dist}/templates/base-express/src/index.ts +0 -0
  146. /package/{cli/src → dist}/templates/base-express/src/middleware/error.ts +0 -0
  147. /package/{cli/src → dist}/templates/base-express/src/middleware/logger.ts +0 -0
  148. /package/{cli/src → dist}/templates/base-express/src/utils/env.ts +0 -0
  149. /package/{cli/src → dist}/templates/base-express/tsconfig.json +0 -0
  150. /package/{cli/src → dist}/templates/extras/ai/anthropic/src/routes/ai/claude.ts +0 -0
  151. /package/{cli/src → dist}/templates/extras/ai/anthropic/src/services/ai/anthropic.ts +0 -0
  152. /package/{cli/src → dist}/templates/extras/ai/gemini/src/services/ai/gemini.ts +0 -0
  153. /package/{cli/src → dist}/templates/extras/ai/openai/src/routes/ai/chat.ts +0 -0
  154. /package/{cli/src → dist}/templates/extras/ai/openai/src/services/ai/openai.ts +0 -0
  155. /package/{cli/src → dist}/templates/extras/ai/vercel-ai/src/routes/ai/generate.ts +0 -0
  156. /package/{cli/src → dist}/templates/extras/ai/vercel-ai/src/routes/ai/stream.ts +0 -0
  157. /package/{cli/src → dist}/templates/extras/ai/vercel-ai/src/services/ai/index.ts +0 -0
  158. /package/{cli/src → dist}/templates/extras/auth/jwt/src/middleware/auth.ts +0 -0
  159. /package/{cli/src → dist}/templates/extras/auth/jwt/src/routes/auth.ts +0 -0
  160. /package/{cli/src → dist}/templates/extras/auth/jwt/src/utils/jwt.ts +0 -0
  161. /package/{cli/src → dist}/templates/extras/auth/oauth/src/config/oauth.ts +0 -0
  162. /package/{cli/src → dist}/templates/extras/auth/oauth/src/routes/auth.ts +0 -0
  163. /package/{cli/src → dist}/templates/extras/auth/session/src/config/session.ts +0 -0
  164. /package/{cli/src → dist}/templates/extras/auth/session/src/middleware/session.ts +0 -0
  165. /package/{cli/src → dist}/templates/extras/cloud/aws/src/services/aws/s3.ts +0 -0
  166. /package/{cli/src → dist}/templates/extras/cloud/aws/src/services/aws/ses.ts +0 -0
  167. /package/{cli/src → dist}/templates/extras/cloud/azure/src/services/azure/blob.ts +0 -0
  168. /package/{cli/src → dist}/templates/extras/cloud/cloudflare-r2/src/services/cloudflare/r2.ts +0 -0
  169. /package/{cli/src → dist}/templates/extras/cloud/gcp/src/services/gcp/storage.ts +0 -0
  170. /package/{cli/src → dist}/templates/extras/database/mongodb/src/db/index.ts +0 -0
  171. /package/{cli/src → dist}/templates/extras/database/mongodb/src/db/models/user.model.ts +0 -0
  172. /package/{cli/src → dist}/templates/extras/database/mysql/drizzle.config.ts +0 -0
  173. /package/{cli/src → dist}/templates/extras/database/postgres/src/db/index.ts +0 -0
  174. /package/{cli/src → dist}/templates/extras/database/redis/src/db/redis.ts +0 -0
  175. /package/{cli/src → dist}/templates/extras/docs/scalar/src/openapi/index.ts +0 -0
  176. /package/{cli/src → dist}/templates/extras/docs/scalar/src/routes/docs.ts +0 -0
  177. /package/{cli/src → dist}/templates/extras/docs/swagger/src/openapi/index.ts +0 -0
  178. /package/{cli/src → dist}/templates/extras/docs/swagger/src/routes/docs.ts +0 -0
  179. /package/{cli/src → dist}/templates/extras/email/nodemailer/src/services/email/nodemailer.ts +0 -0
  180. /package/{cli/src → dist}/templates/extras/email/resend/src/services/email/resend.ts +0 -0
  181. /package/{cli/src → dist}/templates/extras/email/resend/src/templates/email/welcome.ts +0 -0
  182. /package/{cli/src → dist}/templates/extras/email/sendgrid/src/services/email/sendgrid.ts +0 -0
  183. /package/{cli/src → dist}/templates/extras/observability/logtail/src/config/logger.ts +0 -0
  184. /package/{cli/src → dist}/templates/extras/observability/sentry/src/config/sentry.ts +0 -0
  185. /package/{cli/src → dist}/templates/extras/observability/sentry/src/middleware/sentry.ts +0 -0
  186. /package/{cli/src → dist}/templates/extras/queue/bullmq/src/queue/index.ts +0 -0
  187. /package/{cli/src → dist}/templates/extras/queue/bullmq/src/queue/jobs/email.job.ts +0 -0
  188. /package/{cli/src → dist}/templates/extras/queue/bullmq/src/queue/processors/email.processor.ts +0 -0
  189. /package/{cli/src → dist}/templates/extras/queue/bullmq/src/routes/queue.ts +0 -0
  190. /package/{cli/src → dist}/templates/extras/queue/inngest/src/inngest/client.ts +0 -0
  191. /package/{cli/src → dist}/templates/extras/queue/inngest/src/inngest/functions/email.ts +0 -0
  192. /package/{cli/src → dist}/templates/extras/queue/inngest/src/routes/inngest.ts +0 -0
  193. /package/{cli/src → dist}/templates/extras/realtime/socketio/src/socket/handlers.ts +0 -0
  194. /package/{cli/src → dist}/templates/extras/realtime/socketio/src/socket/index.ts +0 -0
  195. /package/{cli/src → dist}/templates/extras/realtime/sse/src/routes/sse.ts +0 -0
  196. /package/{cli/src → dist}/templates/extras/testing/vitest/src/__tests__/example.test.ts +0 -0
  197. /package/{cli/src → dist}/templates/extras/testing/vitest/src/__tests__/setup.ts +0 -0
  198. /package/{cli/src → dist}/templates/extras/testing/vitest/vitest.config.ts +0 -0
  199. /package/{cli/src → dist}/templates/extras/validation/yup/src/middleware/index.ts +0 -0
  200. /package/{cli/src → dist}/templates/extras/validation/yup/src/middleware/validate.ts +0 -0
  201. /package/{cli/src → dist}/templates/extras/validation/yup/src/routes/users.ts +0 -0
  202. /package/{cli/src → dist}/templates/extras/validation/zod/src/middleware/index.ts +0 -0
  203. /package/{cli/src → dist}/templates/extras/validation/zod/src/middleware/validate.ts +0 -0
  204. /package/{cli/src → dist}/templates/extras/validation/zod/src/routes/users.ts +0 -0
  205. /package/{cli/src → dist/templates}/templates/base/package.json +0 -0
  206. /package/{cli/src → dist/templates}/templates/base/src/controllers/user/create-user.controller.ts +0 -0
  207. /package/{cli/src → dist/templates}/templates/base/src/controllers/user/delete-user.controller.ts +0 -0
  208. /package/{cli/src → dist/templates}/templates/base/src/controllers/user/get-user.controller.ts +0 -0
  209. /package/{cli/src → dist/templates}/templates/base/src/controllers/user/get-users.controller.ts +0 -0
  210. /package/{cli/src → dist/templates}/templates/base/src/controllers/user/update-user.controller.ts +0 -0
  211. /package/{cli/src → dist/templates}/templates/base/src/models/user.model.ts +0 -0
  212. /package/{cli/src → dist/templates}/templates/base/src/routes/index.ts +0 -0
  213. /package/{cli/src → dist/templates}/templates/base/src/routes/user.route.ts +0 -0
  214. /package/{cli/src → dist/templates}/templates/base/src/types/common/api-response.types.ts +0 -0
  215. /package/{cli/src → dist/templates}/templates/base/src/types/index.ts +0 -0
  216. /package/{cli/src → dist/templates}/templates/base/src/types/models/user.types.ts +0 -0
  217. /package/{cli/src → dist/templates}/templates/base-bun-native/package.json +0 -0
  218. /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/create-user.controller.ts +0 -0
  219. /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/delete-user.controller.ts +0 -0
  220. /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/get-user.controller.ts +0 -0
  221. /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/get-users.controller.ts +0 -0
  222. /package/{cli/src → dist/templates}/templates/base-bun-native/src/controllers/user/update-user.controller.ts +0 -0
  223. /package/{cli/src → dist/templates}/templates/base-bun-native/src/index.ts +0 -0
  224. /package/{cli/src → dist/templates}/templates/base-bun-native/src/models/user.model.ts +0 -0
  225. /package/{cli/src → dist/templates}/templates/base-bun-native/src/routes/index.ts +0 -0
  226. /package/{cli/src → dist/templates}/templates/base-bun-native/src/routes/user.route.ts +0 -0
  227. /package/{cli/src → dist/templates}/templates/base-bun-native/src/types/common/api-response.types.ts +0 -0
  228. /package/{cli/src → dist/templates}/templates/base-bun-native/src/types/index.ts +0 -0
  229. /package/{cli/src → dist/templates}/templates/base-bun-native/src/types/models/user.types.ts +0 -0
  230. /package/{cli/src → dist/templates}/templates/base-express/package.json +0 -0
  231. /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/create-user.controller.ts +0 -0
  232. /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/delete-user.controller.ts +0 -0
  233. /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/get-user.controller.ts +0 -0
  234. /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/get-users.controller.ts +0 -0
  235. /package/{cli/src → dist/templates}/templates/base-express/src/controllers/user/update-user.controller.ts +0 -0
  236. /package/{cli/src → dist/templates}/templates/base-express/src/models/user.model.ts +0 -0
  237. /package/{cli/src → dist/templates}/templates/base-express/src/routes/index.ts +0 -0
  238. /package/{cli/src → dist/templates}/templates/base-express/src/routes/user.route.ts +0 -0
  239. /package/{cli/src → dist/templates}/templates/base-express/src/types/common/api-response.types.ts +0 -0
  240. /package/{cli/src → dist/templates}/templates/base-express/src/types/index.ts +0 -0
  241. /package/{cli/src → dist/templates}/templates/base-express/src/types/models/user.types.ts +0 -0
  242. /package/{prettier.config.mjs → dist/templates/templates/extras/ai/anthropic/src/routes/ai/claude.ts} +0 -0
@@ -0,0 +1 @@
1
+ export { validate, get_validated, type ValidateTarget } from "./validate.js";
@@ -0,0 +1,83 @@
1
+ import { Context, Next } from "hono";
2
+ import * as yup from "yup";
3
+
4
+ /**
5
+ * Validation middleware for Hono using Yup schemas
6
+ * Validates request body, query parameters, or route params
7
+ */
8
+
9
+ export type ValidateTarget = "body" | "query" | "param";
10
+
11
+ interface ValidationOptions {
12
+ target: ValidateTarget;
13
+ schema: yup.AnySchema;
14
+ }
15
+
16
+ /**
17
+ * Create a validation middleware
18
+ * @param options - Validation configuration
19
+ * @returns Hono middleware function
20
+ */
21
+ export function validate(options: ValidationOptions) {
22
+ return async (c: Context, next: Next) => {
23
+ try {
24
+ let data: unknown;
25
+
26
+ switch (options.target) {
27
+ case "body":
28
+ data = await c.req.json();
29
+ break;
30
+ case "query":
31
+ data = c.req.query();
32
+ break;
33
+ case "param":
34
+ data = c.req.param();
35
+ break;
36
+ default:
37
+ return c.json(
38
+ { error: "Invalid validation target" },
39
+ 400
40
+ );
41
+ }
42
+
43
+ // Validate data against schema
44
+ const validated = await options.schema.validate(data, {
45
+ abortEarly: false,
46
+ stripUnknown: true,
47
+ });
48
+
49
+ // Store validated data in context for route handlers
50
+ c.set(`validated_${options.target}`, validated);
51
+
52
+ await next();
53
+ } catch (error) {
54
+ if (error instanceof yup.ValidationError) {
55
+ return c.json(
56
+ {
57
+ error: "Validation failed",
58
+ details: error.inner.map((err) => ({
59
+ path: err.path || "unknown",
60
+ message: err.message,
61
+ })),
62
+ },
63
+ 400
64
+ );
65
+ }
66
+
67
+ return c.json(
68
+ { error: "Invalid request data" },
69
+ 400
70
+ );
71
+ }
72
+ };
73
+ }
74
+
75
+ /**
76
+ * Helper to get validated data from context
77
+ * @param c - Hono context
78
+ * @param target - Validation target (body/query/param)
79
+ * @returns Validated data
80
+ */
81
+ export function get_validated<T>(c: Context, target: ValidateTarget): T {
82
+ return c.get(`validated_${target}`) as T;
83
+ }
@@ -0,0 +1,132 @@
1
+ import { Hono } from "hono";
2
+ import * as yup from "yup";
3
+ import { validate, get_validated } from "../middleware/validate.js";
4
+
5
+ const users = new Hono();
6
+
7
+ /**
8
+ * Yup Schemas for validation
9
+ */
10
+
11
+ // Schema for creating a new user
12
+ const create_user_schema = yup.object({
13
+ name: yup.string().required().min(2, "Name must be at least 2 characters"),
14
+ email: yup.string().required().email("Invalid email format"),
15
+ age: yup.number().integer().min(18, "Must be at least 18 years old").optional(),
16
+ });
17
+
18
+ // Schema for updating a user
19
+ const update_user_schema = yup.object({
20
+ name: yup.string().min(2).optional(),
21
+ email: yup.string().email().optional(),
22
+ age: yup.number().integer().min(18).optional(),
23
+ });
24
+
25
+ // Schema for query parameters
26
+ const list_users_query_schema = yup.object({
27
+ page: yup.number().transform((value, originalValue) => {
28
+ return originalValue ? parseInt(originalValue, 10) : undefined;
29
+ }).optional(),
30
+ limit: yup.number().transform((value, originalValue) => {
31
+ return originalValue ? parseInt(originalValue, 10) : undefined;
32
+ }).optional(),
33
+ search: yup.string().optional(),
34
+ });
35
+
36
+ // Schema for route params
37
+ const user_id_param_schema = yup.object({
38
+ id: yup.string().required().uuid("Invalid user ID format"),
39
+ });
40
+
41
+ /**
42
+ * Routes with validation
43
+ */
44
+
45
+ // GET /users - List users with query validation
46
+ users.get(
47
+ "/",
48
+ validate({ target: "query", schema: list_users_query_schema }),
49
+ (c) => {
50
+ const query = get_validated<yup.InferType<typeof list_users_query_schema>>(c, "query");
51
+
52
+ return c.json({
53
+ users: [],
54
+ pagination: {
55
+ page: query.page || 1,
56
+ limit: query.limit || 10,
57
+ search: query.search,
58
+ },
59
+ });
60
+ }
61
+ );
62
+
63
+ // POST /users - Create user with body validation
64
+ users.post(
65
+ "/",
66
+ validate({ target: "body", schema: create_user_schema }),
67
+ (c) => {
68
+ const body = get_validated<yup.InferType<typeof create_user_schema>>(c, "body");
69
+
70
+ // Your database logic here
71
+ const new_user = {
72
+ id: crypto.randomUUID(),
73
+ ...body,
74
+ created_at: new Date().toISOString(),
75
+ };
76
+
77
+ return c.json(new_user, 201);
78
+ }
79
+ );
80
+
81
+ // GET /users/:id - Get user by ID with param validation
82
+ users.get(
83
+ "/:id",
84
+ validate({ target: "param", schema: user_id_param_schema }),
85
+ (c) => {
86
+ const params = get_validated<yup.InferType<typeof user_id_param_schema>>(c, "param");
87
+
88
+ // Your database logic here
89
+ const user = {
90
+ id: params.id,
91
+ name: "John Doe",
92
+ email: "john@example.com",
93
+ };
94
+
95
+ return c.json(user);
96
+ }
97
+ );
98
+
99
+ // PATCH /users/:id - Update user with param + body validation
100
+ users.patch(
101
+ "/:id",
102
+ validate({ target: "param", schema: user_id_param_schema }),
103
+ validate({ target: "body", schema: update_user_schema }),
104
+ (c) => {
105
+ const params = get_validated<yup.InferType<typeof user_id_param_schema>>(c, "param");
106
+ const body = get_validated<yup.InferType<typeof update_user_schema>>(c, "body");
107
+
108
+ // Your database logic here
109
+ const updated_user = {
110
+ id: params.id,
111
+ ...body,
112
+ updated_at: new Date().toISOString(),
113
+ };
114
+
115
+ return c.json(updated_user);
116
+ }
117
+ );
118
+
119
+ // DELETE /users/:id
120
+ users.delete(
121
+ "/:id",
122
+ validate({ target: "param", schema: user_id_param_schema }),
123
+ (c) => {
124
+ const params = get_validated<yup.InferType<typeof user_id_param_schema>>(c, "param");
125
+
126
+ return c.json({
127
+ message: `User ${params.id} deleted successfully`,
128
+ });
129
+ }
130
+ );
131
+
132
+ export default users;
@@ -0,0 +1 @@
1
+ export { validate, get_validated, type ValidateTarget } from "./validate.js";
@@ -0,0 +1,80 @@
1
+ import { Context, Next } from "hono";
2
+ import { z, ZodSchema } from "zod";
3
+
4
+ /**
5
+ * Validation middleware for Hono using Zod schemas
6
+ * Validates request body, query parameters, or route params
7
+ */
8
+
9
+ export type ValidateTarget = "body" | "query" | "param";
10
+
11
+ interface ValidationOptions {
12
+ target: ValidateTarget;
13
+ schema: ZodSchema;
14
+ }
15
+
16
+ /**
17
+ * Create a validation middleware
18
+ * @param options - Validation configuration
19
+ * @returns Hono middleware function
20
+ */
21
+ export function validate(options: ValidationOptions) {
22
+ return async (c: Context, next: Next) => {
23
+ try {
24
+ let data: unknown;
25
+
26
+ switch (options.target) {
27
+ case "body":
28
+ data = await c.req.json();
29
+ break;
30
+ case "query":
31
+ data = c.req.query();
32
+ break;
33
+ case "param":
34
+ data = c.req.param();
35
+ break;
36
+ default:
37
+ return c.json(
38
+ { error: "Invalid validation target" },
39
+ 400
40
+ );
41
+ }
42
+
43
+ // Validate data against schema
44
+ const validated = options.schema.parse(data);
45
+
46
+ // Store validated data in context for route handlers
47
+ c.set(`validated_${options.target}`, validated);
48
+
49
+ await next();
50
+ } catch (error) {
51
+ if (error instanceof z.ZodError) {
52
+ return c.json(
53
+ {
54
+ error: "Validation failed",
55
+ details: error.errors.map((err) => ({
56
+ path: err.path.join("."),
57
+ message: err.message,
58
+ })),
59
+ },
60
+ 400
61
+ );
62
+ }
63
+
64
+ return c.json(
65
+ { error: "Invalid request data" },
66
+ 400
67
+ );
68
+ }
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Helper to get validated data from context
74
+ * @param c - Hono context
75
+ * @param target - Validation target (body/query/param)
76
+ * @returns Validated data
77
+ */
78
+ export function get_validated<T>(c: Context, target: ValidateTarget): T {
79
+ return c.get(`validated_${target}`) as T;
80
+ }
@@ -0,0 +1,128 @@
1
+ import { Hono } from "hono";
2
+ import { z } from "zod";
3
+ import { validate, get_validated } from "../middleware/validate.js";
4
+
5
+ const users = new Hono();
6
+
7
+ /**
8
+ * Zod Schemas for validation
9
+ */
10
+
11
+ // Schema for creating a new user
12
+ const create_user_schema = z.object({
13
+ name: z.string().min(2, "Name must be at least 2 characters"),
14
+ email: z.string().email("Invalid email format"),
15
+ age: z.number().int().min(18, "Must be at least 18 years old").optional(),
16
+ });
17
+
18
+ // Schema for updating a user
19
+ const update_user_schema = z.object({
20
+ name: z.string().min(2).optional(),
21
+ email: z.string().email().optional(),
22
+ age: z.number().int().min(18).optional(),
23
+ });
24
+
25
+ // Schema for query parameters
26
+ const list_users_query_schema = z.object({
27
+ page: z.string().regex(/^\d+$/).transform(Number).optional(),
28
+ limit: z.string().regex(/^\d+$/).transform(Number).optional(),
29
+ search: z.string().optional(),
30
+ });
31
+
32
+ // Schema for route params
33
+ const user_id_param_schema = z.object({
34
+ id: z.string().uuid("Invalid user ID format"),
35
+ });
36
+
37
+ /**
38
+ * Routes with validation
39
+ */
40
+
41
+ // GET /users - List users with query validation
42
+ users.get(
43
+ "/",
44
+ validate({ target: "query", schema: list_users_query_schema }),
45
+ (c) => {
46
+ const query = get_validated<z.infer<typeof list_users_query_schema>>(c, "query");
47
+
48
+ return c.json({
49
+ users: [],
50
+ pagination: {
51
+ page: query.page || 1,
52
+ limit: query.limit || 10,
53
+ search: query.search,
54
+ },
55
+ });
56
+ }
57
+ );
58
+
59
+ // POST /users - Create user with body validation
60
+ users.post(
61
+ "/",
62
+ validate({ target: "body", schema: create_user_schema }),
63
+ (c) => {
64
+ const body = get_validated<z.infer<typeof create_user_schema>>(c, "body");
65
+
66
+ // Your database logic here
67
+ const new_user = {
68
+ id: crypto.randomUUID(),
69
+ ...body,
70
+ created_at: new Date().toISOString(),
71
+ };
72
+
73
+ return c.json(new_user, 201);
74
+ }
75
+ );
76
+
77
+ // GET /users/:id - Get user by ID with param validation
78
+ users.get(
79
+ "/:id",
80
+ validate({ target: "param", schema: user_id_param_schema }),
81
+ (c) => {
82
+ const params = get_validated<z.infer<typeof user_id_param_schema>>(c, "param");
83
+
84
+ // Your database logic here
85
+ const user = {
86
+ id: params.id,
87
+ name: "John Doe",
88
+ email: "john@example.com",
89
+ };
90
+
91
+ return c.json(user);
92
+ }
93
+ );
94
+
95
+ // PATCH /users/:id - Update user with param + body validation
96
+ users.patch(
97
+ "/:id",
98
+ validate({ target: "param", schema: user_id_param_schema }),
99
+ validate({ target: "body", schema: update_user_schema }),
100
+ (c) => {
101
+ const params = get_validated<z.infer<typeof user_id_param_schema>>(c, "param");
102
+ const body = get_validated<z.infer<typeof update_user_schema>>(c, "body");
103
+
104
+ // Your database logic here
105
+ const updated_user = {
106
+ id: params.id,
107
+ ...body,
108
+ updated_at: new Date().toISOString(),
109
+ };
110
+
111
+ return c.json(updated_user);
112
+ }
113
+ );
114
+
115
+ // DELETE /users/:id
116
+ users.delete(
117
+ "/:id",
118
+ validate({ target: "param", schema: user_id_param_schema }),
119
+ (c) => {
120
+ const params = get_validated<z.infer<typeof user_id_param_schema>>(c, "param");
121
+
122
+ return c.json({
123
+ message: `User ${params.id} deleted successfully`,
124
+ });
125
+ }
126
+ );
127
+
128
+ export default users;
package/package.json CHANGED
@@ -1,20 +1,54 @@
1
1
  {
2
2
  "name": "deploy-bbc",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "CLI to bootstrap production-ready backends with Bun (Best Backend Code)",
5
- "workspaces": [
6
- "cli"
5
+ "type": "module",
6
+ "bin": {
7
+ "deploy-bbc": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
7
11
  ],
12
+ "engines": {
13
+ "node": ">=18.0.0"
14
+ },
8
15
  "scripts": {
9
- "dev": "bun --watch cli/src/index.ts",
10
- "build": "cd cli && bun run build",
11
- "lint": "eslint . --ext .ts",
12
- "format": "prettier --write \"**/*.{ts,json,md}\""
16
+ "dev": "bun --watch src/index.ts",
17
+ "build": "bun build src/index.ts --outdir dist --target node && cp -r src/templates dist/templates",
18
+ "prepublishOnly": "bun run build",
19
+ "start": "node dist/index.js",
20
+ "type-check": "tsc --noEmit"
21
+ },
22
+ "keywords": [
23
+ "backend",
24
+ "bun",
25
+ "typescript",
26
+ "cli",
27
+ "boilerplate",
28
+ "api"
29
+ ],
30
+ "author": "Aritra Sarkar <aritrasarkar2002@gmail.com>",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/aritra69/deploy-bbc.git"
35
+ },
36
+ "homepage": "https://github.com/aritra69/deploy-bbc#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/aritra69/deploy-bbc/issues"
39
+ },
40
+ "dependencies": {
41
+ "@clack/prompts": "^0.11.0",
42
+ "chalk": "^5.6.2",
43
+ "commander": "^14.0.2",
44
+ "execa": "^9.6.1",
45
+ "fs-extra": "^11.3.3",
46
+ "ora": "^9.1.0"
13
47
  },
14
48
  "devDependencies": {
15
49
  "@types/bun": "latest",
16
- "bun-types": "^1.3.7",
17
- "prettier": "^3.8.1",
50
+ "@types/fs-extra": "^11.0.4",
51
+ "@types/node": "^25.0.10",
18
52
  "typescript": "^5.9.3"
19
53
  }
20
54
  }