Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn off naming convention eslint rules #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 1 addition & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,7 @@ const config = {
"warn",
{ prefer: "type-imports", fixStyle: "separate-type-imports" },
],
"@typescript-eslint/naming-convention": [
"warn",
{
selector: ["variable", "property"],
format: ["camelCase"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: ["typeLike"],
format: ["PascalCase"],
},
{
selector: ["variable", "function"],
format: null,
modifiers: ["global"],
},
],
"@typescript-eslint/naming-convention": ["off"],
"@typescript-eslint/no-misused-promises": [
2,
{ checksVoidReturn: { attributes: false } },
Expand Down
21 changes: 9 additions & 12 deletions src/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export interface RequestParams {
retryable?: boolean;
}

export type RequestTiming = {
export interface RequestTiming {
response_time: number;
body_read_time: number;
};
}

export type RequestResponse<T> = Promise<{
body?: T;
Expand All @@ -41,14 +41,14 @@ export const createHTTPClient = (
apiKey: string,
connectTimeout: number,
idleTimeout: number,
warmConnections: number,
warmConnections: number
) =>
new DefaultHTTPClient(
baseUrl,
apiKey,
connectTimeout,
idleTimeout,
warmConnections,
warmConnections
);

class DefaultHTTPClient implements HTTPClient {
Expand All @@ -62,7 +62,7 @@ class DefaultHTTPClient implements HTTPClient {
apiKey: string,
connectTimeout: number,
idleTimeout: number,
warmConnections: number,
warmConnections: number
) {
this.baseUrl = baseUrl;
this.apiKey = apiKey;
Expand Down Expand Up @@ -104,11 +104,8 @@ class DefaultHTTPClient implements HTTPClient {
}

const headers: Record<string, string> = {
// eslint-disable-next-line @typescript-eslint/naming-convention
"Accept-Encoding": "gzip",
// eslint-disable-next-line @typescript-eslint/naming-convention
Authorization: `Bearer ${this.apiKey}`,
// eslint-disable-next-line @typescript-eslint/naming-convention
"User-Agent": this.userAgent,
};
if (body) {
Expand Down Expand Up @@ -214,15 +211,15 @@ class DefaultHTTPClient implements HTTPClient {
});
}

let response_end = performance.now();
const response_end = performance.now();

return {
body: json as T,
headers: response.headers,
request_timing: make_request_timing(
request_start,
response_start,
response_end,
response_end
),
};
}
Expand All @@ -233,7 +230,7 @@ export class TurbopufferError extends Error {
status?: number;
constructor(
public error: string,
{ status, cause }: { status?: number; cause?: Error },
{ status, cause }: { status?: number; cause?: Error }
) {
super(error, { cause: cause });
this.status = status;
Expand All @@ -253,7 +250,7 @@ function delay(ms: number) {
function make_request_timing(
request_start: number,
response_start: number,
response_end?: number,
response_end?: number
): RequestTiming {
return {
response_time: response_start - request_start,
Expand Down
96 changes: 57 additions & 39 deletions src/turbopuffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const tpuf = new Turbopuffer({

test("bm25_with_custom_schema_and_sum_query", async () => {
const ns = tpuf.namespace(
"typescript_sdk_" + expect.getState().currentTestName,
"typescript_sdk_" + expect.getState().currentTestName
);

try {
Expand All @@ -16,62 +16,76 @@ test("bm25_with_custom_schema_and_sum_query", async () => {
}

const schema = {
"text": {
"type": "?string",
"bm25": {
"language": "english",
"stemming": true,
"case_sensitive": false,
"remove_stopwords": true
}
}
text: {
type: "?string",
bm25: {
language: "english",
stemming: true,
case_sensitive: false,
remove_stopwords: true,
},
},
};

await ns.upsert({
vectors: [
{
id: 1,
vector: [0.1, 0.1],
attributes: { text: "Walruses are large marine mammals with long tusks and whiskers" }
attributes: {
text: "Walruses are large marine mammals with long tusks and whiskers",
},
},
{
id: 2,
vector: [0.2, 0.2],
attributes: { text: "They primarily inhabit the cold Arctic regions" }
attributes: { text: "They primarily inhabit the cold Arctic regions" },
},
{
id: 3,
vector: [0.3, 0.3],
attributes: { text: "Walruses use their tusks to help haul themselves onto ice" }
attributes: {
text: "Walruses use their tusks to help haul themselves onto ice",
},
},
{
id: 4,
vector: [0.4, 0.4],
attributes: { text: "Their diet mainly consists of mollusks and other sea creatures" }
attributes: {
text: "Their diet mainly consists of mollusks and other sea creatures",
},
},
{
id: 5,
vector: [0.5, 0.5],
attributes: { text: "Walrus populations are affected by climate change and melting ice" }
attributes: {
text: "Walrus populations are affected by climate change and melting ice",
},
},
],
distance_metric: "cosine_distance",
schema: schema
schema: schema,
});

const results = await ns.query({
rank_by: ["Sum", [["text", "BM25", "large tusk"], ["text", "BM25", "mollusk diet"]]]
rank_by: [
"Sum",
[
["text", "BM25", "large tusk"],
["text", "BM25", "mollusk diet"],
],
],
});

expect(results.length).toEqual(3);
expect(results[0].id).toEqual(4);
expect(results[1].id).toEqual(1);
expect(results[2].id).toEqual(3);
})
});

test("bm25_with_default_schema_and_simple_query", async () => {
const ns = tpuf.namespace(
"typescript_sdk_" + expect.getState().currentTestName,
"typescript_sdk_" + expect.getState().currentTestName
);

try {
Expand All @@ -81,31 +95,35 @@ test("bm25_with_default_schema_and_simple_query", async () => {
}

const schema = {
"text": {
"type": "?string",
"bm25": true
}
text: {
type: "?string",
bm25: true,
},
};

await ns.upsert({
vectors: [
{
id: 1,
vector: [0.1, 0.1],
attributes: { text: "Walruses can produce a variety of funny sounds, including whistles, grunts, and bell-like noises." },
attributes: {
text: "Walruses can produce a variety of funny sounds, including whistles, grunts, and bell-like noises.",
},
},
{
id: 2,
vector: [0.2, 0.2],
attributes: { text: "They sometimes use their tusks as a tool to break through ice or to scratch their bodies." },
}
attributes: {
text: "They sometimes use their tusks as a tool to break through ice or to scratch their bodies.",
},
},
],
distance_metric: "cosine_distance",
schema: schema
schema: schema,
});

const results = await ns.query({
rank_by: ["text", "BM25", "scratch"]
rank_by: ["text", "BM25", "scratch"],
});

expect(results.length).toEqual(1);
Expand All @@ -114,7 +132,7 @@ test("bm25_with_default_schema_and_simple_query", async () => {

test("sanity", async () => {
const ns = tpuf.namespace(
"typescript_sdk_" + expect.getState().currentTestName,
"typescript_sdk_" + expect.getState().currentTestName
);

try {
Expand Down Expand Up @@ -206,10 +224,10 @@ test("sanity", async () => {
expect(results.length).toEqual(1);
expect(results[0].id).toEqual(2);

let num = await ns.approxNumVectors();
const num = await ns.approxNumVectors();
expect(num).toEqual(1);

let metadata = await ns.metadata();
const metadata = await ns.metadata();
expect(metadata.approx_count).toEqual(1);
expect(metadata.dimensions).toEqual(2);

Expand All @@ -225,20 +243,20 @@ test("sanity", async () => {
await ns.deleteAll();

// For some reason, expect().toThrow doesn't catch properly
let gotError: any = null;
let gotError: unknown = null;
try {
await ns.query({
vector: [1, 1],
filters: ["numbers", "In", [2, 4]],
});
} catch (e: any) {
} catch (e: unknown) {
gotError = e;
}
expect(gotError).toStrictEqual(
new TurbopufferError(
"💔 Resource not found; the requested namespace is empty.",
{ status: 404 },
),
{ status: 404 }
)
);
});

Expand All @@ -250,18 +268,18 @@ test("connection errors are wrapped", async () => {
});

const ns = tpuf.namespace(
"typescript_sdk_" + expect.getState().currentTestName,
"typescript_sdk_" + expect.getState().currentTestName
);

let gotError: any = null;
let gotError: unknown = null;
try {
await ns.query({
vector: [1, 1],
});
} catch (e: any) {
} catch (e: unknown) {
gotError = e;
}
expect(gotError).toStrictEqual(
new TurbopufferError("fetch failed: Connect Timeout Error", {}),
new TurbopufferError("fetch failed: Connect Timeout Error", {})
);
});
Loading