From 93016d171bbe529f83bf7c4b413f02b5020d157c Mon Sep 17 00:00:00 2001 From: ogzhanolguncu Date: Thu, 1 Feb 2024 11:51:08 +0300 Subject: [PATCH 1/5] Add generics to jsonMGet and jsonGet --- pkg/commands/json_mget.ts | 5 +-- pkg/redis.ts | 88 +++++++++++++-------------------------- 2 files changed, 31 insertions(+), 62 deletions(-) diff --git a/pkg/commands/json_mget.ts b/pkg/commands/json_mget.ts index 09b4ec10..b18b1aea 100644 --- a/pkg/commands/json_mget.ts +++ b/pkg/commands/json_mget.ts @@ -3,10 +3,7 @@ import { Command, CommandOptions } from "./command"; /** * @see https://redis.io/commands/json.mget */ -export class JsonMGetCommand)[],> extends Command< - TData, - TData -> { +export class JsonMGetCommand extends Command { constructor(cmd: [keys: string[], path: string], opts?: CommandOptions) { super(["JSON.MGET", ...cmd[0], cmd[1]], opts); } diff --git a/pkg/redis.ts b/pkg/redis.ts index 518bb5b5..a891f10d 100644 --- a/pkg/redis.ts +++ b/pkg/redis.ts @@ -300,14 +300,14 @@ export class Redis { /** * @see https://redis.io/commands/json.get */ - get: (...args: CommandArgs) => - new JsonGetCommand(args, this.opts).exec(this.client), + get: (...args: CommandArgs) => + new JsonGetCommand(args, this.opts).exec(this.client), /** * @see https://redis.io/commands/json.mget */ - mget: (...args: CommandArgs) => - new JsonMGetCommand(args, this.opts).exec(this.client), + mget: (...args: CommandArgs) => + new JsonMGetCommand(args, this.opts).exec(this.client), /** * @see https://redis.io/commands/json.numincrby @@ -376,14 +376,11 @@ export class Redis { use = ( middleware: ( r: UpstashRequest, - next: ( - req: UpstashRequest - ) => Promise> - ) => Promise> + next: (req: UpstashRequest) => Promise>, + ) => Promise>, ) => { const makeRequest = this.client.request.bind(this.client); - this.client.request = (req: UpstashRequest) => - middleware(req, makeRequest) as any; + this.client.request = (req: UpstashRequest) => middleware(req, makeRequest) as any; }; /** @@ -462,10 +459,9 @@ export class Redis { sourceKey: string, ...sourceKeys: string[] ) => - new BitOpCommand( - [op as any, destinationKey, sourceKey, ...sourceKeys], - this.opts - ).exec(this.client); + new BitOpCommand([op as any, destinationKey, sourceKey, ...sourceKeys], this.opts).exec( + this.client, + ); /** * @see https://redis.io/commands/bitpos @@ -602,9 +598,8 @@ export class Redis { /** * @see https://redis.io/commands/hgetall */ - hgetall = >( - ...args: CommandArgs - ) => new HGetAllCommand(args, this.opts).exec(this.client); + hgetall = >(...args: CommandArgs) => + new HGetAllCommand(args, this.opts).exec(this.client); /** * @see https://redis.io/commands/hincrby @@ -633,9 +628,8 @@ export class Redis { /** * @see https://redis.io/commands/hmget */ - hmget = >( - ...args: CommandArgs - ) => new HMGetCommand(args, this.opts).exec(this.client); + hmget = >(...args: CommandArgs) => + new HMGetCommand(args, this.opts).exec(this.client); /** * @see https://redis.io/commands/hmset @@ -652,17 +646,13 @@ export class Redis { >( key: string, count: number, - withValues: boolean + withValues: boolean, ): Promise>; } = >( key: string, count?: number, - withValues?: boolean - ) => - new HRandFieldCommand( - [key, count, withValues] as any, - this.opts - ).exec(this.client); + withValues?: boolean, + ) => new HRandFieldCommand([key, count, withValues] as any, this.opts).exec(this.client); /** * @see https://redis.io/commands/hscan @@ -727,15 +717,8 @@ export class Redis { /** * @see https://redis.io/commands/linsert */ - linsert = ( - key: string, - direction: "before" | "after", - pivot: TData, - value: TData - ) => - new LInsertCommand([key, direction, pivot, value], this.opts).exec( - this.client - ); + linsert = (key: string, direction: "before" | "after", pivot: TData, value: TData) => + new LInsertCommand([key, direction, pivot, value], this.opts).exec(this.client); /** * @see https://redis.io/commands/llen @@ -1009,24 +992,19 @@ export class Redis { * @see https://redis.io/commands/smismember */ smismember = (key: string, members: TMembers) => - new SMIsMemberCommand([key, members], this.opts).exec( - this.client - ); + new SMIsMemberCommand([key, members], this.opts).exec(this.client); /** * @see https://redis.io/commands/smembers */ - smembers = ( - ...args: CommandArgs - ) => new SMembersCommand(args, this.opts).exec(this.client); + smembers = (...args: CommandArgs) => + new SMembersCommand(args, this.opts).exec(this.client); /** * @see https://redis.io/commands/smove */ smove = (source: string, destination: string, member: TData) => - new SMoveCommand([source, destination, member], this.opts).exec( - this.client - ); + new SMoveCommand([source, destination, member], this.opts).exec(this.client); /** * @see https://redis.io/commands/spop @@ -1188,27 +1166,23 @@ export class Redis { */ zadd = ( ...args: - | [ - key: string, - scoreMember: ScoreMember, - ...scoreMemberPairs: ScoreMember[] - ] + | [key: string, scoreMember: ScoreMember, ...scoreMemberPairs: ScoreMember[]] | [ key: string, opts: ZAddCommandOptions, - ...scoreMemberPairs: [ScoreMember, ...ScoreMember[]] + ...scoreMemberPairs: [ScoreMember, ...ScoreMember[]], ] ) => { if ("score" in args[1]) { return new ZAddCommand( [args[0], args[1] as ScoreMember, ...(args.slice(2) as any)], - this.opts + this.opts, ).exec(this.client); } return new ZAddCommand( [args[0], args[1] as any, ...(args.slice(2) as any)], - this.opts + this.opts, ).exec(this.client); }; /** @@ -1233,9 +1207,7 @@ export class Redis { * @see https://redis.io/commands/zincrby */ zincrby = (key: string, increment: number, member: TData) => - new ZIncrByCommand([key, increment, member], this.opts).exec( - this.client - ); + new ZIncrByCommand([key, increment, member], this.opts).exec(this.client); /** * @see https://redis.io/commands/zinterstore @@ -1277,13 +1249,13 @@ export class Redis { key: string, min: `(${string}` | `[${string}` | "-" | "+", max: `(${string}` | `[${string}` | "-" | "+", - opts: { byLex: true } & ZRangeCommandOptions + opts: { byLex: true } & ZRangeCommandOptions, ] | [ key: string, min: number | `(${number}` | "-inf" | "+inf", max: number | `(${number}` | "-inf" | "+inf", - opts: { byScore: true } & ZRangeCommandOptions + opts: { byScore: true } & ZRangeCommandOptions, ] ) => new ZRangeCommand(args as any, this.opts).exec(this.client); From db8c871992c6a15ce332f53770b3840ab390a31b Mon Sep 17 00:00:00 2001 From: ogzhanolguncu Date: Thu, 1 Feb 2024 11:51:22 +0300 Subject: [PATCH 2/5] Format all files --- pkg/commands/expire.test.ts | 6 +- pkg/commands/expire.ts | 2 +- pkg/commands/pfadd.test.ts | 29 ++----- pkg/commands/pfadd.ts | 5 +- pkg/commands/pfcount.test.ts | 5 +- pkg/commands/pfcount.ts | 5 +- pkg/commands/pfmerge.test.ts | 18 ++--- pkg/commands/pfmerge.ts | 2 +- pkg/commands/xack.test.ts | 59 ++++---------- pkg/commands/xack.ts | 2 +- pkg/commands/xautoclaim.test.ts | 67 ++++------------ pkg/commands/xautoclaim.ts | 9 +-- pkg/commands/xclaim.test.ts | 60 +++----------- pkg/commands/xclaim.ts | 9 +-- pkg/commands/xdel.test.ts | 40 +++------- pkg/commands/xdel.ts | 2 +- pkg/commands/xgroup.test.ts | 6 +- pkg/commands/xgroup.ts | 9 ++- pkg/commands/xinfo.test.ts | 41 +++------- pkg/commands/xinfo.ts | 2 +- pkg/commands/xlen.test.ts | 18 +---- pkg/commands/xpending.test.ts | 35 ++------- pkg/commands/xpending.ts | 6 +- pkg/commands/xrange.test.ts | 6 +- pkg/commands/xread.test.ts | 40 ++++------ pkg/commands/xread.ts | 21 ++--- pkg/commands/xreadgroup.test.ts | 90 ++++++--------------- pkg/commands/xreadgroup.ts | 24 ++---- pkg/commands/xrevrange.test.ts | 32 +++----- pkg/commands/xrevrange.ts | 13 +--- pkg/commands/xtrim.test.ts | 40 ++++------ pkg/commands/xtrim.ts | 14 +--- pkg/commands/zadd.test.ts | 134 +++++++++----------------------- pkg/commands/zadd.ts | 10 +-- pkg/http.ts | 40 +++------- pkg/pipeline.ts | 106 +++++++------------------ pkg/test-utils.ts | 5 +- 37 files changed, 268 insertions(+), 744 deletions(-) diff --git a/pkg/commands/expire.test.ts b/pkg/commands/expire.test.ts index 82a0c584..81029642 100644 --- a/pkg/commands/expire.test.ts +++ b/pkg/commands/expire.test.ts @@ -56,7 +56,7 @@ describe("XX", () => { const res2 = await new GetCommand([key]).exec(client); expect(res2).toEqual(null); }, - { timeout: 10000 } + { timeout: 10000 }, ); test("should not set expiry when the key does not have an existing expiry", async () => { @@ -81,7 +81,7 @@ describe("GT", () => { const res2 = await new GetCommand([key]).exec(client); expect(res2).toEqual(null); }, - { timeout: 10000 } + { timeout: 10000 }, ); test("should not set expiry when the new expiry is not greater than current one", async () => { @@ -106,7 +106,7 @@ describe("LT", () => { const res2 = await new GetCommand([key]).exec(client); expect(res2).toEqual(null); }, - { timeout: 10000 } + { timeout: 10000 }, ); test("should not set expiry when the new expiry is not less than current one", async () => { diff --git a/pkg/commands/expire.ts b/pkg/commands/expire.ts index 13ff821b..93dca034 100644 --- a/pkg/commands/expire.ts +++ b/pkg/commands/expire.ts @@ -4,7 +4,7 @@ type ExpireOptions = "NX" | "nx" | "XX" | "xx" | "GT" | "gt" | "LT" | "lt"; export class ExpireCommand extends Command<"0" | "1", 0 | 1> { constructor( cmd: [key: string, seconds: number, option?: ExpireOptions], - opts?: CommandOptions<"0" | "1", 0 | 1> + opts?: CommandOptions<"0" | "1", 0 | 1>, ) { super(["expire", ...cmd], opts); } diff --git a/pkg/commands/pfadd.test.ts b/pkg/commands/pfadd.test.ts index 1e35e6ee..f7adb78f 100644 --- a/pkg/commands/pfadd.test.ts +++ b/pkg/commands/pfadd.test.ts @@ -1,4 +1,4 @@ -import { newHttpClient, randomID, keygen } from "../test-utils.ts"; +import { keygen, newHttpClient, randomID } from "../test-utils.ts"; import { afterEach, describe, expect, test } from "bun:test"; @@ -18,9 +18,7 @@ describe("adding multiple elements at once", () => { const value2 = randomID(); const value3 = randomID(); - const res = await new PfAddCommand([key, value1, value2, value3]).exec( - client - ); + const res = await new PfAddCommand([key, value1, value2, value3]).exec(client); expect(res).toBe(1); const res2 = await new PfCountCommand([key]).exec(client); @@ -35,13 +33,7 @@ describe("inserting the same element multiple times", () => { const value2 = randomID(); test("modified succesfully and returned correct cardinality for repeated elements", async () => { - const resInsert = await new PfAddCommand([ - key, - value1, - value1, - value2, - value2, - ]).exec(client); + const resInsert = await new PfAddCommand([key, value1, value1, value2, value2]).exec(client); expect(resInsert).toBe(1); const resCount = await new PfCountCommand([key]).exec(client); @@ -57,17 +49,10 @@ describe("adding the same strings on different lines doesn't modify the HLL", () const value3 = randomID(); test("modifies the HLL on the first insertion of strings", async () => { - const resAdd = await new PfAddCommand([key, value1, value2, value3]).exec( - client - ); + const resAdd = await new PfAddCommand([key, value1, value2, value3]).exec(client); expect(resAdd).toBe(1); - const resAddDuplicate = await new PfAddCommand([ - key, - value1, - value2, - value3, - ]).exec(client); + const resAddDuplicate = await new PfAddCommand([key, value1, value2, value3]).exec(client); expect(resAddDuplicate).toBe(0); }); }); @@ -86,9 +71,7 @@ describe("merge HLLs with overlapping values and count", () => { const resAdd = await new PfAddCommand([key2, value3, value4]).exec(client); expect(resAdd).toBe(1); - const resMerge = await new PfMergeCommand([mergedKey, key1, key2]).exec( - client - ); + const resMerge = await new PfMergeCommand([mergedKey, key1, key2]).exec(client); expect(resMerge).toBe("OK"); const resCount = await new PfCountCommand([mergedKey]).exec(client); diff --git a/pkg/commands/pfadd.ts b/pkg/commands/pfadd.ts index f5d2faea..c01e77e4 100644 --- a/pkg/commands/pfadd.ts +++ b/pkg/commands/pfadd.ts @@ -4,10 +4,7 @@ import { Command, CommandOptions } from "./command.ts"; * @see https://redis.io/commands/pfadd */ export class PfAddCommand extends Command { - constructor( - cmd: [string, ...(TData[] | TData[])], - opts?: CommandOptions - ) { + constructor(cmd: [string, ...(TData[] | TData[])], opts?: CommandOptions) { super(["pfadd", ...cmd], opts); } } diff --git a/pkg/commands/pfcount.test.ts b/pkg/commands/pfcount.test.ts index e9029b0d..1014c7f5 100644 --- a/pkg/commands/pfcount.test.ts +++ b/pkg/commands/pfcount.test.ts @@ -1,5 +1,5 @@ -import { newHttpClient, keygen, randomID } from "../test-utils.ts"; -import { afterEach, expect, test, describe } from "bun:test"; +import { afterEach, describe, expect, test } from "bun:test"; +import { keygen, newHttpClient, randomID } from "../test-utils.ts"; import { PfAddCommand } from "./pfadd.ts"; import { PfCountCommand } from "./pfcount.ts"; @@ -30,7 +30,6 @@ describe("multiple keys cardinality check", () => { const value2 = randomID(); const value3 = randomID(); const value4 = randomID(); - const value5 = randomID(); test("insert unique strings into two HLLs", async () => { await new PfAddCommand([key1, value1, value2]).exec(client); diff --git a/pkg/commands/pfcount.ts b/pkg/commands/pfcount.ts index ff148e38..99a8e3f3 100644 --- a/pkg/commands/pfcount.ts +++ b/pkg/commands/pfcount.ts @@ -4,10 +4,7 @@ import { Command, CommandOptions } from "./command.ts"; * @see https://redis.io/commands/pfcount */ export class PfCountCommand extends Command { - constructor( - cmd: [string, ...(string[] | string[])], - opts?: CommandOptions - ) { + constructor(cmd: [string, ...(string[] | string[])], opts?: CommandOptions) { super(["pfcount", ...cmd], opts); } } diff --git a/pkg/commands/pfmerge.test.ts b/pkg/commands/pfmerge.test.ts index 92ae9fcd..e8b39880 100644 --- a/pkg/commands/pfmerge.test.ts +++ b/pkg/commands/pfmerge.test.ts @@ -1,6 +1,6 @@ -import { newHttpClient, randomID, keygen } from "../test-utils.ts"; +import { keygen, newHttpClient, randomID } from "../test-utils.ts"; -import { afterEach, expect, test, describe } from "bun:test"; +import { afterEach, describe, expect, test } from "bun:test"; import { PfAddCommand } from "./pfadd.ts"; import { PfCountCommand } from "./pfcount.ts"; @@ -26,9 +26,7 @@ describe("merge HLLs with distinct values and count", () => { const resAdd = await new PfAddCommand([key2, value3, value4]).exec(client); expect(resAdd).toBe(1); - const resMerge = await new PfMergeCommand([mergedKey, key1, key2]).exec( - client - ); + const resMerge = await new PfMergeCommand([mergedKey, key1, key2]).exec(client); expect(resMerge).toBe("OK"); const resCount = await new PfCountCommand([mergedKey]).exec(client); @@ -46,9 +44,7 @@ describe("merge HLL with an empty HLL", () => { const resAdd = await new PfAddCommand([key, value1]).exec(client); expect(resAdd).toBe(1); - const resMerge = await new PfMergeCommand([mergedKey, key, emptyKey]).exec( - client - ); + const resMerge = await new PfMergeCommand([mergedKey, key, emptyKey]).exec(client); expect(resMerge).toBe("OK"); const resCount = await new PfCountCommand([mergedKey]).exec(client); @@ -62,11 +58,7 @@ describe("merge two empty HLLs", () => { const mergedKey = newKey(); test("merge two empty HLLs", async () => { - const resMerge = await new PfMergeCommand([ - mergedKey, - emptyKey1, - emptyKey2, - ]).exec(client); + const resMerge = await new PfMergeCommand([mergedKey, emptyKey1, emptyKey2]).exec(client); expect(resMerge).toBe("OK"); const resCount = await new PfCountCommand([mergedKey]).exec(client); diff --git a/pkg/commands/pfmerge.ts b/pkg/commands/pfmerge.ts index d8e2555c..c487173f 100644 --- a/pkg/commands/pfmerge.ts +++ b/pkg/commands/pfmerge.ts @@ -6,7 +6,7 @@ import { Command, CommandOptions } from "./command.ts"; export class PfMergeCommand extends Command<"OK", "OK"> { constructor( cmd: [destination_key: string, ...(string[] | string[])], - opts?: CommandOptions<"OK", "OK"> + opts?: CommandOptions<"OK", "OK">, ) { super(["pfmerge", ...cmd], opts); } diff --git a/pkg/commands/xack.test.ts b/pkg/commands/xack.test.ts index f034b067..67708d28 100644 --- a/pkg/commands/xack.test.ts +++ b/pkg/commands/xack.test.ts @@ -1,12 +1,9 @@ import { addNewItemToStream, keygen, newHttpClient } from "../test-utils"; import { afterAll, describe, expect, test } from "bun:test"; -import { XAddCommand } from "./xadd"; -import { XDelCommand } from "./xdel"; -import { XRangeCommand } from "./xrange"; +import { XAckCommand } from "./xack"; import { XGroupCommand } from "./xgroup"; import { XReadGroupCommand } from "./xreadgroup"; -import { XAckCommand } from "./xack"; const client = newHttpClient(); @@ -19,33 +16,16 @@ describe("XACK", () => { const group = newKey(); const consumer = newKey(); - const { streamId: streamId1 } = await addNewItemToStream( - streamKey1, - client - ); - const { streamId: streamId2 } = await addNewItemToStream( - streamKey1, - client - ); + const { streamId: streamId1 } = await addNewItemToStream(streamKey1, client); + const { streamId: streamId2 } = await addNewItemToStream(streamKey1, client); - await new XGroupCommand([ - streamKey1, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey1, { type: "CREATE", group, id: "0" }]).exec(client); - (await new XReadGroupCommand([ - group, - consumer, - streamKey1, - ">", - { count: 2 }, - ]).exec(client)) as string[]; + (await new XReadGroupCommand([group, consumer, streamKey1, ">", { count: 2 }]).exec( + client, + )) as string[]; - const res = await new XAckCommand([ - streamKey1, - group, - [streamId1, streamId2], - ]).exec(client); + const res = await new XAckCommand([streamKey1, group, [streamId1, streamId2]]).exec(client); expect(res).toEqual(2); }); @@ -54,31 +34,20 @@ describe("XACK", () => { const group = newKey(); const consumer = newKey(); - const { streamId: streamId1 } = await addNewItemToStream( - streamKey1, - client - ); + const { streamId: streamId1 } = await addNewItemToStream(streamKey1, client); await new XGroupCommand([ streamKey1, { type: "CREATE", group, id: "0", options: { MKSTREAM: true } }, ]).exec(client); - (await new XReadGroupCommand([ - group, - consumer, - streamKey1, - ">", - { count: 2 }, - ]).exec(client)) as string[]; + (await new XReadGroupCommand([group, consumer, streamKey1, ">", { count: 2 }]).exec( + client, + )) as string[]; - const res = await new XAckCommand([streamKey1, group, streamId1]).exec( - client - ); + const res = await new XAckCommand([streamKey1, group, streamId1]).exec(client); expect(res).toEqual(1); - const res1 = await new XAckCommand([streamKey1, group, streamId1]).exec( - client - ); + const res1 = await new XAckCommand([streamKey1, group, streamId1]).exec(client); expect(res1).toEqual(0); }); }); diff --git a/pkg/commands/xack.ts b/pkg/commands/xack.ts index c17ed5a0..ad7c79fc 100644 --- a/pkg/commands/xack.ts +++ b/pkg/commands/xack.ts @@ -6,7 +6,7 @@ import { Command, CommandOptions } from "./command"; export class XAckCommand extends Command { constructor( [key, group, id]: [key: string, group: string, id: string | string[]], - opts?: CommandOptions + opts?: CommandOptions, ) { const ids = Array.isArray(id) ? [...id] : [id]; super(["XACK", key, group, ...ids], opts); diff --git a/pkg/commands/xautoclaim.test.ts b/pkg/commands/xautoclaim.test.ts index 2cc65f11..7fd3e94b 100644 --- a/pkg/commands/xautoclaim.test.ts +++ b/pkg/commands/xautoclaim.test.ts @@ -1,7 +1,7 @@ import { addNewItemToStream, keygen, newHttpClient } from "../test-utils"; -import { sleep } from "bun"; import { afterAll, describe, expect, test } from "bun:test"; +import { sleep } from "bun"; import { XAutoClaim } from "./xautoclaim"; import { XGroupCommand } from "./xgroup"; import { XReadGroupCommand } from "./xreadgroup"; @@ -21,27 +21,13 @@ describe("XCLAIM", () => { await addNewItemToStream(streamKey, client); await addNewItemToStream(streamKey, client); - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - await new XReadGroupCommand([ - group, - consumer1, - [streamKey], - [">"], - { count: 2 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer1, [streamKey], [">"], { count: 2 }]).exec(client); - const res = (await new XAutoClaim([ - streamKey, - group, - consumer2, - 10, - "0-0", - { count: 1 }, - ]).exec(client)) as string[]; + const res = (await new XAutoClaim([streamKey, group, consumer2, 10, "0-0", { count: 1 }]).exec( + client, + )) as string[]; expect(res).toBeInstanceOf(Array); }); @@ -54,18 +40,9 @@ describe("XCLAIM", () => { await addNewItemToStream(streamKey, client); await addNewItemToStream(streamKey, client); - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - await new XReadGroupCommand([ - group, - consumer1, - [streamKey], - [">"], - { count: 2 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer1, [streamKey], [">"], { count: 2 }]).exec(client); await sleep(2000); const res = (await new XAutoClaim([ streamKey, @@ -87,18 +64,9 @@ describe("XCLAIM", () => { await addNewItemToStream(streamKey, client); const { streamId } = await addNewItemToStream(streamKey, client); - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - await new XReadGroupCommand([ - group, - consumer1, - [streamKey], - [">"], - { count: 2 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer1, [streamKey], [">"], { count: 2 }]).exec(client); await sleep(2000); const xclaim = (await new XAutoClaim([ streamKey, @@ -118,20 +86,11 @@ describe("XCLAIM", () => { const consumer2 = newKey(); await addNewItemToStream(streamKey, client); - const { streamId } = await addNewItemToStream(streamKey, client); + await addNewItemToStream(streamKey, client); - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - await new XReadGroupCommand([ - group, - consumer1, - [streamKey], - [">"], - { count: 2 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer1, [streamKey], [">"], { count: 2 }]).exec(client); const xclaim = (await new XAutoClaim([ streamKey, diff --git a/pkg/commands/xautoclaim.ts b/pkg/commands/xautoclaim.ts index 9472e352..47acb86e 100644 --- a/pkg/commands/xautoclaim.ts +++ b/pkg/commands/xautoclaim.ts @@ -11,9 +11,9 @@ export class XAutoClaim extends Command { consumer: string, minIdleTime: number, start: string, - options?: { count?: number; justId?: boolean } + options?: { count?: number; justId?: boolean }, ], - opts?: CommandOptions + opts?: CommandOptions, ) { const commands: unknown[] = []; @@ -24,9 +24,6 @@ export class XAutoClaim extends Command { if (options?.justId) { commands.push("JUSTID"); } - super( - ["XAUTOCLAIM", key, group, consumer, minIdleTime, start, ...commands], - opts - ); + super(["XAUTOCLAIM", key, group, consumer, minIdleTime, start, ...commands], opts); } } diff --git a/pkg/commands/xclaim.test.ts b/pkg/commands/xclaim.test.ts index 70a2a160..835c5068 100644 --- a/pkg/commands/xclaim.test.ts +++ b/pkg/commands/xclaim.test.ts @@ -22,42 +22,17 @@ describe("XCLAIM", () => { const { streamId: streamId2 } = await addNewItemToStream(streamKey, client); await addNewItemToStream(streamKey, client); - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - await new XReadGroupCommand([ - group, - consumer1, - [streamKey], - [">"], - { count: 1 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer1, [streamKey], [">"], { count: 1 }]).exec(client); - await new XReadGroupCommand([ - group, - consumer2, - [streamKey], - [">"], - { count: 1 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer2, [streamKey], [">"], { count: 1 }]).exec(client); - await new XReadGroupCommand([ - group, - consumer3, - [streamKey], - [">"], - { count: 1 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer3, [streamKey], [">"], { count: 1 }]).exec(client); - const res = (await new XClaimCommand([ - streamKey, - group, - consumer3, - 100, - streamId2, - ]).exec(client)) as string[]; + const res = (await new XClaimCommand([streamKey, group, consumer3, 100, streamId2]).exec( + client, + )) as string[]; expect(res).toBeInstanceOf(Array); expect(res[0][0]).toBe(streamId2); @@ -73,26 +48,11 @@ describe("XCLAIM", () => { await addNewItemToStream(streamKey, client); await addNewItemToStream(streamKey, client); - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - await new XReadGroupCommand([ - group, - consumer1, - [streamKey], - [">"], - { count: 1 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer1, [streamKey], [">"], { count: 1 }]).exec(client); - await new XReadGroupCommand([ - group, - consumer3, - [streamKey], - [">"], - { count: 1 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer3, [streamKey], [">"], { count: 1 }]).exec(client); const res = (await new XClaimCommand([ streamKey, diff --git a/pkg/commands/xclaim.ts b/pkg/commands/xclaim.ts index 40a2e7ec..c208441f 100644 --- a/pkg/commands/xclaim.ts +++ b/pkg/commands/xclaim.ts @@ -18,9 +18,9 @@ export class XClaimCommand extends Command { force?: boolean; justId?: boolean; lastId?: number; - } + }, ], - opts?: CommandOptions + opts?: CommandOptions, ) { const ids = Array.isArray(id) ? [...id] : [id]; const commands: unknown[] = []; @@ -49,9 +49,6 @@ export class XClaimCommand extends Command { commands.push("LASTID", options.lastId); } - super( - ["XCLAIM", key, group, consumer, minIdleTime, ...ids, ...commands], - opts - ); + super(["XCLAIM", key, group, consumer, minIdleTime, ...ids, ...commands], opts); } } diff --git a/pkg/commands/xdel.test.ts b/pkg/commands/xdel.test.ts index e07b656c..380e1a33 100644 --- a/pkg/commands/xdel.test.ts +++ b/pkg/commands/xdel.test.ts @@ -13,15 +13,11 @@ afterAll(cleanup); describe("XDEL", () => { test("should delete one item from the stream", async () => { const key = newKey(); - await new XAddCommand([key, "*", { name: "Jane", surname: "Austen" }]).exec( - client - ); + await new XAddCommand([key, "*", { name: "Jane", surname: "Austen" }]).exec(client); - const res = await new XAddCommand([ - key, - "*", - { name: "Toni", surname: "Morrison" }, - ]).exec(client); + const res = await new XAddCommand([key, "*", { name: "Toni", surname: "Morrison" }]).exec( + client, + ); const xdelRes = await new XDelCommand([key, res]).exec(client); const xrangeRes = await new XRangeCommand([key, "-", "+", 1]).exec(client); @@ -33,29 +29,17 @@ describe("XDEL", () => { test("should delete multiple items from the stream", async () => { const key = newKey(); - const id1 = await new XAddCommand([ - key, - "*", - { name: "Jane", surname: "Austen" }, - ]).exec(client); + const id1 = await new XAddCommand([key, "*", { name: "Jane", surname: "Austen" }]).exec(client); - const id2 = await new XAddCommand([ - key, - "*", - { name: "Toni", surname: "Morrison" }, - ]).exec(client); + const id2 = await new XAddCommand([key, "*", { name: "Toni", surname: "Morrison" }]).exec( + client, + ); - const id3 = await new XAddCommand([ - key, - "*", - { name: "Agatha", surname: "Christie" }, - ]).exec(client); + const id3 = await new XAddCommand([key, "*", { name: "Agatha", surname: "Christie" }]).exec( + client, + ); - await new XAddCommand([ - key, - "*", - { name: "Ngozi", surname: "Adichie" }, - ]).exec(client); + await new XAddCommand([key, "*", { name: "Ngozi", surname: "Adichie" }]).exec(client); const xdelRes = await new XDelCommand([key, [id1, id2, id3]]).exec(client); const xrangeRes = await new XRangeCommand([key, "-", "+", 1]).exec(client); diff --git a/pkg/commands/xdel.ts b/pkg/commands/xdel.ts index c9e6fd87..f022052d 100644 --- a/pkg/commands/xdel.ts +++ b/pkg/commands/xdel.ts @@ -6,7 +6,7 @@ import { Command, CommandOptions } from "./command"; export class XDelCommand extends Command { constructor( [key, ids]: [key: string, ids: string[] | string], - opts?: CommandOptions + opts?: CommandOptions, ) { const cmds = Array.isArray(ids) ? [...ids] : [ids]; super(["XDEL", key, ...cmds], opts); diff --git a/pkg/commands/xgroup.test.ts b/pkg/commands/xgroup.test.ts index 422a2352..1b58169d 100644 --- a/pkg/commands/xgroup.test.ts +++ b/pkg/commands/xgroup.test.ts @@ -1,8 +1,8 @@ import { keygen, newHttpClient } from "../test-utils"; import { afterAll, describe, expect, test } from "bun:test"; -import { XGroupCommand } from "./xgroup"; import { XAddCommand } from "./xadd"; +import { XGroupCommand } from "./xgroup"; const client = newHttpClient(); @@ -30,9 +30,7 @@ describe("XGROUP CREATE", () => { const throwable = async () => { const key = newKey(); const group = newKey(); - await new XGroupCommand([key, { type: "CREATE", group, id: "$" }]).exec( - client - ); + await new XGroupCommand([key, { type: "CREATE", group, id: "$" }]).exec(client); }; expect(throwable).toThrow(); diff --git a/pkg/commands/xgroup.ts b/pkg/commands/xgroup.ts index eb4bec78..d6ac4e30 100644 --- a/pkg/commands/xgroup.ts +++ b/pkg/commands/xgroup.ts @@ -43,12 +43,13 @@ type XGroupReturnType = T["type"] extends "CREATE" /** * @see https://redis.io/commands/xgroup */ -export class XGroupCommand< - TOptions extends XGroupCommandType = XGroupCommandType -> extends Command> { +export class XGroupCommand extends Command< + any, + XGroupReturnType +> { constructor( [key, opts]: [key: string, opts: TOptions], - commandOptions?: CommandOptions + commandOptions?: CommandOptions, ) { const command: unknown[] = ["XGROUP"]; diff --git a/pkg/commands/xinfo.test.ts b/pkg/commands/xinfo.test.ts index 5e3a8b86..e6a8957c 100644 --- a/pkg/commands/xinfo.test.ts +++ b/pkg/commands/xinfo.test.ts @@ -19,9 +19,7 @@ describe("GROUPS", () => { await addNewItemToStream(streamKey, client); } - const res = (await new XInfoCommand([streamKey, { type: "GROUPS" }]).exec( - client - )) as string[]; + const res = (await new XInfoCommand([streamKey, { type: "GROUPS" }]).exec(client)) as string[]; expect(res).toEqual([]); }); @@ -34,14 +32,9 @@ describe("GROUPS", () => { await addNewItemToStream(streamKey, client); } - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - const res = (await new XInfoCommand([streamKey, { type: "GROUPS" }]).exec( - client - )) as string[]; + const res = (await new XInfoCommand([streamKey, { type: "GROUPS" }]).exec(client)) as string[]; expect(res[0][1]).toEqual(group); }); }); @@ -56,15 +49,11 @@ describe("CONSUMERS", () => { await addNewItemToStream(streamKey, client); } - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - const res = (await new XInfoCommand([ - streamKey, - { type: "CONSUMERS", group }, - ]).exec(client)) as string[]; + const res = (await new XInfoCommand([streamKey, { type: "CONSUMERS", group }]).exec( + client, + )) as string[]; expect(res).toEqual([]); }); @@ -79,19 +68,13 @@ describe("CONSUMERS", () => { await addNewItemToStream(streamKey, client); } - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - (await new XReadGroupCommand([group, consumer, streamKey, ">"]).exec( - client - )) as string[]; + (await new XReadGroupCommand([group, consumer, streamKey, ">"]).exec(client)) as string[]; - const res = (await new XInfoCommand([ - streamKey, - { type: "CONSUMERS", group }, - ]).exec(client)) as string[]; + const res = (await new XInfoCommand([streamKey, { type: "CONSUMERS", group }]).exec( + client, + )) as string[]; const pendingCount = res[0][3]; expect(pendingCount).toBe(wantedAmount); diff --git a/pkg/commands/xinfo.ts b/pkg/commands/xinfo.ts index bf3f5d51..db2eb473 100644 --- a/pkg/commands/xinfo.ts +++ b/pkg/commands/xinfo.ts @@ -13,7 +13,7 @@ type XInfoCommands = export class XInfoCommand extends Command { constructor( [key, options]: [key: string, options: XInfoCommands], - opts?: CommandOptions + opts?: CommandOptions, ) { const cmds: unknown[] = []; if (options.type === "CONSUMERS") { diff --git a/pkg/commands/xlen.test.ts b/pkg/commands/xlen.test.ts index 6e938071..6bd79ba1 100644 --- a/pkg/commands/xlen.test.ts +++ b/pkg/commands/xlen.test.ts @@ -12,20 +12,10 @@ afterAll(cleanup); describe("XLEN", () => { test("should give size of the stream", async () => { const key = newKey(); - await new XAddCommand([key, "*", { name: "Jane", surname: "Austen" }]).exec( - client - ); - await new XAddCommand([ - key, - "*", - { name: "Toni", surname: "Morrison" }, - ]).exec(client); - - await new XAddCommand([ - key, - "*", - { name: "Hezarfen", surname: "----" }, - ]).exec(client); + await new XAddCommand([key, "*", { name: "Jane", surname: "Austen" }]).exec(client); + await new XAddCommand([key, "*", { name: "Toni", surname: "Morrison" }]).exec(client); + + await new XAddCommand([key, "*", { name: "Hezarfen", surname: "----" }]).exec(client); const res = await new XLenCommand([key]).exec(client); diff --git a/pkg/commands/xpending.test.ts b/pkg/commands/xpending.test.ts index e46c6ee9..944d4b7b 100644 --- a/pkg/commands/xpending.test.ts +++ b/pkg/commands/xpending.test.ts @@ -1,17 +1,10 @@ import { addNewItemToStream, keygen, newHttpClient } from "../test-utils"; -import { - afterAll, - afterEach, - beforeEach, - describe, - expect, - test, -} from "bun:test"; +import { afterAll, afterEach, beforeEach, describe, expect, test } from "bun:test"; +import { sleep } from "bun"; import { XGroupCommand } from "./xgroup"; import { XPendingCommand } from "./xpending"; import { XReadGroupCommand } from "./xreadgroup"; -import { sleep } from "bun"; const client = newHttpClient(); @@ -30,24 +23,12 @@ describe("XPENDING", () => { ]).exec(client); await addNewItemToStream(streamKey1, client); - await new XReadGroupCommand([ - group, - consumer, - streamKey1, - ">", - { count: 1 }, - ]).exec(client); + await new XReadGroupCommand([group, consumer, streamKey1, ">", { count: 1 }]).exec(client); }); afterEach(cleanup); test("should get pending messages", async () => { - const pending = await new XPendingCommand([ - streamKey1, - group, - "-", - "+", - 10, - ]).exec(client); + const pending = await new XPendingCommand([streamKey1, group, "-", "+", 10]).exec(client); expect(pending).toBeInstanceOf(Array); expect(pending.length).toBeGreaterThan(0); @@ -85,13 +66,7 @@ describe("XPENDING", () => { test("should get specific consumer", async () => { const newConsumer = newKey(); - await new XReadGroupCommand([ - group, - newConsumer, - streamKey1, - ">", - { count: 1 }, - ]).exec(client); + await new XReadGroupCommand([group, newConsumer, streamKey1, ">", { count: 1 }]).exec(client); const pending = await new XPendingCommand([ streamKey1, diff --git a/pkg/commands/xpending.ts b/pkg/commands/xpending.ts index 96391418..eacebcd2 100644 --- a/pkg/commands/xpending.ts +++ b/pkg/commands/xpending.ts @@ -14,9 +14,9 @@ export class XPendingCommand extends Command { options?: { idleTime?: number; consumer?: string | string[]; - } + }, ], - opts?: CommandOptions + opts?: CommandOptions, ) { const consumers = typeof options?.consumer !== "undefined" @@ -36,7 +36,7 @@ export class XPendingCommand extends Command { count, ...consumers, ], - opts + opts, ); } } diff --git a/pkg/commands/xrange.test.ts b/pkg/commands/xrange.test.ts index fbb77817..7e924890 100644 --- a/pkg/commands/xrange.test.ts +++ b/pkg/commands/xrange.test.ts @@ -18,11 +18,7 @@ describe("without options", () => { const field2 = "field2"; const member2 = randomID(); - await new XAddCommand([ - key, - "*", - { [field1]: member1, [field2]: member2 }, - ]).exec(client); + await new XAddCommand([key, "*", { [field1]: member1, [field2]: member2 }]).exec(client); const res = await new XRangeCommand([key, "-", "+"]).exec(client); expect(Object.keys(res).length).toBe(1); diff --git a/pkg/commands/xread.test.ts b/pkg/commands/xread.test.ts index 283560e4..f34f9542 100644 --- a/pkg/commands/xread.test.ts +++ b/pkg/commands/xread.test.ts @@ -11,14 +11,9 @@ afterAll(cleanup); describe("COUNT", () => { test("should return successfully", async () => { const streamKey = newKey(); - const { member1: xmember1, member2: xmember2 } = await addNewItemToStream( - streamKey, - client - ); + const { member1: xmember1, member2: xmember2 } = await addNewItemToStream(streamKey, client); - const res = (await new XReadCommand([streamKey, "0-0"]).exec( - client - )) as string[]; + const res = (await new XReadCommand([streamKey, "0-0"]).exec(client)) as string[]; expect(res[0][1][0][1]).toEqual(["field1", xmember1, "field2", xmember2]); }); @@ -29,11 +24,9 @@ describe("COUNT", () => { await addNewItemToStream(streamKey, client); await addNewItemToStream(streamKey, client); - const res = (await new XReadCommand([ - streamKey, - "0-0", - { count: wantedLength }, - ]).exec(client)) as any[]; + const res = (await new XReadCommand([streamKey, "0-0", { count: wantedLength }]).exec( + client, + )) as any[]; expect(res[0][1].length).toBe(wantedLength); }); @@ -44,11 +37,9 @@ describe("COUNT", () => { await addNewItemToStream(streamKey, client); await addNewItemToStream(streamKey, client); - const res = (await new XReadCommand([ - streamKey, - "0-0", - { count: wantedLength }, - ]).exec(client)) as any[]; + const res = (await new XReadCommand([streamKey, "0-0", { count: wantedLength }]).exec( + client, + )) as any[]; expect(res[0][1].length).toBe(wantedLength); }); @@ -61,13 +52,12 @@ describe("IDs", () => { const streamKey = newKey(); await addNewItemToStream(streamKey, client); - const res = (await new XReadCommand([ - streamKey, - `${Date.now() - 15000}-0`, - ]).exec(client)) as string[]; + const res = (await new XReadCommand([streamKey, `${Date.now() - 15000}-0`]).exec( + client, + )) as string[]; expect(res).toBeInstanceOf(Array); }, - { retry: 3 } + { retry: 3 }, ); }); @@ -88,7 +78,7 @@ describe("Multiple stream", () => { ]).exec(client)) as string[]; expect(res.length).toBe(wantedLength); }, - { retry: 3 } + { retry: 3 }, ); test( @@ -105,7 +95,7 @@ describe("Multiple stream", () => { ]).exec(client)) as string[]; expect(res.length).toBe(wantedLength); }, - { retry: 3 } + { retry: 3 }, ); test( @@ -120,6 +110,6 @@ describe("Multiple stream", () => { expect(throwable).toThrow(UNBALANCED_XREAD_ERR); }, - { retry: 3 } + { retry: 3 }, ); }); diff --git a/pkg/commands/xread.ts b/pkg/commands/xread.ts index f72a9799..6b6bbe2b 100644 --- a/pkg/commands/xread.ts +++ b/pkg/commands/xread.ts @@ -6,26 +6,18 @@ export const UNBALANCED_XREAD_ERR = type XReadCommandOptions = [ key: string | string[], id: string | string[], - options?: { count?: number; blockMS?: number } + options?: { count?: number; blockMS?: number }, ]; //This type ensures users have balanced stream keys and stream ids otherwise redis server will throw an error. type XReadOptions = XReadCommandOptions extends [infer K, infer I, ...any[]] ? K extends string ? I extends string - ? [ - key: string, - id: string, - options?: { count?: number; blockMS?: number } - ] + ? [key: string, id: string, options?: { count?: number; blockMS?: number }] : never : K extends string[] ? I extends string[] - ? [ - key: string[], - id: string[], - options?: { count?: number; blockMS?: number } - ] + ? [key: string[], id: string[], options?: { count?: number; blockMS?: number }] : never : never : never; @@ -34,10 +26,7 @@ type XReadOptions = XReadCommandOptions extends [infer K, infer I, ...any[]] * @see https://redis.io/commands/xread */ export class XReadCommand extends Command { - constructor( - [key, id, options]: XReadOptions, - opts?: CommandOptions - ) { + constructor([key, id, options]: XReadOptions, opts?: CommandOptions) { if (Array.isArray(key) && Array.isArray(id)) { if (key.length !== id.length) { throw new Error(UNBALANCED_XREAD_ERR); @@ -55,7 +44,7 @@ export class XReadCommand extends Command { commands.push( "STREAMS", ...(Array.isArray(key) ? [...key] : [key]), - ...(Array.isArray(id) ? [...id] : [id]) + ...(Array.isArray(id) ? [...id] : [id]), ); super(["XREAD", ...commands], opts); diff --git a/pkg/commands/xreadgroup.test.ts b/pkg/commands/xreadgroup.test.ts index a1a120f4..7a4dd503 100644 --- a/pkg/commands/xreadgroup.test.ts +++ b/pkg/commands/xreadgroup.test.ts @@ -2,8 +2,8 @@ import { addNewItemToStream, keygen, newHttpClient } from "../test-utils"; import { afterAll, describe, expect, test } from "bun:test"; import { XGroupCommand } from "./xgroup"; -import { UNBALANCED_XREADGROUP_ERR, XReadGroupCommand } from "./xreadgroup"; import { XInfoCommand } from "./xinfo"; +import { UNBALANCED_XREADGROUP_ERR, XReadGroupCommand } from "./xreadgroup"; const client = newHttpClient(); @@ -21,17 +21,11 @@ describe("COUNT", () => { await addNewItemToStream(streamKey, client); } - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - const res = (await new XReadGroupCommand([ - group, - consumer, - streamKey, - ">", - ]).exec(client)) as string[]; + const res = (await new XReadGroupCommand([group, consumer, streamKey, ">"]).exec( + client, + )) as string[]; const listOfStreams = res[0][1]; expect(listOfStreams.length).toEqual(wantedAmount); @@ -47,10 +41,7 @@ describe("COUNT", () => { await addNewItemToStream(streamKey, client); } - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); const res = (await new XReadGroupCommand([ group, @@ -73,23 +64,13 @@ describe("NOACK", () => { await addNewItemToStream(streamKey, client); - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - await new XReadGroupCommand([ - group, - consumer, - streamKey, - ">", - { NOACK: true }, - ]).exec(client); + await new XReadGroupCommand([group, consumer, streamKey, ">", { NOACK: true }]).exec(client); - const xinfoRes = (await new XInfoCommand([ - streamKey, - { type: "CONSUMERS", group }, - ]).exec(client)) as string[]; + const xinfoRes = (await new XInfoCommand([streamKey, { type: "CONSUMERS", group }]).exec( + client, + )) as string[]; expect(xinfoRes).toEqual([]); }); @@ -103,23 +84,13 @@ describe("NOACK", () => { await addNewItemToStream(streamKey, client); } - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); - await new XReadGroupCommand([ - group, - consumer, - streamKey, - ">", - { NOACK: false }, - ]).exec(client); + await new XReadGroupCommand([group, consumer, streamKey, ">", { NOACK: false }]).exec(client); - const xinfoRes = (await new XInfoCommand([ - streamKey, - { type: "CONSUMERS", group }, - ]).exec(client)) as string[]; + const xinfoRes = (await new XInfoCommand([streamKey, { type: "CONSUMERS", group }]).exec( + client, + )) as string[]; const pendingCount = xinfoRes[0][3]; @@ -139,14 +110,8 @@ describe("Multiple Stream", () => { await addNewItemToStream(streamKey2, client); await addNewItemToStream(streamKey2, client); - await new XGroupCommand([ - streamKey1, - { type: "CREATE", group, id: "0" }, - ]).exec(client); - await new XGroupCommand([ - streamKey2, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey1, { type: "CREATE", group, id: "0" }]).exec(client); + await new XGroupCommand([streamKey2, { type: "CREATE", group, id: "0" }]).exec(client); const res = (await new XReadGroupCommand([ group, @@ -168,10 +133,7 @@ describe("Multiple Stream", () => { await addNewItemToStream(streamKey, client); } - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); const res = (await new XReadGroupCommand([ group, @@ -193,17 +155,9 @@ describe("Multiple Stream", () => { await addNewItemToStream(streamKey, client); - await new XGroupCommand([ - streamKey, - { type: "CREATE", group, id: "0" }, - ]).exec(client); - - await new XReadGroupCommand([ - group, - consumer, - [streamKey, newKey()], - ["0-0"], - ]).exec(client); + await new XGroupCommand([streamKey, { type: "CREATE", group, id: "0" }]).exec(client); + + await new XReadGroupCommand([group, consumer, [streamKey, newKey()], ["0-0"]]).exec(client); }; expect(throwable).toThrow(UNBALANCED_XREADGROUP_ERR); diff --git a/pkg/commands/xreadgroup.ts b/pkg/commands/xreadgroup.ts index 911ba901..8c9361dd 100644 --- a/pkg/commands/xreadgroup.ts +++ b/pkg/commands/xreadgroup.ts @@ -9,7 +9,7 @@ type XReadGroupCommandOptions = [ consumer: string, key: string | string[], id: string | string[], - options?: Options + options?: Options, ]; //This type ensures users have balanced stream keys and stream ids otherwise redis server will throw an error. @@ -18,27 +18,15 @@ type XReadGroupOptions = XReadGroupCommandOptions extends [ string, infer TKey, infer TId, - ...any[] + ...any[], ] ? TKey extends string ? TId extends string - ? [ - group: string, - consumer: string, - key: string, - id: string, - options?: Options - ] + ? [group: string, consumer: string, key: string, id: string, options?: Options] : never : TKey extends string[] ? TId extends string[] - ? [ - group: string, - consumer: string, - key: string[], - id: string[], - options?: Options - ] + ? [group: string, consumer: string, key: string[], id: string[], options?: Options] : never : never : never; @@ -49,7 +37,7 @@ type XReadGroupOptions = XReadGroupCommandOptions extends [ export class XReadGroupCommand extends Command { constructor( [group, consumer, key, id, options]: XReadGroupOptions, - opts?: CommandOptions + opts?: CommandOptions, ) { if (Array.isArray(key) && Array.isArray(id)) { if (key.length !== id.length) { @@ -71,7 +59,7 @@ export class XReadGroupCommand extends Command { commands.push( "STREAMS", ...(Array.isArray(key) ? [...key] : [key]), - ...(Array.isArray(id) ? [...id] : [id]) + ...(Array.isArray(id) ? [...id] : [id]), ); super(["XREADGROUP", "GROUP", group, consumer, ...commands], opts); diff --git a/pkg/commands/xrevrange.test.ts b/pkg/commands/xrevrange.test.ts index 19f2c3d3..89206441 100644 --- a/pkg/commands/xrevrange.test.ts +++ b/pkg/commands/xrevrange.test.ts @@ -10,29 +10,15 @@ const key = newKey(); afterAll(cleanup); beforeEach(async () => { - await new XAddCommand([ - key, - "*", - { name: "Virginia", surname: "Woolf" }, - ]).exec(client); - - await new XAddCommand([key, "*", { name: "Jane", surname: "Austen" }]).exec( - client - ); - - await new XAddCommand([key, "*", { name: "Toni", surname: "Morrison" }]).exec( - client - ); - - await new XAddCommand([ - key, - "*", - { name: "Agatha", surname: "Christie" }, - ]).exec(client); - - await new XAddCommand([key, "*", { name: "Ngozi", surname: "Adichie" }]).exec( - client - ); + await new XAddCommand([key, "*", { name: "Virginia", surname: "Woolf" }]).exec(client); + + await new XAddCommand([key, "*", { name: "Jane", surname: "Austen" }]).exec(client); + + await new XAddCommand([key, "*", { name: "Toni", surname: "Morrison" }]).exec(client); + + await new XAddCommand([key, "*", { name: "Agatha", surname: "Christie" }]).exec(client); + + await new XAddCommand([key, "*", { name: "Ngozi", surname: "Adichie" }]).exec(client); }); describe("without options", () => { diff --git a/pkg/commands/xrevrange.ts b/pkg/commands/xrevrange.ts index 8ec5c256..c25d0aef 100644 --- a/pkg/commands/xrevrange.ts +++ b/pkg/commands/xrevrange.ts @@ -1,16 +1,11 @@ import { Command, CommandOptions } from "./command"; export class XRevRangeCommand< - TData extends Record> + TData extends Record>, > extends Command { constructor( - [key, end, start, count]: [ - key: string, - end: string, - start: string, - count?: number - ], - opts?: CommandOptions + [key, end, start, count]: [key: string, end: string, start: string, count?: number], + opts?: CommandOptions, ) { const command: unknown[] = ["XREVRANGE", key, end, start]; if (typeof count === "number") { @@ -24,7 +19,7 @@ export class XRevRangeCommand< } function deserialize>>( - result: [string, string[]][] + result: [string, string[]][], ): TData { const obj: Record> = {}; for (const e of result) { diff --git a/pkg/commands/xtrim.test.ts b/pkg/commands/xtrim.test.ts index e633bdf1..0c94cca7 100644 --- a/pkg/commands/xtrim.test.ts +++ b/pkg/commands/xtrim.test.ts @@ -18,23 +18,20 @@ describe("XLEN", () => { const promises = []; for (let i = 1; i <= 10000; i++) { - promises.push( - new XAddCommand([key, "*", { [randomID()]: randomID() }]).exec(client) - ); + promises.push(new XAddCommand([key, "*", { [randomID()]: randomID() }]).exec(client)); } await Promise.all(promises); - await new XTrimCommand([ - key, - { strategy: "MAXLEN", threshold: 300, exactness: "~" }, - ]).exec(client); + await new XTrimCommand([key, { strategy: "MAXLEN", threshold: 300, exactness: "~" }]).exec( + client, + ); const len = await new XLenCommand([key]).exec(client); expect(len).toBeGreaterThanOrEqual(290); expect(len).toBeLessThanOrEqual(310); }, - { timeout: 1000 * 60 } + { timeout: 1000 * 60 }, ); test("should trim with zero threshold and remove everything", async () => { @@ -42,16 +39,13 @@ describe("XLEN", () => { const promises = []; for (let i = 1; i <= 50; i++) { - promises.push( - new XAddCommand([key, "*", { [randomID()]: randomID() }]).exec(client) - ); + promises.push(new XAddCommand([key, "*", { [randomID()]: randomID() }]).exec(client)); } await Promise.all(promises); - await new XTrimCommand([ - key, - { strategy: "MAXLEN", threshold: 0, exactness: "=" }, - ]).exec(client); + await new XTrimCommand([key, { strategy: "MAXLEN", threshold: 0, exactness: "=" }]).exec( + client, + ); const len = await new XLenCommand([key]).exec(client); expect(len).toBeLessThanOrEqual(1); @@ -70,15 +64,14 @@ describe("XLEN", () => { const midRangeId = `${baseTimestamp}-50`; - await new XTrimCommand([ - key, - { strategy: "MINID", threshold: midRangeId, limit: 10 }, - ]).exec(client); + await new XTrimCommand([key, { strategy: "MINID", threshold: midRangeId, limit: 10 }]).exec( + client, + ); const len = await new XLenCommand([key]).exec(client); expect(len).toBeLessThanOrEqual(100); }, - { timeout: 20000 } + { timeout: 20000 }, ); test( @@ -94,14 +87,11 @@ describe("XLEN", () => { const midRangeId = `${baseTimestamp}-50`; - await new XTrimCommand([ - key, - { strategy: "MINID", threshold: midRangeId }, - ]).exec(client); + await new XTrimCommand([key, { strategy: "MINID", threshold: midRangeId }]).exec(client); const len = await new XLenCommand([key]).exec(client); expect(len).toBeLessThanOrEqual(50); }, - { timeout: 20000 } + { timeout: 20000 }, ); }); diff --git a/pkg/commands/xtrim.ts b/pkg/commands/xtrim.ts index 986c009b..13155a82 100644 --- a/pkg/commands/xtrim.ts +++ b/pkg/commands/xtrim.ts @@ -14,20 +14,10 @@ type XTrimOptions = { export class XTrimCommand extends Command { constructor( [key, options]: [key: string, options: XTrimOptions], - opts?: CommandOptions + opts?: CommandOptions, ) { const { limit, strategy, threshold, exactness = "~" } = options; - super( - [ - "XTRIM", - key, - strategy, - exactness, - threshold, - ...(limit ? ["LIMIT", limit] : []), - ], - opts - ); + super(["XTRIM", key, strategy, exactness, threshold, ...(limit ? ["LIMIT", limit] : [])], opts); } } diff --git a/pkg/commands/zadd.test.ts b/pkg/commands/zadd.test.ts index 88f15fad..5f0bdaad 100644 --- a/pkg/commands/zadd.test.ts +++ b/pkg/commands/zadd.test.ts @@ -13,17 +13,19 @@ afterAll(cleanup); describe("command format", () => { describe("without options", () => { test("build the correct command", () => { - expect( - new ZAddCommand(["key", { score: 0, member: "member" }]).command - ).toEqual(["zadd", "key", 0, "member"]); + expect(new ZAddCommand(["key", { score: 0, member: "member" }]).command).toEqual([ + "zadd", + "key", + 0, + "member", + ]); }); }); describe("with nx", () => { test("build the correct command", () => { expect( - new ZAddCommand(["key", { nx: true }, { score: 0, member: "member" }]) - .command + new ZAddCommand(["key", { nx: true }, { score: 0, member: "member" }]).command, ).toEqual(["zadd", "key", "nx", 0, "member"]); }); }); @@ -31,8 +33,7 @@ describe("command format", () => { describe("with xx", () => { test("build the correct command", () => { expect( - new ZAddCommand(["key", { xx: true }, { score: 0, member: "member" }]) - .command + new ZAddCommand(["key", { xx: true }, { score: 0, member: "member" }]).command, ).toEqual(["zadd", "key", "xx", 0, "member"]); }); }); @@ -40,8 +41,7 @@ describe("command format", () => { describe("with ch", () => { test("build the correct command", () => { expect( - new ZAddCommand(["key", { ch: true }, { score: 0, member: "member" }]) - .command + new ZAddCommand(["key", { ch: true }, { score: 0, member: "member" }]).command, ).toEqual(["zadd", "key", "ch", 0, "member"]); }); }); @@ -49,8 +49,7 @@ describe("command format", () => { describe("with incr", () => { test("build the correct command", () => { expect( - new ZAddCommand(["key", { incr: true }, { score: 0, member: "member" }]) - .command + new ZAddCommand(["key", { incr: true }, { score: 0, member: "member" }]).command, ).toEqual(["zadd", "key", "incr", 0, "member"]); }); }); @@ -58,11 +57,7 @@ describe("command format", () => { describe("with nx and ch", () => { test("build the correct command", () => { expect( - new ZAddCommand([ - "key", - { nx: true, ch: true }, - { score: 0, member: "member" }, - ]).command + new ZAddCommand(["key", { nx: true, ch: true }, { score: 0, member: "member" }]).command, ).toEqual(["zadd", "key", "nx", "ch", 0, "member"]); }); }); @@ -70,11 +65,8 @@ describe("command format", () => { describe("with nx,ch and incr", () => { test("build the correct command", () => { expect( - new ZAddCommand([ - "key", - { nx: true, ch: true, incr: true }, - { score: 0, member: "member" }, - ]).command + new ZAddCommand(["key", { nx: true, ch: true, incr: true }, { score: 0, member: "member" }]) + .command, ).toEqual(["zadd", "key", "nx", "ch", "incr", 0, "member"]); }); }); @@ -87,7 +79,7 @@ describe("command format", () => { { nx: true }, { score: 0, member: "member" }, { score: 1, member: "member1" }, - ]).command + ]).command, ).toEqual(["zadd", "key", "nx", 0, "member", 1, "member1"]); }); }); @@ -111,11 +103,9 @@ describe("xx", () => { const score = Math.floor(Math.random() * 10); await new ZAddCommand([key, { score, member }]).exec(client); const newScore = score + 1; - const res = await new ZAddCommand([ - key, - { xx: true }, - { score: newScore, member }, - ]).exec(client); + const res = await new ZAddCommand([key, { xx: true }, { score: newScore, member }]).exec( + client, + ); expect(res).toEqual(0); const res2 = await new ZScoreCommand([key, member]).exec(client); @@ -129,11 +119,9 @@ describe("xx", () => { const score = Math.floor(Math.random() * 10); await new ZAddCommand([key, { score, member }]).exec(client); const newScore = score + 1; - const res = await new ZAddCommand([ - key, - { xx: true }, - { score: newScore, member }, - ]).exec(client); + const res = await new ZAddCommand([key, { xx: true }, { score: newScore, member }]).exec( + client, + ); expect(res).toEqual(0); }); }); @@ -147,11 +135,9 @@ describe("nx", () => { const score = Math.floor(Math.random() * 10); await new ZAddCommand([key, { score, member }]).exec(client); const newScore = score + 1; - const res = await new ZAddCommand([ - key, - { nx: true }, - { score: newScore, member }, - ]).exec(client); + const res = await new ZAddCommand([key, { nx: true }, { score: newScore, member }]).exec( + client, + ); expect(res).toEqual(0); const res2 = await new ZScoreCommand([key, member]).exec(client); @@ -163,11 +149,7 @@ describe("nx", () => { const key = newKey(); const member = randomID(); const score = Math.floor(Math.random() * 10); - const res = await new ZAddCommand([ - key, - { nx: true }, - { score, member }, - ]).exec(client); + const res = await new ZAddCommand([key, { nx: true }, { score, member }]).exec(client); expect(res).toEqual(1); }); }); @@ -180,11 +162,9 @@ describe("ch", () => { const score = Math.floor(Math.random() * 10); await new ZAddCommand([key, { score, member }]).exec(client); const newScore = score + 1; - const res = await new ZAddCommand([ - key, - { ch: true }, - { score: newScore, member }, - ]).exec(client); + const res = await new ZAddCommand([key, { ch: true }, { score: newScore, member }]).exec( + client, + ); expect(res).toEqual(1); }); }); @@ -195,11 +175,7 @@ describe("incr", () => { const member = randomID(); const score = Math.floor(Math.random() * 10); await new ZAddCommand([key, { score, member }]).exec(client); - const res = await new ZAddCommand([ - key, - { incr: true }, - { score: 1, member }, - ]).exec(client); + const res = await new ZAddCommand([key, { incr: true }, { score: 1, member }]).exec(client); expect(typeof res).toBe("number"); expect(res).toEqual(score + 1); }); @@ -214,18 +190,9 @@ describe("LT and GT", () => { await new ZAddCommand([key, { score: 2, member: "two" }]).exec(client); await new ZAddCommand([key, { score: 3, member: "three" }]).exec(client); - await new ZAddCommand([ - key, - { gt: true }, - { score: 4, member: "two" }, - ]).exec(client); + await new ZAddCommand([key, { gt: true }, { score: 4, member: "two" }]).exec(client); - const res2 = await new ZRangeCommand([ - key, - 0, - -1, - { withScores: true }, - ]).exec(client); + const res2 = await new ZRangeCommand([key, 0, -1, { withScores: true }]).exec(client); expect(res2).toEqual(["one", 1, "three", 3, "two", 4]); }); @@ -237,18 +204,9 @@ describe("LT and GT", () => { await new ZAddCommand([key, { score: 2, member: "two" }]).exec(client); await new ZAddCommand([key, { score: 3, member: "three" }]).exec(client); - await new ZAddCommand([ - key, - { gt: true }, - { score: 1, member: "two" }, - ]).exec(client); + await new ZAddCommand([key, { gt: true }, { score: 1, member: "two" }]).exec(client); - const res2 = await new ZRangeCommand([ - key, - 0, - -1, - { withScores: true }, - ]).exec(client); + const res2 = await new ZRangeCommand([key, 0, -1, { withScores: true }]).exec(client); expect(res2).toEqual(["one", 1, "two", 2, "three", 3]); }); @@ -261,18 +219,9 @@ describe("LT and GT", () => { await new ZAddCommand([key, { score: 1, member: "one" }]).exec(client); await new ZAddCommand([key, { score: 2, member: "two" }]).exec(client); await new ZAddCommand([key, { score: 3, member: "three" }]).exec(client); - await new ZAddCommand([ - key, - { lt: true }, - { score: 2, member: "three" }, - ]).exec(client); - - const res2 = await new ZRangeCommand([ - key, - 0, - -1, - { withScores: true }, - ]).exec(client); + await new ZAddCommand([key, { lt: true }, { score: 2, member: "three" }]).exec(client); + + const res2 = await new ZRangeCommand([key, 0, -1, { withScores: true }]).exec(client); expect(res2).toEqual(["one", 1, "three", 2, "two", 2]); }); @@ -283,18 +232,9 @@ describe("LT and GT", () => { await new ZAddCommand([key, { score: 2, member: "two" }]).exec(client); await new ZAddCommand([key, { score: 3, member: "three" }]).exec(client); - await new ZAddCommand([ - key, - { lt: true }, - { score: 6, member: "two" }, - ]).exec(client); + await new ZAddCommand([key, { lt: true }, { score: 6, member: "two" }]).exec(client); - const res2 = await new ZRangeCommand([ - key, - 0, - -1, - { withScores: true }, - ]).exec(client); + const res2 = await new ZRangeCommand([key, 0, -1, { withScores: true }]).exec(client); expect(res2).toEqual(["one", 1, "two", 2, "three", 3]); }); diff --git a/pkg/commands/zadd.ts b/pkg/commands/zadd.ts index 404bc247..22f8139b 100644 --- a/pkg/commands/zadd.ts +++ b/pkg/commands/zadd.ts @@ -10,21 +10,17 @@ type LTAndGTOptions = | { lt?: never; gt: true } | { lt?: never; gt?: never }; -export type ZAddCommandOptions = NXAndXXOptions & - LTAndGTOptions & { ch?: true } & { incr?: true }; +export type ZAddCommandOptions = NXAndXXOptions & LTAndGTOptions & { ch?: true } & { incr?: true }; type Arg2 = ScoreMember | ZAddCommandOptions; export type ScoreMember = { score: number; member: TData }; /** * @see https://redis.io/commands/zadd */ -export class ZAddCommand extends Command< - number | null, - number | null -> { +export class ZAddCommand extends Command { constructor( [key, arg1, ...arg2]: [string, Arg2, ...ScoreMember[]], - opts?: CommandOptions + opts?: CommandOptions, ) { const command: unknown[] = ["zadd", key]; if ("nx" in arg1 && arg1.nx) { diff --git a/pkg/http.ts b/pkg/http.ts index 594a3f4c..45daa71b 100644 --- a/pkg/http.ts +++ b/pkg/http.ts @@ -19,9 +19,7 @@ export type UpstashRequest = { export type UpstashResponse = { result?: TResult; error?: string }; export interface Requester { - request: ( - req: UpstashRequest - ) => Promise>; + request: (req: UpstashRequest) => Promise>; } type ResultError = { @@ -143,8 +141,7 @@ export class HttpClient implements Requester { } else { this.retry = { attempts: config?.retry?.retries ?? 5, - backoff: - config?.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50), + backoff: config?.retry?.backoff ?? ((retryCount) => Math.exp(retryCount) * 50), }; } } @@ -153,7 +150,7 @@ export class HttpClient implements Requester { function merge( obj: Record, key: string, - value?: string + value?: string, ): Record { if (!value) { return obj; @@ -166,22 +163,12 @@ export class HttpClient implements Requester { return obj; } - this.headers = merge( - this.headers, - "Upstash-Telemetry-Runtime", - telemetry.runtime - ); - this.headers = merge( - this.headers, - "Upstash-Telemetry-Platform", - telemetry.platform - ); + this.headers = merge(this.headers, "Upstash-Telemetry-Runtime", telemetry.runtime); + this.headers = merge(this.headers, "Upstash-Telemetry-Platform", telemetry.platform); this.headers = merge(this.headers, "Upstash-Telemetry-Sdk", telemetry.sdk); } - public async request( - req: UpstashRequest - ): Promise> { + public async request(req: UpstashRequest): Promise> { const requestOptions: RequestInit & { backend?: string; agent?: any } = { cache: this.options.cache, method: "POST", @@ -201,10 +188,7 @@ export class HttpClient implements Requester { let error: Error | null = null; for (let i = 0; i <= this.retry.attempts; i++) { try { - res = await fetch( - [this.baseUrl, ...(req.path ?? [])].join("/"), - requestOptions - ); + res = await fetch([this.baseUrl, ...(req.path ?? [])].join("/"), requestOptions); break; } catch (err) { if (this.options.signal?.aborted) { @@ -228,9 +212,7 @@ export class HttpClient implements Requester { const body = (await res.json()) as UpstashResponse; if (!res.ok) { - throw new UpstashError( - `${body.error}, command was: ${JSON.stringify(req.body)}` - ); + throw new UpstashError(`${body.error}, command was: ${JSON.stringify(req.body)}`); } if (this.options?.responseEncoding === "base64") { @@ -284,11 +266,7 @@ function decode(raw: ResultError["result"]): ResultError["result"] { case "object": { if (Array.isArray(raw)) { result = raw.map((v) => - typeof v === "string" - ? base64decode(v) - : Array.isArray(v) - ? v.map(decode) - : v + typeof v === "string" ? base64decode(v) : Array.isArray(v) ? v.map(decode) : v, ); } else { // If it's not an array it must be null diff --git a/pkg/pipeline.ts b/pkg/pipeline.ts index 3cf90c68..df28135c 100644 --- a/pkg/pipeline.ts +++ b/pkg/pipeline.ts @@ -250,7 +250,7 @@ export class Pipeline[] = []> { exec = async < TCommandResults extends unknown[] = [] extends TCommands ? unknown[] - : InferResponseData + : InferResponseData, >(): Promise => { if (this.commands.length === 0) { throw new Error("Pipeline is empty"); @@ -264,7 +264,7 @@ export class Pipeline[] = []> { return res.map(({ error, result }, i) => { if (error) { throw new UpstashError( - `Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}` + `Command ${i + 1} [ ${this.commands[i].command[0]} ] failed: ${error}`, ); } @@ -283,9 +283,7 @@ export class Pipeline[] = []> { * Pushes a command into the pipeline and returns a chainable instance of the * pipeline */ - private chain( - command: Command - ): Pipeline<[...TCommands, Command]> { + private chain(command: Command): Pipeline<[...TCommands, Command]> { this.commands.push(command); return this as any; // TS thinks we're returning Pipeline<[]> here, because we're not creating a new instance of the class, hence the cast } @@ -312,9 +310,7 @@ export class Pipeline[] = []> { sourceKey: string, ...sourceKeys: string[] ): Pipeline<[...TCommands, BitOpCommand]>; - (op: "not", destinationKey: string, sourceKey: string): Pipeline< - [...TCommands, BitOpCommand] - >; + (op: "not", destinationKey: string, sourceKey: string): Pipeline<[...TCommands, BitOpCommand]>; } = ( op: "and" | "or" | "xor" | "not", destinationKey: string, @@ -322,10 +318,7 @@ export class Pipeline[] = []> { ...sourceKeys: string[] ) => this.chain( - new BitOpCommand( - [op as any, destinationKey, sourceKey, ...sourceKeys], - this.commandOptions - ) + new BitOpCommand([op as any, destinationKey, sourceKey, ...sourceKeys], this.commandOptions), ); /** @@ -468,9 +461,8 @@ export class Pipeline[] = []> { /** * @see https://redis.io/commands/hgetall */ - hgetall = >( - ...args: CommandArgs - ) => this.chain(new HGetAllCommand(args, this.commandOptions)); + hgetall = >(...args: CommandArgs) => + this.chain(new HGetAllCommand(args, this.commandOptions)); /** * @see https://redis.io/commands/hincrby @@ -499,9 +491,8 @@ export class Pipeline[] = []> { /** * @see https://redis.io/commands/hmget */ - hmget = >( - ...args: CommandArgs - ) => this.chain(new HMGetCommand(args, this.commandOptions)); + hmget = >(...args: CommandArgs) => + this.chain(new HMGetCommand(args, this.commandOptions)); /** * @see https://redis.io/commands/hmset @@ -515,14 +506,9 @@ export class Pipeline[] = []> { hrandfield = >( key: string, count?: number, - withValues?: boolean + withValues?: boolean, ) => - this.chain( - new HRandFieldCommand( - [key, count, withValues] as any, - this.commandOptions - ) - ); + this.chain(new HRandFieldCommand([key, count, withValues] as any, this.commandOptions)); /** * @see https://redis.io/commands/hscan @@ -540,9 +526,7 @@ export class Pipeline[] = []> { * @see https://redis.io/commands/hsetnx */ hsetnx = (key: string, field: string, value: TData) => - this.chain( - new HSetNXCommand([key, field, value], this.commandOptions) - ); + this.chain(new HSetNXCommand([key, field, value], this.commandOptions)); /** * @see https://redis.io/commands/hstrlen @@ -589,18 +573,8 @@ export class Pipeline[] = []> { /** * @see https://redis.io/commands/linsert */ - linsert = ( - key: string, - direction: "before" | "after", - pivot: TData, - value: TData - ) => - this.chain( - new LInsertCommand( - [key, direction, pivot, value], - this.commandOptions - ) - ); + linsert = (key: string, direction: "before" | "after", pivot: TData, value: TData) => + this.chain(new LInsertCommand([key, direction, pivot, value], this.commandOptions)); /** * @see https://redis.io/commands/llen @@ -630,17 +604,13 @@ export class Pipeline[] = []> { * @see https://redis.io/commands/lpush */ lpush = (key: string, ...elements: TData[]) => - this.chain( - new LPushCommand([key, ...elements], this.commandOptions) - ); + this.chain(new LPushCommand([key, ...elements], this.commandOptions)); /** * @see https://redis.io/commands/lpushx */ lpushx = (key: string, ...elements: TData[]) => - this.chain( - new LPushXCommand([key, ...elements], this.commandOptions) - ); + this.chain(new LPushXCommand([key, ...elements], this.commandOptions)); /** * @see https://redis.io/commands/lrange @@ -730,9 +700,7 @@ export class Pipeline[] = []> { * @see https://redis.io/commands/psetex */ psetex = (key: string, ttl: number, value: TData) => - this.chain( - new PSetEXCommand([key, ttl, value], this.commandOptions) - ); + this.chain(new PSetEXCommand([key, ttl, value], this.commandOptions)); /** * @see https://redis.io/commands/pttl @@ -879,28 +847,20 @@ export class Pipeline[] = []> { /** * @see https://redis.io/commands/smembers */ - smembers = ( - ...args: CommandArgs - ) => this.chain(new SMembersCommand(args, this.commandOptions)); + smembers = (...args: CommandArgs) => + this.chain(new SMembersCommand(args, this.commandOptions)); /** * @see https://redis.io/commands/smismember */ smismember = (key: string, members: TMembers) => - this.chain( - new SMIsMemberCommand([key, members], this.commandOptions) - ); + this.chain(new SMIsMemberCommand([key, members], this.commandOptions)); /** * @see https://redis.io/commands/smove */ smove = (source: string, destination: string, member: TData) => - this.chain( - new SMoveCommand( - [source, destination, member], - this.commandOptions - ) - ); + this.chain(new SMoveCommand([source, destination, member], this.commandOptions)); /** * @see https://redis.io/commands/spop @@ -978,31 +938,27 @@ export class Pipeline[] = []> { */ zadd = ( ...args: - | [ - key: string, - scoreMember: ScoreMember, - ...scoreMemberPairs: ScoreMember[] - ] + | [key: string, scoreMember: ScoreMember, ...scoreMemberPairs: ScoreMember[]] | [ key: string, opts: ZAddCommandOptions, - ...scoreMemberPairs: [ScoreMember, ...ScoreMember[]] + ...scoreMemberPairs: [ScoreMember, ...ScoreMember[]], ] ) => { if ("score" in args[1]) { return this.chain( new ZAddCommand( [args[0], args[1] as ScoreMember, ...(args.slice(2) as any)], - this.commandOptions - ) + this.commandOptions, + ), ); } return this.chain( new ZAddCommand( [args[0], args[1] as any, ...(args.slice(2) as any)], - this.commandOptions - ) + this.commandOptions, + ), ); }; @@ -1106,9 +1062,7 @@ export class Pipeline[] = []> { * @see https://redis.io/commands/zincrby */ zincrby = (key: string, increment: number, member: TData) => - this.chain( - new ZIncrByCommand([key, increment, member], this.commandOptions) - ); + this.chain(new ZIncrByCommand([key, increment, member], this.commandOptions)); /** * @see https://redis.io/commands/zinterstore @@ -1150,13 +1104,13 @@ export class Pipeline[] = []> { key: string, min: `(${string}` | `[${string}` | "-" | "+", max: `(${string}` | `[${string}` | "-" | "+", - opts: { byLex: true } & ZRangeCommandOptions + opts: { byLex: true } & ZRangeCommandOptions, ] | [ key: string, min: number | `(${number}` | "-inf" | "+inf", max: number | `(${number}` | "-inf" | "+inf", - opts: { byScore: true } & ZRangeCommandOptions + opts: { byScore: true } & ZRangeCommandOptions, ] ) => this.chain(new ZRangeCommand(args as any, this.commandOptions)); diff --git a/pkg/test-utils.ts b/pkg/test-utils.ts index db168f1d..ceb3d1bf 100644 --- a/pkg/test-utils.ts +++ b/pkg/test-utils.ts @@ -57,10 +57,7 @@ export function keygen(): { }; } -export async function addNewItemToStream( - streamKey: string, - client: HttpClient -) { +export async function addNewItemToStream(streamKey: string, client: HttpClient) { const field1 = "field1"; const member1 = randomID(); const field2 = "field2"; From 1434e7f9d3175838e0a2d1834ed6ca21c3a72b7e Mon Sep 17 00:00:00 2001 From: ogzhanolguncu Date: Thu, 1 Feb 2024 12:12:30 +0300 Subject: [PATCH 3/5] Add precommit hook --- .husky/pre-commit | 4 ++++ bun.lockb | Bin 59753 -> 60106 bytes package.json | 6 ++++-- pkg/commands/xtrim.test.ts | 32 -------------------------------- 4 files changed, 8 insertions(+), 34 deletions(-) create mode 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 00000000..7f4c7fc8 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +bun run fmt && bun run test \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 5f06a5fe8343d619c25b4ade396d5bccf2e61ee1..e95ff4b7bb1dc4ce5e5f246b9538001ccda3d4dc 100755 GIT binary patch delta 7902 zcmeHMc~lfvx~~E{P$;Vl7Of(f-MW3N>5twgKKEW~>3wUiZ|E`U%lu>Gs@E1=t@`26ceDQX_w&{-mVBG{ z(mN9drw+I&iEG`mjEK^86*{Be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!K_%Jz)nRd`X&Xnctee-devfS#Z^u_6gf<^^i2l@m zP!TC~^Pplge^Us&yMA3%+WR&7O^Hn)6;jk8CC&T|;>x#<*}v=WgSF(Fob~3f6lz?9 z-;2MFyxpOxIS4gMpTqRhp)uHY|MSbmpHUq1%C@`fM^~IGzx^6`+=Z3jI9J!l)+-L8 z>xWeF1jQbX>iYp6RLHwjUYxS%?d+X>l#AfIf?paorQ5@vNuOS&qQg<%`0l#Z+Jg~I zq05^FrW$omv0vVU7@f;=4v;jyPKW?MQZ9OUTs& GK7Rq", "license": "MIT", @@ -71,7 +72,8 @@ "@types/crypto-js": "^4.1.3", "bun-types": "^1.0.6", "tsup": "^7.2.0", - "@biomejs/biome": "^1.3.0" + "@biomejs/biome": "^1.3.0", + "husky": "^8.0.3" }, "dependencies": { "crypto-js": "^4.2.0" diff --git a/pkg/commands/xtrim.test.ts b/pkg/commands/xtrim.test.ts index 0c94cca7..0bbfb7a4 100644 --- a/pkg/commands/xtrim.test.ts +++ b/pkg/commands/xtrim.test.ts @@ -15,19 +15,15 @@ describe("XLEN", () => { "should approximately trim stream to 300 items", async () => { const key = newKey(); - const promises = []; for (let i = 1; i <= 10000; i++) { promises.push(new XAddCommand([key, "*", { [randomID()]: randomID() }]).exec(client)); } await Promise.all(promises); - await new XTrimCommand([key, { strategy: "MAXLEN", threshold: 300, exactness: "~" }]).exec( client, ); - const len = await new XLenCommand([key]).exec(client); - expect(len).toBeGreaterThanOrEqual(290); expect(len).toBeLessThanOrEqual(310); }, @@ -36,17 +32,14 @@ describe("XLEN", () => { test("should trim with zero threshold and remove everything", async () => { const key = newKey(); - const promises = []; for (let i = 1; i <= 50; i++) { promises.push(new XAddCommand([key, "*", { [randomID()]: randomID() }]).exec(client)); } await Promise.all(promises); - await new XTrimCommand([key, { strategy: "MAXLEN", threshold: 0, exactness: "=" }]).exec( client, ); - const len = await new XLenCommand([key]).exec(client); expect(len).toBeLessThanOrEqual(1); }); @@ -56,42 +49,17 @@ describe("XLEN", () => { async () => { const key = newKey(); const baseTimestamp = Date.now(); - for (let i = 0; i < 100; i++) { const id = `${baseTimestamp}-${i}`; await new XAddCommand([key, id, { data: `value${i}` }]).exec(client); } - const midRangeId = `${baseTimestamp}-50`; - await new XTrimCommand([key, { strategy: "MINID", threshold: midRangeId, limit: 10 }]).exec( client, ); - const len = await new XLenCommand([key]).exec(client); expect(len).toBeLessThanOrEqual(100); }, { timeout: 20000 }, ); - - test( - "should trim with MINID and a without limit and delete half of the elements", - async () => { - const key = newKey(); - const baseTimestamp = Date.now(); - - for (let i = 0; i < 100; i++) { - const id = `${baseTimestamp}-${i}`; - await new XAddCommand([key, id, { data: `value${i}` }]).exec(client); - } - - const midRangeId = `${baseTimestamp}-50`; - - await new XTrimCommand([key, { strategy: "MINID", threshold: midRangeId }]).exec(client); - - const len = await new XLenCommand([key]).exec(client); - expect(len).toBeLessThanOrEqual(50); - }, - { timeout: 20000 }, - ); }); From f9d77a318fb103d69a0ef87ba3920bca048f90ac Mon Sep 17 00:00:00 2001 From: ogzhanolguncu Date: Thu, 1 Feb 2024 12:25:00 +0300 Subject: [PATCH 4/5] Make changes to xpending test sleep time --- pkg/commands/xpending.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/commands/xpending.test.ts b/pkg/commands/xpending.test.ts index 944d4b7b..ce3b81bf 100644 --- a/pkg/commands/xpending.test.ts +++ b/pkg/commands/xpending.test.ts @@ -50,7 +50,6 @@ describe("XPENDING", () => { }); test("should not get pending messages with idle time", async () => { - await sleep(350); const pending = await new XPendingCommand([ streamKey1, group, @@ -59,7 +58,6 @@ describe("XPENDING", () => { 10, { idleTime: 500 }, ]).exec(client); - expect(pending).toBeInstanceOf(Array); expect(pending.length).toEqual(0); }); From ddc21dfed12d8a453390176e5aef8d66b9bc1426 Mon Sep 17 00:00:00 2001 From: ogzhanolguncu Date: Thu, 1 Feb 2024 12:37:08 +0300 Subject: [PATCH 5/5] Remove prepare in CI --- .github/workflows/release.yml | 4 +++- .github/workflows/tests.yaml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e7be6924..28743ac0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,10 +42,12 @@ jobs: if: "!github.event.release.prerelease" working-directory: ./dist run: | + npm pkg delete scripts.prepare npm publish --access public - name: Publish release candidate if: "github.event.release.prerelease" working-directory: ./dist run: | - npm publish --access public --tag=next \ No newline at end of file + npm pkg delete scripts.prepare + npm publish --access public --tag=next diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fd269114..c4ef420a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -594,4 +594,6 @@ jobs: - name: Publish ci version working-directory: ./dist - run: npm publish --tag=ci --verbose + run: | + npm pkg delete scripts.prepare + npm publish --tag=ci --verbose