Changesets · Branches · Tags · Compare
| Changeset | 085dc16409919ea52eb8612385f681ce9a63b02ffa5a7bfd2855a2c68b398f03 |
|---|---|
| Author | LuQQiu <luqiujob@gmail.com> · 2024-09-13 11:48 -07:00 |
| Committer | GitHub <noreply@github.com> · 2024-09-13 11:48 -07:00 |
| Parents | d6c505476552 |
3 files changed
modified node/src/index.ts +19 −16
| @@ -60,7 +60,7 @@ | ||
| 60 | 60 | type MakeArrowTableOptions |
| 61 | 61 | } from "./arrow"; |
| 62 | 62 | |
| 63 | -const defaultAwsRegion = "us-west-2"; | |
| 63 | +const defaultAwsRegion = "us-east-1"; | |
| 64 | 64 | |
| 65 | 65 | const defaultRequestTimeout = 10_000 |
| 66 | 66 | |
| @@ -111,7 +111,7 @@ | ||
| 111 | 111 | */ |
| 112 | 112 | apiKey?: string |
| 113 | 113 | |
| 114 | - /** Region to connect */ | |
| 114 | + /** Region to connect. Default is 'us-east-1' */ | |
| 115 | 115 | region?: string |
| 116 | 116 | |
| 117 | 117 | /** |
| @@ -197,28 +197,31 @@ | ||
| 197 | 197 | export async function connect( |
| 198 | 198 | arg: string | Partial<ConnectionOptions> |
| 199 | 199 | ): Promise<Connection> { |
| 200 | - let opts: ConnectionOptions; | |
| 200 | + let partOpts: Partial<ConnectionOptions>; | |
| 201 | 201 | if (typeof arg === "string") { |
| 202 | - opts = { uri: arg }; | |
| 202 | + partOpts = { uri: arg }; | |
| 203 | 203 | } else { |
| 204 | 204 | const keys = Object.keys(arg); |
| 205 | 205 | if (keys.length === 1 && keys[0] === "uri" && typeof arg.uri === "string") { |
| 206 | - opts = { uri: arg.uri }; | |
| 206 | + partOpts = { uri: arg.uri }; | |
| 207 | 207 | } 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; | |
| 219 | 209 | } |
| 220 | 210 | } |
| 221 | 211 | |
| 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 | + } | |
| 222 | 225 | if (opts.uri.startsWith("db://")) { |
| 223 | 226 | // Remote connection |
| 224 | 227 | return new RemoteConnection(opts); |
modified node/src/remote/client.ts +4 −4
| @@ -82,7 +82,7 @@ | ||
| 82 | 82 | |
| 83 | 83 | interface MiddlewareInvocationOptions { |
| 84 | 84 | responseType?: ResponseType |
| 85 | - timeout?: number, | |
| 85 | + timeout?: number | |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| @@ -130,8 +130,8 @@ | ||
| 130 | 130 | url: string, |
| 131 | 131 | apiKey: string, |
| 132 | 132 | timeout?: number, |
| 133 | - private readonly _dbName?: string, | |
| 134 | - | |
| 133 | + private readonly _dbName?: string | |
| 134 | + | |
| 135 | 135 | ) { |
| 136 | 136 | this._url = url |
| 137 | 137 | this._apiKey = () => apiKey |
| @@ -237,7 +237,7 @@ | ||
| 237 | 237 | try { |
| 238 | 238 | response = await callWithMiddlewares(req, this._middlewares, { |
| 239 | 239 | responseType, |
| 240 | - timeout: this._timeout, | |
| 240 | + timeout: this._timeout | |
| 241 | 241 | }) |
| 242 | 242 | |
| 243 | 243 | // return response |
modified node/src/test/test.ts +2 −2
| @@ -112,8 +112,8 @@ | ||
| 112 | 112 | name: 'name_2', |
| 113 | 113 | price: 10, |
| 114 | 114 | is_active: true, |
| 115 | - vector: [ 0, 0.1 ] | |
| 116 | - }, | |
| 115 | + vector: [0, 0.1] | |
| 116 | + } | |
| 117 | 117 | ]); |
| 118 | 118 | assert.equal(await table2.countRows(), 3); |
| 119 | 119 | }); |