Skip to content

Commit af34c27

Browse files
committed
refactor: clean up code and improve type-only imports
- Remove unused node server initialization - Fix missing commas in function parameter destructuring - Use `import type` for type-only imports across payload files - Ensure consistent trailing commas in functions and tests - Improve error messages in get.route.ts Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
1 parent 9090a8b commit af34c27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+180
-193
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.3.13/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.3.14/schema.json",
33
"vcs": {
44
"enabled": true,
55
"clientKind": "git",

package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
"description": "🎵 An Unofficial wrapper for the JioSaavn API.",
55
"scripts": {
66
"dev": "bun run --hot src/index.ts",
7-
"build": "echo \"Building...\"",
87
"dev:cf": "wrangler dev src/index.ts",
98
"deploy:cf": "wrangler deploy --minify src/index.ts",
109
"type-check": "tsc --noEmit",
11-
"fmt": "biome format --write",
12-
"lint": "biome check src",
10+
"lint:check": "biome check",
11+
"lint": "biome check --write",
1312
"prepare": "husky"
1413
},
1514
"dependencies": {
@@ -43,11 +42,9 @@
4342
"wrangler": "^4.63.0"
4443
},
4544
"lint-staged": {
46-
"*.{ts,json}": [
47-
"prettier --write \"**/*.{ts,json}\" --cache"
48-
],
49-
"*.ts": [
50-
"tsc --noEmit --esModuleInterop --skipLibCheck --types bun-types"
45+
"*": [
46+
"biome format --write",
47+
"biome check"
5148
]
5249
},
5350
"commitlint": {

src/bun.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from "./routes";
2222
import type { CustomResponse } from "./types/response";
2323

24-
const app = new Hono({ strict: false }); // match routes w/ or w/o trailing slash
24+
export const app = new Hono({ strict: false }); // match routes w/ or w/o trailing slash
2525

2626
/* -----------------------------------------------------------------------------------------------
2727
* OpenAPI documentation
@@ -112,6 +112,4 @@ const server = {
112112
fetch: app.fetch,
113113
};
114114

115-
export { app };
116-
117115
export default server;

src/lib/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const api = async <T>(
55
{
66
isVersion4 = true,
77
query,
8-
}: { isVersion4?: boolean; query?: Record<string, string> } = {}
8+
}: { isVersion4?: boolean; query?: Record<string, string> } = {},
99
) => {
1010
const params = new URLSearchParams({
1111
_format: "json",

src/lib/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { MiddlewareHandler } from "hono";
21
import { Ratelimit } from "@upstash/ratelimit";
32
import { Redis } from "@upstash/redis";
3+
import type { MiddlewareHandler } from "hono";
44

55
import { config } from "./config";
66
import { toCamelCase } from "./utils";

src/lib/utils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Crypto from "crypto-js";
2-
3-
import { Quality } from "../types/misc";
4-
import { ArtistMiniRequest, ArtistMiniResponse } from "../types/artist";
2+
import type { ArtistMiniRequest, ArtistMiniResponse } from "../types/artist";
3+
import type { Quality } from "../types/misc";
54

65
/**
76
* Utility function to create image links for different qualities
@@ -43,10 +42,10 @@ export function createDownloadLinks(encryptedMediaUrl: string): Quality {
4342

4443
const decrypted = Crypto.DES.decrypt(
4544
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
46-
// @ts-ignore
45+
// @ts-expect-error
4746
{ ciphertext: Crypto.enc.Base64.parse(encryptedMediaUrl) },
4847
Crypto.enc.Utf8.parse(key),
49-
{ mode: Crypto.mode.ECB }
48+
{ mode: Crypto.mode.ECB },
5049
);
5150

5251
const decryptedLink = decrypted.toString(Crypto.enc.Utf8);
@@ -71,7 +70,7 @@ export function createDownloadLinks(encryptedMediaUrl: string): Quality {
7170
* @returns Token from the link
7271
*/
7372
export function tokenFromLink(link: string) {
74-
return link.split("/").at(-1)!;
73+
return link.split("/").at(-1) || "";
7574
}
7675

7776
/**
@@ -151,9 +150,9 @@ export function toCamelCase<T>(obj: A | A[]): T {
151150
const result: A = {};
152151

153152
for (const key in obj) {
154-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
153+
if (Object.hasOwn(obj, key)) {
155154
const camelCaseKey = key.replace(/_([a-z])/g, (_, letter) =>
156-
letter.toUpperCase()
155+
letter.toUpperCase(),
157156
);
158157
result[camelCaseKey] = toCamelCase(obj[key] as A);
159158
}

src/node.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/openapi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function q(
1616
description,
1717
schema,
1818
example,
19-
}: Omit<OpenApiParameter, "name" | "in">
19+
}: Omit<OpenApiParameter, "name" | "in">,
2020
): OpenApiParameter {
2121
return { name, in: "query", required, description, schema, example };
2222
}
@@ -28,7 +28,7 @@ function p(
2828
description,
2929
schema,
3030
example,
31-
}: Omit<OpenApiParameter, "name" | "in">
31+
}: Omit<OpenApiParameter, "name" | "in">,
3232
): OpenApiParameter {
3333
return { name, in: "path", required, description, schema, example };
3434
}

src/payloads/album.payload.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { decode } from "entities";
22

33
import { createImageLinks, parseBool } from "../lib/utils";
4-
import {
4+
import type {
55
AlbumModulesRequest,
66
AlbumModulesResponse,
77
AlbumRequest,
@@ -12,7 +12,7 @@ import { songPayload } from "./song.payload";
1212

1313
export function albumPayload(
1414
a: AlbumRequest,
15-
mini: boolean = false
15+
mini: boolean = false,
1616
): AlbumResponse {
1717
const {
1818
id,
@@ -52,7 +52,7 @@ export function albumPayload(
5252
name: decode(title),
5353
subtitle: decode(
5454
subtitle ||
55-
(artistMap?.artists?.map((a) => a.name.trim()).join(", ") ?? "")
55+
(artistMap?.artists?.map((a) => a.name.trim()).join(", ") ?? ""),
5656
),
5757
type,
5858
language,
@@ -76,7 +76,7 @@ export function albumPayload(
7676
}
7777

7878
export function albumModulesPayload(
79-
a: AlbumModulesRequest
79+
a: AlbumModulesRequest,
8080
): AlbumModulesResponse {
8181
const {
8282
reco: r,

0 commit comments

Comments
 (0)