2020-11-01 13:42:00 +00:00
|
|
|
import { Client } from "../models/client.ts";
|
2020-11-02 12:08:38 +00:00
|
|
|
import { Collection } from "../utils/collection.ts";
|
2020-11-01 13:42:00 +00:00
|
|
|
import { BaseManager } from "./BaseManager.ts";
|
|
|
|
|
|
|
|
export class BaseChildManager<T, T2> {
|
|
|
|
client: Client
|
|
|
|
parent: BaseManager<T, T2>
|
|
|
|
|
|
|
|
constructor(client: Client, parent: BaseManager<T, T2>) {
|
|
|
|
this.client = client
|
|
|
|
this.parent = parent
|
|
|
|
}
|
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
async get(key: string): Promise<T2 | undefined> {
|
|
|
|
return this.parent.get(key)
|
2020-11-01 13:42:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-03 09:21:29 +00:00
|
|
|
async set(key: string, value: T): Promise<void> {
|
|
|
|
return this.parent.set(key, value)
|
2020-11-01 13:42:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async delete(key: string): Promise<any> {
|
|
|
|
return false
|
|
|
|
}
|
2020-11-02 12:08:38 +00:00
|
|
|
|
|
|
|
async array(): Promise<any> {
|
2020-11-03 09:21:29 +00:00
|
|
|
return this.parent.array()
|
2020-11-02 12:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async collection(): Promise<Collection<string, T2>> {
|
2020-11-03 09:21:29 +00:00
|
|
|
const arr = await this.array() as undefined | T2[]
|
2020-11-03 23:00:03 +00:00
|
|
|
if (arr === undefined) return new Collection()
|
2020-11-03 09:21:29 +00:00
|
|
|
const collection = new Collection()
|
2020-11-02 12:08:38 +00:00
|
|
|
for (const elem of arr) {
|
2020-11-03 09:21:29 +00:00
|
|
|
// @ts-expect-error
|
2020-11-02 12:08:38 +00:00
|
|
|
collection.set(elem.id, elem)
|
|
|
|
}
|
|
|
|
return collection
|
|
|
|
}
|
2020-11-01 13:42:00 +00:00
|
|
|
}
|