effect-redis 0.0.7 → 0.0.8
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 +5 -5
- package/dist/src/redis.d.ts +1 -0
- package/package.json +15 -12
- package/src/redis.ts +25 -6
package/dist/src/redis.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ declare class RedisPubSub extends RedisPubSub_base {
|
|
|
30
30
|
}
|
|
31
31
|
interface RedisPersistenceShape {
|
|
32
32
|
setValue: (key: string, value: string) => Effect.Effect<void, RedisError, never>;
|
|
33
|
+
sAdd: (key: string, members: string[]) => Effect.Effect<void, RedisError, never>;
|
|
33
34
|
}
|
|
34
35
|
declare const RedisPersistence_base: Context.TagClass<RedisPersistence, "RedisPersistence", RedisPersistenceShape>;
|
|
35
36
|
declare class RedisPersistence extends RedisPersistence_base {
|
package/package.json
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-redis",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Simple Effect wrapper for Redis.",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
|
-
"files": [
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"prepublishOnly": "bun run build",
|
|
15
|
-
"test": "bun test",
|
|
16
|
-
"format": "biome format --write ./src",
|
|
17
|
-
"lint": "biome lint ."
|
|
18
|
-
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"src",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
19
14
|
"devDependencies": {
|
|
20
15
|
"@biomejs/biome": "^1.9.4",
|
|
21
16
|
"@types/bun": "latest"
|
|
@@ -27,5 +22,13 @@
|
|
|
27
22
|
},
|
|
28
23
|
"dependencies": {
|
|
29
24
|
"@effect/platform-bun": "^0.69.2"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build:main": "bun build --minify-syntax --minify-whitespace ./src/index.ts --outdir ./dist --target node --format esm",
|
|
28
|
+
"build:types": "bun tsc --emitDeclarationOnly --outDir dist",
|
|
29
|
+
"build": "bun run build:main && bun run build:types",
|
|
30
|
+
"test": "bun test",
|
|
31
|
+
"format": "biome format --write ./src",
|
|
32
|
+
"lint": "biome lint ."
|
|
30
33
|
}
|
|
31
|
-
}
|
|
34
|
+
}
|
package/src/redis.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context, Data, Effect, Layer } from 'effect';
|
|
1
|
+
import { Context, Data, Effect, Layer, type Scope } from 'effect';
|
|
2
2
|
import { type RedisArgument, createClient } from 'redis';
|
|
3
3
|
|
|
4
4
|
export class RedisError extends Data.TaggedError('RedisError')<{
|
|
@@ -52,6 +52,10 @@ interface RedisPersistenceShape {
|
|
|
52
52
|
key: string,
|
|
53
53
|
value: string,
|
|
54
54
|
) => Effect.Effect<void, RedisError, never>;
|
|
55
|
+
sAdd: (
|
|
56
|
+
key: string,
|
|
57
|
+
members: string[],
|
|
58
|
+
) => Effect.Effect<void, RedisError, never>;
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
class RedisPersistence extends Context.Tag('RedisPersistence')<
|
|
@@ -96,7 +100,11 @@ class RedisStream extends Context.Tag('RedisStream')<
|
|
|
96
100
|
>() {}
|
|
97
101
|
|
|
98
102
|
// Common code for redis client creation
|
|
99
|
-
const redisClientEffect
|
|
103
|
+
const redisClientEffect: Effect.Effect<
|
|
104
|
+
ReturnType<typeof createClient>,
|
|
105
|
+
RedisError,
|
|
106
|
+
Scope.Scope | RedisConnectionOptions
|
|
107
|
+
> = Effect.gen(function* () {
|
|
100
108
|
const { options } = yield* RedisConnectionOptions;
|
|
101
109
|
|
|
102
110
|
return yield* Effect.acquireRelease(
|
|
@@ -131,7 +139,7 @@ const redisClientEffect = Effect.gen(function* () {
|
|
|
131
139
|
});
|
|
132
140
|
|
|
133
141
|
const bootstrapRedisServiceEffect = Effect.gen(function* () {
|
|
134
|
-
const client = yield* redisClientEffect;
|
|
142
|
+
const client: ReturnType<typeof createClient> = yield* redisClientEffect;
|
|
135
143
|
return Redis.of({
|
|
136
144
|
use: (fn) =>
|
|
137
145
|
Effect.gen(function* () {
|
|
@@ -161,7 +169,7 @@ const bootstrapRedisServiceEffect = Effect.gen(function* () {
|
|
|
161
169
|
const RedisLive = Layer.scoped(Redis, bootstrapRedisServiceEffect);
|
|
162
170
|
|
|
163
171
|
const bootstrapRedisPersistenceServiceEffect = Effect.gen(function* () {
|
|
164
|
-
const client = yield* redisClientEffect;
|
|
172
|
+
const client: ReturnType<typeof createClient> = yield* redisClientEffect;
|
|
165
173
|
|
|
166
174
|
return RedisPersistence.of({
|
|
167
175
|
setValue: (key, value) =>
|
|
@@ -173,6 +181,15 @@ const bootstrapRedisPersistenceServiceEffect = Effect.gen(function* () {
|
|
|
173
181
|
message: 'Error in `Redis.setValue`',
|
|
174
182
|
}),
|
|
175
183
|
}),
|
|
184
|
+
sAdd: (key, members) =>
|
|
185
|
+
Effect.tryPromise({
|
|
186
|
+
try: () => client.sAdd(key, members),
|
|
187
|
+
catch: (e) =>
|
|
188
|
+
new RedisError({
|
|
189
|
+
cause: e,
|
|
190
|
+
message: 'Error in `Redis.sAdd`',
|
|
191
|
+
}),
|
|
192
|
+
}),
|
|
176
193
|
});
|
|
177
194
|
});
|
|
178
195
|
|
|
@@ -182,8 +199,10 @@ const RedisPersistenceLive = Layer.scoped(
|
|
|
182
199
|
);
|
|
183
200
|
|
|
184
201
|
const bootstrapRedisPubSubServiceEffect = Effect.gen(function* () {
|
|
185
|
-
const clientPublish
|
|
186
|
-
|
|
202
|
+
const clientPublish: ReturnType<typeof createClient> =
|
|
203
|
+
yield* redisClientEffect;
|
|
204
|
+
const clientSubscribe: ReturnType<typeof createClient> =
|
|
205
|
+
yield* redisClientEffect;
|
|
187
206
|
|
|
188
207
|
return RedisPubSub.of({
|
|
189
208
|
publish: (channel, message) =>
|