diff --git a/src/api/client.ts b/src/api/client.ts index 0c4625c..426cd52 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -36,11 +36,11 @@ export class client { this.socket = socket; this.uploads = uploads; - socket.on("auth", (data) => { + socket.on('auth', (data) => { for (const chat of data.chats) { api._chat_cache.set(chat._id, chat); } - }) + }); } /** signup for an account and login */ diff --git a/src/api/rest.ts b/src/api/rest.ts index 176c8f6..ee1344c 100644 --- a/src/api/rest.ts +++ b/src/api/rest.ts @@ -36,11 +36,11 @@ export class rest_api { /** the api token */ api_token: string; /** @internal chat cache */ - _chat_cache = new Map(); + _chat_cache: Map = new Map(); /** @internal post cache */ - _post_cache = new Map(); + _post_cache: Map = new Map(); /** @internal user cache */ - _user_cache = new Map(); + _user_cache: Map = new Map(); constructor(opts: api_construction_opts) { this.api_user = new user({ diff --git a/src/api/socket.ts b/src/api/socket.ts index 24276ba..cff4826 100644 --- a/src/api/socket.ts +++ b/src/api/socket.ts @@ -16,7 +16,7 @@ export interface socket_connect_opts { /** socket value types */ export type socket_value = | string - | { [key: string]: socket_value } + | { [key: string]: socket_value }; /** a packet sent over the socket */ export interface socket_packet { @@ -39,7 +39,7 @@ export interface socket_auth_event { /** relationships */ relationships: { username: string; - tyoe: user_relationship_status + tyoe: user_relationship_status; }[]; /** chats */ chats: api_chat[]; @@ -55,8 +55,8 @@ export class socket extends EventEmitter<{ [key: `listener-${string}`]: [socket_packet]; create_message: [post]; edit_message: [post]; - delete_message: [{ post_id: string, chat_id: string }]; - typing: [{ chat_id: string, username: string }]; + delete_message: [{ post_id: string; chat_id: string }]; + typing: [{ chat_id: string; username: string }]; auth: [socket_auth_event]; }> { private socket: WebSocket; @@ -100,7 +100,7 @@ export class socket extends EventEmitter<{ this.socket.onerror = (err) => this.emit('socket_error', err); - this.on('cmd-post', packet => { + this.on('cmd-post', (packet) => { try { const api = packet.val as unknown as api_post; const p = new post({ @@ -112,9 +112,9 @@ export class socket extends EventEmitter<{ } catch { // ignore } - }) + }); - this.on('cmd-update_post', packet => { + this.on('cmd-update_post', (packet) => { try { const api = packet.val as unknown as api_post; const p = new post({ @@ -126,25 +126,28 @@ export class socket extends EventEmitter<{ } catch { // ignore } - }) + }); - this.on('cmd-delete_post', packet => { - this.emit('delete_message', packet.val as { post_id: string, chat_id: string }); - }) + this.on('cmd-delete_post', (packet) => { + this.emit( + 'delete_message', + packet.val as { post_id: string; chat_id: string }, + ); + }); - this.on('cmd-typing', packet => { - this.emit('typing', packet.val as { chat_id: string, username: string }); - }) + this.on('cmd-typing', (packet) => { + this.emit('typing', packet.val as { chat_id: string; username: string }); + }); - this.on('cmd-ulist', packet => { - this.ulist = (packet.val as string).split(';') - }) + this.on('cmd-ulist', (packet) => { + this.ulist = (packet.val as string).split(';'); + }); - this.on('cmd-auth', packet => { + this.on('cmd-auth', (packet) => { this.emit('auth', packet.val as unknown as socket_auth_event); this.opts.api_token = (packet.val as unknown as socket_auth_event).token; - }) + }); } static async connect(opts: socket_connect_opts): Promise { diff --git a/tests/chat.ts b/tests/chat.ts index 5473f3b..92f0ce5 100644 --- a/tests/chat.ts +++ b/tests/chat.ts @@ -42,7 +42,7 @@ Deno.test('chat construction', async (i) => { const c = new chat({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_chat, }); @@ -54,7 +54,7 @@ Deno.test('chat leaving', async (i) => { const c = new chat({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_chat, }); @@ -85,7 +85,7 @@ Deno.test('chat updating', async (i) => { const c = new chat({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_chat, }); @@ -124,7 +124,7 @@ Deno.test('chat members', async (i) => { const c = new chat({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_chat, }); @@ -205,7 +205,7 @@ Deno.test('chat messages', async (i) => { const c = new chat({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_chat, }); @@ -296,14 +296,14 @@ Deno.test('chat search', async (i) => { const c = new chat({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_chat, }); const h = new chat({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: { ...regular_chat, _id: 'home', diff --git a/tests/post.ts b/tests/post.ts index 5400f4e..5c19e38 100644 --- a/tests/post.ts +++ b/tests/post.ts @@ -41,7 +41,7 @@ Deno.test('post construction', async (i) => { const p = new post({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_post, }); @@ -53,7 +53,7 @@ Deno.test('post pinning', async (i) => { const p = new post({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_post, }); @@ -116,7 +116,7 @@ Deno.test('post deletion', async (i) => { const p = new post({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_post, }); @@ -149,7 +149,7 @@ Deno.test('post reporting', async (i) => { const p = new post({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_post, }); @@ -182,7 +182,7 @@ Deno.test('post editing', async (i) => { const p = new post({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_post, }); @@ -222,7 +222,7 @@ Deno.test('post reply', async (i) => { const p = new post({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_post, }); diff --git a/tests/user.ts b/tests/user.ts index 336efd7..bfdc594 100644 --- a/tests/user.ts +++ b/tests/user.ts @@ -47,7 +47,7 @@ Deno.test('user construction', async (i) => { const u = new user({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_user, }); @@ -59,7 +59,7 @@ Deno.test('user reporting', async (i) => { const u = new user({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_user, }); @@ -86,7 +86,7 @@ Deno.test('user relationship', async (i) => { const u = new user({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_user, }); @@ -114,7 +114,7 @@ Deno.test('user posts', async (i) => { const u = new user({ api_url: 'http://localhost:8000', api_token: 'test', - api_username: 'test', + data: regular_user, });