Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Fix various breaking bugs/implement QOL (#19)
Browse files Browse the repository at this point in the history
* fix(IRouter): proper types

* feat(RoutingClientInitOptions): keys now uses generic type-guarded by string

* chore: update .npmignore

* feat(Cluster): let fetchGateway throw http error on failure

* fix(RoutingClient): properly use bindQueue in init

* fix(GatewayService): failures of connecting

* chore: bump version
  • Loading branch information
didinele authored Feb 25, 2021
2 parents db87716 + a9709c3 commit 6153918
Show file tree
Hide file tree
Showing 32 changed files with 124 additions and 137 deletions.
2 changes: 1 addition & 1 deletion libs/bitfield/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
4 changes: 2 additions & 2 deletions libs/bitfield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Data structure for working with bitfields",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand All @@ -26,7 +26,7 @@
"typescript": "^4.2.2"
},
"dependencies": {
"@cordis/error": "workspace:^0.1.2",
"@cordis/error": "workspace:^0.1.5",
"tslib": "^2.1.0"
}
}
2 changes: 1 addition & 1 deletion libs/brokers/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
6 changes: 3 additions & 3 deletions libs/brokers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Message broker library for the cordis micro-services, built for AMQP",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.4",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand All @@ -27,8 +27,8 @@
"typescript": "^4.2.2"
},
"dependencies": {
"@cordis/common": "workspace:^0.1.2",
"@cordis/error": "workspace:^0.1.2",
"@cordis/common": "workspace:^0.1.5",
"@cordis/error": "workspace:^0.1.5",
"@msgpack/msgpack": "^2.4.0",
"amqplib": "^0.6.0",
"tslib": "^2.1.0"
Expand Down
8 changes: 4 additions & 4 deletions libs/brokers/src/brokers/routing/RoutingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type * as amqp from 'amqplib';
/**
* Options for initializing the routing client
*/
export interface RoutingClientInitOtions {
export interface RoutingClientInitOtions<K extends string> {
/**
* Name of the exchange to use
*/
Expand All @@ -16,7 +16,7 @@ export interface RoutingClientInitOtions {
/**
* The routing keys you wish to subscribe to
*/
keys: string[];
keys: K[];
/**
* Queue to bind the packets to
* @default queue Randomly generated queue by your AMQP server
Expand Down Expand Up @@ -59,13 +59,13 @@ export class RoutingClient<K extends string, T extends Record<K, any>> extends B
* Initializes the client, binding the events you want to the queue
* @param options Options used for this client
*/
public async init(options: RoutingClientInitOtions) {
public async init(options: RoutingClientInitOtions<K>) {
const { name, topicBased = false, keys, queue: rawQueue = '' } = options;

const exchange = await this.channel.assertExchange(name, topicBased ? 'topic' : 'direct', { durable: false }).then(d => d.exchange);
const queue = await this.channel.assertQueue(rawQueue, { durable: true, exclusive: rawQueue === '' }).then(data => data.queue);

for (const key of keys) await this.channel.bindExchange(queue, exchange, key);
for (const key of keys) await this.channel.bindQueue(queue, exchange, key);

await this.util.consumeQueue({
queue,
Expand Down
2 changes: 1 addition & 1 deletion libs/common/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
4 changes: 2 additions & 2 deletions libs/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Common things amongst the cordis infrastructure",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand All @@ -27,7 +27,7 @@
"typescript": "^4.2.2"
},
"dependencies": {
"@cordis/error": "workspace:^0.1.2",
"@cordis/error": "workspace:^0.1.5",
"discord-api-types": "^0.12.1",
"tslib": "^2.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion libs/error/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
2 changes: 1 addition & 1 deletion libs/error/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Package for creating error structures",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand Down
2 changes: 1 addition & 1 deletion libs/gateway/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
12 changes: 6 additions & 6 deletions libs/gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "The cordis gateway to Discord",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand All @@ -31,12 +31,12 @@
"zlib-sync": "^0.1.7"
},
"dependencies": {
"@cordis/bitfield": "workspace:^0.1.2",
"@cordis/common": "workspace:^0.1.2",
"@cordis/error": "workspace:^0.1.2",
"@cordis/queue": "workspace:^0.1.2",
"@cordis/bitfield": "workspace:^0.1.5",
"@cordis/common": "workspace:^0.1.5",
"@cordis/error": "workspace:^0.1.5",
"@cordis/queue": "workspace:^0.1.5",
"@cordis/redis-store": "workspace:^0.1.0",
"@cordis/rest": "workspace:^0.1.2",
"@cordis/rest": "workspace:^0.1.5",
"@cordis/store": "workspace:^0.1.0",
"common-tags": "^1.8.0",
"discord-api-types": "^0.12.1",
Expand Down
1 change: 0 additions & 1 deletion libs/gateway/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { WebsocketConnectionStatus } from './websocket/WebsocketConnection';
export const CordisGatewayError = makeCordisError(
Error,
{
fetchGatewayFail: 'Failed to fetch /gateway/bot',
tokenInvalid: 'The token you passed is invalid',
invalidShard: 'An invalid shard was provided to Discord',
shardingRequired: 'Sharding is required for this bot to connect.',
Expand Down
15 changes: 5 additions & 10 deletions libs/gateway/src/websocket/Cluster.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EventEmitter } from 'events';
import { CordisGatewayError } from '../error';
import {
WebsocketConnection,
WebsocketConnectionStatus,
Expand Down Expand Up @@ -221,14 +220,10 @@ export class Cluster extends EventEmitter {
public async fetchGateway(ignoreCache = false) {
if (this._fetchGatewayCache && !ignoreCache) return this._fetchGatewayCache;

const data = await this.rest.get<RESTGetAPIGatewayBotResult>(Routes.gatewayBot()).catch(() => null);
const data = await this.rest.get<RESTGetAPIGatewayBotResult>(Routes.gatewayBot());

if (data) {
this._fetchGatewayCache = data;
return data;
}

throw new CordisGatewayError('fetchGatewayFail');
this._fetchGatewayCache = data;
return data;
}

/**
Expand Down Expand Up @@ -259,7 +254,7 @@ export class Cluster extends EventEmitter {
}
}

return Promise.allSettled(this.shards.map(shard => shard.connect()));
return Promise.all(this.shards.map(shard => shard.connect()));
}

/**
Expand All @@ -268,6 +263,6 @@ export class Cluster extends EventEmitter {
public async destroy(options: WebsocketConnectionDestroyOptions = { fatal: true }) {
this.user = null;

return Promise.allSettled(this.shards.map(shard => shard.destroy(options)));
return Promise.all(this.shards.map(shard => shard.destroy(options)));
}
}
2 changes: 1 addition & 1 deletion libs/gateway/src/websocket/WebsocketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class WebsocketConnection {
}

private _wrapReject(reject: (reason: any) => void) {
if (this._connectResolve) this.debug('UB: set another _connectReject without calling the previous one.');
if (this._connectReject) this.debug('UB: set another _connectReject without calling the previous one.');
return (reason: any) => {
this._connectReject = null;
reject(reason);
Expand Down
2 changes: 1 addition & 1 deletion libs/queue/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
2 changes: 1 addition & 1 deletion libs/queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Async queues for sequential operations",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand Down
2 changes: 1 addition & 1 deletion libs/redis-store/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
6 changes: 3 additions & 3 deletions libs/redis-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Redis cache implementing the cordis Store",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand All @@ -27,8 +27,8 @@
"typescript": "^4.2.2"
},
"dependencies": {
"@cordis/error": "workspace:^0.1.2",
"@cordis/store": "workspace:^0.1.2",
"@cordis/error": "workspace:^0.1.5",
"@cordis/store": "workspace:^0.1.5",
"tslib": "^2.1.0"
}
}
2 changes: 1 addition & 1 deletion libs/rest/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
6 changes: 3 additions & 3 deletions libs/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Cordis' REST utilities for the Discord API",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand All @@ -29,8 +29,8 @@
"typescript": "^4.2.2"
},
"dependencies": {
"@cordis/common": "workspace:^0.1.2",
"@cordis/error": "workspace:^0.1.2",
"@cordis/common": "workspace:^0.1.5",
"@cordis/error": "workspace:^0.1.5",
"abort-controller": "^3.0.0",
"form-data": "^3.0.1",
"node-fetch": "^2.6.1",
Expand Down
2 changes: 1 addition & 1 deletion libs/routers/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
2 changes: 1 addition & 1 deletion libs/routers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Construct API paths using simple JavaScript property accessing and execute requests with method calls",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand Down
10 changes: 5 additions & 5 deletions libs/routers/src/IRouter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { File, StringRecord } from '@cordis/rest';

export type IRouter = {
get<T>(options?: { query?: StringRecord }): T;
delete<T>(options?: { data?: StringRecord; reason?: string }): T;
patch<T>(options: { data: StringRecord; reason?: string }): T;
put<T>(options: { data: StringRecord; reason?: string }): T;
post<T>(options: { data: StringRecord; reason?: string; files: File[] }): T;
get<T, Q extends StringRecord | string = StringRecord>(options?: { query?: Q }): T;
delete<T, D extends StringRecord = StringRecord>(options?: { data?: D; reason?: string }): T;
patch<T, D extends StringRecord>(options: { data: D; reason?: string }): T;
put<T, D extends StringRecord>(options: { data: D; reason?: string }): T;
post<T, D extends StringRecord>(options: { data: D; reason?: string; files?: File[] }): T;
} & { [key: string]: IRouter };
2 changes: 1 addition & 1 deletion libs/snowflake/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
2 changes: 1 addition & 1 deletion libs/snowflake/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Utility structure for dealing with Discord snowflakes",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand Down
2 changes: 1 addition & 1 deletion libs/store/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/*.test.*
./src
**/src/**
4 changes: 2 additions & 2 deletions libs/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Map-based storage structure",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
"version": "0.1.2",
"version": "0.1.5",
"scripts": {
"lint": "eslint src --ext .ts",
"build": "tsc"
Expand All @@ -26,7 +26,7 @@
"typescript": "^4.2.2"
},
"dependencies": {
"@cordis/error": "workspace:^0.1.2",
"@cordis/error": "workspace:^0.1.5",
"tslib": "^2.1.0"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package",
"name": "cordis",
"version": "0.1.2",
"version": "0.1.5",
"description": "A modular, micros-service based Discord API wrapper",
"scripts": {
"lint": "pnpm recursive run lint --filter @cordis/*",
Expand Down
Loading

0 comments on commit 6153918

Please sign in to comment.