@upstash/vector 1.1.6 → 1.1.7

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.
@@ -1 +1,81 @@
1
- import{a as s,b as i}from"./chunk-AGHQGIQX.mjs";var o=class T extends i{constructor(e){let r=e?.token??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN??process.env.UPSTASH_VECTOR_REST_TOKEN,t=e?.url??process.env.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL??process.env.UPSTASH_VECTOR_REST_URL;if(!r)throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");if(!t)throw new Error("UPSTASH_VECTOR_REST_URL is missing!");(t.startsWith(" ")||t.endsWith(" ")||/\r|\n/.test(t))&&console.warn("The vector url contains whitespace or newline, which can cause errors!"),(r.startsWith(" ")||r.endsWith(" ")||/\r|\n/.test(r))&&console.warn("The vector token contains whitespace or newline, which can cause errors!");let n=new s({baseUrl:t,retry:e?.retry,headers:{authorization:`Bearer ${r}`},signal:e?.signal,cache:e?.cache===!1?void 0:e?.cache});super(n)}static fromEnv(e,r){let t,n;if(e){if(t=e.UPSTASH_VECTOR_REST_URL,!t)throw new Error("Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`");if(n=e.UPSTASH_VECTOR_REST_TOKEN,!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 T({...r,url:t,token:n})}};export{o as Index};
1
+ import {
2
+ HttpClient,
3
+ Index
4
+ } from "./chunk-XN6MKCVR.mjs";
5
+
6
+ // src/platforms/cloudflare.ts
7
+ var Index2 = class _Index extends Index {
8
+ /**
9
+ * Create a new vector client by providing the url and token
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const index = new Index({
14
+ * url: "<UPSTASH_VECTOR_REST_URL>",
15
+ * token: "<UPSTASH_VECTOR_REST_TOKEN>",
16
+ * });
17
+ * ```
18
+ * OR
19
+ * This will automatically get environment variables from .env file
20
+ * ```typescript
21
+ * const index = new Index();
22
+ * ```
23
+ */
24
+ constructor(config) {
25
+ const safeProcess = typeof process === "undefined" ? {} : process;
26
+ const token = config?.token ?? safeProcess.NEXT_PUBLIC_UPSTASH_VECTOR_REST_TOKEN ?? safeProcess.UPSTASH_VECTOR_REST_TOKEN;
27
+ const url = config?.url ?? safeProcess.NEXT_PUBLIC_UPSTASH_VECTOR_REST_URL ?? safeProcess.UPSTASH_VECTOR_REST_URL;
28
+ if (!token) {
29
+ throw new Error("UPSTASH_VECTOR_REST_TOKEN is missing!");
30
+ }
31
+ if (!url) {
32
+ throw new Error("UPSTASH_VECTOR_REST_URL is missing!");
33
+ }
34
+ if (url.startsWith(" ") || url.endsWith(" ") || /\r|\n/.test(url)) {
35
+ console.warn("The vector url contains whitespace or newline, which can cause errors!");
36
+ }
37
+ if (token.startsWith(" ") || token.endsWith(" ") || /\r|\n/.test(token)) {
38
+ console.warn("The vector token contains whitespace or newline, which can cause errors!");
39
+ }
40
+ const client = new HttpClient({
41
+ baseUrl: url,
42
+ retry: config?.retry,
43
+ headers: { authorization: `Bearer ${token}` },
44
+ signal: config?.signal,
45
+ cache: config?.cache === false ? void 0 : config?.cache
46
+ });
47
+ super(client);
48
+ }
49
+ /**
50
+ * Create a new Upstash Vector instance from environment variables.
51
+ *
52
+ * Use this to automatically load connection secrets from your environment
53
+ * variables. For instance when using the Vercel integration.
54
+ *
55
+ * When used on the Cloudflare Workers, you can just pass the "env" context provided by Cloudflare.
56
+ * Else, this tries to load `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN` from
57
+ * your environment using `process.env`.
58
+ */
59
+ static fromEnv(env, config) {
60
+ let url;
61
+ let token;
62
+ if (env) {
63
+ url = env.UPSTASH_VECTOR_REST_URL;
64
+ if (!url) {
65
+ throw new Error(
66
+ "Unable to find environment variable: `UPSTASH_VECTOR_REST_URL`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_URL`"
67
+ );
68
+ }
69
+ token = env.UPSTASH_VECTOR_REST_TOKEN;
70
+ if (!token) {
71
+ throw new Error(
72
+ "Unable to find environment variable: `UPSTASH_VECTOR_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_VECTOR_REST_TOKEN`"
73
+ );
74
+ }
75
+ }
76
+ return new _Index({ ...config, url, token });
77
+ }
78
+ };
79
+ export {
80
+ Index2 as Index
81
+ };
package/dist/nodejs.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-Kaq7eMt8.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-Kaq7eMt8.mjs';
1
+ import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-gR6tGrYi.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-gR6tGrYi.mjs';
3
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.
package/dist/nodejs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-Kaq7eMt8.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-Kaq7eMt8.js';
1
+ import { R as RequesterConfig, D as Dict, I as Index$1, a as Requester } from './vector-gR6tGrYi.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-gR6tGrYi.js';
3
3
 
4
4
  /**
5
5
  * Connection credentials for upstash vector.