@biglogic/rgs 2.9.3 → 3.0.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/README.md +29 -8
- package/SECURITY.md +10 -0
- package/advanced.js +1 -1
- package/core/types.d.ts +22 -1
- package/core/utils.d.ts +2 -0
- package/examples/README.md +41 -0
- package/examples/async-data-fetch/UserLoader.d.ts +12 -0
- package/examples/async-data-fetch/UserLoader.ts +30 -0
- package/examples/basic-counter/CounterComponent.d.ts +2 -0
- package/examples/basic-counter/CounterComponent.tsx +22 -0
- package/examples/basic-counter/CounterStore.d.ts +7 -0
- package/examples/basic-counter/CounterStore.ts +25 -0
- package/examples/big-data-indexeddb/BigDataStore.d.ts +10 -0
- package/examples/big-data-indexeddb/BigDataStore.ts +60 -0
- package/examples/global-theme/ThemeManager.d.ts +7 -0
- package/examples/global-theme/ThemeManager.ts +32 -0
- package/examples/hybrid-cloud-sync/HybridStore.d.ts +19 -0
- package/examples/hybrid-cloud-sync/HybridStore.ts +78 -0
- package/examples/persistent-cart/CartStore.d.ts +13 -0
- package/examples/persistent-cart/CartStore.ts +41 -0
- package/examples/rbac-dashboard/DashboardStore.d.ts +47 -0
- package/examples/rbac-dashboard/DashboardStore.ts +46 -0
- package/examples/secure-auth/AuthStore.d.ts +14 -0
- package/examples/secure-auth/AuthStore.ts +36 -0
- package/examples/security-best-practices/SecurityStore.d.ts +22 -0
- package/examples/security-best-practices/SecurityStore.ts +75 -0
- package/examples/stress-tests/StressStore.d.ts +41 -0
- package/examples/stress-tests/StressStore.ts +61 -0
- package/examples/super-easy/EasyStore.d.ts +44 -0
- package/examples/super-easy/EasyStore.ts +61 -0
- package/examples/undo-redo-editor/EditorStore.d.ts +9 -0
- package/examples/undo-redo-editor/EditorStore.ts +28 -0
- package/index.d.ts +3 -2
- package/index.js +1 -1
- package/markdown/SUMMARY.md +4 -0
- package/markdown/api.md +40 -1
- package/markdown/chapters/03-the-magnetar-way.md +10 -3
- package/markdown/chapters/04-persistence-and-safety.md +46 -5
- package/markdown/chapters/05-plugins-and-extensibility.md +24 -8
- package/markdown/chapters/06-case-studies.md +69 -69
- package/markdown/chapters/08-migration-guide.md +48 -1
- package/markdown/chapters/09-security-architecture.md +40 -0
- package/package.json +84 -79
- package/plugins/index.d.ts +4 -2
- package/plugins/official/cloud-sync.plugin.d.ts +22 -0
- package/plugins/official/immer.plugin.d.ts +1 -1
- package/plugins/official/indexeddb.plugin.d.ts +7 -0
- package/plugins/official/undo-redo.plugin.d.ts +2 -2
- package/rgs-highlighter-2.9.5.vsix +0 -0
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var yt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Kt=yt((Xn,Ft)=>{"use strict";var ct=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,en=Object.getOwnPropertyNames,tn=Object.prototype.hasOwnProperty,nn=(e,t)=>{for(var n in t)ct(e,n,{get:t[n],enumerable:!0})},rn=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of en(t))!tn.call(e,o)&&o!==n&&ct(e,o,{get:()=>t[o],enumerable:!(r=Yt(t,o))||r.enumerable});return e},on=e=>rn(ct({},"__esModule",{value:!0}),e),Ot={};nn(Ot,{Immer:()=>Vt,applyPatches:()=>An,castDraft:()=>Mn,castImmutable:()=>In,createDraft:()=>Cn,current:()=>Nt,enableArrayMethods:()=>vn,enableMapSet:()=>bn,enablePatches:()=>wn,finishDraft:()=>Rn,freeze:()=>Ge,immerable:()=>ae,isDraft:()=>B,isDraftable:()=>K,nothing:()=>Be,original:()=>an,produce:()=>xn,produceWithPatches:()=>Pn,setAutoFreeze:()=>_n,setUseStrictIteration:()=>En,setUseStrictShallowCopy:()=>kn});Ft.exports=on(Ot);var Be=Symbol.for("immer-nothing"),ae=Symbol.for("immer-draftable"),k=Symbol.for("immer-state");function z(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var F=Object,oe=F.getPrototypeOf,Se="constructor",Pe="prototype",ot="configurable",Ue="enumerable",ze="writable",me="value",B=e=>!!e&&!!e[k];function K(e){return e?Tt(e)||_e(e)||!!e[ae]||!!e[Se]?.[ae]||ke(e)||Ee(e):!1}var sn=F[Pe][Se].toString(),Et=new WeakMap;function Tt(e){if(!e||!le(e))return!1;let t=oe(e);if(t===null||t===F[Pe])return!0;let n=F.hasOwnProperty.call(t,Se)&&t[Se];if(n===Object)return!0;if(!re(n))return!1;let r=Et.get(n);return r===void 0&&(r=Function.toString.call(n),Et.set(n,r)),r===sn}function an(e){return B(e)||z(15,e),e[k].t}function ce(e,t,n=!0){se(e)===0?(n?Reflect.ownKeys(e):F.keys(e)).forEach(r=>{t(r,e[r],e)}):e.forEach((r,o)=>t(o,r,e))}function se(e){let t=e[k];return t?t.r:_e(e)?1:ke(e)?2:Ee(e)?3:0}var he=(e,t,n=se(e))=>n===2?e.has(t):F[Pe].hasOwnProperty.call(e,t),Q=(e,t,n=se(e))=>n===2?e.get(t):e[t],$e=(e,t,n,r=se(e))=>{r===2?e.set(t,n):r===3?e.add(n):e[t]=n};function ln(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}var _e=Array.isArray,ke=e=>e instanceof Map,Ee=e=>e instanceof Set,le=e=>typeof e=="object",re=e=>typeof e=="function",nt=e=>typeof e=="boolean";function cn(e){let t=+e;return Number.isInteger(t)&&String(t)===e}var Dt=e=>le(e)?e?.[k]:null,D=e=>e.e||e.t,un=e=>{let t=Dt(e);return t?t.e??t.t:e},ut=e=>e.s?e.e:e.t;function st(e,t){if(ke(e))return new Map(e);if(Ee(e))return new Set(e);if(_e(e))return Array[Pe].slice.call(e);let n=Tt(e);if(t===!0||t==="class_only"&&!n){let r=F.getOwnPropertyDescriptors(e);delete r[k];let o=Reflect.ownKeys(r);for(let i=0;i<o.length;i++){let p=o[i],h=r[p];h[ze]===!1&&(h[ze]=!0,h[ot]=!0),(h.get||h.set)&&(r[p]={[ot]:!0,[ze]:!0,[Ue]:h[Ue],[me]:e[p]})}return F.create(oe(e),r)}else{let r=oe(e);if(r!==null&&n)return{...e};let o=F.create(r);return F.assign(o,e)}}function Ge(e,t=!1){return Je(e)||B(e)||!K(e)||(se(e)>1&&F.defineProperties(e,{set:je,add:je,clear:je,delete:je}),F.freeze(e),t&&ce(e,(n,r)=>{Ge(r,!0)},!1)),e}function fn(){z(2)}var je={[me]:fn};function Je(e){return e===null||!le(e)?!0:F.isFrozen(e)}var we="MapSet",Ve="Patches",it="ArrayMethods",Ne={};function ie(e){let t=Ne[e];return t||z(0,e),t}var At=e=>!!Ne[e];function ft(e,t){Ne[e]||(Ne[e]=t)}var be,We=()=>be,dn=(e,t)=>({o:[],i:e,l:t,F:!0,m:0,P:new Set,T:new Set,I:At(we)?ie(we):void 0,E:At(it)?ie(it):void 0});function Ct(e,t){t&&(e.x=ie(Ve),e.y=[],e.d=[],e.C=t)}function at(e){lt(e),e.o.forEach(pn),e.o=null}function lt(e){e===be&&(be=e.i)}var Rt=e=>be=dn(be,e);function pn(e){let t=e[k];t.r===0||t.r===1?t.b():t.g=!0}function Mt(e,t){t.m=t.o.length;let n=t.o[0];if(e!==void 0&&e!==n){n[k].s&&(at(t),z(4)),K(e)&&(e=It(t,e));let{x:r}=t;r&&r.M(n[k].t,e,t)}else e=It(t,n);return gn(t,e,!0),at(t),t.y&&t.C(t.y,t.d),e!==Be?e:void 0}function It(e,t){if(Je(t))return t;let n=t[k];if(!n)return Ke(t,e.P,e);if(!qe(n,e))return t;if(!n.s)return n.t;if(!n.u){let{f:r}=n;if(r)for(;r.length>0;)r.pop()(e);Ut(n,e)}return n.e}function gn(e,t,n=!1){!e.i&&e.l.h&&e.F&&Ge(t,n)}function jt(e){e.u=!0,e.a.m--}var qe=(e,t)=>e.a===t,hn=[];function zt(e,t,n,r){let o=D(e),i=e.r;if(r!==void 0&&Q(o,r,i)===t){$e(o,r,n,i);return}if(!e.D){let h=e.D=new Map;ce(o,(y,a)=>{if(B(a)){let u=h.get(a)||[];u.push(y),h.set(a,u)}})}let p=e.D.get(t)??hn;for(let h of p)$e(o,h,n,i)}function yn(e,t,n){e.f.push(function(r){let o=t;if(!o||!qe(o,r))return;r.I?.fixSetContents(o);let i=ut(o);zt(e,o.c??o,i,n),Ut(o,r)})}function Ut(e,t){if(e.s&&!e.u&&(e.r===3||e.r===1&&e.R||(e.n?.size??0)>0)){let{x:n}=t;if(n){let r=n.getPath(e);r&&n.O(e,r,t)}jt(e)}}function Fe(e,t,n){let{a:r}=e;if(B(n)){let o=n[k];qe(o,r)&&o.f.push(function(){ye(e);let i=ut(o);zt(e,n,i,t)})}else K(n)&&e.f.push(function(){let o=D(e);e.r===3?o.has(n)&&Ke(n,r.P,r):Q(o,t,e.r)===n&&r.o.length>1&&(e.n.get(t)??!1)===!0&&e.e&&Ke(Q(e.e,t,e.r),r.P,r)})}function Ke(e,t,n){return!n.l.h&&n.m<1||B(e)||t.has(e)||!K(e)||Je(e)||(t.add(e),ce(e,(r,o)=>{if(B(o)){let i=o[k];if(qe(i,n)){let p=ut(i);$e(e,r,p,e.r),jt(i)}}else K(o)&&Ke(o,t,n)})),e}function Sn(e,t){let n=_e(e),r={r:n?1:0,a:t?t.a:We(),s:!1,u:!1,n:void 0,i:t,t:e,c:null,e:null,b:null,S:!1,f:void 0},o=r,i=Le;n&&(o=[r],i=ve);let{revoke:p,proxy:h}=Proxy.revocable(o,i);return r.c=h,r.b=p,[h,r]}var Le={get(e,t){if(t===k)return e;let n=e.a.E,r=e.r===1&&typeof t=="string";if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);let o=D(e);if(!he(o,t,e.r))return mn(e,o,t);let i=o[t];if(e.u||!K(i)||r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&cn(t))return i;if(i===rt(e.t,t)){ye(e);let p=e.r===1?+t:t,h=xe(e.a,i,e,p);return e.e[p]=h}return i},has(e,t){return t in D(e)},ownKeys(e){return Reflect.ownKeys(D(e))},set(e,t,n){let r=$t(D(e),t);if(r?.set)return r.set.call(e.c,n),!0;if(!e.s){let o=rt(D(e),t),i=o?.[k];if(i&&i.t===n)return e.e[t]=n,e.n.set(t,!1),!0;if(ln(n,o)&&(n!==void 0||he(e.t,t,e.r)))return!0;ye(e),q(e)}return e.e[t]===n&&(n!==void 0||t in e.e)||Number.isNaN(n)&&Number.isNaN(e.e[t])||(e.e[t]=n,e.n.set(t,!0),Fe(e,t,n)),!0},deleteProperty(e,t){return ye(e),rt(e.t,t)!==void 0||t in e.t?(e.n.set(t,!1),q(e)):e.n.delete(t),e.e&&delete e.e[t],!0},getOwnPropertyDescriptor(e,t){let n=D(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{[ze]:!0,[ot]:e.r!==1||t!=="length",[Ue]:r[Ue],[me]:n[t]}},defineProperty(){z(11)},getPrototypeOf(e){return oe(e.t)},setPrototypeOf(){z(12)}},ve={};for(let e in Le){let t=Le[e];ve[e]=function(){let n=arguments;return n[0]=n[0][0],t.apply(this,n)}}ve.deleteProperty=function(e,t){return ve.set.call(this,e,t,void 0)};ve.set=function(e,t,n){return Le.set.call(this,e[0],t,n,e[0])};function rt(e,t){let n=e[k];return(n?D(n):e)[t]}function mn(e,t,n){let r=$t(t,n);return r?me in r?r[me]:r.get?.call(e.c):void 0}function $t(e,t){if(!(t in e))return;let n=oe(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=oe(n)}}function q(e){e.s||(e.s=!0,e.i&&q(e.i))}function ye(e){e.e||(e.n=new Map,e.e=st(e.t,e.a.l.A))}var Vt=class{constructor(e){this.h=!0,this.A=!1,this._=!1,this.produce=(t,n,r)=>{if(re(t)&&!re(n)){let i=n;n=t;let p=this;return function(h=i,...y){return p.produce(h,a=>n.call(this,a,...y))}}re(n)||z(6),r!==void 0&&!re(r)&&z(7);let o;if(K(t)){let i=Rt(this),p=xe(i,t,void 0),h=!0;try{o=n(p),h=!1}finally{h?at(i):lt(i)}return Ct(i,r),Mt(o,i)}else if(!t||!le(t)){if(o=n(t),o===void 0&&(o=t),o===Be&&(o=void 0),this.h&&Ge(o,!0),r){let i=[],p=[];ie(Ve).M(t,o,{y:i,d:p}),r(i,p)}return o}else z(1,t)},this.produceWithPatches=(t,n)=>{if(re(t))return(i,...p)=>this.produceWithPatches(i,h=>t(h,...p));let r,o;return[this.produce(t,n,(i,p)=>{r=i,o=p}),r,o]},nt(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),nt(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),nt(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){K(e)||z(8),B(e)&&(e=Nt(e));let t=Rt(this),n=xe(t,e,void 0);return n[k].S=!0,lt(t),n}finishDraft(e,t){let n=e&&e[k];(!n||!n.S)&&z(9);let{a:r}=n;return Ct(r,t),Mt(void 0,r)}setAutoFreeze(e){this.h=e}setUseStrictShallowCopy(e){this.A=e}setUseStrictIteration(e){this._=e}shouldUseStrictIteration(){return this._}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let o=t[n];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}n>-1&&(t=t.slice(n+1));let r=ie(Ve).N;return B(e)?r(e,t):this.produce(e,o=>r(o,t))}};function xe(e,t,n,r){let[o,i]=ke(t)?ie(we).w(t,n):Ee(t)?ie(we).V(t,n):Sn(t,n);return(n?.a??We()).o.push(o),i.f=n?.f??[],i.p=r,n&&r!==void 0?yn(n,i,r):i.f.push(function(p){p.I?.fixSetContents(i);let{x:h}=p;i.s&&h&&h.O(i,[],p)}),o}function Nt(e){return B(e)||z(10,e),Wt(e)}function Wt(e){if(!K(e)||Je(e))return e;let t=e[k],n,r=!0;if(t){if(!t.s)return t.t;t.u=!0,n=st(e,t.a.l.A),r=t.a.l.shouldUseStrictIteration()}else n=st(e,!0);return ce(n,(o,i)=>{$e(n,o,Wt(i))},r),t&&(t.u=!1),n}function wn(){function e(d,b=[]){if(d.p!==void 0){let _=d.i.e??d.i.t,w=Dt(Q(_,d.p)),M=Q(_,d.p);if(M===void 0||M!==d.c&&M!==d.t&&M!==d.e||w!=null&&w.t!==d.t)return null;let I=d.i.r===3,P;if(I){let l=d.i;P=Array.from(l.o.keys()).indexOf(d.p)}else P=d.p;if(!(I&&_.size>P||he(_,P)))return null;b.push(P)}if(d.i)return e(d.i,b);b.reverse();try{t(d.e,b)}catch{return null}return b}function t(d,b){let _=d;for(let w=0;w<b.length-1;w++){let M=b[w];if(_=Q(_,M),!le(_)||_===null)throw new Error(`Cannot resolve path at '${b.join("/")}'`)}return _}let n="replace",r="add",o="remove";function i(d,b,_){if(d.a.T.has(d))return;d.a.T.add(d);let{y:w,d:M}=_;switch(d.r){case 0:case 2:return h(d,b,w,M);case 1:return p(d,b,w,M);case 3:return y(d,b,w,M)}}function p(d,b,_,w){let{t:M,n:I}=d,P=d.e;P.length<M.length&&([M,P]=[P,M],[_,w]=[w,_]);let l=d.R===!0;for(let g=0;g<M.length;g++){let S=P[g],v=M[g];if((l||I?.get(g.toString()))&&S!==v){let A=S?.[k];if(A&&A.s)continue;let j=b.concat([g]);_.push({op:n,path:j,value:O(S)}),w.push({op:n,path:j,value:O(v)})}}for(let g=M.length;g<P.length;g++){let S=b.concat([g]);_.push({op:r,path:S,value:O(P[g])})}for(let g=P.length-1;M.length<=g;--g){let S=b.concat([g]);w.push({op:o,path:S})}}function h(d,b,_,w){let{t:M,e:I,r:P}=d;ce(d.n,(l,g)=>{let S=Q(M,l,P),v=Q(I,l,P),A=g?he(M,l)?n:r:o;if(S===v&&A===n)return;let j=b.concat(l);_.push(A===o?{op:A,path:j}:{op:A,path:j,value:O(v)}),w.push(A===r?{op:o,path:j}:A===o?{op:r,path:j,value:O(S)}:{op:n,path:j,value:O(S)})})}function y(d,b,_,w){let{t:M,e:I}=d,P=0;M.forEach(l=>{if(!I.has(l)){let g=b.concat([P]);_.push({op:o,path:g,value:l}),w.unshift({op:r,path:g,value:l})}P++}),P=0,I.forEach(l=>{if(!M.has(l)){let g=b.concat([P]);_.push({op:r,path:g,value:l}),w.unshift({op:o,path:g,value:l})}P++})}function a(d,b,_){let{y:w,d:M}=_;w.push({op:n,path:[],value:b===Be?void 0:b}),M.push({op:n,path:[],value:d})}function u(d,b){return b.forEach(_=>{let{path:w,op:M}=_,I=d;for(let S=0;S<w.length-1;S++){let v=se(I),A=w[S];typeof A!="string"&&typeof A!="number"&&(A=""+A),(v===0||v===1)&&(A==="__proto__"||A===Se)&&z(19),re(I)&&A===Pe&&z(19),I=Q(I,A),le(I)||z(18,w.join("/"))}let P=se(I),l=E(_.value),g=w[w.length-1];switch(M){case n:switch(P){case 2:return I.set(g,l);case 3:z(16);default:return I[g]=l}case r:switch(P){case 1:return g==="-"?I.push(l):I.splice(g,0,l);case 2:return I.set(g,l);case 3:return I.add(l);default:return I[g]=l}case o:switch(P){case 1:return I.splice(g,1);case 2:return I.delete(g);case 3:return I.delete(_.value);default:return delete I[g]}default:z(17,M)}}),d}function E(d){if(!K(d))return d;if(_e(d))return d.map(E);if(ke(d))return new Map(Array.from(d.entries()).map(([_,w])=>[_,E(w)]));if(Ee(d))return new Set(Array.from(d).map(E));let b=Object.create(oe(d));for(let _ in d)b[_]=E(d[_]);return he(d,ae)&&(b[ae]=d[ae]),b}function O(d){return B(d)?E(d):d}ft(Ve,{N:u,O:i,M:a,getPath:e})}function bn(){class e extends Map{constructor(a,u){super(),this[k]={r:2,i:u,a:u?u.a:We(),s:!1,u:!1,e:void 0,n:void 0,t:a,c:this,S:!1,g:!1,f:[]}}get size(){return D(this[k]).size}has(a){return D(this[k]).has(a)}set(a,u){let E=this[k];return p(E),(!D(E).has(a)||D(E).get(a)!==u)&&(n(E),q(E),E.n.set(a,!0),E.e.set(a,u),E.n.set(a,!0),Fe(E,a,u)),this}delete(a){if(!this.has(a))return!1;let u=this[k];return p(u),n(u),q(u),u.t.has(a)?u.n.set(a,!1):u.n.delete(a),u.e.delete(a),!0}clear(){let a=this[k];p(a),D(a).size&&(n(a),q(a),a.n=new Map,ce(a.t,u=>{a.n.set(u,!1)}),a.e.clear())}forEach(a,u){let E=this[k];D(E).forEach((O,d,b)=>{a.call(u,this.get(d),d,this)})}get(a){let u=this[k];p(u);let E=D(u).get(a);if(u.u||!K(E)||E!==u.t.get(a))return E;let O=xe(u.a,E,u,a);return n(u),u.e.set(a,O),O}keys(){return D(this[k]).keys()}values(){let a=this.keys();return{[Symbol.iterator]:()=>this.values(),next:()=>{let u=a.next();return u.done?u:{done:!1,value:this.get(u.value)}}}}entries(){let a=this.keys();return{[Symbol.iterator]:()=>this.entries(),next:()=>{let u=a.next();if(u.done)return u;let E=this.get(u.value);return{done:!1,value:[u.value,E]}}}}[Symbol.iterator](){return this.entries()}}function t(y,a){let u=new e(y,a);return[u,u[k]]}function n(y){y.e||(y.n=new Map,y.e=new Map(y.t))}class r extends Set{constructor(a,u){super(),this[k]={r:3,i:u,a:u?u.a:We(),s:!1,u:!1,e:void 0,t:a,c:this,o:new Map,g:!1,S:!1,n:void 0,f:[]}}get size(){return D(this[k]).size}has(a){let u=this[k];return p(u),u.e?!!(u.e.has(a)||u.o.has(a)&&u.e.has(u.o.get(a))):u.t.has(a)}add(a){let u=this[k];return p(u),this.has(a)||(i(u),q(u),u.e.add(a),Fe(u,a,a)),this}delete(a){if(!this.has(a))return!1;let u=this[k];return p(u),i(u),q(u),u.e.delete(a)||(u.o.has(a)?u.e.delete(u.o.get(a)):!1)}clear(){let a=this[k];p(a),D(a).size&&(i(a),q(a),a.e.clear())}values(){let a=this[k];return p(a),i(a),a.e.values()}entries(){let a=this[k];return p(a),i(a),a.e.entries()}keys(){return this.values()}[Symbol.iterator](){return this.values()}forEach(a,u){let E=this.values(),O=E.next();for(;!O.done;)a.call(u,O.value,O.value,this),O=E.next()}}function o(y,a){let u=new r(y,a);return[u,u[k]]}function i(y){y.e||(y.e=new Set,y.t.forEach(a=>{if(K(a)){let u=xe(y.a,a,y,a);y.o.set(a,u),y.e.add(u)}else y.e.add(a)}))}function p(y){y.g&&z(3,JSON.stringify(D(y)))}function h(y){if(y.r===3&&y.e){let a=new Set(y.e);y.e.clear(),a.forEach(u=>{y.e.add(un(u))})}}ft(we,{w:t,V:o,fixSetContents:h})}function vn(){let e=new Set(["shift","unshift"]),t=new Set(["push","pop"]),n=new Set([...t,...e]),r=new Set(["reverse","sort"]),o=new Set([...n,...r,"splice"]),i=new Set(["find","findLast"]),p=new Set(["filter","slice","concat","flat",...i,"findIndex","findLastIndex","some","every","indexOf","lastIndexOf","includes","join","toString","toLocaleString"]);function h(l){return o.has(l)}function y(l){return p.has(l)}function a(l){return h(l)||y(l)}function u(l,g){l.operationMethod=g}function E(l){l.operationMethod=void 0}function O(l,g,S=!0){ye(l);let v=g();return q(l),S&&l.n.set("length",!0),v}function d(l){l.R=!0}function b(l,g){return l<0?Math.max(g+l,0):Math.min(l,g)}function _(l,g,S){for(let v=0;v<S.length;v++){let A=g+v;l.n.set(A,!0),Fe(l,A,S[v])}}function w(l,g,S){return O(l,()=>{let v=l.e.length,A=l.e[g](...S);return e.has(g)&&d(l),g==="push"&&S.length>0?_(l,v,S):g==="unshift"&&S.length>0&&_(l,0,S),n.has(g)?A:l.c})}function M(l,g,S){return O(l,()=>(l.e[g](...S),d(l),l.c),!1)}function I(l,g){return function(...S){let v=g;u(l,v);try{if(h(v)){if(n.has(v))return w(l,v,S);if(r.has(v))return M(l,v,S);if(v==="splice"){let A=O(l,()=>l.e.splice(...S));if(d(l),S.length>2){let j=b(S[0]??0,l.e.length);_(l,j,S.slice(2))}return A}}else return P(l,v,S)}finally{E(l)}}}function P(l,g,S){let v=D(l);if(g==="filter"){let A=S[0],j=[];for(let N=0;N<v.length;N++)A(v[N],N,v)&&j.push(l.c[N]);return j}if(i.has(g)){let A=S[0],j=g==="find",N=j?1:-1,G=j?0:v.length-1;for(let W=G;W>=0&&W<v.length;W+=N)if(A(v[W],W,v))return l.c[W];return}if(g==="slice"){let A=S[0]??0,j=S[1]??v.length,N=b(A,v.length),G=b(j,v.length),W=[];for(let ee=N;ee<G;ee++)W.push(l.c[ee]);return W}return v[g](...S)}ft(it,{createMethodInterceptor:I,isArrayOperationMethod:a,isMutatingArrayMethod:h})}var V=new Vt,xn=V.produce,Pn=V.produceWithPatches.bind(V),_n=V.setAutoFreeze.bind(V),kn=V.setUseStrictShallowCopy.bind(V),En=V.setUseStrictIteration.bind(V),An=V.applyPatches.bind(V),Cn=V.createDraft.bind(V),Rn=V.finishDraft.bind(V),Mn=e=>e,In=e=>e});var Bt=yt((Zn,Lt)=>{"use strict";Lt.exports=Kt()});var St=typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.subtle.generateKey=="function",qt=async()=>{if(!St)throw new Error("Web Crypto API not available");let e=await crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),t=crypto.getRandomValues(new Uint8Array(12));return{key:e,iv:t}},Ht=async e=>{let t=await crypto.subtle.exportKey("raw",e.key);return{key:btoa(String.fromCharCode(...new Uint8Array(t))),iv:btoa(String.fromCharCode(...e.iv))}},Xt=async(e,t)=>{let n=Uint8Array.from(atob(e),i=>i.charCodeAt(0)),r=Uint8Array.from(atob(t),i=>i.charCodeAt(0));return{key:await crypto.subtle.importKey("raw",n,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),iv:r}},mt=async(e,t)=>{let n=new TextEncoder,r=n.encode(JSON.stringify(e)),o=await crypto.subtle.encrypt({name:"AES-GCM",iv:t.iv},t.key,r),i=new Uint8Array(t.iv.length+o.byteLength);return i.set(t.iv),i.set(new Uint8Array(o),t.iv.length),btoa(String.fromCharCode(...i))},wt=async(e,t)=>{let n=Uint8Array.from(atob(e),p=>p.charCodeAt(0)),r=n.slice(0,12),o=n.slice(12),i=await crypto.subtle.decrypt({name:"AES-GCM",iv:r},t.key,o);return JSON.parse(new TextDecoder().decode(i))},Te=null,Qt=e=>{Te=e},bt=()=>Te!==null,ge=e=>{Te&&Te(e)},Ye=(e,t,n)=>{e.set(t instanceof RegExp?t.source:t,n)},De=(e,t,n,r)=>{if(e.size===0)return!0;for(let[o,i]of e){let p;if(typeof o=="function")p=o(t,r);else try{p=new RegExp(o).test(t)}catch{continue}if(p)return i.includes(n)||i.includes("admin")}return!1},pe=e=>{if(typeof e=="string")return e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/javascript:/gi,"[REMOVED]").replace(/on\w+\s*=/gi,"[REMOVED]=").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi,"").replace(/<embed\b[^<]*(?:(?!<\/embed>)<[^<]*)*<\/embed>/gi,"").replace(/<svg\b[^<]*(?:(?!<\/svg>)<[^<]*)*<\/svg>/gi,"").replace(/<foreignObject\b[^<]*(?:(?!<\/foreignObject>)<[^<]*)*<\/foreignObject>/gi,"").replace(/<math\b[^<]*(?:(?!<\/math>)<[^<]*)*<\/math>/gi,"").replace(/<\?php\b[^<]*(?:(?!<\?php>)<[^<]*)*<\?php>/gi,"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/`/g,"`");if(e&&typeof e=="object"&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))t[n]=pe(r);return t}return Array.isArray(e)?e.map(t=>pe(t)):e},et=e=>/^[a-zA-Z0-9_.-]+$/.test(e)&&e.length<=256,tt=(e,t,n,r)=>{let o={id:crypto.randomUUID(),purpose:n,granted:r,timestamp:Date.now()},i=e.get(t)||[];return i.push(o),e.set(t,i),ge({timestamp:Date.now(),action:"set",key:`consent:${n}`,userId:t,success:!0}),o},vt=(e,t,n)=>{let r=e.get(t);if(!r)return!1;for(let o=r.length-1;o>=0;o--){let i=r[o];if(i&&i.purpose===n)return i.granted}return!1},xt=(e,t,n)=>tt(e,t,n,!1),Pt=(e,t)=>e.get(t)||[],_t=(e,t)=>({userId:t,exportedAt:Date.now(),consents:e.get(t)||[]}),kt=(e,t)=>{let n=e.get(t)?.length||0;return e.delete(t),{success:!0,deletedConsents:n}};var dt=null,Ae=null,On=()=>{if(!dt)try{let e=Bt();dt=e.produce,Ae=e.freeze}catch(e){throw console.error("[gState] Immer not installed. Run: npm install immer"),e}},Tn={local:()=>typeof window<"u"?window.localStorage:null,session:()=>typeof window<"u"?window.sessionStorage:null,memory:()=>{let e=new Map;return{getItem:t=>e.get(t)||null,setItem:(t,n)=>e.set(t,n),removeItem:t=>e.delete(t),key:t=>Array.from(e.keys())[t]||null,get length(){return e.size}}}},He=e=>{if(e===null||typeof e!="object")return e;if(typeof structuredClone=="function")try{return structuredClone(e)}catch{}let t=new WeakMap,n=r=>{if(r===null||typeof r!="object")return r;if(t.has(r))return t.get(r);if(r instanceof Date)return new Date(r.getTime());if(r instanceof RegExp)return new RegExp(r.source,r.flags);let o=Array.isArray(r)?[]:Object.create(Object.getPrototypeOf(r));if(t.set(r,o),Array.isArray(r))for(let i=0;i<r.length;i++)o[i]=n(r[i]);else for(let i of Object.keys(r))o[i]=n(r[i]);return o};return n(e)},Xe=(e,t)=>{if(e===t)return!0;if(e===null||t===null||typeof e!="object"||typeof t!="object")return e===t;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!Xe(e[o],t[o]))return!1;return!0}let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let o of n)if(!r.includes(o)||!Xe(e[o],t[o]))return!1;return!0},ue=e=>{let t=new Map,n=new Map,r=new Map,o=new Set,i=new Map,p=new Set,h=new Map,y=new Map,a=new Map,u=new Map,E=new Map,O=new Map,d=new Map,b=new Map,_=e?.namespace||"gstate",w=e?.silent??!1,M=e?.debounceTime??150,I=e?.version??0,P=e?.storage||Tn.local(),l=e?.onError,g=e?.maxObjectSize??5*1024*1024,S=e?.maxTotalSize??50*1024*1024,v=e?.encryptionKey??null,A=e?.validateInput??!0,j=e?.auditEnabled??!0,N=e?.userId,G=e?.immer??!0;G&&On(),e?.accessRules&&e.accessRules.forEach(s=>Ye(d,s.pattern,s.permissions));let W=!1,ee=!1,Re=!1,J=0,Qe=null,Me,Jt=new Promise(s=>{Me=s}),Ze=s=>{if(s==null)return 0;let c=0,f=[s],m=new WeakSet;for(;f.length>0;){let C=f.pop();if(typeof C=="boolean")c+=4;else if(typeof C=="number")c+=8;else if(typeof C=="string")c+=C.length*2;else if(typeof C=="object"&&C!==null){let x=C;if(m.has(x))continue;if(m.add(x),Array.isArray(x))for(let R=0;R<x.length;R++)f.push(x[R]);else for(let R of Object.keys(x))c+=R.length*2,f.push(x[R])}}return c},Ie=()=>`${_}_`,te=(s,c)=>{u.forEach(f=>{if(f.hooks?.[s])try{f.hooks[s](c)}catch(m){let C=m instanceof Error?m:new Error(String(m));l?l(C,{operation:`plugin:${f.name}:${s}`,key:c.key}):w||console.error(`[gState] Plugin "${f.name}" error:`,m)}})},H=(s,c,f,m)=>{j&&bt()&&ge&&ge({timestamp:Date.now(),action:s,key:c,userId:N,success:f,error:m})},de=s=>{if(s&&(a.get(s)?.forEach(c=>pt(c)),h.get(s)?.forEach(c=>{try{c($.get(s))}catch(f){let m=f instanceof Error?f:new Error(String(f));l?l(m,{operation:"watcher",key:s}):w||console.error(`[gState] Watcher error for "${s}":`,f)}}),i.get(s)?.forEach(c=>{try{c()}catch(f){let m=f instanceof Error?f:new Error(String(f));l?l(m,{operation:"keyListener",key:s}):w||console.error(`[gState] Listener error for "${s}":`,f)}})),W){ee=!0;return}o.forEach(c=>{try{c()}catch(f){let m=f instanceof Error?f:new Error(String(f));l?l(m,{operation:"listener"}):w||console.error("[gState] Global listener error:",f)}})},pt=s=>{let c=y.get(s),f=new Set;if(!c)return;let m=x=>(f.add(x),$.get(x)),C=c.selector(m);c.deps.forEach(x=>{if(!f.has(x)){let R=a.get(x);R&&(R.delete(s),R.size===0&&a.delete(x))}}),f.forEach(x=>{c.deps.has(x)||(a.has(x)||a.set(x,new Set),a.get(x).add(s))}),c.deps=f,Xe(c.lastValue,C)||(c.lastValue=G&&C!==null&&typeof C=="object"?Ae(He(C),!0):C,n.set(s,(n.get(s)||0)+1),de(s))},gt=async()=>{if(!P)return;let s=Array.from(E.entries());E.clear();for(let[c,f]of s)try{let m=f.value,C=f.options.encoded||f.options.secure;if(f.options.encrypted){if(!v)throw new Error(`Encryption key missing for "${c}"`);m=await mt(f.value,v)}else C?m=btoa(JSON.stringify(f.value)):typeof f.value=="object"&&f.value!==null&&(m=JSON.stringify(f.value));P.setItem(`${Ie()}${c}`,JSON.stringify({v:n.get(c)||1,t:Date.now(),e:f.options.ttl?Date.now()+f.options.ttl:null,d:m,_sys_v:I,_enc:f.options.encrypted?!0:void 0,_b64:C?!0:void 0})),H("set",c,!0)}catch(m){let C=m instanceof Error?m:new Error(String(m));l?l(C,{operation:"persist",key:c}):w||console.error("[gState] Persist failed:",C)}},ne={},$={_setSilently:(s,c)=>{let f=r.get(s)||0,m=G&&c!==null&&typeof c=="object"?Ae(He(c),!0):c,C=Ze(m);J=J-f+C,r.set(s,C),t.set(s,m),n.set(s,(n.get(s)||0)+1)},_registerMethod:(s,c,f)=>{if(f!==void 0){let x=s,R=c;ne[x]||(ne[x]={}),ne[x][R]=f;return}console.warn("[gState] _registerMethod(name, fn) is deprecated. Use _registerMethod(pluginName, methodName, fn) instead.");let m=s,C=c;ne.core||(ne.core={}),ne.core[m]=C},set:(s,c,f={})=>{let m=t.get(s),C=G&&typeof c=="function"?dt(m,c):c;if(A&&!et(s))return w||console.warn(`[gState] Invalid key: ${s}`),!1;if(!De(d,s,"write",N))return H("set",s,!1,"RBAC Denied"),w||console.error(`[gState] RBAC Denied for "${s}"`),!1;let x=A?pe(C):C,R=r.get(s)||0;te("onBeforeSet",{key:s,value:x,store:$,version:n.get(s)||0});let L=G&&x!==null&&typeof x=="object"?Ae(He(x),!0):x;if(!Xe(m,L)){let T=g>0||S>0?Ze(L):0;if(g>0&&T>g){let U=new Error(`Object size (${T} bytes) exceeds maxObjectSize (${g} bytes)`);l?l(U,{operation:"set",key:s}):w||console.warn(`[gState] ${U.message} for "${s}"`)}if(S>0){let U=J-R+T;if(U>S){let Oe=new Error(`Total store size (${U} bytes) exceeds limit (${S} bytes)`);l?l(Oe,{operation:"set"}):w||console.warn(`[gState] ${Oe.message}`)}}J=J-R+T,r.set(s,T),t.set(s,L),n.set(s,(n.get(s)||0)+1);let X=!!(f.persist||e?.persistByDefault||e?.persistence||f.encrypted||f.encoded||f.secure||f.ttl);return X&&(E.set(s,{value:L,options:{...f,persist:X}}),Qe&&clearTimeout(Qe),Qe=setTimeout(gt,M)),te("onSet",{key:s,value:L,store:$,version:n.get(s)}),H("set",s,!0),de(s),!0}return!1},get:s=>{if(!De(d,s,"read",N))return H("get",s,!1,"RBAC Denied"),null;let c=t.get(s);return te("onGet",{store:$,key:s,value:c}),H("get",s,!0),c},compute:(s,c)=>{try{return y.has(s)||(y.set(s,{selector:c,lastValue:null,deps:new Set}),pt(s)),y.get(s).lastValue}catch(f){let m=f instanceof Error?f:new Error(String(f));return l?l(m,{operation:"compute",key:s}):w||console.error(`[gState] Compute error for "${s}":`,f),null}},watch:(s,c)=>{h.has(s)||h.set(s,new Set);let f=h.get(s);return f.add(c),()=>{f.delete(c),f.size===0&&h.delete(s)}},remove:s=>{if(!De(d,s,"delete",N))return H("delete",s,!1,"RBAC Denied"),!1;let c=t.get(s),f=t.delete(s);return f&&(J-=r.get(s)||0,r.delete(s),te("onRemove",{store:$,key:s,value:c})),n.set(s,(n.get(s)||0)+1),P&&P.removeItem(`${Ie()}${s}`),H("delete",s,!0),de(s),f},delete:s=>$.remove(s),deleteAll:()=>{if(Array.from(t.keys()).forEach(s=>$.remove(s)),P){let s=Ie();for(let c=0;c<(P.length||0);c++){let f=P.key(c);f?.startsWith(s)&&(P.removeItem(f),c--)}}return J=0,r.clear(),!0},list:()=>Object.fromEntries(t.entries()),use:s=>{p.add(s)},transaction:s=>{W=!0,te("onTransaction",{store:$,key:"START"});try{s()}finally{W=!1,te("onTransaction",{store:$,key:"END"}),ee&&(ee=!1,de())}},destroy:()=>{typeof window<"u"&&window.removeEventListener("beforeunload",ht),te("onDestroy",{store:$}),o.clear(),i.clear(),h.clear(),y.clear(),a.clear(),u.clear(),t.clear(),r.clear(),J=0,d.clear(),b.clear()},_addPlugin:s=>{try{u.set(s.name,s),s.hooks?.onInstall?.({store:$})}catch(c){let f=c instanceof Error?c:new Error(String(c));l?l(f,{operation:"plugin:install",key:s.name}):w||console.error(`[gState] Failed to install plugin "${s.name}":`,c)}},_removePlugin:s=>{u.delete(s)},_subscribe:(s,c)=>{if(c){i.has(c)||i.set(c,new Set);let f=i.get(c);return f.add(s),()=>{f.delete(s),f.size===0&&i.delete(c)}}return o.add(s),()=>o.delete(s)},_getVersion:s=>n.get(s)??0,addAccessRule:(s,c)=>Ye(d,s,c),hasPermission:(s,c,f)=>{if(d.size===0)return!0;for(let[m,C]of d){let x;if(typeof m=="function")x=m(s,f);else try{let R=O.get(m);R||(R=new RegExp(m),O.set(m,R)),x=R.test(s)}catch{continue}if(x)return C.includes(c)||C.includes("admin")}return!1},recordConsent:(s,c,f)=>tt(b,s,c,f),hasConsent:(s,c)=>vt(b,s,c),getConsents:s=>Pt(b,s),revokeConsent:(s,c)=>xt(b,s,c),exportUserData:s=>_t(b,s),deleteUserData:s=>kt(b,s),get plugins(){return ne},get isReady(){return Re},whenReady:()=>Jt};["addAccessRule","recordConsent","hasConsent","getConsents","revokeConsent","exportUserData","deleteUserData"].forEach(s=>{let c=$[s];c&&$._registerMethod("security",s,c)});let ht=()=>{E.size>0&>()};return typeof window<"u"&&window.addEventListener("beforeunload",ht),P?(async()=>{try{let c={},f=Ie(),m=0;for(let x=0;x<(P.length||0);x++){let R=P.key(x);if(!R||!R.startsWith(f))continue;let L=P.getItem(R);if(L)try{let T=JSON.parse(L),X=R.substring(f.length);if(m=Math.max(m,T._sys_v!==void 0?T._sys_v:T.v||0),T.e&&Date.now()>T.e){P.removeItem(R),x--;continue}let U=T.d;if(T._enc&&v)U=await wt(U,v);else if(typeof U=="string"){if(T._b64)try{U=JSON.parse(atob(U))}catch{}else if(U.startsWith("{")||U.startsWith("["))try{U=JSON.parse(U)}catch{}}c[X]=U,H("hydrate",X,!0)}catch(T){H("hydrate",R,!1,String(T));let X=T instanceof Error?T:new Error(String(T));l?l(X,{operation:"hydration",key:R}):w||console.error(`[gState] Hydration failed for "${R}":`,T)}}let C=m<I&&e?.migrate?e.migrate(c,m):c;Object.entries(C).forEach(([x,R])=>{let L=G&&R!==null&&typeof R=="object"?Ae(He(R),!0):R,T=Ze(L),X=r.get(x)||0;J=J-X+T,r.set(x,T),t.set(x,L),n.set(x,1)}),Re=!0,Me(),de()}catch(c){Re=!0,Me();let f=c instanceof Error?c:new Error(String(c));l?l(f,{operation:"hydration"}):w||console.error("[gState] Hydration failed:",f)}})():(Re=!0,Me()),$};import{useSyncExternalStore as Gt,useDebugValue as Dn,useMemo as fe}from"react";var Y=null,jn=e=>{Y&&!e?.namespace&&(e?.silent||console.warn("[gState] Store already exists. Pass a unique namespace to create additional stores."));let t=ue(e);return Y=t,t},zn=()=>{Y&&(Y.destroy(),Y=null)},Un=e=>{let t=e||Y,n=fe(()=>r=>t?t._subscribe(r):()=>{},[t]);return Gt(n,()=>t?t.isReady:!1,()=>!0)},Z=()=>Y;var Ce=(e,t)=>{let n=fe(()=>t||Y,[t]),r=fe(()=>({set:()=>(console.warn("[gState] Store not initialized. Call initState() or pass a store instance."),!1),get:()=>null,remove:()=>!1,delete:()=>!1,deleteAll:()=>!1,list:()=>({}),compute:()=>null,watch:()=>()=>{},use:()=>{},transaction:()=>{},destroy:()=>{},_subscribe:()=>()=>{},_setSilently:()=>{},_registerMethod:()=>{},_addPlugin:()=>{},_removePlugin:()=>{},_getVersion:()=>0,get isReady(){return!1},whenReady:()=>Promise.resolve(),get plugins(){return new Proxy({},{get:(y,a)=>new Proxy({},{get:(u,E)=>(...O)=>(console.warn(`[gState] Ghost store: Cannot call store.plugins.${String(a)}.${String(E)}() - store not initialized. Call initState() first or pass a store instance to useStore().`),null)})})}}),[]),o=n||r;fe(()=>{!n&&!t&&console.warn("[gState] Using ghost store - no store initialized. Call initState() or pass a store instance.")},[n,t]);let i=fe(()=>y=>o._subscribe(y,e),[o,e]),p=Gt(i,()=>o.get(e)??void 0,()=>{}),h=fe(()=>(y,a)=>o.set(e,y,a),[o,e]);return Dn(p,y=>`${e}: ${JSON.stringify(y)}`),[p,h]};var $n=(e,t)=>{let n=t?.key||"async_data",r=t?.store||ue({namespace:`async_${n}`,silent:!0});return r.get(n)==null&&r.set(n,{data:null,loading:!1,error:null,updatedAt:null}),Object.assign(r,{execute:async()=>{let i=r.get(n);r.set(n,{...i||{data:null,loading:!1,error:null,updatedAt:null},loading:!0,error:null}),"whenReady"in r&&!r.isReady&&await r.whenReady();try{let p=await e(),h=r.get(n);r.set(n,{...h||{data:null,loading:!1,error:null,updatedAt:null},data:p,loading:!1,updatedAt:Date.now()},{persist:t?.persist})}catch(p){let h=r.get(n);r.set(n,{...h||{data:null,loading:!1,error:null,updatedAt:null},error:p instanceof Error?p:new Error(String(p)),loading:!1})}}})};var Vn=()=>({name:"gstate-immer",hooks:{onInstall:({store:e})=>{e._registerMethod("immer","setWithProduce",((t,n)=>e.set(t,n)))}}});var Nn=e=>{let t=[],n=-1,r=!1,o=e?.limit||50;return{name:"gstate-undo-redo",hooks:{onInstall:({store:i})=>{t.push(i.list()),n=0,i._registerMethod("undoRedo","undo",()=>{if(n>0){r=!0,n--;let p=t[n];return p?(Object.entries(p).forEach(([h,y])=>{i._setSilently(h,y)}),r=!1,!0):!1}return!1}),i._registerMethod("undoRedo","redo",()=>{if(n<t.length-1){r=!0,n++;let p=t[n];return p?(Object.entries(p).forEach(([h,y])=>{i._setSilently(h,y)}),r=!1,!0):!1}return!1}),i._registerMethod("undoRedo","canUndo",()=>n>0),i._registerMethod("undoRedo","canRedo",()=>n<t.length-1)},onSet:({store:i})=>{r||(n<t.length-1&&(t=t.slice(0,n+1)),t.push(i.list()),t.length>o?t.shift():n++)}}}};var Wn=e=>({name:"gstate-schema",hooks:{onSet:({key:t,value:n})=>{if(!t)return;let r=e[t];if(r){let o=r(n);if(o!==!0)throw new Error(`[Schema Error] Validation failed for key "${t}": ${o===!1?"Invalid type":o}`)}}}});var Fn=e=>{let r=globalThis.__REDUX_DEVTOOLS_EXTENSION__;if(!r?.connect)return{name:"gstate-devtools-noop",hooks:{}};let o=null;return{name:"gstate-devtools",hooks:{onInstall:({store:i})=>{o=r.connect({name:e?.name||"Magnetar Store"}),o.init(i.list())},onSet:({key:i,store:p})=>{!i||!o||o.send(`SET_${i.toUpperCase()}`,p.list())},onRemove:({key:i,store:p})=>{!i||!o||o.send(`REMOVE_${i.toUpperCase()}`,p.list())}}}};var Kn=()=>{let e=new Map;return{name:"gstate-snapshot",hooks:{onInstall:({store:t})=>{t._registerMethod("snapshot","takeSnapshot",(n=>{e.set(n,t.list())})),t._registerMethod("snapshot","restoreSnapshot",(n=>{let r=e.get(n);return r?(t.transaction(()=>{Object.entries(r).forEach(([o,i])=>{t.set(o,i)})}),!0):!1})),t._registerMethod("snapshot","listSnapshots",(()=>Array.from(e.keys()))),t._registerMethod("snapshot","deleteSnapshot",(n=>e.delete(n))),t._registerMethod("snapshot","clearSnapshots",(()=>e.clear()))}}}};var Ln=e=>({name:"gstate-guard",hooks:{onBeforeSet:({key:t,value:n,store:r})=>{if(!t)return;let o=e[t];if(o){let i=o(n)}}}});var Bn=e=>({name:"gstate-analytics",hooks:{onSet:({key:t,value:n})=>{t&&(!e.keys||e.keys.includes(t))&&e.provider({key:t,value:n,action:"SET"})},onRemove:({key:t})=>{t&&(!e.keys||e.keys.includes(t))&&e.provider({key:t,value:null,action:"REMOVE"})}}});var Gn=e=>{let t=new BroadcastChannel(e?.channelName||"gstate_sync"),n=!1;return{name:"gstate-sync",hooks:{onInstall:({store:r})=>{t.onmessage=o=>{let{key:i,value:p,action:h}=o.data;i&&(n=!0,h==="REMOVE"?r.remove(i):r.set(i,p),n=!1)}},onSet:({key:r,value:o})=>{!r||n||t.postMessage({key:r,value:o,action:"SET"})},onRemove:({key:r})=>{!r||n||t.postMessage({key:r,action:"REMOVE"})},onDestroy:()=>{t.close()}}}};var Jn=()=>({name:"gstate-debug-noop",hooks:{}});var gr=e=>({name:"gstate-logger",hooks:{onSet:({key:t,value:n,version:r})=>{let o=new Date().toLocaleTimeString(),i=`[gState] SET: ${t} (v${r}) @ ${o}`;e?.collapsed?console.groupCollapsed(i):console.group(i),console.info("%c Value:","color: #4CAF50; font-weight: bold;",n),console.groupEnd()},onRemove:({key:t})=>{console.warn(`[gState] REMOVED: ${t}`)},onTransaction:({key:t})=>{t==="START"?console.group("\u2500\u2500 TRANSACTION START \u2500\u2500"):console.groupEnd()}}});var Cr=(e,t)=>{let r=ue(typeof t=="string"?{namespace:t}:t);return e&&Object.entries(e).forEach(([i,p])=>{r._setSilently(i,p)}),Object.assign(i=>Ce(i,r),r)};var Rr=(e,t)=>Z()?.addAccessRule(e,t),Mr=(e,t,n)=>Z()?.hasPermission(e,t,n)??!0,Ir=(e,t,n)=>{let r=Z();if(!r)throw new Error("[gState] recordConsent failed: No store found. call initState() first.");return r.recordConsent(e,t,n)},Or=(e,t)=>Z()?.hasConsent(e,t)??!1,Tr=e=>Z()?.getConsents(e)??[],Dr=(e,t)=>Z()?.revokeConsent(e,t),jr=e=>{let t=Z();if(!t)throw new Error("[gState] exportUserData failed: No store found.");return t.exportUserData(e)},zr=e=>{let t=Z();if(!t)throw new Error("[gState] deleteUserData failed: No store found.");return t.deleteUserData(e)},Ur=()=>{},$r=()=>{};export{Rr as addAccessRule,Bn as analyticsPlugin,Ur as clearAccessRules,$r as clearAllConsents,$n as createAsyncStore,ue as createStore,Jn as debugPlugin,zr as deleteUserData,zn as destroyState,Fn as devToolsPlugin,Ht as exportKey,jr as exportUserData,qt as generateEncryptionKey,Tr as getConsents,Cr as gstate,Ln as guardPlugin,Or as hasConsent,Mr as hasPermission,Vn as immerPlugin,Xt as importKey,jn as initState,St as isCryptoAvailable,ge as logAudit,gr as loggerPlugin,Ir as recordConsent,Dr as revokeConsent,pe as sanitizeValue,Wn as schemaPlugin,Qt as setAuditLogger,Kn as snapshotPlugin,Gn as syncPlugin,Nn as undoRedoPlugin,Ce as useGState,Un as useIsStoreReady,Ce as useSimpleState,Ce as useStore,et as validateKey};
|
|
1
|
+
var pt=Symbol.for("immer-nothing"),ot=Symbol.for("immer-draftable"),R=Symbol.for("immer-state");function O(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var M=Object,H=M.getPrototypeOf,we="constructor",ke="prototype",je="configurable",be="enumerable",me="writable",te="value",$=e=>!!e&&!!e[R];function U(e){return e?gt(e)||Re(e)||!!e[ot]||!!e[we]?.[ot]||Ae(e)||Ie(e):!1}var Vt=M[ke][we].toString(),st=new WeakMap;function gt(e){if(!e||!He(e))return!1;let t=H(e);if(t===null||t===M[ke])return!0;let n=M.hasOwnProperty.call(t,we)&&t[we];if(n===Object)return!0;if(!J(n))return!1;let r=st.get(n);return r===void 0&&(r=Function.toString.call(n),st.set(n,r)),r===Vt}function Ce(e,t,n=!0){oe(e)===0?(n?Reflect.ownKeys(e):M.keys(e)).forEach(o=>{t(o,e[o],e)}):e.forEach((r,o)=>t(o,r,e))}function oe(e){let t=e[R];return t?t.type_:Re(e)?1:Ae(e)?2:Ie(e)?3:0}var it=(e,t,n=oe(e))=>n===2?e.has(t):M[ke].hasOwnProperty.call(e,t),Fe=(e,t,n=oe(e))=>n===2?e.get(t):e[t],Ee=(e,t,n,r=oe(e))=>{r===2?e.set(t,n):r===3?e.add(n):e[t]=n};function Nt(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}var Re=Array.isArray,Ae=e=>e instanceof Map,Ie=e=>e instanceof Set,He=e=>typeof e=="object",J=e=>typeof e=="function",Ue=e=>typeof e=="boolean";function Ut(e){let t=+e;return Number.isInteger(t)&&String(t)===e}var N=e=>e.copy_||e.base_;var qe=e=>e.modified_?e.copy_:e.base_;function Be(e,t){if(Ae(e))return new Map(e);if(Ie(e))return new Set(e);if(Re(e))return Array[ke].slice.call(e);let n=gt(e);if(t===!0||t==="class_only"&&!n){let r=M.getOwnPropertyDescriptors(e);delete r[R];let o=Reflect.ownKeys(r);for(let i=0;i<o.length;i++){let u=o[i],f=r[u];f[me]===!1&&(f[me]=!0,f[je]=!0),(f.get||f.set)&&(r[u]={[je]:!0,[me]:!0,[be]:f[be],[te]:e[u]})}return M.create(H(e),r)}else{let r=H(e);if(r!==null&&n)return{...e};let o=M.create(r);return M.assign(o,e)}}function j(e,t=!1){return Me(e)||$(e)||!U(e)||(oe(e)>1&&M.defineProperties(e,{set:Se,add:Se,clear:Se,delete:Se}),M.freeze(e),t&&Ce(e,(n,r)=>{j(r,!0)},!1)),e}function $t(){O(2)}var Se={[te]:$t};function Me(e){return e===null||!He(e)?!0:M.isFrozen(e)}var xe="MapSet",Le="Patches",at="ArrayMethods",yt={};function W(e){let t=yt[e];return t||O(0,e),t}var ct=e=>!!yt[e];var ne,ht=()=>ne,jt=(e,t)=>({drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:ct(xe)?W(xe):void 0,arrayMethodsPlugin_:ct(at)?W(at):void 0});function ut(e,t){t&&(e.patchPlugin_=W(Le),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function Ke(e){We(e),e.drafts_.forEach(Ft),e.drafts_=null}function We(e){e===ne&&(ne=e.parent_)}var lt=e=>ne=jt(ne,e);function Ft(e){let t=e[R];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function ft(e,t){t.unfinalizedDrafts_=t.drafts_.length;let n=t.drafts_[0];if(e!==void 0&&e!==n){n[R].modified_&&(Ke(t),O(4)),U(e)&&(e=dt(t,e));let{patchPlugin_:o}=t;o&&o.generateReplacementPatches_(n[R].base_,e,t)}else e=dt(t,n);return Bt(t,e,!0),Ke(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==pt?e:void 0}function dt(e,t){if(Me(t))return t;let n=t[R];if(!n)return Pe(t,e.handledSet_,e);if(!De(n,e))return t;if(!n.modified_)return n.base_;if(!n.finalized_){let{callbacks_:r}=n;if(r)for(;r.length>0;)r.pop()(e);_t(n,e)}return n.copy_}function Bt(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&j(t,n)}function St(e){e.finalized_=!0,e.scope_.unfinalizedDrafts_--}var De=(e,t)=>e.scope_===t,Lt=[];function mt(e,t,n,r){let o=N(e),i=e.type_;if(r!==void 0&&Fe(o,r,i)===t){Ee(o,r,n,i);return}if(!e.draftLocations_){let f=e.draftLocations_=new Map;Ce(o,(p,g)=>{if($(g)){let S=f.get(g)||[];S.push(p),f.set(g,S)}})}let u=e.draftLocations_.get(t)??Lt;for(let f of u)Ee(o,f,n,i)}function Kt(e,t,n){e.callbacks_.push(function(o){let i=t;if(!i||!De(i,o))return;o.mapSetPlugin_?.fixSetContents(i);let u=qe(i);mt(e,i.draft_??i,u,n),_t(i,o)})}function _t(e,t){if(e.modified_&&!e.finalized_&&(e.type_===3||e.type_===1&&e.allIndicesReassigned_||(e.assigned_?.size??0)>0)){let{patchPlugin_:r}=t;if(r){let o=r.getPath(e);o&&r.generatePatches_(e,o,t)}St(e)}}function Wt(e,t,n){let{scope_:r}=e;if($(n)){let o=n[R];De(o,r)&&o.callbacks_.push(function(){_e(e);let u=qe(o);mt(e,n,u,t)})}else U(n)&&e.callbacks_.push(function(){let i=N(e);e.type_===3?i.has(n)&&Pe(n,r.handledSet_,r):Fe(i,t,e.type_)===n&&r.drafts_.length>1&&(e.assigned_.get(t)??!1)===!0&&e.copy_&&Pe(Fe(e.copy_,t,e.type_),r.handledSet_,r)})}function Pe(e,t,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||$(e)||t.has(e)||!U(e)||Me(e)||(t.add(e),Ce(e,(r,o)=>{if($(o)){let i=o[R];if(De(i,n)){let u=qe(i);Ee(e,r,u,e.type_),St(i)}}else U(o)&&Pe(o,t,n)})),e}function Gt(e,t){let n=Re(e),r={type_:n?1:0,scope_:t?t.scope_:ht(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0},o=r,i=ve;n&&(o=[r],i=re);let{revoke:u,proxy:f}=Proxy.revocable(o,i);return r.draft_=f,r.revoke_=u,[f,r]}var ve={get(e,t){if(t===R)return e;let n=e.scope_.arrayMethodsPlugin_,r=e.type_===1&&typeof t=="string";if(r&&n?.isArrayOperationMethod(t))return n.createMethodInterceptor(e,t);let o=N(e);if(!it(o,t,e.type_))return Jt(e,o,t);let i=o[t];if(e.finalized_||!U(i)||r&&e.operationMethod&&n?.isMutatingArrayMethod(e.operationMethod)&&Ut(t))return i;if(i===$e(e.base_,t)){_e(e);let u=e.type_===1?+t:t,f=Je(e.scope_,i,e,u);return e.copy_[u]=f}return i},has(e,t){return t in N(e)},ownKeys(e){return Reflect.ownKeys(N(e))},set(e,t,n){let r=wt(N(e),t);if(r?.set)return r.set.call(e.draft_,n),!0;if(!e.modified_){let o=$e(N(e),t),i=o?.[R];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_.set(t,!1),!0;if(Nt(n,o)&&(n!==void 0||it(e.base_,t,e.type_)))return!0;_e(e),Ge(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_.set(t,!0),Wt(e,t,n)),!0},deleteProperty(e,t){return _e(e),$e(e.base_,t)!==void 0||t in e.base_?(e.assigned_.set(t,!1),Ge(e)):e.assigned_.delete(t),e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){let n=N(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{[me]:!0,[je]:e.type_!==1||t!=="length",[be]:r[be],[te]:n[t]}},defineProperty(){O(11)},getPrototypeOf(e){return H(e.base_)},setPrototypeOf(){O(12)}},re={};for(let e in ve){let t=ve[e];re[e]=function(){let n=arguments;return n[0]=n[0][0],t.apply(this,n)}}re.deleteProperty=function(e,t){return re.set.call(this,e,t,void 0)};re.set=function(e,t,n){return ve.set.call(this,e[0],t,n,e[0])};function $e(e,t){let n=e[R];return(n?N(n):e)[t]}function Jt(e,t,n){let r=wt(t,n);return r?te in r?r[te]:r.get?.call(e.draft_):void 0}function wt(e,t){if(!(t in e))return;let n=H(e);for(;n;){let r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=H(n)}}function Ge(e){e.modified_||(e.modified_=!0,e.parent_&&Ge(e.parent_))}function _e(e){e.copy_||(e.assigned_=new Map,e.copy_=Be(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Ht=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(t,n,r)=>{if(J(t)&&!J(n)){let i=n;n=t;let u=this;return function(p=i,...g){return u.produce(p,S=>n.call(this,S,...g))}}J(n)||O(6),r!==void 0&&!J(r)&&O(7);let o;if(U(t)){let i=lt(this),u=Je(i,t,void 0),f=!0;try{o=n(u),f=!1}finally{f?Ke(i):We(i)}return ut(i,r),ft(o,i)}else if(!t||!He(t)){if(o=n(t),o===void 0&&(o=t),o===pt&&(o=void 0),this.autoFreeze_&&j(o,!0),r){let i=[],u=[];W(Le).generateReplacementPatches_(t,o,{patches_:i,inversePatches_:u}),r(i,u)}return o}else O(1,t)},this.produceWithPatches=(t,n)=>{if(J(t))return(u,...f)=>this.produceWithPatches(u,p=>t(p,...f));let r,o;return[this.produce(t,n,(u,f)=>{r=u,o=f}),r,o]},Ue(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),Ue(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),Ue(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){U(e)||O(8),$(e)&&(e=qt(e));let t=lt(this),n=Je(t,e,void 0);return n[R].isManual_=!0,We(t),n}finishDraft(e,t){let n=e&&e[R];(!n||!n.isManual_)&&O(9);let{scope_:r}=n;return ut(r,t),ft(void 0,r)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){let o=t[n];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}n>-1&&(t=t.slice(n+1));let r=W(Le).applyPatches_;return $(e)?r(e,t):this.produce(e,o=>r(o,t))}};function Je(e,t,n,r){let[o,i]=Ae(t)?W(xe).proxyMap_(t,n):Ie(t)?W(xe).proxySet_(t,n):Gt(t,n);return(n?.scope_??ht()).drafts_.push(o),i.callbacks_=n?.callbacks_??[],i.key_=r,n&&r!==void 0?Kt(n,i,r):i.callbacks_.push(function(p){p.mapSetPlugin_?.fixSetContents(i);let{patchPlugin_:g}=p;i.modified_&&g&&g.generatePatches_(i,[],p)}),o}function qt(e){return $(e)||O(10,e),bt(e)}function bt(e){if(!U(e)||Me(e))return e;let t=e[R],n,r=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=Be(e,t.scope_.immer_.useStrictShallowCopy_),r=t.scope_.immer_.shouldUseStrictIteration()}else n=Be(e,!0);return Ce(n,(o,i)=>{Ee(n,o,bt(i))},r),t&&(t.finalized_=!1),n}var Xt=new Ht,Et=Xt.produce;var xt=typeof crypto<"u"&&typeof crypto.subtle<"u"&&typeof crypto.subtle.generateKey=="function",Qt=async()=>{if(!xt)throw new Error("Web Crypto API not available");let e=await crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),t=crypto.getRandomValues(new Uint8Array(12));return{key:e,iv:t}},Yt=async e=>{let t=await crypto.subtle.exportKey("raw",e.key);return{key:btoa(String.fromCharCode(...new Uint8Array(t))),iv:btoa(String.fromCharCode(...e.iv))}},Zt=async(e,t)=>{let n=Uint8Array.from(atob(e),i=>i.charCodeAt(0)),r=Uint8Array.from(atob(t),i=>i.charCodeAt(0));return{key:await crypto.subtle.importKey("raw",n,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]),iv:r}},Pt=async(e,t)=>{let n=new TextEncoder,r=n.encode(JSON.stringify(e)),o=await crypto.subtle.encrypt({name:"AES-GCM",iv:t.iv},t.key,r),i=new Uint8Array(t.iv.length+o.byteLength);return i.set(t.iv),i.set(new Uint8Array(o),t.iv.length),btoa(String.fromCharCode(...i))},vt=async(e,t)=>{let n=Uint8Array.from(atob(e),u=>u.charCodeAt(0)),r=n.slice(0,12),o=n.slice(12),i=await crypto.subtle.decrypt({name:"AES-GCM",iv:r},t.key,o);return JSON.parse(new TextDecoder().decode(i))},Oe=null,en=e=>{Oe=e},kt=()=>Oe!==null,ie=e=>{Oe&&Oe(e)},Xe=(e,t,n)=>{e.set(t instanceof RegExp?t.source:t,n)},Te=(e,t,n,r)=>{if(e.size===0)return!0;for(let[o,i]of e){let u;if(typeof o=="function")u=o(t,r);else try{u=new RegExp(o).test(t)}catch{continue}if(u)return i.includes(n)||i.includes("admin")}return!1},se=e=>{if(typeof e=="string")return e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"[SEC-REMOVED]").replace(/javascript:/gi,"[SEC-REMOVED]").replace(/data:text\/html/gi,"[SEC-REMOVED]").replace(/vbscript:/gi,"[SEC-REMOVED]").replace(/on\w+\s*=/gi,"[SEC-REMOVED]=").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"[SEC-REMOVED]").replace(/<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi,"[SEC-REMOVED]").replace(/<embed\b[^<]*(?:(?!<\/embed>)<[^<]*)*<\/embed>/gi,"[SEC-REMOVED]").replace(/<svg\b[^<]*(?:(?!<\/svg>)<[^<]*)*<\/svg>/gi,"[SEC-REMOVED]").replace(/<form\b[^<]*(?:(?!<\/form>)<[^<]*)*<\/form>/gi,"[SEC-REMOVED]").replace(/<base\b[^<]*(?:(?!<\/base>)<[^<]*)*<\/base>/gi,"[SEC-REMOVED]").replace(/<link\b[^<]*(?:(?!<\/link>)<[^<]*)*<\/link>/gi,"[SEC-REMOVED]").replace(/<meta\b[^<]*(?:(?!<\/meta>)<[^<]*)*<\/meta>/gi,"[SEC-REMOVED]").replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi,"[SEC-REMOVED]").replace(/&#[xX]?[0-9a-fA-F]+;?/g,"");if(e&&typeof e=="object"&&!Array.isArray(e)){if(Object.getPrototypeOf(e)===Object.prototype){let t={};for(let[n,r]of Object.entries(e))t[n]=se(r);return t}return e}return Array.isArray(e)?e.map(t=>se(t)):e},Qe=e=>/^[a-zA-Z0-9_.-]+$/.test(e)&&e.length<=256,Ye=(e,t,n,r)=>{let o={id:crypto.randomUUID(),purpose:n,granted:r,timestamp:Date.now()},i=e.get(t)||[];return i.push(o),e.set(t,i),ie({timestamp:Date.now(),action:"set",key:`consent:${n}`,userId:t,success:!0}),o},Ct=(e,t,n)=>{let r=e.get(t);if(!r)return!1;for(let o=r.length-1;o>=0;o--){let i=r[o];if(i&&i.purpose===n)return i.granted}return!1},Rt=(e,t,n)=>Ye(e,t,n,!1),At=(e,t)=>e.get(t)||[],It=(e,t)=>({userId:t,exportedAt:Date.now(),consents:e.get(t)||[]}),Mt=(e,t)=>{let n=e.get(t)?.length||0;return e.delete(t),{success:!0,deletedConsents:n}};var ce=e=>{if(e===null||typeof e!="object")return e;if(typeof structuredClone=="function")try{return structuredClone(e)}catch{}let t=new WeakMap,n=r=>{if(r===null||typeof r!="object"||typeof r=="function")return r;if(t.has(r))return t.get(r);if(r instanceof Date)return new Date(r.getTime());if(r instanceof RegExp)return new RegExp(r.source,r.flags);if(r instanceof Map){let u=new Map;return t.set(r,u),r.forEach((f,p)=>u.set(n(p),n(f))),u}if(r instanceof Set){let u=new Set;return t.set(r,u),r.forEach(f=>u.add(n(f))),u}let o=Array.isArray(r)?[]:Object.create(Object.getPrototypeOf(r));t.set(r,o);let i=[...Object.keys(r),...Object.getOwnPropertySymbols(r)];for(let u of i)o[u]=n(r[u]);return o};return n(e)},ae=(e,t)=>{if(e===t)return!0;if(e===null||t===null||typeof e!="object"||typeof t!="object")return e===t;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!ae(e[o],t[o]))return!1;return!0}let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let o=0;o<n.length;o++){let i=n[o];if(!(i in t)||!ae(e[i],t[i]))return!1}return!0};var nn={local:()=>typeof window<"u"?window.localStorage:null,session:()=>typeof window<"u"?window.sessionStorage:null,memory:()=>{let e=new Map;return{getItem:t=>e.get(t)||null,setItem:(t,n)=>e.set(t,n),removeItem:t=>e.delete(t),key:t=>Array.from(e.keys())[t]||null,get length(){return e.size}}}},q=e=>{let t=new Map,n=new Map,r=new Map,o=new Set,i=new Map,u=new Set,f=new Map,p=new Map,g=new Map,S=new Map,m=new Map,v=new Map,_=new Map,k=new Map,P=e?.namespace||"gstate",w=e?.silent??!1,fe=e?.debounceTime??150,X=e?.version??0,A=e?.storage||nn.local(),b=e?.onError,de=e?.maxObjectSize??5*1024*1024,pe=e?.maxTotalSize??50*1024*1024,ge=e?.encryptionKey??null,Ze=e?.validateInput??!0,Ot=e?.auditEnabled??!0,Q=e?.userId,Y=e?.immer??!0,Tt=e?.persistByDefault??e?.persistence??e?.persist??!1;e?.accessRules&&e.accessRules.forEach(s=>Xe(_,s.pattern,s.permissions));let ze=!1,Ve=!1,ye=!1,T=0,G=null,he,zt=new Promise(s=>{he=s}),Ne=s=>{if(s==null)return 0;let a=typeof s;if(a==="boolean")return 4;if(a==="number")return 8;if(a==="string")return s.length*2;if(a!=="object")return 0;let c=0,d=[s],h=new WeakSet;for(;d.length>0;){let l=d.pop();if(typeof l=="boolean")c+=4;else if(typeof l=="number")c+=8;else if(typeof l=="string")c+=l.length*2;else if(typeof l=="object"&&l!==null){let y=l;if(h.has(y))continue;if(h.add(y),Array.isArray(y))for(let E=0;E<y.length;E++)d.push(y[E]);else for(let E of Object.keys(y))c+=E.length*2,d.push(y[E])}}return c},Z=()=>`${P}_`,B=(s,a)=>{if(S.size!==0)for(let c of S.values()){let d=c.hooks?.[s];if(d)try{d(a)}catch(h){let l=h instanceof Error?h:new Error(String(h));b?b(l,{operation:`plugin:${c.name}:${s}`,key:a.key}):w||console.error(`[gState] Plugin "${c.name}" error:`,h)}}},z=(s,a,c,d)=>{Ot&&kt()&&ie&&ie({timestamp:Date.now(),action:s,key:a,userId:Q,success:c,error:d})},ee=s=>{if(s){let a=g.get(s);if(a)for(let h of a)et(h);let c=f.get(s);if(c){let h=C.get(s);for(let l of c)try{l(h)}catch(y){let E=y instanceof Error?y:new Error(String(y));b?b(E,{operation:"watcher",key:s}):w||console.error(`[gState] Watcher error for "${s}":`,y)}}let d=i.get(s);if(d)for(let h of d)try{h()}catch(l){let y=l instanceof Error?l:new Error(String(l));b?b(y,{operation:"keyListener",key:s}):w||console.error(`[gState] Listener error for "${s}":`,l)}}if(ze){Ve=!0;return}for(let a of o)try{a()}catch(c){let d=c instanceof Error?c:new Error(String(c));b?b(d,{operation:"listener"}):w||console.error("[gState] Global listener error: ",c)}},et=s=>{let a=p.get(s),c=new Set;if(!a)return;let d=l=>(c.add(l),p.has(l)?p.get(l).lastValue:C.get(l)),h=a.selector(d);a.deps.forEach(l=>{if(!c.has(l)){let y=g.get(l);y&&(y.delete(s),y.size===0&&g.delete(l))}}),c.forEach(l=>{a.deps.has(l)||(g.has(l)||g.set(l,new Set),g.get(l).add(s))}),a.deps=c,ae(a.lastValue,h)||(a.lastValue=Y&&h!==null&&typeof h=="object"?j(ce(h),!0):h,n.set(s,(n.get(s)||0)+1),ee(s))},tt=async()=>{if(!A)return;try{let a={};t.forEach((h,l)=>{a[l]=h});let c,d=e?.encoded;d?c=btoa(JSON.stringify(a)):c=JSON.stringify(a),A.setItem(Z().replace("_",""),JSON.stringify({v:1,t:Date.now(),e:null,d:c,_sys_v:X,_b64:d?!0:void 0})),z("set","FULL_STATE",!0)}catch(a){let c=a instanceof Error?a:new Error(String(a));b?b(c,{operation:"persist",key:"FULL_STATE"}):w||console.error("[gState] Persist failed: ",c)}let s=Array.from(m.entries());m.clear();for(let[a,c]of s)try{let d=c.value,h=c.options.encoded||c.options.secure;if(c.options.encrypted){if(!ge)throw new Error(`Encryption key missing for "${a}"`);d=await Pt(c.value,ge)}else h?d=btoa(JSON.stringify(c.value)):typeof c.value=="object"&&c.value!==null&&(d=JSON.stringify(c.value));A.setItem(`${Z()}${a} `,JSON.stringify({v:n.get(a)||1,t:Date.now(),e:c.options.ttl?Date.now()+c.options.ttl:null,d,_sys_v:X,_enc:c.options.encrypted?!0:void 0,_b64:h?!0:void 0})),z("set",a,!0)}catch(d){let h=d instanceof Error?d:new Error(String(d));b?b(h,{operation:"persist",key:a}):w||console.error("[gState] Persist failed: ",h)}},L={},C={_setSilently:(s,a)=>{let c=r.get(s)||0,d=Y&&a!==null&&typeof a=="object"?j(ce(a),!0):a,h=Ne(d);T=T-c+h,r.set(s,h),t.set(s,d),n.set(s,(n.get(s)||0)+1)},_registerMethod:(s,a,c)=>{if(c!==void 0){let l=s,y=a;L[l]||(L[l]={}),L[l][y]=c;return}console.warn("[gState] _registerMethod(name, fn) is deprecated. Use _registerMethod(pluginName, methodName, fn) instead.");let d=s,h=a;L.core||(L.core={}),L.core[d]=h},set:(s,a,c={})=>{let d=t.get(s),h=Y&&typeof a=="function"?Et(d,a):a;if(Ze&&!Qe(s))return w||console.warn(`[gState] Invalid key: ${s}`),!1;if(!Te(_,s,"write",Q))return z("set",s,!1,"RBAC Denied"),w||console.error(`[gState] RBAC Denied for "${s}"`),!1;let l=Ze?se(h):h,y=r.get(s)||0;B("onBeforeSet",{key:s,value:l,store:C,version:n.get(s)||0});let E=Y&&l!==null&&typeof l=="object"?j(ce(l),!0):l;if(!ae(d,E)){let D=de>0||pe>0?Ne(E):0;if(de>0&&D>de){let K=new Error(`Object size (${D} bytes) exceeds maxObjectSize (${de} bytes)`);b?b(K,{operation:"set",key:s}):w||console.warn(`[gState] ${K.message} for "${s}"`)}if(pe>0){let K=T-y+D;if(K>pe){let rt=new Error(`Total store size (${K} bytes) exceeds limit (${pe} bytes)`);b?b(rt,{operation:"set"}):w||console.warn(`[gState] ${rt.message}`)}}T=T-y+D,r.set(s,D),t.set(s,E),n.set(s,(n.get(s)||0)+1);let I=c.persist??Tt;return I&&(m.set(s,{value:E,options:{...c,persist:I,encoded:c.encoded||e?.encoded}}),G&&clearTimeout(G),G=setTimeout(tt,fe)),B("onSet",{key:s,value:E,store:C,version:n.get(s)}),z("set",s,!0),ee(s),!0}return!1},get:s=>{if(!Te(_,s,"read",Q))return z("get",s,!1,"RBAC Denied"),null;let a=t.get(s);return B("onGet",{store:C,key:s,value:a}),z("get",s,!0),a},compute:(s,a)=>{try{return p.has(s)||(p.set(s,{selector:a,lastValue:null,deps:new Set}),et(s)),p.get(s).lastValue}catch(c){let d=c instanceof Error?c:new Error(String(c));return b?b(d,{operation:"compute",key:s}):w||console.error(`[gState] Compute error for "${s}": `,c),null}},watch:(s,a)=>{f.has(s)||f.set(s,new Set);let c=f.get(s);return c.add(a),()=>{c.delete(a),c.size===0&&f.delete(s)}},remove:s=>{if(!Te(_,s,"delete",Q))return z("delete",s,!1,"RBAC Denied"),!1;let a=t.get(s),c=t.delete(s);return c&&(T-=r.get(s)||0,r.delete(s),B("onRemove",{store:C,key:s,value:a})),n.set(s,(n.get(s)||0)+1),A&&A.removeItem(`${Z()}${s} `),z("delete",s,!0),ee(s),c},delete:s=>C.remove(s),deleteAll:()=>{if(Array.from(t.keys()).forEach(s=>C.remove(s)),A){let s=Z();for(let a=0;a<(A.length||0);a++){let c=A.key(a);c?.startsWith(s)&&(A.removeItem(c),a--)}}return T=0,r.clear(),!0},list:()=>Object.fromEntries(t.entries()),use:s=>{u.add(s)},transaction:s=>{ze=!0,B("onTransaction",{store:C,key:"START"});try{s()}finally{ze=!1,B("onTransaction",{store:C,key:"END"}),Ve&&(Ve=!1,ee())}},destroy:()=>{G&&(clearTimeout(G),G=null),m.clear(),typeof window<"u"&&window.removeEventListener("beforeunload",nt),B("onDestroy",{store:C}),o.clear(),i.clear(),f.clear(),p.clear(),g.clear(),S.clear(),t.clear(),r.clear(),T=0,_.clear(),k.clear(),n.clear(),v.clear(),u.clear()},_addPlugin:s=>{try{S.set(s.name,s),s.hooks?.onInstall?.({store:C})}catch(a){let c=a instanceof Error?a:new Error(String(a));b?b(c,{operation:"plugin:install",key:s.name}):w||console.error(`[gState] Failed to install plugin "${s.name}": `,a)}},_removePlugin:s=>{S.delete(s)},_subscribe:(s,a)=>{if(a){i.has(a)||i.set(a,new Set);let c=i.get(a);return c.add(s),()=>{c.delete(s),c.size===0&&i.delete(a)}}return o.add(s),()=>o.delete(s)},_getVersion:s=>n.get(s)??0,addAccessRule:(s,a)=>Xe(_,s,a),hasPermission:(s,a,c)=>{if(_.size===0)return!0;for(let[d,h]of _){let l;if(typeof d=="function")l=d(s,c);else try{let y=v.get(d);y||(y=new RegExp(d),v.set(d,y)),l=y.test(s)}catch{continue}if(l)return h.includes(a)||h.includes("admin")}return!1},recordConsent:(s,a,c)=>Ye(k,s,a,c),hasConsent:(s,a)=>Ct(k,s,a),getConsents:s=>At(k,s),revokeConsent:(s,a)=>Rt(k,s,a),exportUserData:s=>It(k,s),deleteUserData:s=>Mt(k,s),get plugins(){return L},get isReady(){return ye},get namespace(){return P},get userId(){return Q},whenReady:()=>zt};["addAccessRule","recordConsent","hasConsent","getConsents","revokeConsent","exportUserData","deleteUserData"].forEach(s=>{let a=C[s];a&&C._registerMethod("security",s,a)});let nt=()=>{m.size>0&&tt()};return typeof window<"u"&&window.addEventListener("beforeunload",nt),A?(async()=>{try{let a={},c=Z(),d=0;for(let l=0;l<(A.length||0);l++){let y=A.key(l);if(!y||!y.startsWith(c))continue;let E=A.getItem(y);if(E)try{let x=JSON.parse(E),D=y.substring(c.length);if(d=Math.max(d,x._sys_v!==void 0?x._sys_v:x.v||0),x.e&&Date.now()>x.e){A.removeItem(y),l--;continue}let I=x.d;if(x._enc&&ge)I=await vt(I,ge);else if(typeof I=="string"){if(x._b64)try{I=JSON.parse(atob(I))}catch{}else if(I.startsWith("{")||I.startsWith("["))try{I=JSON.parse(I)}catch{}}a[D]=I,z("hydrate",D,!0)}catch(x){z("hydrate",y,!1,String(x));let D=x instanceof Error?x:new Error(String(x));b?b(D,{operation:"hydration",key:y}):w||console.error(`[gState] Hydration failed for "${y}": `,x)}}let h=d<X&&e?.migrate?e.migrate(a,d):a;Object.entries(h).forEach(([l,y])=>{let E=Y&&y!==null&&typeof y=="object"?j(ce(y),!0):y,x=Ne(E),D=r.get(l)||0;T=T-D+x,r.set(l,x),t.set(l,E),n.set(l,1)}),ye=!0,he(),ee()}catch(a){ye=!0,he();let c=a instanceof Error?a:new Error(String(a));b?b(c,{operation:"hydration"}):w||console.error("[gState] Hydration failed: ",c)}})():(ye=!0,he()),C};import{useSyncExternalStore as Dt,useDebugValue as rn,useMemo as ue}from"react";var F=null,on=e=>{F&&!e?.namespace&&(e?.silent||console.warn("[gState] Store already exists. Pass a unique namespace to create additional stores."));let t=q(e);return F=t,t},sn=()=>{F&&(F.destroy(),F=null)},an=e=>{let t=e||F,n=ue(()=>r=>t?t._subscribe(r):()=>{},[t]);return Dt(n,()=>t?t.isReady:!1,()=>!0)},V=()=>F;var le=(e,t)=>{let n=ue(()=>t||F,[t]),r=ue(()=>{let p=()=>{},g=()=>!1,S=()=>null;return{set:g,get:S,remove:g,delete:g,deleteAll:g,list:()=>({}),compute:S,watch:()=>()=>{},use:p,transaction:p,destroy:p,_subscribe:()=>()=>{},_setSilently:p,_registerMethod:p,_addPlugin:p,_removePlugin:p,_getVersion:()=>0,get isReady(){return!1},whenReady:()=>Promise.resolve(),get plugins(){return{}}}},[]),o=n||r,i=ue(()=>p=>o._subscribe(p,e),[o,e]),u=Dt(i,()=>o.get(e)??void 0,()=>{}),f=ue(()=>(p,g)=>o.set(e,p,g),[o,e]);return rn(u,p=>`${e}: ${JSON.stringify(p)}`),[u,f]};var cn=(e,t)=>{let n=t?.key||"async_data",r=t?.store||q({namespace:`async_${n}`,silent:!0});return r.get(n)==null&&r.set(n,{data:null,loading:!1,error:null,updatedAt:null}),Object.assign(r,{execute:async()=>{let i=r.get(n);r.set(n,{...i||{data:null,loading:!1,error:null,updatedAt:null},loading:!0,error:null}),"whenReady"in r&&!r.isReady&&await r.whenReady();try{let u=await e(),f=r.get(n);r.set(n,{...f||{data:null,loading:!1,error:null,updatedAt:null},data:u,loading:!1,updatedAt:Date.now()},{persist:t?.persist})}catch(u){let f=r.get(n);r.set(n,{...f||{data:null,loading:!1,error:null,updatedAt:null},error:u instanceof Error?u:new Error(String(u)),loading:!1})}}})};var un=()=>({name:"gstate-immer",hooks:{onInstall:({store:e})=>{e._registerMethod("immer","setWithProduce",((t,n)=>e.set(t,n)))}}});var ln=e=>{let t=[],n=-1,r=!1,o=e?.limit||50;return{name:"gstate-undo-redo",hooks:{onInstall:({store:i})=>{t.push(i.list()),n=0,i._registerMethod("undoRedo","undo",()=>{if(n>0){r=!0,n--;let u=t[n];return u?(Object.entries(u).forEach(([f,p])=>{i._setSilently(f,p)}),r=!1,!0):!1}return!1}),i._registerMethod("undoRedo","redo",()=>{if(n<t.length-1){r=!0,n++;let u=t[n];return u?(Object.entries(u).forEach(([f,p])=>{i._setSilently(f,p)}),r=!1,!0):!1}return!1}),i._registerMethod("undoRedo","canUndo",()=>n>0),i._registerMethod("undoRedo","canRedo",()=>n<t.length-1)},onSet:({store:i})=>{r||(n<t.length-1&&(t=t.slice(0,n+1)),t.push(i.list()),t.length>o?t.shift():n++)}}}};var fn=e=>({name:"gstate-schema",hooks:{onSet:({key:t,value:n})=>{if(!t)return;let r=e[t];if(r){let o=r(n);if(o!==!0)throw new Error(`[Schema Error] Validation failed for key "${t}": ${o===!1?"Invalid type":o}`)}}}});var dn=e=>{let r=globalThis.__REDUX_DEVTOOLS_EXTENSION__;if(!r?.connect)return{name:"gstate-devtools-noop",hooks:{}};let o=null;return{name:"gstate-devtools",hooks:{onInstall:({store:i})=>{o=r.connect({name:e?.name||"Magnetar Store"}),o.init(i.list())},onSet:({key:i,store:u})=>{!i||!o||o.send(`SET_${i.toUpperCase()}`,u.list())},onRemove:({key:i,store:u})=>{!i||!o||o.send(`REMOVE_${i.toUpperCase()}`,u.list())}}}};var pn=()=>{let e=new Map;return{name:"gstate-snapshot",hooks:{onInstall:({store:t})=>{t._registerMethod("snapshot","takeSnapshot",(n=>{e.set(n,t.list())})),t._registerMethod("snapshot","restoreSnapshot",(n=>{let r=e.get(n);return r?(t.transaction(()=>{Object.entries(r).forEach(([o,i])=>{t.set(o,i)})}),!0):!1})),t._registerMethod("snapshot","listSnapshots",(()=>Array.from(e.keys()))),t._registerMethod("snapshot","deleteSnapshot",(n=>e.delete(n))),t._registerMethod("snapshot","clearSnapshots",(()=>e.clear()))}}}};var gn=e=>({name:"gstate-guard",hooks:{onBeforeSet:({key:t,value:n,store:r})=>{if(!t)return;let o=e[t];if(o){let i=o(n)}}}});var yn=e=>({name:"gstate-analytics",hooks:{onSet:({key:t,value:n})=>{t&&(!e.keys||e.keys.includes(t))&&e.provider({key:t,value:n,action:"SET"})},onRemove:({key:t})=>{t&&(!e.keys||e.keys.includes(t))&&e.provider({key:t,value:null,action:"REMOVE"})}}});var hn=e=>{let t=new BroadcastChannel(e?.channelName||"gstate_sync"),n=!1;return{name:"gstate-sync",hooks:{onInstall:({store:r})=>{t.onmessage=o=>{let{key:i,value:u,action:f}=o.data;i&&(n=!0,f==="REMOVE"?r.remove(i):r.set(i,u),n=!1)}},onSet:({key:r,value:o})=>{!r||n||t.postMessage({key:r,value:o,action:"SET"})},onRemove:({key:r})=>{!r||n||t.postMessage({key:r,action:"REMOVE"})},onDestroy:()=>{t.close()}}}};var Sn=()=>({name:"gstate-debug-noop",hooks:{}});var mn=(e={})=>{let t=e.dbName||"rgs-db",n=e.storeName||"states",r=e.version||1,o=null,i=()=>new Promise((g,S)=>{if(o)return g(o);let m=indexedDB.open(t,r);m.onerror=()=>S(m.error),m.onsuccess=()=>{o=m.result,g(o)},m.onupgradeneeded=v=>{let _=v.target.result;_.objectStoreNames.contains(n)||_.createObjectStore(n)}}),u=async(g,S)=>{let m=await i();return new Promise((v,_)=>{let w=m.transaction(n,"readwrite").objectStore(n).put(S,g);w.onsuccess=()=>v(),w.onerror=()=>_(w.error)})},f=async g=>{let S=await i();return new Promise((m,v)=>{let P=S.transaction(n,"readonly").objectStore(n).get(g);P.onsuccess=()=>m(P.result),P.onerror=()=>v(P.error)})},p=async g=>{let S=await i();return new Promise((m,v)=>{let P=S.transaction(n,"readwrite").objectStore(n).delete(g);P.onsuccess=()=>m(),P.onerror=()=>v(P.error)})};return{name:"indexedDB",hooks:{onInstall:({store:g})=>{g._registerMethod("indexedDB","clear",async()=>{(await i()).transaction(n,"readwrite").objectStore(n).clear()})},onInit:async({store:g})=>{let _=(await i()).transaction(n,"readonly").objectStore(n).getAllKeys();_.onsuccess=async()=>{let k=_.result,P=g.namespace+"_";for(let w of k)if(w.startsWith(P)){let fe=await f(w);if(fe){let X=w.substring(P.length);g._setSilently(X,fe.d)}}}},onSet:async({key:g,value:S,store:m})=>{if(!g)return;let v=m.namespace+"_",_={d:S,t:Date.now(),v:m._getVersion?.(g)||1};await u(`${v}${g}`,_)},onRemove:async({key:g,store:S})=>{if(!g)return;let m=S.namespace+"_";await p(`${m}${g}`)}}}};var _n=e=>{let{adapter:t,autoSyncInterval:n}=e,r=new Map,o={lastSyncTimestamp:null,totalKeysSynced:0,totalBytesSynced:0,syncCount:0,lastDuration:0,errors:0},i=null;return{name:"cloudSync",hooks:{onInstall:({store:u})=>{u._registerMethod("cloudSync","sync",async()=>{let f=performance.now(),p={},g=0;try{let S=u.list(),m=Object.keys(S);for(let _ of m){let k=u._getVersion?.(_)||0,P=r.get(_)||0;if(k>P){let w=S[_];p[_]=w,g+=JSON.stringify(w).length,r.set(_,k)}}if(Object.keys(p).length===0)return{status:"no-change",stats:o};if(await t.save(p))return o.lastSyncTimestamp=Date.now(),o.totalKeysSynced+=Object.keys(p).length,o.totalBytesSynced+=g,o.syncCount++,o.lastDuration=performance.now()-f,e.onSync&&e.onSync(o),{status:"success",stats:o};throw new Error(`Adapter ${t.name} failed to save.`)}catch(S){return o.errors++,console.error(`[gState] Cloud Sync Failed (${t.name}):`,S),{status:"error",error:String(S),stats:o}}}),u._registerMethod("cloudSync","getStats",()=>o),n&&n>0&&(i=setInterval(()=>{let p=u.plugins.cloudSync;p&&p.sync()},n))},onDestroy:()=>{i&&clearInterval(i)}}}},wn=(e,t)=>({name:"MongoDB-Atlas",save:async n=>(await fetch(`${e}/action/updateOne`,{method:"POST",headers:{"Content-Type":"application/json","api-key":t},body:JSON.stringify({dataSource:"Cluster0",database:"rgs_cloud",collection:"user_states",filter:{id:"global_state"},update:{$set:{data:n,updatedAt:Date.now()}},upsert:!0})})).ok}),bn=(e,t)=>({name:"Firebase-Firestore",save:async n=>{try{return console.log("[Mock] Firestore Syncing:",n),!0}catch{return!1}}}),En=(e,t)=>({name:"SQL-REST-API",save:async n=>(await fetch(e,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(n)})).ok});var Gn=e=>({name:"gstate-logger",hooks:{onSet:({key:t,value:n,version:r})=>{let o=new Date().toLocaleTimeString(),i=`[gState] SET: ${t} (v${r}) @ ${o}`;e?.collapsed?console.groupCollapsed(i):console.group(i),console.info("%c Value:","color: #4CAF50; font-weight: bold;",n),console.groupEnd()},onRemove:({key:t})=>{console.warn(`[gState] REMOVED: ${t}`)},onTransaction:({key:t})=>{t==="START"?console.group("\u2500\u2500 TRANSACTION START \u2500\u2500"):console.groupEnd()}}});var cr=(e,t)=>{let r=q(typeof t=="string"?{namespace:t}:t);e&&Object.entries(e).forEach(([i,u])=>{r.get(i)===null&&r._setSilently(i,u)});let o=i=>le(i,r);return typeof window<"u"&&(window.gState=r,window.rgs=r),Object.assign(o,r)};var ur=(e,t)=>V()?.addAccessRule(e,t),lr=(e,t,n)=>V()?.hasPermission(e,t,n)??!0,fr=(e,t,n)=>{let r=V();if(!r)throw new Error("[gState] recordConsent failed: No store found. call initState() first.");return r.recordConsent(e,t,n)},dr=(e,t)=>V()?.hasConsent(e,t)??!1,pr=e=>V()?.getConsents(e)??[],gr=(e,t)=>V()?.revokeConsent(e,t),yr=e=>{let t=V();if(!t)throw new Error("[gState] exportUserData failed: No store found.");return t.exportUserData(e)},hr=e=>{let t=V();if(!t)throw new Error("[gState] deleteUserData failed: No store found.");return t.deleteUserData(e)},Sr=()=>{},mr=()=>{};export{ur as addAccessRule,yn as analyticsPlugin,Sr as clearAccessRules,mr as clearAllConsents,_n as cloudSyncPlugin,cn as createAsyncStore,bn as createFirestoreAdapter,wn as createMongoAdapter,En as createSqlRestAdapter,q as createStore,Sn as debugPlugin,hr as deleteUserData,sn as destroyState,dn as devToolsPlugin,Yt as exportKey,yr as exportUserData,Qt as generateEncryptionKey,pr as getConsents,V as getStore,cr as gstate,gn as guardPlugin,dr as hasConsent,lr as hasPermission,un as immerPlugin,Zt as importKey,mn as indexedDBPlugin,on as initState,xt as isCryptoAvailable,ie as logAudit,Gn as loggerPlugin,fr as recordConsent,gr as revokeConsent,se as sanitizeValue,fn as schemaPlugin,en as setAuditLogger,pn as snapshotPlugin,hn as syncPlugin,ln as undoRedoPlugin,le as useGState,an as useIsStoreReady,le as useSimpleState,le as useStore,Qe as validateKey};
|
package/markdown/SUMMARY.md
CHANGED
|
@@ -41,6 +41,10 @@ This documentation is written for everyone: from **easy setup** for those who ju
|
|
|
41
41
|
- Upgrading to latest version (Enterprise Isolation)
|
|
42
42
|
- Upgrading to previous version (`secure` → `encoded`)
|
|
43
43
|
|
|
44
|
+
- **[Security Architecture & Hardening](chapters/09-security-architecture.md)**
|
|
45
|
+
- Advanced XSS prevention and deep cloning reliability.
|
|
46
|
+
- AES-256-GCM and RBAC.
|
|
47
|
+
|
|
44
48
|
---
|
|
45
49
|
|
|
46
50
|
## Reference
|
package/markdown/api.md
CHANGED
|
@@ -26,7 +26,10 @@ function initState<S extends Record<string, unknown>>(
|
|
|
26
26
|
const store = initState({
|
|
27
27
|
namespace: 'myApp',
|
|
28
28
|
version: 1,
|
|
29
|
-
|
|
29
|
+
persistByDefault: true,
|
|
30
|
+
onError: (error, context) => {
|
|
31
|
+
console.error(`Error in ${context.operation}:`, error.message)
|
|
32
|
+
}
|
|
30
33
|
})
|
|
31
34
|
```
|
|
32
35
|
|
|
@@ -63,6 +66,18 @@ function createStore<S extends Record<string, unknown>>(
|
|
|
63
66
|
|
|
64
67
|
---
|
|
65
68
|
|
|
69
|
+
### `getStore`
|
|
70
|
+
|
|
71
|
+
Retrieves the currently active default store instance. Useful for accessing the store outside of React components or in utility functions.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
function getStore(): IStore<Record<string, unknown>> | null
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Returns:** The active `IStore` or `null` if no store was initialized via `initState`.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
66
81
|
## Store Interface (`IStore`)
|
|
67
82
|
|
|
68
83
|
### State Operations
|
|
@@ -110,6 +125,26 @@ store.list(): Record<string, unknown>
|
|
|
110
125
|
|
|
111
126
|
---
|
|
112
127
|
|
|
128
|
+
### Metadata Properties
|
|
129
|
+
|
|
130
|
+
#### `namespace`
|
|
131
|
+
|
|
132
|
+
The unique namespace of the store (read-only).
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
store.namespace: string
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### `userId`
|
|
139
|
+
|
|
140
|
+
The current user ID associated with the store for RBAC and audit logs (read-only).
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
store.userId?: string
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
113
148
|
### Computed Values
|
|
114
149
|
|
|
115
150
|
#### `compute`
|
|
@@ -129,6 +164,8 @@ const fullName = store.compute('fullName', (get) => {
|
|
|
129
164
|
})
|
|
130
165
|
```
|
|
131
166
|
|
|
167
|
+
> **Note:** RGS supports **nested computed dependencies**. A computed value can reactively depend on other computed values in the same store.
|
|
168
|
+
|
|
132
169
|
---
|
|
133
170
|
|
|
134
171
|
### Watching Changes
|
|
@@ -218,6 +255,8 @@ Access plugin methods via `store.plugins`:
|
|
|
218
255
|
store.plugins.undoRedo.undo()
|
|
219
256
|
store.plugins.undoRedo.redo()
|
|
220
257
|
store.plugins.counter.increment()
|
|
258
|
+
store.plugins.cloudSync.sync()
|
|
259
|
+
store.plugins.cloudSync.getStats()
|
|
221
260
|
```
|
|
222
261
|
|
|
223
262
|
---
|
|
@@ -12,11 +12,18 @@ Let's create a User Profile module.
|
|
|
12
12
|
import { gstate } from '@biglogic/rgs';
|
|
13
13
|
|
|
14
14
|
// 1. Define the state and create everything in ONE shot
|
|
15
|
+
// Pass a string namespace to enable automatic persistence to localStorage
|
|
15
16
|
export const useUser = gstate({
|
|
16
17
|
name: 'Guest',
|
|
17
18
|
isLogged: false,
|
|
18
19
|
preferences: { theme: 'dark', lang: 'en' }
|
|
19
|
-
}, 'user_module'); //
|
|
20
|
+
}, 'user_module'); // Auto-persists to localStorage (excludes sensitive fields)
|
|
21
|
+
|
|
22
|
+
// Or use an object config for more control:
|
|
23
|
+
export const useUserNoPersist = gstate({
|
|
24
|
+
name: 'Guest',
|
|
25
|
+
isLogged: false
|
|
26
|
+
}, { namespace: 'user_module', autoPersist: false }); // No persistence
|
|
20
27
|
|
|
21
28
|
// 2. Use it anywhere
|
|
22
29
|
function ProfileHeader() {
|
|
@@ -30,8 +37,8 @@ function ProfileHeader() {
|
|
|
30
37
|
## 💎 Why Magnetar Rocks
|
|
31
38
|
|
|
32
39
|
1. **Inferred Types**: No need to define `<string>`. TypeScript looks at the initial value you passed to `gstate` and figures it out.
|
|
33
|
-
2. **Auto-
|
|
34
|
-
3. **
|
|
40
|
+
2. **Auto-Persistence**: When you pass a string namespace, RGS automatically persists to localStorage (excluding sensitive fields like tokens, passwords, secrets).
|
|
41
|
+
3. **Security**: Sensitive fields (containing 'token', 'password', 'secret', 'key') are automatically excluded from persistence.
|
|
35
42
|
|
|
36
43
|
```typescript
|
|
37
44
|
// You can access the store OUTSIDE components!
|
|
@@ -9,10 +9,33 @@ When you initialize RGS or a Magnetar, you can enable persistence. But it's not
|
|
|
9
9
|
```typescript
|
|
10
10
|
initState({
|
|
11
11
|
persist: true,
|
|
12
|
-
storage: 'local' // or 'session' or a custom adapter
|
|
12
|
+
storage: 'local' // or 'session', or a custom adapter
|
|
13
13
|
});
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
### Advanced Storage: Beyond 5MB
|
|
17
|
+
|
|
18
|
+
For applications that need to store massive amounts of data (Gigabytes), standard `localStorage` is not enough. RGS provides official plugins for advanced scenarios:
|
|
19
|
+
|
|
20
|
+
| Technology | Capacity | Purpose | Plugin |
|
|
21
|
+
| :--- | :--- | :--- | :--- |
|
|
22
|
+
| **LocalStorage** | ~5MB | Basic UI settings, small profiles. | Core (Native) |
|
|
23
|
+
| **IndexedDB** | GBs | Offline-first apps, large datasets, logs. | `indexedDBPlugin` |
|
|
24
|
+
| **Cloud Sync** | Unlimited | Remote backup, cross-device sync. | `cloudSyncPlugin` |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## ☁️ Hybrid Persistence: The "Cloud-Cloud" Strategy
|
|
29
|
+
|
|
30
|
+
RGS allows you to combine local power with cloud safety. You can store your active data in **IndexedDB** for speed and capacity, while automatically backing it up to a remote database (MongoDB, Firebase, SQL) using the **Cloud Sync Plugin**.
|
|
31
|
+
|
|
32
|
+
### Why use Cloud Sync?
|
|
33
|
+
- **Differential Updates**: Safely sends only what was changed since the last sync.
|
|
34
|
+
- **Scheduled or On-Demand**: Sync every 5 minutes automatically, or triggered by a "Save to Cloud" button.
|
|
35
|
+
- **Diagnostics**: Track how much data you are syncing and detect errors before they reach the user.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
16
39
|
### What happens under the hood?
|
|
17
40
|
|
|
18
41
|
```mermaid
|
|
@@ -72,13 +95,31 @@ If anyone tries to `set('price', -50)`, RGS will block the operation and warn yo
|
|
|
72
95
|
|
|
73
96
|
---
|
|
74
97
|
|
|
98
|
+
## ⚠️ Size Limits: maxObjectSize & maxTotalSize
|
|
99
|
+
|
|
100
|
+
Protect your app from memory issues with automatic size warnings:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const store = initState({
|
|
104
|
+
// Warn if single value exceeds 5MB (default: 5MB)
|
|
105
|
+
maxObjectSize: 5 * 1024 * 1024,
|
|
106
|
+
// Warn if total store exceeds 50MB (default: 50MB)
|
|
107
|
+
maxTotalSize: 50 * 1024 * 1024
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Setting a value that exceeds the limit will trigger a warning
|
|
111
|
+
store.set('largeData', bigObject); // Warns if > maxObjectSize
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
75
116
|
## 💡 Case Study: The Cart that Never Lost an Item
|
|
76
117
|
|
|
77
|
-
**Challenge**: User adds products, closes the browser, comes back after two days. The cart must still be there.
|
|
118
|
+
**Challenge**: User adds products, closes the browser, comes back after two days. The cart must still be there, and synced with their account on other devices.
|
|
78
119
|
**RGS Solution**:
|
|
79
120
|
|
|
80
|
-
1. Enable `
|
|
81
|
-
2. Use `
|
|
82
|
-
3. Result? 5-star UX.
|
|
121
|
+
1. Enable `indexedDBPlugin` for robust local storage (handles thousands of items).
|
|
122
|
+
2. Use `cloudSyncPlugin` to bridge the local state with your company's MongoDB Atlas or Firebase.
|
|
123
|
+
3. Result? 5-star UX with full data durability and cross-device sync.
|
|
83
124
|
|
|
84
125
|
**Next step:** [Ecosystem and Plugins: Extending the Power](05-plugins-and-extensibility.md)
|
|
@@ -4,12 +4,14 @@ RGS is not a closed box. It's a modular engine that you can extend to cover ever
|
|
|
4
4
|
|
|
5
5
|
## 🔌 Available Plugins
|
|
6
6
|
|
|
7
|
-
RGS includes
|
|
7
|
+
RGS includes 11 official plugins:
|
|
8
8
|
|
|
9
9
|
| Plugin | Purpose | Import |
|
|
10
10
|
|--------|---------|--------|
|
|
11
11
|
| `devToolsPlugin` | Redux DevTools integration | `rgs` |
|
|
12
12
|
| `debugPlugin` | Console debug access (DEV only) | `rgs` |
|
|
13
|
+
| `indexedDBPlugin` | GB-scale Local Storage | `rgs/advanced` |
|
|
14
|
+
| `cloudSyncPlugin` | Remote Cloud Backup/Sync | `rgs/advanced` |
|
|
13
15
|
| `syncPlugin` | Cross-tab synchronization | `rgs/advanced` |
|
|
14
16
|
| `immerPlugin` | Immer for mutable-style updates | `rgs` |
|
|
15
17
|
| `snapshotPlugin` | Save/restore state snapshots | `rgs` |
|
|
@@ -62,7 +64,21 @@ import { syncPlugin } from 'rgs/advanced';
|
|
|
62
64
|
store._addPlugin(syncPlugin({ channelName: 'my_app_sync' }));
|
|
63
65
|
```
|
|
64
66
|
|
|
65
|
-
##
|
|
67
|
+
## 🔐 3. Encode Option: Base64 Encoding
|
|
68
|
+
|
|
69
|
+
Use the `encoded` option for simple base64 encoding (not encryption, just obfuscation):
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
// Per-value encoding
|
|
73
|
+
store.set('token', 'secret-value', { persist: true, encoded: true })
|
|
74
|
+
|
|
75
|
+
// Or global encoding for all persisted values
|
|
76
|
+
const store = initState({ encoded: true })
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
> **Note:** Use `encryptionKey` with AES-256-GCM for real security. The `encoded` option is just simple obfuscation.
|
|
80
|
+
|
|
81
|
+
## 🕐 4. TTL (Time To Live): Expiring Data
|
|
66
82
|
|
|
67
83
|
Use the `ttl` option in persist to make data expire automatically:
|
|
68
84
|
|
|
@@ -73,7 +89,7 @@ store.set('session_token', tokenValue, {
|
|
|
73
89
|
});
|
|
74
90
|
```
|
|
75
91
|
|
|
76
|
-
## 🎲
|
|
92
|
+
## 🎲 5. Undo/Redo: History Management
|
|
77
93
|
|
|
78
94
|
```typescript
|
|
79
95
|
import { undoRedoPlugin } from '@biglogic/rgs';
|
|
@@ -87,7 +103,7 @@ store.canUndo(); // boolean
|
|
|
87
103
|
store.canRedo(); // boolean
|
|
88
104
|
```
|
|
89
105
|
|
|
90
|
-
## 📸
|
|
106
|
+
## 📸 6. Snapshots: Save & Restore State
|
|
91
107
|
|
|
92
108
|
```typescript
|
|
93
109
|
import { snapshotPlugin } from '@biglogic/rgs';
|
|
@@ -108,7 +124,7 @@ store.deleteSnapshot('backup_1');
|
|
|
108
124
|
store.clearSnapshots();
|
|
109
125
|
```
|
|
110
126
|
|
|
111
|
-
## 🛡️
|
|
127
|
+
## 🛡️ 7. Guard: Pre-Set Transformation
|
|
112
128
|
|
|
113
129
|
Transform values before they hit the store:
|
|
114
130
|
|
|
@@ -120,7 +136,7 @@ store._addPlugin(guardPlugin({
|
|
|
120
136
|
}));
|
|
121
137
|
```
|
|
122
138
|
|
|
123
|
-
## ✅
|
|
139
|
+
## ✅ 8. Schema: Validation
|
|
124
140
|
|
|
125
141
|
Validate values before setting:
|
|
126
142
|
|
|
@@ -135,7 +151,7 @@ store._addPlugin(schemaPlugin({
|
|
|
135
151
|
}));
|
|
136
152
|
```
|
|
137
153
|
|
|
138
|
-
## 📊
|
|
154
|
+
## 📊 9. Analytics: Track Changes
|
|
139
155
|
|
|
140
156
|
```typescript
|
|
141
157
|
import { analyticsPlugin } from '@biglogic/rgs';
|
|
@@ -149,7 +165,7 @@ store._addPlugin(analyticsPlugin({
|
|
|
149
165
|
}));
|
|
150
166
|
```
|
|
151
167
|
|
|
152
|
-
## 🔄
|
|
168
|
+
## 🔄 10. Immer Integration
|
|
153
169
|
|
|
154
170
|
```typescript
|
|
155
171
|
import { immerPlugin } from '@biglogic/rgs';
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
# 🛒 Chapter 6: Case Studies - Real Strategies
|
|
2
|
-
|
|
3
|
-
In this chapter, we put theory aside and see how RGS solves the problems that keep you up at night (or at least frustrated in the office).
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 🍎 Case 1: High-Performance E-commerce
|
|
8
|
-
|
|
9
|
-
**The Problem**: A shopping cart with 50 items, complex sidebar filters, and a product list that must update without "jumping" the whole page.
|
|
10
|
-
|
|
11
|
-
**The RGS Strategy**:
|
|
12
|
-
|
|
13
|
-
1. **Atomic Filters**: Don't save the entire filters object. Use separate keys (`category`, `priceRange`, `search`). This way, if the user only changes the price, the search bar doesn't re-render.
|
|
14
|
-
2. **Persistent Cart**: Use `gstate` with a `cart` namespace.
|
|
15
|
-
3. **Computed State for Totals**:
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
cartStore.compute('totalAmount', ['items'], (s) =>
|
|
19
|
-
s.items.reduce((acc, curr) => acc + curr.price, 0)
|
|
20
|
-
);
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
**Why do this?** Because the component displaying the total price updates *only* when the `items` array changes, not when the user's name or shipping address changes. **Zero waste.**
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## 📊 Case 2: Real-time Dashboard (Sockets/Events)
|
|
28
|
-
|
|
29
|
-
**The Problem**: You receive thousands of updates via WebSocket (e.g., crypto prices or server notifications), and React can't keep up.
|
|
30
|
-
|
|
31
|
-
**The RGS Strategy**:
|
|
32
|
-
|
|
33
|
-
1. **Atomic Transactions**: In RGS, you can group updates.
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
socket.on('bulk_update', (data) => {
|
|
37
|
-
store.transaction(() => {
|
|
38
|
-
data.forEach(item => store.set(`price_${item.id}`, item.price));
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
**Why do this?** Instead of triggering 100 React updates, the `transaction` triggers **only one** at the end. Your dashboard's performance will go from "tractor" to "Ferrari".
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## 🏦 Case 3: Multi-Step Forms (User Onboarding)
|
|
48
|
-
|
|
49
|
-
**The Problem**: A signup form with 5 steps. If the user hits "Back" or refreshes the page, they lose everything.
|
|
50
|
-
|
|
51
|
-
**The RGS Strategy**:
|
|
52
|
-
|
|
53
|
-
1. Use a dedicated `gstate` called `onboarding`.
|
|
54
|
-
2. Enable `persist: true`.
|
|
55
|
-
3. At each step, just call `set('step1', values)`.
|
|
56
|
-
**Why do this?** Because you don't have to manage manual saving logic. When the user returns, the fields are already populated. At the very end (Step 5), call `store.destroy()` to clean up. Clean and elegant.
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
## 🛡️ Message for Advanced Architects
|
|
61
|
-
|
|
62
|
-
*"But I could do all this with a custom cache and an event bus..."*
|
|
63
|
-
Sure you could. You could also walk to work instead of driving. But RGS is the car: it's tested, it handles edge cases (closed tabs, full storage, corrupted types), and it lets you focus on **business logic**, not infrastructure.
|
|
64
|
-
|
|
65
|
-
Stop reinventing the wheel. Use RGS.
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
**Next step:** [FAQ: For the Skeptics and the Curious](07-faq.md)
|
|
1
|
+
# 🛒 Chapter 6: Case Studies - Real Strategies
|
|
2
|
+
|
|
3
|
+
In this chapter, we put theory aside and see how RGS solves the problems that keep you up at night (or at least frustrated in the office).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🍎 Case 1: High-Performance E-commerce
|
|
8
|
+
|
|
9
|
+
**The Problem**: A shopping cart with 50 items, complex sidebar filters, and a product list that must update without "jumping" the whole page.
|
|
10
|
+
|
|
11
|
+
**The RGS Strategy**:
|
|
12
|
+
|
|
13
|
+
1. **Atomic Filters**: Don't save the entire filters object. Use separate keys (`category`, `priceRange`, `search`). This way, if the user only changes the price, the search bar doesn't re-render.
|
|
14
|
+
2. **Persistent Cart**: Use `gstate` with a `cart` namespace.
|
|
15
|
+
3. **Computed State for Totals**:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
cartStore.compute('totalAmount', ['items'], (s) =>
|
|
19
|
+
s.items.reduce((acc, curr) => acc + curr.price, 0)
|
|
20
|
+
);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Why do this?** Because the component displaying the total price updates *only* when the `items` array changes, not when the user's name or shipping address changes. **Zero waste.**
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 📊 Case 2: Real-time Dashboard (Sockets/Events)
|
|
28
|
+
|
|
29
|
+
**The Problem**: You receive thousands of updates via WebSocket (e.g., crypto prices or server notifications), and React can't keep up.
|
|
30
|
+
|
|
31
|
+
**The RGS Strategy**:
|
|
32
|
+
|
|
33
|
+
1. **Atomic Transactions**: In RGS, you can group updates.
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
socket.on('bulk_update', (data) => {
|
|
37
|
+
store.transaction(() => {
|
|
38
|
+
data.forEach(item => store.set(`price_${item.id}`, item.price));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Why do this?** Instead of triggering 100 React updates, the `transaction` triggers **only one** at the end. Your dashboard's performance will go from "tractor" to "Ferrari".
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 🏦 Case 3: Multi-Step Forms (User Onboarding)
|
|
48
|
+
|
|
49
|
+
**The Problem**: A signup form with 5 steps. If the user hits "Back" or refreshes the page, they lose everything.
|
|
50
|
+
|
|
51
|
+
**The RGS Strategy**:
|
|
52
|
+
|
|
53
|
+
1. Use a dedicated `gstate` called `onboarding`.
|
|
54
|
+
2. Enable `persist: true`.
|
|
55
|
+
3. At each step, just call `set('step1', values)`.
|
|
56
|
+
**Why do this?** Because you don't have to manage manual saving logic. When the user returns, the fields are already populated. At the very end (Step 5), call `store.destroy()` to clean up. Clean and elegant.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🛡️ Message for Advanced Architects
|
|
61
|
+
|
|
62
|
+
*"But I could do all this with a custom cache and an event bus..."*
|
|
63
|
+
Sure you could. You could also walk to work instead of driving. But RGS is the car: it's tested, it handles edge cases (closed tabs, full storage, corrupted types), and it lets you focus on **business logic**, not infrastructure.
|
|
64
|
+
|
|
65
|
+
Stop reinventing the wheel. Use RGS.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
**Next step:** [FAQ: For the Skeptics and the Curious](07-faq.md)
|