Skip to content

Commit

Permalink
docs: Use deps.ts instead of import map. (cuz docland didn't support …
Browse files Browse the repository at this point in the history
…import map)
  • Loading branch information
abdulrahman1s committed May 30, 2022
1 parent d1c0967 commit cfcdd3c
Show file tree
Hide file tree
Showing 37 changed files with 107 additions and 121 deletions.
1 change: 0 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"importMap": "import.json",
"compilerOptions": {
"strict": true
},
Expand Down
5 changes: 5 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { EventEmitter } from 'https://deno.land/std@0.132.0/node/events.ts'
export { randomBytes } from 'https://deno.land/std@0.132.0/node/crypto.ts'
export { Collection } from 'https://esm.sh/@discordjs/collection@0.6.0'
export * as API from 'https://deno.land/x/revolt_api@0.4.0/types.ts'
export * from 'https://deno.land/x/revoltio_rest@v1.1.3/mod.ts'
9 changes: 0 additions & 9 deletions import.json

This file was deleted.

1 change: 0 additions & 1 deletion scripts/build_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ await build({
compilerOptions: {
target: 'ES2021',
},
importMap: './import.json',
mappings: {
'https://deno.land/x/revoltio_rest@v1.1.3/mod.ts': {
name: '@revoltio/rest',
Expand Down
3 changes: 1 addition & 2 deletions src/client/BaseClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// deno-lint-ignore-file no-explicit-any
import { EventEmitter } from 'events';
import { EventEmitter, REST, RESTOptions } from '../../deps.ts';
import { Client } from './mod.ts';
import { REST, RESTOptions } from '@revoltio/rest';
import type {
Channel,
DMChannel,
Expand Down
4 changes: 2 additions & 2 deletions src/client/Client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RevoltConfig } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { BaseClient, WebSocketShard } from './mod.ts';
import { ActionManager } from './actions/ActionManager.ts';
import { Error } from '../errors/mod.ts';
Expand All @@ -12,7 +12,7 @@ export class Client extends BaseClient {
readonly servers = new ServerManager(this);
readonly users = new UserManager(this);
user: ClientUser | null = null;
configuration?: RevoltConfig;
configuration?: API.RevoltConfig;
readyAt: Date | null = null;

get readyTimestamp(): number | null {
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/ChannelCreate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Channel as APIChannel } from 'revolt-api-types';
import type { API } from '../../../deps.ts';
import { Action } from './Action.ts';
import { Events } from '../../util/Constants.ts';

export class ChannelCreateAction extends Action {
async handle(data: APIChannel): Promise<unknown> {
async handle(data: API.Channel): Promise<unknown> {
const channel = this.client.channels._add(data);

if (channel) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/ChannelUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Channel as APIChannel } from 'revolt-api-types';
import type { API } from '../../../deps.ts';
import { Action } from './Action.ts';
import { Events } from '../../util/Constants.ts';

export class ChannelUpdateAction extends Action {
handle(data: { id: string; data: APIChannel }): unknown {
handle(data: { id: string; data: API.Channel }): unknown {
const oldChannel = this.client.channels.cache.get(data.id);

if (oldChannel) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/Message.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Message as APIMessage } from 'revolt-api-types';
import type { API } from '../../../deps.ts';
import { Action } from './Action.ts';
import { Events, SYSTEM_USER_ID } from '../../util/Constants.ts';

export class MessageAction extends Action {
async handle(data: APIMessage): Promise<unknown> {
async handle(data: API.Message): Promise<unknown> {
const channel = this.client.channels.cache.get(data.channel);

if (channel?.isText()) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/MessageUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Message as APIMessage } from 'revolt-api-types';
import type { API } from '../../../deps.ts';
import { Action } from './Action.ts';
import { Events } from '../../util/Constants.ts';

export class MessageUpdateAction extends Action {
handle(data: { id: string; channel: string; data: APIMessage }): unknown {
handle(data: { id: string; channel: string; data: API.Message }): unknown {
const channel = this.client.channels.cache.get(data.channel);

if (!channel?.isText()) return;
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/ServerDelete.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Server as APIServer } from 'revolt-api-types';
import type { API } from '../../../deps.ts';
import { Action } from './Action.ts';
import { Events } from '../../util/Constants.ts';

export class ServerDeleteAction extends Action {
handle(data: APIServer): unknown {
handle(data: API.Server): unknown {
const server = this.client.servers.cache.get(data._id);

if (server) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/ServerMemberUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Member as APIMember } from 'revolt-api-types';
import type { API } from '../../../deps.ts';
import { Action } from './Action.ts';
import { Events } from '../../util/Constants.ts';

export class ServerMemberUpdateAction extends Action {
handle(data: { id: string; data: APIMember }): unknown {
handle(data: { id: string; data: API.Member }): unknown {
const server = this.client.servers.cache.get(data.id);
const oldMember = server?.members.cache.get(data.data?._id?.user);

Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/ServerUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Server as APIServer } from 'revolt-api-types';
import type { API } from '../../../deps.ts';
import { Action } from './Action.ts';
import { Events } from '../../util/Constants.ts';

export class ServerUpdateAction extends Action {
handle(data: { id: string; data: APIServer }): unknown {
handle(data: { id: string; data: API.Server }): unknown {
const oldServer = this.client.servers.cache.get(data.id);

if (oldServer) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/actions/UserUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { User as APIUser } from 'revolt-api-types';
import type { API } from '../../../deps.ts';
import { Action } from './Action.ts';
import { ClientUser } from '../../structures/ClientUser.ts';
import { Events } from '../../util/Constants.ts';

export class UserUpdateAction extends Action {
handle(data: { id: string; data: APIUser }): unknown {
handle(data: { id: string; data: API.User }): unknown {
const oldUser = this.client.users.cache.get(data.id);

if (oldUser) {
Expand Down
8 changes: 4 additions & 4 deletions src/managers/ChannelManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Channel as APIChannel } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { BaseManager } from './BaseManager.ts';
import { TypeError } from '../errors/mod.ts';
import {
Expand All @@ -10,12 +10,12 @@ import {
VoiceChannel,
} from '../structures/mod.ts';

export type ChannelResolvable = Channel | APIChannel | string;
export type ChannelResolvable = Channel | API.Channel | string;

export class ChannelManager extends BaseManager<Channel, APIChannel> {
export class ChannelManager extends BaseManager<Channel, API.Channel> {
holds = null;

_add(data: APIChannel): Channel {
_add(data: API.Channel): Channel {
let channel: Channel;

switch (data.channel_type) {
Expand Down
14 changes: 7 additions & 7 deletions src/managers/MessageManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Message as APIMessage } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { BaseManager } from './BaseManager.ts';
import { TypeError } from '../errors/mod.ts';
import { Channel, Message } from '../structures/mod.ts';
import { Collection, UUID } from '../util/mod.ts';

export type MessageResolvable = Message | APIMessage | string;
export type MessageResolvable = Message | API.Message | string;

export interface EditMessageOptions {
content?: string;
Expand Down Expand Up @@ -32,7 +32,7 @@ export interface MessageQueryOptions {
nearby?: string;
}

export class MessageManager extends BaseManager<Message, APIMessage> {
export class MessageManager extends BaseManager<Message, API.Message> {
holds = Message;
constructor(protected readonly channel: Channel) {
super(channel.client);
Expand All @@ -52,7 +52,7 @@ export class MessageManager extends BaseManager<Message, APIMessage> {
attachments,
},
},
) as APIMessage;
) as API.Message;

return this._add(data);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ export class MessageManager extends BaseManager<Message, APIMessage> {
const response =
(await this.client.api.post(`/channels/${this.channel.id}/search`, {
query: query as Required<MessageSearchOptions>,
})) as APIMessage[];
})) as API.Message[];
return response.reduce((coll, cur) => {
const msg = this._add(cur);
coll.set(msg.id, msg);
Expand All @@ -130,7 +130,7 @@ export class MessageManager extends BaseManager<Message, APIMessage> {
if (id) {
const data = await this.client.api.get(
`/channels/${this.channel.id}/messages/${id}`,
) as APIMessage;
) as API.Message;
return this._add(data);
}

Expand All @@ -141,7 +141,7 @@ export class MessageManager extends BaseManager<Message, APIMessage> {
{ query: query as Required<MessageQueryOptions> },
);

return (messages as APIMessage[]).reduce((coll, cur) => {
return (messages as API.Message[]).reduce((coll, cur) => {
const msg = this._add(cur);
coll.set(msg.id, msg);
return coll;
Expand Down
6 changes: 3 additions & 3 deletions src/managers/RoleManager.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { Role as APIRole } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { BaseManager } from './BaseManager.ts';
import { TypeError } from '../errors/mod.ts';
import { Role, Server } from '../structures/mod.ts';

export type RoleResolvable = Role | string;

export class RoleManager extends BaseManager<Role, APIRole & { id: string }> {
export class RoleManager extends BaseManager<Role, API.Role & { id: string }> {
holds = Role;
constructor(protected readonly server: Server) {
super(server.client);
}

_add(data: APIRole & { id: string }): Role {
_add(data: API.Role & { id: string }): Role {
const role = new Role(this.server, data);
this.cache.set(role.id, role);
return role;
Expand Down
6 changes: 3 additions & 3 deletions src/managers/ServerChannelManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Channel as APIChannel } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { BaseManager } from './BaseManager.ts';
import { TypeError } from '../errors/mod.ts';
import {
Expand All @@ -10,7 +10,7 @@ import {
import { UUID } from '../util/mod.ts';

type APIServerChannel = Extract<
APIChannel,
API.Channel,
{ channel_type: 'TextChannel' | 'VoiceChannel' }
>;

Expand All @@ -28,7 +28,7 @@ export class ServerChannelManager extends BaseManager<ServerChannel> {
super(server.client);
}

_add(data: APIChannel): ServerChannel {
_add(data: API.Channel): ServerChannel {
let channel: ServerChannel;

switch (data.channel_type) {
Expand Down
6 changes: 3 additions & 3 deletions src/managers/ServerManager.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { Server as APIServer } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { BaseManager } from './BaseManager.ts';
import { TypeError } from '../errors/mod.ts';
import { Server } from '../structures/mod.ts';
import { UUID } from '../util/mod.ts';

export type ServerResolvable = Server | APIServer | string;
export type ServerResolvable = Server | API.Server | string;

export interface EditServerOptions {
name?: string;
description?: string;
}

export class ServerManager extends BaseManager<Server, APIServer> {
export class ServerManager extends BaseManager<Server, API.Server> {
readonly holds = Server;

_remove(id: string): void {
Expand Down
6 changes: 3 additions & 3 deletions src/managers/ServerMemberManager.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { Member as APIMember } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { BaseManager } from './BaseManager.ts';
import { TypeError } from '../errors/mod.ts';
import { Server, ServerMember, User } from '../structures/mod.ts';
import { Collection } from '../util/mod.ts';

export type ServerMemberResolvable = ServerMember | User | APIMember | string;
export type ServerMemberResolvable = ServerMember | User | API.Member | string;

export interface EditServerMemberOptions {
nickname?: string;
avatar?: string;
roles?: string[];
}

export class ServerMemberManager extends BaseManager<ServerMember, APIMember> {
export class ServerMemberManager extends BaseManager<ServerMember, API.Member> {
holds = ServerMember;
constructor(protected readonly server: Server) {
super(server.client);
Expand Down
12 changes: 6 additions & 6 deletions src/managers/UserManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { User as APIUser } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { BaseManager } from './BaseManager.ts';
import { TypeError } from '../errors/mod.ts';
import { Message, User } from '../structures/mod.ts';

export type UserResolvable = User | APIUser | Message | string;
export type UserResolvable = User | API.User | Message | string;

export class UserManager extends BaseManager<User, APIUser> {
export class UserManager extends BaseManager<User, API.User> {
holds = User;

async fetch(user: UserResolvable, { force = true } = {}): Promise<User> {
Expand All @@ -18,14 +18,14 @@ export class UserManager extends BaseManager<User, APIUser> {
if (user) return user;
}

const data = await this.client.api.get(`/users/${id}`) as APIUser;
const data = await this.client.api.get(`/users/${id}`) as API.User;

return this._add(data);
}

resolve(resolvable: Message | User): User;
resolve(resolvable: string | APIUser): User | null;
resolve(resolvable: User | APIUser | string | Message): User | null {
resolve(resolvable: string | API.User): User | null;
resolve(resolvable: User | API.User | string | Message): User | null {
if (resolvable instanceof Message) return resolvable.author;
return super.resolve(resolvable);
}
Expand Down
8 changes: 4 additions & 4 deletions src/structures/Category.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Category as APICategory } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import { Base, Server, ServerChannel } from './mod.ts';
import { Collection } from '../util/mod.ts';

export class Category extends Base<APICategory> {
export class Category extends Base<API.Category> {
name!: string;
protected _children: string[] = [];
constructor(public server: Server, data: APICategory) {
constructor(public server: Server, data: API.Category) {
super(server.client);
this._patch(data);
}

protected _patch(data: APICategory): this {
protected _patch(data: API.Category): this {
super._patch(data);

if (data.title) {
Expand Down
4 changes: 2 additions & 2 deletions src/structures/Channel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Channel as APIChannel } from 'revolt-api-types';
import type { API } from '../../deps.ts';
import {
Base,
DMChannel,
Expand All @@ -9,7 +9,7 @@ import {
} from './mod.ts';
import { ChannelTypes, UUID } from '../util/mod.ts';

export abstract class Channel<T extends APIChannel = APIChannel>
export abstract class Channel<T extends API.Channel = API.Channel>
extends Base<T> {
type: ChannelTypes | 'UNKNOWN' = 'UNKNOWN';

Expand Down
Loading

0 comments on commit cfcdd3c

Please sign in to comment.