From 9f271295f3cae9a019046f5772456183a9798eb0 Mon Sep 17 00:00:00 2001 From: LimeNade Date: Wed, 3 Apr 2024 20:10:33 +0200 Subject: [PATCH] Chore: Lint --- .vscode/settings.json | 6 +- src/lib/types/BlockDefinition.ts | 4 +- src/lib/utils/localDB/localDBmanager.ts | 169 +++++++++++++----------- 3 files changed, 93 insertions(+), 86 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5ed364e..4c98c88 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,3 @@ { - "cSpell.words": [ - "Blockly", - "colour", - "Deprec" - ] + "cSpell.words": ["Blockly", "colour", "Deprec", "Dexie", "Discodes"] } diff --git a/src/lib/types/BlockDefinition.ts b/src/lib/types/BlockDefinition.ts index 9f79a8f..a96b3f8 100644 --- a/src/lib/types/BlockDefinition.ts +++ b/src/lib/types/BlockDefinition.ts @@ -24,11 +24,11 @@ export type BlockDefinition = code: (args: Record) => string | [string, Order]; mutator?: Mutator; hidden?: boolean; - } + } | { label: true; text: string; - }; + }; export type MutatorBlock = { // Name of the block that appears in the block list in the UI diff --git a/src/lib/utils/localDB/localDBmanager.ts b/src/lib/utils/localDB/localDBmanager.ts index e0f3ecf..81c0315 100644 --- a/src/lib/utils/localDB/localDBmanager.ts +++ b/src/lib/utils/localDB/localDBmanager.ts @@ -1,35 +1,46 @@ 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 - } + plugins!: Table; + users!: Table; + + constructor() { + super("DiscodesDatabase"); + + this.version(1).stores({ + plugins: "id", + users: "id" + }); + } + + /** + * Returns the plugin table or returns undefined if the owner or the plugin doesn't exist. + * + * @param {string} id + * @return {*} {(Promise)} + * @memberof LocalDBManager + */ + async getPlugin(id: string): Promise { + 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; + } + + async createUser(userData: User) { + await this.users.add(userData, window.crypto.randomUUID()); + } } //TODO Make those interfaces! @@ -37,63 +48,63 @@ export default class LocalDBManager extends Dexie { type BlockConfig = unknown; type DiscodesPluginDataStore = { - id: string, - name: string - owner: string - description: string - downloads: number - likes: number - rating: number - version: number - blocks: BlockConfig[] -} + id: string; + name: string; + owner: string; + description: string; + downloads: number; + likes: number; + rating: number; + version: number; + blocks: BlockConfig[]; +}; type DiscodesPlugin = { - id: string, - owner: User - name: string - description: string - downloads: number - likes: number - rating: number - version: number - blocks: BlockConfig[] -} + id: string; + owner: User; + name: string; + description: string; + downloads: number; + likes: number; + rating: number; + version: number; + blocks: BlockConfig[]; +}; type User = { - username: string - id: string - follows: User[] - followers: User[] - createdAt: Date - workspaces: DiscodesWorkspace[] - publishedPlugins: DiscodesPlugin[] - publishedExamples: DiscodesFile[] -} + username: string; + id: string; + follows: User[]; + followers: User[]; + createdAt: Date; + workspaces: DiscodesWorkspace[]; + publishedPlugins: DiscodesPlugin[]; + publishedExamples: DiscodesFile[]; +}; type BlocklyWorkspaceSave = { - workspaceSave: object | string - blockLength: number -} + workspaceSave: object | string; + blockLength: number; +}; type DiscodesFile = { - name: string - createdAt: Date - lastEditedAt: Date - blocklyWorkspaceSave: BlocklyWorkspaceSave - thumbnail: string - timeWasted: number -} + name: string; + createdAt: Date; + lastEditedAt: Date; + blocklyWorkspaceSave: BlocklyWorkspaceSave; + thumbnail: string; + timeWasted: number; +}; type DiscodesWorkspace = { - files: DiscodesFile[] - createdAt: Date - lastEditedAt: Date - owner: string - editors: string[] - viewers: string[] - id: string - name: string - description: string - timeWasted: number -} + files: DiscodesFile[]; + createdAt: Date; + lastEditedAt: Date; + owner: string; + editors: string[]; + viewers: string[]; + id: string; + name: string; + description: string; + timeWasted: number; +};