refactor: separate api types (#71)

* refactor: better api types boundaries

* fix: fmt
This commit is contained in:
Yuzu 2022-07-18 21:18:10 +00:00 committed by GitHub
parent aff4bf2e92
commit 47d20cb6e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 44 additions and 48 deletions

2
mod.ts
View File

@ -5,4 +5,6 @@ export default Session;
export * from './packages/biscuit/mod.ts';
export * from './packages/discordeno/mod.ts';
export * from './packages/cache/mod.ts';
export * from './packages/api-types/discord.ts';
export * from './packages/api-types/shared.ts';
export { default as enableCache } from './packages/cache/mod.ts';

View File

@ -426,19 +426,19 @@ export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): strin
return `/guilds/${guildId}/stickers`;
}
/**
/**
* Return the widget for the guild.
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
*/
export interface GetWidget {
get: 'json' | 'image' | 'settings';
}
/**
* /guilds/{guildId}/widget
/**
* /guilds/{guildId}/widget
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
*/
export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = {get: 'settings'}): string {
export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = { get: 'settings' }): string {
let url = `/guilds/${guildId}/widget`;
if (options.get === 'json') {
url += '.json';
@ -446,5 +446,5 @@ export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = {get: 'set
url += '.png';
}
return url
}
return url;
}

View File

@ -33,7 +33,7 @@ import ThreadMember from './ThreadMember.ts';
/**
* Abstract class that represents the base for creating a new channel.
*/
*/
export abstract class BaseChannel implements Model {
constructor(session: Session, data: DiscordChannel) {
this.id = data.id;
@ -93,7 +93,7 @@ export abstract class BaseChannel implements Model {
/**
* @link https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params
* Represents the options object to create an invitation
*/
*/
export interface DiscordInviteOptions {
/** duration of invite in seconds before expiry, or 0 for never. between 0 and 604800 (7 days) */
maxAge?: number;
@ -122,7 +122,7 @@ export interface CreateWebhook {
}
/** Available text-channel-types list */
export const textBasedChannels:ChannelTypes[] = [
export const textBasedChannels: ChannelTypes[] = [
ChannelTypes.DM,
ChannelTypes.GroupDm,
ChannelTypes.GuildPrivateThread,
@ -208,7 +208,7 @@ export class TextChannel {
}
}
/**
/**
* fetchPins makes an asynchronous request and gets the current channel pins.
* @returns A promise that resolves with an array of Message objects.
*/
@ -221,7 +221,7 @@ export class TextChannel {
return messages[0] ? messages.map((x: DiscordMessage) => new Message(this.session, x)) : [];
}
/**
/**
* createInvite makes an asynchronous request to create a new invitation.
* @param options - The options to create the invitation
* @returns The created invite
@ -247,10 +247,10 @@ export class TextChannel {
return new Invite(this.session, invite);
}
/**
/**
* fetchMessages makes an asynchronous request and gets the channel messages
* @param options - The options to get the messages
* @returns The messages
* @returns The messages
*/
async fetchMessages(options?: Routes.GetMessagesOptions): Promise<Message[] | []> {
if (options?.limit! > 100) throw Error('Values must be between 0-100');
@ -271,7 +271,7 @@ export class TextChannel {
);
}
/**
/**
* pinMessage pins a channel message.
* Same as Message.pin().
* @param messageId - The id of the message to pin
@ -281,7 +281,7 @@ export class TextChannel {
await Message.prototype.pin.call({ id: messageId, channelId: this.id, session: this.session });
}
/**
/**
* unpinMessage unpin a channel message.
* Same as Message.unpin()
* @param messageId - The id of the message to unpin
@ -291,7 +291,7 @@ export class TextChannel {
await Message.prototype.unpin.call({ id: messageId, channelId: this.id, session: this.session });
}
/**
/**
* addReaction adds a reaction to the message.
* Same as Message.addReaction().
* @param messageId - The message to add the reaction to
@ -305,7 +305,7 @@ export class TextChannel {
);
}
/**
/**
* removeReaction removes a reaction from the message.
* Same as Message.removeReaction().
* @param messageId - The id of the message to remove the reaction from
@ -324,7 +324,7 @@ export class TextChannel {
);
}
/**
/**
* removeReactionEmoji removes an emoji reaction from the messageId provided.
* Same as Message.removeReactionEmoji().
* @param messageId - The message id to remove the reaction from.
@ -347,7 +347,7 @@ export class TextChannel {
await Message.prototype.nukeReactions.call({ channelId: this.id, id: messageId });
}
/**
/**
* fetchReactions gets the users who reacted with this emoji on the message.
* Same as Message.fetchReactions().
* @param messageId - The message id to get the reactions from.

View File

@ -1,5 +1,5 @@
import { DiscordGatewayPayload } from '../../types/discord.ts';
import { GatewayBot, PickPartial } from '../../types/shared.ts';
import { DiscordGatewayPayload } from '../../../api-types/discord.ts';
import { GatewayBot, PickPartial } from '../../../api-types/shared.ts';
import { LeakyBucket } from '../../util/bucket.ts';
import { CreateShard, createShard } from '../shard/createShard.ts';
import { Shard, ShardGatewayConfig } from '../shard/types.ts';

View File

@ -1,5 +1,5 @@
import { DiscordGatewayPayload } from '../../types/discord.ts';
import { PickPartial } from '../../types/shared.ts';
import { DiscordGatewayPayload } from '../../../api-types/discord.ts';
import { PickPartial } from '../../../api-types/shared.ts';
import { CreateShard, createShard } from '../shard/createShard.ts';
import { Shard, ShardGatewayConfig } from '../shard/types.ts';

View File

@ -1,4 +1,4 @@
import { GatewayIntents } from '../../types/shared.ts';
import { GatewayIntents } from '../../../api-types/shared.ts';
import { createLeakyBucket } from '../../util/bucket.ts';
import { createShard } from '../shard/createShard.ts';
import { Shard } from '../shard/types.ts';

View File

@ -1,4 +1,4 @@
import { GatewayIntents } from '../../types/shared.ts';
import { GatewayIntents } from '../../../api-types/shared.ts';
import { createShard } from '../shard/createShard.ts';
import { GatewayManager } from './gatewayManager.ts';

View File

@ -23,8 +23,8 @@ import { connect } from './connect.ts';
import { close } from './close.ts';
import { shutdown } from './shutdown.ts';
import { isOpen } from './isOpen.ts';
import { DiscordGatewayPayload, DiscordStatusUpdate } from '../../types/discord.ts';
import { GatewayIntents, PickPartial } from '../../types/shared.ts';
import { DiscordGatewayPayload, DiscordStatusUpdate } from '../../../api-types/discord.ts';
import { GatewayIntents, PickPartial } from '../../../api-types/shared.ts';
import { API_VERSION } from '../../util/constants.ts';
// TODO: debug

View File

@ -1,4 +1,4 @@
import { GatewayCloseEventCodes } from '../../types/shared.ts';
import { GatewayCloseEventCodes } from '../../../api-types/shared.ts';
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
export async function handleClose(shard: Shard, close: CloseEvent): Promise<void> {

View File

@ -1,5 +1,5 @@
import { DiscordGatewayPayload, DiscordHello, DiscordReady } from '../../types/discord.ts';
import { GatewayOpcodes } from '../../types/shared.ts';
import { DiscordGatewayPayload, DiscordHello, DiscordReady } from '../../../api-types/discord.ts';
import { GatewayOpcodes } from '../../../api-types/shared.ts';
import { createLeakyBucket } from '../../util/bucket.ts';
import { delay } from '../../util/delay.ts';
import { decompressWith } from './deps.ts';

View File

@ -1,4 +1,4 @@
import { GatewayOpcodes } from '../../types/shared.ts';
import { GatewayOpcodes } from '../../../api-types/shared.ts';
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
export async function identify(shard: Shard): Promise<void> {

View File

@ -1,4 +1,4 @@
import { GatewayOpcodes } from '../../types/shared.ts';
import { GatewayOpcodes } from '../../../api-types/shared.ts';
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
export async function resume(shard: Shard): Promise<void> {

View File

@ -1,4 +1,4 @@
import { GatewayOpcodes } from '../../types/shared.ts';
import { GatewayOpcodes } from '../../../api-types/shared.ts';
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
export function startHeartbeating(shard: Shard, interval: number) {

View File

@ -1,5 +1,5 @@
import { DiscordGatewayPayload } from '../../types/discord.ts';
import { GatewayOpcodes } from '../../types/shared.ts';
import { DiscordGatewayPayload } from '../../../api-types/discord.ts';
import { GatewayOpcodes } from '../../../api-types/shared.ts';
import { createShard } from './createShard.ts';
// TODO: think whether we also need an identifiedShard function

View File

@ -1,5 +1,6 @@
export * from './gateway/mod.ts';
export * from './rest/mod.ts';
export * from './types/mod.ts';
export * from './util/constants.ts';
export * from './util/token.ts';
export * from '../api-types/discord.ts';
export * from '../api-types/shared.ts';

View File

@ -1,5 +1,5 @@
import { RestManager } from './restManager.ts';
import { FileContent } from '../types/shared.ts';
import { FileContent } from '../../api-types/shared.ts';
import { USER_AGENT } from '../util/constants.ts';
import { RequestMethod, RestPayload, RestRequest } from './rest.ts';

View File

@ -1,5 +1,5 @@
import { RestManager } from './restManager.ts';
import { HTTPResponseCodes } from '../types/shared.ts';
import { HTTPResponseCodes } from '../../api-types/shared.ts';
export async function processGlobalQueue(rest: RestManager) {
// IF QUEUE IS EMPTY EXIT

View File

@ -1,4 +1,4 @@
import { HTTPResponseCodes } from '../types/shared.ts';
import { HTTPResponseCodes } from '../../api-types/shared.ts';
import { BASE_URL } from '../util/constants.ts';
import { RequestMethod } from './rest.ts';
import { RestManager } from './restManager.ts';

View File

@ -1,2 +0,0 @@
export * from './discord.ts';
export * from './shared.ts';

View File

@ -1,4 +1,4 @@
import { PickPartial } from '../types/shared.ts';
import { PickPartial } from '../../api-types/shared.ts';
import { delay } from './delay.ts';
/** A Leaky Bucket.

View File

@ -1,5 +0,0 @@
export * from './bucket.ts';
export * from './collection.ts';
export * from './constants.ts';
export * from './delay.ts';
export * from './token.ts';