@upstash/ratelimit 0.3.0-rc.0 → 0.3.1
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/dist/index.d.ts +569 -0
- package/dist/index.js +736 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +707 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +23 -42
- package/.releaserc +0 -14
- package/esm/_dnt.shims.js +0 -62
- package/esm/analytics.js +0 -84
- package/esm/cache.js +0 -40
- package/esm/deps/deno.land/x/base64@v0.2.1/base.js +0 -100
- package/esm/deps/deno.land/x/base64@v0.2.1/base64url.js +0 -9
- package/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +0 -1
- package/esm/deps/deno.land/x/sha1@v1.0.3/mod.js +0 -191
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/mod.js +0 -66
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/append.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitcount.js +0 -16
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitop.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitpos.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/command.js +0 -57
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/dbsize.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/decr.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/decrby.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/del.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/echo.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/eval.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/evalsha.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/exists.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/expire.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/expireat.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/flushall.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/flushdb.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/get.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getbit.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getdel.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getrange.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getset.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hdel.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hexists.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hget.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hgetall.js +0 -29
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hincrby.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hincrbyfloat.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hkeys.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hlen.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hmget.js +0 -35
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hmset.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hrandfield.js +0 -39
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hscan.js +0 -16
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hset.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hsetnx.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hstrlen.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hvals.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incr.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incrby.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incrbyfloat.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/keys.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lindex.js +0 -6
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/linsert.js +0 -6
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/llen.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lmove.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpop.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpos.js +0 -19
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpush.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpushx.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lrange.js +0 -6
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lrem.js +0 -6
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lset.js +0 -6
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ltrim.js +0 -6
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mget.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mod.js +0 -119
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mset.js +0 -12
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/msetnx.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/persist.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pexpire.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pexpireat.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ping.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/psetex.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pttl.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/publish.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/randomkey.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rename.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/renamenx.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpop.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpush.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpushx.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sadd.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/scan.js +0 -19
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/scard.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_exists.js +0 -12
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_flush.js +0 -16
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_load.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sdiff.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sdiffstore.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/set.js +0 -36
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setbit.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setex.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setnx.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setrange.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sinter.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sinterstore.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sismember.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smembers.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smismember.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smove.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/spop.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/srandmember.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/srem.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sscan.js +0 -16
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/strlen.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sunion.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sunionstore.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/time.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/touch.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ttl.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/type.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/unlink.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zadd.js +0 -26
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zcard.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zcount.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zdiffstore.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zincrby.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zinterstore.js +0 -27
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zlexcount.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zmscore.js +0 -10
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zpopmax.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zpopmin.js +0 -13
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrange.js +0 -26
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrank.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrem.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebylex.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebyrank.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebyscore.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrevrank.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zscan.js +0 -16
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zscore.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zunionstore.js +0 -27
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/error.js +0 -9
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/http.js +0 -165
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/pipeline.js +0 -1199
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/redis.js +0 -1200
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/script.js +0 -77
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/types.js +0 -1
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/pkg/util.js +0 -31
- package/esm/deps/deno.land/x/upstash_redis@v1.19.3/version.js +0 -1
- package/esm/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +0 -50
- package/esm/duration.js +0 -21
- package/esm/mod.js +0 -2
- package/esm/multi.js +0 -268
- package/esm/package.json +0 -3
- package/esm/ratelimit.js +0 -197
- package/esm/single.js +0 -376
- package/esm/types.js +0 -1
- package/script/_dnt.shims.js +0 -66
- package/script/analytics.js +0 -88
- package/script/cache.js +0 -44
- package/script/deps/deno.land/x/base64@v0.2.1/base.js +0 -104
- package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +0 -13
- package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +0 -6
- package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +0 -196
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/mod.js +0 -93
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/append.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitcount.js +0 -20
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitop.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitpos.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/command.js +0 -61
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/dbsize.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/decr.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/decrby.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/del.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/echo.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/eval.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/evalsha.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/exists.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/expire.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/expireat.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/flushall.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/flushdb.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/get.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getbit.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getdel.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getrange.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getset.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hdel.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hexists.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hget.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hgetall.js +0 -33
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hincrby.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hincrbyfloat.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hkeys.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hlen.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hmget.js +0 -39
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hmset.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hrandfield.js +0 -43
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hscan.js +0 -20
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hset.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hsetnx.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hstrlen.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hvals.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incr.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incrby.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incrbyfloat.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/keys.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lindex.js +0 -10
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/linsert.js +0 -10
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/llen.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lmove.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpop.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpos.js +0 -23
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpush.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpushx.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lrange.js +0 -10
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lrem.js +0 -10
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lset.js +0 -10
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ltrim.js +0 -10
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mget.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mod.js +0 -135
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mset.js +0 -16
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/msetnx.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/persist.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pexpire.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pexpireat.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ping.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/psetex.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pttl.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/publish.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/randomkey.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rename.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/renamenx.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpop.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpush.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpushx.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sadd.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/scan.js +0 -23
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/scard.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_exists.js +0 -16
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_flush.js +0 -20
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_load.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sdiff.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sdiffstore.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/set.js +0 -40
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setbit.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setex.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setnx.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setrange.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sinter.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sinterstore.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sismember.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smembers.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smismember.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smove.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/spop.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/srandmember.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/srem.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sscan.js +0 -20
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/strlen.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sunion.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sunionstore.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/time.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/touch.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ttl.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/type.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/unlink.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zadd.js +0 -30
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zcard.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zcount.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zdiffstore.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zincrby.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zinterstore.js +0 -31
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zlexcount.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zmscore.js +0 -14
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zpopmax.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zpopmin.js +0 -17
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrange.js +0 -30
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrank.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrem.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebylex.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebyrank.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebyscore.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrevrank.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zscan.js +0 -20
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zscore.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zunionstore.js +0 -31
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/error.js +0 -13
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/http.js +0 -169
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/pipeline.js +0 -1203
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/redis.js +0 -1204
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/script.js +0 -81
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/types.js +0 -2
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/pkg/util.js +0 -35
- package/script/deps/deno.land/x/upstash_redis@v1.19.3/version.js +0 -4
- package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +0 -55
- package/script/duration.js +0 -25
- package/script/mod.js +0 -7
- package/script/multi.js +0 -295
- package/script/package.json +0 -3
- package/script/ratelimit.js +0 -202
- package/script/single.js +0 -380
- package/script/types.js +0 -2
- package/types/_dnt.shims.d.ts +0 -5
- package/types/analytics.d.ts +0 -36
- package/types/cache.d.ts +0 -16
- package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +0 -5
- package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +0 -1
- package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +0 -1
- package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +0 -26
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/mod.d.ts +0 -41
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/append.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitcount.d.ts +0 -8
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitop.d.ts +0 -12
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/bitpos.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/command.d.ts +0 -37
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/dbsize.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/decr.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/decrby.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/del.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/echo.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/eval.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/evalsha.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/exists.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/expire.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/expireat.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/flushall.d.ts +0 -9
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/flushdb.d.ts +0 -9
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/get.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getbit.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getdel.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getrange.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/getset.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hdel.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hexists.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hget.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hgetall.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hincrby.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hincrbyfloat.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hkeys.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hlen.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hmget.d.ts +0 -15
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hmset.d.ts +0 -9
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hrandfield.d.ts +0 -9
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hscan.d.ts +0 -24
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hset.d.ts +0 -9
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hsetnx.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hstrlen.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/hvals.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incr.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incrby.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/incrbyfloat.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/keys.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lindex.d.ts +0 -4
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/linsert.d.ts +0 -9
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/llen.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lmove.d.ts +0 -12
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpop.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpos.d.ts +0 -15
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpush.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lpushx.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lrange.d.ts +0 -4
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lrem.d.ts +0 -4
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/lset.d.ts +0 -4
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ltrim.d.ts +0 -4
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mget.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mod.d.ts +0 -119
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/mset.d.ts +0 -9
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/msetnx.d.ts +0 -9
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/persist.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pexpire.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pexpireat.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ping.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/psetex.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/pttl.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/publish.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/randomkey.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rename.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/renamenx.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpop.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpush.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/rpushx.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sadd.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/scan.d.ts +0 -18
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/scard.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_exists.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_flush.d.ts +0 -14
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/script_load.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sdiff.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sdiffstore.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/set.d.ts +0 -55
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setbit.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setex.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setnx.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/setrange.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sinter.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sinterstore.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sismember.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smembers.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smismember.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/smove.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/spop.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/srandmember.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/srem.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sscan.d.ts +0 -24
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/strlen.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sunion.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/sunionstore.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/time.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/touch.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/ttl.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/type.d.ts +0 -8
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/unlink.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zadd.d.ts +0 -35
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zcard.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zcount.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zdiffstore.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zincrby.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zinterstore.d.ts +0 -30
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zlexcount.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zmscore.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zpopmax.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zpopmin.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrange.d.ts +0 -42
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrank.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrem.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebylex.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebyrank.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zremrangebyscore.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zrevrank.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zscan.d.ts +0 -24
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zscore.d.ts +0 -7
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/commands/zunionstore.d.ts +0 -30
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/error.d.ts +0 -6
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/http.d.ts +0 -87
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/pipeline.d.ts +0 -577
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/redis.d.ts +0 -575
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/script.d.ts +0 -42
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/types.d.ts +0 -18
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/pkg/util.d.ts +0 -1
- package/types/deps/deno.land/x/upstash_redis@v1.19.3/version.d.ts +0 -1
- package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +0 -3
- package/types/duration.d.ts +0 -7
- package/types/mod.d.ts +0 -5
- package/types/multi.d.ts +0 -128
- package/types/ratelimit.d.ts +0 -123
- package/types/single.d.ts +0 -194
- package/types/types.d.ts +0 -67
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { sha1 as digest } from "../../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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
function parseRecursive(obj) {
|
|
2
|
-
const parsed = Array.isArray(obj)
|
|
3
|
-
? obj.map((o) => {
|
|
4
|
-
try {
|
|
5
|
-
return parseRecursive(o);
|
|
6
|
-
}
|
|
7
|
-
catch {
|
|
8
|
-
return o;
|
|
9
|
-
}
|
|
10
|
-
})
|
|
11
|
-
: JSON.parse(obj);
|
|
12
|
-
/**
|
|
13
|
-
* Parsing very large numbers can result in MAX_SAFE_INTEGER
|
|
14
|
-
* overflow. In that case we return the number as string instead.
|
|
15
|
-
*/
|
|
16
|
-
if (typeof parsed === "number" && parsed.toString() != obj) {
|
|
17
|
-
return obj;
|
|
18
|
-
}
|
|
19
|
-
return parsed;
|
|
20
|
-
}
|
|
21
|
-
export function parseResponse(result) {
|
|
22
|
-
try {
|
|
23
|
-
/**
|
|
24
|
-
* Try to parse the response if possible
|
|
25
|
-
*/
|
|
26
|
-
return parseRecursive(result);
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const VERSION = "development";
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { toUint8Array, fromUint8Array } from "../../../deno.land/x/base64@v0.2.1/base64url.js";
|
|
2
|
-
const decoder = new TextDecoder();
|
|
3
|
-
const encoder = new TextEncoder();
|
|
4
|
-
/** Serializes a Uint8Array to a hexadecimal string. */
|
|
5
|
-
function toHexString(buf) {
|
|
6
|
-
return buf.reduce((hex, byte) => `${hex}${byte < 16 ? "0" : ""}${byte.toString(16)}`, "");
|
|
7
|
-
}
|
|
8
|
-
/** Deserializes a Uint8Array from a hexadecimal string. */
|
|
9
|
-
function fromHexString(hex) {
|
|
10
|
-
const len = hex.length;
|
|
11
|
-
if (len % 2 || !/^[0-9a-fA-F]+$/.test(hex)) {
|
|
12
|
-
throw new TypeError("Invalid hex string.");
|
|
13
|
-
}
|
|
14
|
-
hex = hex.toLowerCase();
|
|
15
|
-
const buf = new Uint8Array(Math.floor(len / 2));
|
|
16
|
-
const end = len / 2;
|
|
17
|
-
for (let i = 0; i < end; ++i) {
|
|
18
|
-
buf[i] = parseInt(hex.substr(i * 2, 2), 16);
|
|
19
|
-
}
|
|
20
|
-
return buf;
|
|
21
|
-
}
|
|
22
|
-
/** Decodes a Uint8Array to utf8-, base64-, or hex-encoded string. */
|
|
23
|
-
export function decode(buf, encoding = "utf8") {
|
|
24
|
-
if (/^utf-?8$/i.test(encoding)) {
|
|
25
|
-
return decoder.decode(buf);
|
|
26
|
-
}
|
|
27
|
-
else if (/^base64$/i.test(encoding)) {
|
|
28
|
-
return fromUint8Array(buf);
|
|
29
|
-
}
|
|
30
|
-
else if (/^hex(?:adecimal)?$/i.test(encoding)) {
|
|
31
|
-
return toHexString(buf);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw new TypeError("Unsupported string encoding.");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export function encode(str, encoding = "utf8") {
|
|
38
|
-
if (/^utf-?8$/i.test(encoding)) {
|
|
39
|
-
return encoder.encode(str);
|
|
40
|
-
}
|
|
41
|
-
else if (/^base64$/i.test(encoding)) {
|
|
42
|
-
return toUint8Array(str);
|
|
43
|
-
}
|
|
44
|
-
else if (/^hex(?:adecimal)?$/i.test(encoding)) {
|
|
45
|
-
return fromHexString(str);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
throw new TypeError("Unsupported string encoding.");
|
|
49
|
-
}
|
|
50
|
-
}
|
package/esm/duration.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert a human readable duration to milliseconds
|
|
3
|
-
*/
|
|
4
|
-
export function ms(d) {
|
|
5
|
-
const [timeString, duration] = d.split(" ");
|
|
6
|
-
const time = parseFloat(timeString);
|
|
7
|
-
switch (duration) {
|
|
8
|
-
case "ms":
|
|
9
|
-
return time;
|
|
10
|
-
case "s":
|
|
11
|
-
return time * 1000;
|
|
12
|
-
case "m":
|
|
13
|
-
return time * 1000 * 60;
|
|
14
|
-
case "h":
|
|
15
|
-
return time * 1000 * 60 * 60;
|
|
16
|
-
case "d":
|
|
17
|
-
return time * 1000 * 60 * 60 * 24;
|
|
18
|
-
default:
|
|
19
|
-
throw new Error(`Unable to parse window size: ${d}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
package/esm/mod.js
DELETED
package/esm/multi.js
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import * as dntShim from "./_dnt.shims.js";
|
|
2
|
-
import { ms } from "./duration.js";
|
|
3
|
-
import { Ratelimit } from "./ratelimit.js";
|
|
4
|
-
import { Cache } from "./cache.js";
|
|
5
|
-
/**
|
|
6
|
-
* Ratelimiter using serverless redis from https://upstash.com/
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const { limit } = new MultiRegionRatelimit({
|
|
11
|
-
* redis: Redis.fromEnv(),
|
|
12
|
-
* limiter: MultiRegionRatelimit.fixedWindow(
|
|
13
|
-
* 10, // Allow 10 requests per window of 30 minutes
|
|
14
|
-
* "30 m", // interval of 30 minutes
|
|
15
|
-
* )
|
|
16
|
-
* })
|
|
17
|
-
*
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export class MultiRegionRatelimit extends Ratelimit {
|
|
21
|
-
/**
|
|
22
|
-
* Create a new Ratelimit instance by providing a `@upstash/redis` instance and the algorithn of your choice.
|
|
23
|
-
*/
|
|
24
|
-
constructor(config) {
|
|
25
|
-
super({
|
|
26
|
-
prefix: config.prefix,
|
|
27
|
-
limiter: config.limiter,
|
|
28
|
-
timeout: config.timeout,
|
|
29
|
-
analytics: config.analytics,
|
|
30
|
-
ctx: {
|
|
31
|
-
redis: config.redis,
|
|
32
|
-
cache: config.ephemeralCache
|
|
33
|
-
? new Cache(config.ephemeralCache)
|
|
34
|
-
: undefined,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Each requests inside a fixed time increases a counter.
|
|
40
|
-
* Once the counter reaches a maxmimum allowed number, all further requests are
|
|
41
|
-
* rejected.
|
|
42
|
-
*
|
|
43
|
-
* **Pro:**
|
|
44
|
-
*
|
|
45
|
-
* - Newer requests are not starved by old ones.
|
|
46
|
-
* - Low storage cost.
|
|
47
|
-
*
|
|
48
|
-
* **Con:**
|
|
49
|
-
*
|
|
50
|
-
* A burst of requests near the boundary of a window can result in a very
|
|
51
|
-
* high request rate because two windows will be filled with requests quickly.
|
|
52
|
-
*
|
|
53
|
-
* @param tokens - How many requests a user can make in each time window.
|
|
54
|
-
* @param window - A fixed timeframe
|
|
55
|
-
*/
|
|
56
|
-
static fixedWindow(
|
|
57
|
-
/**
|
|
58
|
-
* How many requests are allowed per window.
|
|
59
|
-
*/
|
|
60
|
-
tokens,
|
|
61
|
-
/**
|
|
62
|
-
* The duration in which `tokens` requests are allowed.
|
|
63
|
-
*/
|
|
64
|
-
window) {
|
|
65
|
-
const windowDuration = ms(window);
|
|
66
|
-
const script = `
|
|
67
|
-
local key = KEYS[1]
|
|
68
|
-
local id = ARGV[1]
|
|
69
|
-
local window = ARGV[2]
|
|
70
|
-
|
|
71
|
-
redis.call("SADD", key, id)
|
|
72
|
-
local members = redis.call("SMEMBERS", key)
|
|
73
|
-
if #members == 1 then
|
|
74
|
-
-- The first time this key is set, the value will be 1.
|
|
75
|
-
-- So we only need the expire command once
|
|
76
|
-
redis.call("PEXPIRE", key, window)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
return members
|
|
80
|
-
`;
|
|
81
|
-
return async function (ctx, identifier) {
|
|
82
|
-
if (ctx.cache) {
|
|
83
|
-
const { blocked, reset } = ctx.cache.isBlocked(identifier);
|
|
84
|
-
if (blocked) {
|
|
85
|
-
return {
|
|
86
|
-
success: false,
|
|
87
|
-
limit: tokens,
|
|
88
|
-
remaining: 0,
|
|
89
|
-
reset: reset,
|
|
90
|
-
pending: Promise.resolve(),
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
const requestID = dntShim.crypto.randomUUID();
|
|
95
|
-
const bucket = Math.floor(Date.now() / windowDuration);
|
|
96
|
-
const key = [identifier, bucket].join(":");
|
|
97
|
-
const dbs = ctx.redis.map((redis) => ({
|
|
98
|
-
redis,
|
|
99
|
-
request: redis.eval(script, [key], [requestID, windowDuration]),
|
|
100
|
-
}));
|
|
101
|
-
const firstResponse = await Promise.any(dbs.map((s) => s.request));
|
|
102
|
-
const usedTokens = firstResponse.length;
|
|
103
|
-
const remaining = tokens - usedTokens - 1;
|
|
104
|
-
/**
|
|
105
|
-
* If the length between two databases does not match, we sync the two databases
|
|
106
|
-
*/
|
|
107
|
-
async function sync() {
|
|
108
|
-
const individualIDs = await Promise.all(dbs.map((s) => s.request));
|
|
109
|
-
const allIDs = Array.from(new Set(individualIDs.flatMap((_) => _)).values());
|
|
110
|
-
for (const db of dbs) {
|
|
111
|
-
const ids = await db.request;
|
|
112
|
-
/**
|
|
113
|
-
* If the bucket in this db is already full, it doesn't matter which ids it contains.
|
|
114
|
-
* So we do not have to sync.
|
|
115
|
-
*/
|
|
116
|
-
if (ids.length >= tokens) {
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
const diff = allIDs.filter((id) => !ids.includes(id));
|
|
120
|
-
/**
|
|
121
|
-
* Don't waste a request if there is nothing to send
|
|
122
|
-
*/
|
|
123
|
-
if (diff.length === 0) {
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
await db.redis.sadd(key, ...allIDs);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Do not await sync. This should not run in the critical path.
|
|
131
|
-
*/
|
|
132
|
-
const success = remaining > 0;
|
|
133
|
-
const reset = (bucket + 1) * windowDuration;
|
|
134
|
-
if (ctx.cache && !success) {
|
|
135
|
-
ctx.cache.blockUntil(identifier, reset);
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
success,
|
|
139
|
-
limit: tokens,
|
|
140
|
-
remaining,
|
|
141
|
-
reset,
|
|
142
|
-
pending: sync(),
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Combined approach of `slidingLogs` and `fixedWindow` with lower storage
|
|
148
|
-
* costs than `slidingLogs` and improved boundary behavior by calcualting a
|
|
149
|
-
* weighted score between two windows.
|
|
150
|
-
*
|
|
151
|
-
* **Pro:**
|
|
152
|
-
*
|
|
153
|
-
* Good performance allows this to scale to very high loads.
|
|
154
|
-
*
|
|
155
|
-
* **Con:**
|
|
156
|
-
*
|
|
157
|
-
* Nothing major.
|
|
158
|
-
*
|
|
159
|
-
* @param tokens - How many requests a user can make in each time window.
|
|
160
|
-
* @param window - The duration in which the user can max X requests.
|
|
161
|
-
*/
|
|
162
|
-
static slidingWindow(
|
|
163
|
-
/**
|
|
164
|
-
* How many requests are allowed per window.
|
|
165
|
-
*/
|
|
166
|
-
tokens,
|
|
167
|
-
/**
|
|
168
|
-
* The duration in which `tokens` requests are allowed.
|
|
169
|
-
*/
|
|
170
|
-
window) {
|
|
171
|
-
const windowSize = ms(window);
|
|
172
|
-
const script = `
|
|
173
|
-
local currentKey = KEYS[1] -- identifier including prefixes
|
|
174
|
-
local previousKey = KEYS[2] -- key of the previous bucket
|
|
175
|
-
local tokens = tonumber(ARGV[1]) -- tokens per window
|
|
176
|
-
local now = ARGV[2] -- current timestamp in milliseconds
|
|
177
|
-
local window = ARGV[3] -- interval in milliseconds
|
|
178
|
-
local requestID = ARGV[4] -- uuid for this request
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
local currentMembers = redis.call("SMEMBERS", currentKey)
|
|
182
|
-
local requestsInCurrentWindow = #currentMembers
|
|
183
|
-
local previousMembers = redis.call("SMEMBERS", previousKey)
|
|
184
|
-
local requestsInPreviousWindow = #previousMembers
|
|
185
|
-
|
|
186
|
-
local percentageInCurrent = ( now % window) / window
|
|
187
|
-
if requestsInPreviousWindow * ( 1 - percentageInCurrent ) + requestsInCurrentWindow >= tokens then
|
|
188
|
-
return {currentMembers, previousMembers}
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
redis.call("SADD", currentKey, requestID)
|
|
192
|
-
table.insert(currentMembers, requestID)
|
|
193
|
-
if requestsInCurrentWindow == 0 then
|
|
194
|
-
-- The first time this key is set, the value will be 1.
|
|
195
|
-
-- So we only need the expire command once
|
|
196
|
-
redis.call("PEXPIRE", currentKey, window * 2 + 1000) -- Enough time to overlap with a new window + 1 second
|
|
197
|
-
end
|
|
198
|
-
return {currentMembers, previousMembers}
|
|
199
|
-
`;
|
|
200
|
-
const windowDuration = ms(window);
|
|
201
|
-
return async function (ctx, identifier) {
|
|
202
|
-
if (ctx.cache) {
|
|
203
|
-
const { blocked, reset } = ctx.cache.isBlocked(identifier);
|
|
204
|
-
if (blocked) {
|
|
205
|
-
return {
|
|
206
|
-
success: false,
|
|
207
|
-
limit: tokens,
|
|
208
|
-
remaining: 0,
|
|
209
|
-
reset: reset,
|
|
210
|
-
pending: Promise.resolve(),
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
const requestID = dntShim.crypto.randomUUID();
|
|
215
|
-
const now = Date.now();
|
|
216
|
-
const currentWindow = Math.floor(now / windowSize);
|
|
217
|
-
const currentKey = [identifier, currentWindow].join(":");
|
|
218
|
-
const previousWindow = currentWindow - windowSize;
|
|
219
|
-
const previousKey = [identifier, previousWindow].join(":");
|
|
220
|
-
const dbs = ctx.redis.map((redis) => ({
|
|
221
|
-
redis,
|
|
222
|
-
request: redis.eval(script, [currentKey, previousKey], [tokens, now, windowDuration, requestID]),
|
|
223
|
-
}));
|
|
224
|
-
const percentageInCurrent = (now % windowDuration) / windowDuration;
|
|
225
|
-
const [current, previous] = await Promise.any(dbs.map((s) => s.request));
|
|
226
|
-
const usedTokens = previous.length * (1 - percentageInCurrent) +
|
|
227
|
-
current.length;
|
|
228
|
-
const remaining = tokens - usedTokens;
|
|
229
|
-
/**
|
|
230
|
-
* If a database differs from the consensus, we sync it
|
|
231
|
-
*/
|
|
232
|
-
async function sync() {
|
|
233
|
-
const [individualIDs] = await Promise.all(dbs.map((s) => s.request));
|
|
234
|
-
const allIDs = Array.from(new Set(individualIDs.flatMap((_) => _)).values());
|
|
235
|
-
for (const db of dbs) {
|
|
236
|
-
const [ids] = await db.request;
|
|
237
|
-
/**
|
|
238
|
-
* If the bucket in this db is already full, it doesn't matter which ids it contains.
|
|
239
|
-
* So we do not have to sync.
|
|
240
|
-
*/
|
|
241
|
-
if (ids.length >= tokens) {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
const diff = allIDs.filter((id) => !ids.includes(id));
|
|
245
|
-
/**
|
|
246
|
-
* Don't waste a request if there is nothing to send
|
|
247
|
-
*/
|
|
248
|
-
if (diff.length === 0) {
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
await db.redis.sadd(currentKey, ...allIDs);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
const success = remaining > 0;
|
|
255
|
-
const reset = (currentWindow + 1) * windowDuration;
|
|
256
|
-
if (ctx.cache && !success) {
|
|
257
|
-
ctx.cache.blockUntil(identifier, reset);
|
|
258
|
-
}
|
|
259
|
-
return {
|
|
260
|
-
success,
|
|
261
|
-
limit: tokens,
|
|
262
|
-
remaining,
|
|
263
|
-
reset,
|
|
264
|
-
pending: sync(),
|
|
265
|
-
};
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
}
|
package/esm/package.json
DELETED
package/esm/ratelimit.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { Analytics } from "./analytics.js";
|
|
2
|
-
import { Cache } from "./cache.js";
|
|
3
|
-
export class TimeoutError extends Error {
|
|
4
|
-
constructor() {
|
|
5
|
-
super("Timeout");
|
|
6
|
-
this.name = "TimeoutError";
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Ratelimiter using serverless redis from https://upstash.com/
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const { limit } = new Ratelimit({
|
|
15
|
-
* redis: Redis.fromEnv(),
|
|
16
|
-
* limiter: Ratelimit.slidingWindow(
|
|
17
|
-
* 10, // Allow 10 requests per window of 30 minutes
|
|
18
|
-
* "30 m", // interval of 30 minutes
|
|
19
|
-
* ),
|
|
20
|
-
* })
|
|
21
|
-
*
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export class Ratelimit {
|
|
25
|
-
constructor(config) {
|
|
26
|
-
Object.defineProperty(this, "limiter", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true,
|
|
30
|
-
value: void 0
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(this, "ctx", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
writable: true,
|
|
36
|
-
value: void 0
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(this, "prefix", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
configurable: true,
|
|
41
|
-
writable: true,
|
|
42
|
-
value: void 0
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(this, "timeout", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: void 0
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(this, "analytics", {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true,
|
|
53
|
-
writable: true,
|
|
54
|
-
value: void 0
|
|
55
|
-
});
|
|
56
|
-
/**
|
|
57
|
-
* Determine if a request should pass or be rejected based on the identifier and previously chosen ratelimit.
|
|
58
|
-
*
|
|
59
|
-
* Use this if you want to reject all requests that you can not handle right now.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* const ratelimit = new Ratelimit({
|
|
64
|
-
* redis: Redis.fromEnv(),
|
|
65
|
-
* limiter: Ratelimit.slidingWindow(10, "10 s")
|
|
66
|
-
* })
|
|
67
|
-
*
|
|
68
|
-
* const { success } = await ratelimit.limit(id)
|
|
69
|
-
* if (!success){
|
|
70
|
-
* return "Nope"
|
|
71
|
-
* }
|
|
72
|
-
* return "Yes"
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
Object.defineProperty(this, "limit", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
writable: true,
|
|
79
|
-
value: async (identifier, req) => {
|
|
80
|
-
const key = [this.prefix, identifier].join(":");
|
|
81
|
-
let timeoutId = null;
|
|
82
|
-
try {
|
|
83
|
-
const arr = [this.limiter(this.ctx, key)];
|
|
84
|
-
if (this.timeout) {
|
|
85
|
-
arr.push(new Promise((resolve) => {
|
|
86
|
-
timeoutId = setTimeout(() => {
|
|
87
|
-
resolve({
|
|
88
|
-
success: true,
|
|
89
|
-
limit: 0,
|
|
90
|
-
remaining: 0,
|
|
91
|
-
reset: 0,
|
|
92
|
-
pending: Promise.resolve(),
|
|
93
|
-
});
|
|
94
|
-
}, this.timeout);
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
const res = await Promise.race(arr);
|
|
98
|
-
if (this.analytics) {
|
|
99
|
-
const geo = req ? this.analytics.extractGeo(req) : undefined;
|
|
100
|
-
const analyticsP = this.analytics.record({
|
|
101
|
-
identifier,
|
|
102
|
-
time: Date.now(),
|
|
103
|
-
success: res.success,
|
|
104
|
-
...geo,
|
|
105
|
-
});
|
|
106
|
-
res.pending = Promise.all([res.pending, analyticsP]);
|
|
107
|
-
}
|
|
108
|
-
return res;
|
|
109
|
-
}
|
|
110
|
-
finally {
|
|
111
|
-
if (timeoutId) {
|
|
112
|
-
clearTimeout(timeoutId);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
/**
|
|
118
|
-
* Block until the request may pass or timeout is reached.
|
|
119
|
-
*
|
|
120
|
-
* This method returns a promsie that resolves as soon as the request may be processed
|
|
121
|
-
* or after the timeoue has been reached.
|
|
122
|
-
*
|
|
123
|
-
* Use this if you want to delay the request until it is ready to get processed.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* const ratelimit = new Ratelimit({
|
|
128
|
-
* redis: Redis.fromEnv(),
|
|
129
|
-
* limiter: Ratelimit.slidingWindow(10, "10 s")
|
|
130
|
-
* })
|
|
131
|
-
*
|
|
132
|
-
* const { success } = await ratelimit.blockUntilReady(id, 60_000)
|
|
133
|
-
* if (!success){
|
|
134
|
-
* return "Nope"
|
|
135
|
-
* }
|
|
136
|
-
* return "Yes"
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
Object.defineProperty(this, "blockUntilReady", {
|
|
140
|
-
enumerable: true,
|
|
141
|
-
configurable: true,
|
|
142
|
-
writable: true,
|
|
143
|
-
value: async (
|
|
144
|
-
/**
|
|
145
|
-
* An identifier per user or api.
|
|
146
|
-
* Choose a userID, or api token, or ip address.
|
|
147
|
-
*
|
|
148
|
-
* If you want to limit your api across all users, you can set a constant string.
|
|
149
|
-
*/
|
|
150
|
-
identifier,
|
|
151
|
-
/**
|
|
152
|
-
* Maximum duration to wait in milliseconds.
|
|
153
|
-
* After this time the request will be denied.
|
|
154
|
-
*/
|
|
155
|
-
timeout) => {
|
|
156
|
-
if (timeout <= 0) {
|
|
157
|
-
throw new Error("timeout must be positive");
|
|
158
|
-
}
|
|
159
|
-
let res;
|
|
160
|
-
const deadline = Date.now() + timeout;
|
|
161
|
-
while (true) {
|
|
162
|
-
res = await this.limit(identifier);
|
|
163
|
-
if (res.success) {
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
if (res.reset === 0) {
|
|
167
|
-
throw new Error("This should not happen");
|
|
168
|
-
}
|
|
169
|
-
const wait = Math.min(res.reset, deadline) - Date.now();
|
|
170
|
-
await new Promise((r) => setTimeout(r, wait));
|
|
171
|
-
if (Date.now() > deadline) {
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return res;
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
this.ctx = config.ctx;
|
|
179
|
-
this.limiter = config.limiter;
|
|
180
|
-
this.timeout = config.timeout;
|
|
181
|
-
this.prefix = config.prefix ?? "@upstash/ratelimit";
|
|
182
|
-
this.analytics = config.analytics !== false
|
|
183
|
-
? new Analytics({
|
|
184
|
-
redis: Array.isArray(this.ctx.redis)
|
|
185
|
-
? this.ctx.redis[0]
|
|
186
|
-
: this.ctx.redis,
|
|
187
|
-
prefix: this.prefix,
|
|
188
|
-
})
|
|
189
|
-
: undefined;
|
|
190
|
-
if (config.ephemeralCache instanceof Map) {
|
|
191
|
-
this.ctx.cache = new Cache(config.ephemeralCache);
|
|
192
|
-
}
|
|
193
|
-
else if (typeof config.ephemeralCache === "undefined") {
|
|
194
|
-
this.ctx.cache = new Cache(new Map());
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|