aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-03-30 16:26:16 +0000
committerMohamedBassem <me@mbassem.com>2024-03-30 16:26:16 +0000
commit46b78eaac30be26fe40520e97786563344af8403 (patch)
treec4c0e1ae1d3d21a6f1fbf5f44f68e99243bbb5d3 /packages
parent853ed13450b3a0d92cba144cc0dfd0696e7c810c (diff)
downloadkarakeep-46b78eaac30be26fe40520e97786563344af8403.tar.zst
format: Add missing lint and format, and format the entire repo
Diffstat (limited to 'packages')
-rw-r--r--packages/shared/assetdb.ts19
-rw-r--r--packages/shared/logger.ts1
-rw-r--r--packages/shared/package.json5
-rw-r--r--packages/shared/search.ts32
-rw-r--r--packages/trpc/auth.ts3
-rw-r--r--packages/trpc/index.ts19
-rw-r--r--packages/trpc/package.json2
-rw-r--r--packages/trpc/routers/_app.ts1
-rw-r--r--packages/trpc/routers/admin.ts6
-rw-r--r--packages/trpc/routers/apiKeys.ts10
-rw-r--r--packages/trpc/routers/bookmarks.test.ts6
-rw-r--r--packages/trpc/routers/bookmarks.ts44
-rw-r--r--packages/trpc/routers/lists.ts3
-rw-r--r--packages/trpc/routers/users.test.ts10
-rw-r--r--packages/trpc/testUtils.ts7
-rw-r--r--packages/trpc/tsconfig.json3
-rw-r--r--packages/trpc/types/bookmarks.ts3
-rw-r--r--packages/trpc/vitest.config.ts2
18 files changed, 107 insertions, 69 deletions
diff --git a/packages/shared/assetdb.ts b/packages/shared/assetdb.ts
index 0840eec2..8fd4da16 100644
--- a/packages/shared/assetdb.ts
+++ b/packages/shared/assetdb.ts
@@ -22,7 +22,7 @@ export async function saveAsset({
}: {
userId: string;
assetId: string;
- asset: Buffer,
+ asset: Buffer;
metadata: z.infer<typeof zAssetMetadataSchema>;
}) {
const assetDir = getAssetDir(userId, assetId);
@@ -30,7 +30,10 @@ export async function saveAsset({
await Promise.all([
fs.promises.writeFile(path.join(assetDir, "asset.bin"), asset),
- fs.promises.writeFile(path.join(assetDir, "metadata.json"), JSON.stringify(metadata)),
+ fs.promises.writeFile(
+ path.join(assetDir, "metadata.json"),
+ JSON.stringify(metadata),
+ ),
]);
}
@@ -42,14 +45,16 @@ export async function readAsset({
assetId: string;
}) {
const assetDir = getAssetDir(userId, assetId);
-
- const [asset, metadataStr] = await Promise.all([
+
+ const [asset, metadataStr] = await Promise.all([
fs.promises.readFile(path.join(assetDir, "asset.bin")),
- fs.promises.readFile(path.join(assetDir, "metadata.json"), {encoding: "utf8"}),
+ fs.promises.readFile(path.join(assetDir, "metadata.json"), {
+ encoding: "utf8",
+ }),
]);
const metadata = zAssetMetadataSchema.parse(JSON.parse(metadataStr));
- return {asset, metadata};
+ return { asset, metadata };
}
export async function deleteAsset({
@@ -60,5 +65,5 @@ export async function deleteAsset({
assetId: string;
}) {
const assetDir = getAssetDir(userId, assetId);
- await fs.promises.rm(path.join(assetDir), {recursive: true});
+ await fs.promises.rm(path.join(assetDir), { recursive: true });
}
diff --git a/packages/shared/logger.ts b/packages/shared/logger.ts
index 471ec7ab..f406b447 100644
--- a/packages/shared/logger.ts
+++ b/packages/shared/logger.ts
@@ -1,4 +1,5 @@
import winston from "winston";
+
import serverConfig from "./config";
const logger = winston.createLogger({
diff --git a/packages/shared/package.json b/packages/shared/package.json
index 716248e8..032f3db5 100644
--- a/packages/shared/package.json
+++ b/packages/shared/package.json
@@ -15,6 +15,11 @@
"@hoarder/prettier-config": "workspace:^0.1.0",
"@hoarder/tsconfig": "workspace:^0.1.0"
},
+ "scripts": {
+ "typecheck": "tsc --noEmit",
+ "format": "prettier . --ignore-path ../../.prettierignore",
+ "lint": "eslint ."
+ },
"main": "index.ts",
"eslintConfig": {
"root": true,
diff --git a/packages/shared/search.ts b/packages/shared/search.ts
index 8422d79e..7cd81061 100644
--- a/packages/shared/search.ts
+++ b/packages/shared/search.ts
@@ -1,7 +1,9 @@
-import { MeiliSearch, Index } from "meilisearch";
-import serverConfig from "./config";
+import type { Index } from "meilisearch";
+import { MeiliSearch } from "meilisearch";
import { z } from "zod";
+import serverConfig from "./config";
+
export const zBookmarkIdxSchema = z.object({
id: z.string(),
userId: z.string(),
@@ -51,15 +53,29 @@ export async function getSearchIdxClient(): Promise<Index<ZBookmarkIdx> | null>
const desiredSortableAttributes = ["createdAt"].sort();
const settings = await idxFound.getSettings();
- if (JSON.stringify(settings.filterableAttributes?.sort()) != JSON.stringify(desiredFilterableAttributes)) {
- console.log(`[meilisearch] Updating desired filterable attributes to ${desiredFilterableAttributes} from ${settings.filterableAttributes}`);
- const taskId = await idxFound.updateFilterableAttributes(desiredFilterableAttributes);
+ if (
+ JSON.stringify(settings.filterableAttributes?.sort()) !=
+ JSON.stringify(desiredFilterableAttributes)
+ ) {
+ console.log(
+ `[meilisearch] Updating desired filterable attributes to ${desiredFilterableAttributes} from ${settings.filterableAttributes}`,
+ );
+ const taskId = await idxFound.updateFilterableAttributes(
+ desiredFilterableAttributes,
+ );
await searchClient.waitForTask(taskId.taskUid);
}
- if (JSON.stringify(settings.sortableAttributes?.sort()) != JSON.stringify(desiredSortableAttributes)) {
- console.log(`[meilisearch] Updating desired sortable attributes to ${desiredSortableAttributes} from ${settings.sortableAttributes}`);
- const taskId = await idxFound.updateSortableAttributes(desiredSortableAttributes);
+ if (
+ JSON.stringify(settings.sortableAttributes?.sort()) !=
+ JSON.stringify(desiredSortableAttributes)
+ ) {
+ console.log(
+ `[meilisearch] Updating desired sortable attributes to ${desiredSortableAttributes} from ${settings.sortableAttributes}`,
+ );
+ const taskId = await idxFound.updateSortableAttributes(
+ desiredSortableAttributes,
+ );
await searchClient.waitForTask(taskId.taskUid);
}
idxClient = idxFound;
diff --git a/packages/trpc/auth.ts b/packages/trpc/auth.ts
index c766dd9a..846c07b6 100644
--- a/packages/trpc/auth.ts
+++ b/packages/trpc/auth.ts
@@ -1,7 +1,8 @@
import { randomBytes } from "crypto";
-import { apiKeys } from "@hoarder/db/schema";
import * as bcrypt from "bcryptjs";
+
import { db } from "@hoarder/db";
+import { apiKeys } from "@hoarder/db/schema";
// API Keys
diff --git a/packages/trpc/index.ts b/packages/trpc/index.ts
index 51c713c0..4055fa5d 100644
--- a/packages/trpc/index.ts
+++ b/packages/trpc/index.ts
@@ -1,20 +1,21 @@
-import { db } from "@hoarder/db";
-import serverConfig from "@hoarder/shared/config";
-import { TRPCError, initTRPC } from "@trpc/server";
+import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";
-type User = {
+import type { db } from "@hoarder/db";
+import serverConfig from "@hoarder/shared/config";
+
+interface User {
id: string;
name?: string | null | undefined;
email?: string | null | undefined;
role: "admin" | "user" | null;
-};
+}
-export type Context = {
+export interface Context {
user: User | null;
db: typeof db;
-};
+}
// Avoid exporting the entire t-object
// since it's not very descriptive.
@@ -29,7 +30,7 @@ const t = initTRPC.context<Context>().create({
data: {
...shape.data,
zodError:
- error.code === 'BAD_REQUEST' && error.cause instanceof ZodError
+ error.code === "BAD_REQUEST" && error.cause instanceof ZodError
? error.cause.flatten()
: null,
},
@@ -53,7 +54,7 @@ export const publicProcedure = procedure;
export const authedProcedure = procedure.use(function isAuthed(opts) {
const user = opts.ctx.user;
- if (!user || !user.id) {
+ if (!user?.id) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
diff --git a/packages/trpc/package.json b/packages/trpc/package.json
index 411397dc..ec858ca5 100644
--- a/packages/trpc/package.json
+++ b/packages/trpc/package.json
@@ -6,6 +6,8 @@
"type": "module",
"scripts": {
"typecheck": "tsc --noEmit",
+ "format": "prettier . --ignore-path ../../.prettierignore",
+ "lint": "eslint .",
"test": "vitest"
},
"dependencies": {
diff --git a/packages/trpc/routers/_app.ts b/packages/trpc/routers/_app.ts
index 780fd76d..577b523e 100644
--- a/packages/trpc/routers/_app.ts
+++ b/packages/trpc/routers/_app.ts
@@ -5,6 +5,7 @@ import { bookmarksAppRouter } from "./bookmarks";
import { listsAppRouter } from "./lists";
import { tagsAppRouter } from "./tags";
import { usersAppRouter } from "./users";
+
export const appRouter = router({
bookmarks: bookmarksAppRouter,
apiKeys: apiKeysAppRouter,
diff --git a/packages/trpc/routers/admin.ts b/packages/trpc/routers/admin.ts
index 8a7b592d..4a7c6a80 100644
--- a/packages/trpc/routers/admin.ts
+++ b/packages/trpc/routers/admin.ts
@@ -1,6 +1,6 @@
-import { adminProcedure, router } from "../index";
-import { z } from "zod";
import { count } from "drizzle-orm";
+import { z } from "zod";
+
import { bookmarks, users } from "@hoarder/db/schema";
import {
LinkCrawlerQueue,
@@ -8,6 +8,8 @@ import {
SearchIndexingQueue,
} from "@hoarder/shared/queues";
+import { adminProcedure, router } from "../index";
+
export const adminAppRouter = router({
stats: adminProcedure
.output(
diff --git a/packages/trpc/routers/apiKeys.ts b/packages/trpc/routers/apiKeys.ts
index 3093b433..deeb108f 100644
--- a/packages/trpc/routers/apiKeys.ts
+++ b/packages/trpc/routers/apiKeys.ts
@@ -1,9 +1,11 @@
-import { generateApiKey, validatePassword } from "../auth";
-import { authedProcedure, publicProcedure, router } from "../index";
+import { TRPCError } from "@trpc/server";
+import { and, eq } from "drizzle-orm";
import { z } from "zod";
+
import { apiKeys } from "@hoarder/db/schema";
-import { eq, and } from "drizzle-orm";
-import { TRPCError } from "@trpc/server";
+
+import { generateApiKey, validatePassword } from "../auth";
+import { authedProcedure, publicProcedure, router } from "../index";
const zApiKeySchema = z.object({
id: z.string(),
diff --git a/packages/trpc/routers/bookmarks.test.ts b/packages/trpc/routers/bookmarks.test.ts
index 724a9998..58f4739d 100644
--- a/packages/trpc/routers/bookmarks.test.ts
+++ b/packages/trpc/routers/bookmarks.test.ts
@@ -1,5 +1,7 @@
-import { CustomTestContext, defaultBeforeEach } from "../testUtils";
-import { expect, describe, test, beforeEach, assert } from "vitest";
+import { assert, beforeEach, describe, expect, test } from "vitest";
+
+import type { CustomTestContext } from "../testUtils";
+import { defaultBeforeEach } from "../testUtils";
beforeEach<CustomTestContext>(defaultBeforeEach(true));
diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts
index 4fb29c4c..9611829f 100644
--- a/packages/trpc/routers/bookmarks.ts
+++ b/packages/trpc/routers/bookmarks.ts
@@ -21,19 +21,19 @@ import {
} from "@hoarder/shared/queues";
import { getSearchIdxClient } from "@hoarder/shared/search";
-import { authedProcedure, Context, router } from "../index";
+import type { Context } from "../index";
+import type { ZBookmark, ZBookmarkContent } from "../types/bookmarks";
+import type { ZBookmarkTags } from "../types/tags";
+import { authedProcedure, router } from "../index";
import {
DEFAULT_NUM_BOOKMARKS_PER_PAGE,
zBareBookmarkSchema,
- ZBookmark,
- ZBookmarkContent,
zBookmarkSchema,
zGetBookmarksRequestSchema,
zGetBookmarksResponseSchema,
zNewBookmarkRequestSchema,
zUpdateBookmarksRequestSchema,
} from "../types/bookmarks";
-import { ZBookmarkTags } from "../types/tags";
export const ensureBookmarkOwnership = experimental_trpcMiddleware<{
ctx: Context;
@@ -423,29 +423,29 @@ export const bookmarksAppRouter = router({
input.ids ? inArray(bookmarks.id, input.ids) : undefined,
input.tagId !== undefined
? exists(
- ctx.db
- .select()
- .from(tagsOnBookmarks)
- .where(
- and(
- eq(tagsOnBookmarks.bookmarkId, bookmarks.id),
- eq(tagsOnBookmarks.tagId, input.tagId),
+ ctx.db
+ .select()
+ .from(tagsOnBookmarks)
+ .where(
+ and(
+ eq(tagsOnBookmarks.bookmarkId, bookmarks.id),
+ eq(tagsOnBookmarks.tagId, input.tagId),
+ ),
),
- ),
- )
+ )
: undefined,
input.listId !== undefined
? exists(
- ctx.db
- .select()
- .from(bookmarksInLists)
- .where(
- and(
- eq(bookmarksInLists.bookmarkId, bookmarks.id),
- eq(bookmarksInLists.listId, input.listId),
+ ctx.db
+ .select()
+ .from(bookmarksInLists)
+ .where(
+ and(
+ eq(bookmarksInLists.bookmarkId, bookmarks.id),
+ eq(bookmarksInLists.listId, input.listId),
+ ),
),
- ),
- )
+ )
: undefined,
input.cursor ? lte(bookmarks.createdAt, input.cursor) : undefined,
),
diff --git a/packages/trpc/routers/lists.ts b/packages/trpc/routers/lists.ts
index db5bb38e..fb6d8637 100644
--- a/packages/trpc/routers/lists.ts
+++ b/packages/trpc/routers/lists.ts
@@ -5,7 +5,8 @@ import { z } from "zod";
import { SqliteError } from "@hoarder/db";
import { bookmarkLists, bookmarksInLists } from "@hoarder/db/schema";
-import { authedProcedure, Context, router } from "../index";
+import type { Context } from "../index";
+import { authedProcedure, router } from "../index";
import { zBookmarkListSchema } from "../types/lists";
import { ensureBookmarkOwnership } from "./bookmarks";
diff --git a/packages/trpc/routers/users.test.ts b/packages/trpc/routers/users.test.ts
index 87814407..ea342d33 100644
--- a/packages/trpc/routers/users.test.ts
+++ b/packages/trpc/routers/users.test.ts
@@ -1,9 +1,7 @@
-import {
- CustomTestContext,
- defaultBeforeEach,
- getApiCaller,
-} from "../testUtils";
-import { expect, describe, test, beforeEach, assert } from "vitest";
+import { assert, beforeEach, describe, expect, test } from "vitest";
+
+import type { CustomTestContext } from "../testUtils";
+import { defaultBeforeEach, getApiCaller } from "../testUtils";
beforeEach<CustomTestContext>(defaultBeforeEach(false));
diff --git a/packages/trpc/testUtils.ts b/packages/trpc/testUtils.ts
index d5f24def..67fbddcc 100644
--- a/packages/trpc/testUtils.ts
+++ b/packages/trpc/testUtils.ts
@@ -1,7 +1,8 @@
-import { users } from "@hoarder/db/schema";
import { getInMemoryDB } from "@hoarder/db/drizzle";
-import { appRouter } from "./routers/_app";
+import { users } from "@hoarder/db/schema";
+
import { createCallerFactory } from "./index";
+import { appRouter } from "./routers/_app";
export function getTestDB() {
return getInMemoryDB(true);
@@ -63,7 +64,7 @@ export async function buildTestContext(
};
}
-export function defaultBeforeEach(seedDB: boolean = true) {
+export function defaultBeforeEach(seedDB = true) {
return async (context: object) => {
Object.assign(context, await buildTestContext(seedDB));
};
diff --git a/packages/trpc/tsconfig.json b/packages/trpc/tsconfig.json
index 80329662..dbd0afdc 100644
--- a/packages/trpc/tsconfig.json
+++ b/packages/trpc/tsconfig.json
@@ -5,6 +5,5 @@
"exclude": ["node_modules"],
"compilerOptions": {
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
- },
+ }
}
-
diff --git a/packages/trpc/types/bookmarks.ts b/packages/trpc/types/bookmarks.ts
index 1b78d6da..b6c8691f 100644
--- a/packages/trpc/types/bookmarks.ts
+++ b/packages/trpc/types/bookmarks.ts
@@ -1,4 +1,5 @@
import { z } from "zod";
+
import { zBookmarkTagSchema } from "./tags";
export const zBookmarkedLinkSchema = z.object({
@@ -30,7 +31,7 @@ export const zBookmarkContentSchema = z.discriminatedUnion("type", [
zBookmarkedLinkSchema,
zBookmarkedTextSchema,
zBookmarkedAssetSchema,
- z.object({type: z.literal("unknown")}),
+ z.object({ type: z.literal("unknown") }),
]);
export type ZBookmarkContent = z.infer<typeof zBookmarkContentSchema>;
diff --git a/packages/trpc/vitest.config.ts b/packages/trpc/vitest.config.ts
index c3d02f71..41fd70c4 100644
--- a/packages/trpc/vitest.config.ts
+++ b/packages/trpc/vitest.config.ts
@@ -1,7 +1,7 @@
/// <reference types="vitest" />
-import { defineConfig } from "vitest/config";
import tsconfigPaths from "vite-tsconfig-paths";
+import { defineConfig } from "vitest/config";
// https://vitejs.dev/config/
export default defineConfig({