Skip to content

Commit

Permalink
Remove ioredis-mock
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Sep 25, 2024
1 parent 420da4c commit 10841fe
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 698 deletions.
7 changes: 4 additions & 3 deletions dist/TSRedis.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ declare const messageSchema: z.ZodUnion<[z.ZodObject<{
type Message = z.infer<typeof messageSchema>;
export declare class TSRedis {
private redis;
isMocked: boolean;
constructor(options?: RedisOptions & {
mocked: boolean;
});
disconnect(): void;
subscribe(callback: (message: Message) => void): void;
publish(message: Message): Promise<number>;
disconnect(): void | Promise<void>;
subscribe(callback: (message: Message) => void): Promise<void> | undefined;
publish(message: Message): Promise<void> | Promise<number>;
}
export {};
//# sourceMappingURL=TSRedis.d.ts.map
16 changes: 14 additions & 2 deletions dist/TSRedis.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/lib/MahojiClient/Mahoji.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/util/misc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"emoji-regex": "^10.2.1",
"fast-deep-equal": "^3.1.3",
"ioredis": "^5.4.1",
"ioredis-mock": "^8.9.0",
"math-expression-evaluator": "^1.3.14",
"pure-rand": "^6.1.0",
"zod": "3.23.8"
Expand All @@ -32,17 +31,16 @@
"discord.js": "^14.16.2"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@biomejs/biome": "^1.9.2",
"@oldschoolgg/ts-config": "^0.0.1",
"@types/ioredis-mock": "^8.2.5",
"@types/math-expression-evaluator": "^1.2.2",
"@types/node": "^20.14.9",
"@vitest/coverage-v8": "^1.6.0",
"concurrently": "^8.2.2",
"@vitest/coverage-v8": "^2.1.1",
"concurrently": "^9.0.1",
"discord.js": "^14.16.2",
"rimraf": "^5.0.7",
"typescript": "^5.5.3",
"vitest": "^1.6.0"
"typescript": "^5.6.2",
"vitest": "^2.1.1"
},
"engines": {
"node": ">=20.15.0"
Expand Down
8 changes: 6 additions & 2 deletions src/TSRedis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Redis, { type RedisOptions } from 'ioredis';
import MockRedis from 'ioredis-mock';
import { z } from 'zod';

const patronTierChangeMessageSchema = z.object({
Expand All @@ -21,16 +20,20 @@ type Message = z.infer<typeof messageSchema>;
const CHANNEL_ID = 'main';
export class TSRedis {
private redis: Redis;
public isMocked: boolean;

constructor(options: RedisOptions & { mocked: boolean } = { mocked: false }) {
this.redis = options.mocked ? new MockRedis(options) : new Redis(options);
this.redis = options.mocked ? (null as any) : new Redis(options);
this.isMocked = options.mocked;
}

disconnect() {
if (this.isMocked) return Promise.resolve();
return this.redis.disconnect(false);
}

subscribe(callback: (message: Message) => void) {
if (this.isMocked) return Promise.resolve();
this.redis.subscribe(CHANNEL_ID, err => {
if (err) {
console.error('Failed to subscribe: ', err);
Expand All @@ -51,6 +54,7 @@ export class TSRedis {
}

publish(message: Message) {
if (this.isMocked) return Promise.resolve();
const parsedMessage = messageSchema.parse(message);
return this.redis.publish(CHANNEL_ID, JSON.stringify(parsedMessage));
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/MahojiClient/Mahoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function convertCommandOptionToAPIOption(option: CommandOption): any {
case ApplicationCommandOptionType.String: {
return {
...option,
autocomplete: 'autocomplete' in option ?? false
autocomplete: 'autocomplete' in option
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function stringMatches(str: string | number = '', str2: string | number =
}

export function replaceWhitespaceAndUppercase(str: string): string {
return str.replace(/\s/g, "").toUpperCase();
return str.replace(/\s/g, '').toUpperCase();
}

export function roboChimpCLRankQuery(userID: bigint) {
Expand Down
Loading

0 comments on commit 10841fe

Please sign in to comment.