Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/preview-kit

Package Overview
Dependencies
Maintainers
44
Versions
252
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/preview-kit - npm Package Compare versions

Comparing version 5.0.22 to 5.0.23

3

dist/client/createClient.js

@@ -1,2 +0,1 @@

import{createClient as e}from"@sanity/client";const r=r=>{var o,a;const{encodeSourceMap:c=t(),encodeSourceMapAtPath:i,studioUrl:u=n(),logger:l,...s}=r;let p=!0===c;if("auto"===c&&(p=function(){try{return"preview"===import.meta.env.VERCEL_ENV}catch{}try{return"preview"===process.env.VERCEL_ENV}catch{}return!1}()),"string"==typeof c&&"auto"!==c)throw new Error("Invalid value for encodeSourceMap: ".concat(c,". Did you mean 'auto'?"));try{if(p&&!1!==r.resultSourceMap)return u?(null==(a=null==l?void 0:l.debug)||a.call(l,"[@sanity/preview-kit]: Creating source map enabled client"),e({...s,resultSourceMap:r.resultSourceMap?r.resultSourceMap:"withKeyArraySelector",stega:{enabled:!0,studioUrl:u,logger:l,filter:i?e=>i({path:e.sourcePath,filterDefault:()=>e.filterDefault(e)}):void 0}})):(null==(o=null==l?void 0:l.error)||o.call(l,"[@sanity/preview-kit]: Content source map enabled client is enabled, but no studioUrl is provided. Falling back to @sanity/client"),e(s))}catch(e){console.error("[@sanity/preview-kit]: Error creating client",e,"falling back to non-embedded sourcemap mode")}return e(s)};function t(){try{return"true"===import.meta.env.SANITY_SOURCE_MAP}catch{}try{return"true"===process.env.SANITY_SOURCE_MAP}catch{}return!1}function n(){try{return import.meta.env.SANITY_STUDIO_URL}catch{}try{return process.env.SANITY_STUDIO_URL}catch{}}export{r as createClient};
//# sourceMappingURL=createClient.js.map
import{createClient as e}from"@sanity/client";const r=r=>{var o,a;const{encodeSourceMap:c=t(),encodeSourceMapAtPath:i,studioUrl:u=n(),logger:l,...s}=r;let p=!0===c;if("auto"===c&&(p=function(){try{return"preview"===import.meta.env.VERCEL_ENV}catch{}try{return"preview"===process.env.VERCEL_ENV}catch{}return!1}()),"string"==typeof c&&"auto"!==c)throw new Error(`Invalid value for encodeSourceMap: ${c}. Did you mean 'auto'?`);try{if(p&&!1!==r.resultSourceMap)return u?(null==(a=null==l?void 0:l.debug)||a.call(l,"[@sanity/preview-kit]: Creating source map enabled client"),e({...s,resultSourceMap:r.resultSourceMap?r.resultSourceMap:"withKeyArraySelector",stega:{enabled:!0,studioUrl:u,logger:l,filter:i?e=>i({path:e.sourcePath,filterDefault:()=>e.filterDefault(e)}):void 0}})):(null==(o=null==l?void 0:l.error)||o.call(l,"[@sanity/preview-kit]: Content source map enabled client is enabled, but no studioUrl is provided. Falling back to @sanity/client"),e(s))}catch(e){console.error("[@sanity/preview-kit]: Error creating client",e,"falling back to non-embedded sourcemap mode")}return e(s)};function t(){try{return"true"===import.meta.env.SANITY_SOURCE_MAP}catch{}try{return"true"===process.env.SANITY_SOURCE_MAP}catch{}return!1}function n(){try{return import.meta.env.SANITY_STUDIO_URL}catch{}try{return process.env.SANITY_STUDIO_URL}catch{}}export{r as createClient};//# sourceMappingURL=createClient.js.map

@@ -1,2 +0,1 @@

export{createClient}from"./createClient.js";
//# sourceMappingURL=index.js.map
import{createClient as e}from"./createClient.js";export{e as createClient};//# sourceMappingURL=index.js.map

@@ -1,2 +0,1 @@

import{createContext as o}from"react";const r=o(null);export{r as defineStoreContext};
//# sourceMappingURL=context.js.map
import{createContext as o}from"react";const r=o(null);export{r as defineStoreContext};//# sourceMappingURL=context.js.map

@@ -1,2 +0,1 @@

import{useQueryParams as t}from"@sanity/preview-kit-compat";import{useContext as n,useMemo as i,useState as r,useCallback as e}from"react";import o from"react-fast-compare";import{useSyncExternalStoreWithSelector as a}from"use-sync-external-store/with-selector";import{defineStoreContext as s}from"./context.js";function l(l,u,c,p){const{isEqual:h=o}=p||{},d=n(s),f=t(c),m=i((()=>({subscribe:()=>()=>{},getSnapshot:()=>l})),[l]),b=i((()=>(null==d?void 0:d(l,u,f))||{subscribe:()=>()=>{},getSnapshot:()=>l}),[d,l,f,u]),[S]=r((()=>{if(void 0===l)throw new Error("initialSnapshot can't be undefined, if you don't want an initial value use null instead");try{return JSON.parse(JSON.stringify(l))}catch(t){return console.warn("Failed to deep clone initialSnapshot, this is likely an error and an indication that the snapshot isn't JSON serializable",{initialSnapshot:l,error:t}),l}})),v=e((()=>S),[S]),w=e((t=>t),[]),y=a((null==b?void 0:b.subscribe)||m.subscribe,(null==b?void 0:b.getSnapshot)||m.getSnapshot,v,w,h),g=null!==d;return[y,g&&S===y,g]}function u(){return null!==n(s)}export{u as useIsEnabled,l as useLiveQuery};
//# sourceMappingURL=hooks.js.map
import{useQueryParams as t}from"@sanity/preview-kit-compat";import{useContext as n,useMemo as i,useState as r,useCallback as e}from"react";import o from"react-fast-compare";import{useSyncExternalStoreWithSelector as a}from"use-sync-external-store/with-selector";import{defineStoreContext as s}from"./context.js";function l(l,u,c,p){const{isEqual:h=o}=p||{},d=n(s),f=t(c),m=i((()=>({subscribe:()=>()=>{},getSnapshot:()=>l})),[l]),b=i((()=>(null==d?void 0:d(l,u,f))||{subscribe:()=>()=>{},getSnapshot:()=>l}),[d,l,f,u]),[S]=r((()=>{if(void 0===l)throw new Error("initialSnapshot can't be undefined, if you don't want an initial value use null instead");try{return JSON.parse(JSON.stringify(l))}catch(t){return console.warn("Failed to deep clone initialSnapshot, this is likely an error and an indication that the snapshot isn't JSON serializable",{initialSnapshot:l,error:t}),l}})),v=e((()=>S),[S]),w=e((t=>t),[]),y=a((null==b?void 0:b.subscribe)||m.subscribe,(null==b?void 0:b.getSnapshot)||m.getSnapshot,v,w,h),g=null!==d;return[y,g&&S===y,g]}function u(){return null!==n(s)}export{u as useIsEnabled,l as useLiveQuery};//# sourceMappingURL=hooks.js.map

@@ -1,2 +0,1 @@

export{useIsEnabled,useLiveQuery}from"./hooks.js";export{LiveQueryProvider,createLiveQueryProvider,LiveQueryProvider as default}from"./LiveQueryProvider/index.js";
//# sourceMappingURL=index.js.map
import{useIsEnabled as r,useLiveQuery as e}from"./hooks.js";import{LiveQueryProvider as o,createLiveQueryProvider as i,LiveQueryProvider as s}from"./LiveQueryProvider/index.js";export{o as LiveQueryProvider,i as createLiveQueryProvider,s as default,r as useIsEnabled,e as useLiveQuery};//# sourceMappingURL=index.js.map

@@ -1,2 +0,1 @@

export{LiveQuery,LiveQuery as default}from"./LiveQuery.js";
//# sourceMappingURL=index.js.map
import{LiveQuery as e,LiveQuery as r}from"./LiveQuery.js";export{e as LiveQuery,r as default};//# sourceMappingURL=index.js.map

@@ -1,2 +0,1 @@

import{jsx as r}from"react/jsx-runtime";import{lazy as i,Children as e,isValidElement as n}from"react";const a=i((()=>import("./LiveQueryClientComponent.js"))),t={};function o(i){if(!i.enabled)return i.children;const{query:o,params:s=t,initialData:l,as:p}=i;if(p){if(e.count(i.children)>1)throw new Error("LiveQuery: `as` prop can only be used with a single child");if(!n(i.children))throw new Error("LiveQuery: `as` prop requires a valid `children` prop");return r(a,{initialData:l,query:o,params:s,throwOnMissingProvider:i.throwOnMissingProvider,children:r(p,{...i.children.props})})}return r(a,{initialData:l,query:o,params:s,children:i.children})}o.displayName="LiveQuery";export{o as LiveQuery};
//# sourceMappingURL=LiveQuery.js.map
import{jsx as r}from"react/jsx-runtime";import{lazy as i,Children as e,isValidElement as n}from"react";const a=i((()=>import("./LiveQueryClientComponent.js"))),t={};function o(i){if(!i.enabled)return i.children;const{query:o,params:s=t,initialData:l,as:p}=i;if(p){if(e.count(i.children)>1)throw new Error("LiveQuery: `as` prop can only be used with a single child");if(!n(i.children))throw new Error("LiveQuery: `as` prop requires a valid `children` prop");return r(a,{initialData:l,query:o,params:s,throwOnMissingProvider:i.throwOnMissingProvider,children:r(p,{...i.children.props})})}return r(a,{initialData:l,query:o,params:s,children:i.children})}o.displayName="LiveQuery";export{o as LiveQuery};//# sourceMappingURL=LiveQuery.js.map

@@ -1,2 +0,1 @@

"use client";import{memo as r,isValidElement as e,cloneElement as o,Children as t}from"react";import{useLiveQuery as i}from"./useLiveQuery.js";function n(r){const{initialData:n,query:s,params:a,children:u,throwOnMissingProvider:p=!0}=r,[l,d]=i(n,s,a);if(p&&!d)throw new Error("<LiveQuery> require you to wrap them in a parent <LiveQueryProvider> when its 'enabled' prop is true, or set the 'throwOnMissingProvider' prop to 'false' to ignore this error");return e(u)?o(u,{...u.props,data:l,ref:u.ref}):t.count(u)>1?t.only(null):null}n.displayName="LiveQueryClientComponent";const s=r(n);export{s as default};
//# sourceMappingURL=LiveQueryClientComponent.js.map
"use client";import{memo as r,isValidElement as e,cloneElement as o,Children as t}from"react";import{useLiveQuery as i}from"./useLiveQuery.js";function n(r){const{initialData:n,query:s,params:a,children:u,throwOnMissingProvider:p=!0}=r,[l,d]=i(n,s,a);if(p&&!d)throw new Error("<LiveQuery> require you to wrap them in a parent <LiveQueryProvider> when its 'enabled' prop is true, or set the 'throwOnMissingProvider' prop to 'false' to ignore this error");return e(u)?o(u,{...u.props,data:l,ref:u.ref}):t.count(u)>1?t.only(null):null}n.displayName="LiveQueryClientComponent";const s=r(n);export{s as default};//# sourceMappingURL=LiveQueryClientComponent.js.map

@@ -1,2 +0,1 @@

import{useQueryParams as n}from"@sanity/preview-kit-compat";import{useContext as t,useMemo as i,useState as r,useCallback as o,useSyncExternalStore as e}from"react";import{defineStoreContext as a}from"../context.js";function l(l,u,c){const p=t(a),d=n(c),h=i((()=>null==p?void 0:p(l,u,d)),[p,l,d,u]),[f]=r((()=>{if(void 0===l)throw new Error("initialSnapshot can't be undefined, if you don't want an initial value use null instead");try{return JSON.parse(JSON.stringify(l))}catch(n){return console.warn("Failed to deep clone initialSnapshot, this is likely an error and an indication that the snapshot isn't JSON serializable",{initialSnapshot:l,error:n}),l}})),m=o((()=>f),[f]);return[e((null==h?void 0:h.subscribe)||s,(null==h?void 0:h.getSnapshot)||m,m),null!==p]}function s(){return()=>{}}export{l as useLiveQuery};
//# sourceMappingURL=useLiveQuery.js.map
import{useQueryParams as n}from"@sanity/preview-kit-compat";import{useContext as t,useMemo as i,useState as r,useCallback as o,useSyncExternalStore as e}from"react";import{defineStoreContext as a}from"../context.js";function l(l,u,c){const p=t(a),d=n(c),h=i((()=>null==p?void 0:p(l,u,d)),[p,l,d,u]),[f]=r((()=>{if(void 0===l)throw new Error("initialSnapshot can't be undefined, if you don't want an initial value use null instead");try{return JSON.parse(JSON.stringify(l))}catch(n){return console.warn("Failed to deep clone initialSnapshot, this is likely an error and an indication that the snapshot isn't JSON serializable",{initialSnapshot:l,error:n}),l}})),m=o((()=>f),[f]);return[e((null==h?void 0:h.subscribe)||s,(null==h?void 0:h.getSnapshot)||m,m),null!==p]}function s(){return()=>{}}export{l as useLiveQuery};//# sourceMappingURL=useLiveQuery.js.map

@@ -1,2 +0,1 @@

import{lazy as r}from"react";const o=r((()=>import("./LiveQueryProvider.js")));function t(r){return o}export{o as LiveQueryProvider,t as createLiveQueryProvider};
//# sourceMappingURL=index.js.map
import{lazy as r}from"react";const o=r((()=>import("./LiveQueryProvider.js")));function t(r){return o}export{o as LiveQueryProvider,t as createLiveQueryProvider};//# sourceMappingURL=index.js.map

@@ -1,2 +0,1 @@

import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{applySourceDocuments as n}from"@sanity/client/csm";import{useRevalidate as o,useDocumentsInUse as s}from"@sanity/preview-kit-compat";import{vercelStegaSplit as c}from"@vercel/stega";import{LRUCache as i}from"lru-cache";import{applyPatch as a}from"mendoza";import{memo as u,useState as l,useEffect as d,useCallback as f,startTransition as p,useMemo as m}from"react";import{defineStoreContext as h}from"../context.js";const g=new i({max:500}),v=u((function(r){const{children:n,refreshInterval:o=1e4,token:s}=r;if(!r.client)throw new Error("Missing a `client` prop with a configured Sanity client instance");const[c]=l((()=>{const{requestTagPrefix:e,resultSourceMap:t}=r.client.config();return r.client.withConfig({requestTagPrefix:e||"sanity.preview-kit",resultSourceMap:"withKeyArraySelector"!==t||"withKeyArraySelector",...s&&{token:s,useCdn:!1,perspective:"previewDrafts",ignoreBrowserTokenWarning:!0}})})),[i]=l((()=>r.logger));d((()=>{i&&i.log("[@sanity/preview-kit]: With the current configuration you can expect that: Updates that can be traced using Content Source Maps will be applied in real-time. Other updates will be applied every ".concat(o,"ms."))}),[i,o]);const[a,u]=l([]),[g]=l((()=>new Map)),v=function(e){const[t]=l((()=>new Map)),r=f(((r,n,o,s)=>{t.has(r)||(t.set(r,{query:n,params:o,listeners:new Set}),p((()=>e((e=>e.includes(r)?e:[...e,r])))));const c=t.get(r);if(!c||!c.listeners)throw new TypeError("Inconsistent cache for key: "+r);const{listeners:i}=c;return i.add(s),()=>{i.delete(s),0===i.size&&(t.delete(r),p((()=>e((e=>e.includes(r)?e.filter((e=>e!==r)):e)))))}}),[t,e]);return m((()=>({cache:t,subscribe:r})),[t,r])}(u),[w]=l((()=>function(e,t,r){const n=j(t,r);g.has(n)||g.set(n,{result:e,resultSourceMap:{}});return{subscribe:e=>{const o=v.subscribe(n,t,r,e);return()=>o()},getSnapshot:()=>{var e;return null==(e=g.get(n))?void 0:e.result}}})),[b,I]=l([]),[M]=l((()=>new Map)),N=f((e=>{var t;const r=new Set;if(M.clear(),null==(t=e.documents)?void 0:t.length)for(const t of e.documents)r.add(t._id),M.set(t._id,t);p((()=>I((e=>{const t=Array.from(new Set([...e,...r]));return JSON.stringify(t.sort())===JSON.stringify(e.sort())?e:t}))))}),[M]);return e(h.Provider,{value:w,children:[n,t(S,{cache:v.cache,client:c,setTurboIds:I,snapshots:g,turboIds:b,docsInUse:M}),a.map((e=>{if(!v.cache.has(e))return null;const{query:r,params:n,listeners:s}=v.cache.get(e);return t(y,{client:c,listeners:s,params:n,query:r,refreshInterval:o,snapshots:g,turboIdsFromSourceMap:N},e)}))]})}));v.displayName="LiveStoreProvider";const y=u((function(e){const{client:t,refreshInterval:r,query:n,params:s,listeners:c,snapshots:i,turboIdsFromSourceMap:a}=e,{projectId:u,dataset:f}=m((()=>{const{projectId:e,dataset:r}=t.config();return{projectId:e,dataset:r}}),[t]),[p,h]=l(null);if(p)throw p;const[g,v]=o({refreshInterval:r}),y="refresh"===g||"inflight"===g;return d((()=>{if(!y)return;let e=!1;const r=new AbortController;const o=v();return async function(){const{signal:o}=r,{result:l,resultSourceMap:d}=await t.fetch(n,s,{signal:o,filterResponse:!1});if(!o.aborted){i.set(j(n,s),{result:M(u,f,l,d),resultSourceMap:null!=d?d:{}}),d&&a(d);for(const e of c.values())e();e=!0}}().catch((e=>{"AbortError"!==e.name&&h(e)})).finally(o),()=>{e||r.abort()}}),[t,f,c,s,u,n,y,i,v,a]),null}));function w(e,t,r){return"".concat(e,"-").concat(t,"-").concat(r)}y.displayName="QuerySubscription";const S=u((function(e){const{client:n,snapshots:o,cache:c,turboIds:i,setTurboIds:u,docsInUse:f}=e,{projectId:h,dataset:v}=m((()=>{const{projectId:e,dataset:t}=n.config();return{projectId:e,dataset:t}}),[n]);d((()=>{var e,t;const r=new Set;f.clear();for(const{query:n,params:s}of c.values()){const c=j(n,s),i=o.get(c);if(i&&(null==(t=null==(e=i.resultSourceMap)?void 0:e.documents)?void 0:t.length))for(const e of i.resultSourceMap.documents)r.add(e._id),f.set(e._id,e)}const n=[...r].sort();JSON.stringify(i)!==JSON.stringify(n)&&p((()=>u(n)))}),[c,u,o,i,f]),s(f,h,v);const[y,S]=l([]);d((()=>{const e=new Set(y.flat()),t=new Set;for(const r of i)e.has(r)||g.has(w(h,v,r))||t.add(r);const r=[...t].slice(0,100);0!==r.length&&p((()=>S((e=>[...e.slice(-100),r]))))}),[y,v,h,i]);const[I,N]=l();return d((()=>{const e=n.listen("*",{},{events:["mutation"],effectFormat:"mendoza",includePreviousRevision:!1,includeResult:!1,tag:"turbo"}).subscribe((e=>{var t,r;if("mutation"!==e.type||!(null==(r=null==(t=e.effects)?void 0:t.apply)?void 0:r.length))return;const n=w(h,v,e.documentId),o=g.peek(n);if(o){const t={...o};delete t._rev;const r=a(t,e.effects.apply);g.set(n,r)}p((()=>N(e.documentId)))}));return()=>e.unsubscribe()}),[n,v,h]),d((()=>{var e,t,r;if(!I||!i.includes(I))return;const n=[];for(const[r,s]of o.entries())(null==(t=null==(e=s.resultSourceMap)?void 0:e.documents)?void 0:t.length)&&(s.result=M(h,v,s.result,s.resultSourceMap),n.push(r));for(const e of n){const t=null==(r=c.get(e))?void 0:r.listeners;if(t)for(const e of t)e()}p((()=>N(void 0)))}),[c,v,I,h,o,i]),t(r,{children:y.map((e=>t(b,{client:n,projectId:h,dataset:v,ids:e},JSON.stringify(e))))})}));S.displayName="Turbo";const b=u((function(e){const{client:t,projectId:r,dataset:n,ids:o}=e;return d((()=>{const e=o.filter((e=>!g.has(w(r,n,e))));0!==e.length&&t.getDocuments(e).then((e=>{for(const t of e)t&&(null==t?void 0:t._id)&&g.set(w(r,n,t._id),t)}),console.error)}),[t,n,o,r]),null}));b.displayName="GetDocuments";let I=!1;function M(e,t,r,o){return o?n(r,o,(r=>{if(!r._projectId)return g.get(w(e,t,r._id));I||(console.warn("Cross dataset references are not supported yet, ignoring source document",r),I=!0)}),((e,{previousValue:t})=>{if("string"==typeof e&&"string"==typeof t){const{encoded:r}=c(t),{cleaned:n}=c(e);return"".concat(r).concat(n)}return e}),"previewDrafts"):r}function j(e,t){return"".concat(e,"-").concat(JSON.stringify(t))}export{v as default};
//# sourceMappingURL=LiveQueryProvider.js.map
import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{applySourceDocuments as n}from"@sanity/client/csm";import{useRevalidate as s,useDocumentsInUse as o}from"@sanity/preview-kit-compat";import{vercelStegaSplit as c}from"@vercel/stega";import{LRUCache as i}from"lru-cache";import{applyPatch as a}from"mendoza";import{memo as u,useState as l,useEffect as d,useCallback as f,startTransition as p,useMemo as m}from"react";import{defineStoreContext as h}from"../context.js";const g=new i({max:500}),y=u((function(r){const{children:n,refreshInterval:s=1e4,token:o}=r;if(!r.client)throw new Error("Missing a `client` prop with a configured Sanity client instance");const[c]=l((()=>{const{requestTagPrefix:e,resultSourceMap:t}=r.client.config();return r.client.withConfig({requestTagPrefix:e||"sanity.preview-kit",resultSourceMap:"withKeyArraySelector"!==t||"withKeyArraySelector",...o&&{token:o,useCdn:!1,perspective:"previewDrafts",ignoreBrowserTokenWarning:!0}})})),[i]=l((()=>r.logger));d((()=>{i&&i.log(`[@sanity/preview-kit]: With the current configuration you can expect that: Updates that can be traced using Content Source Maps will be applied in real-time. Other updates will be applied every ${s}ms.`)}),[i,s]);const[a,u]=l([]),[g]=l((()=>new Map)),y=function(e){const[t]=l((()=>new Map)),r=f(((r,n,s,o)=>{t.has(r)||(t.set(r,{query:n,params:s,listeners:new Set}),p((()=>e((e=>e.includes(r)?e:[...e,r])))));const c=t.get(r);if(!c||!c.listeners)throw new TypeError("Inconsistent cache for key: "+r);const{listeners:i}=c;return i.add(o),()=>{i.delete(o),0===i.size&&(t.delete(r),p((()=>e((e=>e.includes(r)?e.filter((e=>e!==r)):e)))))}}),[t,e]);return m((()=>({cache:t,subscribe:r})),[t,r])}(u),[w]=l((()=>function(e,t,r){const n=j(t,r);return g.has(n)||g.set(n,{result:e,resultSourceMap:{}}),{subscribe:e=>{const s=y.subscribe(n,t,r,e);return()=>s()},getSnapshot:()=>{var e;return null==(e=g.get(n))?void 0:e.result}}})),[b,I]=l([]),[M]=l((()=>new Map)),N=f((e=>{var t;const r=new Set;if(M.clear(),null!=(t=e.documents)&&t.length)for(const t of e.documents)r.add(t._id),M.set(t._id,t);p((()=>I((e=>{const t=Array.from(new Set([...e,...r]));return JSON.stringify(t.sort())===JSON.stringify(e.sort())?e:t}))))}),[M]);return e(h.Provider,{value:w,children:[n,t(S,{cache:y.cache,client:c,setTurboIds:I,snapshots:g,turboIds:b,docsInUse:M}),a.map((e=>{if(!y.cache.has(e))return null;const{query:r,params:n,listeners:o}=y.cache.get(e);return t(v,{client:c,listeners:o,params:n,query:r,refreshInterval:s,snapshots:g,turboIdsFromSourceMap:N},e)}))]})}));y.displayName="LiveStoreProvider";const v=u((function(e){const{client:t,refreshInterval:r,query:n,params:o,listeners:c,snapshots:i,turboIdsFromSourceMap:a}=e,{projectId:u,dataset:f}=m((()=>{const{projectId:e,dataset:r}=t.config();return{projectId:e,dataset:r}}),[t]),[p,h]=l(null);if(p)throw p;const[g,y]=s({refreshInterval:r}),v="refresh"===g||"inflight"===g;return d((()=>{if(!v)return;let e=!1;const r=new AbortController;const s=y();return async function(){const{signal:s}=r,{result:l,resultSourceMap:d}=await t.fetch(n,o,{signal:s,filterResponse:!1});if(!s.aborted){i.set(j(n,o),{result:M(u,f,l,d),resultSourceMap:null!=d?d:{}}),d&&a(d);for(const e of c.values())e();e=!0}}().catch((e=>{"AbortError"!==e.name&&h(e)})).finally(s),()=>{e||r.abort()}}),[t,f,c,o,u,n,v,i,y,a]),null}));function w(e,t,r){return`${e}-${t}-${r}`}v.displayName="QuerySubscription";const S=u((function(e){const{client:n,snapshots:s,cache:c,turboIds:i,setTurboIds:u,docsInUse:f}=e,{projectId:h,dataset:y}=m((()=>{const{projectId:e,dataset:t}=n.config();return{projectId:e,dataset:t}}),[n]);d((()=>{var e,t;const r=new Set;f.clear();for(const{query:n,params:o}of c.values()){const c=j(n,o),i=s.get(c);if(i&&null!=(t=null==(e=i.resultSourceMap)?void 0:e.documents)&&t.length)for(const e of i.resultSourceMap.documents)r.add(e._id),f.set(e._id,e)}const n=[...r].sort();JSON.stringify(i)!==JSON.stringify(n)&&p((()=>u(n)))}),[c,u,s,i,f]),o(f,h,y);const[v,S]=l([]);d((()=>{const e=new Set(v.flat()),t=new Set;for(const r of i)!e.has(r)&&!g.has(w(h,y,r))&&t.add(r);const r=[...t].slice(0,100);0!==r.length&&p((()=>S((e=>[...e.slice(-100),r]))))}),[v,y,h,i]);const[I,N]=l();return d((()=>{const e=n.listen("*",{},{events:["mutation"],effectFormat:"mendoza",includePreviousRevision:!1,includeResult:!1,tag:"turbo"}).subscribe((e=>{var t,r;if("mutation"!==e.type||null==(r=null==(t=e.effects)?void 0:t.apply)||!r.length)return;const n=w(h,y,e.documentId),s=g.peek(n);if(s){const t={...s};delete t._rev;const r=a(t,e.effects.apply);g.set(n,r)}p((()=>N(e.documentId)))}));return()=>e.unsubscribe()}),[n,y,h]),d((()=>{var e,t,r;if(!I||!i.includes(I))return;const n=[];for(const[r,o]of s.entries())null!=(t=null==(e=o.resultSourceMap)?void 0:e.documents)&&t.length&&(o.result=M(h,y,o.result,o.resultSourceMap),n.push(r));for(const e of n){const t=null==(r=c.get(e))?void 0:r.listeners;if(t)for(const e of t)e()}p((()=>N(void 0)))}),[c,y,I,h,s,i]),t(r,{children:v.map((e=>t(b,{client:n,projectId:h,dataset:y,ids:e},JSON.stringify(e))))})}));S.displayName="Turbo";const b=u((function(e){const{client:t,projectId:r,dataset:n,ids:s}=e;return d((()=>{const e=s.filter((e=>!g.has(w(r,n,e))));0!==e.length&&t.getDocuments(e).then((e=>{for(const t of e)t&&null!=t&&t._id&&g.set(w(r,n,t._id),t)}),console.error)}),[t,n,s,r]),null}));b.displayName="GetDocuments";let I=!1;function M(e,t,r,s){return s?n(r,s,(r=>{if(!r._projectId)return g.get(w(e,t,r._id));I||(console.warn("Cross dataset references are not supported yet, ignoring source document",r),I=!0)}),((e,{previousValue:t})=>{if("string"==typeof e&&"string"==typeof t){const{encoded:r}=c(t),{cleaned:n}=c(e);return`${r}${n}`}return e}),"previewDrafts"):r}function j(e,t){return`${e}-${JSON.stringify(t)}`}export{y as default};//# sourceMappingURL=LiveQueryProvider.js.map
{
"name": "@sanity/preview-kit",
"version": "5.0.22",
"version": "5.0.23",
"description": "General purpose utils for live content and visual editing",

@@ -108,13 +108,12 @@ "keywords": [

"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@sanity/client": "^6.13.3",
"@sanity/pkg-utils": "4.2.3",
"@sanity/client": "^6.14.2",
"@sanity/pkg-utils": "4.2.8",
"@sanity/semantic-release-preset": "^4.1.6",
"@types/node": "^18.18.6",
"@types/react": "^18.2.56",
"@types/react": "^18.2.57",
"@types/react-dom": "^18.2.19",
"@types/use-sync-external-store": "^0.0.6",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"@vitest/coverage-v8": "^1.3.0",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@vitest/coverage-v8": "^1.3.1",
"eslint": "^8.56.0",

@@ -132,7 +131,7 @@ "eslint-config-prettier": "^9.1.0",

"typescript": "^5.3.3",
"vitest": "^1.3.0",
"vitest": "^1.3.1",
"vitest-github-actions-reporter": "^0.11.1"
},
"peerDependencies": {
"@sanity/client": "^6.13.3",
"@sanity/client": "^6.14.2",
"react": "^18.0.0"

@@ -139,0 +138,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc