harmony/src/managers/baseChild.ts

41 lines
988 B
TypeScript
Raw Normal View History

2020-11-08 07:57:24 +00:00
import { Client } from '../models/client.ts'
import { Collection } from '../utils/collection.ts'
import { BaseManager } from './base.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-03 09:21:29 +00:00
async set(key: string, value: T): Promise<void> {
return this.parent.set(key, value)
}
async delete(key: string): Promise<any> {
return false
}
async array(): Promise<any> {
2020-11-03 09:21:29 +00:00
return this.parent.array()
}
async collection(): Promise<Collection<string, T2>> {
2020-12-02 12:29:52 +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()
for (const elem of arr) {
2020-11-03 09:21:29 +00:00
// @ts-expect-error
collection.set(elem.id, elem)
}
return collection
}
2020-12-02 12:29:52 +00:00
}