@upstash/vector 1.1.5 → 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.
- package/README.md +4 -4
- package/dist/chunk-XN6MKCVR.mjs +761 -0
- package/dist/cloudflare.d.mts +2 -2
- package/dist/cloudflare.d.ts +2 -2
- package/dist/cloudflare.js +860 -1
- package/dist/cloudflare.mjs +81 -1
- package/dist/nodejs.d.mts +2 -2
- package/dist/nodejs.d.ts +2 -2
- package/dist/nodejs.js +839 -1
- package/dist/nodejs.mjs +60 -1
- package/dist/{vector-wT6XsV3D.d.mts → vector-gR6tGrYi.d.mts} +82 -12
- package/dist/{vector-wT6XsV3D.d.ts → vector-gR6tGrYi.d.ts} +82 -12
- package/package.json +1 -1
- package/dist/chunk-J6ZA44LH.mjs +0 -1
package/dist/cloudflare.mjs
CHANGED
|
@@ -1 +1,81 @@
|
|
|
1
|
-
import
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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.
|