Skip to content

Commit

Permalink
Chore: Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsLimeNade committed Apr 3, 2024
1 parent 91448ba commit 9f27129
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 86 deletions.
6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"cSpell.words": [
"Blockly",
"colour",
"Deprec"
]
"cSpell.words": ["Blockly", "colour", "Deprec", "Dexie", "Discodes"]
}
4 changes: 2 additions & 2 deletions src/lib/types/BlockDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export type BlockDefinition =
code: (args: Record<string, unknown>) => 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
Expand Down
169 changes: 90 additions & 79 deletions src/lib/utils/localDB/localDBmanager.ts
Original file line number Diff line number Diff line change
@@ -1,99 +1,110 @@
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
}
plugins!: Table<DiscodesPluginDataStore, string>;
users!: Table<User, string>;

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<DiscodesPlugin | undefined>)}
* @memberof LocalDBManager
*/
async getPlugin(id: string): Promise<DiscodesPlugin | undefined> {
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!
//? 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[]
}
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;
};

0 comments on commit 9f27129

Please sign in to comment.