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

Commit 1d16779

Browse files
authored
chore: general cleanup (#86)
* chore: bump all deps * style: update code style and ESLint config * chore: bump to dapi v9
1 parent 1b09363 commit 1d16779

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1628
-1642
lines changed

.eslintrc.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"one-var": "off",
1414
"no-eq-null": "off",
1515
"no-useless-constructor": "off",
16-
"no-negated-condition": "off",
17-
"promise/prefer-await-to-then": "off",
18-
"promise/prefer-await-to-callbacks": "off",
19-
"radix": "off",
20-
"no-multi-assign": "off"
16+
"comma-dangle": "off",
17+
"curly": [
18+
"error",
19+
"all"
20+
],
21+
"no-redeclare": "off"
2122
}
2223
}

libs/bitfield/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
},
3131
"homepage": "https://github.com/cordis-lib/cordis#readme",
3232
"devDependencies": {
33-
"@types/node": "^14.14.44",
34-
"typescript": "^4.2.4"
33+
"@types/node": "^14.17.5",
34+
"typescript": "^4.3.5"
3535
},
3636
"dependencies": {
3737
"@cordis/error": "workspace:^0.3.0",
38-
"tslib": "^2.2.0"
38+
"tslib": "^2.3.0"
3939
}
4040
}

libs/bitfield/src/index.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ test('resolve bit value', () => {
2121
test('bitfield iterator', () => {
2222
const instance = makeTestBitfield(['first', 'second']);
2323
const output = [];
24-
for (const flag of instance) output.push(flag);
24+
for (const flag of instance) {
25+
output.push(flag);
26+
}
2527

2628
expect(output).toStrictEqual(['first', 'second']);
2729
});

libs/bitfield/src/index.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,25 @@ export class BitField<T extends string> {
6060
* @param flags The flags to look for
6161
*/
6262
public static resolve<T extends string>(bit: BitFieldResolvable<T>, flags: Record<T, bigint>): bigint {
63-
if (typeof bit === 'bigint' && bit >= 0n) return bit;
64-
if (bit instanceof BitField) return bit.bits;
63+
if (typeof bit === 'bigint' && bit >= 0n) {
64+
return bit;
65+
}
66+
67+
if (bit instanceof BitField) {
68+
return bit.bits;
69+
}
6570

6671
if (typeof bit === 'string') {
6772
const num = flags[bit];
6873
/* istanbul ignore else */
69-
if (num) return num;
74+
if (num) {
75+
return num;
76+
}
7077
}
7178

72-
if (Array.isArray(bit)) return bit.map(p => this.resolve(p, flags)).reduce((prev, p) => prev | p, 0n);
79+
if (Array.isArray(bit)) {
80+
return bit.map(p => this.resolve(p, flags)).reduce((prev, p) => prev | p, 0n);
81+
}
7382

7483
throw new BitfieldRangeError('bitfieldInvalid');
7584
}
@@ -150,7 +159,10 @@ export class BitField<T extends string> {
150159
* @param bit Bits to check for
151160
*/
152161
public has(bit: BitFieldResolvable<T>): boolean {
153-
if (Array.isArray(bit)) return bit.every(b => this.has(b));
162+
if (Array.isArray(bit)) {
163+
return bit.every(b => this.has(b));
164+
}
165+
154166
return (this.bits & this.resolve(bit)) !== 0n;
155167
}
156168

@@ -160,7 +172,10 @@ export class BitField<T extends string> {
160172
* @returns An array of the missing bits
161173
*/
162174
public missing(bit: BitFieldResolvable<T>) {
163-
if (!Array.isArray(bit)) bit = new this.constructor(this.flags, bit).toArray();
175+
if (!Array.isArray(bit)) {
176+
bit = new this.constructor(this.flags, bit).toArray();
177+
}
178+
164179
return bit.filter(p => !this.has(p));
165180
}
166181

@@ -170,10 +185,15 @@ export class BitField<T extends string> {
170185
*/
171186
public add(...bits: BitFieldResolvable<T>[]) {
172187
let total = 0n;
173-
for (const bit of bits) total |= this.resolve(bit);
188+
for (const bit of bits) {
189+
total |= this.resolve(bit);
190+
}
174191

175192
/* istanbul ignore if */
176-
if (Object.isFrozen(this)) return new this.constructor(this.flags, this.bits | total);
193+
if (Object.isFrozen(this)) {
194+
return new this.constructor(this.flags, this.bits | total);
195+
}
196+
177197
this.bits |= total;
178198
return this;
179199
}
@@ -184,10 +204,15 @@ export class BitField<T extends string> {
184204
*/
185205
public remove(...bits: BitFieldResolvable<T>[]) {
186206
let total = 0n;
187-
for (const bit of bits) total |= this.resolve(bit);
207+
for (const bit of bits) {
208+
total |= this.resolve(bit);
209+
}
188210

189211
/* istanbul ignore if */
190-
if (Object.isFrozen(this)) return new this.constructor(this.flags, this.bits & ~total);
212+
if (Object.isFrozen(this)) {
213+
return new this.constructor(this.flags, this.bits & ~total);
214+
}
215+
191216
this.bits &= ~total;
192217
return this;
193218
}
@@ -211,7 +236,10 @@ export class BitField<T extends string> {
211236
*/
212237
public serialize(): Record<T, boolean> {
213238
const serialized: Record<string, boolean> = {};
214-
for (const [flag, bit] of Object.entries(this.flags)) serialized[flag] = this.has(bit as bigint);
239+
for (const [flag, bit] of Object.entries(this.flags)) {
240+
serialized[flag] = this.has(bit as bigint);
241+
}
242+
215243
return serialized;
216244
}
217245
}

libs/brokers/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
"homepage": "https://github.com/cordis-lib/cordis#readme",
3232
"devDependencies": {
3333
"@types/amqplib": "^0.5.17",
34-
"@types/node": "^14.14.44",
35-
"typescript": "^4.2.4"
34+
"@types/node": "^14.17.5",
35+
"typescript": "^4.3.5"
3636
},
3737
"dependencies": {
3838
"@cordis/common": "workspace:^0.3.0",
3939
"@cordis/error": "workspace:^0.3.0",
40-
"@msgpack/msgpack": "^2.6.3",
40+
"@msgpack/msgpack": "^2.7.0",
4141
"amqplib": "^0.6.0",
42-
"tslib": "^2.2.0"
42+
"tslib": "^2.3.0"
4343
}
4444
}

libs/brokers/src/brokers/Broker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export class Broker extends EventEmitter {
4545
*/
4646
public async destroy() {
4747
try {
48-
for (const tag of this.consumers) await this.channel.cancel(tag);
48+
const promises = [...this.consumers].map(tag => this.channel.cancel(tag));
49+
await Promise.allSettled(promises);
4950
} catch {}
5051

5152
this.consumers.clear();

libs/brokers/src/brokers/BrokerUtil.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ export class BrokerUtil {
113113
// eslint-disable-next-line @typescript-eslint/no-misused-promises
114114
async msg => {
115115
/* istanbul ignore next */
116-
if (!msg) return null;
116+
if (!msg) {
117+
return null;
118+
}
119+
117120
try {
118121
await cb(decode(msg.content) as T, msg);
119122
} catch (e) {
@@ -164,7 +167,9 @@ export class BrokerUtil {
164167
const { msg, ...content } = options;
165168

166169
const missing = getMissingProps(msg.properties, ['correlationId', 'replyTo']);
167-
if (missing.length) throw new CordisBrokerTypeError('missingProperties', missing);
170+
if (missing.length) {
171+
throw new CordisBrokerTypeError('missingProperties', missing);
172+
}
168173

169174
return this.sendToQueue({
170175
to: msg.properties.replyTo,

libs/brokers/src/brokers/pubsub/PubSubClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export class PubSubClient<T> extends Broker {
4040
: await this.channel.assertQueue(options.name, { durable: true }).then(d => d.queue);
4141

4242
const queue = fanout ? await this.channel.assertQueue('', { exclusive: true }).then(d => d.queue) : name;
43-
if (fanout) await this.channel.bindQueue(queue, name, '');
43+
if (fanout) {
44+
await this.channel.bindQueue(queue, name, '');
45+
}
4446

4547
await this.util.consumeQueue({
4648
queue,

libs/brokers/src/brokers/pubsub/PubSubServer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export class PubSubServer<T> extends Broker {
4747
* @param options Message specific options
4848
*/
4949
public publish(content: T, options?: amqp.Options.Publish) {
50-
if (!this.name) throw new CordisBrokerError('brokerNotInit');
50+
if (!this.name) {
51+
throw new CordisBrokerError('brokerNotInit');
52+
}
53+
5154
return this.fanout
5255
? this.util.sendToExchange({ to: this.name, content, key: '', options })
5356
: this.util.sendToQueue({ to: this.name, content, options });

libs/brokers/src/brokers/routing/RoutingClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export class RoutingClient<K extends string, T extends Record<K, any>> extends B
7878
queue,
7979
cb: (content: { type: K; data: T[K] }, { properties: { timestamp } }) => {
8080
// For whatever reason amqplib types all properties as any ONLY when recieving?
81-
if ((timestamp as number) + maxMessageAge < Date.now()) return;
81+
if ((timestamp as number) + maxMessageAge < Date.now()) {
82+
return;
83+
}
8284

8385
this.emit(content.type, content.data);
8486
},

0 commit comments

Comments
 (0)