@upstash/redis 1.0.0-alpha.1 → 1.0.0-alpha.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/.eslintrc.js +49 -0
- package/.prettierrc.js +7 -0
- package/dist/chunk-7YUZYRJS.mjs +29 -0
- package/dist/chunk-FJSI5EBJ.mjs +38 -0
- package/dist/chunk-U7OXAQMQ.mjs +37 -0
- package/dist/chunk-Y5TC4HX2.mjs +798 -0
- package/dist/{chunk-RYSRH3HC.mjs → chunk-ZIB6XPPC.mjs} +4 -27
- package/dist/cloudflare.d.ts +38 -0
- package/dist/cloudflare.js +1738 -0
- package/dist/cloudflare.mjs +35 -0
- package/dist/commands.d.ts +3 -2
- package/dist/commands.js +1 -1
- package/dist/commands.mjs +2 -1
- package/dist/fastly.d.ts +44 -0
- package/dist/fastly.js +1728 -0
- package/dist/fastly.mjs +25 -0
- package/dist/http.d.ts +29 -0
- package/dist/http.js +84 -0
- package/dist/http.mjs +7 -0
- package/dist/index.d.ts +5 -1003
- package/dist/index.js +62 -72
- package/dist/index.mjs +8 -857
- package/dist/nodejs.d.ts +47 -0
- package/dist/nodejs.js +1742 -0
- package/dist/nodejs.mjs +10 -0
- package/dist/package.json +1 -0
- package/dist/redis-dd052782.d.ts +962 -0
- package/dist/{zunionstore-462de5d3.d.ts → zunionstore-dffa797d.d.ts} +2 -27
- package/jest.config.js +195 -0
- package/package.json +1 -1
- package/pkg/cloudflare.ts +77 -0
- package/pkg/command.ts +40 -0
- package/pkg/commands/append.test.ts +28 -0
- package/pkg/commands/append.ts +10 -0
- package/pkg/commands/bitcount.test.ts +36 -0
- package/pkg/commands/bitcount.ts +19 -0
- package/pkg/commands/bitop.test.ts +44 -0
- package/pkg/commands/bitop.ts +22 -0
- package/pkg/commands/bitpos.test.ts +26 -0
- package/pkg/commands/bitpos.ts +10 -0
- package/pkg/commands/dbsize.test.ts +17 -0
- package/pkg/commands/dbsize.ts +10 -0
- package/pkg/commands/decr.test.ts +22 -0
- package/pkg/commands/decr.ts +10 -0
- package/pkg/commands/decrby.test.ts +23 -0
- package/pkg/commands/decrby.ts +10 -0
- package/pkg/commands/del.test.ts +38 -0
- package/pkg/commands/del.ts +11 -0
- package/pkg/commands/echo.test.ts +11 -0
- package/pkg/commands/echo.ts +10 -0
- package/pkg/commands/exists.test.ts +37 -0
- package/pkg/commands/exists.ts +11 -0
- package/pkg/commands/expire.test.ts +22 -0
- package/pkg/commands/expire.ts +10 -0
- package/pkg/commands/expireat.test.ts +24 -0
- package/pkg/commands/expireat.ts +10 -0
- package/pkg/commands/flushall.test.ts +17 -0
- package/pkg/commands/flushall.ts +13 -0
- package/pkg/commands/flushdb.test.ts +17 -0
- package/pkg/commands/flushdb.ts +13 -0
- package/pkg/commands/get.test.ts +34 -0
- package/pkg/commands/get.ts +10 -0
- package/pkg/commands/getbit.test.ts +16 -0
- package/pkg/commands/getbit.ts +10 -0
- package/pkg/commands/getrange.test.ts +25 -0
- package/pkg/commands/getrange.ts +10 -0
- package/pkg/commands/getset.test.ts +33 -0
- package/pkg/commands/getset.ts +10 -0
- package/pkg/commands/hdel.test.ts +30 -0
- package/pkg/commands/hdel.ts +10 -0
- package/pkg/commands/hexists.test.ts +31 -0
- package/pkg/commands/hexists.ts +10 -0
- package/pkg/commands/hget.test.ts +47 -0
- package/pkg/commands/hget.ts +10 -0
- package/pkg/commands/hgetall.test.ts +32 -0
- package/pkg/commands/hgetall.ts +35 -0
- package/pkg/commands/hincrby.test.ts +27 -0
- package/pkg/commands/hincrby.ts +10 -0
- package/pkg/commands/hincrbyfloat.test.ts +25 -0
- package/pkg/commands/hincrbyfloat.ts +10 -0
- package/pkg/commands/hkeys.test.ts +22 -0
- package/pkg/commands/hkeys.ts +10 -0
- package/pkg/commands/hlen.test.ts +24 -0
- package/pkg/commands/hlen.ts +10 -0
- package/pkg/commands/hmget.test.ts +48 -0
- package/pkg/commands/hmget.ts +41 -0
- package/pkg/commands/hmset.test.ts +24 -0
- package/pkg/commands/hmset.ts +10 -0
- package/pkg/commands/hscan.test.ts +46 -0
- package/pkg/commands/hscan.ts +22 -0
- package/pkg/commands/hset.test.ts +21 -0
- package/pkg/commands/hset.ts +10 -0
- package/pkg/commands/hsetnx.test.ts +37 -0
- package/pkg/commands/hsetnx.ts +10 -0
- package/pkg/commands/hstrlen.test.ts +24 -0
- package/pkg/commands/hstrlen.ts +10 -0
- package/pkg/commands/hvals.test.ts +23 -0
- package/pkg/commands/hvals.ts +10 -0
- package/pkg/commands/incr.test.ts +23 -0
- package/pkg/commands/incr.ts +10 -0
- package/pkg/commands/incrby.test.ts +23 -0
- package/pkg/commands/incrby.ts +10 -0
- package/pkg/commands/incrbyfloat.test.ts +24 -0
- package/pkg/commands/incrbyfloat.ts +10 -0
- package/pkg/commands/index.ts +107 -0
- package/pkg/commands/keys.test.ts +17 -0
- package/pkg/commands/keys.ts +10 -0
- package/pkg/commands/lindex.test.ts +33 -0
- package/pkg/commands/lindex.ts +7 -0
- package/pkg/commands/linsert.test.ts +19 -0
- package/pkg/commands/linsert.ts +6 -0
- package/pkg/commands/llen.test.ts +26 -0
- package/pkg/commands/llen.ts +10 -0
- package/pkg/commands/lpop.test.ts +27 -0
- package/pkg/commands/lpop.ts +10 -0
- package/pkg/commands/lpush.test.ts +17 -0
- package/pkg/commands/lpush.ts +11 -0
- package/pkg/commands/lpushx.test.ts +29 -0
- package/pkg/commands/lpushx.ts +11 -0
- package/pkg/commands/lrange.test.ts +22 -0
- package/pkg/commands/lrange.ts +7 -0
- package/pkg/commands/lrem.test.ts +19 -0
- package/pkg/commands/lrem.ts +6 -0
- package/pkg/commands/lset.test.ts +40 -0
- package/pkg/commands/lset.ts +7 -0
- package/pkg/commands/ltrim.test.ts +29 -0
- package/pkg/commands/ltrim.ts +7 -0
- package/pkg/commands/mget.test.ts +44 -0
- package/pkg/commands/mget.ts +9 -0
- package/pkg/commands/mset.test.ts +24 -0
- package/pkg/commands/mset.ts +10 -0
- package/pkg/commands/msetnx.test.ts +46 -0
- package/pkg/commands/msetnx.ts +10 -0
- package/pkg/commands/persist.test.ts +22 -0
- package/pkg/commands/persist.ts +10 -0
- package/pkg/commands/pexpire.test.ts +24 -0
- package/pkg/commands/pexpire.ts +10 -0
- package/pkg/commands/pexpireat.test.ts +24 -0
- package/pkg/commands/pexpireat.ts +10 -0
- package/pkg/commands/ping.test.ts +19 -0
- package/pkg/commands/ping.ts +13 -0
- package/pkg/commands/psetex.test.ts +23 -0
- package/pkg/commands/psetex.ts +10 -0
- package/pkg/commands/pttl.test.ts +17 -0
- package/pkg/commands/pttl.ts +10 -0
- package/pkg/commands/randomkey.test.ts +17 -0
- package/pkg/commands/randomkey.ts +10 -0
- package/pkg/commands/rename.test.ts +18 -0
- package/pkg/commands/rename.ts +10 -0
- package/pkg/commands/renamenx.test.ts +32 -0
- package/pkg/commands/renamenx.ts +10 -0
- package/pkg/commands/rpop.test.ts +27 -0
- package/pkg/commands/rpop.ts +10 -0
- package/pkg/commands/rpush.test.ts +17 -0
- package/pkg/commands/rpush.ts +11 -0
- package/pkg/commands/rpushx.test.ts +29 -0
- package/pkg/commands/rpushx.ts +11 -0
- package/pkg/commands/sadd.test.ts +16 -0
- package/pkg/commands/sadd.ts +11 -0
- package/pkg/commands/scan.test.ts +50 -0
- package/pkg/commands/scan.ts +21 -0
- package/pkg/commands/scard.test.ts +15 -0
- package/pkg/commands/scard.ts +9 -0
- package/pkg/commands/sdiff.test.ts +20 -0
- package/pkg/commands/sdiff.ts +9 -0
- package/pkg/commands/sdiffstore.test.ts +21 -0
- package/pkg/commands/sdiffstore.ts +10 -0
- package/pkg/commands/set.test.ts +112 -0
- package/pkg/commands/set.ts +53 -0
- package/pkg/commands/setbit.test.ts +16 -0
- package/pkg/commands/setbit.ts +10 -0
- package/pkg/commands/setex.test.ts +22 -0
- package/pkg/commands/setex.ts +10 -0
- package/pkg/commands/setnx.test.ts +27 -0
- package/pkg/commands/setnx.ts +10 -0
- package/pkg/commands/setrange.test.ts +25 -0
- package/pkg/commands/setrange.ts +10 -0
- package/pkg/commands/sinter.test.ts +36 -0
- package/pkg/commands/sinter.ts +9 -0
- package/pkg/commands/sinterstore.test.ts +21 -0
- package/pkg/commands/sinterstore.ts +9 -0
- package/pkg/commands/sismember.test.ts +30 -0
- package/pkg/commands/sismember.ts +9 -0
- package/pkg/commands/smembers.test.ts +22 -0
- package/pkg/commands/smembers.ts +10 -0
- package/pkg/commands/smove.test.ts +18 -0
- package/pkg/commands/smove.ts +9 -0
- package/pkg/commands/spop.test.ts +35 -0
- package/pkg/commands/spop.ts +13 -0
- package/pkg/commands/srandmember.test.ts +32 -0
- package/pkg/commands/srandmember.ts +13 -0
- package/pkg/commands/srem.test.ts +18 -0
- package/pkg/commands/srem.ts +10 -0
- package/pkg/commands/sscan.test.ts +50 -0
- package/pkg/commands/sscan.ts +22 -0
- package/pkg/commands/strlen.test.ts +16 -0
- package/pkg/commands/strlen.ts +10 -0
- package/pkg/commands/sunion.test.ts +22 -0
- package/pkg/commands/sunion.ts +10 -0
- package/pkg/commands/sunionstore.test.ts +29 -0
- package/pkg/commands/sunionstore.ts +10 -0
- package/pkg/commands/time.test.ts +11 -0
- package/pkg/commands/time.ts +9 -0
- package/pkg/commands/touch.test.ts +20 -0
- package/pkg/commands/touch.ts +10 -0
- package/pkg/commands/ttl.test.ts +17 -0
- package/pkg/commands/ttl.ts +10 -0
- package/pkg/commands/type.test.ts +72 -0
- package/pkg/commands/type.ts +11 -0
- package/pkg/commands/unlink.test.ts +21 -0
- package/pkg/commands/unlink.ts +10 -0
- package/pkg/commands/zadd.test.ts +177 -0
- package/pkg/commands/zadd.ts +64 -0
- package/pkg/commands/zcard.test.ts +15 -0
- package/pkg/commands/zcard.ts +10 -0
- package/pkg/commands/zcount.test.ts +15 -0
- package/pkg/commands/zcount.ts +9 -0
- package/pkg/commands/zincrby.test.ts +20 -0
- package/pkg/commands/zincrby.ts +9 -0
- package/pkg/commands/zinterstore.test.ts +239 -0
- package/pkg/commands/zinterstore.ts +55 -0
- package/pkg/commands/zlexcount.test.ts +22 -0
- package/pkg/commands/zlexcount.ts +9 -0
- package/pkg/commands/zpopmax.test.ts +45 -0
- package/pkg/commands/zpopmax.ts +13 -0
- package/pkg/commands/zpopmin.test.ts +49 -0
- package/pkg/commands/zpopmin.ts +13 -0
- package/pkg/commands/zrange.test.ts +52 -0
- package/pkg/commands/zrange.ts +22 -0
- package/pkg/commands/zrank.test.ts +22 -0
- package/pkg/commands/zrank.ts +10 -0
- package/pkg/commands/zrem.test.ts +20 -0
- package/pkg/commands/zrem.ts +10 -0
- package/pkg/commands/zremrangebylex.test.ts +26 -0
- package/pkg/commands/zremrangebylex.ts +9 -0
- package/pkg/commands/zremrangebyrank.test.ts +27 -0
- package/pkg/commands/zremrangebyrank.ts +9 -0
- package/pkg/commands/zremrangebyscore.test.ts +24 -0
- package/pkg/commands/zremrangebyscore.ts +9 -0
- package/pkg/commands/zrevrank.test.ts +22 -0
- package/pkg/commands/zrevrank.ts +10 -0
- package/pkg/commands/zscan.test.ts +50 -0
- package/pkg/commands/zscan.ts +22 -0
- package/pkg/commands/zscore.test.ts +18 -0
- package/pkg/commands/zscore.ts +10 -0
- package/pkg/commands/zunionstore.test.ts +215 -0
- package/pkg/commands/zunionstore.ts +55 -0
- package/pkg/commands/zz.ts +1 -0
- package/pkg/error.ts +9 -0
- package/pkg/fastly.ts +54 -0
- package/pkg/http.test.ts +34 -0
- package/pkg/http.ts +62 -0
- package/pkg/index.ts +2 -0
- package/pkg/nodejs.ts +83 -0
- package/pkg/pipeline.test.ts +177 -0
- package/pkg/pipeline.ts +999 -0
- package/pkg/redis.ts +930 -0
- package/pkg/test-utils.ts +41 -0
- package/pkg/types.ts +4 -0
- package/pkg/util.ts +22 -0
- package/pnpm-lock.yaml +3940 -0
- package/tsconfig.json +100 -0
- package/tsconfig.module.json +8 -0
- package/tsup.config.ts +16 -0
package/dist/index.js
CHANGED
|
@@ -38,13 +38,10 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
|
38
38
|
// pkg/index.ts
|
|
39
39
|
var pkg_exports = {};
|
|
40
40
|
__export(pkg_exports, {
|
|
41
|
-
Redis: () =>
|
|
41
|
+
Redis: () => Redis2,
|
|
42
42
|
UpstashError: () => UpstashError
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
// pkg/http.ts
|
|
46
|
-
var import_isomorphic_fetch = require("isomorphic-fetch");
|
|
47
|
-
|
|
48
45
|
// pkg/error.ts
|
|
49
46
|
var UpstashError = class extends Error {
|
|
50
47
|
constructor(message) {
|
|
@@ -53,39 +50,6 @@ var UpstashError = class extends Error {
|
|
|
53
50
|
}
|
|
54
51
|
};
|
|
55
52
|
|
|
56
|
-
// pkg/http.ts
|
|
57
|
-
var HttpClient = class {
|
|
58
|
-
constructor(config) {
|
|
59
|
-
var _a;
|
|
60
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
61
|
-
this.headers = (_a = config.headers) != null ? _a : {};
|
|
62
|
-
this.options = config.options;
|
|
63
|
-
}
|
|
64
|
-
async request(method, req) {
|
|
65
|
-
var _a;
|
|
66
|
-
if (!req.path) {
|
|
67
|
-
req.path = [];
|
|
68
|
-
}
|
|
69
|
-
const headers = __spreadValues(__spreadValues({
|
|
70
|
-
"Content-Type": "application/json"
|
|
71
|
-
}, this.headers), req.headers);
|
|
72
|
-
const res = await fetch([this.baseUrl, ...req.path].join("/"), {
|
|
73
|
-
method,
|
|
74
|
-
headers,
|
|
75
|
-
body: JSON.stringify(req.body),
|
|
76
|
-
backend: (_a = this.options) == null ? void 0 : _a.backend
|
|
77
|
-
});
|
|
78
|
-
const body = await res.json();
|
|
79
|
-
if (!res.ok) {
|
|
80
|
-
throw new UpstashError(body.error);
|
|
81
|
-
}
|
|
82
|
-
return body;
|
|
83
|
-
}
|
|
84
|
-
async post(req) {
|
|
85
|
-
return await this.request("POST", req);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
53
|
// pkg/util.ts
|
|
90
54
|
function parseRecursive(obj) {
|
|
91
55
|
return Array.isArray(obj) ? obj.map((o) => {
|
|
@@ -112,7 +76,7 @@ var Command = class {
|
|
|
112
76
|
this.deserialize = (_a = opts == null ? void 0 : opts.deserialize) != null ? _a : parseResponse;
|
|
113
77
|
}
|
|
114
78
|
async exec(client) {
|
|
115
|
-
const { result, error } = await client.
|
|
79
|
+
const { result, error } = await client.request({
|
|
116
80
|
body: this.command
|
|
117
81
|
});
|
|
118
82
|
if (error) {
|
|
@@ -1044,7 +1008,7 @@ var Pipeline = class {
|
|
|
1044
1008
|
if (this.commands.length === 0) {
|
|
1045
1009
|
throw new Error("Pipeline is empty");
|
|
1046
1010
|
}
|
|
1047
|
-
const res = await this.client.
|
|
1011
|
+
const res = await this.client.request({
|
|
1048
1012
|
path: ["pipeline"],
|
|
1049
1013
|
body: Object.values(this.commands).map((c) => c.command)
|
|
1050
1014
|
});
|
|
@@ -1384,39 +1348,8 @@ var Pipeline = class {
|
|
|
1384
1348
|
|
|
1385
1349
|
// pkg/redis.ts
|
|
1386
1350
|
var Redis = class {
|
|
1387
|
-
constructor(
|
|
1388
|
-
this.client =
|
|
1389
|
-
baseUrl: config.url,
|
|
1390
|
-
headers: {
|
|
1391
|
-
authorization: `Bearer ${config.token}`
|
|
1392
|
-
},
|
|
1393
|
-
options: config.requestOptions
|
|
1394
|
-
});
|
|
1395
|
-
}
|
|
1396
|
-
static fromEnv() {
|
|
1397
|
-
if (typeof (process == null ? void 0 : process.env) === "undefined") {
|
|
1398
|
-
throw new Error("Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please use `fromCloudflareEnv()` instead");
|
|
1399
|
-
}
|
|
1400
|
-
const url = process.env["UPSTASH_REDIS_REST_URL"];
|
|
1401
|
-
if (!url) {
|
|
1402
|
-
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
|
|
1403
|
-
}
|
|
1404
|
-
const token = process.env["UPSTASH_REDIS_REST_TOKEN"];
|
|
1405
|
-
if (!token) {
|
|
1406
|
-
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
|
|
1407
|
-
}
|
|
1408
|
-
return new Redis({ url, token });
|
|
1409
|
-
}
|
|
1410
|
-
static fromCloudflareEnv() {
|
|
1411
|
-
const url = UPSTASH_REDIS_REST_URL;
|
|
1412
|
-
const token = UPSTASH_REDIS_REST_TOKEN;
|
|
1413
|
-
if (!url) {
|
|
1414
|
-
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
|
|
1415
|
-
}
|
|
1416
|
-
if (!token) {
|
|
1417
|
-
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
|
|
1418
|
-
}
|
|
1419
|
-
return new Redis({ url, token });
|
|
1351
|
+
constructor(client) {
|
|
1352
|
+
this.client = client;
|
|
1420
1353
|
}
|
|
1421
1354
|
pipeline() {
|
|
1422
1355
|
return new Pipeline(this.client);
|
|
@@ -1746,6 +1679,63 @@ var Redis = class {
|
|
|
1746
1679
|
return new ZUnionStoreCommand(...args).exec(this.client);
|
|
1747
1680
|
}
|
|
1748
1681
|
};
|
|
1682
|
+
|
|
1683
|
+
// pkg/http.ts
|
|
1684
|
+
var import_isomorphic_fetch = require("isomorphic-fetch");
|
|
1685
|
+
var HttpClient = class {
|
|
1686
|
+
constructor(config) {
|
|
1687
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
1688
|
+
this.headers = __spreadValues({
|
|
1689
|
+
"Content-Type": "application/json"
|
|
1690
|
+
}, config.headers);
|
|
1691
|
+
this.options = config.options;
|
|
1692
|
+
}
|
|
1693
|
+
async request(req) {
|
|
1694
|
+
var _a;
|
|
1695
|
+
if (!req.path) {
|
|
1696
|
+
req.path = [];
|
|
1697
|
+
}
|
|
1698
|
+
const res = await fetch([this.baseUrl, ...req.path].join("/"), {
|
|
1699
|
+
method: "POST",
|
|
1700
|
+
headers: this.headers,
|
|
1701
|
+
body: JSON.stringify(req.body),
|
|
1702
|
+
backend: (_a = this.options) == null ? void 0 : _a.backend
|
|
1703
|
+
});
|
|
1704
|
+
const body = await res.json();
|
|
1705
|
+
if (!res.ok) {
|
|
1706
|
+
throw new UpstashError(body.error);
|
|
1707
|
+
}
|
|
1708
|
+
return body;
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
|
|
1712
|
+
// pkg/nodejs.ts
|
|
1713
|
+
var import_isomorphic_fetch2 = require("isomorphic-fetch");
|
|
1714
|
+
var Redis2 = class extends Redis {
|
|
1715
|
+
constructor(config) {
|
|
1716
|
+
const client = new HttpClient({
|
|
1717
|
+
baseUrl: config.url,
|
|
1718
|
+
headers: {
|
|
1719
|
+
authorization: `Bearer ${config.token}`
|
|
1720
|
+
}
|
|
1721
|
+
});
|
|
1722
|
+
super(client);
|
|
1723
|
+
}
|
|
1724
|
+
static fromEnv() {
|
|
1725
|
+
if (typeof (process == null ? void 0 : process.env) === "undefined") {
|
|
1726
|
+
throw new Error("Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please use `Redis.onCloudflare()` instead");
|
|
1727
|
+
}
|
|
1728
|
+
const url = process.env["UPSTASH_REDIS_REST_URL"];
|
|
1729
|
+
if (!url) {
|
|
1730
|
+
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_URL`");
|
|
1731
|
+
}
|
|
1732
|
+
const token = process.env["UPSTASH_REDIS_REST_TOKEN"];
|
|
1733
|
+
if (!token) {
|
|
1734
|
+
throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`");
|
|
1735
|
+
}
|
|
1736
|
+
return new Redis2({ url, token });
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1749
1739
|
module.exports = __toCommonJS(pkg_exports);
|
|
1750
1740
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1751
1741
|
0 && (module.exports = {
|