@upstash/redis 1.40.0 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/{chunk-RLVWMRRX.mjs → chunk-CGMWROAN.mjs} +557 -4
- package/cloudflare.d.mts +2 -2
- package/cloudflare.d.ts +2 -2
- package/cloudflare.js +557 -4
- package/cloudflare.mjs +1 -1
- package/docs/advanced.mdx +83 -0
- package/docs/commands/array/arcount.mdx +28 -0
- package/docs/commands/array/ardel.mdx +30 -0
- package/docs/commands/array/ardelrange.mdx +32 -0
- package/docs/commands/array/arget.mdx +33 -0
- package/docs/commands/array/argetrange.mdx +38 -0
- package/docs/commands/array/argrep.mdx +69 -0
- package/docs/commands/array/arinfo.mdx +49 -0
- package/docs/commands/array/arinsert.mdx +32 -0
- package/docs/commands/array/arlastitems.mdx +40 -0
- package/docs/commands/array/arlen.mdx +28 -0
- package/docs/commands/array/armget.mdx +31 -0
- package/docs/commands/array/armset.mdx +31 -0
- package/docs/commands/array/arnext.mdx +25 -0
- package/docs/commands/array/arop.mdx +44 -0
- package/docs/commands/array/arring.mdx +36 -0
- package/docs/commands/array/arscan.mdx +42 -0
- package/docs/commands/array/arseek.mdx +34 -0
- package/docs/commands/array/arset.mdx +35 -0
- package/docs/commands/auth/echo.mdx +24 -0
- package/docs/commands/auth/ping.mdx +21 -0
- package/docs/commands/bitmap/bitcount.mdx +39 -0
- package/docs/commands/bitmap/bitop.mdx +142 -0
- package/docs/commands/bitmap/bitpos.mdx +39 -0
- package/docs/commands/bitmap/getbit.mdx +28 -0
- package/docs/commands/bitmap/setbit.mdx +31 -0
- package/docs/commands/connection/client_setinfo.mdx +91 -0
- package/docs/commands/functions/call.mdx +72 -0
- package/docs/commands/functions/call_ro.mdx +57 -0
- package/docs/commands/functions/delete.mdx +22 -0
- package/docs/commands/functions/flush.mdx +16 -0
- package/docs/commands/functions/list.mdx +72 -0
- package/docs/commands/functions/load.mdx +64 -0
- package/docs/commands/functions/stats.mdx +46 -0
- package/docs/commands/generic/del.mdx +29 -0
- package/docs/commands/generic/exists.mdx +26 -0
- package/docs/commands/generic/expire.mdx +29 -0
- package/docs/commands/generic/expireat.mdx +29 -0
- package/docs/commands/generic/keys.mdx +32 -0
- package/docs/commands/generic/persist.mdx +23 -0
- package/docs/commands/generic/pexpire.mdx +28 -0
- package/docs/commands/generic/pexpireat.mdx +29 -0
- package/docs/commands/generic/pttl.mdx +23 -0
- package/docs/commands/generic/randomkey.mdx +21 -0
- package/docs/commands/generic/rename.mdx +28 -0
- package/docs/commands/generic/renamenx.mdx +28 -0
- package/docs/commands/generic/scan.mdx +38 -0
- package/docs/commands/generic/touch.mdx +23 -0
- package/docs/commands/generic/ttl.mdx +23 -0
- package/docs/commands/generic/type.mdx +27 -0
- package/docs/commands/generic/unlink.mdx +29 -0
- package/docs/commands/hash/hdel.mdx +28 -0
- package/docs/commands/hash/hexists.mdx +30 -0
- package/docs/commands/hash/hexpire.mdx +49 -0
- package/docs/commands/hash/hexpireat.mdx +48 -0
- package/docs/commands/hash/hexpiretime.mdx +35 -0
- package/docs/commands/hash/hget.mdx +29 -0
- package/docs/commands/hash/hgetall.mdx +27 -0
- package/docs/commands/hash/hgetdel.mdx +67 -0
- package/docs/commands/hash/hgetex.mdx +123 -0
- package/docs/commands/hash/hincrby.mdx +34 -0
- package/docs/commands/hash/hincrbyfloat.mdx +34 -0
- package/docs/commands/hash/hkeys.mdx +28 -0
- package/docs/commands/hash/hlen.mdx +28 -0
- package/docs/commands/hash/hmget.mdx +33 -0
- package/docs/commands/hash/hpersist.mdx +37 -0
- package/docs/commands/hash/hpexpire.mdx +50 -0
- package/docs/commands/hash/hpexpireat.mdx +48 -0
- package/docs/commands/hash/hpexpiretime.mdx +35 -0
- package/docs/commands/hash/hpttl.mdx +35 -0
- package/docs/commands/hash/hrandfield.mdx +57 -0
- package/docs/commands/hash/hscan.mdx +65 -0
- package/docs/commands/hash/hset.mdx +32 -0
- package/docs/commands/hash/hsetex.mdx +186 -0
- package/docs/commands/hash/hsetnx.mdx +30 -0
- package/docs/commands/hash/hstrlen.mdx +28 -0
- package/docs/commands/hash/httl.mdx +35 -0
- package/docs/commands/hash/hvals.mdx +29 -0
- package/docs/commands/json/arrappend.mdx +35 -0
- package/docs/commands/json/arrindex.mdx +37 -0
- package/docs/commands/json/arrinsert.mdx +34 -0
- package/docs/commands/json/arrlen.mdx +26 -0
- package/docs/commands/json/arrpop.mdx +36 -0
- package/docs/commands/json/arrtrim.mdx +34 -0
- package/docs/commands/json/clear.mdx +30 -0
- package/docs/commands/json/del.mdx +26 -0
- package/docs/commands/json/forget.mdx +26 -0
- package/docs/commands/json/get.mdx +53 -0
- package/docs/commands/json/merge.mdx +32 -0
- package/docs/commands/json/mget.mdx +27 -0
- package/docs/commands/json/mset.mdx +26 -0
- package/docs/commands/json/numincrby.mdx +33 -0
- package/docs/commands/json/nummultby.mdx +33 -0
- package/docs/commands/json/objkeys.mdx +27 -0
- package/docs/commands/json/objlen.mdx +27 -0
- package/docs/commands/json/set.mdx +42 -0
- package/docs/commands/json/strappend.mdx +32 -0
- package/docs/commands/json/strlen.mdx +26 -0
- package/docs/commands/json/toggle.mdx +28 -0
- package/docs/commands/json/type.mdx +28 -0
- package/docs/commands/list/lindex.mdx +32 -0
- package/docs/commands/list/linsert.mdx +41 -0
- package/docs/commands/list/llen.mdx +26 -0
- package/docs/commands/list/lmove.mdx +34 -0
- package/docs/commands/list/lpop.mdx +37 -0
- package/docs/commands/list/lpos.mdx +56 -0
- package/docs/commands/list/lpush.mdx +32 -0
- package/docs/commands/list/lpushx.mdx +38 -0
- package/docs/commands/list/lrange.mdx +37 -0
- package/docs/commands/list/lrem.mdx +33 -0
- package/docs/commands/list/lset.mdx +34 -0
- package/docs/commands/list/ltrim.mdx +33 -0
- package/docs/commands/list/rpop.mdx +37 -0
- package/docs/commands/list/rpush.mdx +32 -0
- package/docs/commands/list/rpushx.mdx +38 -0
- package/docs/commands/overview.mdx +692 -0
- package/docs/commands/pubsub/psubscribe.mdx +36 -0
- package/docs/commands/pubsub/publish.mdx +27 -0
- package/docs/commands/pubsub/subscribe.mdx +28 -0
- package/docs/commands/scripts/eval.mdx +36 -0
- package/docs/commands/scripts/eval_ro.mdx +36 -0
- package/docs/commands/scripts/evalsha.mdx +36 -0
- package/docs/commands/scripts/evalsha_ro.mdx +36 -0
- package/docs/commands/scripts/script_exists.mdx +26 -0
- package/docs/commands/scripts/script_flush.mdx +28 -0
- package/docs/commands/scripts/script_load.mdx +28 -0
- package/docs/commands/server/dbsize.mdx +22 -0
- package/docs/commands/server/flushall.mdx +25 -0
- package/docs/commands/server/flushdb.mdx +25 -0
- package/docs/commands/set/sadd.mdx +32 -0
- package/docs/commands/set/scard.mdx +26 -0
- package/docs/commands/set/sdiff.mdx +27 -0
- package/docs/commands/set/sdiffstore.mdx +32 -0
- package/docs/commands/set/sinter.mdx +27 -0
- package/docs/commands/set/sinterstore.mdx +33 -0
- package/docs/commands/set/sismember.mdx +30 -0
- package/docs/commands/set/smembers.mdx +25 -0
- package/docs/commands/set/smismember.mdx +31 -0
- package/docs/commands/set/smove.mdx +34 -0
- package/docs/commands/set/spop.mdx +36 -0
- package/docs/commands/set/srandmember.mdx +36 -0
- package/docs/commands/set/srem.mdx +29 -0
- package/docs/commands/set/sscan.mdx +39 -0
- package/docs/commands/set/sunion.mdx +27 -0
- package/docs/commands/set/sunionstore.mdx +33 -0
- package/docs/commands/stream/xack.mdx +37 -0
- package/docs/commands/stream/xackdel.mdx +211 -0
- package/docs/commands/stream/xadd.mdx +137 -0
- package/docs/commands/stream/xautoclaim.mdx +80 -0
- package/docs/commands/stream/xclaim.mdx +84 -0
- package/docs/commands/stream/xdel.mdx +34 -0
- package/docs/commands/stream/xdelex.mdx +119 -0
- package/docs/commands/stream/xgroup.mdx +141 -0
- package/docs/commands/stream/xinfo.mdx +77 -0
- package/docs/commands/stream/xlen.mdx +22 -0
- package/docs/commands/stream/xpending.mdx +75 -0
- package/docs/commands/stream/xrange.mdx +59 -0
- package/docs/commands/stream/xread.mdx +65 -0
- package/docs/commands/stream/xreadgroup.mdx +87 -0
- package/docs/commands/stream/xrevrange.mdx +65 -0
- package/docs/commands/stream/xtrim.mdx +75 -0
- package/docs/commands/string/append.mdx +28 -0
- package/docs/commands/string/decr.mdx +27 -0
- package/docs/commands/string/decrby.mdx +30 -0
- package/docs/commands/string/get.mdx +34 -0
- package/docs/commands/string/getdel.mdx +29 -0
- package/docs/commands/string/getrange.mdx +34 -0
- package/docs/commands/string/getset.mdx +28 -0
- package/docs/commands/string/incr.mdx +27 -0
- package/docs/commands/string/incrby.mdx +30 -0
- package/docs/commands/string/incrbyfloat.mdx +30 -0
- package/docs/commands/string/mget.mdx +31 -0
- package/docs/commands/string/mset.mdx +32 -0
- package/docs/commands/string/msetnx.mdx +29 -0
- package/docs/commands/string/set.mdx +79 -0
- package/docs/commands/string/setrange.mdx +38 -0
- package/docs/commands/string/strlen.mdx +26 -0
- package/docs/commands/transaction.mdx +22 -0
- package/docs/commands/zset/zadd.mdx +102 -0
- package/docs/commands/zset/zcard.mdx +31 -0
- package/docs/commands/zset/zcount.mdx +47 -0
- package/docs/commands/zset/zdiffstore.mdx +33 -0
- package/docs/commands/zset/zincrby.mdx +37 -0
- package/docs/commands/zset/zinterstore.mdx +98 -0
- package/docs/commands/zset/zlexcount.mdx +43 -0
- package/docs/commands/zset/zmscore.mdx +34 -0
- package/docs/commands/zset/zpopmax.mdx +25 -0
- package/docs/commands/zset/zpopmin.mdx +25 -0
- package/docs/commands/zset/zrange.mdx +85 -0
- package/docs/commands/zset/zrank.mdx +29 -0
- package/docs/commands/zset/zrem.mdx +33 -0
- package/docs/commands/zset/zremrangebylex.mdx +32 -0
- package/docs/commands/zset/zremrangebyrank.mdx +32 -0
- package/docs/commands/zset/zremrangebyscore.mdx +32 -0
- package/docs/commands/zset/zrevrank.mdx +29 -0
- package/docs/commands/zset/zscan.mdx +58 -0
- package/docs/commands/zset/zscore.mdx +34 -0
- package/docs/commands/zset/zunionstore.mdx +98 -0
- package/docs/deployment.mdx +117 -0
- package/docs/developing.mdx +118 -0
- package/docs/getstarted.mdx +68 -0
- package/docs/overview.mdx +29 -0
- package/docs/pipelining/auto-pipeline.mdx +108 -0
- package/docs/pipelining/pipeline-transaction.mdx +65 -0
- package/docs/retries.mdx +24 -0
- package/docs/troubleshooting.mdx +80 -0
- package/{error-BNzLTXJG.d.mts → error-4e36-PC0.d.mts} +838 -8
- package/{error-BNzLTXJG.d.ts → error-4e36-PC0.d.ts} +838 -8
- package/fastly.d.mts +2 -2
- package/fastly.d.ts +2 -2
- package/fastly.js +557 -4
- package/fastly.mjs +1 -1
- package/nodejs.d.mts +34 -2
- package/nodejs.d.ts +34 -2
- package/nodejs.js +586 -4
- package/nodejs.mjs +30 -1
- package/package.json +16 -5
- package/src/pkg/auto-pipeline.ts +284 -0
- package/src/pkg/commands/append.ts +12 -0
- package/src/pkg/commands/arcount.ts +14 -0
- package/src/pkg/commands/ardel.ts +19 -0
- package/src/pkg/commands/ardelrange.ts +19 -0
- package/src/pkg/commands/arget.ts +17 -0
- package/src/pkg/commands/argetrange.ts +20 -0
- package/src/pkg/commands/argrep.ts +109 -0
- package/src/pkg/commands/arinfo.ts +88 -0
- package/src/pkg/commands/arinsert.ts +24 -0
- package/src/pkg/commands/arlastitems.ts +29 -0
- package/src/pkg/commands/arlen.ts +23 -0
- package/src/pkg/commands/armget.ts +18 -0
- package/src/pkg/commands/armset.ts +26 -0
- package/src/pkg/commands/arnext.ts +20 -0
- package/src/pkg/commands/arop.ts +48 -0
- package/src/pkg/commands/arring.ts +23 -0
- package/src/pkg/commands/arscan.ts +44 -0
- package/src/pkg/commands/arseek.ts +17 -0
- package/src/pkg/commands/arset.ts +20 -0
- package/src/pkg/commands/bitcount.ts +30 -0
- package/src/pkg/commands/bitfield.ts +50 -0
- package/src/pkg/commands/bitop.ts +35 -0
- package/src/pkg/commands/bitpos.ts +15 -0
- package/src/pkg/commands/client_setinfo.ts +17 -0
- package/src/pkg/commands/command.ts +142 -0
- package/src/pkg/commands/copy.ts +22 -0
- package/src/pkg/commands/dbsize.ts +12 -0
- package/src/pkg/commands/decr.ts +12 -0
- package/src/pkg/commands/decrby.ts +12 -0
- package/src/pkg/commands/del.ts +12 -0
- package/src/pkg/commands/echo.ts +12 -0
- package/src/pkg/commands/eval.ts +18 -0
- package/src/pkg/commands/evalRo.ts +18 -0
- package/src/pkg/commands/evalsha.ts +18 -0
- package/src/pkg/commands/evalshaRo.ts +18 -0
- package/src/pkg/commands/exec.ts +23 -0
- package/src/pkg/commands/exists.ts +12 -0
- package/src/pkg/commands/expire.ts +13 -0
- package/src/pkg/commands/expireat.ts +16 -0
- package/src/pkg/commands/fcall.ts +15 -0
- package/src/pkg/commands/fcall_ro.ts +18 -0
- package/src/pkg/commands/flushall.ts +15 -0
- package/src/pkg/commands/flushdb.ts +15 -0
- package/src/pkg/commands/function_delete.ts +12 -0
- package/src/pkg/commands/function_flush.ts +12 -0
- package/src/pkg/commands/function_list.ts +77 -0
- package/src/pkg/commands/function_load.ts +31 -0
- package/src/pkg/commands/function_stats.ts +42 -0
- package/src/pkg/commands/geo_add.ts +54 -0
- package/src/pkg/commands/geo_dist.ts +19 -0
- package/src/pkg/commands/geo_hash.ts +23 -0
- package/src/pkg/commands/geo_pos.ts +39 -0
- package/src/pkg/commands/geo_search.ts +140 -0
- package/src/pkg/commands/geo_search_store.ts +69 -0
- package/src/pkg/commands/get.ts +15 -0
- package/src/pkg/commands/getbit.ts +12 -0
- package/src/pkg/commands/getdel.ts +15 -0
- package/src/pkg/commands/getex.ts +36 -0
- package/src/pkg/commands/getrange.ts +15 -0
- package/src/pkg/commands/getset.ts +15 -0
- package/src/pkg/commands/hdel.ts +12 -0
- package/src/pkg/commands/hexists.ts +12 -0
- package/src/pkg/commands/hexpire.ts +30 -0
- package/src/pkg/commands/hexpireat.ts +30 -0
- package/src/pkg/commands/hexpiretime.ts +13 -0
- package/src/pkg/commands/hget.ts +18 -0
- package/src/pkg/commands/hgetall.ts +44 -0
- package/src/pkg/commands/hgetdel.ts +30 -0
- package/src/pkg/commands/hgetex.ts +56 -0
- package/src/pkg/commands/hincrby.ts +15 -0
- package/src/pkg/commands/hincrbyfloat.ts +15 -0
- package/src/pkg/commands/hkeys.ts +12 -0
- package/src/pkg/commands/hlen.ts +12 -0
- package/src/pkg/commands/hmget.ts +53 -0
- package/src/pkg/commands/hmset.ts +14 -0
- package/src/pkg/commands/hpersist.ts +13 -0
- package/src/pkg/commands/hpexpire.ts +30 -0
- package/src/pkg/commands/hpexpireat.ts +30 -0
- package/src/pkg/commands/hpexpiretime.ts +13 -0
- package/src/pkg/commands/hpttl.ts +13 -0
- package/src/pkg/commands/hrandfield.ts +52 -0
- package/src/pkg/commands/hscan.ts +31 -0
- package/src/pkg/commands/hset.ts +15 -0
- package/src/pkg/commands/hsetex.ts +59 -0
- package/src/pkg/commands/hsetnx.ts +15 -0
- package/src/pkg/commands/hstrlen.ts +12 -0
- package/src/pkg/commands/httl.ts +13 -0
- package/src/pkg/commands/hvals.ts +12 -0
- package/src/pkg/commands/incr.ts +12 -0
- package/src/pkg/commands/incrby.ts +12 -0
- package/src/pkg/commands/incrbyfloat.ts +12 -0
- package/src/pkg/commands/json_arrappend.ts +18 -0
- package/src/pkg/commands/json_arrindex.ts +15 -0
- package/src/pkg/commands/json_arrinsert.ts +18 -0
- package/src/pkg/commands/json_arrlen.ts +15 -0
- package/src/pkg/commands/json_arrpop.ts +15 -0
- package/src/pkg/commands/json_arrtrim.ts +19 -0
- package/src/pkg/commands/json_clear.ts +12 -0
- package/src/pkg/commands/json_del.ts +12 -0
- package/src/pkg/commands/json_forget.ts +12 -0
- package/src/pkg/commands/json_get.ts +45 -0
- package/src/pkg/commands/json_merge.ts +18 -0
- package/src/pkg/commands/json_mget.ts +12 -0
- package/src/pkg/commands/json_mset.ts +27 -0
- package/src/pkg/commands/json_numincrby.ts +15 -0
- package/src/pkg/commands/json_nummultby.ts +15 -0
- package/src/pkg/commands/json_objkeys.ts +15 -0
- package/src/pkg/commands/json_objlen.ts +15 -0
- package/src/pkg/commands/json_resp.ts +11 -0
- package/src/pkg/commands/json_set.ts +35 -0
- package/src/pkg/commands/json_strappend.ts +15 -0
- package/src/pkg/commands/json_strlen.ts +15 -0
- package/src/pkg/commands/json_toggle.ts +12 -0
- package/src/pkg/commands/json_type.ts +12 -0
- package/src/pkg/commands/keys.ts +12 -0
- package/src/pkg/commands/lindex.ts +11 -0
- package/src/pkg/commands/linsert.ts +10 -0
- package/src/pkg/commands/llen.ts +12 -0
- package/src/pkg/commands/lmove.ts +20 -0
- package/src/pkg/commands/lmpop.ts +19 -0
- package/src/pkg/commands/lpop.ts +18 -0
- package/src/pkg/commands/lpos.ts +26 -0
- package/src/pkg/commands/lpush.ts +12 -0
- package/src/pkg/commands/lpushx.ts +12 -0
- package/src/pkg/commands/lrange.ts +11 -0
- package/src/pkg/commands/lrem.ts +10 -0
- package/src/pkg/commands/lset.ts +8 -0
- package/src/pkg/commands/ltrim.ts +8 -0
- package/src/pkg/commands/mget.ts +15 -0
- package/src/pkg/commands/mod.ts +222 -0
- package/src/pkg/commands/mset.ts +12 -0
- package/src/pkg/commands/msetnx.ts +12 -0
- package/src/pkg/commands/persist.ts +12 -0
- package/src/pkg/commands/pexpire.ts +16 -0
- package/src/pkg/commands/pexpireat.ts +16 -0
- package/src/pkg/commands/pfadd.ts +11 -0
- package/src/pkg/commands/pfcount.ts +11 -0
- package/src/pkg/commands/pfmerge.ts +11 -0
- package/src/pkg/commands/ping.ts +15 -0
- package/src/pkg/commands/psetex.ts +14 -0
- package/src/pkg/commands/psubscribe.ts +26 -0
- package/src/pkg/commands/pttl.ts +12 -0
- package/src/pkg/commands/publish.ts +12 -0
- package/src/pkg/commands/randomkey.ts +12 -0
- package/src/pkg/commands/rename.ts +12 -0
- package/src/pkg/commands/renamenx.ts +12 -0
- package/src/pkg/commands/rpop.ts +21 -0
- package/src/pkg/commands/rpush.ts +12 -0
- package/src/pkg/commands/rpushx.ts +12 -0
- package/src/pkg/commands/sadd.ts +15 -0
- package/src/pkg/commands/scan.ts +63 -0
- package/src/pkg/commands/scard.ts +11 -0
- package/src/pkg/commands/script_exists.ts +15 -0
- package/src/pkg/commands/script_flush.ts +22 -0
- package/src/pkg/commands/script_load.ts +12 -0
- package/src/pkg/commands/sdiff.ts +11 -0
- package/src/pkg/commands/sdiffstore.ts +14 -0
- package/src/pkg/commands/search/command-builder.ts +162 -0
- package/src/pkg/commands/search/index.ts +4 -0
- package/src/pkg/commands/search/schema-builder.ts +320 -0
- package/src/pkg/commands/search/search.ts +218 -0
- package/src/pkg/commands/search/types.ts +1029 -0
- package/src/pkg/commands/search/utils.ts +275 -0
- package/src/pkg/commands/set.ts +52 -0
- package/src/pkg/commands/setbit.ts +15 -0
- package/src/pkg/commands/setex.ts +11 -0
- package/src/pkg/commands/setnx.ts +11 -0
- package/src/pkg/commands/setrange.ts +15 -0
- package/src/pkg/commands/sinter.ts +11 -0
- package/src/pkg/commands/sintercard.ts +19 -0
- package/src/pkg/commands/sinterstore.ts +14 -0
- package/src/pkg/commands/sismember.ts +11 -0
- package/src/pkg/commands/smembers.ts +12 -0
- package/src/pkg/commands/smismember.ts +17 -0
- package/src/pkg/commands/smove.ts +14 -0
- package/src/pkg/commands/spop.ts +18 -0
- package/src/pkg/commands/srandmember.ts +18 -0
- package/src/pkg/commands/srem.ts +11 -0
- package/src/pkg/commands/sscan.ts +31 -0
- package/src/pkg/commands/strlen.ts +12 -0
- package/src/pkg/commands/subscribe.ts +254 -0
- package/src/pkg/commands/sunion.ts +12 -0
- package/src/pkg/commands/sunionstore.ts +15 -0
- package/src/pkg/commands/time.ts +10 -0
- package/src/pkg/commands/touch.ts +12 -0
- package/src/pkg/commands/ttl.ts +12 -0
- package/src/pkg/commands/type.ts +13 -0
- package/src/pkg/commands/types.ts +201 -0
- package/src/pkg/commands/unlink.ts +12 -0
- package/src/pkg/commands/vector/index.ts +11 -0
- package/src/pkg/commands/vector/types.ts +63 -0
- package/src/pkg/commands/vector/utils.ts +67 -0
- package/src/pkg/commands/vector/vector.ts +131 -0
- package/src/pkg/commands/vector_add.ts +18 -0
- package/src/pkg/commands/vector_count.ts +11 -0
- package/src/pkg/commands/vector_create.ts +28 -0
- package/src/pkg/commands/vector_del.ts +13 -0
- package/src/pkg/commands/vector_drop.ts +13 -0
- package/src/pkg/commands/vector_get.ts +18 -0
- package/src/pkg/commands/vector_info.ts +25 -0
- package/src/pkg/commands/vector_query.ts +24 -0
- package/src/pkg/commands/xack.ts +16 -0
- package/src/pkg/commands/xackdel.ts +21 -0
- package/src/pkg/commands/xadd.ts +70 -0
- package/src/pkg/commands/xautoclaim.ts +31 -0
- package/src/pkg/commands/xclaim.ts +56 -0
- package/src/pkg/commands/xdel.ts +16 -0
- package/src/pkg/commands/xdelex.ts +25 -0
- package/src/pkg/commands/xgroup.ts +101 -0
- package/src/pkg/commands/xinfo.ts +28 -0
- package/src/pkg/commands/xlen.ts +12 -0
- package/src/pkg/commands/xpending.ts +44 -0
- package/src/pkg/commands/xrange.ts +49 -0
- package/src/pkg/commands/xread.ts +78 -0
- package/src/pkg/commands/xreadgroup.ts +74 -0
- package/src/pkg/commands/xrevrange.ts +48 -0
- package/src/pkg/commands/xtrim.ts +25 -0
- package/src/pkg/commands/zadd.ts +54 -0
- package/src/pkg/commands/zcard.ts +12 -0
- package/src/pkg/commands/zcount.ts +14 -0
- package/src/pkg/commands/zdiffstore.ts +15 -0
- package/src/pkg/commands/zincrby.ts +14 -0
- package/src/pkg/commands/zinterstore.ts +51 -0
- package/src/pkg/commands/zlexcount.ts +11 -0
- package/src/pkg/commands/zmscore.ts +16 -0
- package/src/pkg/commands/zpopmax.ts +18 -0
- package/src/pkg/commands/zpopmin.ts +18 -0
- package/src/pkg/commands/zrange.ts +72 -0
- package/src/pkg/commands/zrank.ts +14 -0
- package/src/pkg/commands/zrem.ts +11 -0
- package/src/pkg/commands/zremrangebylex.ts +11 -0
- package/src/pkg/commands/zremrangebyrank.ts +14 -0
- package/src/pkg/commands/zremrangebyscore.ts +18 -0
- package/src/pkg/commands/zrevrank.ts +14 -0
- package/src/pkg/commands/zscan.ts +31 -0
- package/src/pkg/commands/zscore.ts +15 -0
- package/src/pkg/commands/zunion.ts +54 -0
- package/src/pkg/commands/zunionstore.ts +52 -0
- package/src/pkg/error.ts +28 -0
- package/src/pkg/http.ts +458 -0
- package/src/pkg/index.ts +1 -0
- package/src/pkg/pipeline.ts +2041 -0
- package/src/pkg/redis.ts +2130 -0
- package/src/pkg/script.ts +100 -0
- package/src/pkg/scriptRo.ts +98 -0
- package/src/pkg/types.ts +35 -0
- package/src/pkg/util.ts +115 -0
- package/src/platforms/cloudflare.ts +162 -0
- package/src/platforms/fastly.ts +105 -0
- package/src/platforms/nodejs.ts +231 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
export const FIELD_TYPES = [
|
|
2
|
+
"TEXT",
|
|
3
|
+
"U64",
|
|
4
|
+
"I64",
|
|
5
|
+
"F64",
|
|
6
|
+
"BOOL",
|
|
7
|
+
"DATE",
|
|
8
|
+
"KEYWORD",
|
|
9
|
+
"FACET",
|
|
10
|
+
"HYBRID",
|
|
11
|
+
] as const;
|
|
12
|
+
export type FieldType = (typeof FIELD_TYPES)[number];
|
|
13
|
+
|
|
14
|
+
export type TextField = {
|
|
15
|
+
type: "TEXT";
|
|
16
|
+
noTokenize?: boolean;
|
|
17
|
+
noStem?: boolean;
|
|
18
|
+
from?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type NumericField = {
|
|
22
|
+
type: "U64" | "I64" | "F64";
|
|
23
|
+
fast: true;
|
|
24
|
+
from?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type BoolField = {
|
|
28
|
+
type: "BOOL";
|
|
29
|
+
fast?: boolean;
|
|
30
|
+
from?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type DateField = {
|
|
34
|
+
type: "DATE";
|
|
35
|
+
fast?: boolean;
|
|
36
|
+
from?: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type KeywordField = {
|
|
40
|
+
type: "KEYWORD";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type FacetField = {
|
|
44
|
+
type: "FACET";
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A TEXT field that also stores a vector embedding, so it can be searched by meaning with `$ann`.
|
|
49
|
+
*
|
|
50
|
+
* @see https://upstash.com/docs/redis/search/hybrid-search
|
|
51
|
+
*/
|
|
52
|
+
export type HybridField = {
|
|
53
|
+
type: "HYBRID";
|
|
54
|
+
noStem?: boolean;
|
|
55
|
+
from?: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type DetailedField =
|
|
59
|
+
| TextField
|
|
60
|
+
| HybridField
|
|
61
|
+
| NumericField
|
|
62
|
+
| BoolField
|
|
63
|
+
| DateField
|
|
64
|
+
| KeywordField
|
|
65
|
+
| FacetField;
|
|
66
|
+
export type NestedIndexSchema = {
|
|
67
|
+
[key: string]: FieldType | DetailedField | NestedIndexSchema;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type FlatIndexSchema = {
|
|
71
|
+
[key: string]: FieldType | DetailedField;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type SchemaPaths<T, Prefix extends string = ""> = {
|
|
75
|
+
[K in keyof T]: K extends string
|
|
76
|
+
? T[K] extends FieldType | DetailedField
|
|
77
|
+
? Prefix extends ""
|
|
78
|
+
? K
|
|
79
|
+
: `${Prefix}${K}`
|
|
80
|
+
: T[K] extends object
|
|
81
|
+
? SchemaPaths<T[K], `${Prefix}${K}.`>
|
|
82
|
+
: never
|
|
83
|
+
: never;
|
|
84
|
+
}[keyof T];
|
|
85
|
+
|
|
86
|
+
export type ExtractFieldType<T> = T extends FieldType
|
|
87
|
+
? T
|
|
88
|
+
: T extends { type: infer U }
|
|
89
|
+
? U extends FieldType
|
|
90
|
+
? U
|
|
91
|
+
: never
|
|
92
|
+
: never;
|
|
93
|
+
|
|
94
|
+
export type GetFieldAtPath<
|
|
95
|
+
TSchema,
|
|
96
|
+
Path extends string,
|
|
97
|
+
> = Path extends `${infer First}.${infer Rest}`
|
|
98
|
+
? First extends keyof TSchema
|
|
99
|
+
? GetFieldAtPath<TSchema[First], Rest>
|
|
100
|
+
: never
|
|
101
|
+
: Path extends keyof TSchema
|
|
102
|
+
? TSchema[Path]
|
|
103
|
+
: never;
|
|
104
|
+
|
|
105
|
+
type FieldValueType<T extends FieldType> = T extends "TEXT" | "HYBRID"
|
|
106
|
+
? string
|
|
107
|
+
: T extends "U64" | "I64" | "F64"
|
|
108
|
+
? number
|
|
109
|
+
: T extends "BOOL"
|
|
110
|
+
? boolean
|
|
111
|
+
: T extends "DATE"
|
|
112
|
+
? string
|
|
113
|
+
: T extends "KEYWORD"
|
|
114
|
+
? string
|
|
115
|
+
: T extends "FACET"
|
|
116
|
+
? string
|
|
117
|
+
: never;
|
|
118
|
+
|
|
119
|
+
type GetFieldValueType<TSchema, Path extends string> =
|
|
120
|
+
GetFieldAtPath<TSchema, Path> extends infer Field
|
|
121
|
+
? Field extends FieldType | DetailedField
|
|
122
|
+
? FieldValueType<ExtractFieldType<Field>>
|
|
123
|
+
: never
|
|
124
|
+
: never;
|
|
125
|
+
|
|
126
|
+
// Helper type to check if a field has a 'from' property
|
|
127
|
+
type HasFrom<T> = T extends { from: string } ? true : false;
|
|
128
|
+
|
|
129
|
+
// Distributes field inference across unions so that
|
|
130
|
+
// InferSchemaData<NestedIndexSchema | FlatIndexSchema> does not collapse to never
|
|
131
|
+
type InferSchemaDataField<T> = T extends FieldType
|
|
132
|
+
? FieldValueType<T>
|
|
133
|
+
: T extends DetailedField
|
|
134
|
+
? FieldValueType<ExtractFieldType<T>>
|
|
135
|
+
: T extends NestedIndexSchema
|
|
136
|
+
? InferSchemaData<T>
|
|
137
|
+
: unknown;
|
|
138
|
+
|
|
139
|
+
type IsDefaultSchema<T> = [T] extends [NestedIndexSchema | FlatIndexSchema]
|
|
140
|
+
? [NestedIndexSchema | FlatIndexSchema] extends [T]
|
|
141
|
+
? true
|
|
142
|
+
: false
|
|
143
|
+
: false;
|
|
144
|
+
|
|
145
|
+
type AsAnyIfUnknown<T> = unknown extends T ? any : T;
|
|
146
|
+
|
|
147
|
+
export type InferSchemaData<TSchema> =
|
|
148
|
+
IsDefaultSchema<TSchema> extends true
|
|
149
|
+
? any
|
|
150
|
+
: {
|
|
151
|
+
[K in keyof TSchema as TSchema[K] extends DetailedField
|
|
152
|
+
? HasFrom<TSchema[K]> extends true
|
|
153
|
+
? never
|
|
154
|
+
: K
|
|
155
|
+
: K]: AsAnyIfUnknown<InferSchemaDataField<TSchema[K]>>;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Query Options Types
|
|
159
|
+
// These are the options that can be used for the query command
|
|
160
|
+
// Short-circuit to permissive types when schema is the default (any) to avoid
|
|
161
|
+
// excessively deep type instantiation.
|
|
162
|
+
export type QueryOptions<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
163
|
+
IsDefaultSchema<TSchema> extends true
|
|
164
|
+
? {
|
|
165
|
+
filter?: Record<string, any>;
|
|
166
|
+
limit?: number;
|
|
167
|
+
offset?: number;
|
|
168
|
+
select?: Record<string, true>;
|
|
169
|
+
highlight?: {
|
|
170
|
+
fields: string[];
|
|
171
|
+
preTag?: string;
|
|
172
|
+
postTag?: string;
|
|
173
|
+
};
|
|
174
|
+
orderBy?: Record<string, "ASC" | "DESC">;
|
|
175
|
+
scoreFunc?: ScoreBy<string>;
|
|
176
|
+
}
|
|
177
|
+
: {
|
|
178
|
+
filter?: RootQueryFilter<TSchema> | Retriever<TSchema>;
|
|
179
|
+
/** Maximum number of results to return */
|
|
180
|
+
limit?: number;
|
|
181
|
+
/** Number of results to skip */
|
|
182
|
+
offset?: number;
|
|
183
|
+
select?: Partial<{ [K in SchemaPaths<TSchema>]: true }>; // {}
|
|
184
|
+
highlight?: {
|
|
185
|
+
fields: SchemaPaths<TSchema>[];
|
|
186
|
+
preTag?: string;
|
|
187
|
+
postTag?: string;
|
|
188
|
+
};
|
|
189
|
+
} & QueryOrderOption<TSchema>;
|
|
190
|
+
|
|
191
|
+
type CombineMode = "multiply" | "sum";
|
|
192
|
+
type ScoreMode = "multiply" | "sum" | "replace";
|
|
193
|
+
type ScoreModifier =
|
|
194
|
+
| "none"
|
|
195
|
+
| "log"
|
|
196
|
+
| "log1p"
|
|
197
|
+
| "log2p"
|
|
198
|
+
| "ln"
|
|
199
|
+
| "ln1p"
|
|
200
|
+
| "ln2p"
|
|
201
|
+
| "square"
|
|
202
|
+
| "sqrt"
|
|
203
|
+
| "reciprocal";
|
|
204
|
+
|
|
205
|
+
export type ScoreBy<TSchemaPaths extends string> =
|
|
206
|
+
| ScoreByField<false, TSchemaPaths>
|
|
207
|
+
| {
|
|
208
|
+
fields: ScoreByField<true, TSchemaPaths>[];
|
|
209
|
+
combineMode?: CombineMode;
|
|
210
|
+
scoreMode?: ScoreMode;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
type ScoreByField<TMultiple extends boolean, TSchemaPaths extends string> =
|
|
214
|
+
| {
|
|
215
|
+
field: TSchemaPaths;
|
|
216
|
+
modifier?: ScoreModifier;
|
|
217
|
+
factor?: number;
|
|
218
|
+
missing?: number;
|
|
219
|
+
scoreMode?: TMultiple extends true ? never : ScoreMode;
|
|
220
|
+
}
|
|
221
|
+
| TSchemaPaths;
|
|
222
|
+
|
|
223
|
+
type QueryOrderOption<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
224
|
+
| {
|
|
225
|
+
orderBy?: {
|
|
226
|
+
[K in SchemaPaths<TSchema>]: { [P in K]: "ASC" | "DESC" };
|
|
227
|
+
}[SchemaPaths<TSchema>];
|
|
228
|
+
}
|
|
229
|
+
| {
|
|
230
|
+
scoreFunc?: ScoreBy<SchemaPaths<TSchema>>;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Converts dot notation paths to nested object structure type
|
|
235
|
+
* e.g. "content.title" | "content.author" becomes { content: { title: ..., author: ... } }
|
|
236
|
+
*/
|
|
237
|
+
type PathToNestedObject<
|
|
238
|
+
TSchema,
|
|
239
|
+
Path extends string,
|
|
240
|
+
Value,
|
|
241
|
+
> = Path extends `${infer First}.${infer Rest}`
|
|
242
|
+
? { [K in First]: PathToNestedObject<TSchema, Rest, Value> }
|
|
243
|
+
: { [K in Path]: Value };
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Merges intersection of objects into a single object type with proper nesting
|
|
247
|
+
*/
|
|
248
|
+
type DeepMerge<T> = T extends object
|
|
249
|
+
? {
|
|
250
|
+
[K in keyof T]: T[K] extends object ? DeepMerge<T[K]> : T[K];
|
|
251
|
+
}
|
|
252
|
+
: T;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Build nested result type from selected paths
|
|
256
|
+
*/
|
|
257
|
+
type BuildNestedResult<TSchema, TFields> =
|
|
258
|
+
IsDefaultSchema<TSchema> extends true
|
|
259
|
+
? DeepMerge<
|
|
260
|
+
UnionToIntersection<
|
|
261
|
+
{
|
|
262
|
+
[Path in keyof TFields & string]: PathToNestedObject<any, Path, any>;
|
|
263
|
+
}[keyof TFields & string]
|
|
264
|
+
>
|
|
265
|
+
>
|
|
266
|
+
: DeepMerge<
|
|
267
|
+
UnionToIntersection<
|
|
268
|
+
{
|
|
269
|
+
[Path in keyof TFields & SchemaPaths<TSchema>]: PathToNestedObject<
|
|
270
|
+
TSchema,
|
|
271
|
+
Path & string,
|
|
272
|
+
AsAnyIfUnknown<GetFieldValueType<TSchema, Path & string>>
|
|
273
|
+
>;
|
|
274
|
+
}[keyof TFields & SchemaPaths<TSchema>]
|
|
275
|
+
>
|
|
276
|
+
>;
|
|
277
|
+
|
|
278
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (
|
|
279
|
+
k: infer I
|
|
280
|
+
) => void
|
|
281
|
+
? I
|
|
282
|
+
: never;
|
|
283
|
+
|
|
284
|
+
export type QueryResult<
|
|
285
|
+
TSchema extends NestedIndexSchema | FlatIndexSchema,
|
|
286
|
+
TOptions extends QueryOptions<TSchema> | undefined = undefined,
|
|
287
|
+
> = TOptions extends { select: infer TFields }
|
|
288
|
+
? // eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
289
|
+
{} extends TFields
|
|
290
|
+
? { key: string; score: number }
|
|
291
|
+
: {
|
|
292
|
+
key: string;
|
|
293
|
+
score: number;
|
|
294
|
+
data: BuildNestedResult<TSchema, TFields>;
|
|
295
|
+
}
|
|
296
|
+
: {
|
|
297
|
+
key: string;
|
|
298
|
+
score: number;
|
|
299
|
+
data: InferSchemaData<TSchema>;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export type PublicQueryResult<
|
|
303
|
+
TSchema extends NestedIndexSchema | FlatIndexSchema,
|
|
304
|
+
TSelectFields extends SchemaPaths<TSchema>[] | undefined = undefined,
|
|
305
|
+
> = QueryResult<
|
|
306
|
+
TSchema,
|
|
307
|
+
TSelectFields extends SchemaPaths<TSchema>[]
|
|
308
|
+
? {
|
|
309
|
+
select: { [K in TSelectFields[number]]: true };
|
|
310
|
+
}
|
|
311
|
+
: undefined
|
|
312
|
+
>;
|
|
313
|
+
|
|
314
|
+
// Query Filter Types
|
|
315
|
+
// These are the operations that can be used for each field type
|
|
316
|
+
type StringOperationMap<T extends string> = {
|
|
317
|
+
$eq: T;
|
|
318
|
+
$in: T[];
|
|
319
|
+
$fuzzy: T | { value: T; distance?: number; transpositionCostOne?: boolean; prefix?: boolean };
|
|
320
|
+
$phrase:
|
|
321
|
+
| T
|
|
322
|
+
| { value: T }
|
|
323
|
+
| { value: T; slop: number; prefix?: never }
|
|
324
|
+
| { value: T; prefix: boolean; slop?: never };
|
|
325
|
+
$regex: T;
|
|
326
|
+
$smart: T;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
type NumberOperationMap<T extends number> = {
|
|
330
|
+
$eq: T;
|
|
331
|
+
$in: T[];
|
|
332
|
+
$gt: T;
|
|
333
|
+
$gte: T;
|
|
334
|
+
$lt: T;
|
|
335
|
+
$lte: T;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
type KeywordOperationMap<T extends string> = {
|
|
339
|
+
$eq: T;
|
|
340
|
+
$in: T[];
|
|
341
|
+
$gt: T;
|
|
342
|
+
$gte: T;
|
|
343
|
+
$lt: T;
|
|
344
|
+
$lte: T;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
type BooleanOperationMap<T extends boolean> = {
|
|
348
|
+
$eq: T;
|
|
349
|
+
$in: T[];
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
type DateOperationMap<T extends string | Date> = {
|
|
353
|
+
$eq: T;
|
|
354
|
+
$in: T[];
|
|
355
|
+
$gt: T;
|
|
356
|
+
$gte: T;
|
|
357
|
+
$lte: T;
|
|
358
|
+
$lt: T;
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
type FacetOperationMap<T extends string> = {
|
|
362
|
+
$eq: T;
|
|
363
|
+
$in: T[];
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
// Create union types for each field type
|
|
367
|
+
type StringOperations = {
|
|
368
|
+
[K in keyof StringOperationMap<string>]: { [P in K]: StringOperationMap<string>[K] } & {
|
|
369
|
+
$boost?: number;
|
|
370
|
+
};
|
|
371
|
+
}[keyof StringOperationMap<string>];
|
|
372
|
+
|
|
373
|
+
type NumberOperations = {
|
|
374
|
+
[K in keyof NumberOperationMap<number>]: { [P in K]: NumberOperationMap<number>[K] } & {
|
|
375
|
+
$boost?: number;
|
|
376
|
+
};
|
|
377
|
+
}[keyof NumberOperationMap<number>];
|
|
378
|
+
|
|
379
|
+
type BooleanOperations = {
|
|
380
|
+
[K in keyof BooleanOperationMap<boolean>]: { [P in K]: BooleanOperationMap<boolean>[K] } & {
|
|
381
|
+
$boost?: number;
|
|
382
|
+
};
|
|
383
|
+
}[keyof BooleanOperationMap<boolean>];
|
|
384
|
+
|
|
385
|
+
type DateOperations = {
|
|
386
|
+
[K in keyof DateOperationMap<string | Date>]: { [P in K]: DateOperationMap<string | Date>[K] } & {
|
|
387
|
+
$boost?: number;
|
|
388
|
+
};
|
|
389
|
+
}[keyof DateOperationMap<string | Date>];
|
|
390
|
+
|
|
391
|
+
type KeywordOperations = {
|
|
392
|
+
[K in keyof KeywordOperationMap<string>]: { [P in K]: KeywordOperationMap<string>[K] } & {
|
|
393
|
+
$boost?: number;
|
|
394
|
+
};
|
|
395
|
+
}[keyof KeywordOperationMap<string>];
|
|
396
|
+
|
|
397
|
+
type FacetOperations = {
|
|
398
|
+
[K in keyof FacetOperationMap<string>]: { [P in K]: FacetOperationMap<string>[K] } & {
|
|
399
|
+
$boost?: number;
|
|
400
|
+
};
|
|
401
|
+
}[keyof FacetOperationMap<string>];
|
|
402
|
+
|
|
403
|
+
// Create a union type for all operations for a given field type
|
|
404
|
+
type OperationsForFieldType<T extends FieldType> = T extends "TEXT" | "HYBRID"
|
|
405
|
+
? StringOperations
|
|
406
|
+
: T extends "U64" | "I64" | "F64"
|
|
407
|
+
? NumberOperations
|
|
408
|
+
: T extends "BOOL"
|
|
409
|
+
? BooleanOperations
|
|
410
|
+
: T extends "DATE"
|
|
411
|
+
? DateOperations
|
|
412
|
+
: T extends "KEYWORD"
|
|
413
|
+
? KeywordOperations
|
|
414
|
+
: T extends "FACET"
|
|
415
|
+
? FacetOperations
|
|
416
|
+
: never;
|
|
417
|
+
|
|
418
|
+
// Create a union type for all operations for a given path
|
|
419
|
+
type PathOperations<TSchema, TPath extends string> =
|
|
420
|
+
GetFieldAtPath<TSchema, TPath> extends infer Field
|
|
421
|
+
? Field extends FieldType | DetailedField
|
|
422
|
+
? OperationsForFieldType<ExtractFieldType<Field>> | FieldValueType<ExtractFieldType<Field>>
|
|
423
|
+
: never
|
|
424
|
+
: never;
|
|
425
|
+
|
|
426
|
+
// Create a type for a query leaf (only field paths, no boolean operators)
|
|
427
|
+
type QueryLeaf<TSchema> = {
|
|
428
|
+
// allowed schema paths
|
|
429
|
+
[K in SchemaPaths<TSchema>]?: PathOperations<TSchema, K>;
|
|
430
|
+
} & {
|
|
431
|
+
$and?: never;
|
|
432
|
+
$or?: never;
|
|
433
|
+
$must?: never;
|
|
434
|
+
$should?: never;
|
|
435
|
+
$mustNot?: never;
|
|
436
|
+
$boost?: number;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
type BoolBase<TSchema extends NestedIndexSchema | FlatIndexSchema> = {
|
|
440
|
+
[P in SchemaPaths<TSchema>]?: PathOperations<TSchema, P>;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
// $and: all conditions must match
|
|
444
|
+
type AndNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
445
|
+
$and: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
446
|
+
$boost?: number;
|
|
447
|
+
$or?: never;
|
|
448
|
+
$must?: never;
|
|
449
|
+
$should?: never;
|
|
450
|
+
$mustNot?: never;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// $or: at least one condition must match
|
|
454
|
+
type OrNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
455
|
+
$or: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
456
|
+
$boost?: number;
|
|
457
|
+
$and?: never;
|
|
458
|
+
$must?: never;
|
|
459
|
+
$should?: never;
|
|
460
|
+
$mustNot?: never;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// $must only
|
|
464
|
+
type MustNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
465
|
+
$must: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
466
|
+
$boost?: number;
|
|
467
|
+
$and?: never;
|
|
468
|
+
$or?: never;
|
|
469
|
+
$should?: never;
|
|
470
|
+
$mustNot?: never;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
// $should only
|
|
474
|
+
type ShouldNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
475
|
+
$should: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
476
|
+
$boost?: number;
|
|
477
|
+
$and?: never;
|
|
478
|
+
$or?: never;
|
|
479
|
+
$must?: never;
|
|
480
|
+
$mustNot?: never;
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// $must + $should combined
|
|
484
|
+
type MustShouldNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
485
|
+
$must: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
486
|
+
$should: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
487
|
+
$and?: never;
|
|
488
|
+
$or?: never;
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// $mustNot only
|
|
492
|
+
type NotNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
493
|
+
$mustNot: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
494
|
+
$boost?: number;
|
|
495
|
+
$and?: never;
|
|
496
|
+
$or?: never;
|
|
497
|
+
$must?: never;
|
|
498
|
+
$should?: never;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
type AndNotNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
502
|
+
$and: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
503
|
+
$mustNot: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
504
|
+
$boost?: number;
|
|
505
|
+
$or?: never;
|
|
506
|
+
$must?: never;
|
|
507
|
+
$should?: never;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
type OrNotNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
511
|
+
$or: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
512
|
+
$mustNot: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
513
|
+
$boost?: number;
|
|
514
|
+
$and?: never;
|
|
515
|
+
$must?: never;
|
|
516
|
+
$should?: never;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// $should + $mustNot combined
|
|
520
|
+
type ShouldNotNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
521
|
+
$should: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
522
|
+
$mustNot: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
523
|
+
$boost?: number;
|
|
524
|
+
$and?: never;
|
|
525
|
+
$or?: never;
|
|
526
|
+
$must?: never;
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
type MustNotNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
530
|
+
$must: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
531
|
+
$mustNot: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
532
|
+
$boost?: number;
|
|
533
|
+
$and?: never;
|
|
534
|
+
$or?: never;
|
|
535
|
+
$should?: never;
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// Full boolean node: $must + $should + $mustNot
|
|
539
|
+
type BoolNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = BoolBase<TSchema> & {
|
|
540
|
+
$must: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
541
|
+
$should: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
542
|
+
$mustNot: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
543
|
+
$boost?: number;
|
|
544
|
+
$and?: never;
|
|
545
|
+
$or?: never;
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// Create a type for a query filter
|
|
549
|
+
// Short-circuit to Record<string, any> when schema is the default (any) to avoid
|
|
550
|
+
// excessively deep type instantiation from the recursive filter union types.
|
|
551
|
+
export type QueryFilter<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
552
|
+
IsDefaultSchema<TSchema> extends true
|
|
553
|
+
? Record<string, any>
|
|
554
|
+
:
|
|
555
|
+
| QueryLeaf<TSchema>
|
|
556
|
+
| AndNode<TSchema>
|
|
557
|
+
| OrNode<TSchema>
|
|
558
|
+
| MustNode<TSchema>
|
|
559
|
+
| ShouldNode<TSchema>
|
|
560
|
+
| MustShouldNode<TSchema>
|
|
561
|
+
| NotNode<TSchema>
|
|
562
|
+
| AndNotNode<TSchema>
|
|
563
|
+
| OrNotNode<TSchema>
|
|
564
|
+
| ShouldNotNode<TSchema>
|
|
565
|
+
| MustNotNode<TSchema>
|
|
566
|
+
| BoolNode<TSchema>;
|
|
567
|
+
|
|
568
|
+
// Create a type for root-level queries (restricts $or from mixing with fields)
|
|
569
|
+
export type RootQueryFilter<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
570
|
+
IsDefaultSchema<TSchema> extends true
|
|
571
|
+
? Record<string, any>
|
|
572
|
+
:
|
|
573
|
+
| QueryLeaf<TSchema>
|
|
574
|
+
| AndNode<TSchema>
|
|
575
|
+
| RootOrNode<TSchema>
|
|
576
|
+
| MustNode<TSchema>
|
|
577
|
+
| ShouldNode<TSchema>
|
|
578
|
+
| MustShouldNode<TSchema>
|
|
579
|
+
| AndNotNode<TSchema>
|
|
580
|
+
| ShouldNotNode<TSchema>
|
|
581
|
+
| BoolNode<TSchema>;
|
|
582
|
+
|
|
583
|
+
// Restricted version of OrNode that doesn't allow field operations at root level
|
|
584
|
+
type RootOrNode<TSchema extends NestedIndexSchema | FlatIndexSchema> = {
|
|
585
|
+
[P in SchemaPaths<TSchema>]?: never; // No field operations at root level with $or
|
|
586
|
+
} & {
|
|
587
|
+
$or: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
588
|
+
$boost?: number;
|
|
589
|
+
$and?: never;
|
|
590
|
+
$must?: never;
|
|
591
|
+
$should?: never;
|
|
592
|
+
$mustNot?: QueryFilter<TSchema> | QueryFilter<TSchema>[];
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// Retrievers
|
|
596
|
+
// @see https://upstash.com/docs/redis/search/retrievers/overview
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Runs a semantic search on a HYBRID field.
|
|
600
|
+
*
|
|
601
|
+
* @see https://upstash.com/docs/redis/search/retrievers/ann
|
|
602
|
+
*/
|
|
603
|
+
export type AnnRetriever<TSchema extends NestedIndexSchema | FlatIndexSchema> = {
|
|
604
|
+
$ann: {
|
|
605
|
+
/** The HYBRID field to search */
|
|
606
|
+
field: IsDefaultSchema<TSchema> extends true ? string : HybridPaths<TSchema>;
|
|
607
|
+
/** The text to search for. Cannot be empty. */
|
|
608
|
+
query: string;
|
|
609
|
+
/** Accuracy and speed trade-off. Defaults to `balanced`. */
|
|
610
|
+
profile?: "fast" | "balanced" | "precise";
|
|
611
|
+
/** Only documents that match this query are returned */
|
|
612
|
+
filter?: RootQueryFilter<TSchema>;
|
|
613
|
+
/** Scales how much the results add to the `$rrf` score. Valid only inside `$rrf`. */
|
|
614
|
+
weight?: number;
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Runs one query. Use it inside `$rrf` to set the weight of a query.
|
|
620
|
+
*
|
|
621
|
+
* @see https://upstash.com/docs/redis/search/retrievers/standard
|
|
622
|
+
*/
|
|
623
|
+
export type StandardRetriever<TSchema extends NestedIndexSchema | FlatIndexSchema> = {
|
|
624
|
+
$standard: {
|
|
625
|
+
query: RootQueryFilter<TSchema>;
|
|
626
|
+
/** Scales how much the query adds to the `$rrf` score. Valid only inside `$rrf`. */
|
|
627
|
+
weight?: number;
|
|
628
|
+
};
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Merges the results of 2 to 10 retrievers with Reciprocal Rank Fusion.
|
|
633
|
+
*
|
|
634
|
+
* @see https://upstash.com/docs/redis/search/retrievers/rrf
|
|
635
|
+
*/
|
|
636
|
+
export type RrfRetriever<
|
|
637
|
+
TSchema extends NestedIndexSchema | FlatIndexSchema,
|
|
638
|
+
TAllowAnn extends boolean = true,
|
|
639
|
+
> = {
|
|
640
|
+
$rrf: {
|
|
641
|
+
/** 2 to 10 retrievers to merge */
|
|
642
|
+
retrievers: (
|
|
643
|
+
| RootQueryFilter<TSchema>
|
|
644
|
+
| StandardRetriever<TSchema>
|
|
645
|
+
| (TAllowAnn extends true ? AnnRetriever<TSchema> : never)
|
|
646
|
+
)[];
|
|
647
|
+
/** Higher values give lower-ranked results more influence. Defaults to `60`. */
|
|
648
|
+
rankConstant?: number;
|
|
649
|
+
/** The number of results each retriever contributes. Defaults to `LIMIT`. */
|
|
650
|
+
window?: number;
|
|
651
|
+
};
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
export type Retriever<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
655
|
+
| AnnRetriever<TSchema>
|
|
656
|
+
| StandardRetriever<TSchema>
|
|
657
|
+
| RrfRetriever<TSchema>;
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Retrievers accepted by `SEARCH.COUNT` and `SEARCH.AGGREGATE`, which do not support `$ann`.
|
|
661
|
+
*/
|
|
662
|
+
export type CountRetriever<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
663
|
+
| StandardRetriever<TSchema>
|
|
664
|
+
| RrfRetriever<TSchema, false>;
|
|
665
|
+
|
|
666
|
+
// Helper type to extract only HYBRID field paths from schema
|
|
667
|
+
export type HybridPaths<T, Prefix extends string = ""> = {
|
|
668
|
+
[K in keyof T]: K extends string
|
|
669
|
+
? T[K] extends "HYBRID" | { type: "HYBRID" }
|
|
670
|
+
? Prefix extends ""
|
|
671
|
+
? K
|
|
672
|
+
: `${Prefix}${K}`
|
|
673
|
+
: T[K] extends FieldType | DetailedField
|
|
674
|
+
? never
|
|
675
|
+
: T[K] extends object
|
|
676
|
+
? HybridPaths<T[K], `${Prefix}${K}.`>
|
|
677
|
+
: never
|
|
678
|
+
: never;
|
|
679
|
+
}[keyof T];
|
|
680
|
+
|
|
681
|
+
export type DescribeFieldInfo = {
|
|
682
|
+
type: FieldType;
|
|
683
|
+
noTokenize?: boolean;
|
|
684
|
+
noStem?: boolean;
|
|
685
|
+
fast?: boolean;
|
|
686
|
+
from?: string;
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
export type IndexDescription<TSchema extends NestedIndexSchema | FlatIndexSchema> = {
|
|
690
|
+
name: string;
|
|
691
|
+
dataType: "hash" | "string" | "json" | "stream";
|
|
692
|
+
/**
|
|
693
|
+
* Key prefixes tracked by the index. For a stream index, this holds the single stream key.
|
|
694
|
+
*/
|
|
695
|
+
prefixes: string[];
|
|
696
|
+
language?: Language;
|
|
697
|
+
schema: IsDefaultSchema<TSchema> extends true
|
|
698
|
+
? Record<string, DescribeFieldInfo>
|
|
699
|
+
: Record<SchemaPaths<TSchema>, DescribeFieldInfo>;
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
export type Language =
|
|
703
|
+
| "english"
|
|
704
|
+
| "arabic"
|
|
705
|
+
| "danish"
|
|
706
|
+
| "dutch"
|
|
707
|
+
| "finnish"
|
|
708
|
+
| "french"
|
|
709
|
+
| "german"
|
|
710
|
+
| "greek"
|
|
711
|
+
| "hungarian"
|
|
712
|
+
| "italian"
|
|
713
|
+
| "norwegian"
|
|
714
|
+
| "portuguese"
|
|
715
|
+
| "romanian"
|
|
716
|
+
| "russian"
|
|
717
|
+
| "spanish"
|
|
718
|
+
| "swedish"
|
|
719
|
+
| "tamil"
|
|
720
|
+
| "turkish";
|
|
721
|
+
|
|
722
|
+
// Helper type to extract only FACET field paths from schema
|
|
723
|
+
export type FacetPaths<T, Prefix extends string = ""> = {
|
|
724
|
+
[K in keyof T]: K extends string
|
|
725
|
+
? T[K] extends "FACET" | { type: "FACET" }
|
|
726
|
+
? Prefix extends ""
|
|
727
|
+
? K
|
|
728
|
+
: `${Prefix}${K}`
|
|
729
|
+
: T[K] extends FieldType | DetailedField
|
|
730
|
+
? never
|
|
731
|
+
: T[K] extends object
|
|
732
|
+
? FacetPaths<T[K], `${Prefix}${K}.`>
|
|
733
|
+
: never
|
|
734
|
+
: never;
|
|
735
|
+
}[keyof T];
|
|
736
|
+
|
|
737
|
+
// Aggregate Types
|
|
738
|
+
export type AggregateOptions<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
739
|
+
IsDefaultSchema<TSchema> extends true
|
|
740
|
+
? {
|
|
741
|
+
filter?: Record<string, any>;
|
|
742
|
+
aggregations: {
|
|
743
|
+
[key: string]: Record<string, any>;
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
: {
|
|
747
|
+
filter?: RootQueryFilter<TSchema> | CountRetriever<TSchema>;
|
|
748
|
+
aggregations: {
|
|
749
|
+
[key: string]: Aggregation<TSchema>;
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
export type Aggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
754
|
+
IsDefaultSchema<TSchema> extends true
|
|
755
|
+
? Record<string, any>
|
|
756
|
+
:
|
|
757
|
+
| TermsAggregation<TSchema>
|
|
758
|
+
| RangeAggregation<TSchema>
|
|
759
|
+
| HistogramAggregation<TSchema>
|
|
760
|
+
| StatsAggregation<TSchema>
|
|
761
|
+
| AvgAggregation<TSchema>
|
|
762
|
+
| SumAggregation<TSchema>
|
|
763
|
+
| MinAggregation<TSchema>
|
|
764
|
+
| MaxAggregation<TSchema>
|
|
765
|
+
| CountAggregation<TSchema>
|
|
766
|
+
| ExtendedStatsAggregation<TSchema>
|
|
767
|
+
| PercentilesAggregation<TSchema>
|
|
768
|
+
| CardinalityAggregation<TSchema>
|
|
769
|
+
| FacetAggregation<TSchema>;
|
|
770
|
+
|
|
771
|
+
type BaseAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> = {
|
|
772
|
+
$aggs?: {
|
|
773
|
+
[key: string]: Aggregation<TSchema>;
|
|
774
|
+
};
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
export type TermsAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
778
|
+
BaseAggregation<TSchema> & {
|
|
779
|
+
$terms: {
|
|
780
|
+
field: SchemaPaths<TSchema>;
|
|
781
|
+
size?: number;
|
|
782
|
+
};
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
export type RangeAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
786
|
+
BaseAggregation<TSchema> & {
|
|
787
|
+
$range: {
|
|
788
|
+
field: SchemaPaths<TSchema>;
|
|
789
|
+
ranges: { from?: number; to?: number }[];
|
|
790
|
+
};
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
export type HistogramAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
794
|
+
BaseAggregation<TSchema> & {
|
|
795
|
+
$histogram: {
|
|
796
|
+
field: SchemaPaths<TSchema>;
|
|
797
|
+
interval: number;
|
|
798
|
+
};
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
export type StatsAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
802
|
+
BaseAggregation<TSchema> & {
|
|
803
|
+
$stats: {
|
|
804
|
+
field: SchemaPaths<TSchema>;
|
|
805
|
+
missing?: number;
|
|
806
|
+
};
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
export type AvgAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
810
|
+
BaseAggregation<TSchema> & {
|
|
811
|
+
$avg: {
|
|
812
|
+
field: SchemaPaths<TSchema>;
|
|
813
|
+
missing?: number;
|
|
814
|
+
};
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
export type SumAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
818
|
+
BaseAggregation<TSchema> & {
|
|
819
|
+
$sum: {
|
|
820
|
+
field: SchemaPaths<TSchema>;
|
|
821
|
+
missing?: number;
|
|
822
|
+
};
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
export type MinAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
826
|
+
BaseAggregation<TSchema> & {
|
|
827
|
+
$min: {
|
|
828
|
+
field: SchemaPaths<TSchema>;
|
|
829
|
+
missing?: number;
|
|
830
|
+
};
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
export type MaxAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
834
|
+
BaseAggregation<TSchema> & {
|
|
835
|
+
$max: {
|
|
836
|
+
field: SchemaPaths<TSchema>;
|
|
837
|
+
missing?: number;
|
|
838
|
+
};
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
export type CountAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
842
|
+
BaseAggregation<TSchema> & {
|
|
843
|
+
$count: {
|
|
844
|
+
field: SchemaPaths<TSchema>;
|
|
845
|
+
};
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
export type ExtendedStatsAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
849
|
+
BaseAggregation<TSchema> & {
|
|
850
|
+
$extendedStats: {
|
|
851
|
+
field: SchemaPaths<TSchema>;
|
|
852
|
+
sigma?: number;
|
|
853
|
+
missing?: number;
|
|
854
|
+
};
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
export type PercentilesAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
858
|
+
BaseAggregation<TSchema> & {
|
|
859
|
+
$percentiles: {
|
|
860
|
+
field: SchemaPaths<TSchema>;
|
|
861
|
+
percents?: number[];
|
|
862
|
+
keyed?: boolean;
|
|
863
|
+
missing?: number;
|
|
864
|
+
};
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
export type CardinalityAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
868
|
+
BaseAggregation<TSchema> & {
|
|
869
|
+
$cardinality: {
|
|
870
|
+
field: SchemaPaths<TSchema>;
|
|
871
|
+
};
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
export type FacetAggregation<TSchema extends NestedIndexSchema | FlatIndexSchema> =
|
|
875
|
+
BaseAggregation<TSchema> & {
|
|
876
|
+
$facet: {
|
|
877
|
+
field: FacetPaths<TSchema>;
|
|
878
|
+
path: string;
|
|
879
|
+
depth?: number;
|
|
880
|
+
size?: number;
|
|
881
|
+
minDocCount?: number;
|
|
882
|
+
order?: { count: "desc" | "asc" };
|
|
883
|
+
};
|
|
884
|
+
};
|
|
885
|
+
|
|
886
|
+
export type AggregateResult<
|
|
887
|
+
TSchema extends NestedIndexSchema | FlatIndexSchema,
|
|
888
|
+
TOpts extends AggregateOptions<TSchema>,
|
|
889
|
+
> =
|
|
890
|
+
IsDefaultSchema<TSchema> extends true
|
|
891
|
+
? Record<string, any>
|
|
892
|
+
: BuildAggregateResult<
|
|
893
|
+
TSchema,
|
|
894
|
+
Extract<TOpts["aggregations"], { [key: string]: Aggregation<TSchema> }>
|
|
895
|
+
>;
|
|
896
|
+
|
|
897
|
+
type BuildAggregateResult<
|
|
898
|
+
TSchema extends NestedIndexSchema | FlatIndexSchema,
|
|
899
|
+
TAggs extends { [key: string]: Aggregation<TSchema> },
|
|
900
|
+
> = {
|
|
901
|
+
[K in keyof TAggs]: TAggs[K] extends TermsAggregation<TSchema>
|
|
902
|
+
? TermsResult<TSchema, TAggs[K]>
|
|
903
|
+
: TAggs[K] extends RangeAggregation<TSchema>
|
|
904
|
+
? RangeResult<TSchema, TAggs[K]>
|
|
905
|
+
: TAggs[K] extends HistogramAggregation<TSchema>
|
|
906
|
+
? HistogramResult<TSchema, TAggs[K]>
|
|
907
|
+
: TAggs[K] extends StatsAggregation<TSchema>
|
|
908
|
+
? StatsResult
|
|
909
|
+
: TAggs[K] extends AvgAggregation<TSchema>
|
|
910
|
+
? MetricValueResult
|
|
911
|
+
: TAggs[K] extends SumAggregation<TSchema>
|
|
912
|
+
? MetricValueResult
|
|
913
|
+
: TAggs[K] extends MinAggregation<TSchema>
|
|
914
|
+
? MetricValueResult
|
|
915
|
+
: TAggs[K] extends MaxAggregation<TSchema>
|
|
916
|
+
? MetricValueResult
|
|
917
|
+
: TAggs[K] extends CountAggregation<TSchema>
|
|
918
|
+
? MetricValueResult
|
|
919
|
+
: TAggs[K] extends CardinalityAggregation<TSchema>
|
|
920
|
+
? MetricValueResult
|
|
921
|
+
: TAggs[K] extends ExtendedStatsAggregation<TSchema>
|
|
922
|
+
? ExtendedStatsResult<TAggs[K]>
|
|
923
|
+
: TAggs[K] extends PercentilesAggregation<TSchema>
|
|
924
|
+
? PercentilesResult<TAggs[K]>
|
|
925
|
+
: TAggs[K] extends FacetAggregation<TSchema>
|
|
926
|
+
? FacetResult
|
|
927
|
+
: never;
|
|
928
|
+
};
|
|
929
|
+
|
|
930
|
+
type Bucket<T> = {
|
|
931
|
+
key: T;
|
|
932
|
+
docCount: number;
|
|
933
|
+
from?: number;
|
|
934
|
+
to?: number;
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
type TermsResult<
|
|
938
|
+
TSchema extends NestedIndexSchema | FlatIndexSchema,
|
|
939
|
+
TAgg extends TermsAggregation<TSchema>,
|
|
940
|
+
> = TAgg["$aggs"] extends { [key: string]: Aggregation<TSchema> }
|
|
941
|
+
? {
|
|
942
|
+
buckets: (Bucket<GetFieldValueType<TSchema, TAgg["$terms"]["field"]>> &
|
|
943
|
+
BuildAggregateResult<TSchema, TAgg["$aggs"]>)[];
|
|
944
|
+
sumOtherDocCount: number;
|
|
945
|
+
docCountErrorUpperBound: number;
|
|
946
|
+
}
|
|
947
|
+
: {
|
|
948
|
+
buckets: Bucket<GetFieldValueType<TSchema, TAgg["$terms"]["field"]>>[];
|
|
949
|
+
sumOtherDocCount: number;
|
|
950
|
+
docCountErrorUpperBound: number;
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
type RangeResult<
|
|
954
|
+
TSchema extends NestedIndexSchema | FlatIndexSchema,
|
|
955
|
+
TAgg extends RangeAggregation<TSchema>,
|
|
956
|
+
> = TAgg["$aggs"] extends { [key: string]: Aggregation<TSchema> }
|
|
957
|
+
? {
|
|
958
|
+
buckets: (Bucket<string> & BuildAggregateResult<TSchema, TAgg["$aggs"]>)[];
|
|
959
|
+
}
|
|
960
|
+
: {
|
|
961
|
+
buckets: Bucket<string>[];
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
type HistogramResult<
|
|
965
|
+
TSchema extends NestedIndexSchema | FlatIndexSchema,
|
|
966
|
+
TAgg extends HistogramAggregation<TSchema>,
|
|
967
|
+
> = TAgg["$aggs"] extends { [key: string]: Aggregation<TSchema> }
|
|
968
|
+
? {
|
|
969
|
+
buckets: (Bucket<number> & BuildAggregateResult<TSchema, TAgg["$aggs"]>)[];
|
|
970
|
+
}
|
|
971
|
+
: {
|
|
972
|
+
buckets: Bucket<number>[];
|
|
973
|
+
};
|
|
974
|
+
|
|
975
|
+
type MetricValueResult = {
|
|
976
|
+
value: number;
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
type StatsResult = {
|
|
980
|
+
count: number;
|
|
981
|
+
min: number;
|
|
982
|
+
max: number;
|
|
983
|
+
sum: number;
|
|
984
|
+
avg: number;
|
|
985
|
+
};
|
|
986
|
+
|
|
987
|
+
type ExtendedStatsResult<_TAgg> = {
|
|
988
|
+
count: number;
|
|
989
|
+
min: number;
|
|
990
|
+
max: number;
|
|
991
|
+
avg: number;
|
|
992
|
+
sum: number;
|
|
993
|
+
sumOfSquares: number;
|
|
994
|
+
variance: number;
|
|
995
|
+
variancePopulation: number;
|
|
996
|
+
varianceSampling: number;
|
|
997
|
+
stdDeviation: number;
|
|
998
|
+
stdDeviationPopulation: number;
|
|
999
|
+
stdDeviationSampling: number;
|
|
1000
|
+
stdDeviationBounds: {
|
|
1001
|
+
upper: number;
|
|
1002
|
+
lower: number;
|
|
1003
|
+
upperSampling: number;
|
|
1004
|
+
lowerSampling: number;
|
|
1005
|
+
upperPopulation: number;
|
|
1006
|
+
lowerPopulation: number;
|
|
1007
|
+
};
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
type PercentilesResult<TAgg> = TAgg extends { $percentiles: { keyed: false } }
|
|
1011
|
+
? {
|
|
1012
|
+
values: Array<{ key: number; value: number }>;
|
|
1013
|
+
}
|
|
1014
|
+
: {
|
|
1015
|
+
values: { [key: string]: number };
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
type FacetChildNode = {
|
|
1019
|
+
path: string;
|
|
1020
|
+
docCount: number;
|
|
1021
|
+
sumOtherDocCount: number;
|
|
1022
|
+
children?: FacetChildNode[];
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
type FacetResult = {
|
|
1026
|
+
path: string;
|
|
1027
|
+
sumOtherDocCount: number;
|
|
1028
|
+
children: FacetChildNode[];
|
|
1029
|
+
};
|