@lensmcp/valtio-instrumentation 1.20.0 → 1.21.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/lib/proxy.js CHANGED
@@ -1 +1 @@
1
- "use strict";var h=Object.defineProperty;var a=(e,t)=>h(e,"name",{value:t,configurable:!0});var P=Object.defineProperty,o=a((e,t)=>P(e,"name",{value:t,configurable:!0}),"a"),x=Object.defineProperty,c=o((e,t)=>x(e,"name",{value:t,configurable:!0}),"s");import{proxy as $,subscribe as w,unstable_enableOp as O}from"valtio/vanilla";import{publish as l,depsHash as d}from"@lensmcp/react-instrumentation";import{registerStore as S,subscribersForPathAndParents as I,tagProxy as j}from"./store-registry.js";let v=!1;function u(){if(!v)try{O(!0),v=!0}catch{}}a(u,"l"),o(u,"x"),c(u,"ensureOpsEnabled");let H=0;export function proxy(e,t={}){u();const r=t.storeId??`valtio:store:${++H}`;S(r,t.source);const n=$(e);return j(n,r),l({source:"valtio",category:"state",severity:"info",title:`store-created ${r}`,fingerprint:`valtio-store:${r}`,raw:{kind:"store-created",store:{storeId:r,source:t.source,initialPreview:t.emitInitialPreview===!1?void 0:i(e)}}}),w(n,b=>{for(const y of b){const[,p,f,g]=y,s=(p??[]).map(String).join(".");if(!s)continue;const m=(p??[]).map(String);l({source:"valtio",category:"state",severity:"info",title:`state-update ${r}.${s}`,fingerprint:`valtio-update:${r}:${s}`,raw:{kind:"state-update",update:{storeId:r,path:s,changedKeys:m,beforeHash:d([g]),afterHash:d([f]),preview:i(f),subscribers:I(r,s)}}})}},!0),n}a(proxy,"proxy"),o(proxy,"proxy"),c(proxy,"proxy");function i(e){try{return JSON.parse(JSON.stringify(e))}catch{return}}a(i,"n"),o(i,"f"),c(i,"safePreview");
1
+ "use strict";var m=Object.defineProperty;var a=(t,r)=>m(t,"name",{value:r,configurable:!0});var h=Object.defineProperty,i=a((t,r)=>h(t,"name",{value:r,configurable:!0}),"s");import{proxy as P,subscribe as $,unstable_enableOp as w}from"valtio/vanilla";import{publish as p,depsHash as f}from"@lensmcp/react-instrumentation";import{registerStore as x,subscribersForPathAndParents as S,tagProxy as O}from"./store-registry.js";let d=!1;function l(){if(!d)try{w(!0),d=!0}catch{}}a(l,"x"),i(l,"ensureOpsEnabled");let I=0;export function proxy(t,r={}){l();const e=r.storeId??`valtio:store:${++I}`;x(e,r.source);const o=P(t);return O(o,e),p({source:"valtio",category:"state",severity:"info",title:`store-created ${e}`,fingerprint:`valtio-store:${e}`,raw:{kind:"store-created",store:{storeId:e,source:r.source,initialPreview:r.emitInitialPreview===!1?void 0:n(t)}}}),$(o,v=>{for(const b of v){const[,c,u,y]=b,s=(c??[]).map(String).join(".");if(!s)continue;const g=(c??[]).map(String);p({source:"valtio",category:"state",severity:"info",title:`state-update ${e}.${s}`,fingerprint:`valtio-update:${e}:${s}`,raw:{kind:"state-update",update:{storeId:e,path:s,changedKeys:g,beforeHash:f([y]),afterHash:f([u]),preview:n(u),subscribers:S(e,s)}}})}},!0),o}a(proxy,"proxy"),i(proxy,"proxy");function n(t){try{return JSON.parse(JSON.stringify(t))}catch{return}}a(n,"f"),i(n,"safePreview");
package/lib/snapshot.js CHANGED
@@ -1 +1 @@
1
- "use strict";var k=Object.defineProperty;var a=(e,n)=>k(e,"name",{value:n,configurable:!0});var $=Object.defineProperty,u=a((e,n)=>$(e,"name",{value:n,configurable:!0}),"a"),w=Object.defineProperty,p=u((e,n)=>w(e,"name",{value:n,configurable:!0}),"c");import{useCallback as M,useEffect as m,useLayoutEffect as T,useMemo as I,useRef as S,useSyncExternalStore as x}from"react";import{snapshot as v,subscribe as E}from"valtio/vanilla";import{useSnapshot as L}from"valtio/react";import{affectedToPathList as C,createProxy as N,isChanged as W}from"proxy-compare";import{useLensmcpContext as y,publish as O}from"@lensmcp/react-instrumentation";import{addSubscription as _,removeSubscription as A,storeIdOf as H}from"./store-registry.js";const j=new WeakMap;export function useTrackedSnapshot(e,n){const r=y(),t=n.path??"",o=r.componentInstanceId??"react:component:anonymous";return m(()=>(c("added",n.storeId,t,o),()=>{c("removed",n.storeId,t,o)}),[n.storeId,t,o]),L(e)}a(useTrackedSnapshot,"useTrackedSnapshot"),u(useTrackedSnapshot,"useTrackedSnapshot"),p(useTrackedSnapshot,"useTrackedSnapshot");export function useSnapshot(e){const n=H(e)??"valtio:store:anonymous",r=y().componentInstanceId??"react:component:anonymous",t=I(()=>e&&new WeakMap,[e]),o=S(void 0);let b=!0;const d=x(M(s=>{const i=E(e,s,!1);return s(),i},[e]),()=>{const s=v(e);try{if(!b&&o.current&&t&&!W(o.current,s,t,new WeakMap))return o.current}catch{}return s},()=>v(e));b=!1,T(()=>{o.current=d});const g=I(()=>new WeakMap,[]),f=S(void 0);return f.current||(f.current=new Set),m(()=>{const s=t?C(d,t,!0).map(P=>truncatePath(P)):[],i=new Set(s.length?s:[""]);l(f.current,i,n,r)}),m(()=>{const s=f.current;return()=>{for(const i of[...s])c("removed",n,i,r);s.clear()}},[n,r]),t?N(d,t,g,j):d}a(useSnapshot,"useSnapshot"),u(useSnapshot,"useSnapshot"),p(useSnapshot,"useSnapshot");const h=(()=>{const e=typeof process<"u"?process.env?.LENSMCP_VALTIO_PATH_DEPTH:void 0,n=Number(e);return Number.isFinite(n)&&n>=0&&n<=20?Math.floor(n):3})();export function truncatePath(e){const n=h>0&&h<e.length?h:e.length;let r="";for(let t=0;t<n;t++)r+=t===0?String(e[t]):`.${String(e[t])}`;return r}a(truncatePath,"truncatePath"),u(truncatePath,"truncatePath"),p(truncatePath,"truncatePath");function l(e,n,r,t){for(const o of n)e.has(o)||c("added",r,o,t);for(const o of[...e])n.has(o)||c("removed",r,o,t);e.clear();for(const o of n)e.add(o)}a(l,"v"),u(l,"N"),p(l,"reconcileSubscriptions");function c(e,n,r,t){e==="added"?_({storeId:n,path:r,componentInstanceId:t}):A({storeId:n,path:r,componentInstanceId:t});const o=e==="added"?"sub":"unsub";O({source:"valtio",category:"state",severity:"debug",title:`subscription-${e} ${n}.${r}`,fingerprint:`valtio-${o}:${n}:${r}:${t}`,raw:{kind:`subscription-${e}`,subscription:{storeId:n,path:r,componentInstanceId:t}}})}a(c,"c"),u(c,"i"),p(c,"emitSubscription");
1
+ "use strict";var $=Object.defineProperty;var a=(t,o)=>$(t,"name",{value:o,configurable:!0});var k=Object.defineProperty,i=a((t,o)=>k(t,"name",{value:o,configurable:!0}),"c");import{useCallback as P,useEffect as f,useLayoutEffect as w,useMemo as l,useRef as b,useSyncExternalStore as M}from"react";import{snapshot as I,subscribe as T}from"valtio/vanilla";import{useSnapshot as x}from"valtio/react";import{affectedToPathList as E,createProxy as L,isChanged as C}from"proxy-compare";import{useLensmcpContext as S,publish as W}from"@lensmcp/react-instrumentation";import{addSubscription as N,removeSubscription as _,storeIdOf as A}from"./store-registry.js";const H=new WeakMap;export function useTrackedSnapshot(t,o){const r=S(),e=o.path??"",n=r.componentInstanceId??"react:component:anonymous";return f(()=>(c("added",o.storeId,e,n),()=>{c("removed",o.storeId,e,n)}),[o.storeId,e,n]),x(t)}a(useTrackedSnapshot,"useTrackedSnapshot"),i(useTrackedSnapshot,"useTrackedSnapshot");export function useSnapshot(t){const o=A(t)??"valtio:store:anonymous",r=S().componentInstanceId??"react:component:anonymous",e=l(()=>t&&new WeakMap,[t]),n=b(void 0);let h=!0;const p=M(P(s=>{const u=T(t,s,!1);return s(),u},[t]),()=>{const s=I(t);try{if(!h&&n.current&&e&&!C(n.current,s,e,new WeakMap))return n.current}catch{}return s},()=>I(t));h=!1,w(()=>{n.current=p});const y=l(()=>new WeakMap,[]),d=b(void 0);return d.current||(d.current=new Set),f(()=>{const s=e?E(p,e,!0).map(g=>truncatePath(g)):[],u=new Set(s.length?s:[""]);v(d.current,u,o,r)}),f(()=>{const s=d.current;return()=>{for(const u of[...s])c("removed",o,u,r);s.clear()}},[o,r]),e?L(p,e,y,H):p}a(useSnapshot,"useSnapshot"),i(useSnapshot,"useSnapshot");const m=(()=>{const t=typeof process<"u"?process.env?.LENSMCP_VALTIO_PATH_DEPTH:void 0,o=Number(t);return Number.isFinite(o)&&o>=0&&o<=20?Math.floor(o):3})();export function truncatePath(t){const o=m>0&&m<t.length?m:t.length;let r="";for(let e=0;e<o;e++)r+=e===0?String(t[e]):`.${String(t[e])}`;return r}a(truncatePath,"truncatePath"),i(truncatePath,"truncatePath");function v(t,o,r,e){for(const n of o)t.has(n)||c("added",r,n,e);for(const n of[...t])o.has(n)||c("removed",r,n,e);t.clear();for(const n of o)t.add(n)}a(v,"N"),i(v,"reconcileSubscriptions");function c(t,o,r,e){t==="added"?N({storeId:o,path:r,componentInstanceId:e}):_({storeId:o,path:r,componentInstanceId:e});const n=t==="added"?"sub":"unsub";W({source:"valtio",category:"state",severity:"debug",title:`subscription-${t} ${o}.${r}`,fingerprint:`valtio-${n}:${o}:${r}:${e}`,raw:{kind:`subscription-${t}`,subscription:{storeId:o,path:r,componentInstanceId:e}}})}a(c,"i"),i(c,"emitSubscription");
@@ -1 +1 @@
1
- "use strict";var f=Object.defineProperty;var o=(e,t)=>f(e,"name",{value:t,configurable:!0});var g=Object.defineProperty,s=o((e,t)=>g(e,"name",{value:t,configurable:!0}),"o"),S=Object.defineProperty,n=s((e,t)=>S(e,"name",{value:t,configurable:!0}),"n");const i=new Map,a=new Map,d=new WeakMap;export function registerStore(e,t){a.set(e,{storeId:e,source:t})}o(registerStore,"registerStore"),s(registerStore,"registerStore"),n(registerStore,"registerStore");export function tagProxy(e,t){d.set(e,t)}o(tagProxy,"tagProxy"),s(tagProxy,"tagProxy"),n(tagProxy,"tagProxy");export function storeIdOf(e){return d.get(e)}o(storeIdOf,"storeIdOf"),s(storeIdOf,"storeIdOf"),n(storeIdOf,"storeIdOf");export function isStoreRegistered(e){return a.has(e)}o(isStoreRegistered,"isStoreRegistered"),s(isStoreRegistered,"isStoreRegistered"),n(isStoreRegistered,"isStoreRegistered");export function addSubscription(e){const t=`${e.storeId}::${e.path}`;let r=i.get(t);r||(r=new Set,i.set(t,r)),r.add(e.componentInstanceId)}o(addSubscription,"addSubscription"),s(addSubscription,"addSubscription"),n(addSubscription,"addSubscription");export function removeSubscription(e){const t=`${e.storeId}::${e.path}`,r=i.get(t);r&&(r.delete(e.componentInstanceId),r.size===0&&i.delete(t))}o(removeSubscription,"removeSubscription"),s(removeSubscription,"removeSubscription"),n(removeSubscription,"removeSubscription");export function subscribersFor(e,t){return[...i.get(`${e}::${t}`)??[]]}o(subscribersFor,"subscribersFor"),s(subscribersFor,"subscribersFor"),n(subscribersFor,"subscribersFor");export function subscribersForPathAndParents(e,t){const r=new Set,u=t.split(".");for(let c=u.length;c>0;c--){const p=u.slice(0,c).join(".");for(const b of subscribersFor(e,p))r.add(b)}for(const c of subscribersFor(e,""))r.add(c);return[...r]}o(subscribersForPathAndParents,"subscribersForPathAndParents"),s(subscribersForPathAndParents,"subscribersForPathAndParents"),n(subscribersForPathAndParents,"subscribersForPathAndParents");export function resetRegistry(){i.clear(),a.clear()}o(resetRegistry,"resetRegistry"),s(resetRegistry,"resetRegistry"),n(resetRegistry,"resetRegistry");
1
+ "use strict";var f=Object.defineProperty;var o=(e,t)=>f(e,"name",{value:t,configurable:!0});var b=Object.defineProperty,n=o((e,t)=>b(e,"name",{value:t,configurable:!0}),"n");const s=new Map,c=new Map,u=new WeakMap;export function registerStore(e,t){c.set(e,{storeId:e,source:t})}o(registerStore,"registerStore"),n(registerStore,"registerStore");export function tagProxy(e,t){u.set(e,t)}o(tagProxy,"tagProxy"),n(tagProxy,"tagProxy");export function storeIdOf(e){return u.get(e)}o(storeIdOf,"storeIdOf"),n(storeIdOf,"storeIdOf");export function isStoreRegistered(e){return c.has(e)}o(isStoreRegistered,"isStoreRegistered"),n(isStoreRegistered,"isStoreRegistered");export function addSubscription(e){const t=`${e.storeId}::${e.path}`;let r=s.get(t);r||(r=new Set,s.set(t,r)),r.add(e.componentInstanceId)}o(addSubscription,"addSubscription"),n(addSubscription,"addSubscription");export function removeSubscription(e){const t=`${e.storeId}::${e.path}`,r=s.get(t);r&&(r.delete(e.componentInstanceId),r.size===0&&s.delete(t))}o(removeSubscription,"removeSubscription"),n(removeSubscription,"removeSubscription");export function subscribersFor(e,t){return[...s.get(`${e}::${t}`)??[]]}o(subscribersFor,"subscribersFor"),n(subscribersFor,"subscribersFor");export function subscribersForPathAndParents(e,t){const r=new Set,a=t.split(".");for(let i=a.length;i>0;i--){const d=a.slice(0,i).join(".");for(const p of subscribersFor(e,d))r.add(p)}for(const i of subscribersFor(e,""))r.add(i);return[...r]}o(subscribersForPathAndParents,"subscribersForPathAndParents"),n(subscribersForPathAndParents,"subscribersForPathAndParents");export function resetRegistry(){s.clear(),c.clear()}o(resetRegistry,"resetRegistry"),n(resetRegistry,"resetRegistry");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/valtio-instrumentation",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@lensmcp/react-instrumentation": "1.20.0",
17
+ "@lensmcp/react-instrumentation": "1.21.0",
18
18
  "proxy-compare": "^3.0.0",
19
19
  "tslib": "^2.3.0"
20
20
  },