@batijs/cli 0.0.255 → 0.0.257
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +2 -1
- package/dist/boilerplates/@batijs/d1/files/$README.md.js +31 -0
- package/dist/boilerplates/@batijs/d1/files/$tsconfig.json.js +10 -0
- package/dist/boilerplates/@batijs/d1/files/$wrangler.toml.js +21 -0
- package/dist/boilerplates/@batijs/d1/files/vike.d.ts +8 -0
- package/dist/boilerplates/@batijs/drizzle/files/$.env.js +9 -0
- package/dist/boilerplates/@batijs/drizzle/files/$README.md.js +4 -4
- package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +33 -14
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +16 -0
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/lucia-auth.ts +27 -0
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +11 -0
- package/dist/boilerplates/@batijs/drizzle/files/database/{schema → drizzle/schema}/todos.ts +1 -0
- package/dist/boilerplates/@batijs/drizzle/files/database/{seed.ts → drizzle/seed.ts} +3 -3
- package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +7 -3
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.ts +2 -0
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/lucia-auth.d.ts +12 -0
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.ts +43 -0
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +1 -1
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +2 -2
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +1 -1
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +1 -1
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +1 -1
- package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +1 -18
- package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +5 -5
- package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +39 -26
- package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +7 -0
- package/dist/boilerplates/@batijs/react/files/pages/todo/TodoList.tsx +1 -7
- package/dist/boilerplates/@batijs/shared/files/vite.config.ts +1 -1
- package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +6 -3
- package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +7 -3
- package/dist/boilerplates/@batijs/solid/files/pages/todo/TodoList.tsx +1 -7
- package/dist/boilerplates/@batijs/sqlite/files/$.env.js +9 -0
- package/dist/boilerplates/@batijs/sqlite/files/$README.md.js +18 -0
- package/dist/boilerplates/@batijs/sqlite/files/$package.json.js +120 -0
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/db.ts +15 -0
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/lucia-auth.ts +25 -0
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/todos.ts +9 -0
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/schema/all.ts +3 -0
- package/dist/boilerplates/@batijs/{lucia-auth/files/database/sqliteDb.ts → sqlite/files/database/sqlite/schema/lucia-auth.ts} +6 -5
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/schema/todos.ts +14 -0
- package/dist/boilerplates/@batijs/{lucia-auth/types/database/sqliteDb.d.ts → sqlite/types/database/sqlite/db.d.ts} +1 -1
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/lucia-auth.d.ts +5 -0
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/todos.d.ts +5 -0
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/all.d.ts +2 -0
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/lucia-auth.d.ts +1 -0
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/schema/todos.d.ts +1 -0
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +5 -3
- package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +5 -3
- package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +5 -3
- package/dist/boilerplates/@batijs/vue/files/pages/todo/TodoList.vue +1 -1
- package/dist/boilerplates/boilerplates.json +27 -0
- package/dist/index.js +6 -3
- package/package.json +5 -5
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzleDb.ts +0 -5
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzleDb.d.ts +0 -1
- package/dist/boilerplates/@batijs/lucia-auth/files/database/auth-actions.ts +0 -54
- package/dist/boilerplates/@batijs/lucia-auth/types/database/auth-actions.d.ts +0 -9
- /package/dist/boilerplates/@batijs/{lucia-auth/files/database/schema/auth.ts → drizzle/files/database/drizzle/schema/lucia-auth.ts} +0 -0
- /package/dist/boilerplates/@batijs/{lucia-auth/types/database/schema/auth.d.ts → drizzle/types/database/drizzle/schema/lucia-auth.d.ts} +0 -0
- /package/dist/boilerplates/@batijs/drizzle/types/database/{schema → drizzle/schema}/todos.d.ts +0 -0
- /package/dist/boilerplates/@batijs/drizzle/types/database/{seed.d.ts → drizzle/seed.d.ts} +0 -0
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import { todoTable } from "@batijs/drizzle/database/schema/todos";
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
3
2
|
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
3
|
+
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
4
|
+
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
4
5
|
|
|
5
6
|
export const createTodoHandler: Get<[], UniversalHandler> = () => async (request) => {
|
|
6
7
|
// In a real case, user-provided data should ALWAYS be validated with tools like zod
|
|
7
8
|
const newTodo = (await request.json()) as { text: string };
|
|
8
9
|
|
|
9
10
|
if (BATI.has("drizzle")) {
|
|
10
|
-
await
|
|
11
|
+
await drizzleQueries.insertTodo(newTodo.text);
|
|
12
|
+
} else if (BATI.has("sqlite")) {
|
|
13
|
+
sqliteQueries.insertTodo(newTodo.text);
|
|
11
14
|
} else {
|
|
12
15
|
// This is where you'd persist the data
|
|
13
16
|
console.log("Received new todo", newTodo);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// https://vike.dev/data
|
|
2
|
-
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
3
|
-
import { todoTable } from "@batijs/drizzle/database/schema/todos";
|
|
4
2
|
import { todos } from "@batijs/shared-no-db/database/todoItems";
|
|
3
|
+
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
4
|
+
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
5
5
|
|
|
6
6
|
export type Data = {
|
|
7
7
|
todo: { text: string }[];
|
|
@@ -9,7 +9,11 @@ export type Data = {
|
|
|
9
9
|
|
|
10
10
|
export default async function data(): Promise<Data> {
|
|
11
11
|
if (BATI.has("drizzle")) {
|
|
12
|
-
const todo =
|
|
12
|
+
const todo = drizzleQueries.getAllTodos();
|
|
13
|
+
|
|
14
|
+
return { todo };
|
|
15
|
+
} else if (BATI.has("sqlite")) {
|
|
16
|
+
const todo = sqliteQueries.getAllTodos();
|
|
13
17
|
|
|
14
18
|
return { todo };
|
|
15
19
|
} else {
|
|
@@ -18,13 +18,7 @@ export function TodoList(props: { initialTodoItems: { text: string }[] }) {
|
|
|
18
18
|
|
|
19
19
|
// Optimistic UI update
|
|
20
20
|
setTodoItems((prev) => [...prev, { text: untrack(newTodo) }]);
|
|
21
|
-
if (
|
|
22
|
-
BATI.has("express") ||
|
|
23
|
-
BATI.has("fastify") ||
|
|
24
|
-
BATI.has("h3") ||
|
|
25
|
-
BATI.has("hattip") ||
|
|
26
|
-
BATI.has("hono")
|
|
27
|
-
) {
|
|
21
|
+
if (BATI.hasServer) {
|
|
28
22
|
try {
|
|
29
23
|
if (BATI.has("telefunc")) {
|
|
30
24
|
await onNewTodo({ text: untrack(newTodo) });
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
## *Sqlite*
|
|
7
|
+
|
|
8
|
+
First, ensure that \`DATABASE_URL\` is configured in \`.env\` file, then create the database:
|
|
9
|
+
\`\`\`bash
|
|
10
|
+
pnpm sqlite:migrate # creates sqlite tables
|
|
11
|
+
\`\`\`
|
|
12
|
+
`;
|
|
13
|
+
content.addTodo(todo);
|
|
14
|
+
return content.finalize();
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
getReadme as default
|
|
18
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// package.json
|
|
28
|
+
var require_package = __commonJS({
|
|
29
|
+
"package.json"(exports, module) {
|
|
30
|
+
module.exports = {
|
|
31
|
+
name: "@batijs/sqlite",
|
|
32
|
+
private: true,
|
|
33
|
+
version: "0.0.1",
|
|
34
|
+
description: "",
|
|
35
|
+
type: "module",
|
|
36
|
+
scripts: {
|
|
37
|
+
"check-types": "tsc --noEmit",
|
|
38
|
+
build: "bati-compile-boilerplate"
|
|
39
|
+
},
|
|
40
|
+
keywords: [],
|
|
41
|
+
author: "",
|
|
42
|
+
license: "MIT",
|
|
43
|
+
devDependencies: {
|
|
44
|
+
"@batijs/compile": "workspace:*",
|
|
45
|
+
"@types/node": "^18.19.14",
|
|
46
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
47
|
+
"better-sqlite3": "^11.2.1",
|
|
48
|
+
dotenv: "^16.4.5",
|
|
49
|
+
tsx: "^4.19.0"
|
|
50
|
+
},
|
|
51
|
+
dependencies: {
|
|
52
|
+
"@batijs/core": "workspace:*"
|
|
53
|
+
},
|
|
54
|
+
files: [
|
|
55
|
+
"dist/"
|
|
56
|
+
],
|
|
57
|
+
bati: {
|
|
58
|
+
if: {
|
|
59
|
+
flag: "sqlite"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
exports: {
|
|
63
|
+
"./database/sqlite/db": {
|
|
64
|
+
types: "./dist/types/database/sqlite/db.d.ts"
|
|
65
|
+
},
|
|
66
|
+
"./database/sqlite/queries/lucia-auth": {
|
|
67
|
+
types: "./dist/types/database/sqlite/queries/lucia-auth.d.ts"
|
|
68
|
+
},
|
|
69
|
+
"./database/sqlite/queries/todos": {
|
|
70
|
+
types: "./dist/types/database/sqlite/queries/todos.d.ts"
|
|
71
|
+
},
|
|
72
|
+
"./database/sqlite/schema/lucia-auth": {
|
|
73
|
+
types: "./dist/types/database/sqlite/schema/lucia-auth.d.ts"
|
|
74
|
+
},
|
|
75
|
+
"./database/sqlite/schema/todos": {
|
|
76
|
+
types: "./dist/types/database/sqlite/schema/todos.d.ts"
|
|
77
|
+
},
|
|
78
|
+
"./database/sqlite/schema/all": {
|
|
79
|
+
types: "./dist/types/database/sqlite/schema/all.d.ts"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
typesVersions: {
|
|
83
|
+
"*": {
|
|
84
|
+
"database/sqlite/db": [
|
|
85
|
+
"./dist/types/database/sqlite/db.d.ts"
|
|
86
|
+
],
|
|
87
|
+
"database/sqlite/queries/lucia-auth": [
|
|
88
|
+
"./dist/types/database/sqlite/queries/lucia-auth.d.ts"
|
|
89
|
+
],
|
|
90
|
+
"database/sqlite/queries/todos": [
|
|
91
|
+
"./dist/types/database/sqlite/queries/todos.d.ts"
|
|
92
|
+
],
|
|
93
|
+
"database/sqlite/schema/lucia-auth": [
|
|
94
|
+
"./dist/types/database/sqlite/schema/lucia-auth.d.ts"
|
|
95
|
+
],
|
|
96
|
+
"database/sqlite/schema/todos": [
|
|
97
|
+
"./dist/types/database/sqlite/schema/todos.d.ts"
|
|
98
|
+
],
|
|
99
|
+
"database/sqlite/schema/all": [
|
|
100
|
+
"./dist/types/database/sqlite/schema/all.d.ts"
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// files/$package.json.ts
|
|
109
|
+
import { addDependency, loadAsJson } from "@batijs/core";
|
|
110
|
+
async function getPackageJson(props) {
|
|
111
|
+
const packageJson = await loadAsJson(props);
|
|
112
|
+
packageJson.scripts["sqlite:migrate"] = "tsx ./database/sqlite/schema/all.ts";
|
|
113
|
+
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
114
|
+
devDependencies: ["dotenv", "@types/better-sqlite3", "tsx"],
|
|
115
|
+
dependencies: ["better-sqlite3"]
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
getPackageJson as default
|
|
120
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import sqlite, { type Database } from "better-sqlite3";
|
|
3
|
+
|
|
4
|
+
let singleton: Database | undefined = undefined;
|
|
5
|
+
|
|
6
|
+
export function db(): Database {
|
|
7
|
+
if (!singleton) {
|
|
8
|
+
if (!process.env.DATABASE_URL) {
|
|
9
|
+
throw new Error("Missing DATABASE_URL in .env file");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
singleton = sqlite(process.env.DATABASE_URL);
|
|
13
|
+
}
|
|
14
|
+
return singleton;
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { db } from "../db";
|
|
2
|
+
import type { Transaction } from "better-sqlite3";
|
|
3
|
+
|
|
4
|
+
export function getExistingUser(username: string) {
|
|
5
|
+
return db().prepare("SELECT * FROM users WHERE username = ?").get(username);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getExistingAccount(providerId: string, providerUserId: number) {
|
|
9
|
+
return db()
|
|
10
|
+
.prepare("SELECT * FROM oauth_accounts WHERE provider_id = ? AND provider_user_id = ?")
|
|
11
|
+
.get(providerId, providerUserId);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function signupWithGithub(userId: string, username: string, githubUserId: number): Transaction {
|
|
15
|
+
return db().transaction(() => {
|
|
16
|
+
db().prepare("INSERT INTO users (id, username) VALUES (?, ?)").run(userId, username);
|
|
17
|
+
db()
|
|
18
|
+
.prepare("INSERT INTO oauth_accounts (provider_id, provider_user_id, user_id) VALUES (?, ?, ?)")
|
|
19
|
+
.run("github", githubUserId, userId);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function signupWithCredentials(userId: string, username: string, passwordHash: string) {
|
|
24
|
+
return db().prepare("INSERT INTO users (id, username, password) VALUES(?, ?, ?)").run(userId, username, passwordHash);
|
|
25
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { db } from "../db";
|
|
2
|
+
|
|
3
|
+
export function insertTodo(text: string) {
|
|
4
|
+
return db().prepare("INSERT INTO todos (text) VALUES (?)").run(text);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getAllTodos() {
|
|
8
|
+
return db().prepare<[], { id: number; text: string }>("SELECT * FROM todos").all();
|
|
9
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/*# BATI include-if-imported #*/
|
|
2
|
-
import
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { db } from "../db";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
const client = db();
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* SQLite Schema
|
|
8
9
|
*
|
|
9
10
|
* @link {@see https://lucia-auth.com/database/sqlite#schema}
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
client.exec(`CREATE TABLE IF NOT EXISTS users (
|
|
12
13
|
id TEXT NOT NULL PRIMARY KEY,
|
|
13
14
|
username TEXT NOT NULL UNIQUE,
|
|
14
15
|
password TEXT
|
|
15
16
|
)`);
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
client.exec(`CREATE TABLE IF NOT EXISTS oauth_accounts (
|
|
18
19
|
provider_id TEXT NOT NULL,
|
|
19
20
|
provider_user_id INTEGER NOT NULL,
|
|
20
21
|
user_id TEXT NOT NULL,
|
|
@@ -22,7 +23,7 @@ sqliteDb.exec(`CREATE TABLE IF NOT EXISTS oauth_accounts (
|
|
|
22
23
|
FOREIGN KEY (user_id) REFERENCES users(id) ON UPDATE cascade ON DELETE cascade
|
|
23
24
|
)`);
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
client.exec(`CREATE TABLE IF NOT EXISTS sessions (
|
|
26
27
|
id TEXT NOT NULL PRIMARY KEY,
|
|
27
28
|
expires_at INTEGER NOT NULL,
|
|
28
29
|
user_id TEXT NOT NULL,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { db } from "../db";
|
|
4
|
+
|
|
5
|
+
const client = db();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* SQLite Schema
|
|
9
|
+
* `todos` example
|
|
10
|
+
*/
|
|
11
|
+
client.exec(`CREATE TABLE IF NOT EXISTS todos (
|
|
12
|
+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
13
|
+
text TEXT
|
|
14
|
+
)`);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Database } from "better-sqlite3";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function db(): Database;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Transaction } from "better-sqlite3";
|
|
2
|
+
export declare function getExistingUser(username: string): unknown;
|
|
3
|
+
export declare function getExistingAccount(providerId: string, providerUserId: number): unknown;
|
|
4
|
+
export declare function signupWithGithub(userId: string, username: string, githubUserId: number): Transaction;
|
|
5
|
+
export declare function signupWithCredentials(userId: string, username: string, passwordHash: string): import("better-sqlite3").RunResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
@@ -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
|
"@batijs/shared-no-db": "workspace:*",
|
|
47
48
|
"@batijs/shared-todo": "workspace:*",
|
|
48
49
|
"@types/node": "^18.19.14",
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
2
|
+
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
3
3
|
|
|
4
4
|
export async function onNewTodo({ text }: { text: string }) {
|
|
5
5
|
if (BATI.has("drizzle")) {
|
|
6
|
-
await
|
|
6
|
+
await drizzleQueries.insertTodo(text);
|
|
7
|
+
} else if (BATI.has("sqlite")) {
|
|
8
|
+
sqliteQueries.insertTodo(text);
|
|
7
9
|
} else {
|
|
8
10
|
// This is where you'd persist the data
|
|
9
11
|
console.log("Received new todo", { text });
|
|
@@ -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
|
"@batijs/shared-no-db": "workspace:*",
|
|
47
48
|
"@batijs/shared-todo": "workspace:*",
|
|
48
49
|
"@trpc/client": "^10.45.2",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
2
|
-
import { todoTable } from "@batijs/drizzle/database/schema/todos";
|
|
3
1
|
import { initTRPC } from "@trpc/server";
|
|
2
|
+
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
3
|
+
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Initialization of tRPC backend
|
|
@@ -28,7 +28,9 @@ export const appRouter = router({
|
|
|
28
28
|
})
|
|
29
29
|
.mutation(async (opts) => {
|
|
30
30
|
if (BATI.has("drizzle")) {
|
|
31
|
-
await
|
|
31
|
+
await drizzleQueries.insertTodo(opts.input);
|
|
32
|
+
} else if (BATI.has("sqlite")) {
|
|
33
|
+
sqliteQueries.insertTodo(opts.input);
|
|
32
34
|
} else {
|
|
33
35
|
// This is where you'd persist the data
|
|
34
36
|
console.log("Received new todo", { text: opts.input });
|
|
@@ -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
|
"@batijs/shared-no-db": "workspace:*",
|
|
47
48
|
"@ts-rest/core": "^3.51.0",
|
|
48
49
|
"@ts-rest/serverless": "^3.51.0",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
2
|
-
import { todoTable } from "@batijs/drizzle/database/schema/todos";
|
|
3
1
|
import { fetchRequestHandler, tsr } from "@ts-rest/serverless/fetch";
|
|
4
2
|
import { contract } from "../ts-rest/contract";
|
|
5
3
|
import { Get, UniversalHandler } from "@universal-middleware/core";
|
|
4
|
+
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
5
|
+
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* ts-rest route
|
|
@@ -20,7 +20,9 @@ const router = tsr.router(contract, {
|
|
|
20
20
|
},
|
|
21
21
|
createTodo: async ({ body }) => {
|
|
22
22
|
if (BATI.has("drizzle")) {
|
|
23
|
-
await
|
|
23
|
+
await drizzleQueries.insertTodo(body.text);
|
|
24
|
+
} else if (BATI.has("sqlite")) {
|
|
25
|
+
sqliteQueries.insertTodo(body.text);
|
|
24
26
|
} else {
|
|
25
27
|
// This is where you'd persist the data
|
|
26
28
|
console.log("Received new todo", { text: body.text });
|
|
@@ -25,7 +25,7 @@ const newTodo = ref("");
|
|
|
25
25
|
const submitNewTodo = async () => {
|
|
26
26
|
// Optimistic UI update
|
|
27
27
|
todoItems.value.push({ text: newTodo.value });
|
|
28
|
-
if (BATI.
|
|
28
|
+
if (BATI.hasServer) {
|
|
29
29
|
try {
|
|
30
30
|
if (BATI.has("telefunc")) {
|
|
31
31
|
await onNewTodo({ text: newTodo.value });
|
|
@@ -59,6 +59,22 @@
|
|
|
59
59
|
"files"
|
|
60
60
|
]
|
|
61
61
|
},
|
|
62
|
+
{
|
|
63
|
+
"config": {
|
|
64
|
+
"if": {
|
|
65
|
+
"flag": {
|
|
66
|
+
"$all": [
|
|
67
|
+
"sqlite",
|
|
68
|
+
"cloudflare"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"folder": "@batijs/d1",
|
|
74
|
+
"subfolders": [
|
|
75
|
+
"files"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
62
78
|
{
|
|
63
79
|
"config": {
|
|
64
80
|
"if": {
|
|
@@ -381,6 +397,17 @@
|
|
|
381
397
|
"files"
|
|
382
398
|
]
|
|
383
399
|
},
|
|
400
|
+
{
|
|
401
|
+
"config": {
|
|
402
|
+
"if": {
|
|
403
|
+
"flag": "sqlite"
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
"folder": "@batijs/sqlite",
|
|
407
|
+
"subfolders": [
|
|
408
|
+
"files"
|
|
409
|
+
]
|
|
410
|
+
},
|
|
384
411
|
{
|
|
385
412
|
"config": {
|
|
386
413
|
"if": {
|
package/dist/index.js
CHANGED
|
@@ -324,7 +324,7 @@ Please report this issue to https://github.com/vikejs/bati`
|
|
|
324
324
|
|
|
325
325
|
// index.ts
|
|
326
326
|
import { packageManager, which, withIcon } from "@batijs/core";
|
|
327
|
-
import { cliFlags, features } from "@batijs/features";
|
|
327
|
+
import { BatiSet, cliFlags, features } from "@batijs/features";
|
|
328
328
|
import { execRules } from "@batijs/features/rules";
|
|
329
329
|
|
|
330
330
|
// ../../node_modules/.pnpm/citty@0.1.6/node_modules/citty/dist/index.mjs
|
|
@@ -1676,7 +1676,7 @@ var createDefaultQueryTester = function(query, options) {
|
|
|
1676
1676
|
// package.json
|
|
1677
1677
|
var package_default = {
|
|
1678
1678
|
name: "@batijs/cli",
|
|
1679
|
-
version: "0.0.
|
|
1679
|
+
version: "0.0.257",
|
|
1680
1680
|
type: "module",
|
|
1681
1681
|
scripts: {
|
|
1682
1682
|
"check-types": "tsc --noEmit",
|
|
@@ -1756,6 +1756,9 @@ var rulesMessages = {
|
|
|
1756
1756
|
`${inverse(bold("Cloudflare"))} is only compatible with ${inverse(bold("Hono"))} or ${inverse(bold("HatTip"))}.
|
|
1757
1757
|
Choose one of them, or simply remove selected Server`
|
|
1758
1758
|
),
|
|
1759
|
+
[RulesMessage.ERROR_LUCIA_R_COMPAT_DATABASE]: error(
|
|
1760
|
+
`${inverse(bold("Lucia"))} requires a ${inverse(bold("Database"))}, and is only compatible with ${inverse(bold("SQLite"))} or ${inverse(bold("Drizzle"))}`
|
|
1761
|
+
),
|
|
1759
1762
|
[RulesMessage.INFO_DRIZZLE_STACKBLITZ]: null
|
|
1760
1763
|
};
|
|
1761
1764
|
|
|
@@ -2041,7 +2044,7 @@ async function run() {
|
|
|
2041
2044
|
}
|
|
2042
2045
|
const hooksMap = await retrieveHooks(hooks);
|
|
2043
2046
|
const meta = {
|
|
2044
|
-
BATI: new
|
|
2047
|
+
BATI: new BatiSet(flags, features),
|
|
2045
2048
|
BATI_TEST: Boolean(process.env.BATI_TEST)
|
|
2046
2049
|
};
|
|
2047
2050
|
await main(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@batijs/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.257",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"description": "Next-gen scaffolder. Get started with fully-functional apps, and choose any tool you want",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"typescript": "^5.5.4",
|
|
21
21
|
"unplugin-purge-polyfills": "^0.0.5",
|
|
22
22
|
"vite": "^5.4.2",
|
|
23
|
-
"@batijs/build": "0.0.
|
|
24
|
-
"@batijs/compile": "0.0.
|
|
23
|
+
"@batijs/build": "0.0.257",
|
|
24
|
+
"@batijs/compile": "0.0.257"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@batijs/
|
|
28
|
-
"@batijs/
|
|
27
|
+
"@batijs/core": "0.0.257",
|
|
28
|
+
"@batijs/features": "0.0.257"
|
|
29
29
|
},
|
|
30
30
|
"bin": "./dist/index.js",
|
|
31
31
|
"exports": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const drizzleDb: import("drizzle-orm/better-sqlite3").BetterSQLite3Database<Record<string, never>>;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { drizzleDb } from "@batijs/drizzle/database/drizzleDb";
|
|
2
|
-
import { sqliteDb } from "./sqliteDb";
|
|
3
|
-
import { userTable, oauthAccountTable } from "./schema/auth";
|
|
4
|
-
import { eq, and } from "drizzle-orm";
|
|
5
|
-
|
|
6
|
-
export function getExistingUser(username: string) {
|
|
7
|
-
if (BATI.has("drizzle")) {
|
|
8
|
-
return drizzleDb.select().from(userTable).where(eq(userTable.username, username)).get();
|
|
9
|
-
} else {
|
|
10
|
-
return sqliteDb.prepare("SELECT * FROM users WHERE username = ?").get(username);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function getExistingAccount(providerId: string, providerUserId: number) {
|
|
15
|
-
if (BATI.has("drizzle")) {
|
|
16
|
-
return drizzleDb
|
|
17
|
-
.select()
|
|
18
|
-
.from(oauthAccountTable)
|
|
19
|
-
.where(and(eq(oauthAccountTable.providerId, providerId), eq(oauthAccountTable.providerUserId, providerUserId)))
|
|
20
|
-
.get();
|
|
21
|
-
} else {
|
|
22
|
-
return sqliteDb
|
|
23
|
-
.prepare("SELECT * FROM oauth_accounts WHERE provider_id = ? AND provider_user_id = ?")
|
|
24
|
-
.get(providerId, providerUserId);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function validateInput(username: string | null, password: string | null) {
|
|
29
|
-
const error: {
|
|
30
|
-
username: string | null;
|
|
31
|
-
password: string | null;
|
|
32
|
-
} = {
|
|
33
|
-
username: null,
|
|
34
|
-
password: null,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (!username || username.length < 3 || username.length > 31 || !/^[a-z0-9_-]+$/.test(username)) {
|
|
38
|
-
error.username = "Invalid username";
|
|
39
|
-
}
|
|
40
|
-
if (!password || password.length < 6 || password.length > 255) {
|
|
41
|
-
error.password = "Invalid password";
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (error.username || error.password) {
|
|
45
|
-
return {
|
|
46
|
-
error,
|
|
47
|
-
success: false,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
error,
|
|
52
|
-
success: true,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare function getExistingUser(username: string): unknown;
|
|
2
|
-
export declare function getExistingAccount(providerId: string, providerUserId: number): unknown;
|
|
3
|
-
export declare function validateInput(username: string | null, password: string | null): {
|
|
4
|
-
error: {
|
|
5
|
-
username: string | null;
|
|
6
|
-
password: string | null;
|
|
7
|
-
};
|
|
8
|
-
success: boolean;
|
|
9
|
-
};
|
|
File without changes
|
|
File without changes
|
/package/dist/boilerplates/@batijs/drizzle/types/database/{schema → drizzle/schema}/todos.d.ts
RENAMED
|
File without changes
|
|
File without changes
|