@upstash/vector 1.1.2-cloudflare-01 → 1.1.2

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.
@@ -305,7 +305,7 @@ type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParamete
305
305
  /**
306
306
  * Serverless vector client for upstash vector db.
307
307
  */
308
- declare class Index<TIndexMetadata extends Dict = Dict> {
308
+ declare class Index$1<TIndexMetadata extends Dict = Dict> {
309
309
  protected client: Requester;
310
310
  /**
311
311
  * Create a new vector db client
@@ -521,4 +521,74 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
521
521
  deleteNamespace: (namespace: string) => Promise<string>;
522
522
  }
523
523
 
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 };
524
+ /**
525
+ * Connection credentials for upstash vector.
526
+ * Get them from https://console.upstash.com/vector/<uuid>
527
+ */
528
+ type IndexConfig = {
529
+ /**
530
+ * UPSTASH_VECTOR_REST_URL
531
+ */
532
+ url?: string;
533
+ /**
534
+ * UPSTASH_VECTOR_REST_TOKEN
535
+ */
536
+ token?: string;
537
+ /**
538
+ * The signal will allow aborting requests on the fly.
539
+ * For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
540
+ */
541
+ signal?: AbortSignal;
542
+ } & RequesterConfig;
543
+ /**
544
+ * Serverless vector client for upstash.
545
+ */
546
+ declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
547
+ /**
548
+ * Create a new vector client by providing the url and token
549
+ *
550
+ * @example
551
+ * ```typescript
552
+ * const index = new Index({
553
+ * url: "<UPSTASH_VECTOR_REST_URL>",
554
+ * token: "<UPSTASH_VECTOR_REST_TOKEN>",
555
+ * });
556
+ * ```
557
+ * OR
558
+ * This will automatically get environment variables from .env file
559
+ * ```typescript
560
+ * const index = new Index();
561
+ * ```
562
+ */
563
+ constructor(config?: IndexConfig);
564
+ /**
565
+ * Create a new vector client by providing a custom `Requester` implementation
566
+ *
567
+ * @example
568
+ * ```ts
569
+ *
570
+ * import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
571
+ *
572
+ * const requester: Requester = {
573
+ * request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
574
+ * // ...
575
+ * }
576
+ * }
577
+ *
578
+ * const vector = new vector(requester)
579
+ * ```
580
+ */
581
+ constructor(requesters?: Requester);
582
+ /**
583
+ * Create a new Upstash Vector instance from environment variables.
584
+ *
585
+ * Use this to automatically load connection secrets from your environment
586
+ * variables. For instance when using the Vercel integration.
587
+ *
588
+ * This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
589
+ * your environment using `process.env`.
590
+ */
591
+ static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
592
+ }
593
+
594
+ export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
@@ -305,7 +305,7 @@ type CommandArgs<TCommand extends new (_args: any) => any> = ConstructorParamete
305
305
  /**
306
306
  * Serverless vector client for upstash vector db.
307
307
  */
308
- declare class Index<TIndexMetadata extends Dict = Dict> {
308
+ declare class Index$1<TIndexMetadata extends Dict = Dict> {
309
309
  protected client: Requester;
310
310
  /**
311
311
  * Create a new vector db client
@@ -521,4 +521,74 @@ declare class Index<TIndexMetadata extends Dict = Dict> {
521
521
  deleteNamespace: (namespace: string) => Promise<string>;
522
522
  }
523
523
 
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 };
524
+ /**
525
+ * Connection credentials for upstash vector.
526
+ * Get them from https://console.upstash.com/vector/<uuid>
527
+ */
528
+ type IndexConfig = {
529
+ /**
530
+ * UPSTASH_VECTOR_REST_URL
531
+ */
532
+ url?: string;
533
+ /**
534
+ * UPSTASH_VECTOR_REST_TOKEN
535
+ */
536
+ token?: string;
537
+ /**
538
+ * The signal will allow aborting requests on the fly.
539
+ * For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
540
+ */
541
+ signal?: AbortSignal;
542
+ } & RequesterConfig;
543
+ /**
544
+ * Serverless vector client for upstash.
545
+ */
546
+ declare class Index<TIndexMetadata extends Dict = Dict> extends Index$1<TIndexMetadata> {
547
+ /**
548
+ * Create a new vector client by providing the url and token
549
+ *
550
+ * @example
551
+ * ```typescript
552
+ * const index = new Index({
553
+ * url: "<UPSTASH_VECTOR_REST_URL>",
554
+ * token: "<UPSTASH_VECTOR_REST_TOKEN>",
555
+ * });
556
+ * ```
557
+ * OR
558
+ * This will automatically get environment variables from .env file
559
+ * ```typescript
560
+ * const index = new Index();
561
+ * ```
562
+ */
563
+ constructor(config?: IndexConfig);
564
+ /**
565
+ * Create a new vector client by providing a custom `Requester` implementation
566
+ *
567
+ * @example
568
+ * ```ts
569
+ *
570
+ * import { UpstashRequest, Requester, UpstashResponse, vector } from "@upstash/vector"
571
+ *
572
+ * const requester: Requester = {
573
+ * request: <TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>> => {
574
+ * // ...
575
+ * }
576
+ * }
577
+ *
578
+ * const vector = new vector(requester)
579
+ * ```
580
+ */
581
+ constructor(requesters?: Requester);
582
+ /**
583
+ * Create a new Upstash Vector instance from environment variables.
584
+ *
585
+ * Use this to automatically load connection secrets from your environment
586
+ * variables. For instance when using the Vercel integration.
587
+ *
588
+ * This tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
589
+ * your environment using `process.env`.
590
+ */
591
+ static fromEnv(config?: Omit<IndexConfig, "url" | "token">): Index;
592
+ }
593
+
594
+ export { type FetchResult, Index, type IndexConfig, type InfoResult, type QueryResult, type RangeResult, type Requester, type UpstashRequest, type UpstashResponse, type Vector };
@@ -1 +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};
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 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 M=new Blob([JSON.stringify({result:this.options.signal.reason??"Aborted"})]),A={status:200,statusText:this.options.signal.reason??"Aborted"};a=new Response(M,A);break}o=b,await new Promise(M=>setTimeout(M,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 T=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 T().exec(this.client);listNamespaces=()=>new C().exec(this.client);deleteNamespace=e=>new x(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};
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@upstash/vector", "version": "v1.1.2-cloudflare-01", "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" }
1
+ { "name": "@upstash/vector", "version": "v1.1.2", "author": "Oguzhan Olguncu <oguzhan@upstash.com>", "repository": { "type": "git", "url": "https://github.com/upstash/vector-js" }, "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/index.d.ts" }
@@ -1,59 +0,0 @@
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 };
@@ -1,59 +0,0 @@
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 };
@@ -1 +0,0 @@
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});
@@ -1 +0,0 @@
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};
package/dist/nodejs.d.mts DELETED
@@ -1,74 +0,0 @@
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 DELETED
@@ -1,74 +0,0 @@
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.mjs DELETED
@@ -1 +0,0 @@
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};
File without changes