main
Ethan Niser 2023-09-14 18:58:22 -05:00
parent 80c5863e0b
commit 51e79b7b50
20 changed files with 95 additions and 37 deletions

Binary file not shown.

@ -31,7 +31,7 @@
"@t3-oss/env-core": "^0.6.1",
"drizzle-orm": "^0.28.6",
"drizzle-typebox": "^0.1.1",
"elysia": "^0.6.22",
"elysia": "link:elysia",
"elysia-autoroutes": "^0.2.2",
"lucia": "^2.6.0",
"pino-pretty": "^10.2.0",

@ -1,4 +1,3 @@
import Html from "@kitajs/html";
import { config } from "../config";
export const BaseHtml = ({ children }: Html.PropsWithChildren) => (

@ -1,5 +1,4 @@
import type { Todo } from "../db/schemas/todos";
import Html from "@kitajs/html";
export function TodoItem({ content, completed, id }: Todo) {
return (

@ -3,6 +3,7 @@ import { logger } from "@bogeychan/elysia-logger";
import pretty from "pino-pretty";
import { config } from "../config";
import { db } from "../db";
import "@kitajs/html/register";
import "@kitajs/html/htmx";
const stream = pretty({
@ -38,9 +39,3 @@ export const ctx = new Elysia({
// );
// });
// .onError(({ log, error }) => log.error(error));
export type ElysiaApp = typeof ctx;
export type GetHandler = Parameters<typeof ctx.get>[1];
export type PostHandler = Parameters<typeof ctx.post>[1];
export type PutHandler = Parameters<typeof ctx.put>[1];
export type DelHandler = Parameters<typeof ctx.delete>[1];

@ -1,7 +1,6 @@
import Elysia from "elysia";
import { todosService as todosController } from "./todos";
import { todosController } from "./todos";
export const api = new Elysia({
name: "@app/api",
prefix: "/api",
}).use(todosController);

@ -1 +0,0 @@
import Html from "@kitajs/html";

@ -2,18 +2,14 @@ import { Elysia, t } from "elysia";
import { ctx } from "../context";
import { insertTodoSchema, todos } from "../db/schemas/todos";
import { TodoItem, TodoForm, TodoList } from "../components/todos";
import Html from "@kitajs/html";
import { db } from "../db";
import { eq } from "drizzle-orm";
export const todosService = new Elysia({
name: "@app/todos",
export const todosController = new Elysia({
prefix: "/todos",
})
.use(ctx)
.model({
todo: insertTodoSchema,
})
.get("/", async () => {
const data = await db.select().from(todos).limit(10);
return <TodoList todos={data} />;

@ -1,7 +1,7 @@
import { Elysia, ws } from "elysia";
import { Elysia } from "elysia";
import { type ElysiaWS } from "elysia/ws";
let wsConnections = new Set<ElysiaWS<any>>();
let wsConnections = new Set<ElysiaWS<any, any>>();
function dispatch() {
wsConnections.forEach((connection) => {
@ -11,7 +11,6 @@ function dispatch() {
}
const app = new Elysia()
.use(ws())
.ws("/ws", {
open(ws) {
console.log("open");

@ -0,0 +1,73 @@
import type {
DecoratorBase,
DefinitionBase,
Handler,
InputSchema,
LocalHook,
MergeSchema,
RouteBase,
RouteSchema,
UnwrapRoute,
} from "elysia/types";
import { type Elysia, t } from "elysia";
type RouteArgs<
BasePath extends string,
Decorators extends DecoratorBase,
Definitions extends DefinitionBase,
ParentSchema extends RouteSchema,
Routes extends RouteBase,
Path extends string,
LocalSchema extends InputSchema<keyof Definitions["type"] & string>,
Route extends MergeSchema<
UnwrapRoute<LocalSchema, Definitions["type"]>,
ParentSchema
>,
Function extends Handler<Route, Decorators, `${BasePath}${Path}`>
> = {
handler: Function;
hooks?: LocalHook<
LocalSchema,
Route,
Decorators,
Definitions["error"],
`${BasePath}${Path}`
>;
};
export function elysiaHandler<
BasePath extends string,
Decorators extends DecoratorBase,
Definitions extends DefinitionBase,
ParentSchema extends RouteSchema,
Routes extends RouteBase,
Path extends string,
LocalSchema extends InputSchema<keyof Definitions["type"] & string>,
Route extends MergeSchema<
UnwrapRoute<LocalSchema, Definitions["type"]>,
ParentSchema
>,
Function extends Handler<Route, Decorators, `${BasePath}${Path}`>
>(
elysiaInstance: Elysia<
BasePath,
Decorators,
Definitions,
ParentSchema,
Routes
>,
path: Path,
obj: RouteArgs<
BasePath,
Decorators,
Definitions,
ParentSchema,
Routes,
Path,
LocalSchema,
Route,
Function
>
) {
return obj;
}

@ -1,22 +1,17 @@
import { Elysia } from "elysia";
import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
import { api } from "./controllers";
import { autoroutes } from "elysia-autoroutes";
import { api } from "./controllers/*";
import { config } from "./config";
import { pages } from "./pages/*";
const app = new Elysia({
name: "@app/main",
})
const app = new Elysia()
// @ts-expect-error idk why this is broken
.use(swagger())
// @ts-expect-error idk why this is broken
.use(staticPlugin())
.use(api)
.use(
autoroutes({
routesDir: "./pages",
})
)
.use(pages)
.onStart(() => {
if (config.env.NODE_ENV === "development") {
void fetch("http://localhost:3001/restart");

@ -0,0 +1,4 @@
import Elysia from "elysia";
import { index } from "./index";
export const pages = new Elysia().use(index);

@ -1,8 +1,8 @@
import { GetHandler } from "../context";
import Html from "@kitajs/html";
import Elysia from "elysia";
import { BaseHtml } from "../components/base";
import { ctx } from "../context";
export const get: GetHandler = ({ html }) =>
export const index = new Elysia().use(ctx).get("/", ({ html }) =>
html(
<BaseHtml>
<div
@ -12,4 +12,5 @@ export const get: GetHandler = ({ html }) =>
hx-trigger="load"
/>
</BaseHtml>
)
);

File diff suppressed because one or more lines are too long