@uploadista/event-emitter-websocket 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 +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=require(`@uploadista/core/errors`),t=require(`@uploadista/core/types`),n=require(`effect`);const r=n.Effect.gen(function*(){let e=yield*t.EventBroadcasterService,r=new Map,i=new Map,a=(e,t)=>{let n=i.get(e);if(n)for(let e of n){let n=r.get(e);if(n&&n.readyState===1)try{n.send(t)}catch(t){console.warn(`Failed to send message to connection ${e}:`,t),l(e)}else l(e)}};yield*e.subscribe(`uploadista:events`,e=>{try{let{eventKey:t,message:n}=JSON.parse(e);a(t,n)}catch(e){console.warn(`Failed to parse broadcast message:`,e)}}).pipe(n.Effect.catchAll(e=>(console.error(`Failed to subscribe to broadcast events:`,e),n.Effect.void)));let o=e=>r.get(e)||null,s=()=>r,c=(e,t)=>{r.set(e,t)},l=e=>{r.delete(e);for(let[t,n]of i.entries())n.delete(e),n.size===0&&i.delete(t)};return{getConnection:o,getConnections:s,addConnection:c,removeConnection:l,subscribeToEvents:(e,t)=>{i.has(e)||i.set(e,new Set),i.get(e)?.add(t)},unsubscribeFromEvents:(e,t)=>{let n=i.get(e);n&&(n.delete(t),n.size===0&&i.delete(e))},emitToEvents:(t,r)=>{n.Effect.runPromise(e.publish(`uploadista:events`,JSON.stringify({eventKey:t,message:r}))).catch(e=>{console.error(`Failed to publish event to broadcaster:`,e)})}}});var i=class extends n.Context.Tag(`BaseWebSocketManagerService`)(){};const a=n.Layer.effect(i,r);function o(t){return{emit:(r,i)=>n.Effect.try({try:()=>{t.emitToEvents(r,i)},catch:t=>e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:t})}),subscribe:(r,i)=>n.Effect.try({try:()=>{t.addConnection(i.id,i),t.subscribeToEvents(r,i.id),i.send(JSON.stringify({type:`subscribed`,payload:{eventKey:r},timestamp:new Date().toISOString()}))},catch:t=>e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:t})}),unsubscribe:r=>n.Effect.try({try:()=>{let e=t.getConnections();for(let[n]of e)t.unsubscribeFromEvents(r,n)},catch:t=>e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:t})})}}const s=n.Effect.gen(function*(){return o(yield*i)}),c=e=>n.Layer.effect(t.BaseEventEmitterService,s).pipe(n.Layer.provide(a),n.Layer.provide(e));exports.WebSocketManagerService=i,exports.makeBaseEventEmitter=s,exports.makeWebSocketManager=r,exports.webSocketEventEmitter=c,exports.webSocketManager=a;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@uploadista/core/errors`),t=require(`@uploadista/core/types`),n=require(`effect`);const r=n.Effect.gen(function*(){let e=yield*t.EventBroadcasterService,r=new Map,i=new Map,a=(e,t)=>{let n=i.get(e);if(n)for(let e of n){let n=r.get(e);if(n&&n.readyState===1)try{n.send(t)}catch(t){console.warn(`Failed to send message to connection ${e}:`,t),l(e)}else l(e)}};yield*e.subscribe(`uploadista:events`,e=>{try{let{eventKey:t,message:n}=JSON.parse(e);a(t,n)}catch(e){console.warn(`Failed to parse broadcast message:`,e)}}).pipe(n.Effect.catchAll(e=>(console.error(`Failed to subscribe to broadcast events:`,e),n.Effect.void)));let o=e=>r.get(e)||null,s=()=>r,c=(e,t)=>{r.set(e,t)},l=e=>{r.delete(e);for(let[t,n]of i.entries())n.delete(e),n.size===0&&i.delete(t)};return{getConnection:o,getConnections:s,addConnection:c,removeConnection:l,subscribeToEvents:(e,t)=>{i.has(e)||i.set(e,new Set),i.get(e)?.add(t)},unsubscribeFromEvents:(e,t)=>{let n=i.get(e);n&&(n.delete(t),n.size===0&&i.delete(e))},emitToEvents:(t,r)=>{n.Effect.runPromise(e.publish(`uploadista:events`,JSON.stringify({eventKey:t,message:r}))).catch(e=>{console.error(`Failed to publish event to broadcaster:`,e)})}}});var i=class extends n.Context.Tag(`BaseWebSocketManagerService`)(){};const a=n.Layer.effect(i,r);function o(t){return{emit:(r,i)=>n.Effect.try({try:()=>{t.emitToEvents(r,i)},catch:t=>e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:t})}),subscribe:(r,i)=>n.Effect.try({try:()=>{t.addConnection(i.id,i),t.subscribeToEvents(r,i.id),i.send(JSON.stringify({type:`subscribed`,payload:{eventKey:r},timestamp:new Date().toISOString()}))},catch:t=>e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:t})}),unsubscribe:r=>n.Effect.try({try:()=>{let e=t.getConnections();for(let[n]of e)t.unsubscribeFromEvents(r,n)},catch:t=>e.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:t})})}}const s=n.Effect.gen(function*(){return o(yield*i)}),c=e=>n.Layer.effect(t.BaseEventEmitterService,s).pipe(n.Layer.provide(a),n.Layer.provide(e));exports.WebSocketManagerService=i,exports.makeBaseEventEmitter=s,exports.makeWebSocketManager=r,exports.webSocketEventEmitter=c,exports.webSocketManager=a;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uploadista/event-emitter-websocket",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "WebSocket event emitter for Uploadista",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Uploadista",
|
|
@@ -14,18 +14,18 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@uploadista/core": "0.
|
|
17
|
+
"@uploadista/core": "0.2.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"effect": "^3.0.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@effect/vitest": "0.27.0",
|
|
24
|
-
"effect": "3.19.
|
|
25
|
-
"tsdown": "0.20.
|
|
24
|
+
"effect": "3.19.17",
|
|
25
|
+
"tsdown": "0.20.3",
|
|
26
26
|
"vitest": "4.0.18",
|
|
27
|
-
"@uploadista/
|
|
28
|
-
"@uploadista/
|
|
27
|
+
"@uploadista/typescript-config": "0.2.0",
|
|
28
|
+
"@uploadista/event-broadcaster-memory": "0.2.0"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsc --noEmit && tsdown",
|