@batijs/cli 0.0.255 → 0.0.258

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 (70) hide show
  1. package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +2 -1
  2. package/dist/boilerplates/@batijs/d1/files/$README.md.js +31 -0
  3. package/dist/boilerplates/@batijs/d1/files/$tsconfig.json.js +10 -0
  4. package/dist/boilerplates/@batijs/d1/files/$wrangler.toml.js +21 -0
  5. package/dist/boilerplates/@batijs/d1/files/vike.d.ts +8 -0
  6. package/dist/boilerplates/@batijs/drizzle/files/$.env.js +9 -0
  7. package/dist/boilerplates/@batijs/drizzle/files/$README.md.js +4 -4
  8. package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +33 -14
  9. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +16 -0
  10. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/lucia-auth.ts +27 -0
  11. package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +11 -0
  12. package/dist/boilerplates/@batijs/drizzle/files/database/{schema → drizzle/schema}/todos.ts +1 -0
  13. package/dist/boilerplates/@batijs/drizzle/files/database/{seed.ts → drizzle/seed.ts} +3 -3
  14. package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +7 -3
  15. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.ts +2 -0
  16. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/lucia-auth.d.ts +12 -0
  17. package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.ts +43 -0
  18. package/dist/boilerplates/@batijs/edgedb/files/$package.json.js +1 -1
  19. package/dist/boilerplates/@batijs/eslint/files/$package.json.js +1 -1
  20. package/dist/boilerplates/@batijs/express/files/express-entry.ts +1 -1
  21. package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +2 -2
  22. package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +1 -1
  23. package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +1 -1
  24. package/dist/boilerplates/@batijs/hono/files/$package.json.js +2 -2
  25. package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +1 -1
  26. package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +1 -18
  27. package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +5 -5
  28. package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +39 -26
  29. package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +7 -0
  30. package/dist/boilerplates/@batijs/prisma/files/$package.json.js +2 -2
  31. package/dist/boilerplates/@batijs/react/files/pages/todo/TodoList.tsx +1 -7
  32. package/dist/boilerplates/@batijs/shared/files/vite.config.ts +1 -1
  33. package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +1 -0
  34. package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +6 -3
  35. package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +7 -3
  36. package/dist/boilerplates/@batijs/solid/files/$package.json.js +1 -1
  37. package/dist/boilerplates/@batijs/solid/files/pages/todo/TodoList.tsx +1 -7
  38. package/dist/boilerplates/@batijs/sqlite/files/$.env.js +9 -0
  39. package/dist/boilerplates/@batijs/sqlite/files/$README.md.js +18 -0
  40. package/dist/boilerplates/@batijs/sqlite/files/$package.json.js +120 -0
  41. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/db.ts +15 -0
  42. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/lucia-auth.ts +25 -0
  43. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/todos.ts +9 -0
  44. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/schema/all.ts +3 -0
  45. package/dist/boilerplates/@batijs/{lucia-auth/files/database/sqliteDb.ts → sqlite/files/database/sqlite/schema/lucia-auth.ts} +6 -5
  46. package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/schema/todos.ts +14 -0
  47. package/dist/boilerplates/@batijs/{lucia-auth/types/database/sqliteDb.d.ts → sqlite/types/database/sqlite/db.d.ts} +1 -1
  48. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/lucia-auth.d.ts +5 -0
  49. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/todos.d.ts +5 -0
  50. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/all.d.ts +2 -0
  51. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/lucia-auth.d.ts +1 -0
  52. package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/todos.d.ts +1 -0
  53. package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +1 -0
  54. package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +5 -3
  55. package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -0
  56. package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +5 -3
  57. package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +1 -0
  58. package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +5 -3
  59. package/dist/boilerplates/@batijs/vue/files/pages/todo/TodoList.vue +1 -1
  60. package/dist/boilerplates/boilerplates.json +27 -0
  61. package/dist/index.js +6 -3
  62. package/package.json +5 -5
  63. package/dist/boilerplates/@batijs/drizzle/files/database/drizzleDb.ts +0 -5
  64. package/dist/boilerplates/@batijs/drizzle/types/database/drizzleDb.d.ts +0 -1
  65. package/dist/boilerplates/@batijs/lucia-auth/files/database/auth-actions.ts +0 -54
  66. package/dist/boilerplates/@batijs/lucia-auth/types/database/auth-actions.d.ts +0 -9
  67. /package/dist/boilerplates/@batijs/{lucia-auth/files/database/schema/auth.ts → drizzle/files/database/drizzle/schema/lucia-auth.ts} +0 -0
  68. /package/dist/boilerplates/@batijs/{lucia-auth/types/database/schema/auth.d.ts → drizzle/types/database/drizzle/schema/lucia-auth.d.ts} +0 -0
  69. /package/dist/boilerplates/@batijs/drizzle/types/database/{schema → drizzle/schema}/todos.d.ts +0 -0
  70. /package/dist/boilerplates/@batijs/drizzle/types/database/{seed.d.ts → drizzle/seed.d.ts} +0 -0
@@ -42,6 +42,7 @@ var require_package = __commonJS({
42
42
  license: "MIT",
43
43
  devDependencies: {
44
44
  "@batijs/compile": "workspace:*",
45
+ "@cloudflare/workers-types": "^4.20240821.1",
45
46
  "@hattip/adapter-cloudflare-workers": "^0.0.47",
46
47
  "@types/node": "^18.19.14",
47
48
  "npm-run-all2": "^6.2.2",
@@ -102,7 +103,7 @@ async function getPackageJson(props) {
102
103
  }
103
104
  });
104
105
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
105
- devDependencies: ["wrangler", "npm-run-all2"],
106
+ devDependencies: ["wrangler", "npm-run-all2", "@cloudflare/workers-types"],
106
107
  dependencies: [
107
108
  "vike-cloudflare",
108
109
  ...props.meta.BATI.has("hattip") ? ["@hattip/adapter-cloudflare-workers"] : []
@@ -0,0 +1,31 @@
1
+ // files/$README.md.ts
2
+ import { loadReadme } from "@batijs/core";
3
+ async function getReadme(props) {
4
+ const content = await loadReadme(props);
5
+ const todo = `
6
+ ## *Cloudflare D1*
7
+
8
+ > [!IMPORTANT]
9
+ > D1 integration is incomplete, and some files are still refering to \`better-sqlite3\`.
10
+ > It should be fixed within a few days.
11
+
12
+ ### Setup
13
+ Create a D1 database:
14
+
15
+ \`\`\`sh
16
+ wrangler d1 create <your-db-name>
17
+ \`\`\`
18
+
19
+ > [!NOTE]
20
+ > For reference, a good database name is:
21
+ > - Typically a combination of ASCII characters, shorter than 32 characters, and uses dashes (-) instead of spaces.
22
+ > - Descriptive of the use-case and environment. For example, \u201Cstaging-db-web\u201D or \u201Cproduction-db-backend\u201D.
23
+ > - Only used for describing the database, and is not directly referenced in code.
24
+
25
+ Then copy the output to \`wrangler.toml\``;
26
+ content.addTodo(todo);
27
+ return content.finalize();
28
+ }
29
+ export {
30
+ getReadme as default
31
+ };
@@ -0,0 +1,10 @@
1
+ // files/$tsconfig.json.ts
2
+ import { loadAsJson } from "@batijs/core";
3
+ async function getTsConfig(props) {
4
+ const tsConfig = await loadAsJson(props);
5
+ tsConfig.compilerOptions.types = [...tsConfig.compilerOptions.types ?? [], "@cloudflare/workers-types"];
6
+ return tsConfig;
7
+ }
8
+ export {
9
+ getTsConfig as default
10
+ };
@@ -0,0 +1,21 @@
1
+ // files/$wrangler.toml.ts
2
+ import "@batijs/core";
3
+ async function getToml(props) {
4
+ const content = await props.readfile?.();
5
+ if (!content) {
6
+ throw new Error("wrangler.toml should not be empty");
7
+ }
8
+ const dbSnippet = `
9
+ # https://developers.cloudflare.com/d1/build-with-d1/local-development/#develop-locally-with-pages
10
+ [[d1_databases]]
11
+ binding = "DB" # Should match preview_database_id
12
+ database_name = "YOUR_DATABASE_NAME"
13
+ database_id = "the-id-of-your-D1-database-goes-here" # wrangler d1 info YOUR_DATABASE_NAME
14
+ preview_database_id = "DB" # Required for Pages local development
15
+ `;
16
+ return `${content}
17
+ ${dbSnippet}`;
18
+ }
19
+ export {
20
+ getToml as default
21
+ };
@@ -0,0 +1,8 @@
1
+ import { D1Database } from "@cloudflare/workers-types";
2
+
3
+ // Cloudflare typings
4
+ interface Env {
5
+ DB: D1Database;
6
+ }
7
+
8
+ export {};
@@ -0,0 +1,9 @@
1
+ // files/$.env.ts
2
+ import { appendToEnv } from "@batijs/core";
3
+ async function getEnv(props) {
4
+ const envContent = await props.readfile?.();
5
+ return appendToEnv(envContent, "DATABASE_URL", "sqlite.db", "Path to the sqlite database");
6
+ }
7
+ export {
8
+ getEnv as default
9
+ };
@@ -4,12 +4,12 @@ async function getReadme(props) {
4
4
  const content = await loadReadme(props);
5
5
  const todo = `
6
6
  ## *Drizzle*
7
- - First, ensure all dependencies are installed using your preferred package manager.
8
- - Execute the commands below with your preferred package manager, e.g., for pnpm:
7
+
8
+ First, ensure that \`DATABASE_URL\` is configured in \`.env\` file, then create the database:
9
9
  \`\`\`bash
10
10
  pnpm drizzle:generate # a script that executes drizzle-kit generate.
11
11
  pnpm drizzle:migrate # a script that executes drizzle-kit migrate.
12
- pnpm drizzle:seed # a script that executes tsx ./database/seed.ts.
12
+ pnpm drizzle:seed # a script that executes tsx ./database/drizzle/seed.ts.
13
13
  \`\`\`
14
14
 
15
15
  > [!NOTE]
@@ -17,7 +17,7 @@ pnpm drizzle:seed # a script that executes tsx ./database/seed.ts.
17
17
  >
18
18
  > The \`drizzle-kit migrate\` command is used to apply the generated migrations to your database.
19
19
  >
20
- > The \`tsx ./database/seed.ts\` command is used to run a custom seed script to populate data to your database.
20
+ > The \`tsx ./database/drizzle/seed.ts\` command is used to run a custom seed script to populate data to your database.
21
21
 
22
22
  Read more on [Drizzle ORM documentation](https://orm.drizzle.team/docs/overview)
23
23
  `;
@@ -45,6 +45,7 @@ var require_package = __commonJS({
45
45
  "@types/better-sqlite3": "^7.6.11",
46
46
  "@types/node": "^18.19.14",
47
47
  "better-sqlite3": "^11.2.1",
48
+ dotenv: "^16.4.5",
48
49
  "drizzle-kit": "^0.24.1",
49
50
  "drizzle-orm": "^0.33.0",
50
51
  tsx: "^4.18.0"
@@ -64,14 +65,23 @@ var require_package = __commonJS({
64
65
  "./drizzle.config": {
65
66
  types: "./dist/types/drizzle.config.d.ts"
66
67
  },
67
- "./database/drizzleDb": {
68
- types: "./dist/types/database/drizzleDb.d.ts"
68
+ "./database/drizzle/db": {
69
+ types: "./dist/types/database/drizzle/db.d.ts"
69
70
  },
70
- "./database/schema/todos": {
71
- types: "./dist/types/database/schema/todos.d.ts"
71
+ "./database/drizzle/schema/todos": {
72
+ types: "./dist/types/database/drizzle/schema/todos.d.ts"
72
73
  },
73
- "./database/seed": {
74
- types: "./dist/types/database/seed.d.ts"
74
+ "./database/drizzle/seed": {
75
+ types: "./dist/types/database/drizzle/seed.d.ts"
76
+ },
77
+ "./database/drizzle/schema/lucia-auth": {
78
+ types: "./dist/types/database/drizzle/schema/lucia-auth.d.ts"
79
+ },
80
+ "./database/drizzle/queries/lucia-auth": {
81
+ types: "./dist/types/database/drizzle/queries/lucia-auth.d.ts"
82
+ },
83
+ "./database/drizzle/queries/todos": {
84
+ types: "./dist/types/database/drizzle/queries/todos.d.ts"
75
85
  }
76
86
  },
77
87
  typesVersions: {
@@ -79,14 +89,23 @@ var require_package = __commonJS({
79
89
  "drizzle.config": [
80
90
  "./dist/types/drizzle.config.d.ts"
81
91
  ],
82
- "database/drizzleDb": [
83
- "./dist/types/database/drizzleDb.d.ts"
92
+ "database/drizzle/db": [
93
+ "./dist/types/database/drizzle/db.d.ts"
94
+ ],
95
+ "database/drizzle/schema/todos": [
96
+ "./dist/types/database/drizzle/schema/todos.d.ts"
97
+ ],
98
+ "database/drizzle/seed": [
99
+ "./dist/types/database/drizzle/seed.d.ts"
100
+ ],
101
+ "database/drizzle/schema/lucia-auth": [
102
+ "./dist/types/database/drizzle/schema/lucia-auth.d.ts"
84
103
  ],
85
- "database/schema/todos": [
86
- "./dist/types/database/schema/todos.d.ts"
104
+ "database/drizzle/queries/lucia-auth": [
105
+ "./dist/types/database/drizzle/queries/lucia-auth.d.ts"
87
106
  ],
88
- "database/seed": [
89
- "./dist/types/database/seed.d.ts"
107
+ "database/drizzle/queries/todos": [
108
+ "./dist/types/database/drizzle/queries/todos.d.ts"
90
109
  ]
91
110
  }
92
111
  }
@@ -101,10 +120,10 @@ async function getPackageJson(props) {
101
120
  packageJson.scripts["drizzle:generate"] = "drizzle-kit generate";
102
121
  packageJson.scripts["drizzle:migrate"] = "drizzle-kit migrate";
103
122
  packageJson.scripts["drizzle:studio"] = "drizzle-kit studio";
104
- packageJson.scripts["drizzle:seed"] = "tsx ./database/seed.ts";
123
+ packageJson.scripts["drizzle:seed"] = "tsx ./database/drizzle/seed.ts";
105
124
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
106
125
  devDependencies: ["@types/better-sqlite3", "tsx"],
107
- dependencies: ["better-sqlite3", "drizzle-kit", "drizzle-orm"]
126
+ dependencies: ["better-sqlite3", "drizzle-kit", "drizzle-orm", "dotenv"]
108
127
  });
109
128
  }
110
129
  export {
@@ -0,0 +1,16 @@
1
+ import Database from "better-sqlite3";
2
+ import { type BetterSQLite3Database, drizzle } from "drizzle-orm/better-sqlite3";
3
+
4
+ let singleton: BetterSQLite3Database | undefined = undefined;
5
+
6
+ export function db() {
7
+ if (!singleton) {
8
+ if (!process.env.DATABASE_URL) {
9
+ throw new Error("Missing DATABASE_URL in .env file");
10
+ }
11
+
12
+ const sqlite = new Database(process.env.DATABASE_URL);
13
+ singleton = drizzle(sqlite);
14
+ }
15
+ return singleton;
16
+ }
@@ -0,0 +1,27 @@
1
+ /*# BATI include-if-imported #*/
2
+ import { db } from "../db";
3
+ import { oauthAccountTable, userTable } from "../schema/lucia-auth";
4
+ import { and, eq } from "drizzle-orm";
5
+
6
+ export function getExistingUser(username: string) {
7
+ return db().select().from(userTable).where(eq(userTable.username, username)).get();
8
+ }
9
+
10
+ export function getExistingAccount(providerId: string, providerUserId: number) {
11
+ return db()
12
+ .select()
13
+ .from(oauthAccountTable)
14
+ .where(and(eq(oauthAccountTable.providerId, providerId), eq(oauthAccountTable.providerUserId, providerUserId)))
15
+ .get();
16
+ }
17
+
18
+ export function signupWithGithub(userId: string, username: string, githubUserId: number) {
19
+ return db().transaction(async (tx) => {
20
+ await tx.insert(userTable).values({ id: userId, username: username });
21
+ await tx.insert(oauthAccountTable).values({ providerId: "github", providerUserId: githubUserId, userId });
22
+ });
23
+ }
24
+
25
+ export function signupWithCredentials(userId: string, username: string, passwordHash: string) {
26
+ return db().insert(userTable).values({ id: userId, username, password: passwordHash }).run();
27
+ }
@@ -0,0 +1,11 @@
1
+ /*# BATI include-if-imported #*/
2
+ import { db } from "../db";
3
+ import { todoTable } from "../schema/todos";
4
+
5
+ export function insertTodo(text: string) {
6
+ return db().insert(todoTable).values({ text });
7
+ }
8
+
9
+ export function getAllTodos() {
10
+ return db().select().from(todoTable).all();
11
+ }
@@ -1,3 +1,4 @@
1
+ /*# BATI include-if-imported #*/
1
2
  import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
2
3
 
3
4
  // Example of defining a schema in Drizzle ORM:
@@ -1,8 +1,8 @@
1
- import { drizzleDb } from "./drizzleDb";
1
+ import { db } from "./db";
2
2
  import { todoTable } from "./schema/todos";
3
3
 
4
4
  async function seed() {
5
- drizzleDb
5
+ db()
6
6
  .insert(todoTable)
7
7
  .values([{ text: "Buy milk" }, { text: "Buy strawberries" }])
8
8
  .run();
@@ -10,4 +10,4 @@ async function seed() {
10
10
  console.log("Seed complete!");
11
11
  }
12
12
 
13
- seed();
13
+ await seed();
@@ -1,10 +1,14 @@
1
1
  import { defineConfig } from "drizzle-kit";
2
2
 
3
+ if (!process.env.DATABASE_URL) {
4
+ throw new Error("Missing DATABASE_URL in .env file");
5
+ }
6
+
3
7
  export default defineConfig({
4
8
  dialect: "sqlite",
5
- schema: "./database/schema/*",
6
- out: "./drizzle",
9
+ schema: "./database/drizzle/schema/*",
10
+ out: "./database/drizzle/migrations",
7
11
  dbCredentials: {
8
- url: "sqlite.db",
12
+ url: process.env.DATABASE_URL,
9
13
  },
10
14
  });
@@ -0,0 +1,2 @@
1
+ import { type BetterSQLite3Database } from "drizzle-orm/better-sqlite3";
2
+ export declare function db(): BetterSQLite3Database;
@@ -0,0 +1,12 @@
1
+ export declare function getExistingUser(username: string): {
2
+ id: string;
3
+ username: string;
4
+ password: string | null;
5
+ } | undefined;
6
+ export declare function getExistingAccount(providerId: string, providerUserId: number): {
7
+ providerId: string;
8
+ providerUserId: number;
9
+ 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;
@@ -0,0 +1,43 @@
1
+ export declare function insertTodo(text: string): import("drizzle-orm/sqlite-core").SQLiteInsertBase<import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
2
+ name: "todos";
3
+ schema: undefined;
4
+ columns: {
5
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
6
+ name: "id";
7
+ tableName: "todos";
8
+ dataType: "number";
9
+ columnType: "SQLiteInteger";
10
+ data: number;
11
+ driverParam: number;
12
+ notNull: true;
13
+ hasDefault: true;
14
+ isPrimaryKey: true;
15
+ isAutoincrement: false;
16
+ hasRuntimeDefault: false;
17
+ enumValues: undefined;
18
+ baseColumn: never;
19
+ generated: undefined;
20
+ }, object>;
21
+ text: import("drizzle-orm/sqlite-core").SQLiteColumn<{
22
+ name: "text";
23
+ tableName: "todos";
24
+ dataType: "string";
25
+ columnType: "SQLiteText";
26
+ data: string;
27
+ driverParam: string;
28
+ notNull: true;
29
+ hasDefault: false;
30
+ isPrimaryKey: false;
31
+ isAutoincrement: false;
32
+ hasRuntimeDefault: false;
33
+ enumValues: [string, ...string[]];
34
+ baseColumn: never;
35
+ generated: undefined;
36
+ }, object>;
37
+ };
38
+ dialect: "sqlite";
39
+ }>, "sync", import("better-sqlite3").RunResult, undefined, false, never>;
40
+ export declare function getAllTodos(): {
41
+ id: number;
42
+ text: string;
43
+ }[];
@@ -43,7 +43,7 @@ var require_package = __commonJS({
43
43
  devDependencies: {
44
44
  "@batijs/compile": "workspace:*",
45
45
  "@edgedb/generate": "^0.5.5",
46
- "@prisma/client": "^5.18.0",
46
+ "@prisma/client": "^5.19.0",
47
47
  "@types/node": "^18.19.14",
48
48
  colorette: "^2.0.20",
49
49
  edgedb: "^1.5.10"
@@ -50,7 +50,7 @@ var require_package = __commonJS({
50
50
  "eslint-plugin-solid": "^0.14.2",
51
51
  "eslint-plugin-vue": "^9.27.0",
52
52
  globals: "^15.9.0",
53
- "typescript-eslint": "^8.2.0",
53
+ "typescript-eslint": "^8.3.0",
54
54
  "vue-eslint-parser": "^9.4.3"
55
55
  },
56
56
  dependencies: {
@@ -1,4 +1,4 @@
1
- // BATI.has("auth0")
1
+ // BATI.has("auth0") || BATI.hasDatabase
2
2
  import "dotenv/config";
3
3
  import { dirname } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
@@ -1,4 +1,4 @@
1
- // BATI.has("auth0")
1
+ // BATI.has("auth0") || BATI.hasDatabase
2
2
  import "dotenv/config";
3
3
  import { dirname } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
@@ -130,7 +130,7 @@ async function startServer() {
130
130
  }
131
131
 
132
132
  if (BATI.has("ts-rest")) {
133
- app.all("/api/*", createHandler(tsRestHandler));
133
+ app.all("/api/*", createHandler(tsRestHandler)());
134
134
  }
135
135
 
136
136
  if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
@@ -1,4 +1,4 @@
1
- // BATI.has("auth0")
1
+ // BATI.has("auth0") || BATI.hasDatabase
2
2
  import "dotenv/config";
3
3
  import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
4
4
  import { dirname } from "node:path";
@@ -1,4 +1,4 @@
1
- // BATI.has("auth0")
1
+ // BATI.has("auth0") || BATI.hasDatabase
2
2
  import "dotenv/config";
3
3
  import { authjsHandler, authjsSessionMiddleware } from "@batijs/authjs/server/authjs-handler";
4
4
  import {
@@ -51,8 +51,8 @@ var require_package = __commonJS({
51
51
  "@batijs/telefunc": "workspace:^",
52
52
  "@batijs/trpc": "workspace:^",
53
53
  "@batijs/ts-rest": "workspace:*",
54
- "@hono/node-server": "^1.12.1",
55
- "@hono/vite-dev-server": "^0.14.0",
54
+ "@hono/node-server": "^1.12.2",
55
+ "@hono/vite-dev-server": "^0.15.0",
56
56
  "@trpc/server": "^10.45.2",
57
57
  "@types/node": "^18.19.14",
58
58
  "@universal-middleware/hono": "^0.2.3",
@@ -1,4 +1,4 @@
1
- // BATI.has("auth0")
1
+ // BATI.has("auth0") || BATI.hasDatabase
2
2
  import "dotenv/config";
3
3
  import { authjsHandler, authjsSessionMiddleware } from "@batijs/authjs/server/authjs-handler";
4
4
  import {
@@ -43,6 +43,7 @@ var require_package = __commonJS({
43
43
  devDependencies: {
44
44
  "@batijs/compile": "workspace:*",
45
45
  "@batijs/drizzle": "workspace:*",
46
+ "@batijs/sqlite": "workspace:*",
46
47
  "@lucia-auth/adapter-drizzle": "^1.1.0",
47
48
  "@lucia-auth/adapter-sqlite": "^3.0.2",
48
49
  "@types/better-sqlite3": "^7.6.11",
@@ -70,15 +71,6 @@ var require_package = __commonJS({
70
71
  }
71
72
  },
72
73
  exports: {
73
- "./database/sqliteDb": {
74
- types: "./dist/types/database/sqliteDb.d.ts"
75
- },
76
- "./database/schema/auth": {
77
- types: "./dist/types/database/schema/auth.d.ts"
78
- },
79
- "./database/auth-actions": {
80
- types: "./dist/types/database/auth-actions.d.ts"
81
- },
82
74
  "./lib/lucia-auth": {
83
75
  types: "./dist/types/lib/lucia-auth.d.ts"
84
76
  },
@@ -91,15 +83,6 @@ var require_package = __commonJS({
91
83
  },
92
84
  typesVersions: {
93
85
  "*": {
94
- "database/sqliteDb": [
95
- "./dist/types/database/sqliteDb.d.ts"
96
- ],
97
- "database/schema/auth": [
98
- "./dist/types/database/schema/auth.d.ts"
99
- ],
100
- "database/auth-actions": [
101
- "./dist/types/database/auth-actions.d.ts"
102
- ],
103
86
  "lib/lucia-auth": [
104
87
  "./dist/types/lib/lucia-auth.d.ts"
105
88
  ],
@@ -2,10 +2,10 @@ import "dotenv/config";
2
2
  import { Lucia } from "lucia";
3
3
  import { BetterSqlite3Adapter } from "@lucia-auth/adapter-sqlite";
4
4
  import { GitHub } from "arctic";
5
- import { sqliteDb } from "../database/sqliteDb";
6
5
  import { DrizzleSQLiteAdapter } from "@lucia-auth/adapter-drizzle";
7
- import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
8
- import { sessionTable, userTable } from "../database/schema/auth";
6
+ import { db as drizzleDb } from "@batijs/drizzle/database/drizzle/db";
7
+ import { sessionTable, userTable } from "@batijs/drizzle/database/drizzle/schema/lucia-auth";
8
+ import { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
9
9
 
10
10
  /**
11
11
  * Polyfill needed if you're using Node.js 18 or below
@@ -26,8 +26,8 @@ if (!globalThis.crypto) {
26
26
  * @link {@see https://lucia-auth.com/database/#database-setup}
27
27
  **/
28
28
  const adapter = BATI.has("drizzle")
29
- ? new DrizzleSQLiteAdapter(drizzleDb, sessionTable, userTable)
30
- : new BetterSqlite3Adapter(sqliteDb, {
29
+ ? new DrizzleSQLiteAdapter(drizzleDb(), sessionTable, userTable)
30
+ : new BetterSqlite3Adapter(sqliteDb(), {
31
31
  user: "users",
32
32
  session: "sessions",
33
33
  });
@@ -3,12 +3,10 @@ import { generateId, Scrypt, verifyRequestOrigin } from "lucia";
3
3
  import type { DatabaseOAuthAccount, DatabaseUser, GitHubUser } from "../lib/lucia-auth";
4
4
  import { github, lucia } from "../lib/lucia-auth";
5
5
  import { SqliteError } from "better-sqlite3";
6
- import { sqliteDb } from "../database/sqliteDb";
7
6
  import { generateState, OAuth2RequestError } from "arctic";
8
7
  import { parse, serialize } from "cookie";
9
- import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
10
- import { oauthAccountTable, userTable } from "../database/schema/auth";
11
- import { getExistingAccount, getExistingUser, validateInput } from "../database/auth-actions";
8
+ import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/lucia-auth";
9
+ import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/lucia-auth";
12
10
  import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
13
11
 
14
12
  /**
@@ -108,13 +106,7 @@ export const luciaAuthSignupHandler = (() => async (request) => {
108
106
  const userId = generateId(15);
109
107
 
110
108
  try {
111
- if (BATI.has("drizzle")) {
112
- drizzleDb.insert(userTable).values({ id: userId, username, password: passwordHash }).run();
113
- } else {
114
- sqliteDb
115
- .prepare("INSERT INTO users (id, username, password) VALUES(?, ?, ?)")
116
- .run(userId, username, passwordHash);
117
- }
109
+ (BATI.has("drizzle") ? drizzleQueries : sqliteQueries).signupWithCredentials(userId, username, passwordHash);
118
110
 
119
111
  const session = await lucia.createSession(userId, {});
120
112
 
@@ -165,7 +157,9 @@ export const luciaAuthLoginHandler = (() => async (request) => {
165
157
  });
166
158
  }
167
159
 
168
- const existingUser = getExistingUser(username) as DatabaseUser | undefined;
160
+ const existingUser = (BATI.has("drizzle") ? drizzleQueries : sqliteQueries).getExistingUser(username) as
161
+ | DatabaseUser
162
+ | undefined;
169
163
  if (!existingUser) {
170
164
  return new Response(JSON.stringify({ error: { invalid: "Incorrect username or password" } }), {
171
165
  status: 422,
@@ -280,7 +274,10 @@ export const luciaGithubCallbackHandler = (() => async (request) => {
280
274
  });
281
275
  const githubUser = (await githubUserResponse.json()) as GitHubUser;
282
276
 
283
- const existingAccount = getExistingAccount("github", githubUser.id) as DatabaseOAuthAccount | undefined;
277
+ const existingAccount = (BATI.has("drizzle") ? drizzleQueries : sqliteQueries).getExistingAccount(
278
+ "github",
279
+ githubUser.id,
280
+ ) as DatabaseOAuthAccount | undefined;
284
281
 
285
282
  if (existingAccount) {
286
283
  const session = await lucia.createSession(
@@ -298,19 +295,7 @@ export const luciaGithubCallbackHandler = (() => async (request) => {
298
295
 
299
296
  const userId = generateId(15);
300
297
 
301
- if (BATI.has("drizzle")) {
302
- await drizzleDb.transaction(async (tx) => {
303
- await tx.insert(userTable).values({ id: userId, username: githubUser.login });
304
- await tx.insert(oauthAccountTable).values({ providerId: "github", providerUserId: githubUser.id, userId });
305
- });
306
- } else {
307
- sqliteDb.transaction(() => {
308
- sqliteDb.prepare("INSERT INTO users (id, username) VALUES (?, ?)").run(userId, githubUser.login);
309
- sqliteDb
310
- .prepare("INSERT INTO oauth_accounts (provider_id, provider_user_id, user_id) VALUES (?, ?, ?)")
311
- .run("github", githubUser.id, userId);
312
- });
313
- }
298
+ (BATI.has("drizzle") ? drizzleQueries : sqliteQueries).signupWithGithub(userId, githubUser.login, githubUser.id);
314
299
 
315
300
  const session = await lucia.createSession(userId, {});
316
301
 
@@ -338,3 +323,31 @@ export const luciaGithubCallbackHandler = (() => async (request) => {
338
323
  });
339
324
  }
340
325
  }) satisfies Get<[], UniversalHandler>;
326
+
327
+ export function validateInput(username: string | null, password: string | null) {
328
+ const error: {
329
+ username: string | null;
330
+ password: string | null;
331
+ } = {
332
+ username: null,
333
+ password: null,
334
+ };
335
+
336
+ if (!username || username.length < 3 || username.length > 31 || !/^[a-z0-9_-]+$/.test(username)) {
337
+ error.username = "Invalid username";
338
+ }
339
+ if (!password || password.length < 6 || password.length > 255) {
340
+ error.password = "Invalid password";
341
+ }
342
+
343
+ if (error.username || error.password) {
344
+ return {
345
+ error,
346
+ success: false,
347
+ };
348
+ }
349
+ return {
350
+ error,
351
+ success: true,
352
+ };
353
+ }
@@ -56,3 +56,10 @@ export declare const luciaGithubLoginHandler: () => () => Promise<Response>;
56
56
  * @link {@see https://lucia-auth.com/guides/oauth/basics#validate-callback}
57
57
  */
58
58
  export declare const luciaGithubCallbackHandler: () => (request: Request) => Promise<Response>;
59
+ export declare function validateInput(username: string | null, password: string | null): {
60
+ error: {
61
+ username: string | null;
62
+ password: string | null;
63
+ };
64
+ success: boolean;
65
+ };
@@ -42,10 +42,10 @@ var require_package = __commonJS({
42
42
  license: "MIT",
43
43
  devDependencies: {
44
44
  "@batijs/compile": "workspace:*",
45
- "@prisma/client": "^5.18.0",
45
+ "@prisma/client": "^5.19.0",
46
46
  "@types/node": "^18.19.14",
47
47
  colorette: "^2.0.20",
48
- prisma: "^5.18.0"
48
+ prisma: "^5.19.0"
49
49
  },
50
50
  dependencies: {
51
51
  "@batijs/core": "workspace:*"