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
34 changes: 17 additions & 17 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"$schema": "https://biomejs.dev/schemas/1.0.0/schema.json",

"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"a11y": {
"noSvgWithoutTitle": "off"
},
"correctness": {
"noUnusedVariables": "warn"
},
"security": {
"noDangerouslySetInnerHtml": "off"
},
"style": {
"useBlockStatements": "error",
"noNonNullAssertion": "off"
"noUnusedVariables": "error"
},
"performance": {
"noDelete": "off"
},
"suspicious":{
"nursery": {
"useAwait": "error"
},
"complexity": {
"noBannedTypes": "off"
},
"suspicious": {
"noExplicitAny": "off"
},
"style": {
"noNonNullAssertion": "off"
}
},
"ignore": ["node_modules", ".next", "dist", ".nuxt", ".contentlayer"]
"ignore": ["node_modules", "dist"]
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"enabled": true,
"lineWidth": 100,
"ignore": ["node_modules", ".next", "dist", ".nuxt", ".contentlayer"]
"lineWidth": 100
},
"organizeImports": {
"enabled": true
}
}
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@types/crypto-js": "^4.1.3",
"bun-types": "^1.0.6",
"tsup": "^7.2.0",
"@biomejs/biome": "^1.3.0",
"@biomejs/biome": "latest",
"husky": "^8.0.3"
},
"dependencies": {
Expand Down
39 changes: 17 additions & 22 deletions pkg/commands/geo_dist.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect, test } from "bun:test";
import { newHttpClient } from "../test-utils";



import { GeoAddCommand } from "./geo_add";
import { GeoDistCommand } from "./geo_dist";

Expand All @@ -15,11 +13,9 @@ test("should return distance successfully in meters", async () => {
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" },
]).exec(client);

const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania"]).exec(
client,
);
const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania"]).exec(client);

expect(res).toEqual( 166274.1516);
expect(res).toEqual(166274.1516);
});

test("should return distance for object members", async () => {
Expand All @@ -29,13 +25,15 @@ test("should return distance for object members", async () => {
{ longitude: 15.087269, latitude: 37.502669, member: { name: "Catania" } },
]).exec(client);

const res = await new GeoDistCommand(["Sicily", { name: "Palermo" }, {
name: "Catania",
}]).exec(
client,
);
const res = await new GeoDistCommand([
"Sicily",
{ name: "Palermo" },
{
name: "Catania",
},
]).exec(client);

expect(res).toEqual( 166274.1516);
expect(res).toEqual(166274.1516);
});

test("should return distance successfully in kilometers", async () => {
Expand All @@ -45,10 +43,9 @@ test("should return distance successfully in kilometers", async () => {
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" },
]).exec(client);

const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "KM"])
.exec(client);
const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "KM"]).exec(client);

expect(res).toEqual( 166.2742);
expect(res).toEqual(166.2742);
});

test("should return distance successfully in miles", async () => {
Expand All @@ -58,10 +55,9 @@ test("should return distance successfully in miles", async () => {
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" },
]).exec(client);

const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "MI"])
.exec(client);
const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "MI"]).exec(client);

expect(res).toEqual( 103.3182);
expect(res).toEqual(103.3182);
});

test("should return distance successfully in feet", async () => {
Expand All @@ -71,14 +67,13 @@ test("should return distance successfully in feet", async () => {
{ longitude: 15.087269, latitude: 37.502669, member: "Catania" },
]).exec(client);

const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "FT"])
.exec(client);
const res = await new GeoDistCommand(["Sicily", "Palermo", "Catania", "FT"]).exec(client);

expect(res?.toString()).toEqual( "545518.8700");
expect(res?.toString()).toEqual("545518.8700");
});

test("should return null if members doesn't exist", async () => {
const res = await new GeoDistCommand(["Sicily", "FOO", "BAR"]).exec(client);

expect(res).toEqual( null);
expect(res).toEqual(null);
});
3 changes: 1 addition & 2 deletions pkg/commands/geo_dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Command, CommandOptions } from "./command";
/**
* @see https://redis.io/commands/geodist
*/
export class GeoDistCommand<TMemberType = string>
extends Command<number | null, number | null> {
export class GeoDistCommand<TMemberType = string> extends Command<number | null, number | null> {
constructor(
[key, member1, member2, unit = "M"]: [
key: string,
Expand Down
62 changes: 30 additions & 32 deletions pkg/commands/geo_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ type OptionMappings = {
};

type GeoSearchOptions<TOptions> = {
[K in
keyof TOptions as K extends keyof OptionMappings
? OptionMappings[K]
: never]: K extends "withHash"
[K in keyof TOptions as K extends keyof OptionMappings
? OptionMappings[K]
: never]: K extends "withHash"
? string
: K extends "withCoord"
? { long: number; lat: number }
: K extends "withDist"
? number
: never;
? { long: number; lat: number }
: K extends "withDist"
? number
: never;
};

type GeoSearchResponse<TOptions, TMemberType> = ({
Expand Down Expand Up @@ -96,32 +95,31 @@ export class GeoSearchCommand<
return { member };
}
});
} else {
return result.map((members) => {
let counter = 1;
const obj = {} as any;
}
return result.map((members) => {
let counter = 1;
const obj = {} as any;

try {
obj.member = JSON.parse(members[0] as string);
} catch {
obj.member = members[0];
}
try {
obj.member = JSON.parse(members[0] as string);
} catch {
obj.member = members[0];
}

if (opts.withDist) {
obj.dist = parseFloat(members[counter++]);
}
if (opts.withHash) {
obj.hash = members[counter++].toString();
}
if (opts.withCoord) {
obj.coord = {
long: parseFloat(members[counter][0]),
lat: parseFloat(members[counter][1]),
};
}
return obj;
});
}
if (opts.withDist) {
obj.dist = parseFloat(members[counter++]);
}
if (opts.withHash) {
obj.hash = members[counter++].toString();
}
if (opts.withCoord) {
obj.coord = {
long: parseFloat(members[counter][0]),
lat: parseFloat(members[counter][1]),
};
}
return obj;
});
};

super(
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/hgetall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function deserialize<TData extends Record<string, unknown>>(result: string[]): T
/**
* @see https://redis.io/commands/hgetall
*/
export class HGetAllCommand<TData extends Record<string, unknown>,> extends Command<
export class HGetAllCommand<TData extends Record<string, unknown>> extends Command<
unknown | null,
TData | null
> {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/hmget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function deserialize<TData extends Record<string, unknown>>(
*
* @see https://redis.io/commands/hmget
*/
export class HMGetCommand<TData extends Record<string, unknown>,> extends Command<
export class HMGetCommand<TData extends Record<string, unknown>> extends Command<
(string | null)[],
TData | null
> {
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/xgroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("XGROUP CREATE", () => {
]).exec(client);
expect(res).toEqual("OK");
});
test("should return error if stream and mkstream don't exist ", async () => {
test("should return error if stream and mkstream don't exist ", () => {
const throwable = async () => {
const key = newKey();
const group = newKey();
Expand Down Expand Up @@ -120,7 +120,7 @@ describe("XGROUP DESTROY", () => {
expect(res).toEqual(1);
});

test("should throw if stream doesn't exist", async () => {
test("should throw if stream doesn't exist", () => {
const throwable = async () => {
const key = newKey();
const group = newKey();
Expand Down
16 changes: 8 additions & 8 deletions pkg/commands/xgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ type XGroupCommandType =
type XGroupReturnType<T extends XGroupCommandType> = T["type"] extends "CREATE"
? string
: T["type"] extends "CREATECONSUMER"
? 0 | 1
: T["type"] extends "DELCONSUMER"
? number
: T["type"] extends "DESTROY"
? 0 | 1
: T["type"] extends "SETID"
? string
: never;
? 0 | 1
: T["type"] extends "DELCONSUMER"
? number
: T["type"] extends "DESTROY"
? 0 | 1
: T["type"] extends "SETID"
? string
: never;

/**
* @see https://redis.io/commands/xgroup
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/xrange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function deserialize<TData extends Record<string, Record<string, unknown>>>(
return obj as TData;
}

export class XRangeCommand<TData extends Record<string, Record<string, unknown>>,> extends Command<
export class XRangeCommand<TData extends Record<string, Record<string, unknown>>> extends Command<
string[][],
TData
> {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/xread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("Multiple stream", () => {

test(
"should throw when unbalanced is array passed",
async () => {
() => {
const throwable = async () => {
const streamKey1 = newKey();
await addNewItemToStream(streamKey1, client);
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/xread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type XReadOptions = XReadCommandOptions extends [infer K, infer I, ...any[]]
? [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 }]
? I extends string[]
? [key: string[], id: string[], options?: { count?: number; blockMS?: number }]
: never
: never
: never
: never;

/**
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/xreadgroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe("Multiple Stream", () => {
expect(listOfStreams.length).toEqual(wantedAmount);
});

test("should throw when unbalanced is array passed", async () => {
test("should throw when unbalanced is array passed", () => {
const throwable = async () => {
const streamKey = newKey();
const group = newKey();
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/xreadgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type XReadGroupOptions = XReadGroupCommandOptions extends [
? [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]
? TId extends string[]
? [group: string, consumer: string, key: string[], id: string[], options?: Options]
: never
: never
: never
: never;

/**
Expand Down
Loading