@batijs/cli 0.0.259 → 0.0.260
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/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 +3 -1
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +12 -12
- package/dist/boilerplates/@batijs/hono/files/$package.json.js +14 -3
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +12 -12
- 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 +50 -3
- package/dist/index.js +2 -1
- package/package.json +5 -5
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/seed.ts +0 -13
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/seed.d.ts +0 -1
- 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
|
@@ -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;
|
|
@@ -1,21 +1,48 @@
|
|
|
1
|
+
import type { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
2
|
+
import type { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
3
|
+
import { D1Database } from "@cloudflare/workers-types";
|
|
1
4
|
/**
|
|
2
5
|
* Export reusable router and procedure helpers
|
|
3
6
|
* that can be used throughout the router
|
|
4
7
|
*/
|
|
5
8
|
export declare const router: <TProcRouterRecord extends import("@trpc/server").ProcedureRouterRecord>(procedures: TProcRouterRecord) => import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
|
|
6
|
-
ctx: object
|
|
9
|
+
ctx: object & {
|
|
10
|
+
db: ReturnType<typeof sqliteDb>;
|
|
11
|
+
} & {
|
|
12
|
+
db: ReturnType<typeof dbSqlite>;
|
|
13
|
+
} & {
|
|
14
|
+
db: ReturnType<typeof dbD1>;
|
|
15
|
+
} & {
|
|
16
|
+
db: D1Database;
|
|
17
|
+
};
|
|
7
18
|
meta: object;
|
|
8
19
|
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
9
20
|
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
10
21
|
}>, TProcRouterRecord>;
|
|
11
22
|
export declare const publicProcedure: import("@trpc/server").ProcedureBuilder<{
|
|
12
23
|
_config: import("@trpc/server").RootConfig<{
|
|
13
|
-
ctx: object
|
|
24
|
+
ctx: object & {
|
|
25
|
+
db: ReturnType<typeof sqliteDb>;
|
|
26
|
+
} & {
|
|
27
|
+
db: ReturnType<typeof dbSqlite>;
|
|
28
|
+
} & {
|
|
29
|
+
db: ReturnType<typeof dbD1>;
|
|
30
|
+
} & {
|
|
31
|
+
db: D1Database;
|
|
32
|
+
};
|
|
14
33
|
meta: object;
|
|
15
34
|
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
16
35
|
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
17
36
|
}>;
|
|
18
|
-
_ctx_out: object
|
|
37
|
+
_ctx_out: object & {
|
|
38
|
+
db: ReturnType<typeof sqliteDb>;
|
|
39
|
+
} & {
|
|
40
|
+
db: ReturnType<typeof dbSqlite>;
|
|
41
|
+
} & {
|
|
42
|
+
db: ReturnType<typeof dbD1>;
|
|
43
|
+
} & {
|
|
44
|
+
db: D1Database;
|
|
45
|
+
};
|
|
19
46
|
_input_in: typeof import("@trpc/server").unsetMarker;
|
|
20
47
|
_input_out: typeof import("@trpc/server").unsetMarker;
|
|
21
48
|
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
@@ -23,19 +50,43 @@ export declare const publicProcedure: import("@trpc/server").ProcedureBuilder<{
|
|
|
23
50
|
_meta: object;
|
|
24
51
|
}>;
|
|
25
52
|
export declare const appRouter: import("@trpc/server").CreateRouterInner<import("@trpc/server").RootConfig<{
|
|
26
|
-
ctx: object
|
|
53
|
+
ctx: object & {
|
|
54
|
+
db: ReturnType<typeof sqliteDb>;
|
|
55
|
+
} & {
|
|
56
|
+
db: ReturnType<typeof dbSqlite>;
|
|
57
|
+
} & {
|
|
58
|
+
db: ReturnType<typeof dbD1>;
|
|
59
|
+
} & {
|
|
60
|
+
db: D1Database;
|
|
61
|
+
};
|
|
27
62
|
meta: object;
|
|
28
63
|
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
29
64
|
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
30
65
|
}>, {
|
|
31
66
|
demo: import("@trpc/server").BuildProcedure<"query", {
|
|
32
67
|
_config: import("@trpc/server").RootConfig<{
|
|
33
|
-
ctx: object
|
|
68
|
+
ctx: object & {
|
|
69
|
+
db: ReturnType<typeof sqliteDb>;
|
|
70
|
+
} & {
|
|
71
|
+
db: ReturnType<typeof dbSqlite>;
|
|
72
|
+
} & {
|
|
73
|
+
db: ReturnType<typeof dbD1>;
|
|
74
|
+
} & {
|
|
75
|
+
db: D1Database;
|
|
76
|
+
};
|
|
34
77
|
meta: object;
|
|
35
78
|
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
36
79
|
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
37
80
|
}>;
|
|
38
|
-
_ctx_out: object
|
|
81
|
+
_ctx_out: object & {
|
|
82
|
+
db: ReturnType<typeof sqliteDb>;
|
|
83
|
+
} & {
|
|
84
|
+
db: ReturnType<typeof dbSqlite>;
|
|
85
|
+
} & {
|
|
86
|
+
db: ReturnType<typeof dbD1>;
|
|
87
|
+
} & {
|
|
88
|
+
db: D1Database;
|
|
89
|
+
};
|
|
39
90
|
_input_in: typeof import("@trpc/server").unsetMarker;
|
|
40
91
|
_input_out: typeof import("@trpc/server").unsetMarker;
|
|
41
92
|
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
@@ -46,13 +97,29 @@ export declare const appRouter: import("@trpc/server").CreateRouterInner<import(
|
|
|
46
97
|
}>;
|
|
47
98
|
onNewTodo: import("@trpc/server").BuildProcedure<"mutation", {
|
|
48
99
|
_config: import("@trpc/server").RootConfig<{
|
|
49
|
-
ctx: object
|
|
100
|
+
ctx: object & {
|
|
101
|
+
db: ReturnType<typeof sqliteDb>;
|
|
102
|
+
} & {
|
|
103
|
+
db: ReturnType<typeof dbSqlite>;
|
|
104
|
+
} & {
|
|
105
|
+
db: ReturnType<typeof dbD1>;
|
|
106
|
+
} & {
|
|
107
|
+
db: D1Database;
|
|
108
|
+
};
|
|
50
109
|
meta: object;
|
|
51
110
|
errorShape: import("@trpc/server").DefaultErrorShape;
|
|
52
111
|
transformer: import("@trpc/server").DefaultDataTransformer;
|
|
53
112
|
}>;
|
|
54
113
|
_meta: object;
|
|
55
|
-
_ctx_out: object
|
|
114
|
+
_ctx_out: object & {
|
|
115
|
+
db: ReturnType<typeof sqliteDb>;
|
|
116
|
+
} & {
|
|
117
|
+
db: ReturnType<typeof dbSqlite>;
|
|
118
|
+
} & {
|
|
119
|
+
db: ReturnType<typeof dbD1>;
|
|
120
|
+
} & {
|
|
121
|
+
db: D1Database;
|
|
122
|
+
};
|
|
56
123
|
_input_in: string;
|
|
57
124
|
_input_out: string;
|
|
58
125
|
_output_in: typeof import("@trpc/server").unsetMarker;
|
|
@@ -43,12 +43,14 @@ 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
|
-
"@
|
|
49
|
+
"@cloudflare/workers-types": "^4.20240821.1",
|
|
48
50
|
"@ts-rest/core": "^3.51.0",
|
|
49
51
|
"@ts-rest/serverless": "^3.51.0",
|
|
50
52
|
"@types/node": "^18.19.14",
|
|
51
|
-
"@universal-middleware/core": "^0.2.
|
|
53
|
+
"@universal-middleware/core": "^0.2.6",
|
|
52
54
|
zod: "^3.23.8"
|
|
53
55
|
},
|
|
54
56
|
dependencies: {
|
|
@@ -98,7 +100,6 @@ async function getPackageJson(props) {
|
|
|
98
100
|
dependencies: ["@ts-rest/core", "@ts-rest/serverless", "@universal-middleware/core"],
|
|
99
101
|
devDependencies: ["zod"]
|
|
100
102
|
});
|
|
101
|
-
packageJson.devDependencies.typescript = "~5.4.5";
|
|
102
103
|
return packageJson;
|
|
103
104
|
}
|
|
104
105
|
export {
|
|
@@ -2,44 +2,65 @@ import { fetchRequestHandler, tsr } from "@ts-rest/serverless/fetch";
|
|
|
2
2
|
import { contract } from "../ts-rest/contract";
|
|
3
3
|
import { Get, UniversalHandler } from "@universal-middleware/core";
|
|
4
4
|
import * as drizzleQueries from "@batijs/drizzle/database/drizzle/queries/todos";
|
|
5
|
+
import { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
5
6
|
import * as sqliteQueries from "@batijs/sqlite/database/sqlite/queries/todos";
|
|
7
|
+
import { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
8
|
+
import * as d1Queries from "@batijs/d1-sqlite/database/d1/queries/todos";
|
|
9
|
+
import type { D1Database } from "@cloudflare/workers-types";
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* ts-rest route
|
|
9
13
|
*
|
|
10
14
|
* @link {@see https://ts-rest.com/docs/serverless/fetch-runtimes/}
|
|
11
15
|
**/
|
|
12
|
-
const router = tsr
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
16
|
+
const router = tsr
|
|
17
|
+
.platformContext<
|
|
18
|
+
BATI.If<{
|
|
19
|
+
'BATI.has("sqlite") && !BATI.hasD1': { db: ReturnType<typeof sqliteDb> };
|
|
20
|
+
'BATI.has("drizzle") && !BATI.hasD1': { db: ReturnType<typeof dbSqlite> };
|
|
21
|
+
'BATI.has("drizzle")': { db: ReturnType<typeof dbD1> };
|
|
22
|
+
"BATI.hasD1": { db: D1Database };
|
|
23
|
+
_: object;
|
|
24
|
+
}>
|
|
25
|
+
>()
|
|
26
|
+
.router(contract, {
|
|
27
|
+
demo: async () => {
|
|
28
|
+
return {
|
|
29
|
+
status: 200,
|
|
30
|
+
body: {
|
|
31
|
+
demo: true,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
createTodo: async ({ body }, _ctx) => {
|
|
36
|
+
if (BATI.has("drizzle")) {
|
|
37
|
+
await drizzleQueries.insertTodo(_ctx.db, body.text);
|
|
38
|
+
} else if (BATI.has("sqlite") && !BATI.hasD1) {
|
|
39
|
+
sqliteQueries.insertTodo(_ctx.db, body.text);
|
|
40
|
+
} else if (BATI.hasD1) {
|
|
41
|
+
await d1Queries.insertTodo(_ctx.db, body.text);
|
|
42
|
+
} else {
|
|
43
|
+
// This is where you'd persist the data
|
|
44
|
+
console.log("Received new todo", { text: body.text });
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
status: 200,
|
|
48
|
+
body: {
|
|
49
|
+
status: "Ok",
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
});
|
|
38
54
|
|
|
39
|
-
export const tsRestHandler: Get<[], UniversalHandler> = () => async (request) =>
|
|
55
|
+
export const tsRestHandler: Get<[], UniversalHandler> = () => async (request, ctx, runtime) =>
|
|
40
56
|
fetchRequestHandler({
|
|
41
57
|
request: new Request(request.url, request),
|
|
42
58
|
contract,
|
|
43
59
|
router,
|
|
44
60
|
options: {},
|
|
61
|
+
platformContext: {
|
|
62
|
+
...ctx,
|
|
63
|
+
...runtime,
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
} as any,
|
|
45
66
|
});
|
|
@@ -73,7 +73,8 @@ async function handleOnSubmit(action: "login" | "signup") {
|
|
|
73
73
|
body: JSON.stringify(formData.value),
|
|
74
74
|
headers: { "Content-Type": "application/json" },
|
|
75
75
|
});
|
|
76
|
-
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
const result: Record<string, any> = await response.json();
|
|
77
78
|
if ("error" in result) {
|
|
78
79
|
console.error("A validation error has occurred :", result.error);
|
|
79
80
|
error.value = { ...result.error };
|