tempest.games 0.2.41 → 0.2.43
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 +14 -0
- package/app/assets/{index-5PTtbPbo.js → index-Y097x-9O.js} +37 -37
- package/app/index.html +1 -1
- package/bin/backend.bun.js +52 -52
- package/bin/backend.worker.game.bun.js +2 -2
- package/bin/backend.worker.tribunal.bun.js +79 -79
- package/bin/frontend.bun.js +18 -18
- package/bin/setup-db.bun.js +52 -52
- package/package.json +8 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
var fz=Object.create;var{getPrototypeOf:Sz,defineProperty:F0,getOwnPropertyNames:Kz}=Object;var bz=Object.prototype.hasOwnProperty;var wQ=(z,Q,Z)=>{Z=z!=null?fz(Sz(z)):{};let W=Q||!z||!z.__esModule?F0(Z,"default",{value:z,enumerable:!0}):Z;for(let G of Kz(z))if(!bz.call(W,G))F0(W,G,{get:()=>z[G],enumerable:!0});return W};var xQ=(z,Q)=>()=>(Q||z((Q={exports:{}}).exports,Q),Q.exports);var RQ=(z,Q)=>{for(var Z in Q)F0(z,Z,{get:Q[Z],enumerable:!0,configurable:!0,set:(W)=>Q[Z]=()=>W})};var AQ=(z,Q)=>()=>(z&&(Q=z(z=0)),Q);var vQ=import.meta.require;var I=(z)=>JSON.parse(z),C=(z)=>JSON.stringify(z),TQ=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];function o(z){return L0(f.STORE,z,void 0)}function Y0(z){return _0(f.STORE,z)}function KQ(...z){if(z.length===2)return m(f.STORE,...z);return m(f.STORE,...z)}function E0(z,Q){return Yz(f.STORE,z,Q)}function o0(z){return $z(z,f.STORE)}var k={atom_family:"atom family",atom:"atom",continuity:"continuity",key:"key",mutable_atom_family:"atom family [m]",mutable_atom:"atom [m]",readonly_held_selector_family:"selector family [h]",readonly_held_selector:"selector [h]",readonly_pure_selector_family:"selector family",readonly_pure_selector:"selector",state:"state",timeline:"timeline",transaction:"transaction",unknown:"unknown",writable_held_selector_family:"selector family [wh]",writable_held_selector:"selector [wh]",writable_pure_selector_family:"selector family [w]",writable_pure_selector:"selector [w]"};var w0=(z)=>(Q,Z,W,G,...H)=>{console[z](`${Q} ${k[Z]} \`${W}\` ${G}`,...H)},gz={error:w0("error"),info:w0("info"),warn:w0("warn")},t0=class{logLevel;filter;logger;constructor(z,Q,Z=gz){this.logLevel=z,this.filter=Q,this.logger=Z}error=(...z)=>{if(this.logLevel!==null){let Q=this.filter?.(...z)??!0;if(Q===!0)this.logger.error(...z);else if(Q)this.logger.error(...Q)}};info=(...z)=>{if(this.logLevel==="info"){let Q=this.filter?.(...z)??!0;if(Q===!0)this.logger.info(...z);else if(Q)this.logger.info(...Q)}};warn=(...z)=>{if(this.logLevel!=="error"&&this.logLevel!==null){let Q=this.filter?.(...z)??!0;if(Q===!0)this.logger.warn(...z);else if(Q)this.logger.warn(...Q)}}};var dz=class{store;constructor(z=f.STORE){this.store=z,Qz("root",z)}allocate(z,Q,Z){return t(this.store,z,Q,Z)}fuse(z,Q,Z){return Zz(this.store,z,Q,Z)}deallocate(z){e(this.store,z)}claim(z,Q,Z){return $0(this.store,z,Q,Z)}},e0=class{store;realm;constructor(z=f.STORE){this.store=z,this.realm=new dz(z)}allocate(z,Q,Z){t(this.store,z,Q,Z)}deallocate(z){e(this.store,z)}claim(z,Q,Z){$0(this.store,z,Q,Z)}};function M0(z){return Gz(f.STORE,z)}function X0(z){return R0(f.STORE,z)}var y=class z extends Set{mode="record";subject=new U;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(Q,Z=0){super(Q);if(Q instanceof z)this.parent=Q,this.cacheUpdateNumber=Q.cacheUpdateNumber;if(Z)this.cacheLimit=Z,this.cache=new Array(Z),this.subscribe("auto cache",(W)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=W})}READONLY_VIEW=this;toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(Q){let Z=new z(Q.members,Q.cacheLimit);return Z.cache=Q.cache,Z.cacheIdx=Q.cacheIdx,Z.cacheUpdateNumber=Q.cacheUpdateNumber,Z}add(Q){let Z=super.add(Q);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${C(Q)}`);return Z}clear(){let Q=this.mode==="record"?[...this]:null;if(super.clear(),Q)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(Q)}`)}delete(Q){let Z=super.delete(Q);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${C(Q)}`);return Z}parent=null;child=null;transactionUpdates=null;transaction(Q){this.mode="transaction",this.transactionUpdates=[],this.child=new z(this);let Z=this.child._subscribe("transaction",(W)=>{this.transactionUpdates?.push(W)});try{if(Q(this.child)){for(let G of this.transactionUpdates)this.doStep(G);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(W){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",W),W}finally{Z(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(Q,Z){return this.subject.subscribe(Q,Z)}subscribe(Q,Z){return this.subject.subscribe(Q,(W)=>{Z(`${this.cacheUpdateNumber}=${W}`)})}emit(Q){this.subject.next(Q)}doStep(Q){let Z=Q.indexOf(":"),W=Q.substring(0,Z),G=Q.substring(Z+1);switch(W){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 H of G.split(";"))this.doStep(H)}}getUpdateNumber(Q){let Z=Q.indexOf("=");return Number(Q.substring(0,Z))}do(Q){let Z=Q.indexOf("="),W=Number(Q.substring(0,Z)),G=W-this.cacheUpdateNumber;if(G>0){if(G===1){this.mode="playback";let Y=Q.substring(Z+1);return this.doStep(Y),this.mode="record",this.cacheUpdateNumber=W,null}return this.cacheUpdateNumber+1}if(Math.abs(G)<this.cacheLimit){let Y=this.cacheIdx+G;if(this.cache[Y]===Q)return null;this.mode="playback";let $=!1;while(!$){this.cacheIdx%=this.cacheLimit;let N=this.cache[this.cacheIdx];if(this.cacheIdx--,!N)return"OUT_OF_RANGE";this.undo(N),$=this.cacheIdx===Y-1}let _=Q.substring(Z+1);return this.doStep(_),this.mode="record",this.cacheUpdateNumber=W,null}return"OUT_OF_RANGE"}undoStep(Q){let Z=Q.indexOf(":"),W=Q.substring(0,Z),G=Q.substring(Z+1);switch(W){case"add":this.delete(JSON.parse(G));break;case"del":this.add(JSON.parse(G));break;case"clear":{let H=JSON.parse(G);for(let Y of H)this.add(Y);break}case"tx":{let H=G.split(";");for(let Y=H.length-1;Y>=0;Y--)this.undoStep(H[Y])}}}undo(Q){let Z=Q.indexOf("=");if(Number(Q.substring(0,Z))===this.cacheUpdateNumber){this.mode="playback";let G=Q.substring(Z+1);return this.undoStep(G),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function zz(z=Math.random){return z().toString(36).slice(2)}function L(z){while(z.child!==null)z=z.child;return z}var cz=class z{_buffer;_index=0;constructor(Q){let Z;if(typeof Q==="number")Z=Q;else Z=Q.length;this._buffer=Array.from({length:Z})}get buffer(){return this._buffer}get index(){return this._index}add(Q){this._buffer[this._index]=Q,this._index=(this._index+1)%this._buffer.length}copy(){let Q=new z([...this._buffer]);return Q._index=this._index,Q}};function i(z){let Q={key:z.key,type:z.type};if("family"in z)Q.family=z.family;return Q}var pz=Symbol("counterfeit"),kz={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 _z(z,Q,Z){let W=C(Q),G=`${z.key}(${W})`,H=kz[z.type],Y={key:G,type:H,family:{key:z.key,subKey:W}};if(Z)Y.counterfeit=!0;return Y}var S=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(z,Q)=>`${z}:${Q}`;warn;getRelatedKeys(z){return this.relations.get(z)}addRelation(z,Q){let Z=this.relations.get(z),W=this.relations.get(Q);if(Z)Z.add(Q);else Z=new Set([Q]),this.relations.set(z,Z);if(W)W.add(z);else W=new Set([z]),this.relations.set(Q,W)}deleteRelation(z,Q){let Z=this.relations.get(z);if(Z){if(Z.delete(Q),Z.size===0)this.relations.delete(z);let W=this.relations.get(Q);if(W){if(W.delete(z),W.size===0)this.relations.delete(Q)}}}replaceRelationsUnsafely(z,Q){this.relations.set(z,new Set(Q));for(let Z of Q){let W=new Set().add(z);this.relations.set(Z,W)}}replaceRelationsSafely(z,Q){let Z=this.relations.get(z),W=this.isAType?.(z)?z:void 0,G=W===void 0?z:void 0;if(Z)for(let H of Z){W??=H,G??=H;let Y=this.relations.get(H);if(Y){if(Y.size===1)this.relations.delete(H);else Y.delete(z);this.contents.delete(this.makeContentKey(W,G))}}this.relations.set(z,new Set(Q));for(let H of Q){let Y=this.relations.get(H);if(Y)Y.add(z);else Y=new Set().add(z),this.relations.set(H,Y)}}getContentInternal(z){return this.contents.get(z)}setContent(z,Q){this.contents.set(z,Q)}deleteContent(z){this.contents.delete(z)}constructor(z,Q){if(this.a=z.between[0],this.b=z.between[1],this.cardinality=z.cardinality,!Q?.externalStore)this.relations=new Map(z.relations?.map(([Z,W])=>[Z,new Set(W)])),this.contents=new Map(z.contents);if(this.isAType=Q?.isAType??null,this.isBType=Q?.isBType??null,this.isContent=Q?.isContent??null,Q?.makeContentKey)this.makeContentKey=Q.makeContentKey;if(Q?.externalStore){let Z=Q.externalStore;if(this.has=(W,G)=>Z.has(W,G),this.addRelation=(W,G)=>{Z.addRelation(W,G)},this.deleteRelation=(W,G)=>{Z.deleteRelation(W,G)},this.replaceRelationsSafely=(W,G)=>{Z.replaceRelationsSafely(W,G)},this.replaceRelationsUnsafely=(W,G)=>{Z.replaceRelationsUnsafely(W,G)},this.getRelatedKeys=(W)=>Z.getRelatedKeys(W),Z.getContent)this.getContentInternal=(W)=>{return Z.getContent(W)},this.setContent=(W,G)=>{Z.setContent(W,G)},this.deleteContent=(W)=>{Z.deleteContent(W)};for(let[W,G]of z.relations??[]){let H=this.isAType?.(W)?W:void 0,Y=H===void 0?W:void 0;for(let X of G)H??=X,Y??=X,this.addRelation(H,Y)}for(let[W,G]of z.contents??[])this.setContent(W,G)}if(Q?.warn)this.warn=Q.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([z,Q])=>[z,[...Q]]),contents:[...this.contents.entries()]}}set(...z){let Q,Z,W;switch(z.length){case 1:{let G=z[0];Q=G[this.a],Z=G[this.b],W=void 0;break}case 2:{let G=z[0];if(typeof G==="string")[Q,Z]=z;else Q=G[this.a],Z=G[this.b],W=z[1];break}default:Q=z[0],Z=z[1],W=z[2];break}switch(this.cardinality){case"1:1":{let G=this.getRelatedKey(Q);if(G&&G!==Z)this.delete(Q,G)}case"1:n":{let G=this.getRelatedKey(Z);if(G&&G!==Q)this.delete(G,Z)}break;case"n:n":}if(W){let G=this.makeContentKey(Q,Z);this.setContent(G,W)}return this.addRelation(Q,Z),this}delete(z,Q){Q=typeof Q==="string"?Q:z[this.b];let Z=typeof z==="string"?z:z[this.a];if(Z===void 0&&typeof Q==="string"){let W=this.getRelatedKeys(Q);if(W)for(let G of W)this.delete(G,Q)}if(typeof Z==="string"&&Q===void 0){let W=this.getRelatedKeys(Z);if(W)for(let G of W)this.delete(Z,G)}if(typeof Z==="string"&&typeof Q==="string"){this.deleteRelation(Z,Q);let W=this.makeContentKey(Z,Q);this.deleteContent(W)}return this}getRelatedKey(z){let Q=this.getRelatedKeys(z);if(Q){if(Q.size>1)this.warn?.(`${Q.size} related keys were found for key "${z}": (${[...Q].map((W)=>`"${W}"`).join(", ")}). Only one related key was expected.`);let Z;for(let W of Q){Z=W;break}return Z}}replaceRelations(z,Q,Z){let W=!Array.isArray(Q),G=W?Object.keys(Q):Q;if(Z?.reckless)this.replaceRelationsUnsafely(z,G);else this.replaceRelationsSafely(z,G);if(W)for(let H of G){let Y=this.makeContentKey(z,H),X=Q[H];this.setContent(Y,X)}return this}getContent(z,Q){let Z=this.makeContentKey(z,Q);return this.getContentInternal(Z)}getRelationEntries(z){let Q=z[this.a],Z=z[this.b];if(Q!==void 0&&Z===void 0){let W=this.getRelatedKeys(Q);if(W)return[...W].map((G)=>{return[G,this.getContent(Q,G)]})}if(Q===void 0&&Z!==void 0){let W=this.getRelatedKeys(Z);if(W)return[...W].map((G)=>{return[G,this.getContent(G,Z)]})}return[]}has(z,Q){if(Q)return this.getRelatedKeys(z)?.has(Q)??!1;return this.relations.has(z)}},U=class{Subscriber;subscribers=new Map;subscribe(z,Q){return this.subscribers.set(z,Q),()=>{this.unsubscribe(z)}}unsubscribe(z){this.subscribers.delete(z)}next(z){let Q=this.subscribers.values();for(let Z of Q)Z(z)}},yz=class extends U{state;constructor(z){super();this.state=z}next(z){this.state=z,super.next(z)}},uz=(z,Q)=>{let Z=L(z);if(Z.operation.open)return Z.operation.prev.get(Q.key);return Z.valueMap.get(Q.key)};function Vz(z,Q,Z,W){let G=z.disposalTraces.buffer.find((H)=>H?.key===C(W));switch(z.logger.error("\u274C",Q.type,Q.key,"gets a fallback value because key",W,"is not allocated",G?`This key was previously disposed:
|
|
3
|
+
var fz=Object.create;var{getPrototypeOf:Sz,defineProperty:F0,getOwnPropertyNames:Kz}=Object;var bz=Object.prototype.hasOwnProperty;var wQ=(z,Q,Z)=>{Z=z!=null?fz(Sz(z)):{};let W=Q||!z||!z.__esModule?F0(Z,"default",{value:z,enumerable:!0}):Z;for(let G of Kz(z))if(!bz.call(W,G))F0(W,G,{get:()=>z[G],enumerable:!0});return W};var xQ=(z,Q)=>()=>(Q||z((Q={exports:{}}).exports,Q),Q.exports);var RQ=(z,Q)=>{for(var Z in Q)F0(z,Z,{get:Q[Z],enumerable:!0,configurable:!0,set:(W)=>Q[Z]=()=>W})};var AQ=(z,Q)=>()=>(z&&(Q=z(z=0)),Q);var vQ=import.meta.require;function I(z){return JSON.parse(z)}var C=(z)=>JSON.stringify(z),TQ=[Array.prototype,Boolean.prototype,Number.prototype,Object.prototype,String.prototype];function o(z){return L0(f.STORE,z,void 0)}function Y0(z){return _0(f.STORE,z)}function KQ(...z){if(z.length===2)return m(f.STORE,...z);return m(f.STORE,...z)}function E0(z,Q){return Yz(f.STORE,z,Q)}function o0(z){return $z(z,f.STORE)}var k={atom_family:"atom family",atom:"atom",continuity:"continuity",key:"key",mutable_atom_family:"atom family [m]",mutable_atom:"atom [m]",readonly_held_selector_family:"selector family [h]",readonly_held_selector:"selector [h]",readonly_pure_selector_family:"selector family",readonly_pure_selector:"selector",state:"state",timeline:"timeline",transaction:"transaction",unknown:"unknown",writable_held_selector_family:"selector family [wh]",writable_held_selector:"selector [wh]",writable_pure_selector_family:"selector family [w]",writable_pure_selector:"selector [w]"};var w0=(z)=>(Q,Z,W,G,...H)=>{console[z](`${Q} ${k[Z]} \`${W}\` ${G}`,...H)},gz={error:w0("error"),info:w0("info"),warn:w0("warn")},t0=class{logLevel;filter;logger;constructor(z,Q,Z=gz){this.logLevel=z,this.filter=Q,this.logger=Z}error=(...z)=>{if(this.logLevel!==null){let Q=this.filter?.(...z)??!0;if(Q===!0)this.logger.error(...z);else if(Q)this.logger.error(...Q)}};info=(...z)=>{if(this.logLevel==="info"){let Q=this.filter?.(...z)??!0;if(Q===!0)this.logger.info(...z);else if(Q)this.logger.info(...Q)}};warn=(...z)=>{if(this.logLevel!=="error"&&this.logLevel!==null){let Q=this.filter?.(...z)??!0;if(Q===!0)this.logger.warn(...z);else if(Q)this.logger.warn(...Q)}}};var dz=class{store;constructor(z=f.STORE){this.store=z,Qz("root",z)}allocate(z,Q,Z){return t(this.store,z,Q,Z)}fuse(z,Q,Z){return Zz(this.store,z,Q,Z)}deallocate(z){e(this.store,z)}claim(z,Q,Z){return $0(this.store,z,Q,Z)}},e0=class{store;realm;constructor(z=f.STORE){this.store=z,this.realm=new dz(z)}allocate(z,Q,Z){t(this.store,z,Q,Z)}deallocate(z){e(this.store,z)}claim(z,Q,Z){$0(this.store,z,Q,Z)}};function M0(z){return Gz(f.STORE,z)}function X0(z){return R0(f.STORE,z)}var y=class z extends Set{mode="record";subject=new U;cacheLimit=0;cache=[];cacheIdx=-1;cacheUpdateNumber=-1;constructor(Q,Z=0){super(Q);if(Q instanceof z)this.parent=Q,this.cacheUpdateNumber=Q.cacheUpdateNumber;if(Z)this.cacheLimit=Z,this.cache=new Array(Z),this.subscribe("auto cache",(W)=>{this.cacheIdx++,this.cacheIdx%=this.cacheLimit,this.cache[this.cacheIdx]=W})}READONLY_VIEW=this;toJSON(){return{members:[...this],cache:this.cache,cacheLimit:this.cacheLimit,cacheIdx:this.cacheIdx,cacheUpdateNumber:this.cacheUpdateNumber}}static fromJSON(Q){let Z=new z(Q.members,Q.cacheLimit);return Z.cache=Q.cache,Z.cacheIdx=Q.cacheIdx,Z.cacheUpdateNumber=Q.cacheUpdateNumber,Z}add(Q){let Z=super.add(Q);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`add:${C(Q)}`);return Z}clear(){let Q=this.mode==="record"?[...this]:null;if(super.clear(),Q)this.cacheUpdateNumber++,this.emit(`clear:${JSON.stringify(Q)}`)}delete(Q){let Z=super.delete(Q);if(this.mode==="record")this.cacheUpdateNumber++,this.emit(`del:${C(Q)}`);return Z}parent=null;child=null;transactionUpdates=null;transaction(Q){this.mode="transaction",this.transactionUpdates=[],this.child=new z(this);let Z=this.child._subscribe("transaction",(W)=>{this.transactionUpdates?.push(W)});try{if(Q(this.child)){for(let G of this.transactionUpdates)this.doStep(G);this.cacheUpdateNumber++,this.emit(`tx:${this.transactionUpdates.join(";")}`)}}catch(W){throw console.warn("Did not apply transaction to SetRTX; this error was thrown:",W),W}finally{Z(),this.child=null,this.transactionUpdates=null,this.mode="record"}}_subscribe(Q,Z){return this.subject.subscribe(Q,Z)}subscribe(Q,Z){return this.subject.subscribe(Q,(W)=>{Z(`${this.cacheUpdateNumber}=${W}`)})}emit(Q){this.subject.next(Q)}doStep(Q){let Z=Q.indexOf(":"),W=Q.substring(0,Z),G=Q.substring(Z+1);switch(W){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 H of G.split(";"))this.doStep(H)}}getUpdateNumber(Q){let Z=Q.indexOf("=");return Number(Q.substring(0,Z))}do(Q){let Z=Q.indexOf("="),W=Number(Q.substring(0,Z)),G=W-this.cacheUpdateNumber;if(G>0){if(G===1){this.mode="playback";let Y=Q.substring(Z+1);return this.doStep(Y),this.mode="record",this.cacheUpdateNumber=W,null}return this.cacheUpdateNumber+1}if(Math.abs(G)<this.cacheLimit){let Y=this.cacheIdx+G;if(this.cache[Y]===Q)return null;this.mode="playback";let $=!1;while(!$){this.cacheIdx%=this.cacheLimit;let N=this.cache[this.cacheIdx];if(this.cacheIdx--,!N)return"OUT_OF_RANGE";this.undo(N),$=this.cacheIdx===Y-1}let _=Q.substring(Z+1);return this.doStep(_),this.mode="record",this.cacheUpdateNumber=W,null}return"OUT_OF_RANGE"}undoStep(Q){let Z=Q.indexOf(":"),W=Q.substring(0,Z),G=Q.substring(Z+1);switch(W){case"add":this.delete(JSON.parse(G));break;case"del":this.add(JSON.parse(G));break;case"clear":{let H=JSON.parse(G);for(let Y of H)this.add(Y);break}case"tx":{let H=G.split(";");for(let Y=H.length-1;Y>=0;Y--)this.undoStep(H[Y])}}}undo(Q){let Z=Q.indexOf("=");if(Number(Q.substring(0,Z))===this.cacheUpdateNumber){this.mode="playback";let G=Q.substring(Z+1);return this.undoStep(G),this.mode="record",this.cacheUpdateNumber--,null}return this.cacheUpdateNumber}};function zz(z=Math.random){return z().toString(36).slice(2)}function L(z){while(z.child!==null)z=z.child;return z}var cz=class z{_buffer;_index=0;constructor(Q){let Z;if(typeof Q==="number")Z=Q;else Z=Q.length;this._buffer=Array.from({length:Z})}get buffer(){return this._buffer}get index(){return this._index}add(Q){this._buffer[this._index]=Q,this._index=(this._index+1)%this._buffer.length}copy(){let Q=new z([...this._buffer]);return Q._index=this._index,Q}};function i(z){let Q={key:z.key,type:z.type};if("family"in z)Q.family=z.family;return Q}var pz=Symbol("counterfeit"),kz={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 _z(z,Q,Z){let W=C(Q),G=`${z.key}(${W})`,H=kz[z.type],Y={key:G,type:H,family:{key:z.key,subKey:W}};if(Z)Y.counterfeit=!0;return Y}var S=class{a;b;cardinality;relations=new Map;contents=new Map;isAType;isBType;isContent;makeContentKey=(z,Q)=>`${z}:${Q}`;warn;getRelatedKeys(z){return this.relations.get(z)}addRelation(z,Q){let Z=this.relations.get(z),W=this.relations.get(Q);if(Z)Z.add(Q);else Z=new Set([Q]),this.relations.set(z,Z);if(W)W.add(z);else W=new Set([z]),this.relations.set(Q,W)}deleteRelation(z,Q){let Z=this.relations.get(z);if(Z){if(Z.delete(Q),Z.size===0)this.relations.delete(z);let W=this.relations.get(Q);if(W){if(W.delete(z),W.size===0)this.relations.delete(Q)}}}replaceRelationsUnsafely(z,Q){this.relations.set(z,new Set(Q));for(let Z of Q){let W=new Set().add(z);this.relations.set(Z,W)}}replaceRelationsSafely(z,Q){let Z=this.relations.get(z),W=this.isAType?.(z)?z:void 0,G=W===void 0?z:void 0;if(Z)for(let H of Z){W??=H,G??=H;let Y=this.relations.get(H);if(Y){if(Y.size===1)this.relations.delete(H);else Y.delete(z);this.contents.delete(this.makeContentKey(W,G))}}this.relations.set(z,new Set(Q));for(let H of Q){let Y=this.relations.get(H);if(Y)Y.add(z);else Y=new Set().add(z),this.relations.set(H,Y)}}getContentInternal(z){return this.contents.get(z)}setContent(z,Q){this.contents.set(z,Q)}deleteContent(z){this.contents.delete(z)}constructor(z,Q){if(this.a=z.between[0],this.b=z.between[1],this.cardinality=z.cardinality,!Q?.externalStore)this.relations=new Map(z.relations?.map(([Z,W])=>[Z,new Set(W)])),this.contents=new Map(z.contents);if(this.isAType=Q?.isAType??null,this.isBType=Q?.isBType??null,this.isContent=Q?.isContent??null,Q?.makeContentKey)this.makeContentKey=Q.makeContentKey;if(Q?.externalStore){let Z=Q.externalStore;if(this.has=(W,G)=>Z.has(W,G),this.addRelation=(W,G)=>{Z.addRelation(W,G)},this.deleteRelation=(W,G)=>{Z.deleteRelation(W,G)},this.replaceRelationsSafely=(W,G)=>{Z.replaceRelationsSafely(W,G)},this.replaceRelationsUnsafely=(W,G)=>{Z.replaceRelationsUnsafely(W,G)},this.getRelatedKeys=(W)=>Z.getRelatedKeys(W),Z.getContent)this.getContentInternal=(W)=>{return Z.getContent(W)},this.setContent=(W,G)=>{Z.setContent(W,G)},this.deleteContent=(W)=>{Z.deleteContent(W)};for(let[W,G]of z.relations??[]){let H=this.isAType?.(W)?W:void 0,Y=H===void 0?W:void 0;for(let X of G)H??=X,Y??=X,this.addRelation(H,Y)}for(let[W,G]of z.contents??[])this.setContent(W,G)}if(Q?.warn)this.warn=Q.warn}toJSON(){return{between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([z,Q])=>[z,[...Q]]),contents:[...this.contents.entries()]}}set(...z){let Q,Z,W;switch(z.length){case 1:{let G=z[0];Q=G[this.a],Z=G[this.b],W=void 0;break}case 2:{let G=z[0];if(typeof G==="string")[Q,Z]=z;else Q=G[this.a],Z=G[this.b],W=z[1];break}default:Q=z[0],Z=z[1],W=z[2];break}switch(this.cardinality){case"1:1":{let G=this.getRelatedKey(Q);if(G&&G!==Z)this.delete(Q,G)}case"1:n":{let G=this.getRelatedKey(Z);if(G&&G!==Q)this.delete(G,Z)}break;case"n:n":}if(W){let G=this.makeContentKey(Q,Z);this.setContent(G,W)}return this.addRelation(Q,Z),this}delete(z,Q){Q=typeof Q==="string"?Q:z[this.b];let Z=typeof z==="string"?z:z[this.a];if(Z===void 0&&typeof Q==="string"){let W=this.getRelatedKeys(Q);if(W)for(let G of W)this.delete(G,Q)}if(typeof Z==="string"&&Q===void 0){let W=this.getRelatedKeys(Z);if(W)for(let G of W)this.delete(Z,G)}if(typeof Z==="string"&&typeof Q==="string"){this.deleteRelation(Z,Q);let W=this.makeContentKey(Z,Q);this.deleteContent(W)}return this}getRelatedKey(z){let Q=this.getRelatedKeys(z);if(Q){if(Q.size>1)this.warn?.(`${Q.size} related keys were found for key "${z}": (${[...Q].map((W)=>`"${W}"`).join(", ")}). Only one related key was expected.`);let Z;for(let W of Q){Z=W;break}return Z}}replaceRelations(z,Q,Z){let W=!Array.isArray(Q),G=W?Object.keys(Q):Q;if(Z?.reckless)this.replaceRelationsUnsafely(z,G);else this.replaceRelationsSafely(z,G);if(W)for(let H of G){let Y=this.makeContentKey(z,H),X=Q[H];this.setContent(Y,X)}return this}getContent(z,Q){let Z=this.makeContentKey(z,Q);return this.getContentInternal(Z)}getRelationEntries(z){let Q=z[this.a],Z=z[this.b];if(Q!==void 0&&Z===void 0){let W=this.getRelatedKeys(Q);if(W)return[...W].map((G)=>{return[G,this.getContent(Q,G)]})}if(Q===void 0&&Z!==void 0){let W=this.getRelatedKeys(Z);if(W)return[...W].map((G)=>{return[G,this.getContent(G,Z)]})}return[]}has(z,Q){if(Q)return this.getRelatedKeys(z)?.has(Q)??!1;return this.relations.has(z)}},U=class{Subscriber;subscribers=new Map;subscribe(z,Q){return this.subscribers.set(z,Q),()=>{this.unsubscribe(z)}}unsubscribe(z){this.subscribers.delete(z)}next(z){let Q=this.subscribers.values();for(let Z of Q)Z(z)}},yz=class extends U{state;constructor(z){super();this.state=z}next(z){this.state=z,super.next(z)}},uz=(z,Q)=>{let Z=L(z);if(Z.operation.open)return Z.operation.prev.get(Q.key);return Z.valueMap.get(Q.key)};function Vz(z,Q,Z,W){let G=z.disposalTraces.buffer.find((H)=>H?.key===C(W));switch(z.logger.error("\u274C",Q.type,Q.key,"gets a fallback value because key",W,"is not allocated",G?`This key was previously disposed:
|
|
4
4
|
${G.trace}`:"(no previous disposal trace found)"),Z.type){case"mutable_atom_family":{if(z.defaults.has(Z.key))return z.defaults.get(Z.key);let H=new Z.class;return z.defaults.set(Z.key,H),H}case"atom_family":{if(z.defaults.has(Z.key))return z.defaults.get(Z.key);let H=Z.default,Y=H(W);return z.defaults.set(Z.key,Y),Y}case"readonly_pure_selector_family":case"writable_pure_selector_family":case"readonly_held_selector_family":case"writable_held_selector_family":{if(z.defaults.has(Z.key))return z.defaults.get(Z.key);let H=Z.default(W);return z.defaults.set(Z.key,H),H}}}var I0=class extends Promise{fate;resolve;reject;done=!1;constructor(z){let Q,Z;super((W,G)=>{Q=W,Z=G});this.resolve=Q,this.reject=Z,this.use(z instanceof Promise?z:new Promise(z))}pass(z,Q){if(z===this.fate)this.resolve(Q),this.done=!0}fail(z,Q){if(z===this.fate)this.reject(Q),this.done=!0}use(z){if(this===z)return;if(z instanceof Promise){let Q=z;this.fate=Q,Q.then((Z)=>{this.pass(Q,Z)},(Z)=>{this.fail(Q,Z)})}else this.resolve(z),this.fate=void 0}};function n(z){return"epoch"in z.transactionMeta}function K(z){return"phase"in z.transactionMeta}function Jz(z,Q){if(z.operation.open){let Z=performance.now();return z.logger.info("\uD83D\uDEAB",Q.type,Q.key,`deferring setState at T-${Z} until setState for "${z.operation.token.key}" is done`),Z}return z.operation={open:!0,done:new Set,prev:new Map,timestamp:Date.now(),token:Q},z.logger.info("\u2B55",Q.type,Q.key,`operation start in store "${z.config.name}"${K(z)?` ${z.transactionMeta.phase} "${z.transactionMeta.update.token.key}"`:""}`),z}function Ez(z){if(z.operation.open)z.logger.info("\uD83D\uDD34",z.operation.token.type,z.operation.token.key,`operation done in store "${z.config.name}"`);z.operation={open:!1},z.on.operationClose.next(z.operation)}var Mz=(z,Q)=>{if(!z.operation.open)return z.logger.error("\uD83D\uDC1E","unknown",Q,"isDone called outside of an operation. This is probably a bug in AtomIO."),!0;return z.operation.done.has(Q)},B0=(z,Q)=>{if(!z.operation.open){z.logger.error("\uD83D\uDC1E","unknown",Q,"markDone called outside of an operation. This is probably a bug in AtomIO.");return}z.operation.done.add(Q)};function K0(z,Q){let Z=L(z),{key:W,type:G}=Q,H=Z.selectorAtoms.getRelatedKeys(W);if(Z.logger.info("\uD83E\uDDF9",G,W,H?`evicting ${H.size} states downstream:`:"no downstream states",H??"to evict"),H){if(Z.operation.open)Z.logger.info("\uD83E\uDDF9",G,W,`[ ${[...Z.operation.done].join(", ")} ] already done`);for(let Y of H){if(Mz(Z,Y))continue;Lz(Z,Y),B0(Z,Y)}}}function hz(z,Q){let Z=L(z),W=Z.selectorGraph.getRelationEntries({upstreamSelectorKey:Q}).filter(([G,{source:H}])=>H===Q);for(let[G]of W){if(Mz(Z,G))continue;Lz(Z,G),B0(Z,G),hz(z,G)}}function u(z,Q,Z){let{key:W,subject:G,type:H}=Q,Y=z.valueMap.get(W);if(Y instanceof I0&&!Y.done){let X=Y;if(Z instanceof Promise)return X.use(Z),X;return z.valueMap.set(W,Z),Z}if(Z instanceof Promise){let X=new I0(Z);return z.valueMap.set(W,X),X.then(function $(_){if(z.valueMap.get(W)===X){switch(Jz(z,Q),u(z,Q,_),H){case"atom":case"mutable_atom":K0(z,Q);break;case"readonly_pure_selector":case"writable_pure_selector":hz(z,W);break}Ez(z),G.next({newValue:_,oldValue:X})}}).catch(($)=>{z.logger.error("\uD83D\uDCA5","state",W,"rejected:",$)}),X}return z.valueMap.set(W,Z),Z}function lz(z,Q,Z){z.logger.info("\uD83D\uDCD6",Q.type,Q.key,"reading cached value");let W=z.valueMap.get(Q.key);if(Z==="mut"&&Q.type==="mutable_atom"&&K(z)){let H=Q,{parent:Y}=z;if(z.valueMap.hasOwn(H.key))return W;let X=Y.valueMap.get(H.key);z.logger.info("\uD83D\uDCC3","atom",H.key,"copying");let $=X.toJSON(),_=H.class.fromJSON($);z.valueMap.set(H.key,_),new u0(H,Y),W=_}return W}function Lz(z,Q){let Z=z.valueMap.get(Q);if(Z instanceof I0){let W=z.writableSelectors.get(Q)??z.readonlySelectors.get(Q);if(W)W.getFrom(z);return}if(z.operation.open)z.operation.prev.set(Q,Z);z.valueMap.delete(Q),z.logger.info("\uD83D\uDDD1","state",Q,"evicted")}function Q0(z,Q,Z){if(z.valueMap.has(Q.key))return lz(z,Q,Z);let{key:W}=Q;switch(Q.type){case"readonly_held_selector":case"readonly_pure_selector":case"writable_held_selector":case"writable_pure_selector":return z.logger.info("\uD83E\uDDEE",Q.type,W,"computing value"),Q.getFrom(z);case"atom":{let G;if(Q.default instanceof Function)G=Q.default();else G=Q.default;let H=u(z,Q,G);return z.logger.info("\uD83D\uDC81","atom",Q.key,"could not find cached value; using default",G),H}case"mutable_atom":{let G=new Q.class,H=u(z,Q,G);return z.logger.info("\uD83D\uDC81","mutable_atom",Q.key,"could not find cached value; using default",G),H}}}function b0(z,Q){return R(z,{key:Q.family.key,type:`${Q.type}_family`})}var iz=(z)=>{let Q=L(z);if(!K(Q)){z.logger.warn("\uD83D\uDC1E","transaction","???","abortTransaction called outside of a transaction. This is probably a bug in AtomIO.");return}z.logger.info("\uD83E\uDE82","transaction",Q.transactionMeta.update.token.key,"Aborting transaction"),Q.parent.child=null},Pz=class extends Error{constructor(z,Q){super(`${k[z.type]} ${C(z.key)} not found in store "${Q.config.name}".`)}};function x0(z,Q,Z){return(...W)=>{let G=R(z,Q);if(G)return G.run(W,Z);throw new Pz(Q,z)}}var T0=(z)=>(Q)=>z instanceof Function?z(Q):z;function Oz(z,Q,[Z,W],G){let{key:H,subject:Y,type:X}=Q,$={oldValue:v0(Z)?Z.READONLY_VIEW:Z,newValue:v0(W)?W.READONLY_VIEW:W};if(n(z)){switch(X){case"mutable_atom":z.logger.info("\uD83D\uDCE2",X,H,"is now (",W,") subscribers:",Y.subscribers);break;case"atom":case"writable_pure_selector":case"writable_held_selector":z.logger.info("\uD83D\uDCE2",X,H,"went (",Z,"->",W,") subscribers:",Y.subscribers)}Y.next($)}if(K(z)&&(X==="mutable_atom"||X==="atom")){if(z.on.transactionApplying.state===null){let _=i(Q);if(v0(W))return;let{timestamp:N}=z.operation,q={type:"atom_update",token:_,timestamp:N,update:$};z.transactionMeta.update.subEvents.push(q),z.logger.info("\uD83D\uDCC1","atom",H,"stowed (",Z,"->",W,")");return}if(hQ(Q,"tracker:signal")){let _=H.slice(1),N=z.atoms.get(_);if(Q0(z,N,"mut").do($.newValue)===null===!0)K0(z,N)}}}var f0=(z,Q,Z)=>{let W=Q0(z,Q,"mut"),G=T0(Z)(W);return z.logger.info("\uD83D\uDCDD","atom",Q.key,"set to",G),G=u(z,Q,G),B0(z,Q.key),K0(z,Q),[W,G]};function Nz(z,Q){switch(Q.type){case"mutable_atom":return f0(z,Q,new Q.class);case"atom":{let Z=Q.default;if(Z instanceof Function)Z=Z();return f0(z,Q,Z)}}}function rz(z,Q){let Z;switch(Q.type){case"atom":case"mutable_atom":Z=Nz(z,Q);break;case"writable_pure_selector":case"writable_held_selector":{let W=Q.getFrom(z),G=C0(z,Q.key);for(let Y of G.values()){let X=Nz(z,Y);Oz(z,Q,X,!1)}let H=Q.getFrom(z);Z=[W,H]}break}return Z}function g(z,...Q){g0(z,S0,...Q)}var O0=Symbol("RESET");function h0(z,...Q){let Z,W,G;if(Q.length===1)Z=Q[0],g(z,Z,O0);else W=Q[0],G=Q[1],g(z,W,G,O0)}function az(z,Q,Z){let W,G,H,{type:Y,key:X}=Q;switch(Q.type){case"writable_pure_selector":W=Q.getFrom(z),G=T0(Z)(W),u(z,Q,G);break;case"writable_held_selector":H=Q.const,T0(Z)(H),W=H,G=H}return z.logger.info("\uD83D\uDCDD",Y,X,"setting to",G),B0(z,X),Q.setSelf(G),[W,G]}var nz=(z,Q,Z)=>{let W;switch(Q.type){case"atom":case"mutable_atom":W=f0(z,Q,Z);break;case"writable_pure_selector":case"writable_held_selector":W=az(z,Q,Z);break}return W};function sz(z,Q,Z){let{token:W,update:{newValue:G,oldValue:H}}=Q;g(Z,W,z==="newValue"?G:H)}function oz(z){let{stack:Q}=z;if(Q)return`
|
|
5
5
|
`+Q.split(`
|
|
6
6
|
`)?.slice(1)?.join(`
|
|
@@ -8,7 +8,7 @@ ${G.trace}`:"(no previous disposal trace found)"),Z.type){case"mutable_atom_fami
|
|
|
8
8
|
${N} was most recently disposed
|
|
9
9
|
${q.trace}`:`No previous disposal trace for ${N} was found.`)}return Z}function Zz(z,Q,Z,W){let G=`T$--${Q}==${Z}++${W}`;return t(z,[Z,W],G,"all"),G}function e(z,Q){let Z=C(Q),W=z.molecules.get(Z);if(!W){let J=z.disposalTraces.buffer.find((j)=>j?.key===Z);z.logger.error("\u274C","key",Q,"deallocation failed:",`Could not find allocation for ${Z} in store "${z.config.name}".`,J?`
|
|
10
10
|
This state was most recently deallocated
|
|
11
|
-
${J.trace}`:`No previous disposal trace for ${Z} was found.`);return}let G=z.moleculeJoins.getRelatedKeys(W.key);if(G)for(let J of G){let j=z.joins.get(J);if(j)j.relations.delete(W.key),j.molecules.delete(W.stringKey)}z.moleculeJoins.delete(W.stringKey);let H=[],Y=[],X={type:"molecule_disposal",key:W.key,values:Y,provenance:H,timestamp:Date.now()},$=L(z);$.molecules.delete(Z);let _=K($)&&$.transactionMeta.phase==="building";if(_)$.transactionMeta.update.subEvents.push(X);let N=z.moleculeGraph.getRelationEntries({downstreamMoleculeKey:W.stringKey});if(N)for(let[J,{source:j}]of N)if(j===W.stringKey){let M=I(J);e(z,M)}else H.push(j);let q=$.moleculeData.getRelatedKeys(W.stringKey);if(q)for(let J of q){let j=$.families.get(J),M=x(z,j,W.key);Y.push([j.key,
|
|
11
|
+
${J.trace}`:`No previous disposal trace for ${Z} was found.`);return}let G=z.moleculeJoins.getRelatedKeys(W.key);if(G)for(let J of G){let j=z.joins.get(J);if(j)j.relations.delete(W.key),j.molecules.delete(W.stringKey)}z.moleculeJoins.delete(W.stringKey);let H=[],Y=[],X={type:"molecule_disposal",key:W.key,values:Y,provenance:H,timestamp:Date.now()},$=L(z);$.molecules.delete(Z);let _=K($)&&$.transactionMeta.phase==="building";if(_)$.transactionMeta.update.subEvents.push(X);let N=z.moleculeGraph.getRelationEntries({downstreamMoleculeKey:W.stringKey});if(N)for(let[J,{source:j}]of N)if(j===W.stringKey){let M=I(J);e(z,M)}else H.push(j);let q=$.moleculeData.getRelatedKeys(W.stringKey);if(q)for(let J of q){let j=$.families.get(J),M=x(z,j,W.key),A=m(z,M);Y.push([j.key,A]),N0(z,M)}if($.moleculeGraph.delete(W.stringKey),$.moleculeJoins.delete(W.stringKey),$.moleculeData.delete(W.stringKey),!_)$.on.moleculeDisposal.next(X);$.molecules.delete(W.stringKey);let D=oz(new Error);z.disposalTraces.add({key:Z,trace:D})}function $0(z,Q,Z,W){let G=C(Z),H=L(z),Y=H.molecules.get(G);if(!Y){let D=z.disposalTraces.buffer.find((J)=>J?.key===G);return z.logger.error("\u274C","key",G,"claim failed:",`Could not allocate to ${G} in store "${z.config.name}".`,D?`
|
|
12
12
|
${G} was most recently disposed
|
|
13
13
|
${D.trace}`:`No previous disposal trace for ${G} was found.`),Z}let X=C(Q),$=H.molecules.get(X);if(!$){let D=z.disposalTraces.buffer.find((J)=>J?.key===X);return z.logger.error("\u274C","key",Z,"claim failed:",`Could not allocate to ${X} in store "${z.config.name}".`,D?`
|
|
14
14
|
${X} was most recently disposed
|