Skip to content

Commit

Permalink
set data type on interface QueueStoreManager
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterGamez committed Sep 22, 2024
1 parent 0a2ddfe commit 8ba9ff8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
26 changes: 13 additions & 13 deletions src/structures/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ export class QueueSaver {
}

export class DefaultQueueStore implements QueueStoreManager {
private data = new MiniMap();
private data = new MiniMap<string, StoredQueue>();
constructor() { }

/**
* Get the queue for a guild
* @param guildId The guild ID
* @returns The queue for the guild
*/
async get(guildId) {
return await this.data.get(guildId);
async get(guildId: string) {
return this.data.get(guildId) as string | StoredQueue;
}

/**
Expand All @@ -80,35 +80,35 @@ export class DefaultQueueStore implements QueueStoreManager {
* @param valueToStringify The queue to set
* @returns The queue for the guild
*/
async set(guildId, valueToStringify) {
return await this.data.set(guildId, valueToStringify)
async set(guildId: string, valueToStringify) {
return this.data.set(guildId, valueToStringify) ? true : false;
}

/**
* Delete the queue for a guild
* @param guildId The guild ID
* @returns The queue for the guild
*/
async delete(guildId) {
return await this.data.delete(guildId);
async delete(guildId: string) {
return this.data.delete(guildId);
}

/**
* Stringify the queue for a guild
* @param value The queue to stringify
* @returns The stringified queue
*/
async stringify(value) {
return value; // JSON.stringify(value);
async stringify(value: StoredQueue | string) {
return value as string; // JSON.stringify(value);
}

/**
* Parse the queue for a guild
* @param value The queue to parse
* @returns The parsed queue
*/
async parse(value) {
return value as Partial<StoredQueue>; // JSON.parse(value)
async parse(value: StoredQueue | string) {
return value as StoredQueue; // JSON.parse(value)
}
}

Expand Down Expand Up @@ -178,14 +178,14 @@ export class Queue {
/**
* @returns {{current:Track|null, previous:Track[], tracks:Track[]}}The Queue, but in a raw State, which allows easier handling for the QueueStoreManager
*/
toJSON: () : StoredQueue=> {
toJSON: (): StoredQueue => {
if (this.previous.length > this.options.maxPreviousTracks) this.previous.splice(this.options.maxPreviousTracks, this.previous.length);
return {
current: this.current ? { ...this.current } : null,
previous: this.previous ? [...this.previous] : [],
tracks: this.tracks ? [...this.tracks] : [],
};
} ,
},

/**
* Get the Total Duration of the Queue-Songs summed up
Expand Down
15 changes: 7 additions & 8 deletions src/structures/Types/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import type { Track, UnresolvedTrack } from "./Track";
export interface StoredQueue {
current: Track | null;
previous: Track[];
tracks: (Track|UnresolvedTrack)[];
tracks: (Track | UnresolvedTrack)[];
}

export interface QueueStoreManager extends Record<string, any> {
export interface QueueStoreManager {
/** @async get a Value (MUST RETURN UNPARSED!) */
get: (guildId: unknown) => Promise<unknown>;
get: (guildId: string) => Promise<StoredQueue | string>;
/** @async Set a value inside a guildId (MUST BE UNPARSED) */
set: (guildId: unknown, value: unknown) => Promise<unknown>;
set: (guildId: string, value: StoredQueue | string) => Promise<void | boolean>;
/** @async Delete a Database Value based of it's guildId */
delete: (guildId: unknown) => Promise<unknown>;
delete: (guildId: string) => Promise<void | boolean>;
/** @async Transform the value(s) inside of the QueueStoreManager (IF YOU DON'T NEED PARSING/STRINGIFY, then just return the value) */
stringify: (value: unknown) => Promise<unknown>;
stringify: (value: StoredQueue | string) => Promise<StoredQueue |string>;
/** @async Parse the saved value back to the Queue (IF YOU DON'T NEED PARSING/STRINGIFY, then just return the value) */
parse: (value: unknown) => Promise<Partial<StoredQueue>>;
parse: (value: StoredQueue | string) => Promise<Partial<StoredQueue>>;
}

export interface ManagerQueueOptions {
Expand All @@ -28,7 +28,6 @@ export interface ManagerQueueOptions {
queueChangesWatcher?: QueueChangesWatcher;
}


export interface QueueChangesWatcher {
/** get a Value (MUST RETURN UNPARSED!) */
tracksAdd: (guildId: string, tracks: (Track | UnresolvedTrack)[], position: number, oldStoredQueue: StoredQueue, newStoredQueue: StoredQueue) => void;
Expand Down

0 comments on commit 8ba9ff8

Please sign in to comment.