Comparing version 0.1.12 to 0.1.13
@@ -5,2 +5,11 @@ import { type Table as ArrowTable } from 'apache-arrow'; | ||
export { OpenAIEmbeddingFunction } from './embedding/openai'; | ||
export interface AwsCredentials { | ||
accessKeyId: string; | ||
secretKey: string; | ||
sessionToken?: string; | ||
} | ||
export interface ConnectionOptions { | ||
uri: string; | ||
awsCredentials?: AwsCredentials; | ||
} | ||
/** | ||
@@ -11,2 +20,3 @@ * Connect to a LanceDB instance at the given URI | ||
export declare function connect(uri: string): Promise<Connection>; | ||
export declare function connect(opts: Partial<ConnectionOptions>): Promise<Connection>; | ||
/** | ||
@@ -84,7 +94,2 @@ * A LanceDB Connection that allows you to open tables and create new ones. | ||
} | ||
export interface AwsCredentials { | ||
accessKeyId: string; | ||
secretKey: string; | ||
sessionToken?: string; | ||
} | ||
/** | ||
@@ -94,5 +99,5 @@ * A connection to a LanceDB database. | ||
export declare class LocalConnection implements Connection { | ||
private readonly _uri; | ||
private readonly _options; | ||
private readonly _db; | ||
constructor(db: any, uri: string); | ||
constructor(db: any, options: ConnectionOptions); | ||
get uri(): string; | ||
@@ -116,3 +121,3 @@ /** | ||
openTable<T>(name: string, embeddings: EmbeddingFunction<T>): Promise<Table<T>>; | ||
openTable<T>(name: string, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials): Promise<Table<T>>; | ||
openTable<T>(name: string, embeddings?: EmbeddingFunction<T>): Promise<Table<T>>; | ||
/** | ||
@@ -136,3 +141,3 @@ * Creates a new Table and initialize it with new data. | ||
createTable<T>(name: string, data: Array<Record<string, unknown>>, mode: WriteMode, embeddings: EmbeddingFunction<T>): Promise<Table<T>>; | ||
createTable<T>(name: string, data: Array<Record<string, unknown>>, mode: WriteMode, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials): Promise<Table<T>>; | ||
createTable<T>(name: string, data: Array<Record<string, unknown>>, mode: WriteMode, embeddings?: EmbeddingFunction<T>): Promise<Table<T>>; | ||
createTableArrow(name: string, table: ArrowTable): Promise<Table>; | ||
@@ -149,11 +154,11 @@ /** | ||
private readonly _embeddings?; | ||
private readonly _awsCredentials?; | ||
constructor(tbl: any, name: string); | ||
private readonly _options; | ||
constructor(tbl: any, name: string, options: ConnectionOptions); | ||
/** | ||
* @param tbl | ||
* @param name | ||
* @param options | ||
* @param embeddings An embedding function to use when interacting with this table | ||
*/ | ||
constructor(tbl: any, name: string, embeddings: EmbeddingFunction<T>); | ||
constructor(tbl: any, name: string, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials); | ||
constructor(tbl: any, name: string, options: ConnectionOptions, embeddings: EmbeddingFunction<T>); | ||
get name(): string; | ||
@@ -160,0 +165,0 @@ /** |
@@ -32,10 +32,17 @@ "use strict"; | ||
Object.defineProperty(exports, "OpenAIEmbeddingFunction", { enumerable: true, get: function () { return openai_1.OpenAIEmbeddingFunction; } }); | ||
/** | ||
* Connect to a LanceDB instance at the given URI | ||
* @param uri The uri of the database. | ||
*/ | ||
function connect(uri) { | ||
function connect(arg) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const db = yield databaseNew(uri); | ||
return new LocalConnection(db, uri); | ||
let opts; | ||
if (typeof arg === 'string') { | ||
opts = { uri: arg }; | ||
} | ||
else { | ||
// opts = { uri: arg.uri, awsCredentials = arg.awsCredentials } | ||
opts = Object.assign({ | ||
uri: '', | ||
awsCredentials: undefined | ||
}, arg); | ||
} | ||
const db = yield databaseNew(opts.uri); | ||
return new LocalConnection(db, opts); | ||
}); | ||
@@ -48,8 +55,8 @@ } | ||
class LocalConnection { | ||
constructor(db, uri) { | ||
this._uri = uri; | ||
constructor(db, options) { | ||
this._options = options; | ||
this._db = db; | ||
} | ||
get uri() { | ||
return this._uri; | ||
return this._options.uri; | ||
} | ||
@@ -64,9 +71,14 @@ /** | ||
} | ||
openTable(name, embeddings, awsCredentials) { | ||
openTable(name, embeddings) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const tbl = yield databaseOpenTable.call(this._db, name); | ||
return new LocalTable(tbl, name, embeddings, awsCredentials); | ||
if (embeddings !== undefined) { | ||
return new LocalTable(tbl, name, this._options, embeddings); | ||
} | ||
else { | ||
return new LocalTable(tbl, name, this._options); | ||
} | ||
}); | ||
} | ||
createTable(name, data, mode, embeddings, awsCredentials) { | ||
createTable(name, data, mode, embeddings) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -77,11 +89,16 @@ if (mode === undefined) { | ||
const createArgs = [this._db, name, yield (0, arrow_1.fromRecordsToBuffer)(data, embeddings), mode.toLowerCase()]; | ||
if (awsCredentials !== undefined) { | ||
createArgs.push(awsCredentials.accessKeyId); | ||
createArgs.push(awsCredentials.secretKey); | ||
if (awsCredentials.sessionToken !== undefined) { | ||
createArgs.push(awsCredentials.sessionToken); | ||
if (this._options.awsCredentials !== undefined) { | ||
createArgs.push(this._options.awsCredentials.accessKeyId); | ||
createArgs.push(this._options.awsCredentials.secretKey); | ||
if (this._options.awsCredentials.sessionToken !== undefined) { | ||
createArgs.push(this._options.awsCredentials.sessionToken); | ||
} | ||
} | ||
const tbl = yield tableCreate.call(...createArgs); | ||
return new LocalTable(tbl, name, embeddings, awsCredentials); | ||
if (embeddings !== undefined) { | ||
return new LocalTable(tbl, name, this._options, embeddings); | ||
} | ||
else { | ||
return new LocalTable(tbl, name, this._options); | ||
} | ||
}); | ||
@@ -108,7 +125,7 @@ } | ||
class LocalTable { | ||
constructor(tbl, name, embeddings, awsCredentials) { | ||
constructor(tbl, name, options, embeddings) { | ||
this._tbl = tbl; | ||
this._name = name; | ||
this._embeddings = embeddings; | ||
this._awsCredentials = awsCredentials; | ||
this._options = options; | ||
} | ||
@@ -134,7 +151,7 @@ get name() { | ||
const callArgs = [this._tbl, yield (0, arrow_1.fromRecordsToBuffer)(data, this._embeddings), WriteMode.Append.toString()]; | ||
if (this._awsCredentials !== undefined) { | ||
callArgs.push(this._awsCredentials.accessKeyId); | ||
callArgs.push(this._awsCredentials.secretKey); | ||
if (this._awsCredentials.sessionToken !== undefined) { | ||
callArgs.push(this._awsCredentials.sessionToken); | ||
if (this._options.awsCredentials !== undefined) { | ||
callArgs.push(this._options.awsCredentials.accessKeyId); | ||
callArgs.push(this._options.awsCredentials.secretKey); | ||
if (this._options.awsCredentials.sessionToken !== undefined) { | ||
callArgs.push(this._options.awsCredentials.sessionToken); | ||
} | ||
@@ -154,7 +171,7 @@ } | ||
const callArgs = [this._tbl, yield (0, arrow_1.fromRecordsToBuffer)(data, this._embeddings), WriteMode.Overwrite.toString()]; | ||
if (this._awsCredentials !== undefined) { | ||
callArgs.push(this._awsCredentials.accessKeyId); | ||
callArgs.push(this._awsCredentials.secretKey); | ||
if (this._awsCredentials.sessionToken !== undefined) { | ||
callArgs.push(this._awsCredentials.sessionToken); | ||
if (this._options.awsCredentials !== undefined) { | ||
callArgs.push(this._options.awsCredentials.accessKeyId); | ||
callArgs.push(this._options.awsCredentials.secretKey); | ||
if (this._options.awsCredentials.sessionToken !== undefined) { | ||
callArgs.push(this._options.awsCredentials.sessionToken); | ||
} | ||
@@ -161,0 +178,0 @@ } |
@@ -34,10 +34,10 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const uri = `${baseUri}/valid_url`; | ||
const table = yield createTestDB(uri, 2, 20); | ||
const con = yield lancedb.connect(uri); | ||
chai_1.assert.equal(con.uri, uri); | ||
const opts = { uri: `${baseUri}/valid_url` }; | ||
const table = yield createTestDB(opts, 2, 20); | ||
const con = yield lancedb.connect(opts); | ||
chai_1.assert.equal(con.uri, opts.uri); | ||
const results = yield table.search([0.1, 0.3]).limit(5).execute(); | ||
chai_1.assert.equal(results.length, 5); | ||
}); | ||
}); | ||
}).timeout(10000); | ||
} | ||
@@ -47,6 +47,28 @@ else { | ||
} | ||
if (process.env.TEST_S3_BASE_URL != null && process.env.TEST_AWS_ACCESS_KEY_ID != null && process.env.TEST_AWS_SECRET_ACCESS_KEY != null) { | ||
const baseUri = process.env.TEST_S3_BASE_URL; | ||
it('use custom credentials', function () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const opts = { | ||
uri: `${baseUri}/custom_credentials`, | ||
awsCredentials: { | ||
accessKeyId: process.env.TEST_AWS_ACCESS_KEY_ID, | ||
secretKey: process.env.TEST_AWS_SECRET_ACCESS_KEY | ||
} | ||
}; | ||
const table = yield createTestDB(opts, 2, 20); | ||
const con = yield lancedb.connect(opts); | ||
chai_1.assert.equal(con.uri, opts.uri); | ||
const results = yield table.search([0.1, 0.3]).limit(5).execute(); | ||
chai_1.assert.equal(results.length, 5); | ||
}); | ||
}).timeout(10000); | ||
} | ||
else { | ||
mocha_1.describe.skip('Skip S3 test', function () { }); | ||
} | ||
}); | ||
function createTestDB(uri, numDimensions = 2, numRows = 2) { | ||
function createTestDB(opts, numDimensions = 2, numRows = 2) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const con = yield lancedb.connect(uri); | ||
const con = yield lancedb.connect(opts); | ||
const data = []; | ||
@@ -53,0 +75,0 @@ for (let i = 0; i < numRows; i++) { |
@@ -43,2 +43,20 @@ "use strict"; | ||
}); | ||
it('should accept an options object', function () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const uri = yield createTestDB(); | ||
const con = yield lancedb.connect({ uri }); | ||
assert.equal(con.uri, uri); | ||
}); | ||
}); | ||
it('should accept custom aws credentials', function () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const uri = yield createTestDB(); | ||
const awsCredentials = { | ||
accessKeyId: '', | ||
secretKey: '' | ||
}; | ||
const con = yield lancedb.connect({ uri, awsCredentials }); | ||
assert.equal(con.uri, uri); | ||
}); | ||
}); | ||
it('should return the existing table names', function () { | ||
@@ -45,0 +63,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -15,27 +15,24 @@ // Copyright 2023 Lance Developers. | ||
const { currentTarget } = require('@neon-rs/load'); | ||
let nativeLib; | ||
function getPlatformLibrary() { | ||
if (process.platform === "darwin" && process.arch == "arm64") { | ||
return require('./aarch64-apple-darwin.node'); | ||
} else if (process.platform === "darwin" && process.arch == "x64") { | ||
return require('./x86_64-apple-darwin.node'); | ||
} else if (process.platform === "linux" && process.arch == "x64") { | ||
return require('./x86_64-unknown-linux-gnu.node'); | ||
} else { | ||
throw new Error(`vectordb: unsupported platform ${process.platform}_${process.arch}. Please file a bug report at https://github.com/lancedb/lancedb/issues`) | ||
} | ||
} | ||
try { | ||
nativeLib = require('./index.node') | ||
nativeLib = require(`vectordb-${currentTarget()}`); | ||
} catch (e) { | ||
if (e.code === "MODULE_NOT_FOUND") { | ||
nativeLib = getPlatformLibrary(); | ||
} else { | ||
throw new Error('vectordb: failed to load native library. Please file a bug report at https://github.com/lancedb/lancedb/issues'); | ||
} | ||
try { | ||
// Might be developing locally, so try that. But don't expose that error | ||
// to the user. | ||
nativeLib = require("./index.node"); | ||
} catch { | ||
throw new Error(`vectordb: failed to load native library. | ||
You may need to run \`npm install vectordb-${currentTarget()}\`. | ||
If that does not work, please file a bug report at https://github.com/lancedb/lancedb/issues | ||
Source error: ${e}`); | ||
} | ||
} | ||
module.exports = nativeLib | ||
// Dynamic require for runtime. | ||
module.exports = nativeLib; |
{ | ||
"name": "vectordb", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"description": " Serverless, low-latency vector database for AI applications", | ||
@@ -9,7 +9,9 @@ "main": "dist/index.js", | ||
"tsc": "tsc -b", | ||
"build": "cargo-cp-artifact --artifact cdylib vectordb-node index.node -- cargo build --message-format=json-render-diagnostics", | ||
"build": "cargo-cp-artifact --artifact cdylib vectordb-node index.node -- cargo build --message-format=json", | ||
"build-release": "npm run build -- --release", | ||
"test": "npm run tsc; mocha -recursive dist/test", | ||
"lint": "eslint src --ext .js,.ts", | ||
"clean": "rm -rf node_modules *.node dist/" | ||
"clean": "rm -rf node_modules *.node dist/", | ||
"pack-build": "neon pack-build", | ||
"check-npm": "printenv && which node && which npm && npm --version" | ||
}, | ||
@@ -29,2 +31,3 @@ "repository": { | ||
"devDependencies": { | ||
"@neon-rs/cli": "^0.0.74", | ||
"@types/chai": "^4.3.4", | ||
@@ -57,4 +60,27 @@ "@types/chai-as-promised": "^7.1.5", | ||
"@apache-arrow/ts": "^12.0.0", | ||
"@neon-rs/load": "^0.0.74", | ||
"apache-arrow": "^12.0.0" | ||
}, | ||
"os": [ | ||
"darwin", | ||
"linux" | ||
], | ||
"cpu": [ | ||
"x64", | ||
"arm64" | ||
], | ||
"neon": { | ||
"targets": { | ||
"x86_64-apple-darwin": "vectordb-darwin-x64", | ||
"aarch64-apple-darwin": "vectordb-darwin-arm64", | ||
"x86_64-unknown-linux-gnu": "vectordb-linux-x64-gnu", | ||
"aarch64-unknown-linux-gnu": "vectordb-linux-arm64-gnu" | ||
} | ||
}, | ||
"optionalDependencies": { | ||
"vectordb-darwin-arm64": "0.1.13", | ||
"vectordb-darwin-x64": "0.1.13", | ||
"vectordb-linux-x64-gnu": "0.1.13", | ||
"vectordb-linux-arm64-gnu": "0.1.13" | ||
} | ||
} |
@@ -11,2 +11,6 @@ # LanceDB | ||
This will download the appropriate native library for your platform. We currently | ||
support x86_64 Linux, aarch64 Linux, Intel MacOS, and ARM (M1/M2) MacOS. We do not | ||
yet support Windows or musl-based Linux (such as Alpine Linux). | ||
## Usage | ||
@@ -30,8 +34,30 @@ | ||
Run the tests with | ||
To build everything fresh: | ||
```bash | ||
npm install | ||
npm run tsc | ||
npm run build | ||
``` | ||
Then you should be able to run the tests with: | ||
```bash | ||
npm test | ||
``` | ||
### Rebuilding Rust library | ||
```bash | ||
npm run build | ||
``` | ||
### Rebuilding Typescript | ||
```bash | ||
npm run tsc | ||
``` | ||
### Fix lints | ||
To run the linter and have it automatically fix all errors | ||
@@ -38,0 +64,0 @@ |
109
src/index.ts
@@ -30,2 +30,15 @@ // Copyright 2023 Lance Developers. | ||
export interface AwsCredentials { | ||
accessKeyId: string | ||
secretKey: string | ||
sessionToken?: string | ||
} | ||
export interface ConnectionOptions { | ||
uri: string | ||
awsCredentials?: AwsCredentials | ||
} | ||
/** | ||
@@ -35,5 +48,17 @@ * Connect to a LanceDB instance at the given URI | ||
*/ | ||
export async function connect (uri: string): Promise<Connection> { | ||
const db = await databaseNew(uri) | ||
return new LocalConnection(db, uri) | ||
export async function connect (uri: string): Promise<Connection> | ||
export async function connect (opts: Partial<ConnectionOptions>): Promise<Connection> | ||
export async function connect (arg: string | Partial<ConnectionOptions>): Promise<Connection> { | ||
let opts: ConnectionOptions | ||
if (typeof arg === 'string') { | ||
opts = { uri: arg } | ||
} else { | ||
// opts = { uri: arg.uri, awsCredentials = arg.awsCredentials } | ||
opts = Object.assign({ | ||
uri: '', | ||
awsCredentials: undefined | ||
}, arg) | ||
} | ||
const db = await databaseNew(opts.uri) | ||
return new LocalConnection(db, opts) | ||
} | ||
@@ -127,10 +152,2 @@ | ||
export interface AwsCredentials { | ||
accessKeyId: string | ||
secretKey: string | ||
sessionToken?: string | ||
} | ||
/** | ||
@@ -140,7 +157,7 @@ * A connection to a LanceDB database. | ||
export class LocalConnection implements Connection { | ||
private readonly _uri: string | ||
private readonly _options: ConnectionOptions | ||
private readonly _db: any | ||
constructor (db: any, uri: string) { | ||
this._uri = uri | ||
constructor (db: any, options: ConnectionOptions) { | ||
this._options = options | ||
this._db = db | ||
@@ -150,3 +167,3 @@ } | ||
get uri (): string { | ||
return this._uri | ||
return this._options.uri | ||
} | ||
@@ -174,6 +191,10 @@ | ||
async openTable<T> (name: string, embeddings: EmbeddingFunction<T>): Promise<Table<T>> | ||
async openTable<T> (name: string, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials): Promise<Table<T>> | ||
async openTable<T> (name: string, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials): Promise<Table<T>> { | ||
async openTable<T> (name: string, embeddings?: EmbeddingFunction<T>): Promise<Table<T>> | ||
async openTable<T> (name: string, embeddings?: EmbeddingFunction<T>): Promise<Table<T>> { | ||
const tbl = await databaseOpenTable.call(this._db, name) | ||
return new LocalTable(tbl, name, embeddings, awsCredentials) | ||
if (embeddings !== undefined) { | ||
return new LocalTable(tbl, name, this._options, embeddings) | ||
} else { | ||
return new LocalTable(tbl, name, this._options) | ||
} | ||
} | ||
@@ -200,4 +221,4 @@ | ||
async createTable<T> (name: string, data: Array<Record<string, unknown>>, mode: WriteMode, embeddings: EmbeddingFunction<T>): Promise<Table<T>> | ||
async createTable<T> (name: string, data: Array<Record<string, unknown>>, mode: WriteMode, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials): Promise<Table<T>> | ||
async createTable<T> (name: string, data: Array<Record<string, unknown>>, mode: WriteMode, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials): Promise<Table<T>> { | ||
async createTable<T> (name: string, data: Array<Record<string, unknown>>, mode: WriteMode, embeddings?: EmbeddingFunction<T>): Promise<Table<T>> | ||
async createTable<T> (name: string, data: Array<Record<string, unknown>>, mode: WriteMode, embeddings?: EmbeddingFunction<T>): Promise<Table<T>> { | ||
if (mode === undefined) { | ||
@@ -208,7 +229,7 @@ mode = WriteMode.Create | ||
const createArgs = [this._db, name, await fromRecordsToBuffer(data, embeddings), mode.toLowerCase()] | ||
if (awsCredentials !== undefined) { | ||
createArgs.push(awsCredentials.accessKeyId) | ||
createArgs.push(awsCredentials.secretKey) | ||
if (awsCredentials.sessionToken !== undefined) { | ||
createArgs.push(awsCredentials.sessionToken) | ||
if (this._options.awsCredentials !== undefined) { | ||
createArgs.push(this._options.awsCredentials.accessKeyId) | ||
createArgs.push(this._options.awsCredentials.secretKey) | ||
if (this._options.awsCredentials.sessionToken !== undefined) { | ||
createArgs.push(this._options.awsCredentials.sessionToken) | ||
} | ||
@@ -219,3 +240,7 @@ } | ||
return new LocalTable(tbl, name, embeddings, awsCredentials) | ||
if (embeddings !== undefined) { | ||
return new LocalTable(tbl, name, this._options, embeddings) | ||
} else { | ||
return new LocalTable(tbl, name, this._options) | ||
} | ||
} | ||
@@ -242,17 +267,17 @@ | ||
private readonly _embeddings?: EmbeddingFunction<T> | ||
private readonly _awsCredentials?: AwsCredentials | ||
private readonly _options: ConnectionOptions | ||
constructor (tbl: any, name: string) | ||
constructor (tbl: any, name: string, options: ConnectionOptions) | ||
/** | ||
* @param tbl | ||
* @param name | ||
* @param options | ||
* @param embeddings An embedding function to use when interacting with this table | ||
*/ | ||
constructor (tbl: any, name: string, embeddings: EmbeddingFunction<T>) | ||
constructor (tbl: any, name: string, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials) | ||
constructor (tbl: any, name: string, embeddings?: EmbeddingFunction<T>, awsCredentials?: AwsCredentials) { | ||
constructor (tbl: any, name: string, options: ConnectionOptions, embeddings: EmbeddingFunction<T>) | ||
constructor (tbl: any, name: string, options: ConnectionOptions, embeddings?: EmbeddingFunction<T>) { | ||
this._tbl = tbl | ||
this._name = name | ||
this._embeddings = embeddings | ||
this._awsCredentials = awsCredentials | ||
this._options = options | ||
} | ||
@@ -280,7 +305,7 @@ | ||
const callArgs = [this._tbl, await fromRecordsToBuffer(data, this._embeddings), WriteMode.Append.toString()] | ||
if (this._awsCredentials !== undefined) { | ||
callArgs.push(this._awsCredentials.accessKeyId) | ||
callArgs.push(this._awsCredentials.secretKey) | ||
if (this._awsCredentials.sessionToken !== undefined) { | ||
callArgs.push(this._awsCredentials.sessionToken) | ||
if (this._options.awsCredentials !== undefined) { | ||
callArgs.push(this._options.awsCredentials.accessKeyId) | ||
callArgs.push(this._options.awsCredentials.secretKey) | ||
if (this._options.awsCredentials.sessionToken !== undefined) { | ||
callArgs.push(this._options.awsCredentials.sessionToken) | ||
} | ||
@@ -299,7 +324,7 @@ } | ||
const callArgs = [this._tbl, await fromRecordsToBuffer(data, this._embeddings), WriteMode.Overwrite.toString()] | ||
if (this._awsCredentials !== undefined) { | ||
callArgs.push(this._awsCredentials.accessKeyId) | ||
callArgs.push(this._awsCredentials.secretKey) | ||
if (this._awsCredentials.sessionToken !== undefined) { | ||
callArgs.push(this._awsCredentials.sessionToken) | ||
if (this._options.awsCredentials !== undefined) { | ||
callArgs.push(this._options.awsCredentials.accessKeyId) | ||
callArgs.push(this._options.awsCredentials.secretKey) | ||
if (this._options.awsCredentials.sessionToken !== undefined) { | ||
callArgs.push(this._options.awsCredentials.sessionToken) | ||
} | ||
@@ -306,0 +331,0 @@ } |
@@ -21,2 +21,3 @@ // Copyright 2023 Lance Developers. | ||
import * as lancedb from '../index' | ||
import { type ConnectionOptions } from '../index' | ||
@@ -27,17 +28,38 @@ describe('LanceDB S3 client', function () { | ||
it('should have a valid url', async function () { | ||
const uri = `${baseUri}/valid_url` | ||
const table = await createTestDB(uri, 2, 20) | ||
const con = await lancedb.connect(uri) | ||
assert.equal(con.uri, uri) | ||
const opts = { uri: `${baseUri}/valid_url` } | ||
const table = await createTestDB(opts, 2, 20) | ||
const con = await lancedb.connect(opts) | ||
assert.equal(con.uri, opts.uri) | ||
const results = await table.search([0.1, 0.3]).limit(5).execute() | ||
assert.equal(results.length, 5) | ||
}) | ||
}).timeout(10_000) | ||
} else { | ||
describe.skip('Skip S3 test', function () {}) | ||
} | ||
if (process.env.TEST_S3_BASE_URL != null && process.env.TEST_AWS_ACCESS_KEY_ID != null && process.env.TEST_AWS_SECRET_ACCESS_KEY != null) { | ||
const baseUri = process.env.TEST_S3_BASE_URL | ||
it('use custom credentials', async function () { | ||
const opts: ConnectionOptions = { | ||
uri: `${baseUri}/custom_credentials`, | ||
awsCredentials: { | ||
accessKeyId: process.env.TEST_AWS_ACCESS_KEY_ID as string, | ||
secretKey: process.env.TEST_AWS_SECRET_ACCESS_KEY as string | ||
} | ||
} | ||
const table = await createTestDB(opts, 2, 20) | ||
const con = await lancedb.connect(opts) | ||
assert.equal(con.uri, opts.uri) | ||
const results = await table.search([0.1, 0.3]).limit(5).execute() | ||
assert.equal(results.length, 5) | ||
}).timeout(10_000) | ||
} else { | ||
describe.skip('Skip S3 test', function () {}) | ||
} | ||
}) | ||
async function createTestDB (uri: string, numDimensions: number = 2, numRows: number = 2): Promise<lancedb.Table> { | ||
const con = await lancedb.connect(uri) | ||
async function createTestDB (opts: ConnectionOptions, numDimensions: number = 2, numRows: number = 2): Promise<lancedb.Table> { | ||
const con = await lancedb.connect(opts) | ||
@@ -44,0 +66,0 @@ const data = [] |
@@ -21,3 +21,3 @@ // Copyright 2023 LanceDB Developers. | ||
import * as lancedb from '../index' | ||
import { type EmbeddingFunction, MetricType, Query, WriteMode } from '../index' | ||
import { type AwsCredentials, type EmbeddingFunction, MetricType, Query, WriteMode } from '../index' | ||
@@ -36,2 +36,18 @@ const expect = chai.expect | ||
it('should accept an options object', async function () { | ||
const uri = await createTestDB() | ||
const con = await lancedb.connect({ uri }) | ||
assert.equal(con.uri, uri) | ||
}) | ||
it('should accept custom aws credentials', async function () { | ||
const uri = await createTestDB() | ||
const awsCredentials: AwsCredentials = { | ||
accessKeyId: '', | ||
secretKey: '' | ||
} | ||
const con = await lancedb.connect({ uri, awsCredentials }) | ||
assert.equal(con.uri, uri) | ||
}) | ||
it('should return the existing table names', async function () { | ||
@@ -38,0 +54,0 @@ const uri = await createTestDB() |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
2551
72
0
105956
7
25
36
12
+ Added@neon-rs/load@^0.0.74
+ Added@neon-rs/load@0.0.74(transitive)
+ Addedvectordb-darwin-arm64@0.1.13(transitive)
+ Addedvectordb-darwin-x64@0.1.13(transitive)
+ Addedvectordb-linux-x64-gnu@0.1.13(transitive)