idek just sync it

main
Ethan Niser 2023-09-19 23:34:03 -05:00
parent d530f4f178
commit 342d294dbc
13 changed files with 59 additions and 106 deletions

Binary file not shown.

@ -13,7 +13,8 @@
"uno:dev": "bunx --bun unocss --watch",
"typecheck": "bunx --bun tsc",
"format:check": "prettier --check .",
"format": "prettier --write . --list-different"
"format": "prettier --write . --list-different",
"reset-cache": "rm -rf /home/whatplan/.bun/install/cache && rm -rf node_modules && bun i"
},
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.1.0",
@ -22,7 +23,7 @@
"@unocss/transformer-variant-group": "^0.55.7",
"bun-types": "latest",
"concurrently": "^8.2.1",
"drizzle-kit": "^0.19.13",
"drizzle-kit": "latest",
"prettier": "^3.0.3",
"prettier-plugin-tailwindcss": "^0.5.4",
"typescript": "^5.2.2",
@ -34,11 +35,11 @@
"@elysiajs/static": "^0.6.0",
"@elysiajs/swagger": "^0.6.2",
"@iconify-json/logos": "^1.1.37",
"@libsql/client": "0.3.5-pre.4",
"@libsql/client": "0.3.5-pre.8",
"@lucia-auth/adapter-sqlite": "^2.0.0",
"@t3-oss/env-core": "^0.6.1",
"@tlscipher/holt": "^1.0.4",
"beth-stack": "0.0.18",
"beth-stack": "0.0.20",
"drizzle-orm": "^0.28.6",
"drizzle-typebox": "^0.1.1",
"elysia": "0.7.0-beta.1",

@ -1,6 +1,6 @@
import { libsql } from "@lucia-auth/adapter-sqlite";
import { lucia } from "lucia";
import { web } from "lucia/middleware";
import { elysia, web } from "lucia/middleware";
import { config } from "../config";
import { client } from "../db";

@ -6,9 +6,10 @@ const env = createEnv({
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]),
DATABASE_URL: z.string().min(1),
DATABASE_AUTH_TOKEN: z.string().min(1),
// SYNC_URL: z.string().optional(),
SYNC_URL: z.string().optional(),
NODE_ENV: z.enum(["development", "production"]),
COOKIE_SECRET: z.string().min(1),
TURSO_API_TOKEN: z.string().min(1),
},
runtimeEnv: process.env,
});

@ -1,5 +1,5 @@
import { logger } from "@bogeychan/elysia-logger";
// import { HoltLogger } from "@tlscipher/holt";
import { HoltLogger } from "@tlscipher/holt";
import { bethStack } from "beth-stack/elysia";
import { Elysia } from "elysia";
import pretty from "pino-pretty";
@ -28,6 +28,7 @@ export const ctx = new Elysia({
stream,
}),
)
.use(new HoltLogger().getLogger())
// .use(
// cron({
// name: "heartbeat",
@ -43,10 +44,10 @@ export const ctx = new Elysia({
// },
// })
// )
// .decorate("db", db)
.decorate("db", () => db)
.decorate("config", config)
.decorate("auth", auth);
// .onStart(({ log }) => log.info("Server starting"))
// .onStart(({ log }) => log.info("Server starting"));
// .onStop(({ log }) => log.info("Server stopping"))
// .onRequest(({ log, request }) => {
// log.debug(`Request received: ${request.method}: ${request.url}`);

@ -5,5 +5,6 @@ import { todosController } from "./todos";
export const api = new Elysia({
prefix: "/api",
name: "@controllers",
}).use(todosController);
// .use(authController);

@ -7,6 +7,7 @@ import { insertTodoSchema, todos } from "../db/schema/todos";
export const todosController = new Elysia({
prefix: "/todos",
name: "@controllers/todos",
})
.use(ctx)
.get("/", async () => {

@ -3,12 +3,19 @@ import { drizzle } from "drizzle-orm/libsql";
import { config } from "../config";
import * as schema from "./schema";
export const client = createClient({
const remoteOptions = {
url: config.env.DATABASE_URL,
authToken: config.env.DATABASE_AUTH_TOKEN,
// syncUrl: config.env.SYNC_URL,
});
};
// if (config.env.SYNC_URL) await client.sync();
// const localOptions = {
// url: "file:local.sqlite",
// authToken: config.env.DATABASE_AUTH_TOKEN,
// syncUrl: config.env.DATABASE_URL,
// };
export const client = createClient(remoteOptions);
// await client.sync();
export const db = drizzle(client, { schema, logger: true });

@ -1,12 +1,15 @@
// import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
// import { swagger } from "@elysiajs/swagger";
import { Elysia } from "elysia";
import { config } from "./config";
import { api } from "./controllers/*";
import { pages } from "./pages/*";
const app = new Elysia()
const app = new Elysia({
name: "@app/app",
})
// .use(swagger())
//@ts-expect-error
.use(staticPlugin())
.use(api)
.use(pages)

@ -4,6 +4,8 @@ import { profile } from "./profile";
// import { signin } from "./signin";
export const authGroup = new Elysia()
export const authGroup = new Elysia({
name: "@pages/auth/root",
})
// .use(signup).use(signin)
.use(profile);

@ -2,7 +2,9 @@ import Elysia from "elysia";
import { BaseHtml } from "../../components/base";
import { ctx } from "../../context";
export const profile = new Elysia()
export const profile = new Elysia({
name: "@pages/auth/profile",
})
.use(ctx)
.get("/profile", async ({ auth, html, request }) => {
const authRequest = auth.handleRequest(request);

@ -2,4 +2,8 @@ import Elysia from "elysia";
import { authGroup } from "./(auth)/*";
import { index } from "./index";
export const pages = new Elysia().use(index).use(authGroup);
export const pages = new Elysia({
name: "@pages/root",
})
.use(index)
.use(authGroup);

@ -1,98 +1,28 @@
import { persistedCache, revalidateTag } from "beth-stack/cache";
import { renderToStream, renderToString, Suspense } from "beth-stack/jsx";
import { Elysia } from "elysia";
import { BaseHtml } from "../components/base";
import { ctx } from "../context";
const start = Date.now();
const getTime = async () => (Date.now() - start) / 1000;
const cachedGetTime = persistedCache(getTime, "getTime", {
tags: ["time"],
revalidate: 2,
});
export const index = new Elysia()
export const index = new Elysia({
name: "@pages/index",
})
.use(ctx)
.onRequest(({ request }) => {
const revalidate = request.headers.get("HX-Revalidate");
if (revalidate) {
const tags = JSON.parse(revalidate);
if (!Array.isArray(tags)) {
return;
}
tags.forEach((tag) => {
if (typeof tag !== "string") {
return;
}
revalidateTag(tag);
});
}
})
.get("/test", async ({ html, log }) => {
log.info("test");
const time = await cachedGetTime();
return html(() => <p>{time}</p>);
})
.get("/", async ({ html }) => {
.get("/", async ({ html, db, log, config }) => {
const start = performance.now();
// const todos = await db().query.todos.findMany();
log.info(`query took ${performance.now() - start}ms`);
const res = await fetch("https://api.turso.tech/v1/groups", {
headers: {
Authorization: `Bearer ${config.env.TURSO_API_TOKEN}`,
},
});
const json = await res.text();
return html(() => (
<BaseHtml>
<h1>cache revalidates every two seconds</h1>
<button hx-get="/test" hx-target="#foo" hx-swap="beforeend">
click me to get time since start (cached)
</button>
<br />
<div>hot reload</div>
<div class="i-logos-apple w-lg"></div>
<br />
<button
hx-get="/test"
hx-target="#foo"
hx-swap="beforeend"
hx-revalidate="time"
>
click me to get time since start (revalidate now)
</button>
<div id="foo"></div>
<h1>hi!</h1>
{/* <p safe>{JSON.stringify(todos)}</p> */}
<p safe>{JSON.stringify(json)}</p>
</BaseHtml>
));
})
.get("/test2", async ({ htmlStream }) => {
return htmlStream(() => <App2 />);
});
function wait(ms: number): Promise<number> {
return new Promise((resolve) =>
setTimeout(() => {
resolve(ms);
}, ms),
);
}
export async function Wait({ ms }: { ms: number }) {
const data = await wait(ms);
return <div>loaded in: {data}ms</div>;
}
const App2 = () => (
<BaseHtml>
<div>
<p>I am sent immediately</p>
<Suspense fallback={<div>Loading...</div>}>
<Wait ms={1000} />
<div>hello</div>
</Suspense>
<p>hey me too!</p>
<Suspense fallback={<div>loading 2...</div>}>
<Wait ms={2000} />
<div>hello two!</div>
<Suspense fallback={<div>loading 3...</div>}>
<Wait ms={3000} />
<div>hello three!</div>
</Suspense>
</Suspense>
</div>
</BaseHtml>
);