Skip to content

Commit d4bb005

Browse files
authored
Allow undefined constructor values (#1065)
* chore: allow undefined constructor values * style: fmt
1 parent 36bcd25 commit d4bb005

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

platforms/cloudflare.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export type RedisConfigCloudflare = {
1717
/**
1818
* UPSTASH_REDIS_REST_URL
1919
*/
20-
url: string;
20+
url: string | undefined;
2121
/**
2222
* UPSTASH_REDIS_REST_TOKEN
2323
*/
24-
token: string;
24+
token: string | undefined;
2525
/**
2626
* The signal will allow aborting requests on the fly.
2727
* For more check: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
@@ -47,6 +47,14 @@ export class Redis extends core.Redis {
4747
* ```
4848
*/
4949
constructor(config: RedisConfigCloudflare, env?: Env) {
50+
if(!config.url) {
51+
throw new Error(`[Upstash Redis] The 'url' property is missing or undefined in your Redis config.`)
52+
}
53+
54+
if(!config.token) {
55+
throw new Error(`[Upstash Redis] The 'token' property is missing or undefined in your Redis config.`)
56+
}
57+
5058
if (config.url.startsWith(" ") || config.url.endsWith(" ") || /\r|\n/.test(config.url)) {
5159
console.warn("The redis url contains whitespace or newline, which can cause errors!");
5260
}

platforms/fastly.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export type RedisConfigFastly = {
1414
/**
1515
* UPSTASH_REDIS_REST_URL
1616
*/
17-
url: string;
17+
url: string | undefined;
1818
/**
1919
* UPSTASH_REDIS_REST_TOKEN
2020
*/
21-
token: string;
21+
token: string | undefined;
2222
/**
2323
* A Request can be forwarded to any backend defined on your service. Backends
2424
* can be created via the Fastly CLI, API, or web interface, and are
@@ -45,6 +45,14 @@ export class Redis extends core.Redis {
4545
* ```
4646
*/
4747
constructor(config: RedisConfigFastly) {
48+
if(!config.url) {
49+
throw new Error(`[Upstash Redis] The 'url' property is missing or undefined in your Redis config.`)
50+
}
51+
52+
if(!config.token) {
53+
throw new Error(`[Upstash Redis] The 'token' property is missing or undefined in your Redis config.`)
54+
}
55+
4856
if (config.url.startsWith(" ") || config.url.endsWith(" ") || /\r|\n/.test(config.url)) {
4957
console.warn("The redis url contains whitespace or newline, which can cause errors!");
5058
}

platforms/nodejs.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export type RedisConfigNodejs = {
2727
/**
2828
* UPSTASH_REDIS_REST_URL
2929
*/
30-
url: string;
30+
url: string | undefined;
3131
/**
3232
* UPSTASH_REDIS_REST_TOKEN
3333
*/
34-
token: string;
34+
token: string | undefined;
3535

3636
/**
3737
* An agent allows you to reuse connections to reduce latency for multiple sequential requests.
@@ -98,6 +98,15 @@ export class Redis extends core.Redis {
9898
super(configOrRequester);
9999
return;
100100
}
101+
102+
if(!configOrRequester.url) {
103+
throw new Error(`[Upstash Redis] The 'url' property is missing or undefined in your Redis config.`)
104+
}
105+
106+
if(!configOrRequester.token) {
107+
throw new Error(`[Upstash Redis] The 'token' property is missing or undefined in your Redis config.`)
108+
}
109+
101110
if (
102111
configOrRequester.url.startsWith(" ") ||
103112
configOrRequester.url.endsWith(" ") ||

0 commit comments

Comments
 (0)