@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
package/script/ratelimit.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Ratelimit = exports.TimeoutError = void 0;
|
|
4
|
-
const analytics_js_1 = require("./analytics.js");
|
|
5
|
-
const cache_js_1 = require("./cache.js");
|
|
6
|
-
class TimeoutError extends Error {
|
|
7
|
-
constructor() {
|
|
8
|
-
super("Timeout");
|
|
9
|
-
this.name = "TimeoutError";
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.TimeoutError = TimeoutError;
|
|
13
|
-
/**
|
|
14
|
-
* Ratelimiter using serverless redis from https://upstash.com/
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* const { limit } = new Ratelimit({
|
|
19
|
-
* redis: Redis.fromEnv(),
|
|
20
|
-
* limiter: Ratelimit.slidingWindow(
|
|
21
|
-
* 10, // Allow 10 requests per window of 30 minutes
|
|
22
|
-
* "30 m", // interval of 30 minutes
|
|
23
|
-
* ),
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
class Ratelimit {
|
|
29
|
-
constructor(config) {
|
|
30
|
-
Object.defineProperty(this, "limiter", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, "ctx", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(this, "prefix", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: void 0
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(this, "timeout", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(this, "analytics", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true,
|
|
58
|
-
value: void 0
|
|
59
|
-
});
|
|
60
|
-
/**
|
|
61
|
-
* Determine if a request should pass or be rejected based on the identifier and previously chosen ratelimit.
|
|
62
|
-
*
|
|
63
|
-
* Use this if you want to reject all requests that you can not handle right now.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* const ratelimit = new Ratelimit({
|
|
68
|
-
* redis: Redis.fromEnv(),
|
|
69
|
-
* limiter: Ratelimit.slidingWindow(10, "10 s")
|
|
70
|
-
* })
|
|
71
|
-
*
|
|
72
|
-
* const { success } = await ratelimit.limit(id)
|
|
73
|
-
* if (!success){
|
|
74
|
-
* return "Nope"
|
|
75
|
-
* }
|
|
76
|
-
* return "Yes"
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
Object.defineProperty(this, "limit", {
|
|
80
|
-
enumerable: true,
|
|
81
|
-
configurable: true,
|
|
82
|
-
writable: true,
|
|
83
|
-
value: async (identifier, req) => {
|
|
84
|
-
const key = [this.prefix, identifier].join(":");
|
|
85
|
-
let timeoutId = null;
|
|
86
|
-
try {
|
|
87
|
-
const arr = [this.limiter(this.ctx, key)];
|
|
88
|
-
if (this.timeout) {
|
|
89
|
-
arr.push(new Promise((resolve) => {
|
|
90
|
-
timeoutId = setTimeout(() => {
|
|
91
|
-
resolve({
|
|
92
|
-
success: true,
|
|
93
|
-
limit: 0,
|
|
94
|
-
remaining: 0,
|
|
95
|
-
reset: 0,
|
|
96
|
-
pending: Promise.resolve(),
|
|
97
|
-
});
|
|
98
|
-
}, this.timeout);
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
const res = await Promise.race(arr);
|
|
102
|
-
if (this.analytics) {
|
|
103
|
-
const geo = req ? this.analytics.extractGeo(req) : undefined;
|
|
104
|
-
const analyticsP = this.analytics.record({
|
|
105
|
-
identifier,
|
|
106
|
-
time: Date.now(),
|
|
107
|
-
success: res.success,
|
|
108
|
-
...geo,
|
|
109
|
-
});
|
|
110
|
-
res.pending = Promise.all([res.pending, analyticsP]);
|
|
111
|
-
}
|
|
112
|
-
return res;
|
|
113
|
-
}
|
|
114
|
-
finally {
|
|
115
|
-
if (timeoutId) {
|
|
116
|
-
clearTimeout(timeoutId);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
/**
|
|
122
|
-
* Block until the request may pass or timeout is reached.
|
|
123
|
-
*
|
|
124
|
-
* This method returns a promsie that resolves as soon as the request may be processed
|
|
125
|
-
* or after the timeoue has been reached.
|
|
126
|
-
*
|
|
127
|
-
* Use this if you want to delay the request until it is ready to get processed.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```ts
|
|
131
|
-
* const ratelimit = new Ratelimit({
|
|
132
|
-
* redis: Redis.fromEnv(),
|
|
133
|
-
* limiter: Ratelimit.slidingWindow(10, "10 s")
|
|
134
|
-
* })
|
|
135
|
-
*
|
|
136
|
-
* const { success } = await ratelimit.blockUntilReady(id, 60_000)
|
|
137
|
-
* if (!success){
|
|
138
|
-
* return "Nope"
|
|
139
|
-
* }
|
|
140
|
-
* return "Yes"
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
Object.defineProperty(this, "blockUntilReady", {
|
|
144
|
-
enumerable: true,
|
|
145
|
-
configurable: true,
|
|
146
|
-
writable: true,
|
|
147
|
-
value: async (
|
|
148
|
-
/**
|
|
149
|
-
* An identifier per user or api.
|
|
150
|
-
* Choose a userID, or api token, or ip address.
|
|
151
|
-
*
|
|
152
|
-
* If you want to limit your api across all users, you can set a constant string.
|
|
153
|
-
*/
|
|
154
|
-
identifier,
|
|
155
|
-
/**
|
|
156
|
-
* Maximum duration to wait in milliseconds.
|
|
157
|
-
* After this time the request will be denied.
|
|
158
|
-
*/
|
|
159
|
-
timeout) => {
|
|
160
|
-
if (timeout <= 0) {
|
|
161
|
-
throw new Error("timeout must be positive");
|
|
162
|
-
}
|
|
163
|
-
let res;
|
|
164
|
-
const deadline = Date.now() + timeout;
|
|
165
|
-
while (true) {
|
|
166
|
-
res = await this.limit(identifier);
|
|
167
|
-
if (res.success) {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
if (res.reset === 0) {
|
|
171
|
-
throw new Error("This should not happen");
|
|
172
|
-
}
|
|
173
|
-
const wait = Math.min(res.reset, deadline) - Date.now();
|
|
174
|
-
await new Promise((r) => setTimeout(r, wait));
|
|
175
|
-
if (Date.now() > deadline) {
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return res;
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
this.ctx = config.ctx;
|
|
183
|
-
this.limiter = config.limiter;
|
|
184
|
-
this.timeout = config.timeout;
|
|
185
|
-
this.prefix = config.prefix ?? "@upstash/ratelimit";
|
|
186
|
-
this.analytics = config.analytics !== false
|
|
187
|
-
? new analytics_js_1.Analytics({
|
|
188
|
-
redis: Array.isArray(this.ctx.redis)
|
|
189
|
-
? this.ctx.redis[0]
|
|
190
|
-
: this.ctx.redis,
|
|
191
|
-
prefix: this.prefix,
|
|
192
|
-
})
|
|
193
|
-
: undefined;
|
|
194
|
-
if (config.ephemeralCache instanceof Map) {
|
|
195
|
-
this.ctx.cache = new cache_js_1.Cache(config.ephemeralCache);
|
|
196
|
-
}
|
|
197
|
-
else if (typeof config.ephemeralCache === "undefined") {
|
|
198
|
-
this.ctx.cache = new cache_js_1.Cache(new Map());
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.Ratelimit = Ratelimit;
|
package/script/single.js
DELETED
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegionRatelimit = void 0;
|
|
4
|
-
const duration_js_1 = require("./duration.js");
|
|
5
|
-
const ratelimit_js_1 = require("./ratelimit.js");
|
|
6
|
-
/**
|
|
7
|
-
* Ratelimiter using serverless redis from https://upstash.com/
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* const { limit } = new Ratelimit({
|
|
12
|
-
* redis: Redis.fromEnv(),
|
|
13
|
-
* limiter: Ratelimit.slidingWindow(
|
|
14
|
-
* "30 m", // interval of 30 minutes
|
|
15
|
-
* 10, // Allow 10 requests per window of 30 minutes
|
|
16
|
-
* )
|
|
17
|
-
* })
|
|
18
|
-
*
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
class RegionRatelimit extends ratelimit_js_1.Ratelimit {
|
|
22
|
-
/**
|
|
23
|
-
* Create a new Ratelimit instance by providing a `@upstash/redis` instance and the algorithn of your choice.
|
|
24
|
-
*/
|
|
25
|
-
constructor(config) {
|
|
26
|
-
super({
|
|
27
|
-
prefix: config.prefix,
|
|
28
|
-
limiter: config.limiter,
|
|
29
|
-
timeout: config.timeout,
|
|
30
|
-
analytics: config.analytics,
|
|
31
|
-
ctx: {
|
|
32
|
-
redis: config.redis,
|
|
33
|
-
},
|
|
34
|
-
ephemeralCache: config.ephemeralCache,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Each requests inside a fixed time increases a counter.
|
|
39
|
-
* Once the counter reaches a maxmimum allowed number, all further requests are
|
|
40
|
-
* rejected.
|
|
41
|
-
*
|
|
42
|
-
* **Pro:**
|
|
43
|
-
*
|
|
44
|
-
* - Newer requests are not starved by old ones.
|
|
45
|
-
* - Low storage cost.
|
|
46
|
-
*
|
|
47
|
-
* **Con:**
|
|
48
|
-
*
|
|
49
|
-
* A burst of requests near the boundary of a window can result in a very
|
|
50
|
-
* high request rate because two windows will be filled with requests quickly.
|
|
51
|
-
*
|
|
52
|
-
* @param tokens - How many requests a user can make in each time window.
|
|
53
|
-
* @param window - A fixed timeframe
|
|
54
|
-
*/
|
|
55
|
-
static fixedWindow(
|
|
56
|
-
/**
|
|
57
|
-
* How many requests are allowed per window.
|
|
58
|
-
*/
|
|
59
|
-
tokens,
|
|
60
|
-
/**
|
|
61
|
-
* The duration in which `tokens` requests are allowed.
|
|
62
|
-
*/
|
|
63
|
-
window) {
|
|
64
|
-
const windowDuration = (0, duration_js_1.ms)(window);
|
|
65
|
-
const script = `
|
|
66
|
-
local key = KEYS[1]
|
|
67
|
-
local window = ARGV[1]
|
|
68
|
-
|
|
69
|
-
local r = redis.call("INCR", key)
|
|
70
|
-
if r == 1 then
|
|
71
|
-
-- The first time this key is set, the value will be 1.
|
|
72
|
-
-- So we only need the expire command once
|
|
73
|
-
redis.call("PEXPIRE", key, window)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
return r
|
|
77
|
-
`;
|
|
78
|
-
return async function (ctx, identifier) {
|
|
79
|
-
const bucket = Math.floor(Date.now() / windowDuration);
|
|
80
|
-
const key = [identifier, bucket].join(":");
|
|
81
|
-
if (ctx.cache) {
|
|
82
|
-
const { blocked, reset } = ctx.cache.isBlocked(identifier);
|
|
83
|
-
if (blocked) {
|
|
84
|
-
return {
|
|
85
|
-
success: false,
|
|
86
|
-
limit: tokens,
|
|
87
|
-
remaining: 0,
|
|
88
|
-
reset: reset,
|
|
89
|
-
pending: Promise.resolve(),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const usedTokensAfterUpdate = (await ctx.redis.eval(script, [key], [windowDuration]));
|
|
94
|
-
const success = usedTokensAfterUpdate <= tokens;
|
|
95
|
-
const reset = (bucket + 1) * windowDuration;
|
|
96
|
-
if (ctx.cache && !success) {
|
|
97
|
-
ctx.cache.blockUntil(identifier, reset);
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
success,
|
|
101
|
-
limit: tokens,
|
|
102
|
-
remaining: tokens - usedTokensAfterUpdate,
|
|
103
|
-
reset,
|
|
104
|
-
pending: Promise.resolve(),
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Combined approach of `slidingLogs` and `fixedWindow` with lower storage
|
|
110
|
-
* costs than `slidingLogs` and improved boundary behavior by calcualting a
|
|
111
|
-
* weighted score between two windows.
|
|
112
|
-
*
|
|
113
|
-
* **Pro:**
|
|
114
|
-
*
|
|
115
|
-
* Good performance allows this to scale to very high loads.
|
|
116
|
-
*
|
|
117
|
-
* **Con:**
|
|
118
|
-
*
|
|
119
|
-
* Nothing major.
|
|
120
|
-
*
|
|
121
|
-
* @param tokens - How many requests a user can make in each time window.
|
|
122
|
-
* @param window - The duration in which the user can max X requests.
|
|
123
|
-
*/
|
|
124
|
-
static slidingWindow(
|
|
125
|
-
/**
|
|
126
|
-
* How many requests are allowed per window.
|
|
127
|
-
*/
|
|
128
|
-
tokens,
|
|
129
|
-
/**
|
|
130
|
-
* The duration in which `tokens` requests are allowed.
|
|
131
|
-
*/
|
|
132
|
-
window) {
|
|
133
|
-
const script = `
|
|
134
|
-
local currentKey = KEYS[1] -- identifier including prefixes
|
|
135
|
-
local previousKey = KEYS[2] -- key of the previous bucket
|
|
136
|
-
local tokens = tonumber(ARGV[1]) -- tokens per window
|
|
137
|
-
local now = ARGV[2] -- current timestamp in milliseconds
|
|
138
|
-
local window = ARGV[3] -- interval in milliseconds
|
|
139
|
-
|
|
140
|
-
local requestsInCurrentWindow = redis.call("GET", currentKey)
|
|
141
|
-
if requestsInCurrentWindow == false then
|
|
142
|
-
requestsInCurrentWindow = 0
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
local requestsInPreviousWindow = redis.call("GET", previousKey)
|
|
147
|
-
if requestsInPreviousWindow == false then
|
|
148
|
-
requestsInPreviousWindow = 0
|
|
149
|
-
end
|
|
150
|
-
local percentageInCurrent = ( now % window) / window
|
|
151
|
-
if requestsInPreviousWindow * ( 1 - percentageInCurrent ) + requestsInCurrentWindow >= tokens then
|
|
152
|
-
return 0
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
local newValue = redis.call("INCR", currentKey)
|
|
156
|
-
if newValue == 1 then
|
|
157
|
-
-- The first time this key is set, the value will be 1.
|
|
158
|
-
-- So we only need the expire command once
|
|
159
|
-
redis.call("PEXPIRE", currentKey, window * 2 + 1000) -- Enough time to overlap with a new window + 1 second
|
|
160
|
-
end
|
|
161
|
-
return tokens - newValue
|
|
162
|
-
`;
|
|
163
|
-
const windowSize = (0, duration_js_1.ms)(window);
|
|
164
|
-
return async function (ctx, identifier) {
|
|
165
|
-
const now = Date.now();
|
|
166
|
-
const currentWindow = Math.floor(now / windowSize);
|
|
167
|
-
const currentKey = [identifier, currentWindow].join(":");
|
|
168
|
-
const previousWindow = currentWindow - windowSize;
|
|
169
|
-
const previousKey = [identifier, previousWindow].join(":");
|
|
170
|
-
if (ctx.cache) {
|
|
171
|
-
const { blocked, reset } = ctx.cache.isBlocked(identifier);
|
|
172
|
-
if (blocked) {
|
|
173
|
-
return {
|
|
174
|
-
success: false,
|
|
175
|
-
limit: tokens,
|
|
176
|
-
remaining: 0,
|
|
177
|
-
reset: reset,
|
|
178
|
-
pending: Promise.resolve(),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
const remaining = (await ctx.redis.eval(script, [currentKey, previousKey], [tokens, now, windowSize]));
|
|
183
|
-
const success = remaining > 0;
|
|
184
|
-
const reset = (currentWindow + 1) * windowSize;
|
|
185
|
-
if (ctx.cache && !success) {
|
|
186
|
-
ctx.cache.blockUntil(identifier, reset);
|
|
187
|
-
}
|
|
188
|
-
return {
|
|
189
|
-
success,
|
|
190
|
-
limit: tokens,
|
|
191
|
-
remaining,
|
|
192
|
-
reset,
|
|
193
|
-
pending: Promise.resolve(),
|
|
194
|
-
};
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* You have a bucket filled with `{maxTokens}` tokens that refills constantly
|
|
199
|
-
* at `{refillRate}` per `{interval}`.
|
|
200
|
-
* Every request will remove one token from the bucket and if there is no
|
|
201
|
-
* token to take, the request is rejected.
|
|
202
|
-
*
|
|
203
|
-
* **Pro:**
|
|
204
|
-
*
|
|
205
|
-
* - Bursts of requests are smoothed out and you can process them at a constant
|
|
206
|
-
* rate.
|
|
207
|
-
* - Allows to set a higher initial burst limit by setting `maxTokens` higher
|
|
208
|
-
* than `refillRate`
|
|
209
|
-
*/
|
|
210
|
-
static tokenBucket(
|
|
211
|
-
/**
|
|
212
|
-
* How many tokens are refilled per `interval`
|
|
213
|
-
*
|
|
214
|
-
* An interval of `10s` and refillRate of 5 will cause a new token to be added every 2 seconds.
|
|
215
|
-
*/
|
|
216
|
-
refillRate,
|
|
217
|
-
/**
|
|
218
|
-
* The interval for the `refillRate`
|
|
219
|
-
*/
|
|
220
|
-
interval,
|
|
221
|
-
/**
|
|
222
|
-
* Maximum number of tokens.
|
|
223
|
-
* A newly created bucket starts with this many tokens.
|
|
224
|
-
* Useful to allow higher burst limits.
|
|
225
|
-
*/
|
|
226
|
-
maxTokens) {
|
|
227
|
-
const script = `
|
|
228
|
-
local key = KEYS[1] -- identifier including prefixes
|
|
229
|
-
local maxTokens = tonumber(ARGV[1]) -- maximum number of tokens
|
|
230
|
-
local interval = tonumber(ARGV[2]) -- size of the window in milliseconds
|
|
231
|
-
local refillRate = tonumber(ARGV[3]) -- how many tokens are refilled after each interval
|
|
232
|
-
local now = tonumber(ARGV[4]) -- current timestamp in milliseconds
|
|
233
|
-
local remaining = 0
|
|
234
|
-
|
|
235
|
-
local bucket = redis.call("HMGET", key, "updatedAt", "tokens")
|
|
236
|
-
|
|
237
|
-
if bucket[1] == false then
|
|
238
|
-
-- The bucket does not exist yet, so we create it and add a ttl.
|
|
239
|
-
remaining = maxTokens - 1
|
|
240
|
-
|
|
241
|
-
redis.call("HMSET", key, "updatedAt", now, "tokens", remaining)
|
|
242
|
-
redis.call("PEXPIRE", key, interval)
|
|
243
|
-
|
|
244
|
-
return {remaining, now + interval}
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
-- The bucket does exist
|
|
248
|
-
|
|
249
|
-
local updatedAt = tonumber(bucket[1])
|
|
250
|
-
local tokens = tonumber(bucket[2])
|
|
251
|
-
|
|
252
|
-
if now >= updatedAt + interval then
|
|
253
|
-
remaining = math.min(maxTokens, tokens + refillRate) - 1
|
|
254
|
-
|
|
255
|
-
redis.call("HMSET", key, "updatedAt", now, "tokens", remaining)
|
|
256
|
-
return {remaining, now + interval}
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
if tokens > 0 then
|
|
260
|
-
remaining = tokens - 1
|
|
261
|
-
redis.call("HMSET", key, "updatedAt", now, "tokens", remaining)
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
return {remaining, updatedAt + interval}
|
|
265
|
-
`;
|
|
266
|
-
const intervalDuration = (0, duration_js_1.ms)(interval);
|
|
267
|
-
return async function (ctx, identifier) {
|
|
268
|
-
if (ctx.cache) {
|
|
269
|
-
const { blocked, reset } = ctx.cache.isBlocked(identifier);
|
|
270
|
-
if (blocked) {
|
|
271
|
-
return {
|
|
272
|
-
success: false,
|
|
273
|
-
limit: maxTokens,
|
|
274
|
-
remaining: 0,
|
|
275
|
-
reset: reset,
|
|
276
|
-
pending: Promise.resolve(),
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const now = Date.now();
|
|
281
|
-
const key = [identifier, Math.floor(now / intervalDuration)].join(":");
|
|
282
|
-
const [remaining, reset] = (await ctx.redis.eval(script, [key], [maxTokens, intervalDuration, refillRate, now]));
|
|
283
|
-
const success = remaining > 0;
|
|
284
|
-
if (ctx.cache && !success) {
|
|
285
|
-
ctx.cache.blockUntil(identifier, reset);
|
|
286
|
-
}
|
|
287
|
-
return {
|
|
288
|
-
success,
|
|
289
|
-
limit: maxTokens,
|
|
290
|
-
remaining,
|
|
291
|
-
reset,
|
|
292
|
-
pending: Promise.resolve(),
|
|
293
|
-
};
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* cachedFixedWindow first uses the local cache to decide if a request may pass and then updates
|
|
298
|
-
* it asynchronously.
|
|
299
|
-
* This is experimental and not yet recommended for production use.
|
|
300
|
-
*
|
|
301
|
-
* @experimental
|
|
302
|
-
*
|
|
303
|
-
* Each requests inside a fixed time increases a counter.
|
|
304
|
-
* Once the counter reaches a maxmimum allowed number, all further requests are
|
|
305
|
-
* rejected.
|
|
306
|
-
*
|
|
307
|
-
* **Pro:**
|
|
308
|
-
*
|
|
309
|
-
* - Newer requests are not starved by old ones.
|
|
310
|
-
* - Low storage cost.
|
|
311
|
-
*
|
|
312
|
-
* **Con:**
|
|
313
|
-
*
|
|
314
|
-
* A burst of requests near the boundary of a window can result in a very
|
|
315
|
-
* high request rate because two windows will be filled with requests quickly.
|
|
316
|
-
*
|
|
317
|
-
* @param tokens - How many requests a user can make in each time window.
|
|
318
|
-
* @param window - A fixed timeframe
|
|
319
|
-
*/
|
|
320
|
-
static cachedFixedWindow(
|
|
321
|
-
/**
|
|
322
|
-
* How many requests are allowed per window.
|
|
323
|
-
*/
|
|
324
|
-
tokens,
|
|
325
|
-
/**
|
|
326
|
-
* The duration in which `tokens` requests are allowed.
|
|
327
|
-
*/
|
|
328
|
-
window) {
|
|
329
|
-
const windowDuration = (0, duration_js_1.ms)(window);
|
|
330
|
-
const script = `
|
|
331
|
-
local key = KEYS[1]
|
|
332
|
-
local window = ARGV[1]
|
|
333
|
-
|
|
334
|
-
local r = redis.call("INCR", key)
|
|
335
|
-
if r == 1 then
|
|
336
|
-
-- The first time this key is set, the value will be 1.
|
|
337
|
-
-- So we only need the expire command once
|
|
338
|
-
redis.call("PEXPIRE", key, window)
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
return r
|
|
342
|
-
`;
|
|
343
|
-
return async function (ctx, identifier) {
|
|
344
|
-
if (!ctx.cache) {
|
|
345
|
-
throw new Error("This algorithm requires a cache");
|
|
346
|
-
}
|
|
347
|
-
const bucket = Math.floor(Date.now() / windowDuration);
|
|
348
|
-
const key = [identifier, bucket].join(":");
|
|
349
|
-
const reset = (bucket + 1) * windowDuration;
|
|
350
|
-
const hit = typeof ctx.cache.get(key) === "number";
|
|
351
|
-
if (hit) {
|
|
352
|
-
const cachedTokensAfterUpdate = ctx.cache.incr(key);
|
|
353
|
-
const success = cachedTokensAfterUpdate < tokens;
|
|
354
|
-
const pending = success
|
|
355
|
-
? ctx.redis.eval(script, [key], [windowDuration]).then((t) => {
|
|
356
|
-
ctx.cache.set(key, t);
|
|
357
|
-
})
|
|
358
|
-
: Promise.resolve();
|
|
359
|
-
return {
|
|
360
|
-
success,
|
|
361
|
-
limit: tokens,
|
|
362
|
-
remaining: tokens - cachedTokensAfterUpdate,
|
|
363
|
-
reset: reset,
|
|
364
|
-
pending,
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const usedTokensAfterUpdate = (await ctx.redis.eval(script, [key], [windowDuration]));
|
|
368
|
-
ctx.cache.set(key, usedTokensAfterUpdate);
|
|
369
|
-
const remaining = tokens - usedTokensAfterUpdate;
|
|
370
|
-
return {
|
|
371
|
-
success: remaining >= 0,
|
|
372
|
-
limit: tokens,
|
|
373
|
-
remaining,
|
|
374
|
-
reset: reset,
|
|
375
|
-
pending: Promise.resolve(),
|
|
376
|
-
};
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
exports.RegionRatelimit = RegionRatelimit;
|
package/script/types.js
DELETED
package/types/_dnt.shims.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { crypto, type Crypto, type SubtleCrypto, type AlgorithmIdentifier, type Algorithm, type RsaOaepParams, type BufferSource, type AesCtrParams, type AesCbcParams, type AesGcmParams, type CryptoKey, type KeyAlgorithm, type KeyType, type KeyUsage, type EcdhKeyDeriveParams, type HkdfParams, type HashAlgorithmIdentifier, type Pbkdf2Params, type AesDerivedKeyParams, type HmacImportParams, type JsonWebKey, type RsaOtherPrimesInfo, type KeyFormat, type RsaHashedKeyGenParams, type RsaKeyGenParams, type BigInteger, type EcKeyGenParams, type NamedCurve, type CryptoKeyPair, type AesKeyGenParams, type HmacKeyGenParams, type RsaHashedImportParams, type EcKeyImportParams, type AesKeyAlgorithm, type RsaPssParams, type EcdsaParams } from "@deno/shim-crypto";
|
|
2
|
-
export {} from "@types/node";
|
|
3
|
-
export declare const dntGlobalThis: Omit<typeof globalThis, "crypto"> & {
|
|
4
|
-
crypto: import("@deno/shim-crypto").Crypto;
|
|
5
|
-
};
|
package/types/analytics.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Redis } from "./deps/deno.land/x/upstash_redis@v1.19.3/mod.js";
|
|
2
|
-
export type Geo = {
|
|
3
|
-
country?: string;
|
|
4
|
-
city?: string;
|
|
5
|
-
region?: string;
|
|
6
|
-
ip?: string;
|
|
7
|
-
};
|
|
8
|
-
export type Event = Geo & {
|
|
9
|
-
identifier: string;
|
|
10
|
-
time: number;
|
|
11
|
-
success: boolean;
|
|
12
|
-
};
|
|
13
|
-
export type AnalyticsConfig = {
|
|
14
|
-
redis: Redis;
|
|
15
|
-
prefix?: string;
|
|
16
|
-
};
|
|
17
|
-
export declare class Analytics {
|
|
18
|
-
private readonly redis;
|
|
19
|
-
private readonly prefix;
|
|
20
|
-
constructor(config: AnalyticsConfig);
|
|
21
|
-
extractGeo(req: {
|
|
22
|
-
geo?: Geo;
|
|
23
|
-
}): Geo;
|
|
24
|
-
record(event: Event): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Aggregates the events by the given field and returns the number of successes and failures per value
|
|
27
|
-
*
|
|
28
|
-
* @param aggregateBy - The field to aggregate by
|
|
29
|
-
* @param cutoff - Timestamp in milliseconds to limit the aggregation to `cutoff` until now
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
aggregate<TAggregateBy extends keyof Omit<Event, "time">>(aggregateBy: TAggregateBy, cutoff?: number): Promise<Record<string, {
|
|
33
|
-
success: number;
|
|
34
|
-
blocked: number;
|
|
35
|
-
}>[]>;
|
|
36
|
-
}
|
package/types/cache.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EphemeralCache } from "./types.js";
|
|
2
|
-
export declare class Cache implements EphemeralCache {
|
|
3
|
-
/**
|
|
4
|
-
* Stores identifier -> reset (in milliseconds)
|
|
5
|
-
*/
|
|
6
|
-
private readonly cache;
|
|
7
|
-
constructor(cache: Map<string, number>);
|
|
8
|
-
isBlocked(identifier: string): {
|
|
9
|
-
blocked: boolean;
|
|
10
|
-
reset: number;
|
|
11
|
-
};
|
|
12
|
-
blockUntil(identifier: string, reset: number): void;
|
|
13
|
-
set(key: string, value: number): void;
|
|
14
|
-
get(key: string): number | null;
|
|
15
|
-
incr(key: string): number;
|
|
16
|
-
}
|
|
@@ -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 "../../../denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/** Byte length of a SHA1 digest. */
|
|
2
|
-
export declare const BYTES: number;
|
|
3
|
-
/** A class representation of the SHA1 algorithm. */
|
|
4
|
-
export declare class SHA1 {
|
|
5
|
-
readonly hashSize: number;
|
|
6
|
-
private _buf;
|
|
7
|
-
private _bufIdx;
|
|
8
|
-
private _count;
|
|
9
|
-
private _K;
|
|
10
|
-
private _H;
|
|
11
|
-
private _finalized;
|
|
12
|
-
/** Creates a SHA1 instance. */
|
|
13
|
-
constructor();
|
|
14
|
-
/** Reduces the four input numbers to a single one. */
|
|
15
|
-
protected static F(t: number, b: number, c: number, d: number): number;
|
|
16
|
-
/** Initializes a hash instance. */
|
|
17
|
-
init(): SHA1;
|
|
18
|
-
/** Updates a hash with additional message data. */
|
|
19
|
-
update(msg: string | Uint8Array, inputEncoding?: string): SHA1;
|
|
20
|
-
/** Finalizes a hash with additional message data. */
|
|
21
|
-
digest(outputEncoding?: string): string | Uint8Array;
|
|
22
|
-
/** Performs one transformation cycle. */
|
|
23
|
-
private transform;
|
|
24
|
-
}
|
|
25
|
-
/** Generates a SHA1 hash of the input data. */
|
|
26
|
-
export declare function sha1(msg: string | Uint8Array, inputEncoding?: string, outputEncoding?: string): string | Uint8Array;
|