From 9965ce760e6932ace83b0ee80016a6b154c4c138 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 25 Jul 2014 16:20:27 -0700 Subject: [PATCH] Update build products --- dist/minimart.js | 22 +++++++++++++++------- dist/minimart.min.js | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/dist/minimart.js b/dist/minimart.js index b5e6100..213cdee 100644 --- a/dist/minimart.js +++ b/dist/minimart.js @@ -1,6 +1,7 @@ !function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Minimart=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o ."+self.fragmentClass,1,self.jQueryWrapFunction);World.spawn({handleEvent:function(e){if(e.type==="routes"){var level=e.gestalt.getLevel(1,0);if(!e.gestalt.isEmpty()&&level.isEmpty()){World.shutdownWorld()}}}},[monitoring])}))};DOMFragment.prototype.handleEvent=function(e){if(e.type==="routes"&&e.gestalt.isEmpty()){for(var i=0;i=0;i--){World.stack[i][0].markPidRunnable(World.stack[i][1])}return result})}};World.prototype.enqueueAction=function(pid,action){this.processActions.push([pid,action])};World.prototype.isInert=function(){return this.eventQueue.length===0&&this.processActions.length===0&&Route.is_emptySet(this.runnablePids)};World.prototype.markPidRunnable=function(pid){this.runnablePids[pid]=[pid]};World.prototype.step=function(){this.dispatchEvents();this.performActions();this.stepChildren();return this.alive&&!this.isInert()};World.prototype.asChild=function(pid,f,omitLivenessCheck){if(!(pid in this.processTable)&&!omitLivenessCheck){console.warn("World.asChild eliding invocation of dead process",pid);return}World.stack.push([this,pid]);var result=null;try{result=f()}catch(e){this.kill(pid,e)}if(World.stack.pop()[0]!==this){throw new Error("Internal error: World stack imbalance")}return result};World.prototype.kill=function(pid,exn){if(exn&&exn.stack){console.log("Process exited",pid,exn,exn.stack)}else{console.log("Process exited",pid,exn)}var p=this.processTable[pid];if(p&&p.behavior.trapexit){this.asChild(pid,function(){return p.behavior.trapexit(exn)})}delete this.processTable[pid];if(p){if(exn){p.exitReason=exn;this.tombstones[pid]=p}this.applyAndIssueRoutingUpdate(p.gestalt,Route.emptyGestalt)}};World.prototype.stepChildren=function(){var pids=this.runnablePids;this.runnablePids={};for(var pid in pids){var p=this.processTable[pid];if(p&&p.behavior.step){var childBusy=this.asChild(pid|0,function(){return p.behavior.step()});if(childBusy)this.markPidRunnable(pid)}}};World.prototype.performActions=function(){var queue=this.processActions;this.processActions=[];var item;while((item=queue.shift())&&this.alive){this.performAction(item[0],item[1])}};World.prototype.dispatchEvents=function(){var queue=this.eventQueue;this.eventQueue=[];var item;while(item=queue.shift()){this.dispatchEvent(item)}};World.prototype.performAction=function(pid,action){switch(action.type){case"spawn":var pid=World.nextPid++;var newGestalt=action.initialGestalt.label(pid);this.processTable[pid]={gestalt:newGestalt,behavior:action.behavior};if(action.behavior.boot){this.asChild(pid,function(){action.behavior.boot()});this.markPidRunnable(pid)}this.applyAndIssueRoutingUpdate(Route.emptyGestalt,newGestalt,pid);break;case"routes":if(pid in this.processTable){var oldGestalt=this.processTable[pid].gestalt;var newGestalt=action.gestalt.label(pid|0);this.processTable[pid].gestalt=newGestalt;this.applyAndIssueRoutingUpdate(oldGestalt,newGestalt,pid)}break;case"message":if(action.metaLevel===0){this.eventQueue.push(action)}else{World.send(action.message,action.metaLevel-1,action.isFeedback)}break;case"shutdownWorld":this.alive=false;World.exit();break;default:var exn=new Error("Action type "+action.type+" not understood");exn.action=action;throw exn}};World.prototype.updateFullGestalt=function(){this.fullGestalt=this.partialGestalt.union(this.downwardGestalt)};World.prototype.issueLocalRoutingUpdate=function(affectedSubgestalt,knownTarget){this.eventQueue.push(pendingRoutingUpdate(this.fullGestalt,affectedSubgestalt,knownTarget))};World.prototype.applyAndIssueRoutingUpdate=function(oldg,newg,knownTarget){knownTarget=typeof knownTarget==="undefined"?null:knownTarget;this.partialGestalt=this.partialGestalt.erasePath(oldg).union(newg);this.updateFullGestalt();this.issueLocalRoutingUpdate(oldg.union(newg),knownTarget);World.updateRoutes([this.partialGestalt.drop()])};World.prototype.dispatchEvent=function(e){switch(e.type){case"pendingRoutingUpdate":var pids=e.affectedSubgestalt.match(e.aggregate);if(e.knownTarget!==null)pids.unshift(e.knownTarget);for(var i=0;i1e3?1e3:this.ttl_ms)}return true};Deduplicator.prototype.expireMessages=function(){var now=+new Date;while(this.queue.length>0&&this.queue[0][0]<=now){var entry=this.queue.shift();delete this.map[entry[1]]}if(this.queue.length===0){clearInterval(this.timerId);this.timerId=null}};function Ground(bootFn){var self=this;this.stepperId=null;World.withWorldStack([[this,-1]],function(){self.world=new World(bootFn)})}Ground.prototype.step=function(){var self=this;return World.withWorldStack([[this,-1]],function(){return self.world.step()})};Ground.prototype.checkPid=function(pid){if(pid!==-1)console.error("Weird pid in Ground markPidRunnable",pid)};Ground.prototype.markPidRunnable=function(pid){this.checkPid(pid);this.startStepping()};Ground.prototype.startStepping=function(){var self=this;if(this.stepperId)return;if(this.step()){this.stepperId=setTimeout(function(){self.stepperId=null;self.startStepping()},0)}};Ground.prototype.stopStepping=function(){if(this.stepperId){clearTimeout(this.stepperId);this.stepperId=null}};Ground.prototype.enqueueAction=function(pid,action){this.checkPid(pid);if(action.type==="routes"){if(!action.gestalt.isEmpty()){console.error("You have subscribed to a nonexistent event source.",action.gestalt.pretty())}}else{console.error("You have sent a message into the outer void.",action)}};module.exports.__=__;module.exports._$=_$;module.exports.sub=sub;module.exports.pub=pub;module.exports.spawn=spawn;module.exports.updateRoutes=updateRoutes;module.exports.sendMessage=sendMessage;module.exports.shutdownWorld=shutdownWorld;module.exports.World=World;module.exports.DemandMatcher=DemandMatcher;module.exports.Deduplicator=Deduplicator;module.exports.Ground=Ground;module.exports.Route=Route},{"./route.js":7}],6:[function(_dereq_,module,exports){var FN_ARGS=/^function\s*[^\(]*\(\s*([^\)]*)\)/m;var FN_ARG_SPLIT=/,/;var STRIP_COMMENTS=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;function formalParameters(fn){var result=[];var fnText=fn.toString().replace(STRIP_COMMENTS,"");var argDecl=fnText.match(FN_ARGS);var args=argDecl[1].split(FN_ARG_SPLIT);for(var i=0;i=0;i--){acc=walk(p[i],acc)}return rseq(SOA,acc)}if(p instanceof $Embedded){return appendMatcher(p.matcher,function(v){return acc})}else{return rseq(JSON.stringify(p),acc)}}}function matchPattern(v,p){var captureCount=0;var result={};try{walk(v,p)}catch(e){if(e.matchPatternFailed)return null;throw e}result.length=captureCount;return result;function walk(v,p){if(p===v)return;if(p===__)return;if(Array.isArray(p)&&Array.isArray(v)&&p.length===v.length){for(var i=0;i=spec.length){if(isCapturing)die("Bad specification: unclosed capture");if(m instanceof $Success){return rseq(EOA,rsuccess(projectSuccess(m.value)))}else{return emptyMatcher}}if(is_emptyMatcher(m))return emptyMatcher;var item=spec[specIndex];var nextIndex=specIndex+1;if(item===EOC){if(!isCapturing)die("Bad specification: unepxected EOC");return walk(false,m,nextIndex)}if(item===SOC){if(isCapturing)die("Bad specification: nested capture");return walk(true,m,nextIndex)}if(item===__){if(m instanceof $WildcardSequence){if(isCapturing){return rwild(walk(isCapturing,m,nextIndex))}else{return walk(isCapturing,m,nextIndex)}}if(m instanceof $Success){return emptyMatcher}var target;if(isCapturing){target=new $Dict;rupdateInplace(target,__,walk(isCapturing,m.get(__),nextIndex));for(var key in m.entries){if(key!==__){var mk=m.get(key);if(is_keyOpen(key)){function cont(mk2){return walk(isCapturing,mk2,nextIndex)}rupdateInplace(target,key,captureNested(mk,cont))}else if(is_keyClose(key)){}else{rupdateInplace(target,key,walk(isCapturing,mk,nextIndex))}}}}else{target=walk(isCapturing,m.get(__),nextIndex);for(var key in m.entries){if(key!==__){var mk=m.get(key);if(is_keyOpen(key)){function cont(mk2){return walk(isCapturing,mk2,nextIndex)}target=union(target,skipNested(mk,cont))}else if(is_keyClose(key)){}else{target=union(target,walk(isCapturing,mk,nextIndex))}}}}return target}var result;if(m instanceof $WildcardSequence){if(is_keyOpen(item)){result=walk(isCapturing,rwildseq(m),nextIndex)}else if(is_keyClose(item)){result=walk(isCapturing,m.matcher,nextIndex)}else{result=walk(isCapturing,m,nextIndex)}}else if(m instanceof $Success){result=emptyMatcher}else{if(is_keyOpen(item)){result=walk(isCapturing,rwildseq(m.get(__)),nextIndex)}else if(is_keyClose(item)){result=emptyMatcher}else{result=walk(isCapturing,m.get(__),nextIndex)}result=union(result,walk(isCapturing,m.get(item),nextIndex))}if(isCapturing){result=rseq(item,result)}return result}function captureNested(m,cont){if(m instanceof $WildcardSequence){return rwildseq(cont(m.matcher))}if(is_emptyMatcher(m)||m instanceof $Success){return emptyMatcher}var target=new $Dict;rupdateInplace(target,__,captureNested(m.get(__),cont));for(var key in m.entries){if(key!==__){var mk=m.get(key);if(is_keyOpen(key)){function cont2(mk2){return captureNested(mk2,cont)}rupdateInplace(target,key,captureNested(mk,cont2))}else if(is_keyClose(key)){rupdateInplace(target,key,cont(mk))}else{rupdateInplace(target,key,captureNested(mk,cont))}}}return target.emptyGuard()}function skipNested(m,cont){if(m instanceof $WildcardSequence){return cont(m.matcher)}if(is_emptyMatcher(m)||m instanceof $Success){return emptyMatcher}var target=skipNested(m.get(__),cont);for(var key in m.entries){if(key!==__){var mk=m.get(key);if(is_keyOpen(key)){function cont2(mk2){return skipNested(mk2,cont)}target=union(target,skipNested(mk,cont2))}else if(is_keyClose(key)){target=union(target,cont(mk))}else{target=union(target,skipNested(mk,cont))}}}return target}}function matcherKeys(m){if(is_emptyMatcher(m))return[];return walkSeq(m,function(vss,vsk){return vss});function walk(m,k){if(m instanceof $WildcardSequence)return null;if(m instanceof $Success)return[];if(m.has(__))return null;var acc=[];for(var key in m.entries){var mk=m.get(key);var piece;if(is_keyOpen(key)){function seqK(vss,vsk){var acc=[];for(var i=0;i");walk(i+4,m.matcher);return}if(m instanceof $Success){var vs=JSON.stringify(typeof m.value==="object"?setToArray(m.value):m.value);acc.push("{"+vs+"}");return}if(m.length===0){acc.push(" ::: empty hash!");return}var needSep=false;var keys=m.sortedKeys();for(var keyi=0;keyi";acc.push(key);walk(i+key.length+1,k)}}function indentStr(i){return new Array(i+1).join(" ")}}function serializeMatcher(m,serializeSuccess){return walk(m);function walk(m){if(is_emptyMatcher(m))return[];if(m instanceof $WildcardSequence){return["...)",walk(m.matcher)]}if(m instanceof $Success){return["",serializeSuccess(m.value)]}var acc=[];for(var key in m.entries){var k=m.entries[key];if(key===__)key=["__"];else if(key===SOA)key=["("];else if(key===EOA)key=[")"];else key=JSON.parse(key);acc.push([key,walk(k)])}return acc}}function deserializeMatcher(r,deserializeSuccess){return walk(r);function walk(r){if(r.length===0)return emptyMatcher;if(r[0]==="...)")return rwildseq(walk(r[1]));if(r[0]==="")return rsuccess(deserializeSuccess(r[1]));var acc=new $Dict;for(var i=0;i0){while(metaLevels.length0?this.union1(gestaltUnion(arguments)):this};function telescopeLevels(levels){var result=shallowCopyArray(levels);for(var i=result.length-2;i>=0;i--){result[i]=new GestaltLevel(union(result[i].subscriptions,result[i+1].subscriptions),union(result[i].advertisements,result[i+1].advertisements))}return result}Gestalt.prototype.telescoped=function(){var mls=[];for(var i=0;i0){while(outputMetaLevels.lengththis.period*1.5){World.send(this.message)}this.mostRecentTrigger=now};module.exports.WakeDetector=WakeDetector},{"./minimart.js":5}],11:[function(_dereq_,module,exports){var Minimart=_dereq_("./minimart.js");var Route=Minimart.Route;var World=Minimart.World;var sub=Minimart.sub;var pub=Minimart.pub;var __=Minimart.__;var _$=Minimart._$;var DEFAULT_RECONNECT_DELAY=100;var MAX_RECONNECT_DELAY=3e4;var DEFAULT_IDLE_TIMEOUT=3e5;var DEFAULT_PING_INTERVAL=DEFAULT_IDLE_TIMEOUT-1e4;function WebSocketConnection(label,wsurl,shouldReconnect){this.label=label;this.sendsAttempted=0;this.sendsTransmitted=0;this.receiveCount=0;this.sock=null;this.wsurl=wsurl;this.shouldReconnect=shouldReconnect?true:false;this.reconnectDelay=DEFAULT_RECONNECT_DELAY;this.localGestalt=Route.emptyGestalt;this.peerGestalt=Route.emptyGestalt;this.prevLocalRoutesMessage=null;this.prevPeerRoutesMessage=null;this.deduplicator=new Minimart.Deduplicator;this.connectionCount=0;this.activityTimestamp=0;this.idleTimeout=DEFAULT_IDLE_TIMEOUT;this.pingInterval=DEFAULT_PING_INTERVAL;this.idleTimer=null;this.pingTimer=null}WebSocketConnection.prototype.clearHeartbeatTimers=function(){if(this.idleTimer){clearTimeout(this.idleTimer);this.idleTimer=null}if(this.pingTimer){clearTimeout(this.pingTimer);this.pingTimer=null}};WebSocketConnection.prototype.recordActivity=function(){var self=this;this.activityTimestamp=+new Date;this.clearHeartbeatTimers();this.idleTimer=setTimeout(function(){self.forceclose()},this.idleTimeout);this.pingTimer=setTimeout(function(){self.safeSend(JSON.stringify("ping"))},this.pingInterval)};WebSocketConnection.prototype.statusRoute=function(status){return pub([this.label+"_state",status])};WebSocketConnection.prototype.relayGestalt=function(){return this.statusRoute(this.isConnected()?"connected":"disconnected").union(pub([this.label,__,__],0,10)).union(sub([this.label,__,__],0,10))};WebSocketConnection.prototype.aggregateGestalt=function(){var self=this;return this.peerGestalt.transform(function(m,metaLevel){return Route.compilePattern(true,[self.label,metaLevel,Route.embeddedMatcher(m)])}).union(this.relayGestalt())};WebSocketConnection.prototype.boot=function(){this.reconnect()};WebSocketConnection.prototype.trapexit=function(){this.forceclose()};WebSocketConnection.prototype.isConnected=function(){return this.sock&&this.sock.readyState===this.sock.OPEN};WebSocketConnection.prototype.safeSend=function(m){try{this.sendsAttempted++;if(this.isConnected()){this.sock.send(m);this.sendsTransmitted++}}catch(e){console.warn("Trapped exn while sending",e)}};WebSocketConnection.prototype.sendLocalRoutes=function(){var newLocalRoutesMessage=JSON.stringify(encodeEvent(Minimart.updateRoutes([this.localGestalt])));if(this.prevLocalRoutesMessage!==newLocalRoutesMessage){this.prevLocalRoutesMessage=newLocalRoutesMessage;this.safeSend(newLocalRoutesMessage)}};WebSocketConnection.prototype.collectMatchers=function(getAdvertisements,level,g){var extractMetaLevels=Route.compileProjection([this.label,_$,__]);var mls=Route.matcherKeys(g.project(extractMetaLevels,getAdvertisements,0,level));for(var i=0;iMAX_RECONNECT_DELAY?MAX_RECONNECT_DELAY+Math.random()*1e3:this.reconnectDelay}};function encodeEvent(e){switch(e.type){case"routes":return["routes",e.gestalt.serialize(function(v){return true})];case"message":return["message",e.message,e.metaLevel,e.isFeedback]}}function decodeAction(j){switch(j[0]){case"routes":return Minimart.updateRoutes([Route.deserializeGestalt(j[1],function(v){return true})]);case"message":return Minimart.sendMessage(j[1],j[2],j[3]);default:throw{message:"Invalid JSON-encoded action: "+JSON.stringify(j)}}}module.exports.WebSocketConnection=WebSocketConnection;module.exports.encodeEvent=encodeEvent;module.exports.decodeAction=decodeAction},{"./minimart.js":5}]},{},[4])(4)}); \ No newline at end of file +!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Minimart=e()}}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o ."+self.fragmentClass,1,self.jQueryWrapFunction);World.spawn({handleEvent:function(e){if(e.type==="routes"){var level=e.gestalt.getLevel(1,0);if(!e.gestalt.isEmpty()&&level.isEmpty()){World.shutdownWorld()}}}},[monitoring])}))};DOMFragment.prototype.handleEvent=function(e){if(e.type==="routes"&&e.gestalt.isEmpty()){for(var i=0;i=0;i--){World.stack[i][0].markPidRunnable(World.stack[i][1])}return result})}};World.prototype.enqueueAction=function(pid,action){this.processActions.push([pid,action])};World.prototype.isInert=function(){return this.eventQueue.length===0&&this.processActions.length===0&&Route.is_emptySet(this.runnablePids)};World.prototype.markPidRunnable=function(pid){this.runnablePids[pid]=[pid]};World.prototype.step=function(){this.dispatchEvents();this.performActions();this.stepChildren();return this.alive&&!this.isInert()};World.prototype.asChild=function(pid,f,omitLivenessCheck){if(!(pid in this.processTable)&&!omitLivenessCheck){console.warn("World.asChild eliding invocation of dead process",pid);return}World.stack.push([this,pid]);var result=null;try{result=f()}catch(e){this.kill(pid,e)}if(World.stack.pop()[0]!==this){throw new Error("Internal error: World stack imbalance")}return result};World.prototype.kill=function(pid,exn){if(exn&&exn.stack){console.log("Process exited",pid,exn,exn.stack)}else{console.log("Process exited",pid,exn)}var p=this.processTable[pid];if(p&&p.behavior.trapexit){this.asChild(pid,function(){return p.behavior.trapexit(exn)})}delete this.processTable[pid];if(p){if(exn){p.exitReason=exn;this.tombstones[pid]=p}this.applyAndIssueRoutingUpdate(p.gestalt,Route.emptyGestalt)}};World.prototype.stepChildren=function(){var pids=this.runnablePids;this.runnablePids={};for(var pid in pids){var p=this.processTable[pid];if(p&&p.behavior.step){var childBusy=this.asChild(pid|0,function(){return p.behavior.step()});if(childBusy)this.markPidRunnable(pid)}}};World.prototype.performActions=function(){var queue=this.processActions;this.processActions=[];var item;while((item=queue.shift())&&this.alive){this.performAction(item[0],item[1])}};World.prototype.dispatchEvents=function(){var queue=this.eventQueue;this.eventQueue=[];var item;while(item=queue.shift()){this.dispatchEvent(item)}};World.prototype.performAction=function(pid,action){switch(action.type){case"spawn":var pid=World.nextPid++;var newGestalt=action.initialGestalt.label(pid);this.processTable[pid]={gestalt:newGestalt,behavior:action.behavior};if(action.behavior.boot){this.asChild(pid,function(){action.behavior.boot()});this.markPidRunnable(pid)}this.applyAndIssueRoutingUpdate(Route.emptyGestalt,newGestalt,pid);break;case"routes":if(pid in this.processTable){var oldGestalt=this.processTable[pid].gestalt;var newGestalt=action.gestalt.label(pid|0);this.processTable[pid].gestalt=newGestalt;this.applyAndIssueRoutingUpdate(oldGestalt,newGestalt,pid)}break;case"message":if(action.metaLevel===0){this.eventQueue.push(action)}else{World.send(action.message,action.metaLevel-1,action.isFeedback)}break;case"shutdownWorld":this.alive=false;World.exit();break;default:var exn=new Error("Action type "+action.type+" not understood");exn.action=action;throw exn}};World.prototype.updateFullGestalt=function(){this.fullGestalt=this.partialGestalt.union(this.downwardGestalt)};World.prototype.issueLocalRoutingUpdate=function(affectedSubgestalt,knownTarget){this.eventQueue.push(pendingRoutingUpdate(this.fullGestalt,affectedSubgestalt,knownTarget))};World.prototype.applyAndIssueRoutingUpdate=function(oldg,newg,knownTarget){knownTarget=typeof knownTarget==="undefined"?null:knownTarget;this.partialGestalt=this.partialGestalt.erasePath(oldg).union(newg);this.updateFullGestalt();this.issueLocalRoutingUpdate(oldg.union(newg),knownTarget);World.updateRoutes([this.partialGestalt.drop()])};World.prototype.dispatchEvent=function(e){switch(e.type){case"pendingRoutingUpdate":var pids=e.affectedSubgestalt.match(e.aggregate);if(e.knownTarget!==null)pids.unshift(e.knownTarget);for(var i=0;i1e3?1e3:this.ttl_ms)}return true};Deduplicator.prototype.expireMessages=function(){var now=+new Date;while(this.queue.length>0&&this.queue[0][0]<=now){var entry=this.queue.shift();delete this.map[entry[1]]}if(this.queue.length===0){clearInterval(this.timerId);this.timerId=null}};function Ground(bootFn){var self=this;this.stepperId=null;World.withWorldStack([[this,-1]],function(){self.world=new World(bootFn)})}Ground.prototype.step=function(){var self=this;return World.withWorldStack([[this,-1]],function(){return self.world.step()})};Ground.prototype.checkPid=function(pid){if(pid!==-1)console.error("Weird pid in Ground markPidRunnable",pid)};Ground.prototype.markPidRunnable=function(pid){this.checkPid(pid);this.startStepping()};Ground.prototype.startStepping=function(){var self=this;if(this.stepperId)return;if(this.step()){this.stepperId=setTimeout(function(){self.stepperId=null;self.startStepping()},0)}};Ground.prototype.stopStepping=function(){if(this.stepperId){clearTimeout(this.stepperId);this.stepperId=null}};Ground.prototype.enqueueAction=function(pid,action){this.checkPid(pid);if(action.type==="routes"){if(!action.gestalt.isEmpty()){console.error("You have subscribed to a nonexistent event source.",action.gestalt.pretty())}}else{console.error("You have sent a message into the outer void.",action)}};module.exports.__=__;module.exports._$=_$;module.exports.sub=sub;module.exports.pub=pub;module.exports.spawn=spawn;module.exports.updateRoutes=updateRoutes;module.exports.sendMessage=sendMessage;module.exports.shutdownWorld=shutdownWorld;module.exports.World=World;module.exports.DemandMatcher=DemandMatcher;module.exports.Deduplicator=Deduplicator;module.exports.Ground=Ground;module.exports.Route=Route},{"./route.js":7}],6:[function(_dereq_,module,exports){var FN_ARGS=/^function\s*[^\(]*\(\s*([^\)]*)\)/m;var FN_ARG_SPLIT=/,/;var STRIP_COMMENTS=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;function formalParameters(fn){var result=[];var fnText=fn.toString().replace(STRIP_COMMENTS,"");var argDecl=fnText.match(FN_ARGS);var args=argDecl[1].split(FN_ARG_SPLIT);for(var i=0;i=0;i--){acc=walk(p[i],acc)}return rseq(SOA,acc)}if(p instanceof $Embedded){return appendMatcher(p.matcher,function(v){return acc})}else{return rseq(JSON.stringify(p),acc)}}}function matchPattern(v,p){var captureCount=0;var result={};try{walk(v,p)}catch(e){if(e.matchPatternFailed)return null;throw e}result.length=captureCount;return result;function walk(v,p){if(p===v)return;if(p===__)return;if(Array.isArray(p)&&Array.isArray(v)&&p.length===v.length){for(var i=0;i=spec.length){if(isCapturing)die("Bad specification: unclosed capture");if(m instanceof $Success){return rseq(EOA,rsuccess(projectSuccess(m.value)))}else{return emptyMatcher}}if(is_emptyMatcher(m))return emptyMatcher;var item=spec[specIndex];var nextIndex=specIndex+1;if(item===EOC){if(!isCapturing)die("Bad specification: unepxected EOC");return walk(false,m,nextIndex)}if(item===SOC){if(isCapturing)die("Bad specification: nested capture");return walk(true,m,nextIndex)}if(item===__){if(m instanceof $WildcardSequence){if(isCapturing){return rwild(walk(isCapturing,m,nextIndex))}else{return walk(isCapturing,m,nextIndex)}}if(m instanceof $Success){return emptyMatcher}var target;if(isCapturing){target=new $Dict;rupdateInplace(target,__,walk(isCapturing,m.get(__),nextIndex));for(var key in m.entries){if(key!==__){var mk=m.get(key);if(is_keyOpen(key)){function cont(mk2){return walk(isCapturing,mk2,nextIndex)}rupdateInplace(target,key,captureNested(mk,cont))}else if(is_keyClose(key)){}else{rupdateInplace(target,key,walk(isCapturing,mk,nextIndex))}}}}else{target=walk(isCapturing,m.get(__),nextIndex);for(var key in m.entries){if(key!==__){var mk=m.get(key);if(is_keyOpen(key)){function cont(mk2){return walk(isCapturing,mk2,nextIndex)}target=union(target,skipNested(mk,cont))}else if(is_keyClose(key)){}else{target=union(target,walk(isCapturing,mk,nextIndex))}}}}return target}var result;if(m instanceof $WildcardSequence){if(is_keyOpen(item)){result=walk(isCapturing,rwildseq(m),nextIndex)}else if(is_keyClose(item)){result=walk(isCapturing,m.matcher,nextIndex)}else{result=walk(isCapturing,m,nextIndex)}}else if(m instanceof $Success){result=emptyMatcher}else{if(is_keyOpen(item)){result=walk(isCapturing,rwildseq(m.get(__)),nextIndex)}else if(is_keyClose(item)){result=emptyMatcher}else{result=walk(isCapturing,m.get(__),nextIndex)}result=union(result,walk(isCapturing,m.get(item),nextIndex))}if(isCapturing){result=rseq(item,result)}return result}function captureNested(m,cont){if(m instanceof $WildcardSequence){return rwildseq(cont(m.matcher))}if(is_emptyMatcher(m)||m instanceof $Success){return emptyMatcher}var target=new $Dict;rupdateInplace(target,__,captureNested(m.get(__),cont));for(var key in m.entries){if(key!==__){var mk=m.get(key);if(is_keyOpen(key)){function cont2(mk2){return captureNested(mk2,cont)}rupdateInplace(target,key,captureNested(mk,cont2))}else if(is_keyClose(key)){rupdateInplace(target,key,cont(mk))}else{rupdateInplace(target,key,captureNested(mk,cont))}}}return target.emptyGuard()}function skipNested(m,cont){if(m instanceof $WildcardSequence){return cont(m.matcher)}if(is_emptyMatcher(m)||m instanceof $Success){return emptyMatcher}var target=skipNested(m.get(__),cont);for(var key in m.entries){if(key!==__){var mk=m.get(key);if(is_keyOpen(key)){function cont2(mk2){return skipNested(mk2,cont)}target=union(target,skipNested(mk,cont2))}else if(is_keyClose(key)){target=union(target,cont(mk))}else{target=union(target,skipNested(mk,cont))}}}return target}}function matcherKeys(m){if(is_emptyMatcher(m))return[];return walkSeq(m,function(vss,vsk){return vss});function walk(m,k){if(m instanceof $WildcardSequence)return null;if(m instanceof $Success)return[];if(m.has(__))return null;var acc=[];for(var key in m.entries){var mk=m.get(key);var piece;if(is_keyOpen(key)){function seqK(vss,vsk){var acc=[];for(var i=0;i");walk(i+4,m.matcher);return}if(m instanceof $Success){var vs=JSON.stringify(typeof m.value==="object"?setToArray(m.value):m.value);acc.push("{"+vs+"}");return}if(m.length===0){acc.push(" ::: empty hash!");return}var needSep=false;var keys=m.sortedKeys();for(var keyi=0;keyi";acc.push(key);walk(i+key.length+1,k)}}function indentStr(i){return new Array(i+1).join(" ")}}function serializeMatcher(m,serializeSuccess){return walk(m);function walk(m){if(is_emptyMatcher(m))return[];if(m instanceof $WildcardSequence){return["...)",walk(m.matcher)]}if(m instanceof $Success){return["",serializeSuccess(m.value)]}var acc=[];for(var key in m.entries){var k=m.entries[key];if(key===__)key=["__"];else if(key===SOA)key=["("];else if(key===EOA)key=[")"];else key=JSON.parse(key);acc.push([key,walk(k)])}return acc}}function deserializeMatcher(r,deserializeSuccess){return walk(r);function walk(r){if(r.length===0)return emptyMatcher;if(r[0]==="...)")return rwildseq(walk(r[1]));if(r[0]==="")return rsuccess(deserializeSuccess(r[1]));var acc=new $Dict;for(var i=0;i0){while(metaLevels.length0?this.union1(gestaltUnion(arguments)):this};function telescopeLevels(levels){var result=shallowCopyArray(levels);for(var i=result.length-2;i>=0;i--){result[i]=new GestaltLevel(union(result[i].subscriptions,result[i+1].subscriptions),union(result[i].advertisements,result[i+1].advertisements))}return result}Gestalt.prototype.telescoped=function(){var mls=[];for(var i=0;i0){while(outputMetaLevels.lengththis.period*1.5){World.send(this.message)}this.mostRecentTrigger=now};module.exports.WakeDetector=WakeDetector},{"./minimart.js":5}],11:[function(_dereq_,module,exports){var Minimart=_dereq_("./minimart.js");var Route=Minimart.Route;var World=Minimart.World;var sub=Minimart.sub;var pub=Minimart.pub;var __=Minimart.__;var _$=Minimart._$;var DEFAULT_RECONNECT_DELAY=100;var MAX_RECONNECT_DELAY=3e4;var DEFAULT_IDLE_TIMEOUT=3e5;var DEFAULT_PING_INTERVAL=DEFAULT_IDLE_TIMEOUT-1e4;function WebSocketConnection(label,wsurl,shouldReconnect){this.label=label;this.sendsAttempted=0;this.sendsTransmitted=0;this.receiveCount=0;this.sock=null;this.wsurl=wsurl;this.shouldReconnect=shouldReconnect?true:false;this.reconnectDelay=DEFAULT_RECONNECT_DELAY;this.localGestalt=Route.emptyGestalt;this.peerGestalt=Route.emptyGestalt;this.prevLocalRoutesMessage=null;this.prevPeerRoutesMessage=null;this.deduplicator=new Minimart.Deduplicator;this.connectionCount=0;this.activityTimestamp=0;this.idleTimeout=DEFAULT_IDLE_TIMEOUT;this.pingInterval=DEFAULT_PING_INTERVAL;this.idleTimer=null;this.pingTimer=null}WebSocketConnection.prototype.clearHeartbeatTimers=function(){if(this.idleTimer){clearTimeout(this.idleTimer);this.idleTimer=null}if(this.pingTimer){clearTimeout(this.pingTimer);this.pingTimer=null}};WebSocketConnection.prototype.recordActivity=function(){var self=this;this.activityTimestamp=+new Date;this.clearHeartbeatTimers();this.idleTimer=setTimeout(function(){self.forceclose()},this.idleTimeout);this.pingTimer=setTimeout(function(){self.safeSend(JSON.stringify("ping"))},this.pingInterval)};WebSocketConnection.prototype.statusRoute=function(status){return pub([this.label+"_state",status])};WebSocketConnection.prototype.relayGestalt=function(){return this.statusRoute(this.isConnected()?"connected":"disconnected").union(pub([this.label,__,__],0,10)).union(sub([this.label,__,__],0,10))};WebSocketConnection.prototype.aggregateGestalt=function(){var self=this;return this.peerGestalt.transform(function(m,metaLevel){return Route.compilePattern(true,[self.label,metaLevel,Route.embeddedMatcher(m)])}).union(this.relayGestalt())};WebSocketConnection.prototype.boot=function(){this.reconnect()};WebSocketConnection.prototype.trapexit=function(){this.forceclose()};WebSocketConnection.prototype.isConnected=function(){return this.sock&&this.sock.readyState===this.sock.OPEN};WebSocketConnection.prototype.safeSend=function(m){try{this.sendsAttempted++;if(this.isConnected()){this.sock.send(m);this.sendsTransmitted++}}catch(e){console.warn("Trapped exn while sending",e)}};WebSocketConnection.prototype.sendLocalRoutes=function(){var newLocalRoutesMessage=JSON.stringify(encodeEvent(Minimart.updateRoutes([this.localGestalt])));if(this.prevLocalRoutesMessage!==newLocalRoutesMessage){this.prevLocalRoutesMessage=newLocalRoutesMessage;this.safeSend(newLocalRoutesMessage)}};WebSocketConnection.prototype.collectMatchers=function(getAdvertisements,level,g){var extractMetaLevels=Route.compileProjection([this.label,_$,__]);var mls=Route.matcherKeys(g.project(extractMetaLevels,getAdvertisements,0,level));for(var i=0;iMAX_RECONNECT_DELAY?MAX_RECONNECT_DELAY+Math.random()*1e3:this.reconnectDelay}};function encodeEvent(e){switch(e.type){case"routes":return["routes",e.gestalt.serialize(function(v){return true})];case"message":return["message",e.message,e.metaLevel,e.isFeedback]}}function decodeAction(j){switch(j[0]){case"routes":return Minimart.updateRoutes([Route.deserializeGestalt(j[1],function(v){return true})]);case"message":return Minimart.sendMessage(j[1],j[2],j[3]);default:throw{message:"Invalid JSON-encoded action: "+JSON.stringify(j)}}}module.exports.WebSocketConnection=WebSocketConnection;module.exports.encodeEvent=encodeEvent;module.exports.decodeAction=decodeAction},{"./minimart.js":5}]},{},[4])(4)}); \ No newline at end of file