@upstash/redis 1.0.0-alpha.1 → 1.0.0-alpha.4
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/chunk-6GEVIAL6.mjs +38 -0
- package/chunk-7YUZYRJS.mjs +29 -0
- package/chunk-HIDCSH5S.mjs +36 -0
- package/{dist/index.mjs → chunk-Y5TC4HX2.mjs} +10 -74
- package/{dist/chunk-RYSRH3HC.mjs → chunk-ZIB6XPPC.mjs} +4 -27
- package/cloudflare.d.ts +38 -0
- package/cloudflare.js +1737 -0
- package/cloudflare.mjs +35 -0
- package/{dist/commands.d.ts → commands.d.ts} +3 -2
- package/{dist/commands.js → commands.js} +1 -1
- package/{dist/commands.mjs → commands.mjs} +2 -1
- package/fastly.d.ts +44 -0
- package/fastly.js +1727 -0
- package/fastly.mjs +25 -0
- package/http.d.ts +29 -0
- package/http.js +83 -0
- package/http.mjs +7 -0
- package/index.d.ts +13 -0
- package/{dist/index.js → index.js} +61 -72
- package/index.mjs +13 -0
- package/nodejs.d.ts +47 -0
- package/nodejs.js +1741 -0
- package/nodejs.mjs +10 -0
- package/package.json +1 -1
- package/{dist/index.d.ts → redis-dd052782.d.ts} +4 -53
- package/{dist/zunionstore-462de5d3.d.ts → zunionstore-dffa797d.d.ts} +2 -27
- package/LICENSE +0 -21
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Redis
|
|
3
|
+
} from "./chunk-Y5TC4HX2.mjs";
|
|
4
|
+
import {
|
|
5
|
+
HttpClient
|
|
6
|
+
} from "./chunk-HIDCSH5S.mjs";
|
|
7
|
+
|
|
8
|
+
// pkg/nodejs.ts
|
|
9
|
+
import "isomorphic-fetch";
|
|
10
|
+
var Redis2 = class extends Redis {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
const client = new HttpClient({
|
|
13
|
+
baseUrl: config.url,
|
|
14
|
+
headers: {
|
|
15
|
+
authorization: `Bearer ${config.token}`
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
super(client);
|
|
19
|
+
}
|
|
20
|
+
static fromEnv() {
|
|
21
|
+
if (typeof (process == null ? void 0 : process.env) === "undefined") {
|
|
22
|
+
throw new Error("Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please use `Redis.onCloudflare()` instead");
|
|
23
|
+
}
|
|
24
|
+
const url = process.env["UPSTASH_REDIS_REST_URL"];
|
|
25
|
+
if (!url) {
|
|
26
|
+
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
|
|
27
|
+
}
|
|
28
|
+
const token = process.env["UPSTASH_REDIS_REST_TOKEN"];
|
|
29
|
+
if (!token) {
|
|
30
|
+
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
|
|
31
|
+
}
|
|
32
|
+
return new Redis2({ url, token });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
Redis2 as Redis
|
|
38
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// pkg/error.ts
|
|
19
|
+
var UpstashError = class extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "UpstashError";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
__spreadValues,
|
|
28
|
+
UpstashError
|
|
29
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UpstashError,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./chunk-7YUZYRJS.mjs";
|
|
5
|
+
|
|
6
|
+
// pkg/http.ts
|
|
7
|
+
var HttpClient = class {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
10
|
+
this.headers = __spreadValues({
|
|
11
|
+
"Content-Type": "application/json"
|
|
12
|
+
}, config.headers);
|
|
13
|
+
this.options = config.options;
|
|
14
|
+
}
|
|
15
|
+
async request(req) {
|
|
16
|
+
var _a;
|
|
17
|
+
if (!req.path) {
|
|
18
|
+
req.path = [];
|
|
19
|
+
}
|
|
20
|
+
const res = await fetch([this.baseUrl, ...req.path].join("/"), {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: this.headers,
|
|
23
|
+
body: JSON.stringify(req.body),
|
|
24
|
+
backend: (_a = this.options) == null ? void 0 : _a.backend
|
|
25
|
+
});
|
|
26
|
+
const body = await res.json();
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
throw new UpstashError(body.error);
|
|
29
|
+
}
|
|
30
|
+
return body;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
HttpClient
|
|
36
|
+
};
|
|
@@ -88,7 +88,6 @@ import {
|
|
|
88
88
|
TtlCommand,
|
|
89
89
|
TypeCommand,
|
|
90
90
|
UnlinkCommand,
|
|
91
|
-
UpstashError,
|
|
92
91
|
ZAddCommand,
|
|
93
92
|
ZCardCommand,
|
|
94
93
|
ZCountCommand,
|
|
@@ -106,43 +105,11 @@ import {
|
|
|
106
105
|
ZRevRankCommand,
|
|
107
106
|
ZScanCommand,
|
|
108
107
|
ZScoreCommand,
|
|
109
|
-
ZUnionStoreCommand
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
import "isomorphic-fetch";
|
|
115
|
-
var HttpClient = class {
|
|
116
|
-
constructor(config) {
|
|
117
|
-
var _a;
|
|
118
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
119
|
-
this.headers = (_a = config.headers) != null ? _a : {};
|
|
120
|
-
this.options = config.options;
|
|
121
|
-
}
|
|
122
|
-
async request(method, req) {
|
|
123
|
-
var _a;
|
|
124
|
-
if (!req.path) {
|
|
125
|
-
req.path = [];
|
|
126
|
-
}
|
|
127
|
-
const headers = __spreadValues(__spreadValues({
|
|
128
|
-
"Content-Type": "application/json"
|
|
129
|
-
}, this.headers), req.headers);
|
|
130
|
-
const res = await fetch([this.baseUrl, ...req.path].join("/"), {
|
|
131
|
-
method,
|
|
132
|
-
headers,
|
|
133
|
-
body: JSON.stringify(req.body),
|
|
134
|
-
backend: (_a = this.options) == null ? void 0 : _a.backend
|
|
135
|
-
});
|
|
136
|
-
const body = await res.json();
|
|
137
|
-
if (!res.ok) {
|
|
138
|
-
throw new UpstashError(body.error);
|
|
139
|
-
}
|
|
140
|
-
return body;
|
|
141
|
-
}
|
|
142
|
-
async post(req) {
|
|
143
|
-
return await this.request("POST", req);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
108
|
+
ZUnionStoreCommand
|
|
109
|
+
} from "./chunk-ZIB6XPPC.mjs";
|
|
110
|
+
import {
|
|
111
|
+
UpstashError
|
|
112
|
+
} from "./chunk-7YUZYRJS.mjs";
|
|
146
113
|
|
|
147
114
|
// pkg/pipeline.ts
|
|
148
115
|
var Pipeline = class {
|
|
@@ -154,7 +121,7 @@ var Pipeline = class {
|
|
|
154
121
|
if (this.commands.length === 0) {
|
|
155
122
|
throw new Error("Pipeline is empty");
|
|
156
123
|
}
|
|
157
|
-
const res = await this.client.
|
|
124
|
+
const res = await this.client.request({
|
|
158
125
|
path: ["pipeline"],
|
|
159
126
|
body: Object.values(this.commands).map((c) => c.command)
|
|
160
127
|
});
|
|
@@ -494,39 +461,8 @@ var Pipeline = class {
|
|
|
494
461
|
|
|
495
462
|
// pkg/redis.ts
|
|
496
463
|
var Redis = class {
|
|
497
|
-
constructor(
|
|
498
|
-
this.client =
|
|
499
|
-
baseUrl: config.url,
|
|
500
|
-
headers: {
|
|
501
|
-
authorization: `Bearer ${config.token}`
|
|
502
|
-
},
|
|
503
|
-
options: config.requestOptions
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
static fromEnv() {
|
|
507
|
-
if (typeof (process == null ? void 0 : process.env) === "undefined") {
|
|
508
|
-
throw new Error("Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please use `fromCloudflareEnv()` instead");
|
|
509
|
-
}
|
|
510
|
-
const url = process.env["UPSTASH_REDIS_REST_URL"];
|
|
511
|
-
if (!url) {
|
|
512
|
-
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
|
|
513
|
-
}
|
|
514
|
-
const token = process.env["UPSTASH_REDIS_REST_TOKEN"];
|
|
515
|
-
if (!token) {
|
|
516
|
-
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
|
|
517
|
-
}
|
|
518
|
-
return new Redis({ url, token });
|
|
519
|
-
}
|
|
520
|
-
static fromCloudflareEnv() {
|
|
521
|
-
const url = UPSTASH_REDIS_REST_URL;
|
|
522
|
-
const token = UPSTASH_REDIS_REST_TOKEN;
|
|
523
|
-
if (!url) {
|
|
524
|
-
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
|
|
525
|
-
}
|
|
526
|
-
if (!token) {
|
|
527
|
-
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
|
|
528
|
-
}
|
|
529
|
-
return new Redis({ url, token });
|
|
464
|
+
constructor(client) {
|
|
465
|
+
this.client = client;
|
|
530
466
|
}
|
|
531
467
|
pipeline() {
|
|
532
468
|
return new Pipeline(this.client);
|
|
@@ -856,7 +792,7 @@ var Redis = class {
|
|
|
856
792
|
return new ZUnionStoreCommand(...args).exec(this.client);
|
|
857
793
|
}
|
|
858
794
|
};
|
|
795
|
+
|
|
859
796
|
export {
|
|
860
|
-
Redis
|
|
861
|
-
UpstashError
|
|
797
|
+
Redis
|
|
862
798
|
};
|
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// pkg/error.ts
|
|
19
|
-
var UpstashError = class extends Error {
|
|
20
|
-
constructor(message) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.name = "UpstashError";
|
|
23
|
-
}
|
|
24
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
UpstashError
|
|
3
|
+
} from "./chunk-7YUZYRJS.mjs";
|
|
25
4
|
|
|
26
5
|
// pkg/util.ts
|
|
27
6
|
function parseRecursive(obj) {
|
|
@@ -49,7 +28,7 @@ var Command = class {
|
|
|
49
28
|
this.deserialize = (_a = opts == null ? void 0 : opts.deserialize) != null ? _a : parseResponse;
|
|
50
29
|
}
|
|
51
30
|
async exec(client) {
|
|
52
|
-
const { result, error } = await client.
|
|
31
|
+
const { result, error } = await client.request({
|
|
53
32
|
body: this.command
|
|
54
33
|
});
|
|
55
34
|
if (error) {
|
|
@@ -972,8 +951,6 @@ var ZUnionStoreCommand = class extends Command {
|
|
|
972
951
|
};
|
|
973
952
|
|
|
974
953
|
export {
|
|
975
|
-
__spreadValues,
|
|
976
|
-
UpstashError,
|
|
977
954
|
AppendCommand,
|
|
978
955
|
BitCountCommand,
|
|
979
956
|
BitOpCommand,
|
package/cloudflare.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { R as Redis$1 } from './redis-dd052782';
|
|
2
|
+
import './zunionstore-dffa797d';
|
|
3
|
+
import './http';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Connection credentials for upstash redis.
|
|
7
|
+
* Get them from https://console.upstash.com/redis/<uuid>
|
|
8
|
+
*/
|
|
9
|
+
declare type RedisConfigCloudflare = {
|
|
10
|
+
/**
|
|
11
|
+
* UPSTASH_REDIS_REST_URL
|
|
12
|
+
*/
|
|
13
|
+
url: string;
|
|
14
|
+
/**
|
|
15
|
+
* UPSTASH_REDIS_REST_TOKEN
|
|
16
|
+
*/
|
|
17
|
+
token: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Serverless redis client for upstash.
|
|
21
|
+
*/
|
|
22
|
+
declare class Redis extends Redis$1 {
|
|
23
|
+
/**
|
|
24
|
+
* Create a new redis client
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const redis = new Redis({
|
|
29
|
+
* url: "<UPSTASH_REDIS_REST_URL>",
|
|
30
|
+
* token: "<UPSTASH_REDIS_REST_TOKEN>",
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
constructor(config: RedisConfigCloudflare);
|
|
35
|
+
static fromEnv(): Redis;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { Redis, RedisConfigCloudflare };
|