@live-state/sync 0.0.6-canary-5 → 0.0.6-canary-6

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.
@@ -1 +1 @@
1
- import {d,b,c,f}from'./chunk-RCXJM33Z.js';import {stringify}from'qs';var y=async(e,a,t)=>{let r=s=>{if(!s)return {};if(s instanceof Headers){let d={};return s.forEach((f,b)=>{d[b]=f;}),d}return Array.isArray(s)?Object.fromEntries(s):s},i=r(t==null?void 0:t.headers),c=r(a==null?void 0:a.headers),u={...t,...a,headers:{...i,...c}},n=await fetch(e,u),o;try{o=await n.json();}catch{o=await n.text().catch(()=>{});}if(!n.ok)throw new Error(`Failed to fetch: ${n.status} ${n.statusText}`,{cause:o});return o},p=e=>{if(e===null)return "null";if(Array.isArray(e))return e.map(p);if(typeof e=="object"&&e!==null&&e.constructor===Object){let a={};for(let[t,r]of Object.entries(e))a[t]=p(r);return a}return e},C=e=>{let a={get:async t=>{let r=p(t),i=stringify(r),c=await b(e.credentials)??{},u=await y(`${e.url}/${t.resource}${i?`?${i}`:""}`,{headers:{...c,"Content-Type":"application/json"}},e.fetchOptions);return !u||typeof u!="object"?[]:Object.entries(u).map(([n,o])=>({...f(o),id:n}))},subscribe:()=>{throw new Error("Fetch client does not support subscriptions")}};return {query:Object.entries(e.schema).reduce((t,[r,i])=>(t[r]=c._init(i,a,true),t),{}),mutate:d(()=>{},{apply:async(t,r,i)=>{if(r.length<2)return;if(r.length>2)throw new Error("Trying to access an invalid path");let[c,u]=r,n=await b(e.credentials)??{};if(u==="insert"){let{id:o,...s}=i[0];await y(`${e.url}/${c}/insert`,{method:"POST",headers:{...n,"Content-Type":"application/json"},body:JSON.stringify({resourceId:o,payload:e.schema[c].encodeMutation("set",s,new Date().toISOString())})},e.fetchOptions);return}if(u==="update"){let[o,s]=i,{id:d,...f}=s;await y(`${e.url}/${c}/update`,{method:"POST",headers:{...n,"Content-Type":"application/json"},body:JSON.stringify({resourceId:o,payload:e.schema[c].encodeMutation("set",f,new Date().toISOString())})},e.fetchOptions);return}await y(`${e.url}/${c}/${u}`,{method:"POST",headers:{...n,"Content-Type":"application/json"},body:JSON.stringify({payload:i[0]})},e.fetchOptions);}})}};export{C as createClient};
1
+ import {d,b,c,f}from'./chunk-RCXJM33Z.js';import {stringify}from'qs';var y=async(e,a,t)=>{let r=s=>{if(!s)return {};if(s instanceof Headers){let d={};return s.forEach((f,b)=>{d[b]=f;}),d}return Array.isArray(s)?Object.fromEntries(s):s},i=r(t==null?void 0:t.headers),c=r(a==null?void 0:a.headers),u={...t,...a,headers:{...i,...c}},n=await fetch(e,u),o;try{o=await n.json();}catch{o=await n.text().catch(()=>{});}if(!n.ok)throw new Error(`Failed to fetch: ${n.status} ${n.statusText}`,{cause:o});return o},p=e=>{if(e===null)return "null";if(Array.isArray(e))return e.map(p);if(typeof e=="object"&&e!==null&&e.constructor===Object){let a={};for(let[t,r]of Object.entries(e))a[t]=p(r);return a}return e},C=e=>{let a={get:async t=>{let r=p(t),i=stringify(r),c=await b(e.credentials)??{},u=await y(`${e.url}/${t.resource}${i?`?${i}`:""}`,{headers:{...c,"Content-Type":"application/json"}},e.fetchOptions);return !u||typeof u!="object"?[]:Object.entries(u).map(([n,o])=>({...f(o),id:n}))},subscribe:()=>{throw new Error("Fetch client does not support subscriptions")}};return {query:Object.entries(e.schema).reduce((t,[r,i])=>(t[r]=c._init(i,a,true),t),{}),mutate:d(()=>{},{apply:async(t,r,i)=>{if(r.length<2)return;if(r.length>2)throw new Error("Trying to access an invalid path");let[c,u]=r,n=await b(e.credentials)??{};if(u==="insert"){let{id:o,...s}=i[0];await y(`${e.url}/${c}/insert`,{method:"POST",headers:{...n,"Content-Type":"application/json"},body:JSON.stringify({resourceId:o,payload:e.schema[c].encodeMutation("set",s,new Date().toISOString())})},e.fetchOptions);return}if(u==="update"){let[o,s]=i,{id:d,...f}=s;await y(`${e.url}/${c}/update`,{method:"POST",headers:{...n,"Content-Type":"application/json"},body:JSON.stringify({resourceId:o,payload:e.schema[c].encodeMutation("set",f,new Date().toISOString())})},e.fetchOptions);return}return await y(`${e.url}/${c}/${u}`,{method:"POST",headers:{...n,"Content-Type":"application/json"},body:JSON.stringify({payload:i[0]})},e.fetchOptions)}})}};export{C as createClient};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-state/sync",
3
- "version": "0.0.6-canary-5",
3
+ "version": "0.0.6-canary-6",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"