Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
npm pkg delete scripts.prepare
npm publish --access public --tag=next
4 changes: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

bun run fmt && bun run test
Binary file modified bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"scripts": {
"build": "tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/",
"test": "bun test pkg --coverage",
"fmt": "bunx @biomejs/biome check --apply ./pkg"
"fmt": "bunx @biomejs/biome check --apply ./pkg",
"prepare": "husky install"
},
"author": "Andreas Thomas <[email protected]>",
"license": "MIT",
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/expire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/expire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/commands/json_mget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { Command, CommandOptions } from "./command";
/**
* @see https://redis.io/commands/json.mget
*/
export class JsonMGetCommand<TData extends (unknown | Record<string, unknown>)[],> extends Command<
TData,
TData
> {
export class JsonMGetCommand<TData = unknown[]> extends Command<TData, TData> {
constructor(cmd: [keys: string[], path: string], opts?: CommandOptions<TData, TData>) {
super(["JSON.MGET", ...cmd[0], cmd[1]], opts);
}
Expand Down
29 changes: 6 additions & 23 deletions pkg/commands/pfadd.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
});
});
Expand All @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions pkg/commands/pfadd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { Command, CommandOptions } from "./command.ts";
* @see https://redis.io/commands/pfadd
*/
export class PfAddCommand<TData = string> extends Command<number, number> {
constructor(
cmd: [string, ...(TData[] | TData[])],
opts?: CommandOptions<number, number>
) {
constructor(cmd: [string, ...(TData[] | TData[])], opts?: CommandOptions<number, number>) {
super(["pfadd", ...cmd], opts);
}
}
5 changes: 2 additions & 3 deletions pkg/commands/pfcount.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions pkg/commands/pfcount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { Command, CommandOptions } from "./command.ts";
* @see https://redis.io/commands/pfcount
*/
export class PfCountCommand extends Command<number, number> {
constructor(
cmd: [string, ...(string[] | string[])],
opts?: CommandOptions<number, number>
) {
constructor(cmd: [string, ...(string[] | string[])], opts?: CommandOptions<number, number>) {
super(["pfcount", ...cmd], opts);
}
}
18 changes: 5 additions & 13 deletions pkg/commands/pfmerge.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/pfmerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
59 changes: 14 additions & 45 deletions pkg/commands/xack.test.ts
Original file line number Diff line number Diff line change
@@ -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();

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

Expand All @@ -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);
});
});
2 changes: 1 addition & 1 deletion pkg/commands/xack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Command, CommandOptions } from "./command";
export class XAckCommand extends Command<number, number> {
constructor(
[key, group, id]: [key: string, group: string, id: string | string[]],
opts?: CommandOptions<number, number>
opts?: CommandOptions<number, number>,
) {
const ids = Array.isArray(id) ? [...id] : [id];
super(["XACK", key, group, ...ids], opts);
Expand Down
Loading