@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.
- package/dist/boilerplates/@batijs/authjs/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +2 -2
- package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +2 -3
- package/dist/boilerplates/@batijs/aws/files/$README.md.js +109 -0
- package/dist/boilerplates/@batijs/aws/files/$package.json.js +138 -0
- package/dist/boilerplates/@batijs/aws/files/$tsconfig.json.js +15 -0
- package/dist/boilerplates/@batijs/aws/files/cdk/$stack-name-suffix.json.js +19 -0
- package/dist/boilerplates/@batijs/aws/files/cdk/bin/infrastructure.ts +85 -0
- package/dist/boilerplates/@batijs/aws/files/cdk/lib/vike-stack.ts +186 -0
- package/dist/boilerplates/@batijs/aws/files/cdk.json +72 -0
- package/dist/boilerplates/@batijs/aws/files/tests/aws_handler.spec.ts +116 -0
- package/dist/boilerplates/@batijs/aws/files/vitest.config.ts +8 -0
- package/dist/boilerplates/@batijs/aws/types/cdk/bin/infrastructure.d.ts +11 -0
- package/dist/boilerplates/@batijs/aws/types/cdk/lib/vike-stack.d.ts +13 -0
- package/dist/boilerplates/@batijs/aws/types/vitest.config.d.ts +2 -0
- package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/cloudflare/files/$tsconfig.json.js +10 -0
- package/dist/boilerplates/@batijs/d1/files/$README.md.js +0 -4
- package/dist/boilerplates/@batijs/d1/files/$package.json.js +96 -0
- package/dist/boilerplates/@batijs/d1/files/$wrangler.toml.js +1 -0
- package/dist/boilerplates/@batijs/d1/files/database/d1/helpers.ts +17 -0
- package/dist/boilerplates/@batijs/d1/files/vike.d.ts +8 -0
- package/dist/boilerplates/@batijs/d1/types/database/d1/helpers.d.ts +6 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/$package.json.js +10 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/database/d1/queries/lucia-auth.ts +28 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/database/d1/queries/todos.ts +10 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/database/migrations/lucia-auth.sql +20 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/database/migrations/todos.sql +4 -0
- package/dist/boilerplates/@batijs/d1-sqlite/types/database/d1/queries/lucia-auth.d.ts +5 -0
- package/dist/boilerplates/@batijs/d1-sqlite/types/database/d1/queries/todos.d.ts +6 -0
- package/dist/boilerplates/@batijs/drizzle/files/$.env.js +1 -0
- package/dist/boilerplates/@batijs/drizzle/files/$README.md.js +0 -3
- package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +7 -14
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +10 -12
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/lucia-auth.ts +38 -9
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +16 -5
- package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +7 -4
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.ts +2 -2
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/lucia-auth.d.ts +19 -6
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.ts +9 -2
- package/dist/boilerplates/@batijs/eslint/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/eslint/files/eslint.config.js +2 -1
- package/dist/boilerplates/@batijs/express/files/$package.json.js +2 -1
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +13 -12
- package/dist/boilerplates/@batijs/fastify/files/$package.json.js +2 -1
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +17 -24
- package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +2 -2
- package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +2 -6
- package/dist/boilerplates/@batijs/h3/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +12 -2
- package/dist/boilerplates/@batijs/hattip/files/$package.json.js +15 -2
- package/dist/boilerplates/@batijs/hattip/files/entry_aws_lambda.ts +37 -0
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +12 -12
- package/dist/boilerplates/@batijs/hattip/types/entry_aws_lambda.d.ts +2 -0
- package/dist/boilerplates/@batijs/hono/files/$package.json.js +22 -4
- package/dist/boilerplates/@batijs/hono/files/entry_aws_lambda.ts +37 -0
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +12 -12
- package/dist/boilerplates/@batijs/hono/types/entry_aws_lambda.d.ts +3 -0
- package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +4 -1
- package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +75 -39
- package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +77 -33
- package/dist/boilerplates/@batijs/lucia-auth/types/lib/lucia-auth.d.ts +30 -10
- package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +13 -13
- package/dist/boilerplates/@batijs/react-lucia-auth/files/pages/login/+Page.tsx +2 -1
- package/dist/boilerplates/@batijs/shared/files/vite.config.ts +6 -0
- package/dist/boilerplates/@batijs/shared-db/files/server/db-middleware.ts +37 -0
- package/dist/boilerplates/@batijs/shared-db/types/server/db-middleware.d.ts +17 -0
- package/dist/boilerplates/@batijs/shared-no-db/files/$package.json.js +2 -1
- package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +5 -2
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +22 -4
- package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +2 -2
- package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.ts +19 -1
- package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +10 -4
- package/dist/boilerplates/@batijs/shared-todo/files/vike.d.ts +19 -0
- package/dist/boilerplates/@batijs/shared-todo/types/pages/todo/+data.d.ts +2 -1
- package/dist/boilerplates/@batijs/solid-lucia-auth/files/pages/login/+Page.tsx +2 -1
- package/dist/boilerplates/@batijs/sqlite/files/$.env.js +1 -0
- package/dist/boilerplates/@batijs/sqlite/files/$package.json.js +10 -1
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/lucia-auth.ts +16 -15
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/todos.ts +5 -5
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/lucia-auth.d.ts +5 -5
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/todos.d.ts +3 -2
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +5 -3
- package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +10 -3
- package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +15 -2
- package/dist/boilerplates/@batijs/telefunc/files/vike.d.ts +20 -0
- package/dist/boilerplates/@batijs/trpc/files/$package.json.js +10 -7
- package/dist/boilerplates/@batijs/trpc/files/server/trpc-handler.ts +22 -0
- package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +20 -4
- package/dist/boilerplates/@batijs/trpc/types/server/trpc-handler.d.ts +1 -0
- package/dist/boilerplates/@batijs/trpc/types/trpc/client.d.ts +36 -4
- package/dist/boilerplates/@batijs/trpc/types/trpc/server.d.ts +75 -8
- package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +48 -27
- package/dist/boilerplates/@batijs/vue-lucia-auth/files/pages/login/+Page.vue +2 -1
- package/dist/boilerplates/boilerplates.json +61 -3
- package/dist/index.js +6 -1
- package/package.json +5 -5
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/seed.ts +0 -13
- package/dist/boilerplates/@batijs/trpc/files/$vite.config.ts.js +0 -13
- package/dist/boilerplates/@batijs/trpc/files/trpc/vite-plugin.ts +0 -49
- package/dist/boilerplates/@batijs/trpc/types/trpc/vite-plugin.d.ts +0 -12
- /package/dist/boilerplates/@batijs/{drizzle/types/database/drizzle/seed.d.ts → aws/types/tests/aws_handler.spec.d.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Get, UniversalMiddleware } from "@universal-middleware/core";
|
|
2
|
+
import { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
3
|
+
import { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
4
|
+
import { D1Database } from "@cloudflare/workers-types";
|
|
5
|
+
declare global {
|
|
6
|
+
namespace Universal {
|
|
7
|
+
interface Context {
|
|
8
|
+
db: BATI.If<{
|
|
9
|
+
'BATI.has("sqlite") && !BATI.hasD1': ReturnType<typeof sqliteDb>;
|
|
10
|
+
'BATI.has("drizzle") && !BATI.hasD1': ReturnType<typeof dbSqlite>;
|
|
11
|
+
'BATI.has("drizzle")': ReturnType<typeof dbD1>;
|
|
12
|
+
"BATI.hasD1": D1Database;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export declare const dbMiddleware: Get<[], UniversalMiddleware>;
|
|
@@ -45,11 +45,14 @@ var require_package = __commonJS({
|
|
|
45
45
|
"@batijs/compile": "workspace:*",
|
|
46
46
|
"@batijs/core": "workspace:*",
|
|
47
47
|
"@batijs/drizzle": "workspace:*",
|
|
48
|
-
"@batijs/
|
|
48
|
+
"@batijs/d1": "workspace:*",
|
|
49
|
+
"@batijs/d1-sqlite": "workspace:*",
|
|
49
50
|
"@batijs/features": "workspace:*",
|
|
50
51
|
"@batijs/shared-no-db": "workspace:*",
|
|
52
|
+
"@batijs/sqlite": "workspace:*",
|
|
51
53
|
"@types/node": "^18.19.14",
|
|
52
|
-
"@universal-middleware/core": "^0.2.
|
|
54
|
+
"@universal-middleware/core": "^0.2.6",
|
|
55
|
+
"@cloudflare/workers-types": "^4.20240821.1",
|
|
53
56
|
vike: "^0.4.193",
|
|
54
57
|
vite: "^5.4.2"
|
|
55
58
|
},
|
|
@@ -2,15 +2,33 @@
|
|
|
2
2
|
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
3
3
|
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
4
4
|
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
5
|
+
import * as d1Queries from "@batijs/d1-sqlite/database/d1/queries/todos";
|
|
6
|
+
import type { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
7
|
+
import type { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
8
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
5
9
|
|
|
6
|
-
export const createTodoHandler: Get<
|
|
10
|
+
export const createTodoHandler: Get<
|
|
11
|
+
[],
|
|
12
|
+
UniversalHandler<
|
|
13
|
+
Universal.Context &
|
|
14
|
+
BATI.If<{
|
|
15
|
+
'BATI.has("sqlite") && !BATI.hasD1': { db: ReturnType<typeof sqliteDb> };
|
|
16
|
+
'BATI.has("drizzle") && !BATI.hasD1': { db: ReturnType<typeof dbSqlite> };
|
|
17
|
+
'BATI.has("drizzle")': { db: ReturnType<typeof dbD1> };
|
|
18
|
+
"BATI.hasD1": { db: D1Database };
|
|
19
|
+
_: object;
|
|
20
|
+
}>
|
|
21
|
+
>
|
|
22
|
+
> = () => async (request, _context, _runtime) => {
|
|
7
23
|
// In a real case, user-provided data should ALWAYS be validated with tools like zod
|
|
8
24
|
const newTodo = (await request.json()) as { text: string };
|
|
9
25
|
|
|
10
26
|
if (BATI.has("drizzle")) {
|
|
11
|
-
await drizzleQueries.insertTodo(newTodo.text);
|
|
12
|
-
} else if (BATI.has("sqlite")) {
|
|
13
|
-
sqliteQueries.insertTodo(newTodo.text);
|
|
27
|
+
await drizzleQueries.insertTodo(_context.db, newTodo.text);
|
|
28
|
+
} else if (BATI.has("sqlite") && !BATI.hasD1) {
|
|
29
|
+
sqliteQueries.insertTodo(_context.db, newTodo.text);
|
|
30
|
+
} else if (BATI.hasD1) {
|
|
31
|
+
await d1Queries.insertTodo(_context.db, newTodo.text);
|
|
14
32
|
} else {
|
|
15
33
|
// This is where you'd persist the data
|
|
16
34
|
console.log("Received new todo", newTodo);
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import { renderPage } from "vike/server";
|
|
4
4
|
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
5
5
|
|
|
6
|
-
export const vikeHandler: Get<[], UniversalHandler> = () => async (request, context) => {
|
|
7
|
-
const pageContextInit = { ...context, urlOriginal: request.url, headersOriginal: request.headers };
|
|
6
|
+
export const vikeHandler: Get<[], UniversalHandler> = () => async (request, context, runtime) => {
|
|
7
|
+
const pageContextInit = { ...context, ...runtime, urlOriginal: request.url, headersOriginal: request.headers };
|
|
8
8
|
const pageContext = await renderPage(pageContextInit);
|
|
9
9
|
const response = pageContext.httpResponse;
|
|
10
10
|
|
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
2
|
-
|
|
2
|
+
import type { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
3
|
+
import type { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
4
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
5
|
+
export declare const createTodoHandler: Get<[
|
|
6
|
+
], UniversalHandler<Universal.Context & BATI.If<{
|
|
7
|
+
'BATI.has("sqlite") && !BATI.hasD1': {
|
|
8
|
+
db: ReturnType<typeof sqliteDb>;
|
|
9
|
+
};
|
|
10
|
+
'BATI.has("drizzle") && !BATI.hasD1': {
|
|
11
|
+
db: ReturnType<typeof dbSqlite>;
|
|
12
|
+
};
|
|
13
|
+
'BATI.has("drizzle")': {
|
|
14
|
+
db: ReturnType<typeof dbD1>;
|
|
15
|
+
};
|
|
16
|
+
"BATI.hasD1": {
|
|
17
|
+
db: D1Database;
|
|
18
|
+
};
|
|
19
|
+
_: object;
|
|
20
|
+
}>>>;
|
|
@@ -2,18 +2,24 @@
|
|
|
2
2
|
import { todos } from "@batijs/shared-no-db/database/todoItems";
|
|
3
3
|
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
4
4
|
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
5
|
+
import * as d1Queries from "@batijs/d1-sqlite/database/d1/queries/todos";
|
|
6
|
+
import type { PageContextServer } from "vike/types";
|
|
5
7
|
|
|
6
8
|
export type Data = {
|
|
7
9
|
todo: { text: string }[];
|
|
8
10
|
};
|
|
9
11
|
|
|
10
|
-
export default async function data(): Promise<Data> {
|
|
12
|
+
export default async function data(_pageContext: PageContextServer): Promise<Data> {
|
|
11
13
|
if (BATI.has("drizzle")) {
|
|
12
|
-
const todo = drizzleQueries.getAllTodos();
|
|
14
|
+
const todo = await drizzleQueries.getAllTodos(_pageContext.db);
|
|
13
15
|
|
|
14
16
|
return { todo };
|
|
15
|
-
} else if (BATI.has("sqlite")) {
|
|
16
|
-
const todo = sqliteQueries.getAllTodos();
|
|
17
|
+
} else if (BATI.has("sqlite") && !BATI.hasD1) {
|
|
18
|
+
const todo = sqliteQueries.getAllTodos(_pageContext.db);
|
|
19
|
+
|
|
20
|
+
return { todo };
|
|
21
|
+
} else if (BATI.hasD1) {
|
|
22
|
+
const todo = await d1Queries.getAllTodos(_pageContext.db);
|
|
17
23
|
|
|
18
24
|
return { todo };
|
|
19
25
|
} else {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
2
|
+
import { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
3
|
+
import { D1Database } from "@cloudflare/workers-types";
|
|
4
|
+
|
|
5
|
+
//# BATI.hasDatabase
|
|
6
|
+
declare global {
|
|
7
|
+
namespace Vike {
|
|
8
|
+
interface PageContext {
|
|
9
|
+
db: BATI.If<{
|
|
10
|
+
'BATI.has("sqlite") && !BATI.hasD1': ReturnType<typeof sqliteDb>;
|
|
11
|
+
'BATI.has("drizzle") && !BATI.hasD1': ReturnType<typeof dbSqlite>;
|
|
12
|
+
'BATI.has("drizzle")': ReturnType<typeof dbD1>;
|
|
13
|
+
"BATI.hasD1": D1Database;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {};
|
|
@@ -28,7 +28,8 @@ export function Page() {
|
|
|
28
28
|
body: JSON.stringify(untrack(formData)),
|
|
29
29
|
headers: { "Content-Type": "application/json" },
|
|
30
30
|
});
|
|
31
|
-
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
const result: Record<string, any> = await response.json();
|
|
32
33
|
if ("error" in result) {
|
|
33
34
|
console.error("A validation error has occurred :", result.error);
|
|
34
35
|
setError(result.error);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// files/$.env.ts
|
|
2
2
|
import { appendToEnv } from "@batijs/core";
|
|
3
3
|
async function getEnv(props) {
|
|
4
|
+
if (props.meta.BATI.hasD1) return;
|
|
4
5
|
const envContent = await props.readfile?.();
|
|
5
6
|
return appendToEnv(envContent, "DATABASE_URL", "sqlite.db", "Path to the sqlite database");
|
|
6
7
|
}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Transaction } from "better-sqlite3";
|
|
1
|
+
import type { Database, Transaction } from "better-sqlite3";
|
|
3
2
|
|
|
4
|
-
export function getExistingUser(username: string) {
|
|
5
|
-
return db
|
|
3
|
+
export function getExistingUser<T>(db: Database, username: string) {
|
|
4
|
+
return db.prepare<[string], T>("SELECT * FROM users WHERE username = ?").get(username);
|
|
6
5
|
}
|
|
7
6
|
|
|
8
|
-
export function getExistingAccount(providerId: string, providerUserId: number) {
|
|
9
|
-
return db
|
|
10
|
-
.prepare("SELECT * FROM oauth_accounts WHERE provider_id = ? AND provider_user_id = ?")
|
|
7
|
+
export function getExistingAccount<T>(db: Database, providerId: string, providerUserId: number) {
|
|
8
|
+
return db
|
|
9
|
+
.prepare<[string, number], T>("SELECT * FROM oauth_accounts WHERE provider_id = ? AND provider_user_id = ?")
|
|
11
10
|
.get(providerId, providerUserId);
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
export function signupWithGithub(userId: string, username: string, githubUserId: number): Transaction {
|
|
15
|
-
return db
|
|
16
|
-
db
|
|
17
|
-
db()
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
export function signupWithGithub(db: Database, userId: string, username: string, githubUserId: number): Transaction {
|
|
14
|
+
return db.transaction(() => {
|
|
15
|
+
db.prepare("INSERT INTO users (id, username) VALUES (?, ?)").run(userId, username);
|
|
16
|
+
db.prepare("INSERT INTO oauth_accounts (provider_id, provider_user_id, user_id) VALUES (?, ?, ?)").run(
|
|
17
|
+
"github",
|
|
18
|
+
githubUserId,
|
|
19
|
+
userId,
|
|
20
|
+
);
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export function signupWithCredentials(userId: string, username: string, passwordHash: string) {
|
|
24
|
-
return db
|
|
24
|
+
export function signupWithCredentials(db: Database, userId: string, username: string, passwordHash: string) {
|
|
25
|
+
return db.prepare("INSERT INTO users (id, username, password) VALUES(?, ?, ?)").run(userId, username, passwordHash);
|
|
25
26
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Database } from "better-sqlite3";
|
|
2
2
|
|
|
3
|
-
export function insertTodo(text: string) {
|
|
4
|
-
return db
|
|
3
|
+
export function insertTodo(db: Database, text: string) {
|
|
4
|
+
return db.prepare("INSERT INTO todos (text) VALUES (?)").run(text);
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export function getAllTodos() {
|
|
8
|
-
return db
|
|
7
|
+
export function getAllTodos(db: Database) {
|
|
8
|
+
return db.prepare<[], { id: number; text: string }>("SELECT * FROM todos").all();
|
|
9
9
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Transaction } from "better-sqlite3";
|
|
2
|
-
export declare function getExistingUser(username: string):
|
|
3
|
-
export declare function getExistingAccount(providerId: string, providerUserId: number):
|
|
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;
|
|
1
|
+
import type { Database, Transaction } from "better-sqlite3";
|
|
2
|
+
export declare function getExistingUser<T>(db: Database, username: string): T | undefined;
|
|
3
|
+
export declare function getExistingAccount<T>(db: Database, providerId: string, providerUserId: number): T | undefined;
|
|
4
|
+
export declare function signupWithGithub(db: Database, userId: string, username: string, githubUserId: number): Transaction;
|
|
5
|
+
export declare function signupWithCredentials(db: Database, userId: string, username: string, passwordHash: string): import("better-sqlite3").RunResult;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
1
|
+
import type { Database } from "better-sqlite3";
|
|
2
|
+
export declare function insertTodo(db: Database, text: string): import("better-sqlite3").RunResult;
|
|
3
|
+
export declare function getAllTodos(db: Database): {
|
|
3
4
|
id: number;
|
|
4
5
|
text: string;
|
|
5
6
|
}[];
|
|
@@ -43,11 +43,13 @@ var require_package = __commonJS({
|
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@batijs/compile": "workspace:*",
|
|
45
45
|
"@batijs/drizzle": "workspace:*",
|
|
46
|
-
"@batijs/
|
|
47
|
-
"@batijs/
|
|
46
|
+
"@batijs/d1": "workspace:*",
|
|
47
|
+
"@batijs/d1-sqlite": "workspace:*",
|
|
48
48
|
"@batijs/shared-todo": "workspace:*",
|
|
49
|
+
"@batijs/sqlite": "workspace:*",
|
|
50
|
+
"@cloudflare/workers-types": "^4.20240821.1",
|
|
49
51
|
"@types/node": "^18.19.14",
|
|
50
|
-
"@universal-middleware/core": "^0.2.
|
|
52
|
+
"@universal-middleware/core": "^0.2.6",
|
|
51
53
|
telefunc: "^0.1.78",
|
|
52
54
|
vike: "^0.4.193",
|
|
53
55
|
vite: "^5.4.2"
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
2
2
|
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
3
|
+
import * as d1Queries from "@batijs/d1-sqlite/database/d1/queries/todos";
|
|
4
|
+
import { getContext } from "telefunc";
|
|
3
5
|
|
|
4
6
|
export async function onNewTodo({ text }: { text: string }) {
|
|
5
7
|
if (BATI.has("drizzle")) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const context = getContext();
|
|
9
|
+
await drizzleQueries.insertTodo(context.db, text);
|
|
10
|
+
} else if (BATI.has("sqlite") && !BATI.hasD1) {
|
|
11
|
+
const context = getContext();
|
|
12
|
+
sqliteQueries.insertTodo(context.db, text);
|
|
13
|
+
} else if (BATI.hasD1) {
|
|
14
|
+
const context = getContext();
|
|
15
|
+
await d1Queries.insertTodo(context.db, text);
|
|
9
16
|
} else {
|
|
10
17
|
// This is where you'd persist the data
|
|
11
18
|
console.log("Received new todo", { text });
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { telefunc } from "telefunc";
|
|
2
2
|
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
3
|
+
import type { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
4
|
+
import type { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
5
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
3
6
|
|
|
4
|
-
export const telefuncHandler: Get<[], UniversalHandler> = () => async (request, context) => {
|
|
7
|
+
export const telefuncHandler: Get<[], UniversalHandler> = () => async (request, context, runtime) => {
|
|
5
8
|
const httpResponse = await telefunc({
|
|
6
9
|
url: request.url.toString(),
|
|
7
10
|
method: request.method,
|
|
8
11
|
body: await request.text(),
|
|
9
|
-
context
|
|
12
|
+
context: {
|
|
13
|
+
...(context as BATI.If<{
|
|
14
|
+
'BATI.has("sqlite") && !BATI.hasD1': { db: ReturnType<typeof sqliteDb> };
|
|
15
|
+
'BATI.has("drizzle") && !BATI.hasD1': { db: ReturnType<typeof dbSqlite> };
|
|
16
|
+
'BATI.has("drizzle")': { db: ReturnType<typeof dbD1> };
|
|
17
|
+
"BATI.hasD1": { db: D1Database };
|
|
18
|
+
}>),
|
|
19
|
+
...(runtime as BATI.If<{
|
|
20
|
+
"BATI.hasD1": { runtime: "workerd"; adapter: string; env: { DB: D1Database } };
|
|
21
|
+
}>),
|
|
22
|
+
},
|
|
10
23
|
});
|
|
11
24
|
const { body, statusCode, contentType } = httpResponse;
|
|
12
25
|
return new Response(body, {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { D1Database } from "@cloudflare/workers-types";
|
|
2
|
+
import { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
3
|
+
import { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
4
|
+
|
|
5
|
+
//# BATI.hasDatabase
|
|
6
|
+
declare module "telefunc" {
|
|
7
|
+
namespace Telefunc {
|
|
8
|
+
interface Context {
|
|
9
|
+
db: BATI.If<{
|
|
10
|
+
'BATI.has("sqlite") && !BATI.hasD1': ReturnType<typeof sqliteDb>;
|
|
11
|
+
'BATI.has("drizzle") && !BATI.hasD1': ReturnType<typeof dbSqlite>;
|
|
12
|
+
'BATI.has("drizzle")': ReturnType<typeof dbD1>;
|
|
13
|
+
"BATI.hasD1": D1Database;
|
|
14
|
+
_: object;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {};
|
|
@@ -43,12 +43,15 @@ var require_package = __commonJS({
|
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@batijs/compile": "workspace:*",
|
|
45
45
|
"@batijs/drizzle": "workspace:*",
|
|
46
|
+
"@batijs/d1": "workspace:*",
|
|
47
|
+
"@batijs/d1-sqlite": "workspace:*",
|
|
46
48
|
"@batijs/sqlite": "workspace:*",
|
|
47
|
-
"@batijs/shared-no-db": "workspace:*",
|
|
48
49
|
"@batijs/shared-todo": "workspace:*",
|
|
50
|
+
"@cloudflare/workers-types": "^4.20240821.1",
|
|
49
51
|
"@trpc/client": "^10.45.2",
|
|
50
52
|
"@trpc/server": "^10.45.2",
|
|
51
53
|
"@types/node": "^18.19.14",
|
|
54
|
+
"@universal-middleware/core": "^0.2.6",
|
|
52
55
|
vite: "^5.4.2"
|
|
53
56
|
},
|
|
54
57
|
dependencies: {
|
|
@@ -67,11 +70,11 @@ var require_package = __commonJS({
|
|
|
67
70
|
"trpc/server": [
|
|
68
71
|
"./dist/types/trpc/server.d.ts"
|
|
69
72
|
],
|
|
73
|
+
"server/trpc-handler": [
|
|
74
|
+
"./dist/types/server/trpc-handler.d.ts"
|
|
75
|
+
],
|
|
70
76
|
"trpc/client": [
|
|
71
77
|
"./dist/types/trpc/client.d.ts"
|
|
72
|
-
],
|
|
73
|
-
"trpc/vite-plugin": [
|
|
74
|
-
"./dist/types/trpc/vite-plugin.d.ts"
|
|
75
78
|
]
|
|
76
79
|
}
|
|
77
80
|
},
|
|
@@ -79,11 +82,11 @@ var require_package = __commonJS({
|
|
|
79
82
|
"./trpc/server": {
|
|
80
83
|
types: "./dist/types/trpc/server.d.ts"
|
|
81
84
|
},
|
|
85
|
+
"./server/trpc-handler": {
|
|
86
|
+
types: "./dist/types/server/trpc-handler.d.ts"
|
|
87
|
+
},
|
|
82
88
|
"./trpc/client": {
|
|
83
89
|
types: "./dist/types/trpc/client.d.ts"
|
|
84
|
-
},
|
|
85
|
-
"./trpc/vite-plugin": {
|
|
86
|
-
types: "./dist/types/trpc/vite-plugin.d.ts"
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*# BATI include-if-imported #*/
|
|
2
|
+
import { appRouter } from "../trpc/server";
|
|
3
|
+
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
4
|
+
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
5
|
+
|
|
6
|
+
export const trpcHandler = ((endpoint) => (request, context, runtime) => {
|
|
7
|
+
return fetchRequestHandler({
|
|
8
|
+
endpoint,
|
|
9
|
+
req: request,
|
|
10
|
+
router: appRouter,
|
|
11
|
+
createContext({ req, resHeaders }) {
|
|
12
|
+
return {
|
|
13
|
+
...(context as BATI.Any),
|
|
14
|
+
...(runtime as BATI.If<{
|
|
15
|
+
"BATI.hasD1": { runtime: "workerd"; adapter: string; env: { DB: D1Database } };
|
|
16
|
+
}>),
|
|
17
|
+
req,
|
|
18
|
+
resHeaders,
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}) satisfies Get<[endpoint: string], UniversalHandler>;
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import { initTRPC } from "@trpc/server";
|
|
2
2
|
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
3
3
|
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
4
|
+
import * as d1Queries from "@batijs/d1-sqlite/database/d1/queries/todos";
|
|
5
|
+
import type { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
6
|
+
import type { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
7
|
+
import { D1Database } from "@cloudflare/workers-types";
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Initialization of tRPC backend
|
|
7
11
|
* Should be done only once per backend!
|
|
8
12
|
*/
|
|
9
|
-
const t = initTRPC
|
|
13
|
+
const t = initTRPC
|
|
14
|
+
.context<
|
|
15
|
+
BATI.If<{
|
|
16
|
+
'BATI.has("sqlite") && !BATI.hasD1': { db: ReturnType<typeof sqliteDb> };
|
|
17
|
+
'BATI.has("drizzle") && !BATI.hasD1': { db: ReturnType<typeof dbSqlite> };
|
|
18
|
+
'BATI.has("drizzle")': { db: ReturnType<typeof dbD1> };
|
|
19
|
+
"BATI.hasD1": { db: D1Database };
|
|
20
|
+
_: object;
|
|
21
|
+
}>
|
|
22
|
+
>()
|
|
23
|
+
.create();
|
|
10
24
|
|
|
11
25
|
/**
|
|
12
26
|
* Export reusable router and procedure helpers
|
|
@@ -28,9 +42,11 @@ export const appRouter = router({
|
|
|
28
42
|
})
|
|
29
43
|
.mutation(async (opts) => {
|
|
30
44
|
if (BATI.has("drizzle")) {
|
|
31
|
-
await drizzleQueries.insertTodo(opts.input);
|
|
32
|
-
} else if (BATI.has("sqlite")) {
|
|
33
|
-
sqliteQueries.insertTodo(opts.input);
|
|
45
|
+
await drizzleQueries.insertTodo(opts.ctx.db, opts.input);
|
|
46
|
+
} else if (BATI.has("sqlite") && !BATI.hasD1) {
|
|
47
|
+
sqliteQueries.insertTodo(opts.ctx.db, opts.input);
|
|
48
|
+
} else if (BATI.hasD1) {
|
|
49
|
+
await d1Queries.insertTodo(opts.ctx.db, opts.input);
|
|
34
50
|
} else {
|
|
35
51
|
// This is where you'd persist the data
|
|
36
52
|
console.log("Received new todo", { text: opts.input });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const trpcHandler: (endpoint: string) => (request: Request<unknown, CfProperties<unknown>>, context: Universal.Context, runtime: import("@universal-middleware/core").RuntimeAdapter) => Promise<Response>;
|
|
@@ -2,12 +2,28 @@ export declare const trpc: {
|
|
|
2
2
|
demo: {
|
|
3
3
|
query: import("@trpc/client").Resolver<import("@trpc/server").BuildProcedure<"query", {
|
|
4
4
|
_config: import("@trpc/server").RootConfig<{
|
|
5
|
-
ctx: object
|
|
5
|
+
ctx: object & {
|
|
6
|
+
db: ReturnType<typeof import("@batijs/sqlite/database/sqlite/db").db>;
|
|
7
|
+
} & {
|
|
8
|
+
db: ReturnType<typeof import("@batijs/drizzle/database/drizzle/db").dbSqlite>;
|
|
9
|
+
} & {
|
|
10
|
+
db: ReturnType<typeof import("@batijs/drizzle/database/drizzle/db").dbD1>;
|
|
11
|
+
} & {
|
|
12
|
+
db: import("@cloudflare/workers-types").D1Database;
|
|
13
|
+
};
|
|
6
14
|
meta: object;
|
|
7
15
|
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
8
16
|
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
9
17
|
}>;
|
|
10
|
-
_ctx_out: object
|
|
18
|
+
_ctx_out: object & {
|
|
19
|
+
db: ReturnType<typeof import("@batijs/sqlite/database/sqlite/db").db>;
|
|
20
|
+
} & {
|
|
21
|
+
db: ReturnType<typeof import("@batijs/drizzle/database/drizzle/db").dbSqlite>;
|
|
22
|
+
} & {
|
|
23
|
+
db: ReturnType<typeof import("@batijs/drizzle/database/drizzle/db").dbD1>;
|
|
24
|
+
} & {
|
|
25
|
+
db: import("@cloudflare/workers-types").D1Database;
|
|
26
|
+
};
|
|
11
27
|
_input_in: typeof import("@trpc/server").unsetMarker;
|
|
12
28
|
_input_out: typeof import("@trpc/server").unsetMarker;
|
|
13
29
|
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
@@ -20,13 +36,29 @@ export declare const trpc: {
|
|
|
20
36
|
onNewTodo: {
|
|
21
37
|
mutate: import("@trpc/client").Resolver<import("@trpc/server").BuildProcedure<"mutation", {
|
|
22
38
|
_config: import("@trpc/server").RootConfig<{
|
|
23
|
-
ctx: object
|
|
39
|
+
ctx: object & {
|
|
40
|
+
db: ReturnType<typeof import("@batijs/sqlite/database/sqlite/db").db>;
|
|
41
|
+
} & {
|
|
42
|
+
db: ReturnType<typeof import("@batijs/drizzle/database/drizzle/db").dbSqlite>;
|
|
43
|
+
} & {
|
|
44
|
+
db: ReturnType<typeof import("@batijs/drizzle/database/drizzle/db").dbD1>;
|
|
45
|
+
} & {
|
|
46
|
+
db: import("@cloudflare/workers-types").D1Database;
|
|
47
|
+
};
|
|
24
48
|
meta: object;
|
|
25
49
|
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
26
50
|
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
27
51
|
}>;
|
|
28
52
|
_meta: object;
|
|
29
|
-
_ctx_out: object
|
|
53
|
+
_ctx_out: object & {
|
|
54
|
+
db: ReturnType<typeof import("@batijs/sqlite/database/sqlite/db").db>;
|
|
55
|
+
} & {
|
|
56
|
+
db: ReturnType<typeof import("@batijs/drizzle/database/drizzle/db").dbSqlite>;
|
|
57
|
+
} & {
|
|
58
|
+
db: ReturnType<typeof import("@batijs/drizzle/database/drizzle/db").dbD1>;
|
|
59
|
+
} & {
|
|
60
|
+
db: import("@cloudflare/workers-types").D1Database;
|
|
61
|
+
};
|
|
30
62
|
_input_in: string;
|
|
31
63
|
_input_out: string;
|
|
32
64
|
_output_in: typeof import("@trpc/server").unsetMarker;
|