Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
fix linting, formatting, and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed Aug 6, 2024
1 parent 4f5f06f commit 45a41df
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions src/api/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export class rest_api {
/** the api token */
api_token: string;
/** @internal chat cache */
_chat_cache = new Map<string, api_chat>();
_chat_cache: Map<string, api_chat> = new Map();
/** @internal post cache */
_post_cache = new Map<string, api_post>();
_post_cache: Map<string, api_post> = new Map();
/** @internal user cache */
_user_cache = new Map<string, api_user>();
_user_cache: Map<string, api_user> = new Map();

constructor(opts: api_construction_opts) {
this.api_user = new user({
Expand Down
41 changes: 22 additions & 19 deletions src/api/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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[];
Expand All @@ -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;
Expand Down Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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<socket> {
Expand Down
14 changes: 7 additions & 7 deletions tests/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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',
Expand Down
12 changes: 6 additions & 6 deletions tests/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down
8 changes: 4 additions & 4 deletions tests/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand All @@ -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,
});

Expand Down Expand Up @@ -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,
});

Expand Down

0 comments on commit 45a41df

Please sign in to comment.