@uploadista/event-broadcaster-redis 0.1.4-beta.1 → 0.2.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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- let e=require(`@uploadista/core/errors`),t=require(`@uploadista/core/types`),n=require(`effect`);function r(t){let{redis:r,subscriberRedis:i}=t;return i.on(`error`,e=>{console.error(`[Redis] Subscriber Error:`,e)}),r.on(`error`,e=>{console.error(`[Redis] Error:`,e)}),{publish:(t,i)=>n.Effect.tryPromise({try:async()=>await r.publish(t,i),catch:n=>(console.error(`[Redis] Failed to publish to ${t}:`,n),e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:n}))}).pipe(n.Effect.asVoid),subscribe:(t,r)=>n.Effect.tryPromise({try:async()=>{await i.subscribe(t,(e,t)=>{r(e)})},catch:n=>(console.error(`[Redis] Failed to subscribe to ${t}:`,n),e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:n}))}).pipe(n.Effect.asVoid),unsubscribe:t=>n.Effect.tryPromise({try:()=>i.unsubscribe(t),catch:t=>e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:t})}).pipe(n.Effect.asVoid)}}const i=e=>n.Layer.succeed(t.EventBroadcasterService,r(e));exports.createRedisEventBroadcaster=r,exports.redisEventBroadcaster=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@uploadista/core/errors`),t=require(`@uploadista/core/types`),n=require(`effect`);function r(t){let{redis:r,subscriberRedis:i}=t;return i.on(`error`,e=>{console.error(`[Redis] Subscriber Error:`,e)}),r.on(`error`,e=>{console.error(`[Redis] Error:`,e)}),{publish:(t,i)=>n.Effect.tryPromise({try:async()=>await r.publish(t,i),catch:n=>(console.error(`[Redis] Failed to publish to ${t}:`,n),e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:n}))}).pipe(n.Effect.asVoid),subscribe:(t,r)=>n.Effect.tryPromise({try:async()=>{await i.subscribe(t,(e,t)=>{r(e)})},catch:n=>(console.error(`[Redis] Failed to subscribe to ${t}:`,n),e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:n}))}).pipe(n.Effect.asVoid),unsubscribe:t=>n.Effect.tryPromise({try:()=>i.unsubscribe(t),catch:t=>e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:t})}).pipe(n.Effect.asVoid)}}const i=e=>n.Layer.succeed(t.EventBroadcasterService,r(e));exports.createRedisEventBroadcaster=r,exports.redisEventBroadcaster=i;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,13 @@
1
- import { RedisClientType } from "@redis/client";
2
1
  import { EventBroadcaster, EventBroadcasterService } from "@uploadista/core/types";
3
2
  import { Layer } from "effect";
4
3
 
5
4
  //#region src/redis-event-broadcaster.d.ts
5
+ interface RedisPubSubLike {
6
+ publish(channel: string, message: string): Promise<number>;
7
+ subscribe(channel: string, listener: (message: string, channel: string) => void): Promise<void>;
8
+ unsubscribe(channel: string): Promise<void>;
9
+ on(event: string, listener: (...args: unknown[]) => void): unknown;
10
+ }
6
11
  /**
7
12
  * Configuration for Redis event broadcaster
8
13
  */
@@ -10,12 +15,12 @@ interface RedisEventBroadcasterConfig {
10
15
  /**
11
16
  * Redis client for publishing messages
12
17
  */
13
- redis: RedisClientType;
18
+ redis: RedisPubSubLike;
14
19
  /**
15
20
  * Separate Redis client for subscribing to messages
16
21
  * (Redis requires a dedicated connection for pub/sub)
17
22
  */
18
- subscriberRedis: RedisClientType;
23
+ subscriberRedis: RedisPubSubLike;
19
24
  }
20
25
  /**
21
26
  * Redis-based event broadcaster for distributed deployments.
@@ -28,5 +33,5 @@ declare function createRedisEventBroadcaster(config: RedisEventBroadcasterConfig
28
33
  */
29
34
  declare const redisEventBroadcaster: (config: RedisEventBroadcasterConfig) => Layer.Layer<EventBroadcasterService, never, never>;
30
35
  //#endregion
31
- export { RedisEventBroadcasterConfig, createRedisEventBroadcaster, redisEventBroadcaster };
36
+ export { RedisEventBroadcasterConfig, RedisPubSubLike, createRedisEventBroadcaster, redisEventBroadcaster };
32
37
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/redis-event-broadcaster.ts"],"mappings":";;;;;;AASA;;UAAiB,2BAAA;EASiB;;;EALhC,KAAA,EAAO,eAAA;EAKU;;;AAQnB;EARE,eAAA,EAAiB,eAAA;AAAA;;;;;;iBAQH,2BAAA,CACd,MAAA,EAAQ,2BAAA,GACP,gBAAA;AAuDH;;;AAAA,cAAa,qBAAA,GAAyB,MAAA,EAAQ,2BAAA,KAA2B,KAAA,CAAA,KAAA,CAAA,uBAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/redis-event-broadcaster.ts"],"mappings":";;;;UAKiB,eAAA;EACf,OAAA,CAAQ,OAAA,UAAiB,OAAA,WAAkB,OAAA;EAC3C,SAAA,CACE,OAAA,UACA,QAAA,GAAW,OAAA,UAAiB,OAAA,oBAC3B,OAAA;EACH,WAAA,CAAY,OAAA,WAAkB,OAAA;EAC9B,EAAA,CAAG,KAAA,UAAe,QAAA,MAAc,IAAA;AAAA;;;;UAMjB,2BAAA;EAZP;;;EAgBR,KAAA,EAAO,eAAA;EAdL;;;;EAmBF,eAAA,EAAiB,eAAA;AAAA;;;;;;iBAQH,2BAAA,CACd,MAAA,EAAQ,2BAAA,GACP,gBAAA;;;AAnBH;cA0Ea,qBAAA,GAAyB,MAAA,EAAQ,2BAAA,KAA2B,KAAA,CAAA,KAAA,CAAA,uBAAA"}
package/dist/index.d.mts CHANGED
@@ -1,8 +1,13 @@
1
1
  import { EventBroadcaster, EventBroadcasterService } from "@uploadista/core/types";
2
2
  import { Layer } from "effect";
3
- import { RedisClientType } from "@redis/client";
4
3
 
5
4
  //#region src/redis-event-broadcaster.d.ts
5
+ interface RedisPubSubLike {
6
+ publish(channel: string, message: string): Promise<number>;
7
+ subscribe(channel: string, listener: (message: string, channel: string) => void): Promise<void>;
8
+ unsubscribe(channel: string): Promise<void>;
9
+ on(event: string, listener: (...args: unknown[]) => void): unknown;
10
+ }
6
11
  /**
7
12
  * Configuration for Redis event broadcaster
8
13
  */
@@ -10,12 +15,12 @@ interface RedisEventBroadcasterConfig {
10
15
  /**
11
16
  * Redis client for publishing messages
12
17
  */
13
- redis: RedisClientType;
18
+ redis: RedisPubSubLike;
14
19
  /**
15
20
  * Separate Redis client for subscribing to messages
16
21
  * (Redis requires a dedicated connection for pub/sub)
17
22
  */
18
- subscriberRedis: RedisClientType;
23
+ subscriberRedis: RedisPubSubLike;
19
24
  }
20
25
  /**
21
26
  * Redis-based event broadcaster for distributed deployments.
@@ -28,5 +33,5 @@ declare function createRedisEventBroadcaster(config: RedisEventBroadcasterConfig
28
33
  */
29
34
  declare const redisEventBroadcaster: (config: RedisEventBroadcasterConfig) => Layer.Layer<EventBroadcasterService, never, never>;
30
35
  //#endregion
31
- export { RedisEventBroadcasterConfig, createRedisEventBroadcaster, redisEventBroadcaster };
36
+ export { RedisEventBroadcasterConfig, RedisPubSubLike, createRedisEventBroadcaster, redisEventBroadcaster };
32
37
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/redis-event-broadcaster.ts"],"mappings":";;;;;;AASA;;UAAiB,2BAAA;EASiB;;;EALhC,KAAA,EAAO,eAAA;EAKU;;;AAQnB;EARE,eAAA,EAAiB,eAAA;AAAA;;;;;;iBAQH,2BAAA,CACd,MAAA,EAAQ,2BAAA,GACP,gBAAA;AAuDH;;;AAAA,cAAa,qBAAA,GAAyB,MAAA,EAAQ,2BAAA,KAA2B,KAAA,CAAA,KAAA,CAAA,uBAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/redis-event-broadcaster.ts"],"mappings":";;;;UAKiB,eAAA;EACf,OAAA,CAAQ,OAAA,UAAiB,OAAA,WAAkB,OAAA;EAC3C,SAAA,CACE,OAAA,UACA,QAAA,GAAW,OAAA,UAAiB,OAAA,oBAC3B,OAAA;EACH,WAAA,CAAY,OAAA,WAAkB,OAAA;EAC9B,EAAA,CAAG,KAAA,UAAe,QAAA,MAAc,IAAA;AAAA;;;;UAMjB,2BAAA;EAZP;;;EAgBR,KAAA,EAAO,eAAA;EAdL;;;;EAmBF,eAAA,EAAiB,eAAA;AAAA;;;;;;iBAQH,2BAAA,CACd,MAAA,EAAQ,2BAAA,GACP,gBAAA;;;AAnBH;cA0Ea,qBAAA,GAAyB,MAAA,EAAQ,2BAAA,KAA2B,KAAA,CAAA,KAAA,CAAA,uBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/redis-event-broadcaster.ts"],"sourcesContent":["import type { RedisClientType } from \"@redis/client\";\nimport { UploadistaError } from \"@uploadista/core/errors\";\nimport type { EventBroadcaster } from \"@uploadista/core/types\";\nimport { EventBroadcasterService } from \"@uploadista/core/types\";\nimport { Effect, Layer } from \"effect\";\n\n/**\n * Configuration for Redis event broadcaster\n */\nexport interface RedisEventBroadcasterConfig {\n /**\n * Redis client for publishing messages\n */\n redis: RedisClientType;\n /**\n * Separate Redis client for subscribing to messages\n * (Redis requires a dedicated connection for pub/sub)\n */\n subscriberRedis: RedisClientType;\n}\n\n/**\n * Redis-based event broadcaster for distributed deployments.\n * Uses Redis Pub/Sub to broadcast events across multiple instances.\n * Requires two separate Redis connections (one for pub, one for sub).\n */\nexport function createRedisEventBroadcaster(\n config: RedisEventBroadcasterConfig,\n): EventBroadcaster {\n const { redis, subscriberRedis } = config;\n\n subscriberRedis.on(\"error\", (error) => {\n console.error(`[Redis] Subscriber Error:`, error);\n });\n\n redis.on(\"error\", (error) => {\n console.error(`[Redis] Error:`, error);\n });\n\n return {\n publish: (channel: string, message: string) =>\n Effect.tryPromise({\n try: async () => {\n const result = await redis.publish(channel, message);\n return result;\n },\n catch: (cause) => {\n console.error(`[Redis] Failed to publish to ${channel}:`, cause);\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause,\n });\n },\n }).pipe(Effect.asVoid),\n\n subscribe: (channel: string, handler: (message: string) => void) =>\n Effect.tryPromise({\n try: async () => {\n await subscriberRedis.subscribe(channel, (message, _channel) => {\n handler(message);\n });\n },\n catch: (cause) => {\n console.error(`[Redis] Failed to subscribe to ${channel}:`, cause);\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause,\n });\n },\n }).pipe(Effect.asVoid),\n\n unsubscribe: (channel: string) =>\n Effect.tryPromise({\n try: () => subscriberRedis.unsubscribe(channel),\n catch: (cause) =>\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause,\n }),\n }).pipe(Effect.asVoid),\n };\n}\n\n/**\n * Layer factory for Redis event broadcaster\n */\nexport const redisEventBroadcaster = (config: RedisEventBroadcasterConfig) =>\n Layer.succeed(EventBroadcasterService, createRedisEventBroadcaster(config));\n"],"mappings":"sKA0BA,SAAgB,EACd,EACkB,CAClB,GAAM,CAAE,QAAO,mBAAoB,EAUnC,OARA,EAAgB,GAAG,QAAU,GAAU,CACrC,QAAQ,MAAM,4BAA6B,EAAM,EACjD,CAEF,EAAM,GAAG,QAAU,GAAU,CAC3B,QAAQ,MAAM,iBAAkB,EAAM,EACtC,CAEK,CACL,SAAU,EAAiB,IACzB,EAAO,WAAW,CAChB,IAAK,SACY,MAAM,EAAM,QAAQ,EAAS,EAAQ,CAGtD,MAAQ,IACN,QAAQ,MAAM,gCAAgC,EAAQ,GAAI,EAAM,CACzD,EAAgB,SAAS,gBAAiB,CAC/C,QACD,CAAC,EAEL,CAAC,CAAC,KAAK,EAAO,OAAO,CAExB,WAAY,EAAiB,IAC3B,EAAO,WAAW,CAChB,IAAK,SAAY,CACf,MAAM,EAAgB,UAAU,GAAU,EAAS,IAAa,CAC9D,EAAQ,EAAQ,EAChB,EAEJ,MAAQ,IACN,QAAQ,MAAM,kCAAkC,EAAQ,GAAI,EAAM,CAC3D,EAAgB,SAAS,gBAAiB,CAC/C,QACD,CAAC,EAEL,CAAC,CAAC,KAAK,EAAO,OAAO,CAExB,YAAc,GACZ,EAAO,WAAW,CAChB,QAAW,EAAgB,YAAY,EAAQ,CAC/C,MAAQ,GACN,EAAgB,SAAS,gBAAiB,CACxC,QACD,CAAC,CACL,CAAC,CAAC,KAAK,EAAO,OAAO,CACzB,CAMH,MAAa,EAAyB,GACpC,EAAM,QAAQ,EAAyB,EAA4B,EAAO,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/redis-event-broadcaster.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport type { EventBroadcaster } from \"@uploadista/core/types\";\nimport { EventBroadcasterService } from \"@uploadista/core/types\";\nimport { Effect, Layer } from \"effect\";\n\nexport interface RedisPubSubLike {\n publish(channel: string, message: string): Promise<number>;\n subscribe(\n channel: string,\n listener: (message: string, channel: string) => void,\n ): Promise<void>;\n unsubscribe(channel: string): Promise<void>;\n on(event: string, listener: (...args: unknown[]) => void): unknown;\n}\n\n/**\n * Configuration for Redis event broadcaster\n */\nexport interface RedisEventBroadcasterConfig {\n /**\n * Redis client for publishing messages\n */\n redis: RedisPubSubLike;\n /**\n * Separate Redis client for subscribing to messages\n * (Redis requires a dedicated connection for pub/sub)\n */\n subscriberRedis: RedisPubSubLike;\n}\n\n/**\n * Redis-based event broadcaster for distributed deployments.\n * Uses Redis Pub/Sub to broadcast events across multiple instances.\n * Requires two separate Redis connections (one for pub, one for sub).\n */\nexport function createRedisEventBroadcaster(\n config: RedisEventBroadcasterConfig,\n): EventBroadcaster {\n const { redis, subscriberRedis } = config;\n\n subscriberRedis.on(\"error\", (error) => {\n console.error(`[Redis] Subscriber Error:`, error);\n });\n\n redis.on(\"error\", (error) => {\n console.error(`[Redis] Error:`, error);\n });\n\n return {\n publish: (channel: string, message: string) =>\n Effect.tryPromise({\n try: async () => {\n const result = await redis.publish(channel, message);\n return result;\n },\n catch: (cause) => {\n console.error(`[Redis] Failed to publish to ${channel}:`, cause);\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause,\n });\n },\n }).pipe(Effect.asVoid),\n\n subscribe: (channel: string, handler: (message: string) => void) =>\n Effect.tryPromise({\n try: async () => {\n await subscriberRedis.subscribe(channel, (message, _channel) => {\n handler(message);\n });\n },\n catch: (cause) => {\n console.error(`[Redis] Failed to subscribe to ${channel}:`, cause);\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause,\n });\n },\n }).pipe(Effect.asVoid),\n\n unsubscribe: (channel: string) =>\n Effect.tryPromise({\n try: () => subscriberRedis.unsubscribe(channel),\n catch: (cause) =>\n UploadistaError.fromCode(\"UNKNOWN_ERROR\", {\n cause,\n }),\n }).pipe(Effect.asVoid),\n };\n}\n\n/**\n * Layer factory for Redis event broadcaster\n */\nexport const redisEventBroadcaster = (config: RedisEventBroadcasterConfig) =>\n Layer.succeed(EventBroadcasterService, createRedisEventBroadcaster(config));\n"],"mappings":"sKAmCA,SAAgB,EACd,EACkB,CAClB,GAAM,CAAE,QAAO,mBAAoB,EAUnC,OARA,EAAgB,GAAG,QAAU,GAAU,CACrC,QAAQ,MAAM,4BAA6B,EAAM,EACjD,CAEF,EAAM,GAAG,QAAU,GAAU,CAC3B,QAAQ,MAAM,iBAAkB,EAAM,EACtC,CAEK,CACL,SAAU,EAAiB,IACzB,EAAO,WAAW,CAChB,IAAK,SACY,MAAM,EAAM,QAAQ,EAAS,EAAQ,CAGtD,MAAQ,IACN,QAAQ,MAAM,gCAAgC,EAAQ,GAAI,EAAM,CACzD,EAAgB,SAAS,gBAAiB,CAC/C,QACD,CAAC,EAEL,CAAC,CAAC,KAAK,EAAO,OAAO,CAExB,WAAY,EAAiB,IAC3B,EAAO,WAAW,CAChB,IAAK,SAAY,CACf,MAAM,EAAgB,UAAU,GAAU,EAAS,IAAa,CAC9D,EAAQ,EAAQ,EAChB,EAEJ,MAAQ,IACN,QAAQ,MAAM,kCAAkC,EAAQ,GAAI,EAAM,CAC3D,EAAgB,SAAS,gBAAiB,CAC/C,QACD,CAAC,EAEL,CAAC,CAAC,KAAK,EAAO,OAAO,CAExB,YAAc,GACZ,EAAO,WAAW,CAChB,QAAW,EAAgB,YAAY,EAAQ,CAC/C,MAAQ,GACN,EAAgB,SAAS,gBAAiB,CACxC,QACD,CAAC,CACL,CAAC,CAAC,KAAK,EAAO,OAAO,CACzB,CAMH,MAAa,EAAyB,GACpC,EAAM,QAAQ,EAAyB,EAA4B,EAAO,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadista/event-broadcaster-redis",
3
3
  "type": "module",
4
- "version": "0.1.4-beta.1",
4
+ "version": "0.2.0",
5
5
  "description": "Redis event broadcaster for Uploadista",
6
6
  "license": "MIT",
7
7
  "author": "Uploadista",
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@uploadista/core": "0.1.4-beta.1"
17
+ "@uploadista/core": "0.2.0"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@redis/client": ">=5.8.0 <6.0.0",
@@ -22,12 +22,12 @@
22
22
  },
23
23
  "devDependencies": {
24
24
  "@effect/vitest": "0.27.0",
25
- "@redis/client": "5.10.0",
25
+ "@redis/client": "5.11.0",
26
26
  "@types/node": "24.10.9",
27
- "effect": "3.19.15",
28
- "tsdown": "0.20.1",
27
+ "effect": "3.19.17",
28
+ "tsdown": "0.20.3",
29
29
  "vitest": "4.0.18",
30
- "@uploadista/typescript-config": "0.1.4-beta.1"
30
+ "@uploadista/typescript-config": "0.2.0"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "tsc --noEmit && tsdown",
@@ -1,9 +1,18 @@
1
- import type { RedisClientType } from "@redis/client";
2
1
  import { UploadistaError } from "@uploadista/core/errors";
3
2
  import type { EventBroadcaster } from "@uploadista/core/types";
4
3
  import { EventBroadcasterService } from "@uploadista/core/types";
5
4
  import { Effect, Layer } from "effect";
6
5
 
6
+ export interface RedisPubSubLike {
7
+ publish(channel: string, message: string): Promise<number>;
8
+ subscribe(
9
+ channel: string,
10
+ listener: (message: string, channel: string) => void,
11
+ ): Promise<void>;
12
+ unsubscribe(channel: string): Promise<void>;
13
+ on(event: string, listener: (...args: unknown[]) => void): unknown;
14
+ }
15
+
7
16
  /**
8
17
  * Configuration for Redis event broadcaster
9
18
  */
@@ -11,12 +20,12 @@ export interface RedisEventBroadcasterConfig {
11
20
  /**
12
21
  * Redis client for publishing messages
13
22
  */
14
- redis: RedisClientType;
23
+ redis: RedisPubSubLike;
15
24
  /**
16
25
  * Separate Redis client for subscribing to messages
17
26
  * (Redis requires a dedicated connection for pub/sub)
18
27
  */
19
- subscriberRedis: RedisClientType;
28
+ subscriberRedis: RedisPubSubLike;
20
29
  }
21
30
 
22
31
  /**
package/tsconfig.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "outDir": "./dist",
9
9
  "rootDir": "./src",
10
- "typeRoots": ["../../../../node_modules/@types"],
10
+ "typeRoots": ["./node_modules/@types", "../../../../node_modules/@types"],
11
11
  "lib": ["ES2022"]
12
12
  },
13
13
  "include": ["src"]