effect-redis 0.0.7 → 0.0.9

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.
@@ -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,31 +1,31 @@
1
- {
2
- "name": "effect-redis",
3
- "version": "0.0.7",
4
- "description": "Simple Effect wrapper for Redis.",
5
- "module": "dist/index.js",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "type": "module",
9
- "files": ["dist", "src", "README.md"],
10
- "scripts": {
11
- "build:main": "bun build --minify-syntax --minify-whitespace ./src/index.ts --outdir ./dist --target node --format esm",
12
- "build:types": "bun tsc --emitDeclarationOnly --outDir dist",
13
- "build": "bun run build:main && bun run build:types",
14
- "prepublishOnly": "bun run build",
15
- "test": "bun test",
16
- "format": "biome format --write ./src",
17
- "lint": "biome lint ."
18
- },
19
- "devDependencies": {
20
- "@biomejs/biome": "^1.9.4",
21
- "@types/bun": "latest"
22
- },
23
- "peerDependencies": {
24
- "effect": "^3.16.2",
25
- "redis": "^5.1.0",
26
- "typescript": "^5"
27
- },
28
- "dependencies": {
29
- "@effect/platform-bun": "^0.69.2"
30
- }
31
- }
1
+ {
2
+ "name": "effect-redis",
3
+ "version": "0.0.9",
4
+ "description": "Simple Effect wrapper for Redis.",
5
+ "module": "dist/index.js",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "type": "module",
9
+ "files": ["dist", "src", "README.md"],
10
+ "scripts": {
11
+ "build:main": "bun build --minify-syntax --minify-whitespace ./src/index.ts --outdir ./dist --target node --format esm",
12
+ "build:types": "bun tsc --emitDeclarationOnly --outDir dist",
13
+ "build": "bun run build:main && bun run build:types",
14
+ "prepublishOnly": "bun run build",
15
+ "test": "bun test",
16
+ "format": "biome format --write ./src",
17
+ "lint": "biome lint ."
18
+ },
19
+ "devDependencies": {
20
+ "@biomejs/biome": "^1.9.4",
21
+ "@types/bun": "latest"
22
+ },
23
+ "peerDependencies": {
24
+ "effect": "^3.16.2",
25
+ "redis": "^5.1.0",
26
+ "typescript": "^5"
27
+ },
28
+ "dependencies": {
29
+ "@effect/platform-bun": "^0.69.2"
30
+ }
31
+ }
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 = Effect.gen(function* () {
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 = yield* redisClientEffect;
186
- const clientSubscribe = yield* redisClientEffect;
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) =>
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './redis';
package/dist/redis.d.ts DELETED
@@ -1,40 +0,0 @@
1
- import { Context, Effect, Layer } from 'effect';
2
- import { 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
- }
11
- interface RedisConnectionOptionsShape {
12
- options?: Parameters<typeof createClient>[0];
13
- }
14
- declare const RedisConnectionOptions_base: Context.TagClass<RedisConnectionOptions, "RedisConnectionOptions", RedisConnectionOptionsShape>;
15
- declare class RedisConnectionOptions extends RedisConnectionOptions_base {
16
- }
17
- declare const RedisConnectionOptionsLive: (options?: Parameters<typeof createClient>[0]) => Layer.Layer<RedisConnectionOptions, never, never>;
18
- interface RedisShape {
19
- use: <T>(fn: (client: ReturnType<typeof createClient>) => T) => Effect.Effect<Awaited<T>, RedisError, never>;
20
- }
21
- declare const Redis_base: Context.TagClass<Redis, "Redis", RedisShape>;
22
- declare class Redis extends Redis_base {
23
- }
24
- declare const RedisLive: Layer.Layer<Redis, RedisError, RedisConnectionOptions>;
25
- interface RedisPubSubShape {
26
- publish: (channel: string, message: string) => Effect.Effect<void, RedisError, never>;
27
- subscribe: (channel: string, handler: (message: string) => void) => Effect.Effect<void, RedisError, never>;
28
- }
29
- declare const RedisPubSub_base: Context.TagClass<RedisPubSub, "RedisPubSub", RedisPubSubShape>;
30
- declare class RedisPubSub extends RedisPubSub_base {
31
- }
32
- interface RedisPersistenceShape {
33
- setValue: (key: string, value: string) => Effect.Effect<void, RedisError, never>;
34
- }
35
- declare const RedisPersistence_base: Context.TagClass<RedisPersistence, "RedisPersistence", RedisPersistenceShape>;
36
- declare class RedisPersistence extends RedisPersistence_base {
37
- }
38
- declare const RedisPersistenceLive: Layer.Layer<RedisPersistence, RedisError, RedisConnectionOptions>;
39
- declare const RedisPubSubLive: Layer.Layer<RedisPubSub, RedisError, RedisConnectionOptions>;
40
- export { RedisPersistence, RedisPubSub, RedisConnectionOptions, Redis, RedisPersistenceLive, RedisPubSubLive, RedisConnectionOptionsLive, RedisLive, };