@upstash/redis 1.34.1 → 1.34.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.
package/cloudflare.mjs CHANGED
@@ -1 +1,91 @@
1
- import{a as S,b as i,c as s,d as o}from"./chunk-6D54FT2F.mjs";var a=class l extends s{constructor(e,t){if(!e.url)throw new Error("[Upstash Redis] The 'url' property is missing or undefined in your Redis config.");if(!e.token)throw new Error("[Upstash Redis] The 'token' property is missing or undefined in your Redis config.");(e.url.startsWith(" ")||e.url.endsWith(" ")||/\r|\n/.test(e.url))&&console.warn("The redis url contains whitespace or newline, which can cause errors!"),(e.token.startsWith(" ")||e.token.endsWith(" ")||/\r|\n/.test(e.token))&&console.warn("The redis token contains whitespace or newline, which can cause errors!");let r=new i({retry:e.retry,baseUrl:e.url,headers:{authorization:`Bearer ${e.token}`},responseEncoding:e.responseEncoding,signal:e.signal,keepAlive:e.keepAlive,readYourWrites:e.readYourWrites});if(super(r,{enableTelemetry:!t?.UPSTASH_DISABLE_TELEMETRY,automaticDeserialization:e.automaticDeserialization,latencyLogging:e.latencyLogging,enableAutoPipelining:e.enableAutoPipelining}),this.addTelemetry({platform:"cloudflare",sdk:`@upstash/redis@${o}`}),this.enableAutoPipelining)return this.autoPipeline()}static fromEnv(e,t){let r=e?.UPSTASH_REDIS_REST_URL??UPSTASH_REDIS_REST_URL,n=e?.UPSTASH_REDIS_REST_TOKEN??UPSTASH_REDIS_REST_TOKEN;if(!r)throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_URL`");if(!n)throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`");return new l({...t,url:r,token:n},e)}};export{a as Redis,S as errors};
1
+ import {
2
+ HttpClient,
3
+ Redis,
4
+ VERSION,
5
+ error_exports
6
+ } from "./chunk-3XV7NWGI.mjs";
7
+
8
+ // platforms/cloudflare.ts
9
+ var Redis2 = class _Redis extends Redis {
10
+ /**
11
+ * Create a new redis client
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const redis = new Redis({
16
+ * url: "<UPSTASH_REDIS_REST_URL>",
17
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
18
+ * });
19
+ * ```
20
+ */
21
+ constructor(config, env) {
22
+ if (!config.url) {
23
+ throw new Error(
24
+ `[Upstash Redis] The 'url' property is missing or undefined in your Redis config.`
25
+ );
26
+ }
27
+ if (!config.token) {
28
+ throw new Error(
29
+ `[Upstash Redis] The 'token' property is missing or undefined in your Redis config.`
30
+ );
31
+ }
32
+ if (config.url.startsWith(" ") || config.url.endsWith(" ") || /\r|\n/.test(config.url)) {
33
+ console.warn("The redis url contains whitespace or newline, which can cause errors!");
34
+ }
35
+ if (config.token.startsWith(" ") || config.token.endsWith(" ") || /\r|\n/.test(config.token)) {
36
+ console.warn("The redis token contains whitespace or newline, which can cause errors!");
37
+ }
38
+ const client = new HttpClient({
39
+ retry: config.retry,
40
+ baseUrl: config.url,
41
+ headers: { authorization: `Bearer ${config.token}` },
42
+ responseEncoding: config.responseEncoding,
43
+ signal: config.signal,
44
+ keepAlive: config.keepAlive,
45
+ readYourWrites: config.readYourWrites
46
+ });
47
+ super(client, {
48
+ enableTelemetry: !env?.UPSTASH_DISABLE_TELEMETRY,
49
+ automaticDeserialization: config.automaticDeserialization,
50
+ latencyLogging: config.latencyLogging,
51
+ enableAutoPipelining: config.enableAutoPipelining
52
+ });
53
+ this.addTelemetry({
54
+ platform: "cloudflare",
55
+ sdk: `@upstash/redis@${VERSION}`
56
+ });
57
+ if (this.enableAutoPipelining) {
58
+ return this.autoPipeline();
59
+ }
60
+ }
61
+ /*
62
+ * Create a new Upstash Redis instance from environment variables on cloudflare.
63
+ *
64
+ * This tries to load `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` from
65
+ * the global namespace
66
+ *
67
+ * If you are using a module worker, please pass in the `env` object.
68
+ * ```ts
69
+ * const redis = Redis.fromEnv(env)
70
+ * ```
71
+ */
72
+ static fromEnv(env, opts) {
73
+ const url = env?.UPSTASH_REDIS_REST_URL ?? UPSTASH_REDIS_REST_URL;
74
+ const token = env?.UPSTASH_REDIS_REST_TOKEN ?? UPSTASH_REDIS_REST_TOKEN;
75
+ if (!url) {
76
+ throw new Error(
77
+ "Unable to find environment variable: `UPSTASH_REDIS_REST_URL`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_URL`"
78
+ );
79
+ }
80
+ if (!token) {
81
+ throw new Error(
82
+ "Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`"
83
+ );
84
+ }
85
+ return new _Redis({ ...opts, url, token }, env);
86
+ }
87
+ };
88
+ export {
89
+ Redis2 as Redis,
90
+ error_exports as errors
91
+ };