@upstash/vector 1.1.1 → 1.1.2-canary-cloudflare
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/chunk-HLW45HVB.mjs +1 -0
- package/dist/cloudflare.d.mts +59 -0
- package/dist/cloudflare.d.ts +59 -0
- package/dist/cloudflare.js +1 -0
- package/dist/cloudflare.mjs +1 -0
- package/dist/nodejs.d.mts +74 -0
- package/dist/nodejs.d.ts +74 -0
- package/dist/nodejs.js +1 -0
- package/dist/nodejs.mjs +1 -0
- package/dist/{index.d.mts → vector-fCHAzBG_.d.mts} +40 -132
- package/dist/{index.d.ts → vector-fCHAzBG_.d.ts} +40 -132
- package/package.json +1 -1
- package/dist/index.js +0 -1
- package/dist/index.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var M=class{baseUrl;headers;options;retry;constructor(e){this.options={cache:e.cache,signal:e.signal},this.baseUrl=e.baseUrl.replace(/\/$/,""),this.headers={"Content-Type":"application/json",...e.headers},typeof e?.retry=="boolean"&&e?.retry===!1?this.retry={attempts:1,backoff:()=>0}:this.retry={attempts:e?.retry?.retries??5,backoff:e?.retry?.backoff??(t=>Math.exp(t)*50)}}async request(e){let t={cache:this.options.cache,method:"POST",headers:this.headers,body:JSON.stringify(e.body),keepalive:!0,signal:this.options.signal},a=null,o=null;for(let g=0;g<=this.retry.attempts;g++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(b){if(this.options.signal?.aborted){let T=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),R={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(T,R);break}o=b,await new Promise(T=>setTimeout(T,this.retry.backoff(g)))}if(!a)throw o??new Error("Exhausted all retries");let s=await a.json();if(!a.ok)throw new i(`${s.error}`);return{result:s.result,error:s.error}}};var n=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t}async exec(e){let{result:t,error:a}=await e.request({body:this.payload,path:[this.endpoint]});if(a)throw new i(a);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends n{constructor(e,t){let a="delete";t?.namespace&&(a=`${a}/${t.namespace}`);let o=[];Array.isArray(e)?o.push(...e):o.push(e),super(o,a)}};var d=class extends n{constructor(e,t){let a="query";"data"in e&&(a="query-data"),t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var m=class extends n{constructor(e,t){let a="upsert";if(Array.isArray(e)){if(e.some(s=>"data"in s&&s.data)){a="upsert-data";for(let s of e)!("metadata"in s)&&"data"in s&&(s.metadata={data:s.data})}}else"data"in e&&(a="upsert-data","metadata"in e||(e.metadata={data:e.data}));t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var c=class extends n{constructor([e,t]){let a="fetch";t?.namespace&&(a=`${a}/${t.namespace}`,delete t.namespace),super({ids:e,...t},a)}};var l=class extends n{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var u=class extends n{constructor(e){let t="reset";e?.namespace&&(t=`${t}/${e.namespace}`),super([],t)}};var f=class extends n{constructor(){super([],"info")}};var h=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new m(e,{namespace:this.namespace}).exec(this.client);update=e=>new y(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new d(e,{namespace:this.namespace}).exec(this.client);delete=e=>new p(e,{namespace:this.namespace}).exec(this.client);range=e=>new l(e,{namespace:this.namespace}).exec(this.client);reset=()=>new u({namespace:this.namespace}).exec(this.client)};var y=class extends n{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var C=class extends n{constructor(){super([],"list-namespaces")}};var x=class extends n{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var E=class{client;constructor(e){this.client=e}namespace=e=>new h(this.client,e);delete=(e,t)=>new p(e,t).exec(this.client);query=(e,t)=>new d(e,t).exec(this.client);upsert=(e,t)=>new m(e,t).exec(this.client);update=(e,t)=>new y(e,t).exec(this.client);fetch=(...e)=>new c(e).exec(this.client);reset=e=>new u(e).exec(this.client);range=(e,t)=>new l(e,t).exec(this.client);info=()=>new f().exec(this.client);listNamespaces=()=>new C().exec(this.client);deleteNamespace=e=>new x(e).exec(this.client)};export{M as a,E as b};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-fCHAzBG_.mjs';
|
|
2
|
+
export { F as FetchResult, d as InfoResult, Q as QueryResult, c as RangeResult, a as Requester, U as UpstashRequest, b as UpstashResponse, V as Vector } from './vector-fCHAzBG_.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection credentials for upstash vector.
|
|
6
|
+
* Get them from https://console.upstash.com/vector/<uuid>
|
|
7
|
+
*/
|
|
8
|
+
type IndexConfigCloudflare = {
|
|
9
|
+
/**
|
|
10
|
+
* UPSTASH_VECTOR_REST_URL
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_VECTOR_REST_TOKEN
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The signal will allow aborting requests on the fly.
|
|
19
|
+
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
} & RequesterConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Serverless vector client for upstash.
|
|
25
|
+
*/
|
|
26
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new vector client by providing the url and token
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const index = new Index({
|
|
33
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
34
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
* OR
|
|
38
|
+
* This will automatically get environment variables from .env file
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const index = new Index();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: IndexConfigCloudflare);
|
|
44
|
+
/**
|
|
45
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
46
|
+
*
|
|
47
|
+
* Use this to automatically load connection secrets from your environment
|
|
48
|
+
* variables. For instance when using the Vercel integration.
|
|
49
|
+
*
|
|
50
|
+
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
51
|
+
* your environment using `process.env`.
|
|
52
|
+
*/
|
|
53
|
+
static fromEnv(env?: {
|
|
54
|
+
UPSTASH_VECTOR_REST_URL: string;
|
|
55
|
+
UPSTASH_VECTOR_REST_TOKEN: string;
|
|
56
|
+
}, config?: Omit<IndexConfigCloudflare, "url" | "token">): Index;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Index, type IndexConfigCloudflare };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1 } from './vector-fCHAzBG_.js';
|
|
2
|
+
export { F as FetchResult, d as InfoResult, Q as QueryResult, c as RangeResult, a as Requester, U as UpstashRequest, b as UpstashResponse, V as Vector } from './vector-fCHAzBG_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection credentials for upstash vector.
|
|
6
|
+
* Get them from https://console.upstash.com/vector/<uuid>
|
|
7
|
+
*/
|
|
8
|
+
type IndexConfigCloudflare = {
|
|
9
|
+
/**
|
|
10
|
+
* UPSTASH_VECTOR_REST_URL
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_VECTOR_REST_TOKEN
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The signal will allow aborting requests on the fly.
|
|
19
|
+
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
} & RequesterConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Serverless vector client for upstash.
|
|
25
|
+
*/
|
|
26
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new vector client by providing the url and token
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const index = new Index({
|
|
33
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
34
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
* OR
|
|
38
|
+
* This will automatically get environment variables from .env file
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const index = new Index();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: IndexConfigCloudflare);
|
|
44
|
+
/**
|
|
45
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
46
|
+
*
|
|
47
|
+
* Use this to automatically load connection secrets from your environment
|
|
48
|
+
* variables. For instance when using the Vercel integration.
|
|
49
|
+
*
|
|
50
|
+
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
51
|
+
* your environment using `process.env`.
|
|
52
|
+
*/
|
|
53
|
+
static fromEnv(env?: {
|
|
54
|
+
UPSTASH_VECTOR_REST_URL: string;
|
|
55
|
+
UPSTASH_VECTOR_REST_TOKEN: string;
|
|
56
|
+
}, config?: Omit<IndexConfigCloudflare, "url" | "token">): Index;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Index, type IndexConfigCloudflare };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var M=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var N=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})},V=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of P(e))!w.call(n,s)&&s!==t&&M(n,s,{get:()=>e[s],enumerable:!(a=U(e,s))||a.enumerable});return n};var _=n=>V(M({},"__esModule",{value:!0}),n);var O={};N(O,{Index:()=>S});module.exports=_(O);var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var T=class{baseUrl;headers;options;retry;constructor(e){this.options={cache:e.cache,signal:e.signal},this.baseUrl=e.baseUrl.replace(/\/$/,""),this.headers={"Content-Type":"application/json",...e.headers},typeof e?.retry=="boolean"&&e?.retry===!1?this.retry={attempts:1,backoff:()=>0}:this.retry={attempts:e?.retry?.retries??5,backoff:e?.retry?.backoff??(t=>Math.exp(t)*50)}}async request(e){let t={cache:this.options.cache,method:"POST",headers:this.headers,body:JSON.stringify(e.body),keepalive:!0,signal:this.options.signal},a=null,s=null;for(let x=0;x<=this.retry.attempts;x++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(A){if(this.options.signal?.aborted){let g=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),b={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(g,b);break}s=A,await new Promise(g=>setTimeout(g,this.retry.backoff(x)))}if(!a)throw s??new Error("Exhausted all retries");let o=await a.json();if(!a.ok)throw new i(`${o.error}`);return{result:o.result,error:o.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t}async exec(e){let{result:t,error:a}=await e.request({body:this.payload,path:[this.endpoint]});if(a)throw new i(a);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends r{constructor(e,t){let a="delete";t?.namespace&&(a=`${a}/${t.namespace}`);let s=[];Array.isArray(e)?s.push(...e):s.push(e),super(s,a)}};var d=class extends r{constructor(e,t){let a="query";"data"in e&&(a="query-data"),t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var m=class extends r{constructor(e,t){let a="upsert";if(Array.isArray(e)){if(e.some(o=>"data"in o&&o.data)){a="upsert-data";for(let o of e)!("metadata"in o)&&"data"in o&&(o.metadata={data:o.data})}}else"data"in e&&(a="upsert-data","metadata"in e||(e.metadata={data:e.data}));t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var c=class extends r{constructor([e,t]){let a="fetch";t?.namespace&&(a=`${a}/${t.namespace}`,delete t.namespace),super({ids:e,...t},a)}};var l=class extends r{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var u=class extends r{constructor(e){let t="reset";e?.namespace&&(t=`${t}/${e.namespace}`),super([],t)}};var f=class extends r{constructor(){super([],"info")}};var C=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new m(e,{namespace:this.namespace}).exec(this.client);update=e=>new y(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new d(e,{namespace:this.namespace}).exec(this.client);delete=e=>new p(e,{namespace:this.namespace}).exec(this.client);range=e=>new l(e,{namespace:this.namespace}).exec(this.client);reset=()=>new u({namespace:this.namespace}).exec(this.client)};var y=class extends r{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var h=class extends r{constructor(){super([],"list-namespaces")}};var E=class extends r{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var R=class{client;constructor(e){this.client=e}namespace=e=>new C(this.client,e);delete=(e,t)=>new p(e,t).exec(this.client);query=(e,t)=>new d(e,t).exec(this.client);upsert=(e,t)=>new m(e,t).exec(this.client);update=(e,t)=>new y(e,t).exec(this.client);fetch=(...e)=>new c(e).exec(this.client);reset=e=>new u(e).exec(this.client);range=(e,t)=>new l(e,t).exec(this.client);info=()=>new f().exec(this.client);listNamespaces=()=>new h().exec(this.client);deleteNamespace=e=>new E(e).exec(this.client)};var S=class n extends R{constructor(e){let t=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,a=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!a)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(a.startsWith(" ")||a.endsWith(" ")||/\r|\n/.test(a))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let s=new T({baseUrl:a,retry:e?.retry,headers:{authorization:`Bearer ${t}`},signal:e?.signal});super(s)}static fromEnv(e,t){let a=e?.UPSTASH_VECTOR_REST_URL??UPSTASH_VECTOR_REST_URL;if(!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`");let s=e?.UPSTASH_VECTOR_REST_TOKEN??UPSTASH_VECTOR_REST_TOKEN;if(!s)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_TOKEN`");return new n({...t,url:a,token:s})}};0&&(module.exports={Index});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as s,b as o}from"./chunk-HLW45HVB.mjs";var T=class i extends o{constructor(r){let t=r?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,e=r?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!e)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(e.startsWith(" ")||e.endsWith(" ")||/\r|\n/.test(e))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let n=new s({baseUrl:e,retry:r?.retry,headers:{authorization:`Bearer ${t}`},signal:r?.signal});super(n)}static fromEnv(r,t){let e=r?.UPSTASH_VECTOR_REST_URL??UPSTASH_VECTOR_REST_URL;if(!e)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`");let n=r?.UPSTASH_VECTOR_REST_TOKEN??UPSTASH_VECTOR_REST_TOKEN;if(!n)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_TOKEN`");return new i({...t,url:e,token:n})}};export{T as Index};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-fCHAzBG_.mjs';
|
|
2
|
+
export { F as FetchResult, d as InfoResult, Q as QueryResult, c as RangeResult, U as UpstashRequest, b as UpstashResponse, V as Vector } from './vector-fCHAzBG_.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection credentials for upstash vector.
|
|
6
|
+
* Get them from https://console.upstash.com/vector/<uuid>
|
|
7
|
+
*/
|
|
8
|
+
type IndexConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* UPSTASH_VECTOR_REST_URL
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_VECTOR_REST_TOKEN
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The signal will allow aborting requests on the fly.
|
|
19
|
+
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
} & RequesterConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Serverless vector client for upstash.
|
|
25
|
+
*/
|
|
26
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new vector client by providing the url and token
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const index = new Index({
|
|
33
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
34
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
* OR
|
|
38
|
+
* This will automatically get environment variables from .env file
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const index = new Index();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: IndexConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Create a new vector client by providing a custom `Requester` implementation
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
*
|
|
50
|
+
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
51
|
+
*
|
|
52
|
+
* const requester: Requester = {
|
|
53
|
+
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
54
|
+
* // ...
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* const vector = new vector(requester)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
constructor(requesters?: Requester);
|
|
62
|
+
/**
|
|
63
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
64
|
+
*
|
|
65
|
+
* Use this to automatically load connection secrets from your environment
|
|
66
|
+
* variables. For instance when using the Vercel integration.
|
|
67
|
+
*
|
|
68
|
+
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
69
|
+
* your environment using `process.env`.
|
|
70
|
+
*/
|
|
71
|
+
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Index, type IndexConfig, Requester };
|
package/dist/nodejs.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-fCHAzBG_.js';
|
|
2
|
+
export { F as FetchResult, d as InfoResult, Q as QueryResult, c as RangeResult, U as UpstashRequest, b as UpstashResponse, V as Vector } from './vector-fCHAzBG_.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Connection credentials for upstash vector.
|
|
6
|
+
* Get them from https://console.upstash.com/vector/<uuid>
|
|
7
|
+
*/
|
|
8
|
+
type IndexConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* UPSTASH_VECTOR_REST_URL
|
|
11
|
+
*/
|
|
12
|
+
url?: string;
|
|
13
|
+
/**
|
|
14
|
+
* UPSTASH_VECTOR_REST_TOKEN
|
|
15
|
+
*/
|
|
16
|
+
token?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The signal will allow aborting requests on the fly.
|
|
19
|
+
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
20
|
+
*/
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
} & RequesterConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Serverless vector client for upstash.
|
|
25
|
+
*/
|
|
26
|
+
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new vector client by providing the url and token
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const index = new Index({
|
|
33
|
+
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
34
|
+
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
* OR
|
|
38
|
+
* This will automatically get environment variables from .env file
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const index = new Index();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: IndexConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Create a new vector client by providing a custom `Requester` implementation
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
*
|
|
50
|
+
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
51
|
+
*
|
|
52
|
+
* const requester: Requester = {
|
|
53
|
+
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
54
|
+
* // ...
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* const vector = new vector(requester)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
constructor(requesters?: Requester);
|
|
62
|
+
/**
|
|
63
|
+
* Create a new Upstash Vector instance from environment variables.
|
|
64
|
+
*
|
|
65
|
+
* Use this to automatically load connection secrets from your environment
|
|
66
|
+
* variables. For instance when using the Vercel integration.
|
|
67
|
+
*
|
|
68
|
+
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
69
|
+
* your environment using `process.env`.
|
|
70
|
+
*/
|
|
71
|
+
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Index, type IndexConfig, Requester };
|
package/dist/nodejs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var R=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var N=(n,e)=>{for(var t in e)R(n,t,{get:e[t],enumerable:!0})},D=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of P(e))!w.call(n,s)&&s!==t&&R(n,s,{get:()=>e[s],enumerable:!(a=S(e,s))||a.enumerable});return n};var V=n=>D(R({},"__esModule",{value:!0}),n);var _={};N(_,{Index:()=>b});module.exports=V(_);var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var f=class{baseUrl;headers;options;retry;constructor(e){this.options={cache:e.cache,signal:e.signal},this.baseUrl=e.baseUrl.replace(/\/$/,""),this.headers={"Content-Type":"application/json",...e.headers},typeof e?.retry=="boolean"&&e?.retry===!1?this.retry={attempts:1,backoff:()=>0}:this.retry={attempts:e?.retry?.retries??5,backoff:e?.retry?.backoff??(t=>Math.exp(t)*50)}}async request(e){let t={cache:this.options.cache,method:"POST",headers:this.headers,body:JSON.stringify(e.body),keepalive:!0,signal:this.options.signal},a=null,s=null;for(let g=0;g<=this.retry.attempts;g++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(A){if(this.options.signal?.aborted){let M=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),U={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(M,U);break}s=A,await new Promise(M=>setTimeout(M,this.retry.backoff(g)))}if(!a)throw s??new Error("Exhausted all retries");let o=await a.json();if(!a.ok)throw new i(`${o.error}`);return{result:o.result,error:o.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t}async exec(e){let{result:t,error:a}=await e.request({body:this.payload,path:[this.endpoint]});if(a)throw new i(a);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends r{constructor(e,t){let a="delete";t?.namespace&&(a=`${a}/${t.namespace}`);let s=[];Array.isArray(e)?s.push(...e):s.push(e),super(s,a)}};var d=class extends r{constructor(e,t){let a="query";"data"in e&&(a="query-data"),t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var m=class extends r{constructor(e,t){let a="upsert";if(Array.isArray(e)){if(e.some(o=>"data"in o&&o.data)){a="upsert-data";for(let o of e)!("metadata"in o)&&"data"in o&&(o.metadata={data:o.data})}}else"data"in e&&(a="upsert-data","metadata"in e||(e.metadata={data:e.data}));t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var c=class extends r{constructor([e,t]){let a="fetch";t?.namespace&&(a=`${a}/${t.namespace}`,delete t.namespace),super({ids:e,...t},a)}};var l=class extends r{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var u=class extends r{constructor(e){let t="reset";e?.namespace&&(t=`${t}/${e.namespace}`),super([],t)}};var T=class extends r{constructor(){super([],"info")}};var h=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new m(e,{namespace:this.namespace}).exec(this.client);update=e=>new y(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new d(e,{namespace:this.namespace}).exec(this.client);delete=e=>new p(e,{namespace:this.namespace}).exec(this.client);range=e=>new l(e,{namespace:this.namespace}).exec(this.client);reset=()=>new u({namespace:this.namespace}).exec(this.client)};var y=class extends r{constructor(e,t){let a="update";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var C=class extends r{constructor(){super([],"list-namespaces")}};var x=class extends r{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var E=class{client;constructor(e){this.client=e}namespace=e=>new h(this.client,e);delete=(e,t)=>new p(e,t).exec(this.client);query=(e,t)=>new d(e,t).exec(this.client);upsert=(e,t)=>new m(e,t).exec(this.client);update=(e,t)=>new y(e,t).exec(this.client);fetch=(...e)=>new c(e).exec(this.client);reset=e=>new u(e).exec(this.client);range=(e,t)=>new l(e,t).exec(this.client);info=()=>new T().exec(this.client);listNamespaces=()=>new C().exec(this.client);deleteNamespace=e=>new x(e).exec(this.client)};var b=class n extends E{constructor(e){if(typeof e<"u"&&"request"in e){super(e);return}let t=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,a=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!a)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(a.startsWith(" ")||a.endsWith(" ")||/\r|\n/.test(a))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let s=new f({baseUrl:a,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache:e?.cache===!1?void 0:e?.cache||"no-store",signal:e?.signal});super(s)}static fromEnv(e){let t=process?.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");let a=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new n({...e,url:t,token:a})}};0&&(module.exports={Index});
|
package/dist/nodejs.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r,b as s}from"./chunk-HLW45HVB.mjs";var o=class i extends s{constructor(e){if(typeof e<"u"&&"request"in e){super(e);return}let t=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,n=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!n)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(n.startsWith(" ")||n.endsWith(" ")||/\r|\n/.test(n))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let a=new r({baseUrl:n,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache:e?.cache===!1?void 0:e?.cache||"no-store",signal:e?.signal});super(a)}static fromEnv(e){let t=process?.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");let n=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!n)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new i({...e,url:t,token:n})}};export{o as Index};
|
|
@@ -50,7 +50,7 @@ type Vector<TMetadata = Dict> = {
|
|
|
50
50
|
type NAMESPACE = string;
|
|
51
51
|
type Dict = Record<string, unknown>;
|
|
52
52
|
|
|
53
|
-
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
53
|
+
declare const ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
54
54
|
type EndpointVariants = (typeof ENDPOINTS)[number] | `${(typeof ENDPOINTS)[number]}/${NAMESPACE}`;
|
|
55
55
|
/**
|
|
56
56
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
@@ -170,47 +170,35 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
170
170
|
*
|
|
171
171
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
172
172
|
*/
|
|
173
|
-
upsert: <TMetadata extends Dict = TIndexMetadata>(args:
|
|
173
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
174
|
+
id: string | number;
|
|
175
|
+
vector: number[];
|
|
176
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
177
|
+
} | {
|
|
174
178
|
id: string | number;
|
|
175
|
-
} & ({
|
|
176
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
177
179
|
data: string;
|
|
178
|
-
|
|
180
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
179
181
|
} | {
|
|
182
|
+
id: string | number;
|
|
183
|
+
vector: number[];
|
|
180
184
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
181
|
-
|
|
182
|
-
vector?: undefined;
|
|
183
|
-
})) | ({
|
|
185
|
+
}[] | {
|
|
184
186
|
id: string | number;
|
|
185
|
-
|
|
186
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
187
|
-
vector?: number[] | undefined;
|
|
188
|
-
data?: undefined;
|
|
189
|
-
} | {
|
|
187
|
+
data: string;
|
|
190
188
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
189
|
+
}[]) => Promise<string>;
|
|
190
|
+
update: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
191
|
+
id: string | number;
|
|
191
192
|
vector: number[];
|
|
192
|
-
|
|
193
|
-
})) | ({
|
|
193
|
+
} | {
|
|
194
194
|
id: string | number;
|
|
195
|
-
} & ({
|
|
196
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
197
195
|
data: string;
|
|
198
|
-
vector?: undefined;
|
|
199
196
|
} | {
|
|
200
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
201
|
-
data: string;
|
|
202
|
-
vector?: undefined;
|
|
203
|
-
}))[] | ({
|
|
204
197
|
id: string | number;
|
|
205
|
-
} & ({
|
|
206
198
|
metadata: TMetadata extends infer U ? U : never;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
211
|
-
vector: number[];
|
|
212
|
-
data?: undefined;
|
|
213
|
-
}))[]) => Promise<string>;
|
|
199
|
+
}) => Promise<{
|
|
200
|
+
updated: number;
|
|
201
|
+
}>;
|
|
214
202
|
/**
|
|
215
203
|
* It's used for retrieving specific items from the index namespace, optionally including
|
|
216
204
|
* their metadata and feature vectors.
|
|
@@ -317,7 +305,7 @@ type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParamete
|
|
|
317
305
|
/**
|
|
318
306
|
* Serverless vector client for upstash vector db.
|
|
319
307
|
*/
|
|
320
|
-
declare class Index
|
|
308
|
+
declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
321
309
|
protected client: Requester;
|
|
322
310
|
/**
|
|
323
311
|
* Create a new vector db client
|
|
@@ -396,49 +384,39 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
396
384
|
*
|
|
397
385
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
398
386
|
*/
|
|
399
|
-
upsert: <TMetadata extends Dict = TIndexMetadata>(args:
|
|
387
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
388
|
+
id: string | number;
|
|
389
|
+
vector: number[];
|
|
390
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
391
|
+
} | {
|
|
400
392
|
id: string | number;
|
|
401
|
-
} & ({
|
|
402
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
403
393
|
data: string;
|
|
404
|
-
|
|
394
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
405
395
|
} | {
|
|
396
|
+
id: string | number;
|
|
397
|
+
vector: number[];
|
|
406
398
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
407
|
-
|
|
408
|
-
vector?: undefined;
|
|
409
|
-
})) | ({
|
|
399
|
+
}[] | {
|
|
410
400
|
id: string | number;
|
|
411
|
-
|
|
412
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
413
|
-
vector?: number[] | undefined;
|
|
414
|
-
data?: undefined;
|
|
415
|
-
} | {
|
|
401
|
+
data: string;
|
|
416
402
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
403
|
+
}[], options?: {
|
|
404
|
+
namespace?: string;
|
|
405
|
+
}) => Promise<string>;
|
|
406
|
+
update: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
407
|
+
id: string | number;
|
|
417
408
|
vector: number[];
|
|
418
|
-
|
|
419
|
-
})) | ({
|
|
409
|
+
} | {
|
|
420
410
|
id: string | number;
|
|
421
|
-
} & ({
|
|
422
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
423
411
|
data: string;
|
|
424
|
-
vector?: undefined;
|
|
425
412
|
} | {
|
|
426
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
427
|
-
data: string;
|
|
428
|
-
vector?: undefined;
|
|
429
|
-
}))[] | ({
|
|
430
413
|
id: string | number;
|
|
431
|
-
} & ({
|
|
432
414
|
metadata: TMetadata extends infer U ? U : never;
|
|
433
|
-
|
|
434
|
-
data?: undefined;
|
|
435
|
-
} | {
|
|
436
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
437
|
-
vector: number[];
|
|
438
|
-
data?: undefined;
|
|
439
|
-
}))[], options?: {
|
|
415
|
+
}, options?: {
|
|
440
416
|
namespace?: string;
|
|
441
|
-
}) => Promise<
|
|
417
|
+
}) => Promise<{
|
|
418
|
+
updated: number;
|
|
419
|
+
}>;
|
|
442
420
|
/**
|
|
443
421
|
* It's used for retrieving specific items from the index, optionally including
|
|
444
422
|
* their metadata and feature vectors.
|
|
@@ -543,74 +521,4 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
543
521
|
deleteNamespace: (namespace: string) => Promise<string>;
|
|
544
522
|
}
|
|
545
523
|
|
|
546
|
-
|
|
547
|
-
* Connection credentials for upstash vector.
|
|
548
|
-
* Get them from https://console.upstash.com/vector/<uuid>
|
|
549
|
-
*/
|
|
550
|
-
type IndexConfig = {
|
|
551
|
-
/**
|
|
552
|
-
* UPSTASH_VECTOR_REST_URL
|
|
553
|
-
*/
|
|
554
|
-
url?: string;
|
|
555
|
-
/**
|
|
556
|
-
* UPSTASH_VECTOR_REST_TOKEN
|
|
557
|
-
*/
|
|
558
|
-
token?: string;
|
|
559
|
-
/**
|
|
560
|
-
* The signal will allow aborting requests on the fly.
|
|
561
|
-
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
562
|
-
*/
|
|
563
|
-
signal?: AbortSignal;
|
|
564
|
-
} & RequesterConfig;
|
|
565
|
-
/**
|
|
566
|
-
* Serverless vector client for upstash.
|
|
567
|
-
*/
|
|
568
|
-
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
569
|
-
/**
|
|
570
|
-
* Create a new vector client by providing the url and token
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```typescript
|
|
574
|
-
* const index = new Index({
|
|
575
|
-
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
576
|
-
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
577
|
-
* });
|
|
578
|
-
* ```
|
|
579
|
-
* OR
|
|
580
|
-
* This will automatically get environment variables from .env file
|
|
581
|
-
* ```typescript
|
|
582
|
-
* const index = new Index();
|
|
583
|
-
* ```
|
|
584
|
-
*/
|
|
585
|
-
constructor(config?: IndexConfig);
|
|
586
|
-
/**
|
|
587
|
-
* Create a new vector client by providing a custom `Requester` implementation
|
|
588
|
-
*
|
|
589
|
-
* @example
|
|
590
|
-
* ```ts
|
|
591
|
-
*
|
|
592
|
-
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
593
|
-
*
|
|
594
|
-
* const requester: Requester = {
|
|
595
|
-
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
596
|
-
* // ...
|
|
597
|
-
* }
|
|
598
|
-
* }
|
|
599
|
-
*
|
|
600
|
-
* const vector = new vector(requester)
|
|
601
|
-
* ```
|
|
602
|
-
*/
|
|
603
|
-
constructor(requesters?: Requester);
|
|
604
|
-
/**
|
|
605
|
-
* Create a new Upstash Vector instance from environment variables.
|
|
606
|
-
*
|
|
607
|
-
* Use this to automatically load connection secrets from your environment
|
|
608
|
-
* variables. For instance when using the Vercel integration.
|
|
609
|
-
*
|
|
610
|
-
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
611
|
-
* your environment using `process.env`.
|
|
612
|
-
*/
|
|
613
|
-
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
|
|
524
|
+
export { type Dict as D, type FetchResult as F, Index as I, type QueryResult as Q, type RequesterConfig as R, type UpstashRequest as U, type Vector as V, type Requester as a, type UpstashResponse as b, type RangeResult as c, type InfoResult as d };
|
|
@@ -50,7 +50,7 @@ type Vector<TMetadata = Dict> = {
|
|
|
50
50
|
type NAMESPACE = string;
|
|
51
51
|
type Dict = Record<string, unknown>;
|
|
52
52
|
|
|
53
|
-
declare const ENDPOINTS: readonly ["upsert", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
53
|
+
declare const ENDPOINTS: readonly ["upsert", "update", "query", "delete", "fetch", "reset", "range", "info", "upsert-data", "query-data", "list-namespaces", "delete-namespace"];
|
|
54
54
|
type EndpointVariants = (typeof ENDPOINTS)[number] | `${(typeof ENDPOINTS)[number]}/${NAMESPACE}`;
|
|
55
55
|
/**
|
|
56
56
|
* TResult is the raw data returned from upstash, which may need to be transformed or parsed.
|
|
@@ -170,47 +170,35 @@ declare class Namespace<TIndexMetadata extends Dict = Dict> {
|
|
|
170
170
|
*
|
|
171
171
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
172
172
|
*/
|
|
173
|
-
upsert: <TMetadata extends Dict = TIndexMetadata>(args:
|
|
173
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
174
|
+
id: string | number;
|
|
175
|
+
vector: number[];
|
|
176
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
177
|
+
} | {
|
|
174
178
|
id: string | number;
|
|
175
|
-
} & ({
|
|
176
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
177
179
|
data: string;
|
|
178
|
-
|
|
180
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
179
181
|
} | {
|
|
182
|
+
id: string | number;
|
|
183
|
+
vector: number[];
|
|
180
184
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
181
|
-
|
|
182
|
-
vector?: undefined;
|
|
183
|
-
})) | ({
|
|
185
|
+
}[] | {
|
|
184
186
|
id: string | number;
|
|
185
|
-
|
|
186
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
187
|
-
vector?: number[] | undefined;
|
|
188
|
-
data?: undefined;
|
|
189
|
-
} | {
|
|
187
|
+
data: string;
|
|
190
188
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
189
|
+
}[]) => Promise<string>;
|
|
190
|
+
update: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
191
|
+
id: string | number;
|
|
191
192
|
vector: number[];
|
|
192
|
-
|
|
193
|
-
})) | ({
|
|
193
|
+
} | {
|
|
194
194
|
id: string | number;
|
|
195
|
-
} & ({
|
|
196
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
197
195
|
data: string;
|
|
198
|
-
vector?: undefined;
|
|
199
196
|
} | {
|
|
200
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
201
|
-
data: string;
|
|
202
|
-
vector?: undefined;
|
|
203
|
-
}))[] | ({
|
|
204
197
|
id: string | number;
|
|
205
|
-
} & ({
|
|
206
198
|
metadata: TMetadata extends infer U ? U : never;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
211
|
-
vector: number[];
|
|
212
|
-
data?: undefined;
|
|
213
|
-
}))[]) => Promise<string>;
|
|
199
|
+
}) => Promise<{
|
|
200
|
+
updated: number;
|
|
201
|
+
}>;
|
|
214
202
|
/**
|
|
215
203
|
* It's used for retrieving specific items from the index namespace, optionally including
|
|
216
204
|
* their metadata and feature vectors.
|
|
@@ -317,7 +305,7 @@ type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParamete
|
|
|
317
305
|
/**
|
|
318
306
|
* Serverless vector client for upstash vector db.
|
|
319
307
|
*/
|
|
320
|
-
declare class Index
|
|
308
|
+
declare class Index<TIndexMetadata extends Dict = Dict> {
|
|
321
309
|
protected client: Requester;
|
|
322
310
|
/**
|
|
323
311
|
* Create a new vector db client
|
|
@@ -396,49 +384,39 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
396
384
|
*
|
|
397
385
|
* @returns {string} A promise that resolves with the result of the upsert operation after the command is executed.
|
|
398
386
|
*/
|
|
399
|
-
upsert: <TMetadata extends Dict = TIndexMetadata>(args:
|
|
387
|
+
upsert: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
388
|
+
id: string | number;
|
|
389
|
+
vector: number[];
|
|
390
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
391
|
+
} | {
|
|
400
392
|
id: string | number;
|
|
401
|
-
} & ({
|
|
402
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
403
393
|
data: string;
|
|
404
|
-
|
|
394
|
+
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
405
395
|
} | {
|
|
396
|
+
id: string | number;
|
|
397
|
+
vector: number[];
|
|
406
398
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
407
|
-
|
|
408
|
-
vector?: undefined;
|
|
409
|
-
})) | ({
|
|
399
|
+
}[] | {
|
|
410
400
|
id: string | number;
|
|
411
|
-
|
|
412
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
413
|
-
vector?: number[] | undefined;
|
|
414
|
-
data?: undefined;
|
|
415
|
-
} | {
|
|
401
|
+
data: string;
|
|
416
402
|
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
403
|
+
}[], options?: {
|
|
404
|
+
namespace?: string;
|
|
405
|
+
}) => Promise<string>;
|
|
406
|
+
update: <TMetadata extends Dict = TIndexMetadata>(args: {
|
|
407
|
+
id: string | number;
|
|
417
408
|
vector: number[];
|
|
418
|
-
|
|
419
|
-
})) | ({
|
|
409
|
+
} | {
|
|
420
410
|
id: string | number;
|
|
421
|
-
} & ({
|
|
422
|
-
metadata: TMetadata extends infer U ? U : never;
|
|
423
411
|
data: string;
|
|
424
|
-
vector?: undefined;
|
|
425
412
|
} | {
|
|
426
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
427
|
-
data: string;
|
|
428
|
-
vector?: undefined;
|
|
429
|
-
}))[] | ({
|
|
430
413
|
id: string | number;
|
|
431
|
-
} & ({
|
|
432
414
|
metadata: TMetadata extends infer U ? U : never;
|
|
433
|
-
|
|
434
|
-
data?: undefined;
|
|
435
|
-
} | {
|
|
436
|
-
metadata?: (TMetadata extends infer U ? U : never) | undefined;
|
|
437
|
-
vector: number[];
|
|
438
|
-
data?: undefined;
|
|
439
|
-
}))[], options?: {
|
|
415
|
+
}, options?: {
|
|
440
416
|
namespace?: string;
|
|
441
|
-
}) => Promise<
|
|
417
|
+
}) => Promise<{
|
|
418
|
+
updated: number;
|
|
419
|
+
}>;
|
|
442
420
|
/**
|
|
443
421
|
* It's used for retrieving specific items from the index, optionally including
|
|
444
422
|
* their metadata and feature vectors.
|
|
@@ -543,74 +521,4 @@ declare class Index$1<TIndexMetadata extends Dict = Dict> {
|
|
|
543
521
|
deleteNamespace: (namespace: string) => Promise<string>;
|
|
544
522
|
}
|
|
545
523
|
|
|
546
|
-
|
|
547
|
-
* Connection credentials for upstash vector.
|
|
548
|
-
* Get them from https://console.upstash.com/vector/<uuid>
|
|
549
|
-
*/
|
|
550
|
-
type IndexConfig = {
|
|
551
|
-
/**
|
|
552
|
-
* UPSTASH_VECTOR_REST_URL
|
|
553
|
-
*/
|
|
554
|
-
url?: string;
|
|
555
|
-
/**
|
|
556
|
-
* UPSTASH_VECTOR_REST_TOKEN
|
|
557
|
-
*/
|
|
558
|
-
token?: string;
|
|
559
|
-
/**
|
|
560
|
-
* The signal will allow aborting requests on the fly.
|
|
561
|
-
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
562
|
-
*/
|
|
563
|
-
signal?: AbortSignal;
|
|
564
|
-
} & RequesterConfig;
|
|
565
|
-
/**
|
|
566
|
-
* Serverless vector client for upstash.
|
|
567
|
-
*/
|
|
568
|
-
declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
|
|
569
|
-
/**
|
|
570
|
-
* Create a new vector client by providing the url and token
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```typescript
|
|
574
|
-
* const index = new Index({
|
|
575
|
-
* url: "<UPSTASH_VECTOR_REST_URL>",
|
|
576
|
-
* token: "<UPSTASH_VECTOR_REST_TOKEN>",
|
|
577
|
-
* });
|
|
578
|
-
* ```
|
|
579
|
-
* OR
|
|
580
|
-
* This will automatically get environment variables from .env file
|
|
581
|
-
* ```typescript
|
|
582
|
-
* const index = new Index();
|
|
583
|
-
* ```
|
|
584
|
-
*/
|
|
585
|
-
constructor(config?: IndexConfig);
|
|
586
|
-
/**
|
|
587
|
-
* Create a new vector client by providing a custom `Requester` implementation
|
|
588
|
-
*
|
|
589
|
-
* @example
|
|
590
|
-
* ```ts
|
|
591
|
-
*
|
|
592
|
-
* import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
|
|
593
|
-
*
|
|
594
|
-
* const requester: Requester = {
|
|
595
|
-
* request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
|
|
596
|
-
* // ...
|
|
597
|
-
* }
|
|
598
|
-
* }
|
|
599
|
-
*
|
|
600
|
-
* const vector = new vector(requester)
|
|
601
|
-
* ```
|
|
602
|
-
*/
|
|
603
|
-
constructor(requesters?: Requester);
|
|
604
|
-
/**
|
|
605
|
-
* Create a new Upstash Vector instance from environment variables.
|
|
606
|
-
*
|
|
607
|
-
* Use this to automatically load connection secrets from your environment
|
|
608
|
-
* variables. For instance when using the Vercel integration.
|
|
609
|
-
*
|
|
610
|
-
* This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
|
|
611
|
-
* your environment using `process.env`.
|
|
612
|
-
*/
|
|
613
|
-
static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
|
|
524
|
+
export { type Dict as D, type FetchResult as F, Index as I, type QueryResult as Q, type RequesterConfig as R, type UpstashRequest as U, type Vector as V, type Requester as a, type UpstashResponse as b, type RangeResult as c, type InfoResult as d };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@upstash/vector", "version": "v1.1.
|
|
1
|
+
{ "name": "@upstash/vector", "version": "v1.1.2-canary-cloudflare", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "https://github.com/upstash/vector-js" }, "exports": { ".": { "browser": "./dist/nodejs.mjs", "bun": "./dist/nodejs.mjs", "deno": "./dist/nodejs.mjs", "edge-light": "./dist/nodejs.mjs", "edge-routine": "./dist/nodejs.mjs", "netlify": "./dist/nodejs.mjs", "react-native": "./dist/nodejs.mjs", "wintercg": "./dist/nodejs.mjs", "worker": { "import": "./dist/cloudflare.mjs", "types": "./dist/cloudflare.d.ts" }, "workerd": { "import": "./dist/cloudflare.mjs", "types": "./dist/cloudflare.d.ts" }, "node": "./dist/nodejs.mjs", "require": "./dist/nodejs.mjs", "import": "./dist/nodejs.mjs", "types": "./dist/nodejs.d.ts" } }, "main": "./dist/index.js", "module": "./dist/index.mjs", "devDependencies": { "@biomejs/biome": "^1.4.1", "@commitlint/cli": "^18.6.0", "@commitlint/config-conventional": "^18.6.0", "bun-types": "latest", "husky": "^8.0.3", "tsup": "latest", "typescript": "^5.0.0", "vitest": "^1.2.2" }, "bugs": { "url": "https://github.com/upstash/vector/issues" }, "description": "An HTTP/REST based Vector DB client built on top of Upstash REST API.", "files": [ "dist" ], "homepage": "https://upstash.com/vector", "keywords": [ "vector", "upstash", "db" ], "license": "MIT", "scripts": { "test": "bun test src --coverage --bail --coverageSkipTestFiles=[test-utils.ts] --timeout 20000 && vitest run --typecheck", "fmt": "bunx biome check --apply ./src", "build": "tsup", "prepare": "husky install" }, "types": "./dist/nodejs.d.ts" }
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var R=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var N=(n,e)=>{for(var t in e)R(n,t,{get:e[t],enumerable:!0})},U=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of P(e))!w.call(n,s)&&s!==t&&R(n,s,{get:()=>e[s],enumerable:!(a=S(e,s))||a.enumerable});return n};var D=n=>U(R({},"__esModule",{value:!0}),n);var I={};N(I,{Index:()=>M});module.exports=D(I);var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var f=class{baseUrl;headers;options;retry;constructor(e){this.options={cache:e.cache,signal:e.signal},this.baseUrl=e.baseUrl.replace(/\/$/,""),this.headers={"Content-Type":"application/json",...e.headers},typeof e?.retry=="boolean"&&e?.retry===!1?this.retry={attempts:1,backoff:()=>0}:this.retry={attempts:e?.retry?.retries??5,backoff:e?.retry?.backoff??(t=>Math.exp(t)*50)}}async request(e){let t={cache:this.options.cache,method:"POST",headers:this.headers,body:JSON.stringify(e.body),keepalive:!0,signal:this.options.signal},a=null,s=null;for(let x=0;x<=this.retry.attempts;x++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(b){if(this.options.signal?.aborted){let g=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),A={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(g,A);break}s=b,await new Promise(g=>setTimeout(g,this.retry.backoff(x)))}if(!a)throw s??new Error("Exhausted all retries");let o=await a.json();if(!a.ok)throw new i(`${o.error}`);return{result:o.result,error:o.error}}};var r=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t}async exec(e){let{result:t,error:a}=await e.request({body:this.payload,path:[this.endpoint]});if(a)throw new i(a);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends r{constructor(e,t){let a="delete";t?.namespace&&(a=`${a}/${t.namespace}`);let s=[];Array.isArray(e)?s.push(...e):s.push(e),super(s,a)}};var m=class extends r{constructor(e,t){let a="query";"data"in e&&(a="query-data"),t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var d=class extends r{constructor(e,t){let a="upsert";if(Array.isArray(e)){if(e.some(o=>"data"in o&&o.data)){a="upsert-data";for(let o of e)!("metadata"in o)&&"data"in o&&(o.metadata={data:o.data})}}else"data"in e&&(a="upsert-data","metadata"in e||(e.metadata={data:e.data}));t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var c=class extends r{constructor([e,t]){let a="fetch";t?.namespace&&(a=`${a}/${t.namespace}`,delete t.namespace),super({ids:e,...t},a)}};var l=class extends r{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var u=class extends r{constructor(e){let t="reset";e?.namespace&&(t=`${t}/${e.namespace}`),super([],t)}};var y=class extends r{constructor(){super([],"info")}};var h=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new d(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new m(e,{namespace:this.namespace}).exec(this.client);delete=e=>new p(e,{namespace:this.namespace}).exec(this.client);range=e=>new l(e,{namespace:this.namespace}).exec(this.client);reset=()=>new u({namespace:this.namespace}).exec(this.client)};var T=class extends r{constructor(){super([],"list-namespaces")}};var C=class extends r{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var E=class{client;constructor(e){this.client=e}namespace=e=>new h(this.client,e);delete=(e,t)=>new p(e,t).exec(this.client);query=(e,t)=>new m(e,t).exec(this.client);upsert=(e,t)=>new d(e,t).exec(this.client);fetch=(...e)=>new c(e).exec(this.client);reset=e=>new u(e).exec(this.client);range=(e,t)=>new l(e,t).exec(this.client);info=()=>new y().exec(this.client);listNamespaces=()=>new T().exec(this.client);deleteNamespace=e=>new C(e).exec(this.client)};var M=class n extends E{constructor(e){if(typeof e<"u"&&"request"in e){super(e);return}let t=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,a=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!a)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(a.startsWith(" ")||a.endsWith(" ")||/\r|\n/.test(a))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let s=new f({baseUrl:a,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache:e?.cache===!1?void 0:e?.cache||"no-store",signal:e?.signal});super(s)}static fromEnv(e){let t=process?.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");let a=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new n({...e,url:t,token:a})}};0&&(module.exports={Index});
|
package/dist/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var i=class extends Error{constructor(e){super(e),this.name="UpstashError"}};var f=class{baseUrl;headers;options;retry;constructor(e){this.options={cache:e.cache,signal:e.signal},this.baseUrl=e.baseUrl.replace(/\/$/,""),this.headers={"Content-Type":"application/json",...e.headers},typeof e?.retry=="boolean"&&e?.retry===!1?this.retry={attempts:1,backoff:()=>0}:this.retry={attempts:e?.retry?.retries??5,backoff:e?.retry?.backoff??(t=>Math.exp(t)*50)}}async request(e){let t={cache:this.options.cache,method:"POST",headers:this.headers,body:JSON.stringify(e.body),keepalive:!0,signal:this.options.signal},a=null,o=null;for(let x=0;x<=this.retry.attempts;x++)try{a=await fetch([this.baseUrl,...e.path??[]].join("/"),t);break}catch(M){if(this.options.signal?.aborted){let g=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),b={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(g,b);break}o=M,await new Promise(g=>setTimeout(g,this.retry.backoff(x)))}if(!a)throw o??new Error("Exhausted all retries");let s=await a.json();if(!a.ok)throw new i(`${s.error}`);return{result:s.result,error:s.error}}};var n=class{payload;endpoint;constructor(e,t){this.payload=e,this.endpoint=t}async exec(e){let{result:t,error:a}=await e.request({body:this.payload,path:[this.endpoint]});if(a)throw new i(a);if(typeof t>"u")throw new Error("Request did not return a result");return t}};var p=class extends n{constructor(e,t){let a="delete";t?.namespace&&(a=`${a}/${t.namespace}`);let o=[];Array.isArray(e)?o.push(...e):o.push(e),super(o,a)}};var m=class extends n{constructor(e,t){let a="query";"data"in e&&(a="query-data"),t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var d=class extends n{constructor(e,t){let a="upsert";if(Array.isArray(e)){if(e.some(s=>"data"in s&&s.data)){a="upsert-data";for(let s of e)!("metadata"in s)&&"data"in s&&(s.metadata={data:s.data})}}else"data"in e&&(a="upsert-data","metadata"in e||(e.metadata={data:e.data}));t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var c=class extends n{constructor([e,t]){let a="fetch";t?.namespace&&(a=`${a}/${t.namespace}`,delete t.namespace),super({ids:e,...t},a)}};var l=class extends n{constructor(e,t){let a="range";t?.namespace&&(a=`${a}/${t.namespace}`),super(e,a)}};var u=class extends n{constructor(e){let t="reset";e?.namespace&&(t=`${t}/${e.namespace}`),super([],t)}};var y=class extends n{constructor(){super([],"info")}};var h=class{client;namespace;constructor(e,t){this.client=e,this.namespace=t}upsert=e=>new d(e,{namespace:this.namespace}).exec(this.client);fetch=(...e)=>(e[1]?e[1].namespace=this.namespace:e[1]={namespace:this.namespace},new c(e).exec(this.client));query=e=>new m(e,{namespace:this.namespace}).exec(this.client);delete=e=>new p(e,{namespace:this.namespace}).exec(this.client);range=e=>new l(e,{namespace:this.namespace}).exec(this.client);reset=()=>new u({namespace:this.namespace}).exec(this.client)};var T=class extends n{constructor(){super([],"list-namespaces")}};var C=class extends n{constructor(e){let t=`delete-namespace/${e}`;super([],t)}};var E=class{client;constructor(e){this.client=e}namespace=e=>new h(this.client,e);delete=(e,t)=>new p(e,t).exec(this.client);query=(e,t)=>new m(e,t).exec(this.client);upsert=(e,t)=>new d(e,t).exec(this.client);fetch=(...e)=>new c(e).exec(this.client);reset=e=>new u(e).exec(this.client);range=(e,t)=>new l(e,t).exec(this.client);info=()=>new y().exec(this.client);listNamespaces=()=>new T().exec(this.client);deleteNamespace=e=>new C(e).exec(this.client)};var R=class r extends E{constructor(e){if(typeof e<"u"&&"request"in e){super(e);return}let t=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,a=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!a)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(a.startsWith(" ")||a.endsWith(" ")||/\r|\n/.test(a))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let o=new f({baseUrl:a,retry:e?.retry,headers:{authorization:`Bearer ${t}`},cache:e?.cache===!1?void 0:e?.cache||"no-store",signal:e?.signal});super(o)}static fromEnv(e){let t=process?.env.UPSTASH_VECTOR_REST_URL;if(!t)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`");let a=process?.env.UPSTASH_VECTOR_REST_TOKEN;if(!a)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`");return new r({...e,url:t,token:a})}};export{R as Index};
|