effect-redis 0.0.26 → 0.0.28

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.
@@ -4,7 +4,7 @@ import type { RedisError } from '../types';
4
4
  import { type RedisConnectionOptions } from './connection';
5
5
  export interface StreamEntry {
6
6
  id: RedisArgument;
7
- message: Record<string, string>;
7
+ data: Record<string, string>;
8
8
  }
9
9
  export interface StreamSubscribeOptions {
10
10
  readonly id?: string;
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
- {
2
- "name": "effect-redis",
3
- "version": "0.0.26",
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": [
10
- "dist",
11
- "README.md",
12
- "src"
13
- ],
14
- "scripts": {
15
- "build:main": "bun build --minify-syntax --minify-whitespace ./src/index.ts --outdir ./dist --target node --format esm",
16
- "build:types": "bun tsc --emitDeclarationOnly --outdir ./dist",
17
- "build": "bun run build:main && bun run build:types",
18
- "prepublishOnly": "bun run build",
19
- "test": "vitest run --passWithNoTests",
20
- "format": "biome format --write ./src",
21
- "lint": "biome lint ."
22
- },
23
- "devDependencies": {
24
- "@biomejs/biome": "catalog:",
25
- "@effect/language-service": "catalog:",
26
- "@effect/vitest": "^0.27.0",
27
- "@redis/bloom": "^5.10.0",
28
- "@redis/client": "^5.10.0",
29
- "@redis/json": "^5.10.0",
30
- "@redis/search": "^5.10.0",
31
- "@redis/time-series": "^5.10.0",
32
- "@types/bun": "latest",
33
- "@types/node": "^25.0.3",
34
- "fast-check": "^4.5.3",
35
- "vitest": "catalog:"
36
- },
37
- "peerDependencies": {
38
- "redis": "^5.1.0",
39
- "typescript": "^5"
40
- },
41
- "dependencies": {
42
- "@effect/experimental": "catalog:",
43
- "@effect/platform-bun": "catalog:",
44
- "effect": "catalog:"
45
- }
46
- }
1
+ {
2
+ "name": "effect-redis",
3
+ "version": "0.0.28",
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": [
10
+ "dist",
11
+ "README.md",
12
+ "src"
13
+ ],
14
+ "scripts": {
15
+ "build:main": "bun build --minify-syntax --minify-whitespace ./src/index.ts --outdir ./dist --target node --format esm",
16
+ "build:types": "bun tsc --emitDeclarationOnly --outdir ./dist",
17
+ "build": "bun run build:main && bun run build:types",
18
+ "prepublishOnly": "bun run build",
19
+ "test": "vitest run --passWithNoTests",
20
+ "format": "biome format --write ./src",
21
+ "lint": "biome lint ."
22
+ },
23
+ "devDependencies": {
24
+ "@biomejs/biome": "catalog:",
25
+ "@effect/language-service": "catalog:",
26
+ "@effect/vitest": "^0.27.0",
27
+ "@redis/bloom": "^5.10.0",
28
+ "@redis/client": "^5.10.0",
29
+ "@redis/json": "^5.10.0",
30
+ "@redis/search": "^5.10.0",
31
+ "@redis/time-series": "^5.10.0",
32
+ "@types/bun": "latest",
33
+ "@types/node": "^25.0.3",
34
+ "fast-check": "^4.5.3",
35
+ "vitest": "catalog:"
36
+ },
37
+ "peerDependencies": {
38
+ "redis": "^5.1.0",
39
+ "typescript": "^5"
40
+ },
41
+ "dependencies": {
42
+ "@effect/experimental": "catalog:",
43
+ "@effect/platform-bun": "catalog:",
44
+ "effect": "catalog:"
45
+ }
46
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- // Re-export all Redis services and utilities from the modular structure
2
- export * from './redis';
3
-
4
- // Re-export types
5
- export * from './types';
1
+ // Re-export all Redis services and utilities from the modular structure
2
+ export * from './redis';
3
+
4
+ // Re-export types
5
+ export * from './types';
@@ -1,91 +1,91 @@
1
- import { Context, Effect, Layer, type Scope } from 'effect';
2
- import { createClient } from 'redis';
3
- import type { RedisClient } from './helpers';
4
- export type { RedisClient };
5
- import type { RedisError } from '../types';
6
- import { RedisConnectionError } from '../types';
7
-
8
- // https://d.pr/i/eRkNx2
9
- import type {} from '@redis/client';
10
- import type {} from '@redis/json';
11
- import type {} from '@redis/search';
12
- import type {} from '@redis/time-series';
13
- import type {} from '@redis/bloom';
14
-
15
- // Shape interface for Redis connection configuration options
16
- // Uses Parameters to extract the constructor options type from createClient
17
- export interface RedisConnectionOptionsShape {
18
- readonly options?: Parameters<typeof createClient>[0] | undefined;
19
- readonly createClient?:
20
- | ((
21
- options?: Parameters<typeof createClient>[0],
22
- ) => ReturnType<typeof createClient>)
23
- | undefined;
24
- }
25
-
26
- // Context tag for dependency injection of Redis connection options
27
- // Allows configuration to be provided through Effect's dependency injection system
28
- export class RedisConnectionOptions extends Context.Tag(
29
- 'RedisConnectionOptions',
30
- )<RedisConnectionOptions, RedisConnectionOptionsShape>() {}
31
-
32
- // Context tag for a managed Redis client
33
- // This allows sharing a single Redis connection across multiple services
34
- export class RedisConnection extends Context.Tag('RedisConnection')<
35
- RedisConnection,
36
- RedisClient
37
- >() {}
38
-
39
- export const redisClientEffect: Effect.Effect<
40
- RedisClient,
41
- RedisError,
42
- Scope.Scope | RedisConnectionOptions
43
- > = Effect.gen(function* () {
44
- // Retrieve Redis connection options from the context
45
- const { options, createClient: createClientFromContext } =
46
- yield* RedisConnectionOptions;
47
- const create = createClientFromContext ?? createClient;
48
-
49
- // Create a managed Redis client with automatic resource cleanup
50
- return yield* Effect.acquireRelease(
51
- Effect.gen(function* () {
52
- yield* Effect.log('Connecting to Redis');
53
- const client = yield* Effect.tryPromise({
54
- try: () => create(options).connect(),
55
- catch: (error) =>
56
- new RedisConnectionError({
57
- cause: error,
58
- message: 'Error while connecting to Redis',
59
- }),
60
- });
61
-
62
- // Set up error handling/monitoring for the Redis connection
63
- client.on('error', (error) => {
64
- Effect.runSync(
65
- Effect.logError(`Redis connection error: ${error.message}`),
66
- );
67
- client.destroy();
68
- });
69
-
70
- client.on('end', () => {
71
- Effect.runSync(Effect.logInfo('Redis connection ended'));
72
- });
73
-
74
- return client;
75
- }),
76
- // Cleanup function: properly close Redis connection when scope exits
77
- (client) =>
78
- Effect.gen(function* () {
79
- yield* Effect.log('Cleaning up Redis connection');
80
- yield* Effect.tryPromise(() => client.close()).pipe(
81
- Effect.catchAll(() => Effect.void),
82
- );
83
- }),
84
- );
85
- });
86
-
87
- // Live layer for a shared Redis connection
88
- export const RedisConnectionLive = Layer.scoped(
89
- RedisConnection,
90
- redisClientEffect,
91
- );
1
+ import { Context, Effect, Layer, type Scope } from 'effect';
2
+ import { createClient } from 'redis';
3
+ import type { RedisClient } from './helpers';
4
+ export type { RedisClient };
5
+ import type { RedisError } from '../types';
6
+ import { RedisConnectionError } from '../types';
7
+
8
+ // https://d.pr/i/eRkNx2
9
+ import type {} from '@redis/client';
10
+ import type {} from '@redis/json';
11
+ import type {} from '@redis/search';
12
+ import type {} from '@redis/time-series';
13
+ import type {} from '@redis/bloom';
14
+
15
+ // Shape interface for Redis connection configuration options
16
+ // Uses Parameters to extract the constructor options type from createClient
17
+ export interface RedisConnectionOptionsShape {
18
+ readonly options?: Parameters<typeof createClient>[0] | undefined;
19
+ readonly createClient?:
20
+ | ((
21
+ options?: Parameters<typeof createClient>[0],
22
+ ) => ReturnType<typeof createClient>)
23
+ | undefined;
24
+ }
25
+
26
+ // Context tag for dependency injection of Redis connection options
27
+ // Allows configuration to be provided through Effect's dependency injection system
28
+ export class RedisConnectionOptions extends Context.Tag(
29
+ 'RedisConnectionOptions',
30
+ )<RedisConnectionOptions, RedisConnectionOptionsShape>() {}
31
+
32
+ // Context tag for a managed Redis client
33
+ // This allows sharing a single Redis connection across multiple services
34
+ export class RedisConnection extends Context.Tag('RedisConnection')<
35
+ RedisConnection,
36
+ RedisClient
37
+ >() {}
38
+
39
+ export const redisClientEffect: Effect.Effect<
40
+ RedisClient,
41
+ RedisError,
42
+ Scope.Scope | RedisConnectionOptions
43
+ > = Effect.gen(function* () {
44
+ // Retrieve Redis connection options from the context
45
+ const { options, createClient: createClientFromContext } =
46
+ yield* RedisConnectionOptions;
47
+ const create = createClientFromContext ?? createClient;
48
+
49
+ // Create a managed Redis client with automatic resource cleanup
50
+ return yield* Effect.acquireRelease(
51
+ Effect.gen(function* () {
52
+ yield* Effect.log('Connecting to Redis');
53
+ const client = yield* Effect.tryPromise({
54
+ try: () => create(options).connect(),
55
+ catch: (error) =>
56
+ new RedisConnectionError({
57
+ cause: error,
58
+ message: 'Error while connecting to Redis',
59
+ }),
60
+ });
61
+
62
+ // Set up error handling/monitoring for the Redis connection
63
+ client.on('error', (error) => {
64
+ Effect.runSync(
65
+ Effect.logError(`Redis connection error: ${error.message}`),
66
+ );
67
+ client.destroy();
68
+ });
69
+
70
+ client.on('end', () => {
71
+ Effect.runSync(Effect.logInfo('Redis connection ended'));
72
+ });
73
+
74
+ return client;
75
+ }),
76
+ // Cleanup function: properly close Redis connection when scope exits
77
+ (client) =>
78
+ Effect.gen(function* () {
79
+ yield* Effect.log('Cleaning up Redis connection');
80
+ yield* Effect.tryPromise(() => client.close()).pipe(
81
+ Effect.catchAll(() => Effect.void),
82
+ );
83
+ }),
84
+ );
85
+ });
86
+
87
+ // Live layer for a shared Redis connection
88
+ export const RedisConnectionLive = Layer.scoped(
89
+ RedisConnection,
90
+ redisClientEffect,
91
+ );