gemi 0.127.0 → 0.129.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/ai/index.js +2 -2
- package/dist/ai/index.js.map +1 -1
- package/dist/app/index.js +1 -1
- package/dist/bun/plugin.js +1 -1
- package/dist/bun/preload.js +1 -1
- package/dist/{chunk-bghxdjqv.js → chunk-03wc6em7.js} +1 -1
- package/dist/{chunk-56ryda9y.js → chunk-0m2fyw7g.js} +2 -2
- package/dist/{chunk-56ryda9y.js.map → chunk-0m2fyw7g.js.map} +1 -1
- package/dist/chunk-0ryswty9.js +120 -0
- package/dist/{chunk-6c8pn6hj.js.map → chunk-0ryswty9.js.map} +10 -4
- package/dist/{chunk-ecb8qggy.js → chunk-0vxwrc4t.js} +2 -2
- package/dist/{chunk-ecb8qggy.js.map → chunk-0vxwrc4t.js.map} +1 -1
- package/dist/{chunk-1v368y9a.js → chunk-1gdzajwb.js} +2 -2
- package/dist/{chunk-1v368y9a.js.map → chunk-1gdzajwb.js.map} +1 -1
- package/dist/{chunk-h4755p9h.js → chunk-1rq53cb0.js} +2 -2
- package/dist/{chunk-h4755p9h.js.map → chunk-1rq53cb0.js.map} +1 -1
- package/dist/{chunk-v7nw1g2n.js → chunk-1yttk239.js} +2 -2
- package/dist/{chunk-v7nw1g2n.js.map → chunk-1yttk239.js.map} +1 -1
- package/dist/{chunk-28bby5pp.js → chunk-1z311hyj.js} +2 -2
- package/dist/{chunk-28bby5pp.js.map → chunk-1z311hyj.js.map} +1 -1
- package/dist/{chunk-n8mxsfc2.js → chunk-2869cbhd.js} +3 -3
- package/dist/{chunk-n8mxsfc2.js.map → chunk-2869cbhd.js.map} +1 -1
- package/dist/{chunk-dm7mada7.js → chunk-2bmk0fzm.js} +3 -3
- package/dist/{chunk-dm7mada7.js.map → chunk-2bmk0fzm.js.map} +1 -1
- package/dist/{chunk-ych1dv5q.js → chunk-2epj17ac.js} +3 -3
- package/dist/{chunk-ych1dv5q.js.map → chunk-2epj17ac.js.map} +1 -1
- package/dist/{chunk-0arss2xy.js → chunk-2z1gd231.js} +2 -2
- package/dist/{chunk-0arss2xy.js.map → chunk-2z1gd231.js.map} +1 -1
- package/dist/{chunk-xe2cfmyb.js → chunk-3dyd4z06.js} +2 -2
- package/dist/{chunk-xe2cfmyb.js.map → chunk-3dyd4z06.js.map} +1 -1
- package/dist/{chunk-p0ccxfkq.js → chunk-43vjbd6n.js} +1 -1
- package/dist/{chunk-nv2t87c3.js → chunk-4yp84g2y.js} +2 -2
- package/dist/{chunk-nv2t87c3.js.map → chunk-4yp84g2y.js.map} +1 -1
- package/dist/{chunk-bhbxhk9e.js → chunk-5bk7767a.js} +2 -2
- package/dist/{chunk-bhbxhk9e.js.map → chunk-5bk7767a.js.map} +1 -1
- package/dist/{chunk-k6gvbvyw.js → chunk-5nkvpc0a.js} +1 -1
- package/dist/{chunk-gxp48t81.js → chunk-5ym464xx.js} +4 -4
- package/dist/{chunk-gxp48t81.js.map → chunk-5ym464xx.js.map} +1 -1
- package/dist/{chunk-v80890xx.js → chunk-7321qjgb.js} +3 -3
- package/dist/{chunk-v80890xx.js.map → chunk-7321qjgb.js.map} +1 -1
- package/dist/{chunk-0f0xxqhy.js → chunk-87rtxv9n.js} +3 -3
- package/dist/{chunk-0f0xxqhy.js.map → chunk-87rtxv9n.js.map} +1 -1
- package/dist/{chunk-avfntxm1.js → chunk-8jqve5dr.js} +2 -2
- package/dist/{chunk-avfntxm1.js.map → chunk-8jqve5dr.js.map} +1 -1
- package/dist/{chunk-5vvfcdpk.js → chunk-9122838b.js} +2 -2
- package/dist/{chunk-5vvfcdpk.js.map → chunk-9122838b.js.map} +1 -1
- package/dist/{chunk-jg3kg55f.js → chunk-9701fx4z.js} +2 -2
- package/dist/{chunk-jg3kg55f.js.map → chunk-9701fx4z.js.map} +1 -1
- package/dist/{chunk-mj7h1dgh.js → chunk-b7wmssj5.js} +2 -2
- package/dist/{chunk-mj7h1dgh.js.map → chunk-b7wmssj5.js.map} +1 -1
- package/dist/{chunk-etf6h5m1.js → chunk-bg5qb9hm.js} +2 -2
- package/dist/{chunk-etf6h5m1.js.map → chunk-bg5qb9hm.js.map} +1 -1
- package/dist/{chunk-w4111j5d.js → chunk-bnp6wpzd.js} +2 -2
- package/dist/{chunk-w4111j5d.js.map → chunk-bnp6wpzd.js.map} +1 -1
- package/dist/{chunk-yg8se4vs.js → chunk-cp84b0ev.js} +3 -3
- package/dist/{chunk-yg8se4vs.js.map → chunk-cp84b0ev.js.map} +1 -1
- package/dist/{chunk-hye22tpt.js → chunk-dak8txaw.js} +2 -2
- package/dist/{chunk-hye22tpt.js.map → chunk-dak8txaw.js.map} +1 -1
- package/dist/{chunk-7x2n788t.js → chunk-er5ed5pg.js} +3 -3
- package/dist/{chunk-7x2n788t.js.map → chunk-er5ed5pg.js.map} +1 -1
- package/dist/{chunk-s2y2b8tz.js → chunk-f8ce6e9c.js} +2 -2
- package/dist/{chunk-s2y2b8tz.js.map → chunk-f8ce6e9c.js.map} +1 -1
- package/dist/{chunk-7eerqsg2.js → chunk-fezaxj28.js} +2 -2
- package/dist/{chunk-7eerqsg2.js.map → chunk-fezaxj28.js.map} +1 -1
- package/dist/{chunk-q9mxjh10.js → chunk-fv53h1q2.js} +2 -2
- package/dist/{chunk-q9mxjh10.js.map → chunk-fv53h1q2.js.map} +1 -1
- package/dist/{chunk-62zn06wb.js → chunk-gpdsxwkt.js} +2 -2
- package/dist/{chunk-62zn06wb.js.map → chunk-gpdsxwkt.js.map} +1 -1
- package/dist/{chunk-15bmfr7f.js → chunk-gzaaspe7.js} +2 -2
- package/dist/{chunk-15bmfr7f.js.map → chunk-gzaaspe7.js.map} +1 -1
- package/dist/{chunk-3fyhd641.js → chunk-h55c9bdf.js} +1 -1
- package/dist/{chunk-x5vpjzpp.js → chunk-ja41ts8v.js} +2 -2
- package/dist/{chunk-x5vpjzpp.js.map → chunk-ja41ts8v.js.map} +1 -1
- package/dist/{chunk-1dzs05dc.js → chunk-jcps2gpp.js} +2 -2
- package/dist/{chunk-1dzs05dc.js.map → chunk-jcps2gpp.js.map} +1 -1
- package/dist/chunk-jj1ppnnk.js +10 -0
- package/dist/{chunk-3p9vj0h6.js.map → chunk-jj1ppnnk.js.map} +5 -4
- package/dist/{chunk-psdyfaf1.js → chunk-jm1f9cas.js} +2 -2
- package/dist/{chunk-psdyfaf1.js.map → chunk-jm1f9cas.js.map} +1 -1
- package/dist/{chunk-99z9d0sa.js → chunk-k107vw69.js} +2 -2
- package/dist/{chunk-99z9d0sa.js.map → chunk-k107vw69.js.map} +1 -1
- package/dist/{chunk-7dzprr9b.js → chunk-k10vbrjx.js} +3 -3
- package/dist/{chunk-7dzprr9b.js.map → chunk-k10vbrjx.js.map} +1 -1
- package/dist/{chunk-c48gag78.js → chunk-kmcnfk2s.js} +1 -1
- package/dist/{chunk-yffm8nxa.js → chunk-mc8mxx2a.js} +2 -2
- package/dist/{chunk-yffm8nxa.js.map → chunk-mc8mxx2a.js.map} +1 -1
- package/dist/{chunk-ewv1m1sv.js → chunk-n1t4ea9g.js} +3 -3
- package/dist/{chunk-ewv1m1sv.js.map → chunk-n1t4ea9g.js.map} +1 -1
- package/dist/{chunk-9hhxy88x.js → chunk-n4dk0dc9.js} +2 -2
- package/dist/{chunk-9hhxy88x.js.map → chunk-n4dk0dc9.js.map} +1 -1
- package/dist/{chunk-rvdsaqdv.js → chunk-nh9ewam0.js} +1 -1
- package/dist/{chunk-84rbdyhe.js → chunk-njaxnv6c.js} +2 -2
- package/dist/{chunk-84rbdyhe.js.map → chunk-njaxnv6c.js.map} +1 -1
- package/dist/{chunk-7nfprr9v.js → chunk-np73p641.js} +2 -2
- package/dist/{chunk-7nfprr9v.js.map → chunk-np73p641.js.map} +1 -1
- package/dist/{chunk-87jj7n9q.js → chunk-nvfhx9d1.js} +2 -2
- package/dist/{chunk-87jj7n9q.js.map → chunk-nvfhx9d1.js.map} +1 -1
- package/dist/{chunk-qmcjh6de.js → chunk-nwzsgzvy.js} +2 -2
- package/dist/{chunk-qmcjh6de.js.map → chunk-nwzsgzvy.js.map} +1 -1
- package/dist/{chunk-43faxwf5.js → chunk-p528pvmm.js} +2 -2
- package/dist/{chunk-43faxwf5.js.map → chunk-p528pvmm.js.map} +1 -1
- package/dist/{chunk-kzk5r6v4.js → chunk-peng31np.js} +3 -3
- package/dist/{chunk-kzk5r6v4.js.map → chunk-peng31np.js.map} +1 -1
- package/dist/{chunk-mj4n5mar.js → chunk-pgddb43b.js} +2 -2
- package/dist/{chunk-mj4n5mar.js.map → chunk-pgddb43b.js.map} +1 -1
- package/dist/{chunk-s2krqtwj.js → chunk-pgh7gsag.js} +2 -2
- package/dist/{chunk-s2krqtwj.js.map → chunk-pgh7gsag.js.map} +1 -1
- package/dist/chunk-pqn9j5s8.js +5 -0
- package/dist/{chunk-87bmhng2.js.map → chunk-pqn9j5s8.js.map} +1 -1
- package/dist/{chunk-m63v6aze.js → chunk-pxsq9841.js} +2 -2
- package/dist/{chunk-m63v6aze.js.map → chunk-pxsq9841.js.map} +1 -1
- package/dist/{chunk-1eb4p352.js → chunk-py1twqh8.js} +2 -2
- package/dist/{chunk-1eb4p352.js.map → chunk-py1twqh8.js.map} +1 -1
- package/dist/{chunk-nrf23yan.js → chunk-qjmcn5m5.js} +2 -2
- package/dist/{chunk-nrf23yan.js.map → chunk-qjmcn5m5.js.map} +1 -1
- package/dist/{chunk-t8kzaxaa.js → chunk-qpwb3gnh.js} +2 -2
- package/dist/{chunk-t8kzaxaa.js.map → chunk-qpwb3gnh.js.map} +1 -1
- package/dist/{chunk-c65rh4k8.js → chunk-qv8sj2z3.js} +2 -2
- package/dist/{chunk-c65rh4k8.js.map → chunk-qv8sj2z3.js.map} +1 -1
- package/dist/{chunk-3hndrc5z.js → chunk-sbdm4enk.js} +2 -2
- package/dist/{chunk-3hndrc5z.js.map → chunk-sbdm4enk.js.map} +1 -1
- package/dist/{chunk-v1eeh7a7.js → chunk-sh39q44t.js} +3 -3
- package/dist/{chunk-v1eeh7a7.js.map → chunk-sh39q44t.js.map} +1 -1
- package/dist/{chunk-b2pdqxj3.js → chunk-t7gvgz20.js} +3 -3
- package/dist/{chunk-b2pdqxj3.js.map → chunk-t7gvgz20.js.map} +1 -1
- package/dist/{chunk-gv59djt3.js → chunk-tn3y2qkj.js} +2 -2
- package/dist/{chunk-gv59djt3.js.map → chunk-tn3y2qkj.js.map} +1 -1
- package/dist/{chunk-9x0pgkns.js → chunk-ty5sp1ym.js} +2 -2
- package/dist/{chunk-9x0pgkns.js.map → chunk-ty5sp1ym.js.map} +1 -1
- package/dist/{chunk-8df7fn7f.js → chunk-v09w6pr2.js} +3 -3
- package/dist/{chunk-8df7fn7f.js.map → chunk-v09w6pr2.js.map} +1 -1
- package/dist/{chunk-s0kns9q1.js → chunk-vc5kpxdk.js} +3 -3
- package/dist/{chunk-s0kns9q1.js.map → chunk-vc5kpxdk.js.map} +1 -1
- package/dist/{chunk-1gd1ykgj.js → chunk-vjpby5sf.js} +3 -3
- package/dist/{chunk-1gd1ykgj.js.map → chunk-vjpby5sf.js.map} +1 -1
- package/dist/{chunk-p7abyc0b.js → chunk-wf3qe12c.js} +2 -2
- package/dist/{chunk-p7abyc0b.js.map → chunk-wf3qe12c.js.map} +1 -1
- package/dist/{chunk-yhxjhrvp.js → chunk-wmkrb1qv.js} +2 -2
- package/dist/{chunk-yhxjhrvp.js.map → chunk-wmkrb1qv.js.map} +1 -1
- package/dist/{chunk-094m8mj3.js → chunk-wn437678.js} +2 -2
- package/dist/{chunk-094m8mj3.js.map → chunk-wn437678.js.map} +1 -1
- package/dist/{chunk-rtb64x14.js → chunk-wv3nnq8c.js} +3 -3
- package/dist/{chunk-rtb64x14.js.map → chunk-wv3nnq8c.js.map} +1 -1
- package/dist/{chunk-wat33wxh.js → chunk-ww86zqbw.js} +2 -2
- package/dist/{chunk-wat33wxh.js.map → chunk-ww86zqbw.js.map} +1 -1
- package/dist/{chunk-ebdkmzm9.js → chunk-x92g4x4w.js} +2 -2
- package/dist/{chunk-ebdkmzm9.js.map → chunk-x92g4x4w.js.map} +1 -1
- package/dist/{chunk-qy3s6pwz.js → chunk-xhm5wgfe.js} +2 -2
- package/dist/{chunk-qy3s6pwz.js.map → chunk-xhm5wgfe.js.map} +1 -1
- package/dist/{chunk-89swy5aq.js → chunk-xtnbcbkf.js} +2 -2
- package/dist/{chunk-89swy5aq.js.map → chunk-xtnbcbkf.js.map} +1 -1
- package/dist/{chunk-pxstrw29.js → chunk-zw5z1k84.js} +2 -2
- package/dist/{chunk-pxstrw29.js.map → chunk-zw5z1k84.js.map} +1 -1
- package/dist/chunks/RealtimeClient-CqGve6h8.js +545 -0
- package/dist/chunks/RealtimeClient-CqGve6h8.js.map +1 -0
- package/dist/chunks/{ThemeProvider-BIrCSrFY.js → ThemeProvider-DaX0eyqs.js} +155 -539
- package/dist/chunks/ThemeProvider-DaX0eyqs.js.map +1 -0
- package/dist/chunks/live-DIUDdLrA.js +69 -0
- package/dist/chunks/live-DIUDdLrA.js.map +1 -0
- package/dist/chunks/subscriptionStream-CULcRbx0.js +166 -0
- package/dist/chunks/subscriptionStream-CULcRbx0.js.map +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +118 -330
- package/dist/client/index.js.map +1 -1
- package/dist/client/init.d.ts +1 -1
- package/dist/client/init.d.ts.map +1 -1
- package/dist/client/realtime/FakeSocket.d.ts +1 -1
- package/dist/client/realtime/FakeSocket.d.ts.map +1 -1
- package/dist/client/realtime/RealtimeClient.d.ts +4 -20
- package/dist/client/realtime/RealtimeClient.d.ts.map +1 -1
- package/dist/client/realtime/live.d.ts +25 -0
- package/dist/client/realtime/live.d.ts.map +1 -0
- package/dist/client/realtime/loader.d.ts +59 -0
- package/dist/client/realtime/loader.d.ts.map +1 -0
- package/dist/client/realtime/useChannelSubscription.d.ts +1 -1
- package/dist/client/realtime/useChannelSubscription.d.ts.map +1 -1
- package/dist/client/subscriptionStream.d.ts +36 -0
- package/dist/client/subscriptionStream.d.ts.map +1 -0
- package/dist/client/useChannel.d.ts +1 -13
- package/dist/client/useChannel.d.ts.map +1 -1
- package/dist/client/useQuery.d.ts +1 -1
- package/dist/client/useQuery.d.ts.map +1 -1
- package/dist/client/useSubscription.d.ts +5 -10
- package/dist/client/useSubscription.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/console/run.js +2 -2
- package/dist/console/run.js.map +1 -1
- package/dist/container/index.js +2 -2
- package/dist/container/index.js.map +1 -1
- package/dist/database/index.js +2 -2
- package/dist/database/index.js.map +1 -1
- package/dist/email/index.js +2 -2
- package/dist/email/index.js.map +1 -1
- package/dist/facades/Runs.d.ts +64 -0
- package/dist/facades/Runs.d.ts.map +1 -0
- package/dist/facades/index.d.ts +1 -0
- package/dist/facades/index.d.ts.map +1 -1
- package/dist/facades/index.js +2 -2
- package/dist/facades/index.js.map +1 -1
- package/dist/foundation/index.js +2 -2
- package/dist/foundation/index.js.map +1 -1
- package/dist/http/index.js +2 -2
- package/dist/http/index.js.map +1 -1
- package/dist/i18n/dictionaryRuntime.js +2 -2
- package/dist/i18n/dictionaryRuntime.js.map +1 -1
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/index.js.map +1 -1
- package/dist/kernel/index.js +3 -3
- package/dist/kernel/index.js.map +3 -3
- package/dist/kernel/providers.d.ts.map +1 -1
- package/dist/orm/index.js +2 -2
- package/dist/orm/index.js.map +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/services/broadcast/protocol.d.ts +1 -2
- package/dist/services/broadcast/protocol.d.ts.map +1 -1
- package/dist/services/broadcast/socketHeader.d.ts +9 -0
- package/dist/services/broadcast/socketHeader.d.ts.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +3 -3
- package/dist/services/index.js.map +2 -2
- package/dist/services/queue/work.js +2 -2
- package/dist/services/queue/work.js.map +1 -1
- package/dist/services/runs/DatabaseRunStore.d.ts +62 -0
- package/dist/services/runs/DatabaseRunStore.d.ts.map +1 -0
- package/dist/services/runs/RunManager.d.ts +200 -0
- package/dist/services/runs/RunManager.d.ts.map +1 -0
- package/dist/services/runs/RunStore.d.ts +163 -0
- package/dist/services/runs/RunStore.d.ts.map +1 -0
- package/dist/services/runs/RunsServiceProvider.d.ts +5 -0
- package/dist/services/runs/RunsServiceProvider.d.ts.map +1 -0
- package/dist/services/runs/config.d.ts +20 -0
- package/dist/services/runs/config.d.ts.map +1 -0
- package/dist/stats/route-table.js +1 -1
- package/dist/support/index.js +2 -2
- package/dist/support/index.js.map +1 -1
- package/dist/testing/Page.d.ts.map +1 -1
- package/dist/testing/index.js +3 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/vitest/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3p9vj0h6.js +0 -10
- package/dist/chunk-6c8pn6hj.js +0 -57
- package/dist/chunk-87bmhng2.js +0 -5
- package/dist/chunks/ThemeProvider-BIrCSrFY.js.map +0 -1
- /package/dist/{chunk-bghxdjqv.js.map → chunk-03wc6em7.js.map} +0 -0
- /package/dist/{chunk-p0ccxfkq.js.map → chunk-43vjbd6n.js.map} +0 -0
- /package/dist/{chunk-k6gvbvyw.js.map → chunk-5nkvpc0a.js.map} +0 -0
- /package/dist/{chunk-3fyhd641.js.map → chunk-h55c9bdf.js.map} +0 -0
- /package/dist/{chunk-c48gag78.js.map → chunk-kmcnfk2s.js.map} +0 -0
- /package/dist/{chunk-rvdsaqdv.js.map → chunk-nh9ewam0.js.map} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
var j=Object.create;var{getPrototypeOf:k,defineProperty:f,getOwnPropertyNames:l}=Object;var m=Object.prototype.hasOwnProperty;function n(a){return this[a]}var o,p,s=(a,b,c)=>{var g=a!=null&&typeof a==="object";if(g){var h=b?o??=new WeakMap:p??=new WeakMap,i=h.get(a);if(i)return i}c=a!=null?j(k(a)):{};let d=b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c;for(let e of l(a))if(!m.call(d,e))f(d,e,{get:n.bind(a,e),enumerable:!0});if(g)h.set(a,d);return d};var t=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var q=(a)=>a;function r(a,b){this[a]=q.bind(null,b)}var u=(a,b)=>{for(var c in b)f(a,c,{get:b[c],enumerable:!0,configurable:!0,set:r.bind(b,c)})};var v=(a,b)=>()=>(a&&(b=a(a=0)),b);var w=import.meta.require;
|
|
3
|
-
export{s as
|
|
3
|
+
export{s as _k,t as $k,u as al,v as bl,w as cl};
|
|
4
4
|
|
|
5
|
-
//# debugId=
|
|
5
|
+
//# debugId=F458BEAB8F951F2E64756E2164756E21
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{R as S,T as h,U as u}from"./chunk-
|
|
2
|
+
import{R as S,T as h,U as u}from"./chunk-sbdm4enk.js";import{ma as q,na as w}from"./chunk-03wc6em7.js";import"./chunk-a22h5cby.js";import"./chunk-epvpmakp.js";import"./chunk-r3v2cnrj.js";import"./chunk-qv8sj2z3.js";import"./chunk-kk18xqgc.js";import"./chunk-bnp6wpzd.js";import{ri as N}from"./chunk-fezaxj28.js";import{Jk as y}from"./chunk-f8ce6e9c.js";import{Yk as C}from"./chunk-0vxwrc4t.js";import"./chunk-xtnbcbkf.js";import{join as $J}from"path";import{createServer as zJ}from"vite";import{join as l}from"path";import{IncomingMessage as d,ServerResponse as p}from"http";import{Socket as i}from"net";function c(J){return J.replace(/\x1b\[[0-9;]*m/g,"").replace(/\[[0-9;]*m/g,"").replace(/\n\s*\n/g,`
|
|
3
3
|
`).split(`
|
|
4
4
|
`).map((W)=>W.trim()).filter((W)=>W.length>0).join(`
|
|
5
5
|
`).trim()}function _(J){return`
|
|
@@ -55,4 +55,4 @@ window.$RefreshSig$ = () => (type) => type;
|
|
|
55
55
|
window.__vite_plugin_react_preamble_installed__ = true;
|
|
56
56
|
`;function t(J){let{pathname:W}=new URL(J.url),Z=($)=>new Response($,{headers:{"Content-Type":"application/javascript"}});if(W===T)return Z(a);if(W.startsWith("/render-error.js"))return Z("window.render_error = true");if(W.startsWith("/refresh.js"))return Z(s);return null}function P(J,W,Z){let $=l(process.cwd(),"app");return async(z)=>{let{pathname:Q}=new URL(z.url),U=(G)=>{if(console.error(G),Z.ssrFixStacktrace?.(G),O(G),C(Q))return new Response(JSON.stringify({error:N("server_error",G?.message??String(G),500)}),{status:500,headers:{"Content-Type":"application/json"}});return globalThis.__gemiErrorPageServed=!0,new Response(_(I(G)),{status:500,headers:{"Content-Type":"text/html"}})},X=async(G)=>{let j=t(G);if(j)return j;try{let L=J.fetch.bind(J),K=await n(Z,G)??await L(G);if(K instanceof Response)return K;let A={},F={},D={},m=(Y,B)=>`"${Y}": () => import("${B}")`,b=[];for(let Y of["404",...J.getFlatComponentTree.call(J)]){if(Bun.env.NODE_ENV==="test")break;let B=`${process.env.APP_DIR}`,x=await V(Z).import(`${B}/views/${Y}.tsx`);A[Y]=x.default,F[Y]=x?.OpenGraph,D[Y]=x,b.push(m(Y,`/app/views/${Y}.tsx`))}let v=`{${b.join(",")}}`;return await K({getStyles:async(Y,B)=>await S($,Z,Y,B?.layout),resolveIsland:(Y)=>({src:`/${Y}${y}`,preload:[]}),buildId:"dev",bootstrapModules:[T],viewImportMap:A,viewModules:D,ogMap:F,loaders:v,cssManifest:{}})}catch(L){return U(L)}};return await W(z,(G)=>J.withGlobalMiddleware(G,X,U))}}function r(J){try{return Bun.listen({hostname:"0.0.0.0",port:J,socket:{data(){}}}).stop(!0),!0}catch(W){return W?.code!=="EADDRINUSE"}}function f(J,W=r){let Z=24678+(J-5173);if(Z>65471)Z=24678;for(let $=Z;$<Z+64;$++)if(W($))return $;throw Error(`Could not find a free port for Vite's HMR websocket: tried ${Z}-${Z+64-1}. Set one explicitly in gemi.config.ts as \`vite: { server: { ws: { port } } }\`.`)}import{createServer as e}from"http";var JJ=new Set(["vite-hmr","vite-ping"]);async function R(J){let W=e((Z,$)=>{$.writeHead(426,{"Content-Type":"text/plain"}),$.end("Upgrade Required")});return await new Promise((Z,$)=>{W.once("error",$),W.listen(J,"127.0.0.1",()=>{W.off("error",$),Z()})}),W}function k(J){if(!J||typeof J!=="object")return null;let Z=J.server?.address?.();if(Z&&typeof Z==="object"&&"port"in Z)return Number(Z.port)||null;return null}function E(J){if(J.headers.get("upgrade")?.toLowerCase()!=="websocket")return!1;return JJ.has(J.headers.get("sec-websocket-protocol")??"")}var WJ=(J)=>typeof J==="string"?J:new Uint8Array(J);async function g(J,W,Z){let $=new URL(J.url),z=J.headers.get("sec-websocket-protocol")??"vite-hmr",Q={host:J.headers.get("host")??$.host},U=J.headers.get("origin");if(U)Q.origin=U;let X=new WebSocket(`ws://127.0.0.1:${Z}${$.pathname}${$.search}`,{protocols:[z],headers:Q});X.binaryType="arraybuffer";let G={upstream:X,early:[]};if(X.onmessage=(K)=>{let A=WJ(K.data);if(G.browser)G.browser.send(A);else G.early.push(A)},X.onclose=(K)=>{G.browser?.close(ZJ(K.code),K.reason)},X.onerror=()=>{},!await new Promise((K)=>{X.addEventListener("open",()=>K(!0),{once:!0}),X.addEventListener("close",()=>K(!1),{once:!0})}))return new Response("Vite refused the HMR websocket",{status:403});if(!W.upgrade(J,{headers:{"Sec-WebSocket-Protocol":z},data:G}))return X.close(),new Response("WebSocket upgrade failed",{status:400});return}function ZJ(J){if(J===1000||J>=1001&&J<=1003||J>=1007&&J<=1014)return J;if(J>=3000&&J<=4999)return J;return 1000}var H={open(J){let W=J.data;for(let Z of W.early)J.send(Z);if(W.early=[],W.browser=J,W.upstream.readyState!==WebSocket.OPEN)J.close(1000)},message(J,W){if(J.data.upstream.readyState===WebSocket.OPEN)J.data.upstream.send(W)},close(J){let{upstream:W}=J.data;if(W.readyState<=WebSocket.OPEN)W.close()}};function GJ(J,W){let Z=W.websocket,$=(z)=>z.data?.gemiSocket===!0;return{...W.socketOptions(),maxPayloadLength:16777216,closeOnBackpressureLimit:!1,open:(z)=>$(z)?Z.open?.(z):J.open?.(z),message:(z,Q)=>$(z)?Z.message(z,Q):J.message(z,Q),close:(z,Q,U)=>$(z)?Z.close?.(z,Q,U):J.close?.(z,Q,U)}}var M=process.cwd(),QJ=$J(M,"app");if(!globalThis.__gemiErrorHooked)globalThis.__gemiErrorHooked=!0,process.on("unhandledRejection",(J)=>{console.error(J),O(J)}),process.on("uncaughtException",(J)=>{console.error(J),O(J)});async function TJ(J,W){let Z=Number(process.env.PORT)||5173,$=u(),z=Boolean(globalThis.__gemiVite),Q=globalThis.__gemiVite??=await zJ({configFile:!1,plugins:[w()],server:{middlewareMode:!0,port:Z,ws:{server:await R(f(Z))},allowedHosts:J.devAllowedHosts.call(J),watch:{ignored:(L)=>{let K=L.split(/[/\\]/).pop()??"";return K===".env"||K.startsWith(".env.")}}},appType:"custom",resolve:{dedupe:["react","react-dom"]},optimizeDeps:{include:["react","react-dom","react-dom/client"]},ssr:{external:[...q]}});process.env.ROOT_DIR=M,process.env.APP_DIR=QJ;let U=P(J,W,Q),X=k(Q.config?.server?.ws),G=J.sockets(),j=Bun.serve({port:Z,idleTimeout:$,fetch:(L,K)=>{if(X!==null&&E(L))return g(L,K,X);if(G?.matches(L))return G.upgrade(L,K);return U(L)},websocket:G?GJ(H,G):H});if(await G?.start(j),z)V(Q).clearCache();if(z)if(globalThis.__gemiErrorActive&&globalThis.__gemiErrorPageServed)globalThis.__gemiErrorActive=!1,globalThis.__gemiErrorPageServed=!1,Q.ws.send({type:"full-reload"});else globalThis.__gemiErrorActive=!1,Q.ws.send({type:"custom",event:"http-reload"});else h({port:j.port,rootDir:M});return j}export{I as viteErrorPayload,TJ as httpDev};
|
|
57
57
|
|
|
58
|
-
//# debugId=
|
|
58
|
+
//# debugId=666BFE47DA47E41B64756E2164756E21
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
"import { createServer, type Server as NodeServer } from \"node:http\";\n\nimport type { Server, ServerWebSocket, WebSocketHandler } from \"bun\";\n\n// Vite's HMR websocket, carried on the dev server's own port.\n//\n// In middleware mode Vite has no HTTP server of its own, so by default it\n// stands up a second one for the websocket, on a second port (see\n// `hmrPort.ts`), and tells the browser to connect to `<page host>:<that port>`.\n// A reverse proxy or tunnel (ngrok, a container port mapping, a phone on the\n// LAN through https) only carries the port the page came from, so HMR could\n// not connect there, and the client logged connection failures forever.\n//\n// Vite can attach its websocket to a server it is handed (`server.ws.server`)\n// instead, and then tells the browser to connect to the page's own origin. That\n// server has to be a Node `http.Server`; the dev server is `Bun.serve`. So:\n//\n// - the Node server Vite is handed listens on loopback only, on the port\n// `resolveHmrPort` picked, and answers nothing but websocket upgrades;\n// - `Bun.serve` accepts the browser's upgrade on the page's origin and relays\n// frames both ways to that loopback server.\n//\n// The relay forwards the browser's `Host` and `Origin` and the request's query\n// (the `token`), so Vite still runs its own host and token checks against what\n// the browser actually sent.\n\n/** The subprotocols Vite's client opens its sockets with. */\nconst VITE_PROTOCOLS = new Set([\"vite-hmr\", \"vite-ping\"]);\n\n/**\n * Start the loopback Node server Vite attaches its HMR websocket to.\n * Everything but an upgrade gets `426 Upgrade Required`, as Vite's own\n * websocket server answers.\n */\nexport async function listenHmrServer(port: number): Promise<NodeServer> {\n const server = createServer((_req, res) => {\n res.writeHead(426, { \"Content-Type\": \"text/plain\" });\n res.end(\"Upgrade Required\");\n });\n await new Promise<void>((resolve, reject) => {\n server.once(\"error\", reject);\n server.listen(port, \"127.0.0.1\", () => {\n server.off(\"error\", reject);\n resolve();\n });\n });\n return server;\n}\n\n/**\n * The loopback port to relay to, read from the config Vite actually resolved,\n * so an app that set its own `server.ws` in `gemi.config.ts` is relayed to\n * where Vite really is, or not relayed at all. `null` when Vite was not given\n * a server (its websocket is then on a port of its own, and the client goes\n * there directly) or when HMR is off.\n */\nexport function hmrRelayPort(wsConfig: unknown): number | null {\n if (!wsConfig || typeof wsConfig !== \"object\") return null;\n const server = (wsConfig as { server?: { address?: () => unknown } }).server;\n const address = server?.address?.();\n if (address && typeof address === \"object\" && \"port\" in address) {\n return Number((address as { port: number }).port) || null;\n }\n return null;\n}\n\n/** Whether a request is the Vite client opening its HMR (or ping) socket. */\nexport function isHmrUpgrade(req: Request): boolean {\n if (req.headers.get(\"upgrade\")?.toLowerCase() !== \"websocket\") return false;\n return VITE_PROTOCOLS.has(req.headers.get(\"sec-websocket-protocol\") ?? \"\");\n}\n\nexport type HmrRelayData = {\n /** The socket to Vite, already open when the browser's is accepted. */\n upstream: WebSocket;\n /** Frames Vite sent before the browser's socket opened (its `connected`). */\n early: (string | Uint8Array)[];\n browser?: ServerWebSocket<HmrRelayData>;\n};\n\ntype Frame = string | Uint8Array;\n\nconst frameOf = (data: unknown): Frame =>\n typeof data === \"string\" ? data : new Uint8Array(data as ArrayBuffer);\n\n/**\n * Open the socket to Vite first, and accept the browser's upgrade only once\n * Vite has accepted it. Returns `undefined` once Bun has taken the request\n * over, or a refusal.\n *\n * The order matters. Vite refuses a socket whose host is not in\n * `allowedHosts`, or a cross-origin one without its token. Had the browser's\n * socket been accepted first and closed when Vite refused, the client would\n * read that as \"server connection lost\", ping (which Vite always answers),\n * and reload the page, forever. Refused before it opens, the client logs one\n * \"failed to connect to websocket\" and the page keeps working.\n */\nexport async function upgradeHmr(\n req: Request,\n server: Server<HmrRelayData>,\n port: number,\n): Promise<Response | undefined> {\n const url = new URL(req.url);\n const protocol = req.headers.get(\"sec-websocket-protocol\") ?? \"vite-hmr\";\n // `Host` is what Vite's `allowedHosts` check reads; the URL's host is the\n // same value `Bun.serve` derived it from.\n const headers: Record<string, string> = {\n host: req.headers.get(\"host\") ?? url.host,\n };\n const origin = req.headers.get(\"origin\");\n if (origin) headers.origin = origin;\n\n const upstream = new WebSocket(\n `ws://127.0.0.1:${port}${url.pathname}${url.search}`,\n {\n protocols: [protocol],\n headers,\n } as any,\n );\n upstream.binaryType = \"arraybuffer\";\n const data: HmrRelayData = { upstream, early: [] };\n\n upstream.onmessage = (event) => {\n const frame = frameOf(event.data);\n if (data.browser) data.browser.send(frame);\n else data.early.push(frame);\n };\n upstream.onclose = (event) => {\n data.browser?.close(sendableCloseCode(event.code), event.reason);\n };\n upstream.onerror = () => {\n // A `close` follows; it ends the browser's socket if there is one.\n };\n\n const opened = await new Promise<boolean>((resolve) => {\n upstream.addEventListener(\"open\", () => resolve(true), { once: true });\n upstream.addEventListener(\"close\", () => resolve(false), { once: true });\n });\n if (!opened) {\n return new Response(\"Vite refused the HMR websocket\", { status: 403 });\n }\n\n const upgraded = server.upgrade(req, {\n // The browser fails a connection whose response does not echo the\n // subprotocol it asked for.\n headers: { \"Sec-WebSocket-Protocol\": protocol },\n data,\n });\n if (!upgraded) {\n upstream.close();\n return new Response(\"WebSocket upgrade failed\", { status: 400 });\n }\n return undefined;\n}\n\n// A close code that may be sent in a close frame. 1005, 1006 and 1015 are\n// reported locally and never sent.\nfunction sendableCloseCode(code: number): number {\n if (\n code === 1000 ||\n (code >= 1001 && code <= 1003) ||\n (code >= 1007 && code <= 1014)\n ) {\n return code;\n }\n if (code >= 3000 && code <= 4999) return code;\n return 1000;\n}\n\n/** `Bun.serve`'s `websocket` option: relays frames to and from Vite. */\nexport const hmrRelayHandler: WebSocketHandler<HmrRelayData> = {\n open(ws: ServerWebSocket<HmrRelayData>) {\n const data = ws.data;\n for (const frame of data.early) ws.send(frame);\n data.early = [];\n data.browser = ws;\n // Vite may have hung up while the upgrade was in flight.\n if (data.upstream.readyState !== WebSocket.OPEN) ws.close(1000);\n },\n message(ws: ServerWebSocket<HmrRelayData>, message) {\n if (ws.data.upstream.readyState === WebSocket.OPEN) {\n ws.data.upstream.send(message);\n }\n },\n close(ws: ServerWebSocket<HmrRelayData>) {\n const { upstream } = ws.data;\n if (upstream.readyState <= WebSocket.OPEN) upstream.close();\n },\n};\n"
|
|
10
10
|
],
|
|
11
11
|
"mappings": ";weAAA,SAAS,QAET,iBAAS,QCDT,SAAS,OACT,oBAAS,cAAiB,OAC1B,WAAS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AAM,CAAM,EA+BvB,EACF,EAAU,CAAI,EAAE,WAAW,EAQ7B,GAAI,EAMF,GAAI,WAAW,mBAAqB,WAAW,sBAC7C,WAAW,kBAAoB,GAC/B,WAAW,sBAAwB,GACnC,EAAK,GAAG,KAAK,CAAE,KAAM,aAAc,CAAC,EAEpC,gBAAW,kBAAoB,GAC/B,EAAK,GAAG,KAAK,CAAE,KAAM,SAAU,MAAO,aAAc,CAAC,EAIvD,OAAmB,CAAE,KAAM,EAAO,KAAM,SAAQ,CAAC,EAGnD,OAAO",
|
|
12
|
-
"debugId": "
|
|
12
|
+
"debugId": "666BFE47DA47E41B64756E2164756E21",
|
|
13
13
|
"names": []
|
|
14
14
|
}
|
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
import { z as channelKey } from "./ThemeProvider-DaX0eyqs.js";
|
|
2
|
+
//#region services/broadcast/protocol.ts
|
|
3
|
+
/**
|
|
4
|
+
* The `gemi.v1` WebSocket protocol, shared by the server transport
|
|
5
|
+
* (`SocketHub`) and the browser client (`gemi/client`'s connection manager).
|
|
6
|
+
* Types and constants only: this module is imported by the browser bundle, so
|
|
7
|
+
* it must never import a server module.
|
|
8
|
+
*
|
|
9
|
+
* Every frame is a JSON text frame. Binary frames are refused.
|
|
10
|
+
*
|
|
11
|
+
* From the client:
|
|
12
|
+
*
|
|
13
|
+
* - `{op:"sub", id, ch, p?}`: subscribe `id` (chosen by the client, unique per
|
|
14
|
+
* socket) to the channel pattern `ch` with params `p`. The server builds
|
|
15
|
+
* the topic and authorizes it.
|
|
16
|
+
* - `{op:"unsub", id}`
|
|
17
|
+
* - `{op:"ping"}`: answered with `pong`. The client sends one every
|
|
18
|
+
* `heartbeatMs` and reconnects when it hears nothing for twice that.
|
|
19
|
+
*
|
|
20
|
+
* From the server:
|
|
21
|
+
*
|
|
22
|
+
* - `{op:"hello", socketId, tag, heartbeatMs}`: the first frame. `socketId`
|
|
23
|
+
* goes in the `X-Gemi-Socket` header of the client's own requests (for
|
|
24
|
+
* `Broadcast.toOthers`); it is never shown to anyone else. `tag` is what
|
|
25
|
+
* an event frame's `x` carries when it skips this socket.
|
|
26
|
+
* - `{op:"subscribed", id, t}`: `id` joined topic `t`. Sent only once this
|
|
27
|
+
* process receives the topic's events, so the resync the client runs on it
|
|
28
|
+
* cannot miss one.
|
|
29
|
+
* - `{op:"denied", id, code}`: `id` was refused, or later revoked.
|
|
30
|
+
* - `{op:"ev", t, ev, d?, x?}`: an event on topic `t`. Dropped by the socket
|
|
31
|
+
* whose `tag` is `x`.
|
|
32
|
+
* - `{op:"gap"}`: events may have been lost for this socket; resync all.
|
|
33
|
+
* - `{op:"pong"}`
|
|
34
|
+
* - `{op:"bye", code, retryAfter}`: the server is going away (a restart).
|
|
35
|
+
* Reconnect after `retryAfter` ms.
|
|
36
|
+
*/
|
|
37
|
+
/** The WebSocket subprotocol. */
|
|
38
|
+
var BROADCAST_PROTOCOL = "gemi.v1";
|
|
39
|
+
/**
|
|
40
|
+
* Close codes the server uses. 1012 and 1013 are the standard "restart" and
|
|
41
|
+
* "try again later"; the 4xxx ones are gemi's own.
|
|
42
|
+
*/
|
|
43
|
+
var CloseCode = {
|
|
44
|
+
/** The client went away (tab closed, socket released). */
|
|
45
|
+
Normal: 1e3,
|
|
46
|
+
/** A frame that was not JSON text, or not a known op. */
|
|
47
|
+
UnsupportedData: 1003,
|
|
48
|
+
/** Too many frames, or a frame over the size limit. */
|
|
49
|
+
PolicyViolation: 1008,
|
|
50
|
+
/** The server is restarting; `bye` said when to come back. */
|
|
51
|
+
Restart: 1012,
|
|
52
|
+
/** The socket fell too far behind; reconnect and resync. */
|
|
53
|
+
TryAgainLater: 1013,
|
|
54
|
+
/** The socket's user was signed out or its access revoked. */
|
|
55
|
+
Revoked: 4001
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Whether a refusal is final for this socket's session: resubscribing will
|
|
59
|
+
* get the same answer, so the client does not retry it on its own.
|
|
60
|
+
*/
|
|
61
|
+
function isPermanentDenial(code) {
|
|
62
|
+
return code === "unknown_channel" || code === "invalid_params" || code === "invalid";
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region client/realtime/RealtimeClient.ts
|
|
66
|
+
/** The minimum gap between two resyncs of one subscription. */
|
|
67
|
+
var RESYNC_COALESCE_MS = 2e3;
|
|
68
|
+
/** How long the socket stays open after its last subscription goes. */
|
|
69
|
+
var IDLE_CLOSE_MS = 5e3;
|
|
70
|
+
/**
|
|
71
|
+
* How long a subscription outlives its last listener. A hook that remounts
|
|
72
|
+
* within it (StrictMode's double mount, a route change back, a list that
|
|
73
|
+
* re-renders its rows) picks the same subscription up again: no `unsub`, no
|
|
74
|
+
* new `sub`, nothing counted against the server's rate limit.
|
|
75
|
+
*/
|
|
76
|
+
var RELEASE_LINGER_MS = 1500;
|
|
77
|
+
/** The least wait before resending a `sub` denied with `rate_limited`. */
|
|
78
|
+
var RATE_LIMITED_RETRY_MS = 5e3;
|
|
79
|
+
/**
|
|
80
|
+
* How often a `sub` denied with `limit` is resent on one socket. The socket
|
|
81
|
+
* holds as many channels as the server allows, so only a released one makes
|
|
82
|
+
* room: worth a few tries with backoff, not a retry for as long as the socket
|
|
83
|
+
* lives. Past it the subscription waits for the next connection.
|
|
84
|
+
*/
|
|
85
|
+
var MAX_LIMIT_RETRIES = 5;
|
|
86
|
+
var MIN_BACKOFF_MS = 1e3;
|
|
87
|
+
var MAX_BACKOFF_MS = 3e4;
|
|
88
|
+
var DEFAULT_HEARTBEAT_MS = 25e3;
|
|
89
|
+
var DEFAULT_HIDDEN_DISCONNECT_MS = 6e4;
|
|
90
|
+
/**
|
|
91
|
+
* The tab's one WebSocket to the app (`gemi.v1`), multiplexing every channel
|
|
92
|
+
* the mounted hooks subscribe to.
|
|
93
|
+
*
|
|
94
|
+
* Opened by the first subscription and closed a few seconds after the last
|
|
95
|
+
* one goes. Reconnects with full-jitter backoff (1 to 30 s), or after the
|
|
96
|
+
* server's `bye.retryAfter`, at once on `online`; resubscribes everything
|
|
97
|
+
* then. A tab hidden for `hiddenDisconnectMs` disconnects, and reconnects
|
|
98
|
+
* when shown. Every `subscribed` ack and every `gap` resyncs the
|
|
99
|
+
* subscription (coalesced to one per 2 s), because events are volatile: a
|
|
100
|
+
* client that may have missed one refetches over HTTP.
|
|
101
|
+
*
|
|
102
|
+
* Loaded on first use (#891): import this module as a type only, and reach
|
|
103
|
+
* the tab's instance through `./loader`, or it lands in every route's entry
|
|
104
|
+
* chunk.
|
|
105
|
+
*/
|
|
106
|
+
var RealtimeClient = class {
|
|
107
|
+
options;
|
|
108
|
+
internals;
|
|
109
|
+
ws = null;
|
|
110
|
+
entries = /* @__PURE__ */ new Map();
|
|
111
|
+
byId = /* @__PURE__ */ new Map();
|
|
112
|
+
topics = /* @__PURE__ */ new Map();
|
|
113
|
+
nextId = 1;
|
|
114
|
+
attempt = 0;
|
|
115
|
+
tag = null;
|
|
116
|
+
socketIdValue = null;
|
|
117
|
+
heartbeatMs = DEFAULT_HEARTBEAT_MS;
|
|
118
|
+
reconnectTimer = null;
|
|
119
|
+
idleTimer = null;
|
|
120
|
+
hiddenTimer = null;
|
|
121
|
+
pingTimer = null;
|
|
122
|
+
livenessTimer = null;
|
|
123
|
+
retryAfter = null;
|
|
124
|
+
revoked = false;
|
|
125
|
+
pausedWhileHidden = false;
|
|
126
|
+
listening = false;
|
|
127
|
+
constructor(options = {}, internals = {}) {
|
|
128
|
+
this.options = withDefaults(options);
|
|
129
|
+
this.internals = internals;
|
|
130
|
+
}
|
|
131
|
+
configure(options) {
|
|
132
|
+
this.options = withDefaults({
|
|
133
|
+
...this.options,
|
|
134
|
+
...options
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** The id to send as `X-Gemi-Socket`, while the socket is open. */
|
|
138
|
+
get socketId() {
|
|
139
|
+
return this.socketIdValue;
|
|
140
|
+
}
|
|
141
|
+
subscribe(pattern, params, listener) {
|
|
142
|
+
const key = channelKey(pattern, params);
|
|
143
|
+
let entry = this.entries.get(key);
|
|
144
|
+
if (!entry) {
|
|
145
|
+
entry = {
|
|
146
|
+
key,
|
|
147
|
+
id: String(this.nextId++),
|
|
148
|
+
pattern,
|
|
149
|
+
params: { ...params },
|
|
150
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
151
|
+
status: "closed",
|
|
152
|
+
code: null,
|
|
153
|
+
permanent: false,
|
|
154
|
+
topic: null,
|
|
155
|
+
lastResyncAt: 0,
|
|
156
|
+
resyncTimer: null,
|
|
157
|
+
lingerTimer: null,
|
|
158
|
+
retryTimer: null,
|
|
159
|
+
retries: 0
|
|
160
|
+
};
|
|
161
|
+
this.entries.set(key, entry);
|
|
162
|
+
this.byId.set(entry.id, entry);
|
|
163
|
+
if (this.isOpen()) this.sendSub(entry);
|
|
164
|
+
}
|
|
165
|
+
if (entry.lingerTimer) {
|
|
166
|
+
clearTimeout(entry.lingerTimer);
|
|
167
|
+
entry.lingerTimer = null;
|
|
168
|
+
}
|
|
169
|
+
entry.listeners.add(listener);
|
|
170
|
+
listener.onStatus?.(entry.status, entry.code);
|
|
171
|
+
this.cancelIdleClose();
|
|
172
|
+
this.listen();
|
|
173
|
+
if (!this.ws && !this.reconnectTimer && !this.pausedWhileHidden) this.connect();
|
|
174
|
+
let released = false;
|
|
175
|
+
return () => {
|
|
176
|
+
if (released) return;
|
|
177
|
+
released = true;
|
|
178
|
+
this.release(entry, listener);
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
release(entry, listener) {
|
|
182
|
+
entry.listeners.delete(listener);
|
|
183
|
+
if (entry.listeners.size > 0 || entry.lingerTimer) return;
|
|
184
|
+
entry.lingerTimer = setTimeout(() => {
|
|
185
|
+
entry.lingerTimer = null;
|
|
186
|
+
if (entry.listeners.size === 0) this.drop(entry);
|
|
187
|
+
}, RELEASE_LINGER_MS);
|
|
188
|
+
}
|
|
189
|
+
drop(entry) {
|
|
190
|
+
if (entry.resyncTimer) clearTimeout(entry.resyncTimer);
|
|
191
|
+
this.clearRetry(entry);
|
|
192
|
+
this.entries.delete(entry.key);
|
|
193
|
+
this.byId.delete(entry.id);
|
|
194
|
+
this.dropTopic(entry);
|
|
195
|
+
if (this.isOpen() && (entry.status === "open" || entry.status === "connecting")) this.send({
|
|
196
|
+
op: "unsub",
|
|
197
|
+
id: entry.id
|
|
198
|
+
});
|
|
199
|
+
if (this.entries.size === 0) this.scheduleIdleClose();
|
|
200
|
+
}
|
|
201
|
+
isOpen() {
|
|
202
|
+
return this.ws !== null && this.ws.readyState === 1;
|
|
203
|
+
}
|
|
204
|
+
connect() {
|
|
205
|
+
if (typeof window === "undefined") return;
|
|
206
|
+
if (this.entries.size === 0) return;
|
|
207
|
+
const Impl = this.internals.WebSocket ?? globalThis.WebSocket;
|
|
208
|
+
if (!Impl) return;
|
|
209
|
+
this.clearReconnect();
|
|
210
|
+
let ws;
|
|
211
|
+
try {
|
|
212
|
+
ws = new Impl(this.url(), [BROADCAST_PROTOCOL]);
|
|
213
|
+
} catch {
|
|
214
|
+
this.scheduleReconnect();
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
this.ws = ws;
|
|
218
|
+
for (const entry of this.entries.values()) if (!entry.permanent) this.setStatus(entry, "connecting", null);
|
|
219
|
+
ws.onopen = () => {
|
|
220
|
+
if (this.ws !== ws) return;
|
|
221
|
+
this.touch();
|
|
222
|
+
for (const entry of this.entries.values()) {
|
|
223
|
+
if (entry.permanent) continue;
|
|
224
|
+
entry.retries = 0;
|
|
225
|
+
this.sendSub(entry);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
ws.onmessage = (event) => {
|
|
229
|
+
if (this.ws !== ws) return;
|
|
230
|
+
this.touch();
|
|
231
|
+
let frame;
|
|
232
|
+
try {
|
|
233
|
+
frame = JSON.parse(String(event.data));
|
|
234
|
+
} catch {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this.handle(frame);
|
|
238
|
+
};
|
|
239
|
+
ws.onclose = (event) => {
|
|
240
|
+
if (this.ws !== ws) return;
|
|
241
|
+
this.onClosed(event.code);
|
|
242
|
+
};
|
|
243
|
+
ws.onerror = () => {};
|
|
244
|
+
}
|
|
245
|
+
url() {
|
|
246
|
+
if (this.internals.url) return this.internals.url;
|
|
247
|
+
const { protocol, host } = window.location;
|
|
248
|
+
return `${protocol === "https:" ? "wss:" : "ws:"}//${host}${this.options.path}`;
|
|
249
|
+
}
|
|
250
|
+
sendSub(entry) {
|
|
251
|
+
this.setStatus(entry, "connecting", null);
|
|
252
|
+
const frame = {
|
|
253
|
+
op: "sub",
|
|
254
|
+
id: entry.id,
|
|
255
|
+
ch: entry.pattern
|
|
256
|
+
};
|
|
257
|
+
if (Object.keys(entry.params).length > 0) frame.p = entry.params;
|
|
258
|
+
this.send(frame);
|
|
259
|
+
}
|
|
260
|
+
send(frame) {
|
|
261
|
+
if (!this.isOpen()) return;
|
|
262
|
+
try {
|
|
263
|
+
this.ws.send(JSON.stringify(frame));
|
|
264
|
+
} catch {}
|
|
265
|
+
}
|
|
266
|
+
handle(frame) {
|
|
267
|
+
switch (frame.op) {
|
|
268
|
+
case "hello":
|
|
269
|
+
this.socketIdValue = frame.socketId;
|
|
270
|
+
this.tag = frame.tag;
|
|
271
|
+
this.attempt = 0;
|
|
272
|
+
this.revoked = false;
|
|
273
|
+
if (frame.heartbeatMs > 0) this.heartbeatMs = frame.heartbeatMs;
|
|
274
|
+
this.startHeartbeat();
|
|
275
|
+
return;
|
|
276
|
+
case "subscribed": {
|
|
277
|
+
const entry = this.byId.get(frame.id);
|
|
278
|
+
if (!entry) return;
|
|
279
|
+
this.dropTopic(entry);
|
|
280
|
+
entry.topic = frame.t;
|
|
281
|
+
let ids = this.topics.get(frame.t);
|
|
282
|
+
if (!ids) this.topics.set(frame.t, ids = /* @__PURE__ */ new Set());
|
|
283
|
+
ids.add(entry.id);
|
|
284
|
+
this.clearRetry(entry);
|
|
285
|
+
entry.retries = 0;
|
|
286
|
+
this.setStatus(entry, "open", null);
|
|
287
|
+
this.resync(entry);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
case "denied": {
|
|
291
|
+
const entry = this.byId.get(frame.id);
|
|
292
|
+
if (!entry) return;
|
|
293
|
+
this.dropTopic(entry);
|
|
294
|
+
entry.permanent = isPermanentDenial(frame.code);
|
|
295
|
+
this.setStatus(entry, "denied", frame.code);
|
|
296
|
+
this.scheduleRetry(entry, frame.code);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
case "ev": {
|
|
300
|
+
if (frame.x !== void 0 && frame.x === this.tag) return;
|
|
301
|
+
const ids = this.topics.get(frame.t);
|
|
302
|
+
if (!ids) return;
|
|
303
|
+
for (const id of Array.from(ids)) {
|
|
304
|
+
const entry = this.byId.get(id);
|
|
305
|
+
if (!entry) continue;
|
|
306
|
+
for (const listener of Array.from(entry.listeners)) try {
|
|
307
|
+
listener.onEvent?.(frame.ev, frame.d);
|
|
308
|
+
} catch (error) {
|
|
309
|
+
reportListenerError(error);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
case "gap":
|
|
315
|
+
for (const entry of this.entries.values()) if (entry.status === "open") this.resync(entry);
|
|
316
|
+
return;
|
|
317
|
+
case "bye":
|
|
318
|
+
this.retryAfter = Math.max(0, Number(frame.retryAfter) || 0);
|
|
319
|
+
return;
|
|
320
|
+
case "pong": return;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
onClosed(code) {
|
|
324
|
+
this.ws = null;
|
|
325
|
+
this.socketIdValue = null;
|
|
326
|
+
this.tag = null;
|
|
327
|
+
this.stopHeartbeat();
|
|
328
|
+
this.topics.clear();
|
|
329
|
+
for (const entry of this.entries.values()) {
|
|
330
|
+
entry.topic = null;
|
|
331
|
+
this.clearRetry(entry);
|
|
332
|
+
if (!entry.permanent) this.setStatus(entry, "closed", null);
|
|
333
|
+
}
|
|
334
|
+
if (code === CloseCode.Revoked) this.revoked = true;
|
|
335
|
+
if (this.entries.size > 0 && !this.pausedWhileHidden) this.scheduleReconnect();
|
|
336
|
+
}
|
|
337
|
+
scheduleReconnect() {
|
|
338
|
+
this.clearReconnect();
|
|
339
|
+
let delay;
|
|
340
|
+
if (this.retryAfter !== null) {
|
|
341
|
+
delay = this.retryAfter;
|
|
342
|
+
this.retryAfter = null;
|
|
343
|
+
} else if (this.revoked) {
|
|
344
|
+
this.revoked = false;
|
|
345
|
+
delay = Math.floor(this.random() * 500);
|
|
346
|
+
} else delay = backoffDelay(this.attempt, this.random());
|
|
347
|
+
this.attempt++;
|
|
348
|
+
this.reconnectTimer = setTimeout(() => {
|
|
349
|
+
this.reconnectTimer = null;
|
|
350
|
+
this.connect();
|
|
351
|
+
}, delay);
|
|
352
|
+
}
|
|
353
|
+
clearReconnect() {
|
|
354
|
+
if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
|
|
355
|
+
this.reconnectTimer = null;
|
|
356
|
+
}
|
|
357
|
+
random() {
|
|
358
|
+
return (this.internals.random ?? Math.random)();
|
|
359
|
+
}
|
|
360
|
+
startHeartbeat() {
|
|
361
|
+
this.stopHeartbeat();
|
|
362
|
+
this.pingTimer = setInterval(() => this.send({ op: "ping" }), this.heartbeatMs);
|
|
363
|
+
this.touch();
|
|
364
|
+
}
|
|
365
|
+
stopHeartbeat() {
|
|
366
|
+
if (this.pingTimer) clearInterval(this.pingTimer);
|
|
367
|
+
if (this.livenessTimer) clearTimeout(this.livenessTimer);
|
|
368
|
+
this.pingTimer = null;
|
|
369
|
+
this.livenessTimer = null;
|
|
370
|
+
}
|
|
371
|
+
/** Anything from the server proves the socket alive. */
|
|
372
|
+
touch() {
|
|
373
|
+
if (this.livenessTimer) clearTimeout(this.livenessTimer);
|
|
374
|
+
const ws = this.ws;
|
|
375
|
+
this.livenessTimer = setTimeout(() => {
|
|
376
|
+
if (this.ws !== ws || !ws) return;
|
|
377
|
+
try {
|
|
378
|
+
ws.close();
|
|
379
|
+
} catch {}
|
|
380
|
+
this.onClosed(1006);
|
|
381
|
+
}, this.heartbeatMs * 2);
|
|
382
|
+
}
|
|
383
|
+
setStatus(entry, status, code) {
|
|
384
|
+
if (entry.status === status && entry.code === code) return;
|
|
385
|
+
entry.status = status;
|
|
386
|
+
entry.code = code;
|
|
387
|
+
for (const listener of Array.from(entry.listeners)) try {
|
|
388
|
+
listener.onStatus?.(status, code);
|
|
389
|
+
} catch (error) {
|
|
390
|
+
reportListenerError(error);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
/** At most one resync per subscription per 2 s; a later one is deferred, not dropped. */
|
|
394
|
+
resync(entry) {
|
|
395
|
+
if (entry.resyncTimer) return;
|
|
396
|
+
const now = Date.now();
|
|
397
|
+
const wait = entry.lastResyncAt + RESYNC_COALESCE_MS - now;
|
|
398
|
+
const fire = () => {
|
|
399
|
+
entry.resyncTimer = null;
|
|
400
|
+
entry.lastResyncAt = Date.now();
|
|
401
|
+
for (const listener of Array.from(entry.listeners)) try {
|
|
402
|
+
listener.onResync?.();
|
|
403
|
+
} catch (error) {
|
|
404
|
+
reportListenerError(error);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
if (entry.lastResyncAt === 0 || wait <= 0) fire();
|
|
408
|
+
else entry.resyncTimer = setTimeout(fire, wait);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* A transient denial (`rate_limited`, `error`, `limit`) is retried on the
|
|
412
|
+
* same socket, with backoff: a healthy socket may never reconnect. `denied`
|
|
413
|
+
* and `revoked` are the channel's answer for this session, so they wait for
|
|
414
|
+
* the next connection (a sign-in reconnects), and a permanent one is never
|
|
415
|
+
* resent. `limit` gives up after `MAX_LIMIT_RETRIES` on one socket.
|
|
416
|
+
*/
|
|
417
|
+
scheduleRetry(entry, code) {
|
|
418
|
+
if (code !== "rate_limited" && code !== "error" && code !== "limit") return;
|
|
419
|
+
if (code === "limit" && entry.retries >= 5) return;
|
|
420
|
+
this.clearRetry(entry);
|
|
421
|
+
const delay = Math.max(code === "rate_limited" ? RATE_LIMITED_RETRY_MS : MIN_BACKOFF_MS, backoffDelay(entry.retries, this.random()));
|
|
422
|
+
entry.retries++;
|
|
423
|
+
entry.retryTimer = setTimeout(() => {
|
|
424
|
+
entry.retryTimer = null;
|
|
425
|
+
if (this.entries.get(entry.key) !== entry || entry.status !== "denied") return;
|
|
426
|
+
if (this.isOpen()) this.sendSub(entry);
|
|
427
|
+
}, delay);
|
|
428
|
+
}
|
|
429
|
+
clearRetry(entry) {
|
|
430
|
+
if (entry.retryTimer) clearTimeout(entry.retryTimer);
|
|
431
|
+
entry.retryTimer = null;
|
|
432
|
+
}
|
|
433
|
+
dropTopic(entry) {
|
|
434
|
+
if (!entry.topic) return;
|
|
435
|
+
const ids = this.topics.get(entry.topic);
|
|
436
|
+
ids?.delete(entry.id);
|
|
437
|
+
if (ids && ids.size === 0) this.topics.delete(entry.topic);
|
|
438
|
+
entry.topic = null;
|
|
439
|
+
}
|
|
440
|
+
scheduleIdleClose() {
|
|
441
|
+
this.cancelIdleClose();
|
|
442
|
+
this.idleTimer = setTimeout(() => {
|
|
443
|
+
this.idleTimer = null;
|
|
444
|
+
if (this.entries.size > 0) return;
|
|
445
|
+
this.clearReconnect();
|
|
446
|
+
this.close();
|
|
447
|
+
}, IDLE_CLOSE_MS);
|
|
448
|
+
}
|
|
449
|
+
cancelIdleClose() {
|
|
450
|
+
if (this.idleTimer) clearTimeout(this.idleTimer);
|
|
451
|
+
this.idleTimer = null;
|
|
452
|
+
}
|
|
453
|
+
/** Closes the socket without reconnecting. */
|
|
454
|
+
close() {
|
|
455
|
+
const ws = this.ws;
|
|
456
|
+
if (!ws) return;
|
|
457
|
+
this.ws = null;
|
|
458
|
+
try {
|
|
459
|
+
ws.close(CloseCode.Normal);
|
|
460
|
+
} catch {}
|
|
461
|
+
this.onClosed(CloseCode.Normal);
|
|
462
|
+
}
|
|
463
|
+
listen() {
|
|
464
|
+
if (this.listening || typeof window === "undefined") return;
|
|
465
|
+
this.listening = true;
|
|
466
|
+
window.addEventListener("online", this.onOnline);
|
|
467
|
+
if (typeof document !== "undefined") document.addEventListener("visibilitychange", this.onVisibility);
|
|
468
|
+
}
|
|
469
|
+
onOnline = () => {
|
|
470
|
+
if (this.entries.size === 0 || this.ws || this.pausedWhileHidden) return;
|
|
471
|
+
this.attempt = 0;
|
|
472
|
+
this.connect();
|
|
473
|
+
};
|
|
474
|
+
onVisibility = () => {
|
|
475
|
+
if (document.visibilityState === "hidden") {
|
|
476
|
+
if (this.hiddenTimer) return;
|
|
477
|
+
this.hiddenTimer = setTimeout(() => {
|
|
478
|
+
this.hiddenTimer = null;
|
|
479
|
+
if (document.visibilityState !== "hidden") return;
|
|
480
|
+
this.pausedWhileHidden = true;
|
|
481
|
+
this.clearReconnect();
|
|
482
|
+
this.close();
|
|
483
|
+
}, this.options.hiddenDisconnectMs);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
if (this.hiddenTimer) clearTimeout(this.hiddenTimer);
|
|
487
|
+
this.hiddenTimer = null;
|
|
488
|
+
if (this.pausedWhileHidden) {
|
|
489
|
+
this.pausedWhileHidden = false;
|
|
490
|
+
this.attempt = 0;
|
|
491
|
+
this.connect();
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* Drops the socket and opens a new one at once, when anything is
|
|
496
|
+
* subscribed. A socket keeps the session it was opened with (the upgrade's
|
|
497
|
+
* cookies), so signing in or out in this tab reconnects it: every channel
|
|
498
|
+
* is then authorized as the new session, and the acks resync.
|
|
499
|
+
*/
|
|
500
|
+
reconnect() {
|
|
501
|
+
this.close();
|
|
502
|
+
this.clearReconnect();
|
|
503
|
+
this.attempt = 0;
|
|
504
|
+
if (this.entries.size > 0 && !this.pausedWhileHidden) this.connect();
|
|
505
|
+
}
|
|
506
|
+
/** For tests: drops the socket, timers and listeners. */
|
|
507
|
+
dispose() {
|
|
508
|
+
this.clearReconnect();
|
|
509
|
+
this.cancelIdleClose();
|
|
510
|
+
if (this.hiddenTimer) clearTimeout(this.hiddenTimer);
|
|
511
|
+
for (const entry of this.entries.values()) {
|
|
512
|
+
if (entry.resyncTimer) clearTimeout(entry.resyncTimer);
|
|
513
|
+
if (entry.lingerTimer) clearTimeout(entry.lingerTimer);
|
|
514
|
+
this.clearRetry(entry);
|
|
515
|
+
}
|
|
516
|
+
this.entries.clear();
|
|
517
|
+
this.byId.clear();
|
|
518
|
+
this.close();
|
|
519
|
+
if (this.listening && typeof window !== "undefined") {
|
|
520
|
+
window.removeEventListener("online", this.onOnline);
|
|
521
|
+
document?.removeEventListener("visibilitychange", this.onVisibility);
|
|
522
|
+
this.listening = false;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
/** Full jitter, 1 to 30 s: `max(1 s, random × min(30 s, 1 s × 2^attempt))`. */
|
|
527
|
+
function backoffDelay(attempt, random) {
|
|
528
|
+
const cap = Math.min(MAX_BACKOFF_MS, MIN_BACKOFF_MS * 2 ** Math.min(attempt, 10));
|
|
529
|
+
return Math.max(MIN_BACKOFF_MS, Math.floor(random * cap));
|
|
530
|
+
}
|
|
531
|
+
function withDefaults(options) {
|
|
532
|
+
return {
|
|
533
|
+
path: options.path ?? "/__gemi/socket",
|
|
534
|
+
hiddenDisconnectMs: options.hiddenDisconnectMs ?? DEFAULT_HIDDEN_DISCONNECT_MS
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
function reportListenerError(error) {
|
|
538
|
+
setTimeout(() => {
|
|
539
|
+
throw error;
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
//#endregion
|
|
543
|
+
export { IDLE_CLOSE_MS, MAX_LIMIT_RETRIES, RELEASE_LINGER_MS, RESYNC_COALESCE_MS, RealtimeClient, backoffDelay };
|
|
544
|
+
|
|
545
|
+
//# sourceMappingURL=RealtimeClient-CqGve6h8.js.map
|