import { GuildMetadata, Member, Channel, Message, Resource, Token } from "./data-types"; import { Fetchable, GuaranteedFetchable } from "./guild-types"; export default class EnsuredFetchable implements GuaranteedFetchable { constructor( private fetchable: Fetchable ) {} private static guarantee(value: T | null): T { if (!value) throw new Error('got null value'); return value; } async fetchMetadata(): Promise { return EnsuredFetchable.guarantee(await this.fetchable.fetchMetadata()); } async fetchMembers(): Promise { return EnsuredFetchable.guarantee(await this.fetchable.fetchMembers()); } async fetchChannels(): Promise { return EnsuredFetchable.guarantee(await this.fetchable.fetchChannels()); } async fetchMessagesRecent(channelId: string, number: number): Promise { return EnsuredFetchable.guarantee(await this.fetchable.fetchMessagesRecent(channelId, number)); } async fetchMessagesBefore(channelId: string, messageId: string, number: number): Promise { return EnsuredFetchable.guarantee(await this.fetchable.fetchMessagesBefore(channelId, messageId, number)); } async fetchMessagesAfter(channelId: string, messageId: string, number: number): Promise { return EnsuredFetchable.guarantee(await this.fetchable.fetchMessagesAfter(channelId, messageId, number)); } async fetchResource(resourceId: string): Promise { return EnsuredFetchable.guarantee(await this.fetchable.fetchResource(resourceId)); } async fetchTokens(): Promise { return EnsuredFetchable.guarantee(await this.fetchable.fetchTokens()); } }