spacewave 0.57.12 → 0.57.13
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/build.json +1 -1
- package/dist/engine-worker.mjs +74 -74
- package/dist/react.mjs +1 -1
- package/dist/server.mjs +1 -1
- package/examples/task-board/package.json +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{T as e,a as t,i as n,n as r,r as i,t as a,w as o}from"./chunks/json-BuGtLL3Z.mjs";import{createContext as s,use as c,useCallback as l,useEffect as u,useEffectEvent as d,useMemo as f,useRef as p,useState as m}from"react";import{jsx as h}from"react/jsx-runtime";function g(e){let t=p(null),n=p(0);return(t.current===null||!(t.current.length===e.length&&t.current.every((t,n)=>t===e[n])))&&(t.current=[...e],n.current+=1),n.current}function _(e){let[t,n]=m({value:null,loading:e,error:null}),r=p(0),i=p(0),a=l(e=>i.current!==e,[]),o=l(e=>!e.signal.aborted&&e.generation===r.current,[]),s=l(()=>{n(e=>e.loading&&e.error===null?e:{value:e.value,loading:!0,error:null})},[]);return{state:t,isPending:a,isCurrent:o,setLoading:s,resetForRetry:l(()=>{n({value:null,loading:!0,error:null})},[]),settleNull:l((e,t)=>{i.current=e,r.current+=1,n(e=>e.value===null&&e.loading===t&&e.error===null?e:{value:null,loading:t,error:null})},[]),begin:l(e=>{let t=new AbortController;return r.current+=1,i.current=e,s(),{generation:r.current,signal:t.signal,abort:()=>t.abort()}},[s]),complete:l((e,t)=>o(e)?(n({value:t,loading:!1,error:null}),!0):!1,[o]),fail:l((e,t)=>o(e)?(n({value:null,loading:!1,error:t}),!0):!1,[o])}}function v(t,n,r){let i=g([t.value]),[a,o]=m(0),s=p(null),c=l(n,r),d=g([c,i]),{state:h,begin:v,complete:y,fail:b,isCurrent:x,isPending:S,setLoading:C,settleNull:w}=_(!0),T=t.loading||S(d)||h.loading;u(()=>{let n=t.value;if(n===null){w(d,t.loading);return}if(t.loading){C();return}let r=v(d);return(async()=>{let t=!1;try{for await(let e of c(n,r.signal)){if(!x(r))break;t=!0,s.current===i&&(s.current=null),y(r,e)}if(!x(r))return;t||y(r,null)}catch(t){if(!x(r))return;let n=t instanceof Error?t:Error(String(t));if(e(t)||n.name===`AbortError`){if(s.current!==i){s.current=i,o(e=>e+1);return}b(r,n);return}b(r,n)}})(),()=>r.abort()},[t.loading,t.value,i,a,d,v,y,b,x,C,w,c]);let E=l(()=>{o(e=>e+1)},[]);return f(()=>({value:h.value,loading:T,error:t.error??h.error,retry:t.error?t.retry:E}),[h.value,T,h.error,E,t.error,t.retry])}function y(e){let t=s(null);function r({db:e,children:n}){return h(t.Provider,{value:e,children:n})}function i(){let e=c(t);if(!e)throw Error(`useDatabase must be called within the SyncProvider returned by createSyncContext`);return e}function a(e,t={}){let r=i(),a=t.prefix??``,o=v(f(()=>({value:r,loading:!1,error:null,retry:()=>{}}),[r]),(t,n)=>t.collection(e).watch({prefix:a},{signal:n}),[r,e,a]);return o.loading?{status:`loading`,data:[]}:o.value?o.value:o.error?{status:`error`,data:[],error:o.error instanceof n?o.error:new n(`UNAVAILABLE`,`The collection subscription failed`)}:{status:`loading`,data:[]}}return{SyncProvider:r,useDatabase:i,useCollection:a}}var b=class{resourceRef;constructor(e){this.resourceRef=e}get id(){return this.resourceRef.resourceId}get client(){return this.resourceRef.client}get released(){return this.resourceRef.released}release(){this.resourceRef.release()}[Symbol.dispose](){this.release()}};const x=s(null);function S(){return c(x)}const C=s(void 0);function w(){return c(C)}function T(){return w()?.client??null}let E=1;function D(){let e=p(null);return e.current===null&&(e.current=`_r_${E++}_`),e.current}function O(e){let[t,n,r,i]=e;if(typeof t==`function`){if(!Array.isArray(n))throw Error(`useResource: deps array is required as second argument`);return{type:`no-parent`,factory:t,deps:n,options:r,parents:[]}}if(Array.isArray(t)){if(!Array.isArray(r))throw Error(`useResource: deps array is required as third argument`);return{type:`multi-parent`,factory:n,deps:r,options:i,parents:t}}if(!Array.isArray(r))throw Error(`useResource: deps array is required as third argument`);return{type:`single-parent`,factory:n,deps:r,options:i,parents:[t]}}function k(e){let t=e.map(e=>e.value),n=f(()=>t,t),r=e.some(e=>e.loading),i=e.find(e=>e.error)?.error??null,a=e.
|
|
1
|
+
import{T as e,a as t,i as n,n as r,r as i,t as a,w as o}from"./chunks/json-BuGtLL3Z.mjs";import{createContext as s,use as c,useCallback as l,useEffect as u,useEffectEvent as d,useMemo as f,useRef as p,useState as m}from"react";import{jsx as h}from"react/jsx-runtime";function g(e){let t=p(null),n=p(0);return(t.current===null||!(t.current.length===e.length&&t.current.every((t,n)=>t===e[n])))&&(t.current=[...e],n.current+=1),n.current}function _(e){let[t,n]=m({value:null,loading:e,error:null}),r=p(0),i=p(0),a=l(e=>i.current!==e,[]),o=l(e=>!e.signal.aborted&&e.generation===r.current,[]),s=l(()=>{n(e=>e.loading&&e.error===null?e:{value:e.value,loading:!0,error:null})},[]);return{state:t,isPending:a,isCurrent:o,setLoading:s,resetForRetry:l(()=>{n({value:null,loading:!0,error:null})},[]),settleNull:l((e,t)=>{i.current=e,r.current+=1,n(e=>e.value===null&&e.loading===t&&e.error===null?e:{value:null,loading:t,error:null})},[]),begin:l(e=>{let t=new AbortController;return r.current+=1,i.current=e,s(),{generation:r.current,signal:t.signal,abort:()=>t.abort()}},[s]),complete:l((e,t)=>o(e)?(n({value:t,loading:!1,error:null}),!0):!1,[o]),fail:l((e,t)=>o(e)?(n({value:null,loading:!1,error:t}),!0):!1,[o])}}function v(t,n,r){let i=g([t.value]),[a,o]=m(0),s=p(null),c=l(n,r),d=g([c,i]),{state:h,begin:v,complete:y,fail:b,isCurrent:x,isPending:S,setLoading:C,settleNull:w}=_(!0),T=t.loading||S(d)||h.loading;u(()=>{let n=t.value;if(n===null){w(d,t.loading);return}if(t.loading){C();return}let r=v(d);return(async()=>{let t=!1;try{for await(let e of c(n,r.signal)){if(!x(r))break;t=!0,s.current===i&&(s.current=null),y(r,e)}if(!x(r))return;t||y(r,null)}catch(t){if(!x(r))return;let n=t instanceof Error?t:Error(String(t));if(e(t)||n.name===`AbortError`){if(s.current!==i){s.current=i,o(e=>e+1);return}b(r,n);return}b(r,n)}})(),()=>r.abort()},[t.loading,t.value,i,a,d,v,y,b,x,C,w,c]);let E=l(()=>{o(e=>e+1)},[]);return f(()=>({value:h.value,loading:T,error:t.error??h.error,retry:t.error?t.retry:E}),[h.value,T,h.error,E,t.error,t.retry])}function y(e){let t=s(null);function r({db:e,children:n}){return h(t.Provider,{value:e,children:n})}function i(){let e=c(t);if(!e)throw Error(`useDatabase must be called within the SyncProvider returned by createSyncContext`);return e}function a(e,t={}){let r=i(),a=t.prefix??``,o=v(f(()=>({value:r,loading:!1,error:null,retry:()=>{}}),[r]),(t,n)=>t.collection(e).watch({prefix:a},{signal:n}),[r,e,a]);return o.loading?{status:`loading`,data:[]}:o.value?o.value:o.error?{status:`error`,data:[],error:o.error instanceof n?o.error:new n(`UNAVAILABLE`,`The collection subscription failed`)}:{status:`loading`,data:[]}}return{SyncProvider:r,useDatabase:i,useCollection:a}}var b=class{resourceRef;constructor(e){this.resourceRef=e}get id(){return this.resourceRef.resourceId}get client(){return this.resourceRef.client}get released(){return this.resourceRef.released}release(){this.resourceRef.release()}[Symbol.dispose](){this.release()}};const x=s(null);function S(){return c(x)}const C=s(void 0);function w(){return c(C)}function T(){return w()?.client??null}let E=1;function D(){let e=p(null);return e.current===null&&(e.current=`_r_${E++}_`),e.current}function O(e){let[t,n,r,i]=e;if(typeof t==`function`){if(!Array.isArray(n))throw Error(`useResource: deps array is required as second argument`);return{type:`no-parent`,factory:t,deps:n,options:r,parents:[]}}if(Array.isArray(t)){if(!Array.isArray(r))throw Error(`useResource: deps array is required as third argument`);return{type:`multi-parent`,factory:n,deps:r,options:i,parents:t}}if(!Array.isArray(r))throw Error(`useResource: deps array is required as third argument`);return{type:`single-parent`,factory:n,deps:r,options:i,parents:[t]}}function k(e){let t=e.map(e=>e.value),n=f(()=>t,t),r=e.some(e=>e.loading),i=e.find(e=>e.error)?.error??null,a=e.flatMap(e=>[e.retry,e.error!=null]);return{values:n,loading:r,error:i,failedRetries:f(()=>e.filter(e=>e.error!=null).map(e=>e.retry),a)}}async function A(e,t,n,r){return e.type===`no-parent`?e.factory(n,r):e.type===`single-parent`?e.factory(t[0],n,r):e.factory(t,n,r)}function j(e){let t=e?.retryOnReleasedResource;return t===!1?[]:t===void 0||t===!0?[`server-released`]:t.reasons??[`server-released`]}function M(e,t){let n=t?.retryOnReleasedResource;return n===!1?[]:n&&n!==!0&&n.getResourceIds?n.getResourceIds(e):e instanceof b?[e.id]:[]}function N(...e){let[t,n,r,i]=e,a=D(),s=S(),c=T(),h=f(()=>O(e),[t,n,r,i]),v=h.options?.enabled??!0,y=k(h.parents),x=g(y.values),C=g([l(h.factory,h.deps),x]),{state:w,begin:E,complete:N,fail:P,isPending:F,resetForRetry:I,settleNull:L}=_(v&&!y.loading),R=F(C)||w.loading,[z,B]=m(0),V=d(e=>{e!==null&&h.options?.onSuccess?.(e)}),H=d(e=>{h.options?.onError?.(e)}),U=l(()=>{y.failedRetries.forEach(e=>e()),I(),B(e=>e+1)},[y.failedRetries,I]),W=f(()=>j(h.options),[h.options]),G=f(()=>!v||w.value===null?[]:M(w.value,h.options),[v,w.value,h.options]),K=p(!1),q=p(null),J=f(()=>y.values.flatMap(e=>e instanceof b?[e.id]:[]),[y.values]);u(()=>{K.current=!1},[z,w.value]),u(()=>{if(c&&J.length!==0)return c.onResourceReleased(e=>{(e.reason===`server-released`||e.reason===`connection-lost`||e.reason===`client-released`)&&J.includes(e.resourceId)&&q.current?.abort()})},[J,c]);let Y=h.parents.flatMap(e=>{let t=e.__devtools?.id;return t==null?[]:[t]}),X=f(()=>Y,Y),Z=p(U);Z.current=U;let Q=p(w);Q.current=w,u(()=>{if(!s)return;s.register(a,X,()=>Z.current());let e=Q.current,t=e.loading?`loading`:e.error?`error`:`ready`;return s.update(a,t,e.value,e.error),()=>{s.unregister(a)}},[s,a,X]);let $=p({loading:w.loading,error:w.error,value:w.value});return u(()=>{if(!s)return;let e=$.current;if(e.loading===w.loading&&e.error===w.error&&e.value===w.value)return;$.current={loading:w.loading,error:w.error,value:w.value};let t=w.loading?`loading`:w.error?`error`:`ready`;s.update(a,t,w.value,w.error)},[s,a,w.loading,w.error,w.value]),u(()=>{if(!v){L(C,!1);return}if(y.values.some(e=>e===null)){L(C,y.loading);return}if(y.loading)return;if(y.values.some(e=>e instanceof b&&e.released)){L(C,!0);return}let e=[],t=E(C);q.current=t;let n=!1,r=t=>t&&(n?(queueMicrotask(()=>t[Symbol.dispose]()),t):(e.push(t),t)),i=()=>{n=!0,e.forEach(e=>e[Symbol.dispose]())};async function a(){try{let e=await A(h,y.values,t.signal,r);if(!N(t,e)){i();return}V(e)}catch(e){i();let n=o(e);P(t,n)&&H(n)}finally{q.current===t&&(q.current=null)}}return a(),()=>{t.abort(),q.current===t&&(q.current=null),i()}},[z,v,y.loading,C,E,N,P,L]),u(()=>{if(c&&!w.loading&&W.length!==0&&G.length!==0)return c.onResourceReleased(e=>{W.includes(e.reason)&&G.includes(e.resourceId)&&(K.current||(K.current=!0,U()))})},[G,W,c,U,w.loading]),f(()=>({value:v?w.value:null,loading:v&&(y.loading||R),error:v?y.error||w.error:null,retry:U,__devtools:s?{id:a}:void 0}),[v,w.value,R,w.error,y.loading,y.error,U,s,a])}function P(e,n,r){let i=a(r),o=v(f(()=>({value:e,loading:!1,error:null,retry:()=>{}}),[e]),(e,t)=>e.watch(n,JSON.parse(i),t),[e,n,i]);return!e||o.loading?{status:`pending`}:o.error?{status:`error`,error:t(o.error)}:o.value??{status:`pending`}}function F(e,a){let[o,s]=m(null),c=p(o),l=e&&o?.source===e&&o.name===a?o:null,u=N(async e=>l?l.source.mutate(l.name,l.input,{signal:e,requestId:l.requestId}):null,[l]),d=t=>{if(!e)throw new n(`UNAVAILABLE`,`Application is not ready`);if(c.current?.source===e&&c.current.name===a&&(c.current!==l||u.loading))throw new n(`CONFLICT`,`An operation is still pending`);let o={source:e,name:a,input:r(i(t)),requestId:crypto.randomUUID()};c.current=o,s(o)},f={status:`idle`};if(l){let e=l.requestId;f=u.loading?{status:`pending`,requestId:e}:u.error?{status:`error`,requestId:e,error:t(u.error)}:{status:`accepted`,requestId:e,value:u.value}}return{submit:d,state:f,retry:u.retry}}export{y as createSyncContext,F as useAppMutation,P as useAppQuery};
|