tempest.games 0.2.24 → 0.2.25
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/CHANGELOG.md +7 -0
- package/app/assets/{index-DQgRZz7y.js → index-CfnJ3uCQ.js} +1 -1
- package/app/index.html +1 -1
- package/bin/backend.bun.js +1 -1
- package/bin/backend.worker.game.bun.js +1 -1
- package/bin/backend.worker.tribunal.bun.js +1 -1
- package/bin/frontend.bun.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,7 @@ function Rk(t,e){for(var n=0;n<e.length;n++){const r=e[n];if(typeof r!="string"&
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Z0;function _k(){if(Z0)return Pa;Z0=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(r,o,c){var u=null;if(c!==void 0&&(u=""+c),o.key!==void 0&&(u=""+o.key),"key"in o){c={};for(var d in o)d!=="key"&&(c[d]=o[d])}else c=o;return o=c.ref,{$$typeof:t,type:r,key:u,ref:o!==void 0?o:null,props:c}}return Pa.Fragment=e,Pa.jsx=n,Pa.jsxs=n,Pa}var Q0;function kk(){return Q0||(Q0=1,Bh.exports=_k()),Bh.exports}var J=kk();function Mk(t){return Object.entries(t)}const Ck=(t,e,n=gt.STORE)=>l1(n,{key:`${t.key}:JSON`,get:({get:r})=>e.toJson(r(t)),set:({set:r},o)=>{r(t,e.fromJson(o))}});function Dk(t,e,n){return qm(t,{key:`${e.key}:JSON`,get:o=>({get:c})=>{const u=c(e,o);return n.toJson(u)},set:o=>({set:c},u)=>{c(e,o,n.fromJson(u))}},["mutable","json"])}const Mr=t=>JSON.parse(t),Ze=t=>JSON.stringify(t);function it(t){return EM(gt.STORE,t)}function et(...t){return t.length===2?zn(gt.STORE,...t):zn(gt.STORE,...t)}function Nk(t,e,n=gt.STORE){return n.joins.set(t.key,new A1(t,e,n)),{key:t.key,type:"join",a:t.between[0],b:t.between[1],cardinality:t.cardinality}}function $k(t){return OM(t,gt.STORE)}const Lh=t=>(e,n,r,o,...c)=>{console[t](`${e} ${n} "${r}" ${o}`,...c)},jk={error:Lh("error"),info:Lh("info"),warn:Lh("warn")};var Bk=class{logLevel;filter;logger;constructor(t,e,n=jk){this.logLevel=t,this.filter=e,this.logger=n}error=(...t)=>{const e=this.filter?.(...t)??!0;this.logLevel!==null&&(e===!0?this.logger.error(...t):e!==!1&&this.logger.error(...e))};info=(...t)=>{const e=this.filter?.(...t)??!0;this.logLevel==="info"&&(e===!0?this.logger.info(...t):e!==!1&&this.logger.info(...e))};warn=(...t)=>{const e=this.filter?.(...t)??!0;this.logLevel!=="error"&&this.logLevel!==null&&(e===!0?this.logger.warn(...t):e!==!1&&this.logger.warn(...e))}},Lk=class{store;constructor(t=gt.STORE){this.store=t,aM("root",t)}allocate(t,e,n){return pl(this.store,t,e,n)}fuse(t,e,n){return lM(this.store,t,e,n)}deallocate(t){ml(this.store,t)}claim(t,e,n){return Au(this.store,t,e,n)}},Vk=class{store;realm;constructor(t=gt.STORE){this.store=t,this.realm=new Lk(t)}allocate(t,e,n){pl(this.store,t,e,n)}deallocate(t){ml(this.store,t)}claim(t,e,n){Au(this.store,t,e,n)}};function pi(t){return l1(gt.STORE,t)}function Uk(t){return nM(gt.STORE,t)}function De(...t){t.length===2?Et(gt.STORE,...t):Et(gt.STORE,...t)}function zk(t,e,n=Ju()){return xM(gt.STORE,t,e,n)}function Kk(t){return b1(gt.STORE,t)}function Pk(t,e=Ju()){return jm(gt.STORE,t,e)}var Ao=class au extends Set{mode="record";subject=new tt;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(e,n=0){super(e),e instanceof au&&(this.parent=e,this.cacheUpdateNumber=e.cacheUpdateNumber),n&&(this.cacheLimit=n,this.cache=new Array(n),this.subscribe("auto cache",r=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=r}))}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(e){const n=new au(e.members,e.cacheLimit);return n.cache=e.cache,n.cacheIdx=e.cacheIdx,n.cacheUpdateNumber=e.cacheUpdateNumber,n}add(e){const n=super.add(e);return this.mode==="record"&&(this.cacheUpdateNumber++,this.emit(`add:${Ze(e)}`)),n}clear(){const e=this.mode==="record"?[...this]:null;super.clear(),e&&(this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(e)}`))}delete(e){const n=super.delete(e);return this.mode==="record"&&(this.cacheUpdateNumber++,this.emit(`del:${Ze(e)}`)),n}parent=null;child=null;transactionUpdates=null;transaction(e){this.mode="transaction",this.transactionUpdates=[],this.child=new au(this);const n=this.child._subscribe("transaction",r=>{this.transactionUpdates?.push(r)});try{if(e(this.child)){for(const o of this.transactionUpdates)this.doStep(o);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(r){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",r),r}finally{n(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(e,n){return this.subject.subscribe(e,n)}subscribe(e,n){return this.subject.subscribe(e,r=>{n(`${this.cacheUpdateNumber}=${r}`)})}emit(e){this.subject.next(e)}doStep(e){const n=e.indexOf(":"),r=e.substring(0,n),o=e.substring(n+1);switch(r){case"add":this.add(JSON.parse(o));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(o));break;case"tx":for(const c of o.split(";"))this.doStep(c)}}getUpdateNumber(e){const n=e.indexOf("=");return Number(e.substring(0,n))}do(e){const n=e.indexOf("="),r=Number(e.substring(0,n)),o=r-this.cacheUpdateNumber;if(o>0){if(o===1){this.mode="playback";const u=e.substring(n+1);return this.doStep(u),this.mode="record",this.cacheUpdateNumber=r,null}return this.cacheUpdateNumber+1}if(Math.abs(o)<this.cacheLimit){const u=this.cacheIdx+o;if(this.cache[u]===e)return null;this.mode="playback";let h=!1;for(;!h;){this.cacheIdx%=this.cacheLimit;const y=this.cache[this.cacheIdx];if(this.cacheIdx--,!y)return"OUT_OF_RANGE";this.undo(y),h=this.cacheIdx===u-1}const p=e.substring(n+1);return this.doStep(p),this.mode="record",this.cacheUpdateNumber=r,null}return"OUT_OF_RANGE"}undoStep(e){const n=e.indexOf(":"),r=e.substring(0,n),o=e.substring(n+1);switch(r){case"add":this.delete(JSON.parse(o));break;case"del":this.add(JSON.parse(o));break;case"clear":{const c=JSON.parse(o);for(const u of c)this.add(u);break}case"tx":{const c=o.split(";");for(let u=c.length-1;u>=0;u--)this.undoStep(c[u])}}}undo(e){const n=e.indexOf("=");if(Number(e.substring(0,n))===this.cacheUpdateNumber){this.mode="playback";const o=e.substring(n+1);return this.undoStep(o),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function Ju(t=Math.random){return t().toString(36).slice(2)}var Rp=class extends Promise{fate;resolve;reject;done=!1;constructor(t){let e,n;super((r,o)=>{e=r,n=o}),this.resolve=e,this.reject=n,this.use(t instanceof Promise?t:new Promise(t))}pass(t,e){t===this.fate&&(this.resolve(e),this.done=!0)}fail(t,e){t===this.fate&&(this.reject(e),this.done=!0)}use(t){if(t instanceof Promise){const e=t;this.fate=e,e.then(n=>{this.pass(e,n)},n=>{this.fail(e,n)})}else this.resolve(t),this.fate=void 0}};function ve(t){for(;t.child!==null;)t=t.child;return t}var qk=class i1{_buffer;_index=0;constructor(e){let n;typeof e=="number"?n=e:n=e.length,this._buffer=Array.from({length:n})}get buffer(){return this._buffer}get index(){return this._index}add(e){this._buffer[this._index]=e,this._index=(this._index+1)%this._buffer.length}copy(){const e=new i1([...this._buffer]);return e._index=this._index,e}};const Ik={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function Hk(t,e){const n=Ze(e),r=`${t.key}(${n})`,o=Ik[t.type],c={key:r,type:o};return Object.assign(c,{family:{key:t.key,subKey:n}}),Object.assign(c,{counterfeit:!0}),c}function Eo(t){const e={key:t.key,type:t.type};return"family"in t&&(e.family=t.family),e}var Qt=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(t,e)=>`${t}:${e}`;warn;getRelatedKeys(t){return this.relations.get(t)}addRelation(t,e){let n=this.relations.get(t),r=this.relations.get(e);n?n.add(e):(n=new Set([e]),this.relations.set(t,n)),r?r.add(t):(r=new Set([t]),this.relations.set(e,r))}deleteRelation(t,e){const n=this.relations.get(t);if(n){n.delete(e),n.size===0&&this.relations.delete(t);const r=this.relations.get(e);r&&(r.delete(t),r.size===0&&this.relations.delete(e))}}replaceRelationsUnsafely(t,e){this.relations.set(t,new Set(e));for(const n of e){const r=new Set().add(t);this.relations.set(n,r)}}replaceRelationsSafely(t,e){const n=this.relations.get(t);let r=this.isAType?.(t)?t:void 0,o=r===void 0?t:void 0;if(n)for(const c of n){r??=c,o??=c;const u=this.relations.get(c);u&&(u.size===1?this.relations.delete(c):u.delete(t),this.contents.delete(this.makeContentKey(r,o)))}this.relations.set(t,new Set(e));for(const c of e){let u=this.relations.get(c);u?u.add(t):(u=new Set().add(t),this.relations.set(c,u))}}getContentInternal(t){return this.contents.get(t)}setContent(t,e){this.contents.set(t,e)}deleteContent(t){this.contents.delete(t)}constructor(t,e){if(this.a=t.between[0],this.b=t.between[1],this.cardinality=t.cardinality,e?.externalStore||(this.relations=new Map(t.relations?.map(([n,r])=>[n,new Set(r)])),this.contents=new Map(t.contents)),this.isAType=e?.isAType??null,this.isBType=e?.isBType??null,this.isContent=e?.isContent??null,e?.makeContentKey&&(this.makeContentKey=e.makeContentKey),e?.externalStore){const n=e.externalStore;this.has=(r,o)=>n.has(r,o),this.addRelation=(r,o)=>{n.addRelation(r,o)},this.deleteRelation=(r,o)=>{n.deleteRelation(r,o)},this.replaceRelationsSafely=(r,o)=>{n.replaceRelationsSafely(r,o)},this.replaceRelationsUnsafely=(r,o)=>{n.replaceRelationsUnsafely(r,o)},this.getRelatedKeys=r=>n.getRelatedKeys(r),n.getContent&&(this.getContentInternal=r=>n.getContent(r),this.setContent=(r,o)=>{n.setContent(r,o)},this.deleteContent=r=>{n.deleteContent(r)});for(const[r,o]of t.relations??[]){let c=this.isAType?.(r)?r:void 0,u=c===void 0?r:void 0;for(const d of o)c??=d,u??=d,this.addRelation(c,u)}for(const[r,o]of t.contents??[])this.setContent(r,o)}e?.warn&&(this.warn=e.warn)}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([t,e])=>[t,[...e]]),contents:[...this.contents.entries()]}}set(...t){let e,n,r;switch(t.length){case 1:{const o=t[0];e=o[this.a],n=o[this.b],r=void 0;break}case 2:{const o=t[0];typeof o=="string"?[e,n]=t:(e=o[this.a],n=o[this.b],r=t[1]);break}default:{e=t[0],n=t[1],r=t[2];break}}switch(this.cardinality){case"1:1":{const o=this.getRelatedKey(e);o&&o!==n&&this.delete(e,o)}case"1:n":{const o=this.getRelatedKey(n);o&&o!==e&&this.delete(o,n)}break}if(r){const o=this.makeContentKey(e,n);this.setContent(o,r)}return this.addRelation(e,n),this}delete(t,e){e=typeof e=="string"?e:t[this.b];const n=typeof t=="string"?t:t[this.a];if(n===void 0&&typeof e=="string"){const r=this.getRelatedKeys(e);if(r)for(const o of r)this.delete(o,e)}if(typeof n=="string"&&e===void 0){const r=this.getRelatedKeys(n);if(r)for(const o of r)this.delete(n,o)}if(typeof n=="string"&&typeof e=="string"){this.deleteRelation(n,e);const r=this.makeContentKey(n,e);this.deleteContent(r)}return this}getRelatedKey(t){const e=this.getRelatedKeys(t);if(e){e.size>1&&this.warn?.(`${e.size} related keys were found for key "${t}": (${[...e].map(r=>`"${r}"`).join(", ")}). Only one related key was expected.`);let n;for(const r of e){n=r;break}return n}}replaceRelations(t,e,n){const r=!Array.isArray(e),o=r?Object.keys(e):e;if(n?.reckless?this.replaceRelationsUnsafely(t,o):this.replaceRelationsSafely(t,o),r)for(const c of o){const u=this.makeContentKey(t,c),d=e[c];this.setContent(u,d)}return this}getContent(t,e){const n=this.makeContentKey(t,e);return this.getContentInternal(n)}getRelationEntries(t){const e=t[this.a],n=t[this.b];if(e!==void 0&&n===void 0){const r=this.getRelatedKeys(e);if(r)return[...r].map(o=>[o,this.getContent(e,o)])}if(e===void 0&&n!==void 0){const r=this.getRelatedKeys(n);if(r)return[...r].map(o=>[o,this.getContent(o,n)])}return[]}has(t,e){return e?this.getRelatedKeys(t)?.has(e)??!1:this.relations.has(t)}},tt=class{Subscriber;subscribers=new Map;subscribe(t,e){return this.subscribers.set(t,e),()=>{this.unsubscribe(t)}}unsubscribe(t){this.subscribers.delete(t)}next(t){const e=this.subscribers.values();for(const n of e)n(t)}},Fk=class extends tt{state;constructor(t){super(),this.state=t}next(t){this.state=t,super.next(t)}};function mi(t){return"epoch"in t.transactionMeta}function Jt(t){return"phase"in t.transactionMeta}const Gk=t=>{const e=ve(t);if(!Jt(e)){t.logger.warn("🐞","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}t.logger.info("🪂","transaction",e.transactionMeta.update.key,"Aborting transaction"),e.parent.child=null};function ln(t){return t[0].toUpperCase()+t.slice(1)}function hs(t){return t.type.split("_").map(ln).join(" ")}var $m=class extends Error{constructor(t,e){super(`${hs(t)} ${Ze(t.key)} not found in store "${e.config.name}".`)}};function jm(t,e,n){return(...r)=>{const o=yt(t,e);if(o)return o.run(r,n);throw new $m(e,t)}}const Bm=t=>e=>t instanceof Function?t(e):t,Xu=(t,e)=>{if(t.valueMap.has(e.key))return t.logger.info("📖",e.type,e.key,"reading cached value"),AM(e,t);switch(e.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return t.logger.info("🧮",e.type,e.key,"computing value"),e.get();case"atom":case"mutable_atom":{const n=e.default;let r;return n instanceof Function?r=n():r=n,t.logger.info("💁","atom",e.key,"could not find cached value; using default",r),r}}},wu=(t,e)=>{if(t.operation.open){const n=performance.now();return t.logger.info("❗",e.type,e.key,`deferring setState at T-${n} until setState for "${t.operation.token.key}" is done`),n}t.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:e},t.logger.info("⭕",e.type,e.key,`operation start in store "${t.config.name}"${Jt(t)?` ${t.transactionMeta.phase} "${t.transactionMeta.update.key}"`:""}`)},Tu=t=>{t.operation.open&&t.logger.info("🔴",t.operation.token.type,t.operation.token.key,`operation done in store "${t.config.name}"`),t.operation={open:!1},t.on.operationClose.next(t.operation)},r1=(t,e)=>t.operation.open?t.operation.done.has(e):(t.logger.error("🐞","unknown",e,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0),hl=(t,e)=>{if(!t.operation.open){t.logger.error("🐞","unknown",e,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}t.operation.done.add(e)},Yk=(t,e,n)=>{switch(e.type){case"mutable_atom":t.logger.info("📢",e.type,e.key,"is now (",n.newValue,") subscribers:",e.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":t.logger.info("📢",e.type,e.key,"went (",n.oldValue,"->",n.newValue,") subscribers:",e.subject.subscribers)}e.subject.next(n)};function Op(t,e){const n=ve(t),r=n.selectorAtoms.getRelatedKeys(e.key);if(n.logger.info("🧹",e.type,e.key,r?`evicting ${r.size} states downstream:`:"no downstream states",r??"to evict"),r){n.operation.open&&n.logger.info("🧹",e.type,e.key,`[ ${[...n.operation.done].join(", ")} ] already done`);for(const o of r)r1(n,o)||(T1(o,n),hl(n,o))}}function Jk(t,e){const n=ve(t),r=n.selectorGraph.getRelationEntries({upstreamSelectorKey:e.key}).filter(([o,{source:c}])=>c===e.key);for(const[o]of r)r1(n,o)||(T1(o,n),hl(n,o))}const s1=(t,e,n)=>{const r=Xu(t,e);let o=r;if(e.type==="mutable_atom"&&Jt(t)){const{parent:u}=t;o=kp(t,e,u)}o=Bm(n)(o),t.logger.info("📝","atom",e.key,"set to",o),o=fi(t,e.key,o,e.subject),hl(t,e.key),Op(t,e);const c={oldValue:r,newValue:o};if(!Jt(t)){Yk(t,e,c);return}if(t.on.transactionApplying.state===null){const{key:u}=e;if(TM(c.newValue))return;const d={type:"atom_update",key:u,...c};e.family&&(d.family=e.family),t.transactionMeta.update.updates.push(d),t.logger.info("📁","atom",u,"stowed (",c.oldValue,"->",c.newValue,")")}else if(e.key.startsWith("*")){const u=e.key.slice(1),d=t.atoms.get(u);let h=t.valueMap.get(u);if(d.type==="mutable_atom"&&Jt(t)){const{parent:y}=t;h=kp(t,d,y)}h.do(c.newValue)===null&&Op(t,d)}};function W0(t,e){let n=e.default;n instanceof Function&&(n=n()),s1(t,e,n)}function Xk(t,e){switch(e.type){case"atom":case"mutable_atom":W0(t,e);break;case"writable_pure_selector":case"writable_held_selector":{const n=a1(e,t);for(const r of n)W0(t,r)}break}}function Lm(t,e,n){const r={key:e.key,type:"atom_family"},o=t.families.get(e.key);o&&t.logger.error("❗","atom_family",e.key,`Overwriting an existing ${hs(o)} "${o.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const c=new tt,d=Object.assign(h=>{const p=Ze(h),y={key:e.key,subKey:p},g=`${e.key}(${p})`,v=ve(t),S=e.default,T={key:g,default:S instanceof Function?S(h):S};e.effects&&(T.effects=e.effects(h));const w=Wu(v,T,y);return c.next({type:"state_creation",token:w}),w},r,{subject:c,install:h=>Lm(h,e),internalRoles:n});return t.families.set(e.key,d),t.defaults.set(e.key,e.default),r}const Vm=(t,e)=>ve(t).atoms.has(e),Zk=(t,e)=>ve(t).writableSelectors.has(e),Qk=(t,e)=>ve(t).readonlySelectors.has(e),Wk=(t,e)=>Vm(t,e)||Zk(t,e)||Qk(t,e),_p=(t,e)=>ve(t).selectorGraph.getRelationEntries({downstreamSelectorKey:e}).filter(([r,{source:o}])=>o!==e).map(([r,{source:o}])=>o).filter(r=>Wk(t,r)),o1=(t,e,n)=>{const r=[],o=_p(t,e);for(;o.length>0;){const c=o.shift();n.has(c)||(n.add(c),Vm(t,c)?r.includes(c)||r.push(c):o.push(..._p(t,c)))}return r},a1=(t,e)=>{const n=t.key,r=_p(e,n),o=new Set;return r.flatMap(c=>Vm(e,c)?c:o1(e,c,o)).map(c=>e.atoms.get(c))},eM=(t,e,n,r,o)=>{const c=ve(t),{type:u,key:d}=r;if(u==="atom"||u==="mutable_atom")c.selectorAtoms.set({selectorKey:n,atomKey:d}),t.logger.info("🔍",e,n,`discovers root atom "${d}"`);else{const h=o1(t,d,o);t.logger.info("🔍",e,n,`discovers root atoms: [ ${h.map(p=>`"${p}"`).join(", ")} ]`);for(const p of h)c.selectorAtoms=c.selectorAtoms.set({selectorKey:n,atomKey:p})}o.add(d)},Zu=(t,e,n,r)=>({get:(...o)=>{const c=ve(t);let u;if(o.length===2){const[y,g]=o;u=zt(t,y,g)}else[u]=o;const d=yt(t,u),h=Xu(t,d),p=u.key;return t.logger.info("🔌",e,n,`registers dependency ( "${p}" =`,h,")"),c.selectorGraph.set({upstreamSelectorKey:p,downstreamSelectorKey:n},{source:u.key}),eM(t,e,n,u,r),h},set:(...o)=>{let c,u;if(o.length===2)c=o[0],u=o[1];else{const p=o[0],y=o[1];u=o[2],c=zt(t,p,y)}const d=ve(t),h=yt(d,c);h1(d,h,u)},find:(...o)=>zt(t,...o),json:o=>ps(t,o)}),Um=(t,e,n)=>{const r=ve(t),o=new tt,c=new Set,{key:u,const:d}=e,h="readonly_held_selector",{get:p,find:y,json:g}=Zu(r,h,u,c),S={...e,type:h,subject:o,install:w=>Um(w,e,n),get:()=>(e.get({get:p,find:y,json:g},d),fi(ve(t),u,d,o),c.clear(),d),...n&&{family:n}};r.readonlySelectors.set(u,S),t.logger.info("✨",h,u,"=",d);const T={key:u,type:h};return n&&(T.family=n),T},zm=(t,e,n)=>{const r=ve(t),o=new tt,c=new Set,u=e.key,d="readonly_pure_selector",{get:h,find:p,json:y}=Zu(r,d,u,c),g=()=>{const w=e.get({get:h,find:p,json:y});return fi(ve(t),u,w,o),c.clear(),w},v={...e,type:d,subject:o,install:w=>zm(w,e,n),get:g,...n&&{family:n}};r.readonlySelectors.set(u,v);const S=g();t.logger.info("✨",d,u,"=",S);const T={key:u,type:d};return n&&(T.family=n),T},Km=(t,e,n)=>{const r=ve(t),o=new tt,c=new Set,{key:u,const:d}=e,h="writable_held_selector",p=Zu(r,h,u,c),{find:y,get:g,json:v}=p,S={find:y,get:g,json:v},T=(k=e.get,C=ve(t))=>(k(S,d),fi(C,u,d,o),c.clear(),d),D={...e,type:h,subject:o,install:k=>Km(k,e,n),get:T,set:k=>{const C=ve(t),O=T(e.get,C),X=Bm(k)(O);t.logger.info("📝",h,u,"set (",O,"->",X,")"),fi(C,u,X,o),hl(C,u),mi(C)&&o.next({newValue:X,oldValue:O}),e.set(p,X)},...n&&{family:n}};r.writableSelectors.set(u,D);const $=T();t.logger.info("✨",h,u,"=",$);const _={key:u,type:h};return n&&(_.family=n),_},Pm=(t,e,n)=>{const r=ve(t),o=new tt,c=new Set,u=e.key,d="writable_pure_selector",h=Zu(r,d,u,c),{find:p,get:y,json:g}=h,v={find:p,get:y,json:g},S=(_=e.get,k=ve(t))=>{const C=_(v);return fi(k,u,C,o),c.clear(),C},w={...e,type:d,subject:o,install:_=>Pm(_,e,n),get:S,set:_=>{const k=ve(t),C=S(e.get,k),O=Bm(_)(C);t.logger.info("📝",d,u,"set (",C,"->",O,")"),fi(k,e.key,O,o),hl(k,e.key),mi(k)&&o.next({newValue:O,oldValue:C}),e.set(h,O)},...n&&{family:n}};r.writableSelectors.set(u,w);const D=S();t.logger.info("✨",w.type,w.key,"=",D);const $={key:u,type:d};return n&&($.family=n),$};function l1(t,e){const n="set"in e,r="const"in e;if(r&&n){const c=Km(t,e,void 0);return t.on.selectorCreation.next(c),c}if(r){const c=Um(t,e,void 0);return t.on.selectorCreation.next(c),c}if(n){const c=Pm(t,e,void 0);return t.on.selectorCreation.next(c),c}const o=zm(t,e,void 0);return t.on.selectorCreation.next(o),o}function tM(t,e){const n=ve(t),{key:r,type:o}=e,c=yt(n,e);if(!c.family)t.logger.error("❌",o,r,"Standalone selectors cannot be disposed.");else{n.molecules.get(c.family.subKey)&&n.moleculeData.delete(c.family.subKey,c.family.key);let d;switch(e.type){case"writable_held_selector":n.writableSelectors.delete(r),d={key:c.family.key,type:"writable_held_selector_family"},yt(t,d).subject.next({type:"state_disposal",subType:"selector",token:e});break;case"writable_pure_selector":n.writableSelectors.delete(r),d={key:c.family.key,type:"writable_pure_selector_family"},yt(t,d).subject.next({type:"state_disposal",subType:"selector",token:e});break;case"readonly_held_selector":n.readonlySelectors.delete(r),d={key:c.family.key,type:"readonly_held_selector_family"},yt(t,d).subject.next({type:"state_disposal",subType:"selector",token:e});break;case"readonly_pure_selector":n.readonlySelectors.delete(r),d={key:c.family.key,type:"readonly_pure_selector_family"},yt(t,d).subject.next({type:"state_disposal",subType:"selector",token:e});break}n.valueMap.delete(r),n.selectorAtoms.delete(r),n.selectorGraph.delete(r),t.logger.info("🔥",e.type,r,"deleted"),Jt(n)&&n.transactionMeta.phase==="building"?n.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:e}):t.on.selectorDisposal.next(e)}}function lo(t,e,n){const r=e.key,o="readonly_pure_selector_family",c={key:r,type:o},u=t.families.get(r);u&&t.logger.error("❗",o,r,`Overwriting an existing ${hs(u)} "${u.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const d=new tt,p=Object.assign(y=>{const g=Ze(y),v={key:r,subKey:g},S=`${r}(${g})`,T=ve(t),w=zm(T,{key:S,get:e.get(y)},v);return d.next({type:"state_creation",token:w}),w},c,{internalRoles:n,subject:d,install:y=>lo(y,e),default:y=>e.get(y)({get:(...v)=>zn(t,...v),find:(...v)=>zt(t,...v),json:v=>ps(t,v)})});return t.families.set(r,p),c}function c1(t,e,n){const r=e.key,o="readonly_held_selector_family",c={key:r,type:o},u=t.families.get(r);u&&t.logger.error("❗",o,r,`Overwriting an existing ${hs(u)} "${u.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const d=new tt,p=Object.assign(y=>{const g=Ze(y),v={key:r,subKey:g},S=`${r}(${g})`,T=ve(t),w=Um(T,{key:S,const:e.const(y),get:e.get(y)},v);return d.next({type:"state_creation",token:w}),w},c,{internalRoles:n,subject:d,install:y=>c1(y,e),default:e.const});return t.families.set(r,p),c}function u1(t,e,n){const r=e.key,o="writable_held_selector_family",c={key:r,type:o},u=t.families.get(r);u&&t.logger.error("❗",o,r,`Overwriting an existing ${hs(u)} "${u.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const d=new tt,p=Object.assign(y=>{const g=Ze(y),v={key:r,subKey:g},S=`${r}(${g})`,T=ve(t),w=Km(T,{key:S,const:e.const(y),get:e.get(y),set:e.set(y)},v);return d.next({type:"state_creation",token:w}),w},c,{internalRoles:n,subject:d,install:y=>u1(y,e),default:e.const});return t.families.set(r,p),c}function qm(t,e,n){const r=e.key,o="writable_pure_selector_family",c={key:r,type:o},u=t.families.get(r);u&&t.logger.error("❗",o,r,`Overwriting an existing ${hs(u)} "${u.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const d=new tt,p=Object.assign(y=>{const g=Ze(y),v={key:r,subKey:g},S=`${r}(${g})`,T=ve(t),w=Pm(T,{key:S,get:e.get(y),set:e.set(y)},v);return d.next({type:"state_creation",token:w}),w},c,{internalRoles:n,subject:d,install:y=>qm(y,e),default:y=>e.get(y)({get:(...v)=>zn(t,...v),find:(...v)=>zt(t,...v),json:v=>ps(t,v)})});return t.families.set(r,p),c}function nM(t,e){const n="set"in e,r="const"in e;return r&&n?u1(t,e,void 0):r?c1(t,e,void 0):n?qm(t,e):lo(t,e)}function iM(t,e,n){const r=t.families.get(e.key);if(r===void 0)throw new $m(e,t);const o=r(n),c=ve(t);if(o.family)if(mi(c))switch(o.type){case"atom":case"mutable_atom":t.on.atomCreation.next(o);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":t.on.selectorCreation.next(o);break}else Jt(c)&&c.on.transactionApplying.state===null&&c.transactionMeta.update.updates.push({type:"state_creation",token:o});return o}function rM(t,e,n){const r=Ze(n),o=`${e.key}(${r})`,c=ve(t);let u;switch(e.type){case"atom_family":case"mutable_atom_family":u=c.atoms.get(o);break;case"writable_held_selector_family":case"writable_pure_selector_family":u=c.writableSelectors.get(o);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":u=c.readonlySelectors.get(o);break}return u&&Eo(u)}function zt(t,e,n){let r=rM(t,e,n);if(r)return r;const o=Ze(n),c=t.molecules.get(o);if(!c&&t.config.lifespan==="immortal"){const u=Hk(e,n);return t.logger.error("❌",u.type,u.key,`was not found in store "${t.config.name}"; returned a counterfeit token.`),u}return r=iM(t,e,n),c&&ve(t).moleculeData.set(o,e.key),r}function Qu(t,...e){let n;if(e.length===1)n=e[0];else{const r=e[0],o=e[1];n=zt(t,r,o)}try{yt(t,n)}catch{t.logger.error("❌",n.type,n.key,`could not be disposed because it was not found in the store "${t.config.name}".`);return}switch(n.type){case"atom":case"mutable_atom":Gm(t,n);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":tM(t,n);break}}function f1(t,e){if(e.family){const n=t.families.get(e.family.key);if(n)return n}}function d1(t,...e){let n,r,o;if(e.length===1?(n=e[0],r=f1(t,n)??null,r&&(o=n.family?Mr(n.family.subKey):null,n=zt(t,r,o))):(r=e[0],o=e[1],n=zt(t,r,o)),"counterfeit"in n&&"family"in n){const d=n.family.subKey,h=t.disposalTraces.buffer.find(p=>p?.key===d);t.logger.error("❌",n.type,n.key,`could not be reset because it was not found in the store "${t.config.name}".`,h?`This state was previously disposed:
|
|
9
|
+
*/var Z0;function _k(){if(Z0)return Pa;Z0=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(r,o,c){var u=null;if(c!==void 0&&(u=""+c),o.key!==void 0&&(u=""+o.key),"key"in o){c={};for(var d in o)d!=="key"&&(c[d]=o[d])}else c=o;return o=c.ref,{$$typeof:t,type:r,key:u,ref:o!==void 0?o:null,props:c}}return Pa.Fragment=e,Pa.jsx=n,Pa.jsxs=n,Pa}var Q0;function kk(){return Q0||(Q0=1,Bh.exports=_k()),Bh.exports}var J=kk();function Mk(t){return Object.entries(t)}const Ck=(t,e,n=gt.STORE)=>l1(n,{key:`${t.key}:JSON`,get:({get:r})=>e.toJson(r(t)),set:({set:r},o)=>{r(t,e.fromJson(o))}});function Dk(t,e,n){return qm(t,{key:`${e.key}:JSON`,get:o=>({get:c})=>{const u=c(e,o);return n.toJson(u)},set:o=>({set:c},u)=>{c(e,o,n.fromJson(u))}},["mutable","json"])}const Mr=t=>JSON.parse(t),Ze=t=>JSON.stringify(t);function it(t){return EM(gt.STORE,t)}function et(...t){return t.length===2?zn(gt.STORE,...t):zn(gt.STORE,...t)}function Nk(t,e,n=gt.STORE){return n.joins.set(t.key,new A1(t,e,n)),{key:t.key,type:"join",a:t.between[0],b:t.between[1],cardinality:t.cardinality}}function $k(t){return OM(t,gt.STORE)}const Lh=t=>(e,n,r,o,...c)=>{console[t](`${e} ${n} "${r}" ${o}`,...c)},jk={error:Lh("error"),info:Lh("info"),warn:Lh("warn")};var Bk=class{logLevel;filter;logger;constructor(t,e,n=jk){this.logLevel=t,this.filter=e,this.logger=n}error=(...t)=>{const e=this.filter?.(...t)??!0;this.logLevel!==null&&(e===!0?this.logger.error(...t):e!==!1&&this.logger.error(...e))};info=(...t)=>{const e=this.filter?.(...t)??!0;this.logLevel==="info"&&(e===!0?this.logger.info(...t):e!==!1&&this.logger.info(...e))};warn=(...t)=>{const e=this.filter?.(...t)??!0;this.logLevel!=="error"&&this.logLevel!==null&&(e===!0?this.logger.warn(...t):e!==!1&&this.logger.warn(...e))}},Lk=class{store;constructor(t=gt.STORE){this.store=t,aM("root",t)}allocate(t,e,n){return pl(this.store,t,e,n)}fuse(t,e,n){return lM(this.store,t,e,n)}deallocate(t){ml(this.store,t)}claim(t,e,n){return Au(this.store,t,e,n)}},Vk=class{store;realm;constructor(t=gt.STORE){this.store=t,this.realm=new Lk(t)}allocate(t,e,n){pl(this.store,t,e,n)}deallocate(t){ml(this.store,t)}claim(t,e,n){Au(this.store,t,e,n)}};function pi(t){return l1(gt.STORE,t)}function Uk(t){return nM(gt.STORE,t)}function De(...t){t.length===2?Et(gt.STORE,...t):Et(gt.STORE,...t)}function zk(t,e,n=Ju()){return xM(gt.STORE,t,e,n)}function Kk(t){return b1(gt.STORE,t)}function Pk(t,e=Ju()){return jm(gt.STORE,t,e)}var Ao=class au extends Set{mode="record";subject=new tt;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(e,n=0){super(e),e instanceof au&&(this.parent=e,this.cacheUpdateNumber=e.cacheUpdateNumber),n&&(this.cacheLimit=n,this.cache=new Array(n),this.subscribe("auto cache",r=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=r}))}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(e){const n=new au(e.members,e.cacheLimit);return n.cache=e.cache,n.cacheIdx=e.cacheIdx,n.cacheUpdateNumber=e.cacheUpdateNumber,n}add(e){const n=super.add(e);return this.mode==="record"&&(this.cacheUpdateNumber++,this.emit(`add:${Ze(e)}`)),n}clear(){const e=this.mode==="record"?[...this]:null;super.clear(),e&&(this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(e)}`))}delete(e){const n=super.delete(e);return this.mode==="record"&&(this.cacheUpdateNumber++,this.emit(`del:${Ze(e)}`)),n}parent=null;child=null;transactionUpdates=null;transaction(e){this.mode="transaction",this.transactionUpdates=[],this.child=new au(this);const n=this.child._subscribe("transaction",r=>{this.transactionUpdates?.push(r)});try{if(e(this.child)){for(const o of this.transactionUpdates)this.doStep(o);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(r){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",r),r}finally{n(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(e,n){return this.subject.subscribe(e,n)}subscribe(e,n){return this.subject.subscribe(e,r=>{n(`${this.cacheUpdateNumber}=${r}`)})}emit(e){this.subject.next(e)}doStep(e){const n=e.indexOf(":"),r=e.substring(0,n),o=e.substring(n+1);switch(r){case"add":this.add(JSON.parse(o));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(o));break;case"tx":for(const c of o.split(";"))this.doStep(c)}}getUpdateNumber(e){const n=e.indexOf("=");return Number(e.substring(0,n))}do(e){const n=e.indexOf("="),r=Number(e.substring(0,n)),o=r-this.cacheUpdateNumber;if(o>0){if(o===1){this.mode="playback";const u=e.substring(n+1);return this.doStep(u),this.mode="record",this.cacheUpdateNumber=r,null}return this.cacheUpdateNumber+1}if(Math.abs(o)<this.cacheLimit){const u=this.cacheIdx+o;if(this.cache[u]===e)return null;this.mode="playback";let h=!1;for(;!h;){this.cacheIdx%=this.cacheLimit;const y=this.cache[this.cacheIdx];if(this.cacheIdx--,!y)return"OUT_OF_RANGE";this.undo(y),h=this.cacheIdx===u-1}const p=e.substring(n+1);return this.doStep(p),this.mode="record",this.cacheUpdateNumber=r,null}return"OUT_OF_RANGE"}undoStep(e){const n=e.indexOf(":"),r=e.substring(0,n),o=e.substring(n+1);switch(r){case"add":this.delete(JSON.parse(o));break;case"del":this.add(JSON.parse(o));break;case"clear":{const c=JSON.parse(o);for(const u of c)this.add(u);break}case"tx":{const c=o.split(";");for(let u=c.length-1;u>=0;u--)this.undoStep(c[u])}}}undo(e){const n=e.indexOf("=");if(Number(e.substring(0,n))===this.cacheUpdateNumber){this.mode="playback";const o=e.substring(n+1);return this.undoStep(o),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function Ju(t=Math.random){return t().toString(36).slice(2)}var Rp=class extends Promise{fate;resolve;reject;done=!1;constructor(t){let e,n;super((r,o)=>{e=r,n=o}),this.resolve=e,this.reject=n,this.use(t instanceof Promise?t:new Promise(t))}pass(t,e){t===this.fate&&(this.resolve(e),this.done=!0)}fail(t,e){t===this.fate&&(this.reject(e),this.done=!0)}use(t){if(t instanceof Promise){const e=t;this.fate=e,e.then(n=>{this.pass(e,n)},n=>{this.fail(e,n)})}else this.resolve(t),this.fate=void 0}};function ve(t){for(;t.child!==null;)t=t.child;return t}var qk=class i1{_buffer;_index=0;constructor(e){let n;typeof e=="number"?n=e:n=e.length,this._buffer=Array.from({length:n})}get buffer(){return this._buffer}get index(){return this._index}add(e){this._buffer[this._index]=e,this._index=(this._index+1)%this._buffer.length}copy(){const e=new i1([...this._buffer]);return e._index=this._index,e}};const Ik={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function Hk(t,e){const n=Ze(e),r=`${t.key}(${n})`,o=Ik[t.type],c={key:r,type:o};return Object.assign(c,{family:{key:t.key,subKey:n}}),Object.assign(c,{counterfeit:!0}),c}function Eo(t){const e={key:t.key,type:t.type};return"family"in t&&(e.family=t.family),e}var Qt=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(t,e)=>`${t}:${e}`;warn;getRelatedKeys(t){return this.relations.get(t)}addRelation(t,e){let n=this.relations.get(t),r=this.relations.get(e);n?n.add(e):(n=new Set([e]),this.relations.set(t,n)),r?r.add(t):(r=new Set([t]),this.relations.set(e,r))}deleteRelation(t,e){const n=this.relations.get(t);if(n){n.delete(e),n.size===0&&this.relations.delete(t);const r=this.relations.get(e);r&&(r.delete(t),r.size===0&&this.relations.delete(e))}}replaceRelationsUnsafely(t,e){this.relations.set(t,new Set(e));for(const n of e){const r=new Set().add(t);this.relations.set(n,r)}}replaceRelationsSafely(t,e){const n=this.relations.get(t);let r=this.isAType?.(t)?t:void 0,o=r===void 0?t:void 0;if(n)for(const c of n){r??=c,o??=c;const u=this.relations.get(c);u&&(u.size===1?this.relations.delete(c):u.delete(t),this.contents.delete(this.makeContentKey(r,o)))}this.relations.set(t,new Set(e));for(const c of e){let u=this.relations.get(c);u?u.add(t):(u=new Set().add(t),this.relations.set(c,u))}}getContentInternal(t){return this.contents.get(t)}setContent(t,e){this.contents.set(t,e)}deleteContent(t){this.contents.delete(t)}constructor(t,e){if(this.a=t.between[0],this.b=t.between[1],this.cardinality=t.cardinality,e?.externalStore||(this.relations=new Map(t.relations?.map(([n,r])=>[n,new Set(r)])),this.contents=new Map(t.contents)),this.isAType=e?.isAType??null,this.isBType=e?.isBType??null,this.isContent=e?.isContent??null,e?.makeContentKey&&(this.makeContentKey=e.makeContentKey),e?.externalStore){const n=e.externalStore;this.has=(r,o)=>n.has(r,o),this.addRelation=(r,o)=>{n.addRelation(r,o)},this.deleteRelation=(r,o)=>{n.deleteRelation(r,o)},this.replaceRelationsSafely=(r,o)=>{n.replaceRelationsSafely(r,o)},this.replaceRelationsUnsafely=(r,o)=>{n.replaceRelationsUnsafely(r,o)},this.getRelatedKeys=r=>n.getRelatedKeys(r),n.getContent&&(this.getContentInternal=r=>n.getContent(r),this.setContent=(r,o)=>{n.setContent(r,o)},this.deleteContent=r=>{n.deleteContent(r)});for(const[r,o]of t.relations??[]){let c=this.isAType?.(r)?r:void 0,u=c===void 0?r:void 0;for(const d of o)c??=d,u??=d,this.addRelation(c,u)}for(const[r,o]of t.contents??[])this.setContent(r,o)}e?.warn&&(this.warn=e.warn)}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([t,e])=>[t,[...e]]),contents:[...this.contents.entries()]}}set(...t){let e,n,r;switch(t.length){case 1:{const o=t[0];e=o[this.a],n=o[this.b],r=void 0;break}case 2:{const o=t[0];typeof o=="string"?[e,n]=t:(e=o[this.a],n=o[this.b],r=t[1]);break}default:{e=t[0],n=t[1],r=t[2];break}}switch(this.cardinality){case"1:1":{const o=this.getRelatedKey(e);o&&o!==n&&this.delete(e,o)}case"1:n":{const o=this.getRelatedKey(n);o&&o!==e&&this.delete(o,n)}break}if(r){const o=this.makeContentKey(e,n);this.setContent(o,r)}return this.addRelation(e,n),this}delete(t,e){e=typeof e=="string"?e:t[this.b];const n=typeof t=="string"?t:t[this.a];if(n===void 0&&typeof e=="string"){const r=this.getRelatedKeys(e);if(r)for(const o of r)this.delete(o,e)}if(typeof n=="string"&&e===void 0){const r=this.getRelatedKeys(n);if(r)for(const o of r)this.delete(n,o)}if(typeof n=="string"&&typeof e=="string"){this.deleteRelation(n,e);const r=this.makeContentKey(n,e);this.deleteContent(r)}return this}getRelatedKey(t){const e=this.getRelatedKeys(t);if(e){e.size>1&&this.warn?.(`${e.size} related keys were found for key "${t}": (${[...e].map(r=>`"${r}"`).join(", ")}). Only one related key was expected.`);let n;for(const r of e){n=r;break}return n}}replaceRelations(t,e,n){const r=!Array.isArray(e),o=r?Object.keys(e):e;if(n?.reckless?this.replaceRelationsUnsafely(t,o):this.replaceRelationsSafely(t,o),r)for(const c of o){const u=this.makeContentKey(t,c),d=e[c];this.setContent(u,d)}return this}getContent(t,e){const n=this.makeContentKey(t,e);return this.getContentInternal(n)}getRelationEntries(t){const e=t[this.a],n=t[this.b];if(e!==void 0&&n===void 0){const r=this.getRelatedKeys(e);if(r)return[...r].map(o=>[o,this.getContent(e,o)])}if(e===void 0&&n!==void 0){const r=this.getRelatedKeys(n);if(r)return[...r].map(o=>[o,this.getContent(o,n)])}return[]}has(t,e){return e?this.getRelatedKeys(t)?.has(e)??!1:this.relations.has(t)}},tt=class{Subscriber;subscribers=new Map;subscribe(t,e){return this.subscribers.set(t,e),()=>{this.unsubscribe(t)}}unsubscribe(t){this.subscribers.delete(t)}next(t){const e=this.subscribers.values();for(const n of e)n(t)}},Fk=class extends tt{state;constructor(t){super(),this.state=t}next(t){this.state=t,super.next(t)}};function mi(t){return"epoch"in t.transactionMeta}function Jt(t){return"phase"in t.transactionMeta}const Gk=t=>{const e=ve(t);if(!Jt(e)){t.logger.warn("🐞","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}t.logger.info("🪂","transaction",e.transactionMeta.update.key,"Aborting transaction"),e.parent.child=null};function ln(t){return t[0].toUpperCase()+t.slice(1)}function hs(t){return t.type.split("_").map(ln).join(" ")}var $m=class extends Error{constructor(t,e){super(`${hs(t)} ${Ze(t.key)} not found in store "${e.config.name}".`)}};function jm(t,e,n){return(...r)=>{const o=yt(t,e);if(o)return o.run(r,n);throw new $m(e,t)}}const Bm=t=>e=>t instanceof Function?t(e):t,Xu=(t,e)=>{if(t.valueMap.has(e.key))return t.logger.info("📖",e.type,e.key,"reading cached value"),AM(e,t);switch(e.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return t.logger.info("🧮",e.type,e.key,"computing value"),e.get();case"atom":case"mutable_atom":{const n=e.default;let r;return n instanceof Function?r=n():r=n,t.logger.info("💁","atom",e.key,"could not find cached value; using default",r),r}}},wu=(t,e)=>{if(t.operation.open){const n=performance.now();return t.logger.info("❗",e.type,e.key,`deferring setState at T-${n} until setState for "${t.operation.token.key}" is done`),n}t.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:e},t.logger.info("⭕",e.type,e.key,`operation start in store "${t.config.name}"${Jt(t)?` ${t.transactionMeta.phase} "${t.transactionMeta.update.key}"`:""}`)},Tu=t=>{t.operation.open&&t.logger.info("🔴",t.operation.token.type,t.operation.token.key,`operation done in store "${t.config.name}"`),t.operation={open:!1},t.on.operationClose.next(t.operation)},r1=(t,e)=>t.operation.open?t.operation.done.has(e):(t.logger.error("🐞","unknown",e,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0),hl=(t,e)=>{if(!t.operation.open){t.logger.error("🐞","unknown",e,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}t.operation.done.add(e)},Yk=(t,e,n)=>{switch(e.type){case"mutable_atom":t.logger.info("📢",e.type,e.key,"is now (",n.newValue,") subscribers:",e.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":t.logger.info("📢",e.type,e.key,"went (",n.oldValue,"->",n.newValue,") subscribers:",e.subject.subscribers)}e.subject.next(n)};function Op(t,e){const n=ve(t),r=n.selectorAtoms.getRelatedKeys(e.key);if(n.logger.info("🧹",e.type,e.key,r?`evicting ${r.size} states downstream:`:"no downstream states",r??"to evict"),r){n.operation.open&&n.logger.info("🧹",e.type,e.key,`[ ${[...n.operation.done].join(", ")} ] already done`);for(const o of r)r1(n,o)||(T1(o,n),hl(n,o))}}function Jk(t,e){const n=ve(t),r=n.selectorGraph.getRelationEntries({upstreamSelectorKey:e.key}).filter(([o,{source:c}])=>c===e.key);for(const[o]of r)r1(n,o)||(T1(o,n),hl(n,o))}const s1=(t,e,n)=>{const r=Xu(t,e);let o=r;if(e.type==="mutable_atom"&&Jt(t)){const{parent:u}=t;o=kp(t,e,u)}o=Bm(n)(o),t.logger.info("📝","atom",e.key,"set to",o),o=fi(t,e.key,o,e.subject),hl(t,e.key),Op(t,e);const c={oldValue:r,newValue:o};if(!Jt(t)){Yk(t,e,c);return}if(t.on.transactionApplying.state===null){const{key:u}=e;if(TM(c.newValue))return;const d={type:"atom_update",key:u,...c};e.family&&(d.family=e.family),t.transactionMeta.update.updates.push(d),t.logger.info("📁","atom",u,"stowed (",c.oldValue,"->",c.newValue,")")}else if(e.key.startsWith("*")){const u=e.key.slice(1),d=t.atoms.get(u);let h=t.valueMap.get(u);if(d.type==="mutable_atom"&&Jt(t)){const{parent:y}=t;h=kp(t,d,y)}h.do(c.newValue)===null&&Op(t,d)}};function W0(t,e){let n=e.default;n instanceof Function&&(n=n()),s1(t,e,n)}function Xk(t,e){switch(e.type){case"atom":case"mutable_atom":W0(t,e);break;case"writable_pure_selector":case"writable_held_selector":{const n=a1(e,t);for(const r of n)W0(t,r)}break}}function Lm(t,e,n){const r={key:e.key,type:"atom_family"},o=t.families.get(e.key);o&&t.logger.error("❗","atom_family",e.key,`Overwriting an existing ${hs(o)} "${o.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const c=new tt,d=Object.assign(h=>{const p=Ze(h),y={key:e.key,subKey:p},g=`${e.key}(${p})`,v=ve(t),S=e.default,T={key:g,default:S instanceof Function?()=>S(h):S};e.effects&&(T.effects=e.effects(h));const w=Wu(v,T,y);return c.next({type:"state_creation",token:w}),w},r,{subject:c,install:h=>Lm(h,e),internalRoles:n});return t.families.set(e.key,d),t.defaults.set(e.key,e.default),r}const Vm=(t,e)=>ve(t).atoms.has(e),Zk=(t,e)=>ve(t).writableSelectors.has(e),Qk=(t,e)=>ve(t).readonlySelectors.has(e),Wk=(t,e)=>Vm(t,e)||Zk(t,e)||Qk(t,e),_p=(t,e)=>ve(t).selectorGraph.getRelationEntries({downstreamSelectorKey:e}).filter(([r,{source:o}])=>o!==e).map(([r,{source:o}])=>o).filter(r=>Wk(t,r)),o1=(t,e,n)=>{const r=[],o=_p(t,e);for(;o.length>0;){const c=o.shift();n.has(c)||(n.add(c),Vm(t,c)?r.includes(c)||r.push(c):o.push(..._p(t,c)))}return r},a1=(t,e)=>{const n=t.key,r=_p(e,n),o=new Set;return r.flatMap(c=>Vm(e,c)?c:o1(e,c,o)).map(c=>e.atoms.get(c))},eM=(t,e,n,r,o)=>{const c=ve(t),{type:u,key:d}=r;if(u==="atom"||u==="mutable_atom")c.selectorAtoms.set({selectorKey:n,atomKey:d}),t.logger.info("🔍",e,n,`discovers root atom "${d}"`);else{const h=o1(t,d,o);t.logger.info("🔍",e,n,`discovers root atoms: [ ${h.map(p=>`"${p}"`).join(", ")} ]`);for(const p of h)c.selectorAtoms=c.selectorAtoms.set({selectorKey:n,atomKey:p})}o.add(d)},Zu=(t,e,n,r)=>({get:(...o)=>{const c=ve(t);let u;if(o.length===2){const[y,g]=o;u=zt(t,y,g)}else[u]=o;const d=yt(t,u),h=Xu(t,d),p=u.key;return t.logger.info("🔌",e,n,`registers dependency ( "${p}" =`,h,")"),c.selectorGraph.set({upstreamSelectorKey:p,downstreamSelectorKey:n},{source:u.key}),eM(t,e,n,u,r),h},set:(...o)=>{let c,u;if(o.length===2)c=o[0],u=o[1];else{const p=o[0],y=o[1];u=o[2],c=zt(t,p,y)}const d=ve(t),h=yt(d,c);h1(d,h,u)},find:(...o)=>zt(t,...o),json:o=>ps(t,o)}),Um=(t,e,n)=>{const r=ve(t),o=new tt,c=new Set,{key:u,const:d}=e,h="readonly_held_selector",{get:p,find:y,json:g}=Zu(r,h,u,c),S={...e,type:h,subject:o,install:w=>Um(w,e,n),get:()=>(e.get({get:p,find:y,json:g},d),fi(ve(t),u,d,o),c.clear(),d),...n&&{family:n}};r.readonlySelectors.set(u,S),t.logger.info("✨",h,u,"=",d);const T={key:u,type:h};return n&&(T.family=n),T},zm=(t,e,n)=>{const r=ve(t),o=new tt,c=new Set,u=e.key,d="readonly_pure_selector",{get:h,find:p,json:y}=Zu(r,d,u,c),g=()=>{const w=e.get({get:h,find:p,json:y});return fi(ve(t),u,w,o),c.clear(),w},v={...e,type:d,subject:o,install:w=>zm(w,e,n),get:g,...n&&{family:n}};r.readonlySelectors.set(u,v);const S=g();t.logger.info("✨",d,u,"=",S);const T={key:u,type:d};return n&&(T.family=n),T},Km=(t,e,n)=>{const r=ve(t),o=new tt,c=new Set,{key:u,const:d}=e,h="writable_held_selector",p=Zu(r,h,u,c),{find:y,get:g,json:v}=p,S={find:y,get:g,json:v},T=(k=e.get,C=ve(t))=>(k(S,d),fi(C,u,d,o),c.clear(),d),D={...e,type:h,subject:o,install:k=>Km(k,e,n),get:T,set:k=>{const C=ve(t),O=T(e.get,C),X=Bm(k)(O);t.logger.info("📝",h,u,"set (",O,"->",X,")"),fi(C,u,X,o),hl(C,u),mi(C)&&o.next({newValue:X,oldValue:O}),e.set(p,X)},...n&&{family:n}};r.writableSelectors.set(u,D);const $=T();t.logger.info("✨",h,u,"=",$);const _={key:u,type:h};return n&&(_.family=n),_},Pm=(t,e,n)=>{const r=ve(t),o=new tt,c=new Set,u=e.key,d="writable_pure_selector",h=Zu(r,d,u,c),{find:p,get:y,json:g}=h,v={find:p,get:y,json:g},S=(_=e.get,k=ve(t))=>{const C=_(v);return fi(k,u,C,o),c.clear(),C},w={...e,type:d,subject:o,install:_=>Pm(_,e,n),get:S,set:_=>{const k=ve(t),C=S(e.get,k),O=Bm(_)(C);t.logger.info("📝",d,u,"set (",C,"->",O,")"),fi(k,e.key,O,o),hl(k,e.key),mi(k)&&o.next({newValue:O,oldValue:C}),e.set(h,O)},...n&&{family:n}};r.writableSelectors.set(u,w);const D=S();t.logger.info("✨",w.type,w.key,"=",D);const $={key:u,type:d};return n&&($.family=n),$};function l1(t,e){const n="set"in e,r="const"in e;if(r&&n){const c=Km(t,e,void 0);return t.on.selectorCreation.next(c),c}if(r){const c=Um(t,e,void 0);return t.on.selectorCreation.next(c),c}if(n){const c=Pm(t,e,void 0);return t.on.selectorCreation.next(c),c}const o=zm(t,e,void 0);return t.on.selectorCreation.next(o),o}function tM(t,e){const n=ve(t),{key:r,type:o}=e,c=yt(n,e);if(!c.family)t.logger.error("❌",o,r,"Standalone selectors cannot be disposed.");else{n.molecules.get(c.family.subKey)&&n.moleculeData.delete(c.family.subKey,c.family.key);let d;switch(e.type){case"writable_held_selector":n.writableSelectors.delete(r),d={key:c.family.key,type:"writable_held_selector_family"},yt(t,d).subject.next({type:"state_disposal",subType:"selector",token:e});break;case"writable_pure_selector":n.writableSelectors.delete(r),d={key:c.family.key,type:"writable_pure_selector_family"},yt(t,d).subject.next({type:"state_disposal",subType:"selector",token:e});break;case"readonly_held_selector":n.readonlySelectors.delete(r),d={key:c.family.key,type:"readonly_held_selector_family"},yt(t,d).subject.next({type:"state_disposal",subType:"selector",token:e});break;case"readonly_pure_selector":n.readonlySelectors.delete(r),d={key:c.family.key,type:"readonly_pure_selector_family"},yt(t,d).subject.next({type:"state_disposal",subType:"selector",token:e});break}n.valueMap.delete(r),n.selectorAtoms.delete(r),n.selectorGraph.delete(r),t.logger.info("🔥",e.type,r,"deleted"),Jt(n)&&n.transactionMeta.phase==="building"?n.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:e}):t.on.selectorDisposal.next(e)}}function lo(t,e,n){const r=e.key,o="readonly_pure_selector_family",c={key:r,type:o},u=t.families.get(r);u&&t.logger.error("❗",o,r,`Overwriting an existing ${hs(u)} "${u.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const d=new tt,p=Object.assign(y=>{const g=Ze(y),v={key:r,subKey:g},S=`${r}(${g})`,T=ve(t),w=zm(T,{key:S,get:e.get(y)},v);return d.next({type:"state_creation",token:w}),w},c,{internalRoles:n,subject:d,install:y=>lo(y,e),default:y=>e.get(y)({get:(...v)=>zn(t,...v),find:(...v)=>zt(t,...v),json:v=>ps(t,v)})});return t.families.set(r,p),c}function c1(t,e,n){const r=e.key,o="readonly_held_selector_family",c={key:r,type:o},u=t.families.get(r);u&&t.logger.error("❗",o,r,`Overwriting an existing ${hs(u)} "${u.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const d=new tt,p=Object.assign(y=>{const g=Ze(y),v={key:r,subKey:g},S=`${r}(${g})`,T=ve(t),w=Um(T,{key:S,const:e.const(y),get:e.get(y)},v);return d.next({type:"state_creation",token:w}),w},c,{internalRoles:n,subject:d,install:y=>c1(y,e),default:e.const});return t.families.set(r,p),c}function u1(t,e,n){const r=e.key,o="writable_held_selector_family",c={key:r,type:o},u=t.families.get(r);u&&t.logger.error("❗",o,r,`Overwriting an existing ${hs(u)} "${u.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const d=new tt,p=Object.assign(y=>{const g=Ze(y),v={key:r,subKey:g},S=`${r}(${g})`,T=ve(t),w=Km(T,{key:S,const:e.const(y),get:e.get(y),set:e.set(y)},v);return d.next({type:"state_creation",token:w}),w},c,{internalRoles:n,subject:d,install:y=>u1(y,e),default:e.const});return t.families.set(r,p),c}function qm(t,e,n){const r=e.key,o="writable_pure_selector_family",c={key:r,type:o},u=t.families.get(r);u&&t.logger.error("❗",o,r,`Overwriting an existing ${hs(u)} "${u.key}" in store "${t.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);const d=new tt,p=Object.assign(y=>{const g=Ze(y),v={key:r,subKey:g},S=`${r}(${g})`,T=ve(t),w=Pm(T,{key:S,get:e.get(y),set:e.set(y)},v);return d.next({type:"state_creation",token:w}),w},c,{internalRoles:n,subject:d,install:y=>qm(y,e),default:y=>e.get(y)({get:(...v)=>zn(t,...v),find:(...v)=>zt(t,...v),json:v=>ps(t,v)})});return t.families.set(r,p),c}function nM(t,e){const n="set"in e,r="const"in e;return r&&n?u1(t,e,void 0):r?c1(t,e,void 0):n?qm(t,e):lo(t,e)}function iM(t,e,n){const r=t.families.get(e.key);if(r===void 0)throw new $m(e,t);const o=r(n),c=ve(t);if(o.family)if(mi(c))switch(o.type){case"atom":case"mutable_atom":t.on.atomCreation.next(o);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":t.on.selectorCreation.next(o);break}else Jt(c)&&c.on.transactionApplying.state===null&&c.transactionMeta.update.updates.push({type:"state_creation",token:o});return o}function rM(t,e,n){const r=Ze(n),o=`${e.key}(${r})`,c=ve(t);let u;switch(e.type){case"atom_family":case"mutable_atom_family":u=c.atoms.get(o);break;case"writable_held_selector_family":case"writable_pure_selector_family":u=c.writableSelectors.get(o);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":u=c.readonlySelectors.get(o);break}return u&&Eo(u)}function zt(t,e,n){let r=rM(t,e,n);if(r)return r;const o=Ze(n),c=t.molecules.get(o);if(!c&&t.config.lifespan==="immortal"){const u=Hk(e,n);return t.logger.error("❌",u.type,u.key,`was not found in store "${t.config.name}"; returned a counterfeit token.`),u}return r=iM(t,e,n),c&&ve(t).moleculeData.set(o,e.key),r}function Qu(t,...e){let n;if(e.length===1)n=e[0];else{const r=e[0],o=e[1];n=zt(t,r,o)}try{yt(t,n)}catch{t.logger.error("❌",n.type,n.key,`could not be disposed because it was not found in the store "${t.config.name}".`);return}switch(n.type){case"atom":case"mutable_atom":Gm(t,n);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":tM(t,n);break}}function f1(t,e){if(e.family){const n=t.families.get(e.family.key);if(n)return n}}function d1(t,...e){let n,r,o;if(e.length===1?(n=e[0],r=f1(t,n)??null,r&&(o=n.family?Mr(n.family.subKey):null,n=zt(t,r,o))):(r=e[0],o=e[1],n=zt(t,r,o)),"counterfeit"in n&&"family"in n){const d=n.family.subKey,h=t.disposalTraces.buffer.find(p=>p?.key===d);t.logger.error("❌",n.type,n.key,`could not be reset because it was not found in the store "${t.config.name}".`,h?`This state was previously disposed:
|
|
10
10
|
${h.trace}`:"No previous disposal trace was found.");return}const c=wu(t,n);if(c){const d=t.on.operationClose.subscribe(`waiting to reset "${n.key}" at T-${c}`,()=>{d(),t.logger.info("🟢",n.type,n.key,`resuming deferred resetState from T-${c}`),d1(t,n)});return}const u=yt(t,n);Xk(t,u),Tu(t)}const h1=(t,e,n)=>{switch(e.type){case"atom":case"mutable_atom":s1(t,e,n);break;case"writable_pure_selector":case"writable_held_selector":e.set(n);break}};function Et(t,...e){let n,r,o,c;if(e.length===2?(n=e[0],c=e[1],r=f1(t,n)??null,r&&(o=n.family?Mr(n.family.subKey):null,n=zt(t,r,o))):(r=e[0],o=e[1],c=e[2],n=zt(t,r,o)),"counterfeit"in n&&"family"in n){const h=n.family.subKey,p=t.disposalTraces.buffer.find(y=>y?.key===h);t.logger.error("❌",n.type,n.key,`could not be set because it was not found in the store "${t.config.name}".`,p?`This state was previously disposed:
|
|
11
11
|
${p.trace}`:"No previous disposal trace was found.");return}const u=wu(t,n);if(u){const h=t.on.operationClose.subscribe(`waiting to set "${n.key}" at T-${u}`,()=>{h(),t.logger.info("🟢",n.type,n.key,`resuming deferred setState from T-${u}`),Et(t,n,c)});return}const d=yt(t,n);h1(t,d,c),Tu(t)}function sM(t,e,n){const{key:r,newValue:o,oldValue:c}=e,u=t==="newValue"?o:c,d={key:r,type:"atom"};e.family&&Object.assign(d,{family:e.family}),Et(n,d,u)}function oM(t){const{stack:e}=t;return e?`
|
|
12
12
|
`+e.split(`
|
package/app/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>TEMPEST</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-CfnJ3uCQ.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-ki_mruCb.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/bin/backend.bun.js
CHANGED
|
@@ -283,7 +283,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
283
283
|
`)}})).pipeThrough(new TextEncoderStream)}var aen={"Content-Type":"text/event-stream","Cache-Control":"no-cache, no-transform","X-Accel-Buffering":"no",Connection:"keep-alive"},ten=Ri(jf(),1),ID=Ri(Kt(),1);function BT(n){return ds(ten.default(function*(){throw n}))}var ren={mutation:["POST"],query:["GET"],subscription:["GET"]},oen={mutation:["POST"],query:["GET","POST"],subscription:["GET","POST"]};function Em(n){var i,e,a;let{ctx:t,info:r,responseMeta:o,untransformedJSON:u,errors:l=[],headers:s}=n,c=u?HM(u):200,f=!u,b=f?[]:Array.isArray(u)?u:[u],g=(i=o===null||o===void 0?void 0:o({ctx:t,info:r,paths:r===null||r===void 0?void 0:r.calls.map((m)=>m.path),data:b,errors:l,eagerGeneration:f,type:(e=r===null||r===void 0||(a=r.calls.find((m)=>{var h;return(h=m.procedure)===null||h===void 0?void 0:h._def.type}))===null||a===void 0||(a=a.procedure)===null||a===void 0?void 0:a._def.type)!==null&&e!==void 0?e:"unknown"}))!==null&&i!==void 0?i:{};if(g.headers){if(g.headers instanceof Headers)for(let[m,h]of g.headers.entries())s.append(m,h);else for(let[m,h]of Object.entries(g.headers))if(Array.isArray(h))for(let D of h)s.append(m,D);else if(typeof h==="string")s.set(m,h)}if(g.status)c=g.status;return{status:c}}function uen(n,i){let{router:e,req:a,onError:t}=i.opts,r=ot(n);t===null||t===void 0||t({error:r,path:i.path,input:i.input,ctx:i.ctx,type:i.type,req:a});let o={error:fs({config:e._def._config,error:r,type:i.type,path:i.path,input:i.input,ctx:i.ctx})},u=kp(e._def._config,o),l=JSON.stringify(u);return{error:r,untransformedJSON:o,body:l}}function a6(n){if(!$a(n))return!1;if(dm(n))return!0;return Object.values(n).some(f6)||Object.values(n).some(dm)}async function b6(n){var i,e,a,t,r,o;let{router:u,req:l}=n,s=new Headers([["vary","trpc-accept"]]),c=u._def._config,f=new URL(l.url);if(l.method==="HEAD")return new Response(null,{status:204});let b=(i=(e=n.allowBatching)!==null&&e!==void 0?e:(a=n.batching)===null||a===void 0?void 0:a.enabled)!==null&&i!==void 0?i:!0,g=((t=n.allowMethodOverride)!==null&&t!==void 0?t:!1)&&l.method==="POST",m=await ds(async()=>{try{return[void 0,await vin({req:l,path:decodeURIComponent(n.path),router:u,searchParams:f.searchParams,headers:n.req.headers,url:f})]}catch(x){return[ot(x),void 0]}}),h=ds(()=>{let x=void 0;return{valueOrUndefined:()=>{if(!x)return;return x[1]},value:()=>{let[N,I]=x;if(N)throw N;return I},create:async(N)=>{if(x)throw new Error("This should only be called once - report a bug in tRPC");try{x=[void 0,await n.createContext({info:N})]}catch(I){x=[ot(I),void 0]}}}}),D=g?oen:ren,T=l.headers.get("trpc-accept")==="application/jsonl",v=(r=(o=c.sse)===null||o===void 0?void 0:o.enabled)!==null&&r!==void 0?r:!0;try{let[x,N]=m;if(x)throw x;if(N.isBatchCall&&!b)throw new Xn({code:"BAD_REQUEST",message:"Batching is not enabled on the server"});if(T&&!N.isBatchCall)throw new Xn({message:"Streaming requests must be batched (you can do a batch of 1)",code:"BAD_REQUEST"});await h.create(N);let I=N.calls.map(async(K)=>{let Z=K.procedure;try{if(n.error)throw n.error;if(!Z)throw new Xn({code:"NOT_FOUND",message:`No procedure found on path "${K.path}"`});if(!D[Z._def.type].includes(l.method))throw new Xn({code:"METHOD_NOT_SUPPORTED",message:`Unsupported ${l.method}-request to ${Z._def.type} procedure at path "${K.path}"`});if(Z._def.type==="subscription"){if(N.isBatchCall)throw new Xn({code:"BAD_REQUEST",message:"Cannot batch subscription calls"})}return[void 0,{data:await Z({path:K.path,getRawInput:K.getRawInput,ctx:h.value(),type:Z._def.type,signal:n.req.signal})}]}catch(Dn){var J,tn,on;let Ln=ot(Dn),Q=K.result();return(J=n.onError)===null||J===void 0||J.call(n,{error:Ln,path:K.path,input:Q,ctx:h.valueOrUndefined(),type:(tn=(on=K.procedure)===null||on===void 0?void 0:on._def.type)!==null&&tn!==void 0?tn:"unknown",req:n.req}),[Ln,void 0]}});if(!N.isBatchCall){let[K]=N.calls,[Z,J]=await I[0];switch(N.type){case"unknown":case"mutation":case"query":{if(s.set("content-type","application/json"),a6(J===null||J===void 0?void 0:J.data))throw new Xn({code:"UNSUPPORTED_MEDIA_TYPE",message:"Cannot use stream-like response in non-streaming request - use httpBatchStreamLink"});let tn=Z?{error:fs({config:c,ctx:h.valueOrUndefined(),error:Z,input:K.result(),path:K.path,type:N.type})}:{result:{data:J.data}},on=Em({ctx:h.valueOrUndefined(),info:N,responseMeta:n.responseMeta,errors:Z?[Z]:[],headers:s,untransformedJSON:[tn]});return new Response(JSON.stringify(kp(c,tn)),{status:on.status,headers:s})}case"subscription":{let tn=ds(()=>{if(Z)return BT(Z);if(!v)return BT(new Xn({code:"METHOD_NOT_SUPPORTED",message:'Missing experimental flag "sseSubscriptions"'}));if(!OD(J.data)&&!dm(J.data))return BT(new Xn({message:`Subscription ${K.path} did not return an observable or a AsyncGenerator`,code:"INTERNAL_SERVER_ERROR"}));return OD(J.data)?HT(J.data,n.req.signal):J.data}),on=een(ID.default(ID.default({},c.sse),{},{data:tn,serialize:(Ln)=>c.transformer.output.serialize(Ln),formatError(Ln){var Q,O,k;let pn=ot(Ln.error),Sn=K===null||K===void 0?void 0:K.result(),vn=K===null||K===void 0?void 0:K.path,mn=(Q=K===null||K===void 0||(O=K.procedure)===null||O===void 0?void 0:O._def.type)!==null&&Q!==void 0?Q:"unknown";return(k=n.onError)===null||k===void 0||k.call(n,{error:pn,path:vn,input:Sn,ctx:h.valueOrUndefined(),req:n.req,type:mn}),fs({config:c,ctx:h.valueOrUndefined(),error:pn,input:Sn,path:vn,type:mn})}}));for(let[Ln,Q]of Object.entries(aen))s.set(Ln,Q);let Dn=Em({ctx:h.valueOrUndefined(),info:N,responseMeta:n.responseMeta,errors:[],headers:s,untransformedJSON:null});return new Response(on,{headers:s,status:Dn.status})}}}if(N.accept==="application/jsonl"){s.set("content-type","application/json"),s.set("transfer-encoding","chunked");let K=Em({ctx:h.valueOrUndefined(),info:N,responseMeta:n.responseMeta,errors:[],headers:s,untransformedJSON:null}),Z=Qin(ID.default(ID.default({},c.jsonl),{},{maxDepth:1/0,data:I.map(async(J)=>{let[tn,on]=await J,Dn=N.calls[0];if(tn){var Ln,Q;return{error:fs({config:c,ctx:h.valueOrUndefined(),error:tn,input:Dn.result(),path:Dn.path,type:(Ln=(Q=Dn.procedure)===null||Q===void 0?void 0:Q._def.type)!==null&&Ln!==void 0?Ln:"unknown"})}}let O=OD(on.data)?HT(on.data,n.req.signal):Promise.resolve(on.data);return{result:Promise.resolve({data:O})}}),serialize:c.transformer.output.serialize,onError:(J)=>{var tn,on;(tn=n.onError)===null||tn===void 0||tn.call(n,{error:ot(J),path:void 0,input:void 0,ctx:h.valueOrUndefined(),req:n.req,type:(on=N===null||N===void 0?void 0:N.type)!==null&&on!==void 0?on:"unknown"})},formatError(J){var tn,on;let Dn=N===null||N===void 0?void 0:N.calls[J.path[0]],Ln=ot(J.error),Q=Dn===null||Dn===void 0?void 0:Dn.result(),O=Dn===null||Dn===void 0?void 0:Dn.path,k=(tn=Dn===null||Dn===void 0||(on=Dn.procedure)===null||on===void 0?void 0:on._def.type)!==null&&tn!==void 0?tn:"unknown";return fs({config:c,ctx:h.valueOrUndefined(),error:Ln,input:Q,path:O,type:k})}}));return new Response(Z,{headers:s,status:K.status})}s.set("content-type","application/json");let G=(await Promise.all(I)).map((K)=>{let[Z,J]=K;if(Z)return K;if(a6(J.data))return[new Xn({code:"UNSUPPORTED_MEDIA_TYPE",message:"Cannot use stream-like response in non-streaming request - use httpBatchStreamLink"}),void 0];return K}),Y=G.map(([K,Z],J)=>{let tn=N.calls[J];if(K){var on,Dn;return{error:fs({config:c,ctx:h.valueOrUndefined(),error:K,input:tn.result(),path:tn.path,type:(on=(Dn=tn.procedure)===null||Dn===void 0?void 0:Dn._def.type)!==null&&on!==void 0?on:"unknown"})}}return{result:{data:Z.data}}}),W=G.map(([K])=>K).filter(Boolean),$=Em({ctx:h.valueOrUndefined(),info:N,responseMeta:n.responseMeta,untransformedJSON:Y,errors:W,headers:s});return new Response(JSON.stringify(kp(c,Y)),{status:$.status,headers:s})}catch(x){var S;let[N,I]=m,G=h.valueOrUndefined(),{error:Y,untransformedJSON:W,body:$}=uen(x,{opts:n,ctx:h.valueOrUndefined(),type:(S=I===null||I===void 0?void 0:I.type)!==null&&S!==void 0?S:"unknown"}),K=Em({ctx:G,info:I,responseMeta:n.responseMeta,untransformedJSON:W,errors:[Y],headers:s});return new Response($,{status:K.status,headers:s})}}var zD=Ri(Kt(),1),h6="middlewareMarker";function len(){function n(e){return{_middlewares:e,unstable_pipe(a){let t="_middlewares"in a?a._middlewares:[a];return n([...e,...t])}}}function i(e){return n([e])}return i}function sen(n){let i=async function e(a){let t,r=await a.getRawInput();try{t=await n(r)}catch(u){throw new Xn({code:"BAD_REQUEST",cause:u})}let o=$a(a.input)&&$a(t)?zD.default(zD.default({},a.input),t):t;return a.next({input:o})};return i._type="input",i}function cen(n){let i=async function e({next:a}){let t=await a();if(!t.ok)return t;try{let r=await n(t.data);return zD.default(zD.default({},t),{},{data:r})}catch(r){throw new Xn({message:"Output validation failed",code:"INTERNAL_SERVER_ERROR",cause:r})}};return i._type="output",i}var pen=Ri(Xp(),1),A6=class extends Error{constructor(n){var i;super((i=n[0])===null||i===void 0?void 0:i.message);pen.default(this,"issues",void 0),this.name="SchemaError",this.issues=n}};function E6(n){let i=n,e="~standard"in i;if(typeof i==="function"&&typeof i.assert==="function")return i.assert.bind(i);if(typeof i==="function"&&!e)return i;if(typeof i.parseAsync==="function")return i.parseAsync.bind(i);if(typeof i.parse==="function")return i.parse.bind(i);if(typeof i.validateSync==="function")return i.validateSync.bind(i);if(typeof i.create==="function")return i.create.bind(i);if(typeof i.assert==="function")return(a)=>{return i.assert(a),a};if(e)return async(a)=>{let t=await i["~standard"].validate(a);if(t.issues)throw new A6(t.issues);return t.value};throw new Error("Could not find a validator fn")}var den=Qt({"../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutPropertiesLoose.js"(n,i){function e(a,t){if(a==null)return{};var r={};for(var o in a)if({}.hasOwnProperty.call(a,o)){if(t.includes(o))continue;r[o]=a[o]}return r}i.exports=e,i.exports.__esModule=!0,i.exports.default=i.exports}}),fen=Qt({"../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectWithoutProperties.js"(n,i){var e=den();function a(t,r){if(t==null)return{};var o,u,l=e(t,r);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(u=0;u<s.length;u++)o=s[u],r.includes(o)||{}.propertyIsEnumerable.call(t,o)&&(l[o]=t[o])}return l}i.exports=a,i.exports.__esModule=!0,i.exports.default=i.exports}}),ben=Ri(fen(),1),sa=Ri(Kt(),1),Een=["middlewares","inputs","meta"];function Ac(n,i){let{middlewares:e=[],inputs:a,meta:t}=i,r=ben.default(i,Een);return D6(sa.default(sa.default({},SD(n,r)),{},{inputs:[...n.inputs,...a!==null&&a!==void 0?a:[]],middlewares:[...n.middlewares,...e],meta:n.meta&&t?sa.default(sa.default({},n.meta),t):t!==null&&t!==void 0?t:n.meta}))}function D6(n={}){let i=sa.default({procedure:!0,inputs:[],middlewares:[]},n);return{_def:i,input(a){let t=E6(a);return Ac(i,{inputs:[a],middlewares:[sen(t)]})},output(a){let t=E6(a);return Ac(i,{output:a,middlewares:[cen(t)]})},meta(a){return Ac(i,{meta:a})},use(a){let t="_middlewares"in a?a._middlewares:[a];return Ac(i,{middlewares:t})},unstable_concat(a){return Ac(i,a._def)},concat(a){return Ac(i,a._def)},query(a){return jT(sa.default(sa.default({},i),{},{type:"query"}),a)},mutation(a){return jT(sa.default(sa.default({},i),{},{type:"mutation"}),a)},subscription(a){return jT(sa.default(sa.default({},i),{},{type:"subscription"}),a)},experimental_caller(a){return Ac(i,{caller:a})}}}function jT(n,i){let e=Ac(n,{resolver:i,middlewares:[async function u(l){let s=await i(l);return{marker:h6,ok:!0,data:s,ctx:l.ctx}}]}),a=sa.default(sa.default({},e._def),{},{type:n.type,experimental_caller:Boolean(e._def.caller),meta:e._def.meta,$types:null}),t=men(e._def),r=e._def.caller;if(!r)return t;let o=async(...u)=>{return await r({args:u,invoke:t,_def:a})};return o._def=a,o}var gen=`
|
|
284
284
|
This is a client-only function.
|
|
285
285
|
If you want to call this function on the server, see https://trpc.io/docs/v11/server/server-side-calls
|
|
286
|
-
`.trim();async function w6(n,i,e){try{let a=i.middlewares[n];return await a(sa.default(sa.default({},e),{},{meta:i.meta,input:e.input,next(r){var o;let u=r;return w6(n+1,i,sa.default(sa.default({},e),{},{ctx:(u===null||u===void 0?void 0:u.ctx)?sa.default(sa.default({},e.ctx),u.ctx):e.ctx,input:u&&"input"in u?u.input:e.input,getRawInput:(o=u===null||u===void 0?void 0:u.getRawInput)!==null&&o!==void 0?o:e.getRawInput}))}}))}catch(a){return{ok:!1,error:ot(a),marker:h6}}}function men(n){async function i(e){if(!e||!("getRawInput"in e))throw new Error(gen);let a=await w6(0,n,e);if(!a)throw new Xn({code:"INTERNAL_SERVER_ERROR",message:"No result from middlewares - did you forget to `return next()`?"});if(!a.ok)throw a.error;return a.data}return i._def=n,i.procedure=!0,i.meta=n.meta,i}var Jf,qf,nb,g6=typeof window==="undefined"||"Deno"in window||((Jf=globalThis.process)===null||Jf===void 0||(Jf=Jf.env)===null||Jf===void 0?void 0:Jf.NODE_ENV)==="test"||!!((qf=globalThis.process)===null||qf===void 0||(qf=qf.env)===null||qf===void 0?void 0:qf.JEST_WORKER_ID)||!!((nb=globalThis.process)===null||nb===void 0||(nb=nb.env)===null||nb===void 0?void 0:nb.VITEST_WORKER_ID),m6=Ri(Kt(),1),hen=class n{context(){return new n}meta(){return new n}create(i){var e,a,t,r,o,u;let l=m6.default(m6.default({},i),{},{transformer:WM((e=i===null||i===void 0?void 0:i.transformer)!==null&&e!==void 0?e:Kf),isDev:(a=i===null||i===void 0?void 0:i.isDev)!==null&&a!==void 0?a:((t=globalThis.process)===null||t===void 0?void 0:t.env.NODE_ENV)!=="production",allowOutsideOfServer:(r=i===null||i===void 0?void 0:i.allowOutsideOfServer)!==null&&r!==void 0?r:!1,errorFormatter:(o=i===null||i===void 0?void 0:i.errorFormatter)!==null&&o!==void 0?o:Qf,isServer:(u=i===null||i===void 0?void 0:i.isServer)!==null&&u!==void 0?u:g6,$types:null});{var s;if(!((s=i===null||i===void 0?void 0:i.isServer)!==null&&s!==void 0?s:g6)&&(i===null||i===void 0?void 0:i.allowOutsideOfServer)!==!0)throw new Error("You're trying to use @trpc/server in a non-server environment. This is not supported by default.")}return{_config:l,procedure:D6({meta:i===null||i===void 0?void 0:i.defaultMeta}),middleware:len(),router:GT(l),mergeRouters:YM,createCallerFactory:yT()}}},JT=new hen;function Aen(n,i){if("body"in n){if(n.body===void 0)return;if(typeof n.body==="string")return n.body;return JSON.stringify(n.body)}let e=0,a=!1;return new ReadableStream({start(t){let r=(u)=>{if(e+=u.length,!i.maxBodySize||e<=i.maxBodySize){t.enqueue(new Uint8Array(u.buffer,u.byteOffset,u.byteLength));return}t.error(new Xn({code:"PAYLOAD_TOO_LARGE"})),a=!0,n.off("data",r),n.off("end",o)},o=()=>{if(a)return;a=!0,n.off("data",r),n.off("end",o),t.close()};n.on("data",r),n.on("end",o)},cancel(){n.destroy()}})}function qT(n){try{var i,e;let a=n.headers[":scheme"]&&n.headers[":scheme"]==="https"||n.socket&&"encrypted"in n.socket&&n.socket.encrypted?"https:":"http:",t=(i=(e=n.headers.host)!==null&&e!==void 0?e:n.headers[":authority"])!==null&&i!==void 0?i:"localhost";return new URL(n.url,`${a}//${t}`)}catch(a){throw new Xn({code:"BAD_REQUEST",message:"Invalid URL",cause:a})}}function Den(n){let i=new Headers;for(let e in n){let a=n[e];if(typeof e==="string"&&e.startsWith(":"))continue;if(Array.isArray(a))for(let t of a)i.append(e,t);else if(a!=null)i.append(e,a)}return i}function wen(n,i,e){let a=new AbortController,t=()=>{i.off("close",t),n.off("aborted",t),a.abort()};i.once("close",t),n.once("aborted",t);let r=qT(n),o={headers:Den(n.headers),method:n.method,signal:a.signal};if(n.method!=="GET"&&n.method!=="HEAD")o.body=Aen(n,e),o.duplex="half";return new Request(r,o)}async function ven(n,i){if(n.write(i)===!1)await new Promise((e,a)=>{let t=(u)=>{a(u),o()},r=()=>{e(),o()},o=()=>{n.off("error",t),n.off("drain",r)};n.once("error",t),n.once("drain",r)})}async function Ren(n){let{res:i}=n;try{let e=new WritableStream({async write(a){var t;await ven(i,a),(t=i.flush)===null||t===void 0||t.call(i)}});await n.body.pipeTo(e,{signal:n.signal})}catch(e){if(ZT(e))return;throw e}}async function Ten(n){let{response:i,rawResponse:e}=n;if(e.statusCode===200)e.statusCode=i.status;for(let[a,t]of i.headers)e.setHeader(a,t);try{if(i.body)await Ren({res:e,signal:n.request.signal,body:i.body})}catch(a){if(!e.headersSent)e.statusCode=500;throw a}finally{e.end()}}var ib=Ri(Kt(),1);function n_(n){return(i)=>{var e;let{res:a,req:t}=n,r=ot(i),o=fs({config:n.router._def._config,error:r,type:"unknown",path:void 0,input:void 0,ctx:void 0});(e=n.onError)===null||e===void 0||e.call(n,{req:t,error:r,type:"unknown",path:void 0,input:void 0,ctx:void 0});let u=kp(n.router._def._config,{error:o});a.statusCode=o.data.httpStatus,a.end(JSON.stringify(u))}}async function v6(n){return new Promise((i)=>{var e;let a=(e=n.middleware)!==null&&e!==void 0?e:(t,r,o)=>o();return n.res.once("finish",()=>{i()}),a(n.req,n.res,(t)=>{ds(async()=>{var r;let o=wen(n.req,n.res,{maxBodySize:(r=n.maxBodySize)!==null&&r!==void 0?r:null}),u=async(s)=>{var c;return await((c=n.createContext)===null||c===void 0?void 0:c.call(n,ib.default(ib.default({},n),s)))},l=await b6(ib.default(ib.default({},n),{},{req:o,error:t?ot(t):null,createContext:u,onError(s){var c;n===null||n===void 0||(c=n.onError)===null||c===void 0||c.call(n,ib.default(ib.default({},s),{},{req:n.req}))}}));await Ten({request:o,response:l,rawResponse:n.res})}).catch(n_(n))})})}var i_=Ri(Kt(),1);function _en(n){var i;let a=((i=n.basePath)!==null&&i!==void 0?i:"/").length;return(t,r)=>{let o="";ds(async()=>{o=qT(t).pathname.slice(a),await v6(i_.default(i_.default({},n),{},{req:t,res:r,path:o}))}).catch(n_(i_.default({req:t,res:r,path:o},n)))}}function R6(n){return _en(n)}var T6=(n,i,e=Mi.STORE)=>{return e_(e,{key:`${n.key}:JSON`,get:({get:a})=>i.toJson(a(n)),set:({set:a},t)=>{a(n,i.fromJson(t))}})};function _6(n,i,e){return HD(n,{key:`${i.key}:JSON`,get:(t)=>({get:r})=>{let o=r(i,t);return e.toJson(o)},set:(t)=>({set:r},o)=>{r(i,t,e.fromJson(o))}},["mutable","json"])}var jt=(n)=>JSON.parse(n),ee=(n)=>JSON.stringify(n),xFn=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];var Rr=class n extends Set{mode="record";subject=new Xi;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(i,e=0){super(i);if(i instanceof n)this.parent=i,this.cacheUpdateNumber=i.cacheUpdateNumber;if(e)this.cacheLimit=e,this.cache=new Array(e),this.subscribe("auto cache",(a)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=a})}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(i){let e=new n(i.members,i.cacheLimit);return e.cache=i.cache,e.cacheIdx=i.cacheIdx,e.cacheUpdateNumber=i.cacheUpdateNumber,e}add(i){let e=super.add(i);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${ee(i)}`);return e}clear(){let i=this.mode==="record"?[...this]:null;if(super.clear(),i)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(i)}`)}delete(i){let e=super.delete(i);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${ee(i)}`);return e}parent=null;child=null;transactionUpdates=null;transaction(i){this.mode="transaction",this.transactionUpdates=[],this.child=new n(this);let e=this.child._subscribe("transaction",(a)=>{this.transactionUpdates?.push(a)});try{if(i(this.child)){for(let t of this.transactionUpdates)this.doStep(t);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(a){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",a),a}finally{e(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(i,e){return this.subject.subscribe(i,e)}subscribe(i,e){return this.subject.subscribe(i,(a)=>{e(`${this.cacheUpdateNumber}=${a}`)})}emit(i){this.subject.next(i)}doStep(i){let e=i.indexOf(":"),a=i.substring(0,e),t=i.substring(e+1);switch(a){case"add":this.add(JSON.parse(t));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(t));break;case"tx":for(let r of t.split(";"))this.doStep(r)}}getUpdateNumber(i){let e=i.indexOf("=");return Number(i.substring(0,e))}do(i){let e=i.indexOf("="),a=Number(i.substring(0,e)),t=a-this.cacheUpdateNumber;if(t>0){if(t===1){this.mode="playback";let o=i.substring(e+1);return this.doStep(o),this.mode="record",this.cacheUpdateNumber=a,null}return this.cacheUpdateNumber+1}if(Math.abs(t)<this.cacheLimit){let o=this.cacheIdx+t;if(this.cache[o]===i)return null;this.mode="playback";let l=!1;while(!l){this.cacheIdx%=this.cacheLimit;let c=this.cache[this.cacheIdx];if(this.cacheIdx--,!c)return"OUT_OF_RANGE";this.undo(c),l=this.cacheIdx===o-1}let s=i.substring(e+1);return this.doStep(s),this.mode="record",this.cacheUpdateNumber=a,null}return"OUT_OF_RANGE"}undoStep(i){let e=i.indexOf(":"),a=i.substring(0,e),t=i.substring(e+1);switch(a){case"add":this.delete(JSON.parse(t));break;case"del":this.add(JSON.parse(t));break;case"clear":{let r=JSON.parse(t);for(let o of r)this.add(o);break}case"tx":{let r=t.split(";");for(let o=r.length-1;o>=0;o--)this.undoStep(r[o])}}}undo(i){let e=i.indexOf("=");if(Number(i.substring(0,e))===this.cacheUpdateNumber){this.mode="playback";let t=i.substring(e+1);return this.undoStep(t),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function C6(n=Math.random){return n().toString(36).slice(2)}var a_=class extends Promise{fate;resolve;reject;done=!1;constructor(n){let i,e;super((a,t)=>{i=a,e=t});this.resolve=i,this.reject=e,this.use(n instanceof Promise?n:new Promise(n))}pass(n,i){if(n===this.fate)this.resolve(i),this.done=!0}fail(n,i){if(n===this.fate)this.reject(i),this.done=!0}use(n){if(n instanceof Promise){let i=n;this.fate=i,i.then((e)=>{this.pass(i,e)},(e)=>{this.fail(i,e)})}else this.resolve(n),this.fate=void 0}};function ni(n){while(n.child!==null)n=n.child;return n}var Nen=class n{_buffer;_index=0;constructor(i){let e;if(typeof i==="number")e=i;else e=i.length;this._buffer=Array.from({length:e})}get buffer(){return this._buffer}get index(){return this._index}add(i){this._buffer[this._index]=i,this._index=(this._index+1)%this._buffer.length}copy(){let i=new n([...this._buffer]);return i._index=this._index,i}},Sen={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function Fen(n,i){let e=ee(i),a=`${n.key}(${e})`,t=Sen[n.type],r={key:a,type:t};return Object.assign(r,{family:{key:n.key,subKey:e}}),Object.assign(r,{counterfeit:!0}),r}function ab(n){let i={key:n.key,type:n.type};if("family"in n)i.family=n.family;return i}var Pa=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(n,i)=>`${n}:${i}`;warn;getRelatedKeys(n){return this.relations.get(n)}addRelation(n,i){let e=this.relations.get(n),a=this.relations.get(i);if(e)e.add(i);else e=new Set([i]),this.relations.set(n,e);if(a)a.add(n);else a=new Set([n]),this.relations.set(i,a)}deleteRelation(n,i){let e=this.relations.get(n);if(e){if(e.delete(i),e.size===0)this.relations.delete(n);let a=this.relations.get(i);if(a){if(a.delete(n),a.size===0)this.relations.delete(i)}}}replaceRelationsUnsafely(n,i){this.relations.set(n,new Set(i));for(let e of i){let a=new Set().add(n);this.relations.set(e,a)}}replaceRelationsSafely(n,i){let e=this.relations.get(n),a=this.isAType?.(n)?n:void 0,t=a===void 0?n:void 0;if(e)for(let r of e){a??=r,t??=r;let o=this.relations.get(r);if(o){if(o.size===1)this.relations.delete(r);else o.delete(n);this.contents.delete(this.makeContentKey(a,t))}}this.relations.set(n,new Set(i));for(let r of i){let o=this.relations.get(r);if(o)o.add(n);else o=new Set().add(n),this.relations.set(r,o)}}getContentInternal(n){return this.contents.get(n)}setContent(n,i){this.contents.set(n,i)}deleteContent(n){this.contents.delete(n)}constructor(n,i){if(this.a=n.between[0],this.b=n.between[1],this.cardinality=n.cardinality,!i?.externalStore)this.relations=new Map(n.relations?.map(([e,a])=>[e,new Set(a)])),this.contents=new Map(n.contents);if(this.isAType=i?.isAType??null,this.isBType=i?.isBType??null,this.isContent=i?.isContent??null,i?.makeContentKey)this.makeContentKey=i.makeContentKey;if(i?.externalStore){let e=i.externalStore;if(this.has=(a,t)=>e.has(a,t),this.addRelation=(a,t)=>{e.addRelation(a,t)},this.deleteRelation=(a,t)=>{e.deleteRelation(a,t)},this.replaceRelationsSafely=(a,t)=>{e.replaceRelationsSafely(a,t)},this.replaceRelationsUnsafely=(a,t)=>{e.replaceRelationsUnsafely(a,t)},this.getRelatedKeys=(a)=>e.getRelatedKeys(a),e.getContent)this.getContentInternal=(a)=>{return e.getContent(a)},this.setContent=(a,t)=>{e.setContent(a,t)},this.deleteContent=(a)=>{e.deleteContent(a)};for(let[a,t]of n.relations??[]){let r=this.isAType?.(a)?a:void 0,o=r===void 0?a:void 0;for(let u of t)r??=u,o??=u,this.addRelation(r,o)}for(let[a,t]of n.contents??[])this.setContent(a,t)}if(i?.warn)this.warn=i.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([n,i])=>[n,[...i]]),contents:[...this.contents.entries()]}}set(...n){let i,e,a;switch(n.length){case 1:{let t=n[0];i=t[this.a],e=t[this.b],a=void 0;break}case 2:{let t=n[0];if(typeof t==="string")[i,e]=n;else i=t[this.a],e=t[this.b],a=n[1];break}default:{i=n[0],e=n[1],a=n[2];break}}switch(this.cardinality){case"1:1":{let t=this.getRelatedKey(i);if(t&&t!==e)this.delete(i,t)}case"1:n":{let t=this.getRelatedKey(e);if(t&&t!==i)this.delete(t,e)}break;case"n:n":}if(a){let t=this.makeContentKey(i,e);this.setContent(t,a)}return this.addRelation(i,e),this}delete(n,i){i=typeof i==="string"?i:n[this.b];let e=typeof n==="string"?n:n[this.a];if(e===void 0&&typeof i==="string"){let a=this.getRelatedKeys(i);if(a)for(let t of a)this.delete(t,i)}if(typeof e==="string"&&i===void 0){let a=this.getRelatedKeys(e);if(a)for(let t of a)this.delete(e,t)}if(typeof e==="string"&&typeof i==="string"){this.deleteRelation(e,i);let a=this.makeContentKey(e,i);this.deleteContent(a)}return this}getRelatedKey(n){let i=this.getRelatedKeys(n);if(i){if(i.size>1)this.warn?.(`${i.size} related keys were found for key "${n}": (${[...i].map((a)=>`"${a}"`).join(", ")}). Only one related key was expected.`);let e;for(let a of i){e=a;break}return e}}replaceRelations(n,i,e){let a=!Array.isArray(i),t=a?Object.keys(i):i;if(e?.reckless)this.replaceRelationsUnsafely(n,t);else this.replaceRelationsSafely(n,t);if(a)for(let r of t){let o=this.makeContentKey(n,r),u=i[r];this.setContent(o,u)}return this}getContent(n,i){let e=this.makeContentKey(n,i);return this.getContentInternal(e)}getRelationEntries(n){let i=n[this.a],e=n[this.b];if(i!==void 0&&e===void 0){let a=this.getRelatedKeys(i);if(a)return[...a].map((t)=>{return[t,this.getContent(i,t)]})}if(i===void 0&&e!==void 0){let a=this.getRelatedKeys(e);if(a)return[...a].map((t)=>{return[t,this.getContent(t,e)]})}return[]}has(n,i){if(i)return this.getRelatedKeys(n)?.has(i)??!1;return this.relations.has(n)}},Xi=class{Subscriber;subscribers=new Map;subscribe(n,i){return this.subscribers.set(n,i),()=>{this.unsubscribe(n)}}unsubscribe(n){this.subscribers.delete(n)}next(n){let i=this.subscribers.values();for(let e of i)e(n)}},xen=class extends Xi{state;constructor(n){super();this.state=n}next(n){this.state=n,super.next(n)}};function Dc(n){return"epoch"in n.transactionMeta}function Ba(n){return"phase"in n.transactionMeta}var Cen=(n)=>{let i=ni(n);if(!Ba(i)){n.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}n.logger.info("\uD83E\uDE82","transaction",i.transactionMeta.update.key,"Aborting transaction"),i.parent.child=null};function De(n){return n[0].toUpperCase()+n.slice(1)}function Zp(n){return n.type.split("_").map(De).join(" ")}var u_=class extends Error{constructor(n,i){super(`${Zp(n)} ${ee(n.key)} not found in store "${i.config.name}".`)}};function l_(n,i,e){return(...a)=>{let t=qe(n,i);if(t)return t.run(a,e);throw new u_(i,n)}}var s_=(n)=>(i)=>n instanceof Function?n(i):n,WD=(n,i)=>{if(n.valueMap.has(i.key))return n.logger.info("\uD83D\uDCD6",i.type,i.key,"reading cached value"),tan(i,n);switch(i.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return n.logger.info("\uD83E\uDDEE",i.type,i.key,"computing value"),i.get();case"atom":case"mutable_atom":{let e=i.default,a;if(e instanceof Function)a=e();else a=e;return n.logger.info("\uD83D\uDC81","atom",i.key,"could not find cached value; using default",a),a}}},$D=(n,i)=>{if(n.operation.open){let e=performance.now();return n.logger.info("\u2757",i.type,i.key,`deferring setState at T-${e} until setState for "${n.operation.token.key}" is done`),e}n.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:i},n.logger.info("\u2B55",i.type,i.key,`operation start in store "${n.config.name}"${!Ba(n)?"":` ${n.transactionMeta.phase} "${n.transactionMeta.update.key}"`}`)},PD=(n)=>{if(n.operation.open)n.logger.info("\uD83D\uDD34",n.operation.token.type,n.operation.token.key,`operation done in store "${n.config.name}"`);n.operation={open:!1},n.on.operationClose.next(n.operation)},O6=(n,i)=>{if(!n.operation.open)return n.logger.error("\uD83D\uDC1E","unknown",i,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return n.operation.done.has(i)},wm=(n,i)=>{if(!n.operation.open){n.logger.error("\uD83D\uDC1E","unknown",i,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}n.operation.done.add(i)},Oen=(n,i,e)=>{switch(i.type){case"mutable_atom":n.logger.info("\uD83D\uDCE2",i.type,i.key,"is now (",e.newValue,") subscribers:",i.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":n.logger.info("\uD83D\uDCE2",i.type,i.key,"went (",e.oldValue,"->",e.newValue,") subscribers:",i.subject.subscribers)}i.subject.next(e)};function t_(n,i){let e=ni(n),a=e.selectorAtoms.getRelatedKeys(i.key);if(e.logger.info("\uD83E\uDDF9",i.type,i.key,a?`evicting ${a.size} states downstream:`:"no downstream states",a??"to evict"),a){if(e.operation.open)e.logger.info("\uD83E\uDDF9",i.type,i.key,`[ ${[...e.operation.done].join(", ")} ] already done`);for(let t of a){if(O6(e,t))continue;k6(t,e),wm(e,t)}}}function Len(n,i){let e=ni(n),a=e.selectorGraph.getRelationEntries({upstreamSelectorKey:i.key}).filter(([t,{source:r}])=>r===i.key);for(let[t]of a){if(O6(e,t))continue;k6(t,e),wm(e,t)}}var L6=(n,i,e)=>{let a=WD(n,i),t=a;if(i.type==="mutable_atom"&&Ba(n)){let{parent:o}=n;t=o_(n,i,o)}t=s_(e)(t),n.logger.info("\uD83D\uDCDD","atom",i.key,"set to",t),t=vl(n,i.key,t,i.subject),wm(n,i.key),t_(n,i);let r={oldValue:a,newValue:t};if(!Ba(n)){Oen(n,i,r);return}if(n.on.transactionApplying.state===null){let{key:o}=i;if(aan(r.newValue))return;let u={type:"atom_update",key:o,...r};if(i.family)u.family=i.family;n.transactionMeta.update.updates.push(u),n.logger.info("\uD83D\uDCC1","atom",o,"stowed (",r.oldValue,"->",r.newValue,")")}else if(i.key.startsWith("*")){let o=i.key.slice(1),u=n.atoms.get(o),l=n.valueMap.get(o);if(u.type==="mutable_atom"&&Ba(n)){let{parent:c}=n;l=o_(n,u,c)}if(l.do(r.newValue)===null)t_(n,u)}};function N6(n,i){let e=i.default;if(e instanceof Function)e=e();L6(n,i,e)}function Ien(n,i){switch(i.type){case"atom":case"mutable_atom":N6(n,i);break;case"writable_pure_selector":case"writable_held_selector":{let e=U6(i,n);for(let a of e)N6(n,a)}break}}function YD(n,i,e){let a={key:i.key,type:"atom_family"},t=n.families.get(i.key);if(t)n.logger.error("\u2757","atom_family",i.key,`Overwriting an existing ${Zp(t)} "${t.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let r=new Xi,u=Object.assign((l)=>{let s=ee(l),c={key:i.key,subKey:s},f=`${i.key}(${s})`,b=ni(n),g=i.default,m={key:f,default:g instanceof Function?g(l):g};if(i.effects)m.effects=i.effects(l);let h=kD(b,m,c);return r.next({type:"state_creation",token:h}),h},a,{subject:r,install:(l)=>YD(l,i),internalRoles:e});return n.families.set(i.key,u),n.defaults.set(i.key,i.default),a}function I6(n,i){if("mutable"in i)return h_(n,i);return YD(n,i)}var c_=(n,i)=>ni(n).atoms.has(i),Men=(n,i)=>ni(n).writableSelectors.has(i),Uen=(n,i)=>ni(n).readonlySelectors.has(i),Gen=(n,i)=>c_(n,i)||Men(n,i)||Uen(n,i),r_=(n,i)=>{return ni(n).selectorGraph.getRelationEntries({downstreamSelectorKey:i}).filter(([a,{source:t}])=>t!==i).map(([a,{source:t}])=>t).filter((a)=>Gen(n,a))},M6=(n,i,e)=>{let a=[],t=r_(n,i);while(t.length>0){let r=t.shift();if(e.has(r))continue;if(e.add(r),!c_(n,r))t.push(...r_(n,r));else if(!a.includes(r))a.push(r)}return a},U6=(n,i)=>{let e=n.key,a=r_(i,e),t=new Set;return a.flatMap((r)=>c_(i,r)?r:M6(i,r,t)).map((r)=>i.atoms.get(r))},yen=(n,i,e,a,t)=>{let r=ni(n),{type:o,key:u}=a;if(o==="atom"||o==="mutable_atom")r.selectorAtoms.set({selectorKey:e,atomKey:u}),n.logger.info("\uD83D\uDD0D",i,e,`discovers root atom "${u}"`);else{let l=M6(n,u,t);n.logger.info("\uD83D\uDD0D",i,e,`discovers root atoms: [ ${l.map((s)=>`"${s}"`).join(", ")} ]`);for(let s of l)r.selectorAtoms=r.selectorAtoms.set({selectorKey:e,atomKey:s})}t.add(u)},VD=(n,i,e,a)=>({get:(...t)=>{let r=ni(n),o;if(t.length===2){let[c,f]=t;o=Ui(n,c,f)}else[o]=t;let u=qe(n,o),l=WD(n,u),s=o.key;return n.logger.info("\uD83D\uDD0C",i,e,`registers dependency ( "${s}" =`,l,")"),r.selectorGraph.set({upstreamSelectorKey:s,downstreamSelectorKey:e},{source:o.key}),yen(n,i,e,o,a),l},set:(...t)=>{let r,o;if(t.length===2)r=t[0],o=t[1];else{let s=t[0],c=t[1];o=t[2],r=Ui(n,s,c)}let u=ni(n),l=qe(u,r);$6(u,l,o)},find:(...t)=>Ui(n,...t),json:(t)=>Qp(n,t)}),p_=(n,i,e)=>{let a=ni(n),t=new Xi,r=new Set,{key:o,const:u}=i,l="readonly_held_selector",{get:s,find:c,json:f}=VD(a,"readonly_held_selector",o,r),g={...i,type:"readonly_held_selector",subject:t,install:(h)=>p_(h,i,e),get:()=>{return i.get({get:s,find:c,json:f},u),vl(ni(n),o,u,t),r.clear(),u},...e&&{family:e}};a.readonlySelectors.set(o,g),n.logger.info("\u2728","readonly_held_selector",o,"=",u);let m={key:o,type:"readonly_held_selector"};if(e)m.family=e;return m},d_=(n,i,e)=>{let a=ni(n),t=new Xi,r=new Set,o=i.key,u="readonly_pure_selector",{get:l,find:s,json:c}=VD(a,"readonly_pure_selector",o,r),f=()=>{let h=i.get({get:l,find:s,json:c});return vl(ni(n),o,h,t),r.clear(),h},b={...i,type:"readonly_pure_selector",subject:t,install:(h)=>d_(h,i,e),get:f,...e&&{family:e}};a.readonlySelectors.set(o,b);let g=f();n.logger.info("\u2728","readonly_pure_selector",o,"=",g);let m={key:o,type:"readonly_pure_selector"};if(e)m.family=e;return m},f_=(n,i,e)=>{let a=ni(n),t=new Xi,r=new Set,{key:o,const:u}=i,l="writable_held_selector",s=VD(a,"writable_held_selector",o,r),{find:c,get:f,json:b}=s,g={find:c,get:f,json:b},m=(S=i.get,x=ni(n))=>{return S(g,u),vl(x,o,u,t),r.clear(),u},D={...i,type:"writable_held_selector",subject:t,install:(S)=>f_(S,i,e),get:m,set:(S)=>{let x=ni(n),N=m(i.get,x),I=s_(S)(N);if(n.logger.info("\uD83D\uDCDD","writable_held_selector",o,"set (",N,"->",I,")"),vl(x,o,I,t),wm(x,o),Dc(x))t.next({newValue:I,oldValue:N});i.set(s,I)},...e&&{family:e}};a.writableSelectors.set(o,D);let T=m();n.logger.info("\u2728","writable_held_selector",o,"=",T);let v={key:o,type:"writable_held_selector"};if(e)v.family=e;return v},b_=(n,i,e)=>{let a=ni(n),t=new Xi,r=new Set,o=i.key,u="writable_pure_selector",l=VD(a,"writable_pure_selector",o,r),{find:s,get:c,json:f}=l,b={find:s,get:c,json:f},g=(v=i.get,S=ni(n))=>{let x=v(b);return vl(S,o,x,t),r.clear(),x},h={...i,type:"writable_pure_selector",subject:t,install:(v)=>b_(v,i,e),get:g,set:(v)=>{let S=ni(n),x=g(i.get,S),N=s_(v)(x);if(n.logger.info("\uD83D\uDCDD","writable_pure_selector",o,"set (",x,"->",N,")"),vl(S,i.key,N,t),wm(S,i.key),Dc(S))t.next({newValue:N,oldValue:x});i.set(l,N)},...e&&{family:e}};a.writableSelectors.set(o,h);let D=g();n.logger.info("\u2728",h.type,h.key,"=",D);let T={key:o,type:"writable_pure_selector"};if(e)T.family=e;return T};function e_(n,i){let e="set"in i,a="const"in i;if(a&&e){let r=f_(n,i,void 0);return n.on.selectorCreation.next(r),r}if(a){let r=p_(n,i,void 0);return n.on.selectorCreation.next(r),r}if(e){let r=b_(n,i,void 0);return n.on.selectorCreation.next(r),r}let t=d_(n,i,void 0);return n.on.selectorCreation.next(t),t}function zen(n,i){let e=ni(n),{key:a,type:t}=i,r=qe(e,i);if(!r.family)n.logger.error("\u274C",t,a,"Standalone selectors cannot be disposed.");else{if(e.molecules.get(r.family.subKey))e.moleculeData.delete(r.family.subKey,r.family.key);let u;switch(i.type){case"writable_held_selector":e.writableSelectors.delete(a),u={key:r.family.key,type:"writable_held_selector_family"},qe(n,u).subject.next({type:"state_disposal",subType:"selector",token:i});break;case"writable_pure_selector":e.writableSelectors.delete(a),u={key:r.family.key,type:"writable_pure_selector_family"},qe(n,u).subject.next({type:"state_disposal",subType:"selector",token:i});break;case"readonly_held_selector":e.readonlySelectors.delete(a),u={key:r.family.key,type:"readonly_held_selector_family"},qe(n,u).subject.next({type:"state_disposal",subType:"selector",token:i});break;case"readonly_pure_selector":e.readonlySelectors.delete(a),u={key:r.family.key,type:"readonly_pure_selector_family"},qe(n,u).subject.next({type:"state_disposal",subType:"selector",token:i});break}if(e.valueMap.delete(a),e.selectorAtoms.delete(a),e.selectorGraph.delete(a),n.logger.info("\uD83D\uDD25",i.type,a,"deleted"),Ba(e)&&e.transactionMeta.phase==="building")e.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:i});else n.on.selectorDisposal.next(i)}}function eb(n,i,e){let a=i.key,t="readonly_pure_selector_family",r={key:a,type:"readonly_pure_selector_family"},o=n.families.get(a);if(o)n.logger.error("\u2757","readonly_pure_selector_family",a,`Overwriting an existing ${Zp(o)} "${o.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let u=new Xi,s=Object.assign((c)=>{let f=ee(c),b={key:a,subKey:f},g=`${a}(${f})`,m=ni(n),h=d_(m,{key:g,get:i.get(c)},b);return u.next({type:"state_creation",token:h}),h},r,{internalRoles:e,subject:u,install:(c)=>eb(c,i),default:(c)=>{return i.get(c)({get:(...b)=>Tr(n,...b),find:(...b)=>Ui(n,...b),json:(b)=>Qp(n,b)})}});return n.families.set(a,s),r}function G6(n,i,e){let a=i.key,t="readonly_held_selector_family",r={key:a,type:"readonly_held_selector_family"},o=n.families.get(a);if(o)n.logger.error("\u2757","readonly_held_selector_family",a,`Overwriting an existing ${Zp(o)} "${o.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let u=new Xi,s=Object.assign((c)=>{let f=ee(c),b={key:a,subKey:f},g=`${a}(${f})`,m=ni(n),h=p_(m,{key:g,const:i.const(c),get:i.get(c)},b);return u.next({type:"state_creation",token:h}),h},r,{internalRoles:e,subject:u,install:(c)=>G6(c,i),default:i.const});return n.families.set(a,s),r}function y6(n,i,e){let a=i.key,t="writable_held_selector_family",r={key:a,type:"writable_held_selector_family"},o=n.families.get(a);if(o)n.logger.error("\u2757","writable_held_selector_family",a,`Overwriting an existing ${Zp(o)} "${o.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let u=new Xi,s=Object.assign((c)=>{let f=ee(c),b={key:a,subKey:f},g=`${a}(${f})`,m=ni(n),h=f_(m,{key:g,const:i.const(c),get:i.get(c),set:i.set(c)},b);return u.next({type:"state_creation",token:h}),h},r,{internalRoles:e,subject:u,install:(c)=>y6(c,i),default:i.const});return n.families.set(a,s),r}function HD(n,i,e){let a=i.key,t="writable_pure_selector_family",r={key:a,type:"writable_pure_selector_family"},o=n.families.get(a);if(o)n.logger.error("\u2757","writable_pure_selector_family",a,`Overwriting an existing ${Zp(o)} "${o.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let u=new Xi,s=Object.assign((c)=>{let f=ee(c),b={key:a,subKey:f},g=`${a}(${f})`,m=ni(n),h=b_(m,{key:g,get:i.get(c),set:i.set(c)},b);return u.next({type:"state_creation",token:h}),h},r,{internalRoles:e,subject:u,install:(c)=>HD(c,i),default:(c)=>{return i.get(c)({get:(...b)=>Tr(n,...b),find:(...b)=>Ui(n,...b),json:(b)=>Qp(n,b)})}});return n.families.set(a,s),r}function z6(n,i){let e="set"in i,a="const"in i;if(a&&e)return y6(n,i,void 0);if(a)return G6(n,i,void 0);if(e)return HD(n,i);return eb(n,i)}function Hen(n,i,e){let a=n.families.get(i.key);if(a===void 0)throw new u_(i,n);let t=a(e),r=ni(n);if(t.family){if(Dc(r))switch(t.type){case"atom":case"mutable_atom":n.on.atomCreation.next(t);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":n.on.selectorCreation.next(t);break}else if(Ba(r)&&r.on.transactionApplying.state===null)r.transactionMeta.update.updates.push({type:"state_creation",token:t})}return t}function $en(n,i,e){let a=ee(e),t=`${i.key}(${a})`,r=ni(n),o;switch(i.type){case"atom_family":case"mutable_atom_family":o=r.atoms.get(t);break;case"writable_held_selector_family":case"writable_pure_selector_family":o=r.writableSelectors.get(t);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":o=r.readonlySelectors.get(t);break}if(o)return ab(o);return o}function Ui(n,i,e){let a=$en(n,i,e);if(a)return a;let t=ee(e),r=n.molecules.get(t);if(!r&&n.config.lifespan==="immortal"){let o=Fen(i,e);return n.logger.error("\u274C",o.type,o.key,`was not found in store "${n.config.name}"; returned a counterfeit token.`),o}if(a=Hen(n,i,e),r)ni(n).moleculeData.set(t,i.key);return a}function tb(n,...i){let e;if(i.length===1)e=i[0];else{let a=i[0],t=i[1];e=Ui(n,a,t)}try{qe(n,e)}catch(a){n.logger.error("\u274C",e.type,e.key,`could not be disposed because it was not found in the store "${n.config.name}".`);return}switch(e.type){case"atom":case"mutable_atom":Q6(n,e);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":zen(n,e);break}}function H6(n,i){if(i.family){let e=n.families.get(i.family.key);if(e)return e}}function XD(n,...i){let e,a,t;if(i.length===1){if(e=i[0],a=H6(n,e)??null,a)t=e.family?jt(e.family.subKey):null,e=Ui(n,a,t)}else a=i[0],t=i[1],e=Ui(n,a,t);if("counterfeit"in e&&"family"in e){let u=e.family.subKey,l=n.disposalTraces.buffer.find((s)=>s?.key===u);n.logger.error("\u274C",e.type,e.key,`could not be reset because it was not found in the store "${n.config.name}".`,l?`This state was previously disposed:
|
|
286
|
+
`.trim();async function w6(n,i,e){try{let a=i.middlewares[n];return await a(sa.default(sa.default({},e),{},{meta:i.meta,input:e.input,next(r){var o;let u=r;return w6(n+1,i,sa.default(sa.default({},e),{},{ctx:(u===null||u===void 0?void 0:u.ctx)?sa.default(sa.default({},e.ctx),u.ctx):e.ctx,input:u&&"input"in u?u.input:e.input,getRawInput:(o=u===null||u===void 0?void 0:u.getRawInput)!==null&&o!==void 0?o:e.getRawInput}))}}))}catch(a){return{ok:!1,error:ot(a),marker:h6}}}function men(n){async function i(e){if(!e||!("getRawInput"in e))throw new Error(gen);let a=await w6(0,n,e);if(!a)throw new Xn({code:"INTERNAL_SERVER_ERROR",message:"No result from middlewares - did you forget to `return next()`?"});if(!a.ok)throw a.error;return a.data}return i._def=n,i.procedure=!0,i.meta=n.meta,i}var Jf,qf,nb,g6=typeof window==="undefined"||"Deno"in window||((Jf=globalThis.process)===null||Jf===void 0||(Jf=Jf.env)===null||Jf===void 0?void 0:Jf.NODE_ENV)==="test"||!!((qf=globalThis.process)===null||qf===void 0||(qf=qf.env)===null||qf===void 0?void 0:qf.JEST_WORKER_ID)||!!((nb=globalThis.process)===null||nb===void 0||(nb=nb.env)===null||nb===void 0?void 0:nb.VITEST_WORKER_ID),m6=Ri(Kt(),1),hen=class n{context(){return new n}meta(){return new n}create(i){var e,a,t,r,o,u;let l=m6.default(m6.default({},i),{},{transformer:WM((e=i===null||i===void 0?void 0:i.transformer)!==null&&e!==void 0?e:Kf),isDev:(a=i===null||i===void 0?void 0:i.isDev)!==null&&a!==void 0?a:((t=globalThis.process)===null||t===void 0?void 0:t.env.NODE_ENV)!=="production",allowOutsideOfServer:(r=i===null||i===void 0?void 0:i.allowOutsideOfServer)!==null&&r!==void 0?r:!1,errorFormatter:(o=i===null||i===void 0?void 0:i.errorFormatter)!==null&&o!==void 0?o:Qf,isServer:(u=i===null||i===void 0?void 0:i.isServer)!==null&&u!==void 0?u:g6,$types:null});{var s;if(!((s=i===null||i===void 0?void 0:i.isServer)!==null&&s!==void 0?s:g6)&&(i===null||i===void 0?void 0:i.allowOutsideOfServer)!==!0)throw new Error("You're trying to use @trpc/server in a non-server environment. This is not supported by default.")}return{_config:l,procedure:D6({meta:i===null||i===void 0?void 0:i.defaultMeta}),middleware:len(),router:GT(l),mergeRouters:YM,createCallerFactory:yT()}}},JT=new hen;function Aen(n,i){if("body"in n){if(n.body===void 0)return;if(typeof n.body==="string")return n.body;return JSON.stringify(n.body)}let e=0,a=!1;return new ReadableStream({start(t){let r=(u)=>{if(e+=u.length,!i.maxBodySize||e<=i.maxBodySize){t.enqueue(new Uint8Array(u.buffer,u.byteOffset,u.byteLength));return}t.error(new Xn({code:"PAYLOAD_TOO_LARGE"})),a=!0,n.off("data",r),n.off("end",o)},o=()=>{if(a)return;a=!0,n.off("data",r),n.off("end",o),t.close()};n.on("data",r),n.on("end",o)},cancel(){n.destroy()}})}function qT(n){try{var i,e;let a=n.headers[":scheme"]&&n.headers[":scheme"]==="https"||n.socket&&"encrypted"in n.socket&&n.socket.encrypted?"https:":"http:",t=(i=(e=n.headers.host)!==null&&e!==void 0?e:n.headers[":authority"])!==null&&i!==void 0?i:"localhost";return new URL(n.url,`${a}//${t}`)}catch(a){throw new Xn({code:"BAD_REQUEST",message:"Invalid URL",cause:a})}}function Den(n){let i=new Headers;for(let e in n){let a=n[e];if(typeof e==="string"&&e.startsWith(":"))continue;if(Array.isArray(a))for(let t of a)i.append(e,t);else if(a!=null)i.append(e,a)}return i}function wen(n,i,e){let a=new AbortController,t=()=>{i.off("close",t),n.off("aborted",t),a.abort()};i.once("close",t),n.once("aborted",t);let r=qT(n),o={headers:Den(n.headers),method:n.method,signal:a.signal};if(n.method!=="GET"&&n.method!=="HEAD")o.body=Aen(n,e),o.duplex="half";return new Request(r,o)}async function ven(n,i){if(n.write(i)===!1)await new Promise((e,a)=>{let t=(u)=>{a(u),o()},r=()=>{e(),o()},o=()=>{n.off("error",t),n.off("drain",r)};n.once("error",t),n.once("drain",r)})}async function Ren(n){let{res:i}=n;try{let e=new WritableStream({async write(a){var t;await ven(i,a),(t=i.flush)===null||t===void 0||t.call(i)}});await n.body.pipeTo(e,{signal:n.signal})}catch(e){if(ZT(e))return;throw e}}async function Ten(n){let{response:i,rawResponse:e}=n;if(e.statusCode===200)e.statusCode=i.status;for(let[a,t]of i.headers)e.setHeader(a,t);try{if(i.body)await Ren({res:e,signal:n.request.signal,body:i.body})}catch(a){if(!e.headersSent)e.statusCode=500;throw a}finally{e.end()}}var ib=Ri(Kt(),1);function n_(n){return(i)=>{var e;let{res:a,req:t}=n,r=ot(i),o=fs({config:n.router._def._config,error:r,type:"unknown",path:void 0,input:void 0,ctx:void 0});(e=n.onError)===null||e===void 0||e.call(n,{req:t,error:r,type:"unknown",path:void 0,input:void 0,ctx:void 0});let u=kp(n.router._def._config,{error:o});a.statusCode=o.data.httpStatus,a.end(JSON.stringify(u))}}async function v6(n){return new Promise((i)=>{var e;let a=(e=n.middleware)!==null&&e!==void 0?e:(t,r,o)=>o();return n.res.once("finish",()=>{i()}),a(n.req,n.res,(t)=>{ds(async()=>{var r;let o=wen(n.req,n.res,{maxBodySize:(r=n.maxBodySize)!==null&&r!==void 0?r:null}),u=async(s)=>{var c;return await((c=n.createContext)===null||c===void 0?void 0:c.call(n,ib.default(ib.default({},n),s)))},l=await b6(ib.default(ib.default({},n),{},{req:o,error:t?ot(t):null,createContext:u,onError(s){var c;n===null||n===void 0||(c=n.onError)===null||c===void 0||c.call(n,ib.default(ib.default({},s),{},{req:n.req}))}}));await Ten({request:o,response:l,rawResponse:n.res})}).catch(n_(n))})})}var i_=Ri(Kt(),1);function _en(n){var i;let a=((i=n.basePath)!==null&&i!==void 0?i:"/").length;return(t,r)=>{let o="";ds(async()=>{o=qT(t).pathname.slice(a),await v6(i_.default(i_.default({},n),{},{req:t,res:r,path:o}))}).catch(n_(i_.default({req:t,res:r,path:o},n)))}}function R6(n){return _en(n)}var T6=(n,i,e=Mi.STORE)=>{return e_(e,{key:`${n.key}:JSON`,get:({get:a})=>i.toJson(a(n)),set:({set:a},t)=>{a(n,i.fromJson(t))}})};function _6(n,i,e){return HD(n,{key:`${i.key}:JSON`,get:(t)=>({get:r})=>{let o=r(i,t);return e.toJson(o)},set:(t)=>({set:r},o)=>{r(i,t,e.fromJson(o))}},["mutable","json"])}var jt=(n)=>JSON.parse(n),ee=(n)=>JSON.stringify(n),xFn=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];var Rr=class n extends Set{mode="record";subject=new Xi;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(i,e=0){super(i);if(i instanceof n)this.parent=i,this.cacheUpdateNumber=i.cacheUpdateNumber;if(e)this.cacheLimit=e,this.cache=new Array(e),this.subscribe("auto cache",(a)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=a})}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(i){let e=new n(i.members,i.cacheLimit);return e.cache=i.cache,e.cacheIdx=i.cacheIdx,e.cacheUpdateNumber=i.cacheUpdateNumber,e}add(i){let e=super.add(i);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${ee(i)}`);return e}clear(){let i=this.mode==="record"?[...this]:null;if(super.clear(),i)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(i)}`)}delete(i){let e=super.delete(i);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${ee(i)}`);return e}parent=null;child=null;transactionUpdates=null;transaction(i){this.mode="transaction",this.transactionUpdates=[],this.child=new n(this);let e=this.child._subscribe("transaction",(a)=>{this.transactionUpdates?.push(a)});try{if(i(this.child)){for(let t of this.transactionUpdates)this.doStep(t);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(a){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",a),a}finally{e(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(i,e){return this.subject.subscribe(i,e)}subscribe(i,e){return this.subject.subscribe(i,(a)=>{e(`${this.cacheUpdateNumber}=${a}`)})}emit(i){this.subject.next(i)}doStep(i){let e=i.indexOf(":"),a=i.substring(0,e),t=i.substring(e+1);switch(a){case"add":this.add(JSON.parse(t));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(t));break;case"tx":for(let r of t.split(";"))this.doStep(r)}}getUpdateNumber(i){let e=i.indexOf("=");return Number(i.substring(0,e))}do(i){let e=i.indexOf("="),a=Number(i.substring(0,e)),t=a-this.cacheUpdateNumber;if(t>0){if(t===1){this.mode="playback";let o=i.substring(e+1);return this.doStep(o),this.mode="record",this.cacheUpdateNumber=a,null}return this.cacheUpdateNumber+1}if(Math.abs(t)<this.cacheLimit){let o=this.cacheIdx+t;if(this.cache[o]===i)return null;this.mode="playback";let l=!1;while(!l){this.cacheIdx%=this.cacheLimit;let c=this.cache[this.cacheIdx];if(this.cacheIdx--,!c)return"OUT_OF_RANGE";this.undo(c),l=this.cacheIdx===o-1}let s=i.substring(e+1);return this.doStep(s),this.mode="record",this.cacheUpdateNumber=a,null}return"OUT_OF_RANGE"}undoStep(i){let e=i.indexOf(":"),a=i.substring(0,e),t=i.substring(e+1);switch(a){case"add":this.delete(JSON.parse(t));break;case"del":this.add(JSON.parse(t));break;case"clear":{let r=JSON.parse(t);for(let o of r)this.add(o);break}case"tx":{let r=t.split(";");for(let o=r.length-1;o>=0;o--)this.undoStep(r[o])}}}undo(i){let e=i.indexOf("=");if(Number(i.substring(0,e))===this.cacheUpdateNumber){this.mode="playback";let t=i.substring(e+1);return this.undoStep(t),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function C6(n=Math.random){return n().toString(36).slice(2)}var a_=class extends Promise{fate;resolve;reject;done=!1;constructor(n){let i,e;super((a,t)=>{i=a,e=t});this.resolve=i,this.reject=e,this.use(n instanceof Promise?n:new Promise(n))}pass(n,i){if(n===this.fate)this.resolve(i),this.done=!0}fail(n,i){if(n===this.fate)this.reject(i),this.done=!0}use(n){if(n instanceof Promise){let i=n;this.fate=i,i.then((e)=>{this.pass(i,e)},(e)=>{this.fail(i,e)})}else this.resolve(n),this.fate=void 0}};function ni(n){while(n.child!==null)n=n.child;return n}var Nen=class n{_buffer;_index=0;constructor(i){let e;if(typeof i==="number")e=i;else e=i.length;this._buffer=Array.from({length:e})}get buffer(){return this._buffer}get index(){return this._index}add(i){this._buffer[this._index]=i,this._index=(this._index+1)%this._buffer.length}copy(){let i=new n([...this._buffer]);return i._index=this._index,i}},Sen={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function Fen(n,i){let e=ee(i),a=`${n.key}(${e})`,t=Sen[n.type],r={key:a,type:t};return Object.assign(r,{family:{key:n.key,subKey:e}}),Object.assign(r,{counterfeit:!0}),r}function ab(n){let i={key:n.key,type:n.type};if("family"in n)i.family=n.family;return i}var Pa=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(n,i)=>`${n}:${i}`;warn;getRelatedKeys(n){return this.relations.get(n)}addRelation(n,i){let e=this.relations.get(n),a=this.relations.get(i);if(e)e.add(i);else e=new Set([i]),this.relations.set(n,e);if(a)a.add(n);else a=new Set([n]),this.relations.set(i,a)}deleteRelation(n,i){let e=this.relations.get(n);if(e){if(e.delete(i),e.size===0)this.relations.delete(n);let a=this.relations.get(i);if(a){if(a.delete(n),a.size===0)this.relations.delete(i)}}}replaceRelationsUnsafely(n,i){this.relations.set(n,new Set(i));for(let e of i){let a=new Set().add(n);this.relations.set(e,a)}}replaceRelationsSafely(n,i){let e=this.relations.get(n),a=this.isAType?.(n)?n:void 0,t=a===void 0?n:void 0;if(e)for(let r of e){a??=r,t??=r;let o=this.relations.get(r);if(o){if(o.size===1)this.relations.delete(r);else o.delete(n);this.contents.delete(this.makeContentKey(a,t))}}this.relations.set(n,new Set(i));for(let r of i){let o=this.relations.get(r);if(o)o.add(n);else o=new Set().add(n),this.relations.set(r,o)}}getContentInternal(n){return this.contents.get(n)}setContent(n,i){this.contents.set(n,i)}deleteContent(n){this.contents.delete(n)}constructor(n,i){if(this.a=n.between[0],this.b=n.between[1],this.cardinality=n.cardinality,!i?.externalStore)this.relations=new Map(n.relations?.map(([e,a])=>[e,new Set(a)])),this.contents=new Map(n.contents);if(this.isAType=i?.isAType??null,this.isBType=i?.isBType??null,this.isContent=i?.isContent??null,i?.makeContentKey)this.makeContentKey=i.makeContentKey;if(i?.externalStore){let e=i.externalStore;if(this.has=(a,t)=>e.has(a,t),this.addRelation=(a,t)=>{e.addRelation(a,t)},this.deleteRelation=(a,t)=>{e.deleteRelation(a,t)},this.replaceRelationsSafely=(a,t)=>{e.replaceRelationsSafely(a,t)},this.replaceRelationsUnsafely=(a,t)=>{e.replaceRelationsUnsafely(a,t)},this.getRelatedKeys=(a)=>e.getRelatedKeys(a),e.getContent)this.getContentInternal=(a)=>{return e.getContent(a)},this.setContent=(a,t)=>{e.setContent(a,t)},this.deleteContent=(a)=>{e.deleteContent(a)};for(let[a,t]of n.relations??[]){let r=this.isAType?.(a)?a:void 0,o=r===void 0?a:void 0;for(let u of t)r??=u,o??=u,this.addRelation(r,o)}for(let[a,t]of n.contents??[])this.setContent(a,t)}if(i?.warn)this.warn=i.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([n,i])=>[n,[...i]]),contents:[...this.contents.entries()]}}set(...n){let i,e,a;switch(n.length){case 1:{let t=n[0];i=t[this.a],e=t[this.b],a=void 0;break}case 2:{let t=n[0];if(typeof t==="string")[i,e]=n;else i=t[this.a],e=t[this.b],a=n[1];break}default:{i=n[0],e=n[1],a=n[2];break}}switch(this.cardinality){case"1:1":{let t=this.getRelatedKey(i);if(t&&t!==e)this.delete(i,t)}case"1:n":{let t=this.getRelatedKey(e);if(t&&t!==i)this.delete(t,e)}break;case"n:n":}if(a){let t=this.makeContentKey(i,e);this.setContent(t,a)}return this.addRelation(i,e),this}delete(n,i){i=typeof i==="string"?i:n[this.b];let e=typeof n==="string"?n:n[this.a];if(e===void 0&&typeof i==="string"){let a=this.getRelatedKeys(i);if(a)for(let t of a)this.delete(t,i)}if(typeof e==="string"&&i===void 0){let a=this.getRelatedKeys(e);if(a)for(let t of a)this.delete(e,t)}if(typeof e==="string"&&typeof i==="string"){this.deleteRelation(e,i);let a=this.makeContentKey(e,i);this.deleteContent(a)}return this}getRelatedKey(n){let i=this.getRelatedKeys(n);if(i){if(i.size>1)this.warn?.(`${i.size} related keys were found for key "${n}": (${[...i].map((a)=>`"${a}"`).join(", ")}). Only one related key was expected.`);let e;for(let a of i){e=a;break}return e}}replaceRelations(n,i,e){let a=!Array.isArray(i),t=a?Object.keys(i):i;if(e?.reckless)this.replaceRelationsUnsafely(n,t);else this.replaceRelationsSafely(n,t);if(a)for(let r of t){let o=this.makeContentKey(n,r),u=i[r];this.setContent(o,u)}return this}getContent(n,i){let e=this.makeContentKey(n,i);return this.getContentInternal(e)}getRelationEntries(n){let i=n[this.a],e=n[this.b];if(i!==void 0&&e===void 0){let a=this.getRelatedKeys(i);if(a)return[...a].map((t)=>{return[t,this.getContent(i,t)]})}if(i===void 0&&e!==void 0){let a=this.getRelatedKeys(e);if(a)return[...a].map((t)=>{return[t,this.getContent(t,e)]})}return[]}has(n,i){if(i)return this.getRelatedKeys(n)?.has(i)??!1;return this.relations.has(n)}},Xi=class{Subscriber;subscribers=new Map;subscribe(n,i){return this.subscribers.set(n,i),()=>{this.unsubscribe(n)}}unsubscribe(n){this.subscribers.delete(n)}next(n){let i=this.subscribers.values();for(let e of i)e(n)}},xen=class extends Xi{state;constructor(n){super();this.state=n}next(n){this.state=n,super.next(n)}};function Dc(n){return"epoch"in n.transactionMeta}function Ba(n){return"phase"in n.transactionMeta}var Cen=(n)=>{let i=ni(n);if(!Ba(i)){n.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}n.logger.info("\uD83E\uDE82","transaction",i.transactionMeta.update.key,"Aborting transaction"),i.parent.child=null};function De(n){return n[0].toUpperCase()+n.slice(1)}function Zp(n){return n.type.split("_").map(De).join(" ")}var u_=class extends Error{constructor(n,i){super(`${Zp(n)} ${ee(n.key)} not found in store "${i.config.name}".`)}};function l_(n,i,e){return(...a)=>{let t=qe(n,i);if(t)return t.run(a,e);throw new u_(i,n)}}var s_=(n)=>(i)=>n instanceof Function?n(i):n,WD=(n,i)=>{if(n.valueMap.has(i.key))return n.logger.info("\uD83D\uDCD6",i.type,i.key,"reading cached value"),tan(i,n);switch(i.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return n.logger.info("\uD83E\uDDEE",i.type,i.key,"computing value"),i.get();case"atom":case"mutable_atom":{let e=i.default,a;if(e instanceof Function)a=e();else a=e;return n.logger.info("\uD83D\uDC81","atom",i.key,"could not find cached value; using default",a),a}}},$D=(n,i)=>{if(n.operation.open){let e=performance.now();return n.logger.info("\u2757",i.type,i.key,`deferring setState at T-${e} until setState for "${n.operation.token.key}" is done`),e}n.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:i},n.logger.info("\u2B55",i.type,i.key,`operation start in store "${n.config.name}"${!Ba(n)?"":` ${n.transactionMeta.phase} "${n.transactionMeta.update.key}"`}`)},PD=(n)=>{if(n.operation.open)n.logger.info("\uD83D\uDD34",n.operation.token.type,n.operation.token.key,`operation done in store "${n.config.name}"`);n.operation={open:!1},n.on.operationClose.next(n.operation)},O6=(n,i)=>{if(!n.operation.open)return n.logger.error("\uD83D\uDC1E","unknown",i,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return n.operation.done.has(i)},wm=(n,i)=>{if(!n.operation.open){n.logger.error("\uD83D\uDC1E","unknown",i,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}n.operation.done.add(i)},Oen=(n,i,e)=>{switch(i.type){case"mutable_atom":n.logger.info("\uD83D\uDCE2",i.type,i.key,"is now (",e.newValue,") subscribers:",i.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":n.logger.info("\uD83D\uDCE2",i.type,i.key,"went (",e.oldValue,"->",e.newValue,") subscribers:",i.subject.subscribers)}i.subject.next(e)};function t_(n,i){let e=ni(n),a=e.selectorAtoms.getRelatedKeys(i.key);if(e.logger.info("\uD83E\uDDF9",i.type,i.key,a?`evicting ${a.size} states downstream:`:"no downstream states",a??"to evict"),a){if(e.operation.open)e.logger.info("\uD83E\uDDF9",i.type,i.key,`[ ${[...e.operation.done].join(", ")} ] already done`);for(let t of a){if(O6(e,t))continue;k6(t,e),wm(e,t)}}}function Len(n,i){let e=ni(n),a=e.selectorGraph.getRelationEntries({upstreamSelectorKey:i.key}).filter(([t,{source:r}])=>r===i.key);for(let[t]of a){if(O6(e,t))continue;k6(t,e),wm(e,t)}}var L6=(n,i,e)=>{let a=WD(n,i),t=a;if(i.type==="mutable_atom"&&Ba(n)){let{parent:o}=n;t=o_(n,i,o)}t=s_(e)(t),n.logger.info("\uD83D\uDCDD","atom",i.key,"set to",t),t=vl(n,i.key,t,i.subject),wm(n,i.key),t_(n,i);let r={oldValue:a,newValue:t};if(!Ba(n)){Oen(n,i,r);return}if(n.on.transactionApplying.state===null){let{key:o}=i;if(aan(r.newValue))return;let u={type:"atom_update",key:o,...r};if(i.family)u.family=i.family;n.transactionMeta.update.updates.push(u),n.logger.info("\uD83D\uDCC1","atom",o,"stowed (",r.oldValue,"->",r.newValue,")")}else if(i.key.startsWith("*")){let o=i.key.slice(1),u=n.atoms.get(o),l=n.valueMap.get(o);if(u.type==="mutable_atom"&&Ba(n)){let{parent:c}=n;l=o_(n,u,c)}if(l.do(r.newValue)===null)t_(n,u)}};function N6(n,i){let e=i.default;if(e instanceof Function)e=e();L6(n,i,e)}function Ien(n,i){switch(i.type){case"atom":case"mutable_atom":N6(n,i);break;case"writable_pure_selector":case"writable_held_selector":{let e=U6(i,n);for(let a of e)N6(n,a)}break}}function YD(n,i,e){let a={key:i.key,type:"atom_family"},t=n.families.get(i.key);if(t)n.logger.error("\u2757","atom_family",i.key,`Overwriting an existing ${Zp(t)} "${t.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let r=new Xi,u=Object.assign((l)=>{let s=ee(l),c={key:i.key,subKey:s},f=`${i.key}(${s})`,b=ni(n),g=i.default,m={key:f,default:g instanceof Function?()=>g(l):g};if(i.effects)m.effects=i.effects(l);let h=kD(b,m,c);return r.next({type:"state_creation",token:h}),h},a,{subject:r,install:(l)=>YD(l,i),internalRoles:e});return n.families.set(i.key,u),n.defaults.set(i.key,i.default),a}function I6(n,i){if("mutable"in i)return h_(n,i);return YD(n,i)}var c_=(n,i)=>ni(n).atoms.has(i),Men=(n,i)=>ni(n).writableSelectors.has(i),Uen=(n,i)=>ni(n).readonlySelectors.has(i),Gen=(n,i)=>c_(n,i)||Men(n,i)||Uen(n,i),r_=(n,i)=>{return ni(n).selectorGraph.getRelationEntries({downstreamSelectorKey:i}).filter(([a,{source:t}])=>t!==i).map(([a,{source:t}])=>t).filter((a)=>Gen(n,a))},M6=(n,i,e)=>{let a=[],t=r_(n,i);while(t.length>0){let r=t.shift();if(e.has(r))continue;if(e.add(r),!c_(n,r))t.push(...r_(n,r));else if(!a.includes(r))a.push(r)}return a},U6=(n,i)=>{let e=n.key,a=r_(i,e),t=new Set;return a.flatMap((r)=>c_(i,r)?r:M6(i,r,t)).map((r)=>i.atoms.get(r))},yen=(n,i,e,a,t)=>{let r=ni(n),{type:o,key:u}=a;if(o==="atom"||o==="mutable_atom")r.selectorAtoms.set({selectorKey:e,atomKey:u}),n.logger.info("\uD83D\uDD0D",i,e,`discovers root atom "${u}"`);else{let l=M6(n,u,t);n.logger.info("\uD83D\uDD0D",i,e,`discovers root atoms: [ ${l.map((s)=>`"${s}"`).join(", ")} ]`);for(let s of l)r.selectorAtoms=r.selectorAtoms.set({selectorKey:e,atomKey:s})}t.add(u)},VD=(n,i,e,a)=>({get:(...t)=>{let r=ni(n),o;if(t.length===2){let[c,f]=t;o=Ui(n,c,f)}else[o]=t;let u=qe(n,o),l=WD(n,u),s=o.key;return n.logger.info("\uD83D\uDD0C",i,e,`registers dependency ( "${s}" =`,l,")"),r.selectorGraph.set({upstreamSelectorKey:s,downstreamSelectorKey:e},{source:o.key}),yen(n,i,e,o,a),l},set:(...t)=>{let r,o;if(t.length===2)r=t[0],o=t[1];else{let s=t[0],c=t[1];o=t[2],r=Ui(n,s,c)}let u=ni(n),l=qe(u,r);$6(u,l,o)},find:(...t)=>Ui(n,...t),json:(t)=>Qp(n,t)}),p_=(n,i,e)=>{let a=ni(n),t=new Xi,r=new Set,{key:o,const:u}=i,l="readonly_held_selector",{get:s,find:c,json:f}=VD(a,"readonly_held_selector",o,r),g={...i,type:"readonly_held_selector",subject:t,install:(h)=>p_(h,i,e),get:()=>{return i.get({get:s,find:c,json:f},u),vl(ni(n),o,u,t),r.clear(),u},...e&&{family:e}};a.readonlySelectors.set(o,g),n.logger.info("\u2728","readonly_held_selector",o,"=",u);let m={key:o,type:"readonly_held_selector"};if(e)m.family=e;return m},d_=(n,i,e)=>{let a=ni(n),t=new Xi,r=new Set,o=i.key,u="readonly_pure_selector",{get:l,find:s,json:c}=VD(a,"readonly_pure_selector",o,r),f=()=>{let h=i.get({get:l,find:s,json:c});return vl(ni(n),o,h,t),r.clear(),h},b={...i,type:"readonly_pure_selector",subject:t,install:(h)=>d_(h,i,e),get:f,...e&&{family:e}};a.readonlySelectors.set(o,b);let g=f();n.logger.info("\u2728","readonly_pure_selector",o,"=",g);let m={key:o,type:"readonly_pure_selector"};if(e)m.family=e;return m},f_=(n,i,e)=>{let a=ni(n),t=new Xi,r=new Set,{key:o,const:u}=i,l="writable_held_selector",s=VD(a,"writable_held_selector",o,r),{find:c,get:f,json:b}=s,g={find:c,get:f,json:b},m=(S=i.get,x=ni(n))=>{return S(g,u),vl(x,o,u,t),r.clear(),u},D={...i,type:"writable_held_selector",subject:t,install:(S)=>f_(S,i,e),get:m,set:(S)=>{let x=ni(n),N=m(i.get,x),I=s_(S)(N);if(n.logger.info("\uD83D\uDCDD","writable_held_selector",o,"set (",N,"->",I,")"),vl(x,o,I,t),wm(x,o),Dc(x))t.next({newValue:I,oldValue:N});i.set(s,I)},...e&&{family:e}};a.writableSelectors.set(o,D);let T=m();n.logger.info("\u2728","writable_held_selector",o,"=",T);let v={key:o,type:"writable_held_selector"};if(e)v.family=e;return v},b_=(n,i,e)=>{let a=ni(n),t=new Xi,r=new Set,o=i.key,u="writable_pure_selector",l=VD(a,"writable_pure_selector",o,r),{find:s,get:c,json:f}=l,b={find:s,get:c,json:f},g=(v=i.get,S=ni(n))=>{let x=v(b);return vl(S,o,x,t),r.clear(),x},h={...i,type:"writable_pure_selector",subject:t,install:(v)=>b_(v,i,e),get:g,set:(v)=>{let S=ni(n),x=g(i.get,S),N=s_(v)(x);if(n.logger.info("\uD83D\uDCDD","writable_pure_selector",o,"set (",x,"->",N,")"),vl(S,i.key,N,t),wm(S,i.key),Dc(S))t.next({newValue:N,oldValue:x});i.set(l,N)},...e&&{family:e}};a.writableSelectors.set(o,h);let D=g();n.logger.info("\u2728",h.type,h.key,"=",D);let T={key:o,type:"writable_pure_selector"};if(e)T.family=e;return T};function e_(n,i){let e="set"in i,a="const"in i;if(a&&e){let r=f_(n,i,void 0);return n.on.selectorCreation.next(r),r}if(a){let r=p_(n,i,void 0);return n.on.selectorCreation.next(r),r}if(e){let r=b_(n,i,void 0);return n.on.selectorCreation.next(r),r}let t=d_(n,i,void 0);return n.on.selectorCreation.next(t),t}function zen(n,i){let e=ni(n),{key:a,type:t}=i,r=qe(e,i);if(!r.family)n.logger.error("\u274C",t,a,"Standalone selectors cannot be disposed.");else{if(e.molecules.get(r.family.subKey))e.moleculeData.delete(r.family.subKey,r.family.key);let u;switch(i.type){case"writable_held_selector":e.writableSelectors.delete(a),u={key:r.family.key,type:"writable_held_selector_family"},qe(n,u).subject.next({type:"state_disposal",subType:"selector",token:i});break;case"writable_pure_selector":e.writableSelectors.delete(a),u={key:r.family.key,type:"writable_pure_selector_family"},qe(n,u).subject.next({type:"state_disposal",subType:"selector",token:i});break;case"readonly_held_selector":e.readonlySelectors.delete(a),u={key:r.family.key,type:"readonly_held_selector_family"},qe(n,u).subject.next({type:"state_disposal",subType:"selector",token:i});break;case"readonly_pure_selector":e.readonlySelectors.delete(a),u={key:r.family.key,type:"readonly_pure_selector_family"},qe(n,u).subject.next({type:"state_disposal",subType:"selector",token:i});break}if(e.valueMap.delete(a),e.selectorAtoms.delete(a),e.selectorGraph.delete(a),n.logger.info("\uD83D\uDD25",i.type,a,"deleted"),Ba(e)&&e.transactionMeta.phase==="building")e.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:i});else n.on.selectorDisposal.next(i)}}function eb(n,i,e){let a=i.key,t="readonly_pure_selector_family",r={key:a,type:"readonly_pure_selector_family"},o=n.families.get(a);if(o)n.logger.error("\u2757","readonly_pure_selector_family",a,`Overwriting an existing ${Zp(o)} "${o.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let u=new Xi,s=Object.assign((c)=>{let f=ee(c),b={key:a,subKey:f},g=`${a}(${f})`,m=ni(n),h=d_(m,{key:g,get:i.get(c)},b);return u.next({type:"state_creation",token:h}),h},r,{internalRoles:e,subject:u,install:(c)=>eb(c,i),default:(c)=>{return i.get(c)({get:(...b)=>Tr(n,...b),find:(...b)=>Ui(n,...b),json:(b)=>Qp(n,b)})}});return n.families.set(a,s),r}function G6(n,i,e){let a=i.key,t="readonly_held_selector_family",r={key:a,type:"readonly_held_selector_family"},o=n.families.get(a);if(o)n.logger.error("\u2757","readonly_held_selector_family",a,`Overwriting an existing ${Zp(o)} "${o.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let u=new Xi,s=Object.assign((c)=>{let f=ee(c),b={key:a,subKey:f},g=`${a}(${f})`,m=ni(n),h=p_(m,{key:g,const:i.const(c),get:i.get(c)},b);return u.next({type:"state_creation",token:h}),h},r,{internalRoles:e,subject:u,install:(c)=>G6(c,i),default:i.const});return n.families.set(a,s),r}function y6(n,i,e){let a=i.key,t="writable_held_selector_family",r={key:a,type:"writable_held_selector_family"},o=n.families.get(a);if(o)n.logger.error("\u2757","writable_held_selector_family",a,`Overwriting an existing ${Zp(o)} "${o.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let u=new Xi,s=Object.assign((c)=>{let f=ee(c),b={key:a,subKey:f},g=`${a}(${f})`,m=ni(n),h=f_(m,{key:g,const:i.const(c),get:i.get(c),set:i.set(c)},b);return u.next({type:"state_creation",token:h}),h},r,{internalRoles:e,subject:u,install:(c)=>y6(c,i),default:i.const});return n.families.set(a,s),r}function HD(n,i,e){let a=i.key,t="writable_pure_selector_family",r={key:a,type:"writable_pure_selector_family"},o=n.families.get(a);if(o)n.logger.error("\u2757","writable_pure_selector_family",a,`Overwriting an existing ${Zp(o)} "${o.key}" in store "${n.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let u=new Xi,s=Object.assign((c)=>{let f=ee(c),b={key:a,subKey:f},g=`${a}(${f})`,m=ni(n),h=b_(m,{key:g,get:i.get(c),set:i.set(c)},b);return u.next({type:"state_creation",token:h}),h},r,{internalRoles:e,subject:u,install:(c)=>HD(c,i),default:(c)=>{return i.get(c)({get:(...b)=>Tr(n,...b),find:(...b)=>Ui(n,...b),json:(b)=>Qp(n,b)})}});return n.families.set(a,s),r}function z6(n,i){let e="set"in i,a="const"in i;if(a&&e)return y6(n,i,void 0);if(a)return G6(n,i,void 0);if(e)return HD(n,i);return eb(n,i)}function Hen(n,i,e){let a=n.families.get(i.key);if(a===void 0)throw new u_(i,n);let t=a(e),r=ni(n);if(t.family){if(Dc(r))switch(t.type){case"atom":case"mutable_atom":n.on.atomCreation.next(t);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":n.on.selectorCreation.next(t);break}else if(Ba(r)&&r.on.transactionApplying.state===null)r.transactionMeta.update.updates.push({type:"state_creation",token:t})}return t}function $en(n,i,e){let a=ee(e),t=`${i.key}(${a})`,r=ni(n),o;switch(i.type){case"atom_family":case"mutable_atom_family":o=r.atoms.get(t);break;case"writable_held_selector_family":case"writable_pure_selector_family":o=r.writableSelectors.get(t);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":o=r.readonlySelectors.get(t);break}if(o)return ab(o);return o}function Ui(n,i,e){let a=$en(n,i,e);if(a)return a;let t=ee(e),r=n.molecules.get(t);if(!r&&n.config.lifespan==="immortal"){let o=Fen(i,e);return n.logger.error("\u274C",o.type,o.key,`was not found in store "${n.config.name}"; returned a counterfeit token.`),o}if(a=Hen(n,i,e),r)ni(n).moleculeData.set(t,i.key);return a}function tb(n,...i){let e;if(i.length===1)e=i[0];else{let a=i[0],t=i[1];e=Ui(n,a,t)}try{qe(n,e)}catch(a){n.logger.error("\u274C",e.type,e.key,`could not be disposed because it was not found in the store "${n.config.name}".`);return}switch(e.type){case"atom":case"mutable_atom":Q6(n,e);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":zen(n,e);break}}function H6(n,i){if(i.family){let e=n.families.get(i.family.key);if(e)return e}}function XD(n,...i){let e,a,t;if(i.length===1){if(e=i[0],a=H6(n,e)??null,a)t=e.family?jt(e.family.subKey):null,e=Ui(n,a,t)}else a=i[0],t=i[1],e=Ui(n,a,t);if("counterfeit"in e&&"family"in e){let u=e.family.subKey,l=n.disposalTraces.buffer.find((s)=>s?.key===u);n.logger.error("\u274C",e.type,e.key,`could not be reset because it was not found in the store "${n.config.name}".`,l?`This state was previously disposed:
|
|
287
287
|
${l.trace}`:"No previous disposal trace was found.");return}let r=$D(n,e);if(r){let u=n.on.operationClose.subscribe(`waiting to reset "${e.key}" at T-${r}`,()=>{u(),n.logger.info("\uD83D\uDFE2",e.type,e.key,`resuming deferred resetState from T-${r}`),XD(n,e)});return}let o=qe(n,e);Ien(n,o),PD(n)}var $6=(n,i,e)=>{switch(i.type){case"atom":case"mutable_atom":L6(n,i,e);break;case"writable_pure_selector":case"writable_held_selector":i.set(e);break}};function ca(n,...i){let e,a,t,r;if(i.length===2){if(e=i[0],r=i[1],a=H6(n,e)??null,a)t=e.family?jt(e.family.subKey):null,e=Ui(n,a,t)}else a=i[0],t=i[1],r=i[2],e=Ui(n,a,t);if("counterfeit"in e&&"family"in e){let l=e.family.subKey,s=n.disposalTraces.buffer.find((c)=>c?.key===l);n.logger.error("\u274C",e.type,e.key,`could not be set because it was not found in the store "${n.config.name}".`,s?`This state was previously disposed:
|
|
288
288
|
${s.trace}`:"No previous disposal trace was found.");return}let o=$D(n,e);if(o){let l=n.on.operationClose.subscribe(`waiting to set "${e.key}" at T-${o}`,()=>{l(),n.logger.info("\uD83D\uDFE2",e.type,e.key,`resuming deferred setState from T-${o}`),ca(n,e,r)});return}let u=qe(n,e);$6(n,u,r),PD(n)}function Pen(n,i,e){let{key:a,newValue:t,oldValue:r}=i,o=n==="newValue"?t:r,u={key:a,type:"atom"};if(i.family)Object.assign(u,{family:i.family});ca(e,u,o)}function Ben(n){let{stack:i}=n;if(i)return`
|
|
289
289
|
`+i.split(`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var AQ=Object.create;var{getPrototypeOf:wQ,defineProperty:$0,getOwnPropertyNames:RQ}=Object;var xQ=Object.prototype.hasOwnProperty;var VZ=(Q,Z,Y)=>{Y=Q!=null?AQ(wQ(Q)):{};let G=Z||!Q||!Q.__esModule?$0(Y,"default",{value:Q,enumerable:!0}):Y;for(let _ of RQ(Q))if(!xQ.call(G,_))$0(G,_,{get:()=>Q[_],enumerable:!0});return G};var $Z=(Q,Z)=>()=>(Z||Q((Z={exports:{}}).exports,Z),Z.exports);var FZ=(Q,Z)=>{for(var Y in Z)$0(Q,Y,{get:Z[Y],enumerable:!0,configurable:!0,set:(G)=>Z[Y]=()=>G})};var hZ=(Q,Z)=>()=>(Q&&(Z=Q(Q=0)),Z);var IZ=import.meta.require;var r0=(Q,Z,Y=w.STORE)=>{return F0(Y,{key:`${Q.key}:JSON`,get:({get:G})=>Z.toJson(G(Q)),set:({set:G},_)=>{G(Q,Z.fromJson(_))}})};function a0(Q,Z,Y){return L0(Q,{key:`${Z.key}:JSON`,get:(_)=>({get:X})=>{let W=X(Z,_);return Y.toJson(W)},set:(_)=>({set:X},W)=>{X(Z,_,Y.fromJson(W))}},["mutable","json"])}var v=(Q)=>JSON.parse(Q),h=(Q)=>JSON.stringify(Q),wZ=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];function r(Q){return XQ(w.STORE,Q)}function _0(Q){return QQ(w.STORE,Q)}function TZ(...Q){if(Q.length===2)return k(w.STORE,...Q);return k(w.STORE,...Q)}function M0(Q,Z,Y=w.STORE){return Y.joins.set(Q.key,new A0(Q,Z,Y)),{key:Q.key,type:"join",a:Q.between[0],b:Q.between[1],cardinality:Q.cardinality}}function s0(Q){return qQ(Q,w.STORE)}var h0=(Q)=>(Z,Y,G,_,...X)=>{console[Q](`${Z} ${Y} "${G}" ${_}`,...X)},TQ={error:h0("error"),info:h0("info"),warn:h0("warn")},o0=class{logLevel;filter;logger;constructor(Q,Z,Y=TQ){this.logLevel=Q,this.filter=Z,this.logger=Y}error=(...Q)=>{let Z=this.filter?.(...Q)??!0;if(this.logLevel!==null){if(Z===!0)this.logger.error(...Q);else if(Z!==!1)this.logger.error(...Z)}};info=(...Q)=>{let Z=this.filter?.(...Q)??!0;if(this.logLevel==="info"){if(Z===!0)this.logger.info(...Q);else if(Z!==!1)this.logger.info(...Z)}};warn=(...Q)=>{let Z=this.filter?.(...Q)??!0;if(this.logLevel!=="error"&&this.logLevel!==null){if(Z===!0)this.logger.warn(...Q);else if(Z!==!1)this.logger.warn(...Z)}}};var vQ=class{store;constructor(Q=w.STORE){this.store=Q,YQ("root",Q)}allocate(Q,Z,Y){return s(this.store,Q,Z,Y)}fuse(Q,Z,Y){return GQ(this.store,Q,Z,Y)}deallocate(Q){o(this.store,Q)}claim(Q,Z,Y){return W0(this.store,Q,Z,Y)}},t0=class{store;realm;constructor(Q=w.STORE){this.store=Q,this.realm=new vQ(Q)}allocate(Q,Z,Y){s(this.store,Q,Z,Y)}deallocate(Q){o(this.store,Q)}claim(Q,Z,Y){W0(this.store,Q,Z,Y)}};function J0(Q){return ZQ(w.STORE,Q)}function X0(Q){return U0(w.STORE,Q)}var f=class Q extends Set{mode="record";subject=new I;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(Z,Y=0){super(Z);if(Z instanceof Q)this.parent=Z,this.cacheUpdateNumber=Z.cacheUpdateNumber;if(Y)this.cacheLimit=Y,this.cache=new Array(Y),this.subscribe("auto cache",(G)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=G})}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(Z){let Y=new Q(Z.members,Z.cacheLimit);return Y.cache=Z.cache,Y.cacheIdx=Z.cacheIdx,Y.cacheUpdateNumber=Z.cacheUpdateNumber,Y}add(Z){let Y=super.add(Z);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${h(Z)}`);return Y}clear(){let Z=this.mode==="record"?[...this]:null;if(super.clear(),Z)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(Z)}`)}delete(Z){let Y=super.delete(Z);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${h(Z)}`);return Y}parent=null;child=null;transactionUpdates=null;transaction(Z){this.mode="transaction",this.transactionUpdates=[],this.child=new Q(this);let Y=this.child._subscribe("transaction",(G)=>{this.transactionUpdates?.push(G)});try{if(Z(this.child)){for(let _ of this.transactionUpdates)this.doStep(_);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(G){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",G),G}finally{Y(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(Z,Y){return this.subject.subscribe(Z,Y)}subscribe(Z,Y){return this.subject.subscribe(Z,(G)=>{Y(`${this.cacheUpdateNumber}=${G}`)})}emit(Z){this.subject.next(Z)}doStep(Z){let Y=Z.indexOf(":"),G=Z.substring(0,Y),_=Z.substring(Y+1);switch(G){case"add":this.add(JSON.parse(_));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(_));break;case"tx":for(let X of _.split(";"))this.doStep(X)}}getUpdateNumber(Z){let Y=Z.indexOf("=");return Number(Z.substring(0,Y))}do(Z){let Y=Z.indexOf("="),G=Number(Z.substring(0,Y)),_=G-this.cacheUpdateNumber;if(_>0){if(_===1){this.mode="playback";let W=Z.substring(Y+1);return this.doStep(W),this.mode="record",this.cacheUpdateNumber=G,null}return this.cacheUpdateNumber+1}if(Math.abs(_)<this.cacheLimit){let W=this.cacheIdx+_;if(this.cache[W]===Z)return null;this.mode="playback";let H=!1;while(!H){this.cacheIdx%=this.cacheLimit;let z=this.cache[this.cacheIdx];if(this.cacheIdx--,!z)return"OUT_OF_RANGE";this.undo(z),H=this.cacheIdx===W-1}let N=Z.substring(Y+1);return this.doStep(N),this.mode="record",this.cacheUpdateNumber=G,null}return"OUT_OF_RANGE"}undoStep(Z){let Y=Z.indexOf(":"),G=Z.substring(0,Y),_=Z.substring(Y+1);switch(G){case"add":this.delete(JSON.parse(_));break;case"del":this.add(JSON.parse(_));break;case"clear":{let X=JSON.parse(_);for(let W of X)this.add(W);break}case"tx":{let X=_.split(";");for(let W=X.length-1;W>=0;W--)this.undoStep(X[W])}}}undo(Z){let Y=Z.indexOf("=");if(Number(Z.substring(0,Y))===this.cacheUpdateNumber){this.mode="playback";let _=Z.substring(Y+1);return this.undoStep(_),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function e0(Q=Math.random){return Q().toString(36).slice(2)}var w0=class extends Promise{fate;resolve;reject;done=!1;constructor(Q){let Z,Y;super((G,_)=>{Z=G,Y=_});this.resolve=Z,this.reject=Y,this.use(Q instanceof Promise?Q:new Promise(Q))}pass(Q,Z){if(Q===this.fate)this.resolve(Z),this.done=!0}fail(Q,Z){if(Q===this.fate)this.reject(Z),this.done=!0}use(Q){if(Q instanceof Promise){let Z=Q;this.fate=Z,Z.then((Y)=>{this.pass(Z,Y)},(Y)=>{this.fail(Z,Y)})}else this.resolve(Q),this.fate=void 0}};function O(Q){while(Q.child!==null)Q=Q.child;return Q}var fQ=class Q{_buffer;_index=0;constructor(Z){let Y;if(typeof Z==="number")Y=Z;else Y=Z.length;this._buffer=Array.from({length:Y})}get buffer(){return this._buffer}get index(){return this._index}add(Z){this._buffer[this._index]=Z,this._index=(this._index+1)%this._buffer.length}copy(){let Z=new Q([...this._buffer]);return Z._index=this._index,Z}},bQ={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function gQ(Q,Z){let Y=h(Z),G=`${Q.key}(${Y})`,_=bQ[Q.type],X={key:G,type:_};return Object.assign(X,{family:{key:Q.key,subKey:Y}}),Object.assign(X,{counterfeit:!0}),X}function e(Q){let Z={key:Q.key,type:Q.type};if("family"in Q)Z.family=Q.family;return Z}var S=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(Q,Z)=>`${Q}:${Z}`;warn;getRelatedKeys(Q){return this.relations.get(Q)}addRelation(Q,Z){let Y=this.relations.get(Q),G=this.relations.get(Z);if(Y)Y.add(Z);else Y=new Set([Z]),this.relations.set(Q,Y);if(G)G.add(Q);else G=new Set([Q]),this.relations.set(Z,G)}deleteRelation(Q,Z){let Y=this.relations.get(Q);if(Y){if(Y.delete(Z),Y.size===0)this.relations.delete(Q);let G=this.relations.get(Z);if(G){if(G.delete(Q),G.size===0)this.relations.delete(Z)}}}replaceRelationsUnsafely(Q,Z){this.relations.set(Q,new Set(Z));for(let Y of Z){let G=new Set().add(Q);this.relations.set(Y,G)}}replaceRelationsSafely(Q,Z){let Y=this.relations.get(Q),G=this.isAType?.(Q)?Q:void 0,_=G===void 0?Q:void 0;if(Y)for(let X of Y){G??=X,_??=X;let W=this.relations.get(X);if(W){if(W.size===1)this.relations.delete(X);else W.delete(Q);this.contents.delete(this.makeContentKey(G,_))}}this.relations.set(Q,new Set(Z));for(let X of Z){let W=this.relations.get(X);if(W)W.add(Q);else W=new Set().add(Q),this.relations.set(X,W)}}getContentInternal(Q){return this.contents.get(Q)}setContent(Q,Z){this.contents.set(Q,Z)}deleteContent(Q){this.contents.delete(Q)}constructor(Q,Z){if(this.a=Q.between[0],this.b=Q.between[1],this.cardinality=Q.cardinality,!Z?.externalStore)this.relations=new Map(Q.relations?.map(([Y,G])=>[Y,new Set(G)])),this.contents=new Map(Q.contents);if(this.isAType=Z?.isAType??null,this.isBType=Z?.isBType??null,this.isContent=Z?.isContent??null,Z?.makeContentKey)this.makeContentKey=Z.makeContentKey;if(Z?.externalStore){let Y=Z.externalStore;if(this.has=(G,_)=>Y.has(G,_),this.addRelation=(G,_)=>{Y.addRelation(G,_)},this.deleteRelation=(G,_)=>{Y.deleteRelation(G,_)},this.replaceRelationsSafely=(G,_)=>{Y.replaceRelationsSafely(G,_)},this.replaceRelationsUnsafely=(G,_)=>{Y.replaceRelationsUnsafely(G,_)},this.getRelatedKeys=(G)=>Y.getRelatedKeys(G),Y.getContent)this.getContentInternal=(G)=>{return Y.getContent(G)},this.setContent=(G,_)=>{Y.setContent(G,_)},this.deleteContent=(G)=>{Y.deleteContent(G)};for(let[G,_]of Q.relations??[]){let X=this.isAType?.(G)?G:void 0,W=X===void 0?G:void 0;for(let q of _)X??=q,W??=q,this.addRelation(X,W)}for(let[G,_]of Q.contents??[])this.setContent(G,_)}if(Z?.warn)this.warn=Z.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([Q,Z])=>[Q,[...Z]]),contents:[...this.contents.entries()]}}set(...Q){let Z,Y,G;switch(Q.length){case 1:{let _=Q[0];Z=_[this.a],Y=_[this.b],G=void 0;break}case 2:{let _=Q[0];if(typeof _==="string")[Z,Y]=Q;else Z=_[this.a],Y=_[this.b],G=Q[1];break}default:{Z=Q[0],Y=Q[1],G=Q[2];break}}switch(this.cardinality){case"1:1":{let _=this.getRelatedKey(Z);if(_&&_!==Y)this.delete(Z,_)}case"1:n":{let _=this.getRelatedKey(Y);if(_&&_!==Z)this.delete(_,Y)}break;case"n:n":}if(G){let _=this.makeContentKey(Z,Y);this.setContent(_,G)}return this.addRelation(Z,Y),this}delete(Q,Z){Z=typeof Z==="string"?Z:Q[this.b];let Y=typeof Q==="string"?Q:Q[this.a];if(Y===void 0&&typeof Z==="string"){let G=this.getRelatedKeys(Z);if(G)for(let _ of G)this.delete(_,Z)}if(typeof Y==="string"&&Z===void 0){let G=this.getRelatedKeys(Y);if(G)for(let _ of G)this.delete(Y,_)}if(typeof Y==="string"&&typeof Z==="string"){this.deleteRelation(Y,Z);let G=this.makeContentKey(Y,Z);this.deleteContent(G)}return this}getRelatedKey(Q){let Z=this.getRelatedKeys(Q);if(Z){if(Z.size>1)this.warn?.(`${Z.size} related keys were found for key "${Q}": (${[...Z].map((G)=>`"${G}"`).join(", ")}). Only one related key was expected.`);let Y;for(let G of Z){Y=G;break}return Y}}replaceRelations(Q,Z,Y){let G=!Array.isArray(Z),_=G?Object.keys(Z):Z;if(Y?.reckless)this.replaceRelationsUnsafely(Q,_);else this.replaceRelationsSafely(Q,_);if(G)for(let X of _){let W=this.makeContentKey(Q,X),q=Z[X];this.setContent(W,q)}return this}getContent(Q,Z){let Y=this.makeContentKey(Q,Z);return this.getContentInternal(Y)}getRelationEntries(Q){let Z=Q[this.a],Y=Q[this.b];if(Z!==void 0&&Y===void 0){let G=this.getRelatedKeys(Z);if(G)return[...G].map((_)=>{return[_,this.getContent(Z,_)]})}if(Z===void 0&&Y!==void 0){let G=this.getRelatedKeys(Y);if(G)return[...G].map((_)=>{return[_,this.getContent(_,Y)]})}return[]}has(Q,Z){if(Z)return this.getRelatedKeys(Q)?.has(Z)??!1;return this.relations.has(Q)}},I=class{Subscriber;subscribers=new Map;subscribe(Q,Z){return this.subscribers.set(Q,Z),()=>{this.unsubscribe(Q)}}unsubscribe(Q){this.subscribers.delete(Q)}next(Q){let Z=this.subscribers.values();for(let Y of Z)Y(Q)}},dQ=class extends I{state;constructor(Q){super();this.state=Q}next(Q){this.state=Q,super.next(Q)}};function y(Q){return"epoch"in Q.transactionMeta}function x(Q){return"phase"in Q.transactionMeta}var mQ=(Q)=>{let Z=O(Q);if(!x(Z)){Q.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}Q.logger.info("\uD83E\uDE82","transaction",Z.transactionMeta.update.key,"Aborting transaction"),Z.parent.child=null};function U(Q){return Q[0].toUpperCase()+Q.slice(1)}function i(Q){return Q.type.split("_").map(U).join(" ")}var v0=class extends Error{constructor(Q,Z){super(`${i(Q)} ${h(Q.key)} not found in store "${Z.config.name}".`)}};function I0(Q,Z,Y){return(...G)=>{let _=A(Q,Z);if(_)return _.run(G,Y);throw new v0(Z,Q)}}var S0=(Q)=>(Z)=>Q instanceof Function?Q(Z):Q,O0=(Q,Z)=>{if(Q.valueMap.has(Z.key))return Q.logger.info("\uD83D\uDCD6",Z.type,Z.key,"reading cached value"),MZ(Z,Q);switch(Z.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return Q.logger.info("\uD83E\uDDEE",Z.type,Z.key,"computing value"),Z.get();case"atom":case"mutable_atom":{let Y=Z.default,G;if(Y instanceof Function)G=Y();else G=Y;return Q.logger.info("\uD83D\uDC81","atom",Z.key,"could not find cached value; using default",G),G}}},C0=(Q,Z)=>{if(Q.operation.open){let Y=performance.now();return Q.logger.info("\u2757",Z.type,Z.key,`deferring setState at T-${Y} until setState for "${Q.operation.token.key}" is done`),Y}Q.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:Z},Q.logger.info("\u2B55",Z.type,Z.key,`operation start in store "${Q.config.name}"${!x(Q)?"":` ${Q.transactionMeta.phase} "${Q.transactionMeta.update.key}"`}`)},P0=(Q)=>{if(Q.operation.open)Q.logger.info("\uD83D\uDD34",Q.operation.token.type,Q.operation.token.key,`operation done in store "${Q.config.name}"`);Q.operation={open:!1},Q.on.operationClose.next(Q.operation)},DQ=(Q,Z)=>{if(!Q.operation.open)return Q.logger.error("\uD83D\uDC1E","unknown",Z,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return Q.operation.done.has(Z)},N0=(Q,Z)=>{if(!Q.operation.open){Q.logger.error("\uD83D\uDC1E","unknown",Z,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}Q.operation.done.add(Z)},kQ=(Q,Z,Y)=>{switch(Z.type){case"mutable_atom":Q.logger.info("\uD83D\uDCE2",Z.type,Z.key,"is now (",Y.newValue,") subscribers:",Z.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":Q.logger.info("\uD83D\uDCE2",Z.type,Z.key,"went (",Y.oldValue,"->",Y.newValue,") subscribers:",Z.subject.subscribers)}Z.subject.next(Y)};function R0(Q,Z){let Y=O(Q),G=Y.selectorAtoms.getRelatedKeys(Z.key);if(Y.logger.info("\uD83E\uDDF9",Z.type,Z.key,G?`evicting ${G.size} states downstream:`:"no downstream states",G??"to evict"),G){if(Y.operation.open)Y.logger.info("\uD83E\uDDF9",Z.type,Z.key,`[ ${[...Y.operation.done].join(", ")} ] already done`);for(let _ of G){if(DQ(Y,_))continue;$Q(_,Y),N0(Y,_)}}}function cQ(Q,Z){let Y=O(Q),G=Y.selectorGraph.getRelationEntries({upstreamSelectorKey:Z.key}).filter(([_,{source:X}])=>X===Z.key);for(let[_]of G){if(DQ(Y,_))continue;$Q(_,Y),N0(Y,_)}}var LQ=(Q,Z,Y)=>{let G=O0(Q,Z),_=G;if(Z.type==="mutable_atom"&&x(Q)){let{parent:W}=Q;_=T0(Q,Z,W)}_=S0(Y)(_),Q.logger.info("\uD83D\uDCDD","atom",Z.key,"set to",_),_=u(Q,Z.key,_,Z.subject),N0(Q,Z.key),R0(Q,Z);let X={oldValue:G,newValue:_};if(!x(Q)){kQ(Q,Z,X);return}if(Q.on.transactionApplying.state===null){let{key:W}=Z;if(LZ(X.newValue))return;let q={type:"atom_update",key:W,...X};if(Z.family)q.family=Z.family;Q.transactionMeta.update.updates.push(q),Q.logger.info("\uD83D\uDCC1","atom",W,"stowed (",X.oldValue,"->",X.newValue,")")}else if(Z.key.startsWith("*")){let W=Z.key.slice(1),q=Q.atoms.get(W),H=Q.valueMap.get(W);if(q.type==="mutable_atom"&&x(Q)){let{parent:z}=Q;H=T0(Q,q,z)}if(H.do(X.newValue)===null)R0(Q,q)}};function HQ(Q,Z){let Y=Z.default;if(Y instanceof Function)Y=Y();LQ(Q,Z,Y)}function uQ(Q,Z){switch(Z.type){case"atom":case"mutable_atom":HQ(Q,Z);break;case"writable_pure_selector":case"writable_held_selector":{let Y=JQ(Z,Q);for(let G of Y)HQ(Q,G)}break}}function B0(Q,Z,Y){let G={key:Z.key,type:"atom_family"},_=Q.families.get(Z.key);if(_)Q.logger.error("\u2757","atom_family",Z.key,`Overwriting an existing ${i(_)} "${_.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let X=new I,q=Object.assign((H)=>{let N=h(H),z={key:Z.key,subKey:N},L=`${Z.key}(${N})`,M=O(Q),C=Z.default,E={key:L,default:C instanceof Function?C(H):C};if(Z.effects)E.effects=Z.effects(H);let B=V0(M,E,z);return X.next({type:"state_creation",token:B}),B},G,{subject:X,install:(H)=>B0(H,Z),internalRoles:Y});return Q.families.set(Z.key,q),Q.defaults.set(Z.key,Z.default),G}function QQ(Q,Z){if("mutable"in Z)return c0(Q,Z);return B0(Q,Z)}var K0=(Q,Z)=>O(Q).atoms.has(Z),pQ=(Q,Z)=>O(Q).writableSelectors.has(Z),yQ=(Q,Z)=>O(Q).readonlySelectors.has(Z),lQ=(Q,Z)=>K0(Q,Z)||pQ(Q,Z)||yQ(Q,Z),x0=(Q,Z)=>{return O(Q).selectorGraph.getRelationEntries({downstreamSelectorKey:Z}).filter(([G,{source:_}])=>_!==Z).map(([G,{source:_}])=>_).filter((G)=>lQ(Q,G))},MQ=(Q,Z,Y)=>{let G=[],_=x0(Q,Z);while(_.length>0){let X=_.shift();if(Y.has(X))continue;if(Y.add(X),!K0(Q,X))_.push(...x0(Q,X));else if(!G.includes(X))G.push(X)}return G},JQ=(Q,Z)=>{let Y=Q.key,G=x0(Z,Y),_=new Set;return G.flatMap((X)=>K0(Z,X)?X:MQ(Z,X,_)).map((X)=>Z.atoms.get(X))},iQ=(Q,Z,Y,G,_)=>{let X=O(Q),{type:W,key:q}=G;if(W==="atom"||W==="mutable_atom")X.selectorAtoms.set({selectorKey:Y,atomKey:q}),Q.logger.info("\uD83D\uDD0D",Z,Y,`discovers root atom "${q}"`);else{let H=MQ(Q,q,_);Q.logger.info("\uD83D\uDD0D",Z,Y,`discovers root atoms: [ ${H.map((N)=>`"${N}"`).join(", ")} ]`);for(let N of H)X.selectorAtoms=X.selectorAtoms.set({selectorKey:Y,atomKey:N})}_.add(q)},j0=(Q,Z,Y,G)=>({get:(..._)=>{let X=O(Q),W;if(_.length===2){let[z,L]=_;W=$(Q,z,L)}else[W]=_;let q=A(Q,W),H=O0(Q,q),N=W.key;return Q.logger.info("\uD83D\uDD0C",Z,Y,`registers dependency ( "${N}" =`,H,")"),X.selectorGraph.set({upstreamSelectorKey:N,downstreamSelectorKey:Y},{source:W.key}),iQ(Q,Z,Y,W,G),H},set:(..._)=>{let X,W;if(_.length===2)X=_[0],W=_[1];else{let N=_[0],z=_[1];W=_[2],X=$(Q,N,z)}let q=O(Q),H=A(q,X);OQ(q,H,W)},find:(..._)=>$(Q,..._),json:(_)=>n(Q,_)}),f0=(Q,Z,Y)=>{let G=O(Q),_=new I,X=new Set,{key:W,const:q}=Z,H="readonly_held_selector",{get:N,find:z,json:L}=j0(G,"readonly_held_selector",W,X),C={...Z,type:"readonly_held_selector",subject:_,install:(B)=>f0(B,Z,Y),get:()=>{return Z.get({get:N,find:z,json:L},q),u(O(Q),W,q,_),X.clear(),q},...Y&&{family:Y}};G.readonlySelectors.set(W,C),Q.logger.info("\u2728","readonly_held_selector",W,"=",q);let E={key:W,type:"readonly_held_selector"};if(Y)E.family=Y;return E},b0=(Q,Z,Y)=>{let G=O(Q),_=new I,X=new Set,W=Z.key,q="readonly_pure_selector",{get:H,find:N,json:z}=j0(G,"readonly_pure_selector",W,X),L=()=>{let B=Z.get({get:H,find:N,json:z});return u(O(Q),W,B,_),X.clear(),B},M={...Z,type:"readonly_pure_selector",subject:_,install:(B)=>b0(B,Z,Y),get:L,...Y&&{family:Y}};G.readonlySelectors.set(W,M);let C=L();Q.logger.info("\u2728","readonly_pure_selector",W,"=",C);let E={key:W,type:"readonly_pure_selector"};if(Y)E.family=Y;return E},g0=(Q,Z,Y)=>{let G=O(Q),_=new I,X=new Set,{key:W,const:q}=Z,H="writable_held_selector",N=j0(G,"writable_held_selector",W,X),{find:z,get:L,json:M}=N,C={find:z,get:L,json:M},E=(T=Z.get,D=O(Q))=>{return T(C,q),u(D,W,q,_),X.clear(),q},K={...Z,type:"writable_held_selector",subject:_,install:(T)=>g0(T,Z,Y),get:E,set:(T)=>{let D=O(Q),J=E(Z.get,D),j=S0(T)(J);if(Q.logger.info("\uD83D\uDCDD","writable_held_selector",W,"set (",J,"->",j,")"),u(D,W,j,_),N0(D,W),y(D))_.next({newValue:j,oldValue:J});Z.set(N,j)},...Y&&{family:Y}};G.writableSelectors.set(W,K);let l=E();Q.logger.info("\u2728","writable_held_selector",W,"=",l);let d={key:W,type:"writable_held_selector"};if(Y)d.family=Y;return d},d0=(Q,Z,Y)=>{let G=O(Q),_=new I,X=new Set,W=Z.key,q="writable_pure_selector",H=j0(G,"writable_pure_selector",W,X),{find:N,get:z,json:L}=H,M={find:N,get:z,json:L},C=(d=Z.get,T=O(Q))=>{let D=d(M);return u(T,W,D,_),X.clear(),D},B={...Z,type:"writable_pure_selector",subject:_,install:(d)=>d0(d,Z,Y),get:C,set:(d)=>{let T=O(Q),D=C(Z.get,T),J=S0(d)(D);if(Q.logger.info("\uD83D\uDCDD","writable_pure_selector",W,"set (",D,"->",J,")"),u(T,Z.key,J,_),N0(T,Z.key),y(T))_.next({newValue:J,oldValue:D});Z.set(H,J)},...Y&&{family:Y}};G.writableSelectors.set(W,B);let K=C();Q.logger.info("\u2728",B.type,B.key,"=",K);let l={key:W,type:"writable_pure_selector"};if(Y)l.family=Y;return l};function F0(Q,Z){let Y="set"in Z,G="const"in Z;if(G&&Y){let X=g0(Q,Z,void 0);return Q.on.selectorCreation.next(X),X}if(G){let X=f0(Q,Z,void 0);return Q.on.selectorCreation.next(X),X}if(Y){let X=d0(Q,Z,void 0);return Q.on.selectorCreation.next(X),X}let _=b0(Q,Z,void 0);return Q.on.selectorCreation.next(_),_}function nQ(Q,Z){let Y=O(Q),{key:G,type:_}=Z,X=A(Y,Z);if(!X.family)Q.logger.error("\u274C",_,G,"Standalone selectors cannot be disposed.");else{if(Y.molecules.get(X.family.subKey))Y.moleculeData.delete(X.family.subKey,X.family.key);let q;switch(Z.type){case"writable_held_selector":Y.writableSelectors.delete(G),q={key:X.family.key,type:"writable_held_selector_family"},A(Q,q).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"writable_pure_selector":Y.writableSelectors.delete(G),q={key:X.family.key,type:"writable_pure_selector_family"},A(Q,q).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"readonly_held_selector":Y.readonlySelectors.delete(G),q={key:X.family.key,type:"readonly_held_selector_family"},A(Q,q).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"readonly_pure_selector":Y.readonlySelectors.delete(G),q={key:X.family.key,type:"readonly_pure_selector_family"},A(Q,q).subject.next({type:"state_disposal",subType:"selector",token:Z});break}if(Y.valueMap.delete(G),Y.selectorAtoms.delete(G),Y.selectorGraph.delete(G),Q.logger.info("\uD83D\uDD25",Z.type,G,"deleted"),x(Y)&&Y.transactionMeta.phase==="building")Y.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:Z});else Q.on.selectorDisposal.next(Z)}}function t(Q,Z,Y){let G=Z.key,_="readonly_pure_selector_family",X={key:G,type:"readonly_pure_selector_family"},W=Q.families.get(G);if(W)Q.logger.error("\u2757","readonly_pure_selector_family",G,`Overwriting an existing ${i(W)} "${W.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let q=new I,N=Object.assign((z)=>{let L=h(z),M={key:G,subKey:L},C=`${G}(${L})`,E=O(Q),B=b0(E,{key:C,get:Z.get(z)},M);return q.next({type:"state_creation",token:B}),B},X,{internalRoles:Y,subject:q,install:(z)=>t(z,Z),default:(z)=>{return Z.get(z)({get:(...M)=>k(Q,...M),find:(...M)=>$(Q,...M),json:(M)=>n(Q,M)})}});return Q.families.set(G,N),X}function EQ(Q,Z,Y){let G=Z.key,_="readonly_held_selector_family",X={key:G,type:"readonly_held_selector_family"},W=Q.families.get(G);if(W)Q.logger.error("\u2757","readonly_held_selector_family",G,`Overwriting an existing ${i(W)} "${W.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let q=new I,N=Object.assign((z)=>{let L=h(z),M={key:G,subKey:L},C=`${G}(${L})`,E=O(Q),B=f0(E,{key:C,const:Z.const(z),get:Z.get(z)},M);return q.next({type:"state_creation",token:B}),B},X,{internalRoles:Y,subject:q,install:(z)=>EQ(z,Z),default:Z.const});return Q.families.set(G,N),X}function CQ(Q,Z,Y){let G=Z.key,_="writable_held_selector_family",X={key:G,type:"writable_held_selector_family"},W=Q.families.get(G);if(W)Q.logger.error("\u2757","writable_held_selector_family",G,`Overwriting an existing ${i(W)} "${W.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let q=new I,N=Object.assign((z)=>{let L=h(z),M={key:G,subKey:L},C=`${G}(${L})`,E=O(Q),B=g0(E,{key:C,const:Z.const(z),get:Z.get(z),set:Z.set(z)},M);return q.next({type:"state_creation",token:B}),B},X,{internalRoles:Y,subject:q,install:(z)=>CQ(z,Z),default:Z.const});return Q.families.set(G,N),X}function L0(Q,Z,Y){let G=Z.key,_="writable_pure_selector_family",X={key:G,type:"writable_pure_selector_family"},W=Q.families.get(G);if(W)Q.logger.error("\u2757","writable_pure_selector_family",G,`Overwriting an existing ${i(W)} "${W.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let q=new I,N=Object.assign((z)=>{let L=h(z),M={key:G,subKey:L},C=`${G}(${L})`,E=O(Q),B=d0(E,{key:C,get:Z.get(z),set:Z.set(z)},M);return q.next({type:"state_creation",token:B}),B},X,{internalRoles:Y,subject:q,install:(z)=>L0(z,Z),default:(z)=>{return Z.get(z)({get:(...M)=>k(Q,...M),find:(...M)=>$(Q,...M),json:(M)=>n(Q,M)})}});return Q.families.set(G,N),X}function ZQ(Q,Z){let Y="set"in Z,G="const"in Z;if(G&&Y)return CQ(Q,Z,void 0);if(G)return EQ(Q,Z,void 0);if(Y)return L0(Q,Z);return t(Q,Z)}function rQ(Q,Z,Y){let G=Q.families.get(Z.key);if(G===void 0)throw new v0(Z,Q);let _=G(Y),X=O(Q);if(_.family){if(y(X))switch(_.type){case"atom":case"mutable_atom":Q.on.atomCreation.next(_);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":Q.on.selectorCreation.next(_);break}else if(x(X)&&X.on.transactionApplying.state===null)X.transactionMeta.update.updates.push({type:"state_creation",token:_})}return _}function aQ(Q,Z,Y){let G=h(Y),_=`${Z.key}(${G})`,X=O(Q),W;switch(Z.type){case"atom_family":case"mutable_atom_family":W=X.atoms.get(_);break;case"writable_held_selector_family":case"writable_pure_selector_family":W=X.writableSelectors.get(_);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":W=X.readonlySelectors.get(_);break}if(W)return e(W);return W}function $(Q,Z,Y){let G=aQ(Q,Z,Y);if(G)return G;let _=h(Y),X=Q.molecules.get(_);if(!X&&Q.config.lifespan==="immortal"){let W=gQ(Z,Y);return Q.logger.error("\u274C",W.type,W.key,`was not found in store "${Q.config.name}"; returned a counterfeit token.`),W}if(G=rQ(Q,Z,Y),X)O(Q).moleculeData.set(_,Z.key);return G}function a(Q,...Z){let Y;if(Z.length===1)Y=Z[0];else{let G=Z[0],_=Z[1];Y=$(Q,G,_)}try{A(Q,Y)}catch(G){Q.logger.error("\u274C",Y.type,Y.key,`could not be disposed because it was not found in the store "${Q.config.name}".`);return}switch(Y.type){case"atom":case"mutable_atom":FQ(Q,Y);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":nQ(Q,Y);break}}function PQ(Q,Z){if(Z.family){let Y=Q.families.get(Z.family.key);if(Y)return Y}}function E0(Q,...Z){let Y,G,_;if(Z.length===1){if(Y=Z[0],G=PQ(Q,Y)??null,G)_=Y.family?v(Y.family.subKey):null,Y=$(Q,G,_)}else G=Z[0],_=Z[1],Y=$(Q,G,_);if("counterfeit"in Y&&"family"in Y){let q=Y.family.subKey,H=Q.disposalTraces.buffer.find((N)=>N?.key===q);Q.logger.error("\u274C",Y.type,Y.key,`could not be reset because it was not found in the store "${Q.config.name}".`,H?`This state was previously disposed:
|
|
3
|
+
var AQ=Object.create;var{getPrototypeOf:wQ,defineProperty:$0,getOwnPropertyNames:RQ}=Object;var xQ=Object.prototype.hasOwnProperty;var VZ=(Q,Z,Y)=>{Y=Q!=null?AQ(wQ(Q)):{};let G=Z||!Q||!Q.__esModule?$0(Y,"default",{value:Q,enumerable:!0}):Y;for(let _ of RQ(Q))if(!xQ.call(G,_))$0(G,_,{get:()=>Q[_],enumerable:!0});return G};var $Z=(Q,Z)=>()=>(Z||Q((Z={exports:{}}).exports,Z),Z.exports);var FZ=(Q,Z)=>{for(var Y in Z)$0(Q,Y,{get:Z[Y],enumerable:!0,configurable:!0,set:(G)=>Z[Y]=()=>G})};var hZ=(Q,Z)=>()=>(Q&&(Z=Q(Q=0)),Z);var IZ=import.meta.require;var r0=(Q,Z,Y=w.STORE)=>{return F0(Y,{key:`${Q.key}:JSON`,get:({get:G})=>Z.toJson(G(Q)),set:({set:G},_)=>{G(Q,Z.fromJson(_))}})};function a0(Q,Z,Y){return L0(Q,{key:`${Z.key}:JSON`,get:(_)=>({get:X})=>{let W=X(Z,_);return Y.toJson(W)},set:(_)=>({set:X},W)=>{X(Z,_,Y.fromJson(W))}},["mutable","json"])}var v=(Q)=>JSON.parse(Q),h=(Q)=>JSON.stringify(Q),wZ=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];function r(Q){return XQ(w.STORE,Q)}function _0(Q){return QQ(w.STORE,Q)}function TZ(...Q){if(Q.length===2)return k(w.STORE,...Q);return k(w.STORE,...Q)}function M0(Q,Z,Y=w.STORE){return Y.joins.set(Q.key,new A0(Q,Z,Y)),{key:Q.key,type:"join",a:Q.between[0],b:Q.between[1],cardinality:Q.cardinality}}function s0(Q){return qQ(Q,w.STORE)}var h0=(Q)=>(Z,Y,G,_,...X)=>{console[Q](`${Z} ${Y} "${G}" ${_}`,...X)},TQ={error:h0("error"),info:h0("info"),warn:h0("warn")},o0=class{logLevel;filter;logger;constructor(Q,Z,Y=TQ){this.logLevel=Q,this.filter=Z,this.logger=Y}error=(...Q)=>{let Z=this.filter?.(...Q)??!0;if(this.logLevel!==null){if(Z===!0)this.logger.error(...Q);else if(Z!==!1)this.logger.error(...Z)}};info=(...Q)=>{let Z=this.filter?.(...Q)??!0;if(this.logLevel==="info"){if(Z===!0)this.logger.info(...Q);else if(Z!==!1)this.logger.info(...Z)}};warn=(...Q)=>{let Z=this.filter?.(...Q)??!0;if(this.logLevel!=="error"&&this.logLevel!==null){if(Z===!0)this.logger.warn(...Q);else if(Z!==!1)this.logger.warn(...Z)}}};var vQ=class{store;constructor(Q=w.STORE){this.store=Q,YQ("root",Q)}allocate(Q,Z,Y){return s(this.store,Q,Z,Y)}fuse(Q,Z,Y){return GQ(this.store,Q,Z,Y)}deallocate(Q){o(this.store,Q)}claim(Q,Z,Y){return W0(this.store,Q,Z,Y)}},t0=class{store;realm;constructor(Q=w.STORE){this.store=Q,this.realm=new vQ(Q)}allocate(Q,Z,Y){s(this.store,Q,Z,Y)}deallocate(Q){o(this.store,Q)}claim(Q,Z,Y){W0(this.store,Q,Z,Y)}};function J0(Q){return ZQ(w.STORE,Q)}function X0(Q){return U0(w.STORE,Q)}var f=class Q extends Set{mode="record";subject=new I;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(Z,Y=0){super(Z);if(Z instanceof Q)this.parent=Z,this.cacheUpdateNumber=Z.cacheUpdateNumber;if(Y)this.cacheLimit=Y,this.cache=new Array(Y),this.subscribe("auto cache",(G)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=G})}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(Z){let Y=new Q(Z.members,Z.cacheLimit);return Y.cache=Z.cache,Y.cacheIdx=Z.cacheIdx,Y.cacheUpdateNumber=Z.cacheUpdateNumber,Y}add(Z){let Y=super.add(Z);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${h(Z)}`);return Y}clear(){let Z=this.mode==="record"?[...this]:null;if(super.clear(),Z)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(Z)}`)}delete(Z){let Y=super.delete(Z);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${h(Z)}`);return Y}parent=null;child=null;transactionUpdates=null;transaction(Z){this.mode="transaction",this.transactionUpdates=[],this.child=new Q(this);let Y=this.child._subscribe("transaction",(G)=>{this.transactionUpdates?.push(G)});try{if(Z(this.child)){for(let _ of this.transactionUpdates)this.doStep(_);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(G){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",G),G}finally{Y(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(Z,Y){return this.subject.subscribe(Z,Y)}subscribe(Z,Y){return this.subject.subscribe(Z,(G)=>{Y(`${this.cacheUpdateNumber}=${G}`)})}emit(Z){this.subject.next(Z)}doStep(Z){let Y=Z.indexOf(":"),G=Z.substring(0,Y),_=Z.substring(Y+1);switch(G){case"add":this.add(JSON.parse(_));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(_));break;case"tx":for(let X of _.split(";"))this.doStep(X)}}getUpdateNumber(Z){let Y=Z.indexOf("=");return Number(Z.substring(0,Y))}do(Z){let Y=Z.indexOf("="),G=Number(Z.substring(0,Y)),_=G-this.cacheUpdateNumber;if(_>0){if(_===1){this.mode="playback";let W=Z.substring(Y+1);return this.doStep(W),this.mode="record",this.cacheUpdateNumber=G,null}return this.cacheUpdateNumber+1}if(Math.abs(_)<this.cacheLimit){let W=this.cacheIdx+_;if(this.cache[W]===Z)return null;this.mode="playback";let H=!1;while(!H){this.cacheIdx%=this.cacheLimit;let z=this.cache[this.cacheIdx];if(this.cacheIdx--,!z)return"OUT_OF_RANGE";this.undo(z),H=this.cacheIdx===W-1}let N=Z.substring(Y+1);return this.doStep(N),this.mode="record",this.cacheUpdateNumber=G,null}return"OUT_OF_RANGE"}undoStep(Z){let Y=Z.indexOf(":"),G=Z.substring(0,Y),_=Z.substring(Y+1);switch(G){case"add":this.delete(JSON.parse(_));break;case"del":this.add(JSON.parse(_));break;case"clear":{let X=JSON.parse(_);for(let W of X)this.add(W);break}case"tx":{let X=_.split(";");for(let W=X.length-1;W>=0;W--)this.undoStep(X[W])}}}undo(Z){let Y=Z.indexOf("=");if(Number(Z.substring(0,Y))===this.cacheUpdateNumber){this.mode="playback";let _=Z.substring(Y+1);return this.undoStep(_),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function e0(Q=Math.random){return Q().toString(36).slice(2)}var w0=class extends Promise{fate;resolve;reject;done=!1;constructor(Q){let Z,Y;super((G,_)=>{Z=G,Y=_});this.resolve=Z,this.reject=Y,this.use(Q instanceof Promise?Q:new Promise(Q))}pass(Q,Z){if(Q===this.fate)this.resolve(Z),this.done=!0}fail(Q,Z){if(Q===this.fate)this.reject(Z),this.done=!0}use(Q){if(Q instanceof Promise){let Z=Q;this.fate=Z,Z.then((Y)=>{this.pass(Z,Y)},(Y)=>{this.fail(Z,Y)})}else this.resolve(Q),this.fate=void 0}};function O(Q){while(Q.child!==null)Q=Q.child;return Q}var fQ=class Q{_buffer;_index=0;constructor(Z){let Y;if(typeof Z==="number")Y=Z;else Y=Z.length;this._buffer=Array.from({length:Y})}get buffer(){return this._buffer}get index(){return this._index}add(Z){this._buffer[this._index]=Z,this._index=(this._index+1)%this._buffer.length}copy(){let Z=new Q([...this._buffer]);return Z._index=this._index,Z}},bQ={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function gQ(Q,Z){let Y=h(Z),G=`${Q.key}(${Y})`,_=bQ[Q.type],X={key:G,type:_};return Object.assign(X,{family:{key:Q.key,subKey:Y}}),Object.assign(X,{counterfeit:!0}),X}function e(Q){let Z={key:Q.key,type:Q.type};if("family"in Q)Z.family=Q.family;return Z}var S=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(Q,Z)=>`${Q}:${Z}`;warn;getRelatedKeys(Q){return this.relations.get(Q)}addRelation(Q,Z){let Y=this.relations.get(Q),G=this.relations.get(Z);if(Y)Y.add(Z);else Y=new Set([Z]),this.relations.set(Q,Y);if(G)G.add(Q);else G=new Set([Q]),this.relations.set(Z,G)}deleteRelation(Q,Z){let Y=this.relations.get(Q);if(Y){if(Y.delete(Z),Y.size===0)this.relations.delete(Q);let G=this.relations.get(Z);if(G){if(G.delete(Q),G.size===0)this.relations.delete(Z)}}}replaceRelationsUnsafely(Q,Z){this.relations.set(Q,new Set(Z));for(let Y of Z){let G=new Set().add(Q);this.relations.set(Y,G)}}replaceRelationsSafely(Q,Z){let Y=this.relations.get(Q),G=this.isAType?.(Q)?Q:void 0,_=G===void 0?Q:void 0;if(Y)for(let X of Y){G??=X,_??=X;let W=this.relations.get(X);if(W){if(W.size===1)this.relations.delete(X);else W.delete(Q);this.contents.delete(this.makeContentKey(G,_))}}this.relations.set(Q,new Set(Z));for(let X of Z){let W=this.relations.get(X);if(W)W.add(Q);else W=new Set().add(Q),this.relations.set(X,W)}}getContentInternal(Q){return this.contents.get(Q)}setContent(Q,Z){this.contents.set(Q,Z)}deleteContent(Q){this.contents.delete(Q)}constructor(Q,Z){if(this.a=Q.between[0],this.b=Q.between[1],this.cardinality=Q.cardinality,!Z?.externalStore)this.relations=new Map(Q.relations?.map(([Y,G])=>[Y,new Set(G)])),this.contents=new Map(Q.contents);if(this.isAType=Z?.isAType??null,this.isBType=Z?.isBType??null,this.isContent=Z?.isContent??null,Z?.makeContentKey)this.makeContentKey=Z.makeContentKey;if(Z?.externalStore){let Y=Z.externalStore;if(this.has=(G,_)=>Y.has(G,_),this.addRelation=(G,_)=>{Y.addRelation(G,_)},this.deleteRelation=(G,_)=>{Y.deleteRelation(G,_)},this.replaceRelationsSafely=(G,_)=>{Y.replaceRelationsSafely(G,_)},this.replaceRelationsUnsafely=(G,_)=>{Y.replaceRelationsUnsafely(G,_)},this.getRelatedKeys=(G)=>Y.getRelatedKeys(G),Y.getContent)this.getContentInternal=(G)=>{return Y.getContent(G)},this.setContent=(G,_)=>{Y.setContent(G,_)},this.deleteContent=(G)=>{Y.deleteContent(G)};for(let[G,_]of Q.relations??[]){let X=this.isAType?.(G)?G:void 0,W=X===void 0?G:void 0;for(let q of _)X??=q,W??=q,this.addRelation(X,W)}for(let[G,_]of Q.contents??[])this.setContent(G,_)}if(Z?.warn)this.warn=Z.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([Q,Z])=>[Q,[...Z]]),contents:[...this.contents.entries()]}}set(...Q){let Z,Y,G;switch(Q.length){case 1:{let _=Q[0];Z=_[this.a],Y=_[this.b],G=void 0;break}case 2:{let _=Q[0];if(typeof _==="string")[Z,Y]=Q;else Z=_[this.a],Y=_[this.b],G=Q[1];break}default:{Z=Q[0],Y=Q[1],G=Q[2];break}}switch(this.cardinality){case"1:1":{let _=this.getRelatedKey(Z);if(_&&_!==Y)this.delete(Z,_)}case"1:n":{let _=this.getRelatedKey(Y);if(_&&_!==Z)this.delete(_,Y)}break;case"n:n":}if(G){let _=this.makeContentKey(Z,Y);this.setContent(_,G)}return this.addRelation(Z,Y),this}delete(Q,Z){Z=typeof Z==="string"?Z:Q[this.b];let Y=typeof Q==="string"?Q:Q[this.a];if(Y===void 0&&typeof Z==="string"){let G=this.getRelatedKeys(Z);if(G)for(let _ of G)this.delete(_,Z)}if(typeof Y==="string"&&Z===void 0){let G=this.getRelatedKeys(Y);if(G)for(let _ of G)this.delete(Y,_)}if(typeof Y==="string"&&typeof Z==="string"){this.deleteRelation(Y,Z);let G=this.makeContentKey(Y,Z);this.deleteContent(G)}return this}getRelatedKey(Q){let Z=this.getRelatedKeys(Q);if(Z){if(Z.size>1)this.warn?.(`${Z.size} related keys were found for key "${Q}": (${[...Z].map((G)=>`"${G}"`).join(", ")}). Only one related key was expected.`);let Y;for(let G of Z){Y=G;break}return Y}}replaceRelations(Q,Z,Y){let G=!Array.isArray(Z),_=G?Object.keys(Z):Z;if(Y?.reckless)this.replaceRelationsUnsafely(Q,_);else this.replaceRelationsSafely(Q,_);if(G)for(let X of _){let W=this.makeContentKey(Q,X),q=Z[X];this.setContent(W,q)}return this}getContent(Q,Z){let Y=this.makeContentKey(Q,Z);return this.getContentInternal(Y)}getRelationEntries(Q){let Z=Q[this.a],Y=Q[this.b];if(Z!==void 0&&Y===void 0){let G=this.getRelatedKeys(Z);if(G)return[...G].map((_)=>{return[_,this.getContent(Z,_)]})}if(Z===void 0&&Y!==void 0){let G=this.getRelatedKeys(Y);if(G)return[...G].map((_)=>{return[_,this.getContent(_,Y)]})}return[]}has(Q,Z){if(Z)return this.getRelatedKeys(Q)?.has(Z)??!1;return this.relations.has(Q)}},I=class{Subscriber;subscribers=new Map;subscribe(Q,Z){return this.subscribers.set(Q,Z),()=>{this.unsubscribe(Q)}}unsubscribe(Q){this.subscribers.delete(Q)}next(Q){let Z=this.subscribers.values();for(let Y of Z)Y(Q)}},dQ=class extends I{state;constructor(Q){super();this.state=Q}next(Q){this.state=Q,super.next(Q)}};function y(Q){return"epoch"in Q.transactionMeta}function x(Q){return"phase"in Q.transactionMeta}var mQ=(Q)=>{let Z=O(Q);if(!x(Z)){Q.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}Q.logger.info("\uD83E\uDE82","transaction",Z.transactionMeta.update.key,"Aborting transaction"),Z.parent.child=null};function U(Q){return Q[0].toUpperCase()+Q.slice(1)}function i(Q){return Q.type.split("_").map(U).join(" ")}var v0=class extends Error{constructor(Q,Z){super(`${i(Q)} ${h(Q.key)} not found in store "${Z.config.name}".`)}};function I0(Q,Z,Y){return(...G)=>{let _=A(Q,Z);if(_)return _.run(G,Y);throw new v0(Z,Q)}}var S0=(Q)=>(Z)=>Q instanceof Function?Q(Z):Q,O0=(Q,Z)=>{if(Q.valueMap.has(Z.key))return Q.logger.info("\uD83D\uDCD6",Z.type,Z.key,"reading cached value"),MZ(Z,Q);switch(Z.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return Q.logger.info("\uD83E\uDDEE",Z.type,Z.key,"computing value"),Z.get();case"atom":case"mutable_atom":{let Y=Z.default,G;if(Y instanceof Function)G=Y();else G=Y;return Q.logger.info("\uD83D\uDC81","atom",Z.key,"could not find cached value; using default",G),G}}},C0=(Q,Z)=>{if(Q.operation.open){let Y=performance.now();return Q.logger.info("\u2757",Z.type,Z.key,`deferring setState at T-${Y} until setState for "${Q.operation.token.key}" is done`),Y}Q.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:Z},Q.logger.info("\u2B55",Z.type,Z.key,`operation start in store "${Q.config.name}"${!x(Q)?"":` ${Q.transactionMeta.phase} "${Q.transactionMeta.update.key}"`}`)},P0=(Q)=>{if(Q.operation.open)Q.logger.info("\uD83D\uDD34",Q.operation.token.type,Q.operation.token.key,`operation done in store "${Q.config.name}"`);Q.operation={open:!1},Q.on.operationClose.next(Q.operation)},DQ=(Q,Z)=>{if(!Q.operation.open)return Q.logger.error("\uD83D\uDC1E","unknown",Z,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return Q.operation.done.has(Z)},N0=(Q,Z)=>{if(!Q.operation.open){Q.logger.error("\uD83D\uDC1E","unknown",Z,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}Q.operation.done.add(Z)},kQ=(Q,Z,Y)=>{switch(Z.type){case"mutable_atom":Q.logger.info("\uD83D\uDCE2",Z.type,Z.key,"is now (",Y.newValue,") subscribers:",Z.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":Q.logger.info("\uD83D\uDCE2",Z.type,Z.key,"went (",Y.oldValue,"->",Y.newValue,") subscribers:",Z.subject.subscribers)}Z.subject.next(Y)};function R0(Q,Z){let Y=O(Q),G=Y.selectorAtoms.getRelatedKeys(Z.key);if(Y.logger.info("\uD83E\uDDF9",Z.type,Z.key,G?`evicting ${G.size} states downstream:`:"no downstream states",G??"to evict"),G){if(Y.operation.open)Y.logger.info("\uD83E\uDDF9",Z.type,Z.key,`[ ${[...Y.operation.done].join(", ")} ] already done`);for(let _ of G){if(DQ(Y,_))continue;$Q(_,Y),N0(Y,_)}}}function cQ(Q,Z){let Y=O(Q),G=Y.selectorGraph.getRelationEntries({upstreamSelectorKey:Z.key}).filter(([_,{source:X}])=>X===Z.key);for(let[_]of G){if(DQ(Y,_))continue;$Q(_,Y),N0(Y,_)}}var LQ=(Q,Z,Y)=>{let G=O0(Q,Z),_=G;if(Z.type==="mutable_atom"&&x(Q)){let{parent:W}=Q;_=T0(Q,Z,W)}_=S0(Y)(_),Q.logger.info("\uD83D\uDCDD","atom",Z.key,"set to",_),_=u(Q,Z.key,_,Z.subject),N0(Q,Z.key),R0(Q,Z);let X={oldValue:G,newValue:_};if(!x(Q)){kQ(Q,Z,X);return}if(Q.on.transactionApplying.state===null){let{key:W}=Z;if(LZ(X.newValue))return;let q={type:"atom_update",key:W,...X};if(Z.family)q.family=Z.family;Q.transactionMeta.update.updates.push(q),Q.logger.info("\uD83D\uDCC1","atom",W,"stowed (",X.oldValue,"->",X.newValue,")")}else if(Z.key.startsWith("*")){let W=Z.key.slice(1),q=Q.atoms.get(W),H=Q.valueMap.get(W);if(q.type==="mutable_atom"&&x(Q)){let{parent:z}=Q;H=T0(Q,q,z)}if(H.do(X.newValue)===null)R0(Q,q)}};function HQ(Q,Z){let Y=Z.default;if(Y instanceof Function)Y=Y();LQ(Q,Z,Y)}function uQ(Q,Z){switch(Z.type){case"atom":case"mutable_atom":HQ(Q,Z);break;case"writable_pure_selector":case"writable_held_selector":{let Y=JQ(Z,Q);for(let G of Y)HQ(Q,G)}break}}function B0(Q,Z,Y){let G={key:Z.key,type:"atom_family"},_=Q.families.get(Z.key);if(_)Q.logger.error("\u2757","atom_family",Z.key,`Overwriting an existing ${i(_)} "${_.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let X=new I,q=Object.assign((H)=>{let N=h(H),z={key:Z.key,subKey:N},L=`${Z.key}(${N})`,M=O(Q),C=Z.default,E={key:L,default:C instanceof Function?()=>C(H):C};if(Z.effects)E.effects=Z.effects(H);let B=V0(M,E,z);return X.next({type:"state_creation",token:B}),B},G,{subject:X,install:(H)=>B0(H,Z),internalRoles:Y});return Q.families.set(Z.key,q),Q.defaults.set(Z.key,Z.default),G}function QQ(Q,Z){if("mutable"in Z)return c0(Q,Z);return B0(Q,Z)}var K0=(Q,Z)=>O(Q).atoms.has(Z),pQ=(Q,Z)=>O(Q).writableSelectors.has(Z),yQ=(Q,Z)=>O(Q).readonlySelectors.has(Z),lQ=(Q,Z)=>K0(Q,Z)||pQ(Q,Z)||yQ(Q,Z),x0=(Q,Z)=>{return O(Q).selectorGraph.getRelationEntries({downstreamSelectorKey:Z}).filter(([G,{source:_}])=>_!==Z).map(([G,{source:_}])=>_).filter((G)=>lQ(Q,G))},MQ=(Q,Z,Y)=>{let G=[],_=x0(Q,Z);while(_.length>0){let X=_.shift();if(Y.has(X))continue;if(Y.add(X),!K0(Q,X))_.push(...x0(Q,X));else if(!G.includes(X))G.push(X)}return G},JQ=(Q,Z)=>{let Y=Q.key,G=x0(Z,Y),_=new Set;return G.flatMap((X)=>K0(Z,X)?X:MQ(Z,X,_)).map((X)=>Z.atoms.get(X))},iQ=(Q,Z,Y,G,_)=>{let X=O(Q),{type:W,key:q}=G;if(W==="atom"||W==="mutable_atom")X.selectorAtoms.set({selectorKey:Y,atomKey:q}),Q.logger.info("\uD83D\uDD0D",Z,Y,`discovers root atom "${q}"`);else{let H=MQ(Q,q,_);Q.logger.info("\uD83D\uDD0D",Z,Y,`discovers root atoms: [ ${H.map((N)=>`"${N}"`).join(", ")} ]`);for(let N of H)X.selectorAtoms=X.selectorAtoms.set({selectorKey:Y,atomKey:N})}_.add(q)},j0=(Q,Z,Y,G)=>({get:(..._)=>{let X=O(Q),W;if(_.length===2){let[z,L]=_;W=$(Q,z,L)}else[W]=_;let q=A(Q,W),H=O0(Q,q),N=W.key;return Q.logger.info("\uD83D\uDD0C",Z,Y,`registers dependency ( "${N}" =`,H,")"),X.selectorGraph.set({upstreamSelectorKey:N,downstreamSelectorKey:Y},{source:W.key}),iQ(Q,Z,Y,W,G),H},set:(..._)=>{let X,W;if(_.length===2)X=_[0],W=_[1];else{let N=_[0],z=_[1];W=_[2],X=$(Q,N,z)}let q=O(Q),H=A(q,X);OQ(q,H,W)},find:(..._)=>$(Q,..._),json:(_)=>n(Q,_)}),f0=(Q,Z,Y)=>{let G=O(Q),_=new I,X=new Set,{key:W,const:q}=Z,H="readonly_held_selector",{get:N,find:z,json:L}=j0(G,"readonly_held_selector",W,X),C={...Z,type:"readonly_held_selector",subject:_,install:(B)=>f0(B,Z,Y),get:()=>{return Z.get({get:N,find:z,json:L},q),u(O(Q),W,q,_),X.clear(),q},...Y&&{family:Y}};G.readonlySelectors.set(W,C),Q.logger.info("\u2728","readonly_held_selector",W,"=",q);let E={key:W,type:"readonly_held_selector"};if(Y)E.family=Y;return E},b0=(Q,Z,Y)=>{let G=O(Q),_=new I,X=new Set,W=Z.key,q="readonly_pure_selector",{get:H,find:N,json:z}=j0(G,"readonly_pure_selector",W,X),L=()=>{let B=Z.get({get:H,find:N,json:z});return u(O(Q),W,B,_),X.clear(),B},M={...Z,type:"readonly_pure_selector",subject:_,install:(B)=>b0(B,Z,Y),get:L,...Y&&{family:Y}};G.readonlySelectors.set(W,M);let C=L();Q.logger.info("\u2728","readonly_pure_selector",W,"=",C);let E={key:W,type:"readonly_pure_selector"};if(Y)E.family=Y;return E},g0=(Q,Z,Y)=>{let G=O(Q),_=new I,X=new Set,{key:W,const:q}=Z,H="writable_held_selector",N=j0(G,"writable_held_selector",W,X),{find:z,get:L,json:M}=N,C={find:z,get:L,json:M},E=(T=Z.get,D=O(Q))=>{return T(C,q),u(D,W,q,_),X.clear(),q},K={...Z,type:"writable_held_selector",subject:_,install:(T)=>g0(T,Z,Y),get:E,set:(T)=>{let D=O(Q),J=E(Z.get,D),j=S0(T)(J);if(Q.logger.info("\uD83D\uDCDD","writable_held_selector",W,"set (",J,"->",j,")"),u(D,W,j,_),N0(D,W),y(D))_.next({newValue:j,oldValue:J});Z.set(N,j)},...Y&&{family:Y}};G.writableSelectors.set(W,K);let l=E();Q.logger.info("\u2728","writable_held_selector",W,"=",l);let d={key:W,type:"writable_held_selector"};if(Y)d.family=Y;return d},d0=(Q,Z,Y)=>{let G=O(Q),_=new I,X=new Set,W=Z.key,q="writable_pure_selector",H=j0(G,"writable_pure_selector",W,X),{find:N,get:z,json:L}=H,M={find:N,get:z,json:L},C=(d=Z.get,T=O(Q))=>{let D=d(M);return u(T,W,D,_),X.clear(),D},B={...Z,type:"writable_pure_selector",subject:_,install:(d)=>d0(d,Z,Y),get:C,set:(d)=>{let T=O(Q),D=C(Z.get,T),J=S0(d)(D);if(Q.logger.info("\uD83D\uDCDD","writable_pure_selector",W,"set (",D,"->",J,")"),u(T,Z.key,J,_),N0(T,Z.key),y(T))_.next({newValue:J,oldValue:D});Z.set(H,J)},...Y&&{family:Y}};G.writableSelectors.set(W,B);let K=C();Q.logger.info("\u2728",B.type,B.key,"=",K);let l={key:W,type:"writable_pure_selector"};if(Y)l.family=Y;return l};function F0(Q,Z){let Y="set"in Z,G="const"in Z;if(G&&Y){let X=g0(Q,Z,void 0);return Q.on.selectorCreation.next(X),X}if(G){let X=f0(Q,Z,void 0);return Q.on.selectorCreation.next(X),X}if(Y){let X=d0(Q,Z,void 0);return Q.on.selectorCreation.next(X),X}let _=b0(Q,Z,void 0);return Q.on.selectorCreation.next(_),_}function nQ(Q,Z){let Y=O(Q),{key:G,type:_}=Z,X=A(Y,Z);if(!X.family)Q.logger.error("\u274C",_,G,"Standalone selectors cannot be disposed.");else{if(Y.molecules.get(X.family.subKey))Y.moleculeData.delete(X.family.subKey,X.family.key);let q;switch(Z.type){case"writable_held_selector":Y.writableSelectors.delete(G),q={key:X.family.key,type:"writable_held_selector_family"},A(Q,q).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"writable_pure_selector":Y.writableSelectors.delete(G),q={key:X.family.key,type:"writable_pure_selector_family"},A(Q,q).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"readonly_held_selector":Y.readonlySelectors.delete(G),q={key:X.family.key,type:"readonly_held_selector_family"},A(Q,q).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"readonly_pure_selector":Y.readonlySelectors.delete(G),q={key:X.family.key,type:"readonly_pure_selector_family"},A(Q,q).subject.next({type:"state_disposal",subType:"selector",token:Z});break}if(Y.valueMap.delete(G),Y.selectorAtoms.delete(G),Y.selectorGraph.delete(G),Q.logger.info("\uD83D\uDD25",Z.type,G,"deleted"),x(Y)&&Y.transactionMeta.phase==="building")Y.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:Z});else Q.on.selectorDisposal.next(Z)}}function t(Q,Z,Y){let G=Z.key,_="readonly_pure_selector_family",X={key:G,type:"readonly_pure_selector_family"},W=Q.families.get(G);if(W)Q.logger.error("\u2757","readonly_pure_selector_family",G,`Overwriting an existing ${i(W)} "${W.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let q=new I,N=Object.assign((z)=>{let L=h(z),M={key:G,subKey:L},C=`${G}(${L})`,E=O(Q),B=b0(E,{key:C,get:Z.get(z)},M);return q.next({type:"state_creation",token:B}),B},X,{internalRoles:Y,subject:q,install:(z)=>t(z,Z),default:(z)=>{return Z.get(z)({get:(...M)=>k(Q,...M),find:(...M)=>$(Q,...M),json:(M)=>n(Q,M)})}});return Q.families.set(G,N),X}function EQ(Q,Z,Y){let G=Z.key,_="readonly_held_selector_family",X={key:G,type:"readonly_held_selector_family"},W=Q.families.get(G);if(W)Q.logger.error("\u2757","readonly_held_selector_family",G,`Overwriting an existing ${i(W)} "${W.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let q=new I,N=Object.assign((z)=>{let L=h(z),M={key:G,subKey:L},C=`${G}(${L})`,E=O(Q),B=f0(E,{key:C,const:Z.const(z),get:Z.get(z)},M);return q.next({type:"state_creation",token:B}),B},X,{internalRoles:Y,subject:q,install:(z)=>EQ(z,Z),default:Z.const});return Q.families.set(G,N),X}function CQ(Q,Z,Y){let G=Z.key,_="writable_held_selector_family",X={key:G,type:"writable_held_selector_family"},W=Q.families.get(G);if(W)Q.logger.error("\u2757","writable_held_selector_family",G,`Overwriting an existing ${i(W)} "${W.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let q=new I,N=Object.assign((z)=>{let L=h(z),M={key:G,subKey:L},C=`${G}(${L})`,E=O(Q),B=g0(E,{key:C,const:Z.const(z),get:Z.get(z),set:Z.set(z)},M);return q.next({type:"state_creation",token:B}),B},X,{internalRoles:Y,subject:q,install:(z)=>CQ(z,Z),default:Z.const});return Q.families.set(G,N),X}function L0(Q,Z,Y){let G=Z.key,_="writable_pure_selector_family",X={key:G,type:"writable_pure_selector_family"},W=Q.families.get(G);if(W)Q.logger.error("\u2757","writable_pure_selector_family",G,`Overwriting an existing ${i(W)} "${W.key}" in store "${Q.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let q=new I,N=Object.assign((z)=>{let L=h(z),M={key:G,subKey:L},C=`${G}(${L})`,E=O(Q),B=d0(E,{key:C,get:Z.get(z),set:Z.set(z)},M);return q.next({type:"state_creation",token:B}),B},X,{internalRoles:Y,subject:q,install:(z)=>L0(z,Z),default:(z)=>{return Z.get(z)({get:(...M)=>k(Q,...M),find:(...M)=>$(Q,...M),json:(M)=>n(Q,M)})}});return Q.families.set(G,N),X}function ZQ(Q,Z){let Y="set"in Z,G="const"in Z;if(G&&Y)return CQ(Q,Z,void 0);if(G)return EQ(Q,Z,void 0);if(Y)return L0(Q,Z);return t(Q,Z)}function rQ(Q,Z,Y){let G=Q.families.get(Z.key);if(G===void 0)throw new v0(Z,Q);let _=G(Y),X=O(Q);if(_.family){if(y(X))switch(_.type){case"atom":case"mutable_atom":Q.on.atomCreation.next(_);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":Q.on.selectorCreation.next(_);break}else if(x(X)&&X.on.transactionApplying.state===null)X.transactionMeta.update.updates.push({type:"state_creation",token:_})}return _}function aQ(Q,Z,Y){let G=h(Y),_=`${Z.key}(${G})`,X=O(Q),W;switch(Z.type){case"atom_family":case"mutable_atom_family":W=X.atoms.get(_);break;case"writable_held_selector_family":case"writable_pure_selector_family":W=X.writableSelectors.get(_);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":W=X.readonlySelectors.get(_);break}if(W)return e(W);return W}function $(Q,Z,Y){let G=aQ(Q,Z,Y);if(G)return G;let _=h(Y),X=Q.molecules.get(_);if(!X&&Q.config.lifespan==="immortal"){let W=gQ(Z,Y);return Q.logger.error("\u274C",W.type,W.key,`was not found in store "${Q.config.name}"; returned a counterfeit token.`),W}if(G=rQ(Q,Z,Y),X)O(Q).moleculeData.set(_,Z.key);return G}function a(Q,...Z){let Y;if(Z.length===1)Y=Z[0];else{let G=Z[0],_=Z[1];Y=$(Q,G,_)}try{A(Q,Y)}catch(G){Q.logger.error("\u274C",Y.type,Y.key,`could not be disposed because it was not found in the store "${Q.config.name}".`);return}switch(Y.type){case"atom":case"mutable_atom":FQ(Q,Y);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":nQ(Q,Y);break}}function PQ(Q,Z){if(Z.family){let Y=Q.families.get(Z.family.key);if(Y)return Y}}function E0(Q,...Z){let Y,G,_;if(Z.length===1){if(Y=Z[0],G=PQ(Q,Y)??null,G)_=Y.family?v(Y.family.subKey):null,Y=$(Q,G,_)}else G=Z[0],_=Z[1],Y=$(Q,G,_);if("counterfeit"in Y&&"family"in Y){let q=Y.family.subKey,H=Q.disposalTraces.buffer.find((N)=>N?.key===q);Q.logger.error("\u274C",Y.type,Y.key,`could not be reset because it was not found in the store "${Q.config.name}".`,H?`This state was previously disposed:
|
|
4
4
|
${H.trace}`:"No previous disposal trace was found.");return}let X=C0(Q,Y);if(X){let q=Q.on.operationClose.subscribe(`waiting to reset "${Y.key}" at T-${X}`,()=>{q(),Q.logger.info("\uD83D\uDFE2",Y.type,Y.key,`resuming deferred resetState from T-${X}`),E0(Q,Y)});return}let W=A(Q,Y);uQ(Q,W),P0(Q)}var OQ=(Q,Z,Y)=>{switch(Z.type){case"atom":case"mutable_atom":LQ(Q,Z,Y);break;case"writable_pure_selector":case"writable_held_selector":Z.set(Y);break}};function g(Q,...Z){let Y,G,_,X;if(Z.length===2){if(Y=Z[0],X=Z[1],G=PQ(Q,Y)??null,G)_=Y.family?v(Y.family.subKey):null,Y=$(Q,G,_)}else G=Z[0],_=Z[1],X=Z[2],Y=$(Q,G,_);if("counterfeit"in Y&&"family"in Y){let H=Y.family.subKey,N=Q.disposalTraces.buffer.find((z)=>z?.key===H);Q.logger.error("\u274C",Y.type,Y.key,`could not be set because it was not found in the store "${Q.config.name}".`,N?`This state was previously disposed:
|
|
5
5
|
${N.trace}`:"No previous disposal trace was found.");return}let W=C0(Q,Y);if(W){let H=Q.on.operationClose.subscribe(`waiting to set "${Y.key}" at T-${W}`,()=>{H(),Q.logger.info("\uD83D\uDFE2",Y.type,Y.key,`resuming deferred setState from T-${W}`),g(Q,Y,X)});return}let q=A(Q,Y);OQ(Q,q,X),P0(Q)}function sQ(Q,Z,Y){let{key:G,newValue:_,oldValue:X}=Z,W=Q==="newValue"?_:X,q={key:G,type:"atom"};if(Z.family)Object.assign(q,{family:Z.family});g(Y,q,W)}function oQ(Q){let{stack:Z}=Q;if(Z)return`
|
|
6
6
|
`+Z.split(`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var OC=Object.create;var{getPrototypeOf:wC,defineProperty:sU,getOwnPropertyNames:VC}=Object;var DC=Object.prototype.hasOwnProperty;var EC=($,X,Y)=>{Y=$!=null?OC(wC($)):{};let z=X||!$||!$.__esModule?sU(Y,"default",{value:$,enumerable:!0}):Y;for(let G of VC($))if(!DC.call(z,G))sU(z,G,{get:()=>$[G],enumerable:!0});return z};var NC=($,X)=>()=>(X||$((X={exports:{}}).exports,X),X.exports);var Z8=($,X)=>{for(var Y in X)sU($,Y,{get:X[Y],enumerable:!0,configurable:!0,set:(z)=>X[Y]=()=>z})};var By=($,X)=>()=>($&&(X=$($=0)),X);var sE=import.meta.require;var eF=NC((sc,sF)=>{var PG=sE("os"),vG=sE("path");function aF($){let X=process.env.XDG_CACHE_HOME||vG.join(PG.homedir(),".cache");return vG.join(X,$)}function Xx($){return vG.join(PG.homedir(),"Library","Caches",$)}function Yx($){let X=process.env.LOCALAPPDATA||vG.join(PG.homedir(),"AppData","Local");return vG.join(X,$,"Cache")}var Gx=function(){switch(PG.platform()){case"darwin":return Xx;case"win32":return Yx;case"aix":case"android":case"freebsd":case"linux":case"netbsd":case"openbsd":case"sunos":return aF;default:return console.error(`(node:${process.pid}) [cachedir] Warning: the platform "${PG.platform()}" is not currently supported by node-cachedir, falling back to "posix". Please file an issue with your platform here: https://github.com/LinusU/node-cachedir/issues/new`),aF}}();sF.exports=function $(X){if(typeof X!=="string")throw new TypeError("id is not a string");if(X.length===0)throw new Error("id cannot be empty");if(/[^0-9a-zA-Z-]/.test(X))throw new Error("id cannot contain special characters");return Gx(X)}});var eE=($,X,Y=R6.STORE)=>{return eU(Y,{key:`${$.key}:JSON`,get:({get:z})=>X.toJson(z($)),set:({set:z},G)=>{z($,X.fromJson(G))}})};function $N($,X,Y){return w7($,{key:`${X.key}:JSON`,get:(G)=>({get:U})=>{let W=U(X,G);return Y.toJson(W)},set:(G)=>({set:U},W)=>{U(X,G,Y.fromJson(W))}},["mutable","json"])}var N4=($)=>JSON.parse($),d$=($)=>JSON.stringify($),Sy=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];function oX($){return HN(R6.STORE,$)}function b2($){return UN(R6.STORE,$)}function XW(...$){if($.length===2)return b1(R6.STORE,...$);return b1(R6.STORE,...$)}function V7($,X,Y=R6.STORE){return Y.joins.set($.key,new UW($,X,Y)),{key:$.key,type:"join",a:$.between[0],b:$.between[1],cardinality:$.cardinality}}function XN($){return wN($,R6.STORE)}var $W=($)=>(X,Y,z,G,...U)=>{console[$](`${X} ${Y} "${z}" ${G}`,...U)},FC={error:$W("error"),info:$W("info"),warn:$W("warn")},YN=class{logLevel;filter;logger;constructor($,X,Y=FC){this.logLevel=$,this.filter=X,this.logger=Y}error=(...$)=>{let X=this.filter?.(...$)??!0;if(this.logLevel!==null){if(X===!0)this.logger.error(...$);else if(X!==!1)this.logger.error(...X)}};info=(...$)=>{let X=this.filter?.(...$)??!0;if(this.logLevel==="info"){if(X===!0)this.logger.info(...$);else if(X!==!1)this.logger.info(...X)}};warn=(...$)=>{let X=this.filter?.(...$)??!0;if(this.logLevel!=="error"&&this.logLevel!==null){if(X===!0)this.logger.warn(...$);else if(X!==!1)this.logger.warn(...X)}}};var MC=class{store;constructor($=R6.STORE){this.store=$,WN("root",$)}allocate($,X,Y){return aX(this.store,$,X,Y)}fuse($,X,Y){return QN(this.store,$,X,Y)}deallocate($){sX(this.store,$)}claim($,X,Y){return f2(this.store,$,X,Y)}},GN=class{store;realm;constructor($=R6.STORE){this.store=$,this.realm=new MC($)}allocate($,X,Y){aX(this.store,$,X,Y)}deallocate($){sX(this.store,$)}claim($,X,Y){f2(this.store,$,X,Y)}};function D7($){return GW(R6.STORE,$)}function h2($){return zW(R6.STORE,$)}var y4=class $ extends Set{mode="record";subject=new y$;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(X,Y=0){super(X);if(X instanceof $)this.parent=X,this.cacheUpdateNumber=X.cacheUpdateNumber;if(Y)this.cacheLimit=Y,this.cache=new Array(Y),this.subscribe("auto cache",(z)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=z})}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(X){let Y=new $(X.members,X.cacheLimit);return Y.cache=X.cache,Y.cacheIdx=X.cacheIdx,Y.cacheUpdateNumber=X.cacheUpdateNumber,Y}add(X){let Y=super.add(X);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${d$(X)}`);return Y}clear(){let X=this.mode==="record"?[...this]:null;if(super.clear(),X)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(X)}`)}delete(X){let Y=super.delete(X);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${d$(X)}`);return Y}parent=null;child=null;transactionUpdates=null;transaction(X){this.mode="transaction",this.transactionUpdates=[],this.child=new $(this);let Y=this.child._subscribe("transaction",(z)=>{this.transactionUpdates?.push(z)});try{if(X(this.child)){for(let G of this.transactionUpdates)this.doStep(G);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(z){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",z),z}finally{Y(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(X,Y){return this.subject.subscribe(X,Y)}subscribe(X,Y){return this.subject.subscribe(X,(z)=>{Y(`${this.cacheUpdateNumber}=${z}`)})}emit(X){this.subject.next(X)}doStep(X){let Y=X.indexOf(":"),z=X.substring(0,Y),G=X.substring(Y+1);switch(z){case"add":this.add(JSON.parse(G));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(G));break;case"tx":for(let U of G.split(";"))this.doStep(U)}}getUpdateNumber(X){let Y=X.indexOf("=");return Number(X.substring(0,Y))}do(X){let Y=X.indexOf("="),z=Number(X.substring(0,Y)),G=z-this.cacheUpdateNumber;if(G>0){if(G===1){this.mode="playback";let W=X.substring(Y+1);return this.doStep(W),this.mode="record",this.cacheUpdateNumber=z,null}return this.cacheUpdateNumber+1}if(Math.abs(G)<this.cacheLimit){let W=this.cacheIdx+G;if(this.cache[W]===X)return null;this.mode="playback";let H=!1;while(!H){this.cacheIdx%=this.cacheLimit;let O=this.cache[this.cacheIdx];if(this.cacheIdx--,!O)return"OUT_OF_RANGE";this.undo(O),H=this.cacheIdx===W-1}let Z=X.substring(Y+1);return this.doStep(Z),this.mode="record",this.cacheUpdateNumber=z,null}return"OUT_OF_RANGE"}undoStep(X){let Y=X.indexOf(":"),z=X.substring(0,Y),G=X.substring(Y+1);switch(z){case"add":this.delete(JSON.parse(G));break;case"del":this.add(JSON.parse(G));break;case"clear":{let U=JSON.parse(G);for(let W of U)this.add(W);break}case"tx":{let U=G.split(";");for(let W=U.length-1;W>=0;W--)this.undoStep(U[W])}}}undo(X){let Y=X.indexOf("=");if(Number(X.substring(0,Y))===this.cacheUpdateNumber){this.mode="playback";let G=X.substring(Y+1);return this.undoStep(G),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function zN($=Math.random){return $().toString(36).slice(2)}var WW=class extends Promise{fate;resolve;reject;done=!1;constructor($){let X,Y;super((z,G)=>{X=z,Y=G});this.resolve=X,this.reject=Y,this.use($ instanceof Promise?$:new Promise($))}pass($,X){if($===this.fate)this.resolve(X),this.done=!0}fail($,X){if($===this.fate)this.reject(X),this.done=!0}use($){if($ instanceof Promise){let X=$;this.fate=X,X.then((Y)=>{this.pass(X,Y)},(Y)=>{this.fail(X,Y)})}else this.resolve($),this.fate=void 0}};function N$($){while($.child!==null)$=$.child;return $}var JC=class ${_buffer;_index=0;constructor(X){let Y;if(typeof X==="number")Y=X;else Y=X.length;this._buffer=Array.from({length:Y})}get buffer(){return this._buffer}get index(){return this._index}add(X){this._buffer[this._index]=X,this._index=(this._index+1)%this._buffer.length}copy(){let X=new $([...this._buffer]);return X._index=this._index,X}},AC={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function KC($,X){let Y=d$(X),z=`${$.key}(${Y})`,G=AC[$.type],U={key:z,type:G};return Object.assign(U,{family:{key:$.key,subKey:Y}}),Object.assign(U,{counterfeit:!0}),U}function L0($){let X={key:$.key,type:$.type};if("family"in $)X.family=$.family;return X}var F4=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=($,X)=>`${$}:${X}`;warn;getRelatedKeys($){return this.relations.get($)}addRelation($,X){let Y=this.relations.get($),z=this.relations.get(X);if(Y)Y.add(X);else Y=new Set([X]),this.relations.set($,Y);if(z)z.add($);else z=new Set([$]),this.relations.set(X,z)}deleteRelation($,X){let Y=this.relations.get($);if(Y){if(Y.delete(X),Y.size===0)this.relations.delete($);let z=this.relations.get(X);if(z){if(z.delete($),z.size===0)this.relations.delete(X)}}}replaceRelationsUnsafely($,X){this.relations.set($,new Set(X));for(let Y of X){let z=new Set().add($);this.relations.set(Y,z)}}replaceRelationsSafely($,X){let Y=this.relations.get($),z=this.isAType?.($)?$:void 0,G=z===void 0?$:void 0;if(Y)for(let U of Y){z??=U,G??=U;let W=this.relations.get(U);if(W){if(W.size===1)this.relations.delete(U);else W.delete($);this.contents.delete(this.makeContentKey(z,G))}}this.relations.set($,new Set(X));for(let U of X){let W=this.relations.get(U);if(W)W.add($);else W=new Set().add($),this.relations.set(U,W)}}getContentInternal($){return this.contents.get($)}setContent($,X){this.contents.set($,X)}deleteContent($){this.contents.delete($)}constructor($,X){if(this.a=$.between[0],this.b=$.between[1],this.cardinality=$.cardinality,!X?.externalStore)this.relations=new Map($.relations?.map(([Y,z])=>[Y,new Set(z)])),this.contents=new Map($.contents);if(this.isAType=X?.isAType??null,this.isBType=X?.isBType??null,this.isContent=X?.isContent??null,X?.makeContentKey)this.makeContentKey=X.makeContentKey;if(X?.externalStore){let Y=X.externalStore;if(this.has=(z,G)=>Y.has(z,G),this.addRelation=(z,G)=>{Y.addRelation(z,G)},this.deleteRelation=(z,G)=>{Y.deleteRelation(z,G)},this.replaceRelationsSafely=(z,G)=>{Y.replaceRelationsSafely(z,G)},this.replaceRelationsUnsafely=(z,G)=>{Y.replaceRelationsUnsafely(z,G)},this.getRelatedKeys=(z)=>Y.getRelatedKeys(z),Y.getContent)this.getContentInternal=(z)=>{return Y.getContent(z)},this.setContent=(z,G)=>{Y.setContent(z,G)},this.deleteContent=(z)=>{Y.deleteContent(z)};for(let[z,G]of $.relations??[]){let U=this.isAType?.(z)?z:void 0,W=U===void 0?z:void 0;for(let Q of G)U??=Q,W??=Q,this.addRelation(U,W)}for(let[z,G]of $.contents??[])this.setContent(z,G)}if(X?.warn)this.warn=X.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([$,X])=>[$,[...X]]),contents:[...this.contents.entries()]}}set(...$){let X,Y,z;switch($.length){case 1:{let G=$[0];X=G[this.a],Y=G[this.b],z=void 0;break}case 2:{let G=$[0];if(typeof G==="string")[X,Y]=$;else X=G[this.a],Y=G[this.b],z=$[1];break}default:{X=$[0],Y=$[1],z=$[2];break}}switch(this.cardinality){case"1:1":{let G=this.getRelatedKey(X);if(G&&G!==Y)this.delete(X,G)}case"1:n":{let G=this.getRelatedKey(Y);if(G&&G!==X)this.delete(G,Y)}break;case"n:n":}if(z){let G=this.makeContentKey(X,Y);this.setContent(G,z)}return this.addRelation(X,Y),this}delete($,X){X=typeof X==="string"?X:$[this.b];let Y=typeof $==="string"?$:$[this.a];if(Y===void 0&&typeof X==="string"){let z=this.getRelatedKeys(X);if(z)for(let G of z)this.delete(G,X)}if(typeof Y==="string"&&X===void 0){let z=this.getRelatedKeys(Y);if(z)for(let G of z)this.delete(Y,G)}if(typeof Y==="string"&&typeof X==="string"){this.deleteRelation(Y,X);let z=this.makeContentKey(Y,X);this.deleteContent(z)}return this}getRelatedKey($){let X=this.getRelatedKeys($);if(X){if(X.size>1)this.warn?.(`${X.size} related keys were found for key "${$}": (${[...X].map((z)=>`"${z}"`).join(", ")}). Only one related key was expected.`);let Y;for(let z of X){Y=z;break}return Y}}replaceRelations($,X,Y){let z=!Array.isArray(X),G=z?Object.keys(X):X;if(Y?.reckless)this.replaceRelationsUnsafely($,G);else this.replaceRelationsSafely($,G);if(z)for(let U of G){let W=this.makeContentKey($,U),Q=X[U];this.setContent(W,Q)}return this}getContent($,X){let Y=this.makeContentKey($,X);return this.getContentInternal(Y)}getRelationEntries($){let X=$[this.a],Y=$[this.b];if(X!==void 0&&Y===void 0){let z=this.getRelatedKeys(X);if(z)return[...z].map((G)=>{return[G,this.getContent(X,G)]})}if(X===void 0&&Y!==void 0){let z=this.getRelatedKeys(Y);if(z)return[...z].map((G)=>{return[G,this.getContent(G,Y)]})}return[]}has($,X){if(X)return this.getRelatedKeys($)?.has(X)??!1;return this.relations.has($)}},y$=class{Subscriber;subscribers=new Map;subscribe($,X){return this.subscribers.set($,X),()=>{this.unsubscribe($)}}unsubscribe($){this.subscribers.delete($)}next($){let X=this.subscribers.values();for(let Y of X)Y($)}},_C=class extends y${state;constructor($){super();this.state=$}next($){this.state=$,super.next($)}};function H8($){return"epoch"in $.transactionMeta}function t6($){return"phase"in $.transactionMeta}var qC=($)=>{let X=N$($);if(!t6(X)){$.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}$.logger.info("\uD83E\uDE82","transaction",X.transactionMeta.update.key,"Aborting transaction"),X.parent.child=null};function U6($){return $[0].toUpperCase()+$.slice(1)}function r8($){return $.type.split("_").map(U6).join(" ")}var OW=class extends Error{constructor($,X){super(`${r8($)} ${d$($.key)} not found in store "${X.config.name}".`)}};function YW($,X,Y){return(...z)=>{let G=P6($,X);if(G)return G.run(z,Y);throw new OW(X,$)}}var wW=($)=>(X)=>$ instanceof Function?$(X):$,M7=($,X)=>{if($.valueMap.has(X.key))return $.logger.info("\uD83D\uDCD6",X.type,X.key,"reading cached value"),aC(X,$);switch(X.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return $.logger.info("\uD83E\uDDEE",X.type,X.key,"computing value"),X.get();case"atom":case"mutable_atom":{let Y=X.default,z;if(Y instanceof Function)z=Y();else z=Y;return $.logger.info("\uD83D\uDC81","atom",X.key,"could not find cached value; using default",z),z}}},N7=($,X)=>{if($.operation.open){let Y=performance.now();return $.logger.info("\u2757",X.type,X.key,`deferring setState at T-${Y} until setState for "${$.operation.token.key}" is done`),Y}$.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:X},$.logger.info("\u2B55",X.type,X.key,`operation start in store "${$.config.name}"${!t6($)?"":` ${$.transactionMeta.phase} "${$.transactionMeta.update.key}"`}`)},F7=($)=>{if($.operation.open)$.logger.info("\uD83D\uDD34",$.operation.token.type,$.operation.token.key,`operation done in store "${$.config.name}"`);$.operation={open:!1},$.on.operationClose.next($.operation)},FN=($,X)=>{if(!$.operation.open)return $.logger.error("\uD83D\uDC1E","unknown",X,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return $.operation.done.has(X)},u2=($,X)=>{if(!$.operation.open){$.logger.error("\uD83D\uDC1E","unknown",X,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}$.operation.done.add(X)},TC=($,X,Y)=>{switch(X.type){case"mutable_atom":$.logger.info("\uD83D\uDCE2",X.type,X.key,"is now (",Y.newValue,") subscribers:",X.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":$.logger.info("\uD83D\uDCE2",X.type,X.key,"went (",Y.oldValue,"->",Y.newValue,") subscribers:",X.subject.subscribers)}X.subject.next(Y)};function QW($,X){let Y=N$($),z=Y.selectorAtoms.getRelatedKeys(X.key);if(Y.logger.info("\uD83E\uDDF9",X.type,X.key,z?`evicting ${z.size} states downstream:`:"no downstream states",z??"to evict"),z){if(Y.operation.open)Y.logger.info("\uD83E\uDDF9",X.type,X.key,`[ ${[...Y.operation.done].join(", ")} ] already done`);for(let G of z){if(FN(Y,G))continue;vN(G,Y),u2(Y,G)}}}function RC($,X){let Y=N$($),z=Y.selectorGraph.getRelationEntries({upstreamSelectorKey:X.key}).filter(([G,{source:U}])=>U===X.key);for(let[G]of z){if(FN(Y,G))continue;vN(G,Y),u2(Y,G)}}var MN=($,X,Y)=>{let z=M7($,X),G=z;if(X.type==="mutable_atom"&&t6($)){let{parent:W}=$;G=HW($,X,W)}G=wW(Y)(G),$.logger.info("\uD83D\uDCDD","atom",X.key,"set to",G),G=s1($,X.key,G,X.subject),u2($,X.key),QW($,X);let U={oldValue:z,newValue:G};if(!t6($)){TC($,X,U);return}if($.on.transactionApplying.state===null){let{key:W}=X;if(tC(U.newValue))return;let Q={type:"atom_update",key:W,...U};if(X.family)Q.family=X.family;$.transactionMeta.update.updates.push(Q),$.logger.info("\uD83D\uDCC1","atom",W,"stowed (",U.oldValue,"->",U.newValue,")")}else if(X.key.startsWith("*")){let W=X.key.slice(1),Q=$.atoms.get(W),H=$.valueMap.get(W);if(Q.type==="mutable_atom"&&t6($)){let{parent:O}=$;H=HW($,Q,O)}if(H.do(U.newValue)===null)QW($,Q)}};function DN($,X){let Y=X.default;if(Y instanceof Function)Y=Y();MN($,X,Y)}function PC($,X){switch(X.type){case"atom":case"mutable_atom":DN($,X);break;case"writable_pure_selector":case"writable_held_selector":{let Y=JN(X,$);for(let z of Y)DN($,z)}break}}function m2($,X,Y){let z={key:X.key,type:"atom_family"},G=$.families.get(X.key);if(G)$.logger.error("\u2757","atom_family",X.key,`Overwriting an existing ${r8(G)} "${G.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let U=new y$,Q=Object.assign((H)=>{let Z=d$(H),O={key:X.key,subKey:Z},w=`${X.key}(${Z})`,V=N$($),D=X.default,E={key:w,default:D instanceof Function?D(H):D};if(X.effects)E.effects=X.effects(H);let F=o8(V,E,O);return U.next({type:"state_creation",token:F}),F},z,{subject:U,install:(H)=>m2(H,X),internalRoles:Y});return $.families.set(X.key,Q),$.defaults.set(X.key,X.default),z}function UN($,X){if("mutable"in X)return JW($,X);return m2($,X)}var VW=($,X)=>N$($).atoms.has(X),vC=($,X)=>N$($).writableSelectors.has(X),CC=($,X)=>N$($).readonlySelectors.has(X),jC=($,X)=>VW($,X)||vC($,X)||CC($,X),ZW=($,X)=>{return N$($).selectorGraph.getRelationEntries({downstreamSelectorKey:X}).filter(([z,{source:G}])=>G!==X).map(([z,{source:G}])=>G).filter((z)=>jC($,z))},LN=($,X,Y)=>{let z=[],G=ZW($,X);while(G.length>0){let U=G.shift();if(Y.has(U))continue;if(Y.add(U),!VW($,U))G.push(...ZW($,U));else if(!z.includes(U))z.push(U)}return z},JN=($,X)=>{let Y=$.key,z=ZW(X,Y),G=new Set;return z.flatMap((U)=>VW(X,U)?U:LN(X,U,G)).map((U)=>X.atoms.get(U))},BC=($,X,Y,z,G)=>{let U=N$($),{type:W,key:Q}=z;if(W==="atom"||W==="mutable_atom")U.selectorAtoms.set({selectorKey:Y,atomKey:Q}),$.logger.info("\uD83D\uDD0D",X,Y,`discovers root atom "${Q}"`);else{let H=LN($,Q,G);$.logger.info("\uD83D\uDD0D",X,Y,`discovers root atoms: [ ${H.map((Z)=>`"${Z}"`).join(", ")} ]`);for(let Z of H)U.selectorAtoms=U.selectorAtoms.set({selectorKey:Y,atomKey:Z})}G.add(Q)},L7=($,X,Y,z)=>({get:(...G)=>{let U=N$($),W;if(G.length===2){let[O,w]=G;W=g$($,O,w)}else[W]=G;let Q=P6($,W),H=M7($,Q),Z=W.key;return $.logger.info("\uD83D\uDD0C",X,Y,`registers dependency ( "${Z}" =`,H,")"),U.selectorGraph.set({upstreamSelectorKey:Z,downstreamSelectorKey:Y},{source:W.key}),BC($,X,Y,W,z),H},set:(...G)=>{let U,W;if(G.length===2)U=G[0],W=G[1];else{let Z=G[0],O=G[1];W=G[2],U=g$($,Z,O)}let Q=N$($),H=P6(Q,U);qN(Q,H,W)},find:(...G)=>g$($,...G),json:(G)=>n8($,G)}),DW=($,X,Y)=>{let z=N$($),G=new y$,U=new Set,{key:W,const:Q}=X,H="readonly_held_selector",{get:Z,find:O,json:w}=L7(z,"readonly_held_selector",W,U),D={...X,type:"readonly_held_selector",subject:G,install:(F)=>DW(F,X,Y),get:()=>{return X.get({get:Z,find:O,json:w},Q),s1(N$($),W,Q,G),U.clear(),Q},...Y&&{family:Y}};z.readonlySelectors.set(W,D),$.logger.info("\u2728","readonly_held_selector",W,"=",Q);let E={key:W,type:"readonly_held_selector"};if(Y)E.family=Y;return E},EW=($,X,Y)=>{let z=N$($),G=new y$,U=new Set,W=X.key,Q="readonly_pure_selector",{get:H,find:Z,json:O}=L7(z,"readonly_pure_selector",W,U),w=()=>{let F=X.get({get:H,find:Z,json:O});return s1(N$($),W,F,G),U.clear(),F},V={...X,type:"readonly_pure_selector",subject:G,install:(F)=>EW(F,X,Y),get:w,...Y&&{family:Y}};z.readonlySelectors.set(W,V);let D=w();$.logger.info("\u2728","readonly_pure_selector",W,"=",D);let E={key:W,type:"readonly_pure_selector"};if(Y)E.family=Y;return E},NW=($,X,Y)=>{let z=N$($),G=new y$,U=new Set,{key:W,const:Q}=X,H="writable_held_selector",Z=L7(z,"writable_held_selector",W,U),{find:O,get:w,json:V}=Z,D={find:O,get:w,json:V},E=(R=X.get,_=N$($))=>{return R(D,Q),s1(_,W,Q,G),U.clear(),Q},L={...X,type:"writable_held_selector",subject:G,install:(R)=>NW(R,X,Y),get:E,set:(R)=>{let _=N$($),v=E(X.get,_),x=wW(R)(v);if($.logger.info("\uD83D\uDCDD","writable_held_selector",W,"set (",v,"->",x,")"),s1(_,W,x,G),u2(_,W),H8(_))G.next({newValue:x,oldValue:v});X.set(Z,x)},...Y&&{family:Y}};z.writableSelectors.set(W,L);let K=E();$.logger.info("\u2728","writable_held_selector",W,"=",K);let q={key:W,type:"writable_held_selector"};if(Y)q.family=Y;return q},FW=($,X,Y)=>{let z=N$($),G=new y$,U=new Set,W=X.key,Q="writable_pure_selector",H=L7(z,"writable_pure_selector",W,U),{find:Z,get:O,json:w}=H,V={find:Z,get:O,json:w},D=(q=X.get,R=N$($))=>{let _=q(V);return s1(R,W,_,G),U.clear(),_},F={...X,type:"writable_pure_selector",subject:G,install:(q)=>FW(q,X,Y),get:D,set:(q)=>{let R=N$($),_=D(X.get,R),v=wW(q)(_);if($.logger.info("\uD83D\uDCDD","writable_pure_selector",W,"set (",_,"->",v,")"),s1(R,X.key,v,G),u2(R,X.key),H8(R))G.next({newValue:v,oldValue:_});X.set(H,v)},...Y&&{family:Y}};z.writableSelectors.set(W,F);let L=D();$.logger.info("\u2728",F.type,F.key,"=",L);let K={key:W,type:"writable_pure_selector"};if(Y)K.family=Y;return K};function eU($,X){let Y="set"in X,z="const"in X;if(z&&Y){let U=NW($,X,void 0);return $.on.selectorCreation.next(U),U}if(z){let U=DW($,X,void 0);return $.on.selectorCreation.next(U),U}if(Y){let U=FW($,X,void 0);return $.on.selectorCreation.next(U),U}let G=EW($,X,void 0);return $.on.selectorCreation.next(G),G}function IC($,X){let Y=N$($),{key:z,type:G}=X,U=P6(Y,X);if(!U.family)$.logger.error("\u274C",G,z,"Standalone selectors cannot be disposed.");else{if(Y.molecules.get(U.family.subKey))Y.moleculeData.delete(U.family.subKey,U.family.key);let Q;switch(X.type){case"writable_held_selector":Y.writableSelectors.delete(z),Q={key:U.family.key,type:"writable_held_selector_family"},P6($,Q).subject.next({type:"state_disposal",subType:"selector",token:X});break;case"writable_pure_selector":Y.writableSelectors.delete(z),Q={key:U.family.key,type:"writable_pure_selector_family"},P6($,Q).subject.next({type:"state_disposal",subType:"selector",token:X});break;case"readonly_held_selector":Y.readonlySelectors.delete(z),Q={key:U.family.key,type:"readonly_held_selector_family"},P6($,Q).subject.next({type:"state_disposal",subType:"selector",token:X});break;case"readonly_pure_selector":Y.readonlySelectors.delete(z),Q={key:U.family.key,type:"readonly_pure_selector_family"},P6($,Q).subject.next({type:"state_disposal",subType:"selector",token:X});break}if(Y.valueMap.delete(z),Y.selectorAtoms.delete(z),Y.selectorGraph.delete(z),$.logger.info("\uD83D\uDD25",X.type,z,"deleted"),t6(Y)&&Y.transactionMeta.phase==="building")Y.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:X});else $.on.selectorDisposal.next(X)}}function i8($,X,Y){let z=X.key,G="readonly_pure_selector_family",U={key:z,type:"readonly_pure_selector_family"},W=$.families.get(z);if(W)$.logger.error("\u2757","readonly_pure_selector_family",z,`Overwriting an existing ${r8(W)} "${W.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let Q=new y$,Z=Object.assign((O)=>{let w=d$(O),V={key:z,subKey:w},D=`${z}(${w})`,E=N$($),F=EW(E,{key:D,get:X.get(O)},V);return Q.next({type:"state_creation",token:F}),F},U,{internalRoles:Y,subject:Q,install:(O)=>i8(O,X),default:(O)=>{return X.get(O)({get:(...V)=>b1($,...V),find:(...V)=>g$($,...V),json:(V)=>n8($,V)})}});return $.families.set(z,Z),U}function AN($,X,Y){let z=X.key,G="readonly_held_selector_family",U={key:z,type:"readonly_held_selector_family"},W=$.families.get(z);if(W)$.logger.error("\u2757","readonly_held_selector_family",z,`Overwriting an existing ${r8(W)} "${W.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let Q=new y$,Z=Object.assign((O)=>{let w=d$(O),V={key:z,subKey:w},D=`${z}(${w})`,E=N$($),F=DW(E,{key:D,const:X.const(O),get:X.get(O)},V);return Q.next({type:"state_creation",token:F}),F},U,{internalRoles:Y,subject:Q,install:(O)=>AN(O,X),default:X.const});return $.families.set(z,Z),U}function KN($,X,Y){let z=X.key,G="writable_held_selector_family",U={key:z,type:"writable_held_selector_family"},W=$.families.get(z);if(W)$.logger.error("\u2757","writable_held_selector_family",z,`Overwriting an existing ${r8(W)} "${W.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let Q=new y$,Z=Object.assign((O)=>{let w=d$(O),V={key:z,subKey:w},D=`${z}(${w})`,E=N$($),F=NW(E,{key:D,const:X.const(O),get:X.get(O),set:X.set(O)},V);return Q.next({type:"state_creation",token:F}),F},U,{internalRoles:Y,subject:Q,install:(O)=>KN(O,X),default:X.const});return $.families.set(z,Z),U}function w7($,X,Y){let z=X.key,G="writable_pure_selector_family",U={key:z,type:"writable_pure_selector_family"},W=$.families.get(z);if(W)$.logger.error("\u2757","writable_pure_selector_family",z,`Overwriting an existing ${r8(W)} "${W.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let Q=new y$,Z=Object.assign((O)=>{let w=d$(O),V={key:z,subKey:w},D=`${z}(${w})`,E=N$($),F=FW(E,{key:D,get:X.get(O),set:X.set(O)},V);return Q.next({type:"state_creation",token:F}),F},U,{internalRoles:Y,subject:Q,install:(O)=>w7(O,X),default:(O)=>{return X.get(O)({get:(...V)=>b1($,...V),find:(...V)=>g$($,...V),json:(V)=>n8($,V)})}});return $.families.set(z,Z),U}function GW($,X){let Y="set"in X,z="const"in X;if(z&&Y)return KN($,X,void 0);if(z)return AN($,X,void 0);if(Y)return w7($,X);return i8($,X)}function xC($,X,Y){let z=$.families.get(X.key);if(z===void 0)throw new OW(X,$);let G=z(Y),U=N$($);if(G.family){if(H8(U))switch(G.type){case"atom":case"mutable_atom":$.on.atomCreation.next(G);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":$.on.selectorCreation.next(G);break}else if(t6(U)&&U.on.transactionApplying.state===null)U.transactionMeta.update.updates.push({type:"state_creation",token:G})}return G}function SC($,X,Y){let z=d$(Y),G=`${X.key}(${z})`,U=N$($),W;switch(X.type){case"atom_family":case"mutable_atom_family":W=U.atoms.get(G);break;case"writable_held_selector_family":case"writable_pure_selector_family":W=U.writableSelectors.get(G);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":W=U.readonlySelectors.get(G);break}if(W)return L0(W);return W}function g$($,X,Y){let z=SC($,X,Y);if(z)return z;let G=d$(Y),U=$.molecules.get(G);if(!U&&$.config.lifespan==="immortal"){let W=KC(X,Y);return $.logger.error("\u274C",W.type,W.key,`was not found in store "${$.config.name}"; returned a counterfeit token.`),W}if(z=xC($,X,Y),U)N$($).moleculeData.set(G,X.key);return z}function tX($,...X){let Y;if(X.length===1)Y=X[0];else{let z=X[0],G=X[1];Y=g$($,z,G)}try{P6($,Y)}catch(z){$.logger.error("\u274C",Y.type,Y.key,`could not be disposed because it was not found in the store "${$.config.name}".`);return}switch(Y.type){case"atom":case"mutable_atom":CN($,Y);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":IC($,Y);break}}function _N($,X){if(X.family){let Y=$.families.get(X.family.key);if(Y)return Y}}function E7($,...X){let Y,z,G;if(X.length===1){if(Y=X[0],z=_N($,Y)??null,z)G=Y.family?N4(Y.family.subKey):null,Y=g$($,z,G)}else z=X[0],G=X[1],Y=g$($,z,G);if("counterfeit"in Y&&"family"in Y){let Q=Y.family.subKey,H=$.disposalTraces.buffer.find((Z)=>Z?.key===Q);$.logger.error("\u274C",Y.type,Y.key,`could not be reset because it was not found in the store "${$.config.name}".`,H?`This state was previously disposed:
|
|
3
|
+
var OC=Object.create;var{getPrototypeOf:wC,defineProperty:sU,getOwnPropertyNames:VC}=Object;var DC=Object.prototype.hasOwnProperty;var EC=($,X,Y)=>{Y=$!=null?OC(wC($)):{};let z=X||!$||!$.__esModule?sU(Y,"default",{value:$,enumerable:!0}):Y;for(let G of VC($))if(!DC.call(z,G))sU(z,G,{get:()=>$[G],enumerable:!0});return z};var NC=($,X)=>()=>(X||$((X={exports:{}}).exports,X),X.exports);var Z8=($,X)=>{for(var Y in X)sU($,Y,{get:X[Y],enumerable:!0,configurable:!0,set:(z)=>X[Y]=()=>z})};var By=($,X)=>()=>($&&(X=$($=0)),X);var sE=import.meta.require;var eF=NC((sc,sF)=>{var PG=sE("os"),vG=sE("path");function aF($){let X=process.env.XDG_CACHE_HOME||vG.join(PG.homedir(),".cache");return vG.join(X,$)}function Xx($){return vG.join(PG.homedir(),"Library","Caches",$)}function Yx($){let X=process.env.LOCALAPPDATA||vG.join(PG.homedir(),"AppData","Local");return vG.join(X,$,"Cache")}var Gx=function(){switch(PG.platform()){case"darwin":return Xx;case"win32":return Yx;case"aix":case"android":case"freebsd":case"linux":case"netbsd":case"openbsd":case"sunos":return aF;default:return console.error(`(node:${process.pid}) [cachedir] Warning: the platform "${PG.platform()}" is not currently supported by node-cachedir, falling back to "posix". Please file an issue with your platform here: https://github.com/LinusU/node-cachedir/issues/new`),aF}}();sF.exports=function $(X){if(typeof X!=="string")throw new TypeError("id is not a string");if(X.length===0)throw new Error("id cannot be empty");if(/[^0-9a-zA-Z-]/.test(X))throw new Error("id cannot contain special characters");return Gx(X)}});var eE=($,X,Y=R6.STORE)=>{return eU(Y,{key:`${$.key}:JSON`,get:({get:z})=>X.toJson(z($)),set:({set:z},G)=>{z($,X.fromJson(G))}})};function $N($,X,Y){return w7($,{key:`${X.key}:JSON`,get:(G)=>({get:U})=>{let W=U(X,G);return Y.toJson(W)},set:(G)=>({set:U},W)=>{U(X,G,Y.fromJson(W))}},["mutable","json"])}var N4=($)=>JSON.parse($),d$=($)=>JSON.stringify($),Sy=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];function oX($){return HN(R6.STORE,$)}function b2($){return UN(R6.STORE,$)}function XW(...$){if($.length===2)return b1(R6.STORE,...$);return b1(R6.STORE,...$)}function V7($,X,Y=R6.STORE){return Y.joins.set($.key,new UW($,X,Y)),{key:$.key,type:"join",a:$.between[0],b:$.between[1],cardinality:$.cardinality}}function XN($){return wN($,R6.STORE)}var $W=($)=>(X,Y,z,G,...U)=>{console[$](`${X} ${Y} "${z}" ${G}`,...U)},FC={error:$W("error"),info:$W("info"),warn:$W("warn")},YN=class{logLevel;filter;logger;constructor($,X,Y=FC){this.logLevel=$,this.filter=X,this.logger=Y}error=(...$)=>{let X=this.filter?.(...$)??!0;if(this.logLevel!==null){if(X===!0)this.logger.error(...$);else if(X!==!1)this.logger.error(...X)}};info=(...$)=>{let X=this.filter?.(...$)??!0;if(this.logLevel==="info"){if(X===!0)this.logger.info(...$);else if(X!==!1)this.logger.info(...X)}};warn=(...$)=>{let X=this.filter?.(...$)??!0;if(this.logLevel!=="error"&&this.logLevel!==null){if(X===!0)this.logger.warn(...$);else if(X!==!1)this.logger.warn(...X)}}};var MC=class{store;constructor($=R6.STORE){this.store=$,WN("root",$)}allocate($,X,Y){return aX(this.store,$,X,Y)}fuse($,X,Y){return QN(this.store,$,X,Y)}deallocate($){sX(this.store,$)}claim($,X,Y){return f2(this.store,$,X,Y)}},GN=class{store;realm;constructor($=R6.STORE){this.store=$,this.realm=new MC($)}allocate($,X,Y){aX(this.store,$,X,Y)}deallocate($){sX(this.store,$)}claim($,X,Y){f2(this.store,$,X,Y)}};function D7($){return GW(R6.STORE,$)}function h2($){return zW(R6.STORE,$)}var y4=class $ extends Set{mode="record";subject=new y$;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(X,Y=0){super(X);if(X instanceof $)this.parent=X,this.cacheUpdateNumber=X.cacheUpdateNumber;if(Y)this.cacheLimit=Y,this.cache=new Array(Y),this.subscribe("auto cache",(z)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=z})}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(X){let Y=new $(X.members,X.cacheLimit);return Y.cache=X.cache,Y.cacheIdx=X.cacheIdx,Y.cacheUpdateNumber=X.cacheUpdateNumber,Y}add(X){let Y=super.add(X);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${d$(X)}`);return Y}clear(){let X=this.mode==="record"?[...this]:null;if(super.clear(),X)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(X)}`)}delete(X){let Y=super.delete(X);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${d$(X)}`);return Y}parent=null;child=null;transactionUpdates=null;transaction(X){this.mode="transaction",this.transactionUpdates=[],this.child=new $(this);let Y=this.child._subscribe("transaction",(z)=>{this.transactionUpdates?.push(z)});try{if(X(this.child)){for(let G of this.transactionUpdates)this.doStep(G);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(z){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",z),z}finally{Y(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(X,Y){return this.subject.subscribe(X,Y)}subscribe(X,Y){return this.subject.subscribe(X,(z)=>{Y(`${this.cacheUpdateNumber}=${z}`)})}emit(X){this.subject.next(X)}doStep(X){let Y=X.indexOf(":"),z=X.substring(0,Y),G=X.substring(Y+1);switch(z){case"add":this.add(JSON.parse(G));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(G));break;case"tx":for(let U of G.split(";"))this.doStep(U)}}getUpdateNumber(X){let Y=X.indexOf("=");return Number(X.substring(0,Y))}do(X){let Y=X.indexOf("="),z=Number(X.substring(0,Y)),G=z-this.cacheUpdateNumber;if(G>0){if(G===1){this.mode="playback";let W=X.substring(Y+1);return this.doStep(W),this.mode="record",this.cacheUpdateNumber=z,null}return this.cacheUpdateNumber+1}if(Math.abs(G)<this.cacheLimit){let W=this.cacheIdx+G;if(this.cache[W]===X)return null;this.mode="playback";let H=!1;while(!H){this.cacheIdx%=this.cacheLimit;let O=this.cache[this.cacheIdx];if(this.cacheIdx--,!O)return"OUT_OF_RANGE";this.undo(O),H=this.cacheIdx===W-1}let Z=X.substring(Y+1);return this.doStep(Z),this.mode="record",this.cacheUpdateNumber=z,null}return"OUT_OF_RANGE"}undoStep(X){let Y=X.indexOf(":"),z=X.substring(0,Y),G=X.substring(Y+1);switch(z){case"add":this.delete(JSON.parse(G));break;case"del":this.add(JSON.parse(G));break;case"clear":{let U=JSON.parse(G);for(let W of U)this.add(W);break}case"tx":{let U=G.split(";");for(let W=U.length-1;W>=0;W--)this.undoStep(U[W])}}}undo(X){let Y=X.indexOf("=");if(Number(X.substring(0,Y))===this.cacheUpdateNumber){this.mode="playback";let G=X.substring(Y+1);return this.undoStep(G),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function zN($=Math.random){return $().toString(36).slice(2)}var WW=class extends Promise{fate;resolve;reject;done=!1;constructor($){let X,Y;super((z,G)=>{X=z,Y=G});this.resolve=X,this.reject=Y,this.use($ instanceof Promise?$:new Promise($))}pass($,X){if($===this.fate)this.resolve(X),this.done=!0}fail($,X){if($===this.fate)this.reject(X),this.done=!0}use($){if($ instanceof Promise){let X=$;this.fate=X,X.then((Y)=>{this.pass(X,Y)},(Y)=>{this.fail(X,Y)})}else this.resolve($),this.fate=void 0}};function N$($){while($.child!==null)$=$.child;return $}var JC=class ${_buffer;_index=0;constructor(X){let Y;if(typeof X==="number")Y=X;else Y=X.length;this._buffer=Array.from({length:Y})}get buffer(){return this._buffer}get index(){return this._index}add(X){this._buffer[this._index]=X,this._index=(this._index+1)%this._buffer.length}copy(){let X=new $([...this._buffer]);return X._index=this._index,X}},AC={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function KC($,X){let Y=d$(X),z=`${$.key}(${Y})`,G=AC[$.type],U={key:z,type:G};return Object.assign(U,{family:{key:$.key,subKey:Y}}),Object.assign(U,{counterfeit:!0}),U}function L0($){let X={key:$.key,type:$.type};if("family"in $)X.family=$.family;return X}var F4=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=($,X)=>`${$}:${X}`;warn;getRelatedKeys($){return this.relations.get($)}addRelation($,X){let Y=this.relations.get($),z=this.relations.get(X);if(Y)Y.add(X);else Y=new Set([X]),this.relations.set($,Y);if(z)z.add($);else z=new Set([$]),this.relations.set(X,z)}deleteRelation($,X){let Y=this.relations.get($);if(Y){if(Y.delete(X),Y.size===0)this.relations.delete($);let z=this.relations.get(X);if(z){if(z.delete($),z.size===0)this.relations.delete(X)}}}replaceRelationsUnsafely($,X){this.relations.set($,new Set(X));for(let Y of X){let z=new Set().add($);this.relations.set(Y,z)}}replaceRelationsSafely($,X){let Y=this.relations.get($),z=this.isAType?.($)?$:void 0,G=z===void 0?$:void 0;if(Y)for(let U of Y){z??=U,G??=U;let W=this.relations.get(U);if(W){if(W.size===1)this.relations.delete(U);else W.delete($);this.contents.delete(this.makeContentKey(z,G))}}this.relations.set($,new Set(X));for(let U of X){let W=this.relations.get(U);if(W)W.add($);else W=new Set().add($),this.relations.set(U,W)}}getContentInternal($){return this.contents.get($)}setContent($,X){this.contents.set($,X)}deleteContent($){this.contents.delete($)}constructor($,X){if(this.a=$.between[0],this.b=$.between[1],this.cardinality=$.cardinality,!X?.externalStore)this.relations=new Map($.relations?.map(([Y,z])=>[Y,new Set(z)])),this.contents=new Map($.contents);if(this.isAType=X?.isAType??null,this.isBType=X?.isBType??null,this.isContent=X?.isContent??null,X?.makeContentKey)this.makeContentKey=X.makeContentKey;if(X?.externalStore){let Y=X.externalStore;if(this.has=(z,G)=>Y.has(z,G),this.addRelation=(z,G)=>{Y.addRelation(z,G)},this.deleteRelation=(z,G)=>{Y.deleteRelation(z,G)},this.replaceRelationsSafely=(z,G)=>{Y.replaceRelationsSafely(z,G)},this.replaceRelationsUnsafely=(z,G)=>{Y.replaceRelationsUnsafely(z,G)},this.getRelatedKeys=(z)=>Y.getRelatedKeys(z),Y.getContent)this.getContentInternal=(z)=>{return Y.getContent(z)},this.setContent=(z,G)=>{Y.setContent(z,G)},this.deleteContent=(z)=>{Y.deleteContent(z)};for(let[z,G]of $.relations??[]){let U=this.isAType?.(z)?z:void 0,W=U===void 0?z:void 0;for(let Q of G)U??=Q,W??=Q,this.addRelation(U,W)}for(let[z,G]of $.contents??[])this.setContent(z,G)}if(X?.warn)this.warn=X.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([$,X])=>[$,[...X]]),contents:[...this.contents.entries()]}}set(...$){let X,Y,z;switch($.length){case 1:{let G=$[0];X=G[this.a],Y=G[this.b],z=void 0;break}case 2:{let G=$[0];if(typeof G==="string")[X,Y]=$;else X=G[this.a],Y=G[this.b],z=$[1];break}default:{X=$[0],Y=$[1],z=$[2];break}}switch(this.cardinality){case"1:1":{let G=this.getRelatedKey(X);if(G&&G!==Y)this.delete(X,G)}case"1:n":{let G=this.getRelatedKey(Y);if(G&&G!==X)this.delete(G,Y)}break;case"n:n":}if(z){let G=this.makeContentKey(X,Y);this.setContent(G,z)}return this.addRelation(X,Y),this}delete($,X){X=typeof X==="string"?X:$[this.b];let Y=typeof $==="string"?$:$[this.a];if(Y===void 0&&typeof X==="string"){let z=this.getRelatedKeys(X);if(z)for(let G of z)this.delete(G,X)}if(typeof Y==="string"&&X===void 0){let z=this.getRelatedKeys(Y);if(z)for(let G of z)this.delete(Y,G)}if(typeof Y==="string"&&typeof X==="string"){this.deleteRelation(Y,X);let z=this.makeContentKey(Y,X);this.deleteContent(z)}return this}getRelatedKey($){let X=this.getRelatedKeys($);if(X){if(X.size>1)this.warn?.(`${X.size} related keys were found for key "${$}": (${[...X].map((z)=>`"${z}"`).join(", ")}). Only one related key was expected.`);let Y;for(let z of X){Y=z;break}return Y}}replaceRelations($,X,Y){let z=!Array.isArray(X),G=z?Object.keys(X):X;if(Y?.reckless)this.replaceRelationsUnsafely($,G);else this.replaceRelationsSafely($,G);if(z)for(let U of G){let W=this.makeContentKey($,U),Q=X[U];this.setContent(W,Q)}return this}getContent($,X){let Y=this.makeContentKey($,X);return this.getContentInternal(Y)}getRelationEntries($){let X=$[this.a],Y=$[this.b];if(X!==void 0&&Y===void 0){let z=this.getRelatedKeys(X);if(z)return[...z].map((G)=>{return[G,this.getContent(X,G)]})}if(X===void 0&&Y!==void 0){let z=this.getRelatedKeys(Y);if(z)return[...z].map((G)=>{return[G,this.getContent(G,Y)]})}return[]}has($,X){if(X)return this.getRelatedKeys($)?.has(X)??!1;return this.relations.has($)}},y$=class{Subscriber;subscribers=new Map;subscribe($,X){return this.subscribers.set($,X),()=>{this.unsubscribe($)}}unsubscribe($){this.subscribers.delete($)}next($){let X=this.subscribers.values();for(let Y of X)Y($)}},_C=class extends y${state;constructor($){super();this.state=$}next($){this.state=$,super.next($)}};function H8($){return"epoch"in $.transactionMeta}function t6($){return"phase"in $.transactionMeta}var qC=($)=>{let X=N$($);if(!t6(X)){$.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}$.logger.info("\uD83E\uDE82","transaction",X.transactionMeta.update.key,"Aborting transaction"),X.parent.child=null};function U6($){return $[0].toUpperCase()+$.slice(1)}function r8($){return $.type.split("_").map(U6).join(" ")}var OW=class extends Error{constructor($,X){super(`${r8($)} ${d$($.key)} not found in store "${X.config.name}".`)}};function YW($,X,Y){return(...z)=>{let G=P6($,X);if(G)return G.run(z,Y);throw new OW(X,$)}}var wW=($)=>(X)=>$ instanceof Function?$(X):$,M7=($,X)=>{if($.valueMap.has(X.key))return $.logger.info("\uD83D\uDCD6",X.type,X.key,"reading cached value"),aC(X,$);switch(X.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return $.logger.info("\uD83E\uDDEE",X.type,X.key,"computing value"),X.get();case"atom":case"mutable_atom":{let Y=X.default,z;if(Y instanceof Function)z=Y();else z=Y;return $.logger.info("\uD83D\uDC81","atom",X.key,"could not find cached value; using default",z),z}}},N7=($,X)=>{if($.operation.open){let Y=performance.now();return $.logger.info("\u2757",X.type,X.key,`deferring setState at T-${Y} until setState for "${$.operation.token.key}" is done`),Y}$.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:X},$.logger.info("\u2B55",X.type,X.key,`operation start in store "${$.config.name}"${!t6($)?"":` ${$.transactionMeta.phase} "${$.transactionMeta.update.key}"`}`)},F7=($)=>{if($.operation.open)$.logger.info("\uD83D\uDD34",$.operation.token.type,$.operation.token.key,`operation done in store "${$.config.name}"`);$.operation={open:!1},$.on.operationClose.next($.operation)},FN=($,X)=>{if(!$.operation.open)return $.logger.error("\uD83D\uDC1E","unknown",X,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return $.operation.done.has(X)},u2=($,X)=>{if(!$.operation.open){$.logger.error("\uD83D\uDC1E","unknown",X,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}$.operation.done.add(X)},TC=($,X,Y)=>{switch(X.type){case"mutable_atom":$.logger.info("\uD83D\uDCE2",X.type,X.key,"is now (",Y.newValue,") subscribers:",X.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":$.logger.info("\uD83D\uDCE2",X.type,X.key,"went (",Y.oldValue,"->",Y.newValue,") subscribers:",X.subject.subscribers)}X.subject.next(Y)};function QW($,X){let Y=N$($),z=Y.selectorAtoms.getRelatedKeys(X.key);if(Y.logger.info("\uD83E\uDDF9",X.type,X.key,z?`evicting ${z.size} states downstream:`:"no downstream states",z??"to evict"),z){if(Y.operation.open)Y.logger.info("\uD83E\uDDF9",X.type,X.key,`[ ${[...Y.operation.done].join(", ")} ] already done`);for(let G of z){if(FN(Y,G))continue;vN(G,Y),u2(Y,G)}}}function RC($,X){let Y=N$($),z=Y.selectorGraph.getRelationEntries({upstreamSelectorKey:X.key}).filter(([G,{source:U}])=>U===X.key);for(let[G]of z){if(FN(Y,G))continue;vN(G,Y),u2(Y,G)}}var MN=($,X,Y)=>{let z=M7($,X),G=z;if(X.type==="mutable_atom"&&t6($)){let{parent:W}=$;G=HW($,X,W)}G=wW(Y)(G),$.logger.info("\uD83D\uDCDD","atom",X.key,"set to",G),G=s1($,X.key,G,X.subject),u2($,X.key),QW($,X);let U={oldValue:z,newValue:G};if(!t6($)){TC($,X,U);return}if($.on.transactionApplying.state===null){let{key:W}=X;if(tC(U.newValue))return;let Q={type:"atom_update",key:W,...U};if(X.family)Q.family=X.family;$.transactionMeta.update.updates.push(Q),$.logger.info("\uD83D\uDCC1","atom",W,"stowed (",U.oldValue,"->",U.newValue,")")}else if(X.key.startsWith("*")){let W=X.key.slice(1),Q=$.atoms.get(W),H=$.valueMap.get(W);if(Q.type==="mutable_atom"&&t6($)){let{parent:O}=$;H=HW($,Q,O)}if(H.do(U.newValue)===null)QW($,Q)}};function DN($,X){let Y=X.default;if(Y instanceof Function)Y=Y();MN($,X,Y)}function PC($,X){switch(X.type){case"atom":case"mutable_atom":DN($,X);break;case"writable_pure_selector":case"writable_held_selector":{let Y=JN(X,$);for(let z of Y)DN($,z)}break}}function m2($,X,Y){let z={key:X.key,type:"atom_family"},G=$.families.get(X.key);if(G)$.logger.error("\u2757","atom_family",X.key,`Overwriting an existing ${r8(G)} "${G.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let U=new y$,Q=Object.assign((H)=>{let Z=d$(H),O={key:X.key,subKey:Z},w=`${X.key}(${Z})`,V=N$($),D=X.default,E={key:w,default:D instanceof Function?()=>D(H):D};if(X.effects)E.effects=X.effects(H);let F=o8(V,E,O);return U.next({type:"state_creation",token:F}),F},z,{subject:U,install:(H)=>m2(H,X),internalRoles:Y});return $.families.set(X.key,Q),$.defaults.set(X.key,X.default),z}function UN($,X){if("mutable"in X)return JW($,X);return m2($,X)}var VW=($,X)=>N$($).atoms.has(X),vC=($,X)=>N$($).writableSelectors.has(X),CC=($,X)=>N$($).readonlySelectors.has(X),jC=($,X)=>VW($,X)||vC($,X)||CC($,X),ZW=($,X)=>{return N$($).selectorGraph.getRelationEntries({downstreamSelectorKey:X}).filter(([z,{source:G}])=>G!==X).map(([z,{source:G}])=>G).filter((z)=>jC($,z))},LN=($,X,Y)=>{let z=[],G=ZW($,X);while(G.length>0){let U=G.shift();if(Y.has(U))continue;if(Y.add(U),!VW($,U))G.push(...ZW($,U));else if(!z.includes(U))z.push(U)}return z},JN=($,X)=>{let Y=$.key,z=ZW(X,Y),G=new Set;return z.flatMap((U)=>VW(X,U)?U:LN(X,U,G)).map((U)=>X.atoms.get(U))},BC=($,X,Y,z,G)=>{let U=N$($),{type:W,key:Q}=z;if(W==="atom"||W==="mutable_atom")U.selectorAtoms.set({selectorKey:Y,atomKey:Q}),$.logger.info("\uD83D\uDD0D",X,Y,`discovers root atom "${Q}"`);else{let H=LN($,Q,G);$.logger.info("\uD83D\uDD0D",X,Y,`discovers root atoms: [ ${H.map((Z)=>`"${Z}"`).join(", ")} ]`);for(let Z of H)U.selectorAtoms=U.selectorAtoms.set({selectorKey:Y,atomKey:Z})}G.add(Q)},L7=($,X,Y,z)=>({get:(...G)=>{let U=N$($),W;if(G.length===2){let[O,w]=G;W=g$($,O,w)}else[W]=G;let Q=P6($,W),H=M7($,Q),Z=W.key;return $.logger.info("\uD83D\uDD0C",X,Y,`registers dependency ( "${Z}" =`,H,")"),U.selectorGraph.set({upstreamSelectorKey:Z,downstreamSelectorKey:Y},{source:W.key}),BC($,X,Y,W,z),H},set:(...G)=>{let U,W;if(G.length===2)U=G[0],W=G[1];else{let Z=G[0],O=G[1];W=G[2],U=g$($,Z,O)}let Q=N$($),H=P6(Q,U);qN(Q,H,W)},find:(...G)=>g$($,...G),json:(G)=>n8($,G)}),DW=($,X,Y)=>{let z=N$($),G=new y$,U=new Set,{key:W,const:Q}=X,H="readonly_held_selector",{get:Z,find:O,json:w}=L7(z,"readonly_held_selector",W,U),D={...X,type:"readonly_held_selector",subject:G,install:(F)=>DW(F,X,Y),get:()=>{return X.get({get:Z,find:O,json:w},Q),s1(N$($),W,Q,G),U.clear(),Q},...Y&&{family:Y}};z.readonlySelectors.set(W,D),$.logger.info("\u2728","readonly_held_selector",W,"=",Q);let E={key:W,type:"readonly_held_selector"};if(Y)E.family=Y;return E},EW=($,X,Y)=>{let z=N$($),G=new y$,U=new Set,W=X.key,Q="readonly_pure_selector",{get:H,find:Z,json:O}=L7(z,"readonly_pure_selector",W,U),w=()=>{let F=X.get({get:H,find:Z,json:O});return s1(N$($),W,F,G),U.clear(),F},V={...X,type:"readonly_pure_selector",subject:G,install:(F)=>EW(F,X,Y),get:w,...Y&&{family:Y}};z.readonlySelectors.set(W,V);let D=w();$.logger.info("\u2728","readonly_pure_selector",W,"=",D);let E={key:W,type:"readonly_pure_selector"};if(Y)E.family=Y;return E},NW=($,X,Y)=>{let z=N$($),G=new y$,U=new Set,{key:W,const:Q}=X,H="writable_held_selector",Z=L7(z,"writable_held_selector",W,U),{find:O,get:w,json:V}=Z,D={find:O,get:w,json:V},E=(R=X.get,_=N$($))=>{return R(D,Q),s1(_,W,Q,G),U.clear(),Q},L={...X,type:"writable_held_selector",subject:G,install:(R)=>NW(R,X,Y),get:E,set:(R)=>{let _=N$($),v=E(X.get,_),x=wW(R)(v);if($.logger.info("\uD83D\uDCDD","writable_held_selector",W,"set (",v,"->",x,")"),s1(_,W,x,G),u2(_,W),H8(_))G.next({newValue:x,oldValue:v});X.set(Z,x)},...Y&&{family:Y}};z.writableSelectors.set(W,L);let K=E();$.logger.info("\u2728","writable_held_selector",W,"=",K);let q={key:W,type:"writable_held_selector"};if(Y)q.family=Y;return q},FW=($,X,Y)=>{let z=N$($),G=new y$,U=new Set,W=X.key,Q="writable_pure_selector",H=L7(z,"writable_pure_selector",W,U),{find:Z,get:O,json:w}=H,V={find:Z,get:O,json:w},D=(q=X.get,R=N$($))=>{let _=q(V);return s1(R,W,_,G),U.clear(),_},F={...X,type:"writable_pure_selector",subject:G,install:(q)=>FW(q,X,Y),get:D,set:(q)=>{let R=N$($),_=D(X.get,R),v=wW(q)(_);if($.logger.info("\uD83D\uDCDD","writable_pure_selector",W,"set (",_,"->",v,")"),s1(R,X.key,v,G),u2(R,X.key),H8(R))G.next({newValue:v,oldValue:_});X.set(H,v)},...Y&&{family:Y}};z.writableSelectors.set(W,F);let L=D();$.logger.info("\u2728",F.type,F.key,"=",L);let K={key:W,type:"writable_pure_selector"};if(Y)K.family=Y;return K};function eU($,X){let Y="set"in X,z="const"in X;if(z&&Y){let U=NW($,X,void 0);return $.on.selectorCreation.next(U),U}if(z){let U=DW($,X,void 0);return $.on.selectorCreation.next(U),U}if(Y){let U=FW($,X,void 0);return $.on.selectorCreation.next(U),U}let G=EW($,X,void 0);return $.on.selectorCreation.next(G),G}function IC($,X){let Y=N$($),{key:z,type:G}=X,U=P6(Y,X);if(!U.family)$.logger.error("\u274C",G,z,"Standalone selectors cannot be disposed.");else{if(Y.molecules.get(U.family.subKey))Y.moleculeData.delete(U.family.subKey,U.family.key);let Q;switch(X.type){case"writable_held_selector":Y.writableSelectors.delete(z),Q={key:U.family.key,type:"writable_held_selector_family"},P6($,Q).subject.next({type:"state_disposal",subType:"selector",token:X});break;case"writable_pure_selector":Y.writableSelectors.delete(z),Q={key:U.family.key,type:"writable_pure_selector_family"},P6($,Q).subject.next({type:"state_disposal",subType:"selector",token:X});break;case"readonly_held_selector":Y.readonlySelectors.delete(z),Q={key:U.family.key,type:"readonly_held_selector_family"},P6($,Q).subject.next({type:"state_disposal",subType:"selector",token:X});break;case"readonly_pure_selector":Y.readonlySelectors.delete(z),Q={key:U.family.key,type:"readonly_pure_selector_family"},P6($,Q).subject.next({type:"state_disposal",subType:"selector",token:X});break}if(Y.valueMap.delete(z),Y.selectorAtoms.delete(z),Y.selectorGraph.delete(z),$.logger.info("\uD83D\uDD25",X.type,z,"deleted"),t6(Y)&&Y.transactionMeta.phase==="building")Y.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:X});else $.on.selectorDisposal.next(X)}}function i8($,X,Y){let z=X.key,G="readonly_pure_selector_family",U={key:z,type:"readonly_pure_selector_family"},W=$.families.get(z);if(W)$.logger.error("\u2757","readonly_pure_selector_family",z,`Overwriting an existing ${r8(W)} "${W.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let Q=new y$,Z=Object.assign((O)=>{let w=d$(O),V={key:z,subKey:w},D=`${z}(${w})`,E=N$($),F=EW(E,{key:D,get:X.get(O)},V);return Q.next({type:"state_creation",token:F}),F},U,{internalRoles:Y,subject:Q,install:(O)=>i8(O,X),default:(O)=>{return X.get(O)({get:(...V)=>b1($,...V),find:(...V)=>g$($,...V),json:(V)=>n8($,V)})}});return $.families.set(z,Z),U}function AN($,X,Y){let z=X.key,G="readonly_held_selector_family",U={key:z,type:"readonly_held_selector_family"},W=$.families.get(z);if(W)$.logger.error("\u2757","readonly_held_selector_family",z,`Overwriting an existing ${r8(W)} "${W.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let Q=new y$,Z=Object.assign((O)=>{let w=d$(O),V={key:z,subKey:w},D=`${z}(${w})`,E=N$($),F=DW(E,{key:D,const:X.const(O),get:X.get(O)},V);return Q.next({type:"state_creation",token:F}),F},U,{internalRoles:Y,subject:Q,install:(O)=>AN(O,X),default:X.const});return $.families.set(z,Z),U}function KN($,X,Y){let z=X.key,G="writable_held_selector_family",U={key:z,type:"writable_held_selector_family"},W=$.families.get(z);if(W)$.logger.error("\u2757","writable_held_selector_family",z,`Overwriting an existing ${r8(W)} "${W.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let Q=new y$,Z=Object.assign((O)=>{let w=d$(O),V={key:z,subKey:w},D=`${z}(${w})`,E=N$($),F=NW(E,{key:D,const:X.const(O),get:X.get(O),set:X.set(O)},V);return Q.next({type:"state_creation",token:F}),F},U,{internalRoles:Y,subject:Q,install:(O)=>KN(O,X),default:X.const});return $.families.set(z,Z),U}function w7($,X,Y){let z=X.key,G="writable_pure_selector_family",U={key:z,type:"writable_pure_selector_family"},W=$.families.get(z);if(W)$.logger.error("\u2757","writable_pure_selector_family",z,`Overwriting an existing ${r8(W)} "${W.key}" in store "${$.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let Q=new y$,Z=Object.assign((O)=>{let w=d$(O),V={key:z,subKey:w},D=`${z}(${w})`,E=N$($),F=FW(E,{key:D,get:X.get(O),set:X.set(O)},V);return Q.next({type:"state_creation",token:F}),F},U,{internalRoles:Y,subject:Q,install:(O)=>w7(O,X),default:(O)=>{return X.get(O)({get:(...V)=>b1($,...V),find:(...V)=>g$($,...V),json:(V)=>n8($,V)})}});return $.families.set(z,Z),U}function GW($,X){let Y="set"in X,z="const"in X;if(z&&Y)return KN($,X,void 0);if(z)return AN($,X,void 0);if(Y)return w7($,X);return i8($,X)}function xC($,X,Y){let z=$.families.get(X.key);if(z===void 0)throw new OW(X,$);let G=z(Y),U=N$($);if(G.family){if(H8(U))switch(G.type){case"atom":case"mutable_atom":$.on.atomCreation.next(G);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":$.on.selectorCreation.next(G);break}else if(t6(U)&&U.on.transactionApplying.state===null)U.transactionMeta.update.updates.push({type:"state_creation",token:G})}return G}function SC($,X,Y){let z=d$(Y),G=`${X.key}(${z})`,U=N$($),W;switch(X.type){case"atom_family":case"mutable_atom_family":W=U.atoms.get(G);break;case"writable_held_selector_family":case"writable_pure_selector_family":W=U.writableSelectors.get(G);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":W=U.readonlySelectors.get(G);break}if(W)return L0(W);return W}function g$($,X,Y){let z=SC($,X,Y);if(z)return z;let G=d$(Y),U=$.molecules.get(G);if(!U&&$.config.lifespan==="immortal"){let W=KC(X,Y);return $.logger.error("\u274C",W.type,W.key,`was not found in store "${$.config.name}"; returned a counterfeit token.`),W}if(z=xC($,X,Y),U)N$($).moleculeData.set(G,X.key);return z}function tX($,...X){let Y;if(X.length===1)Y=X[0];else{let z=X[0],G=X[1];Y=g$($,z,G)}try{P6($,Y)}catch(z){$.logger.error("\u274C",Y.type,Y.key,`could not be disposed because it was not found in the store "${$.config.name}".`);return}switch(Y.type){case"atom":case"mutable_atom":CN($,Y);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":IC($,Y);break}}function _N($,X){if(X.family){let Y=$.families.get(X.family.key);if(Y)return Y}}function E7($,...X){let Y,z,G;if(X.length===1){if(Y=X[0],z=_N($,Y)??null,z)G=Y.family?N4(Y.family.subKey):null,Y=g$($,z,G)}else z=X[0],G=X[1],Y=g$($,z,G);if("counterfeit"in Y&&"family"in Y){let Q=Y.family.subKey,H=$.disposalTraces.buffer.find((Z)=>Z?.key===Q);$.logger.error("\u274C",Y.type,Y.key,`could not be reset because it was not found in the store "${$.config.name}".`,H?`This state was previously disposed:
|
|
4
4
|
${H.trace}`:"No previous disposal trace was found.");return}let U=N7($,Y);if(U){let Q=$.on.operationClose.subscribe(`waiting to reset "${Y.key}" at T-${U}`,()=>{Q(),$.logger.info("\uD83D\uDFE2",Y.type,Y.key,`resuming deferred resetState from T-${U}`),E7($,Y)});return}let W=P6($,Y);PC($,W),F7($)}var qN=($,X,Y)=>{switch(X.type){case"atom":case"mutable_atom":MN($,X,Y);break;case"writable_pure_selector":case"writable_held_selector":X.set(Y);break}};function Y1($,...X){let Y,z,G,U;if(X.length===2){if(Y=X[0],U=X[1],z=_N($,Y)??null,z)G=Y.family?N4(Y.family.subKey):null,Y=g$($,z,G)}else z=X[0],G=X[1],U=X[2],Y=g$($,z,G);if("counterfeit"in Y&&"family"in Y){let H=Y.family.subKey,Z=$.disposalTraces.buffer.find((O)=>O?.key===H);$.logger.error("\u274C",Y.type,Y.key,`could not be set because it was not found in the store "${$.config.name}".`,Z?`This state was previously disposed:
|
|
5
5
|
${Z.trace}`:"No previous disposal trace was found.");return}let W=N7($,Y);if(W){let H=$.on.operationClose.subscribe(`waiting to set "${Y.key}" at T-${W}`,()=>{H(),$.logger.info("\uD83D\uDFE2",Y.type,Y.key,`resuming deferred setState from T-${W}`),Y1($,Y,U)});return}let Q=P6($,Y);qN($,Q,U),F7($)}function kC($,X,Y){let{key:z,newValue:G,oldValue:U}=X,W=$==="newValue"?G:U,Q={key:z,type:"atom"};if(X.family)Object.assign(Q,{family:X.family});Y1(Y,Q,W)}function bC($){let{stack:X}=$;if(X)return`
|
|
6
6
|
`+X.split(`
|
package/bin/frontend.bun.js
CHANGED
|
@@ -44,7 +44,7 @@ Right: ${Z}`;var UQ=r({kind:"unit",hasAssociatedError:!0,keys:{unit:{preserveUnd
|
|
|
44
44
|
${H},
|
|
45
45
|
`;if(!X.hasKind("union"))return J;let Q=new y8({kind:"Allows",optimistic:!0}).indent();X.compile(Q);let $=Q.write(`${X.id}Optimistic`);return`${J}${$},
|
|
46
46
|
`},`{
|
|
47
|
-
`)+"}");class t6{config;resolvedConfig;name;get[X1](){return"scope"}referencesById={};references=[];resolutions={};exportedNames=[];aliases={};resolved=!1;nodesByHash={};intrinsic;constructor(Y,Z){if(this.config=p8(B.config,Z),this.resolvedConfig=p8(B.resolvedConfig,Z),this.name=this.resolvedConfig.name??`anonymousScope${Object.keys(X5).length}`,this.name in X5)w(`A Scope already named ${this.name} already exists`);X5[this.name]=this;let X=Object.entries(Y).map((_)=>this.preparseOwnAliasEntry(..._));for(let[_,G]of X){let W=_;if(_[0]==="#"){if(W=_.slice(1),W in this.aliases)w(uG(W));this.aliases[W]=G}else{if(W in this.aliases)w(uG(_));this.aliases[W]=G,this.exportedNames.push(W)}if(!y(G,"module")&&!y(G,"generic")&&!O4(G)){let H=this.preparseOwnDefinitionFormat(G,{alias:W});this.resolutions[W]=y(H,"root")?this.bindReference(H):this.createParseContext(H).id}}dG??=this.node("union",{branches:["string","number","object","bigint","symbol",{unit:!0},{unit:!1},{unit:void 0},{unit:null}]},{prereduced:!0}),this.nodesByHash[dG.hash]=this.node("intersection",{},{prereduced:!0}),this.intrinsic=B.intrinsic?o(B.intrinsic,(_,G)=>_.startsWith("json")?[]:[_,this.bindReference(G)]):{}}cacheGetter(Y,Z){return Object.defineProperty(this,Y,{value:Z}),Z}get internal(){return this}_json;get json(){if(!this._json)this.export();return this._json}defineSchema(Y){return Y}generic=(...Y)=>{let Z=this;return(X,_)=>new M4(Y,_?new c6(X):X,Z,Z,_??null)};units=(Y,Z)=>{let X=[];for(let G of Y)if(!X.includes(G))X.push(G);let _=X.map((G)=>this.node("unit",{unit:G},Z));return this.node("union",_,{...Z,prereduced:!0})};lazyResolutions=[];lazilyResolve(Y,Z){let X=this.node("alias",{reference:Z??"synthetic",resolve:Y},{prereduced:!0});if(!this.resolved)this.lazyResolutions.push(X);return X}schema=(Y,Z)=>this.finalize(this.parseSchema(Y,Z));parseSchema=(Y,Z)=>this.node(c8(Y),Y,Z);preparseNode(Y,Z,X){let _=typeof Y==="string"?Y:c8(Z,Y);if(V0(Z)&&Z.kind===_)return Z;if(_==="alias"&&!X?.prereduced){let{reference:H}=s8.implementation.normalize(Z,this);if(H.startsWith("$")){let J=this.resolveRoot(H.slice(1));Z=J,_=J.kind}}else if(_==="union"&&Q1(Z,"object")){let H=SQ(Z);if(H?.length===1)Z=H[0],_=c8(Z)}if(V0(Z)&&Z.kind===_)return Z;let W=G8[_].normalize?.(Z,this)??Z;if(V0(W))return W.kind===_?W:vQ(_,W.kind);return{...X,$:this,kind:_,def:W,prefix:X.alias??_}}bindReference(Y){let Z;if(V0(Y))Z=Y.$===this?Y:new Y.constructor(Y.attachments,this);else Z=Y.$===this?Y:new M4(Y.params,Y.bodyDef,Y.$,this,Y.hkt);if(!this.resolved)Object.assign(this.referencesById,Z.referencesById);return Z}resolveRoot(Y){return this.maybeResolveRoot(Y)??w(W5(Y))}maybeResolveRoot(Y){let Z=this.maybeResolve(Y);if(y(Z,"generic"))return;return Z}maybeResolveSubalias(Y){return _5(this.aliases,Y)??_5(this.ambient,Y)}get ambient(){return B.ambient}maybeResolve(Y){let Z=this.resolutions[Y];if(Z){if(typeof Z!=="string")return this.bindReference(Z);let _=_1[Z];if(y(_,"root"))return this.resolutions[Y]=_;if(y(_,"context")){if(_.phase==="resolving")return this.node("alias",{reference:`$${Y}`},{prereduced:!0});if(_.phase==="resolved")return _0(`Unexpected resolved context for was uncached by its scope: ${n(_)}`);_.phase="resolving";let G=this.bindReference(this.parseOwnDefinitionFormat(_.def,_));return _.phase="resolved",_1[G.id]=G,_1[_.id]=G,this.resolutions[Y]=G}return _0(`Unexpected nodesById entry for ${Z}: ${n(_)}`)}let X=this.aliases[Y]??this.ambient?.[Y];if(!X)return this.maybeResolveSubalias(Y);if(X=this.normalizeRootScopeValue(X),y(X,"generic"))return this.resolutions[Y]=this.bindReference(X);if(y(X,"module")){if(!X.root)w(sG(Y));return this.resolutions[Y]=this.bindReference(X.root)}return this.resolutions[Y]=this.parse(X,{alias:Y})}createParseContext(Y){let Z=Y.id??yZ(Y.prefix);return _1[Z]=Object.assign(Y,{[X1]:"context",$:this,id:Z,phase:"unresolved"})}traversal(Y){return new f1(Y,this.resolvedConfig)}import(...Y){return new J8(o(this.export(...Y),(Z,X)=>[`#${Z}`,X]))}precompilation;_exportedResolutions;_exports;export(...Y){if(!this._exports){this._exports={};for(let X of this.exportedNames){let _=this.aliases[X];this._exports[X]=y(_,"module")?Z5(_,this):cG(this.maybeResolve(X))}for(let X of this.lazyResolutions)X.resolution;if(this._exportedResolutions=rG(this,this._exports),this._json=nG(this._exportedResolutions),Object.assign(this.resolutions,this._exportedResolutions),this.references=Object.values(this.referencesById),!this.resolvedConfig.jitless){let X=oG(this.references);this.precompilation=X.write(lG,4),iG(this.references,X)}this.resolved=!0}let Z=Y.length?Y:this.exportedNames;return new J8(o(Z,(X,_)=>[_,this._exports[_]]))}resolve(Y){return this.export()[Y]}node=(Y,Z,X={})=>{let _=this.preparseNode(Y,Z,X);if(V0(_))return this.bindReference(_);let G=this.createParseContext(_),W=pZ(G),H=this.bindReference(W);return _1[G.id]=H};parse=(Y,Z={})=>this.finalize(this.parseDefinition(Y,Z));parseDefinition(Y,Z={}){if(y(Y,"root"))return this.bindReference(Y);let X=this.preparseOwnDefinitionFormat(Y,Z);if(y(X,"root"))return this.bindReference(X);let _=this.createParseContext(X);_1[_.id]=_;let G=this.bindReference(this.parseOwnDefinitionFormat(Y,_));if(G.isCyclic)G=DG(G,_.id);return _1[_.id]=G,G}finalize(Y){if(cG(Y),!Y.precompilation&&!this.resolvedConfig.jitless)xQ(Y.references);return Y}}class G5 extends t6{parseOwnDefinitionFormat(Y,Z){return pZ(Z)}preparseOwnDefinitionFormat(Y,Z){return this.preparseNode(c8(Y),Y,Z)}preparseOwnAliasEntry(Y,Z){return[Y,Z]}normalizeRootScopeValue(Y){return Y}}var cG=(Y)=>{let Z=Y.references.filter((X)=>X.hasKind("alias"));for(let X of Z){Object.assign(X.referencesById,X.resolution.referencesById);for(let _ of Y.references)if(X.id in _.referencesById)Object.assign(_.referencesById,X.referencesById)}return Y},nG=(Y)=>o(Y,(Z,X)=>[Z,y(X,"root")||y(X,"generic")?X.json:y(X,"module")?nG(X):_0(`Unexpected resolution ${n(X)}`)]),_5=(Y,Z)=>{let X=Z.indexOf(".");if(X===-1)return;let _=Z.slice(0,X),G=Y[_];if(G===void 0)return;if(!y(G,"module"))return w(hQ(_));let W=Z.slice(X+1),H=G[W];if(H===void 0)return _5(G,W);if(y(H,"root")||y(H,"generic"))return H;if(y(H,"module"))return H.root??w(sG(Z));_0(`Unexpected resolution for alias '${Z}': ${n(H)}`)},e6=(Y,Z)=>new G5(Y,Z),e8=new G5({});var rG=(Y,Z)=>{let X={};for(let _ in Z){let G=Z[_];if(y(G,"module")){let W=rG(Y,G),H=o(W,(J,Q)=>[`${_}.${J}`,Q]);Object.assign(X,H)}else if(y(G,"root")||y(G,"generic"))X[_]=G;else _0(`Unexpected scope resolution ${n(G)}`)}return X},W5=(Y)=>`'${Y}' is unresolvable`,hQ=(Y)=>`'${Y}' must reference a module to be accessed using dot syntax`,sG=(Y)=>`Reference to submodule '${Y}' must specify an alias`;e8.export();var{schema:$0,node:$8,defineSchema:jw,generic:q1}=e8;var H5="^(?:0|[1-9]\\d*)$",fQ=new RegExp(H5),vw=q0(fQ);var aG=e6({bigint:"bigint",boolean:[{unit:!1},{unit:!0}],false:{unit:!1},never:[],null:{unit:null},number:"number",object:"object",string:"string",symbol:"symbol",true:{unit:!0},unknown:{},undefined:{unit:void 0},Array,Date},{prereducedAliases:!0}).export();B.intrinsic={...aG};var tG=e6({integer:{domain:"number",divisor:1},lengthBoundable:["string",Array],key:["string","symbol"],nonNegativeIntegerString:{domain:"string",pattern:H5}},{prereducedAliases:!0}).export();Object.assign(B.intrinsic,tG);var bQ=e6({jsonPrimitive:["string","number",{unit:!0},{unit:!1},{unit:null}],jsonObject:{domain:"object",index:{signature:"string",value:"$jsonData"}},jsonData:["$jsonPrimitive","$jsonObject"]},{prereducedAliases:!0}).export(),d={...aG,...tG,...bQ,emptyStructure:$8("structure",{},{prereduced:!0})};B.intrinsic={...d};var Y9=(Y)=>typeof Y==="string"&&Y[0]==="d"&&(Y[1]==="'"||Y[1]==='"')&&Y.at(-1)===Y[1],eG=(Y)=>Y.toString()!=="Invalid Date",Z9=(Y)=>Y.slice(2,-1),J5=(Y)=>`'${Y}' could not be parsed by the Date constructor`,X9=(Y,Z)=>kQ(Y,Z),kQ=(Y,Z)=>{let X=new Date(Y);if(eG(X))return X;let _=h_(Y);if(_!==void 0){let G=new Date(_);if(eG(G))return G}return Z?w(Z===!0?J5(Y):Z):void 0};var $5=(Y,Z)=>{let X=Y.scanner.shiftUntil(gQ[G9[Z]]);if(Y.scanner.lookahead==="")return Y.error(pQ(X,Z));if(Y.scanner.shift(),Z==="/"){try{new RegExp(X)}catch(_){w(String(_))}Y.root=Y.ctx.$.node("intersection",{domain:"string",pattern:X},{prereduced:!0})}else if(p0(Z,Q5))Y.root=Y.ctx.$.node("unit",{unit:X});else{let _=X9(X,J5(X));Y.root=Y.ctx.$.node("unit",{meta:X,unit:_})}},Q5={"'":1,'"':1},_9={"/":1,"'":1,'"':1},G9={"d'":"'",'d"':'"',"'":"'",'"':'"',"/":"/"},gQ={"'":(Y)=>Y.lookahead==="'",'"':(Y)=>Y.lookahead==='"',"/":(Y)=>Y.lookahead==="/"},yQ={'"':"double-quote","'":"single-quote","/":"forward slash"},pQ=(Y,Z)=>`${Z}${Y} requires a closing ${yQ[G9[Z]]}`;var W9=(Y)=>`Private type references should not include '#'. Use '${Y}' instead.`,YY="Optional definitions like 'string?' are only valid as properties in an object or tuple",ZY="Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple";var H9={">":!0,">=":!0},J9={"<":!0,"<=":!0};var Q8={"<":">",">":"<","<=":">=",">=":"<=","==":"=="},$9=(Y)=>`Unmatched )${Y===""?"":` before ${Y}`}`,XY=(Y)=>`Missing ${Y}`,Q9=(Y,Z)=>`Left bounds are only valid when paired with right bounds (try ...${Z}${Y})`,_Y=(Y)=>`Left-bounded expressions must specify their limits using < or <= (was ${Y})`,z9=(Y,Z,X,_)=>`An expression may have at most one left bound (parsed ${Y}${Q8[Z]}, ${X}${Q8[_]})`;var F9=(Y,Z,X)=>U9(Y,Z,X,[]),U9=(Y,Z,X,_)=>{let G=X.parseUntilFinalizer();if(_.push(G.root),G.finalizer===">"){if(_.length!==Z.params.length)return X.error(z5(Y,Z.names,_.map((W)=>W.expression)));return _}if(G.finalizer===",")return U9(Y,Z,X,_);return G.error(XY(">"))},z5=(Y,Z,X)=>`${Y}<${Z.join(", ")}> requires exactly ${Z.length} args (got ${X.length}${X.length===0?"":`: ${X.join(", ")}`})`;var F5=(Y)=>{let Z=Y.scanner.shiftUntilNextTerminator();if(Z==="keyof")Y.addPrefix("keyof");else Y.root=uQ(Y,Z)},mQ=(Y,Z,X)=>{if(X.scanner.shiftUntilNonWhitespace(),X.scanner.shift()!=="<")return X.error(z5(Y,Z.names,[]));let G=F9(Y,Z,X);return Z(...G)},uQ=(Y,Z)=>dQ(Y,Z)??cQ(Y,Z)??Y.error(Z===""?Y.scanner.lookahead==="#"?W9(Y.shiftedByOne().scanner.shiftUntilNextTerminator()):U5(Y):W5(Z)),dQ=(Y,Z)=>{if(Y.ctx.args?.[Z]){let _=Y.ctx.args[Z];if(typeof _!=="string")return _;return Y.ctx.$.node("alias",{reference:_},{prereduced:!0})}let X=Y.ctx.$.maybeResolve(Z);if(y(X,"root"))return X;if(X===void 0)return;if(y(X,"generic"))return mQ(Z,X,Y);return w(`Unexpected resolution ${n(X)}`)},cQ=(Y,Z)=>{let X=f_(Z);if(X!==void 0)return Y.ctx.$.node("unit",{unit:X});let _=k_(Z);if(_!==void 0)return Y.ctx.$.node("unit",{unit:_})},U5=(Y)=>{let Z=Y.previousOperator();return Z?O5(Z,Y.scanner.unscanned):lQ(Y.scanner.unscanned)},O5=(Y,Z="")=>`Token '${Y}' requires a right operand${Z?` before '${Z}'`:""}`,lQ=(Y)=>`Expected an expression${Y?` before '${Y}'`:""}`;var E5=(Y)=>Y.scanner.lookahead===""?Y.error(U5(Y)):Y.scanner.lookahead==="("?Y.shiftedByOne().reduceGroupOpen():Y.scanner.lookaheadIsIn(_9)?$5(Y,Y.scanner.shift()):Y.scanner.lookaheadIsIn(E4)?E5(Y.shiftedByOne()):Y.scanner.lookahead==="d"?Y.scanner.nextLookahead in Q5?$5(Y,`${Y.scanner.shift()}${Y.scanner.shift()}`):F5(Y):F5(Y);class G4 extends AZ{shiftUntilNextTerminator(){return this.shiftUntilNonWhitespace(),this.shiftUntil(()=>(this.lookahead in G4.terminatingChars))}static terminatingChars={"<":1,">":1,"=":1,"|":1,"&":1,")":1,"[":1,"%":1,",":1,":":1,"?":1,"#":1,...E4};static finalizingLookaheads={">":1,",":1,"":1,"=":1,"?":1};static lookaheadIsFinalizing=(Y,Z)=>Y===">"?Z[0]==="="?Z[1]==="=":Z.trimStart()===""||p0(Z.trimStart()[0],G4.terminatingChars):Y==="="?Z[0]!=="=":Y===","||Y==="?"}var E9=(Y,Z)=>{let X=iQ(Y,Z);if(Y.root.hasKind("unit")){if(typeof Y.root.unit==="number"){Y.reduceLeftBound(Y.root.unit,X),Y.unsetRoot();return}if(Y.root.unit instanceof Date){let _=`d'${Y.root.description??Y.root.unit.toISOString()}'`;Y.unsetRoot(),Y.reduceLeftBound(_,X);return}}return nQ(Y,X)},L9={"<":1,">":1,"=":1},iQ=(Y,Z)=>Y.scanner.lookaheadIs("=")?`${Z}${Y.scanner.shift()}`:Z;var O9=(Y,Z,X,_)=>{if(X.extends(B.intrinsic.number)){if(typeof Z!=="number")return w(L5(Y,Z,_));return Y==="=="?["min","max"]:Y[0]===">"?["min"]:["max"]}if(X.extends(B.intrinsic.lengthBoundable)){if(typeof Z!=="number")return w(L5(Y,Z,_));return Y==="=="?["exactLength"]:Y[0]===">"?["minLength"]:["maxLength"]}if(X.extends(B.intrinsic.Date))return Y==="=="?["after","before"]:Y[0]===">"?["after"]:["before"];return w(_G(X.expression))},oQ=(Y)=>({rule:Y9(Y.limit)?Z9(Y.limit):Y.limit,exclusive:Y.comparator.length===1}),nQ=(Y,Z)=>{let X=Y.unsetRoot(),_=Y.scanner.location;Y.parseOperand();let G=Y.unsetRoot(),W=Y.scanner.sliceChars(_,Y.scanner.location);if(Y.root=X,!G.hasKind("unit")||typeof G.unit!=="number"&&!(G.unit instanceof Date))return Y.error(L5(Z,W,"right"));let H=G.unit,J=Z.length===1,Q=O9(Z,typeof H==="number"?H:W,X,"right");for(let z of Q)Y.constrainRoot(z,Z==="=="?{rule:H}:{rule:H,exclusive:J});if(!Y.branches.leftBound)return;if(!p0(Z,J9))return Y.error(_Y(Z));let $=O9(Y.branches.leftBound.comparator,Y.branches.leftBound.limit,X,"left");Y.constrainRoot($[0],oQ(Y.branches.leftBound)),Y.branches.leftBound=null},L5=(Y,Z,X)=>`Comparator ${X==="left"?Q8[Y]:Y} must be ${X==="left"?"preceded":"followed"} by a corresponding literal (was ${Z})`;var D9=(Y)=>{Y.scanner.shiftUntilNonWhitespace();let Z=Y.scanner.shiftUntilNextTerminator();Y.root=Y.root.brand(Z)};var M9=(Y)=>{let Z=Y.scanner.shiftUntilNextTerminator(),X=b_(Z,{errorOnFail:V9(Z)});if(X===0)Y.error(V9(0));Y.root=Y.root.constrain("divisor",X)},V9=(Y)=>`% operator must be followed by a non-zero integer literal (was ${Y})`;var D5=(Y)=>{let Z=Y.scanner.shift();return Z===""?Y.finalize(""):Z==="["?Y.scanner.shift()==="]"?Y.setRoot(Y.root.array()):Y.error(rQ):Z==="|"?Y.scanner.lookahead===">"?Y.shiftedByOne().pushRootToBranch("|>"):Y.pushRootToBranch(Z):Z==="&"?Y.pushRootToBranch(Z):Z===")"?Y.finalizeGroup():G4.lookaheadIsFinalizing(Z,Y.scanner.unscanned)?Y.finalize(Z):p0(Z,L9)?E9(Y,Z):Z==="%"?M9(Y):Z==="#"?D9(Y):(Z in E4)?D5(Y):Y.error(GY(Z))},GY=(Y,Z="")=>`'${Y}' is not allowed here${Z&&` (should be ${Z})`}`,rQ="Missing expected ']'";var A9=(Y)=>{let Z=Y.unsetRoot();Y.parseOperand();let X=Y.unsetRoot();if(!X.hasKind("unit"))return Y.error(sQ(X.expression));let _=X.unit instanceof Date?()=>new Date(X.unit):X.unit;return[Z,"=",_]},sQ=(Y)=>`Default value '${Y}' must a literal value`;var V5=(Y,Z)=>{let X=Z.$.maybeResolveRoot(Y);if(X)return X;if(Y.endsWith("[]")){let W=Z.$.maybeResolveRoot(Y.slice(0,-2));if(W)return W.array()}let _=new z8(new G4(Y),Z),G=aQ(_);if(_.finalizer===">")w(GY(">"));return G},aQ=(Y)=>{Y.parseOperand();let Z=Y6(Y).root;if(!Z)return _0(`Root was unexpectedly unset after parsing string '${Y.scanner.scanned}'`);if(Y.finalizer==="=")Z=A9(Y);else if(Y.finalizer==="?")Z=[Z,"?"];if(Y.scanner.shiftUntilNonWhitespace(),Y.scanner.lookahead)w(GY(Y.scanner.lookahead));return Z},Y6=(Y)=>{while(Y.finalizer===void 0)tQ(Y);return Y},tQ=(Y)=>Y.hasRoot()?Y.parseOperator():Y.parseOperand();class z8{root;branches={prefixes:[],leftBound:null,intersection:null,union:null,pipe:null};finalizer;groups=[];scanner;ctx;constructor(Y,Z){this.scanner=Y,this.ctx=Z}error(Y){return w(Y)}hasRoot(){return this.root!==void 0}setRoot(Y){this.root=Y}unsetRoot(){let Y=this.root;return this.root=void 0,Y}constrainRoot(...Y){this.root=this.root.constrain(Y[0],Y[1])}finalize(Y){if(this.groups.length)return this.error(XY(")"));this.finalizeBranches(),this.finalizer=Y}reduceLeftBound(Y,Z){let X=Q8[Z];if(!p0(X,H9))return this.error(_Y(Z));if(this.branches.leftBound)return this.error(z9(this.branches.leftBound.limit,this.branches.leftBound.comparator,Y,X));this.branches.leftBound={comparator:X,limit:Y}}finalizeBranches(){if(this.assertRangeUnset(),this.branches.pipe){this.pushRootToBranch("|>"),this.root=this.branches.pipe;return}if(this.branches.union){this.pushRootToBranch("|"),this.root=this.branches.union;return}if(this.branches.intersection){this.pushRootToBranch("&"),this.root=this.branches.intersection;return}this.applyPrefixes()}finalizeGroup(){this.finalizeBranches();let Y=this.groups.pop();if(!Y)return this.error($9(this.scanner.unscanned));this.branches=Y}addPrefix(Y){this.branches.prefixes.push(Y)}applyPrefixes(){while(this.branches.prefixes.length){let Y=this.branches.prefixes.pop();this.root=Y==="keyof"?this.root.keyof():_0(`Unexpected prefix '${Y}'`)}}pushRootToBranch(Y){this.assertRangeUnset(),this.applyPrefixes();let Z=this.root;if(this.root=void 0,this.branches.intersection=this.branches.intersection?.rawAnd(Z)??Z,Y==="&")return;if(this.branches.union=this.branches.union?.rawOr(this.branches.intersection)??this.branches.intersection,this.branches.intersection=null,Y==="|")return;this.branches.pipe=this.branches.pipe?.rawPipeOnce(this.branches.union)??this.branches.union,this.branches.union=null}parseUntilFinalizer(){return Y6(new z8(this.scanner,this.ctx))}parseOperator(){return D5(this)}parseOperand(){return E5(this)}assertRangeUnset(){if(this.branches.leftBound)return this.error(Q9(this.branches.leftBound.limit,this.branches.leftBound.comparator))}reduceGroupOpen(){this.groups.push(this.branches),this.branches={prefixes:[],leftBound:null,union:null,intersection:null,pipe:null}}previousOperator(){return this.branches.leftBound?.comparator??this.branches.prefixes.at(-1)??(this.branches.intersection?"&":this.branches.union?"|":this.branches.pipe?"|>":void 0)}shiftedByOne(){return this.scanner.shift(),this}}var eQ="An empty string is not a valid generic parameter name",WY=(Y,Z,X)=>{Y.shiftUntilNonWhitespace();let _=Y.shiftUntilNextTerminator();if(_===""){if(Y.lookahead===""&&Z.length)return Z;return w(eQ)}return Y.shiftUntilNonWhitespace(),Yz(Y,_,Z,X)},w9="extends ",Yz=(Y,Z,X,_)=>{if(Y.shiftUntilNonWhitespace(),Y.unscanned.startsWith(w9))Y.jumpForward(w9.length);else{if(Y.lookahead===",")Y.shift();return X.push(Z),WY(Y,X,_)}let G=Y6(new z8(Y,_));return X.push([Z,G.root]),WY(Y,X,_)};class M5 extends h1{$;constructor(Y){super((...Z)=>new Z6(Y)(...Z),{bind:Y});this.$=Y}in(Y){return new Z6(this.$,Y===void 0?void 0:this.$.parse(Y))}at(Y,Z){return new Z6(this.$).at(Y,Z)}case(Y,Z){return new Z6(this.$).case(Y,Z)}}class Z6 extends h1{$;in;key;branches=[];constructor(Y,Z){super((X)=>this.caseEntries(Object.entries(X).map(([_,G])=>_==="default"?[_,G]:[this.$.parse(_),G])));this.$=Y,this.in=Z}at(Y,Z){if(this.key)w(Xz);if(this.branches.length)w(Zz);return this.key=Y,Z?this.match(Z):this}case(Y,Z){return this.caseEntry(this.$.parse(Y),Z)}caseEntry(Y,Z){let _=(this.key?this.$.parse({[this.key]:Y}):Y).pipe(Z);return this.branches.push(_),this}match(Y){return this(Y)}strings(Y){return this.caseEntries(Object.entries(Y).map(([Z,X])=>Z==="default"?[Z,X]:[this.$.node("unit",{unit:Z}),X]))}caseEntries(Y){for(let Z=0;Z<Y.length;Z++){let[X,_]=Y[Z];if(X==="default"){if(Z!==Y.length-1)w("default may only be specified as the last key of a switch definition");return this.default(_)}if(typeof _!=="function")return w(`Value for case "${X}" must be a function (was ${y0(_)})`);this.caseEntry(X,_)}return this}default(Y){if(typeof Y==="function")this.case(d.unknown,Y);let Z={branches:this.branches,ordered:!0};if(Y==="never"||Y==="assert")Z.meta={onFail:R9};let X=this.$.node("union",Z);if(!this.in)return this.$.finalize(X);let _=this.in.pipe(X);if(Y==="never"||Y==="assert")_=_.configureReferences({onFail:R9},"self");return this.$.finalize(_)}}var R9=(Y)=>Y.throw(),Zz="A key matcher must be specified before the first case i.e. match.at('foo') or match.in<object>().at('bar')",Xz="At most one key matcher may be specified per expression";var HY=(Y,Z)=>{if(O0(Y)){if(Y[1]==="=")return[Z.$.parseOwnDefinitionFormat(Y[0],Z),"=",Y[2]];if(Y[1]==="?")return[Z.$.parseOwnDefinitionFormat(Y[0],Z),"?"]}return JY(Y,Z)},N9="Only required keys may make their values optional, e.g. { [mySymbol]: ['number', '?'] }",I9="Only required keys may specify default values, e.g. { value: 'number = 0' }";var B9=(Y,Z)=>{let X,_={},G=j4(Y);for(let[H,J]of G){let Q=Wz(H);if(Q.kind==="spread"){if(!c1(_))return w(Gz);let V=Z.$.parseOwnDefinitionFormat(J,Z);if(V.equals(d.object))continue;if(!V.hasKind("intersection")||!V.basis?.equals(d.object))return w(Hz(V.expression));X=V.structure;continue}if(Q.kind==="undeclared"){if(J!=="reject"&&J!=="delete"&&J!=="ignore")w(_z(J));_.undeclared=J;continue}let $=HY(J,Z),z=Q;if(Q.kind==="required"){if(!O0($))A5(_,"required",{key:Q.normalized,value:$},Z);else A5(_,"optional",$[1]==="="?{key:Q.normalized,value:$[0],default:$[2]}:{key:Q.normalized,value:$[0]},Z);continue}if(O0($)){if($[1]==="?")w(N9);if($[1]==="=")w(I9)}if(Q.kind==="optional"){A5(_,"optional",{key:Q.normalized,value:$},Z);continue}let O=Z.$.parseOwnDefinitionFormat(z.normalized,Z),L=a6(O,$,Z.$);if(L.index)_.index=Z0(_.index,L.index);if(L.required)_.required=Z0(_.required,L.required)}let W=Z.$.node("structure",_);return Z.$.parseSchema({domain:"object",structure:X?.merge(W)??W})},A5=(Y,Z,X,_)=>{Y[Z]=Z0(Y[Z],_.$.node(Z,X))},_z=(Y)=>`Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${n(Y)})`,Gz="Spread operator may only be used as the first key in an object",Wz=(Y)=>typeof Y==="symbol"?{kind:"required",normalized:Y}:Y.at(-1)==="?"?Y.at(-2)===x8?{kind:"required",normalized:`${Y.slice(0,-2)}?`}:{kind:"optional",normalized:Y.slice(0,-1)}:Y[0]==="["&&Y.at(-1)==="]"?{kind:"index",normalized:Y.slice(1,-1)}:Y[0]===x8&&Y[1]==="["&&Y.at(-1)==="]"?{kind:"required",normalized:Y.slice(1)}:Y==="..."?{kind:"spread"}:Y==="+"?{kind:"undeclared"}:{kind:"required",normalized:Y==="\\..."?"...":Y==="\\+"?"+":Y},Hz=(Y)=>`Spread operand must resolve to an object literal type (was ${Y})`;var C9=(Y,Z)=>Dz(Y)?P9[Y[0]](Y,Z):Ez(Y)?j9[Y[1]](Y,Z):null,Jz=(Y,Z)=>Z.$.parseOwnDefinitionFormat(Y[1],Z).keyof(),w5=(Y,Z)=>{if(Y[2]===void 0)return w(O5(Y[1],""));let X=Z.$.parseOwnDefinitionFormat(Y[0],Z),_=Z.$.parseOwnDefinitionFormat(Y[2],Z);if(Y[1]==="|")return Z.$.node("union",{branches:[X,_]});let G=Y[1]==="&"?O1(X,_,Z.$):d8(X,_,Z.$);if(G instanceof S)return G.throw();return G},$z=(Y,Z)=>Z.$.parseOwnDefinitionFormat(Y[0],Z).array(),Qz=(Y,Z)=>{if(typeof Y[2]!=="function")return w(q9("=>",Y[2]));return Z.$.parseOwnDefinitionFormat(Y[0],Z).pipe(Y[2])},q9=(Y,Z)=>`${Y===":"?"Narrow":"Morph"} expression requires a function following '${Y}' (was ${typeof Z})`,zz=(Y,Z)=>{if(typeof Y[2]!=="function")return w(q9(":",Y[2]));return Z.$.parseOwnDefinitionFormat(Y[0],Z).constrain("predicate",Y[2])},Fz=(Y,Z)=>Z.$.parseOwnDefinitionFormat(Y[0],Z).configureReferences(Y[2],"shallow"),K9=(Y)=>Y,Uz=K9({"[]":$z,"?":()=>w(YY)}),Oz=K9({"|":w5,"&":w5,":":zz,"=>":Qz,"|>":w5,"@":Fz,"=":()=>w(ZY)}),j9={...Uz,...Oz},Ez=(Y)=>j9[Y[1]]!==void 0,Lz=(Y)=>Y,P9=Lz({keyof:Jz,instanceof:(Y,Z)=>{if(typeof Y[1]!=="function")return w(T9(S8(Y[1])));let X=Y.slice(1).map((_)=>typeof _==="function"?Z.$.node("proto",{proto:_}):w(T9(S8(_))));return X.length===1?X[0]:Z.$.node("union",{branches:X})},"===":(Y,Z)=>Z.$.units(Y.slice(1))}),Dz=(Y)=>P9[Y[0]]!==void 0,T9=(Y)=>`Expected a constructor following 'instanceof' operator (was ${Y})`;var x9=(Y,Z)=>{let X=[{}],_=0;while(_<Y.length){let G=!1;if(Y[_]==="..."&&_<Y.length-1)G=!0,_++;let W=HY(Y[_],Z),[H,J,Q]=!O0(W)?[W]:W;if(_++,G){if(!H.extends(B.intrinsic.Array))return w(Az(H.expression));X=X.flatMap(($)=>H.distribute((z)=>Mz(p6($),z)))}else X=X.map(($)=>{if(J==="?")return h9($,H);if(J==="=")return Vz($,H,Q);return R5($,H)})}return Z.$.parseSchema(X.map((G)=>c1(G)?{proto:Array,exactLength:0}:{proto:Array,sequence:G}))},R5=(Y,Z)=>{if(Y.defaultables||Y.optionals)return w(Y.variadic?tZ:wz);if(Y.variadic)Y.postfix=Z0(Y.postfix,Z);else Y.prefix=Z0(Y.prefix,Z);return Y},h9=(Y,Z)=>{if(Y.variadic)return w(f9);return Y.optionals=Z0(Y.optionals,Z),Y},Vz=(Y,Z,X)=>{if(Y.variadic)return w(f9);if(Y.optionals)return w(Rz);return Y.defaultables=Z0(Y.defaultables,[[Z,X]]),Y},S9=(Y,Z)=>{if(Y.postfix)w(v9);if(Y.variadic){if(!Y.variadic.equals(Z))w(v9)}else Y.variadic=Z.internal;return Y},Mz=(Y,Z)=>{let X=Z.select({method:"find",kind:"sequence"});if(!X)return S9(Y,B.intrinsic.unknown);if(X.prefix)for(let _ of X.prefix)R5(Y,_);if(X.optionals)for(let _ of X.optionals)h9(Y,_);if(X.variadic)S9(Y,X.variadic);if(X.postfix)for(let _ of X.postfix)R5(Y,_);return Y},Az=(Y)=>`Spread element must be an array (was ${Y})`,v9="A tuple may have at most one variadic element",wz="A required element may not follow an optional element",f9="An optional element may not follow a variadic element";var Rz="A defaultable element may not follow an optional element without a default";var Nz={},JY=(Y,Z)=>{if(typeof Y==="string"){if(Z.args&&Object.keys(Z.args).some((_)=>Y.includes(_)))return V5(Y,Z);let X=Nz[Z.$.name]??={};return X[Y]??=V5(Y,Z)}return Q1(Y,"object")?Iz(Y,Z):w(N5(y0(Y)))},Iz=(Y,Z)=>{let X=P8(Y);switch(X){case void 0:if(y(Y,"root"))return Y;return B9(Y,Z);case"Array":return Bz(Y,Z);case"RegExp":return Z.$.node("intersection",{domain:"string",pattern:Y},{prereduced:!0});case"Function":{let _=O4(Y)?Y():Y;if(y(_,"root"))return _;return w(N5("Function"))}default:return w(N5(X??n(Y)))}},Bz=(Y,Z)=>C9(Y,Z)??x9(Y,Z),N5=(Y)=>`Type definitions must be strings or objects (was ${Y})`;class I5 extends h1{constructor(Y){let Z=Object.assign({errors:F1,hkt:a0,$:Y,raw:Y.parse,module:Y.constructor.module,scope:Y.constructor.scope,define:Y.define,match:Y.match,generic:Y.generic,schema:Y.schema,keywords:Y.ambient,unit:Y.unit,enumerated:Y.enumerated,instanceOf:Y.instanceOf,valueOf:Y.valueOf,or:Y.or,and:Y.and,merge:Y.merge,pipe:Y.pipe},Y.ambientAttachments);super((...X)=>{if(X.length===1)return Y.parse(X[0]);if(X.length===2&&typeof X[0]==="string"&&X[0][0]==="<"&&X[0].at(-1)===">"){let _=X[0].slice(1,-1),G=Y.parseGenericParams(_,{});return new M4(G,X[1],Y,Y,null)}return Y.parse(X)},{bind:Y,attach:Z})}}var F8=B;class $Y extends t6{get ambientAttachments(){if(!F8.typeAttachments)return;return this.cacheGetter("ambientAttachments",o(F8.typeAttachments,(Y,Z)=>[Y,this.bindReference(Z)]))}preparseOwnAliasEntry(Y,Z){let X=Y.indexOf("<");if(X===-1){if(y(Z,"module")||y(Z,"generic"))return[Y,Z];let W=this.name==="ark"?Y:Y==="root"?this.name:`${this.name}.${Y}`,H=this.resolvedConfig.keywords?.[W];if(H)Z=[Z,"@",H];return[Y,Z]}if(Y.at(-1)!==">")w("'>' must be the last character of a generic declaration in a scope");let _=Y.slice(0,X),G=Y.slice(X+1,-1);return[_,()=>{let W=this.parseGenericParams(G,{alias:_});return YG(W,Z,this)}]}parseGenericParams(Y,Z){return WY(new G4(Y),[],this.createParseContext({...Z,def:Y,prefix:"generic"}))}normalizeRootScopeValue(Y){if(O4(Y)&&!y(Y,"generic"))return Y();return Y}preparseOwnDefinitionFormat(Y,Z){return{...Z,def:Y,prefix:Z.alias??"type"}}parseOwnDefinitionFormat(Y,Z){if(!(Z.alias&&(Z.alias in this.aliases))&&!Z.args)Z.args={this:Z.id};let _=JY(Y,Z);if(O0(_)){if(_[1]==="=")return w(ZY);if(_[1]==="?")return w(YY)}return _}unit=(Y)=>this.units([Y]);valueOf=(Y)=>this.units(w_(Y));enumerated=(...Y)=>this.units(Y);instanceOf=(Y)=>this.node("proto",{proto:Y},{prereduced:!0});or=(...Y)=>this.schema(Y.map((Z)=>this.parse(Z)));and=(...Y)=>Y.reduce((Z,X)=>Z.and(this.parse(X)),this.intrinsic.unknown);merge=(...Y)=>Y.reduce((Z,X)=>Z.merge(this.parse(X)),this.intrinsic.object);pipe=(...Y)=>this.intrinsic.unknown.pipe(...Y);match=new M5(this);declare=()=>({type:this.type});define(Y){return Y}type=new I5(this);static scope=(Y,Z={})=>new $Y(Y,Z);static module=(Y,Z={})=>this.scope(Y,Z).export()}var B5=Object.assign($Y.scope,{define:(Y)=>Y}),Y0=$Y;class b9 extends a0{description='merge an object\'s properties onto another like `Merge(User, { isAdmin: "true" })`'}var Tz=q1(["base",d.object],["props",d.object])((Y)=>Y.base.merge(Y.props),b9),k9=Y0.module({Key:d.key,Merge:Tz});class g9 extends a0{}var Cz=q1("element")((Y)=>{let Z=Y.element.exclude(d.Array),X=Z.array();return Z.rawOr(X).pipe(U4).distribute((_)=>_.assertHasKind("morph").declareOut(X),$0)},g9),y9=Y0.module({root:d.Array,readonly:"root",index:d.nonNegativeIntegerString,liftFrom:Cz},{name:"Array"});var T5=$0(["string",S4.FileConstructor]),qz=T5.rawOr(T5.array()),p9=$0({meta:"an object representing parsed form data",domain:"object",index:{signature:"string",value:qz}}),m9=Y0.module({root:["instanceof",FormData],value:T5,parsed:p9,parse:$0({in:FormData,morphs:(Y)=>{let Z={};for(let[X,_]of Y)if(X in Z){let G=Z[X];if(typeof G==="string"||G instanceof S4.FileConstructor)Z[X]=[G,_];else G.push(_)}else Z[X]=_;return Z},declaredOut:p9})},{name:"FormData"});var u9=Y0.module({Int8:["instanceof",Int8Array],Uint8:["instanceof",Uint8Array],Uint8Clamped:["instanceof",Uint8ClampedArray],Int16:["instanceof",Int16Array],Uint16:["instanceof",Uint16Array],Int32:["instanceof",Int32Array],Uint32:["instanceof",Uint32Array],Float32:["instanceof",Float32Array],Float64:["instanceof",Float64Array],BigInt64:["instanceof",BigInt64Array],BigUint64:["instanceof",BigUint64Array]},{name:"TypedArray"});var Kz={Boolean:1,Number:1,String:1},d9=Y0.module({...o({...FZ,...OZ},(Y,Z)=>(Y in Kz)?[]:[Y,["instanceof",Z]]),Array:y9,TypedArray:u9,FormData:m9});var jz=$0({domain:{domain:"number",meta:"a number representing a Unix timestamp"},divisor:{rule:1,meta:"an integer representing a Unix timestamp"},min:{rule:-8640000000000000,meta:"a Unix timestamp after -8640000000000000"},max:{rule:8640000000000000,meta:"a Unix timestamp before 8640000000000000"},meta:"an integer representing a safe Unix timestamp"}),Pz=$0({domain:"number",divisor:1}),QY=Y0.module({root:d.number,integer:Pz,epoch:jz,safe:$0({domain:{domain:"number",numberAllowsNaN:!1},min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER}),NaN:["===",Number.NaN],Infinity:["===",Number.POSITIVE_INFINITY],NegativeInfinity:["===",Number.NEGATIVE_INFINITY]},{name:"number"});var I0=(Y,Z,X)=>{let _={domain:"string",pattern:{rule:Y.source,flags:Y.flags,meta:Z}};if(X)_.meta={format:X};return $8("intersection",_)},c9=I0(h8,"a well-formed integer string"),X7=Y0.module({root:c9,parse:$0({in:c9,morphs:(Y,Z)=>{let X=Number.parseInt(Y);return Number.isSafeInteger(X)?X:Z.error("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER")},declaredOut:d.integer})},{name:"string.integer"}),Sz=I0(/^[\dA-Fa-f]+$/,"hex characters only"),vz=Y0.module({root:I0(/^(?:[\d+/A-Za-z]{4})*(?:[\d+/A-Za-z]{2}==|[\d+/A-Za-z]{3}=)?$/,"base64-encoded"),url:I0(/^(?:[\w-]{4})*(?:[\w-]{2}(?:==|%3D%3D)?|[\w-]{3}(?:=|%3D)?)?$/,"base64url-encoded")},{name:"string.base64"}),l9=I0(/^[A-Z].*$/,"capitalized"),xz=Y0.module({root:$0({in:"string",morphs:(Y)=>Y.charAt(0).toUpperCase()+Y.slice(1),declaredOut:l9}),preformatted:l9},{name:"string.capitalize"}),hz=(Y)=>{let Z=Y.replaceAll(/[ -]+/g,""),X=0,_,G,W=!1;for(let H=Z.length-1;H>=0;H--){if(_=Z.substring(H,H+1),G=Number.parseInt(_,10),W)G*=2,X+=G>=10?G%10+1:G;else X+=G;W=!W}return!!(X%10===0?Z:!1)},fz=/^(?:4\d{12}(?:\d{3,6})?|5[1-5]\d{14}|(222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[01]\d|2720)\d{12}|6(?:011|5\d\d)\d{12,15}|3[47]\d{13}|3(?:0[0-5]|[68]\d)\d{11}|(?:2131|1800|35\d{3})\d{11}|6[27]\d{14}|^(81\d{14,17}))$/,bz=$0({domain:"string",pattern:{meta:"a credit card number",rule:fz.source},predicate:{meta:"a credit card number",predicate:hz}});var kz=/^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))(T((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([,.]\d+(?!:))?)?(\17[0-5]\d([,.]\d+)?)?([Zz]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;var gz=(Y)=>!Number.isNaN(new Date(Y).valueOf()),i9=$0({domain:"string",predicate:{meta:"a parsable date",predicate:gz}}).assertHasKind("intersection"),o9=X7.root.internal.narrow((Y,Z)=>{let X=Number.parseInt(Y),_=QY.epoch(X);if(_ instanceof F1)return Z.errors.merge(_),!1;return!0}).configure({description:"an integer string representing a safe Unix timestamp"},"self").assertHasKind("intersection"),yz=Y0.module({root:o9,parse:$0({in:o9,morphs:(Y)=>new Date(Y),declaredOut:d.Date})},{name:"string.date.epoch"}),n9=I0(kz,"an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection"),pz=Y0.module({root:n9,parse:$0({in:n9,morphs:(Y)=>new Date(Y),declaredOut:d.Date})},{name:"string.date.iso"}),mz=Y0.module({root:i9,parse:$0({declaredIn:i9,in:"string",morphs:(Y,Z)=>{let X=new Date(Y);if(Number.isNaN(X.valueOf()))return Z.error("a parsable date");return X},declaredOut:d.Date}),iso:pz,epoch:yz},{name:"string.date"}),uz=I0(/^[\w%+.-]+@[\d.A-Za-z-]+\.[A-Za-z]{2,}$/,"an email address","email"),r9="(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])",A4=`(${r9}[.]){3}${r9}`,dz=new RegExp(`^${A4}$`),v0="(?:[0-9a-fA-F]{1,4})",cz=new RegExp(`^((?:${v0}:){7}(?:${v0}|:)|(?:${v0}:){6}(?:${A4}|:${v0}|:)|(?:${v0}:){5}(?::${A4}|(:${v0}){1,2}|:)|(?:${v0}:){4}(?:(:${v0}){0,1}:${A4}|(:${v0}){1,3}|:)|(?:${v0}:){3}(?:(:${v0}){0,2}:${A4}|(:${v0}){1,4}|:)|(?:${v0}:){2}(?:(:${v0}){0,3}:${A4}|(:${v0}){1,5}|:)|(?:${v0}:){1}(?:(:${v0}){0,4}:${A4}|(:${v0}){1,6}|:)|(?::((?::${v0}){0,5}:${A4}|(?::${v0}){1,7}|:)))(%[0-9a-zA-Z.]{1,})?$`),lz=Y0.module({root:["v4 | v6","@","an IP address"],v4:I0(dz,"an IPv4 address","ipv4"),v6:I0(cz,"an IPv6 address","ipv6")},{name:"string.ip"}),U8="a JSON string",_7=(Y)=>{if(!(Y instanceof SyntaxError))throw Y;return`must be ${U8} (${Y})`},iz=$0({meta:U8,domain:"string",predicate:{meta:U8,predicate:(Y,Z)=>{try{return JSON.parse(Y),!0}catch(X){return Z.reject({code:"predicate",expected:U8,problem:_7(X)})}}}}),oz=(Y,Z)=>{if(Y.length===0)return Z.error({code:"predicate",expected:U8,actual:"empty"});try{return JSON.parse(Y)}catch(X){return Z.error({code:"predicate",expected:U8,problem:_7(X)})}},nz=Y0.module({root:iz,parse:$0({meta:"safe JSON string parser",in:"string",morphs:oz,declaredOut:d.jsonObject})},{name:"string.json"}),s9=I0(/^[a-z]*$/,"only lowercase letters"),rz=Y0.module({root:$0({in:"string",morphs:(Y)=>Y.toLowerCase(),declaredOut:s9}),preformatted:s9},{name:"string.lower"}),G7=["NFC","NFD","NFKC","NFKD"],X6=o(G7,(Y,Z)=>[Z,$0({domain:"string",predicate:(X)=>X.normalize(Z)===X,meta:`${Z}-normalized unicode`})]),zY=o(G7,(Y,Z)=>[Z,$0({in:"string",morphs:(X)=>X.normalize(Z),declaredOut:X6[Z]})]),sz=Y0.module({root:zY.NFC,preformatted:X6.NFC},{name:"string.normalize.NFC"}),az=Y0.module({root:zY.NFD,preformatted:X6.NFD},{name:"string.normalize.NFD"}),tz=Y0.module({root:zY.NFKC,preformatted:X6.NFKC},{name:"string.normalize.NFKC"}),ez=Y0.module({root:zY.NFKD,preformatted:X6.NFKD},{name:"string.normalize.NFKD"}),YF=Y0.module({root:"NFC",NFC:sz,NFD:az,NFKC:tz,NFKD:ez},{name:"string.normalize"}),a9=I0(k6,"a well-formed numeric string"),ZF=Y0.module({root:a9,parse:$0({in:a9,morphs:(Y)=>Number.parseFloat(Y),declaredOut:d.number})},{name:"string.numeric"}),t9="a regex pattern",XF=$0({domain:"string",predicate:{meta:t9,predicate:(Y,Z)=>{try{return new RegExp(Y),!0}catch(X){return Z.reject({code:"predicate",expected:t9,problem:String(X)})}}},meta:{format:"regex"}}),_F=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*))*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/,GF=I0(_F,"a semantic version (see https://semver.org/)"),e9=I0(/^\S.*\S$|^\S?$/,"trimmed"),WF=Y0.module({root:$0({in:"string",morphs:(Y)=>Y.trim(),declaredOut:e9}),preformatted:e9},{name:"string.trim"}),Y7=I0(/^[A-Z]*$/,"only uppercase letters"),HF=Y0.module({root:$0({in:"string",morphs:(Y)=>Y.toUpperCase(),declaredOut:Y7}),preformatted:Y7},{name:"string.upper"}),JF=(Y)=>{if(URL.canParse)return URL.canParse(Y);try{return new URL(Y),!0}catch{return!1}},Z7=$0({domain:"string",predicate:{meta:"a URL string",predicate:JF},meta:{format:"uri"}}),$F=Y0.module({root:Z7,parse:$0({declaredIn:Z7,in:"string",morphs:(Y,Z)=>{try{return new URL(Y)}catch{return Z.error("a URL string")}},declaredOut:$0(URL)})},{name:"string.url"}),QF=Y0.module({root:["versioned | nil | max","@",{description:"a UUID",format:"uuid"}],"#nil":"'00000000-0000-0000-0000-000000000000'","#max":"'ffffffff-ffff-ffff-ffff-ffffffffffff'","#versioned":/[\da-f]{8}-[\da-f]{4}-[1-8][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}/i,v1:I0(/^[\da-f]{8}-[\da-f]{4}-1[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv1"),v2:I0(/^[\da-f]{8}-[\da-f]{4}-2[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv2"),v3:I0(/^[\da-f]{8}-[\da-f]{4}-3[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv3"),v4:I0(/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv4"),v5:I0(/^[\da-f]{8}-[\da-f]{4}-5[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv5"),v6:I0(/^[\da-f]{8}-[\da-f]{4}-6[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv6"),v7:I0(/^[\da-f]{8}-[\da-f]{4}-7[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv7"),v8:I0(/^[\da-f]{8}-[\da-f]{4}-8[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv8")},{name:"string.uuid"}),W7=Y0.module({root:d.string,alpha:I0(/^[A-Za-z]*$/,"only letters"),alphanumeric:I0(/^[\dA-Za-z]*$/,"only letters and digits 0-9"),hex:Sz,base64:vz,capitalize:xz,creditCard:bz,date:mz,digits:I0(/^\d*$/,"only digits 0-9"),email:uz,integer:X7,ip:lz,json:nz,lower:rz,normalize:YF,numeric:ZF,regex:XF,semver:GF,trim:WF,upper:HF,url:$F,uuid:QF},{name:"string"});var H7=Y0.module({bigint:d.bigint,boolean:d.boolean,false:d.false,never:d.never,null:d.null,number:d.number,object:d.object,string:d.string,symbol:d.symbol,true:d.true,unknown:d.unknown,undefined:d.undefined}),J7=Y0.module({root:d.unknown,any:d.unknown},{name:"unknown"}),zF=Y0.module({root:d.jsonObject,stringify:$8("morph",{in:d.jsonObject,morphs:(Y)=>JSON.stringify(Y),declaredOut:d.string})},{name:"object.json"}),$7=Y0.module({root:d.object,json:zF},{name:"object"});class Q7 extends a0{description='instantiate an object from an index signature and corresponding value type like `Record("string", "number")`'}var FF=q1(["K",d.key],"V")((Y)=>({domain:"object",index:{signature:Y.K,value:Y.V}}),Q7);class z7 extends a0{description='pick a set of properties from an object like `Pick(User, "name | age")`'}var UF=q1(["T",d.object],["K",d.key])((Y)=>Y.T.pick(Y.K),z7);class F7 extends a0{description='omit a set of properties from an object like `Omit(User, "age")`'}var OF=q1(["T",d.object],["K",d.key])((Y)=>Y.T.omit(Y.K),F7);class U7 extends a0{description="make all named properties of an object optional like `Partial(User)`"}var EF=q1(["T",d.object])((Y)=>Y.T.partial(),U7);class O7 extends a0{description="make all named properties of an object required like `Required(User)`"}var LF=q1(["T",d.object])((Y)=>Y.T.required(),O7);class E7 extends a0{description='exclude branches of a union like `Exclude("boolean", "true")`'}var DF=q1("T","U")((Y)=>Y.T.exclude(Y.U),E7);class L7 extends a0{description='extract branches of a union like `Extract("0 | false | 1", "number")`'}var VF=q1("T","U")((Y)=>Y.T.extract(Y.U),L7),D7=Y0.module({Exclude:DF,Extract:VF,Omit:OF,Partial:EF,Pick:UF,Record:FF,Required:LF});var w4=B5({...H7,...D7,...d9,...k9,string:W7,number:QY,object:$7,unknown:J7},{prereducedAliases:!0,name:"ark"}),m0=w4.export();Object.assign(F8.ambient,m0);F8.typeAttachments={string:m0.string.root,number:m0.number.root,bigint:m0.bigint,boolean:m0.boolean,symbol:m0.symbol,undefined:m0.undefined,null:m0.null,object:m0.object.root,unknown:m0.unknown.root,false:m0.false,true:m0.true,never:m0.never,arrayIndex:m0.Array.index,Key:m0.Key,Record:m0.Record,Array:m0.Array.root,Date:m0.Date};var E1=Object.assign(w4.type,F8.typeAttachments),MF=w4.match,AF=w4.generic,YB=w4.schema,wF=w4.define,RF=w4.declare;var V7=(Y,Z,X=x0.STORE)=>{return C5(X,{key:`${Y.key}:JSON`,get:({get:_})=>Z.toJson(_(Y)),set:({set:_},G)=>{_(Y,Z.fromJson(G))}})};function M7(Y,Z,X){return FY(Y,{key:`${Z.key}:JSON`,get:(G)=>({get:W})=>{let H=W(Z,G);return X.toJson(H)},set:(G)=>({set:W},H)=>{W(Z,G,X.fromJson(H))}},["mutable","json"])}var G1=(Y)=>JSON.parse(Y),z0=(Y)=>JSON.stringify(Y),VB=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];function O8(Y){return q7(x0.STORE,Y)}function _6(Y){return I7(x0.STORE,Y)}function K5(...Y){if(Y.length===2)return k1(x0.STORE,...Y);return k1(x0.STORE,...Y)}function UY(Y,Z,X=x0.STORE){return X.joins.set(Y.key,new v5(Y,Z,X)),{key:Y.key,type:"join",a:Y.between[0],b:Y.between[1],cardinality:Y.cardinality}}function A7(Y){return j7(Y,x0.STORE)}var q5=(Y)=>(Z,X,_,G,...W)=>{console[Y](`${Z} ${X} "${_}" ${G}`,...W)},NF={error:q5("error"),info:q5("info"),warn:q5("warn")},w7=class{logLevel;filter;logger;constructor(Y,Z,X=NF){this.logLevel=Y,this.filter=Z,this.logger=X}error=(...Y)=>{let Z=this.filter?.(...Y)??!0;if(this.logLevel!==null){if(Z===!0)this.logger.error(...Y);else if(Z!==!1)this.logger.error(...Z)}};info=(...Y)=>{let Z=this.filter?.(...Y)??!0;if(this.logLevel==="info"){if(Z===!0)this.logger.info(...Y);else if(Z!==!1)this.logger.info(...Z)}};warn=(...Y)=>{let Z=this.filter?.(...Y)??!0;if(this.logLevel!=="error"&&this.logLevel!==null){if(Z===!0)this.logger.warn(...Y);else if(Z!==!1)this.logger.warn(...Z)}}};var IF=class{store;constructor(Y=x0.STORE){this.store=Y,B7("root",Y)}allocate(Y,Z,X){return L8(this.store,Y,Z,X)}fuse(Y,Z,X){return T7(this.store,Y,Z,X)}deallocate(Y){D8(this.store,Y)}claim(Y,Z,X){return W6(this.store,Y,Z,X)}},R7=class{store;realm;constructor(Y=x0.STORE){this.store=Y,this.realm=new IF(Y)}allocate(Y,Z,X){L8(this.store,Y,Z,X)}deallocate(Y){D8(this.store,Y)}claim(Y,Z,X){W6(this.store,Y,Z,X)}};function OY(Y){return P5(x0.STORE,Y)}function G6(Y){return S5(x0.STORE,Y)}var L1=class Y extends Set{mode="record";subject=new J0;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(Z,X=0){super(Z);if(Z instanceof Y)this.parent=Z,this.cacheUpdateNumber=Z.cacheUpdateNumber;if(X)this.cacheLimit=X,this.cache=new Array(X),this.subscribe("auto cache",(_)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=_})}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(Z){let X=new Y(Z.members,Z.cacheLimit);return X.cache=Z.cache,X.cacheIdx=Z.cacheIdx,X.cacheUpdateNumber=Z.cacheUpdateNumber,X}add(Z){let X=super.add(Z);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${z0(Z)}`);return X}clear(){let Z=this.mode==="record"?[...this]:null;if(super.clear(),Z)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(Z)}`)}delete(Z){let X=super.delete(Z);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${z0(Z)}`);return X}parent=null;child=null;transactionUpdates=null;transaction(Z){this.mode="transaction",this.transactionUpdates=[],this.child=new Y(this);let X=this.child._subscribe("transaction",(_)=>{this.transactionUpdates?.push(_)});try{if(Z(this.child)){for(let G of this.transactionUpdates)this.doStep(G);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(_){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",_),_}finally{X(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(Z,X){return this.subject.subscribe(Z,X)}subscribe(Z,X){return this.subject.subscribe(Z,(_)=>{X(`${this.cacheUpdateNumber}=${_}`)})}emit(Z){this.subject.next(Z)}doStep(Z){let X=Z.indexOf(":"),_=Z.substring(0,X),G=Z.substring(X+1);switch(_){case"add":this.add(JSON.parse(G));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(G));break;case"tx":for(let W of G.split(";"))this.doStep(W)}}getUpdateNumber(Z){let X=Z.indexOf("=");return Number(Z.substring(0,X))}do(Z){let X=Z.indexOf("="),_=Number(Z.substring(0,X)),G=_-this.cacheUpdateNumber;if(G>0){if(G===1){this.mode="playback";let H=Z.substring(X+1);return this.doStep(H),this.mode="record",this.cacheUpdateNumber=_,null}return this.cacheUpdateNumber+1}if(Math.abs(G)<this.cacheLimit){let H=this.cacheIdx+G;if(this.cache[H]===Z)return null;this.mode="playback";let Q=!1;while(!Q){this.cacheIdx%=this.cacheLimit;let z=this.cache[this.cacheIdx];if(this.cacheIdx--,!z)return"OUT_OF_RANGE";this.undo(z),Q=this.cacheIdx===H-1}let $=Z.substring(X+1);return this.doStep($),this.mode="record",this.cacheUpdateNumber=_,null}return"OUT_OF_RANGE"}undoStep(Z){let X=Z.indexOf(":"),_=Z.substring(0,X),G=Z.substring(X+1);switch(_){case"add":this.delete(JSON.parse(G));break;case"del":this.add(JSON.parse(G));break;case"clear":{let W=JSON.parse(G);for(let H of W)this.add(H);break}case"tx":{let W=G.split(";");for(let H=W.length-1;H>=0;H--)this.undoStep(W[H])}}}undo(Z){let X=Z.indexOf("=");if(Number(Z.substring(0,X))===this.cacheUpdateNumber){this.mode="playback";let G=Z.substring(X+1);return this.undoStep(G),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function N7(Y=Math.random){return Y().toString(36).slice(2)}var x5=class extends Promise{fate;resolve;reject;done=!1;constructor(Y){let Z,X;super((_,G)=>{Z=_,X=G});this.resolve=Z,this.reject=X,this.use(Y instanceof Promise?Y:new Promise(Y))}pass(Y,Z){if(Y===this.fate)this.resolve(Z),this.done=!0}fail(Y,Z){if(Y===this.fate)this.reject(Z),this.done=!0}use(Y){if(Y instanceof Promise){let Z=Y;this.fate=Z,Z.then((X)=>{this.pass(Z,X)},(X)=>{this.fail(Z,X)})}else this.resolve(Y),this.fate=void 0}};function i(Y){while(Y.child!==null)Y=Y.child;return Y}var TF=class Y{_buffer;_index=0;constructor(Z){let X;if(typeof Z==="number")X=Z;else X=Z.length;this._buffer=Array.from({length:X})}get buffer(){return this._buffer}get index(){return this._index}add(Z){this._buffer[this._index]=Z,this._index=(this._index+1)%this._buffer.length}copy(){let Z=new Y([...this._buffer]);return Z._index=this._index,Z}},CF={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function qF(Y,Z){let X=z0(Z),_=`${Y.key}(${X})`,G=CF[Y.type],W={key:_,type:G};return Object.assign(W,{family:{key:Y.key,subKey:X}}),Object.assign(W,{counterfeit:!0}),W}function W4(Y){let Z={key:Y.key,type:Y.type};if("family"in Y)Z.family=Y.family;return Z}var W1=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(Y,Z)=>`${Y}:${Z}`;warn;getRelatedKeys(Y){return this.relations.get(Y)}addRelation(Y,Z){let X=this.relations.get(Y),_=this.relations.get(Z);if(X)X.add(Z);else X=new Set([Z]),this.relations.set(Y,X);if(_)_.add(Y);else _=new Set([Y]),this.relations.set(Z,_)}deleteRelation(Y,Z){let X=this.relations.get(Y);if(X){if(X.delete(Z),X.size===0)this.relations.delete(Y);let _=this.relations.get(Z);if(_){if(_.delete(Y),_.size===0)this.relations.delete(Z)}}}replaceRelationsUnsafely(Y,Z){this.relations.set(Y,new Set(Z));for(let X of Z){let _=new Set().add(Y);this.relations.set(X,_)}}replaceRelationsSafely(Y,Z){let X=this.relations.get(Y),_=this.isAType?.(Y)?Y:void 0,G=_===void 0?Y:void 0;if(X)for(let W of X){_??=W,G??=W;let H=this.relations.get(W);if(H){if(H.size===1)this.relations.delete(W);else H.delete(Y);this.contents.delete(this.makeContentKey(_,G))}}this.relations.set(Y,new Set(Z));for(let W of Z){let H=this.relations.get(W);if(H)H.add(Y);else H=new Set().add(Y),this.relations.set(W,H)}}getContentInternal(Y){return this.contents.get(Y)}setContent(Y,Z){this.contents.set(Y,Z)}deleteContent(Y){this.contents.delete(Y)}constructor(Y,Z){if(this.a=Y.between[0],this.b=Y.between[1],this.cardinality=Y.cardinality,!Z?.externalStore)this.relations=new Map(Y.relations?.map(([X,_])=>[X,new Set(_)])),this.contents=new Map(Y.contents);if(this.isAType=Z?.isAType??null,this.isBType=Z?.isBType??null,this.isContent=Z?.isContent??null,Z?.makeContentKey)this.makeContentKey=Z.makeContentKey;if(Z?.externalStore){let X=Z.externalStore;if(this.has=(_,G)=>X.has(_,G),this.addRelation=(_,G)=>{X.addRelation(_,G)},this.deleteRelation=(_,G)=>{X.deleteRelation(_,G)},this.replaceRelationsSafely=(_,G)=>{X.replaceRelationsSafely(_,G)},this.replaceRelationsUnsafely=(_,G)=>{X.replaceRelationsUnsafely(_,G)},this.getRelatedKeys=(_)=>X.getRelatedKeys(_),X.getContent)this.getContentInternal=(_)=>{return X.getContent(_)},this.setContent=(_,G)=>{X.setContent(_,G)},this.deleteContent=(_)=>{X.deleteContent(_)};for(let[_,G]of Y.relations??[]){let W=this.isAType?.(_)?_:void 0,H=W===void 0?_:void 0;for(let J of G)W??=J,H??=J,this.addRelation(W,H)}for(let[_,G]of Y.contents??[])this.setContent(_,G)}if(Z?.warn)this.warn=Z.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([Y,Z])=>[Y,[...Z]]),contents:[...this.contents.entries()]}}set(...Y){let Z,X,_;switch(Y.length){case 1:{let G=Y[0];Z=G[this.a],X=G[this.b],_=void 0;break}case 2:{let G=Y[0];if(typeof G==="string")[Z,X]=Y;else Z=G[this.a],X=G[this.b],_=Y[1];break}default:{Z=Y[0],X=Y[1],_=Y[2];break}}switch(this.cardinality){case"1:1":{let G=this.getRelatedKey(Z);if(G&&G!==X)this.delete(Z,G)}case"1:n":{let G=this.getRelatedKey(X);if(G&&G!==Z)this.delete(G,X)}break;case"n:n":}if(_){let G=this.makeContentKey(Z,X);this.setContent(G,_)}return this.addRelation(Z,X),this}delete(Y,Z){Z=typeof Z==="string"?Z:Y[this.b];let X=typeof Y==="string"?Y:Y[this.a];if(X===void 0&&typeof Z==="string"){let _=this.getRelatedKeys(Z);if(_)for(let G of _)this.delete(G,Z)}if(typeof X==="string"&&Z===void 0){let _=this.getRelatedKeys(X);if(_)for(let G of _)this.delete(X,G)}if(typeof X==="string"&&typeof Z==="string"){this.deleteRelation(X,Z);let _=this.makeContentKey(X,Z);this.deleteContent(_)}return this}getRelatedKey(Y){let Z=this.getRelatedKeys(Y);if(Z){if(Z.size>1)this.warn?.(`${Z.size} related keys were found for key "${Y}": (${[...Z].map((_)=>`"${_}"`).join(", ")}). Only one related key was expected.`);let X;for(let _ of Z){X=_;break}return X}}replaceRelations(Y,Z,X){let _=!Array.isArray(Z),G=_?Object.keys(Z):Z;if(X?.reckless)this.replaceRelationsUnsafely(Y,G);else this.replaceRelationsSafely(Y,G);if(_)for(let W of G){let H=this.makeContentKey(Y,W),J=Z[W];this.setContent(H,J)}return this}getContent(Y,Z){let X=this.makeContentKey(Y,Z);return this.getContentInternal(X)}getRelationEntries(Y){let Z=Y[this.a],X=Y[this.b];if(Z!==void 0&&X===void 0){let _=this.getRelatedKeys(Z);if(_)return[..._].map((G)=>{return[G,this.getContent(Z,G)]})}if(Z===void 0&&X!==void 0){let _=this.getRelatedKeys(X);if(_)return[..._].map((G)=>{return[G,this.getContent(G,X)]})}return[]}has(Y,Z){if(Z)return this.getRelatedKeys(Y)?.has(Z)??!1;return this.relations.has(Y)}},J0=class{Subscriber;subscribers=new Map;subscribe(Y,Z){return this.subscribers.set(Y,Z),()=>{this.unsubscribe(Y)}}unsubscribe(Y){this.subscribers.delete(Y)}next(Y){let Z=this.subscribers.values();for(let X of Z)X(Y)}},KF=class extends J0{state;constructor(Y){super();this.state=Y}next(Y){this.state=Y,super.next(Y)}};function R4(Y){return"epoch"in Y.transactionMeta}function o0(Y){return"phase"in Y.transactionMeta}var jF=(Y)=>{let Z=i(Y);if(!o0(Z)){Y.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}Y.logger.info("\uD83E\uDE82","transaction",Z.transactionMeta.update.key,"Aborting transaction"),Z.parent.child=null};function B0(Y){return Y[0].toUpperCase()+Y.slice(1)}function f4(Y){return Y.type.split("_").map(B0).join(" ")}var k5=class extends Error{constructor(Y,Z){super(`${f4(Y)} ${z0(Y.key)} not found in store "${Z.config.name}".`)}};function j5(Y,Z,X){return(..._)=>{let G=h0(Y,Z);if(G)return G.run(_,X);throw new k5(Z,Y)}}var g5=(Y)=>(Z)=>Y instanceof Function?Y(Z):Y,VY=(Y,Z)=>{if(Y.valueMap.has(Z.key))return Y.logger.info("\uD83D\uDCD6",Z.type,Z.key,"reading cached value"),_U(Z,Y);switch(Z.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return Y.logger.info("\uD83E\uDDEE",Z.type,Z.key,"computing value"),Z.get();case"atom":case"mutable_atom":{let X=Z.default,_;if(X instanceof Function)_=X();else _=X;return Y.logger.info("\uD83D\uDC81","atom",Z.key,"could not find cached value; using default",_),_}}},LY=(Y,Z)=>{if(Y.operation.open){let X=performance.now();return Y.logger.info("\u2757",Z.type,Z.key,`deferring setState at T-${X} until setState for "${Y.operation.token.key}" is done`),X}Y.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:Z},Y.logger.info("\u2B55",Z.type,Z.key,`operation start in store "${Y.config.name}"${!o0(Y)?"":` ${Y.transactionMeta.phase} "${Y.transactionMeta.update.key}"`}`)},DY=(Y)=>{if(Y.operation.open)Y.logger.info("\uD83D\uDD34",Y.operation.token.type,Y.operation.token.key,`operation done in store "${Y.config.name}"`);Y.operation={open:!1},Y.on.operationClose.next(Y.operation)},h7=(Y,Z)=>{if(!Y.operation.open)return Y.logger.error("\uD83D\uDC1E","unknown",Z,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return Y.operation.done.has(Z)},$6=(Y,Z)=>{if(!Y.operation.open){Y.logger.error("\uD83D\uDC1E","unknown",Z,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}Y.operation.done.add(Z)},PF=(Y,Z,X)=>{switch(Z.type){case"mutable_atom":Y.logger.info("\uD83D\uDCE2",Z.type,Z.key,"is now (",X.newValue,") subscribers:",Z.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":Y.logger.info("\uD83D\uDCE2",Z.type,Z.key,"went (",X.oldValue,"->",X.newValue,") subscribers:",Z.subject.subscribers)}Z.subject.next(X)};function h5(Y,Z){let X=i(Y),_=X.selectorAtoms.getRelatedKeys(Z.key);if(X.logger.info("\uD83E\uDDF9",Z.type,Z.key,_?`evicting ${_.size} states downstream:`:"no downstream states",_??"to evict"),_){if(X.operation.open)X.logger.info("\uD83E\uDDF9",Z.type,Z.key,`[ ${[...X.operation.done].join(", ")} ] already done`);for(let G of _){if(h7(X,G))continue;l7(G,X),$6(X,G)}}}function SF(Y,Z){let X=i(Y),_=X.selectorGraph.getRelationEntries({upstreamSelectorKey:Z.key}).filter(([G,{source:W}])=>W===Z.key);for(let[G]of _){if(h7(X,G))continue;l7(G,X),$6(X,G)}}var f7=(Y,Z,X)=>{let _=VY(Y,Z),G=_;if(Z.type==="mutable_atom"&&o0(Y)){let{parent:H}=Y;G=b5(Y,Z,H)}G=g5(X)(G),Y.logger.info("\uD83D\uDCDD","atom",Z.key,"set to",G),G=o1(Y,Z.key,G,Z.subject),$6(Y,Z.key),h5(Y,Z);let W={oldValue:_,newValue:G};if(!o0(Y)){PF(Y,Z,W);return}if(Y.on.transactionApplying.state===null){let{key:H}=Z;if(XU(W.newValue))return;let J={type:"atom_update",key:H,...W};if(Z.family)J.family=Z.family;Y.transactionMeta.update.updates.push(J),Y.logger.info("\uD83D\uDCC1","atom",H,"stowed (",W.oldValue,"->",W.newValue,")")}else if(Z.key.startsWith("*")){let H=Z.key.slice(1),J=Y.atoms.get(H),Q=Y.valueMap.get(H);if(J.type==="mutable_atom"&&o0(Y)){let{parent:z}=Y;Q=b5(Y,J,z)}if(Q.do(W.newValue)===null)h5(Y,J)}};function S7(Y,Z){let X=Z.default;if(X instanceof Function)X=X();f7(Y,Z,X)}function vF(Y,Z){switch(Z.type){case"atom":case"mutable_atom":S7(Y,Z);break;case"writable_pure_selector":case"writable_held_selector":{let X=k7(Z,Y);for(let _ of X)S7(Y,_)}break}}function Q6(Y,Z,X){let _={key:Z.key,type:"atom_family"},G=Y.families.get(Z.key);if(G)Y.logger.error("\u2757","atom_family",Z.key,`Overwriting an existing ${f4(G)} "${G.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let W=new J0,J=Object.assign((Q)=>{let $=z0(Q),z={key:Z.key,subKey:$},O=`${Z.key}(${$})`,L=i(Y),V=Z.default,N={key:O,default:V instanceof Function?V(Q):V};if(Z.effects)N.effects=Z.effects(Q);let A=k4(L,N,z);return W.next({type:"state_creation",token:A}),A},_,{subject:W,install:(Q)=>Q6(Q,Z),internalRoles:X});return Y.families.set(Z.key,J),Y.defaults.set(Z.key,Z.default),_}function I7(Y,Z){if("mutable"in Z)return i5(Y,Z);return Q6(Y,Z)}var y5=(Y,Z)=>i(Y).atoms.has(Z),xF=(Y,Z)=>i(Y).writableSelectors.has(Z),hF=(Y,Z)=>i(Y).readonlySelectors.has(Z),fF=(Y,Z)=>y5(Y,Z)||xF(Y,Z)||hF(Y,Z),f5=(Y,Z)=>{return i(Y).selectorGraph.getRelationEntries({downstreamSelectorKey:Z}).filter(([_,{source:G}])=>G!==Z).map(([_,{source:G}])=>G).filter((_)=>fF(Y,_))},b7=(Y,Z,X)=>{let _=[],G=f5(Y,Z);while(G.length>0){let W=G.shift();if(X.has(W))continue;if(X.add(W),!y5(Y,W))G.push(...f5(Y,W));else if(!_.includes(W))_.push(W)}return _},k7=(Y,Z)=>{let X=Y.key,_=f5(Z,X),G=new Set;return _.flatMap((W)=>y5(Z,W)?W:b7(Z,W,G)).map((W)=>Z.atoms.get(W))},bF=(Y,Z,X,_,G)=>{let W=i(Y),{type:H,key:J}=_;if(H==="atom"||H==="mutable_atom")W.selectorAtoms.set({selectorKey:X,atomKey:J}),Y.logger.info("\uD83D\uDD0D",Z,X,`discovers root atom "${J}"`);else{let Q=b7(Y,J,G);Y.logger.info("\uD83D\uDD0D",Z,X,`discovers root atoms: [ ${Q.map(($)=>`"${$}"`).join(", ")} ]`);for(let $ of Q)W.selectorAtoms=W.selectorAtoms.set({selectorKey:X,atomKey:$})}G.add(J)},MY=(Y,Z,X,_)=>({get:(...G)=>{let W=i(Y),H;if(G.length===2){let[z,O]=G;H=H0(Y,z,O)}else[H]=G;let J=h0(Y,H),Q=VY(Y,J),$=H.key;return Y.logger.info("\uD83D\uDD0C",Z,X,`registers dependency ( "${$}" =`,Q,")"),W.selectorGraph.set({upstreamSelectorKey:$,downstreamSelectorKey:X},{source:H.key}),bF(Y,Z,X,H,_),Q},set:(...G)=>{let W,H;if(G.length===2)W=G[0],H=G[1];else{let $=G[0],z=G[1];H=G[2],W=H0(Y,$,z)}let J=i(Y),Q=h0(J,W);m7(J,Q,H)},find:(...G)=>H0(Y,...G),json:(G)=>b4(Y,G)}),p5=(Y,Z,X)=>{let _=i(Y),G=new J0,W=new Set,{key:H,const:J}=Z,Q="readonly_held_selector",{get:$,find:z,json:O}=MY(_,"readonly_held_selector",H,W),V={...Z,type:"readonly_held_selector",subject:G,install:(A)=>p5(A,Z,X),get:()=>{return Z.get({get:$,find:z,json:O},J),o1(i(Y),H,J,G),W.clear(),J},...X&&{family:X}};_.readonlySelectors.set(H,V),Y.logger.info("\u2728","readonly_held_selector",H,"=",J);let N={key:H,type:"readonly_held_selector"};if(X)N.family=X;return N},m5=(Y,Z,X)=>{let _=i(Y),G=new J0,W=new Set,H=Z.key,J="readonly_pure_selector",{get:Q,find:$,json:z}=MY(_,"readonly_pure_selector",H,W),O=()=>{let A=Z.get({get:Q,find:$,json:z});return o1(i(Y),H,A,G),W.clear(),A},L={...Z,type:"readonly_pure_selector",subject:G,install:(A)=>m5(A,Z,X),get:O,...X&&{family:X}};_.readonlySelectors.set(H,L);let V=O();Y.logger.info("\u2728","readonly_pure_selector",H,"=",V);let N={key:H,type:"readonly_pure_selector"};if(X)N.family=X;return N},u5=(Y,Z,X)=>{let _=i(Y),G=new J0,W=new Set,{key:H,const:J}=Z,Q="writable_held_selector",$=MY(_,"writable_held_selector",H,W),{find:z,get:O,json:L}=$,V={find:z,get:O,json:L},N=(g=Z.get,R=i(Y))=>{return g(V,J),o1(R,H,J,G),W.clear(),J},f={...Z,type:"writable_held_selector",subject:G,install:(g)=>u5(g,Z,X),get:N,set:(g)=>{let R=i(Y),I=N(Z.get,R),K=g5(g)(I);if(Y.logger.info("\uD83D\uDCDD","writable_held_selector",H,"set (",I,"->",K,")"),o1(R,H,K,G),$6(R,H),R4(R))G.next({newValue:K,oldValue:I});Z.set($,K)},...X&&{family:X}};_.writableSelectors.set(H,f);let b=N();Y.logger.info("\u2728","writable_held_selector",H,"=",b);let k={key:H,type:"writable_held_selector"};if(X)k.family=X;return k},d5=(Y,Z,X)=>{let _=i(Y),G=new J0,W=new Set,H=Z.key,J="writable_pure_selector",Q=MY(_,"writable_pure_selector",H,W),{find:$,get:z,json:O}=Q,L={find:$,get:z,json:O},V=(k=Z.get,g=i(Y))=>{let R=k(L);return o1(g,H,R,G),W.clear(),R},A={...Z,type:"writable_pure_selector",subject:G,install:(k)=>d5(k,Z,X),get:V,set:(k)=>{let g=i(Y),R=V(Z.get,g),I=g5(k)(R);if(Y.logger.info("\uD83D\uDCDD","writable_pure_selector",H,"set (",R,"->",I,")"),o1(g,Z.key,I,G),$6(g,Z.key),R4(g))G.next({newValue:I,oldValue:R});Z.set(Q,I)},...X&&{family:X}};_.writableSelectors.set(H,A);let f=V();Y.logger.info("\u2728",A.type,A.key,"=",f);let b={key:H,type:"writable_pure_selector"};if(X)b.family=X;return b};function C5(Y,Z){let X="set"in Z,_="const"in Z;if(_&&X){let W=u5(Y,Z,void 0);return Y.on.selectorCreation.next(W),W}if(_){let W=p5(Y,Z,void 0);return Y.on.selectorCreation.next(W),W}if(X){let W=d5(Y,Z,void 0);return Y.on.selectorCreation.next(W),W}let G=m5(Y,Z,void 0);return Y.on.selectorCreation.next(G),G}function kF(Y,Z){let X=i(Y),{key:_,type:G}=Z,W=h0(X,Z);if(!W.family)Y.logger.error("\u274C",G,_,"Standalone selectors cannot be disposed.");else{if(X.molecules.get(W.family.subKey))X.moleculeData.delete(W.family.subKey,W.family.key);let J;switch(Z.type){case"writable_held_selector":X.writableSelectors.delete(_),J={key:W.family.key,type:"writable_held_selector_family"},h0(Y,J).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"writable_pure_selector":X.writableSelectors.delete(_),J={key:W.family.key,type:"writable_pure_selector_family"},h0(Y,J).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"readonly_held_selector":X.readonlySelectors.delete(_),J={key:W.family.key,type:"readonly_held_selector_family"},h0(Y,J).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"readonly_pure_selector":X.readonlySelectors.delete(_),J={key:W.family.key,type:"readonly_pure_selector_family"},h0(Y,J).subject.next({type:"state_disposal",subType:"selector",token:Z});break}if(X.valueMap.delete(_),X.selectorAtoms.delete(_),X.selectorGraph.delete(_),Y.logger.info("\uD83D\uDD25",Z.type,_,"deleted"),o0(X)&&X.transactionMeta.phase==="building")X.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:Z});else Y.on.selectorDisposal.next(Z)}}function h4(Y,Z,X){let _=Z.key,G="readonly_pure_selector_family",W={key:_,type:"readonly_pure_selector_family"},H=Y.families.get(_);if(H)Y.logger.error("\u2757","readonly_pure_selector_family",_,`Overwriting an existing ${f4(H)} "${H.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let J=new J0,$=Object.assign((z)=>{let O=z0(z),L={key:_,subKey:O},V=`${_}(${O})`,N=i(Y),A=m5(N,{key:V,get:Z.get(z)},L);return J.next({type:"state_creation",token:A}),A},W,{internalRoles:X,subject:J,install:(z)=>h4(z,Z),default:(z)=>{return Z.get(z)({get:(...L)=>k1(Y,...L),find:(...L)=>H0(Y,...L),json:(L)=>b4(Y,L)})}});return Y.families.set(_,$),W}function g7(Y,Z,X){let _=Z.key,G="readonly_held_selector_family",W={key:_,type:"readonly_held_selector_family"},H=Y.families.get(_);if(H)Y.logger.error("\u2757","readonly_held_selector_family",_,`Overwriting an existing ${f4(H)} "${H.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let J=new J0,$=Object.assign((z)=>{let O=z0(z),L={key:_,subKey:O},V=`${_}(${O})`,N=i(Y),A=p5(N,{key:V,const:Z.const(z),get:Z.get(z)},L);return J.next({type:"state_creation",token:A}),A},W,{internalRoles:X,subject:J,install:(z)=>g7(z,Z),default:Z.const});return Y.families.set(_,$),W}function y7(Y,Z,X){let _=Z.key,G="writable_held_selector_family",W={key:_,type:"writable_held_selector_family"},H=Y.families.get(_);if(H)Y.logger.error("\u2757","writable_held_selector_family",_,`Overwriting an existing ${f4(H)} "${H.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let J=new J0,$=Object.assign((z)=>{let O=z0(z),L={key:_,subKey:O},V=`${_}(${O})`,N=i(Y),A=u5(N,{key:V,const:Z.const(z),get:Z.get(z),set:Z.set(z)},L);return J.next({type:"state_creation",token:A}),A},W,{internalRoles:X,subject:J,install:(z)=>y7(z,Z),default:Z.const});return Y.families.set(_,$),W}function FY(Y,Z,X){let _=Z.key,G="writable_pure_selector_family",W={key:_,type:"writable_pure_selector_family"},H=Y.families.get(_);if(H)Y.logger.error("\u2757","writable_pure_selector_family",_,`Overwriting an existing ${f4(H)} "${H.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let J=new J0,$=Object.assign((z)=>{let O=z0(z),L={key:_,subKey:O},V=`${_}(${O})`,N=i(Y),A=d5(N,{key:V,get:Z.get(z),set:Z.set(z)},L);return J.next({type:"state_creation",token:A}),A},W,{internalRoles:X,subject:J,install:(z)=>FY(z,Z),default:(z)=>{return Z.get(z)({get:(...L)=>k1(Y,...L),find:(...L)=>H0(Y,...L),json:(L)=>b4(Y,L)})}});return Y.families.set(_,$),W}function P5(Y,Z){let X="set"in Z,_="const"in Z;if(_&&X)return y7(Y,Z,void 0);if(_)return g7(Y,Z,void 0);if(X)return FY(Y,Z);return h4(Y,Z)}function gF(Y,Z,X){let _=Y.families.get(Z.key);if(_===void 0)throw new k5(Z,Y);let G=_(X),W=i(Y);if(G.family){if(R4(W))switch(G.type){case"atom":case"mutable_atom":Y.on.atomCreation.next(G);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":Y.on.selectorCreation.next(G);break}else if(o0(W)&&W.on.transactionApplying.state===null)W.transactionMeta.update.updates.push({type:"state_creation",token:G})}return G}function yF(Y,Z,X){let _=z0(X),G=`${Z.key}(${_})`,W=i(Y),H;switch(Z.type){case"atom_family":case"mutable_atom_family":H=W.atoms.get(G);break;case"writable_held_selector_family":case"writable_pure_selector_family":H=W.writableSelectors.get(G);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":H=W.readonlySelectors.get(G);break}if(H)return W4(H);return H}function H0(Y,Z,X){let _=yF(Y,Z,X);if(_)return _;let G=z0(X),W=Y.molecules.get(G);if(!W&&Y.config.lifespan==="immortal"){let H=qF(Z,X);return Y.logger.error("\u274C",H.type,H.key,`was not found in store "${Y.config.name}"; returned a counterfeit token.`),H}if(_=gF(Y,Z,X),W)i(Y).moleculeData.set(G,Z.key);return _}function E8(Y,...Z){let X;if(Z.length===1)X=Z[0];else{let _=Z[0],G=Z[1];X=H0(Y,_,G)}try{h0(Y,X)}catch(_){Y.logger.error("\u274C",X.type,X.key,`could not be disposed because it was not found in the store "${Y.config.name}".`);return}switch(X.type){case"atom":case"mutable_atom":i7(Y,X);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":kF(Y,X);break}}function p7(Y,Z){if(Z.family){let X=Y.families.get(Z.family.key);if(X)return X}}function EY(Y,...Z){let X,_,G;if(Z.length===1){if(X=Z[0],_=p7(Y,X)??null,_)G=X.family?G1(X.family.subKey):null,X=H0(Y,_,G)}else _=Z[0],G=Z[1],X=H0(Y,_,G);if("counterfeit"in X&&"family"in X){let J=X.family.subKey,Q=Y.disposalTraces.buffer.find(($)=>$?.key===J);Y.logger.error("\u274C",X.type,X.key,`could not be reset because it was not found in the store "${Y.config.name}".`,Q?`This state was previously disposed:
|
|
47
|
+
`)+"}");class t6{config;resolvedConfig;name;get[X1](){return"scope"}referencesById={};references=[];resolutions={};exportedNames=[];aliases={};resolved=!1;nodesByHash={};intrinsic;constructor(Y,Z){if(this.config=p8(B.config,Z),this.resolvedConfig=p8(B.resolvedConfig,Z),this.name=this.resolvedConfig.name??`anonymousScope${Object.keys(X5).length}`,this.name in X5)w(`A Scope already named ${this.name} already exists`);X5[this.name]=this;let X=Object.entries(Y).map((_)=>this.preparseOwnAliasEntry(..._));for(let[_,G]of X){let W=_;if(_[0]==="#"){if(W=_.slice(1),W in this.aliases)w(uG(W));this.aliases[W]=G}else{if(W in this.aliases)w(uG(_));this.aliases[W]=G,this.exportedNames.push(W)}if(!y(G,"module")&&!y(G,"generic")&&!O4(G)){let H=this.preparseOwnDefinitionFormat(G,{alias:W});this.resolutions[W]=y(H,"root")?this.bindReference(H):this.createParseContext(H).id}}dG??=this.node("union",{branches:["string","number","object","bigint","symbol",{unit:!0},{unit:!1},{unit:void 0},{unit:null}]},{prereduced:!0}),this.nodesByHash[dG.hash]=this.node("intersection",{},{prereduced:!0}),this.intrinsic=B.intrinsic?o(B.intrinsic,(_,G)=>_.startsWith("json")?[]:[_,this.bindReference(G)]):{}}cacheGetter(Y,Z){return Object.defineProperty(this,Y,{value:Z}),Z}get internal(){return this}_json;get json(){if(!this._json)this.export();return this._json}defineSchema(Y){return Y}generic=(...Y)=>{let Z=this;return(X,_)=>new M4(Y,_?new c6(X):X,Z,Z,_??null)};units=(Y,Z)=>{let X=[];for(let G of Y)if(!X.includes(G))X.push(G);let _=X.map((G)=>this.node("unit",{unit:G},Z));return this.node("union",_,{...Z,prereduced:!0})};lazyResolutions=[];lazilyResolve(Y,Z){let X=this.node("alias",{reference:Z??"synthetic",resolve:Y},{prereduced:!0});if(!this.resolved)this.lazyResolutions.push(X);return X}schema=(Y,Z)=>this.finalize(this.parseSchema(Y,Z));parseSchema=(Y,Z)=>this.node(c8(Y),Y,Z);preparseNode(Y,Z,X){let _=typeof Y==="string"?Y:c8(Z,Y);if(V0(Z)&&Z.kind===_)return Z;if(_==="alias"&&!X?.prereduced){let{reference:H}=s8.implementation.normalize(Z,this);if(H.startsWith("$")){let J=this.resolveRoot(H.slice(1));Z=J,_=J.kind}}else if(_==="union"&&Q1(Z,"object")){let H=SQ(Z);if(H?.length===1)Z=H[0],_=c8(Z)}if(V0(Z)&&Z.kind===_)return Z;let W=G8[_].normalize?.(Z,this)??Z;if(V0(W))return W.kind===_?W:vQ(_,W.kind);return{...X,$:this,kind:_,def:W,prefix:X.alias??_}}bindReference(Y){let Z;if(V0(Y))Z=Y.$===this?Y:new Y.constructor(Y.attachments,this);else Z=Y.$===this?Y:new M4(Y.params,Y.bodyDef,Y.$,this,Y.hkt);if(!this.resolved)Object.assign(this.referencesById,Z.referencesById);return Z}resolveRoot(Y){return this.maybeResolveRoot(Y)??w(W5(Y))}maybeResolveRoot(Y){let Z=this.maybeResolve(Y);if(y(Z,"generic"))return;return Z}maybeResolveSubalias(Y){return _5(this.aliases,Y)??_5(this.ambient,Y)}get ambient(){return B.ambient}maybeResolve(Y){let Z=this.resolutions[Y];if(Z){if(typeof Z!=="string")return this.bindReference(Z);let _=_1[Z];if(y(_,"root"))return this.resolutions[Y]=_;if(y(_,"context")){if(_.phase==="resolving")return this.node("alias",{reference:`$${Y}`},{prereduced:!0});if(_.phase==="resolved")return _0(`Unexpected resolved context for was uncached by its scope: ${n(_)}`);_.phase="resolving";let G=this.bindReference(this.parseOwnDefinitionFormat(_.def,_));return _.phase="resolved",_1[G.id]=G,_1[_.id]=G,this.resolutions[Y]=G}return _0(`Unexpected nodesById entry for ${Z}: ${n(_)}`)}let X=this.aliases[Y]??this.ambient?.[Y];if(!X)return this.maybeResolveSubalias(Y);if(X=this.normalizeRootScopeValue(X),y(X,"generic"))return this.resolutions[Y]=this.bindReference(X);if(y(X,"module")){if(!X.root)w(sG(Y));return this.resolutions[Y]=this.bindReference(X.root)}return this.resolutions[Y]=this.parse(X,{alias:Y})}createParseContext(Y){let Z=Y.id??yZ(Y.prefix);return _1[Z]=Object.assign(Y,{[X1]:"context",$:this,id:Z,phase:"unresolved"})}traversal(Y){return new f1(Y,this.resolvedConfig)}import(...Y){return new J8(o(this.export(...Y),(Z,X)=>[`#${Z}`,X]))}precompilation;_exportedResolutions;_exports;export(...Y){if(!this._exports){this._exports={};for(let X of this.exportedNames){let _=this.aliases[X];this._exports[X]=y(_,"module")?Z5(_,this):cG(this.maybeResolve(X))}for(let X of this.lazyResolutions)X.resolution;if(this._exportedResolutions=rG(this,this._exports),this._json=nG(this._exportedResolutions),Object.assign(this.resolutions,this._exportedResolutions),this.references=Object.values(this.referencesById),!this.resolvedConfig.jitless){let X=oG(this.references);this.precompilation=X.write(lG,4),iG(this.references,X)}this.resolved=!0}let Z=Y.length?Y:this.exportedNames;return new J8(o(Z,(X,_)=>[_,this._exports[_]]))}resolve(Y){return this.export()[Y]}node=(Y,Z,X={})=>{let _=this.preparseNode(Y,Z,X);if(V0(_))return this.bindReference(_);let G=this.createParseContext(_),W=pZ(G),H=this.bindReference(W);return _1[G.id]=H};parse=(Y,Z={})=>this.finalize(this.parseDefinition(Y,Z));parseDefinition(Y,Z={}){if(y(Y,"root"))return this.bindReference(Y);let X=this.preparseOwnDefinitionFormat(Y,Z);if(y(X,"root"))return this.bindReference(X);let _=this.createParseContext(X);_1[_.id]=_;let G=this.bindReference(this.parseOwnDefinitionFormat(Y,_));if(G.isCyclic)G=DG(G,_.id);return _1[_.id]=G,G}finalize(Y){if(cG(Y),!Y.precompilation&&!this.resolvedConfig.jitless)xQ(Y.references);return Y}}class G5 extends t6{parseOwnDefinitionFormat(Y,Z){return pZ(Z)}preparseOwnDefinitionFormat(Y,Z){return this.preparseNode(c8(Y),Y,Z)}preparseOwnAliasEntry(Y,Z){return[Y,Z]}normalizeRootScopeValue(Y){return Y}}var cG=(Y)=>{let Z=Y.references.filter((X)=>X.hasKind("alias"));for(let X of Z){Object.assign(X.referencesById,X.resolution.referencesById);for(let _ of Y.references)if(X.id in _.referencesById)Object.assign(_.referencesById,X.referencesById)}return Y},nG=(Y)=>o(Y,(Z,X)=>[Z,y(X,"root")||y(X,"generic")?X.json:y(X,"module")?nG(X):_0(`Unexpected resolution ${n(X)}`)]),_5=(Y,Z)=>{let X=Z.indexOf(".");if(X===-1)return;let _=Z.slice(0,X),G=Y[_];if(G===void 0)return;if(!y(G,"module"))return w(hQ(_));let W=Z.slice(X+1),H=G[W];if(H===void 0)return _5(G,W);if(y(H,"root")||y(H,"generic"))return H;if(y(H,"module"))return H.root??w(sG(Z));_0(`Unexpected resolution for alias '${Z}': ${n(H)}`)},e6=(Y,Z)=>new G5(Y,Z),e8=new G5({});var rG=(Y,Z)=>{let X={};for(let _ in Z){let G=Z[_];if(y(G,"module")){let W=rG(Y,G),H=o(W,(J,Q)=>[`${_}.${J}`,Q]);Object.assign(X,H)}else if(y(G,"root")||y(G,"generic"))X[_]=G;else _0(`Unexpected scope resolution ${n(G)}`)}return X},W5=(Y)=>`'${Y}' is unresolvable`,hQ=(Y)=>`'${Y}' must reference a module to be accessed using dot syntax`,sG=(Y)=>`Reference to submodule '${Y}' must specify an alias`;e8.export();var{schema:$0,node:$8,defineSchema:jw,generic:q1}=e8;var H5="^(?:0|[1-9]\\d*)$",fQ=new RegExp(H5),vw=q0(fQ);var aG=e6({bigint:"bigint",boolean:[{unit:!1},{unit:!0}],false:{unit:!1},never:[],null:{unit:null},number:"number",object:"object",string:"string",symbol:"symbol",true:{unit:!0},unknown:{},undefined:{unit:void 0},Array,Date},{prereducedAliases:!0}).export();B.intrinsic={...aG};var tG=e6({integer:{domain:"number",divisor:1},lengthBoundable:["string",Array],key:["string","symbol"],nonNegativeIntegerString:{domain:"string",pattern:H5}},{prereducedAliases:!0}).export();Object.assign(B.intrinsic,tG);var bQ=e6({jsonPrimitive:["string","number",{unit:!0},{unit:!1},{unit:null}],jsonObject:{domain:"object",index:{signature:"string",value:"$jsonData"}},jsonData:["$jsonPrimitive","$jsonObject"]},{prereducedAliases:!0}).export(),d={...aG,...tG,...bQ,emptyStructure:$8("structure",{},{prereduced:!0})};B.intrinsic={...d};var Y9=(Y)=>typeof Y==="string"&&Y[0]==="d"&&(Y[1]==="'"||Y[1]==='"')&&Y.at(-1)===Y[1],eG=(Y)=>Y.toString()!=="Invalid Date",Z9=(Y)=>Y.slice(2,-1),J5=(Y)=>`'${Y}' could not be parsed by the Date constructor`,X9=(Y,Z)=>kQ(Y,Z),kQ=(Y,Z)=>{let X=new Date(Y);if(eG(X))return X;let _=h_(Y);if(_!==void 0){let G=new Date(_);if(eG(G))return G}return Z?w(Z===!0?J5(Y):Z):void 0};var $5=(Y,Z)=>{let X=Y.scanner.shiftUntil(gQ[G9[Z]]);if(Y.scanner.lookahead==="")return Y.error(pQ(X,Z));if(Y.scanner.shift(),Z==="/"){try{new RegExp(X)}catch(_){w(String(_))}Y.root=Y.ctx.$.node("intersection",{domain:"string",pattern:X},{prereduced:!0})}else if(p0(Z,Q5))Y.root=Y.ctx.$.node("unit",{unit:X});else{let _=X9(X,J5(X));Y.root=Y.ctx.$.node("unit",{meta:X,unit:_})}},Q5={"'":1,'"':1},_9={"/":1,"'":1,'"':1},G9={"d'":"'",'d"':'"',"'":"'",'"':'"',"/":"/"},gQ={"'":(Y)=>Y.lookahead==="'",'"':(Y)=>Y.lookahead==='"',"/":(Y)=>Y.lookahead==="/"},yQ={'"':"double-quote","'":"single-quote","/":"forward slash"},pQ=(Y,Z)=>`${Z}${Y} requires a closing ${yQ[G9[Z]]}`;var W9=(Y)=>`Private type references should not include '#'. Use '${Y}' instead.`,YY="Optional definitions like 'string?' are only valid as properties in an object or tuple",ZY="Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple";var H9={">":!0,">=":!0},J9={"<":!0,"<=":!0};var Q8={"<":">",">":"<","<=":">=",">=":"<=","==":"=="},$9=(Y)=>`Unmatched )${Y===""?"":` before ${Y}`}`,XY=(Y)=>`Missing ${Y}`,Q9=(Y,Z)=>`Left bounds are only valid when paired with right bounds (try ...${Z}${Y})`,_Y=(Y)=>`Left-bounded expressions must specify their limits using < or <= (was ${Y})`,z9=(Y,Z,X,_)=>`An expression may have at most one left bound (parsed ${Y}${Q8[Z]}, ${X}${Q8[_]})`;var F9=(Y,Z,X)=>U9(Y,Z,X,[]),U9=(Y,Z,X,_)=>{let G=X.parseUntilFinalizer();if(_.push(G.root),G.finalizer===">"){if(_.length!==Z.params.length)return X.error(z5(Y,Z.names,_.map((W)=>W.expression)));return _}if(G.finalizer===",")return U9(Y,Z,X,_);return G.error(XY(">"))},z5=(Y,Z,X)=>`${Y}<${Z.join(", ")}> requires exactly ${Z.length} args (got ${X.length}${X.length===0?"":`: ${X.join(", ")}`})`;var F5=(Y)=>{let Z=Y.scanner.shiftUntilNextTerminator();if(Z==="keyof")Y.addPrefix("keyof");else Y.root=uQ(Y,Z)},mQ=(Y,Z,X)=>{if(X.scanner.shiftUntilNonWhitespace(),X.scanner.shift()!=="<")return X.error(z5(Y,Z.names,[]));let G=F9(Y,Z,X);return Z(...G)},uQ=(Y,Z)=>dQ(Y,Z)??cQ(Y,Z)??Y.error(Z===""?Y.scanner.lookahead==="#"?W9(Y.shiftedByOne().scanner.shiftUntilNextTerminator()):U5(Y):W5(Z)),dQ=(Y,Z)=>{if(Y.ctx.args?.[Z]){let _=Y.ctx.args[Z];if(typeof _!=="string")return _;return Y.ctx.$.node("alias",{reference:_},{prereduced:!0})}let X=Y.ctx.$.maybeResolve(Z);if(y(X,"root"))return X;if(X===void 0)return;if(y(X,"generic"))return mQ(Z,X,Y);return w(`Unexpected resolution ${n(X)}`)},cQ=(Y,Z)=>{let X=f_(Z);if(X!==void 0)return Y.ctx.$.node("unit",{unit:X});let _=k_(Z);if(_!==void 0)return Y.ctx.$.node("unit",{unit:_})},U5=(Y)=>{let Z=Y.previousOperator();return Z?O5(Z,Y.scanner.unscanned):lQ(Y.scanner.unscanned)},O5=(Y,Z="")=>`Token '${Y}' requires a right operand${Z?` before '${Z}'`:""}`,lQ=(Y)=>`Expected an expression${Y?` before '${Y}'`:""}`;var E5=(Y)=>Y.scanner.lookahead===""?Y.error(U5(Y)):Y.scanner.lookahead==="("?Y.shiftedByOne().reduceGroupOpen():Y.scanner.lookaheadIsIn(_9)?$5(Y,Y.scanner.shift()):Y.scanner.lookaheadIsIn(E4)?E5(Y.shiftedByOne()):Y.scanner.lookahead==="d"?Y.scanner.nextLookahead in Q5?$5(Y,`${Y.scanner.shift()}${Y.scanner.shift()}`):F5(Y):F5(Y);class G4 extends AZ{shiftUntilNextTerminator(){return this.shiftUntilNonWhitespace(),this.shiftUntil(()=>(this.lookahead in G4.terminatingChars))}static terminatingChars={"<":1,">":1,"=":1,"|":1,"&":1,")":1,"[":1,"%":1,",":1,":":1,"?":1,"#":1,...E4};static finalizingLookaheads={">":1,",":1,"":1,"=":1,"?":1};static lookaheadIsFinalizing=(Y,Z)=>Y===">"?Z[0]==="="?Z[1]==="=":Z.trimStart()===""||p0(Z.trimStart()[0],G4.terminatingChars):Y==="="?Z[0]!=="=":Y===","||Y==="?"}var E9=(Y,Z)=>{let X=iQ(Y,Z);if(Y.root.hasKind("unit")){if(typeof Y.root.unit==="number"){Y.reduceLeftBound(Y.root.unit,X),Y.unsetRoot();return}if(Y.root.unit instanceof Date){let _=`d'${Y.root.description??Y.root.unit.toISOString()}'`;Y.unsetRoot(),Y.reduceLeftBound(_,X);return}}return nQ(Y,X)},L9={"<":1,">":1,"=":1},iQ=(Y,Z)=>Y.scanner.lookaheadIs("=")?`${Z}${Y.scanner.shift()}`:Z;var O9=(Y,Z,X,_)=>{if(X.extends(B.intrinsic.number)){if(typeof Z!=="number")return w(L5(Y,Z,_));return Y==="=="?["min","max"]:Y[0]===">"?["min"]:["max"]}if(X.extends(B.intrinsic.lengthBoundable)){if(typeof Z!=="number")return w(L5(Y,Z,_));return Y==="=="?["exactLength"]:Y[0]===">"?["minLength"]:["maxLength"]}if(X.extends(B.intrinsic.Date))return Y==="=="?["after","before"]:Y[0]===">"?["after"]:["before"];return w(_G(X.expression))},oQ=(Y)=>({rule:Y9(Y.limit)?Z9(Y.limit):Y.limit,exclusive:Y.comparator.length===1}),nQ=(Y,Z)=>{let X=Y.unsetRoot(),_=Y.scanner.location;Y.parseOperand();let G=Y.unsetRoot(),W=Y.scanner.sliceChars(_,Y.scanner.location);if(Y.root=X,!G.hasKind("unit")||typeof G.unit!=="number"&&!(G.unit instanceof Date))return Y.error(L5(Z,W,"right"));let H=G.unit,J=Z.length===1,Q=O9(Z,typeof H==="number"?H:W,X,"right");for(let z of Q)Y.constrainRoot(z,Z==="=="?{rule:H}:{rule:H,exclusive:J});if(!Y.branches.leftBound)return;if(!p0(Z,J9))return Y.error(_Y(Z));let $=O9(Y.branches.leftBound.comparator,Y.branches.leftBound.limit,X,"left");Y.constrainRoot($[0],oQ(Y.branches.leftBound)),Y.branches.leftBound=null},L5=(Y,Z,X)=>`Comparator ${X==="left"?Q8[Y]:Y} must be ${X==="left"?"preceded":"followed"} by a corresponding literal (was ${Z})`;var D9=(Y)=>{Y.scanner.shiftUntilNonWhitespace();let Z=Y.scanner.shiftUntilNextTerminator();Y.root=Y.root.brand(Z)};var M9=(Y)=>{let Z=Y.scanner.shiftUntilNextTerminator(),X=b_(Z,{errorOnFail:V9(Z)});if(X===0)Y.error(V9(0));Y.root=Y.root.constrain("divisor",X)},V9=(Y)=>`% operator must be followed by a non-zero integer literal (was ${Y})`;var D5=(Y)=>{let Z=Y.scanner.shift();return Z===""?Y.finalize(""):Z==="["?Y.scanner.shift()==="]"?Y.setRoot(Y.root.array()):Y.error(rQ):Z==="|"?Y.scanner.lookahead===">"?Y.shiftedByOne().pushRootToBranch("|>"):Y.pushRootToBranch(Z):Z==="&"?Y.pushRootToBranch(Z):Z===")"?Y.finalizeGroup():G4.lookaheadIsFinalizing(Z,Y.scanner.unscanned)?Y.finalize(Z):p0(Z,L9)?E9(Y,Z):Z==="%"?M9(Y):Z==="#"?D9(Y):(Z in E4)?D5(Y):Y.error(GY(Z))},GY=(Y,Z="")=>`'${Y}' is not allowed here${Z&&` (should be ${Z})`}`,rQ="Missing expected ']'";var A9=(Y)=>{let Z=Y.unsetRoot();Y.parseOperand();let X=Y.unsetRoot();if(!X.hasKind("unit"))return Y.error(sQ(X.expression));let _=X.unit instanceof Date?()=>new Date(X.unit):X.unit;return[Z,"=",_]},sQ=(Y)=>`Default value '${Y}' must a literal value`;var V5=(Y,Z)=>{let X=Z.$.maybeResolveRoot(Y);if(X)return X;if(Y.endsWith("[]")){let W=Z.$.maybeResolveRoot(Y.slice(0,-2));if(W)return W.array()}let _=new z8(new G4(Y),Z),G=aQ(_);if(_.finalizer===">")w(GY(">"));return G},aQ=(Y)=>{Y.parseOperand();let Z=Y6(Y).root;if(!Z)return _0(`Root was unexpectedly unset after parsing string '${Y.scanner.scanned}'`);if(Y.finalizer==="=")Z=A9(Y);else if(Y.finalizer==="?")Z=[Z,"?"];if(Y.scanner.shiftUntilNonWhitespace(),Y.scanner.lookahead)w(GY(Y.scanner.lookahead));return Z},Y6=(Y)=>{while(Y.finalizer===void 0)tQ(Y);return Y},tQ=(Y)=>Y.hasRoot()?Y.parseOperator():Y.parseOperand();class z8{root;branches={prefixes:[],leftBound:null,intersection:null,union:null,pipe:null};finalizer;groups=[];scanner;ctx;constructor(Y,Z){this.scanner=Y,this.ctx=Z}error(Y){return w(Y)}hasRoot(){return this.root!==void 0}setRoot(Y){this.root=Y}unsetRoot(){let Y=this.root;return this.root=void 0,Y}constrainRoot(...Y){this.root=this.root.constrain(Y[0],Y[1])}finalize(Y){if(this.groups.length)return this.error(XY(")"));this.finalizeBranches(),this.finalizer=Y}reduceLeftBound(Y,Z){let X=Q8[Z];if(!p0(X,H9))return this.error(_Y(Z));if(this.branches.leftBound)return this.error(z9(this.branches.leftBound.limit,this.branches.leftBound.comparator,Y,X));this.branches.leftBound={comparator:X,limit:Y}}finalizeBranches(){if(this.assertRangeUnset(),this.branches.pipe){this.pushRootToBranch("|>"),this.root=this.branches.pipe;return}if(this.branches.union){this.pushRootToBranch("|"),this.root=this.branches.union;return}if(this.branches.intersection){this.pushRootToBranch("&"),this.root=this.branches.intersection;return}this.applyPrefixes()}finalizeGroup(){this.finalizeBranches();let Y=this.groups.pop();if(!Y)return this.error($9(this.scanner.unscanned));this.branches=Y}addPrefix(Y){this.branches.prefixes.push(Y)}applyPrefixes(){while(this.branches.prefixes.length){let Y=this.branches.prefixes.pop();this.root=Y==="keyof"?this.root.keyof():_0(`Unexpected prefix '${Y}'`)}}pushRootToBranch(Y){this.assertRangeUnset(),this.applyPrefixes();let Z=this.root;if(this.root=void 0,this.branches.intersection=this.branches.intersection?.rawAnd(Z)??Z,Y==="&")return;if(this.branches.union=this.branches.union?.rawOr(this.branches.intersection)??this.branches.intersection,this.branches.intersection=null,Y==="|")return;this.branches.pipe=this.branches.pipe?.rawPipeOnce(this.branches.union)??this.branches.union,this.branches.union=null}parseUntilFinalizer(){return Y6(new z8(this.scanner,this.ctx))}parseOperator(){return D5(this)}parseOperand(){return E5(this)}assertRangeUnset(){if(this.branches.leftBound)return this.error(Q9(this.branches.leftBound.limit,this.branches.leftBound.comparator))}reduceGroupOpen(){this.groups.push(this.branches),this.branches={prefixes:[],leftBound:null,union:null,intersection:null,pipe:null}}previousOperator(){return this.branches.leftBound?.comparator??this.branches.prefixes.at(-1)??(this.branches.intersection?"&":this.branches.union?"|":this.branches.pipe?"|>":void 0)}shiftedByOne(){return this.scanner.shift(),this}}var eQ="An empty string is not a valid generic parameter name",WY=(Y,Z,X)=>{Y.shiftUntilNonWhitespace();let _=Y.shiftUntilNextTerminator();if(_===""){if(Y.lookahead===""&&Z.length)return Z;return w(eQ)}return Y.shiftUntilNonWhitespace(),Yz(Y,_,Z,X)},w9="extends ",Yz=(Y,Z,X,_)=>{if(Y.shiftUntilNonWhitespace(),Y.unscanned.startsWith(w9))Y.jumpForward(w9.length);else{if(Y.lookahead===",")Y.shift();return X.push(Z),WY(Y,X,_)}let G=Y6(new z8(Y,_));return X.push([Z,G.root]),WY(Y,X,_)};class M5 extends h1{$;constructor(Y){super((...Z)=>new Z6(Y)(...Z),{bind:Y});this.$=Y}in(Y){return new Z6(this.$,Y===void 0?void 0:this.$.parse(Y))}at(Y,Z){return new Z6(this.$).at(Y,Z)}case(Y,Z){return new Z6(this.$).case(Y,Z)}}class Z6 extends h1{$;in;key;branches=[];constructor(Y,Z){super((X)=>this.caseEntries(Object.entries(X).map(([_,G])=>_==="default"?[_,G]:[this.$.parse(_),G])));this.$=Y,this.in=Z}at(Y,Z){if(this.key)w(Xz);if(this.branches.length)w(Zz);return this.key=Y,Z?this.match(Z):this}case(Y,Z){return this.caseEntry(this.$.parse(Y),Z)}caseEntry(Y,Z){let _=(this.key?this.$.parse({[this.key]:Y}):Y).pipe(Z);return this.branches.push(_),this}match(Y){return this(Y)}strings(Y){return this.caseEntries(Object.entries(Y).map(([Z,X])=>Z==="default"?[Z,X]:[this.$.node("unit",{unit:Z}),X]))}caseEntries(Y){for(let Z=0;Z<Y.length;Z++){let[X,_]=Y[Z];if(X==="default"){if(Z!==Y.length-1)w("default may only be specified as the last key of a switch definition");return this.default(_)}if(typeof _!=="function")return w(`Value for case "${X}" must be a function (was ${y0(_)})`);this.caseEntry(X,_)}return this}default(Y){if(typeof Y==="function")this.case(d.unknown,Y);let Z={branches:this.branches,ordered:!0};if(Y==="never"||Y==="assert")Z.meta={onFail:R9};let X=this.$.node("union",Z);if(!this.in)return this.$.finalize(X);let _=this.in.pipe(X);if(Y==="never"||Y==="assert")_=_.configureReferences({onFail:R9},"self");return this.$.finalize(_)}}var R9=(Y)=>Y.throw(),Zz="A key matcher must be specified before the first case i.e. match.at('foo') or match.in<object>().at('bar')",Xz="At most one key matcher may be specified per expression";var HY=(Y,Z)=>{if(O0(Y)){if(Y[1]==="=")return[Z.$.parseOwnDefinitionFormat(Y[0],Z),"=",Y[2]];if(Y[1]==="?")return[Z.$.parseOwnDefinitionFormat(Y[0],Z),"?"]}return JY(Y,Z)},N9="Only required keys may make their values optional, e.g. { [mySymbol]: ['number', '?'] }",I9="Only required keys may specify default values, e.g. { value: 'number = 0' }";var B9=(Y,Z)=>{let X,_={},G=j4(Y);for(let[H,J]of G){let Q=Wz(H);if(Q.kind==="spread"){if(!c1(_))return w(Gz);let V=Z.$.parseOwnDefinitionFormat(J,Z);if(V.equals(d.object))continue;if(!V.hasKind("intersection")||!V.basis?.equals(d.object))return w(Hz(V.expression));X=V.structure;continue}if(Q.kind==="undeclared"){if(J!=="reject"&&J!=="delete"&&J!=="ignore")w(_z(J));_.undeclared=J;continue}let $=HY(J,Z),z=Q;if(Q.kind==="required"){if(!O0($))A5(_,"required",{key:Q.normalized,value:$},Z);else A5(_,"optional",$[1]==="="?{key:Q.normalized,value:$[0],default:$[2]}:{key:Q.normalized,value:$[0]},Z);continue}if(O0($)){if($[1]==="?")w(N9);if($[1]==="=")w(I9)}if(Q.kind==="optional"){A5(_,"optional",{key:Q.normalized,value:$},Z);continue}let O=Z.$.parseOwnDefinitionFormat(z.normalized,Z),L=a6(O,$,Z.$);if(L.index)_.index=Z0(_.index,L.index);if(L.required)_.required=Z0(_.required,L.required)}let W=Z.$.node("structure",_);return Z.$.parseSchema({domain:"object",structure:X?.merge(W)??W})},A5=(Y,Z,X,_)=>{Y[Z]=Z0(Y[Z],_.$.node(Z,X))},_z=(Y)=>`Value of '+' key must be 'reject', 'delete', or 'ignore' (was ${n(Y)})`,Gz="Spread operator may only be used as the first key in an object",Wz=(Y)=>typeof Y==="symbol"?{kind:"required",normalized:Y}:Y.at(-1)==="?"?Y.at(-2)===x8?{kind:"required",normalized:`${Y.slice(0,-2)}?`}:{kind:"optional",normalized:Y.slice(0,-1)}:Y[0]==="["&&Y.at(-1)==="]"?{kind:"index",normalized:Y.slice(1,-1)}:Y[0]===x8&&Y[1]==="["&&Y.at(-1)==="]"?{kind:"required",normalized:Y.slice(1)}:Y==="..."?{kind:"spread"}:Y==="+"?{kind:"undeclared"}:{kind:"required",normalized:Y==="\\..."?"...":Y==="\\+"?"+":Y},Hz=(Y)=>`Spread operand must resolve to an object literal type (was ${Y})`;var C9=(Y,Z)=>Dz(Y)?P9[Y[0]](Y,Z):Ez(Y)?j9[Y[1]](Y,Z):null,Jz=(Y,Z)=>Z.$.parseOwnDefinitionFormat(Y[1],Z).keyof(),w5=(Y,Z)=>{if(Y[2]===void 0)return w(O5(Y[1],""));let X=Z.$.parseOwnDefinitionFormat(Y[0],Z),_=Z.$.parseOwnDefinitionFormat(Y[2],Z);if(Y[1]==="|")return Z.$.node("union",{branches:[X,_]});let G=Y[1]==="&"?O1(X,_,Z.$):d8(X,_,Z.$);if(G instanceof S)return G.throw();return G},$z=(Y,Z)=>Z.$.parseOwnDefinitionFormat(Y[0],Z).array(),Qz=(Y,Z)=>{if(typeof Y[2]!=="function")return w(q9("=>",Y[2]));return Z.$.parseOwnDefinitionFormat(Y[0],Z).pipe(Y[2])},q9=(Y,Z)=>`${Y===":"?"Narrow":"Morph"} expression requires a function following '${Y}' (was ${typeof Z})`,zz=(Y,Z)=>{if(typeof Y[2]!=="function")return w(q9(":",Y[2]));return Z.$.parseOwnDefinitionFormat(Y[0],Z).constrain("predicate",Y[2])},Fz=(Y,Z)=>Z.$.parseOwnDefinitionFormat(Y[0],Z).configureReferences(Y[2],"shallow"),K9=(Y)=>Y,Uz=K9({"[]":$z,"?":()=>w(YY)}),Oz=K9({"|":w5,"&":w5,":":zz,"=>":Qz,"|>":w5,"@":Fz,"=":()=>w(ZY)}),j9={...Uz,...Oz},Ez=(Y)=>j9[Y[1]]!==void 0,Lz=(Y)=>Y,P9=Lz({keyof:Jz,instanceof:(Y,Z)=>{if(typeof Y[1]!=="function")return w(T9(S8(Y[1])));let X=Y.slice(1).map((_)=>typeof _==="function"?Z.$.node("proto",{proto:_}):w(T9(S8(_))));return X.length===1?X[0]:Z.$.node("union",{branches:X})},"===":(Y,Z)=>Z.$.units(Y.slice(1))}),Dz=(Y)=>P9[Y[0]]!==void 0,T9=(Y)=>`Expected a constructor following 'instanceof' operator (was ${Y})`;var x9=(Y,Z)=>{let X=[{}],_=0;while(_<Y.length){let G=!1;if(Y[_]==="..."&&_<Y.length-1)G=!0,_++;let W=HY(Y[_],Z),[H,J,Q]=!O0(W)?[W]:W;if(_++,G){if(!H.extends(B.intrinsic.Array))return w(Az(H.expression));X=X.flatMap(($)=>H.distribute((z)=>Mz(p6($),z)))}else X=X.map(($)=>{if(J==="?")return h9($,H);if(J==="=")return Vz($,H,Q);return R5($,H)})}return Z.$.parseSchema(X.map((G)=>c1(G)?{proto:Array,exactLength:0}:{proto:Array,sequence:G}))},R5=(Y,Z)=>{if(Y.defaultables||Y.optionals)return w(Y.variadic?tZ:wz);if(Y.variadic)Y.postfix=Z0(Y.postfix,Z);else Y.prefix=Z0(Y.prefix,Z);return Y},h9=(Y,Z)=>{if(Y.variadic)return w(f9);return Y.optionals=Z0(Y.optionals,Z),Y},Vz=(Y,Z,X)=>{if(Y.variadic)return w(f9);if(Y.optionals)return w(Rz);return Y.defaultables=Z0(Y.defaultables,[[Z,X]]),Y},S9=(Y,Z)=>{if(Y.postfix)w(v9);if(Y.variadic){if(!Y.variadic.equals(Z))w(v9)}else Y.variadic=Z.internal;return Y},Mz=(Y,Z)=>{let X=Z.select({method:"find",kind:"sequence"});if(!X)return S9(Y,B.intrinsic.unknown);if(X.prefix)for(let _ of X.prefix)R5(Y,_);if(X.optionals)for(let _ of X.optionals)h9(Y,_);if(X.variadic)S9(Y,X.variadic);if(X.postfix)for(let _ of X.postfix)R5(Y,_);return Y},Az=(Y)=>`Spread element must be an array (was ${Y})`,v9="A tuple may have at most one variadic element",wz="A required element may not follow an optional element",f9="An optional element may not follow a variadic element";var Rz="A defaultable element may not follow an optional element without a default";var Nz={},JY=(Y,Z)=>{if(typeof Y==="string"){if(Z.args&&Object.keys(Z.args).some((_)=>Y.includes(_)))return V5(Y,Z);let X=Nz[Z.$.name]??={};return X[Y]??=V5(Y,Z)}return Q1(Y,"object")?Iz(Y,Z):w(N5(y0(Y)))},Iz=(Y,Z)=>{let X=P8(Y);switch(X){case void 0:if(y(Y,"root"))return Y;return B9(Y,Z);case"Array":return Bz(Y,Z);case"RegExp":return Z.$.node("intersection",{domain:"string",pattern:Y},{prereduced:!0});case"Function":{let _=O4(Y)?Y():Y;if(y(_,"root"))return _;return w(N5("Function"))}default:return w(N5(X??n(Y)))}},Bz=(Y,Z)=>C9(Y,Z)??x9(Y,Z),N5=(Y)=>`Type definitions must be strings or objects (was ${Y})`;class I5 extends h1{constructor(Y){let Z=Object.assign({errors:F1,hkt:a0,$:Y,raw:Y.parse,module:Y.constructor.module,scope:Y.constructor.scope,define:Y.define,match:Y.match,generic:Y.generic,schema:Y.schema,keywords:Y.ambient,unit:Y.unit,enumerated:Y.enumerated,instanceOf:Y.instanceOf,valueOf:Y.valueOf,or:Y.or,and:Y.and,merge:Y.merge,pipe:Y.pipe},Y.ambientAttachments);super((...X)=>{if(X.length===1)return Y.parse(X[0]);if(X.length===2&&typeof X[0]==="string"&&X[0][0]==="<"&&X[0].at(-1)===">"){let _=X[0].slice(1,-1),G=Y.parseGenericParams(_,{});return new M4(G,X[1],Y,Y,null)}return Y.parse(X)},{bind:Y,attach:Z})}}var F8=B;class $Y extends t6{get ambientAttachments(){if(!F8.typeAttachments)return;return this.cacheGetter("ambientAttachments",o(F8.typeAttachments,(Y,Z)=>[Y,this.bindReference(Z)]))}preparseOwnAliasEntry(Y,Z){let X=Y.indexOf("<");if(X===-1){if(y(Z,"module")||y(Z,"generic"))return[Y,Z];let W=this.name==="ark"?Y:Y==="root"?this.name:`${this.name}.${Y}`,H=this.resolvedConfig.keywords?.[W];if(H)Z=[Z,"@",H];return[Y,Z]}if(Y.at(-1)!==">")w("'>' must be the last character of a generic declaration in a scope");let _=Y.slice(0,X),G=Y.slice(X+1,-1);return[_,()=>{let W=this.parseGenericParams(G,{alias:_});return YG(W,Z,this)}]}parseGenericParams(Y,Z){return WY(new G4(Y),[],this.createParseContext({...Z,def:Y,prefix:"generic"}))}normalizeRootScopeValue(Y){if(O4(Y)&&!y(Y,"generic"))return Y();return Y}preparseOwnDefinitionFormat(Y,Z){return{...Z,def:Y,prefix:Z.alias??"type"}}parseOwnDefinitionFormat(Y,Z){if(!(Z.alias&&(Z.alias in this.aliases))&&!Z.args)Z.args={this:Z.id};let _=JY(Y,Z);if(O0(_)){if(_[1]==="=")return w(ZY);if(_[1]==="?")return w(YY)}return _}unit=(Y)=>this.units([Y]);valueOf=(Y)=>this.units(w_(Y));enumerated=(...Y)=>this.units(Y);instanceOf=(Y)=>this.node("proto",{proto:Y},{prereduced:!0});or=(...Y)=>this.schema(Y.map((Z)=>this.parse(Z)));and=(...Y)=>Y.reduce((Z,X)=>Z.and(this.parse(X)),this.intrinsic.unknown);merge=(...Y)=>Y.reduce((Z,X)=>Z.merge(this.parse(X)),this.intrinsic.object);pipe=(...Y)=>this.intrinsic.unknown.pipe(...Y);match=new M5(this);declare=()=>({type:this.type});define(Y){return Y}type=new I5(this);static scope=(Y,Z={})=>new $Y(Y,Z);static module=(Y,Z={})=>this.scope(Y,Z).export()}var B5=Object.assign($Y.scope,{define:(Y)=>Y}),Y0=$Y;class b9 extends a0{description='merge an object\'s properties onto another like `Merge(User, { isAdmin: "true" })`'}var Tz=q1(["base",d.object],["props",d.object])((Y)=>Y.base.merge(Y.props),b9),k9=Y0.module({Key:d.key,Merge:Tz});class g9 extends a0{}var Cz=q1("element")((Y)=>{let Z=Y.element.exclude(d.Array),X=Z.array();return Z.rawOr(X).pipe(U4).distribute((_)=>_.assertHasKind("morph").declareOut(X),$0)},g9),y9=Y0.module({root:d.Array,readonly:"root",index:d.nonNegativeIntegerString,liftFrom:Cz},{name:"Array"});var T5=$0(["string",S4.FileConstructor]),qz=T5.rawOr(T5.array()),p9=$0({meta:"an object representing parsed form data",domain:"object",index:{signature:"string",value:qz}}),m9=Y0.module({root:["instanceof",FormData],value:T5,parsed:p9,parse:$0({in:FormData,morphs:(Y)=>{let Z={};for(let[X,_]of Y)if(X in Z){let G=Z[X];if(typeof G==="string"||G instanceof S4.FileConstructor)Z[X]=[G,_];else G.push(_)}else Z[X]=_;return Z},declaredOut:p9})},{name:"FormData"});var u9=Y0.module({Int8:["instanceof",Int8Array],Uint8:["instanceof",Uint8Array],Uint8Clamped:["instanceof",Uint8ClampedArray],Int16:["instanceof",Int16Array],Uint16:["instanceof",Uint16Array],Int32:["instanceof",Int32Array],Uint32:["instanceof",Uint32Array],Float32:["instanceof",Float32Array],Float64:["instanceof",Float64Array],BigInt64:["instanceof",BigInt64Array],BigUint64:["instanceof",BigUint64Array]},{name:"TypedArray"});var Kz={Boolean:1,Number:1,String:1},d9=Y0.module({...o({...FZ,...OZ},(Y,Z)=>(Y in Kz)?[]:[Y,["instanceof",Z]]),Array:y9,TypedArray:u9,FormData:m9});var jz=$0({domain:{domain:"number",meta:"a number representing a Unix timestamp"},divisor:{rule:1,meta:"an integer representing a Unix timestamp"},min:{rule:-8640000000000000,meta:"a Unix timestamp after -8640000000000000"},max:{rule:8640000000000000,meta:"a Unix timestamp before 8640000000000000"},meta:"an integer representing a safe Unix timestamp"}),Pz=$0({domain:"number",divisor:1}),QY=Y0.module({root:d.number,integer:Pz,epoch:jz,safe:$0({domain:{domain:"number",numberAllowsNaN:!1},min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER}),NaN:["===",Number.NaN],Infinity:["===",Number.POSITIVE_INFINITY],NegativeInfinity:["===",Number.NEGATIVE_INFINITY]},{name:"number"});var I0=(Y,Z,X)=>{let _={domain:"string",pattern:{rule:Y.source,flags:Y.flags,meta:Z}};if(X)_.meta={format:X};return $8("intersection",_)},c9=I0(h8,"a well-formed integer string"),X7=Y0.module({root:c9,parse:$0({in:c9,morphs:(Y,Z)=>{let X=Number.parseInt(Y);return Number.isSafeInteger(X)?X:Z.error("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER")},declaredOut:d.integer})},{name:"string.integer"}),Sz=I0(/^[\dA-Fa-f]+$/,"hex characters only"),vz=Y0.module({root:I0(/^(?:[\d+/A-Za-z]{4})*(?:[\d+/A-Za-z]{2}==|[\d+/A-Za-z]{3}=)?$/,"base64-encoded"),url:I0(/^(?:[\w-]{4})*(?:[\w-]{2}(?:==|%3D%3D)?|[\w-]{3}(?:=|%3D)?)?$/,"base64url-encoded")},{name:"string.base64"}),l9=I0(/^[A-Z].*$/,"capitalized"),xz=Y0.module({root:$0({in:"string",morphs:(Y)=>Y.charAt(0).toUpperCase()+Y.slice(1),declaredOut:l9}),preformatted:l9},{name:"string.capitalize"}),hz=(Y)=>{let Z=Y.replaceAll(/[ -]+/g,""),X=0,_,G,W=!1;for(let H=Z.length-1;H>=0;H--){if(_=Z.substring(H,H+1),G=Number.parseInt(_,10),W)G*=2,X+=G>=10?G%10+1:G;else X+=G;W=!W}return!!(X%10===0?Z:!1)},fz=/^(?:4\d{12}(?:\d{3,6})?|5[1-5]\d{14}|(222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[01]\d|2720)\d{12}|6(?:011|5\d\d)\d{12,15}|3[47]\d{13}|3(?:0[0-5]|[68]\d)\d{11}|(?:2131|1800|35\d{3})\d{11}|6[27]\d{14}|^(81\d{14,17}))$/,bz=$0({domain:"string",pattern:{meta:"a credit card number",rule:fz.source},predicate:{meta:"a credit card number",predicate:hz}});var kz=/^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))(T((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([,.]\d+(?!:))?)?(\17[0-5]\d([,.]\d+)?)?([Zz]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;var gz=(Y)=>!Number.isNaN(new Date(Y).valueOf()),i9=$0({domain:"string",predicate:{meta:"a parsable date",predicate:gz}}).assertHasKind("intersection"),o9=X7.root.internal.narrow((Y,Z)=>{let X=Number.parseInt(Y),_=QY.epoch(X);if(_ instanceof F1)return Z.errors.merge(_),!1;return!0}).configure({description:"an integer string representing a safe Unix timestamp"},"self").assertHasKind("intersection"),yz=Y0.module({root:o9,parse:$0({in:o9,morphs:(Y)=>new Date(Y),declaredOut:d.Date})},{name:"string.date.epoch"}),n9=I0(kz,"an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection"),pz=Y0.module({root:n9,parse:$0({in:n9,morphs:(Y)=>new Date(Y),declaredOut:d.Date})},{name:"string.date.iso"}),mz=Y0.module({root:i9,parse:$0({declaredIn:i9,in:"string",morphs:(Y,Z)=>{let X=new Date(Y);if(Number.isNaN(X.valueOf()))return Z.error("a parsable date");return X},declaredOut:d.Date}),iso:pz,epoch:yz},{name:"string.date"}),uz=I0(/^[\w%+.-]+@[\d.A-Za-z-]+\.[A-Za-z]{2,}$/,"an email address","email"),r9="(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])",A4=`(${r9}[.]){3}${r9}`,dz=new RegExp(`^${A4}$`),v0="(?:[0-9a-fA-F]{1,4})",cz=new RegExp(`^((?:${v0}:){7}(?:${v0}|:)|(?:${v0}:){6}(?:${A4}|:${v0}|:)|(?:${v0}:){5}(?::${A4}|(:${v0}){1,2}|:)|(?:${v0}:){4}(?:(:${v0}){0,1}:${A4}|(:${v0}){1,3}|:)|(?:${v0}:){3}(?:(:${v0}){0,2}:${A4}|(:${v0}){1,4}|:)|(?:${v0}:){2}(?:(:${v0}){0,3}:${A4}|(:${v0}){1,5}|:)|(?:${v0}:){1}(?:(:${v0}){0,4}:${A4}|(:${v0}){1,6}|:)|(?::((?::${v0}){0,5}:${A4}|(?::${v0}){1,7}|:)))(%[0-9a-zA-Z.]{1,})?$`),lz=Y0.module({root:["v4 | v6","@","an IP address"],v4:I0(dz,"an IPv4 address","ipv4"),v6:I0(cz,"an IPv6 address","ipv6")},{name:"string.ip"}),U8="a JSON string",_7=(Y)=>{if(!(Y instanceof SyntaxError))throw Y;return`must be ${U8} (${Y})`},iz=$0({meta:U8,domain:"string",predicate:{meta:U8,predicate:(Y,Z)=>{try{return JSON.parse(Y),!0}catch(X){return Z.reject({code:"predicate",expected:U8,problem:_7(X)})}}}}),oz=(Y,Z)=>{if(Y.length===0)return Z.error({code:"predicate",expected:U8,actual:"empty"});try{return JSON.parse(Y)}catch(X){return Z.error({code:"predicate",expected:U8,problem:_7(X)})}},nz=Y0.module({root:iz,parse:$0({meta:"safe JSON string parser",in:"string",morphs:oz,declaredOut:d.jsonObject})},{name:"string.json"}),s9=I0(/^[a-z]*$/,"only lowercase letters"),rz=Y0.module({root:$0({in:"string",morphs:(Y)=>Y.toLowerCase(),declaredOut:s9}),preformatted:s9},{name:"string.lower"}),G7=["NFC","NFD","NFKC","NFKD"],X6=o(G7,(Y,Z)=>[Z,$0({domain:"string",predicate:(X)=>X.normalize(Z)===X,meta:`${Z}-normalized unicode`})]),zY=o(G7,(Y,Z)=>[Z,$0({in:"string",morphs:(X)=>X.normalize(Z),declaredOut:X6[Z]})]),sz=Y0.module({root:zY.NFC,preformatted:X6.NFC},{name:"string.normalize.NFC"}),az=Y0.module({root:zY.NFD,preformatted:X6.NFD},{name:"string.normalize.NFD"}),tz=Y0.module({root:zY.NFKC,preformatted:X6.NFKC},{name:"string.normalize.NFKC"}),ez=Y0.module({root:zY.NFKD,preformatted:X6.NFKD},{name:"string.normalize.NFKD"}),YF=Y0.module({root:"NFC",NFC:sz,NFD:az,NFKC:tz,NFKD:ez},{name:"string.normalize"}),a9=I0(k6,"a well-formed numeric string"),ZF=Y0.module({root:a9,parse:$0({in:a9,morphs:(Y)=>Number.parseFloat(Y),declaredOut:d.number})},{name:"string.numeric"}),t9="a regex pattern",XF=$0({domain:"string",predicate:{meta:t9,predicate:(Y,Z)=>{try{return new RegExp(Y),!0}catch(X){return Z.reject({code:"predicate",expected:t9,problem:String(X)})}}},meta:{format:"regex"}}),_F=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*))*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/,GF=I0(_F,"a semantic version (see https://semver.org/)"),e9=I0(/^\S.*\S$|^\S?$/,"trimmed"),WF=Y0.module({root:$0({in:"string",morphs:(Y)=>Y.trim(),declaredOut:e9}),preformatted:e9},{name:"string.trim"}),Y7=I0(/^[A-Z]*$/,"only uppercase letters"),HF=Y0.module({root:$0({in:"string",morphs:(Y)=>Y.toUpperCase(),declaredOut:Y7}),preformatted:Y7},{name:"string.upper"}),JF=(Y)=>{if(URL.canParse)return URL.canParse(Y);try{return new URL(Y),!0}catch{return!1}},Z7=$0({domain:"string",predicate:{meta:"a URL string",predicate:JF},meta:{format:"uri"}}),$F=Y0.module({root:Z7,parse:$0({declaredIn:Z7,in:"string",morphs:(Y,Z)=>{try{return new URL(Y)}catch{return Z.error("a URL string")}},declaredOut:$0(URL)})},{name:"string.url"}),QF=Y0.module({root:["versioned | nil | max","@",{description:"a UUID",format:"uuid"}],"#nil":"'00000000-0000-0000-0000-000000000000'","#max":"'ffffffff-ffff-ffff-ffff-ffffffffffff'","#versioned":/[\da-f]{8}-[\da-f]{4}-[1-8][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}/i,v1:I0(/^[\da-f]{8}-[\da-f]{4}-1[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv1"),v2:I0(/^[\da-f]{8}-[\da-f]{4}-2[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv2"),v3:I0(/^[\da-f]{8}-[\da-f]{4}-3[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv3"),v4:I0(/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv4"),v5:I0(/^[\da-f]{8}-[\da-f]{4}-5[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv5"),v6:I0(/^[\da-f]{8}-[\da-f]{4}-6[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv6"),v7:I0(/^[\da-f]{8}-[\da-f]{4}-7[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv7"),v8:I0(/^[\da-f]{8}-[\da-f]{4}-8[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i,"a UUIDv8")},{name:"string.uuid"}),W7=Y0.module({root:d.string,alpha:I0(/^[A-Za-z]*$/,"only letters"),alphanumeric:I0(/^[\dA-Za-z]*$/,"only letters and digits 0-9"),hex:Sz,base64:vz,capitalize:xz,creditCard:bz,date:mz,digits:I0(/^\d*$/,"only digits 0-9"),email:uz,integer:X7,ip:lz,json:nz,lower:rz,normalize:YF,numeric:ZF,regex:XF,semver:GF,trim:WF,upper:HF,url:$F,uuid:QF},{name:"string"});var H7=Y0.module({bigint:d.bigint,boolean:d.boolean,false:d.false,never:d.never,null:d.null,number:d.number,object:d.object,string:d.string,symbol:d.symbol,true:d.true,unknown:d.unknown,undefined:d.undefined}),J7=Y0.module({root:d.unknown,any:d.unknown},{name:"unknown"}),zF=Y0.module({root:d.jsonObject,stringify:$8("morph",{in:d.jsonObject,morphs:(Y)=>JSON.stringify(Y),declaredOut:d.string})},{name:"object.json"}),$7=Y0.module({root:d.object,json:zF},{name:"object"});class Q7 extends a0{description='instantiate an object from an index signature and corresponding value type like `Record("string", "number")`'}var FF=q1(["K",d.key],"V")((Y)=>({domain:"object",index:{signature:Y.K,value:Y.V}}),Q7);class z7 extends a0{description='pick a set of properties from an object like `Pick(User, "name | age")`'}var UF=q1(["T",d.object],["K",d.key])((Y)=>Y.T.pick(Y.K),z7);class F7 extends a0{description='omit a set of properties from an object like `Omit(User, "age")`'}var OF=q1(["T",d.object],["K",d.key])((Y)=>Y.T.omit(Y.K),F7);class U7 extends a0{description="make all named properties of an object optional like `Partial(User)`"}var EF=q1(["T",d.object])((Y)=>Y.T.partial(),U7);class O7 extends a0{description="make all named properties of an object required like `Required(User)`"}var LF=q1(["T",d.object])((Y)=>Y.T.required(),O7);class E7 extends a0{description='exclude branches of a union like `Exclude("boolean", "true")`'}var DF=q1("T","U")((Y)=>Y.T.exclude(Y.U),E7);class L7 extends a0{description='extract branches of a union like `Extract("0 | false | 1", "number")`'}var VF=q1("T","U")((Y)=>Y.T.extract(Y.U),L7),D7=Y0.module({Exclude:DF,Extract:VF,Omit:OF,Partial:EF,Pick:UF,Record:FF,Required:LF});var w4=B5({...H7,...D7,...d9,...k9,string:W7,number:QY,object:$7,unknown:J7},{prereducedAliases:!0,name:"ark"}),m0=w4.export();Object.assign(F8.ambient,m0);F8.typeAttachments={string:m0.string.root,number:m0.number.root,bigint:m0.bigint,boolean:m0.boolean,symbol:m0.symbol,undefined:m0.undefined,null:m0.null,object:m0.object.root,unknown:m0.unknown.root,false:m0.false,true:m0.true,never:m0.never,arrayIndex:m0.Array.index,Key:m0.Key,Record:m0.Record,Array:m0.Array.root,Date:m0.Date};var E1=Object.assign(w4.type,F8.typeAttachments),MF=w4.match,AF=w4.generic,YB=w4.schema,wF=w4.define,RF=w4.declare;var V7=(Y,Z,X=x0.STORE)=>{return C5(X,{key:`${Y.key}:JSON`,get:({get:_})=>Z.toJson(_(Y)),set:({set:_},G)=>{_(Y,Z.fromJson(G))}})};function M7(Y,Z,X){return FY(Y,{key:`${Z.key}:JSON`,get:(G)=>({get:W})=>{let H=W(Z,G);return X.toJson(H)},set:(G)=>({set:W},H)=>{W(Z,G,X.fromJson(H))}},["mutable","json"])}var G1=(Y)=>JSON.parse(Y),z0=(Y)=>JSON.stringify(Y),VB=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];function O8(Y){return q7(x0.STORE,Y)}function _6(Y){return I7(x0.STORE,Y)}function K5(...Y){if(Y.length===2)return k1(x0.STORE,...Y);return k1(x0.STORE,...Y)}function UY(Y,Z,X=x0.STORE){return X.joins.set(Y.key,new v5(Y,Z,X)),{key:Y.key,type:"join",a:Y.between[0],b:Y.between[1],cardinality:Y.cardinality}}function A7(Y){return j7(Y,x0.STORE)}var q5=(Y)=>(Z,X,_,G,...W)=>{console[Y](`${Z} ${X} "${_}" ${G}`,...W)},NF={error:q5("error"),info:q5("info"),warn:q5("warn")},w7=class{logLevel;filter;logger;constructor(Y,Z,X=NF){this.logLevel=Y,this.filter=Z,this.logger=X}error=(...Y)=>{let Z=this.filter?.(...Y)??!0;if(this.logLevel!==null){if(Z===!0)this.logger.error(...Y);else if(Z!==!1)this.logger.error(...Z)}};info=(...Y)=>{let Z=this.filter?.(...Y)??!0;if(this.logLevel==="info"){if(Z===!0)this.logger.info(...Y);else if(Z!==!1)this.logger.info(...Z)}};warn=(...Y)=>{let Z=this.filter?.(...Y)??!0;if(this.logLevel!=="error"&&this.logLevel!==null){if(Z===!0)this.logger.warn(...Y);else if(Z!==!1)this.logger.warn(...Z)}}};var IF=class{store;constructor(Y=x0.STORE){this.store=Y,B7("root",Y)}allocate(Y,Z,X){return L8(this.store,Y,Z,X)}fuse(Y,Z,X){return T7(this.store,Y,Z,X)}deallocate(Y){D8(this.store,Y)}claim(Y,Z,X){return W6(this.store,Y,Z,X)}},R7=class{store;realm;constructor(Y=x0.STORE){this.store=Y,this.realm=new IF(Y)}allocate(Y,Z,X){L8(this.store,Y,Z,X)}deallocate(Y){D8(this.store,Y)}claim(Y,Z,X){W6(this.store,Y,Z,X)}};function OY(Y){return P5(x0.STORE,Y)}function G6(Y){return S5(x0.STORE,Y)}var L1=class Y extends Set{mode="record";subject=new J0;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(Z,X=0){super(Z);if(Z instanceof Y)this.parent=Z,this.cacheUpdateNumber=Z.cacheUpdateNumber;if(X)this.cacheLimit=X,this.cache=new Array(X),this.subscribe("auto cache",(_)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=_})}toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(Z){let X=new Y(Z.members,Z.cacheLimit);return X.cache=Z.cache,X.cacheIdx=Z.cacheIdx,X.cacheUpdateNumber=Z.cacheUpdateNumber,X}add(Z){let X=super.add(Z);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${z0(Z)}`);return X}clear(){let Z=this.mode==="record"?[...this]:null;if(super.clear(),Z)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(Z)}`)}delete(Z){let X=super.delete(Z);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${z0(Z)}`);return X}parent=null;child=null;transactionUpdates=null;transaction(Z){this.mode="transaction",this.transactionUpdates=[],this.child=new Y(this);let X=this.child._subscribe("transaction",(_)=>{this.transactionUpdates?.push(_)});try{if(Z(this.child)){for(let G of this.transactionUpdates)this.doStep(G);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(_){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",_),_}finally{X(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(Z,X){return this.subject.subscribe(Z,X)}subscribe(Z,X){return this.subject.subscribe(Z,(_)=>{X(`${this.cacheUpdateNumber}=${_}`)})}emit(Z){this.subject.next(Z)}doStep(Z){let X=Z.indexOf(":"),_=Z.substring(0,X),G=Z.substring(X+1);switch(_){case"add":this.add(JSON.parse(G));break;case"clear":this.clear();break;case"del":this.delete(JSON.parse(G));break;case"tx":for(let W of G.split(";"))this.doStep(W)}}getUpdateNumber(Z){let X=Z.indexOf("=");return Number(Z.substring(0,X))}do(Z){let X=Z.indexOf("="),_=Number(Z.substring(0,X)),G=_-this.cacheUpdateNumber;if(G>0){if(G===1){this.mode="playback";let H=Z.substring(X+1);return this.doStep(H),this.mode="record",this.cacheUpdateNumber=_,null}return this.cacheUpdateNumber+1}if(Math.abs(G)<this.cacheLimit){let H=this.cacheIdx+G;if(this.cache[H]===Z)return null;this.mode="playback";let Q=!1;while(!Q){this.cacheIdx%=this.cacheLimit;let z=this.cache[this.cacheIdx];if(this.cacheIdx--,!z)return"OUT_OF_RANGE";this.undo(z),Q=this.cacheIdx===H-1}let $=Z.substring(X+1);return this.doStep($),this.mode="record",this.cacheUpdateNumber=_,null}return"OUT_OF_RANGE"}undoStep(Z){let X=Z.indexOf(":"),_=Z.substring(0,X),G=Z.substring(X+1);switch(_){case"add":this.delete(JSON.parse(G));break;case"del":this.add(JSON.parse(G));break;case"clear":{let W=JSON.parse(G);for(let H of W)this.add(H);break}case"tx":{let W=G.split(";");for(let H=W.length-1;H>=0;H--)this.undoStep(W[H])}}}undo(Z){let X=Z.indexOf("=");if(Number(Z.substring(0,X))===this.cacheUpdateNumber){this.mode="playback";let G=Z.substring(X+1);return this.undoStep(G),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function N7(Y=Math.random){return Y().toString(36).slice(2)}var x5=class extends Promise{fate;resolve;reject;done=!1;constructor(Y){let Z,X;super((_,G)=>{Z=_,X=G});this.resolve=Z,this.reject=X,this.use(Y instanceof Promise?Y:new Promise(Y))}pass(Y,Z){if(Y===this.fate)this.resolve(Z),this.done=!0}fail(Y,Z){if(Y===this.fate)this.reject(Z),this.done=!0}use(Y){if(Y instanceof Promise){let Z=Y;this.fate=Z,Z.then((X)=>{this.pass(Z,X)},(X)=>{this.fail(Z,X)})}else this.resolve(Y),this.fate=void 0}};function i(Y){while(Y.child!==null)Y=Y.child;return Y}var TF=class Y{_buffer;_index=0;constructor(Z){let X;if(typeof Z==="number")X=Z;else X=Z.length;this._buffer=Array.from({length:X})}get buffer(){return this._buffer}get index(){return this._index}add(Z){this._buffer[this._index]=Z,this._index=(this._index+1)%this._buffer.length}copy(){let Z=new Y([...this._buffer]);return Z._index=this._index,Z}},CF={atom_family:"atom",molecule_family:"molecule",mutable_atom_family:"mutable_atom",readonly_held_selector_family:"readonly_held_selector",readonly_pure_selector_family:"readonly_pure_selector",writable_held_selector_family:"writable_held_selector",writable_pure_selector_family:"writable_pure_selector"};function qF(Y,Z){let X=z0(Z),_=`${Y.key}(${X})`,G=CF[Y.type],W={key:_,type:G};return Object.assign(W,{family:{key:Y.key,subKey:X}}),Object.assign(W,{counterfeit:!0}),W}function W4(Y){let Z={key:Y.key,type:Y.type};if("family"in Y)Z.family=Y.family;return Z}var W1=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(Y,Z)=>`${Y}:${Z}`;warn;getRelatedKeys(Y){return this.relations.get(Y)}addRelation(Y,Z){let X=this.relations.get(Y),_=this.relations.get(Z);if(X)X.add(Z);else X=new Set([Z]),this.relations.set(Y,X);if(_)_.add(Y);else _=new Set([Y]),this.relations.set(Z,_)}deleteRelation(Y,Z){let X=this.relations.get(Y);if(X){if(X.delete(Z),X.size===0)this.relations.delete(Y);let _=this.relations.get(Z);if(_){if(_.delete(Y),_.size===0)this.relations.delete(Z)}}}replaceRelationsUnsafely(Y,Z){this.relations.set(Y,new Set(Z));for(let X of Z){let _=new Set().add(Y);this.relations.set(X,_)}}replaceRelationsSafely(Y,Z){let X=this.relations.get(Y),_=this.isAType?.(Y)?Y:void 0,G=_===void 0?Y:void 0;if(X)for(let W of X){_??=W,G??=W;let H=this.relations.get(W);if(H){if(H.size===1)this.relations.delete(W);else H.delete(Y);this.contents.delete(this.makeContentKey(_,G))}}this.relations.set(Y,new Set(Z));for(let W of Z){let H=this.relations.get(W);if(H)H.add(Y);else H=new Set().add(Y),this.relations.set(W,H)}}getContentInternal(Y){return this.contents.get(Y)}setContent(Y,Z){this.contents.set(Y,Z)}deleteContent(Y){this.contents.delete(Y)}constructor(Y,Z){if(this.a=Y.between[0],this.b=Y.between[1],this.cardinality=Y.cardinality,!Z?.externalStore)this.relations=new Map(Y.relations?.map(([X,_])=>[X,new Set(_)])),this.contents=new Map(Y.contents);if(this.isAType=Z?.isAType??null,this.isBType=Z?.isBType??null,this.isContent=Z?.isContent??null,Z?.makeContentKey)this.makeContentKey=Z.makeContentKey;if(Z?.externalStore){let X=Z.externalStore;if(this.has=(_,G)=>X.has(_,G),this.addRelation=(_,G)=>{X.addRelation(_,G)},this.deleteRelation=(_,G)=>{X.deleteRelation(_,G)},this.replaceRelationsSafely=(_,G)=>{X.replaceRelationsSafely(_,G)},this.replaceRelationsUnsafely=(_,G)=>{X.replaceRelationsUnsafely(_,G)},this.getRelatedKeys=(_)=>X.getRelatedKeys(_),X.getContent)this.getContentInternal=(_)=>{return X.getContent(_)},this.setContent=(_,G)=>{X.setContent(_,G)},this.deleteContent=(_)=>{X.deleteContent(_)};for(let[_,G]of Y.relations??[]){let W=this.isAType?.(_)?_:void 0,H=W===void 0?_:void 0;for(let J of G)W??=J,H??=J,this.addRelation(W,H)}for(let[_,G]of Y.contents??[])this.setContent(_,G)}if(Z?.warn)this.warn=Z.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([Y,Z])=>[Y,[...Z]]),contents:[...this.contents.entries()]}}set(...Y){let Z,X,_;switch(Y.length){case 1:{let G=Y[0];Z=G[this.a],X=G[this.b],_=void 0;break}case 2:{let G=Y[0];if(typeof G==="string")[Z,X]=Y;else Z=G[this.a],X=G[this.b],_=Y[1];break}default:{Z=Y[0],X=Y[1],_=Y[2];break}}switch(this.cardinality){case"1:1":{let G=this.getRelatedKey(Z);if(G&&G!==X)this.delete(Z,G)}case"1:n":{let G=this.getRelatedKey(X);if(G&&G!==Z)this.delete(G,X)}break;case"n:n":}if(_){let G=this.makeContentKey(Z,X);this.setContent(G,_)}return this.addRelation(Z,X),this}delete(Y,Z){Z=typeof Z==="string"?Z:Y[this.b];let X=typeof Y==="string"?Y:Y[this.a];if(X===void 0&&typeof Z==="string"){let _=this.getRelatedKeys(Z);if(_)for(let G of _)this.delete(G,Z)}if(typeof X==="string"&&Z===void 0){let _=this.getRelatedKeys(X);if(_)for(let G of _)this.delete(X,G)}if(typeof X==="string"&&typeof Z==="string"){this.deleteRelation(X,Z);let _=this.makeContentKey(X,Z);this.deleteContent(_)}return this}getRelatedKey(Y){let Z=this.getRelatedKeys(Y);if(Z){if(Z.size>1)this.warn?.(`${Z.size} related keys were found for key "${Y}": (${[...Z].map((_)=>`"${_}"`).join(", ")}). Only one related key was expected.`);let X;for(let _ of Z){X=_;break}return X}}replaceRelations(Y,Z,X){let _=!Array.isArray(Z),G=_?Object.keys(Z):Z;if(X?.reckless)this.replaceRelationsUnsafely(Y,G);else this.replaceRelationsSafely(Y,G);if(_)for(let W of G){let H=this.makeContentKey(Y,W),J=Z[W];this.setContent(H,J)}return this}getContent(Y,Z){let X=this.makeContentKey(Y,Z);return this.getContentInternal(X)}getRelationEntries(Y){let Z=Y[this.a],X=Y[this.b];if(Z!==void 0&&X===void 0){let _=this.getRelatedKeys(Z);if(_)return[..._].map((G)=>{return[G,this.getContent(Z,G)]})}if(Z===void 0&&X!==void 0){let _=this.getRelatedKeys(X);if(_)return[..._].map((G)=>{return[G,this.getContent(G,X)]})}return[]}has(Y,Z){if(Z)return this.getRelatedKeys(Y)?.has(Z)??!1;return this.relations.has(Y)}},J0=class{Subscriber;subscribers=new Map;subscribe(Y,Z){return this.subscribers.set(Y,Z),()=>{this.unsubscribe(Y)}}unsubscribe(Y){this.subscribers.delete(Y)}next(Y){let Z=this.subscribers.values();for(let X of Z)X(Y)}},KF=class extends J0{state;constructor(Y){super();this.state=Y}next(Y){this.state=Y,super.next(Y)}};function R4(Y){return"epoch"in Y.transactionMeta}function o0(Y){return"phase"in Y.transactionMeta}var jF=(Y)=>{let Z=i(Y);if(!o0(Z)){Y.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}Y.logger.info("\uD83E\uDE82","transaction",Z.transactionMeta.update.key,"Aborting transaction"),Z.parent.child=null};function B0(Y){return Y[0].toUpperCase()+Y.slice(1)}function f4(Y){return Y.type.split("_").map(B0).join(" ")}var k5=class extends Error{constructor(Y,Z){super(`${f4(Y)} ${z0(Y.key)} not found in store "${Z.config.name}".`)}};function j5(Y,Z,X){return(..._)=>{let G=h0(Y,Z);if(G)return G.run(_,X);throw new k5(Z,Y)}}var g5=(Y)=>(Z)=>Y instanceof Function?Y(Z):Y,VY=(Y,Z)=>{if(Y.valueMap.has(Z.key))return Y.logger.info("\uD83D\uDCD6",Z.type,Z.key,"reading cached value"),_U(Z,Y);switch(Z.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return Y.logger.info("\uD83E\uDDEE",Z.type,Z.key,"computing value"),Z.get();case"atom":case"mutable_atom":{let X=Z.default,_;if(X instanceof Function)_=X();else _=X;return Y.logger.info("\uD83D\uDC81","atom",Z.key,"could not find cached value; using default",_),_}}},LY=(Y,Z)=>{if(Y.operation.open){let X=performance.now();return Y.logger.info("\u2757",Z.type,Z.key,`deferring setState at T-${X} until setState for "${Y.operation.token.key}" is done`),X}Y.operation={open:!0,done:new Set,prev:new Map,time:Date.now(),token:Z},Y.logger.info("\u2B55",Z.type,Z.key,`operation start in store "${Y.config.name}"${!o0(Y)?"":` ${Y.transactionMeta.phase} "${Y.transactionMeta.update.key}"`}`)},DY=(Y)=>{if(Y.operation.open)Y.logger.info("\uD83D\uDD34",Y.operation.token.type,Y.operation.token.key,`operation done in store "${Y.config.name}"`);Y.operation={open:!1},Y.on.operationClose.next(Y.operation)},h7=(Y,Z)=>{if(!Y.operation.open)return Y.logger.error("\uD83D\uDC1E","unknown",Z,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return Y.operation.done.has(Z)},$6=(Y,Z)=>{if(!Y.operation.open){Y.logger.error("\uD83D\uDC1E","unknown",Z,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}Y.operation.done.add(Z)},PF=(Y,Z,X)=>{switch(Z.type){case"mutable_atom":Y.logger.info("\uD83D\uDCE2",Z.type,Z.key,"is now (",X.newValue,") subscribers:",Z.subject.subscribers);break;case"atom":case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":Y.logger.info("\uD83D\uDCE2",Z.type,Z.key,"went (",X.oldValue,"->",X.newValue,") subscribers:",Z.subject.subscribers)}Z.subject.next(X)};function h5(Y,Z){let X=i(Y),_=X.selectorAtoms.getRelatedKeys(Z.key);if(X.logger.info("\uD83E\uDDF9",Z.type,Z.key,_?`evicting ${_.size} states downstream:`:"no downstream states",_??"to evict"),_){if(X.operation.open)X.logger.info("\uD83E\uDDF9",Z.type,Z.key,`[ ${[...X.operation.done].join(", ")} ] already done`);for(let G of _){if(h7(X,G))continue;l7(G,X),$6(X,G)}}}function SF(Y,Z){let X=i(Y),_=X.selectorGraph.getRelationEntries({upstreamSelectorKey:Z.key}).filter(([G,{source:W}])=>W===Z.key);for(let[G]of _){if(h7(X,G))continue;l7(G,X),$6(X,G)}}var f7=(Y,Z,X)=>{let _=VY(Y,Z),G=_;if(Z.type==="mutable_atom"&&o0(Y)){let{parent:H}=Y;G=b5(Y,Z,H)}G=g5(X)(G),Y.logger.info("\uD83D\uDCDD","atom",Z.key,"set to",G),G=o1(Y,Z.key,G,Z.subject),$6(Y,Z.key),h5(Y,Z);let W={oldValue:_,newValue:G};if(!o0(Y)){PF(Y,Z,W);return}if(Y.on.transactionApplying.state===null){let{key:H}=Z;if(XU(W.newValue))return;let J={type:"atom_update",key:H,...W};if(Z.family)J.family=Z.family;Y.transactionMeta.update.updates.push(J),Y.logger.info("\uD83D\uDCC1","atom",H,"stowed (",W.oldValue,"->",W.newValue,")")}else if(Z.key.startsWith("*")){let H=Z.key.slice(1),J=Y.atoms.get(H),Q=Y.valueMap.get(H);if(J.type==="mutable_atom"&&o0(Y)){let{parent:z}=Y;Q=b5(Y,J,z)}if(Q.do(W.newValue)===null)h5(Y,J)}};function S7(Y,Z){let X=Z.default;if(X instanceof Function)X=X();f7(Y,Z,X)}function vF(Y,Z){switch(Z.type){case"atom":case"mutable_atom":S7(Y,Z);break;case"writable_pure_selector":case"writable_held_selector":{let X=k7(Z,Y);for(let _ of X)S7(Y,_)}break}}function Q6(Y,Z,X){let _={key:Z.key,type:"atom_family"},G=Y.families.get(Z.key);if(G)Y.logger.error("\u2757","atom_family",Z.key,`Overwriting an existing ${f4(G)} "${G.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let W=new J0,J=Object.assign((Q)=>{let $=z0(Q),z={key:Z.key,subKey:$},O=`${Z.key}(${$})`,L=i(Y),V=Z.default,N={key:O,default:V instanceof Function?()=>V(Q):V};if(Z.effects)N.effects=Z.effects(Q);let A=k4(L,N,z);return W.next({type:"state_creation",token:A}),A},_,{subject:W,install:(Q)=>Q6(Q,Z),internalRoles:X});return Y.families.set(Z.key,J),Y.defaults.set(Z.key,Z.default),_}function I7(Y,Z){if("mutable"in Z)return i5(Y,Z);return Q6(Y,Z)}var y5=(Y,Z)=>i(Y).atoms.has(Z),xF=(Y,Z)=>i(Y).writableSelectors.has(Z),hF=(Y,Z)=>i(Y).readonlySelectors.has(Z),fF=(Y,Z)=>y5(Y,Z)||xF(Y,Z)||hF(Y,Z),f5=(Y,Z)=>{return i(Y).selectorGraph.getRelationEntries({downstreamSelectorKey:Z}).filter(([_,{source:G}])=>G!==Z).map(([_,{source:G}])=>G).filter((_)=>fF(Y,_))},b7=(Y,Z,X)=>{let _=[],G=f5(Y,Z);while(G.length>0){let W=G.shift();if(X.has(W))continue;if(X.add(W),!y5(Y,W))G.push(...f5(Y,W));else if(!_.includes(W))_.push(W)}return _},k7=(Y,Z)=>{let X=Y.key,_=f5(Z,X),G=new Set;return _.flatMap((W)=>y5(Z,W)?W:b7(Z,W,G)).map((W)=>Z.atoms.get(W))},bF=(Y,Z,X,_,G)=>{let W=i(Y),{type:H,key:J}=_;if(H==="atom"||H==="mutable_atom")W.selectorAtoms.set({selectorKey:X,atomKey:J}),Y.logger.info("\uD83D\uDD0D",Z,X,`discovers root atom "${J}"`);else{let Q=b7(Y,J,G);Y.logger.info("\uD83D\uDD0D",Z,X,`discovers root atoms: [ ${Q.map(($)=>`"${$}"`).join(", ")} ]`);for(let $ of Q)W.selectorAtoms=W.selectorAtoms.set({selectorKey:X,atomKey:$})}G.add(J)},MY=(Y,Z,X,_)=>({get:(...G)=>{let W=i(Y),H;if(G.length===2){let[z,O]=G;H=H0(Y,z,O)}else[H]=G;let J=h0(Y,H),Q=VY(Y,J),$=H.key;return Y.logger.info("\uD83D\uDD0C",Z,X,`registers dependency ( "${$}" =`,Q,")"),W.selectorGraph.set({upstreamSelectorKey:$,downstreamSelectorKey:X},{source:H.key}),bF(Y,Z,X,H,_),Q},set:(...G)=>{let W,H;if(G.length===2)W=G[0],H=G[1];else{let $=G[0],z=G[1];H=G[2],W=H0(Y,$,z)}let J=i(Y),Q=h0(J,W);m7(J,Q,H)},find:(...G)=>H0(Y,...G),json:(G)=>b4(Y,G)}),p5=(Y,Z,X)=>{let _=i(Y),G=new J0,W=new Set,{key:H,const:J}=Z,Q="readonly_held_selector",{get:$,find:z,json:O}=MY(_,"readonly_held_selector",H,W),V={...Z,type:"readonly_held_selector",subject:G,install:(A)=>p5(A,Z,X),get:()=>{return Z.get({get:$,find:z,json:O},J),o1(i(Y),H,J,G),W.clear(),J},...X&&{family:X}};_.readonlySelectors.set(H,V),Y.logger.info("\u2728","readonly_held_selector",H,"=",J);let N={key:H,type:"readonly_held_selector"};if(X)N.family=X;return N},m5=(Y,Z,X)=>{let _=i(Y),G=new J0,W=new Set,H=Z.key,J="readonly_pure_selector",{get:Q,find:$,json:z}=MY(_,"readonly_pure_selector",H,W),O=()=>{let A=Z.get({get:Q,find:$,json:z});return o1(i(Y),H,A,G),W.clear(),A},L={...Z,type:"readonly_pure_selector",subject:G,install:(A)=>m5(A,Z,X),get:O,...X&&{family:X}};_.readonlySelectors.set(H,L);let V=O();Y.logger.info("\u2728","readonly_pure_selector",H,"=",V);let N={key:H,type:"readonly_pure_selector"};if(X)N.family=X;return N},u5=(Y,Z,X)=>{let _=i(Y),G=new J0,W=new Set,{key:H,const:J}=Z,Q="writable_held_selector",$=MY(_,"writable_held_selector",H,W),{find:z,get:O,json:L}=$,V={find:z,get:O,json:L},N=(g=Z.get,R=i(Y))=>{return g(V,J),o1(R,H,J,G),W.clear(),J},f={...Z,type:"writable_held_selector",subject:G,install:(g)=>u5(g,Z,X),get:N,set:(g)=>{let R=i(Y),I=N(Z.get,R),K=g5(g)(I);if(Y.logger.info("\uD83D\uDCDD","writable_held_selector",H,"set (",I,"->",K,")"),o1(R,H,K,G),$6(R,H),R4(R))G.next({newValue:K,oldValue:I});Z.set($,K)},...X&&{family:X}};_.writableSelectors.set(H,f);let b=N();Y.logger.info("\u2728","writable_held_selector",H,"=",b);let k={key:H,type:"writable_held_selector"};if(X)k.family=X;return k},d5=(Y,Z,X)=>{let _=i(Y),G=new J0,W=new Set,H=Z.key,J="writable_pure_selector",Q=MY(_,"writable_pure_selector",H,W),{find:$,get:z,json:O}=Q,L={find:$,get:z,json:O},V=(k=Z.get,g=i(Y))=>{let R=k(L);return o1(g,H,R,G),W.clear(),R},A={...Z,type:"writable_pure_selector",subject:G,install:(k)=>d5(k,Z,X),get:V,set:(k)=>{let g=i(Y),R=V(Z.get,g),I=g5(k)(R);if(Y.logger.info("\uD83D\uDCDD","writable_pure_selector",H,"set (",R,"->",I,")"),o1(g,Z.key,I,G),$6(g,Z.key),R4(g))G.next({newValue:I,oldValue:R});Z.set(Q,I)},...X&&{family:X}};_.writableSelectors.set(H,A);let f=V();Y.logger.info("\u2728",A.type,A.key,"=",f);let b={key:H,type:"writable_pure_selector"};if(X)b.family=X;return b};function C5(Y,Z){let X="set"in Z,_="const"in Z;if(_&&X){let W=u5(Y,Z,void 0);return Y.on.selectorCreation.next(W),W}if(_){let W=p5(Y,Z,void 0);return Y.on.selectorCreation.next(W),W}if(X){let W=d5(Y,Z,void 0);return Y.on.selectorCreation.next(W),W}let G=m5(Y,Z,void 0);return Y.on.selectorCreation.next(G),G}function kF(Y,Z){let X=i(Y),{key:_,type:G}=Z,W=h0(X,Z);if(!W.family)Y.logger.error("\u274C",G,_,"Standalone selectors cannot be disposed.");else{if(X.molecules.get(W.family.subKey))X.moleculeData.delete(W.family.subKey,W.family.key);let J;switch(Z.type){case"writable_held_selector":X.writableSelectors.delete(_),J={key:W.family.key,type:"writable_held_selector_family"},h0(Y,J).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"writable_pure_selector":X.writableSelectors.delete(_),J={key:W.family.key,type:"writable_pure_selector_family"},h0(Y,J).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"readonly_held_selector":X.readonlySelectors.delete(_),J={key:W.family.key,type:"readonly_held_selector_family"},h0(Y,J).subject.next({type:"state_disposal",subType:"selector",token:Z});break;case"readonly_pure_selector":X.readonlySelectors.delete(_),J={key:W.family.key,type:"readonly_pure_selector_family"},h0(Y,J).subject.next({type:"state_disposal",subType:"selector",token:Z});break}if(X.valueMap.delete(_),X.selectorAtoms.delete(_),X.selectorGraph.delete(_),Y.logger.info("\uD83D\uDD25",Z.type,_,"deleted"),o0(X)&&X.transactionMeta.phase==="building")X.transactionMeta.update.updates.push({type:"state_disposal",subType:"selector",token:Z});else Y.on.selectorDisposal.next(Z)}}function h4(Y,Z,X){let _=Z.key,G="readonly_pure_selector_family",W={key:_,type:"readonly_pure_selector_family"},H=Y.families.get(_);if(H)Y.logger.error("\u2757","readonly_pure_selector_family",_,`Overwriting an existing ${f4(H)} "${H.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let J=new J0,$=Object.assign((z)=>{let O=z0(z),L={key:_,subKey:O},V=`${_}(${O})`,N=i(Y),A=m5(N,{key:V,get:Z.get(z)},L);return J.next({type:"state_creation",token:A}),A},W,{internalRoles:X,subject:J,install:(z)=>h4(z,Z),default:(z)=>{return Z.get(z)({get:(...L)=>k1(Y,...L),find:(...L)=>H0(Y,...L),json:(L)=>b4(Y,L)})}});return Y.families.set(_,$),W}function g7(Y,Z,X){let _=Z.key,G="readonly_held_selector_family",W={key:_,type:"readonly_held_selector_family"},H=Y.families.get(_);if(H)Y.logger.error("\u2757","readonly_held_selector_family",_,`Overwriting an existing ${f4(H)} "${H.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let J=new J0,$=Object.assign((z)=>{let O=z0(z),L={key:_,subKey:O},V=`${_}(${O})`,N=i(Y),A=p5(N,{key:V,const:Z.const(z),get:Z.get(z)},L);return J.next({type:"state_creation",token:A}),A},W,{internalRoles:X,subject:J,install:(z)=>g7(z,Z),default:Z.const});return Y.families.set(_,$),W}function y7(Y,Z,X){let _=Z.key,G="writable_held_selector_family",W={key:_,type:"writable_held_selector_family"},H=Y.families.get(_);if(H)Y.logger.error("\u2757","writable_held_selector_family",_,`Overwriting an existing ${f4(H)} "${H.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let J=new J0,$=Object.assign((z)=>{let O=z0(z),L={key:_,subKey:O},V=`${_}(${O})`,N=i(Y),A=u5(N,{key:V,const:Z.const(z),get:Z.get(z),set:Z.set(z)},L);return J.next({type:"state_creation",token:A}),A},W,{internalRoles:X,subject:J,install:(z)=>y7(z,Z),default:Z.const});return Y.families.set(_,$),W}function FY(Y,Z,X){let _=Z.key,G="writable_pure_selector_family",W={key:_,type:"writable_pure_selector_family"},H=Y.families.get(_);if(H)Y.logger.error("\u2757","writable_pure_selector_family",_,`Overwriting an existing ${f4(H)} "${H.key}" in store "${Y.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);let J=new J0,$=Object.assign((z)=>{let O=z0(z),L={key:_,subKey:O},V=`${_}(${O})`,N=i(Y),A=d5(N,{key:V,get:Z.get(z),set:Z.set(z)},L);return J.next({type:"state_creation",token:A}),A},W,{internalRoles:X,subject:J,install:(z)=>FY(z,Z),default:(z)=>{return Z.get(z)({get:(...L)=>k1(Y,...L),find:(...L)=>H0(Y,...L),json:(L)=>b4(Y,L)})}});return Y.families.set(_,$),W}function P5(Y,Z){let X="set"in Z,_="const"in Z;if(_&&X)return y7(Y,Z,void 0);if(_)return g7(Y,Z,void 0);if(X)return FY(Y,Z);return h4(Y,Z)}function gF(Y,Z,X){let _=Y.families.get(Z.key);if(_===void 0)throw new k5(Z,Y);let G=_(X),W=i(Y);if(G.family){if(R4(W))switch(G.type){case"atom":case"mutable_atom":Y.on.atomCreation.next(G);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":Y.on.selectorCreation.next(G);break}else if(o0(W)&&W.on.transactionApplying.state===null)W.transactionMeta.update.updates.push({type:"state_creation",token:G})}return G}function yF(Y,Z,X){let _=z0(X),G=`${Z.key}(${_})`,W=i(Y),H;switch(Z.type){case"atom_family":case"mutable_atom_family":H=W.atoms.get(G);break;case"writable_held_selector_family":case"writable_pure_selector_family":H=W.writableSelectors.get(G);break;case"readonly_held_selector_family":case"readonly_pure_selector_family":H=W.readonlySelectors.get(G);break}if(H)return W4(H);return H}function H0(Y,Z,X){let _=yF(Y,Z,X);if(_)return _;let G=z0(X),W=Y.molecules.get(G);if(!W&&Y.config.lifespan==="immortal"){let H=qF(Z,X);return Y.logger.error("\u274C",H.type,H.key,`was not found in store "${Y.config.name}"; returned a counterfeit token.`),H}if(_=gF(Y,Z,X),W)i(Y).moleculeData.set(G,Z.key);return _}function E8(Y,...Z){let X;if(Z.length===1)X=Z[0];else{let _=Z[0],G=Z[1];X=H0(Y,_,G)}try{h0(Y,X)}catch(_){Y.logger.error("\u274C",X.type,X.key,`could not be disposed because it was not found in the store "${Y.config.name}".`);return}switch(X.type){case"atom":case"mutable_atom":i7(Y,X);break;case"writable_pure_selector":case"readonly_pure_selector":case"writable_held_selector":case"readonly_held_selector":kF(Y,X);break}}function p7(Y,Z){if(Z.family){let X=Y.families.get(Z.family.key);if(X)return X}}function EY(Y,...Z){let X,_,G;if(Z.length===1){if(X=Z[0],_=p7(Y,X)??null,_)G=X.family?G1(X.family.subKey):null,X=H0(Y,_,G)}else _=Z[0],G=Z[1],X=H0(Y,_,G);if("counterfeit"in X&&"family"in X){let J=X.family.subKey,Q=Y.disposalTraces.buffer.find(($)=>$?.key===J);Y.logger.error("\u274C",X.type,X.key,`could not be reset because it was not found in the store "${Y.config.name}".`,Q?`This state was previously disposed:
|
|
48
48
|
${Q.trace}`:"No previous disposal trace was found.");return}let W=LY(Y,X);if(W){let J=Y.on.operationClose.subscribe(`waiting to reset "${X.key}" at T-${W}`,()=>{J(),Y.logger.info("\uD83D\uDFE2",X.type,X.key,`resuming deferred resetState from T-${W}`),EY(Y,X)});return}let H=h0(Y,X);vF(Y,H),DY(Y)}var m7=(Y,Z,X)=>{switch(Z.type){case"atom":case"mutable_atom":f7(Y,Z,X);break;case"writable_pure_selector":case"writable_held_selector":Z.set(X);break}};function R1(Y,...Z){let X,_,G,W;if(Z.length===2){if(X=Z[0],W=Z[1],_=p7(Y,X)??null,_)G=X.family?G1(X.family.subKey):null,X=H0(Y,_,G)}else _=Z[0],G=Z[1],W=Z[2],X=H0(Y,_,G);if("counterfeit"in X&&"family"in X){let Q=X.family.subKey,$=Y.disposalTraces.buffer.find((z)=>z?.key===Q);Y.logger.error("\u274C",X.type,X.key,`could not be set because it was not found in the store "${Y.config.name}".`,$?`This state was previously disposed:
|
|
49
49
|
${$.trace}`:"No previous disposal trace was found.");return}let H=LY(Y,X);if(H){let Q=Y.on.operationClose.subscribe(`waiting to set "${X.key}" at T-${H}`,()=>{Q(),Y.logger.info("\uD83D\uDFE2",X.type,X.key,`resuming deferred setState from T-${H}`),R1(Y,X,W)});return}let J=h0(Y,X);m7(Y,J,W),DY(Y)}function pF(Y,Z,X){let{key:_,newValue:G,oldValue:W}=Z,H=Y==="newValue"?G:W,J={key:_,type:"atom"};if(Z.family)Object.assign(J,{family:Z.family});R1(X,J,H)}function mF(Y){let{stack:Z}=Y;if(Z)return`
|
|
50
50
|
`+Z.split(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tempest.games",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.25",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"safegen": "0.6.2",
|
|
46
46
|
"socket.io": "4.8.1",
|
|
47
47
|
"socket.io-client": "4.8.1",
|
|
48
|
-
"atom.io": "0.33.
|
|
48
|
+
"atom.io": "0.33.16",
|
|
49
49
|
"safedeposit": "0.1.1",
|
|
50
50
|
"treetrunks": "0.1.3"
|
|
51
51
|
},
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"vite": "7.0.6",
|
|
71
71
|
"vite-tsconfig-paths": "5.1.4",
|
|
72
72
|
"vitest": "3.2.4",
|
|
73
|
-
"flightdeck": "0.2.
|
|
73
|
+
"flightdeck": "0.2.47",
|
|
74
74
|
"varmint": "0.5.2"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|