Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a plugin and user store #13

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/lib/utils/localDB/localDBmanager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
export default class LocalDBManager {
import { Dexie, type Table } from "dexie";

export default class LocalDBManager extends Dexie {
plugins!: Table<DiscodesPluginDataStore, string>
users!: Table<User, string>

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
Expand All @@ -25,7 +67,7 @@ type User = {
followers: User[]
createdAt: Date
workspaces: DiscodesWorkspace[]
publishedPluins: DiscodesPlugin[]
publishedPlugins: DiscodesPlugin[]
publishedExamples: DiscodesFile[]
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
@@ -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("/");
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading