@lancedb/lancedb 0.22.0-beta.1 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/arrow.js CHANGED
@@ -417,7 +417,11 @@ function* rowPathsAndValues(row, basePath = []) {
417
417
  yield* rowPathsAndValues(value, [...basePath, key]);
418
418
  }
419
419
  else {
420
- yield [[...basePath, key], value];
420
+ // Skip undefined values - they should be treated the same as missing fields
421
+ // for embedding function purposes
422
+ if (value !== undefined) {
423
+ yield [[...basePath, key], value];
424
+ }
421
425
  }
422
426
  }
423
427
  }
@@ -596,7 +600,7 @@ function transposeData(data, field, path = []) {
596
600
  }
597
601
  return current;
598
602
  });
599
- return makeVector(values, field.type);
603
+ return makeVector(values, field.type, undefined, field.nullable);
600
604
  }
601
605
  }
602
606
  /**
@@ -633,8 +637,26 @@ function makeListVector(lists) {
633
637
  return listBuilder.finish().toVector();
634
638
  }
635
639
  /** Helper function to convert an Array of JS values to an Arrow Vector */
636
- function makeVector(values, type, stringAsDictionary) {
640
+ function makeVector(values, type, stringAsDictionary, nullable) {
637
641
  if (type !== undefined) {
642
+ // Convert undefined values to null for nullable fields
643
+ if (nullable) {
644
+ values = values.map((v) => (v === undefined ? null : v));
645
+ }
646
+ // workaround for: https://github.com/apache/arrow-js/issues/68
647
+ if (apache_arrow_1.DataType.isBool(type)) {
648
+ const hasNonNullValue = values.some((v) => v !== null && v !== undefined);
649
+ if (!hasNonNullValue) {
650
+ const nullBitmap = new Uint8Array(Math.ceil(values.length / 8));
651
+ const data = (0, apache_arrow_1.makeData)({
652
+ type: type,
653
+ length: values.length,
654
+ nullCount: values.length,
655
+ nullBitmap,
656
+ });
657
+ return (0, apache_arrow_1.makeVector)(data);
658
+ }
659
+ }
638
660
  // No need for inference, let Arrow create it
639
661
  if (type instanceof apache_arrow_1.Int) {
640
662
  if (apache_arrow_1.DataType.isInt(type) && type.bitWidth === 64) {
@@ -741,7 +763,7 @@ async function applyEmbeddingsFromMetadata(table, schema) {
741
763
  for (const field of schema.fields) {
742
764
  if (!(field.name in columns)) {
743
765
  const nullValues = new Array(table.numRows).fill(null);
744
- columns[field.name] = makeVector(nullValues, field.type);
766
+ columns[field.name] = makeVector(nullValues, field.type, undefined, field.nullable);
745
767
  }
746
768
  }
747
769
  const newTable = new apache_arrow_1.Table(columns);
@@ -793,7 +815,7 @@ async function applyEmbeddings(table, embeddings, schema) {
793
815
  else if (schema != null) {
794
816
  const destField = schema.fields.find((f) => f.name === destColumn);
795
817
  if (destField != null) {
796
- newColumns[destColumn] = makeVector([], destField.type);
818
+ newColumns[destColumn] = makeVector([], destField.type, undefined, destField.nullable);
797
819
  }
798
820
  else {
799
821
  throw new Error(`Attempt to apply embeddings to an empty table failed because schema was missing embedding column '${destColumn}'`);
@@ -204,6 +204,28 @@ export declare abstract class Connection {
204
204
  * @param {string[]} namespace The namespace to drop tables from (defaults to root namespace).
205
205
  */
206
206
  abstract dropAllTables(namespace?: string[]): Promise<void>;
207
+ /**
208
+ * Clone a table from a source table.
209
+ *
210
+ * A shallow clone creates a new table that shares the underlying data files
211
+ * with the source table but has its own independent manifest. This allows
212
+ * both the source and cloned tables to evolve independently while initially
213
+ * sharing the same data, deletion, and index files.
214
+ *
215
+ * @param {string} targetTableName - The name of the target table to create.
216
+ * @param {string} sourceUri - The URI of the source table to clone from.
217
+ * @param {object} options - Clone options.
218
+ * @param {string[]} options.targetNamespace - The namespace for the target table (defaults to root namespace).
219
+ * @param {number} options.sourceVersion - The version of the source table to clone.
220
+ * @param {string} options.sourceTag - The tag of the source table to clone.
221
+ * @param {boolean} options.isShallow - Whether to perform a shallow clone (defaults to true).
222
+ */
223
+ abstract cloneTable(targetTableName: string, sourceUri: string, options?: {
224
+ targetNamespace?: string[];
225
+ sourceVersion?: number;
226
+ sourceTag?: string;
227
+ isShallow?: boolean;
228
+ }): Promise<Table>;
207
229
  }
208
230
  /** @hideconstructor */
209
231
  export declare class LocalConnection extends Connection {
@@ -215,6 +237,12 @@ export declare class LocalConnection extends Connection {
215
237
  display(): string;
216
238
  tableNames(namespaceOrOptions?: string[] | Partial<TableNamesOptions>, options?: Partial<TableNamesOptions>): Promise<string[]>;
217
239
  openTable(name: string, namespace?: string[], options?: Partial<OpenTableOptions>): Promise<Table>;
240
+ cloneTable(targetTableName: string, sourceUri: string, options?: {
241
+ targetNamespace?: string[];
242
+ sourceVersion?: number;
243
+ sourceTag?: string;
244
+ isShallow?: boolean;
245
+ }): Promise<Table>;
218
246
  private getStorageOptions;
219
247
  createTable(nameOrOptions: string | ({
220
248
  name: string;
@@ -71,6 +71,10 @@ class LocalConnection extends Connection {
71
71
  const innerTable = await this.inner.openTable(name, namespace ?? [], cleanseStorageOptions(options?.storageOptions), options?.indexCacheSize);
72
72
  return new table_1.LocalTable(innerTable);
73
73
  }
74
+ async cloneTable(targetTableName, sourceUri, options) {
75
+ const innerTable = await this.inner.cloneTable(targetTableName, sourceUri, options?.targetNamespace ?? [], options?.sourceVersion ?? null, options?.sourceTag ?? null, options?.isShallow ?? true);
76
+ return new table_1.LocalTable(innerTable);
77
+ }
74
78
  getStorageOptions(options) {
75
79
  if (options?.dataStorageVersion !== undefined) {
76
80
  if (options.storageOptions === undefined) {
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Header providers for LanceDB remote connections.
3
+ *
4
+ * This module provides a flexible header management framework for LanceDB remote
5
+ * connections, allowing users to implement custom header strategies for
6
+ * authentication, request tracking, custom metadata, or any other header-based
7
+ * requirements.
8
+ *
9
+ * @module header
10
+ */
11
+ /**
12
+ * Abstract base class for providing custom headers for each request.
13
+ *
14
+ * Users can implement this interface to provide dynamic headers for various purposes
15
+ * such as authentication (OAuth tokens, API keys), request tracking (correlation IDs),
16
+ * custom metadata, or any other header-based requirements. The provider is called
17
+ * before each request to ensure fresh header values are always used.
18
+ *
19
+ * @example
20
+ * Simple JWT token provider:
21
+ * ```typescript
22
+ * class JWTProvider extends HeaderProvider {
23
+ * constructor(private token: string) {
24
+ * super();
25
+ * }
26
+ *
27
+ * getHeaders(): Record<string, string> {
28
+ * return { authorization: `Bearer ${this.token}` };
29
+ * }
30
+ * }
31
+ * ```
32
+ *
33
+ * @example
34
+ * Provider with request tracking:
35
+ * ```typescript
36
+ * class RequestTrackingProvider extends HeaderProvider {
37
+ * constructor(private sessionId: string) {
38
+ * super();
39
+ * }
40
+ *
41
+ * getHeaders(): Record<string, string> {
42
+ * return {
43
+ * "X-Session-Id": this.sessionId,
44
+ * "X-Request-Id": `req-${Date.now()}`
45
+ * };
46
+ * }
47
+ * }
48
+ * ```
49
+ */
50
+ export declare abstract class HeaderProvider {
51
+ /**
52
+ * Get the latest headers to be added to requests.
53
+ *
54
+ * This method is called before each request to the remote LanceDB server.
55
+ * Implementations should return headers that will be merged with existing headers.
56
+ *
57
+ * @returns Dictionary of header names to values to add to the request.
58
+ * @throws If unable to fetch headers, the exception will be propagated and the request will fail.
59
+ */
60
+ abstract getHeaders(): Record<string, string>;
61
+ }
62
+ /**
63
+ * Example implementation: A simple header provider that returns static headers.
64
+ *
65
+ * This is an example implementation showing how to create a HeaderProvider
66
+ * for cases where headers don't change during the session.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const provider = new StaticHeaderProvider({
71
+ * authorization: "Bearer my-token",
72
+ * "X-Custom-Header": "custom-value"
73
+ * });
74
+ * const headers = provider.getHeaders();
75
+ * // Returns: {authorization: 'Bearer my-token', 'X-Custom-Header': 'custom-value'}
76
+ * ```
77
+ */
78
+ export declare class StaticHeaderProvider extends HeaderProvider {
79
+ private _headers;
80
+ /**
81
+ * Initialize with static headers.
82
+ * @param headers - Headers to return for every request.
83
+ */
84
+ constructor(headers: Record<string, string>);
85
+ /**
86
+ * Return the static headers.
87
+ * @returns Copy of the static headers.
88
+ */
89
+ getHeaders(): Record<string, string>;
90
+ }
91
+ /**
92
+ * Token response from OAuth provider.
93
+ * @public
94
+ */
95
+ export interface TokenResponse {
96
+ accessToken: string;
97
+ expiresIn?: number;
98
+ }
99
+ /**
100
+ * Example implementation: OAuth token provider with automatic refresh.
101
+ *
102
+ * This is an example implementation showing how to manage OAuth tokens
103
+ * with automatic refresh when they expire.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * async function fetchToken(): Promise<TokenResponse> {
108
+ * const response = await fetch("https://oauth.example.com/token", {
109
+ * method: "POST",
110
+ * body: JSON.stringify({
111
+ * grant_type: "client_credentials",
112
+ * client_id: "your-client-id",
113
+ * client_secret: "your-client-secret"
114
+ * }),
115
+ * headers: { "Content-Type": "application/json" }
116
+ * });
117
+ * const data = await response.json();
118
+ * return {
119
+ * accessToken: data.access_token,
120
+ * expiresIn: data.expires_in
121
+ * };
122
+ * }
123
+ *
124
+ * const provider = new OAuthHeaderProvider(fetchToken);
125
+ * const headers = provider.getHeaders();
126
+ * // Returns: {"authorization": "Bearer <your-token>"}
127
+ * ```
128
+ */
129
+ export declare class OAuthHeaderProvider extends HeaderProvider {
130
+ private _tokenFetcher;
131
+ private _refreshBufferSeconds;
132
+ private _currentToken;
133
+ private _tokenExpiresAt;
134
+ private _refreshPromise;
135
+ /**
136
+ * Initialize the OAuth provider.
137
+ * @param tokenFetcher - Function to fetch new tokens. Should return object with 'accessToken' and optionally 'expiresIn'.
138
+ * @param refreshBufferSeconds - Seconds before expiry to refresh token. Default 300 (5 minutes).
139
+ */
140
+ constructor(tokenFetcher: () => Promise<TokenResponse> | TokenResponse, refreshBufferSeconds?: number);
141
+ /**
142
+ * Check if token needs refresh.
143
+ */
144
+ private _needsRefresh;
145
+ /**
146
+ * Refresh the token if it's expired or close to expiring.
147
+ */
148
+ private _refreshTokenIfNeeded;
149
+ /**
150
+ * Get OAuth headers, refreshing token if needed.
151
+ * Note: This is synchronous for now as the Rust implementation expects sync.
152
+ * In a real implementation, this would need to handle async properly.
153
+ * @returns Headers with Bearer token authorization.
154
+ * @throws If unable to fetch or refresh token.
155
+ */
156
+ getHeaders(): Record<string, string>;
157
+ /**
158
+ * Manually refresh the token.
159
+ * Call this before using getHeaders() to ensure token is available.
160
+ */
161
+ refreshToken(): Promise<void>;
162
+ }
package/dist/header.js ADDED
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright The LanceDB Authors
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.OAuthHeaderProvider = exports.StaticHeaderProvider = exports.HeaderProvider = void 0;
6
+ /**
7
+ * Header providers for LanceDB remote connections.
8
+ *
9
+ * This module provides a flexible header management framework for LanceDB remote
10
+ * connections, allowing users to implement custom header strategies for
11
+ * authentication, request tracking, custom metadata, or any other header-based
12
+ * requirements.
13
+ *
14
+ * @module header
15
+ */
16
+ /**
17
+ * Abstract base class for providing custom headers for each request.
18
+ *
19
+ * Users can implement this interface to provide dynamic headers for various purposes
20
+ * such as authentication (OAuth tokens, API keys), request tracking (correlation IDs),
21
+ * custom metadata, or any other header-based requirements. The provider is called
22
+ * before each request to ensure fresh header values are always used.
23
+ *
24
+ * @example
25
+ * Simple JWT token provider:
26
+ * ```typescript
27
+ * class JWTProvider extends HeaderProvider {
28
+ * constructor(private token: string) {
29
+ * super();
30
+ * }
31
+ *
32
+ * getHeaders(): Record<string, string> {
33
+ * return { authorization: `Bearer ${this.token}` };
34
+ * }
35
+ * }
36
+ * ```
37
+ *
38
+ * @example
39
+ * Provider with request tracking:
40
+ * ```typescript
41
+ * class RequestTrackingProvider extends HeaderProvider {
42
+ * constructor(private sessionId: string) {
43
+ * super();
44
+ * }
45
+ *
46
+ * getHeaders(): Record<string, string> {
47
+ * return {
48
+ * "X-Session-Id": this.sessionId,
49
+ * "X-Request-Id": `req-${Date.now()}`
50
+ * };
51
+ * }
52
+ * }
53
+ * ```
54
+ */
55
+ class HeaderProvider {
56
+ }
57
+ exports.HeaderProvider = HeaderProvider;
58
+ /**
59
+ * Example implementation: A simple header provider that returns static headers.
60
+ *
61
+ * This is an example implementation showing how to create a HeaderProvider
62
+ * for cases where headers don't change during the session.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const provider = new StaticHeaderProvider({
67
+ * authorization: "Bearer my-token",
68
+ * "X-Custom-Header": "custom-value"
69
+ * });
70
+ * const headers = provider.getHeaders();
71
+ * // Returns: {authorization: 'Bearer my-token', 'X-Custom-Header': 'custom-value'}
72
+ * ```
73
+ */
74
+ class StaticHeaderProvider extends HeaderProvider {
75
+ _headers;
76
+ /**
77
+ * Initialize with static headers.
78
+ * @param headers - Headers to return for every request.
79
+ */
80
+ constructor(headers) {
81
+ super();
82
+ this._headers = { ...headers };
83
+ }
84
+ /**
85
+ * Return the static headers.
86
+ * @returns Copy of the static headers.
87
+ */
88
+ getHeaders() {
89
+ return { ...this._headers };
90
+ }
91
+ }
92
+ exports.StaticHeaderProvider = StaticHeaderProvider;
93
+ /**
94
+ * Example implementation: OAuth token provider with automatic refresh.
95
+ *
96
+ * This is an example implementation showing how to manage OAuth tokens
97
+ * with automatic refresh when they expire.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * async function fetchToken(): Promise<TokenResponse> {
102
+ * const response = await fetch("https://oauth.example.com/token", {
103
+ * method: "POST",
104
+ * body: JSON.stringify({
105
+ * grant_type: "client_credentials",
106
+ * client_id: "your-client-id",
107
+ * client_secret: "your-client-secret"
108
+ * }),
109
+ * headers: { "Content-Type": "application/json" }
110
+ * });
111
+ * const data = await response.json();
112
+ * return {
113
+ * accessToken: data.access_token,
114
+ * expiresIn: data.expires_in
115
+ * };
116
+ * }
117
+ *
118
+ * const provider = new OAuthHeaderProvider(fetchToken);
119
+ * const headers = provider.getHeaders();
120
+ * // Returns: {"authorization": "Bearer <your-token>"}
121
+ * ```
122
+ */
123
+ class OAuthHeaderProvider extends HeaderProvider {
124
+ _tokenFetcher;
125
+ _refreshBufferSeconds;
126
+ _currentToken = null;
127
+ _tokenExpiresAt = null;
128
+ _refreshPromise = null;
129
+ /**
130
+ * Initialize the OAuth provider.
131
+ * @param tokenFetcher - Function to fetch new tokens. Should return object with 'accessToken' and optionally 'expiresIn'.
132
+ * @param refreshBufferSeconds - Seconds before expiry to refresh token. Default 300 (5 minutes).
133
+ */
134
+ constructor(tokenFetcher, refreshBufferSeconds = 300) {
135
+ super();
136
+ this._tokenFetcher = tokenFetcher;
137
+ this._refreshBufferSeconds = refreshBufferSeconds;
138
+ }
139
+ /**
140
+ * Check if token needs refresh.
141
+ */
142
+ _needsRefresh() {
143
+ if (this._currentToken === null) {
144
+ return true;
145
+ }
146
+ if (this._tokenExpiresAt === null) {
147
+ // No expiration info, assume token is valid
148
+ return false;
149
+ }
150
+ // Refresh if we're within the buffer time of expiration
151
+ const now = Date.now() / 1000;
152
+ return now >= this._tokenExpiresAt - this._refreshBufferSeconds;
153
+ }
154
+ /**
155
+ * Refresh the token if it's expired or close to expiring.
156
+ */
157
+ async _refreshTokenIfNeeded() {
158
+ if (!this._needsRefresh()) {
159
+ return;
160
+ }
161
+ // If refresh is already in progress, wait for it
162
+ if (this._refreshPromise) {
163
+ await this._refreshPromise;
164
+ return;
165
+ }
166
+ // Start refresh
167
+ this._refreshPromise = (async () => {
168
+ try {
169
+ const tokenData = await this._tokenFetcher();
170
+ this._currentToken = tokenData.accessToken;
171
+ if (!this._currentToken) {
172
+ throw new Error("Token fetcher did not return 'accessToken'");
173
+ }
174
+ // Set expiration if provided
175
+ if (tokenData.expiresIn) {
176
+ this._tokenExpiresAt = Date.now() / 1000 + tokenData.expiresIn;
177
+ }
178
+ else {
179
+ // Token doesn't expire or expiration unknown
180
+ this._tokenExpiresAt = null;
181
+ }
182
+ }
183
+ finally {
184
+ this._refreshPromise = null;
185
+ }
186
+ })();
187
+ await this._refreshPromise;
188
+ }
189
+ /**
190
+ * Get OAuth headers, refreshing token if needed.
191
+ * Note: This is synchronous for now as the Rust implementation expects sync.
192
+ * In a real implementation, this would need to handle async properly.
193
+ * @returns Headers with Bearer token authorization.
194
+ * @throws If unable to fetch or refresh token.
195
+ */
196
+ getHeaders() {
197
+ // For simplicity in this example, we assume the token is already fetched
198
+ // In a real implementation, this would need to handle the async nature properly
199
+ if (!this._currentToken && !this._refreshPromise) {
200
+ // Synchronously trigger refresh - this is a limitation of the current implementation
201
+ throw new Error("Token not initialized. Call refreshToken() first or use async initialization.");
202
+ }
203
+ if (!this._currentToken) {
204
+ throw new Error("Failed to obtain OAuth token");
205
+ }
206
+ return { authorization: `Bearer ${this._currentToken}` };
207
+ }
208
+ /**
209
+ * Manually refresh the token.
210
+ * Call this before using getHeaders() to ensure token is available.
211
+ */
212
+ async refreshToken() {
213
+ this._currentToken = null; // Force refresh
214
+ await this._refreshTokenIfNeeded();
215
+ }
216
+ }
217
+ exports.OAuthHeaderProvider = OAuthHeaderProvider;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,15 @@
1
1
  import { Connection } from "./connection";
2
2
  import { ConnectionOptions, Session } from "./native.js";
3
- export { AddColumnsSql, ConnectionOptions, IndexStatistics, IndexConfig, ClientConfig, TimeoutConfig, RetryConfig, OptimizeStats, CompactionStats, RemovalStats, TableStatistics, FragmentStatistics, FragmentSummaryStats, Tags, TagContents, MergeResult, AddResult, AddColumnsResult, AlterColumnsResult, DeleteResult, DropColumnsResult, UpdateResult, } from "./native.js";
3
+ import { HeaderProvider } from "./header";
4
+ export { JsHeaderProvider as NativeJsHeaderProvider } from "./native.js";
5
+ export { AddColumnsSql, ConnectionOptions, IndexStatistics, IndexConfig, ClientConfig, TimeoutConfig, RetryConfig, TlsConfig, OptimizeStats, CompactionStats, RemovalStats, TableStatistics, FragmentStatistics, FragmentSummaryStats, Tags, TagContents, MergeResult, AddResult, AddColumnsResult, AlterColumnsResult, DeleteResult, DropColumnsResult, UpdateResult, } from "./native.js";
4
6
  export { makeArrowTable, MakeArrowTableOptions, Data, VectorColumnOptions, } from "./arrow";
5
7
  export { Connection, CreateTableOptions, TableNamesOptions, OpenTableOptions, } from "./connection";
6
8
  export { Session } from "./native.js";
7
9
  export { ExecutableQuery, Query, QueryBase, VectorQuery, TakeQuery, QueryExecutionOptions, FullTextSearchOptions, RecordBatchIterator, FullTextQuery, MatchQuery, PhraseQuery, BoostQuery, MultiMatchQuery, BooleanQuery, FullTextQueryType, Operator, Occur, } from "./query";
8
10
  export { Index, IndexOptions, IvfPqOptions, IvfFlatOptions, HnswPqOptions, HnswSqOptions, FtsOptions, } from "./indices";
9
11
  export { Table, AddDataOptions, UpdateOptions, OptimizeOptions, Version, ColumnAlteration, } from "./table";
12
+ export { HeaderProvider, StaticHeaderProvider, OAuthHeaderProvider, TokenResponse, } from "./header";
10
13
  export { MergeInsertBuilder, WriteExecutionOptions } from "./merge";
11
14
  export * as embedding from "./embedding";
12
15
  export * as rerankers from "./rerankers";
@@ -35,8 +38,20 @@ export { IntoSql, packBits } from "./util";
35
38
  * {storageOptions: {timeout: "60s"}
36
39
  * });
37
40
  * ```
41
+ * @example
42
+ * Using with a header provider for per-request authentication:
43
+ * ```ts
44
+ * const provider = new StaticHeaderProvider({
45
+ * "X-API-Key": "my-key"
46
+ * });
47
+ * const conn = await connectWithHeaderProvider(
48
+ * "db://host:port",
49
+ * options,
50
+ * provider
51
+ * );
52
+ * ```
38
53
  */
39
- export declare function connect(uri: string, options?: Partial<ConnectionOptions>, session?: Session): Promise<Connection>;
54
+ export declare function connect(uri: string, options?: Partial<ConnectionOptions>, session?: Session, headerProvider?: HeaderProvider | (() => Record<string, string>) | (() => Promise<Record<string, string>>)): Promise<Connection>;
40
55
  /**
41
56
  * Connect to a LanceDB instance at the given URI.
42
57
  *
package/dist/index.js CHANGED
@@ -2,21 +2,24 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  // SPDX-FileCopyrightText: Copyright The LanceDB Authors
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.packBits = exports.rerankers = exports.embedding = exports.MergeInsertBuilder = exports.Table = exports.Index = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.RecordBatchIterator = exports.TakeQuery = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Session = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = exports.TagContents = exports.Tags = void 0;
5
+ exports.packBits = exports.rerankers = exports.embedding = exports.MergeInsertBuilder = exports.OAuthHeaderProvider = exports.StaticHeaderProvider = exports.HeaderProvider = exports.Table = exports.Index = exports.Occur = exports.Operator = exports.FullTextQueryType = exports.BooleanQuery = exports.MultiMatchQuery = exports.BoostQuery = exports.PhraseQuery = exports.MatchQuery = exports.RecordBatchIterator = exports.TakeQuery = exports.VectorQuery = exports.QueryBase = exports.Query = exports.Session = exports.Connection = exports.VectorColumnOptions = exports.MakeArrowTableOptions = exports.makeArrowTable = exports.TagContents = exports.Tags = exports.NativeJsHeaderProvider = void 0;
6
6
  exports.connect = connect;
7
7
  const connection_1 = require("./connection");
8
8
  const native_js_1 = require("./native.js");
9
+ // Re-export native header provider for use with connectWithHeaderProvider
9
10
  var native_js_2 = require("./native.js");
10
- Object.defineProperty(exports, "Tags", { enumerable: true, get: function () { return native_js_2.Tags; } });
11
- Object.defineProperty(exports, "TagContents", { enumerable: true, get: function () { return native_js_2.TagContents; } });
11
+ Object.defineProperty(exports, "NativeJsHeaderProvider", { enumerable: true, get: function () { return native_js_2.JsHeaderProvider; } });
12
+ var native_js_3 = require("./native.js");
13
+ Object.defineProperty(exports, "Tags", { enumerable: true, get: function () { return native_js_3.Tags; } });
14
+ Object.defineProperty(exports, "TagContents", { enumerable: true, get: function () { return native_js_3.TagContents; } });
12
15
  var arrow_1 = require("./arrow");
13
16
  Object.defineProperty(exports, "makeArrowTable", { enumerable: true, get: function () { return arrow_1.makeArrowTable; } });
14
17
  Object.defineProperty(exports, "MakeArrowTableOptions", { enumerable: true, get: function () { return arrow_1.MakeArrowTableOptions; } });
15
18
  Object.defineProperty(exports, "VectorColumnOptions", { enumerable: true, get: function () { return arrow_1.VectorColumnOptions; } });
16
19
  var connection_2 = require("./connection");
17
20
  Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_2.Connection; } });
18
- var native_js_3 = require("./native.js");
19
- Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return native_js_3.Session; } });
21
+ var native_js_4 = require("./native.js");
22
+ Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return native_js_4.Session; } });
20
23
  var query_1 = require("./query");
21
24
  Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
22
25
  Object.defineProperty(exports, "QueryBase", { enumerable: true, get: function () { return query_1.QueryBase; } });
@@ -35,29 +38,66 @@ var indices_1 = require("./indices");
35
38
  Object.defineProperty(exports, "Index", { enumerable: true, get: function () { return indices_1.Index; } });
36
39
  var table_1 = require("./table");
37
40
  Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
41
+ var header_1 = require("./header");
42
+ Object.defineProperty(exports, "HeaderProvider", { enumerable: true, get: function () { return header_1.HeaderProvider; } });
43
+ Object.defineProperty(exports, "StaticHeaderProvider", { enumerable: true, get: function () { return header_1.StaticHeaderProvider; } });
44
+ Object.defineProperty(exports, "OAuthHeaderProvider", { enumerable: true, get: function () { return header_1.OAuthHeaderProvider; } });
38
45
  var merge_1 = require("./merge");
39
46
  Object.defineProperty(exports, "MergeInsertBuilder", { enumerable: true, get: function () { return merge_1.MergeInsertBuilder; } });
40
47
  exports.embedding = require("./embedding");
41
48
  exports.rerankers = require("./rerankers");
42
49
  var util_1 = require("./util");
43
50
  Object.defineProperty(exports, "packBits", { enumerable: true, get: function () { return util_1.packBits; } });
44
- async function connect(uriOrOptions, options) {
51
+ async function connect(uriOrOptions, optionsOrSession, sessionOrHeaderProvider, headerProvider) {
45
52
  let uri;
46
53
  let finalOptions = {};
54
+ let finalHeaderProvider;
47
55
  if (typeof uriOrOptions !== "string") {
56
+ // First overload: connect(options)
48
57
  const { uri: uri_, ...opts } = uriOrOptions;
49
58
  uri = uri_;
50
59
  finalOptions = opts;
51
60
  }
52
61
  else {
62
+ // Second overload: connect(uri, options?, session?, headerProvider?)
53
63
  uri = uriOrOptions;
54
- finalOptions = options || {};
64
+ // Handle optionsOrSession parameter
65
+ if (optionsOrSession && "inner" in optionsOrSession) {
66
+ // Second param is session, so no options provided
67
+ finalOptions = {};
68
+ }
69
+ else {
70
+ // Second param is options
71
+ finalOptions = optionsOrSession || {};
72
+ }
73
+ // Handle sessionOrHeaderProvider parameter
74
+ if (sessionOrHeaderProvider &&
75
+ (typeof sessionOrHeaderProvider === "function" ||
76
+ "getHeaders" in sessionOrHeaderProvider)) {
77
+ // Third param is header provider
78
+ finalHeaderProvider = sessionOrHeaderProvider;
79
+ }
80
+ else {
81
+ // Third param is session, header provider is fourth param
82
+ finalHeaderProvider = headerProvider;
83
+ }
55
84
  }
56
85
  if (!uri) {
57
86
  throw new Error("uri is required");
58
87
  }
59
88
  finalOptions = finalOptions ?? {};
60
89
  finalOptions.storageOptions = (0, connection_1.cleanseStorageOptions)(finalOptions.storageOptions);
61
- const nativeConn = await native_js_1.Connection.new(uri, finalOptions);
90
+ // Create native header provider if one was provided
91
+ let nativeProvider;
92
+ if (finalHeaderProvider) {
93
+ if (typeof finalHeaderProvider === "function") {
94
+ nativeProvider = new native_js_1.JsHeaderProvider(finalHeaderProvider);
95
+ }
96
+ else if (finalHeaderProvider &&
97
+ typeof finalHeaderProvider.getHeaders === "function") {
98
+ nativeProvider = new native_js_1.JsHeaderProvider(async () => finalHeaderProvider.getHeaders());
99
+ }
100
+ }
101
+ const nativeConn = await native_js_1.Connection.new(uri, finalOptions, nativeProvider);
62
102
  return new connection_1.LocalConnection(nativeConn);
63
103
  }
package/dist/native.d.ts CHANGED
@@ -81,12 +81,24 @@ export interface RetryConfig {
81
81
  */
82
82
  statuses?: Array<number>
83
83
  }
84
+ /** TLS/mTLS configuration for the remote HTTP client. */
85
+ export interface TlsConfig {
86
+ /** Path to the client certificate file (PEM format) for mTLS authentication. */
87
+ certFile?: string
88
+ /** Path to the client private key file (PEM format) for mTLS authentication. */
89
+ keyFile?: string
90
+ /** Path to the CA certificate file (PEM format) for server verification. */
91
+ sslCaCert?: string
92
+ /** Whether to verify the hostname in the server's certificate. */
93
+ assertHostname?: boolean
94
+ }
84
95
  export interface ClientConfig {
85
96
  userAgent?: string
86
97
  retryConfig?: RetryConfig
87
98
  timeoutConfig?: TimeoutConfig
88
99
  extraHeaders?: Record<string, string>
89
100
  idDelimiter?: string
101
+ tlsConfig?: TlsConfig
90
102
  }
91
103
  export interface RerankerCallbacks {
92
104
  rerankHybrid: (...args: any[]) => any
@@ -312,7 +324,7 @@ export interface OpenTableOptions {
312
324
  }
313
325
  export class Connection {
314
326
  /** Create a new Connection instance from the given URI. */
315
- static new(uri: string, options: ConnectionOptions): Promise<Connection>
327
+ static new(uri: string, options: ConnectionOptions, headerProvider?: JsHeaderProvider | undefined | null): Promise<Connection>
316
328
  display(): string
317
329
  isOpen(): boolean
318
330
  close(): void
@@ -329,10 +341,20 @@ export class Connection {
329
341
  createTable(name: string, buf: Buffer, mode: string, namespace: Array<string>, storageOptions?: Record<string, string> | undefined | null): Promise<Table>
330
342
  createEmptyTable(name: string, schemaBuf: Buffer, mode: string, namespace: Array<string>, storageOptions?: Record<string, string> | undefined | null): Promise<Table>
331
343
  openTable(name: string, namespace: Array<string>, storageOptions?: Record<string, string> | undefined | null, indexCacheSize?: number | undefined | null): Promise<Table>
344
+ cloneTable(targetTableName: string, sourceUri: string, targetNamespace: Array<string>, sourceVersion: number | undefined | null, sourceTag: string | undefined | null, isShallow: boolean): Promise<Table>
332
345
  /** Drop table with the name. Or raise an error if the table does not exist. */
333
346
  dropTable(name: string, namespace: Array<string>): Promise<void>
334
347
  dropAllTables(namespace: Array<string>): Promise<void>
335
348
  }
349
+ /**
350
+ * JavaScript HeaderProvider implementation that wraps a JavaScript callback.
351
+ * This is the only native header provider - all header provider implementations
352
+ * should provide a JavaScript function that returns headers.
353
+ */
354
+ export class JsHeaderProvider {
355
+ /** Create a new JsHeaderProvider from a JavaScript callback */
356
+ constructor(getHeadersCallback: (...args: any[]) => any)
357
+ }
336
358
  export class Index {
337
359
  static ivfPq(distanceType?: string | undefined | null, numPartitions?: number | undefined | null, numSubVectors?: number | undefined | null, numBits?: number | undefined | null, maxIterations?: number | undefined | null, sampleRate?: number | undefined | null): Index
338
360
  static ivfFlat(distanceType?: string | undefined | null, numPartitions?: number | undefined | null, maxIterations?: number | undefined | null, sampleRate?: number | undefined | null): Index
package/dist/native.js CHANGED
@@ -319,8 +319,9 @@ if (!nativeBinding) {
319
319
  }
320
320
  throw new Error(`Failed to load native binding`);
321
321
  }
322
- const { Connection, Index, RecordBatchIterator, NativeMergeInsertBuilder, Query, VectorQuery, TakeQuery, JsFullTextQuery, Reranker, RrfReranker, Session, Table, TagContents, Tags } = nativeBinding;
322
+ const { Connection, JsHeaderProvider, Index, RecordBatchIterator, NativeMergeInsertBuilder, Query, VectorQuery, TakeQuery, JsFullTextQuery, Reranker, RrfReranker, Session, Table, TagContents, Tags } = nativeBinding;
323
323
  module.exports.Connection = Connection;
324
+ module.exports.JsHeaderProvider = JsHeaderProvider;
324
325
  module.exports.Index = Index;
325
326
  module.exports.RecordBatchIterator = RecordBatchIterator;
326
327
  module.exports.NativeMergeInsertBuilder = NativeMergeInsertBuilder;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "ann"
12
12
  ],
13
13
  "private": false,
14
- "version": "0.22.0-beta.1",
14
+ "version": "0.22.1",
15
15
  "main": "dist/index.js",
16
16
  "exports": {
17
17
  ".": "./dist/index.js",
@@ -100,14 +100,14 @@
100
100
  "reflect-metadata": "^0.2.2"
101
101
  },
102
102
  "optionalDependencies": {
103
- "@lancedb/lancedb-darwin-x64": "0.22.0-beta.1",
104
- "@lancedb/lancedb-darwin-arm64": "0.22.0-beta.1",
105
- "@lancedb/lancedb-linux-x64-gnu": "0.22.0-beta.1",
106
- "@lancedb/lancedb-linux-arm64-gnu": "0.22.0-beta.1",
107
- "@lancedb/lancedb-linux-x64-musl": "0.22.0-beta.1",
108
- "@lancedb/lancedb-linux-arm64-musl": "0.22.0-beta.1",
109
- "@lancedb/lancedb-win32-x64-msvc": "0.22.0-beta.1",
110
- "@lancedb/lancedb-win32-arm64-msvc": "0.22.0-beta.1"
103
+ "@lancedb/lancedb-darwin-x64": "0.22.1",
104
+ "@lancedb/lancedb-darwin-arm64": "0.22.1",
105
+ "@lancedb/lancedb-linux-x64-gnu": "0.22.1",
106
+ "@lancedb/lancedb-linux-arm64-gnu": "0.22.1",
107
+ "@lancedb/lancedb-linux-x64-musl": "0.22.1",
108
+ "@lancedb/lancedb-linux-arm64-musl": "0.22.1",
109
+ "@lancedb/lancedb-win32-x64-msvc": "0.22.1",
110
+ "@lancedb/lancedb-win32-arm64-msvc": "0.22.1"
111
111
  },
112
112
  "peerDependencies": {
113
113
  "apache-arrow": ">=15.0.0 <=18.1.0"