@wcstack/state 3.1.0 → 3.3.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.
Files changed (56) hide show
  1. package/README.ja.md +128 -90
  2. package/README.md +129 -91
  3. package/dist/auto.min.js +1 -1
  4. package/dist/auto.min.js.map +1 -1
  5. package/dist/define.d.ts +11 -7
  6. package/dist/index.d.ts +58 -15
  7. package/dist/index.esm.js +1 -1
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/manifest.d.ts +39 -5
  10. package/dist/manifest.esm.js +315 -253
  11. package/dist/parser.d.ts +16 -2
  12. package/dist/parser.esm.js +223 -50
  13. package/dist/split/chunks/binder.js +1 -1
  14. package/dist/split/chunks/binder.js.map +1 -1
  15. package/dist/split/chunks/checkDependency.js +1 -1
  16. package/dist/split/chunks/declarationAliases.js +2 -0
  17. package/dist/split/chunks/declarationAliases.js.map +1 -0
  18. package/dist/split/chunks/declarationHooks.js +2 -0
  19. package/dist/split/chunks/declarationHooks.js.map +1 -0
  20. package/dist/split/chunks/featureBridge.js +2 -0
  21. package/dist/split/chunks/featureBridge.js.map +1 -0
  22. package/dist/split/chunks/filterRegistry.js +1 -1
  23. package/dist/split/chunks/filterRegistry.js.map +1 -1
  24. package/dist/split/chunks/getAllPropertyDescriptors.js +1 -1
  25. package/dist/split/chunks/getAllPropertyDescriptors.js.map +1 -1
  26. package/dist/split/chunks/lifecycleHooks.js +1 -1
  27. package/dist/split/chunks/pathDiagnostics.js +1 -1
  28. package/dist/split/chunks/pathDiagnostics.js.map +1 -1
  29. package/dist/split/chunks/registerComponents.js +1 -1
  30. package/dist/split/chunks/registerComponents.js.map +1 -1
  31. package/dist/split/chunks/setAll.js +1 -1
  32. package/dist/split/chunks/setAll.js.map +1 -1
  33. package/dist/split/chunks/version.js +1 -1
  34. package/dist/split/core.d.ts +21 -9
  35. package/dist/split/core.js +1 -1
  36. package/dist/split/core.js.map +1 -1
  37. package/dist/split/features/devtools.js +1 -1
  38. package/dist/split/features/devtools.js.map +1 -1
  39. package/dist/split/features/diagnostics.js +1 -1
  40. package/dist/split/features/diagnostics.js.map +1 -1
  41. package/dist/split/features/formats.js +1 -1
  42. package/dist/split/features/formats.js.map +1 -1
  43. package/dist/split/features/recursion.js +1 -1
  44. package/dist/split/features/recursion.js.map +1 -1
  45. package/dist/split/features/scopes.js +1 -1
  46. package/dist/split/features/scopes.js.map +1 -1
  47. package/dist/split/features/ssr.js +1 -1
  48. package/dist/split/features/ssr.js.map +1 -1
  49. package/dist/split/features/temporal.js +1 -1
  50. package/dist/split/features/temporal.js.map +1 -1
  51. package/dist/wcs-manifest.json +98 -44
  52. package/package.json +1 -1
  53. package/dist/split/chunks/mount.js +0 -2
  54. package/dist/split/chunks/mount.js.map +0 -1
  55. package/dist/split/chunks/watchRuntime.js +0 -2
  56. package/dist/split/chunks/watchRuntime.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{g as t,w as e,E as n,W as s,F as a,m as o,D as l,p as r,G as i,H as d,t as c,J as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aA as h,I as p,l as g,aB as y,O as I,L as w,k as m,N as x,M as P,aC as v,G as A,aD as b,H as $,af as k,aE as R,aF as E,aG as S,aH as M,aI as j,aJ as O,aK as L,a6 as C,c as D,aL as T,ab as V,Y as B,aM as N,K as H,x as G}from"./binder.js";import{N as q}from"./getAllPropertyDescriptors.js";import{c as z}from"./checkDependency.js";import{c as W}from"./filterRegistry.js";const K=new WeakMap;function F(t,e){let n=K.get(t);void 0===n&&(n=new Map,K.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const J=new WeakMap;function U(t){const e=J.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return F(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:F(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return J.set(t,n),n}function Y(t){J.delete(t)}function Q(t){"readonly"===t.mutability&&u("This state is readonly.")}const X=new Map;class Z{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const n=e.split("."),s=n.slice();let a=0,o=0,l=0,r="none";const i=[];for(let t=0;t<n.length;t++){const e=n[t];if("*"===e)s[t]="*",i.push(null),a++,l++;else{const n=Number(e);Number.isNaN(n)||(s[t]="*",i.push(n),o++,l++)}}const d=s.join("."),c=t(d);(a>0||o>0)&&(r=a===l?"context":o===l?"all":"partial"),this.path=e,this.segments=n,this.wildcardCount=l,this.wildcardType=r,this.wildcardIndexes=i,this.pathInfo=c}}function _(t){let e;return X.get(t)??(X.set(t,e=new Z(t)),e)}function tt(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const s=n.pathInfo.indexByWildcardPath[e];return void 0===s||null===n.listIndex?null:p(n.listIndex,s,n.pathInfo.wildcardCount)}function et(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function nt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==q)return r}}return q}function st(t,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(U(i),o.pathInfo.segments);if(!(o.pathInfo.path in t)){if(null===o.parentAddress){const e=nt(i,o,null,l,r);if(e!==q)return e;u(n(o.pathInfo.path,t,i.getterPaths))}const e=at(t,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==s&&!(d in Object(e))){const t=nt(i,o,Object(e),l,r);if(t!==q)return t}if(d===s){const t=o.listIndex?.index??u(a(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(t,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(t,o.pathInfo.path,l)}finally{r.popAddress()}}function at(t,e,n,s){z(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==q)return l}}return et(a,e)?function(t,e,n,s,a){const o=g(a,e),l=y(o),r=a.stateGeneration;if(null!==l&&!1===l.dirty&&l.generation===r)return l.value;const i=st(t,e,n,s,a);return I(o,{value:i,dirty:!1,generation:r}),i}(t,e,n,s,a):st(t,e,n,s,a)}function ot(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const p=m(h,o),y=g(n.stateElement,p),I=x(y),w=at(t,p,e,n),v=P(o,I,w).newIndexes,A=i[d]??null;if(l.set(y,w),null===A)for(let t=0;t<v.length;t++){const e=v[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=v[A]??u(`ListIndex not found at index ${A} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())w(t,Array.isArray(e)?e:[]);return i}function lt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=at(t,m(r,o),e,n),d=v(i,o);null==d&&u(`ListIndexes not found: ${r.path}`);const c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function rt(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function it(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function dt(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];rt(i,n,s,r);const d=it(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function ct(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function ft(t,e,n,a){if(e.pathInfo.path in t)return!0;const o=e.parentAddress;if(null===o)return!1;const l=at(t,o,n,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=e.pathInfo.lastSegment;if(r===s){const t=e.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const ut=new WeakMap;function ht(t,e){null===e?ut.delete(t):ut.set(t,e)}function pt(e,n,s){const a=e.wildcardParentPaths[n],o=t(a),l=m(o,s),r=g(e.stateElement,l),i=x(r),d=e.stateProxy[A](l),c=P(l.listIndex,i,d);e.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return W.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,e.searchType);if(n===e.wildcardPaths.length-1)e.targetListIndexes.push(...f);else for(const t of f)pt(e,n+1,t)}const gt=[];function yt(t,e,n,s,a){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:a.newIndexes,movedRows:null}:0===a.addIndexSet.size&&0===a.changeIndexSet.size?0===a.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:gt,movedRows:null}:{fullRows:a.newIndexes,movedRows:null}:{fullRows:gt,movedRows:null}:{fullRows:a.addIndexSet,movedRows:a.changeIndexSet}}const It=[];function wt(e,n,s){const a=e.stateElement.indexDependentGetterPaths;if(!a||0===a.size)return It;let o=null;const r=n+l;for(const e of a){if(e!==n&&!e.startsWith(r))continue;const a=t(e);if(a.wildcardCount!==s.wildcardCount)return null;(o??=[]).push(a)}return o??It}function mt(e,n,a){const o=n.pathInfo.path,l=e.staticMap.get(o);if(l)for(const r of l){const l=t(r);if(e.listPathSet.has(o)&&l.lastSegment===s){const t=e.stateProxy[A](n),s=g(e.stateElement,n),i=x(s),d=P(n.listIndex,i,t);e.observedListValueByAbsAddress.set(s,Array.isArray(t)?t:[]);const c=yt(e,o,0,0,d);for(const t of c.fullRows){const n=m(l,t);e.result.add(n),a.push(n)}if(null!==c.movedRows){const t=wt(e,r,l);if(null===t)for(const t of c.movedRows){const n=m(l,t);e.result.add(n),a.push(n)}else if(t.length>0)for(const n of c.movedRows)for(const s of t){const t=m(s,n);e.result.add(t),a.push(t)}}}else{const t=m(l,n.listIndex);e.result.add(t),a.push(t)}}const r=e.dynamicMap.get(o);if(r)for(const s of r){const o=t(s),l=[];if(o.wildcardCount>0){const t=b(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=p(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};pt(a,t,s),l.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=p(n.listIndex,t-1,n.pathInfo.wildcardCount);l.push(e)}}else l.push(null);for(const t of l){const n=m(o,t);e.result.add(n),a.push(n)}}}function xt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null};!function(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),n(r),l.length=0,mt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}(f,e,r);for(const[t,e]of f.observedListValueByAbsAddress)w(t,e);return Array.from(f.result)}function Pt(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function vt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function At(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function bt(t,e,n,s,a,o){const l=E(t,e),r=S(t,e);if(!l&&!r)return;const i=D(),d=W.enablePropagationContext?M()??null:null,c=t=>{k(t),i.enqueueAbsoluteAddress(t,d)};l&&j(t,e,n,s,a).forEach(c),r&&O(t,e,n?s:o(),a).forEach(c)}function $t(t,e,n,s,a,o,l="diff"){const r=W.enablePropagationContext?M()??L(-1):null,i=D();i.enqueueAbsoluteAddress(e,r),o&&k(e),xt(s.stateElement,t,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=g(s.stateElement,e);k(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:l,keyedMergePath:a})}function kt(t,e,n,s,a){a&&(t.getterPaths.has(e)?k(n):I(n,{value:s,dirty:!1,generation:t.stateGeneration}))}function Rt(t,e,n,o,l,r,i,d){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,o);const i=at(t,n,l,r),d=e.pathInfo.segments[e.pathInfo.segments.length-1];if(d===s){const t=e.listIndex?.index??u(a(`path "${e.pathInfo.path}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,o);r.pushAddress(e),r.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{$t(e,n,l,r,i,d)}}function Et(e,n,a,o,r,i,d,c){const f=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),h=at(e,f,r,i)??[];let p=(y=h,ut.get(y)??null);var y;if(null===p){const t=$(h)??[];p={value:[...h],listIndexes:[...t]},ht(h,p)}try{return Rt(e,n,a,o,r,i,d,c)}finally{const a=p.value.indexOf(o),d=at(e,f,r,i)??[],c=Array.isArray(d)?$(d)??[]:[],u=n.listIndex.index,y=-1!==a?p.listIndexes[a]:C(f.listIndex,-1);c[u]=y;if(new Set(d).size===p.value.length){for(let t=0;t<c.length;t++)c[t].index=t;ht(h,null),function(e,n,a,o,r,i){const d=i.stateElement,c=D(),f=g(d,e);T(f)===a&&(V(n.value,n.listIndexes),B(f,n.value),N(n.value));c.enqueueRenderOnlyAddress(f);const u=new Map;n.listIndexes.forEach((t,e)=>u.set(t,e));const h=t(e.pathInfo.path+l+s);for(let t=0;t<o.length;t++){const e=o[t],s=u.get(e);if(s===t)continue;const a=m(h,e),l=g(d,a);if(void 0===s){const e=H(d,h,n.listIndexes[t]??null);At(d,l,e),$t(a,l,r,i,null,et(d,a),"full");continue}xt(d,a,d.staticDependency,d.dynamicDependency,d.listPaths,r,"new",t=>{const e=g(d,t);k(e),c.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}}(f,p,d,c,r,i)}}}function St(e,n,a,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(a)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=at(e,n,o,r),c=function(t,e,n,s){const a=dt(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=dt(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,a);if(null!==c)return function(e,n,a,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===$(o)&&P(c,null,o);const f=P(c,o,a.list),u=Mt(e,n,a.list,r,i,d),h=t(d+l+s);for(const n of a.matched){const s=ct(n.oldRow,n.newRow);if(0===s.length)continue;const a=f.newIndexes[n.position];for(const o of s){if(void 0===a){n.oldRow[o.field]=o.value;continue}const s=t(h.path+l+o.field);St(e,m(s,a),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return Mt(e,n,a,o,r,null)}function Mt(t,e,n,o,l,i){const d=l.stateElement,c=e.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let s=0;s<t.length;s++){const a=t[s](d,e,n,o,l);if(a!==q)return a}}const h=R();if(!(c in t)&&null!==e.parentAddress&&!d.elementPaths.has(c)){const p=at(t,e.parentAddress,o,l);if("object"==typeof p&&null!==p){const t=e.pathInfo.lastSegment,y=t===s?e.listIndex?.index:t;let I,w=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const t=void 0!==y&&y in p,e=void 0!==y?p[y]:void 0;if(t&&Object.is(e,n))return!0;I=e,w=!0}bt(d,c,w,I,n,()=>p[y]);const m=et(d,e),x=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:x,value:n,oldValue:I,hasOldValue:w}),Pt(d,c,x,I,w);let P=!1;try{if(void 0===y&&u(a(`path "${c}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0)),f&&0!==f.writeMissing.length&&t!==s&&!(y in p)){const t=f.writeMissing;for(let s=0;s<t.length;s++){P=!0;const a=t[s](d,e,p,y,n,o,l);if(a!==q)return a;P=!1}}return Reflect.set(p,y,n)}finally{$t(e,x,o,l,i,m),P?k(x):kt(d,c,x,n,m),vt(d,e.pathInfo,{value:n})}}}let p,y=!1;if(!h&&W.sameValueGuard&&(null===n||"object"!=typeof n)){const s=at(t,e,o,l);if(ft(t,e,o,l)&&Object.is(s,n))return!0;p=s,y=!0}bt(d,c,y,p,n,()=>at(t,e,o,l));const I=d.elementPaths.has(e.pathInfo.path),w=et(d,e),m=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:m,value:n,oldValue:p,hasOldValue:y}),Pt(d,c,m,p,y);try{return I?Et(t,e,m,n,o,l,i,w):Rt(t,e,m,n,o,l,i,w)}finally{I||kt(d,c,m,n,w),vt(d,e.pathInfo,{value:n})}}function jt(e,n,s,a){return(n,o,...l)=>{const r=t(n);if(a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",n,r.wildcardParentPathInfos.length,o.length));const d=lt(e,s,a,r,o),c=m(r,d);if(0===l.length)return at(e,c,s,a);Q(a),St(e,c,l[0],s,a)}}function Ot(e,n,s,a){const o=jt(e,0,s,a);return(n,l)=>{const r=t(n);if(void 0===l||Array.isArray(l)||u(`$getAll("${n}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",n,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=tt(a,r.wildcardPaths[t]);if(e){l=G(e,e.length);break}}if(void 0===l){const t=a.addressStackLength>0?a.lastAddressStack:null,e=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==e&&e.length>0&&u(d(n,t.pathInfo.path)),l=[]}}const c=ot(e,s,a,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function Lt(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return tt(s,a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`))??u(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=at(t,m(l,a),n,s),i=v(r,a)??u(`ListIndex not found: ${l.path}`),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function Ct(e,n,s,a){return(n,o,l,r)=>{Q(a);const d=t(n);Array.isArray(o)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),o.length>d.wildcardParentPathInfos.length&&u(i("$setAll",n,d.wildcardParentPathInfos.length,o.length));const h=!0===r?.spread,p="function"==typeof l;h&&p&&u(c(n,"cannot combine { spread: true } with a mapper function.")),h&&!Array.isArray(l)&&u(c(n,"requires an array as the value when { spread: true } is set."));const g=ot(e,s,a,d,o,{commitDiffBaseline:!1});h&&l.length!==g.length&&u(f(n,g.length,l.length));const y=[];for(let t=0;t<g.length;t++){const n=lt(e,s,a,d,g[t]);y.push(m(d,n))}let I=0;for(let t=0;t<y.length;t++){const n=y[t];let o;if(p){o=l(at(e,n,s,a),...g[t])}else o=h?l[t]:l;void 0!==o&&(St(e,n,o,s,a),I++)}return I}}export{Q as a,Ot as b,Ct as c,_ as d,Lt as e,U as f,at as g,ft as h,Y as i,jt as r,St as s,xt as w};
1
+ import{g as t,w as e,E as n,W as s,F as a,q as o,D as l,d as r,G as i,H as d,t as c,J as f}from"./pathDiagnostics.js";import{r as u}from"./errorGuidance.js";import{aC as h,m as p,l as g,aD as y,aE as I,M as w,j as m,O as x,N as P,aF as v,aG as A,h as b,aH as $,k,ai as E,aI as R,aJ as S,aK as j,aL as M,aM as O,aN as C,aO as L,a9 as D,c as N,aP as T,ae as V,$ as q,aQ as B,p as H,o as z}from"./binder.js";import{N as G}from"./getAllPropertyDescriptors.js";import{c as W}from"./checkDependency.js";import{c as F}from"./filterRegistry.js";const J=new WeakMap;function K(t,e){let n=J.get(t);void 0===n&&(n=new Map,J.set(t,n));let s=n.get(e);return void 0===s&&(s=new h(e,t),n.set(e,s)),s}const U=new WeakMap;function Q(t){const e=U.get(t);if(void 0!==e)return e;const n=new Proxy(Object.create(null),{get(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return K(t,n)},has:(e,n)=>"string"==typeof n&&t.commandTokenNames.has(n),ownKeys:()=>Array.from(t.commandTokenNames),getOwnPropertyDescriptor(e,n){if("string"==typeof n&&t.commandTokenNames.has(n))return{configurable:!0,enumerable:!0,value:K(t,n)}},set(){u("$command namespace is read-only; assigning to it is not allowed.")},deleteProperty(){u("$command namespace is read-only; deleting from it is not allowed.")}});return U.set(t,n),n}function X(t){U.delete(t)}function Y(t){"readonly"===t.mutability&&u("This state is readonly.")}const Z=new Map;class _{path;segments;wildcardCount;wildcardType;wildcardIndexes;pathInfo;constructor(e){const n=e.split("."),s=n.slice();let a=0,o=0,l=0,r="none";const i=[];for(let t=0;t<n.length;t++){const e=n[t];if("*"===e)s[t]="*",i.push(null),a++,l++;else{const n=Number(e);Number.isNaN(n)||(s[t]="*",i.push(n),o++,l++)}}const d=s.join("."),c=t(d);(a>0||o>0)&&(r=a===l?"context":o===l?"all":"partial"),this.path=e,this.segments=n,this.wildcardCount=l,this.wildcardType=r,this.wildcardIndexes=i,this.pathInfo=c}}function tt(t){let e;return Z.get(t)??(Z.set(t,e=new _(t)),e)}function et(t,e){if(0===t.addressStackLength)return null;const n=t.lastAddressStack;if(null===n)return null;const s=n.pathInfo.indexByWildcardPath[e];return void 0===s||null===n.listIndex?null:p(n.listIndex,s,n.pathInfo.wildcardCount)}function nt(t,e){return(!0!==t.hasMounts||35!==e.pathInfo.lastSegment.charCodeAt(0))&&(e.pathInfo.wildcardCount>0||t.getterPaths.has(e.pathInfo.path))}function st(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.readMissing;for(let o=0;o<l.length;o++){const r=l[o](t,e,n,s,a);if(r!==G)return r}}return G}function at(t,o,l,r,i){if(o.pathInfo.segments[0]===e)return function(t,e){let n=t;for(let t=1;t<e.length;t++){if(Object(n)!==n)return;n=Reflect.get(n,e[t])}return n}(Q(i),o.pathInfo.segments);if(!(o.pathInfo.path in t)){if(null===o.parentAddress){const e=st(i,o,null,l,r);if(e!==G)return e;u(n(o.pathInfo.path,t,i.getterPaths))}const e=ot(t,o.parentAddress,l,r);if(null==e)return;const d=o.pathInfo.segments[o.pathInfo.segments.length-1],c=i.addressHooks;if(c&&0!==c.readMissing.length&&d!==s&&!(d in Object(e))){const t=st(i,o,Object(e),l,r);if(t!==G)return t}if(d===s){const t=o.listIndex?.index??u(a(`path "${o.pathInfo.path}"`,o.pathInfo.wildcardCount,o.listIndex?.length??0));return Reflect.get(e,t)}return Reflect.get(e,d)}if(!i.getterPaths.has(o.pathInfo.path))return Reflect.get(t,o.pathInfo.path);r.pushAddress(o);try{return Reflect.get(t,o.pathInfo.path,l)}finally{r.popAddress()}}function ot(t,e,n,s){W(s,e),!0===s.stateElement.hasRecursion&&s.stateElement.recursionRegistry.materializeForPathInfo(s.stateElement,e.pathInfo);const a=s.stateElement,o=a.addressHooks;if(o){const t=o.read;for(let o=0;o<t.length;o++){const l=t[o](a,e,n,s);if(l!==G)return l}}return nt(a,e)?function(t,e,n,s,a){const o=g(a,e),l=y(o),r=a.stateGeneration;if(null!==l&&!1===l.dirty&&l.generation===r)return l.value;const i=at(t,e,n,s,a);return I(o,{value:i,dirty:!1,generation:r}),i}(t,e,n,s,a):at(t,e,n,s,a)}function lt(t,e,n,s,a,o){const l=new Map,r=(s,a,o,i,d,c,f)=>{const h=s[a]??null;if(null===h)return void f.push(c);const p=m(h,o),y=g(n.stateElement,p),I=x(y),w=ot(t,p,e,n),v=P(o,I,w).newIndexes,A=i[d]??null;if(l.set(y,w),null===A)for(let t=0;t<v.length;t++){const e=v[t];r(s,a+1,e,i,d+1,c.concat(e.index),f)}else{const t=v[A]??u(`ListIndex not found at index ${A} of ${h.path}`);a+1<s.length?r(s,a+1,t,i,d+1,c.concat(t.index),f):f.push(c.concat(t.index))}},i=[];if(r(s.wildcardParentPathInfos,0,null,a,0,[],i),o.commitDiffBaseline)for(const[t,e]of l.entries())w(t,Array.isArray(e)?e:[]);return i}function rt(t,e,n,s,a){let o=null;for(let l=0;l<s.wildcardParentPathInfos.length;l++){const r=s.wildcardParentPathInfos[l],i=ot(t,m(r,o),e,n),d=v(i,o);null==d&&u(`ListIndexes not found: ${r.path}`);const c=a[l];o=d[c]??u(`ListIndex not found at index ${c} of ${r.path}`)}return o}function it(t,e,n,s){"object"==typeof t&&null!==t||u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (got ${null===t?"null":typeof t}).`);const a=Object.getPrototypeOf(t);a!==Object.prototype&&null!==a&&u(`${o} list "${e}": ${n} row at index ${s} must be a plain object (class instances and exotic objects cannot be value-expanded).`)}function dt(t,e,n,s,a){const l="function"==typeof e?e(t):t[e];return null==l&&u(`${o} list "${n}": ${s} row at index ${a} has no key (${"function"==typeof e?"key function":`field "${e}"`} returned ${String(l)}).`),l}function ct(t,e,n,s){const a=new Array(t.length),l=new Set;for(let r=0;r<t.length;r++){const i=t[r];it(i,n,s,r);const d=dt(i,e,n,s,r);l.has(d)&&u(`${o} list "${n}": duplicate key ${JSON.stringify(d)} in ${s} list.`),l.add(d),a[r]=d}return a}function ft(t,e){const n=[];for(const s of Object.keys(e))Object.is(t[s],e[s])||n.push({field:s,value:e[s]});for(const s of Object.keys(t))Object.hasOwn(e,s)||null==t[s]||n.push({field:s,value:null});return n}function ut(t,e,n,a){if(e.pathInfo.path in t)return!0;const o=e.parentAddress;if(null===o)return!1;const l=ot(t,o,n,a);if(null===l||"object"!=typeof l&&"function"!=typeof l)return!1;const r=e.pathInfo.lastSegment;if(r===s){const t=e.listIndex?.index;return"number"==typeof t&&t in l}return r in l}const ht=new WeakMap;function pt(t,e){null===e?ht.delete(t):ht.set(t,e)}function gt(e,n,s){const a=e.wildcardParentPaths[n],o=t(a),l=m(o,s),r=g(e.stateElement,l),i=x(r),d=e.stateProxy[b](l),c=P(l.listIndex,i,d);e.observedListValueByAbsAddress.set(r,Array.isArray(d)?d:[]);const f=function(t,e){switch(e){case"old":return t.oldIndexes;case"new":return t.newIndexes;case"add":return t.addIndexSet;case"change":return t.changeIndexSet;case"delete":return t.deleteIndexSet;default:return F.debug&&console.log(`Invalid search type: ${e}`),[]}}(c,e.searchType);if(n===e.wildcardPaths.length-1)e.targetListIndexes.push(...f);else for(const t of f)gt(e,n+1,t)}const yt=[];function It(t,e,n,s,a){return"full"===t.listExpansion||t.stateElement.crossRowListPaths?.has(e)?{fullRows:a.newIndexes,movedRows:null}:0===a.addIndexSet.size&&0===a.changeIndexSet.size?0===a.deleteIndexSet.size?t.keyedMergePath===e?{fullRows:yt,movedRows:null}:{fullRows:a.newIndexes,movedRows:null}:{fullRows:yt,movedRows:null}:{fullRows:a.addIndexSet,movedRows:a.changeIndexSet}}const wt=[];function mt(e,n,s){const a=e.stateElement.indexDependentGetterPaths;if(!a||0===a.size)return wt;let o=null;const r=n+l;for(const e of a){if(e!==n&&!e.startsWith(r))continue;const a=t(e);if(a.wildcardCount!==s.wildcardCount)return null;(o??=[]).push(a)}return o??wt}function xt(t,e,n){const s=[],a=t.ranks,o=(t,e)=>{let n=a.get(t.pathInfo.path)??e;n<e&&(n=e),(s[n]??=[]).push(t)};o(e,0);const l=[];for(let e=0;e<s.length;e++){const a=s[e];if(void 0!==a)for(let s=0;s<a.length;s++){const r=a[s];if(!t.visited.has(r)){t.visited.add(r),n(r),l.length=0,Pt(t,r,l);for(let t=0;t<l.length;t++)o(l[t],e+1)}}}}function Pt(e,n,a){const o=n.pathInfo.path,l=e.staticMap.get(o);if(l)for(const r of l){const l=t(r);if(e.listPathSet.has(o)&&l.lastSegment===s){const t=e.stateProxy[b](n),s=g(e.stateElement,n),i=x(s),d=P(n.listIndex,i,t);e.observedListValueByAbsAddress.set(s,Array.isArray(t)?t:[]);const c=It(e,o,0,0,d);for(const t of c.fullRows){const n=m(l,t);e.result.add(n),a.push(n)}if(null!==c.movedRows){const t=mt(e,r,l);if(null===t)for(const t of c.movedRows){const n=m(l,t);e.result.add(n),a.push(n)}else if(t.length>0)for(const n of c.movedRows)for(const s of t){const t=m(s,n);e.result.add(t),a.push(t)}}}else{const t=m(l,n.listIndex);e.result.add(t),a.push(t)}}const r=e.dynamicMap.get(o);if(r)for(const s of r){const o=t(s),l=[];if(o.wildcardCount>0){const t=$(n.pathInfo,o);if(o.wildcardCount-t>=1){let s;t>0?(null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`),s=p(n.listIndex,t-1,n.pathInfo.wildcardCount)):s=null;const a={stateElement:e.stateElement,observedListValueByAbsAddress:e.observedListValueByAbsAddress,targetListIndexes:[],wildcardPaths:o.wildcardPaths,wildcardParentPaths:o.wildcardParentPaths,stateProxy:e.stateProxy,searchType:e.searchType};gt(a,t,s),l.push(...a.targetListIndexes)}else{null===n.listIndex&&u(`Cannot expand dynamic dependency with wildcard for non-list address: ${n.pathInfo.path}`);const e=p(n.listIndex,t-1,n.pathInfo.wildcardCount);l.push(e)}}else l.push(null);for(const t of l){const n=m(o,t);e.result.add(n),a.push(n)}}}function vt(t,e,n,s,a,o,l,r,i){const d=e.pathInfo.path;if(!n.has(d)&&!s.has(d))return r(e),[];const c=function(t,e,n,s){const a=new Map,o=new Map,l=[t];for(o.set(t,0);l.length>0;){const t=l.pop();if(a.has(t))continue;const s=e.get(t),r=n.get(t);let i;i=void 0===s?r??[]:void 0===r?s:s.concat(r),a.set(t,i);for(let t=0;t<i.length;t++){const e=i[t];o.set(e,(o.get(e)??0)+1),a.has(e)||l.push(e)}}const r=new Map,i=new Set,d=[];for(const[t,e]of o)0===e&&(r.set(t,0),i.add(t),d.push(t));for(let t=0;t<d.length;t++){const e=d[t],n=r.get(e)+1;n>s&&u(`Maximum dependency depth of ${s} exceeded. Possible circular dependency detected at path: ${e}`);const l=a.get(e);for(let t=0;t<l.length;t++){const e=l[t];n>(r.get(e)??-1)&&r.set(e,n);const s=o.get(e)-1;o.set(e,s),0===s&&(i.add(e),d.push(e))}}if(i.size!==a.size){let t=-1;for(const e of i){const n=r.get(e);n>t&&(t=n)}const e=t+1;for(const t of a.keys())i.has(t)||r.set(t,e)}return r}(d,n,s,1e3),f={ranks:c,stateElement:t,observedListValueByAbsAddress:new Map,staticMap:n,dynamicMap:s,result:new Set,listPathSet:a,visited:new Set,stateProxy:o,searchType:l,listExpansion:i?.listExpansion??"full",keyedMergePath:i?.keyedMergePath??null};xt(f,e,r),function(t,e){for(let n=0;n<1e3;n++){const n=A(t.stateElement);if(null===n)return;n.forEach(n=>{xt(t,m(n.absolutePathInfo.pathInfo,n.listIndex),e)})}}(f,r);for(const[t,e]of f.observedListValueByAbsAddress)w(t,e);return Array.from(f.result)}function At(t,e,n,s,a){const o=t.addressHooks;if(o){const l=o.writeObserve;for(let o=0;o<l.length;o++)l[o](t,e,n,s,a)}}function bt(t,e,n){const s=t.addressHooks;if(s){const a=s.written;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function $t(t,e,n){const s=t.addressHooks;if(s){const a=s.swapped;for(let s=0;s<a.length;s++)a[s](t,e,n)}}function kt(t,e,n,s,a,o){const l=R(t,e),r=S(t,e);if(!l&&!r)return null;const i=[],d=Rt(i);return l&&j(t,e,n,s,a).forEach(d),r&&M(t,e,n?s:o(),a).forEach(d),i}function Et(){return F.enablePropagationContext?C()??null:null}function Rt(t){const e=N(),n=Et();return s=>{E(s),e.enqueueAbsoluteAddress(s,n),t.push(s)}}function St(t,e,n){if(null===t||0===t.length)return;const s=n.stateElement,a=s.staticDependency,o=s.dynamicDependency,l=N(),r=Et();for(let n=0;n<t.length;n++){const i=t[n].absolutePathInfo,d=i.pathInfo.path;if(!a.has(d)&&!o.has(d))continue;const c=m(i.pathInfo,t[n].listIndex);vt(s,c,a,o,s.listPaths,e,"new",t=>{if(t===c)return;const e=g(s,t);E(e),l.enqueueAbsoluteAddress(e,r)},{listExpansion:"diff"})}}function jt(t,e,n,s,a){const o=R(t,e),l=S(t,e);if(!o&&!l)return;const r=n(),i=[],d=Rt(i);o&&j(t,e,!1,void 0,r).forEach(d),l&&M(t,e,void 0,r,!1).forEach(d),St(i,s,a)}function Mt(t,e,n,s,a,o,l="diff"){const r=F.enablePropagationContext?C()??L(-1):null,i=N();i.enqueueAbsoluteAddress(e,r),o&&E(e),vt(s.stateElement,t,s.stateElement.staticDependency,s.stateElement.dynamicDependency,s.stateElement.listPaths,n,"new",e=>{if(e===t)return;const n=g(s.stateElement,e);E(n),i.enqueueAbsoluteAddress(n,r)},{listExpansion:l,keyedMergePath:a})}function Ot(t,e,n,s,a){a&&(t.getterPaths.has(e)?E(n):I(n,{value:s,dirty:!1,generation:t.stateGeneration}))}function Ct(t,e,n,o,l,r,i,d){try{if(!(e.pathInfo.path in t)){const n=e.parentAddress;if(null===n)return Reflect.set(t,e.pathInfo.path,o);const i=ot(t,n,l,r),d=e.pathInfo.segments[e.pathInfo.segments.length-1];if(d===s){const t=e.listIndex?.index??u(a(`path "${e.pathInfo.path}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0));return Reflect.set(i,t,o)}return Reflect.set(i,d,o)}if(!r.stateElement.setterPaths.has(e.pathInfo.path))return Reflect.set(t,e.pathInfo.path,o);r.pushAddress(e),r.beginUntrack();try{return Reflect.set(t,e.pathInfo.path,o,l)}finally{r.endUntrack(),r.popAddress()}}finally{Mt(e,n,l,r,i,d)}}function Lt(e,n,a,o,r,i,d,c){const f=n.parentAddress??u(`address.parentAddress is undefined path: ${n.pathInfo.path}`),h=ot(e,f,r,i)??[];let p=(y=h,ht.get(y)??null);var y;if(null===p){const t=k(h)??[];p={value:[...h],listIndexes:[...t]},pt(h,p)}try{return Ct(e,n,a,o,r,i,d,c)}finally{const a=p.value.indexOf(o),d=ot(e,f,r,i)??[],c=Array.isArray(d)?k(d)??[]:[],u=n.listIndex.index,y=-1!==a?p.listIndexes[a]:D(f.listIndex,-1);c[u]=y;if(new Set(d).size===p.value.length){for(let t=0;t<c.length;t++)c[t].index=t;pt(h,null),function(e,n,a,o,r,i){const d=i.stateElement,c=N(),f=g(d,e);T(f)===a&&(V(n.value,n.listIndexes),q(f,n.value),B(n.value));c.enqueueRenderOnlyAddress(f);const u=new Map;n.listIndexes.forEach((t,e)=>u.set(t,e));const h=t(e.pathInfo.path+l+s);for(let t=0;t<o.length;t++){const e=o[t],s=u.get(e);if(s===t)continue;const a=m(h,e),l=g(d,a);if(void 0===s){const e=H(d,h,n.listIndexes[t]??null);$t(d,l,e),Mt(a,l,r,i,null,nt(d,a),"full");continue}vt(d,a,d.staticDependency,d.dynamicDependency,d.listPaths,r,"new",t=>{const e=g(d,t);E(e),c.enqueueRenderOnlyAddress(e)},{listExpansion:"diff"})}}(f,p,d,c,r,i)}}}function Dt(e,n,a,o,r){const i=r.stateElement.listKeys;if(null!=i&&Array.isArray(a)){const d=i.get(n.pathInfo.path);if(void 0!==d){const i=ot(e,n,o,r),c=function(t,e,n,s){const a=ct(s,e,t,"new");if(!Array.isArray(n)||0===n.length||0===s.length)return null;const o=n,l=ct(o,e,t,"current"),r=new Map;for(let t=0;t<o.length;t++)r.set(l[t],o[t]);const i=new Array(s.length),d=[];for(let t=0;t<s.length;t++){const e=s[t],n=r.get(a[t]);void 0!==n&&n!==e?(i[t]=n,d.push({position:t,oldRow:n,newRow:e})):i[t]=e}return d.length>0?{list:i,matched:d}:null}(n.pathInfo.path,d,i,a);if(null!==c)return function(e,n,a,o,r,i){const d=n.pathInfo.path,c=n.listIndex;null===k(o)&&P(c,null,o);const f=P(c,o,a.list),u=Nt(e,n,a.list,r,i,d),h=t(d+l+s);for(const n of a.matched){const s=ft(n.oldRow,n.newRow);if(0===s.length)continue;const a=f.newIndexes[n.position];for(const o of s){if(void 0===a){n.oldRow[o.field]=o.value;continue}const s=t(h.path+l+o.field);Dt(e,m(s,a),o.value,r,i)}}return u}(e,n,c,i,o,r)}}return Nt(e,n,a,o,r,null)}function Nt(t,e,n,o,l,i){const d=l.stateElement,c=e.pathInfo.path,f=d.addressHooks;if(f){const t=f.write;for(let s=0;s<t.length;s++){const a=t[s](d,e,n,o,l);if(a!==G)return a}}const h=O();if(!(c in t)&&null!==e.parentAddress&&!d.elementPaths.has(c)){const p=ot(t,e.parentAddress,o,l);if("object"==typeof p&&null!==p){const t=e.pathInfo.lastSegment,y=t===s?e.listIndex?.index:t;let I,w=!1;if(!h&&F.sameValueGuard&&(null===n||"object"!=typeof n)){const t=void 0!==y&&y in p,e=void 0!==y?p[y]:void 0;if(t&&Object.is(e,n))return!0;I=e,w=!0}const m=kt(d,c,w,I,n,()=>p[y]),x=nt(d,e),P=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:P,value:n,oldValue:I,hasOldValue:w}),At(d,c,P,I,w);let v=!1;try{if(void 0===y&&u(a(`path "${c}"`,e.pathInfo.wildcardCount,e.listIndex?.length??0)),f&&0!==f.writeMissing.length&&t!==s&&!(y in p)){const t=f.writeMissing;for(let s=0;s<t.length;s++){v=!0;const a=t[s](d,e,p,y,n,o,l);if(a!==G)return a;v=!1}}return Reflect.set(p,y,n)}finally{Mt(e,P,o,l,i,x),St(m,o,l),v?E(P):Ot(d,c,P,n,x),bt(d,e.pathInfo,{value:n})}}}let p,y=!1;if(!h&&F.sameValueGuard&&(null===n||"object"!=typeof n)){const s=ot(t,e,o,l);if(ut(t,e,o,l)&&Object.is(s,n))return!0;p=s,y=!0}const I=kt(d,c,y,p,n,()=>ot(t,e,o,l)),w=d.elementPaths.has(e.pathInfo.path),m=nt(d,e),x=g(d,e);null!==r&&r({type:"state:write",absoluteAddress:x,value:n,oldValue:p,hasOldValue:y}),At(d,c,x,p,y);try{return w?Lt(t,e,x,n,o,l,i,m):Ct(t,e,x,n,o,l,i,m)}finally{St(I,o,l),w||Ot(d,c,x,n,m),bt(d,e.pathInfo,{value:n})}}function Tt(e,n,s,a){return(n,o,...l)=>{Array.isArray(o)||u(`$resolve("${n}") requires an explicit indexes array (pass [] when the path has no wildcards) — got `+(null===o?"null":typeof o)+"."),l.length>1&&u(`$resolve("${n}") takes 2 arguments to read and 3 to write (path, indexes, value) — got ${2+l.length}.`);const r=t(n);if(a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}o.length!==r.wildcardParentPathInfos.length&&u(i("$resolve",n,r.wildcardParentPathInfos.length,o.length));const d=rt(e,s,a,r,o),c=m(r,d);if(0===l.length)return ot(e,c,s,a);Y(a),Dt(e,c,l[0],s,a)}}function Vt(e,n,s,a){const o=Tt(e,0,s,a);return(n,l)=>{const r=t(n);if(void 0===l||Array.isArray(l)||u(`$getAll("${n}") requires the indexes to be an array when given (omit them for the loop context, or pass [] to expand every level) — got `+(null===l?"null":typeof l)+"."),a.addressStackLength>0){const t=a.lastAddressStack?.pathInfo??null,e=a.stateElement;null!==t&&t.path!==r.path&&e.getterPaths.has(t.path)&&e.addDynamicDependency(r.path,t.path)}if(void 0!==l&&l.length>r.wildcardParentPathInfos.length&&u(i("$getAll",n,r.wildcardParentPathInfos.length,l.length)),void 0===l){for(let t=r.wildcardPaths.length-1;t>=0;t--){const e=et(a,r.wildcardPaths[t]);if(e){l=z(e,e.length);break}}if(void 0===l){const t=a.addressStackLength>0?a.lastAddressStack:null,e=t?.listIndex??null;r.wildcardCount>0&&null!==t&&null!==e&&e.length>0&&u(d(n,t.pathInfo.path)),l=[]}}const c=lt(e,s,a,r,l,{commitDiffBaseline:!0}),f=[];for(let t=0;t<c.length;t++)f.push(o(r.path,c[t]));return f}}function qt(t,e,n,s){const a=e.pathInfo;switch(e.wildcardType){case"none":return null;case"context":return et(s,a.wildcardPaths.at(-1)??u(`lastWildcardPath is null: ${e.pathInfo.path}`))??u(`ListIndex not found: ${e.pathInfo.path}`);case"all":{let a=null;for(let o=0;o<e.pathInfo.wildcardCount;o++){const l=e.pathInfo.wildcardParentPathInfos[o]??u(`wildcardParentPathInfo is null: ${e.pathInfo.path}`),r=ot(t,m(l,a),n,s),i=v(r,a)??u(`ListIndex not found: ${l.path}`),d=e.wildcardIndexes[o]??u(`wildcardIndex is null: ${e.pathInfo.path}`);a=i[d]??u(`ListIndex not found at index ${d} of ${l.path}`)}return a}case"partial":u(`Partial wildcard type is not supported yet: ${e.pathInfo.path}`)}}function Bt(e,n,s,a){return(n,o,l,r)=>{Y(a);const d=t(n);Array.isArray(o)||u(c(n,"requires an explicit indexes array (pass [] to expand every level).")),o.length>d.wildcardParentPathInfos.length&&u(i("$setAll",n,d.wildcardParentPathInfos.length,o.length));const h=!0===r?.spread,p="function"==typeof l;h&&p&&u(c(n,"cannot combine { spread: true } with a mapper function.")),h&&!Array.isArray(l)&&u(c(n,"requires an array as the value when { spread: true } is set."));const g=lt(e,s,a,d,o,{commitDiffBaseline:!1});h&&l.length!==g.length&&u(f(n,g.length,l.length));const y=[];for(let t=0;t<g.length;t++){const n=rt(e,s,a,d,g[t]);y.push(m(d,n))}let I=0;for(let t=0;t<y.length;t++){const n=y[t];let o;if(p){o=l(ot(e,n,s,a),...g[t])}else o=h?l[t]:l;void 0!==o&&(Dt(e,n,o,s,a),I++)}return I}}export{Y as a,Vt as b,Bt as c,tt as d,qt as e,Q as f,ot as g,ut as h,X as i,jt as n,Tt as r,Dt as s,vt as w};
2
2
  //# sourceMappingURL=setAll.js.map