diff --git a/bun.lockb b/bun.lockb index c7e7dac..68a7243 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..b87e67e --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,17 @@ +import js from "@eslint/js"; +import globals from "globals"; +import tseslint from "typescript-eslint"; +import { defineConfig } from "eslint/config"; + +export default defineConfig([ + { + files: ["src/**/*.{js,mjs,cjs,ts,mts,cts}"], + plugins: { js }, + extends: ["js/recommended"], + }, + { + files: ["src/**/*.{js,mjs,cjs,ts,mts,cts}"], + languageOptions: { globals: globals.node }, + }, + tseslint.configs.recommended, +]); diff --git a/package.json b/package.json index 54a28cd..5c89849 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "build": "bun build ./src/index.ts --compile --target bun --minify-whitespace --minify-syntax --minify-identifiers --outfile dist/server", "dev": "bun run --watch src/index.ts", "map": "madge --image structure.svg src/index.ts", + "lint": "bunx eslint", "route:sync": "bun run ./scripts/sync-routes.ts", "env:publish": "bun run ./scripts/create-example-env.ts" }, @@ -27,8 +28,12 @@ "ua-parser-js": "^2.0.3" }, "devDependencies": { + "@eslint/js": "^9.29.0", "bun-types": "latest", - "prisma": "^6.7.0" + "eslint": "^9.29.0", + "globals": "^16.2.0", + "prisma": "^6.7.0", + "typescript-eslint": "^8.34.1" }, "module": "src/index.js" } diff --git a/src/helpers/callback/httpResponse.ts b/src/helpers/callback/httpResponse.ts index 98d687b..69fd05a 100644 --- a/src/helpers/callback/httpResponse.ts +++ b/src/helpers/callback/httpResponse.ts @@ -1,3 +1,5 @@ +import { Context } from "elysia"; + /** * Returns a standardized response for write operations (POST, PUT, DELETE). * Only includes data in the response during development. @@ -9,21 +11,19 @@ * * @returns An object with `status`, `message`, and optionally `data` (in development only). */ -export function returnWriteResponse( - set: any, +export function returnWriteResponse( + set: Context["set"], status: number, message?: string, - data?: any + data?: T ) { set.status = status; - const response: Record = { + return { status, message, + ...(process.env.APP_ENV === "development" && { data }), }; - if (process.env.APP_ENV === "development") response.data = data; - - return response; } /** @@ -37,11 +37,11 @@ export function returnWriteResponse( * * @returns An object with `status`, `message`, and `data`. */ -export function returnReadResponse( - set: any, +export function returnReadResponse( + set: Context["set"], status: number, message: string, - data: any + data: T ) { set.status = status; return { @@ -61,20 +61,20 @@ export function returnReadResponse( * * @returns An object with `status`, `message`, and optionally `error_details` (in development only). */ -export function returnErrorResponse( - set: any, +export function returnErrorResponse( + set: Context["set"], status: number, message: string, - errorDetails?: any + errorDetails?: T ) { set.status = status; - const response: Record = { + return { status: "error", message, + ...(process.env.APP_ENV === "development" && + errorDetails && { + error_details: errorDetails, + }), }; - if (process.env.APP_ENV === "development" && errorDetails) - response.error_details = errorDetails; - - return response; }