itty-sockets 0.3.1 → 0.3.3

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/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './connect';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";exports.connect=(e,s={})=>{let o,t=[],n=0,r={},a=()=>(o||(o=new WebSocket(`wss://ittysockets.io/r/${e}?${new URLSearchParams(s)}`),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of r.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of r[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of r.close??[])e()}),c);const c=new Proxy(a,{get:(e,s)=>({open:a,close:()=>(1==o?.readyState?o.close():n=1,c),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),c):(t.push(e),a())),push:(e,s)=>(n=1,c.send(e,s)),on:(e,s)=>((r[e]??=[]).push(s),a()),remove:(e,s,o=r[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),a())}[s])});return c};
package/index.mjs ADDED
@@ -0,0 +1 @@
1
+ const e=(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};export{e as connect};
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
2
  "name": "itty-sockets",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Tiny realtime messaging client in under 450 bytes. No backend needed.",
5
- "main": "./connect.js",
6
- "module": "./connect.mjs",
7
- "types": "./connect.d.ts",
5
+ "type": "module",
8
6
  "scripts": {
9
7
  "dev": "bun test --watch",
10
8
  "lint": "bun eslint src",
@@ -50,10 +48,24 @@
50
48
  "yarn-release": "^1.10.6"
51
49
  },
52
50
  "exports": {
51
+ ".": {
52
+ "import": "./index.mjs",
53
+ "require": "./index.js",
54
+ "types": "./index.d.ts"
55
+ },
53
56
  "./connect": {
54
57
  "import": "./connect.mjs",
55
58
  "require": "./connect.js",
56
59
  "types": "./connect.d.ts"
57
60
  }
58
- }
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
+ ]
59
71
  }