add:eslint | add eslint for code formatter
This commit is contained in:
17
eslint.config.mjs
Normal file
17
eslint.config.mjs
Normal file
@ -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,
|
||||
]);
|
||||
@ -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"
|
||||
}
|
||||
|
||||
@ -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<T>(
|
||||
set: Context["set"],
|
||||
status: number,
|
||||
message?: string,
|
||||
data?: any
|
||||
data?: T
|
||||
) {
|
||||
set.status = status;
|
||||
|
||||
const response: Record<string, any> = {
|
||||
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<T>(
|
||||
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<T>(
|
||||
set: Context["set"],
|
||||
status: number,
|
||||
message: string,
|
||||
errorDetails?: any
|
||||
errorDetails?: T
|
||||
) {
|
||||
set.status = status;
|
||||
|
||||
const response: Record<string, any> = {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user