Elffuss BraidHub

kikocis/lancedb public

feat(node): let NODE API region default to us-east-1 (#1631)

Fixes #1622 
To sync with python API
Changeset085dc16409919ea52eb8612385f681ce9a63b02ffa5a7bfd2855a2c68b398f03
AuthorLuQQiu <luqiujob@gmail.com> · 2024-09-13 11:48 -07:00
CommitterGitHub <noreply@github.com> · 2024-09-13 11:48 -07:00
Parentsd6c505476552

Browse the files at this changeset

3 files changed

modified node/src/index.ts +19 −16
@@ -60,7 +60,7 @@
6060 type MakeArrowTableOptions
6161 } from "./arrow";
6262
63-const defaultAwsRegion = "us-west-2";
63+const defaultAwsRegion = "us-east-1";
6464
6565 const defaultRequestTimeout = 10_000
6666
@@ -111,7 +111,7 @@
111111 */
112112 apiKey?: string
113113
114- /** Region to connect */
114+ /** Region to connect. Default is 'us-east-1' */
115115 region?: string
116116
117117 /**
@@ -197,28 +197,31 @@
197197 export async function connect(
198198 arg: string | Partial<ConnectionOptions>
199199 ): Promise<Connection> {
200- let opts: ConnectionOptions;
200+ let partOpts: Partial<ConnectionOptions>;
201201 if (typeof arg === "string") {
202- opts = { uri: arg };
202+ partOpts = { uri: arg };
203203 } else {
204204 const keys = Object.keys(arg);
205205 if (keys.length === 1 && keys[0] === "uri" && typeof arg.uri === "string") {
206- opts = { uri: arg.uri };
206+ partOpts = { uri: arg.uri };
207207 } else {
208- opts = Object.assign(
209- {
210- uri: "",
211- awsCredentials: undefined,
212- awsRegion: defaultAwsRegion,
213- apiKey: undefined,
214- region: defaultAwsRegion,
215- timeout: defaultRequestTimeout
216- },
217- arg
218- );
208+ partOpts = arg;
219209 }
220210 }
221211
212+ let defaultRegion = process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION;
213+ defaultRegion = (defaultRegion ?? "").trim() !== "" ? defaultRegion : defaultAwsRegion;
214+
215+ const opts: ConnectionOptions = {
216+ uri: partOpts.uri ?? "",
217+ awsCredentials: partOpts.awsCredentials ?? undefined,
218+ awsRegion: partOpts.awsRegion ?? defaultRegion,
219+ apiKey: partOpts.apiKey ?? undefined,
220+ region: partOpts.region ?? defaultRegion,
221+ timeout: partOpts.timeout ?? defaultRequestTimeout,
222+ readConsistencyInterval: partOpts.readConsistencyInterval ?? undefined,
223+ storageOptions: partOpts.storageOptions ?? undefined
224+ }
222225 if (opts.uri.startsWith("db://")) {
223226 // Remote connection
224227 return new RemoteConnection(opts);
modified node/src/remote/client.ts +4 −4
@@ -82,7 +82,7 @@
8282
8383 interface MiddlewareInvocationOptions {
8484 responseType?: ResponseType
85- timeout?: number,
85+ timeout?: number
8686 }
8787
8888 /**
@@ -130,8 +130,8 @@
130130 url: string,
131131 apiKey: string,
132132 timeout?: number,
133- private readonly _dbName?: string,
134-
133+ private readonly _dbName?: string
134+
135135 ) {
136136 this._url = url
137137 this._apiKey = () => apiKey
@@ -237,7 +237,7 @@
237237 try {
238238 response = await callWithMiddlewares(req, this._middlewares, {
239239 responseType,
240- timeout: this._timeout,
240+ timeout: this._timeout
241241 })
242242
243243 // return response
modified node/src/test/test.ts +2 −2
@@ -112,8 +112,8 @@
112112 name: 'name_2',
113113 price: 10,
114114 is_active: true,
115- vector: [ 0, 0.1 ]
116- },
115+ vector: [0, 0.1]
116+ }
117117 ]);
118118 assert.equal(await table2.countRows(), 3);
119119 });