Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add prettier and eslint #17 #25

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bunx lint-staged
18 changes: 18 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.devcontainer
,github
.vscode
nodemodules
supabase
temp
.dockerfile
.env
.gitignore
.prettierrc
bun.lockb
bunfig.toml
Dockerfile
entrypoint.sh
package--lock.json
package.json
README.md
tsconfig,json
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Binary file modified bun.lockb
Binary file not shown.
29 changes: 29 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import tsParser from "@typescript-eslint/parser";


export default [
{languageOptions: { globals: globals.node }},

pluginJs.configs.recommended,

...tseslint.configs.recommended,

{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parser: tsParser,
parserOptions: {
project: "./tsconfig.json",
},
},
rules: {
// "no-console": "warn",
"quotes": ["warn", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],
"semi": ["error", "always"],
},
},

];
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"neon:setup": "bun run neon:auth && bun run neon:projects-list > neon-cache.json",
"neon:projects-list": "bunx neonctl projects list --output json",
"start": "bun run src/index.ts --env-file=.env.prod",
"test": "[ ! -f neon-cache.json ] && bun run neon:setup || echo '✅ Cache found' && bun test --env-file=.env.test"
"test": "[ ! -f neon-cache.json ] && bun run neon:setup || echo '✅ Cache found' && bun test --env-file=.env.test",
"prepare": "husky"
},
"dependencies": {
"@elysiajs/bearer": "^0.8.0",
Expand All @@ -30,20 +31,33 @@
"drizzle-orm": "^0.29.3",
"elysia": "latest",
"elysia-rate-limit": "^2.0.1",
"eslint-config-prettier": "^9.1.0",
"jose": "^5.2.0",
"module-alias": "^2.2.3",
"postgres": "^3.4.3"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@neondatabase/serverless": "^0.9.3",
"@sinclair/typebox": "^0.32.28",
"bun-types": "latest",
"drizzle-kit": "^0.20.10",
"eslint": "9.x",
"globals": "^15.4.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.6",
"neonctl": "^1.30.0",
"supabase": "^1.127.4"
"prettier": "3.3.2",
"supabase": "^1.127.4",
"typescript-eslint": "^7.13.0"
},
"module": "src/index.js",
"_moduleAliases": {
"~": "src"
},
"lint-staged": {
"**/*.{js,ts,tsx,json,css,md}": [
"prettier src --write --ignore-unknown"
]
}
}
2 changes: 1 addition & 1 deletion src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App from "./app";
describe("ApplicationTest", () => {
it("Should log a greeting", async () => {
const response = await App.handle(new Request("http://localhost/")).then(
(res) => res.text()
(res) => res.text(),
);
expect(response).toBe("Hello Traveller!");
});
Expand Down
2 changes: 1 addition & 1 deletion src/bin/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { migratePostgresDb } from "~/repository";

migratePostgresDb();
migratePostgresDb();
2 changes: 1 addition & 1 deletion src/controllers/tag/@main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Elysia } from "elysia";
import { CreateTag, GetTag, LinkTagToTransaction } from ".";

const TagController = new Elysia().group("/tag", (app) =>
app.use(CreateTag).use(GetTag).use(LinkTagToTransaction)
app.use(CreateTag).use(GetTag).use(LinkTagToTransaction),
);

export default TagController;
6 changes: 3 additions & 3 deletions src/controllers/tag/getTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export const GetTag = new Elysia()
params: t.Optional(
t.Object({
id: t.Number(),
})
}),
),
body: t.Optional(
t.Object({
ids: t.Array(t.Number()),
})
}),
),
}
},
);
2 changes: 1 addition & 1 deletion src/controllers/tag/linkTagToTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export const LinkTagToTransaction = new Elysia().use(useAuthenticateUser).post(
},
{
body: LinkItemDTO,
}
},
);
4 changes: 2 additions & 2 deletions src/controllers/upload/uploadBatchTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const UploadBatchTransactions = new Elysia()
const { raw } = body;
const transactions = raw.map((transaction) => {
const transactionType = transactionTypes.find(
(type) => type.name === transaction.type
(type) => type.name === transaction.type,
);
if (!transactionType) {
throw new Error(`Transaction type, ${transactionType}, not found`);
Expand All @@ -44,5 +44,5 @@ export const UploadBatchTransactions = new Elysia()
{
type: "application/json",
body: IncomingTransactionPayloadDTO,
}
},
);
2 changes: 1 addition & 1 deletion src/controllers/upload/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export const useUploadsControllerErrorHandling = new Elysia().onError(
set.status = 500;
return { message: "Internal server error", error: error.message };
}
}
},
);
2 changes: 1 addition & 1 deletion src/controllers/user/@main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Elysia } from "elysia";
import { AuthenticateUser, RegisterUsers, VerifyAccessToken } from ".";

const UsersController = new Elysia().group("/users", (app) =>
app.use(AuthenticateUser).use(RegisterUsers).use(VerifyAccessToken)
app.use(AuthenticateUser).use(RegisterUsers).use(VerifyAccessToken),
);

export default UsersController;
4 changes: 2 additions & 2 deletions src/controllers/user/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const user: UserRegisterDTOType = {

// Test the entire controller as a unit
describe("Test user controller", () => {
var created: NewUser | undefined;
var accessToken: string | undefined;
let created: NewUser | undefined;
let accessToken: string | undefined;
it("should create a user", async () => {
const request = new Request(`http://localhost${RegisterUserR}`, {
method: "POST",
Expand Down
16 changes: 7 additions & 9 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ export const useMainApplicationErrorHandling = new Elysia().onError(
set.status = 400;
return "Bad Request :(";
}
}
},
);

export const useApplicationConfigs = new Elysia().state(
"config",
loadConfigs()
loadConfigs(),
);

export const useTransactionTypes = new Elysia().state(
"transactionTypes",
await (async () => {
return await connection!.query.transactionTypeTable.findMany();
})()
})(),
);

export const useAuthenticateUser = new Elysia()
Expand All @@ -50,9 +50,8 @@ export const useAuthenticateUser = new Elysia()
.onBeforeHandle(async ({ bearer, set, store: { keys } }) => {
if (!bearer) {
set.status = 401;
set.headers[
"WWW-Authenticate"
] = `Bearer realm='sign', error="invalid_request"`;
set.headers["WWW-Authenticate"] =
`Bearer realm='sign', error="invalid_request"`;

return { message: "not_authenticated" };
}
Expand All @@ -62,9 +61,8 @@ export const useAuthenticateUser = new Elysia()

if (typeof payload === "string") {
set.status = 401;
set.headers[
"WWW-Authenticate"
] = `Bearer realm='sign', error="invalid_token"`;
set.headers["WWW-Authenticate"] =
`Bearer realm='sign', error="invalid_token"`;
switch (payload) {
case "User not found":
case "Invalid":
Expand Down
10 changes: 5 additions & 5 deletions src/repository/functional/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export async function getAllUserTags(id: number) {
.where(eq(tagsTable.userId, id))
.leftJoin(
transactionTagsTable,
eq(tagsTable.id, transactionTagsTable.tagId)
eq(tagsTable.id, transactionTagsTable.tagId),
)
.leftJoin(
transactionsTable,
eq(transactionTagsTable.transactionId, transactionsTable.id)
eq(transactionTagsTable.transactionId, transactionsTable.id),
);
}

Expand All @@ -55,12 +55,12 @@ export async function getTagById(userId: number, tagId: Array<number>) {
.where(and(eq(tagsTable.userId, userId), eq(tagsTable.id, id)))
.leftJoin(
transactionTagsTable,
eq(tagsTable.id, transactionTagsTable.tagId)
eq(tagsTable.id, transactionTagsTable.tagId),
)
.leftJoin(
transactionsTable,
eq(transactionTagsTable.transactionId, transactionsTable.id)
eq(transactionTagsTable.transactionId, transactionsTable.id),
);
})
}),
);
}
8 changes: 4 additions & 4 deletions src/repository/functional/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export async function insertNewTransactions(transactions: NewTransaction[]) {
const res = await Promise.all(
transactions.map(async (transaction) => {
return await insert(transaction);
})
}),
);
console.timeEnd(insertTimingKey);

var allSuccess = true;
let allSuccess = true;
const oks = [];
const duplicates = [];
const failed = [];
Expand Down Expand Up @@ -53,11 +53,11 @@ export async function insertNewTransactions(transactions: NewTransaction[]) {
}

async function insert(
transaction: NewTransaction
transaction: NewTransaction,
): Promise<InsertResponseType> {
const db = getDatabaseInstance();
/// Inserts a single transaction and returns partial of the value
var newTransaction;
let newTransaction;
try {
newTransaction = await db
.insert(transactionsTable)
Expand Down
2 changes: 1 addition & 1 deletion src/repository/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const transactionTagsTable = pgTable("transaction_tags_table", {
...defaultFields,
tagId: integer("tag_id").references(() => tagsTable.id),
transactionId: integer("transaction_id").references(
() => transactionsTable.id
() => transactionsTable.id,
),
});

Expand Down
2 changes: 1 addition & 1 deletion src/repository/seed/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./transactionsTypes";
export * from "./transactionsTypes";
2 changes: 1 addition & 1 deletion src/repository/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type PostgresDBType = ReturnType<typeof PostgresJSDrizzle>;
export type DBConnectionType = [
// add keys here to cache the db and retrieve later
"CliDBType", // example
"PreloadKey"
"PreloadKey",
];
export type CacheDBKeyType =
| ("testingConnection" | "prodConnection")
Expand Down
2 changes: 1 addition & 1 deletion src/testing/authTestingTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function authTemplate() {
let accessToken: string | undefined;
let userId: string | undefined;
let createdUser: NewUser | undefined;
let user = {
const user = {
email: "[email protected]",
password: "testPassword3",
username: "testUser3",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function verifyJWT(
token: string,
): Promise<VerifyJWTResponse> {
const pk = await jose.importSPKI(publicKey, "RS256");
var payload;
let payload;

try {
const { payload: pl } = await jose.jwtVerify<JWTPayload>(token, pk);
Expand Down