@upstash/redis 0.0.0-ci.c4f9e888-20220808 → 0.0.0-ci.c6073771-20221014
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/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +1 -0
- package/esm/deps/{denopkg.com/chiefbiiko/sha1@master → deno.land/x/sha1@v1.0.3}/mod.js +0 -0
- package/esm/deps/denopkg.com/chiefbiiko/{std-encoding@v1.1.1 → std-encoding@v1.0.0}/mod.js +4 -8
- package/esm/pkg/commands/scan.js +3 -0
- package/esm/pkg/commands/zmscore.js +10 -0
- package/esm/pkg/http.js +53 -2
- package/esm/pkg/pipeline.js +23 -5
- package/esm/pkg/redis.js +34 -1
- package/esm/pkg/script.js +1 -1
- package/package.json +1 -39
- package/script/deps/{denopkg.com/chiefbiiko/sha1@master → deno.land/x/sha1@v1.0.3}/deps.js +1 -1
- package/script/deps/{denopkg.com/chiefbiiko/sha1@master → deno.land/x/sha1@v1.0.3}/mod.js +0 -0
- package/script/deps/denopkg.com/chiefbiiko/{std-encoding@v1.1.1 → std-encoding@v1.0.0}/mod.js +4 -31
- package/script/pkg/commands/scan.js +3 -0
- package/script/pkg/commands/zmscore.js +14 -0
- package/script/pkg/http.js +53 -2
- package/script/pkg/pipeline.js +23 -5
- package/script/pkg/redis.js +34 -1
- package/script/pkg/script.js +1 -1
- package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
- package/types/deps/{denopkg.com/chiefbiiko/sha1@master → deno.land/x/sha1@v1.0.3}/mod.d.ts +0 -0
- package/types/deps/denopkg.com/chiefbiiko/{std-encoding@v1.1.1 → std-encoding@v1.0.0}/mod.d.ts +0 -0
- package/types/pkg/commands/scan.d.ts +1 -0
- package/types/pkg/commands/zmscore.d.ts +7 -0
- package/types/pkg/pipeline.d.ts +12 -3
- package/types/pkg/redis.d.ts +15 -1
- package/esm/deps/deno.land/x/base64@v0.2.1/mod.js +0 -13
- package/esm/deps/denopkg.com/chiefbiiko/sha1@master/deps.js +0 -1
- package/script/deps/deno.land/x/base64@v0.2.1/mod.js +0 -17
- package/types/deps/deno.land/x/base64@v0.2.1/mod.d.ts +0 -1
- package/types/deps/denopkg.com/chiefbiiko/sha1@master/deps.d.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { encode, decode } from "../../../denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js";
|
|
File without changes
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as base64url from "../../../deno.land/x/base64@v0.2.1/base64url.js";
|
|
1
|
+
import { toUint8Array, fromUint8Array } from "../../../deno.land/x/base64@v0.2.1/base64url.js";
|
|
3
2
|
const decoder = new TextDecoder();
|
|
4
3
|
const encoder = new TextEncoder();
|
|
5
4
|
/** Serializes a Uint8Array to a hexadecimal string. */
|
|
@@ -26,10 +25,7 @@ export function decode(buf, encoding = "utf8") {
|
|
|
26
25
|
return decoder.decode(buf);
|
|
27
26
|
}
|
|
28
27
|
else if (/^base64$/i.test(encoding)) {
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
else if (/^base64url$/i.test(encoding)) {
|
|
32
|
-
return base64url.fromUint8Array(buf);
|
|
28
|
+
return fromUint8Array(buf);
|
|
33
29
|
}
|
|
34
30
|
else if (/^hex(?:adecimal)?$/i.test(encoding)) {
|
|
35
31
|
return toHexString(buf);
|
|
@@ -42,8 +38,8 @@ export function encode(str, encoding = "utf8") {
|
|
|
42
38
|
if (/^utf-?8$/i.test(encoding)) {
|
|
43
39
|
return encoder.encode(str);
|
|
44
40
|
}
|
|
45
|
-
else if (/^base64
|
|
46
|
-
return
|
|
41
|
+
else if (/^base64$/i.test(encoding)) {
|
|
42
|
+
return toUint8Array(str);
|
|
47
43
|
}
|
|
48
44
|
else if (/^hex(?:adecimal)?$/i.test(encoding)) {
|
|
49
45
|
return fromHexString(str);
|
package/esm/pkg/commands/scan.js
CHANGED
package/esm/pkg/http.js
CHANGED
|
@@ -26,7 +26,11 @@ export class HttpClient {
|
|
|
26
26
|
value: void 0
|
|
27
27
|
});
|
|
28
28
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
29
|
-
this.headers = {
|
|
29
|
+
this.headers = {
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
"Upstash-Encoding": "base64",
|
|
32
|
+
...config.headers,
|
|
33
|
+
};
|
|
30
34
|
this.options = { backend: config.options?.backend };
|
|
31
35
|
if (typeof config?.retry === "boolean" && config?.retry === false) {
|
|
32
36
|
this.retry = {
|
|
@@ -72,6 +76,53 @@ export class HttpClient {
|
|
|
72
76
|
if (!res.ok) {
|
|
73
77
|
throw new UpstashError(body.error);
|
|
74
78
|
}
|
|
75
|
-
return body;
|
|
79
|
+
return Array.isArray(body) ? body.map(decode) : decode(body);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function base64decode(b64) {
|
|
83
|
+
let dec = "";
|
|
84
|
+
try {
|
|
85
|
+
dec = atob(b64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("");
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
|
|
89
|
+
return dec;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return decodeURIComponent(dec);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
console.warn(`Unable to decode URI [${dec}]: ${e.message}`);
|
|
96
|
+
return dec;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function decode(raw) {
|
|
100
|
+
let result = undefined;
|
|
101
|
+
switch (typeof raw.result) {
|
|
102
|
+
case "undefined":
|
|
103
|
+
return raw;
|
|
104
|
+
case "number":
|
|
105
|
+
result = raw.result;
|
|
106
|
+
break;
|
|
107
|
+
case "object":
|
|
108
|
+
if (Array.isArray(raw.result)) {
|
|
109
|
+
result = raw.result.map((v) => typeof v === "string"
|
|
110
|
+
? base64decode(v)
|
|
111
|
+
: Array.isArray(v)
|
|
112
|
+
? v.map(base64decode)
|
|
113
|
+
: v);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// If it's not an array it must be null
|
|
117
|
+
// Apparently null is an object in javascript
|
|
118
|
+
result = null;
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
case "string":
|
|
122
|
+
result = raw.result === "OK" ? "OK" : base64decode(raw.result);
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
break;
|
|
76
126
|
}
|
|
127
|
+
return { result, error: raw.error };
|
|
77
128
|
}
|
package/esm/pkg/pipeline.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
2
2
|
import { UpstashError } from "./error.js";
|
|
3
|
+
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
3
4
|
/**
|
|
4
5
|
* Upstash REST API supports command pipelining to send multiple commands in
|
|
5
6
|
* batch, instead of sending each command one by one and waiting for a response.
|
|
@@ -16,7 +17,7 @@ import { UpstashError } from "./error.js";
|
|
|
16
17
|
* **Examples:**
|
|
17
18
|
*
|
|
18
19
|
* ```ts
|
|
19
|
-
* const p = redis.pipeline()
|
|
20
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
20
21
|
* p.set("key","value")
|
|
21
22
|
* p.get("key")
|
|
22
23
|
* const res = await p.exec()
|
|
@@ -39,7 +40,7 @@ import { UpstashError } from "./error.js";
|
|
|
39
40
|
* ```
|
|
40
41
|
*/
|
|
41
42
|
export class Pipeline {
|
|
42
|
-
constructor(
|
|
43
|
+
constructor(opts) {
|
|
43
44
|
Object.defineProperty(this, "client", {
|
|
44
45
|
enumerable: true,
|
|
45
46
|
configurable: true,
|
|
@@ -58,6 +59,12 @@ export class Pipeline {
|
|
|
58
59
|
writable: true,
|
|
59
60
|
value: void 0
|
|
60
61
|
});
|
|
62
|
+
Object.defineProperty(this, "multiExec", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
value: void 0
|
|
67
|
+
});
|
|
61
68
|
/**
|
|
62
69
|
* Send the pipeline request to upstash.
|
|
63
70
|
*
|
|
@@ -76,8 +83,9 @@ export class Pipeline {
|
|
|
76
83
|
if (this.commands.length === 0) {
|
|
77
84
|
throw new Error("Pipeline is empty");
|
|
78
85
|
}
|
|
86
|
+
const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
|
|
79
87
|
const res = (await this.client.request({
|
|
80
|
-
path
|
|
88
|
+
path,
|
|
81
89
|
body: Object.values(this.commands).map((c) => c.command),
|
|
82
90
|
}));
|
|
83
91
|
return res.map(({ error, result }, i) => {
|
|
@@ -1011,6 +1019,15 @@ export class Pipeline {
|
|
|
1011
1019
|
writable: true,
|
|
1012
1020
|
value: (...args) => this.chain(new ZLexCountCommand(args, this.commandOptions))
|
|
1013
1021
|
});
|
|
1022
|
+
/**
|
|
1023
|
+
* @see https://redis.io/commands/zmscore
|
|
1024
|
+
*/
|
|
1025
|
+
Object.defineProperty(this, "zmscore", {
|
|
1026
|
+
enumerable: true,
|
|
1027
|
+
configurable: true,
|
|
1028
|
+
writable: true,
|
|
1029
|
+
value: (...args) => this.chain(new ZMScoreCommand(args, this.commandOptions))
|
|
1030
|
+
});
|
|
1014
1031
|
/**
|
|
1015
1032
|
* @see https://redis.io/commands/zpopmax
|
|
1016
1033
|
*/
|
|
@@ -1119,9 +1136,10 @@ export class Pipeline {
|
|
|
1119
1136
|
writable: true,
|
|
1120
1137
|
value: (...args) => this.chain(new ZUnionStoreCommand(args, this.commandOptions))
|
|
1121
1138
|
});
|
|
1122
|
-
this.client = client;
|
|
1139
|
+
this.client = opts.client;
|
|
1123
1140
|
this.commands = [];
|
|
1124
|
-
this.commandOptions = commandOptions;
|
|
1141
|
+
this.commandOptions = opts.commandOptions;
|
|
1142
|
+
this.multiExec = opts.multiExec ?? false;
|
|
1125
1143
|
}
|
|
1126
1144
|
/**
|
|
1127
1145
|
* Pushes a command into the pipelien and returns a chainable instance of the
|
package/esm/pkg/redis.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AppendCommand, BitCountCommand, BitOpCommand, BitPosCommand, DBSizeCommand, DecrByCommand, DecrCommand, DelCommand, EchoCommand, EvalCommand, EvalshaCommand, ExistsCommand, ExpireAtCommand, ExpireCommand, FlushAllCommand, FlushDBCommand, GetBitCommand, GetCommand, GetRangeCommand, GetSetCommand, HDelCommand, HExistsCommand, HGetAllCommand, HGetCommand, HIncrByCommand, HIncrByFloatCommand, HKeysCommand, HLenCommand, HMGetCommand, HMSetCommand, HScanCommand, HSetCommand, HSetNXCommand, HStrLenCommand, HValsCommand, IncrByCommand, IncrByFloatCommand, IncrCommand, KeysCommand, LIndexCommand, LInsertCommand, LLenCommand, LPopCommand, LPosCommand, LPushCommand, LPushXCommand, LRangeCommand, LRemCommand, LSetCommand, LTrimCommand, MGetCommand, MSetCommand, MSetNXCommand, PersistCommand, PExpireAtCommand, PExpireCommand, PingCommand, PSetEXCommand, PTtlCommand, PublishCommand, RandomKeyCommand, RenameCommand, RenameNXCommand, RPopCommand, RPushCommand, RPushXCommand, SAddCommand, ScanCommand, SCardCommand, ScriptExistsCommand, ScriptFlushCommand, ScriptLoadCommand, SDiffCommand, SDiffStoreCommand, SetBitCommand, SetCommand, SetExCommand, SetNxCommand, SetRangeCommand, SInterCommand, SInterStoreCommand, SIsMemberCommand, SMembersCommand, SMoveCommand, SPopCommand, SRandMemberCommand, SRemCommand, SScanCommand, StrLenCommand, SUnionCommand, SUnionStoreCommand, TimeCommand, TouchCommand, TtlCommand, TypeCommand, UnlinkCommand, ZAddCommand, ZCardCommand, ZCountCommand, ZIncrByCommand, ZInterStoreCommand, ZLexCountCommand, ZPopMaxCommand, ZPopMinCommand, ZRangeCommand, ZRankCommand, ZRemCommand, ZRemRangeByLexCommand, ZRemRangeByRankCommand, ZRemRangeByScoreCommand, ZRevRankCommand, ZScanCommand, ZScoreCommand, ZUnionStoreCommand, } from "./commands/mod.js";
|
|
2
2
|
import { Pipeline } from "./pipeline.js";
|
|
3
3
|
import { Script } from "./script.js";
|
|
4
|
+
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
4
5
|
/**
|
|
5
6
|
* Serverless redis client for upstash.
|
|
6
7
|
*/
|
|
@@ -50,7 +51,30 @@ export class Redis {
|
|
|
50
51
|
enumerable: true,
|
|
51
52
|
configurable: true,
|
|
52
53
|
writable: true,
|
|
53
|
-
value: () => new Pipeline(
|
|
54
|
+
value: () => new Pipeline({
|
|
55
|
+
client: this.client,
|
|
56
|
+
commandOptions: this.opts,
|
|
57
|
+
multiExec: false,
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
62
|
+
*
|
|
63
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
64
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
65
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link Pipeline}
|
|
68
|
+
*/
|
|
69
|
+
Object.defineProperty(this, "multi", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: () => new Pipeline({
|
|
74
|
+
client: this.client,
|
|
75
|
+
commandOptions: this.opts,
|
|
76
|
+
multiExec: true,
|
|
77
|
+
})
|
|
54
78
|
});
|
|
55
79
|
/**
|
|
56
80
|
* @see https://redis.io/commands/append
|
|
@@ -975,6 +999,15 @@ export class Redis {
|
|
|
975
999
|
writable: true,
|
|
976
1000
|
value: (...args) => new ZLexCountCommand(args, this.opts).exec(this.client)
|
|
977
1001
|
});
|
|
1002
|
+
/**
|
|
1003
|
+
* @see https://redis.io/commands/zmscore
|
|
1004
|
+
*/
|
|
1005
|
+
Object.defineProperty(this, "zmscore", {
|
|
1006
|
+
enumerable: true,
|
|
1007
|
+
configurable: true,
|
|
1008
|
+
writable: true,
|
|
1009
|
+
value: (...args) => new ZMScoreCommand(args, this.opts).exec(this.client)
|
|
1010
|
+
});
|
|
978
1011
|
/**
|
|
979
1012
|
* @see https://redis.io/commands/zpopmax
|
|
980
1013
|
*/
|
package/esm/pkg/script.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"main": "./script/platforms/nodejs.js",
|
|
4
4
|
"types": "./types/platforms/nodejs.d.ts",
|
|
5
5
|
"name": "@upstash/redis",
|
|
6
|
-
"version": "v0.0.0-ci.
|
|
6
|
+
"version": "v0.0.0-ci.c6073771-20221014",
|
|
7
7
|
"description": "An HTTP/REST based Redis client built on top of Upstash REST API.",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -22,10 +22,6 @@
|
|
|
22
22
|
"url": "https://github.com/upstash/upstash-redis/issues"
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/upstash/upstash-redis#readme",
|
|
25
|
-
"devDependencies": {
|
|
26
|
-
"@size-limit/preset-small-lib": "latest",
|
|
27
|
-
"size-limit": "latest"
|
|
28
|
-
},
|
|
29
25
|
"dependencies": {
|
|
30
26
|
"isomorphic-fetch": "^3.0.0"
|
|
31
27
|
},
|
|
@@ -37,40 +33,6 @@
|
|
|
37
33
|
"with-fetch": "./types/platforms/node_with_fetch.d.ts"
|
|
38
34
|
}
|
|
39
35
|
},
|
|
40
|
-
"size-limit": [
|
|
41
|
-
{
|
|
42
|
-
"path": "esm/platforms/nodejs.js",
|
|
43
|
-
"limit": "6 KB"
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"path": "esm/platforms/fastly.js",
|
|
47
|
-
"limit": "6 KB"
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"path": "esm/platforms/cloudflare.js",
|
|
51
|
-
"limit": "6 KB"
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"path": "esm/platforms/node_with_fetch.js",
|
|
55
|
-
"limit": "15 KB"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
"path": "script/platforms/nodejs.js",
|
|
59
|
-
"limit": "10 KB"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"path": "script/platforms/fastly.js",
|
|
63
|
-
"limit": "10 KB"
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"path": "script/platforms/cloudflare.js",
|
|
67
|
-
"limit": "10 KB"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"path": "script/platforms/node_with_fetch.js",
|
|
71
|
-
"limit": "15 KB"
|
|
72
|
-
}
|
|
73
|
-
],
|
|
74
36
|
"exports": {
|
|
75
37
|
".": {
|
|
76
38
|
"import": "./esm/platforms/nodejs.js",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decode = exports.encode = void 0;
|
|
4
|
-
var mod_js_1 = require("
|
|
4
|
+
var mod_js_1 = require("../../../denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js");
|
|
5
5
|
Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return mod_js_1.encode; } });
|
|
6
6
|
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return mod_js_1.decode; } });
|
|
File without changes
|
package/script/deps/denopkg.com/chiefbiiko/{std-encoding@v1.1.1 → std-encoding@v1.0.0}/mod.js
RENAMED
|
@@ -1,31 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.encode = exports.decode = void 0;
|
|
27
|
-
const
|
|
28
|
-
const base64url = __importStar(require("../../../deno.land/x/base64@v0.2.1/base64url.js"));
|
|
4
|
+
const base64url_js_1 = require("../../../deno.land/x/base64@v0.2.1/base64url.js");
|
|
29
5
|
const decoder = new TextDecoder();
|
|
30
6
|
const encoder = new TextEncoder();
|
|
31
7
|
/** Serializes a Uint8Array to a hexadecimal string. */
|
|
@@ -52,10 +28,7 @@ function decode(buf, encoding = "utf8") {
|
|
|
52
28
|
return decoder.decode(buf);
|
|
53
29
|
}
|
|
54
30
|
else if (/^base64$/i.test(encoding)) {
|
|
55
|
-
return
|
|
56
|
-
}
|
|
57
|
-
else if (/^base64url$/i.test(encoding)) {
|
|
58
|
-
return base64url.fromUint8Array(buf);
|
|
31
|
+
return (0, base64url_js_1.fromUint8Array)(buf);
|
|
59
32
|
}
|
|
60
33
|
else if (/^hex(?:adecimal)?$/i.test(encoding)) {
|
|
61
34
|
return toHexString(buf);
|
|
@@ -69,8 +42,8 @@ function encode(str, encoding = "utf8") {
|
|
|
69
42
|
if (/^utf-?8$/i.test(encoding)) {
|
|
70
43
|
return encoder.encode(str);
|
|
71
44
|
}
|
|
72
|
-
else if (/^base64
|
|
73
|
-
return
|
|
45
|
+
else if (/^base64$/i.test(encoding)) {
|
|
46
|
+
return (0, base64url_js_1.toUint8Array)(str);
|
|
74
47
|
}
|
|
75
48
|
else if (/^hex(?:adecimal)?$/i.test(encoding)) {
|
|
76
49
|
return fromHexString(str);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZMScoreCommand = void 0;
|
|
4
|
+
const command_js_1 = require("./command.js");
|
|
5
|
+
/**
|
|
6
|
+
* @see https://redis.io/commands/zmscore
|
|
7
|
+
*/
|
|
8
|
+
class ZMScoreCommand extends command_js_1.Command {
|
|
9
|
+
constructor(cmd, opts) {
|
|
10
|
+
const [key, members] = cmd;
|
|
11
|
+
super(["zmscore", key, ...members], opts);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ZMScoreCommand = ZMScoreCommand;
|
package/script/pkg/http.js
CHANGED
|
@@ -29,7 +29,11 @@ class HttpClient {
|
|
|
29
29
|
value: void 0
|
|
30
30
|
});
|
|
31
31
|
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
32
|
-
this.headers = {
|
|
32
|
+
this.headers = {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
"Upstash-Encoding": "base64",
|
|
35
|
+
...config.headers,
|
|
36
|
+
};
|
|
33
37
|
this.options = { backend: config.options?.backend };
|
|
34
38
|
if (typeof config?.retry === "boolean" && config?.retry === false) {
|
|
35
39
|
this.retry = {
|
|
@@ -75,7 +79,54 @@ class HttpClient {
|
|
|
75
79
|
if (!res.ok) {
|
|
76
80
|
throw new error_js_1.UpstashError(body.error);
|
|
77
81
|
}
|
|
78
|
-
return body;
|
|
82
|
+
return Array.isArray(body) ? body.map(decode) : decode(body);
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
exports.HttpClient = HttpClient;
|
|
86
|
+
function base64decode(b64) {
|
|
87
|
+
let dec = "";
|
|
88
|
+
try {
|
|
89
|
+
dec = atob(b64).split("").map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)).join("");
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
console.warn(`Unable to decode base64 [${dec}]: ${e.message}`);
|
|
93
|
+
return dec;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return decodeURIComponent(dec);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
console.warn(`Unable to decode URI [${dec}]: ${e.message}`);
|
|
100
|
+
return dec;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function decode(raw) {
|
|
104
|
+
let result = undefined;
|
|
105
|
+
switch (typeof raw.result) {
|
|
106
|
+
case "undefined":
|
|
107
|
+
return raw;
|
|
108
|
+
case "number":
|
|
109
|
+
result = raw.result;
|
|
110
|
+
break;
|
|
111
|
+
case "object":
|
|
112
|
+
if (Array.isArray(raw.result)) {
|
|
113
|
+
result = raw.result.map((v) => typeof v === "string"
|
|
114
|
+
? base64decode(v)
|
|
115
|
+
: Array.isArray(v)
|
|
116
|
+
? v.map(base64decode)
|
|
117
|
+
: v);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// If it's not an array it must be null
|
|
121
|
+
// Apparently null is an object in javascript
|
|
122
|
+
result = null;
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case "string":
|
|
126
|
+
result = raw.result === "OK" ? "OK" : base64decode(raw.result);
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
return { result, error: raw.error };
|
|
132
|
+
}
|
package/script/pkg/pipeline.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Pipeline = void 0;
|
|
4
4
|
const mod_js_1 = require("./commands/mod.js");
|
|
5
5
|
const error_js_1 = require("./error.js");
|
|
6
|
+
const zmscore_js_1 = require("./commands/zmscore.js");
|
|
6
7
|
/**
|
|
7
8
|
* Upstash REST API supports command pipelining to send multiple commands in
|
|
8
9
|
* batch, instead of sending each command one by one and waiting for a response.
|
|
@@ -19,7 +20,7 @@ const error_js_1 = require("./error.js");
|
|
|
19
20
|
* **Examples:**
|
|
20
21
|
*
|
|
21
22
|
* ```ts
|
|
22
|
-
* const p = redis.pipeline()
|
|
23
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
23
24
|
* p.set("key","value")
|
|
24
25
|
* p.get("key")
|
|
25
26
|
* const res = await p.exec()
|
|
@@ -42,7 +43,7 @@ const error_js_1 = require("./error.js");
|
|
|
42
43
|
* ```
|
|
43
44
|
*/
|
|
44
45
|
class Pipeline {
|
|
45
|
-
constructor(
|
|
46
|
+
constructor(opts) {
|
|
46
47
|
Object.defineProperty(this, "client", {
|
|
47
48
|
enumerable: true,
|
|
48
49
|
configurable: true,
|
|
@@ -61,6 +62,12 @@ class Pipeline {
|
|
|
61
62
|
writable: true,
|
|
62
63
|
value: void 0
|
|
63
64
|
});
|
|
65
|
+
Object.defineProperty(this, "multiExec", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true,
|
|
69
|
+
value: void 0
|
|
70
|
+
});
|
|
64
71
|
/**
|
|
65
72
|
* Send the pipeline request to upstash.
|
|
66
73
|
*
|
|
@@ -79,8 +86,9 @@ class Pipeline {
|
|
|
79
86
|
if (this.commands.length === 0) {
|
|
80
87
|
throw new Error("Pipeline is empty");
|
|
81
88
|
}
|
|
89
|
+
const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
|
|
82
90
|
const res = (await this.client.request({
|
|
83
|
-
path
|
|
91
|
+
path,
|
|
84
92
|
body: Object.values(this.commands).map((c) => c.command),
|
|
85
93
|
}));
|
|
86
94
|
return res.map(({ error, result }, i) => {
|
|
@@ -1014,6 +1022,15 @@ class Pipeline {
|
|
|
1014
1022
|
writable: true,
|
|
1015
1023
|
value: (...args) => this.chain(new mod_js_1.ZLexCountCommand(args, this.commandOptions))
|
|
1016
1024
|
});
|
|
1025
|
+
/**
|
|
1026
|
+
* @see https://redis.io/commands/zmscore
|
|
1027
|
+
*/
|
|
1028
|
+
Object.defineProperty(this, "zmscore", {
|
|
1029
|
+
enumerable: true,
|
|
1030
|
+
configurable: true,
|
|
1031
|
+
writable: true,
|
|
1032
|
+
value: (...args) => this.chain(new zmscore_js_1.ZMScoreCommand(args, this.commandOptions))
|
|
1033
|
+
});
|
|
1017
1034
|
/**
|
|
1018
1035
|
* @see https://redis.io/commands/zpopmax
|
|
1019
1036
|
*/
|
|
@@ -1122,9 +1139,10 @@ class Pipeline {
|
|
|
1122
1139
|
writable: true,
|
|
1123
1140
|
value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
|
|
1124
1141
|
});
|
|
1125
|
-
this.client = client;
|
|
1142
|
+
this.client = opts.client;
|
|
1126
1143
|
this.commands = [];
|
|
1127
|
-
this.commandOptions = commandOptions;
|
|
1144
|
+
this.commandOptions = opts.commandOptions;
|
|
1145
|
+
this.multiExec = opts.multiExec ?? false;
|
|
1128
1146
|
}
|
|
1129
1147
|
/**
|
|
1130
1148
|
* Pushes a command into the pipelien and returns a chainable instance of the
|
package/script/pkg/redis.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Redis = void 0;
|
|
|
4
4
|
const mod_js_1 = require("./commands/mod.js");
|
|
5
5
|
const pipeline_js_1 = require("./pipeline.js");
|
|
6
6
|
const script_js_1 = require("./script.js");
|
|
7
|
+
const zmscore_js_1 = require("./commands/zmscore.js");
|
|
7
8
|
/**
|
|
8
9
|
* Serverless redis client for upstash.
|
|
9
10
|
*/
|
|
@@ -53,7 +54,30 @@ class Redis {
|
|
|
53
54
|
enumerable: true,
|
|
54
55
|
configurable: true,
|
|
55
56
|
writable: true,
|
|
56
|
-
value: () => new pipeline_js_1.Pipeline(
|
|
57
|
+
value: () => new pipeline_js_1.Pipeline({
|
|
58
|
+
client: this.client,
|
|
59
|
+
commandOptions: this.opts,
|
|
60
|
+
multiExec: false,
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
65
|
+
*
|
|
66
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
67
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
68
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
69
|
+
*
|
|
70
|
+
* @see {@link Pipeline}
|
|
71
|
+
*/
|
|
72
|
+
Object.defineProperty(this, "multi", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: () => new pipeline_js_1.Pipeline({
|
|
77
|
+
client: this.client,
|
|
78
|
+
commandOptions: this.opts,
|
|
79
|
+
multiExec: true,
|
|
80
|
+
})
|
|
57
81
|
});
|
|
58
82
|
/**
|
|
59
83
|
* @see https://redis.io/commands/append
|
|
@@ -978,6 +1002,15 @@ class Redis {
|
|
|
978
1002
|
writable: true,
|
|
979
1003
|
value: (...args) => new mod_js_1.ZLexCountCommand(args, this.opts).exec(this.client)
|
|
980
1004
|
});
|
|
1005
|
+
/**
|
|
1006
|
+
* @see https://redis.io/commands/zmscore
|
|
1007
|
+
*/
|
|
1008
|
+
Object.defineProperty(this, "zmscore", {
|
|
1009
|
+
enumerable: true,
|
|
1010
|
+
configurable: true,
|
|
1011
|
+
writable: true,
|
|
1012
|
+
value: (...args) => new zmscore_js_1.ZMScoreCommand(args, this.opts).exec(this.client)
|
|
1013
|
+
});
|
|
981
1014
|
/**
|
|
982
1015
|
* @see https://redis.io/commands/zpopmax
|
|
983
1016
|
*/
|
package/script/pkg/script.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Script = void 0;
|
|
4
|
-
const mod_js_1 = require("../deps/
|
|
4
|
+
const mod_js_1 = require("../deps/deno.land/x/sha1@v1.0.3/mod.js");
|
|
5
5
|
/**
|
|
6
6
|
* Creates a new script.
|
|
7
7
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { encode, decode } from "../../../denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js";
|
|
File without changes
|
package/types/deps/denopkg.com/chiefbiiko/{std-encoding@v1.1.1 → std-encoding@v1.0.0}/mod.d.ts
RENAMED
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Command, CommandOptions } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/zmscore
|
|
4
|
+
*/
|
|
5
|
+
export declare class ZMScoreCommand<TData> extends Command<string[] | null, number[] | null> {
|
|
6
|
+
constructor(cmd: [key: string, members: TData[]], opts?: CommandOptions<string[] | null, number[] | null>);
|
|
7
|
+
}
|
package/types/pkg/pipeline.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { CommandArgs } from "./types.js";
|
|
|
18
18
|
* **Examples:**
|
|
19
19
|
*
|
|
20
20
|
* ```ts
|
|
21
|
-
* const p = redis.pipeline()
|
|
21
|
+
* const p = redis.pipeline() // or redis.multi()
|
|
22
22
|
* p.set("key","value")
|
|
23
23
|
* p.get("key")
|
|
24
24
|
* const res = await p.exec()
|
|
@@ -44,7 +44,12 @@ export declare class Pipeline {
|
|
|
44
44
|
private client;
|
|
45
45
|
private commands;
|
|
46
46
|
private commandOptions?;
|
|
47
|
-
|
|
47
|
+
private multiExec;
|
|
48
|
+
constructor(opts: {
|
|
49
|
+
client: Requester;
|
|
50
|
+
commandOptions?: CommandOptions<any, any>;
|
|
51
|
+
multiExec?: boolean;
|
|
52
|
+
});
|
|
48
53
|
/**
|
|
49
54
|
* Send the pipeline request to upstash.
|
|
50
55
|
*
|
|
@@ -374,7 +379,7 @@ export declare class Pipeline {
|
|
|
374
379
|
/**
|
|
375
380
|
* @see https://redis.io/commands/set
|
|
376
381
|
*/
|
|
377
|
-
set: <TData>(key: string, value: TData, opts?: SetCommandOptions
|
|
382
|
+
set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => this;
|
|
378
383
|
/**
|
|
379
384
|
* @see https://redis.io/commands/setbit
|
|
380
385
|
*/
|
|
@@ -483,6 +488,10 @@ export declare class Pipeline {
|
|
|
483
488
|
* @see https://redis.io/commands/zlexcount
|
|
484
489
|
*/
|
|
485
490
|
zlexcount: (key: string, min: string, max: string) => this;
|
|
491
|
+
/**
|
|
492
|
+
* @see https://redis.io/commands/zmscore
|
|
493
|
+
*/
|
|
494
|
+
zmscore: (key: string, members: unknown[]) => this;
|
|
486
495
|
/**
|
|
487
496
|
* @see https://redis.io/commands/zpopmax
|
|
488
497
|
*/
|
package/types/pkg/redis.d.ts
CHANGED
|
@@ -40,6 +40,16 @@ export declare class Redis {
|
|
|
40
40
|
* @see {@link Pipeline}
|
|
41
41
|
*/
|
|
42
42
|
pipeline: () => Pipeline;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new transaction to allow executing multiple steps atomically.
|
|
45
|
+
*
|
|
46
|
+
* All the commands in a transaction are serialized and executed sequentially. A request sent by
|
|
47
|
+
* another client will never be served in the middle of the execution of a Redis Transaction. This
|
|
48
|
+
* guarantees that the commands are executed as a single isolated operation.
|
|
49
|
+
*
|
|
50
|
+
* @see {@link Pipeline}
|
|
51
|
+
*/
|
|
52
|
+
multi: () => Pipeline;
|
|
43
53
|
/**
|
|
44
54
|
* @see https://redis.io/commands/append
|
|
45
55
|
*/
|
|
@@ -356,7 +366,7 @@ export declare class Redis {
|
|
|
356
366
|
/**
|
|
357
367
|
* @see https://redis.io/commands/set
|
|
358
368
|
*/
|
|
359
|
-
set: <TData>(key: string, value: TData, opts?: SetCommandOptions
|
|
369
|
+
set: <TData>(key: string, value: TData, opts?: SetCommandOptions) => Promise<"OK" | TData | null>;
|
|
360
370
|
/**
|
|
361
371
|
* @see https://redis.io/commands/setbit
|
|
362
372
|
*/
|
|
@@ -465,6 +475,10 @@ export declare class Redis {
|
|
|
465
475
|
* @see https://redis.io/commands/zlexcount
|
|
466
476
|
*/
|
|
467
477
|
zlexcount: (key: string, min: string, max: string) => Promise<number>;
|
|
478
|
+
/**
|
|
479
|
+
* @see https://redis.io/commands/zmscore
|
|
480
|
+
*/
|
|
481
|
+
zmscore: (key: string, members: unknown[]) => Promise<number[] | null>;
|
|
468
482
|
/**
|
|
469
483
|
* @see https://redis.io/commands/zpopmax
|
|
470
484
|
*/
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { init } from "./base.js";
|
|
2
|
-
const lookup = [];
|
|
3
|
-
const revLookup = [];
|
|
4
|
-
const code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
5
|
-
for (let i = 0, l = code.length; i < l; ++i) {
|
|
6
|
-
lookup[i] = code[i];
|
|
7
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
8
|
-
}
|
|
9
|
-
// Support decoding URL-safe base64 strings, as Node.js does.
|
|
10
|
-
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
|
11
|
-
revLookup["-".charCodeAt(0)] = 62;
|
|
12
|
-
revLookup["_".charCodeAt(0)] = 63;
|
|
13
|
-
export const { byteLength, toUint8Array, fromUint8Array } = init(lookup, revLookup);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { encode, decode } from "../std-encoding@v1.1.1/mod.js";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.fromUint8Array = exports.toUint8Array = exports.byteLength = void 0;
|
|
5
|
-
const base_js_1 = require("./base.js");
|
|
6
|
-
const lookup = [];
|
|
7
|
-
const revLookup = [];
|
|
8
|
-
const code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
9
|
-
for (let i = 0, l = code.length; i < l; ++i) {
|
|
10
|
-
lookup[i] = code[i];
|
|
11
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
12
|
-
}
|
|
13
|
-
// Support decoding URL-safe base64 strings, as Node.js does.
|
|
14
|
-
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
|
15
|
-
revLookup["-".charCodeAt(0)] = 62;
|
|
16
|
-
revLookup["_".charCodeAt(0)] = 63;
|
|
17
|
-
_a = (0, base_js_1.init)(lookup, revLookup), exports.byteLength = _a.byteLength, exports.toUint8Array = _a.toUint8Array, exports.fromUint8Array = _a.fromUint8Array;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const byteLength: (b64: string) => number, toUint8Array: (b64: string) => Uint8Array, fromUint8Array: (buf: Uint8Array) => string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { encode, decode } from "../std-encoding@v1.1.1/mod.js";
|