commit 6bd7c32a8aaaa6f68e5792986b89d1cbf9c7664c Author: Ethan Niser <100045248+ethanniser@users.noreply.github.com> Date: Tue Sep 12 15:58:44 2023 +0000 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f81d56e --- /dev/null +++ b/.gitignore @@ -0,0 +1,169 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +\*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +\*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +\*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +\*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.cache +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +.cache/ + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp +.cache + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.\* diff --git a/README.md b/README.md new file mode 100644 index 0000000..88d6915 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# test + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.0.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/books.db b/books.db new file mode 100644 index 0000000..3d24819 Binary files /dev/null and b/books.db differ diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..772b64c Binary files /dev/null and b/bun.lockb differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..0bd666b --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "test", + "module": "src/main.ts", + "type": "module", + "devDependencies": { + "bun-types": "latest", + "drizzle-kit": "^0.19.13" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "@bogeychan/elysia-logger": "^0.0.8", + "@elysiajs/html": "^0.6.5", + "@elysiajs/static": "^0.6.0", + "@elysiajs/swagger": "^0.6.2", + "@t3-oss/env-core": "^0.6.1", + "drizzle-orm": "^0.28.6", + "drizzle-typebox": "^0.1.1", + "elysia": "^0.6.22", + "pino-pretty": "^10.2.0", + "zod": "^3.22.2" + } +} \ No newline at end of file diff --git a/public/example.txt b/public/example.txt new file mode 100644 index 0000000..e69de29 diff --git a/sqlite.db b/sqlite.db new file mode 100644 index 0000000..e69de29 diff --git a/src/config/index.ts b/src/config/index.ts new file mode 100644 index 0000000..4ac2999 --- /dev/null +++ b/src/config/index.ts @@ -0,0 +1,9 @@ +import { createEnv } from "@t3-oss/env-core"; +import { z } from "zod"; + +export const env = createEnv({ + server: { + LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]), + }, + runtimeEnv: process.env, +}); diff --git a/src/context/index.ts b/src/context/index.ts new file mode 100644 index 0000000..3c01238 --- /dev/null +++ b/src/context/index.ts @@ -0,0 +1,32 @@ +import { Elysia } from "elysia"; +import { logger } from "@bogeychan/elysia-logger"; +import pretty from "pino-pretty"; +import { html } from "@elysiajs/html"; +import { env } from "../config"; +import { db } from "../model/store"; + +const stream = pretty({ + colorize: true, +}); + +export const ctx = new Elysia({ + name: "@app/ctx", +}) + .use( + logger({ + level: env.LOG_LEVEL, + stream, + }) + ) + .use(html()) + .decorate("db", db) + .decorate("config", env) + .onStart(({ log }) => log.info("Server starting")) + .onStop(({ log }) => log.info("Server stopping")) + .onRequest(({ log, request }) => + log.debug(`Request received: ${request.method}: ${request.url}`) + ) + .onResponse(({ log, response }) => + log.debug(`Response sent: ${response.statusCode}`) + ) + .onError(({ log, error }) => log.error(error)); diff --git a/src/controllers/todos.tsx b/src/controllers/todos.tsx new file mode 100644 index 0000000..b5a300f --- /dev/null +++ b/src/controllers/todos.tsx @@ -0,0 +1,24 @@ +import Elysia from "elysia"; +import { ctx } from "../context"; +import { insertTodoSchema } from "../model/todo"; +import { TodoItem } from "../views/todoItem"; + +export const todosController = new Elysia({ + name: "@app/todos", + prefix: "/todos", +}) + .use(ctx) + .model({ + todo: insertTodoSchema, + }) + .get("/", async ({ db }) => { + const todos = await db.query.todos.findMany(); + + return ( +