@lensmcp/valtio-instrumentation 1.25.7 → 1.25.9
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/preview.js +1 -1
- package/lib/proxy.js +1 -1
- package/lib/snapshot.js +1 -1
- package/lib/store-registry.js +1 -1
- package/package.json +3 -3
package/lib/preview.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var A=Object.defineProperty;var
|
|
1
|
+
"use strict";var A=Object.defineProperty;var u=(n,t)=>A(n,"name",{value:t,configurable:!0});var E=Object.defineProperty,s=u((n,t)=>E(n,"name",{value:t,configurable:!0}),"n"),j=Object.defineProperty,a=s((n,t)=>j(n,"name",{value:t,configurable:!0}),"s");export const DEFAULT_PREVIEW_LIMITS={maxBytes:4096,maxDepth:3,maxEntries:20,maxStringChars:256};const o=32,p=32,k=2+o+p;export function previewValue(n,t=DEFAULT_PREVIEW_LIMITS){if(!(t.maxBytes>=o))return;const i={limits:t,budget:t.maxBytes};return f(n,i,1,0)}u(previewValue,"previewValue"),s(previewValue,"previewValue"),a(previewValue,"previewValue");function f(n,t,i,r){switch(typeof n){case"string":return d(n,Math.min(t.limits.maxStringChars,t.budget-r-2),t);case"number":return c(t,Number.isFinite(n)?n:null);case"boolean":return c(t,n);case"bigint":return d(n.toString(),o-2,t);case"undefined":case"function":case"symbol":return;default:break}if(n===null)return c(t,null);if(n instanceof Date)return Number.isNaN(n.getTime())?c(t,null):d(n.toISOString(),o-2,t);if(ArrayBuffer.isView(n))return g(t,`[${Object.prototype.toString.call(n).slice(8,-1)}(${n.byteLength} B)]`);const e=i<=t.limits.maxDepth&&t.budget-r>=k;return Array.isArray(n)?e?y(n,t,i,r):g(t,`[Array(${n.length})]`):e?x(n,t,i,r):g(t,"[Object]")}u(f,"m"),s(f,"l"),a(f,"previewOf");function y(n,t,i,r){const e=[];t.budget-=2;const b=r+p,h=Math.min(n.length,t.limits.maxEntries);for(let l=0;l<h&&!(t.budget-b-1<o);l++){t.budget-=1;const m=f(n[l],t,i+1,b);e.push(m===void 0?c(t,null):m)}return e.length<n.length&&e.push(g(t,`\u2026 ${n.length-e.length} more items`)),e}u(y,"S"),s(y,"k"),a(y,"previewArray");function x(n,t,i,r){const e={};t.budget-=2;const b=r+p,h=Object.keys(n);let l=0;for(const m of h){if(l>=t.limits.maxEntries)break;const S=v(m,t.limits.maxStringChars),w=S.length+4;if(t.budget-b-w<o)break;const $=t.budget;t.budget-=w;const O=f(n[m],t,i+1,b);O===void 0?t.budget=$:e[S]=O,l+=1}return l<h.length&&(t.budget-=5,e["\u2026"]=g(t,`+${h.length-l} more keys`)),e}u(x,"v"),s(x,"A"),a(x,"previewObject");function c(n,t){return n.budget-=t===null?4:String(t).length,t}u(c,"o"),s(c,"b"),a(c,"spend");function g(n,t){return n.budget-=t.length+2,t}u(g,"c"),s(g,"d"),a(g,"summary");function d(n,t,i){let r=n;if(n.length>t){const e=Math.max(0,Math.floor(t)-11-String(n.length).length);r=`${n.slice(0,e)}\u2026 (+${n.length-e} chars)`}return i.budget-=r.length+2,r}u(d,"f"),s(d,"a"),a(d,"clipString");function v(n,t){return n.length<=t?n:`${n.slice(0,t)}\u2026`}u(v,"$"),s(v,"M"),a(v,"clipKey");
|
package/lib/proxy.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var P=Object.defineProperty;var a=(e,t)=>P(e,"name",{value:t,configurable:!0});var I=Object.defineProperty,o=a((e,t)=>I(e,"name",{value:t,configurable:!0}),"o"),x=Object.defineProperty,u=o((e,t)=>x(e,"name",{value:t,configurable:!0}),"n");import{proxy as E,subscribe as w,unstable_enableOp as S}from"valtio/vanilla";import{publish as $,publishLazy as L,depsHash as v,notePageState as _}from"@lensmcp/react-instrumentation";import{DEFAULT_PREVIEW_LIMITS as d,previewValue as O}from"./preview.js";import{registerStore as T,subscribersForPathAndParents as V,tagProxy as A}from"./store-registry.js";import{truncatePath as m}from"./snapshot.js";let b=!1;function p(){if(!b)try{S(!0),b=!0}catch{}}a(p,"m"),o(p,"L"),u(p,"ensureOpsEnabled");let j=0;export function proxy(e,t={}){p();const r=t.storeId??`valtio:store:${++j}`;T(r,t.source);const n=E(e);return A(n,r),$({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===!0?i(e):void 0}}}),w(n,y=>{for(const g of y){const[,s,f,h]=g;if(!(s??[]).length)continue;const l=`valtio-update:${r}:${m(s??[])}`;_(r,m(s??[])),L(l,()=>{const c=(s??[]).map(String).join(".");return{source:"valtio",category:"state",severity:"info",title:`state-update ${r}.${c}`,fingerprint:l,raw:{kind:"state-update",update:{storeId:r,path:c,changedKeys:(s??[]).map(String),beforeHash:v([h]),afterHash:v([f]),preview:i(f),subscribers:V(r,c)}}}})}},!0),n}a(proxy,"proxy"),o(proxy,"proxy"),u(proxy,"proxy");const B=(()=>{const e=typeof process<"u"?process.env?.LENSMCP_VALTIO_PREVIEW_BYTES:void 0,t=Number(e),r=e!==void 0&&e!==""&&Number.isFinite(t)&&t>=0;return{...d,maxBytes:r?Math.floor(t):d.maxBytes}})();function i(e){try{return O(e,B)}catch{return}}a(i,"c"),o(i,"l"),u(i,"safePreview");
|
package/lib/snapshot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var $=Object.defineProperty;var a=(e,t)=>$(e,"name",{value:t,configurable:!0});var
|
|
1
|
+
"use strict";var $=Object.defineProperty;var a=(e,t)=>$(e,"name",{value:t,configurable:!0});var A=Object.defineProperty,u=a((e,t)=>A(e,"name",{value:t,configurable:!0}),"a"),k=Object.defineProperty,f=u((e,t)=>k(e,"name",{value:t,configurable:!0}),"a");import{useCallback as x,useEffect as b,useLayoutEffect as N,useMemo as S,useRef as v,useSyncExternalStore as _}from"react";import{snapshot as g,subscribe as E}from"valtio/vanilla";import{useSnapshot as w}from"valtio/react";import{affectedToPathList as C,createProxy as O,isChanged as R}from"proxy-compare";import{estimateJsonBytes as W}from"@lensmcp/protocol-types";import{useComponentIdentity as P,useLensmcpContext as y,publish as B}from"@lensmcp/react-instrumentation";import{addSubscription as F,removeSubscription as H,storeIdOf as V}from"./store-registry.js";const z=new WeakMap;export function useTrackedSnapshot(e,t){const n=y(),o=t.path??"",r=P(),s=n.componentInstanceId??r.componentInstanceId;return b(()=>(h("added",t.storeId,o,s,r.componentLogicalId),()=>{h("removed",t.storeId,o,s,r.componentLogicalId)}),[t.storeId,o,s]),w(e)}a(useTrackedSnapshot,"useTrackedSnapshot"),u(useTrackedSnapshot,"useTrackedSnapshot"),f(useTrackedSnapshot,"useTrackedSnapshot");export function useSnapshot(e){const t=V(e)??"valtio:store:anonymous",n=y(),o=P(),r=n.componentInstanceId??o.componentInstanceId,s=S(()=>e&&new WeakMap,[e]),i=v(void 0);let d=!0;const c=_(x(p=>{const T=E(e,p,!1);return p(),T},[e]),()=>{const p=g(e);try{if(!d&&i.current&&s&&!R(i.current,p,s,new WeakMap))return i.current}catch{}return p},()=>g(e));d=!1,N(()=>{i.current=c});const M=S(()=>new WeakMap,[]),m=v(void 0);return m.current||(m.current=new Set),b(()=>{const p=collectReadPaths(s?C(c,s,!0):[]);reconcileSubscriptions(m.current,p,t,r,o.componentLogicalId)}),b(()=>{const p=m.current;return()=>{dropAllSubscriptions(p,t,r,o.componentLogicalId)}},[t,r]),s?O(c,s,M,z):c}a(useSnapshot,"useSnapshot"),u(useSnapshot,"useSnapshot"),f(useSnapshot,"useSnapshot");const I=(()=>{const e=typeof process<"u"?process.env?.LENSMCP_VALTIO_PATH_DEPTH:void 0,t=Number(e);return Number.isFinite(t)&&t>=0&&t<=20?Math.floor(t):3})(),L=120;export function truncatePath(e){const t=I>0&&I<e.length?I:e.length;let n="";for(let o=0;o<t;o++)if(n+=o===0?String(e[o]):`.${String(e[o])}`,n.length>=L)return`${n.slice(0,L)}\u2026`;return n}a(truncatePath,"truncatePath"),u(truncatePath,"truncatePath"),f(truncatePath,"truncatePath");const j=(()=>{const e=typeof process<"u"?process.env?.LENSMCP_VALTIO_MAX_PATHS:void 0,t=Number(e);return Number.isFinite(t)&&t>=1?Math.floor(t):32})(),D=(()=>{const e=typeof process<"u"?process.env?.LENSMCP_VALTIO_SUB_BYTES:void 0,t=Number(e);return Number.isFinite(t)&&t>0?Math.floor(t):4*1024})();export function collectReadPaths(e){const t=new Set;let n=0,o=0;for(const r of e){const s=truncatePath(r);if(!t.has(s)){if(t.size>=j||o>=D){n++;continue}o+=W(s),t.add(s)}}return t.size===0&&t.add(""),{paths:t,scanned:e.length,dropped:n}}a(collectReadPaths,"collectReadPaths"),u(collectReadPaths,"collectReadPaths"),f(collectReadPaths,"collectReadPaths");export function reconcileSubscriptions(e,t,n,o,r){const s=t.paths,i=[],d=[];for(const c of s)e.has(c)||i.push(c);for(const c of e)s.has(c)||d.push(c);l("added",i,n,o,r,t.dropped),l("removed",d,n,o,r),e.clear();for(const c of s)e.add(c)}a(reconcileSubscriptions,"reconcileSubscriptions"),u(reconcileSubscriptions,"reconcileSubscriptions"),f(reconcileSubscriptions,"reconcileSubscriptions");export function dropAllSubscriptions(e,t,n,o){l("removed",[...e],t,n,o),e.clear()}a(dropAllSubscriptions,"dropAllSubscriptions"),u(dropAllSubscriptions,"dropAllSubscriptions"),f(dropAllSubscriptions,"dropAllSubscriptions");function l(e,t,n,o,r,s=0){if(t.length===0)return;for(const d of t)e==="added"?F({storeId:n,path:d,componentInstanceId:o}):H({storeId:n,path:d,componentInstanceId:o});const i=e==="added"?"sub":"unsub";B({source:"valtio",category:"state",severity:"debug",title:`subscription-${e} ${n} (${t.length} path${t.length===1?"":"s"}${s?`, ${s} dropped`:""})`,fingerprint:`valtio-${i}:${n}`,raw:{kind:`subscription-${e}`,subscription:{storeId:n,path:t[0],paths:[...t],componentInstanceId:o,...r?{componentLogicalId:r}:{},...s?{truncated:!0,droppedPaths:s}:{}}}})}a(l,"f"),u(l,"p"),f(l,"emitSubscriptions");function h(e,t,n,o,r){l(e,[n],t,o,r)}a(h,"I"),u(h,"A"),f(h,"emitSubscription");
|
package/lib/store-registry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var f=Object.defineProperty;var o=(e,t)=>f(e,"name",{value:t,configurable:!0});var
|
|
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");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/valtio-instrumentation",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lensmcp/protocol-types": "1.25.
|
|
18
|
-
"@lensmcp/react-instrumentation": "1.25.
|
|
17
|
+
"@lensmcp/protocol-types": "1.25.9",
|
|
18
|
+
"@lensmcp/react-instrumentation": "1.25.9",
|
|
19
19
|
"proxy-compare": "^3.0.0",
|
|
20
20
|
"tslib": "^2.3.0"
|
|
21
21
|
},
|