From 7ed86cadfb74d72c818af0d392ae2e548cc9bd25 Mon Sep 17 00:00:00 2001 From: LuQQiu Date: Fri, 13 Sep 2024 11:48:57 -0700 Subject: [PATCH] feat(node): let NODE API region default to us-east-1 (#1631) Fixes #1622 To sync with python API --- node/src/index.ts | 35 +++++++++++++++++++---------------- node/src/remote/client.ts | 8 ++++---- node/src/test/test.ts | 4 ++-- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/node/src/index.ts b/node/src/index.ts index 5e65f4d6..6e580c8b 100644 --- a/node/src/index.ts +++ b/node/src/index.ts @@ -60,7 +60,7 @@ export { type MakeArrowTableOptions } from "./arrow"; -const defaultAwsRegion = "us-west-2"; +const defaultAwsRegion = "us-east-1"; const defaultRequestTimeout = 10_000 @@ -111,7 +111,7 @@ export interface ConnectionOptions { */ apiKey?: string - /** Region to connect */ + /** Region to connect. Default is 'us-east-1' */ region?: string /** @@ -197,28 +197,31 @@ export async function connect( export async function connect( arg: string | Partial ): Promise { - let opts: ConnectionOptions; + let partOpts: Partial; if (typeof arg === "string") { - opts = { uri: arg }; + partOpts = { uri: arg }; } else { const keys = Object.keys(arg); if (keys.length === 1 && keys[0] === "uri" && typeof arg.uri === "string") { - opts = { uri: arg.uri }; + partOpts = { uri: arg.uri }; } else { - opts = Object.assign( - { - uri: "", - awsCredentials: undefined, - awsRegion: defaultAwsRegion, - apiKey: undefined, - region: defaultAwsRegion, - timeout: defaultRequestTimeout - }, - arg - ); + partOpts = arg; } } + let defaultRegion = process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION; + defaultRegion = (defaultRegion ?? "").trim() !== "" ? defaultRegion : defaultAwsRegion; + + const opts: ConnectionOptions = { + uri: partOpts.uri ?? "", + awsCredentials: partOpts.awsCredentials ?? undefined, + awsRegion: partOpts.awsRegion ?? defaultRegion, + apiKey: partOpts.apiKey ?? undefined, + region: partOpts.region ?? defaultRegion, + timeout: partOpts.timeout ?? defaultRequestTimeout, + readConsistencyInterval: partOpts.readConsistencyInterval ?? undefined, + storageOptions: partOpts.storageOptions ?? undefined + } if (opts.uri.startsWith("db://")) { // Remote connection return new RemoteConnection(opts); diff --git a/node/src/remote/client.ts b/node/src/remote/client.ts index 78b1edfc..27e1c039 100644 --- a/node/src/remote/client.ts +++ b/node/src/remote/client.ts @@ -82,7 +82,7 @@ async function callWithMiddlewares ( interface MiddlewareInvocationOptions { responseType?: ResponseType - timeout?: number, + timeout?: number } /** @@ -130,8 +130,8 @@ export class HttpLancedbClient { url: string, apiKey: string, timeout?: number, - private readonly _dbName?: string, - + private readonly _dbName?: string + ) { this._url = url this._apiKey = () => apiKey @@ -237,7 +237,7 @@ export class HttpLancedbClient { try { response = await callWithMiddlewares(req, this._middlewares, { responseType, - timeout: this._timeout, + timeout: this._timeout }) // return response diff --git a/node/src/test/test.ts b/node/src/test/test.ts index a970bd8e..33f676dc 100644 --- a/node/src/test/test.ts +++ b/node/src/test/test.ts @@ -112,8 +112,8 @@ describe("LanceDB client", function () { name: 'name_2', price: 10, is_active: true, - vector: [ 0, 0.1 ] - }, + vector: [0, 0.1] + } ]); assert.equal(await table2.countRows(), 3); });