effect-redis 0.0.13 → 0.0.14

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.js CHANGED
@@ -29,4 +29,4 @@ ${this.stack.split(`
29
29
  `),endStackDef=stackDef.slice(2).join(`
30
30
  `).trim();if(!endStackDef.includes("("))endStackDef=endStackDef.replace(/at (.*)/,"at ($1)");let endStackCall=stackCall.slice(2).join(`
31
31
  `).trim();if(!endStackCall.includes("("))endStackCall=endStackCall.replace(/at (.*)/,"at ($1)");return cache=`${endStackDef}
32
- ${endStackCall}`,cache}},opts=options.spanOptions&&"captureStackTrace"in options.spanOptions?options.spanOptions:{captureStackTrace,...options.spanOptions};return withSpan3(effect,options.spanName,opts)}var fnUntraced2=fnUntraced,ensureSuccessType=()=>(effect)=>effect,ensureErrorType=()=>(effect)=>effect,ensureRequirementsType=()=>(effect)=>effect;var exports_Layer={};__export(exports_Layer,{zipWith:()=>zipWith5,withSpan:()=>withSpan4,withParentSpan:()=>withParentSpan4,updateService:()=>updateService3,unwrapScoped:()=>unwrapScoped2,unwrapEffect:()=>unwrapEffect2,toRuntimeWithMemoMap:()=>toRuntimeWithMemoMap2,toRuntime:()=>toRuntime2,tapErrorCause:()=>tapErrorCause4,tapError:()=>tapError4,tap:()=>tap4,syncContext:()=>syncContext2,sync:()=>sync4,suspend:()=>suspend4,succeedContext:()=>succeedContext2,succeed:()=>succeed7,span:()=>span3,setVersionMismatchErrorLogLevel:()=>setVersionMismatchErrorLogLevel,setUnhandledErrorLogLevel:()=>setUnhandledErrorLogLevel,setTracerTiming:()=>setTracerTiming,setTracerEnabled:()=>setTracerEnabled,setTracer:()=>setTracer2,setScheduler:()=>setScheduler,setRequestCaching:()=>setRequestCaching,setRequestCache:()=>setRequestCache,setRequestBatching:()=>setRequestBatching,setRandom:()=>setRandom,setConfigProvider:()=>setConfigProvider2,setClock:()=>setClock,service:()=>service2,scopedDiscard:()=>scopedDiscard2,scopedContext:()=>scopedContext2,scoped:()=>scoped3,scope:()=>scope4,retry:()=>retry3,provideMerge:()=>provideMerge2,provide:()=>provide3,project:()=>project2,passthrough:()=>passthrough3,parentSpan:()=>parentSpan2,orElse:()=>orElse4,orDie:()=>orDie4,mock:()=>mock2,mergeAll:()=>mergeAll6,merge:()=>merge8,memoize:()=>memoize3,matchCause:()=>matchCause4,match:()=>match11,mapError:()=>mapError4,map:()=>map12,makeMemoMap:()=>makeMemoMap2,locallyWith:()=>locallyWith2,locallyScoped:()=>locallyScoped2,locallyEffect:()=>locallyEffect2,locally:()=>locally2,launch:()=>launch2,isLayer:()=>isLayer2,isFresh:()=>isFresh2,function:()=>fromFunction2,fresh:()=>fresh2,flatten:()=>flatten8,flatMap:()=>flatMap11,fiberRefLocallyScopedWith:()=>fiberRefLocallyScopedWith3,failSync:()=>failSync4,failCauseSync:()=>failCauseSync4,failCause:()=>failCause6,fail:()=>fail7,extendScope:()=>extendScope2,empty:()=>empty28,effectDiscard:()=>effectDiscard,effectContext:()=>effectContext,effect:()=>effect,discard:()=>discard2,dieSync:()=>dieSync4,die:()=>die6,context:()=>context4,catchAllCause:()=>catchAllCause4,catchAll:()=>catchAll4,buildWithScope:()=>buildWithScope2,buildWithMemoMap:()=>buildWithMemoMap2,build:()=>build2,annotateSpans:()=>annotateSpans4,annotateLogs:()=>annotateLogs4,MemoMapTypeId:()=>MemoMapTypeId2,LayerTypeId:()=>LayerTypeId2,CurrentMemoMap:()=>CurrentMemoMap2});var setConfigProvider=(configProvider)=>scopedDiscard(withConfigProviderScoped(configProvider)),parentSpan=(span2)=>succeedContext(make5(spanTag,span2)),span2=(name,options)=>{return options=addSpanStackTrace(options),scoped(spanTag,options?.onEnd?tap(makeSpanScoped(name,options),(span3)=>addFinalizer((exit3)=>options.onEnd(span3,exit3))):makeSpanScoped(name,options))},setTracer=(tracer3)=>scopedDiscard(withTracerScoped(tracer3));var LayerTypeId2=LayerTypeId,MemoMapTypeId2=MemoMapTypeId,CurrentMemoMap2=CurrentMemoMap,isLayer2=isLayer,isFresh2=isFresh,annotateLogs4=annotateLogs2,annotateSpans4=annotateSpans2,build2=build,buildWithScope2=buildWithScope,catchAll4=catchAll2,catchAllCause4=catchAllCause2,context4=context2,die6=die4,dieSync4=dieSync2,discard2=discard,effect=fromEffect2,effectDiscard=fromEffectDiscard,effectContext=fromEffectContext,empty28=empty27,extendScope2=extendScope,fail7=fail4,failSync4=failSync2,failCause6=failCause3,failCauseSync4=failCauseSync2,flatMap11=flatMap9,flatten8=flatten6,fresh2=fresh,mock2=mock,fromFunction2=fromFunction;var launch2=launch,map12=map9,mapError4=mapError2,match11=match9,matchCause4=matchCause2,memoize3=memoize2,merge8=merge6,mergeAll6=mergeAll4,orDie4=orDie2,orElse4=orElse2,passthrough3=passthrough,project2=project,locallyEffect2=locallyEffect,locally2=fiberRefLocally2,locallyWith2=fiberRefLocallyWith2,locallyScoped2=fiberRefLocallyScoped2,fiberRefLocallyScopedWith3=fiberRefLocallyScopedWith2,retry3=retry,scope4=scope2,scoped3=scoped,scopedDiscard2=scopedDiscard,scopedContext2=scopedContext,service2=service,succeed7=succeed4,succeedContext2=succeedContext,suspend4=suspend2,sync4=sync2,syncContext2=syncContext,tap4=tap2,tapError4=tapError2,tapErrorCause4=tapErrorCause2,toRuntime2=toRuntime,toRuntimeWithMemoMap2=toRuntimeWithMemoMap,provide3=provide,provideMerge2=provideMerge,zipWith5=zipWith3,unwrapEffect2=unwrapEffect,unwrapScoped2=unwrapScoped,setClock=(clock3)=>scopedDiscard2(fiberRefLocallyScopedWith(currentServices,add2(clockTag,clock3))),setConfigProvider2=setConfigProvider,parentSpan2=parentSpan,setRandom=(random4)=>scopedDiscard2(fiberRefLocallyScopedWith(currentServices,add2(randomTag,random4))),setRequestBatching=(requestBatching)=>scopedDiscard2(fiberRefLocallyScoped(currentRequestBatching,requestBatching)),setRequestCaching=(requestCaching)=>scopedDiscard2(fiberRefLocallyScoped(currentCacheEnabled,requestCaching)),setRequestCache=(cache)=>scopedDiscard2(isEffect(cache)?flatMap7(cache,(x)=>fiberRefLocallyScoped(currentCache,x)):fiberRefLocallyScoped(currentCache,cache)),setScheduler=(scheduler)=>scopedDiscard2(fiberRefLocallyScoped(currentScheduler,scheduler)),span3=span2,setTracer2=setTracer,setTracerEnabled=(enabled2)=>scopedDiscard2(fiberRefLocallyScoped(currentTracerEnabled,enabled2)),setTracerTiming=(enabled2)=>scopedDiscard2(fiberRefLocallyScoped(currentTracerTimingEnabled,enabled2)),setUnhandledErrorLogLevel=(level)=>scopedDiscard2(fiberRefLocallyScoped(currentUnhandledErrorLogLevel,level)),setVersionMismatchErrorLogLevel=(level)=>scopedDiscard2(fiberRefLocallyScoped(currentVersionMismatchErrorLogLevel,level)),withSpan4=withSpan2,withParentSpan4=withParentSpan2,makeMemoMap2=makeMemoMap,buildWithMemoMap2=buildWithMemoMap,updateService3=dual(3,(layer,tag,f)=>provide3(layer,map12(context4(),(c)=>add2(c,tag,f(unsafeGet3(c,tag))))));var import_redis=__toESM(require_dist2(),1);class RedisError extends exports_Data.TaggedError("RedisError"){}class RedisConnectionOptions extends exports_Context.Tag("RedisConnectionOptions")(){}class Redis extends exports_Context.Tag("Redis")(){}class RedisPubSub extends exports_Context.Tag("RedisPubSub")(){}class RedisPersistence extends exports_Context.Tag("RedisPersistence")(){}class RedisStream extends exports_Context.Tag("RedisStream")(){}var redisClientEffect=exports_Effect.gen(function*(){let{options}=yield*RedisConnectionOptions;return yield*exports_Effect.acquireRelease(exports_Effect.tryPromise({try:()=>import_redis.createClient(options).connect().then((r)=>{return console.log("Connected to Redis"),r.on("error",(e)=>{console.log("Redis error(on error):",e.message),r.destroy()}),r.on("end",()=>{console.log("Connection to Redis ended")}),r}),catch:(e)=>new RedisError({cause:e,message:"Error while connecting to Redis"})}),(client)=>client.isReady?exports_Effect.tryPromise({try:async()=>{console.log("Cleaning up Redis connection"),await client.quit()},catch:(e)=>new RedisError({cause:e,message:"Error while closing Redis connection"})}).pipe(exports_Effect.catchAll(()=>exports_Effect.void)):exports_Effect.void)}),bootstrapRedisServiceEffect=exports_Effect.gen(function*(){let client=yield*redisClientEffect;return Redis.of({use:(fn2)=>exports_Effect.gen(function*(){let result=yield*exports_Effect.try({try:()=>fn2(client),catch:(e)=>new RedisError({cause:e,message:"Synchronous error in `Redis.use`"})});if(result instanceof Promise)return yield*exports_Effect.tryPromise({try:()=>result,catch:(e)=>new RedisError({cause:e,message:"Asynchronous error in `Redis.use`"})});return result})})}),bootstrapRedisPersistenceServiceEffect=exports_Effect.gen(function*(){let client=yield*redisClientEffect;return RedisPersistence.of({setValue:(key,value)=>exports_Effect.tryPromise({try:()=>client.set(key,value),catch:(e)=>new RedisError({cause:e,message:"Error in `Redis.setValue`"})}),getValue:(key)=>exports_Effect.tryPromise({try:()=>client.get(key),catch:(e)=>new RedisError({cause:e,message:"Error in `Redis.getValue`"})}),del:(key)=>exports_Effect.tryPromise({try:()=>client.del(key),catch:(e)=>new RedisError({cause:e,message:"Error in `Redis.del`"})}),exists:(key)=>exports_Effect.tryPromise({try:async()=>{return await client.exists(key)===1},catch:(e)=>new RedisError({cause:e,message:"Error in `Redis.exists`"})}),sAdd:(key,members)=>exports_Effect.tryPromise({try:()=>client.sAdd(key,members),catch:(e)=>new RedisError({cause:e,message:"Error in `Redis.sAdd`"})})})}),bootstrapRedisPubSubServiceEffect=exports_Effect.gen(function*(){let clientPublish=yield*redisClientEffect,clientSubscribe=yield*redisClientEffect;return RedisPubSub.of({publish:(channel,message)=>exports_Effect.tryPromise({try:()=>clientPublish.publish(channel,message),catch:(e)=>new RedisError({cause:e,message:"Error in `Redis.publish`"})}),subscribe:(channel,handler)=>exports_Effect.tryPromise({try:()=>clientSubscribe.subscribe(channel,handler),catch:(e)=>new RedisError({cause:e,message:"Error in `Redis.subscribe`"})})})}),bootstrapRedisStreamServiceEffect=exports_Effect.gen(function*(){let clientProducer=yield*redisClientEffect,clientConsumer=yield*redisClientEffect;return RedisStream.of({xadd:(key,id,message)=>exports_Effect.tryPromise({try:async()=>{return await clientProducer.xAdd(key,id,message)},catch:(e)=>new RedisError({cause:e,message:"Error in `RedisStream.xadd`"})}),xread:(key,id,block,count)=>exports_Effect.tryPromise({try:async()=>{let options={};if(block!==void 0)options.BLOCK=block;if(count!==void 0)options.COUNT=count;let streams=[{key,id}],result=await clientConsumer.xRead(streams,options);if(!result)return[];if(!Array.isArray(result))return[];return result.flatMap((stream)=>{if(stream&&typeof stream==="object"&&"messages"in stream&&Array.isArray(stream.messages))return stream.messages.map((msg)=>{if(msg&&typeof msg==="object"&&"id"in msg)return{id:String(msg.id),message:msg.message};return{id:"",message:{}}});return[]})},catch:(e)=>new RedisError({cause:e,message:"Error in `RedisStream.xread`"})}),xrange:(key,start3,end3,count)=>exports_Effect.tryPromise({try:async()=>{let options={};if(count!==void 0)options.COUNT=count;return(await clientConsumer.xRange(key,start3,end3,options)).map((msg)=>({id:msg.id,message:msg.message}))},catch:(e)=>new RedisError({cause:e,message:"Error in `RedisStream.xrange`"})})})}),RedisConnectionOptionsLive=(options)=>exports_Layer.succeed(RedisConnectionOptions,RedisConnectionOptions.of({options})),RedisLive=exports_Layer.scoped(Redis,bootstrapRedisServiceEffect),RedisPubSubLive=exports_Layer.scoped(RedisPubSub,bootstrapRedisPubSubServiceEffect),RedisPersistenceLive=exports_Layer.scoped(RedisPersistence,bootstrapRedisPersistenceServiceEffect),RedisStreamLive=exports_Layer.scoped(RedisStream,bootstrapRedisStreamServiceEffect);export{RedisStreamLive,RedisStream,RedisPubSubLive,RedisPubSub,RedisPersistenceLive,RedisPersistence,RedisLive,RedisError,RedisConnectionOptionsLive,RedisConnectionOptions,Redis};
32
+ ${endStackCall}`,cache}},opts=options.spanOptions&&"captureStackTrace"in options.spanOptions?options.spanOptions:{captureStackTrace,...options.spanOptions};return withSpan3(effect,options.spanName,opts)}var fnUntraced2=fnUntraced,ensureSuccessType=()=>(effect)=>effect,ensureErrorType=()=>(effect)=>effect,ensureRequirementsType=()=>(effect)=>effect;var exports_Layer={};__export(exports_Layer,{zipWith:()=>zipWith5,withSpan:()=>withSpan4,withParentSpan:()=>withParentSpan4,updateService:()=>updateService3,unwrapScoped:()=>unwrapScoped2,unwrapEffect:()=>unwrapEffect2,toRuntimeWithMemoMap:()=>toRuntimeWithMemoMap2,toRuntime:()=>toRuntime2,tapErrorCause:()=>tapErrorCause4,tapError:()=>tapError4,tap:()=>tap4,syncContext:()=>syncContext2,sync:()=>sync4,suspend:()=>suspend4,succeedContext:()=>succeedContext2,succeed:()=>succeed7,span:()=>span3,setVersionMismatchErrorLogLevel:()=>setVersionMismatchErrorLogLevel,setUnhandledErrorLogLevel:()=>setUnhandledErrorLogLevel,setTracerTiming:()=>setTracerTiming,setTracerEnabled:()=>setTracerEnabled,setTracer:()=>setTracer2,setScheduler:()=>setScheduler,setRequestCaching:()=>setRequestCaching,setRequestCache:()=>setRequestCache,setRequestBatching:()=>setRequestBatching,setRandom:()=>setRandom,setConfigProvider:()=>setConfigProvider2,setClock:()=>setClock,service:()=>service2,scopedDiscard:()=>scopedDiscard2,scopedContext:()=>scopedContext2,scoped:()=>scoped3,scope:()=>scope4,retry:()=>retry3,provideMerge:()=>provideMerge2,provide:()=>provide3,project:()=>project2,passthrough:()=>passthrough3,parentSpan:()=>parentSpan2,orElse:()=>orElse4,orDie:()=>orDie4,mock:()=>mock2,mergeAll:()=>mergeAll6,merge:()=>merge8,memoize:()=>memoize3,matchCause:()=>matchCause4,match:()=>match11,mapError:()=>mapError4,map:()=>map12,makeMemoMap:()=>makeMemoMap2,locallyWith:()=>locallyWith2,locallyScoped:()=>locallyScoped2,locallyEffect:()=>locallyEffect2,locally:()=>locally2,launch:()=>launch2,isLayer:()=>isLayer2,isFresh:()=>isFresh2,function:()=>fromFunction2,fresh:()=>fresh2,flatten:()=>flatten8,flatMap:()=>flatMap11,fiberRefLocallyScopedWith:()=>fiberRefLocallyScopedWith3,failSync:()=>failSync4,failCauseSync:()=>failCauseSync4,failCause:()=>failCause6,fail:()=>fail7,extendScope:()=>extendScope2,empty:()=>empty28,effectDiscard:()=>effectDiscard,effectContext:()=>effectContext,effect:()=>effect,discard:()=>discard2,dieSync:()=>dieSync4,die:()=>die6,context:()=>context4,catchAllCause:()=>catchAllCause4,catchAll:()=>catchAll4,buildWithScope:()=>buildWithScope2,buildWithMemoMap:()=>buildWithMemoMap2,build:()=>build2,annotateSpans:()=>annotateSpans4,annotateLogs:()=>annotateLogs4,MemoMapTypeId:()=>MemoMapTypeId2,LayerTypeId:()=>LayerTypeId2,CurrentMemoMap:()=>CurrentMemoMap2});var setConfigProvider=(configProvider)=>scopedDiscard(withConfigProviderScoped(configProvider)),parentSpan=(span2)=>succeedContext(make5(spanTag,span2)),span2=(name,options)=>{return options=addSpanStackTrace(options),scoped(spanTag,options?.onEnd?tap(makeSpanScoped(name,options),(span3)=>addFinalizer((exit3)=>options.onEnd(span3,exit3))):makeSpanScoped(name,options))},setTracer=(tracer3)=>scopedDiscard(withTracerScoped(tracer3));var LayerTypeId2=LayerTypeId,MemoMapTypeId2=MemoMapTypeId,CurrentMemoMap2=CurrentMemoMap,isLayer2=isLayer,isFresh2=isFresh,annotateLogs4=annotateLogs2,annotateSpans4=annotateSpans2,build2=build,buildWithScope2=buildWithScope,catchAll4=catchAll2,catchAllCause4=catchAllCause2,context4=context2,die6=die4,dieSync4=dieSync2,discard2=discard,effect=fromEffect2,effectDiscard=fromEffectDiscard,effectContext=fromEffectContext,empty28=empty27,extendScope2=extendScope,fail7=fail4,failSync4=failSync2,failCause6=failCause3,failCauseSync4=failCauseSync2,flatMap11=flatMap9,flatten8=flatten6,fresh2=fresh,mock2=mock,fromFunction2=fromFunction;var launch2=launch,map12=map9,mapError4=mapError2,match11=match9,matchCause4=matchCause2,memoize3=memoize2,merge8=merge6,mergeAll6=mergeAll4,orDie4=orDie2,orElse4=orElse2,passthrough3=passthrough,project2=project,locallyEffect2=locallyEffect,locally2=fiberRefLocally2,locallyWith2=fiberRefLocallyWith2,locallyScoped2=fiberRefLocallyScoped2,fiberRefLocallyScopedWith3=fiberRefLocallyScopedWith2,retry3=retry,scope4=scope2,scoped3=scoped,scopedDiscard2=scopedDiscard,scopedContext2=scopedContext,service2=service,succeed7=succeed4,succeedContext2=succeedContext,suspend4=suspend2,sync4=sync2,syncContext2=syncContext,tap4=tap2,tapError4=tapError2,tapErrorCause4=tapErrorCause2,toRuntime2=toRuntime,toRuntimeWithMemoMap2=toRuntimeWithMemoMap,provide3=provide,provideMerge2=provideMerge,zipWith5=zipWith3,unwrapEffect2=unwrapEffect,unwrapScoped2=unwrapScoped,setClock=(clock3)=>scopedDiscard2(fiberRefLocallyScopedWith(currentServices,add2(clockTag,clock3))),setConfigProvider2=setConfigProvider,parentSpan2=parentSpan,setRandom=(random4)=>scopedDiscard2(fiberRefLocallyScopedWith(currentServices,add2(randomTag,random4))),setRequestBatching=(requestBatching)=>scopedDiscard2(fiberRefLocallyScoped(currentRequestBatching,requestBatching)),setRequestCaching=(requestCaching)=>scopedDiscard2(fiberRefLocallyScoped(currentCacheEnabled,requestCaching)),setRequestCache=(cache)=>scopedDiscard2(isEffect(cache)?flatMap7(cache,(x)=>fiberRefLocallyScoped(currentCache,x)):fiberRefLocallyScoped(currentCache,cache)),setScheduler=(scheduler)=>scopedDiscard2(fiberRefLocallyScoped(currentScheduler,scheduler)),span3=span2,setTracer2=setTracer,setTracerEnabled=(enabled2)=>scopedDiscard2(fiberRefLocallyScoped(currentTracerEnabled,enabled2)),setTracerTiming=(enabled2)=>scopedDiscard2(fiberRefLocallyScoped(currentTracerTimingEnabled,enabled2)),setUnhandledErrorLogLevel=(level)=>scopedDiscard2(fiberRefLocallyScoped(currentUnhandledErrorLogLevel,level)),setVersionMismatchErrorLogLevel=(level)=>scopedDiscard2(fiberRefLocallyScoped(currentVersionMismatchErrorLogLevel,level)),withSpan4=withSpan2,withParentSpan4=withParentSpan2,makeMemoMap2=makeMemoMap,buildWithMemoMap2=buildWithMemoMap,updateService3=dual(3,(layer,tag,f)=>provide3(layer,map12(context4(),(c)=>add2(c,tag,f(unsafeGet3(c,tag))))));var import_redis=__toESM(require_dist2(),1);class RedisConnectionError extends exports_Data.TaggedError("RedisConnectionError"){}class RedisCommandError extends exports_Data.TaggedError("RedisCommandError"){}class RedisGeneralError extends exports_Data.TaggedError("RedisGeneralError"){}class RedisConnectionOptions extends exports_Context.Tag("RedisConnectionOptions")(){}class Redis extends exports_Context.Tag("Redis")(){}class RedisPubSub extends exports_Context.Tag("RedisPubSub")(){}class RedisPersistence extends exports_Context.Tag("RedisPersistence")(){}class RedisStream extends exports_Context.Tag("RedisStream")(){}var redisClientEffect=exports_Effect.gen(function*(){let{options,createClient:createClientFromContext}=yield*RedisConnectionOptions,create=createClientFromContext??import_redis.createClient;return yield*exports_Effect.acquireRelease(exports_Effect.tryPromise({try:()=>create(options).connect().then((r)=>{return console.log("Connected to Redis"),r.on("error",(e)=>{console.log("Redis error(on error):",e.message),r.destroy()}),r.on("end",()=>{console.log("Connection to Redis ended")}),r}),catch:(e)=>new RedisConnectionError({cause:e,message:"Error while connecting to Redis"})}),(client,_exit)=>exports_Effect.tryPromise(()=>{return console.log("Cleaning up Redis connection"),client.close()}).pipe(exports_Effect.catchAll(()=>exports_Effect.void)))}),toRedisError=(error)=>{let message=error instanceof Error?error.message:String(error);if(error instanceof Error){let maybeErrno=error,code=typeof maybeErrno.code==="string"?maybeErrno.code:void 0;if(code!==void 0&&new Set(["ECONNREFUSED","ETIMEDOUT","ECONNRESET","EPIPE","ENOTFOUND","ENETUNREACH","EHOSTUNREACH","EAI_AGAIN"]).has(code)||message.toLowerCase().includes("socket")||message.toLowerCase().includes("connect")||message.toLowerCase().includes("connection"))return new RedisConnectionError({cause:error,message});if(["WRONGTYPE","NOAUTH","WRONGPASS","NOPERM","READONLY","MOVED","ASK","NOSCRIPT","BUSY","ERR"].some((marker)=>message.startsWith(marker)))return new RedisCommandError({cause:error,message,command:"Unknown"})}return new RedisGeneralError({cause:error,message})},bootstrapRedisServiceEffect=exports_Effect.gen(function*(){let client=yield*redisClientEffect;return Redis.of({use:(fn2)=>exports_Effect.gen(function*(){let result=yield*exports_Effect.try({try:()=>fn2(client),catch:(e)=>new RedisCommandError({cause:e,message:"Synchronous error in `Redis.use`",command:"Unknown"})});if(result instanceof Promise)return yield*exports_Effect.tryPromise({try:()=>result,catch:(e)=>new RedisCommandError({cause:e,message:"Asynchronous error in `Redis.use`",command:"Unknown"})});return result}),get:(key)=>exports_Effect.tryPromise({try:()=>client.get(key),catch:toRedisError}),set:(key,value,options)=>exports_Effect.tryPromise({try:()=>{if(!options)return client.set(key,value);let setOptions={};if(options.expiration)setOptions[options.expiration.mode]=options.expiration.time;if(options.condition)setOptions[options.condition]=!0;if(options.get)setOptions.GET=!0;return Object.keys(setOptions).length>0?client.set(key,value,setOptions):client.set(key,value)},catch:toRedisError}),del:(...keys3)=>exports_Effect.tryPromise({try:()=>client.del(keys3),catch:toRedisError}),exists:(...keys3)=>exports_Effect.tryPromise({try:()=>client.exists(keys3),catch:toRedisError}),expire:(key,seconds2)=>exports_Effect.tryPromise({try:()=>client.expire(key,seconds2),catch:toRedisError}),ttl:(key)=>exports_Effect.tryPromise({try:()=>client.ttl(key),catch:toRedisError}),pexpire:(key,milliseconds)=>exports_Effect.tryPromise({try:()=>client.pExpire(key,milliseconds),catch:toRedisError}),pttl:(key)=>exports_Effect.tryPromise({try:()=>client.pTTL(key),catch:toRedisError}),hset:(key,field,value)=>exports_Effect.tryPromise({try:()=>client.hSet(key,field,value),catch:toRedisError}),hget:(key,field)=>exports_Effect.tryPromise({try:()=>client.hGet(key,field),catch:toRedisError}),hgetall:(key)=>exports_Effect.tryPromise({try:()=>client.hGetAll(key),catch:toRedisError}),hdel:(key,...fields)=>exports_Effect.tryPromise({try:()=>client.hDel(key,fields),catch:toRedisError}),hexists:(key,field)=>exports_Effect.tryPromise({try:async()=>await client.hExists(key,field)===1,catch:toRedisError}),hkeys:(key)=>exports_Effect.tryPromise({try:()=>client.hKeys(key),catch:toRedisError}),hvals:(key)=>exports_Effect.tryPromise({try:()=>client.hVals(key),catch:toRedisError}),hlen:(key)=>exports_Effect.tryPromise({try:()=>client.hLen(key),catch:toRedisError}),lpush:(key,...values3)=>exports_Effect.tryPromise({try:()=>client.lPush(key,values3),catch:toRedisError}),rpush:(key,...values3)=>exports_Effect.tryPromise({try:()=>client.rPush(key,values3),catch:toRedisError}),lpop:(key,count)=>exports_Effect.tryPromise({try:async()=>{if(count!==void 0)return client.lPopCount(key,count);return client.lPop(key)},catch:toRedisError}),rpop:(key,count)=>exports_Effect.tryPromise({try:async()=>{if(count!==void 0)return client.rPopCount(key,count);return client.rPop(key)},catch:toRedisError}),lrange:(key,start3,stop)=>exports_Effect.tryPromise({try:()=>client.lRange(key,start3,stop),catch:toRedisError}),llen:(key)=>exports_Effect.tryPromise({try:()=>client.lLen(key),catch:toRedisError}),lrem:(key,count,element)=>exports_Effect.tryPromise({try:()=>client.lRem(key,count,element),catch:toRedisError}),sadd:(key,...members)=>exports_Effect.tryPromise({try:()=>client.sAdd(key,members),catch:toRedisError}),srem:(key,...members)=>exports_Effect.tryPromise({try:()=>client.sRem(key,members),catch:toRedisError}),sismember:(key,member)=>exports_Effect.tryPromise({try:async()=>await client.sIsMember(key,member)===1,catch:toRedisError}),smembers:(key)=>exports_Effect.tryPromise({try:()=>client.sMembers(key),catch:toRedisError}),scard:(key)=>exports_Effect.tryPromise({try:()=>client.sCard(key),catch:toRedisError}),zadd:(key,score,member,...rest)=>{let members=[{score,value:member}];for(let i=0;i<rest.length;i+=2)members.push({score:rest[i],value:rest[i+1]});return exports_Effect.tryPromise({try:()=>client.zAdd(key,members),catch:toRedisError})},zrange:(key,start3,stop,withScores)=>exports_Effect.tryPromise({try:async()=>{if(withScores)return client.zRangeWithScores(key,start3,stop);return client.zRange(key,start3,stop)},catch:toRedisError}),zrangebyscore:(key,min3,max5,withScores)=>exports_Effect.tryPromise({try:async()=>{if(withScores)return client.zRangeByScoreWithScores(key,min3,max5);return client.zRangeByScore(key,min3,max5)},catch:toRedisError}),zscore:(key,member)=>exports_Effect.tryPromise({try:()=>client.zScore(key,member),catch:toRedisError}),zrem:(key,...members)=>exports_Effect.tryPromise({try:()=>client.zRem(key,members),catch:toRedisError}),zcard:(key)=>exports_Effect.tryPromise({try:()=>client.zCard(key),catch:toRedisError}),incr:(key)=>exports_Effect.tryPromise({try:()=>client.incr(key),catch:toRedisError}),decr:(key)=>exports_Effect.tryPromise({try:()=>client.decr(key),catch:toRedisError}),incrby:(key,increment)=>exports_Effect.tryPromise({try:()=>client.incrBy(key,increment),catch:toRedisError}),decrby:(key,decrement)=>exports_Effect.tryPromise({try:()=>client.decrBy(key,decrement),catch:toRedisError}),scan:(options)=>exports_Effect.tryPromise({try:async()=>{let scanOptions={};if(options?.match)scanOptions.MATCH=options.match;if(options?.count)scanOptions.COUNT=options.count;if(options?.type)scanOptions.TYPE=options.type;let result=await client.scan(String(options?.cursor??"0"),scanOptions);return{cursor:String(result.cursor),keys:result.keys}},catch:toRedisError}),flushdb:()=>exports_Effect.tryPromise({try:async()=>{return await client.flushDb(),"OK"},catch:toRedisError}),flushall:()=>exports_Effect.tryPromise({try:async()=>{return await client.flushAll(),"OK"},catch:toRedisError}),dbsize:()=>exports_Effect.tryPromise({try:()=>client.dbSize(),catch:toRedisError}),ping:(message)=>exports_Effect.tryPromise({try:async()=>{return await(message?client.ping(message):client.ping())},catch:toRedisError}),execute:(command,...args2)=>exports_Effect.tryPromise({try:()=>client.sendCommand([command,...args2.map((a)=>String(a))]),catch:toRedisError}),multi:(commands)=>exports_Effect.tryPromise({try:async()=>{let multi=client.multi();for(let[cmd,...args2]of commands)multi.addCommand([cmd,...args2.map((a)=>String(a))]);return multi.exec()},catch:toRedisError}),quit:()=>exports_Effect.tryPromise({try:async()=>{return await client.quit(),"OK"},catch:toRedisError}),disconnect:()=>exports_Effect.tryPromise({try:()=>client.disconnect(),catch:toRedisError})})}),bootstrapRedisPersistenceServiceEffect=exports_Effect.gen(function*(){let client=yield*redisClientEffect;return RedisPersistence.of({setValue:(key,value)=>exports_Effect.tryPromise({try:()=>client.set(key,value),catch:(e)=>new RedisCommandError({cause:e,message:"Error in `Redis.setValue`",command:"SET"})}),getValue:(key)=>exports_Effect.tryPromise({try:()=>client.get(key),catch:(e)=>new RedisCommandError({cause:e,message:"Error in `Redis.getValue`",command:"GET"})}),del:(key)=>exports_Effect.tryPromise({try:()=>client.del(key),catch:(e)=>new RedisCommandError({cause:e,message:"Error in `Redis.del`",command:"DEL"})}),exists:(key)=>exports_Effect.tryPromise({try:async()=>{return await client.exists(key)===1},catch:(e)=>new RedisCommandError({cause:e,message:"Error in `Redis.exists`",command:"EXISTS"})}),sAdd:(key,members)=>exports_Effect.tryPromise({try:()=>client.sAdd(key,members),catch:(e)=>new RedisCommandError({cause:e,message:"Error in `Redis.sAdd`",command:"SADD"})})})}),bootstrapRedisPubSubServiceEffect=exports_Effect.gen(function*(){let clientPublish=yield*redisClientEffect,clientSubscribe=yield*redisClientEffect;return RedisPubSub.of({publish:(channel,message)=>exports_Effect.tryPromise({try:()=>clientPublish.publish(channel,message),catch:(e)=>new RedisCommandError({cause:e,message:"Error in `Redis.publish`",command:"PUBLISH"})}),subscribe:(channel,handler)=>exports_Effect.tryPromise({try:()=>clientSubscribe.subscribe(channel,handler),catch:(e)=>new RedisCommandError({cause:e,message:"Error in `Redis.subscribe`",command:"SUBSCRIBE"})})})}),bootstrapRedisStreamServiceEffect=exports_Effect.gen(function*(){let clientProducer=yield*redisClientEffect,clientConsumer=yield*redisClientEffect;return RedisStream.of({xadd:(key,id,message)=>exports_Effect.tryPromise({try:async()=>{return await clientProducer.xAdd(key,id,message)},catch:(e)=>new RedisCommandError({cause:e,message:"Error in `RedisStream.xadd`",command:"XADD"})}),xread:(key,id,block,count)=>exports_Effect.tryPromise({try:async()=>{let options={};if(block!==void 0)options.BLOCK=block;if(count!==void 0)options.COUNT=count;let streams=[{key,id}],result=await clientConsumer.xRead(streams,options);if(!result)return[];if(!Array.isArray(result))return[];return result.flatMap((stream)=>{if(stream&&typeof stream==="object"&&"messages"in stream&&Array.isArray(stream.messages))return stream.messages.map((msg)=>{if(msg&&typeof msg==="object"&&"id"in msg)return{id:String(msg.id),message:msg.message};return{id:"",message:{}}});return[]})},catch:(e)=>new RedisCommandError({cause:e,message:"Error in `RedisStream.xread`",command:"XREAD"})}),xrange:(key,start3,end3,count)=>exports_Effect.tryPromise({try:async()=>{let options={};if(count!==void 0)options.COUNT=count;return(await clientConsumer.xRange(key,start3,end3,options)).map((msg)=>({id:msg.id,message:msg.message}))},catch:(e)=>new RedisCommandError({cause:e,message:"Error in `RedisStream.xrange`",command:"XRANGE"})})})}),RedisConnectionOptionsLive=(options,createClientOverride)=>exports_Layer.succeed(RedisConnectionOptions,RedisConnectionOptions.of({options,createClient:createClientOverride})),RedisLive=exports_Layer.scoped(Redis,bootstrapRedisServiceEffect),RedisPubSubLive=exports_Layer.scoped(RedisPubSub,bootstrapRedisPubSubServiceEffect),RedisPersistenceLive=exports_Layer.scoped(RedisPersistence,bootstrapRedisPersistenceServiceEffect),RedisStreamLive=exports_Layer.scoped(RedisStream,bootstrapRedisStreamServiceEffect);export{toRedisError,RedisStreamLive,RedisStream,RedisPubSubLive,RedisPubSub,RedisPersistenceLive,RedisPersistence,RedisLive,RedisConnectionOptionsLive,RedisConnectionOptions,Redis};
package/dist/redis.d.ts CHANGED
@@ -1,13 +1,6 @@
1
1
  import { Context, Effect, Layer } from 'effect';
2
2
  import { type RedisArgument, createClient } from 'redis';
3
- declare const RedisError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
4
- readonly _tag: "RedisError";
5
- } & Readonly<A>;
6
- export declare class RedisError extends RedisError_base<{
7
- cause: unknown;
8
- message: string;
9
- }> {
10
- }
3
+ import type { KeyOptions, RedisError, RedisHashValue, RedisListValue, RedisSetMember, RedisValue, ScanOptions, ScanResult } from './types';
11
4
  interface RedisConnectionOptionsShape {
12
5
  options?: Parameters<typeof createClient>[0];
13
6
  }
@@ -15,7 +8,201 @@ declare const RedisConnectionOptions_base: Context.TagClass<RedisConnectionOptio
15
8
  declare class RedisConnectionOptions extends RedisConnectionOptions_base {
16
9
  }
17
10
  interface RedisShape {
18
- use: <T>(fn: (client: ReturnType<typeof createClient>) => T) => Effect.Effect<Awaited<T>, RedisError, never>;
11
+ readonly use: <T>(fn: (client: ReturnType<typeof createClient>) => T) => Effect.Effect<Awaited<T>, RedisError, never>;
12
+ /**
13
+ * Get value by key
14
+ */
15
+ readonly get: (key: string) => Effect.Effect<string | null, RedisError>;
16
+ /**
17
+ * Set value by key
18
+ */
19
+ readonly set: (key: string, value: RedisValue, options?: KeyOptions) => Effect.Effect<'OK' | string | null, RedisError>;
20
+ /**
21
+ * Delete key(s)
22
+ */
23
+ readonly del: (...keys: string[]) => Effect.Effect<number, RedisError>;
24
+ /**
25
+ * Check if key exists
26
+ */
27
+ readonly exists: (...keys: string[]) => Effect.Effect<number, RedisError>;
28
+ /**
29
+ * Set expiration for key
30
+ */
31
+ readonly expire: (key: string, seconds: number) => Effect.Effect<number, RedisError>;
32
+ /**
33
+ * Set expiration for key in milliseconds
34
+ */
35
+ readonly pexpire: (key: string, milliseconds: number) => Effect.Effect<number, RedisError>;
36
+ /**
37
+ * Get TTL for key in seconds
38
+ */
39
+ readonly ttl: (key: string) => Effect.Effect<number, RedisError>;
40
+ /**
41
+ * Get TTL for key in milliseconds
42
+ */
43
+ readonly pttl: (key: string) => Effect.Effect<number, RedisError>;
44
+ /**
45
+ * Hash operations - Set field in hash
46
+ */
47
+ readonly hset: (key: string, field: string, value: RedisHashValue) => Effect.Effect<number, RedisError>;
48
+ /**
49
+ * Hash operations - Get field from hash
50
+ */
51
+ readonly hget: (key: string, field: string) => Effect.Effect<string | null, RedisError>;
52
+ /**
53
+ * Hash operations - Get all fields and values from hash
54
+ */
55
+ readonly hgetall: (key: string) => Effect.Effect<Record<string, string>, RedisError>;
56
+ /**
57
+ * Hash operations - Delete field(s) from hash
58
+ */
59
+ readonly hdel: (key: string, ...fields: string[]) => Effect.Effect<number, RedisError>;
60
+ /**
61
+ * Hash operations - Check if field exists in hash
62
+ */
63
+ readonly hexists: (key: string, field: string) => Effect.Effect<boolean, RedisError>;
64
+ /**
65
+ * Hash operations - Get all fields from hash
66
+ */
67
+ readonly hkeys: (key: string) => Effect.Effect<string[], RedisError>;
68
+ /**
69
+ * Hash operations - Get all values from hash
70
+ */
71
+ readonly hvals: (key: string) => Effect.Effect<string[], RedisError>;
72
+ /**
73
+ * Hash operations - Get number of fields in hash
74
+ */
75
+ readonly hlen: (key: string) => Effect.Effect<number, RedisError>;
76
+ /**
77
+ * List operations - Push value(s) to left of list
78
+ */
79
+ readonly lpush: (key: string, ...values: RedisListValue[]) => Effect.Effect<number, RedisError>;
80
+ /**
81
+ * List operations - Push value(s) to right of list
82
+ */
83
+ readonly rpush: (key: string, ...values: RedisListValue[]) => Effect.Effect<number, RedisError>;
84
+ /**
85
+ * List operations - Pop value from left of list
86
+ */
87
+ readonly lpop: (key: string, count?: number) => Effect.Effect<string | string[] | null, RedisError>;
88
+ /**
89
+ * List operations - Pop value from right of list
90
+ */
91
+ readonly rpop: (key: string, count?: number) => Effect.Effect<string | string[] | null, RedisError>;
92
+ /**
93
+ * List operations - Get range of elements from list
94
+ */
95
+ readonly lrange: (key: string, start: number, stop: number) => Effect.Effect<string[], RedisError>;
96
+ /**
97
+ * List operations - Get length of list
98
+ */
99
+ readonly llen: (key: string) => Effect.Effect<number, RedisError>;
100
+ /**
101
+ * List operations - Remove elements from list
102
+ */
103
+ readonly lrem: (key: string, count: number, element: RedisListValue) => Effect.Effect<number, RedisError>;
104
+ /**
105
+ * Set operations - Add member(s) to set
106
+ */
107
+ readonly sadd: (key: string, ...members: RedisSetMember[]) => Effect.Effect<number, RedisError>;
108
+ /**
109
+ * Set operations - Remove member(s) from set
110
+ */
111
+ readonly srem: (key: string, ...members: RedisSetMember[]) => Effect.Effect<number, RedisError>;
112
+ /**
113
+ * Set operations - Check if member is in set
114
+ */
115
+ readonly sismember: (key: string, member: RedisSetMember) => Effect.Effect<boolean, RedisError>;
116
+ /**
117
+ * Set operations - Get all members of set
118
+ */
119
+ readonly smembers: (key: string) => Effect.Effect<string[], RedisError>;
120
+ /**
121
+ * Set operations - Get number of members in set
122
+ */
123
+ readonly scard: (key: string) => Effect.Effect<number, RedisError>;
124
+ /**
125
+ * Sorted Set operations - Add member(s) to sorted set
126
+ */
127
+ readonly zadd: (key: string, score: number, member: string, ...rest: Array<number | string>) => Effect.Effect<number, RedisError>;
128
+ /**
129
+ * Sorted Set operations - Get range of members from sorted set
130
+ */
131
+ readonly zrange: (key: string, start: number, stop: number, withScores?: boolean) => Effect.Effect<string[] | {
132
+ value: string;
133
+ score: number;
134
+ }[], RedisError>;
135
+ /**
136
+ * Sorted Set operations - Get range of members by score
137
+ */
138
+ readonly zrangebyscore: (key: string, min: number | string, max: number | string, withScores?: boolean) => Effect.Effect<string[] | {
139
+ value: string;
140
+ score: number;
141
+ }[], RedisError>;
142
+ /**
143
+ * Sorted Set operations - Get score of member
144
+ */
145
+ readonly zscore: (key: string, member: string) => Effect.Effect<number | null, RedisError>;
146
+ /**
147
+ * Sorted Set operations - Remove member(s) from sorted set
148
+ */
149
+ readonly zrem: (key: string, ...members: string[]) => Effect.Effect<number, RedisError>;
150
+ /**
151
+ * Sorted Set operations - Get number of members in sorted set
152
+ */
153
+ readonly zcard: (key: string) => Effect.Effect<number, RedisError>;
154
+ /**
155
+ * Increment value
156
+ */
157
+ readonly incr: (key: string) => Effect.Effect<number, RedisError>;
158
+ /**
159
+ * Decrement value
160
+ */
161
+ readonly decr: (key: string) => Effect.Effect<number, RedisError>;
162
+ /**
163
+ * Increment value by amount
164
+ */
165
+ readonly incrby: (key: string, increment: number) => Effect.Effect<number, RedisError>;
166
+ /**
167
+ * Decrement value by amount
168
+ */
169
+ readonly decrby: (key: string, decrement: number) => Effect.Effect<number, RedisError>;
170
+ /**
171
+ * Scan keys
172
+ */
173
+ readonly scan: (options?: ScanOptions) => Effect.Effect<ScanResult, RedisError>;
174
+ /**
175
+ * Flush database
176
+ */
177
+ readonly flushdb: () => Effect.Effect<'OK', RedisError>;
178
+ /**
179
+ * Flush all databases
180
+ */
181
+ readonly flushall: () => Effect.Effect<'OK', RedisError>;
182
+ /**
183
+ * Get database size
184
+ */
185
+ readonly dbsize: () => Effect.Effect<number, RedisError>;
186
+ /**
187
+ * Ping Redis
188
+ */
189
+ readonly ping: (message?: string) => Effect.Effect<string, RedisError>;
190
+ /**
191
+ * Execute raw Redis command
192
+ */
193
+ readonly execute: <A>(command: string, ...args: (string | number | Buffer)[]) => Effect.Effect<A, RedisError>;
194
+ /**
195
+ * Multi/exec transaction
196
+ */
197
+ readonly multi: (commands: Array<[string, ...(string | number | Buffer)[]]>) => Effect.Effect<unknown[], RedisError>;
198
+ /**
199
+ * Close connection
200
+ */
201
+ readonly quit: () => Effect.Effect<'OK', RedisError>;
202
+ /**
203
+ * Force close connection
204
+ */
205
+ readonly disconnect: () => Effect.Effect<void, RedisError>;
19
206
  }
20
207
  declare const Redis_base: Context.TagClass<Redis, "Redis", RedisShape>;
21
208
  declare class Redis extends Redis_base {
@@ -0,0 +1 @@
1
+ export * from './redis';
@@ -0,0 +1,257 @@
1
+ import { Context, Effect, Layer } from 'effect';
2
+ import { type RedisArgument, createClient } from 'redis';
3
+ import type { KeyOptions, RedisError, RedisHashValue, RedisListValue, RedisSetMember, RedisValue, ScanOptions, ScanResult } from './types';
4
+ interface RedisConnectionOptionsShape {
5
+ options?: Parameters<typeof createClient>[0];
6
+ createClient?: (options?: Parameters<typeof createClient>[0]) => ReturnType<typeof createClient>;
7
+ }
8
+ declare const RedisConnectionOptions_base: Context.TagClass<RedisConnectionOptions, "RedisConnectionOptions", RedisConnectionOptionsShape>;
9
+ declare class RedisConnectionOptions extends RedisConnectionOptions_base {
10
+ }
11
+ interface RedisShape {
12
+ readonly use: <T>(fn: (client: ReturnType<typeof createClient>) => T) => Effect.Effect<Awaited<T>, RedisError, never>;
13
+ /**
14
+ * Get value by key
15
+ */
16
+ readonly get: (key: string) => Effect.Effect<string | null, RedisError>;
17
+ /**
18
+ * Set value by key
19
+ */
20
+ readonly set: (key: string, value: RedisValue, options?: KeyOptions) => Effect.Effect<'OK' | string | null, RedisError>;
21
+ /**
22
+ * Delete key(s)
23
+ */
24
+ readonly del: (...keys: string[]) => Effect.Effect<number, RedisError>;
25
+ /**
26
+ * Check if key exists
27
+ */
28
+ readonly exists: (...keys: string[]) => Effect.Effect<number, RedisError>;
29
+ /**
30
+ * Set expiration for key
31
+ */
32
+ readonly expire: (key: string, seconds: number) => Effect.Effect<number, RedisError>;
33
+ /**
34
+ * Set expiration for key in milliseconds
35
+ */
36
+ readonly pexpire: (key: string, milliseconds: number) => Effect.Effect<number, RedisError>;
37
+ /**
38
+ * Get TTL for key in seconds
39
+ */
40
+ readonly ttl: (key: string) => Effect.Effect<number, RedisError>;
41
+ /**
42
+ * Get TTL for key in milliseconds
43
+ */
44
+ readonly pttl: (key: string) => Effect.Effect<number, RedisError>;
45
+ /**
46
+ * Hash operations - Set field in hash
47
+ */
48
+ readonly hset: (key: string, field: string, value: RedisHashValue) => Effect.Effect<number, RedisError>;
49
+ /**
50
+ * Hash operations - Get field from hash
51
+ */
52
+ readonly hget: (key: string, field: string) => Effect.Effect<string | null, RedisError>;
53
+ /**
54
+ * Hash operations - Get all fields and values from hash
55
+ */
56
+ readonly hgetall: (key: string) => Effect.Effect<Record<string, string>, RedisError>;
57
+ /**
58
+ * Hash operations - Delete field(s) from hash
59
+ */
60
+ readonly hdel: (key: string, ...fields: string[]) => Effect.Effect<number, RedisError>;
61
+ /**
62
+ * Hash operations - Check if field exists in hash
63
+ */
64
+ readonly hexists: (key: string, field: string) => Effect.Effect<boolean, RedisError>;
65
+ /**
66
+ * Hash operations - Get all fields from hash
67
+ */
68
+ readonly hkeys: (key: string) => Effect.Effect<string[], RedisError>;
69
+ /**
70
+ * Hash operations - Get all values from hash
71
+ */
72
+ readonly hvals: (key: string) => Effect.Effect<string[], RedisError>;
73
+ /**
74
+ * Hash operations - Get number of fields in hash
75
+ */
76
+ readonly hlen: (key: string) => Effect.Effect<number, RedisError>;
77
+ /**
78
+ * List operations - Push value(s) to left of list
79
+ */
80
+ readonly lpush: (key: string, ...values: RedisListValue[]) => Effect.Effect<number, RedisError>;
81
+ /**
82
+ * List operations - Push value(s) to right of list
83
+ */
84
+ readonly rpush: (key: string, ...values: RedisListValue[]) => Effect.Effect<number, RedisError>;
85
+ /**
86
+ * List operations - Pop value from left of list
87
+ */
88
+ readonly lpop: (key: string, count?: number) => Effect.Effect<string | string[] | null, RedisError>;
89
+ /**
90
+ * List operations - Pop value from right of list
91
+ */
92
+ readonly rpop: (key: string, count?: number) => Effect.Effect<string | string[] | null, RedisError>;
93
+ /**
94
+ * List operations - Get range of elements from list
95
+ */
96
+ readonly lrange: (key: string, start: number, stop: number) => Effect.Effect<string[], RedisError>;
97
+ /**
98
+ * List operations - Get length of list
99
+ */
100
+ readonly llen: (key: string) => Effect.Effect<number, RedisError>;
101
+ /**
102
+ * List operations - Remove elements from list
103
+ */
104
+ readonly lrem: (key: string, count: number, element: RedisListValue) => Effect.Effect<number, RedisError>;
105
+ /**
106
+ * Set operations - Add member(s) to set
107
+ */
108
+ readonly sadd: (key: string, ...members: RedisSetMember[]) => Effect.Effect<number, RedisError>;
109
+ /**
110
+ * Set operations - Remove member(s) from set
111
+ */
112
+ readonly srem: (key: string, ...members: RedisSetMember[]) => Effect.Effect<number, RedisError>;
113
+ /**
114
+ * Set operations - Check if member is in set
115
+ */
116
+ readonly sismember: (key: string, member: RedisSetMember) => Effect.Effect<boolean, RedisError>;
117
+ /**
118
+ * Set operations - Get all members of set
119
+ */
120
+ readonly smembers: (key: string) => Effect.Effect<string[], RedisError>;
121
+ /**
122
+ * Set operations - Get number of members in set
123
+ */
124
+ readonly scard: (key: string) => Effect.Effect<number, RedisError>;
125
+ /**
126
+ * Sorted Set operations - Add member(s) to sorted set
127
+ */
128
+ readonly zadd: (key: string, score: number, member: string, ...rest: Array<number | string>) => Effect.Effect<number, RedisError>;
129
+ /**
130
+ * Sorted Set operations - Get range of members from sorted set
131
+ */
132
+ readonly zrange: (key: string, start: number, stop: number, withScores?: boolean) => Effect.Effect<string[] | {
133
+ value: string;
134
+ score: number;
135
+ }[], RedisError>;
136
+ /**
137
+ * Sorted Set operations - Get range of members by score
138
+ */
139
+ readonly zrangebyscore: (key: string, min: number | string, max: number | string, withScores?: boolean) => Effect.Effect<string[] | {
140
+ value: string;
141
+ score: number;
142
+ }[], RedisError>;
143
+ /**
144
+ * Sorted Set operations - Get score of member
145
+ */
146
+ readonly zscore: (key: string, member: string) => Effect.Effect<number | null, RedisError>;
147
+ /**
148
+ * Sorted Set operations - Remove member(s) from sorted set
149
+ */
150
+ readonly zrem: (key: string, ...members: string[]) => Effect.Effect<number, RedisError>;
151
+ /**
152
+ * Sorted Set operations - Get number of members in sorted set
153
+ */
154
+ readonly zcard: (key: string) => Effect.Effect<number, RedisError>;
155
+ /**
156
+ * Increment value
157
+ */
158
+ readonly incr: (key: string) => Effect.Effect<number, RedisError>;
159
+ /**
160
+ * Decrement value
161
+ */
162
+ readonly decr: (key: string) => Effect.Effect<number, RedisError>;
163
+ /**
164
+ * Increment value by amount
165
+ */
166
+ readonly incrby: (key: string, increment: number) => Effect.Effect<number, RedisError>;
167
+ /**
168
+ * Decrement value by amount
169
+ */
170
+ readonly decrby: (key: string, decrement: number) => Effect.Effect<number, RedisError>;
171
+ /**
172
+ * Scan keys
173
+ */
174
+ readonly scan: (options?: ScanOptions) => Effect.Effect<ScanResult, RedisError>;
175
+ /**
176
+ * Flush database
177
+ */
178
+ readonly flushdb: () => Effect.Effect<'OK', RedisError>;
179
+ /**
180
+ * Flush all databases
181
+ */
182
+ readonly flushall: () => Effect.Effect<'OK', RedisError>;
183
+ /**
184
+ * Get database size
185
+ */
186
+ readonly dbsize: () => Effect.Effect<number, RedisError>;
187
+ /**
188
+ * Ping Redis
189
+ */
190
+ readonly ping: (message?: string) => Effect.Effect<string, RedisError>;
191
+ /**
192
+ * Execute raw Redis command
193
+ */
194
+ readonly execute: <A>(command: string, ...args: (string | number | Buffer)[]) => Effect.Effect<A, RedisError>;
195
+ /**
196
+ * Multi/exec transaction
197
+ */
198
+ readonly multi: (commands: Array<[string, ...(string | number | Buffer)[]]>) => Effect.Effect<unknown[], RedisError>;
199
+ /**
200
+ * Close connection
201
+ */
202
+ readonly quit: () => Effect.Effect<'OK', RedisError>;
203
+ /**
204
+ * Force close connection
205
+ */
206
+ readonly disconnect: () => Effect.Effect<void, RedisError>;
207
+ }
208
+ declare const Redis_base: Context.TagClass<Redis, "Redis", RedisShape>;
209
+ declare class Redis extends Redis_base {
210
+ }
211
+ interface RedisPubSubShape {
212
+ publish: (channel: string, message: string) => Effect.Effect<void, RedisError, never>;
213
+ subscribe: (channel: string, handler: (message: string) => void) => Effect.Effect<void, RedisError, never>;
214
+ }
215
+ declare const RedisPubSub_base: Context.TagClass<RedisPubSub, "RedisPubSub", RedisPubSubShape>;
216
+ declare class RedisPubSub extends RedisPubSub_base {
217
+ }
218
+ interface RedisPersistenceShape {
219
+ setValue: (key: string, value: string) => Effect.Effect<void, RedisError, never>;
220
+ getValue: (key: string) => Effect.Effect<string | null, RedisError, never>;
221
+ del: (key: string) => Effect.Effect<number, RedisError, never>;
222
+ exists: (key: string) => Effect.Effect<boolean, RedisError, never>;
223
+ sAdd: (key: string, members: string[]) => Effect.Effect<void, RedisError, never>;
224
+ }
225
+ declare const RedisPersistence_base: Context.TagClass<RedisPersistence, "RedisPersistence", RedisPersistenceShape>;
226
+ declare class RedisPersistence extends RedisPersistence_base {
227
+ }
228
+ export interface StreamEntry {
229
+ id: RedisArgument;
230
+ message: Record<string, string>;
231
+ }
232
+ interface RedisStreamShape {
233
+ xadd: (key: RedisArgument, // Stream key name
234
+ id: RedisArgument | '*', // Entry ID or '*' for auto-generation
235
+ message: Record<string, RedisArgument>) => Effect.Effect<string, RedisError, never>;
236
+ xread: (key: RedisArgument, // Stream key to read from
237
+ id: RedisArgument, // Start reading from this ID ('$' for new entries only)
238
+ block?: number, // Block in milliseconds (0 for indefinite wait)
239
+ count?: number) => Effect.Effect<StreamEntry[], RedisError, never>;
240
+ xrange: (key: RedisArgument, // Stream key name
241
+ start: RedisArgument, // Start ID ('-' for earliest available)
242
+ end: RedisArgument, // End ID ('+' for latest available)
243
+ count?: number) => Effect.Effect<StreamEntry[], RedisError, never>;
244
+ }
245
+ declare const RedisStream_base: Context.TagClass<RedisStream, "RedisStream", RedisStreamShape>;
246
+ declare class RedisStream extends RedisStream_base {
247
+ }
248
+ /**
249
+ * Helper function to convert Redis errors to Effect errors
250
+ */
251
+ export declare const toRedisError: (error: unknown) => RedisError;
252
+ declare const RedisConnectionOptionsLive: (options?: Parameters<typeof createClient>[0], createClientOverride?: (options?: Parameters<typeof createClient>[0]) => ReturnType<typeof createClient>) => Layer.Layer<RedisConnectionOptions, never, never>;
253
+ declare const RedisLive: Layer.Layer<Redis, RedisError, RedisConnectionOptions>;
254
+ declare const RedisPubSubLive: Layer.Layer<RedisPubSub, RedisError, RedisConnectionOptions>;
255
+ declare const RedisPersistenceLive: Layer.Layer<RedisPersistence, RedisError, RedisConnectionOptions>;
256
+ declare const RedisStreamLive: Layer.Layer<RedisStream, RedisError, RedisConnectionOptions>;
257
+ export { Redis, RedisConnectionOptions, RedisConnectionOptionsLive, RedisLive, RedisPersistence, RedisPersistenceLive, RedisPubSub, RedisPubSubLive, RedisStream, RedisStreamLive, };
@@ -0,0 +1,93 @@
1
+ /** biome-ignore-all lint/correctness/noUnusedVariables: <explanation */
2
+ /** biome-ignore-all lint/suspicious/noEmptyInterface: <explanation */
3
+ /**
4
+ * Common Redis value types
5
+ */
6
+ export type RedisValue = string | number | Buffer;
7
+ /**
8
+ * Redis hash field types
9
+ */
10
+ export type RedisHashValue = string | number | Buffer | Record<string, string | number | Buffer>;
11
+ /**
12
+ * Redis set member types
13
+ */
14
+ export type RedisSetMember = string | Buffer;
15
+ /**
16
+ * Redis sorted set member with score
17
+ */
18
+ export interface SortedSetMember {
19
+ member: string;
20
+ score: number;
21
+ }
22
+ /**
23
+ * Redis list value types
24
+ */
25
+ export type RedisListValue = string | number | Buffer;
26
+ /**
27
+ * Redis key with optional options
28
+ */
29
+ export interface KeyOptions {
30
+ readonly expiration?: {
31
+ mode: 'EX' | 'PX' | 'EXAT' | 'PXAT';
32
+ time: number;
33
+ };
34
+ readonly condition?: 'NX' | 'XX';
35
+ readonly get?: boolean;
36
+ }
37
+ export type ScanOptions = {
38
+ readonly cursor?: string;
39
+ readonly match?: string;
40
+ readonly count?: number;
41
+ readonly type?: string;
42
+ };
43
+ export type ScanResult = {
44
+ readonly cursor: string;
45
+ readonly keys: ReadonlyArray<string>;
46
+ };
47
+ /**
48
+ * Get options
49
+ */
50
+ export interface GetOptions {
51
+ readonly ex?: number;
52
+ readonly px?: number;
53
+ readonly exat?: number;
54
+ readonly pxat?: number;
55
+ readonly persist?: boolean;
56
+ }
57
+ /**
58
+ * Set range result
59
+ */
60
+ export interface SetRangeResult {
61
+ readonly previousValue: string | null;
62
+ readonly length: number;
63
+ }
64
+ declare const RedisConnectionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
65
+ readonly _tag: "RedisConnectionError";
66
+ } & Readonly<A>;
67
+ /*****************************************************************
68
+ * Error Types
69
+ *****************************************************************/
70
+ export declare class RedisConnectionError extends RedisConnectionError_base<{
71
+ readonly cause: unknown;
72
+ readonly message: string;
73
+ }> {
74
+ }
75
+ declare const RedisCommandError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
76
+ readonly _tag: "RedisCommandError";
77
+ } & Readonly<A>;
78
+ export declare class RedisCommandError extends RedisCommandError_base<{
79
+ readonly cause: unknown;
80
+ readonly message: string;
81
+ readonly command: string;
82
+ }> {
83
+ }
84
+ declare const RedisGeneralError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
85
+ readonly _tag: "RedisGeneralError";
86
+ } & Readonly<A>;
87
+ export declare class RedisGeneralError extends RedisGeneralError_base<{
88
+ readonly cause: unknown;
89
+ readonly message: string;
90
+ }> {
91
+ }
92
+ export type RedisError = RedisConnectionError | RedisCommandError | RedisGeneralError;
93
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
1
+ /** biome-ignore-all lint/correctness/noUnusedVariables: <explanation */
2
+ /** biome-ignore-all lint/suspicious/noEmptyInterface: <explanation */
3
+ /**
4
+ * Common Redis value types
5
+ */
6
+ export type RedisValue = string | number | Buffer;
7
+ /**
8
+ * Redis hash field types
9
+ */
10
+ export type RedisHashValue = string | number | Buffer | Record<string, string | number | Buffer>;
11
+ /**
12
+ * Redis set member types
13
+ */
14
+ export type RedisSetMember = string | Buffer;
15
+ /**
16
+ * Redis sorted set member with score
17
+ */
18
+ export interface SortedSetMember {
19
+ member: string;
20
+ score: number;
21
+ }
22
+ /**
23
+ * Redis list value types
24
+ */
25
+ export type RedisListValue = string | number | Buffer;
26
+ /**
27
+ * Redis key with optional options
28
+ */
29
+ export interface KeyOptions {
30
+ readonly expiration?: {
31
+ mode: 'EX' | 'PX' | 'EXAT' | 'PXAT';
32
+ time: number;
33
+ };
34
+ readonly condition?: 'NX' | 'XX';
35
+ readonly get?: boolean;
36
+ }
37
+ export type ScanOptions = {
38
+ readonly cursor?: string;
39
+ readonly match?: string;
40
+ readonly count?: number;
41
+ readonly type?: string;
42
+ };
43
+ export type ScanResult = {
44
+ readonly cursor: string;
45
+ readonly keys: ReadonlyArray<string>;
46
+ };
47
+ /**
48
+ * Get options
49
+ */
50
+ export interface GetOptions {
51
+ readonly ex?: number;
52
+ readonly px?: number;
53
+ readonly exat?: number;
54
+ readonly pxat?: number;
55
+ readonly persist?: boolean;
56
+ }
57
+ /**
58
+ * Set range result
59
+ */
60
+ export interface SetRangeResult {
61
+ readonly previousValue: string | null;
62
+ readonly length: number;
63
+ }
64
+ declare const RedisConnectionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
65
+ readonly _tag: "RedisConnectionError";
66
+ } & Readonly<A>;
67
+ /*****************************************************************
68
+ * Error Types
69
+ *****************************************************************/
70
+ export declare class RedisConnectionError extends RedisConnectionError_base<{
71
+ readonly cause: unknown;
72
+ readonly message: string;
73
+ }> {
74
+ }
75
+ declare const RedisCommandError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
76
+ readonly _tag: "RedisCommandError";
77
+ } & Readonly<A>;
78
+ export declare class RedisCommandError extends RedisCommandError_base<{
79
+ readonly cause: unknown;
80
+ readonly message: string;
81
+ readonly command: string;
82
+ }> {
83
+ }
84
+ declare const RedisGeneralError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
85
+ readonly _tag: "RedisGeneralError";
86
+ } & Readonly<A>;
87
+ export declare class RedisGeneralError extends RedisGeneralError_base<{
88
+ readonly cause: unknown;
89
+ readonly message: string;
90
+ }> {
91
+ }
92
+ export type RedisError = RedisConnectionError | RedisCommandError | RedisGeneralError;
93
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-redis",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Simple Effect wrapper for Redis.",
5
5
  "module": "dist/index.js",
6
6
  "main": "dist/index.js",
@@ -21,6 +21,8 @@
21
21
  },
22
22
  "devDependencies": {
23
23
  "@biomejs/biome": "^2.3.8",
24
+ "@effect/language-service": "^0.62.5",
25
+ "@effect/vitest": "^0.27.0",
24
26
  "@types/bun": "latest",
25
27
  "vitest": "^4.0.14"
26
28
  },