@batijs/cli 0.0.259 → 0.0.261

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 (104) hide show
  1. package/dist/boilerplates/@batijs/authjs/files/$package.json.js +1 -1
  2. package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +2 -2
  3. package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +2 -3
  4. package/dist/boilerplates/@batijs/aws/files/$README.md.js +109 -0
  5. package/dist/boilerplates/@batijs/aws/files/$package.json.js +138 -0
  6. package/dist/boilerplates/@batijs/aws/files/$tsconfig.json.js +15 -0
  7. package/dist/boilerplates/@batijs/aws/files/cdk/$stack-name-suffix.json.js +19 -0
  8. package/dist/boilerplates/@batijs/aws/files/cdk/bin/infrastructure.ts +85 -0
  9. package/dist/boilerplates/@batijs/aws/files/cdk/lib/vike-stack.ts +186 -0
  10. package/dist/boilerplates/@batijs/aws/files/cdk.json +72 -0
  11. package/dist/boilerplates/@batijs/aws/files/tests/aws_handler.spec.ts +116 -0
  12. package/dist/boilerplates/@batijs/aws/files/vitest.config.ts +8 -0
  13. package/dist/boilerplates/@batijs/aws/types/cdk/bin/infrastructure.d.ts +11 -0
  14. package/dist/boilerplates/@batijs/aws/types/cdk/lib/vike-stack.d.ts +13 -0
  15. package/dist/boilerplates/@batijs/aws/types/vitest.config.d.ts +2 -0
  16. package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +1 -1
  17. package/dist/boilerplates/@batijs/cloudflare/files/$tsconfig.json.js +10 -0
  18. package/dist/boilerplates/@batijs/d1/files/$README.md.js +0 -4
  19. package/dist/boilerplates/@batijs/d1/files/$package.json.js +96 -0
  20. package/dist/boilerplates/@batijs/d1/files/$wrangler.toml.js +1 -0
  21. package/dist/boilerplates/@batijs/d1/files/database/d1/helpers.ts +17 -0
  22. package/dist/boilerplates/@batijs/d1/files/vike.d.ts +8 -0
  23. package/dist/boilerplates/@batijs/d1/types/database/d1/helpers.d.ts +6 -0
  24. package/dist/boilerplates/@batijs/d1-sqlite/files/$package.json.js +10 -0
  25. package/dist/boilerplates/@batijs/d1-sqlite/files/database/d1/queries/lucia-auth.ts +28 -0
  26. package/dist/boilerplates/@batijs/d1-sqlite/files/database/d1/queries/todos.ts +10 -0
  27. package/dist/boilerplates/@batijs/d1-sqlite/files/database/migrations/lucia-auth.sql +20 -0
  28. package/dist/boilerplates/@batijs/d1-sqlite/files/database/migrations/todos.sql +4 -0
  29. package/dist/boilerplates/@batijs/d1-sqlite/types/database/d1/queries/lucia-auth.d.ts +5 -0
  30. package/dist/boilerplates/@batijs/d1-sqlite/types/database/d1/queries/todos.d.ts +6 -0
  31. package/dist/boilerplates/@batijs/drizzle/files/$.env.js +1 -0
  32. package/dist/boilerplates/@batijs/drizzle/files/$README.md.js +0 -3
  33. package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +7 -14
  34. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +10 -12
  35. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/lucia-auth.ts +38 -9
  36. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +16 -5
  37. package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +7 -4
  38. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.ts +2 -2
  39. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/lucia-auth.d.ts +19 -6
  40. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.ts +9 -2
  41. package/dist/boilerplates/@batijs/eslint/files/$package.json.js +1 -1
  42. package/dist/boilerplates/@batijs/eslint/files/eslint.config.js +2 -1
  43. package/dist/boilerplates/@batijs/express/files/$package.json.js +2 -1
  44. package/dist/boilerplates/@batijs/express/files/express-entry.ts +13 -12
  45. package/dist/boilerplates/@batijs/fastify/files/$package.json.js +2 -1
  46. package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +17 -24
  47. package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +2 -2
  48. package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +2 -2
  49. package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +2 -6
  50. package/dist/boilerplates/@batijs/h3/files/$package.json.js +1 -0
  51. package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +12 -2
  52. package/dist/boilerplates/@batijs/hattip/files/$package.json.js +15 -2
  53. package/dist/boilerplates/@batijs/hattip/files/entry_aws_lambda.ts +37 -0
  54. package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +12 -12
  55. package/dist/boilerplates/@batijs/hattip/types/entry_aws_lambda.d.ts +2 -0
  56. package/dist/boilerplates/@batijs/hono/files/$package.json.js +22 -4
  57. package/dist/boilerplates/@batijs/hono/files/entry_aws_lambda.ts +37 -0
  58. package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +12 -12
  59. package/dist/boilerplates/@batijs/hono/types/entry_aws_lambda.d.ts +3 -0
  60. package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +4 -1
  61. package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +75 -39
  62. package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +77 -33
  63. package/dist/boilerplates/@batijs/lucia-auth/types/lib/lucia-auth.d.ts +30 -10
  64. package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +13 -13
  65. package/dist/boilerplates/@batijs/react-lucia-auth/files/pages/login/+Page.tsx +2 -1
  66. package/dist/boilerplates/@batijs/shared/files/vite.config.ts +6 -0
  67. package/dist/boilerplates/@batijs/shared-db/files/server/db-middleware.ts +37 -0
  68. package/dist/boilerplates/@batijs/shared-db/types/server/db-middleware.d.ts +17 -0
  69. package/dist/boilerplates/@batijs/shared-no-db/files/$package.json.js +2 -1
  70. package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +5 -2
  71. package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +22 -4
  72. package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +2 -2
  73. package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.ts +19 -1
  74. package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +10 -4
  75. package/dist/boilerplates/@batijs/shared-todo/files/vike.d.ts +19 -0
  76. package/dist/boilerplates/@batijs/shared-todo/types/pages/todo/+data.d.ts +2 -1
  77. package/dist/boilerplates/@batijs/solid-lucia-auth/files/pages/login/+Page.tsx +2 -1
  78. package/dist/boilerplates/@batijs/sqlite/files/$.env.js +1 -0
  79. package/dist/boilerplates/@batijs/sqlite/files/$package.json.js +10 -1
  80. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/lucia-auth.ts +16 -15
  81. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/todos.ts +5 -5
  82. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/lucia-auth.d.ts +5 -5
  83. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/todos.d.ts +3 -2
  84. package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +5 -3
  85. package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +10 -3
  86. package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +15 -2
  87. package/dist/boilerplates/@batijs/telefunc/files/vike.d.ts +20 -0
  88. package/dist/boilerplates/@batijs/trpc/files/$package.json.js +10 -7
  89. package/dist/boilerplates/@batijs/trpc/files/server/trpc-handler.ts +22 -0
  90. package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +20 -4
  91. package/dist/boilerplates/@batijs/trpc/types/server/trpc-handler.d.ts +1 -0
  92. package/dist/boilerplates/@batijs/trpc/types/trpc/client.d.ts +36 -4
  93. package/dist/boilerplates/@batijs/trpc/types/trpc/server.d.ts +75 -8
  94. package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +4 -3
  95. package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +48 -27
  96. package/dist/boilerplates/@batijs/vue-lucia-auth/files/pages/login/+Page.vue +2 -1
  97. package/dist/boilerplates/boilerplates.json +61 -3
  98. package/dist/index.js +6 -1
  99. package/package.json +5 -5
  100. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/seed.ts +0 -13
  101. package/dist/boilerplates/@batijs/trpc/files/$vite.config.ts.js +0 -13
  102. package/dist/boilerplates/@batijs/trpc/files/trpc/vite-plugin.ts +0 -49
  103. package/dist/boilerplates/@batijs/trpc/types/trpc/vite-plugin.d.ts +0 -12
  104. /package/dist/boilerplates/@batijs/{drizzle/types/database/drizzle/seed.d.ts → aws/types/tests/aws_handler.spec.d.ts} +0 -0
@@ -1,2 +1,2 @@
1
- import { type BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
2
- export declare function db(): BetterSQLite3Database;
1
+ export declare function dbSqlite(): import("drizzle-orm/better-sqlite3").BetterSQLite3Database<Record<string, never>>;
2
+ export declare function dbD1(d1: D1Database): import("drizzle-orm/d1").DrizzleD1Database<Record<string, never>>;
@@ -1,12 +1,25 @@
1
- export declare function getExistingUser(username: string): {
1
+ import { dbD1, dbSqlite } from "../db";
2
+ export declare function getExistingUser(db: BATI.If<{
3
+ "!BATI.hasD1": ReturnType<typeof dbSqlite>;
4
+ _: ReturnType<typeof dbD1>;
5
+ }>, username: string): Promise<{
2
6
  id: string;
3
7
  username: string;
4
8
  password: string | null;
5
- } | undefined;
6
- export declare function getExistingAccount(providerId: string, providerUserId: number): {
9
+ } | undefined>;
10
+ export declare function getExistingAccount(db: BATI.If<{
11
+ "!BATI.hasD1": ReturnType<typeof dbSqlite>;
12
+ _: ReturnType<typeof dbD1>;
13
+ }>, providerId: string, providerUserId: number): Promise<{
7
14
  providerId: string;
8
15
  providerUserId: number;
9
16
  userId: string;
10
- } | undefined;
11
- export declare function signupWithGithub(userId: string, username: string, githubUserId: number): Promise<void>;
12
- export declare function signupWithCredentials(userId: string, username: string, passwordHash: string): import("better-sqlite3").RunResult;
17
+ } | undefined>;
18
+ export declare function signupWithGithub(db: BATI.If<{
19
+ "!BATI.hasD1": ReturnType<typeof dbSqlite>;
20
+ _: ReturnType<typeof dbD1>;
21
+ }>, userId: string, username: string, githubUserId: number): Promise<void>;
22
+ export declare function signupWithCredentials(db: BATI.If<{
23
+ "!BATI.hasD1": ReturnType<typeof dbSqlite>;
24
+ _: ReturnType<typeof dbD1>;
25
+ }>, userId: string, username: string, passwordHash: string): Promise<import("better-sqlite3").RunResult>;
@@ -1,4 +1,8 @@
1
- export declare function insertTodo(text: string): import("drizzle-orm/sqlite-core").SQLiteInsertBase<import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
1
+ import { dbD1, type dbSqlite } from "../db";
2
+ export declare function insertTodo(db: BATI.If<{
3
+ "!BATI.hasD1": ReturnType<typeof dbSqlite>;
4
+ _: ReturnType<typeof dbD1>;
5
+ }>, text: string): import("drizzle-orm/sqlite-core").SQLiteInsertBase<import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2
6
  name: "todos";
3
7
  schema: undefined;
4
8
  columns: {
@@ -37,7 +41,10 @@ export declare function insertTodo(text: string): import("drizzle-orm/sqlite-cor
37
41
  };
38
42
  dialect: "sqlite";
39
43
  }>, "sync", import("better-sqlite3").RunResult, undefined, false, never>;
40
- export declare function getAllTodos(): {
44
+ export declare function getAllTodos(db: BATI.If<{
45
+ "!BATI.hasD1": ReturnType<typeof dbSqlite>;
46
+ _: ReturnType<typeof dbD1>;
47
+ }>): {
41
48
  id: number;
42
49
  text: string;
43
50
  }[];
@@ -47,7 +47,7 @@ var require_package = __commonJS({
47
47
  "eslint-config-prettier": "^9.1.0",
48
48
  "eslint-plugin-prettier": "^5.2.1",
49
49
  "eslint-plugin-react": "^7.35.0",
50
- "eslint-plugin-solid": "^0.14.2",
50
+ "eslint-plugin-solid": "^0.14.3",
51
51
  "eslint-plugin-vue": "^9.27.0",
52
52
  globals: "^15.9.0",
53
53
  "typescript-eslint": "^8.3.0",
@@ -3,7 +3,7 @@
3
3
  import eslint from "@eslint/js";
4
4
  import prettier from "eslint-plugin-prettier/recommended";
5
5
  import react from "eslint-plugin-react/configs/recommended.js";
6
- import solid from "eslint-plugin-solid/dist/configs/typescript.js";
6
+ import solid from "eslint-plugin-solid/configs/typescript";
7
7
  import pluginVue from "eslint-plugin-vue";
8
8
  import globals from "globals";
9
9
  import tseslint from "typescript-eslint";
@@ -41,6 +41,7 @@ export default tseslint.config(
41
41
  argsIgnorePattern: "^_",
42
42
  },
43
43
  ],
44
+ "@typescript-eslint/no-namespace": 0,
44
45
  },
45
46
  },
46
47
  //# BATI.has("vue")
@@ -48,6 +48,7 @@ var require_package = __commonJS({
48
48
  "@batijs/lucia-auth": "workspace:*",
49
49
  "@batijs/shared-server": "workspace:^",
50
50
  "@batijs/shared-todo": "workspace:^",
51
+ "@batijs/shared-db": "workspace:^",
51
52
  "@batijs/telefunc": "workspace:*",
52
53
  "@batijs/trpc": "workspace:*",
53
54
  "@batijs/ts-rest": "workspace:*",
@@ -55,7 +56,7 @@ var require_package = __commonJS({
55
56
  "@types/cookie-parser": "^1.4.7",
56
57
  "@types/express": "^4.17.21",
57
58
  "@types/node": "^18.19.14",
58
- "@universal-middleware/express": "^0.2.2",
59
+ "@universal-middleware/express": "^0.2.3",
59
60
  "cookie-parser": "^1.4.6",
60
61
  "cross-env": "^7.0.3",
61
62
  dotenv: "^16.4.5",
@@ -15,17 +15,18 @@ import {
15
15
  luciaAuthLogoutHandler,
16
16
  luciaAuthSignupHandler,
17
17
  luciaCsrfMiddleware,
18
+ luciaDbMiddleware,
18
19
  luciaGithubCallbackHandler,
19
20
  luciaGithubLoginHandler,
20
21
  } from "@batijs/lucia-auth/server/lucia-auth-handlers";
21
22
  import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
22
23
  import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
23
24
  import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
24
- import { appRouter } from "@batijs/trpc/trpc/server";
25
25
  import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
26
- import * as trpcExpress from "@trpc/server/adapters/express";
27
26
  import { createHandler, createMiddleware } from "@universal-middleware/express";
27
+ import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
28
28
  import express from "express";
29
+ import { trpcHandler } from "@batijs/trpc/server/trpc-handler";
29
30
 
30
31
  const __filename = fileURLToPath(import.meta.url);
31
32
  const __dirname = dirname(__filename);
@@ -54,6 +55,13 @@ async function startServer() {
54
55
  app.use(viteDevMiddleware);
55
56
  }
56
57
 
58
+ if (BATI.hasDatabase) {
59
+ /**
60
+ * Make database available in Context as `context.db`
61
+ */
62
+ app.use(createMiddleware(dbMiddleware)());
63
+ }
64
+
57
65
  if (BATI.has("authjs") || BATI.has("auth0")) {
58
66
  /**
59
67
  * Append Auth.js session to context
@@ -74,6 +82,7 @@ async function startServer() {
74
82
  }
75
83
 
76
84
  if (BATI.has("lucia-auth")) {
85
+ app.use(createMiddleware(luciaDbMiddleware)());
77
86
  app.use(createMiddleware(luciaCsrfMiddleware)());
78
87
  app.use(createMiddleware(luciaAuthContextMiddleware)());
79
88
  app.use(createMiddleware(luciaAuthCookieMiddleware)());
@@ -89,17 +98,9 @@ async function startServer() {
89
98
  /**
90
99
  * tRPC route
91
100
  *
92
- * @link {@see https://trpc.io/docs/server/adapters/express#3-use-the-express-adapter}
101
+ * @link {@see https://trpc.io/docs/server/adapters/fetch}
93
102
  **/
94
- app.use(
95
- "/api/trpc",
96
- trpcExpress.createExpressMiddleware({
97
- router: appRouter,
98
- createContext({ req, res }: trpcExpress.CreateExpressContextOptions) {
99
- return { req, res };
100
- },
101
- }),
102
- );
103
+ app.use("/api/trpc", createHandler(trpcHandler)("/api/trpc"));
103
104
  }
104
105
 
105
106
  if (BATI.has("telefunc")) {
@@ -48,6 +48,7 @@ var require_package = __commonJS({
48
48
  "@batijs/lucia-auth": "workspace:*",
49
49
  "@batijs/shared-server": "workspace:^",
50
50
  "@batijs/shared-todo": "workspace:^",
51
+ "@batijs/shared-db": "workspace:^",
51
52
  "@batijs/telefunc": "workspace:^",
52
53
  "@batijs/trpc": "workspace:^",
53
54
  "@batijs/ts-rest": "workspace:*",
@@ -56,7 +57,7 @@ var require_package = __commonJS({
56
57
  "@trpc/server": "^10.45.2",
57
58
  "@types/express": "^4.17.21",
58
59
  "@types/node": "^18.19.14",
59
- "@universal-middleware/fastify": "^0.2.2",
60
+ "@universal-middleware/fastify": "^0.2.3",
60
61
  "cross-env": "^7.0.3",
61
62
  dotenv: "^16.4.5",
62
63
  fastify: "^4.28.1",
@@ -15,21 +15,18 @@ import {
15
15
  luciaAuthLogoutHandler,
16
16
  luciaAuthSignupHandler,
17
17
  luciaCsrfMiddleware,
18
+ luciaDbMiddleware,
18
19
  luciaGithubCallbackHandler,
19
20
  luciaGithubLoginHandler,
20
21
  } from "@batijs/lucia-auth/server/lucia-auth-handlers";
21
22
  import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
22
23
  import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
23
24
  import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
24
- import { appRouter, type AppRouter } from "@batijs/trpc/trpc/server";
25
25
  import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
26
- import {
27
- type CreateFastifyContextOptions,
28
- fastifyTRPCPlugin,
29
- type FastifyTRPCPluginOptions,
30
- } from "@trpc/server/adapters/fastify";
31
26
  import Fastify from "fastify";
32
27
  import { createHandler, createMiddleware } from "@universal-middleware/fastify";
28
+ import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
29
+ import { trpcHandler } from "@batijs/trpc/server/trpc-handler";
33
30
 
34
31
  const __filename = fileURLToPath(import.meta.url);
35
32
  const __dirname = dirname(__filename);
@@ -68,11 +65,18 @@ async function startServer() {
68
65
  app.use(viteDevMiddleware);
69
66
  }
70
67
 
68
+ if (BATI.hasDatabase) {
69
+ /**
70
+ * Make database available in Context as `context.db`
71
+ */
72
+ await app.register(createMiddleware(dbMiddleware)());
73
+ }
74
+
71
75
  if (BATI.has("authjs") || BATI.has("auth0")) {
72
76
  /**
73
77
  * Append Auth.js session to context
74
78
  **/
75
- app.register(createMiddleware(authjsSessionMiddleware)());
79
+ await app.register(createMiddleware(authjsSessionMiddleware)());
76
80
 
77
81
  /**
78
82
  * Auth.js route
@@ -88,9 +92,10 @@ async function startServer() {
88
92
  }
89
93
 
90
94
  if (BATI.has("lucia-auth")) {
91
- app.register(createMiddleware(luciaCsrfMiddleware)());
92
- app.register(createMiddleware(luciaAuthContextMiddleware)());
93
- app.register(createMiddleware(luciaAuthCookieMiddleware)());
95
+ await app.register(createMiddleware(luciaDbMiddleware)());
96
+ await app.register(createMiddleware(luciaCsrfMiddleware)());
97
+ await app.register(createMiddleware(luciaAuthContextMiddleware)());
98
+ await app.register(createMiddleware(luciaAuthCookieMiddleware)());
94
99
 
95
100
  app.post("/api/signup", createHandler(luciaAuthSignupHandler)());
96
101
  app.post("/api/login", createHandler(luciaAuthLoginHandler)());
@@ -103,21 +108,9 @@ async function startServer() {
103
108
  /**
104
109
  * tRPC route
105
110
  *
106
- * @link {@see https://trpc.io/docs/server/adapters/fastify}
111
+ * @link {@see https://trpc.io/docs/server/adapters/fetch}
107
112
  **/
108
- await app.register(fastifyTRPCPlugin, {
109
- prefix: "/api/trpc",
110
- trpcOptions: {
111
- router: appRouter,
112
- createContext({ req, res }: CreateFastifyContextOptions) {
113
- return { req, res };
114
- },
115
- onError({ path, error }) {
116
- // report to error monitoring
117
- console.error(`Error in tRPC handler on path '${path}':`, error);
118
- },
119
- } satisfies FastifyTRPCPluginOptions<AppRouter>["trpcOptions"],
120
- });
113
+ app.all("/api/trpc/*", createHandler(trpcHandler)("/api/trpc"));
121
114
  }
122
115
 
123
116
  if (BATI.has("telefunc")) {
@@ -44,10 +44,10 @@ var require_package = __commonJS({
44
44
  "@batijs/compile": "workspace:*",
45
45
  "@types/cookie": "^0.6.0",
46
46
  "@types/node": "^18.19.14",
47
- "@universal-middleware/core": "^0.2.5",
47
+ "@universal-middleware/core": "^0.2.6",
48
48
  cookie: "^0.6.0",
49
49
  dotenv: "^16.4.5",
50
- firebase: "^10.13.0",
50
+ firebase: "^10.13.1",
51
51
  "firebase-admin": "^12.4.0",
52
52
  firebaseui: "^6.1.0",
53
53
  vike: "^0.4.193",
@@ -3,7 +3,7 @@ import { getAuth } from "firebase-admin/auth";
3
3
  import { firebaseAdmin } from "../libs/firebaseAdmin";
4
4
  import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
5
5
 
6
- export const firebaseAuthMiddleware = (() => async (request, context) => {
6
+ export const firebaseAuthMiddleware: Get<[], UniversalMiddleware> = () => async (request, context) => {
7
7
  if (!request.headers.has("cookie")) return;
8
8
 
9
9
  const cookies = parse(request.headers.get("cookie")!);
@@ -24,7 +24,7 @@ export const firebaseAuthMiddleware = (() => async (request, context) => {
24
24
  user: null,
25
25
  };
26
26
  }
27
- }) satisfies Get<[], UniversalMiddleware>;
27
+ };
28
28
 
29
29
  export const firebaseAuthLoginHandler: Get<[], UniversalHandler> = () => async (request) => {
30
30
  const body = await request.json();
@@ -1,8 +1,4 @@
1
- import type { Get, UniversalHandler } from "@universal-middleware/core";
2
- export declare const firebaseAuthMiddleware: () => (request: Request, context: Universal.Context) => Promise<{
3
- user: import("firebase-admin/auth").UserRecord;
4
- } | {
5
- user: null;
6
- } | undefined>;
1
+ import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
2
+ export declare const firebaseAuthMiddleware: Get<[], UniversalMiddleware>;
7
3
  export declare const firebaseAuthLoginHandler: Get<[], UniversalHandler>;
8
4
  export declare const firebaseAuthLogoutHandler: Get<[], UniversalHandler>;
@@ -48,6 +48,7 @@ var require_package = __commonJS({
48
48
  "@batijs/lucia-auth": "workspace:*",
49
49
  "@batijs/shared-server": "workspace:^",
50
50
  "@batijs/shared-todo": "workspace:^",
51
+ "@batijs/shared-db": "workspace:^",
51
52
  "@batijs/telefunc": "workspace:^",
52
53
  "@batijs/trpc": "workspace:^",
53
54
  "@batijs/ts-rest": "workspace:*",
@@ -16,6 +16,7 @@ import {
16
16
  luciaAuthLogoutHandler,
17
17
  luciaAuthSignupHandler,
18
18
  luciaCsrfMiddleware,
19
+ luciaDbMiddleware,
19
20
  luciaGithubCallbackHandler,
20
21
  luciaGithubLoginHandler,
21
22
  } from "@batijs/lucia-auth/server/lucia-auth-handlers";
@@ -30,7 +31,8 @@ import installWhatwgNodeFetch from "@hattip/polyfills/whatwg-node";
30
31
  import { type NodeHTTPCreateContextFnOptions, nodeHTTPRequestHandler } from "@trpc/server/adapters/node-http";
31
32
  import { createApp, createRouter, eventHandler, fromNodeMiddleware, toNodeListener } from "h3";
32
33
  import serveStatic from "serve-static";
33
- import { createHandler, createMiddleware } from "@universal-middleware/h3";
34
+ import { createHandler, createMiddleware, getContext } from "@universal-middleware/h3";
35
+ import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
34
36
 
35
37
  installWhatwgNodeFetch();
36
38
  installGetSetCookie();
@@ -65,6 +67,13 @@ async function startServer() {
65
67
 
66
68
  const router = createRouter();
67
69
 
70
+ if (BATI.hasDatabase) {
71
+ /**
72
+ * Make database available in Context as `context.db`
73
+ */
74
+ app.use(createMiddleware(dbMiddleware)());
75
+ }
76
+
68
77
  if (BATI.has("authjs") || BATI.has("auth0")) {
69
78
  /**
70
79
  * Append Auth.js session to context
@@ -85,6 +94,7 @@ async function startServer() {
85
94
  }
86
95
 
87
96
  if (BATI.has("lucia-auth")) {
97
+ app.use(createMiddleware(luciaDbMiddleware)());
88
98
  app.use(createMiddleware(luciaCsrfMiddleware)());
89
99
  app.use(createMiddleware(luciaAuthContextMiddleware)());
90
100
  app.use(createMiddleware(luciaAuthCookieMiddleware)());
@@ -111,7 +121,7 @@ async function startServer() {
111
121
  path: event.context.params!.path,
112
122
  router: appRouter,
113
123
  createContext({ req, res }: NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>) {
114
- return { req, res };
124
+ return { ...getContext(event)!, req, res } as BATI.Any;
115
125
  },
116
126
  }),
117
127
  ),
@@ -48,17 +48,23 @@ var require_package = __commonJS({
48
48
  "@batijs/lucia-auth": "workspace:*",
49
49
  "@batijs/shared-server": "workspace:^",
50
50
  "@batijs/shared-todo": "workspace:^",
51
+ "@batijs/shared-db": "workspace:^",
51
52
  "@batijs/telefunc": "workspace:^",
52
53
  "@batijs/trpc": "workspace:^",
53
54
  "@batijs/ts-rest": "workspace:*",
55
+ "@cloudflare/workers-types": "^4.20240821.1",
54
56
  "@hattip/adapter-node": "^0.0.47",
55
57
  "@hattip/adapter-vercel-edge": "^0.0.47",
56
58
  "@hattip/core": "^0.0.47",
57
59
  "@hattip/router": "^0.0.47",
58
60
  "@hattip/vite": "^0.0.47",
61
+ "@hattip/adapter-aws-lambda": "^0.0.47",
62
+ "@hattip/static": "^0.0.47",
63
+ "@hattip/walk": "^0.0.47",
64
+ "@types/aws-lambda": "^8.10.143",
59
65
  "@trpc/server": "^10.45.2",
60
66
  "@types/node": "^18.19.14",
61
- "@universal-middleware/hattip": "^0.2.2",
67
+ "@universal-middleware/hattip": "^0.2.4",
62
68
  "cross-env": "^7.0.3",
63
69
  dotenv: "^16.4.5",
64
70
  hattip: "^0.0.33",
@@ -80,12 +86,18 @@ var require_package = __commonJS({
80
86
  exports: {
81
87
  "./hattip-entry": {
82
88
  types: "./dist/types/hattip-entry.d.ts"
89
+ },
90
+ "./entry_aws_lambda": {
91
+ types: "./dist/types/entry_aws_lambda.d.ts"
83
92
  }
84
93
  },
85
94
  typesVersions: {
86
95
  "*": {
87
96
  "hattip-entry": [
88
97
  "./dist/types/hattip-entry.d.ts"
98
+ ],
99
+ entry_aws_lambda: [
100
+ "./dist/types/entry_aws_lambda.d.ts"
89
101
  ]
90
102
  }
91
103
  }
@@ -134,7 +146,8 @@ async function getPackageJson(props) {
134
146
  "vite",
135
147
  "vike",
136
148
  "@universal-middleware/hattip",
137
- ...props.meta.BATI.has("vercel") ? ["@hattip/adapter-vercel-edge"] : []
149
+ ...props.meta.BATI.has("vercel") ? ["@hattip/adapter-vercel-edge"] : [],
150
+ ...props.meta.BATI.has("aws") ? ["@types/aws-lambda", "@hattip/adapter-aws-lambda", "@hattip/static", "@hattip/walk"] : []
138
151
  ]
139
152
  });
140
153
  }
@@ -0,0 +1,37 @@
1
+ /*{ @if (it.BATI.has("aws")) }*/
2
+ /*
3
+ entry_aws_lambda.ts
4
+
5
+ This file is the entry point for AWS Lambda
6
+
7
+ Notes:
8
+ * The file name must not have any special characters or dots except for the extension. https://docs.aws.amazon.com/lambda/latest/api/API_CreateFunction.html#API_CreateFunction_RequestSyntax
9
+
10
+ */
11
+
12
+ import { existsSync } from "node:fs";
13
+ import awsLambdaAdapter from "@hattip/adapter-aws-lambda";
14
+ import { walk } from "@hattip/walk";
15
+ import type { FileInfo } from "@hattip/walk";
16
+ import { createStaticMiddleware } from "@hattip/static";
17
+ import { createFileReader } from "@hattip/static/fs";
18
+ import hattipHandler from "@batijs/hattip/hattip-entry";
19
+ import type { Handler, APIGatewayProxyResultV2, APIGatewayProxyEventV2 } from "aws-lambda";
20
+
21
+ const root = new URL("./dist/client", import.meta.url);
22
+ const staticRootExists = existsSync(root);
23
+ const files = staticRootExists ? walk(root) : new Map<string, FileInfo>();
24
+ const staticMiddleware = staticRootExists
25
+ ? createStaticMiddleware(files, createFileReader(root), {
26
+ urlRoot: "/",
27
+ })
28
+ : undefined;
29
+
30
+ const awsHandler = awsLambdaAdapter((ctx) => {
31
+ if (hattipHandler === undefined) throw new Error("hattipHandler is undefined");
32
+ if (staticMiddleware === undefined) return hattipHandler(ctx);
33
+ return staticMiddleware(ctx) || hattipHandler(ctx);
34
+ });
35
+
36
+ export const handler: Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2> = awsHandler;
37
+ /*{ /if }*/
@@ -13,22 +13,30 @@ import {
13
13
  luciaAuthLogoutHandler,
14
14
  luciaAuthSignupHandler,
15
15
  luciaCsrfMiddleware,
16
+ luciaDbMiddleware,
16
17
  luciaGithubCallbackHandler,
17
18
  luciaGithubLoginHandler,
18
19
  } from "@batijs/lucia-auth/server/lucia-auth-handlers";
19
20
  import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
20
21
  import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
21
22
  import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
22
- import { appRouter } from "@batijs/trpc/trpc/server";
23
23
  import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
24
24
  import type { HattipHandler } from "@hattip/core";
25
25
  import { createRouter } from "@hattip/router";
26
- import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
27
26
  import vercelAdapter from "@hattip/adapter-vercel-edge";
28
27
  import { createHandler, createMiddleware } from "@universal-middleware/hattip";
28
+ import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
29
+ import { trpcHandler } from "@batijs/trpc/server/trpc-handler";
29
30
 
30
31
  const router = createRouter();
31
32
 
33
+ if (BATI.hasDatabase) {
34
+ /**
35
+ * Make database available in Context as `context.db`
36
+ */
37
+ router.use(createMiddleware(dbMiddleware)());
38
+ }
39
+
32
40
  if (BATI.has("telefunc")) {
33
41
  /**
34
42
  * Telefunc route
@@ -44,16 +52,7 @@ if (BATI.has("trpc")) {
44
52
  *
45
53
  * @link {@see https://trpc.io/docs/server/adapters/fetch}
46
54
  **/
47
- router.use("/api/trpc/*", (context) => {
48
- return fetchRequestHandler({
49
- router: appRouter,
50
- req: context.request,
51
- endpoint: "/api/trpc",
52
- createContext({ req }) {
53
- return { req };
54
- },
55
- });
56
- });
55
+ router.use("/api/trpc/*", createHandler(trpcHandler)("/api/trpc"));
57
56
  }
58
57
 
59
58
  if (BATI.has("ts-rest")) {
@@ -80,6 +79,7 @@ if (BATI.has("firebase-auth")) {
80
79
  }
81
80
 
82
81
  if (BATI.has("lucia-auth")) {
82
+ router.use(createMiddleware(luciaDbMiddleware)());
83
83
  router.use(createMiddleware(luciaCsrfMiddleware)());
84
84
  router.use(createMiddleware(luciaAuthContextMiddleware)());
85
85
  router.use(createMiddleware(luciaAuthCookieMiddleware)());
@@ -0,0 +1,2 @@
1
+ import type { Handler, APIGatewayProxyResultV2, APIGatewayProxyEventV2 } from "aws-lambda";
2
+ export declare const handler: Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2>;
@@ -51,11 +51,14 @@ var require_package = __commonJS({
51
51
  "@batijs/telefunc": "workspace:^",
52
52
  "@batijs/trpc": "workspace:^",
53
53
  "@batijs/ts-rest": "workspace:*",
54
+ "@batijs/shared-db": "workspace:*",
55
+ "@cloudflare/workers-types": "^4.20240821.1",
54
56
  "@hono/node-server": "^1.12.2",
55
- "@hono/vite-dev-server": "^0.15.0",
57
+ "@hono/vite-dev-server": "^0.15.1",
58
+ "@types/aws-lambda": "^8.10.145",
56
59
  "@trpc/server": "^10.45.2",
57
60
  "@types/node": "^18.19.14",
58
- "@universal-middleware/hono": "^0.2.3",
61
+ "@universal-middleware/hono": "^0.2.5",
59
62
  "cross-env": "^7.0.3",
60
63
  dotenv: "^16.4.5",
61
64
  hono: "^4.5.8",
@@ -79,6 +82,9 @@ var require_package = __commonJS({
79
82
  "./hono-entry": {
80
83
  types: "./dist/types/hono-entry.d.ts"
81
84
  },
85
+ "./entry_aws_lambda": {
86
+ types: "./dist/types/entry_aws_lambda.d.ts"
87
+ },
82
88
  "./hono-entry.node": {
83
89
  types: "./dist/types/hono-entry.node.d.ts"
84
90
  }
@@ -88,6 +94,9 @@ var require_package = __commonJS({
88
94
  "hono-entry": [
89
95
  "./dist/types/hono-entry.d.ts"
90
96
  ],
97
+ entry_aws_lambda: [
98
+ "./dist/types/entry_aws_lambda.d.ts"
99
+ ],
91
100
  "hono-entry.node": [
92
101
  "./dist/types/hono-entry.node.d.ts"
93
102
  ]
@@ -118,8 +127,17 @@ async function getPackageJson(props) {
118
127
  }
119
128
  });
120
129
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
121
- devDependencies: ["@hono/vite-dev-server", "@types/node"],
122
- dependencies: ["@hono/node-server", "@universal-middleware/hono", "cross-env", "hono", "tsx", "vite", "vike"]
130
+ devDependencies: ["@hono/vite-dev-server", "@types/node", "@types/aws-lambda"],
131
+ dependencies: [
132
+ "@hono/node-server",
133
+ "@universal-middleware/hono",
134
+ "cross-env",
135
+ "hono",
136
+ "tsx",
137
+ "vite",
138
+ "vike",
139
+ "dotenv"
140
+ ]
123
141
  });
124
142
  }
125
143
  export {
@@ -0,0 +1,37 @@
1
+ /*{ @if (it.BATI.has("aws")) }*/
2
+ /*
3
+ entry_aws_lambda.ts
4
+
5
+ This file is the entry point for AWS Lambda
6
+
7
+ Notes:
8
+ * The file name must not have any special characters or dots except for the extension. https://docs.aws.amazon.com/lambda/latest/api/API_CreateFunction.html#API_CreateFunction_RequestSyntax
9
+
10
+ */
11
+
12
+ import { Hono } from "hono";
13
+ import { serveStatic } from "@hono/node-server/serve-static";
14
+ import { handle } from "hono/aws-lambda";
15
+ import type { LambdaEvent, LambdaContext } from "hono/aws-lambda";
16
+ import app from "@batijs/hono/hono-entry"; // file is provided by hono
17
+ import type { Handler, APIGatewayProxyResult } from "aws-lambda";
18
+
19
+ type Bindings = {
20
+ event: LambdaEvent;
21
+ lambdaContext: LambdaContext;
22
+ };
23
+
24
+ const lambdaApp = new Hono<{ Bindings: Bindings }>();
25
+
26
+ lambdaApp.use(
27
+ "/*",
28
+ serveStatic({
29
+ root: `./dist/client/`,
30
+ }),
31
+ );
32
+
33
+ lambdaApp.route("/", app!);
34
+ const awsHandler = handle(lambdaApp);
35
+
36
+ export const handler: Handler<LambdaEvent, APIGatewayProxyResult> = awsHandler;
37
+ /*{ /if }*/