From 0852640b55f29e0829197ab238c426a67c47c85a Mon Sep 17 00:00:00 2001 From: Elliot Braem <16282460+elliotBraem@users.noreply.github.com> Date: Tue, 10 Sep 2024 13:20:22 -0400 Subject: [PATCH] add formatting and types --- .prettierignore | 4 ++ .prettierrc | 6 +++ package.json | 6 ++- pnpm-lock.yaml | 13 ++++-- src/app/api/[[...slugs]]/route.ts | 69 +++++++++++++++++-------------- src/app/page.tsx | 16 ++----- src/app/types.ts | 10 +++++ 7 files changed, 76 insertions(+), 48 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 src/app/types.ts diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..6007730 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +dist +node_modules +public +test-results \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..f0eb61e --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "trailingComma": "es5", + "tabWidth": 2, + "semi": true, + "singleQuote": false +} diff --git a/package.json b/package.json index 949334c..b08b09f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "fmt": "prettier --write '**/*.{js,jsx,ts,tsx,json}'", + "fmt:check": "prettier --check '**/*.{js,jsx,ts,tsx,json}'" }, "dependencies": { "@elysiajs/swagger": "^1.0.5", @@ -20,7 +22,6 @@ "react-dom": "^18", "react-markdown": "^9.0.1", "react-syntax-highlighter": "^15.5.0", - "solid": "link:@heroicons/react/solid", "stream": "^0.0.3", "zod": "^3.23.8" }, @@ -33,6 +34,7 @@ "eslint": "^8", "eslint-config-next": "14.2.3", "postcss": "^8", + "prettier": "^3.3.3", "tailwindcss": "^3.4.1", "typescript": "^5" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3ec16ca..f75187a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,9 +41,6 @@ importers: react-syntax-highlighter: specifier: ^15.5.0 version: 15.5.0(react@18.0.0) - solid: - specifier: link:@heroicons/react/solid - version: link:@heroicons/react/solid stream: specifier: ^0.0.3 version: 0.0.3 @@ -75,6 +72,9 @@ importers: postcss: specifier: ^8 version: 8.0.0 + prettier: + specifier: ^3.3.3 + version: 3.3.3 tailwindcss: specifier: ^3.4.1 version: 3.4.1 @@ -1687,6 +1687,11 @@ packages: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} + prettier@3.3.3: + resolution: {integrity: sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==} + engines: {node: '>=14'} + hasBin: true + prismjs@1.27.0: resolution: {integrity: sha512-t13BGPUlFDR7wRB5kQDG4jjl7XeuH6jbJGt11JHPL96qwsEHNX2+68tFXqc1/k+/jALsbSWJKUOT/hcYAZ5LkA==} engines: {node: '>=6'} @@ -4103,6 +4108,8 @@ snapshots: prelude-ls@1.2.1: {} + prettier@3.3.3: {} + prismjs@1.27.0: {} prismjs@1.29.0: {} diff --git a/src/app/api/[[...slugs]]/route.ts b/src/app/api/[[...slugs]]/route.ts index dfaced6..73f5fe4 100644 --- a/src/app/api/[[...slugs]]/route.ts +++ b/src/app/api/[[...slugs]]/route.ts @@ -1,18 +1,24 @@ +import { Budget } from "@/app/types"; import { swagger } from "@elysiajs/swagger"; -import Big from "big.js"; -import { Elysia } from "elysia"; import axios from "axios"; +import { Elysia } from "elysia"; import { Readable } from "stream"; -const API_KEY = process.env.WORDWARE_API_KEY -const API_URL = process.env.WORDWARE_API_URL -const API_VERSION = process.env.WORDWARE_API_VERSION +const API_KEY = process.env.WORDWARE_API_KEY; +const API_URL = process.env.WORDWARE_API_URL; +const API_VERSION = process.env.WORDWARE_API_VERSION; + +// BODY Type const app = new Elysia({ prefix: "/api", aot: false }) .use(swagger()) - .post("/budget", async ({ body }) => { + .post("/budget", async ({ body }: { body: Budget }) => { if (!API_KEY) { - throw new Error('Wordware API key is not set'); + throw new Error("API Key is not set"); + } + + if (!API_URL) { + throw new Error("API URL is not set"); } const bodyFormatted = { @@ -30,59 +36,60 @@ const app = new Elysia({ prefix: "/api", aot: false }) }; try { - const response = await axios.post( - API_URL, - bodyFormatted, - { - headers: { - Authorization: `Bearer ${API_KEY}`, - 'Content-Type': 'application/json', - }, - responseType: 'stream', + const response = await axios.post(API_URL, bodyFormatted, { + headers: { + Authorization: `Bearer ${API_KEY}`, + "Content-Type": "application/json", }, - ); + responseType: "stream", + }); return new Promise((resolve, reject) => { const stream = response.data as Readable; - let rawData = ''; + let rawData = ""; - stream.on('data', (chunk) => { + stream.on("data", (chunk) => { rawData += chunk.toString(); }); - stream.on('end', () => { - const lines = rawData.split('\n').filter(line => line.trim()); + stream.on("end", () => { + const lines = rawData.split("\n").filter((line) => line.trim()); let completeObject: any = null; for (const line of lines) { try { const parsedChunk = JSON.parse(line); - if (parsedChunk.type === 'chunk' && parsedChunk.value.state === 'complete') { + if ( + parsedChunk.type === "chunk" && + parsedChunk.value.state === "complete" + ) { completeObject = parsedChunk.value.output; break; } } catch (error) { - console.error('Failed to parse JSON:', error); + console.error("Failed to parse JSON:", error); } } if (completeObject) { - console.log('Complete Object:', completeObject); - resolve({ overview: completeObject.overview, csv: completeObject.CSV }); + console.log("Complete Object:", completeObject); + resolve({ + overview: completeObject.overview, + csv: completeObject.CSV, + }); } else { - console.log('No complete state found. Raw data:', rawData); - resolve({ error: 'No complete state found', rawData }); + console.log("No complete state found. Raw data:", rawData); + resolve({ error: "No complete state found", rawData }); } }); - stream.on('error', (error) => { - console.error('Stream error:', error); + stream.on("error", (error) => { + console.error("Stream error:", error); reject(error); }); }); - } catch (error) { - console.error('Request failed:', error); + console.error("Request failed:", error); throw error; } }) diff --git a/src/app/page.tsx b/src/app/page.tsx index ef23181..b139a81 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -3,9 +3,7 @@ import Link from "next/link"; export default function Home() { return (
-

- Budgetoor -

+

Budgetoor