itty-sockets 0.3.0 → 0.3.2

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.
Files changed (2) hide show
  1. package/package.json +12 -5
  2. package/connect.snippet.js +0 -1
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
2
  "name": "itty-sockets",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Tiny realtime messaging client in under 450 bytes. No backend needed.",
5
- "main": "./sockets.js",
6
- "module": "./sockets.mjs",
7
- "types": "./sockets.d.ts",
5
+ "type": "module",
8
6
  "scripts": {
9
7
  "dev": "bun test --watch",
10
8
  "lint": "bun eslint src",
@@ -60,5 +58,14 @@
60
58
  "require": "./connect.js",
61
59
  "types": "./connect.d.ts"
62
60
  }
63
- }
61
+ },
62
+ "files": [
63
+ "LICENSE",
64
+ "index.mjs",
65
+ "index.js",
66
+ "index.d.ts",
67
+ "connect.mjs",
68
+ "connect.js",
69
+ "connect.d.ts"
70
+ ]
64
71
  }
@@ -1 +0,0 @@
1
- let connect=(e,o={})=>{let s,t=[],n=0,r={},a=()=>(s||(s=new WebSocket(`wss://ittysockets.io/r/${e}?${new URLSearchParams(o)}`),s.onopen=()=>{for(;t.length;)s?.send(t.shift());for(let e of r.open??[])e();n&&s?.close()},s.onmessage=(e,o=JSON.parse(e.data))=>{for(let e of r[o.type??"message"]??[])e({...o,date:new Date(o.date)})},s.onclose=()=>{n=0,s=null;for(let e of r.close??[])e()}),l);const l=new Proxy(a,{get:(e,o)=>({open:a,close:()=>(1==s?.readyState?s.close():n=1,l),send:(e,o)=>(e=JSON.stringify(e),e=o?`@@${o}@@${e}`:e,1==s?.readyState?(s.send(e),l):(t.push(e),a())),push:(e,o)=>(n=1,l.send(e,o)),on:(e,o)=>((r[e]??=[]).push(o),a()),remove:(e,o,s=r[e],t=s?.indexOf(o)??-1)=>(~t&&s?.splice(t,1),a())}[o])});return l};