refactor: 🔥 Remove dead code

This commit is contained in:
Jesse Wierzbinski 2024-05-07 03:13:37 +00:00
parent 592f7c0ac2
commit 7b05a34cce
No known key found for this signature in database
36 changed files with 32 additions and 1692 deletions

View file

@ -13,17 +13,12 @@ import {
exactly,
} from "magic-regexp";
import { parse } from "qs";
import type {
APIRouteExports,
APIRouteMetadata,
HttpVerb,
RouteHandler,
} from "server-handler";
import type { z } from "zod";
import { fromZodError } from "zod-validation-error";
import type { Application } from "~database/entities/Application";
import { getFromHeader, getFromRequest } from "~database/entities/User";
import { getFromHeader } from "~database/entities/User";
import type { User } from "~packages/database-interface/user";
import type { APIRouteMetadata, HttpVerb } from "~types/api";
export const applyConfig = (routeMeta: APIRouteMetadata) => {
const newMeta = routeMeta;
@ -39,15 +34,6 @@ export const applyConfig = (routeMeta: APIRouteMetadata) => {
return newMeta;
};
export const apiRoute = <
Metadata extends APIRouteMetadata,
ZodSchema extends Zod.AnyZodObject,
>(
routeFunction: APIRouteExports["default"],
) => {
return routeFunction;
};
export const idValidator = createRegExp(
anyOf(digit, charIn("ABCDEF")).times(8),
exactly("-"),

View file

@ -3,8 +3,6 @@ import { config } from "config-manager";
import { count } from "drizzle-orm";
import { LogLevel, type LogManager, type MultiLogManager } from "log-manager";
import { Meilisearch } from "meilisearch";
import type { Status } from "~database/entities/Status";
import type { UserType } from "~database/entities/User";
import { db } from "~drizzle/db";
import { Notes, Users } from "~drizzle/schema";
import type { User } from "~packages/database-interface/user";
@ -54,18 +52,6 @@ export enum MeiliIndexType {
Statuses = "statuses",
}
export const addStausToMeilisearch = async (status: Status) => {
if (!config.meilisearch.enabled) return;
await meilisearch.index(MeiliIndexType.Statuses).addDocuments([
{
id: status.id,
content: status.content,
createdAt: status.createdAt,
},
]);
};
export const addUserToMeilisearch = async (user: User) => {
if (!config.meilisearch.enabled) return;

View file

@ -1,17 +0,0 @@
export const deepMerge = (
target: Record<string, unknown>,
source: Record<string, unknown>,
) => {
const result = { ...target, ...source };
for (const key of Object.keys(result)) {
result[key] =
typeof target[key] === "object" && typeof source[key] === "object"
? // @ts-expect-error deepMerge is recursive
deepMerge(target[key], source[key])
: structuredClone(result[key]);
}
return result;
};
export const deepMergeArray = (array: Record<string, unknown>[]) =>
array.reduce((ci, ni) => deepMerge(ci, ni), {});

View file

@ -1,31 +0,0 @@
import { fileURLToPath } from "node:url";
/**
* Determines whether a module is the entry point for the running node process.
* This works for both CommonJS and ES6 environments.
*
* ### CommonJS
* ```js
* if (moduleIsEntry(module)) {
* console.log('WOO HOO!!!');
* }
* ```
*
* ### ES6
* ```js
* if (moduleIsEntry(import.meta.url)) {
* console.log('WOO HOO!!!');
* }
* ```
*/
export const moduleIsEntry = (moduleOrImportMetaUrl: NodeModule | string) => {
if (typeof moduleOrImportMetaUrl === "string") {
return process.argv[1] === fileURLToPath(moduleOrImportMetaUrl);
}
if (typeof require !== "undefined" && "exports" in moduleOrImportMetaUrl) {
return require.main === moduleOrImportMetaUrl;
}
return false;
};

View file

@ -59,5 +59,3 @@ export const checkIfOauthIsValid = (
return false;
};
export const oauthCodeVerifiers: Record<string, string> = {};

View file

@ -1,20 +0,0 @@
import { exists, mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
export const writeToTempDirectory = async (filename: string, data: string) => {
const tempDir = join("/tmp/", "lysand");
if (!(await exists(tempDir))) await mkdir(tempDir);
const tempFile = join(tempDir, filename);
await writeFile(tempFile, data);
return tempFile;
};
export const readFromTempDirectory = async (filename: string) => {
const tempDir = join("/tmp/", "lysand");
if (!(await exists(tempDir))) await mkdir(tempDir);
const tempFile = join(tempDir, filename);
return readFile(tempFile, "utf-8");
};