@nodetool-ai/vectorstore 0.7.0-rc.23 → 0.8.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/README.md +62 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/chroma-client.js.map +1 -1
- package/dist/collection-access.d.ts +51 -0
- package/dist/collection-access.d.ts.map +1 -0
- package/dist/collection-access.js +100 -0
- package/dist/collection-access.js.map +1 -0
- package/dist/embedding.d.ts +22 -9
- package/dist/embedding.d.ts.map +1 -1
- package/dist/embedding.js +33 -26
- package/dist/embedding.js.map +1 -1
- package/dist/index.d.ts +21 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -45
- package/dist/index.js.map +1 -1
- package/dist/pinecone-provider.d.ts +30 -0
- package/dist/pinecone-provider.d.ts.map +1 -0
- package/dist/pinecone-provider.js +61 -0
- package/dist/pinecone-provider.js.map +1 -0
- package/dist/postgrest.d.ts +93 -0
- package/dist/postgrest.d.ts.map +1 -0
- package/dist/postgrest.js +250 -0
- package/dist/postgrest.js.map +1 -0
- package/dist/provider-factory.d.ts +23 -0
- package/dist/provider-factory.d.ts.map +1 -0
- package/dist/provider-factory.js +93 -0
- package/dist/provider-factory.js.map +1 -0
- package/dist/provider.d.ts +163 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +34 -0
- package/dist/provider.js.map +1 -0
- package/dist/sqlite-vec-provider.d.ts +38 -0
- package/dist/sqlite-vec-provider.d.ts.map +1 -0
- package/dist/sqlite-vec-provider.js +223 -0
- package/dist/sqlite-vec-provider.js.map +1 -0
- package/dist/sqlite-vec-store.d.ts +4 -2
- package/dist/sqlite-vec-store.d.ts.map +1 -1
- package/dist/sqlite-vec-store.js +28 -8
- package/dist/sqlite-vec-store.js.map +1 -1
- package/dist/supabase-provider.d.ts +60 -0
- package/dist/supabase-provider.d.ts.map +1 -0
- package/dist/supabase-provider.js +497 -0
- package/dist/supabase-provider.js.map +1 -0
- package/package.json +24 -8
- package/sql/supabase-migration.sql +104 -0
package/dist/index.js
CHANGED
|
@@ -1,56 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { OWNER_METADATA_KEY, RESERVED_COLLECTION_METADATA_KEYS, MAX_COLLECTION_NAME_LENGTH, collectionOwner, canAccessCollection, stripReservedMetadata, validateCollectionName } from "./collection-access.js";
|
|
2
|
+
// @nodetool-ai/vectorstore — backend-agnostic vector store
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Backend-agnostic vector provider abstraction (preferred public API)
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
export { CollectionNotFoundError, ProviderConfigError, UnsupportedFilterError } from "./provider.js";
|
|
7
|
+
export { SqliteVecProvider } from "./sqlite-vec-provider.js";
|
|
8
|
+
export { PineconeProvider } from "./pinecone-provider.js";
|
|
9
|
+
export { SupabaseProvider } from "./supabase-provider.js";
|
|
10
|
+
export { PostgrestClient } from "./postgrest.js";
|
|
11
|
+
export { createSqliteVecProvider, createVectorProviderFromEnv, getDefaultVectorProvider, resetDefaultVectorProvider, setDefaultVectorProvider } from "./provider-factory.js";
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Embedding functions
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
4
15
|
export { ProviderEmbeddingFunction, OpenAIEmbeddingFunction, OllamaEmbeddingFunction, GeminiEmbeddingFunction, MistralEmbeddingFunction, CohereEmbeddingFunction, VoyageEmbeddingFunction, JinaEmbeddingFunction, getProviderEmbeddingFunction } from "./embedding.js";
|
|
16
|
+
export { splitDocument } from "./chroma-client.js";
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Low-level sqlite-vec types — exported for tests and code that needs to
|
|
19
|
+
// reach the underlying SQLite handle. New code should use VectorProvider.
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
export { SqliteVecStore, VecCollection, VecNotFoundError, getDefaultStore, resetDefaultStore } from "./sqlite-vec-store.js";
|
|
5
22
|
// ---------------------------------------------------------------------------
|
|
6
|
-
// Convenience
|
|
23
|
+
// Convenience: resolve a collection through the default provider, attaching
|
|
24
|
+
// an embedding function inferred from the collection's metadata.
|
|
7
25
|
// ---------------------------------------------------------------------------
|
|
8
|
-
import {
|
|
26
|
+
import { getDefaultVectorProvider } from "./provider-factory.js";
|
|
9
27
|
import { getProviderEmbeddingFunction } from "./embedding.js";
|
|
28
|
+
import { CollectionNotFoundError } from "./provider.js";
|
|
10
29
|
/**
|
|
11
|
-
*
|
|
30
|
+
* Resolve a collection by name through the default provider. If
|
|
31
|
+
* `embeddingFunction` is omitted, one is inferred from the collection's
|
|
32
|
+
* `embedding_model` / `embedding_provider` metadata. Use `getOrCreate` to
|
|
33
|
+
* create the collection if it does not exist.
|
|
12
34
|
*/
|
|
13
|
-
export async function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
export async function getAllCollections() {
|
|
31
|
-
const store = getDefaultStore();
|
|
32
|
-
const collections = await store.listCollections();
|
|
33
|
-
const result = [];
|
|
34
|
-
for (const col of collections) {
|
|
35
|
-
const metadata = col.metadata ?? {};
|
|
36
|
-
const model = metadata.embedding_model;
|
|
37
|
-
const provider = metadata.embedding_provider;
|
|
38
|
-
let ef;
|
|
39
|
-
if (model) {
|
|
40
|
-
ef = getProviderEmbeddingFunction(model, provider) ?? undefined;
|
|
35
|
+
export async function resolveCollection(name, opts = {}) {
|
|
36
|
+
const provider = getDefaultVectorProvider();
|
|
37
|
+
let ef = opts.embeddingFunction;
|
|
38
|
+
if (!ef) {
|
|
39
|
+
try {
|
|
40
|
+
const existing = await provider.getCollection({ name });
|
|
41
|
+
const meta = existing.metadata ?? {};
|
|
42
|
+
const model = meta.embedding_model;
|
|
43
|
+
const efProvider = meta.embedding_provider;
|
|
44
|
+
if (model) {
|
|
45
|
+
ef = getProviderEmbeddingFunction(model, efProvider) ?? undefined;
|
|
46
|
+
}
|
|
47
|
+
if (ef) {
|
|
48
|
+
return provider.getCollection({ name, embeddingFunction: ef });
|
|
49
|
+
}
|
|
50
|
+
return existing;
|
|
41
51
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
name: col.name,
|
|
46
|
-
embeddingFunction: ef
|
|
47
|
-
});
|
|
48
|
-
result.push(withEf);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
result.push(col);
|
|
52
|
+
catch (e) {
|
|
53
|
+
if (!(e instanceof CollectionNotFoundError) || !opts.getOrCreate)
|
|
54
|
+
throw e;
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
|
|
57
|
+
if (opts.getOrCreate) {
|
|
58
|
+
return provider.getOrCreateCollection({
|
|
59
|
+
name,
|
|
60
|
+
embeddingFunction: ef,
|
|
61
|
+
metadata: opts.metadata
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return provider.getCollection({ name, embeddingFunction: ef });
|
|
55
65
|
}
|
|
56
66
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,iCAAiC,EACjC,0BAA0B,EAC1B,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,wBAAwB,CAAC;AAChC,2DAA2D;AAE3D,8EAA8E;AAC9E,sEAAsE;AACtE,8EAA8E;AAE9E,OAAO,EACL,uBAAuB,EACvB,mBAAmB,E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,CAAC;QACR,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;YACxD,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,eAAqC,CAAC;YACzD,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAwC,CAAC;YACjE,IAAI,KAAK,EAAE,CAAC;gBACV,EAAE,GAAG,4BAA4B,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,SAAS,CAAC;YACpE,CAAC;YACD,IAAI,EAAE,EAAE,CAAC;gBACP,OAAO,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,CAAC,CAAC,YAAY,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW;gBAAE,MAAM,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IAED,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,OAAO,QAAQ,CAAC,qBAAqB,CAAC;YACpC,IAAI;YACJ,iBAAiB,EAAE,EAAE;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pinecone implementation of the VectorProvider interface.
|
|
3
|
+
*
|
|
4
|
+
* Stub: only the constructor / config validation is wired up. Each method
|
|
5
|
+
* documents the Pinecone REST/SDK call it should make. Implementing this
|
|
6
|
+
* adapter is a matter of pulling in `@pinecone-database/pinecone` and
|
|
7
|
+
* mapping our types onto its `Index` and `Vector` shapes.
|
|
8
|
+
*/
|
|
9
|
+
import { type CollectionInfo, type CreateCollectionOptions, type GetCollectionOptions, type VectorCollection, type VectorProvider } from "./provider.js";
|
|
10
|
+
export interface PineconeProviderOptions {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/** Pinecone control-plane environment, e.g. "us-east-1-aws". */
|
|
13
|
+
environment?: string;
|
|
14
|
+
/** Project / controller host. */
|
|
15
|
+
controllerHostUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class PineconeProvider implements VectorProvider {
|
|
18
|
+
readonly name = "pinecone";
|
|
19
|
+
readonly apiKey: string;
|
|
20
|
+
readonly environment?: string;
|
|
21
|
+
readonly controllerHostUrl?: string;
|
|
22
|
+
constructor(opts: PineconeProviderOptions);
|
|
23
|
+
listCollections(): Promise<CollectionInfo[]>;
|
|
24
|
+
getCollection(_opts: GetCollectionOptions): Promise<VectorCollection>;
|
|
25
|
+
createCollection(_opts: CreateCollectionOptions): Promise<VectorCollection>;
|
|
26
|
+
getOrCreateCollection(_opts: CreateCollectionOptions): Promise<VectorCollection>;
|
|
27
|
+
deleteCollection(_name: string): Promise<void>;
|
|
28
|
+
close(): void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=pinecone-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinecone-provider.d.ts","sourceRoot":"","sources":["../src/pinecone-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,qBAAa,gBAAiB,YAAW,cAAc;IACrD,QAAQ,CAAC,IAAI,cAAc;IAE3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAEpC,YAAY,IAAI,EAAE,uBAAuB,EAOxC;IAED,eAAe,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAG3C;IAED,aAAa,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAGpE;IAED,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAI1E;IAED,qBAAqB,CACnB,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CAE3B;IAED,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7C;IAED,KAAK,IAAI,IAAI,CAEZ;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pinecone implementation of the VectorProvider interface.
|
|
3
|
+
*
|
|
4
|
+
* Stub: only the constructor / config validation is wired up. Each method
|
|
5
|
+
* documents the Pinecone REST/SDK call it should make. Implementing this
|
|
6
|
+
* adapter is a matter of pulling in `@pinecone-database/pinecone` and
|
|
7
|
+
* mapping our types onto its `Index` and `Vector` shapes.
|
|
8
|
+
*/
|
|
9
|
+
import { ProviderConfigError } from "./provider.js";
|
|
10
|
+
export class PineconeProvider {
|
|
11
|
+
name = "pinecone";
|
|
12
|
+
apiKey;
|
|
13
|
+
environment;
|
|
14
|
+
controllerHostUrl;
|
|
15
|
+
constructor(opts) {
|
|
16
|
+
if (!opts.apiKey) {
|
|
17
|
+
throw new ProviderConfigError("PineconeProvider requires apiKey");
|
|
18
|
+
}
|
|
19
|
+
this.apiKey = opts.apiKey;
|
|
20
|
+
this.environment = opts.environment;
|
|
21
|
+
this.controllerHostUrl = opts.controllerHostUrl;
|
|
22
|
+
}
|
|
23
|
+
listCollections() {
|
|
24
|
+
// Maps to: pinecone.listIndexes()
|
|
25
|
+
throw notImplemented();
|
|
26
|
+
}
|
|
27
|
+
getCollection(_opts) {
|
|
28
|
+
// Maps to: pinecone.index(name)
|
|
29
|
+
throw notImplemented();
|
|
30
|
+
}
|
|
31
|
+
createCollection(_opts) {
|
|
32
|
+
// Maps to: pinecone.createIndex({ name, dimension, metric })
|
|
33
|
+
// `dimension` is REQUIRED by Pinecone — surface clearly if missing.
|
|
34
|
+
throw notImplemented();
|
|
35
|
+
}
|
|
36
|
+
getOrCreateCollection(_opts) {
|
|
37
|
+
throw notImplemented();
|
|
38
|
+
}
|
|
39
|
+
deleteCollection(_name) {
|
|
40
|
+
// Maps to: pinecone.deleteIndex(name)
|
|
41
|
+
throw notImplemented();
|
|
42
|
+
}
|
|
43
|
+
close() {
|
|
44
|
+
// No persistent connection.
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Method stubs deliberately left for future implementation. The collection
|
|
48
|
+
// shape will look like:
|
|
49
|
+
//
|
|
50
|
+
// class PineconeCollection implements VectorCollection {
|
|
51
|
+
// constructor(private index: PineconeIndex) {}
|
|
52
|
+
// upsert(records) → index.upsert(records.map(toPineconeVector))
|
|
53
|
+
// query({ embedding, topK, filter }) →
|
|
54
|
+
// index.query({ vector, topK, filter, includeMetadata: true })
|
|
55
|
+
// delete(ids) → index.deleteMany(ids)
|
|
56
|
+
// get({ ids }) → index.fetch(ids)
|
|
57
|
+
// }
|
|
58
|
+
function notImplemented() {
|
|
59
|
+
return new Error("PineconeProvider is not yet implemented — install @pinecone-database/pinecone and wire up the methods.");
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=pinecone-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinecone-provider.js","sourceRoot":"","s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@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal fetch-backed PostgREST client (`/rest/v1/`), covering exactly the
|
|
3
|
+
* query surface SupabaseProvider uses: select (with count/head), insert,
|
|
4
|
+
* upsert (on_conflict), update, delete, the filter operators
|
|
5
|
+
* eq / in / is / ilike / contains, order, limit, range, maybeSingle, and rpc.
|
|
6
|
+
*
|
|
7
|
+
* The fluent shape mirrors the supabase-js subset previously consumed, so
|
|
8
|
+
* call sites and test fakes stay structural. Every builder is a thenable
|
|
9
|
+
* resolving to `{ data, error, count }` — errors are returned, not thrown,
|
|
10
|
+
* matching PostgREST's `{ message, code, details, hint }` error bodies.
|
|
11
|
+
*/
|
|
12
|
+
export interface PostgrestError {
|
|
13
|
+
message: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
details?: string;
|
|
16
|
+
hint?: string;
|
|
17
|
+
}
|
|
18
|
+
export type PostgrestRow = Record<string, unknown>;
|
|
19
|
+
export interface PostgrestRowsResult {
|
|
20
|
+
data: PostgrestRow[] | null;
|
|
21
|
+
error: PostgrestError | null;
|
|
22
|
+
count: number | null;
|
|
23
|
+
}
|
|
24
|
+
interface PostgrestMaybeSingleResult {
|
|
25
|
+
data: PostgrestRow | null;
|
|
26
|
+
error: PostgrestError | null;
|
|
27
|
+
}
|
|
28
|
+
interface PostgrestRpcResult {
|
|
29
|
+
data: unknown;
|
|
30
|
+
error: PostgrestError | null;
|
|
31
|
+
}
|
|
32
|
+
interface PostgrestSelectOptions {
|
|
33
|
+
count?: "exact";
|
|
34
|
+
head?: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface PostgrestUpsertOptions {
|
|
37
|
+
onConflict?: string;
|
|
38
|
+
}
|
|
39
|
+
/** The fluent builder surface used by SupabaseProvider. */
|
|
40
|
+
interface PostgrestFilterBuilder extends PromiseLike<PostgrestRowsResult> {
|
|
41
|
+
eq(column: string, value: unknown): this;
|
|
42
|
+
in(column: string, values: readonly unknown[]): this;
|
|
43
|
+
is(column: string, value: null | boolean): this;
|
|
44
|
+
ilike(column: string, pattern: string): this;
|
|
45
|
+
contains(column: string, value: Record<string, unknown>): this;
|
|
46
|
+
order(column: string, options?: {
|
|
47
|
+
ascending?: boolean;
|
|
48
|
+
}): this;
|
|
49
|
+
limit(n: number): this;
|
|
50
|
+
range(from: number, to: number): this;
|
|
51
|
+
maybeSingle(): PromiseLike<PostgrestMaybeSingleResult>;
|
|
52
|
+
}
|
|
53
|
+
interface PostgrestTableApi {
|
|
54
|
+
select(columns?: string, options?: PostgrestSelectOptions): PostgrestFilterBuilder;
|
|
55
|
+
insert(values: PostgrestRow | PostgrestRow[]): PostgrestFilterBuilder;
|
|
56
|
+
upsert(values: PostgrestRow | PostgrestRow[], options?: PostgrestUpsertOptions): PostgrestFilterBuilder;
|
|
57
|
+
update(values: PostgrestRow): PostgrestFilterBuilder;
|
|
58
|
+
delete(): PostgrestFilterBuilder;
|
|
59
|
+
}
|
|
60
|
+
/** The client surface used by SupabaseProvider (injectable in tests). */
|
|
61
|
+
export interface PostgrestClientApi {
|
|
62
|
+
from(table: string): PostgrestTableApi;
|
|
63
|
+
rpc(name: string, args: Record<string, unknown>): PromiseLike<PostgrestRpcResult>;
|
|
64
|
+
}
|
|
65
|
+
interface PostgrestClientOptions {
|
|
66
|
+
/** Base URL of the Supabase project (e.g. https://xyz.supabase.co). */
|
|
67
|
+
url: string;
|
|
68
|
+
/** API key sent as both `apikey` and Bearer authorization. */
|
|
69
|
+
apiKey: string;
|
|
70
|
+
/** Postgres schema; sent via Accept-Profile / Content-Profile when not "public". */
|
|
71
|
+
schema?: string;
|
|
72
|
+
}
|
|
73
|
+
type Method = "GET" | "HEAD" | "POST" | "PATCH" | "DELETE";
|
|
74
|
+
interface RequestState {
|
|
75
|
+
method: Method;
|
|
76
|
+
body?: string;
|
|
77
|
+
searchParams: URLSearchParams;
|
|
78
|
+
prefer: string[];
|
|
79
|
+
hasWriteBody: boolean;
|
|
80
|
+
}
|
|
81
|
+
export declare class PostgrestClient implements PostgrestClientApi {
|
|
82
|
+
private readonly base;
|
|
83
|
+
private readonly apiKey;
|
|
84
|
+
private readonly schema;
|
|
85
|
+
constructor(options: PostgrestClientOptions);
|
|
86
|
+
from(table: string): PostgrestTableApi;
|
|
87
|
+
rpc(name: string, args: Record<string, unknown>): PromiseLike<PostgrestRpcResult>;
|
|
88
|
+
private executeRpc;
|
|
89
|
+
/** Perform one HTTP request against the PostgREST endpoint. */
|
|
90
|
+
request(path: string, state: RequestState): Promise<Response>;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=postgrest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgrest.d.ts","sourceRoot":"","sources":["../src/postgrest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;IAC7B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,UAAU,0BAA0B;IAClC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B;AAED,UAAU,kBAAkB;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B;AAED,UAAU,sBAAsB;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,UAAU,sBA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ACF"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal fetch-backed PostgREST client (`/rest/v1/`), covering exactly the
|
|
3
|
+
* query surface SupabaseProvider uses: select (with count/head), insert,
|
|
4
|
+
* upsert (on_conflict), update, delete, the filter operators
|
|
5
|
+
* eq / in / is / ilike / contains, order, limit, range, maybeSingle, and rpc.
|
|
6
|
+
*
|
|
7
|
+
* The fluent shape mirrors the supabase-js subset previously consumed, so
|
|
8
|
+
* call sites and test fakes stay structural. Every builder is a thenable
|
|
9
|
+
* resolving to `{ data, error, count }` — errors are returned, not thrown,
|
|
10
|
+
* matching PostgREST's `{ message, code, details, hint }` error bodies.
|
|
11
|
+
*/
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Value encoding
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
/** Quote one element of an `in.(...)` list per PostgREST rules. */
|
|
16
|
+
function quoteInElement(value) {
|
|
17
|
+
const s = String(value);
|
|
18
|
+
return `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
19
|
+
}
|
|
20
|
+
async function readErrorBody(response) {
|
|
21
|
+
let parsed = null;
|
|
22
|
+
try {
|
|
23
|
+
parsed = (await response.json());
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Non-JSON error body — fall through to the status fallback.
|
|
27
|
+
}
|
|
28
|
+
const message = parsed && typeof parsed.message === "string" && parsed.message
|
|
29
|
+
? parsed.message
|
|
30
|
+
: `PostgREST request failed with status ${response.status}`;
|
|
31
|
+
const error = { message };
|
|
32
|
+
if (parsed) {
|
|
33
|
+
if (typeof parsed.code === "string")
|
|
34
|
+
error.code = parsed.code;
|
|
35
|
+
if (typeof parsed.details === "string")
|
|
36
|
+
error.details = parsed.details;
|
|
37
|
+
if (typeof parsed.hint === "string")
|
|
38
|
+
error.hint = parsed.hint;
|
|
39
|
+
}
|
|
40
|
+
return error;
|
|
41
|
+
}
|
|
42
|
+
/** Parse the total from a `Content-Range: 0-9/42` header. */
|
|
43
|
+
function parseContentRangeCount(header) {
|
|
44
|
+
if (!header)
|
|
45
|
+
return null;
|
|
46
|
+
const total = header.split("/")[1];
|
|
47
|
+
if (!total || total === "*")
|
|
48
|
+
return null;
|
|
49
|
+
const n = Number(total);
|
|
50
|
+
return Number.isFinite(n) ? n : null;
|
|
51
|
+
}
|
|
52
|
+
class FilterBuilder {
|
|
53
|
+
client;
|
|
54
|
+
table;
|
|
55
|
+
state;
|
|
56
|
+
constructor(client, table, state) {
|
|
57
|
+
this.client = client;
|
|
58
|
+
this.table = table;
|
|
59
|
+
this.state = state;
|
|
60
|
+
}
|
|
61
|
+
eq(column, value) {
|
|
62
|
+
this.state.searchParams.append(column, `eq.${String(value)}`);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
in(column, values) {
|
|
66
|
+
this.state.searchParams.append(column, `in.(${values.map(quoteInElement).join(",")})`);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
is(column, value) {
|
|
70
|
+
this.state.searchParams.append(column, `is.${value === null ? "null" : String(value)}`);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
ilike(column, pattern) {
|
|
74
|
+
this.state.searchParams.append(column, `ilike.${pattern}`);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
contains(column, value) {
|
|
78
|
+
this.state.searchParams.append(column, `cs.${JSON.stringify(value)}`);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
order(column, options) {
|
|
82
|
+
const dir = options?.ascending === false ? "desc" : "asc";
|
|
83
|
+
this.state.searchParams.append("order", `${column}.${dir}`);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
limit(n) {
|
|
87
|
+
this.state.searchParams.set("limit", String(n));
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
range(from, to) {
|
|
91
|
+
this.state.searchParams.set("offset", String(from));
|
|
92
|
+
this.state.searchParams.set("limit", String(to - from + 1));
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
maybeSingle() {
|
|
96
|
+
this.limit(1);
|
|
97
|
+
return this.execute().then((res) => ({
|
|
98
|
+
data: res.data?.[0] ?? null,
|
|
99
|
+
error: res.error
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
then(onfulfilled, onrejected) {
|
|
103
|
+
return this.execute().then(onfulfilled, onrejected);
|
|
104
|
+
}
|
|
105
|
+
async execute() {
|
|
106
|
+
const response = await this.client.request(`/rest/v1/${this.table}`, this.state);
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
return { data: null, error: await readErrorBody(response), count: null };
|
|
109
|
+
}
|
|
110
|
+
const count = parseContentRangeCount(response.headers.get("content-range"));
|
|
111
|
+
if (this.state.method === "HEAD") {
|
|
112
|
+
return { data: null, error: null, count };
|
|
113
|
+
}
|
|
114
|
+
const text = await response.text();
|
|
115
|
+
if (!text) {
|
|
116
|
+
return { data: null, error: null, count };
|
|
117
|
+
}
|
|
118
|
+
const parsed = JSON.parse(text);
|
|
119
|
+
return {
|
|
120
|
+
data: Array.isArray(parsed) ? parsed : [parsed],
|
|
121
|
+
error: null,
|
|
122
|
+
count
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
class TableApi {
|
|
127
|
+
client;
|
|
128
|
+
table;
|
|
129
|
+
constructor(client, table) {
|
|
130
|
+
this.client = client;
|
|
131
|
+
this.table = table;
|
|
132
|
+
}
|
|
133
|
+
builder(state) {
|
|
134
|
+
return new FilterBuilder(this.client, this.table, state);
|
|
135
|
+
}
|
|
136
|
+
select(columns = "*", options = {}) {
|
|
137
|
+
const searchParams = new URLSearchParams();
|
|
138
|
+
searchParams.set("select", columns.replace(/\s/g, ""));
|
|
139
|
+
const prefer = [];
|
|
140
|
+
if (options.count)
|
|
141
|
+
prefer.push(`count=${options.count}`);
|
|
142
|
+
return this.builder({
|
|
143
|
+
method: options.head ? "HEAD" : "GET",
|
|
144
|
+
searchParams,
|
|
145
|
+
prefer,
|
|
146
|
+
hasWriteBody: false
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
insert(values) {
|
|
150
|
+
return this.builder({
|
|
151
|
+
method: "POST",
|
|
152
|
+
body: JSON.stringify(values),
|
|
153
|
+
searchParams: new URLSearchParams(),
|
|
154
|
+
prefer: ["return=minimal"],
|
|
155
|
+
hasWriteBody: true
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
upsert(values, options = {}) {
|
|
159
|
+
const searchParams = new URLSearchParams();
|
|
160
|
+
if (options.onConflict) {
|
|
161
|
+
searchParams.set("on_conflict", options.onConflict);
|
|
162
|
+
}
|
|
163
|
+
return this.builder({
|
|
164
|
+
method: "POST",
|
|
165
|
+
body: JSON.stringify(values),
|
|
166
|
+
searchParams,
|
|
167
|
+
prefer: ["resolution=merge-duplicates", "return=minimal"],
|
|
168
|
+
hasWriteBody: true
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
update(values) {
|
|
172
|
+
return this.builder({
|
|
173
|
+
method: "PATCH",
|
|
174
|
+
body: JSON.stringify(values),
|
|
175
|
+
searchParams: new URLSearchParams(),
|
|
176
|
+
prefer: ["return=minimal"],
|
|
177
|
+
hasWriteBody: true
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
delete() {
|
|
181
|
+
return this.builder({
|
|
182
|
+
method: "DELETE",
|
|
183
|
+
searchParams: new URLSearchParams(),
|
|
184
|
+
prefer: ["return=minimal"],
|
|
185
|
+
hasWriteBody: false
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export class PostgrestClient {
|
|
190
|
+
base;
|
|
191
|
+
apiKey;
|
|
192
|
+
schema;
|
|
193
|
+
constructor(options) {
|
|
194
|
+
let base = options.url;
|
|
195
|
+
while (base.endsWith("/"))
|
|
196
|
+
base = base.slice(0, -1);
|
|
197
|
+
this.base = base;
|
|
198
|
+
this.apiKey = options.apiKey;
|
|
199
|
+
this.schema = options.schema ?? "public";
|
|
200
|
+
}
|
|
201
|
+
from(table) {
|
|
202
|
+
return new TableApi(this, table);
|
|
203
|
+
}
|
|
204
|
+
rpc(name, args) {
|
|
205
|
+
return this.executeRpc(name, args);
|
|
206
|
+
}
|
|
207
|
+
async executeRpc(name, args) {
|
|
208
|
+
const response = await this.request(`/rest/v1/rpc/${name}`, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
body: JSON.stringify(args),
|
|
211
|
+
searchParams: new URLSearchParams(),
|
|
212
|
+
prefer: [],
|
|
213
|
+
hasWriteBody: true
|
|
214
|
+
});
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
return { data: null, error: await readErrorBody(response) };
|
|
217
|
+
}
|
|
218
|
+
const text = await response.text();
|
|
219
|
+
return { data: text ? JSON.parse(text) : null, error: null };
|
|
220
|
+
}
|
|
221
|
+
/** Perform one HTTP request against the PostgREST endpoint. */
|
|
222
|
+
async request(path, state) {
|
|
223
|
+
const qs = state.searchParams.toString();
|
|
224
|
+
const url = `${this.base}${path}${qs ? `?${qs}` : ""}`;
|
|
225
|
+
const headers = {
|
|
226
|
+
apikey: this.apiKey,
|
|
227
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
228
|
+
};
|
|
229
|
+
if (state.hasWriteBody) {
|
|
230
|
+
headers["Content-Type"] = "application/json";
|
|
231
|
+
}
|
|
232
|
+
if (state.prefer.length > 0) {
|
|
233
|
+
headers.Prefer = state.prefer.join(",");
|
|
234
|
+
}
|
|
235
|
+
if (this.schema !== "public") {
|
|
236
|
+
if (state.method === "GET" || state.method === "HEAD") {
|
|
237
|
+
headers["Accept-Profile"] = this.schema;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
headers["Content-Profile"] = this.schema;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const init = { method: state.method, headers };
|
|
244
|
+
if (state.body !== undefined) {
|
|
245
|
+
init.body = state.body;
|
|
246
|
+
}
|
|
247
|
+
return fetch(url, init);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=postgrest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgrest.js","sourceRoot":"","sources":["../src/postgrest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAiFH,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,mEAAmE;AACnE,SAAS,cAAc,CAAC,KAAc;IACpC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;AAC9D,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,QAAkB;IAC7C,IAAI,MAAM,GAAmC,IAAI,CAAC;IAClD,IAAI,CAAC;QACH,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA4B,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,6DAA6D;IAC/D,CAAC;IACD,MAAM,OAAO,GACX,MAAM,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,OAAO;QAC5D,CAAC,CAAC,MAAM,CAAC,OAAO;QAChB,CAAC,CAAC,wCAAwC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChE,MAAM,KAAK,GAAmB,EAAE,OAAO,EAAE,CAAC;IAC1C,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;YAAE,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAC9D,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ;YAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QACvE,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QA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
3
|
+
*
|
|
4
|
+
* Selection order:
|
|
5
|
+
* 1. Explicit `setDefaultVectorProvider(...)` call.
|
|
6
|
+
* 2. Env var `NODETOOL_VECTOR_PROVIDER` ∈ { "sqlite-vec", "pinecone", "supabase" }.
|
|
7
|
+
* 3. Fallback: `SqliteVecProvider` with default db path.
|
|
8
|
+
*
|
|
9
|
+
* Path resolution for sqlite-vec follows `@nodetool-ai/config` conventions —
|
|
10
|
+
* `VECTORSTORE_DB_PATH` overrides the default location. The sqlite-vec
|
|
11
|
+
* adapter shares the process-wide `getDefaultStore()` instance so that
|
|
12
|
+
* callers using the lower-level API and the provider see one connection.
|
|
13
|
+
*/
|
|
14
|
+
import { SqliteVecProvider, type SqliteVecProviderOptions } from "./sqlite-vec-provider.js";
|
|
15
|
+
import { type VectorProvider } from "./provider.js";
|
|
16
|
+
export type VectorProviderKind = "sqlite-vec" | "pinecone" | "supabase";
|
|
17
|
+
export declare function getDefaultVectorProvider(): VectorProvider;
|
|
18
|
+
export declare function setDefaultVectorProvider(provider: VectorProvider): void;
|
|
19
|
+
export declare function resetDefaultVectorProvider(): void;
|
|
20
|
+
export declare function createVectorProviderFromEnv(env?: Record<string, string | undefined>): VectorProvider;
|
|
21
|
+
/** Convenience for tests / one-off scripts. */
|
|
22
|
+
export declare function createSqliteVecProvider(opts?: SqliteVecProviderOptions): SqliteVecProvider;
|
|
23
|
+
//# sourceMappingURL=provider-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-factory.d.ts","sourceRoot":"","sources":["../src/provider-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC9B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,UAAU,GAAG,UAAU,CAAC;AAIxE,wBAAgB,wBAAwB,IAAI,cAAc,CAIzD;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CASvE;AAED,wBAAgB,0BAA0B,IAAI,IAAI,CASjD;AAED,wBAAgB,2BAA2B,CACzC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,cAAc,CAmDhB;AAED,+CAA+C;AAC/C,wBAAgB,uBAAuB,CACrC,IAAI,GAAE,wBAA6B,GAClC,iBAAiB,CAEnB"}
|