diff --git a/bun.lockb b/bun.lockb index 67c6b17..0b029f2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/controllers/AccountController.ts b/controllers/AccountController.ts index 955ed1c..cd6cee4 100644 --- a/controllers/AccountController.ts +++ b/controllers/AccountController.ts @@ -1,5 +1,5 @@ -import LoginViewModel from "../models/account/LoginViewModel"; -import RegisterViewModel from "../models/account/RegisterViewModel"; +import type LoginViewModel from "../models/account/LoginViewModel"; +import type RegisterViewModel from "../models/account/RegisterViewModel"; import Config from "../objects/Config"; import Session from "../objects/Session"; import UserService from "../services/UserService"; diff --git a/controllers/Controller.ts b/controllers/Controller.ts index 0f20a7c..bdb4492 100644 --- a/controllers/Controller.ts +++ b/controllers/Controller.ts @@ -1,10 +1,10 @@ -import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"; +import { cyan } from "dyetty"; import { Console } from "hsconsole"; +import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"; +import RequestCtx from "../objects/RequestCtx"; import Session from "../objects/Session"; import SessionUser from "../objects/SessionUser"; -import RequestCtx from "../objects/RequestCtx"; import UserType from "../enums/UserType"; -import { cyan } from "dyetty"; // prepare for ts-ignore :3 // TODO: figure out some runtime field / type checking so @@ -47,7 +47,6 @@ export default abstract class Controller { // @ts-ignore const controllerRequestHandler = this[method]; const requestHandler = (req:FastifyRequest, res:FastifyReply) => { - const requestStartTime = Date.now(); let session = Session.CheckValiditiy(req.cookies); if (doAuth && session === undefined) { return res.redirect(`/account/login?returnTo=${encodeURIComponent(req.url)}`); @@ -148,10 +147,10 @@ export default abstract class Controller { public res: FastifyReply; // Methods - view(view?:string | Object, model?: Object) {} - redirectToAction(action:string, controller?:string) {} - ok(message?:string) {} - badRequest(message?:string) {} - unauthorised(message?:string) {} - forbidden(message?:string) {} + view(view?:string | Object, model?: Object) { view; model; } + redirectToAction(action:string, controller?:string) { action; controller; } + ok(message?:string) { message } + badRequest(message?:string) { message } + unauthorised(message?:string) { message } + forbidden(message?:string) { message } } \ No newline at end of file diff --git a/controllers/HomeController.ts b/controllers/HomeController.ts index 51f2ff6..adeef43 100644 --- a/controllers/HomeController.ts +++ b/controllers/HomeController.ts @@ -1,9 +1,6 @@ -import DashboardViewModel from "../models/home/DashboardViewModel"; -import Config from "../objects/Config"; -import HashFS from "../objects/HashFS"; -import UserService from "../services/UserService"; import Controller from "./Controller"; -import { randomBytes } from "crypto"; +import type DashboardViewModel from "../models/home/DashboardViewModel"; +import UserService from "../services/UserService"; export default class HomeController extends Controller { public async Index_Get_AllowAnonymous() { diff --git a/index.ts b/index.ts index 6e897f8..ee5ae0c 100644 --- a/index.ts +++ b/index.ts @@ -15,9 +15,7 @@ import AccountController from "./controllers/AccountController"; import { magenta, blue, cyan, green, red } from "dyetty"; import ConsoleUtility from "./utilities/ConsoleUtility"; import HashFS from "./objects/HashFS"; -import { existsSync, mkdirSync, rmSync } from "fs"; import FunkyArray from "funky-array"; -import UserService from "./services/UserService"; import MediaService from "./services/MediaService"; import Media from "./entities/Media"; @@ -98,7 +96,7 @@ fastify.addHook("onSend", (req, res, _payload, done) => { done(); }); -fastify.setNotFoundHandler(async (req, res) => { +fastify.setNotFoundHandler(async (_req, res) => { return res.status(404).view("views/404.ejs"); }); diff --git a/objects/Database.ts b/objects/Database.ts index aece586..4050872 100644 --- a/objects/Database.ts +++ b/objects/Database.ts @@ -1,6 +1,6 @@ import { blue } from "dyetty"; import { Console } from "hsconsole"; -import { createPool, Pool, RowDataPacket } from "mysql2"; +import { createPool, type Pool, type RowDataPacket } from "mysql2"; export type DBInDataType = string | number | Date | null | undefined; diff --git a/objects/HashFS.ts b/objects/HashFS.ts index 0b88053..ac5c67f 100644 --- a/objects/HashFS.ts +++ b/objects/HashFS.ts @@ -1,13 +1,13 @@ // ! Hashed File Store (not file system!!) import { join } from "path"; -import { existsSync, mkdirSync, createWriteStream, rename, stat, writeFile, copyFile, rm, rmSync, } from "fs"; +import { existsSync, mkdirSync, createWriteStream, rename, stat, writeFile, rm, rmSync, } from "fs"; import { Console } from "hsconsole"; import { yellow } from "dyetty"; import { createHash, randomBytes } from "crypto"; import FunkyArray from "funky-array"; import HashFSFileInformation from "./HashFSFileInformation"; -import { BusboyFileStream } from "@fastify/busboy" +import type { BusboyFileStream } from "@fastify/busboy"; export default class HashFS { public static STARTUP_DIR: string; diff --git a/objects/RequestCtx.ts b/objects/RequestCtx.ts index a4aa7b8..11fd2b5 100644 --- a/objects/RequestCtx.ts +++ b/objects/RequestCtx.ts @@ -1,4 +1,4 @@ -import { FastifyReply, FastifyRequest } from "fastify"; +import { type FastifyReply, type FastifyRequest } from "fastify"; import SessionUser from "./SessionUser"; import UserType from "../enums/UserType"; diff --git a/objects/Session.ts b/objects/Session.ts index 3fc97b6..39e9040 100644 --- a/objects/Session.ts +++ b/objects/Session.ts @@ -2,7 +2,7 @@ import Config from "./Config"; import FastifyCookie from "@fastify/cookie"; import FunkyArray from "funky-array"; import SessionUser from "./SessionUser"; -import { FastifyReply, FastifyRequest } from "fastify"; +import { type FastifyReply } from "fastify"; import User from "../entities/User"; import { randomBytes } from "crypto"; diff --git a/package.json b/package.json index 06b1188..e9be00e 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ "build": "tsc --build" }, "devDependencies": { + "@types/bun": "^1.1.15", "@types/ejs": "^3.1.5", - "@types/node": "^22.10.4", "@vercel/ncc": "^0.38.3", "check-outdated": "^2.12.0", "nodemon": "^3.1.9", diff --git a/services/UserService.ts b/services/UserService.ts index ad182b7..adeed28 100644 --- a/services/UserService.ts +++ b/services/UserService.ts @@ -4,7 +4,7 @@ import PasswordUtility from "../utilities/PasswordUtility"; import UserType from "../enums/UserType"; import User from "../entities/User"; import MediaRepo from "../repos/MediaRepo"; -import { MultipartFile } from "@fastify/multipart" +import { type MultipartFile } from "@fastify/multipart" import HashFS from "../objects/HashFS"; import Media from "../entities/Media"; import { randomBytes } from "crypto"; diff --git a/tsconfig.json b/tsconfig.json index 747094e..df029f1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,27 @@ { "compilerOptions": { - "module": "commonjs", - "moduleResolution": "node", - "target": "ES2022", - "esModuleInterop": true, - "resolveJsonModule": true, - "rootDir": "./", - "outDir": "./build", - "strict": true + // Enable latest features + "lib": ["ESNext"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags + "noUnusedLocals": true, + "noUnusedParameters": true, + "noPropertyAccessFromIndexSignature": true } } \ No newline at end of file diff --git a/utilities/ConsoleUtility.ts b/utilities/ConsoleUtility.ts index ca8349f..926399e 100644 --- a/utilities/ConsoleUtility.ts +++ b/utilities/ConsoleUtility.ts @@ -1,5 +1,4 @@ import { green, yellow, red, gray } from "dyetty"; -import { Console } from "hsconsole"; export default abstract class ConsoleUtility { public static StatusColor(statusCode: number) {