From 1b36084f1d24531812dfed6bdf1a2f570deed289 Mon Sep 17 00:00:00 2001 From: Retro Date: Wed, 3 Apr 2024 20:59:56 +0630 Subject: [PATCH 1/2] Create a plugin and user store --- src/lib/utils/localDB/localDBmanager.ts | 46 +++++++++++++++++++++++-- yarn.lock | 5 +++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/lib/utils/localDB/localDBmanager.ts b/src/lib/utils/localDB/localDBmanager.ts index 4a967a6..e0f3ecf 100644 --- a/src/lib/utils/localDB/localDBmanager.ts +++ b/src/lib/utils/localDB/localDBmanager.ts @@ -1,11 +1,53 @@ -export default class LocalDBManager { +import { Dexie, type Table } from "dexie"; +export default class LocalDBManager extends Dexie { + plugins!: Table + users!: Table + + constructor() { + super("DiscodesDatabase") + + this.version(1).stores({ + plugins: "id", + users: "id" + }) + } + + async getPlugin(id: string) { + const val = await this.plugins.get(id) + + if(!val) return undefined + + const ownerId = val.owner + const owner = await this.users.get(ownerId) + + if(!owner) return undefined + + const obj: DiscodesPlugin = { + ...val, + owner + } + + return obj + } } //TODO Make those interfaces! //? Some data are for the backend only, if you feel like it doesn't belong in the localDB don't add them! Thx <3 type BlockConfig = unknown; +type DiscodesPluginDataStore = { + id: string, + name: string + owner: string + description: string + downloads: number + likes: number + rating: number + version: number + blocks: BlockConfig[] +} + type DiscodesPlugin = { id: string, owner: User @@ -25,7 +67,7 @@ type User = { followers: User[] createdAt: Date workspaces: DiscodesWorkspace[] - publishedPluins: DiscodesPlugin[] + publishedPlugins: DiscodesPlugin[] publishedExamples: DiscodesFile[] } diff --git a/yarn.lock b/yarn.lock index cf6ffcd..db064bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -983,6 +983,11 @@ devalue@^4.3.2: resolved "https://registry.npmjs.org/devalue/-/devalue-4.3.2.tgz#cc44e4cf3872ac5a78229fbce3b77e57032727b5" integrity sha512-KqFl6pOgOW+Y6wJgu80rHpo2/3H07vr8ntR9rkkFIRETewbf5GaYYcakYfiKz89K+sLsuPkQIZaXDMjUObZwWg== +dexie@^4.0.1: + version "4.0.1" + resolved "https://registry.npmjs.org/dexie/-/dexie-4.0.1.tgz#0b2aa9a39f706f0bb970134047afaa326a3c923e" + integrity sha512-wSNn+TcCh+DuE2pdg058K3MhxA4g+IiZlW7yGz4cMd/t3z2rJXZcV3HDxZljbrICU2Iq0qY4UHnbolTMK/+bcA== + didyoumean@^1.2.2: version "1.2.2" resolved "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz#989346ffe9e839b4555ecf5666edea0d3e8ad037" From e5a0fcf5481f38ee1b3cfb2064e858f0d243bc6c Mon Sep 17 00:00:00 2001 From: Retro Date: Wed, 3 Apr 2024 21:11:21 +0630 Subject: [PATCH 2/2] Removed unused variable --- tests/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.ts b/tests/test.ts index a131e2c..6b249c1 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -1,4 +1,4 @@ -import { expect, test } from "@playwright/test"; +import { test } from "@playwright/test"; test("index page has expected h1", async({ page }) => { await page.goto("/");