@upstash/redis 0.0.0-ci.e3757170 → 0.0.0-ci.e730ad54-20220901
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/README.md +34 -272
- package/esm/deps/deno.land/x/base64@v0.2.1/base.js +100 -0
- package/esm/deps/deno.land/x/base64@v0.2.1/base64url.js +9 -0
- package/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +1 -0
- package/esm/deps/deno.land/x/sha1@v1.0.3/mod.js +191 -0
- package/esm/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +50 -0
- package/esm/pkg/commands/lpos.js +19 -0
- package/esm/pkg/commands/mod.js +1 -0
- package/esm/pkg/commands/scan.js +3 -0
- package/esm/pkg/commands/sdiffstore.js +1 -1
- package/esm/pkg/commands/set.js +16 -4
- package/esm/pkg/commands/zmscore.js +11 -0
- package/esm/pkg/commands/zrange.js +6 -0
- package/esm/pkg/pipeline.js +20 -1
- package/esm/pkg/redis.js +36 -1
- package/esm/pkg/script.js +77 -0
- package/package.json +1 -39
- package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
- package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
- package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
- package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
- package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
- package/script/pkg/commands/lpos.js +23 -0
- package/script/pkg/commands/mod.js +1 -0
- package/script/pkg/commands/scan.js +3 -0
- package/script/pkg/commands/sdiffstore.js +1 -1
- package/script/pkg/commands/set.js +16 -4
- package/script/pkg/commands/zmscore.js +15 -0
- package/script/pkg/commands/zrange.js +6 -0
- package/script/pkg/pipeline.js +19 -0
- package/script/pkg/redis.js +35 -0
- package/script/pkg/script.js +81 -0
- package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
- package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
- package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
- package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
- package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
- package/types/pkg/commands/bitop.d.ts +0 -1
- package/types/pkg/commands/bitpos.d.ts +1 -1
- package/types/pkg/commands/lpop.d.ts +1 -1
- package/types/pkg/commands/lpos.d.ts +15 -0
- package/types/pkg/commands/mget.d.ts +1 -1
- package/types/pkg/commands/mod.d.ts +1 -0
- package/types/pkg/commands/rpop.d.ts +2 -2
- package/types/pkg/commands/scan.d.ts +1 -0
- package/types/pkg/commands/sdiffstore.d.ts +1 -1
- package/types/pkg/commands/set.d.ts +31 -2
- package/types/pkg/commands/spop.d.ts +2 -2
- package/types/pkg/commands/zadd.d.ts +1 -1
- package/types/pkg/commands/zmscore.d.ts +7 -0
- package/types/pkg/commands/zrange.d.ts +7 -0
- package/types/pkg/pipeline.d.ts +18 -6
- package/types/pkg/redis.d.ts +26 -8
- package/types/pkg/script.d.ts +42 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/lpos
|
|
4
|
+
*/
|
|
5
|
+
export class LPosCommand extends Command {
|
|
6
|
+
constructor(cmd, opts) {
|
|
7
|
+
const args = ["lpos", cmd[0], cmd[1]];
|
|
8
|
+
if (typeof cmd[2]?.rank === "number") {
|
|
9
|
+
args.push("rank", cmd[2].rank);
|
|
10
|
+
}
|
|
11
|
+
if (typeof cmd[2]?.count === "number") {
|
|
12
|
+
args.push("count", cmd[2].count);
|
|
13
|
+
}
|
|
14
|
+
if (typeof cmd[2]?.maxLen === "number") {
|
|
15
|
+
args.push("maxLen", cmd[2].maxLen);
|
|
16
|
+
}
|
|
17
|
+
super(args, opts);
|
|
18
|
+
}
|
|
19
|
+
}
|
package/esm/pkg/commands/mod.js
CHANGED
package/esm/pkg/commands/scan.js
CHANGED
package/esm/pkg/commands/set.js
CHANGED
|
@@ -6,17 +6,29 @@ export class SetCommand extends Command {
|
|
|
6
6
|
constructor([key, value, opts], cmdOpts) {
|
|
7
7
|
const command = ["set", key, value];
|
|
8
8
|
if (opts) {
|
|
9
|
+
if ("nx" in opts && opts.nx) {
|
|
10
|
+
command.push("nx");
|
|
11
|
+
}
|
|
12
|
+
else if ("xx" in opts && opts.xx) {
|
|
13
|
+
command.push("xx");
|
|
14
|
+
}
|
|
15
|
+
if ("get" in opts && opts.get) {
|
|
16
|
+
command.push("get");
|
|
17
|
+
}
|
|
9
18
|
if ("ex" in opts && typeof opts.ex === "number") {
|
|
10
19
|
command.push("ex", opts.ex);
|
|
11
20
|
}
|
|
12
21
|
else if ("px" in opts && typeof opts.px === "number") {
|
|
13
22
|
command.push("px", opts.px);
|
|
14
23
|
}
|
|
15
|
-
if ("
|
|
16
|
-
command.push("
|
|
24
|
+
else if ("exat" in opts && typeof opts.exat === "number") {
|
|
25
|
+
command.push("exat", opts.exat);
|
|
17
26
|
}
|
|
18
|
-
else if ("
|
|
19
|
-
command.push("
|
|
27
|
+
else if ("pxat" in opts && typeof opts.pxat === "number") {
|
|
28
|
+
command.push("pxat", opts.pxat);
|
|
29
|
+
}
|
|
30
|
+
else if ("keepTtl" in opts && opts.keepTtl) {
|
|
31
|
+
command.push("keepTtl", opts.keepTtl);
|
|
20
32
|
}
|
|
21
33
|
}
|
|
22
34
|
super(command, cmdOpts);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from "./command.js";
|
|
2
|
+
/**
|
|
3
|
+
* @see https://redis.io/commands/zscore
|
|
4
|
+
*/
|
|
5
|
+
export class ZMScoreCommand extends Command {
|
|
6
|
+
constructor(cmd, opts) {
|
|
7
|
+
const [key, members] = cmd;
|
|
8
|
+
console.log({ key, members });
|
|
9
|
+
super(["zmscore", key, ...members], opts);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -12,6 +12,12 @@ export class ZRangeCommand extends Command {
|
|
|
12
12
|
if (opts?.byLex) {
|
|
13
13
|
command.push("bylex");
|
|
14
14
|
}
|
|
15
|
+
if (opts?.rev) {
|
|
16
|
+
command.push("rev");
|
|
17
|
+
}
|
|
18
|
+
if (typeof opts?.count !== "undefined" && typeof opts?.offset !== "undefined") {
|
|
19
|
+
command.push("limit", opts.offset, opts.count);
|
|
20
|
+
}
|
|
15
21
|
if (opts?.withScores) {
|
|
16
22
|
command.push("withscores");
|
|
17
23
|
}
|
package/esm/pkg/pipeline.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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, 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";
|
|
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.
|
|
@@ -475,6 +476,15 @@ export class Pipeline {
|
|
|
475
476
|
writable: true,
|
|
476
477
|
value: (...args) => this.chain(new LPopCommand(args, this.commandOptions))
|
|
477
478
|
});
|
|
479
|
+
/**
|
|
480
|
+
* @see https://redis.io/commands/lpos
|
|
481
|
+
*/
|
|
482
|
+
Object.defineProperty(this, "lpos", {
|
|
483
|
+
enumerable: true,
|
|
484
|
+
configurable: true,
|
|
485
|
+
writable: true,
|
|
486
|
+
value: (...args) => this.chain(new LPosCommand(args, this.commandOptions))
|
|
487
|
+
});
|
|
478
488
|
/**
|
|
479
489
|
* @see https://redis.io/commands/lpush
|
|
480
490
|
*/
|
|
@@ -1002,6 +1012,15 @@ export class Pipeline {
|
|
|
1002
1012
|
writable: true,
|
|
1003
1013
|
value: (...args) => this.chain(new ZLexCountCommand(args, this.commandOptions))
|
|
1004
1014
|
});
|
|
1015
|
+
/**
|
|
1016
|
+
* @see https://redis.io/commands/zmscore
|
|
1017
|
+
*/
|
|
1018
|
+
Object.defineProperty(this, "zmscore", {
|
|
1019
|
+
enumerable: true,
|
|
1020
|
+
configurable: true,
|
|
1021
|
+
writable: true,
|
|
1022
|
+
value: (...args) => this.chain(new ZMScoreCommand(args, this.commandOptions))
|
|
1023
|
+
});
|
|
1005
1024
|
/**
|
|
1006
1025
|
* @see https://redis.io/commands/zpopmax
|
|
1007
1026
|
*/
|
package/esm/pkg/redis.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
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, 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";
|
|
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
|
+
import { Script } from "./script.js";
|
|
4
|
+
import { ZMScoreCommand } from "./commands/zmscore.js";
|
|
3
5
|
/**
|
|
4
6
|
* Serverless redis client for upstash.
|
|
5
7
|
*/
|
|
@@ -28,6 +30,18 @@ export class Redis {
|
|
|
28
30
|
writable: true,
|
|
29
31
|
value: void 0
|
|
30
32
|
});
|
|
33
|
+
/**
|
|
34
|
+
* Wrap a new middleware around the HTTP client.
|
|
35
|
+
*/
|
|
36
|
+
Object.defineProperty(this, "use", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true,
|
|
40
|
+
value: (middleware) => {
|
|
41
|
+
const makeRequest = this.client.request.bind(this.client);
|
|
42
|
+
this.client.request = (req) => middleware(req, makeRequest);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
31
45
|
/**
|
|
32
46
|
* Create a new pipeline that allows you to send requests in bulk.
|
|
33
47
|
*
|
|
@@ -426,6 +440,15 @@ export class Redis {
|
|
|
426
440
|
writable: true,
|
|
427
441
|
value: (...args) => new LPopCommand(args, this.opts).exec(this.client)
|
|
428
442
|
});
|
|
443
|
+
/**
|
|
444
|
+
* @see https://redis.io/commands/lpos
|
|
445
|
+
*/
|
|
446
|
+
Object.defineProperty(this, "lpos", {
|
|
447
|
+
enumerable: true,
|
|
448
|
+
configurable: true,
|
|
449
|
+
writable: true,
|
|
450
|
+
value: (...args) => new LPosCommand(args, this.opts).exec(this.client)
|
|
451
|
+
});
|
|
429
452
|
/**
|
|
430
453
|
* @see https://redis.io/commands/lpush
|
|
431
454
|
*/
|
|
@@ -953,6 +976,15 @@ export class Redis {
|
|
|
953
976
|
writable: true,
|
|
954
977
|
value: (...args) => new ZLexCountCommand(args, this.opts).exec(this.client)
|
|
955
978
|
});
|
|
979
|
+
/**
|
|
980
|
+
* @see https://redis.io/commands/zmscore
|
|
981
|
+
*/
|
|
982
|
+
Object.defineProperty(this, "zmscore", {
|
|
983
|
+
enumerable: true,
|
|
984
|
+
configurable: true,
|
|
985
|
+
writable: true,
|
|
986
|
+
value: (...args) => new ZMScoreCommand(args, this.opts).exec(this.client)
|
|
987
|
+
});
|
|
956
988
|
/**
|
|
957
989
|
* @see https://redis.io/commands/zpopmax
|
|
958
990
|
*/
|
|
@@ -1064,4 +1096,7 @@ export class Redis {
|
|
|
1064
1096
|
this.client = client;
|
|
1065
1097
|
this.opts = opts;
|
|
1066
1098
|
}
|
|
1099
|
+
createScript(script) {
|
|
1100
|
+
return new Script(this, script);
|
|
1101
|
+
}
|
|
1067
1102
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { sha1 as digest } from "../deps/deno.land/x/sha1@v1.0.3/mod.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new script.
|
|
4
|
+
*
|
|
5
|
+
* Scripts offer the ability to optimistically try to execute a script without having to send the
|
|
6
|
+
* entire script to the server. If the script is loaded on the server, it tries again by sending
|
|
7
|
+
* the entire script. Afterwards, the script is cached on the server.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const redis = new Redis({...})
|
|
12
|
+
*
|
|
13
|
+
* const script = redis.createScript<string>("return ARGV[1];")
|
|
14
|
+
* const arg1 = await script.eval([], ["Hello World"])
|
|
15
|
+
* assertEquals(arg1, "Hello World")
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class Script {
|
|
19
|
+
constructor(redis, script) {
|
|
20
|
+
Object.defineProperty(this, "script", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "sha1", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: void 0
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "redis", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: void 0
|
|
37
|
+
});
|
|
38
|
+
this.redis = redis;
|
|
39
|
+
this.sha1 = this.digest(script);
|
|
40
|
+
this.script = script;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Send an `EVAL` command to redis.
|
|
44
|
+
*/
|
|
45
|
+
async eval(keys, args) {
|
|
46
|
+
return await this.redis.eval(this.script, keys, args);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Calculates the sha1 hash of the script and then calls `EVALSHA`.
|
|
50
|
+
*/
|
|
51
|
+
async evalsha(keys, args) {
|
|
52
|
+
return await this.redis.evalsha(this.sha1, keys, args);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Optimistically try to run `EVALSHA` first.
|
|
56
|
+
* If the script is not loaded in redis, it will fall back and try again with `EVAL`.
|
|
57
|
+
*
|
|
58
|
+
* Following calls will be able to use the cached script
|
|
59
|
+
*/
|
|
60
|
+
async exec(keys, args) {
|
|
61
|
+
const res = await this.redis.evalsha(this.sha1, keys, args).catch(async (err) => {
|
|
62
|
+
if (err instanceof Error &&
|
|
63
|
+
err.message.toLowerCase().includes("noscript")) {
|
|
64
|
+
return await this.redis.eval(this.script, keys, args);
|
|
65
|
+
}
|
|
66
|
+
throw err;
|
|
67
|
+
});
|
|
68
|
+
return res;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Compute the sha1 hash of the script and return its hex representation.
|
|
72
|
+
*/
|
|
73
|
+
digest(s) {
|
|
74
|
+
const hash = digest(s, "utf8", "hex");
|
|
75
|
+
return typeof hash === "string" ? hash : new TextDecoder().decode(hash);
|
|
76
|
+
}
|
|
77
|
+
}
|
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.e730ad54-20220901",
|
|
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",
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = void 0;
|
|
4
|
+
function getLengths(b64) {
|
|
5
|
+
const len = b64.length;
|
|
6
|
+
// if (len % 4 > 0) {
|
|
7
|
+
// throw new TypeError("Invalid string. Length must be a multiple of 4");
|
|
8
|
+
// }
|
|
9
|
+
// Trim off extra bytes after placeholder bytes are found
|
|
10
|
+
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
11
|
+
let validLen = b64.indexOf("=");
|
|
12
|
+
if (validLen === -1) {
|
|
13
|
+
validLen = len;
|
|
14
|
+
}
|
|
15
|
+
const placeHoldersLen = validLen === len ? 0 : 4 - (validLen % 4);
|
|
16
|
+
return [validLen, placeHoldersLen];
|
|
17
|
+
}
|
|
18
|
+
function init(lookup, revLookup, urlsafe = false) {
|
|
19
|
+
function _byteLength(validLen, placeHoldersLen) {
|
|
20
|
+
return Math.floor(((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen);
|
|
21
|
+
}
|
|
22
|
+
function tripletToBase64(num) {
|
|
23
|
+
return (lookup[(num >> 18) & 0x3f] +
|
|
24
|
+
lookup[(num >> 12) & 0x3f] +
|
|
25
|
+
lookup[(num >> 6) & 0x3f] +
|
|
26
|
+
lookup[num & 0x3f]);
|
|
27
|
+
}
|
|
28
|
+
function encodeChunk(buf, start, end) {
|
|
29
|
+
const out = new Array((end - start) / 3);
|
|
30
|
+
for (let i = start, curTriplet = 0; i < end; i += 3) {
|
|
31
|
+
out[curTriplet++] = tripletToBase64((buf[i] << 16) + (buf[i + 1] << 8) + buf[i + 2]);
|
|
32
|
+
}
|
|
33
|
+
return out.join("");
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
// base64 is 4/3 + up to two characters of the original data
|
|
37
|
+
byteLength(b64) {
|
|
38
|
+
return _byteLength.apply(null, getLengths(b64));
|
|
39
|
+
},
|
|
40
|
+
toUint8Array(b64) {
|
|
41
|
+
const [validLen, placeHoldersLen] = getLengths(b64);
|
|
42
|
+
const buf = new Uint8Array(_byteLength(validLen, placeHoldersLen));
|
|
43
|
+
// If there are placeholders, only get up to the last complete 4 chars
|
|
44
|
+
const len = placeHoldersLen ? validLen - 4 : validLen;
|
|
45
|
+
let tmp;
|
|
46
|
+
let curByte = 0;
|
|
47
|
+
let i;
|
|
48
|
+
for (i = 0; i < len; i += 4) {
|
|
49
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 18) |
|
|
50
|
+
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
|
51
|
+
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
|
52
|
+
revLookup[b64.charCodeAt(i + 3)];
|
|
53
|
+
buf[curByte++] = (tmp >> 16) & 0xff;
|
|
54
|
+
buf[curByte++] = (tmp >> 8) & 0xff;
|
|
55
|
+
buf[curByte++] = tmp & 0xff;
|
|
56
|
+
}
|
|
57
|
+
if (placeHoldersLen === 2) {
|
|
58
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 2) |
|
|
59
|
+
(revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
60
|
+
buf[curByte++] = tmp & 0xff;
|
|
61
|
+
}
|
|
62
|
+
else if (placeHoldersLen === 1) {
|
|
63
|
+
tmp = (revLookup[b64.charCodeAt(i)] << 10) |
|
|
64
|
+
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
|
65
|
+
(revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
66
|
+
buf[curByte++] = (tmp >> 8) & 0xff;
|
|
67
|
+
buf[curByte++] = tmp & 0xff;
|
|
68
|
+
}
|
|
69
|
+
return buf;
|
|
70
|
+
},
|
|
71
|
+
fromUint8Array(buf) {
|
|
72
|
+
const maxChunkLength = 16383; // Must be multiple of 3
|
|
73
|
+
const len = buf.length;
|
|
74
|
+
const extraBytes = len % 3; // If we have 1 byte left, pad 2 bytes
|
|
75
|
+
const len2 = len - extraBytes;
|
|
76
|
+
const parts = new Array(Math.ceil(len2 / maxChunkLength) + (extraBytes ? 1 : 0));
|
|
77
|
+
let curChunk = 0;
|
|
78
|
+
let chunkEnd;
|
|
79
|
+
// Go through the array every three bytes, we'll deal with trailing stuff later
|
|
80
|
+
for (let i = 0; i < len2; i += maxChunkLength) {
|
|
81
|
+
chunkEnd = i + maxChunkLength;
|
|
82
|
+
parts[curChunk++] = encodeChunk(buf, i, chunkEnd > len2 ? len2 : chunkEnd);
|
|
83
|
+
}
|
|
84
|
+
let tmp;
|
|
85
|
+
// Pad the end with zeros, but make sure to not forget the extra bytes
|
|
86
|
+
if (extraBytes === 1) {
|
|
87
|
+
tmp = buf[len2];
|
|
88
|
+
parts[curChunk] = lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3f];
|
|
89
|
+
if (!urlsafe)
|
|
90
|
+
parts[curChunk] += "==";
|
|
91
|
+
}
|
|
92
|
+
else if (extraBytes === 2) {
|
|
93
|
+
tmp = (buf[len2] << 8) | (buf[len2 + 1] & 0xff);
|
|
94
|
+
parts[curChunk] = lookup[tmp >> 10] +
|
|
95
|
+
lookup[(tmp >> 4) & 0x3f] +
|
|
96
|
+
lookup[(tmp << 2) & 0x3f];
|
|
97
|
+
if (!urlsafe)
|
|
98
|
+
parts[curChunk] += "=";
|
|
99
|
+
}
|
|
100
|
+
return parts.join("");
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
exports.init = init;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
_a = (0, base_js_1.init)(lookup, revLookup, true), exports.byteLength = _a.byteLength, exports.toUint8Array = _a.toUint8Array, exports.fromUint8Array = _a.fromUint8Array;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decode = exports.encode = void 0;
|
|
4
|
+
var mod_js_1 = require("../../../denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js");
|
|
5
|
+
Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return mod_js_1.encode; } });
|
|
6
|
+
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return mod_js_1.decode; } });
|