diff options
| author | MohamedBassem <me@mbassem.com> | 2024-03-30 16:26:16 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-03-30 16:26:16 +0000 |
| commit | 46b78eaac30be26fe40520e97786563344af8403 (patch) | |
| tree | c4c0e1ae1d3d21a6f1fbf5f44f68e99243bbb5d3 /packages/shared | |
| parent | 853ed13450b3a0d92cba144cc0dfd0696e7c810c (diff) | |
| download | karakeep-46b78eaac30be26fe40520e97786563344af8403.tar.zst | |
format: Add missing lint and format, and format the entire repo
Diffstat (limited to 'packages/shared')
| -rw-r--r-- | packages/shared/assetdb.ts | 19 | ||||
| -rw-r--r-- | packages/shared/logger.ts | 1 | ||||
| -rw-r--r-- | packages/shared/package.json | 5 | ||||
| -rw-r--r-- | packages/shared/search.ts | 32 |
4 files changed, 42 insertions, 15 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; |
