tgi-store-mongodb
Version:
1 lines • 66 kB
JavaScript
(function(){"use strict";function t(e,r){var o;if(!1==this instanceof t)throw new Error("new operator required");if("string"==typeof e){var n=e;(e={}).name=n,"string"==typeof r&&(e.type=r)}e=e||{},this.name=e.name||null,this.label=e.label||e.name,this.label&&(this.label=this.label.charAt(0).toUpperCase()+this.label.slice(1)),this.type=e.type||"String",o=function(t){var e=t.split("(");return e[1]=parseInt(e[1]),e}(this.type),this.type=o[0],this.hint=e.hint||{},void 0!==e.hidden&&(this.hidden=e.hidden),this.validationRule=e.validationRule||{};var i=[],s=["name","type","label","hint","hidden","value","validationRule"];switch(this.type){case"ID":i=_(e,s),this.value=e.value||null;break;case"String":i=_(e,s.concat(["placeHolder","quickPick","size"])),this.size=o[1]?o[1]:"number"==typeof e.size?e.size:e.size||50,this.value=e.value||null,e.quickPick&&(this.quickPick=e.quickPick),this.placeHolder=e.placeHolder||null;break;case"Date":i=_(e,s.concat("placeHolder")),this.value=e.value||null,this.placeHolder=e.placeHolder||null;break;case"Boolean":i=_(e,s),!1===e.value?this.value=!1:this.value=e.value||null;break;case"Number":i=_(e,s.concat("placeHolder")),0===e.value?this.value=0:this.value=e.value||null,this.placeHolder=e.placeHolder||null;break;case"Model":i=_(e,s),this.value=e.value||null,this.value instanceof t.ModelID&&(this.modelType=this.value.modelType);break;case"Group":i=_(e,s),this.value=e.value||null;break;case"Table":i=_(e,s.concat("group")),this.value=e.value||null,this.group=e.group||null;break;case"Object":i=_(e,s),this.value=e.value||null}for(var a=this.getObjectStateErrors(),c=0;c<i.length;c++)a.push("invalid property: "+i[c]);if(a.length>1)throw new Error("error creating Attribute: multiple errors");if(a.length)throw new Error("error creating Attribute: "+a[0]);this._eventListeners=[],this._errorConditions={}}function e(t){if(!1==this instanceof e)throw new Error("new operator required");"function"==typeof t&&(t={type:"Function",contents:t}),t instanceof d&&(t={type:"Procedure",contents:t});var r,o=_(t=t||{},["name","description","type","contents","scope","timeout","theme","icon","bucket","presentationMode","location","images"]),n=[];for(r=0;r<o.length;r++)n.push("invalid property: "+o[r]);if(n.length>1)throw new Error("error creating Command: multiple errors");if(n.length)throw new Error("error creating Command: "+n[0]);for(r in t)this[r]=t[r];if(this.name=this.name||"a command","string"!=typeof this.name)throw new Error("name must be string");if(void 0===this.description&&(this.description=this.name+" Command"),void 0===this.type&&(this.type="Stub"),!q(e.getTypes(),this.type))throw new Error("Invalid command type: "+this.type);switch(this.type){case"Stub":break;case"Menu":if(!(this.contents instanceof Array))throw new Error("contents must be array of menu items");if(!this.contents.length)throw new Error("contents must be array of menu items");for(r in this.contents)if(this.contents.hasOwnProperty(r)&&"string"!=typeof this.contents[r]&&!(this.contents[r]instanceof e))throw new Error("contents must be array of menu items");break;case"Presentation":if(!(this.contents instanceof g))throw new Error("contents must be a Presentation");if(this.presentationMode=this.presentationMode||"View",!q(e.getPresentationModes(),this.presentationMode))throw new Error("Invalid presentationMode: "+this.presentationMode);break;case"Function":if("function"!=typeof this.contents)throw new Error("contents must be a Function");break;case"Procedure":if(!(this.contents instanceof d))throw new Error("contents must be a Procedure");break;default:throw new TypeError}if(void 0!==this.scope&&!(this.scope instanceof f||this.scope instanceof p))throw new Error("optional scope property must be Model or List");if(void 0!==this.timeout&&"number"!=typeof this.timeout)throw new Error("timeout must be a Number");if(void 0!==this.timeout&&"number"!=typeof this.timeout)throw new Error("timeout must be a Number");if(void 0!==this.theme){if("string"!=typeof this.theme)throw new Error("invalid theme");if(!q(["default","primary","success","info","warning","danger","link"],this.theme))throw new Error("invalid theme")}if(void 0!==this.icon){if("string"!=typeof this.icon)throw new Error("invalid icon");if(!q(["fa","glyphicon"],this.icon.split("-")[0])||!this.icon.split("-")[1])throw new Error("invalid icon")}this._eventListeners=[]}function r(e){if(!1==this instanceof r)throw new Error("new operator required");if(!1==e instanceof t.ModelID)throw new Error("Attribute.ModelID required in constructor");this.dateCreated=new Date,this.modelID=e,this.attributeValues={}}function o(t){if(!1==this instanceof o)throw new Error("new operator required");(t=t||{}).name=t.name||"(unnamed)",t.description=t.description||"a Interface",t.vendor=t.vendor||null;var e,r=_(t,["name","description","vendor"]),n=[];for(e=0;e<r.length;e++)n.push("invalid property: "+r[e]);if(n.length>1)throw new Error("error creating Interface: multiple errors");if(n.length)throw new Error("error creating Interface: "+n[0]);this.startcallback=null,this.stopcallback=null,this.mocks=[],this.mockPending=!1;for(e in t)this[e]=t[e]}function n(t,e){if(!1==this instanceof n)throw new Error("new operator required");if(void 0===t)throw new Error("message type required");if(!q(n.getTypes(),t))throw new Error("Invalid message type: "+t);this.type=t,this.contents=e}function i(t){if(!1==this instanceof i)throw new Error("new operator required");if("string"==typeof t){var r=t;(t={}).type=r}if(t=t||{},this.type=t.type||null,t.value&&(this.value=t.value),!this.type||"string"!=typeof this.type)throw new Error("Request type required");switch(this.type){case"Command":if(this.command=t.command||null,!(this.command instanceof e))throw new Error("command object required")}}function s(t){if(!1==this instanceof s)throw new Error("new operator required");this.contents=t||"",this._eventListeners=[]}function a(t,e){if(!1==this instanceof a)throw new Error("new operator required");if("string"!=typeof t)throw new Error("argument must a url string");if("function"!=typeof e)throw new Error("argument must a callback");var r=this;r.connected=!1,r.initialConnect=!0,r.location=t,""===r.location&&(r.location="http host"),r.socket=io.connect(t,{reconnection:!1}),r.socket.on("connect",function(){r.connected=!0,r.initialConnect=!1,console.log("socket.io ("+r.location+") connected"),e.call(r,new n("Connected",""))}),r.socket.on("connecting",function(){console.log("socket.io ("+r.location+") connecting")}),r.socket.on("error",function(t){var o="general error with "+r.location+(t?", reason "+t:"");console.error(o),r.initialConnect&&e.call(r,new n("Error",o))}),r.socket.on("connect_error",function(t){var o="connect error with "+r.location+(t?", reason "+t:"");console.error(o),r.initialConnect&&e.call(r,new n("Error",o))}),r.socket.on("connect_failed",function(t){var o="connect failed with "+r.location+(t?", reason "+t:"");console.error(o),r.initialConnect&&e.call(r,new n("Error",o))}),r.socket.on("message",function(t){r.rawCallBack?r.rawCallBack(t):console.log("socket.io ("+r.location+") message: "+t)}),r.socket.on("disconnect",function(t){r.connected=!1,console.log("socket.io ("+r.location+") disconnect: "+t)})}function c(e,r,o){if(!1==this instanceof c)throw new Error("new operator required");if(!(e instanceof f))throw new Error("argument must be a Model");if("object"!=typeof r)throw new Error("object expected");if(!(o instanceof Array))throw new Error("array of attributes expected");this.primaryModel=e,this.relatedModels=r,this.attributes=o;var n=new t("id","ID");n.model=e,this.attributes.unshift(n);for(var i in r)if(r.hasOwnProperty(i)){var s=r[i];if("object"!=typeof s)throw new Error("relatedModel key values expect object");if(void 0===s.id)throw new Error("relatedModel key values expect object with id key");if(void 0===s.model)throw new Error("relatedModel key values expect object with model key");if(!(s.id instanceof t))throw new Error("relatedModel id must be a Attribute");if(!(s.model instanceof f))throw new Error("relatedModel model must be a Model")}for(var a=0;a<o.length;a++){var h=o[a];if(!(h instanceof t))throw new Error("attribute array must contain Attributes");if(!(h.model instanceof f))throw new Error("attribute array must contain Attributes with model references")}}function h(e){if(!1==this instanceof h)throw new Error("new operator required");(e=e||{}).attributes||(e.attributes=[]);var r=new t.ModelID(new E);e.attributes.push(new t({name:"user",type:"Model",value:r})),e.attributes.push(new t({name:"deltas",type:"Object",value:{}})),f.call(this,e),this.modelType="Workspace"}var l=this,u={CORE:function(){return{version:"0.4.43",Application:y,Attribute:t,Command:e,Delta:r,Interface:o,List:p,Log:v,MemoryStore:k,Message:n,Model:f,Presentation:g,Procedure:d,REPLInterface:w,Request:i,Session:b,Store:m,Text:s,Transport:a,User:E,View:c,Workspace:h,inheritPrototype:P,getInvalidProperties:_,getConstructorFromModelType:M,createModelFromModelType:S,trim:T,ltrim:D,rtrim:x,left:C,center:I,right:O,lpad:A,rpad:R,cpad:L,contains:q}}};t.ModelID=function(e){if(!1==this instanceof t.ModelID)throw new Error("new operator required");if(!1==e instanceof f)throw new Error("must be constructed with Model");var r=e.getShortName();r&&(this.name=r),this.value=e.get("id"),this.constructorFunction=e.constructor,this.modelType=e.modelType},t.ModelID.prototype.toString=function(){return this.name?this.modelType+" "+this.name:this.modelType+" "+this.value},t.prototype.toString=function(){return null===this.name?"new Attribute":"Attribute: "+this.name+" = "+this.value},t.prototype.onEvent=function(t,e){if(!(t instanceof Array)){if("string"!=typeof t)throw new Error("subscription string or array required");t=[t]}if("function"!=typeof e)throw new Error("callback is required");for(var r in t)if(t.hasOwnProperty(r)&&"*"!=t[r]&&!q(["StateChange","Validate"],t[r]))throw new Error("Unknown command event: "+t[r]);return this._eventListeners.push({events:t,callback:e}),this},t.prototype.offEvent=function(){this._eventListeners=[]},t.prototype._emitEvent=function(t){var e;for(e in this._eventListeners)if(this._eventListeners.hasOwnProperty(e)){var r=this._eventListeners[e];(r.events.length&&"*"===r.events[0]||q(r.events,t))&&r.callback.call(this,t)}},t.prototype.get=function(){return this.value},t.prototype.set=function(e){switch(this.type){case"Model":if(!(e instanceof t.ModelID))throw new Error("set error: value must be Attribute.ModelID");this.value=e;break;default:this.value=e}return this._emitEvent("StateChange"),this.value},t.prototype.coerce=function(t){var e,r=t;switch(this.type){case"String":return void 0===r?"":"boolean"!=typeof r||r?r?(r=t.toString()).length>this.size?r.substring(0,this.size):r:"":"false";case"Number":return void 0===r?0:r?("string"==typeof r?(r=(e=(r=r.replace(/^\s+|\s+$/g,"")).split(" ")).length?e[0]:"",r=Number(r.replace(/[^/0-9\ \.]+/g,""))):r=Number(r),r||0):0;case"Boolean":return void 0!==r&&("string"==typeof r?"Y"===(r=r.toUpperCase())||"YES"===r||"T"===r||"TRUE"===r||"1"===r:!!r);case"Date":return"string"==typeof r&&2==r.split("/").length&&(r=r+"/"+(new Date).getFullYear()),new Date(r)}throw Error("coerce cannot determine appropriate value")},t.prototype.getObjectStateErrors=function(){var e;switch(this.validationErrors=[],this.name||this.validationErrors.push("name required"),q(["ID","String","Date","Boolean","Number","Model","Group","Table","Object"],this.type)||this.validationErrors.push("Invalid type: "+this.type),this.type){case"ID":break;case"String":"number"!=typeof this.size&&this.validationErrors.push("size must be a number from 1 to 255"),(this.size<1||this.size>255)&&this.validationErrors.push("size must be a number from 1 to 255"),null!==this.value&&"string"!=typeof this.value&&this.validationErrors.push("value must be null or a String");break;case"Date":null===this.value||this.value instanceof Date||this.validationErrors.push("value must be null or a Date");break;case"Boolean":null!==this.value&&"boolean"!=typeof this.value&&this.validationErrors.push("value must be null or a Boolean");break;case"Number":null!==this.value&&"number"!=typeof this.value&&this.validationErrors.push("value must be null or a Number");break;case"Model":this.value instanceof t.ModelID||this.validationErrors.push("value must be Attribute.ModelID");break;case"Group":if(null===this.value||this.value instanceof Array)for(e in this.value)this.value.hasOwnProperty(e)&&(this.value[e]instanceof t||this.validationErrors.push("each element in group must be instance of Attribute"),this.value[e].getObjectStateErrors().length&&this.validationErrors.push("group contains invalid members"));else this.validationErrors.push("value must be null or an array");break;case"Table":if(this.group instanceof t)if(this.group.value instanceof Array)if(this.group.value.length<1)this.validationErrors.push("group property value must contain at least one Attribute");else for(e in this.group.value)this.group.value.hasOwnProperty(e)&&(this.group.value[e]instanceof t||this.validationErrors.push("each element in group must be instance of Attribute"),this.group.value[e].getObjectStateErrors().length&&this.validationErrors.push("group contains invalid members"));else this.validationErrors.push("group.value must be an array");else this.validationErrors.push("group property required")}var r=_(this.validationRule,["required","range","isOneOf","isValidModel"]);return r.length&&this.validationErrors.push("invalid validationRule: "+r),this.validationMessage=this.validationErrors.length>0?this.validationErrors[0]:"",this.validationErrors},t.prototype.validate=function(t){if("function"!=typeof t)throw new Error("callback is required");this.getObjectStateErrors(),this._emitEvent("Validate");var e;for(e in this._errorConditions)this._errorConditions.hasOwnProperty(e)&&this.validationErrors.push(this._errorConditions[e]);this.validationRule.required&&!this.value&&("Number"==this.type?0!==this.value&&this.validationErrors.push(this.label+" required"):"Boolean"==this.type?!1!==this.value&&this.validationErrors.push(this.label+" required"):this.validationErrors.push(this.label+" required")),this.validationRule.range&&(this.validationRule.range instanceof Array||(this.validationRule.range=[this.validationRule.range]),(this.validationRule.range[0]||0===this.validationRule.range[0])&&this.value<this.validationRule.range[0]&&this.validationErrors.push(this.label+" must be at least "+this.validationRule.range[0]),(this.validationRule.range[1]||0===this.validationRule.range[1])&&this.value>this.validationRule.range[1]&&this.validationErrors.push(this.label+" must be no more than "+this.validationRule.range[1])),this.validationRule.isOneOf&&(this.validationRule.isOneOf instanceof Array||(this.validationRule.isOneOf=[this.validationRule.isOneOf]),-1==this.validationRule.isOneOf.indexOf(this.value)&&this.validationErrors.push(this.label+" invalid")),this.validationMessage=this.validationErrors.length>0?this.validationErrors[0]:"",this._emitEvent("StateChange"),t.call(this)},t.prototype.setError=function(t,e){if(t=t||"",e=e||"",!t)throw new Error("condition required");if(!e)throw new Error("description required");this._errorConditions[t]=e},t.prototype.clearError=function(t){if(!(t=t||""))throw new Error("condition required");delete this._errorConditions[t]},t.getTypes=function(){return["ID","String","Date","Boolean","Number","Model","Group","Table","Object"].slice(0)},t.getEvents=function(){return["StateChange","Validate"].slice(0)},e.prototype.toString=function(){return this.type+" Command: "+this.name},e.prototype.onEvent=function(t,e){if(!(t instanceof Array)){if("string"!=typeof t)throw new Error("subscription string or array required");t=[t]}if("function"!=typeof e)throw new Error("callback is required");for(var r in t)if(t.hasOwnProperty(r)&&"*"!=t[r]&&!q(["BeforeExecute","AfterExecute","Error","Aborted","Completed"],t[r]))throw new Error("Unknown command event: "+t[r]);this._eventListeners.push({events:t,callback:e})},e.prototype._emitEvent=function(t,e){var r;for(r in this._eventListeners)if(this._eventListeners.hasOwnProperty(r)){var o=this._eventListeners[r];(o.events.length&&"*"===o.events[0]||q(o.events,t))&&o.callback.call(this,t,e)}},e.prototype.execute=function(t){function r(){for(var t=i.contents.tasks||[],e=0;e<t.length;e++){var r=!0;if(void 0===t[e].command.status){for(var o in t[e].requires){if("string"==typeof t[e].requires[o])for(var n=0;n<t.length;n++)t[n].label==t[e].requires[o]&&(!t[n].command.status||t[n].command.status<=0)&&(r=!1);if("number"==typeof t[e].requires[o])if(-1==t[e].requires[o])"0"!=e&&(!t[e-1].command.status||t[e-1].command.status<=0)&&(r=!1);else{var s=t[e].requires[o];(!t[s].command.status||t[s].command.status<=0)&&(r=!1)}}r&&t[e].command.execute()}}}function n(t,e){var o=i.contents.tasks,n=!0;switch(t){case"Error":i._emitEvent("Error",e);break;case"Aborted":i.abort();break;case"Completed":for(var s in o)o.hasOwnProperty(s)&&(o[s].command.status&&0!==o[s].command.status||(n=!1));n?i.complete():r()}}var i=this,s=arguments;if(!i.type)throw new Error("command not implemented");if(!q(["Function","Procedure","Menu","Presentation"],i.type))throw new Error("command type "+i.type+" not implemented");var a;switch(i.type){case"Presentation":if(!(i.contents instanceof g))throw new Error("contents must be a Presentation");if((a=i.contents.getObjectStateErrors()).length)throw a.length>1?new Error("error executing Presentation: multiple errors"):new Error("error executing Presentation: "+a[0]);if(!(t instanceof o))throw new Error("interface param required")}i._emitEvent("BeforeExecute");try{switch(i.type){case"Function":setTimeout(function(){i.status=0;try{i.contents.apply(i,s)}catch(t){i.error=t,i._emitEvent("Error",t),i._emitEvent("Completed"),i.status=-1}},0);break;case"Procedure":setTimeout(function(){i.status=0;for(var t=i.contents.tasks||[],o=0;o<t.length;o++){if("function"==typeof t[o]){var s=t[o];t[o]={requires:[-1],command:new e({type:"Function",contents:s})}}t[o].command._parentProcedure||(t[o].command._taskIndex=o,t[o].command._parentProcedure=i,t[o].command.onEvent("*",n)),t[o].command.status=void 0}r()},0);break;case"Menu":t.render(i,"View");break;case"Presentation":i.contents.preRenderCallback?i.contents.preRenderCallback(i,function(){t.render(i)}):t.render(i)}}catch(t){i.error=t,i._emitEvent("Error",t),i._emitEvent("Completed"),i.status=-1}i._emitEvent("AfterExecute")},e.prototype.abort=function(){this._emitEvent("Aborted"),this.status=-1,this._emitEvent("Completed")},e.prototype.complete=function(){this.status=1,this._emitEvent("Completed")},e.prototype.restart=function(){this.status=void 0,this._emitEvent("Restarted"),this.execute()},e.getTypes=function(){return["Stub","Menu","Presentation","Function","Procedure"].slice(0)},e.getEvents=function(){return["BeforeExecute","AfterExecute","Error","Aborted","Completed"].slice(0)},e.getPresentationModes=function(){return["View","Edit","List"].slice(0)},o.prototype.toString=function(){return this.description},o.prototype.canMock=function(){return!0},o.prototype.doMock=function(){var t,e;if(this.mockPending=!1,!(this.mocks.length<1)){var r=this.mocks.shift();if("ok"!=r.type)if("yes"!=r.type&&"no"!=r.type&&"cancel"!=r.type)if("ask"!=r.type)if("choose"!=r.type){this.dispatch(r),this.mockPending=!0;var n=this;setTimeout(function(){n.doMock()},0)}else this.choosecallback?(t=this.choosecallback,delete this.choosecallback,t(o.firstMatch(r.value,this.chooseChoices))):(this.choosePending=!0,this.chooseResponse=r.value);else this.askcallback?(t=this.askcallback,delete this.askcallback,t(r.value)):(this.askPending=!0,this.askResponse=r.value);else{switch(r.type){case"yes":e=!0;break;case"no":e=!1;break;case"cancel":e=void 0}this.yesnocallback?(t=this.yesnocallback,delete this.yesnocallback,t(e)):(this.yesnoPending=!0,this.yesnoResponse=e)}else this.okcallback?(t=this.okcallback,delete this.okcallback,t()):this.okPending=!0}},o.prototype.mockRequest=function(t){if(!(t instanceof Array||t instanceof i))throw new Error("missing request parameter");t instanceof Array||(t=[t]);var e;for(e=0;e<t.length;e++)if(!1==t[e]instanceof i)throw new Error("invalid request parameter");for(e=0;e<t.length;e++)this.mocks.push(t[e]);this.mockPending||this.doMock()},o.prototype.start=function(t,e,r){if(!(t instanceof y))throw new Error("Application required");if(!(e instanceof g))throw new Error("presentation required");if("function"!=typeof r)throw new Error("callback required");this.application=t,this.presentation=e,this.startcallback=r},o.prototype.stop=function(t){if("function"!=typeof t)throw new Error("callback required")},o.prototype.dispatch=function(t,e){if(!1==t instanceof i)throw new Error("Request required");if(e&&"function"!=typeof e)throw new Error("response callback is not a function");this.application&&this.application.dispatch(t)||this.startcallback&&this.startcallback(t)},o.prototype.notify=function(t){if(!1==t instanceof n)throw new Error("Message required")},o.prototype.render=function(t,r){if(!1==t instanceof e)throw new Error("Command object required")},o.prototype.info=function(t){if(!t||"string"!=typeof t)throw new Error("text required")},o.prototype.done=function(t){if(!t||"string"!=typeof t)throw new Error("text required")},o.prototype.warn=function(t){if(!t||"string"!=typeof t)throw new Error("text required")},o.prototype.err=function(t){if(!t||"string"!=typeof t)throw new Error("text required")},o.prototype.ok=function(t,e){if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.okPending?(delete this.okPending,e()):this.okcallback=e},o.prototype.yesno=function(t,e){if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.yesnoPending?(delete this.yesnoPending,e(this.yesnoResponse)):this.yesnocallback=e},o.prototype.ask=function(e,r,o){if(!e||"string"!=typeof e)throw new Error("prompt required");if(!1==r instanceof t)throw new Error("attribute or callback expected");if("function"!=typeof o)throw new Error("callback required");this.askPending?(delete this.askPending,o(this.askResponse)):this.askcallback=o},o.prototype.choose=function(t,e,r){if(!t||"string"!=typeof t)throw new Error("prompt required");if(!1==e instanceof Array)throw new Error("choices array required");if(!e.length)throw new Error("choices array empty");if("function"!=typeof r)throw new Error("callback required");this.choosePending?(delete this.choosePending,r(o.firstMatch(this.chooseResponse,e))):(this.choosecallback=r,this.chooseChoices=e)},o.firstMatch=function(t,e){if(void 0!==t)for(var r=0;r<e.length;r++){var o=e[r].toLowerCase();if(C(o,t.length)==t.toLowerCase())return r}};var p=function(t){if(!1==this instanceof p)throw new Error("new operator required");if(t instanceof f)this.model=t;else{if(!(t instanceof c))throw new Error("argument required: model");this.view=t,this.model=this.view.primaryModel}this.attributes=t.attributes,this._items=[],this._itemIndex=-1};p.prototype.length=function(){return this._items.length},p.prototype.clear=function(){return this._items=[],this._itemIndex=-1,this},p.prototype.get=function(t){if(this._items.length<1)throw new Error("list is empty");for(var e=0;e<this.attributes.length;e++){var r=this.attributes[e].name.toUpperCase(),o=t.toUpperCase(),n=o.split("."),i=r==o;if(2==n.length){o=n[1];var s=n[0],a=this.attributes[e].model.modelType.toUpperCase();i=r==o&&s==a}if(i)return"Date"!=this.attributes[e].type||this._items[this._itemIndex][e]instanceof Date?this._items[this._itemIndex][e]:null===this._items[this._itemIndex][e]||void 0===this._items[this._itemIndex][e]?null:new Date(this._items[this._itemIndex][e])}},p.prototype.set=function(t,e){if(this._items.length<1)throw new Error("list is empty");for(var r=0;r<this.attributes.length;r++){var o=this.attributes[r].name.toUpperCase(),n=t.toUpperCase(),i=n.split("."),s=o==n;if(2==i.length){n=i[1];var a=i[0],c=this.attributes[r].model.modelType.toUpperCase();s=o==n&&a==c}if(s)return void(this._items[this._itemIndex][r]=e)}throw new Error("attribute not valid for list model")},p.prototype.addItem=function(t){var e,r=[];if(t)for(e in t.attributes)r.push(t.attributes[e].value);else for(e in this.attributes)r.push(void 0);return this._items.push(r),this._itemIndex=this._items.length-1,this},p.prototype.removeItem=function(){return this._items.splice(this._itemIndex,1),this._itemIndex--,this},p.prototype.findItemByID=function(t){for(var e=this.moveFirst();e;){if(t==this._items[this._itemIndex][0])return!0;e=this.moveNext()}return!1},p.prototype.indexedItem=function(t){return!(this._items.length<1)&&(!(t<0)&&(!(t>=this._items.length)&&(this._itemIndex=t,!0)))},p.prototype.moveNext=function(){return!(this._items.length<1)&&this.indexedItem(this._itemIndex+1)},p.prototype.movePrevious=function(){return!(this._items.length<1)&&this.indexedItem(this._itemIndex-1)},p.prototype.moveFirst=function(){return!(this._items.length<1)&&this.indexedItem(0)},p.prototype.moveLast=function(){return!(this._items.length<1)&&this.indexedItem(this._items.length-1)},p.prototype.sort=function(t){var e,r=0;for(var o in t)e||(e=o);if(!e)throw new Error("sort order required");for(var n=1==t[e];r<this.attributes.length&&this.attributes[r].name!=e;)r++;this._items.sort(function(t,e){if(n){if(t[r]<e[r])return-1;if(t[r]>e[r])return 1}else{if(t[r]>e[r])return-1;if(t[r]<e[r])return 1}return 0})},n.prototype.toString=function(){switch(this.type){case"Null":return this.type+" Message";default:return this.type+" Message: "+this.contents}},n.getTypes=function(){return["Null","Connected","Error","Sent","Ping","PutModel","PutModelAck","GetModel","GetModelAck","DeleteModel","DeleteModelAck","GetList","GetListAck"].slice(0)};var f=function(e){var r;if(!1==this instanceof f)throw new Error("new operator required");if(this.attributes=[new t("id","ID")],e=e||{},this.modelType=e.modelType||"Model",e.attributes)for(r in e.attributes)e.attributes.hasOwnProperty(r)&&this.attributes.push(e.attributes[r]);var o=_(e,["modelType","attributes"]),n=this.getObjectStateErrors();for(r=0;r<o.length;r++)n.push("invalid property: "+o[r]);if(n.length>1)throw new Error("error creating Model: multiple errors");if(n.length)throw new Error("error creating Model: "+n[0]);this._eventListeners=[],this._errorConditions={}};f._ModelConstructor={},f.prototype.toString=function(){return"a "+this.modelType},f.prototype.copy=function(t){for(var e=0;e<this.attributes.length;e++)this.attributes[e].value=t.attributes[e].value},f.prototype.getObjectStateErrors=function(){if(this.validationErrors=[],this.attributes instanceof Array)if(this.attributes.length<1)this.validationErrors.push("attributes must not be empty");else for(var e=0;e<this.attributes.length;e++)0!==e||this.attributes[e]instanceof t&&"ID"==this.attributes[e].type||this.validationErrors.push("first attribute must be ID"),this.attributes[e]instanceof t||this.validationErrors.push("attribute must be Attribute");else this.validationErrors.push("attributes must be Array");return void 0===this.tags||this.tags instanceof Array||this.validationErrors.push("tags must be Array or null"),this.validationErrors},f.prototype.attribute=function(t){for(var e=0;e<this.attributes.length;e++)if(this.attributes[e].name.toUpperCase()==t.toUpperCase())return this.attributes[e];throw new Error("attribute not found in model: "+t)},f.prototype.get=function(t){for(var e=0;e<this.attributes.length;e++)if(this.attributes[e].name.toUpperCase()==t.toUpperCase())return this.attributes[e].get()},f.prototype.getShortName=function(){for(var t=0;t<this.attributes.length;t++)if("String"==this.attributes[t].type)return this.attributes[t].get();return""},f.prototype.getLongName=function(){return this.getShortName()},f.prototype.getAttributeType=function(t){for(var e=0;e<this.attributes.length;e++)if(this.attributes[e].name.toUpperCase()==t.toUpperCase())return this.attributes[e].type},f.prototype.set=function(t,e){for(var r=0;r<this.attributes.length;r++)if(this.attributes[r].name.toUpperCase()==t.toUpperCase())return this.attributes[r].set(e),void this._emitEvent("StateChange");throw new Error("attribute not valid for model")},f.prototype.validate=function(t){var e,r,o=this,n=0;if("function"!=typeof t)throw new Error("callback is required");o.getObjectStateErrors();for(r in o._errorConditions)o._errorConditions.hasOwnProperty(r)&&o.validationErrors.push(o._errorConditions[r]);if(o.validationErrors.length)return o.validationMessage=o.validationErrors.length>0?o.validationErrors[0]:"",o._emitEvent("StateChange"),void t.call(o);for(e=0;e<o.attributes.length;e++)n++,function(e){setTimeout(function(){e.validate(function(){e.validationErrors.length&&o.validationErrors.push("bush"),0==--n&&(o.validationErrors.length||o._emitEvent("Validate"),o.validationMessage=o.validationErrors.length>0?o.validationErrors[0]:"",o._emitEvent("StateChange"),t.call(o))})},0)}(o.attributes[e])},f.prototype.onEvent=function(t,e){if(!(t instanceof Array)){if("string"!=typeof t)throw new Error("subscription string or array required");t=[t]}if("function"!=typeof e)throw new Error("callback is required");for(var r in t)if(t.hasOwnProperty(r)&&"*"!=t[r]&&!q(["StateChange","Validate"],t[r]))throw new Error("Unknown command event: "+t[r]);return this._eventListeners.push({events:t,callback:e}),this},f.prototype._emitEvent=function(t,e){var r;for(r in this._eventListeners)if(this._eventListeners.hasOwnProperty(r)){var o=this._eventListeners[r];(o.events.length&&"*"===o.events[0]||q(o.events,t))&&o.callback.call(this,t,e)}},f.prototype.setError=function(t,e){if(t=t||"",e=e||"",!t)throw new Error("condition required");if(!e)throw new Error("description required");this._errorConditions[t]=e},f.prototype.clearError=function(t){if(!(t=t||""))throw new Error("condition required");delete this._errorConditions[t]};var d=function(t){if(!1==this instanceof d)throw new Error("new operator required");t instanceof Array&&(t={tasks:t});var e,r=_(t=t||{},["tasks","tasksNeeded","tasksCompleted"]),o=[];for(e=0;e<r.length;e++)o.push("invalid property: "+r[e]);if(o.length>1)throw new Error("error creating Procedure: multiple errors");if(o.length)throw new Error("error creating Procedure: "+o[0]);for(e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);if(o=this.getObjectStateErrors()){if(o.length>1)throw new Error("error creating Procedure: multiple errors");if(o.length)throw new Error("error creating Procedure: "+o[0])}};d.prototype.getObjectStateErrors=function(){var t,r,o,n;if(this.tasks&&!(this.tasks instanceof Array))return["tasks is not an array"];var i=[];for(t in this.tasks)if(this.tasks.hasOwnProperty(t)){var s=this.tasks[t];for(n=_(s,["label","command","requires","timeout"]),r=0;r<n.length;r++)i.push("invalid task["+t+"] property: "+n[r]);void 0!==s.label&&"string"!=typeof s.label&&i.push("task["+t+"].label must be string"),void 0===s.command||s.command instanceof e||i.push("task["+t+"].command must be a Command object"),void 0===s.requires&&(s.requires=-1),s.requires instanceof Array||(s.requires=[s.requires]);for(r in s.requires)if(s.requires.hasOwnProperty(r)&&null!==s.requires[r])switch(typeof s.requires[r]){case"string":var a=!1;for(o=0;!a&&o<this.tasks.length;o++)s.requires[r]==this.tasks[o].label&&(a=!0);if(!a)throw new Error("missing label: "+s.requires[r]);break;case"number":if(s.requires[r]>=this.tasks.length)throw new Error("missing task #"+s.requires[r]+" for requires in task["+t+"]");if(s.requires[r]<-1)throw new Error("task #"+s.requires[r]+" invalid requires in task["+t+"]");break;default:throw new Error("invalid type for requires in task["+t+"]")}}return i.length?i:null},i.prototype.toString=function(){switch(this.type){case"Command":return this.type+" Request: "+this.command;default:return this.type+" Request"}};var m=function(t){if(!1==this instanceof m)throw new Error("new operator required");t=t||{},this.storeType=t.storeType||"Store",this.name=t.name||"a "+this.storeType,this.storeProperty={isReady:!1,canGetModel:!1,canPutModel:!1,canDeleteModel:!1,canGetList:!1};for(var e=_(t,["name","storeType"]),r=[],o=0;o<e.length;o++)r.push("invalid property: "+e[o]);if(r.length>1)throw new Error("error creating Store: multiple errors");if(r.length)throw new Error("error creating Store: "+r[0])};m.prototype.toString=function(){return this.name=="a "+this.storeType?this.name:this.storeType+": "+this.name},m.prototype.getServices=function(){return this.storeProperty},m.prototype.onConnect=function(t,e){if("string"!=typeof t)throw new Error("argument must a url string");if("function"!=typeof e)throw new Error("argument must a callback");e(this,void 0)},m.prototype.getModel=function(){throw new Error(this.storeType+" does not provide getModel")},m.prototype.putModel=function(){throw new Error("Store does not provide putModel")},m.prototype.deleteModel=function(){throw new Error("Store does not provide deleteModel")},m.prototype.getList=function(){throw new Error("Store does not provide getList")},m.prototype.getViewList=function(t,e,r,o){function n(e,r){function o(){if(s){for(t.addItem(),a=0;a<t.attributes.length;a++){var e=t.attributes[a];e.model==t.model&&t.set(e.name,h.get(e.name))}l=[];for(var r in t.view.relatedModels)t.view.relatedModels.hasOwnProperty(r)&&l.push(r);n()}else i(t)}function n(){if(!l.length)return s=h.moveNext(),void o();var e=l.shift(),r=t.view.relatedModels[e],a=h.get(r.id.name);r.model.set("id",a),c.getModel(r.model,function(e,r){if(void 0===r){for(var o=0;o<t.attributes.length;o++){var s=t.attributes[o];s.model==e&&t.set(e.modelType+"."+s.name,e.get(s.name))}n()}else i(r)})}if(t.clear(),void 0===r){var s=h.moveFirst(),l=[];o()}else i(t,r)}var i,s,a,c=this;if("function"==typeof o?(i=o,s=r):i=r,!(t instanceof p))throw new Error("argument must be a List");if(!t.view)throw new Error("List is Model type use getList");if(!(e instanceof Object))throw new Error("filter argument must be Object");if("function"!=typeof i)throw new Error("callback required");var h=new p(t.model);s?this.getList(h,e,s,n):this.getList(h,e,n)},s.prototype.toString=function(){return"Text: '"+(this.contents||"")+"'"},s.prototype.get=function(){return this.contents},s.prototype.set=function(t){return this.contents=t,this._emitEvent("StateChange"),this.contents},s.prototype._emitEvent=function(t){var e;for(e in this._eventListeners)if(this._eventListeners.hasOwnProperty(e)){var r=this._eventListeners[e];(r.events.length&&"*"===r.events[0]||q(r.events,t))&&r.callback.call(this,t)}},s.prototype.onEvent=function(t,e){if(!(t instanceof Array)){if("string"!=typeof t)throw new Error("subscription string or array required");t=[t]}if("function"!=typeof e)throw new Error("callback is required");for(var r in t)if(t.hasOwnProperty(r)&&"*"!=t[r]&&!q(["StateChange"],t[r]))throw new Error("Unknown command event: "+t[r]);return this._eventListeners.push({events:t,callback:e}),this},s.prototype.offEvent=function(){this._eventListeners=[]},a.showLog=!1,a.messageHandlers={},a.setMessageHandler=function(t,e){a.messageHandlers[t]=e},a.hostMessageProcess=function(t,e){a.showLog&&console.log("Transport.hostMessageProcess "+JSON.stringify(t)),a.messageHandlers[t.type]?a.messageHandlers[t.type](t.contents,e):e(!0)},a.prototype.sendRaw=function(t){this.socket.send(t)},a.prototype.onRaw=function(t){this.rawCallBack=t},a.prototype.send=function(t,e){var r=this;if(void 0===t)throw new Error("message required");if(!(t instanceof n))throw new Error("parameter must be instance of Message");if(void 0!==e&&"function"!=typeof e)throw new Error("argument must a callback");this.connected?void 0!==e?(a.showLog&&console.log("Transport emit "+JSON.stringify(t)),r.socket.emit("ackmessage",t,function(t){e.call(r,t)})):(a.showLog&&console.log("Transport send "+JSON.stringify(t)),r.socket.send(t)):e.call(r,new n("Error","not connected"))},a.prototype.close=function(){if(!this.connected)throw new Error("not connected");this.socket.disconnect()},c.prototype.toString=function(){return this.primaryModel+" View"};var w=function(t){if(!1==this instanceof o)throw new Error("new operator required");(t=t||{}).name=t.name||"(unnamed)",t.description=t.description||"a REPLInterface",t.vendor=t.vendor||null;var e,r=_(t,["name","description","vendor"]),n=[];for(e=0;e<r.length;e++)n.push("invalid property: "+r[e]);if(n.length>1)throw new Error("error creating Interface: multiple errors");if(n.length)throw new Error("error creating Interface: "+n[0]);this.startcallback=null,this.stopcallback=null,this.mocks=[],this.mockPending=!1,this.navStack=[];for(e in t)this[e]=t[e]};w.prototype=Object.create(o.prototype),w.prototype.toString=function(){return this.description},w.prototype.canMock=function(){return!0},w.prototype.doMock=function(){var t,e;if(this.mockPending=!1,!(this.mocks.length<1)){var r=this.mocks.shift();if("ok"!=r.type)if("yes"!=r.type&&"no"!=r.type&&"cancel"!=r.type)if("ask"!=r.type)if("choose"!=r.type){this.dispatch(r),this.mockPending=!0;var n=this;setTimeout(function(){n.doMock()},0)}else this.choosecallback?(t=this.choosecallback,delete this.choosecallback,t(o.firstMatch(r.value,this.chooseChoices))):(this.choosePending=!0,this.chooseResponse=r.value);else this.askcallback?(t=this.askcallback,delete this.askcallback,t(r.value)):(this.askPending=!0,this.askResponse=r.value);else{switch(r.type){case"yes":e=!0;break;case"no":e=!1;break;case"cancel":e=void 0}this.yesnocallback?(t=this.yesnocallback,delete this.yesnocallback,t(e)):(this.yesnoPending=!0,this.yesnoResponse=e)}else this.okcallback?(t=this.okcallback,delete this.okcallback,t()):this.okPending=!0}},w.prototype.mockRequest=function(t){if(!(t instanceof Array||t instanceof i))throw new Error("missing request parameter");t instanceof Array||(t=[t]);var e;for(e=0;e<t.length;e++)if(!1==t[e]instanceof i)throw new Error("invalid request parameter");for(e=0;e<t.length;e++)this.mocks.push(t[e]);this.mockPending||this.doMock()},w.prototype.start=function(t,e,r){if(!(t instanceof y))throw new Error("Application required");if(!(e instanceof g))throw new Error("presentation required");if("function"!=typeof r)throw new Error("callback required");this.application=t,this.presentation=e,this.startcallback=r,this.evaluateInput()},w.prototype.stop=function(t){if("function"!=typeof t)throw new Error("callback required")},w.prototype.dispatch=function(t,e){if(!1==t instanceof i)throw new Error("Request required");if(e&&"function"!=typeof e)throw new Error("response callback is not a function");this.application&&this.application.dispatch(t)||this.startcallback&&this.startcallback(t)},w.prototype.notify=function(t){if(!1==t instanceof n)throw new Error("Message required");this._Output(t)},w.prototype.render=function(r,o,n){if(!1==r instanceof g)throw new Error("Presentation object required");if("string"!=typeof o)throw new Error("presentationMode required");if(!q(e.getPresentationModes(),o))throw new Error("Invalid presentationMode: "+o);if(n&&"function"!=typeof n)throw new Error("optional second argument must a commandRequest callback function");var i,s,a=r.get("contents"),c=0;switch(o){case"View":for(i=0;i<a.length;i++)a[i]instanceof t&&a[i].label.length>c&&(c=a[i].label.length);for(i=0;i<a.length;i++)(s=a[i])instanceof t?this._Output(A(s.label,c)+": "+s.value):this._Output(s);break;case"Edit":for(this.editPresentationContents=a.slice();this.editPresentationContents.length&&!(this.editPresentationContents[0]instanceof t);){var h=this.editPresentationContents.shift();h instanceof e||this._Output(h)}this.editPresentationContents.length&&this.editPresentationContents[0]instanceof t&&this._setPrompt(this.editPresentationContents[0].label+": "),this.editPresentationContents.length||delete this.editPresentationContents;break;default:throw new Error("presentationMode not handled: "+o)}},w.prototype.info=function(t){if(!t||"string"!=typeof t)throw new Error("text required");this._Output(t)},w.prototype.ok=function(t,e){if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this._Output(t),this.okPending?(delete this.okPending,e()):this.okcallback=e},w.prototype.yesno=function(t,e){if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.yesnoPrompt=t,this._setPrompt(this.yesnoPrompt),this.yesnoPending?(delete this.yesnoPending,e(this.yesnoResponse)):this.yesnocallback=e},w.prototype.ask=function(e,r,o){if(!e||"string"!=typeof e)throw new Error("prompt required");if(!1==r instanceof t)throw new Error("attribute or callback expected");if("function"!=typeof o)throw new Error("callback required");this.askPrompt=e,this._setPrompt(e),this.askPending?(delete this.askPending,o(this.askResponse)):this.askcallback=o},w.prototype.choose=function(t,e,r){if(!t||"string"!=typeof t)throw new Error("prompt required");if(!1==e instanceof Array)throw new Error("choices array required");if(!e.length)throw new Error("choices array empty");if("function"!=typeof r)throw new Error("callback required");this.choosePrompt=t,this._Output(t);for(var n=0;n<e.length;n++)this._Output(" "+e[n]);this._setPrompt("Choice? "),this.choosePending?(delete this.choosePending,r(o.firstMatch(this.chooseResponse,e))):(this.choosecallback=r,this.chooseChoices=e)},w.prototype.evaluateInput=function(t){var e=this;void 0===t&&(t=""),this._evaluateInput(t),setTimeout(function(){var t=e.application?e.application.get("brand"):"?";!e.promptText&&e.application&&e.application.primaryInterface&&e._ShowNav(),e.promptText&&(t=e.promptText,delete e.promptText),e.capturePromptcallback&&e.capturePromptcallback(t)},10)},w.prototype._evaluateInput=function(r){var n,i,s,a=(""+r).toUpperCase();if(this.okcallback)return n=this.okcallback,delete this.okcallback,void n();if(this.yesnocallback)return"Y"==a||"YES"==a?(n=this.yesnocallback,delete this.yesnocallback,void n(!0)):"N"==a||"NO"==a?(n=this.yesnocallback,delete this.yesnocallback,void n(!1)):0===r.length?(n=this.yesnocallback,delete this.yesnocallback,void n()):(this._Output("yes or no response required"),void this._setPrompt(this.yesnoPrompt));if(this.askcallback)return n=this.askcallback,delete this.askcallback,void n(r);if(this.choosecallback){n=this.choosecallback;var c=o.firstMatch(r,this.chooseChoices);if(c)delete this.choosecallback,n(c);else if(r.length>0){for(this.application.info('"'+r+'" not valid'),this._Output(this.choosePrompt),i=0;i<this.chooseChoices.length;i++)this._Output(" "+this.chooseChoices[i]);this._setPrompt("Choice? ")}else delete this.choosecallback,n()}else{if(this.editPresentationContents){if(!(this.editPresentationContents.length&&this.editPresentationContents[0]instanceof t))throw this.editPresentationContents.length||delete this.editPresentationContents,new Error("editPresentationContents expected attribute");for(s=this.editPresentationContents.shift(),r.length&&(s.value=r);this.editPresentationContents.length&&!(this.editPresentationContents[0]instanceof t);)(s=this.editPresentationContents.shift())instanceof e||this._Output(s);return this.editPresentationContents.length&&this.editPresentationContents[0]instanceof t&&this._setPrompt(this.editPresentationContents[0].label+": "),void(this.editPresentationContents.length||delete this.editPresentationContents)}if(this.presentation){var h=this.presentation.get("contents");for(this.navStack.length>0&&(h=this.navStack[this.navStack.length-1].contents),i=0;i<h.length;i++){var l=h[i];if(l instanceof e){var u=l.name.toUpperCase();if(r.length&&C(u,a.length)==a){switch(l.type){case"Stub":this.info(l.description+" not available.");break;case"Menu":this.navStack.push(l);break;case"Presentation":l.presentationMode="Edit",l.execute(this);break;default:l.execute()}return}}}r.length>0?this.application.info('"'+r+'" not valid'):this.navStack.pop()}else this._Output("input ignored: "+r)}},w.prototype._ShowNav=function(){var t,r=this.application?this.application.get("brand"):"?",o=this.presentation.get("contents"),n="",i="",s="";if(this.navStack.length>0){var a=this.navStack[this.navStack.length-1];for(n=a.name.replace(/\s/g,"")+": ",o=a.contents,t=0;t<this.navStack.length;t++)r+=" / "+this.navStack[t].name.replace(/\s/g,"")}for(t=0;t<o.length;t++){var c=o[t];c instanceof e&&(i+=s+c.name.replace(/\s/g,""),s=", ")}this.application.info(n+i),this._setPrompt(r+">")},w.prototype.captureOutput=function(t){this.captureOutputcallback=t},w.prototype.capturePrompt=function(t){this.capturePromptcallback=t},w.prototype._setPrompt=function(t){this.promptText=t},w.prototype._Output=function(t){this.captureOutputcallback&&this.captureOutputcallback(t)};var y=function(e){if(!1==this instanceof y)throw new Error("new operator required");(e=e||{}).attributes||(e.attributes=[]),e.attributes.push(new t({name:"name",type:"String(20)"})),e.attributes.push(new t({name:"brand",type:"String"})),e.interface&&(this.setInterface(e.interface),delete e.interface),f.call(this,e),this.modelType="Application",this.set("name","newApp"),this.set("brand","NEW APP")};y.prototype=Object.create(f.prototype),f._ModelConstructor.Application=y,y.prototype.start=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("error starting application: interface not set");if("function"!=typeof t)throw new Error("callback required");var e=this;this.startcallback=t,this.presentation||(this.presentation=new g),this.primaryInterface.start(e,this.presentation,function(t){"Command"==t.type?t.command.execute():e.startcallback&&e.startcallback(t)})},y.prototype.dispatch=function(t,e){if(!1==t instanceof i)throw new Error("Request required");if(e&&"function"!=typeof e)throw new Error("response callback is not a function");return"Command"==t.type?(t.command.execute(),!0):!!this.startcallback&&(this.startcallback(t),!0)},y.prototype.setInterface=function(t){if(!1==t instanceof o)throw new Error("instance of Interface a required parameter");this.primaryInterface=t},y.prototype.getInterface=function(){return this.primaryInterface},y.prototype.setPresentation=function(t){if(!1==t instanceof g)throw new Error("instance of Presentation a required parameter");this.presentation=t},y.prototype.getPresentation=function(){return this.presentation},y.prototype.info=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("text parameter required");this.primaryInterface.info(t)},y.prototype.done=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("text parameter required");this.primaryInterface.done(t)},y.prototype.warn=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("text parameter required");this.primaryInterface.warn(t)},y.prototype.err=function(t){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("text parameter required");this.primaryInterface.err(t)},y.prototype.ok=function(t,e){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.primaryInterface.ok(t,e)},y.prototype.yesno=function(t,e){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("prompt required");if("function"!=typeof e)throw new Error("callback required");this.primaryInterface.yesno(t,e)},y.prototype.ask=function(e,r,n){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!e||"string"!=typeof e)throw new Error("prompt required");if("function"!=typeof r){if(!1==r instanceof t)throw new Error("attribute or callback expected");if("function"!=typeof n)throw new Error("callback required");this.primaryInterface.ask(e,r,n)}else this.primaryInterface.ask(e,new t({name:"default"}),r)},y.prototype.choose=function(t,e,r){if(!1==this.primaryInterface instanceof o)throw new Error("interface not set");if(!t||"string"!=typeof t)throw new Error("prompt required");if(!1==e instanceof Array)throw new Error("choices array required");if(!e.length)throw new Error("choices array empty");if("function"!=typeof r)throw new Error("callback required");this.primaryInterface.choose(t,e,r)};var v=function(e){if(!1==this instanceof v)throw new Error("new operator required");if("string"==typeof e){var r=e;(e={}).contents=r}(e=e||{}).attributes||(e.attributes=[]);var o=e.logType||"Text",n=e.importance||"Info",i=e.contents||"(no text)";if(!q(["Text","Delta"],o))throw new Error("Unknown log type: "+o);void 0!==e.logType&&delete e.logType,void 0!==e.importance&&delete e.importance,void 0!==e.contents&&delete e.contents,e.attributes.push(new t({name:"dateLogged",type:"Date",value:new Date})),e.attributes.push(new t({name:"logType",type:"String",value:o})),e.attributes.push(new t({name:"importance",type:"String",value:n})),"Delta"==o?e.attributes.push(new t({name:"contents",type:"Object",value:i})):e.attributes.push(new t({name:"contents",type:"String",value:i})),f.call(this,e),this.modelType="Log"};v.prototype=Object.create(f.prototype),f._ModelConstructor.Log=v,v.prototype.toString=function(){return"Delta"==this.get("logType")?this.get("importance")+": (delta)":this.get("importance")+": "+this.get("contents")};var g=function(e){if(!1==this instanceof g)throw new Error("new operator required");(e=e||{}).attributes||(e.attributes=[]),e.attributes.push(new t({name:"name",type:"String"})),e.attributes.push(new t({name:"modelName",type:"String"})),e.attributes.push(new t({name:"contents",type:"Object",value:[]})),f.call(this,e),this.modelType="Presentation"};g.prototype=Object.create(f.prototype),f._ModelConstructor.Presentation=g,g.prototype.getObjectStateEr