Skip to content

Commit e755855

Browse files
build: add biome as everything (format, lint) (#14)
* build: add biome as everything (format, lint) * build: add biome commands * fix: biome includes * chore: apply biome * ci: add gh action * fix: wrong position of the gh action file * ci: fix package.json path * ci: again? * ci: pnpm action-setup crazy * ci: are we there?
1 parent 035d762 commit e755855

37 files changed

+598
-509
lines changed

.github/workflows/test.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
workflow_dispatch:
8+
9+
jobs:
10+
test:
11+
name: Typecheck and Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v5
15+
- uses: pnpm/action-setup@v4
16+
with:
17+
package_json_file: "backend/package.json"
18+
run_install: false
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version-file: "backend/package.json"
22+
cache: pnpm
23+
cache-dependency-path: "backend/pnpm-lock.yaml"
24+
- name: Install Dependencies
25+
working-directory: backend
26+
run: pnpm install --frozen-lockfile
27+
- name: Typecheck
28+
working-directory: backend
29+
run: pnpm run typecheck
30+
- name: Run Biome
31+
working-directory: backend
32+
run: pnpm exec biome ci .

backend/biome.jsonc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
3+
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4+
"files": {
5+
"ignoreUnknown": false,
6+
"includes": ["./src/**"]
7+
},
8+
"formatter": {
9+
"enabled": true,
10+
"formatWithErrors": false,
11+
"indentStyle": "space",
12+
"indentWidth": 2,
13+
"lineEnding": "lf",
14+
"lineWidth": 120,
15+
"attributePosition": "auto",
16+
"bracketSameLine": false,
17+
"bracketSpacing": true,
18+
"expand": "auto",
19+
"useEditorconfig": true
20+
},
21+
"linter": {
22+
"enabled": true,
23+
"rules": {
24+
"recommended": true,
25+
"suspicious": {
26+
"noVar": "error"
27+
}
28+
}
29+
},
30+
"javascript": {
31+
"formatter": {
32+
"jsxQuoteStyle": "double",
33+
"quoteProperties": "asNeeded",
34+
"trailingCommas": "es5",
35+
"semicolons": "asNeeded",
36+
"arrowParentheses": "always",
37+
"bracketSameLine": false,
38+
"quoteStyle": "double",
39+
"attributePosition": "auto",
40+
"bracketSpacing": true
41+
},
42+
"globals": ["exports"]
43+
},
44+
"html": { "formatter": { "selfCloseVoidElements": "always" } },
45+
"assist": {
46+
"enabled": true,
47+
"actions": { "source": { "organizeImports": "on" } }
48+
}
49+
}

backend/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
"build:npm": "NODE_ENV=production tsup --config tsup.npm.config.ts",
1313
"dev": "NODE_ENV=development tsx watch --clear-screen=false --env-file=.env src/server.ts | pino-pretty",
1414
"start": "NODE_ENV=production node dist/server.js",
15-
"typecheck": "tsc --noEmit",
1615
"db:push": "drizzle-kit push",
1716
"db:generate": "drizzle-kit generate",
18-
"db:migrate": "drizzle-kit migrate"
17+
"db:migrate": "drizzle-kit migrate",
18+
"typecheck": "tsc --noEmit",
19+
"check": "biome check",
20+
"check:fix": "biome check --write"
1921
},
2022
"devDependencies": {
23+
"@biomejs/biome": "^2.2.4",
2124
"@types/node": "^24.5.2",
2225
"@types/pg": "^8.15.5",
2326
"drizzle-kit": "^0.31.4",

backend/pnpm-lock.yaml

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/src/auth/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { betterAuth } from "better-auth";
2-
import { drizzleAdapter } from "better-auth/adapters/drizzle";
3-
import { db } from "@/db/db";
4-
import { SCHEMA } from "@/db";
5-
import { env } from "@/env";
6-
import { AUTH_PATH } from "@/constants";
7-
import { telegramPlugin } from "./plugins/telegram";
1+
import { betterAuth } from "better-auth"
2+
import { drizzleAdapter } from "better-auth/adapters/drizzle"
3+
import { AUTH_PATH } from "@/constants"
4+
import { SCHEMA } from "@/db"
5+
import { db } from "@/db/db"
6+
import { env } from "@/env"
7+
import { telegramPlugin } from "./plugins/telegram"
88

99
export const auth = betterAuth({
1010
basePath: AUTH_PATH,
@@ -45,4 +45,4 @@ export const auth = betterAuth({
4545
clientSecret: env.GITHUB_CLIENT_SECRET,
4646
},
4747
},
48-
});
48+
})
Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import { DB, SCHEMA } from "@/db";
2-
import { type BetterAuthPlugin } from "better-auth";
3-
import { z } from "zod";
4-
import { createAuthEndpoint, sessionMiddleware } from "better-auth/api";
5-
import crypto from "crypto";
6-
import { eq } from "drizzle-orm";
1+
import crypto from "node:crypto"
2+
import type { BetterAuthPlugin } from "better-auth"
3+
import { createAuthEndpoint, sessionMiddleware } from "better-auth/api"
4+
import { eq } from "drizzle-orm"
5+
import { z } from "zod"
6+
import { DB, SCHEMA } from "@/db"
77

8-
const TTL = 300; // seconds
9-
const CODE_LENGTH = 6;
8+
const TTL = 300 // seconds
9+
const CODE_LENGTH = 6
1010

1111
const linkBody = z.object({
12-
telegramUsername: z
13-
.string()
14-
.transform((s) => (s.startsWith("@") ? s.slice(1) : s)),
15-
});
12+
telegramUsername: z.string().transform((s) => (s.startsWith("@") ? s.slice(1) : s)),
13+
})
1614

1715
export const telegramPlugin = () => {
1816
return {
@@ -41,13 +39,13 @@ export const telegramPlugin = () => {
4139
body: linkBody,
4240
},
4341
async (ctx) => {
44-
const userId = ctx.context.session?.user.id;
42+
const userId = ctx.context.session?.user.id
4543
if (!userId)
4644
return ctx.error("UNAUTHORIZED", {
4745
message: "You must be authenticated",
48-
});
46+
})
4947

50-
const { telegramUsername } = ctx.body;
48+
const { telegramUsername } = ctx.body
5149
const [{ code, ttl }] = await DB.insert(SCHEMA.TG.link)
5250
.values({
5351
code: crypto
@@ -60,10 +58,10 @@ export const telegramPlugin = () => {
6058
userId,
6159
telegramUsername,
6260
})
63-
.returning();
61+
.returning()
6462

65-
return ctx.json({ code, ttl });
66-
},
63+
return ctx.json({ code, ttl })
64+
}
6765
),
6866
verifyLink: createAuthEndpoint(
6967
"/telegram/link/verify",
@@ -75,41 +73,39 @@ export const telegramPlugin = () => {
7573
}),
7674
},
7775
async (ctx) => {
78-
const userId = ctx.context.session?.user.id;
76+
const userId = ctx.context.session?.user.id
7977
if (!userId)
8078
return ctx.error("UNAUTHORIZED", {
8179
message: "You must be authenticated",
82-
});
80+
})
8381

84-
const code = ctx.query.code;
82+
const code = ctx.query.code
8583
const res = await DB.select()
8684
.from(SCHEMA.TG.link)
87-
.where((t) => eq(t.code, code));
85+
.where((t) => eq(t.code, code))
8886
if (!res || res.length !== 1)
8987
return ctx.error("NOT_FOUND", {
9088
message: "No link session with this code found",
91-
});
89+
})
9290

93-
const row = res[0];
91+
const row = res[0]
9492

9593
if (row.userId !== userId)
9694
return ctx.error("FORBIDDEN", {
9795
message: "This link session does not belong to you",
98-
});
96+
})
9997

100-
const expireTime = row.createdAt.getTime() + row.ttl * 1000;
101-
const expired = Date.now() >= expireTime;
98+
const expireTime = row.createdAt.getTime() + row.ttl * 1000
99+
const expired = Date.now() >= expireTime
102100

103-
const verified = !!row.telegramId;
101+
const verified = !!row.telegramId
104102
if (verified) {
105-
await DB.delete(SCHEMA.TG.link).where(
106-
eq(SCHEMA.TG.link.code, code),
107-
);
103+
await DB.delete(SCHEMA.TG.link).where(eq(SCHEMA.TG.link.code, code))
108104
}
109105

110-
return ctx.json({ expired, verified });
111-
},
106+
return ctx.json({ expired, verified })
107+
}
112108
),
113109
},
114-
} satisfies BetterAuthPlugin;
115-
};
110+
} satisfies BetterAuthPlugin
111+
}

backend/src/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export const TRPC_PATH = "/api/trpc";
2-
export const AUTH_PATH = "/api/auth";
1+
export const TRPC_PATH = "/api/trpc"
2+
export const AUTH_PATH = "/api/auth"
33

44
export const TRUSTED_ORIGINS = [
55
"http://localhost:3001",

0 commit comments

Comments
 (0)